Skip to content

Commit

Permalink
librados: conditionally initialize the tracepoint provider
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 6368c28)
  • Loading branch information
Jason Dillaman committed Nov 20, 2015
1 parent afc4f17 commit bf34b36
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/librados/librados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "common/errno.h"
#include "common/ceph_argparse.h"
#include "common/common_init.h"
#include "common/TracepointProvider.h"
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
#include "include/types.h"
Expand Down Expand Up @@ -61,6 +62,12 @@ using std::runtime_error;

#define RADOS_LIST_MAX_ENTRIES 1024

namespace {

TracepointProvider::Traits tracepoint_traits("librados_tp.so", "rados_tracing");

} // anonymous namespace

/*
* Structure of this file
*
Expand Down Expand Up @@ -2171,10 +2178,9 @@ librados::ObjectOperation::~ObjectOperation()
}

///////////////////////////// C API //////////////////////////////
static
int rados_create_common(rados_t *pcluster,
const char * const clustername,
CephInitParameters *iparams)

static CephContext *rados_create_cct(const char * const clustername,
CephInitParameters *iparams)
{
// missing things compared to global_init:
// g_ceph_context, g_conf, g_lockdep, signal handlers
Expand All @@ -2184,26 +2190,27 @@ int rados_create_common(rados_t *pcluster,
cct->_conf->parse_env(); // environment variables override
cct->_conf->apply_changes(NULL);

librados::RadosClient *radosp = new librados::RadosClient(cct);
*pcluster = (void *)radosp;

cct->put();
return 0;
TracepointProvider::initialize<tracepoint_traits>(cct);
return cct;
}

extern "C" int rados_create(rados_t *pcluster, const char * const id)
{
tracepoint(librados, rados_create_enter, id);
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
if (id) {
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
}
int retval = rados_create_common(pcluster, "ceph", &iparams);
tracepoint(librados, rados_create_exit, retval, *pcluster);
return retval;
CephContext *cct = rados_create_cct("ceph", &iparams);

tracepoint(librados, rados_create_enter, id);
*pcluster = reinterpret_cast<rados_t>(new librados::RadosClient(cct));
tracepoint(librados, rados_create_exit, 0, *pcluster);

cct->put();
return 0;
}

// as above, but
// as above, but
// 1) don't assume 'client.'; name is a full type.id namestr
// 2) allow setting clustername
// 3) flags is for future expansion (maybe some of the global_init()
Expand All @@ -2212,16 +2219,21 @@ extern "C" int rados_create(rados_t *pcluster, const char * const id)
extern "C" int rados_create2(rados_t *pcluster, const char *const clustername,
const char * const name, uint64_t flags)
{
tracepoint(librados, rados_create2_enter, clustername, name, flags);
// client is assumed, but from_str will override
int retval = 0;
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
if (!name || !iparams.name.from_str(name)) {
tracepoint(librados, rados_create2_exit, -EINVAL, *pcluster);
return -EINVAL;
retval = -EINVAL;
}

int retval = rados_create_common(pcluster, clustername, &iparams);
CephContext *cct = rados_create_cct(clustername, &iparams);
tracepoint(librados, rados_create2_enter, clustername, name, flags);
if (retval == 0) {
*pcluster = reinterpret_cast<rados_t>(new librados::RadosClient(cct));
}
tracepoint(librados, rados_create2_exit, retval, *pcluster);

cct->put();
return retval;
}

Expand All @@ -2231,8 +2243,10 @@ extern "C" int rados_create2(rados_t *pcluster, const char *const clustername,
*/
extern "C" int rados_create_with_context(rados_t *pcluster, rados_config_t cct_)
{
tracepoint(librados, rados_create_with_context_enter, cct_);
CephContext *cct = (CephContext *)cct_;
TracepointProvider::initialize<tracepoint_traits>(cct);

tracepoint(librados, rados_create_with_context_enter, cct_);
librados::RadosClient *radosp = new librados::RadosClient(cct);
*pcluster = (void *)radosp;
tracepoint(librados, rados_create_with_context_exit, 0, *pcluster);
Expand Down

0 comments on commit bf34b36

Please sign in to comment.