Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / TracepointProvider.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "common/TracepointProvider.h"
5 #include "common/config.h"
6
7 TracepointProvider::TracepointProvider(CephContext *cct, const char *library,
8                                        const char *config_key)
9   : m_cct(cct), m_library(library), m_config_keys{config_key, NULL},
10     m_lock("TracepointProvider::m_lock") {
11   m_cct->_conf->add_observer(this);
12   verify_config(m_cct->_conf);
13 }
14
15 TracepointProvider::~TracepointProvider() {
16   m_cct->_conf->remove_observer(this);
17   if (m_handle) {
18     dlclose(m_handle);
19   }
20 }
21
22 void TracepointProvider::handle_conf_change(
23     const struct md_config_t *conf, const std::set<std::string> &changed) {
24   if (changed.count(m_config_keys[0])) {
25     verify_config(conf);
26   }
27 }
28
29 void TracepointProvider::verify_config(const struct md_config_t *conf) {
30   Mutex::Locker locker(m_lock);
31   if (m_handle) {
32     return;
33   }
34
35   char buf[10];
36   char *pbuf = buf;
37   if (conf->get_val(m_config_keys[0], &pbuf, sizeof(buf)) != 0 ||
38       strncmp(buf, "true", 5) != 0) {
39     return;
40   }
41
42   m_handle = dlopen(m_library.c_str(), RTLD_NOW | RTLD_NODELETE);
43   assert(m_handle);
44 }
45