Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / system / st_rados_notify.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation.  See file COPYING.
12 *
13 */
14
15 #include "cross_process_sem.h"
16 #include "include/rados/librados.h"
17 #include "st_rados_notify.h"
18 #include "systest_runnable.h"
19
20 StRadosNotify::StRadosNotify(int argc, const char **argv,
21                              CrossProcessSem *setup_sem,
22                              CrossProcessSem *notify_sem,
23                              CrossProcessSem *notified_sem,
24                              int notify_retcode,
25                              const std::string &pool_name,
26                              const std::string &obj_name)
27   : SysTestRunnable(argc, argv),
28     m_setup_sem(setup_sem),
29     m_notify_sem(notify_sem),
30     m_notified_sem(notified_sem),
31     m_notify_retcode(notify_retcode),
32     m_pool_name(pool_name),
33     m_obj_name(obj_name)
34 {
35 }
36
37 StRadosNotify::~StRadosNotify()
38 {
39 }
40
41 #pragma GCC diagnostic ignored "-Wpragmas"
42 #pragma GCC diagnostic push
43 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44
45 int StRadosNotify::run()
46 {
47   rados_t cl;
48   RETURN1_IF_NONZERO(rados_create(&cl, NULL));
49   rados_conf_parse_argv(cl, m_argc, m_argv);
50   RETURN1_IF_NONZERO(rados_conf_read_file(cl, NULL));
51   rados_conf_parse_env(cl, NULL);
52
53   if (m_setup_sem) {
54     m_setup_sem->wait();
55     m_setup_sem->post();
56   }
57
58   rados_ioctx_t io_ctx;
59   RETURN1_IF_NONZERO(rados_connect(cl));
60   RETURN1_IF_NONZERO(rados_ioctx_create(cl, m_pool_name.c_str(), &io_ctx));
61
62   if (m_notify_sem) {
63     m_notify_sem->wait();
64     m_notify_sem->post();
65   }
66
67   printf("%s: notifying object %s\n", get_id_str(), m_obj_name.c_str());
68   RETURN1_IF_NOT_VAL(m_notify_retcode,
69                      rados_notify(io_ctx, m_obj_name.c_str(), 0, NULL, 0));
70   if (m_notified_sem) {
71     m_notified_sem->post();
72   }
73
74   rados_ioctx_destroy(io_ctx);
75   rados_shutdown(cl);
76
77   return 0;
78 }
79
80 #pragma GCC diagnostic pop
81 #pragma GCC diagnostic warning "-Wpragmas"