X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Flibrados%2FRadosClient.cc;h=c90f3c129d454805d524d47b02bcef0b9bedfee6;hb=224ce89bce8186937e77bdbda572a650953f8c23;hp=3e0de3adeb1da875bfcf874505e2abb737887f9d;hpb=7c673caec407dd16107e56e4b51a6d00f021315c;p=ceph.git diff --git a/ceph/src/librados/RadosClient.cc b/ceph/src/librados/RadosClient.cc index 3e0de3ade..c90f3c129 100644 --- a/ceph/src/librados/RadosClient.cc +++ b/ceph/src/librados/RadosClient.cc @@ -28,6 +28,7 @@ #include "common/errno.h" #include "include/buffer.h" #include "include/stringify.h" +#include "include/util.h" #include "messages/MLog.h" #include "msg/Messenger.h" @@ -77,7 +78,7 @@ librados::RadosClient::RadosClient(CephContext *cct_) lock("librados::RadosClient::lock"), timer(cct, lock), refcnt(1), - log_last_version(0), log_cb(NULL), log_cb_arg(NULL), + log_last_version(0), log_cb(NULL), log_cb2(NULL), log_cb_arg(NULL), finisher(cct, "radosclient", "fn-radosclient") { } @@ -307,6 +308,12 @@ int librados::RadosClient::connect() monclient.sub_want("mgrmap", 0, 0); monclient.renew_subs(); + if (service_daemon) { + ldout(cct, 10) << __func__ << " registering as " << service_name << "." + << daemon_name << dendl; + mgrclient.service_daemon_register(service_name, daemon_name, + daemon_metadata); + } mgrclient.init(); objecter->set_client_incarnation(0); @@ -351,7 +358,7 @@ void librados::RadosClient::shutdown() } bool need_objecter = false; - if (objecter && objecter->initialized.read()) { + if (objecter && objecter->initialized) { need_objecter = true; } @@ -920,7 +927,10 @@ int librados::RadosClient::pg_command(pg_t pgid, vector& cmd, return ret; } -int librados::RadosClient::monitor_log(const string& level, rados_log_callback_t cb, void *arg) +int librados::RadosClient::monitor_log(const string& level, + rados_log_callback_t cb, + rados_log_callback2_t cb2, + void *arg) { Mutex::Locker l(lock); @@ -928,12 +938,14 @@ int librados::RadosClient::monitor_log(const string& level, rados_log_callback_t return -ENOTCONN; } - if (cb == NULL) { + if (cb == NULL && cb2 == NULL) { // stop watch - ldout(cct, 10) << __func__ << " removing cb " << (void*)log_cb << dendl; + ldout(cct, 10) << __func__ << " removing cb " << (void*)log_cb + << " " << (void*)log_cb2 << dendl; monclient.sub_unwant(log_watch); log_watch.clear(); log_cb = NULL; + log_cb2 = NULL; log_cb_arg = NULL; return 0; } @@ -954,15 +966,17 @@ int librados::RadosClient::monitor_log(const string& level, rados_log_callback_t return -EINVAL; } - if (log_cb) + if (log_cb || log_cb2) monclient.sub_unwant(log_watch); // (re)start watch - ldout(cct, 10) << __func__ << " add cb " << (void*)cb << " level " << level << dendl; + ldout(cct, 10) << __func__ << " add cb " << (void*)cb << " " << (void*)cb2 + << " level " << level << dendl; monclient.sub_want(watch_level, 0, 0); monclient.renew_subs(); log_cb = cb; + log_cb2 = cb2; log_cb_arg = arg; log_watch = watch_level; return 0; @@ -976,21 +990,29 @@ void librados::RadosClient::handle_log(MLog *m) if (log_last_version < m->version) { log_last_version = m->version; - if (log_cb) { + if (log_cb || log_cb2) { for (std::deque::iterator it = m->entries.begin(); it != m->entries.end(); ++it) { LogEntry e = *it; ostringstream ss; - ss << e.stamp << " " << e.who.name << " " << e.prio << " " << e.msg; + ss << e.stamp << " " << e.name << " " << e.prio << " " << e.msg; string line = ss.str(); string who = stringify(e.who); + string name = stringify(e.name); string level = stringify(e.prio); struct timespec stamp; e.stamp.to_timespec(&stamp); ldout(cct, 20) << __func__ << " delivering " << ss.str() << dendl; - log_cb(log_cb_arg, line.c_str(), who.c_str(), - stamp.tv_sec, stamp.tv_nsec, - e.seq, level.c_str(), e.msg.c_str()); + if (log_cb) + log_cb(log_cb_arg, line.c_str(), who.c_str(), + stamp.tv_sec, stamp.tv_nsec, + e.seq, level.c_str(), e.msg.c_str()); + if (log_cb2) + log_cb2(log_cb_arg, line.c_str(), + e.channel.c_str(), + who.c_str(), name.c_str(), + stamp.tv_sec, stamp.tv_nsec, + e.seq, level.c_str(), e.msg.c_str()); } } @@ -999,3 +1021,51 @@ void librados::RadosClient::handle_log(MLog *m) m->put(); } + +int librados::RadosClient::service_daemon_register( + const std::string& service, ///< service name (e.g., 'rgw') + const std::string& name, ///< daemon name (e.g., 'gwfoo') + const std::map& metadata) +{ + if (service_daemon) { + return -EEXIST; + } + if (service == "osd" || + service == "mds" || + service == "client" || + service == "mon" || + service == "mgr") { + // normal ceph entity types are not allowed! + return -EINVAL; + } + if (service.empty() || name.empty()) { + return -EINVAL; + } + + collect_sys_info(&daemon_metadata, cct); + + ldout(cct,10) << __func__ << " " << service << "." << name << dendl; + service_daemon = true; + service_name = service; + daemon_name = name; + daemon_metadata.insert(metadata.begin(), metadata.end()); + + if (state == DISCONNECTED) { + return 0; + } + if (state == CONNECTING) { + return -EBUSY; + } + mgrclient.service_daemon_register(service_name, daemon_name, + daemon_metadata); + return 0; +} + +int librados::RadosClient::service_daemon_update_status( + const std::map& status) +{ + if (state != CONNECTED) { + return -ENOTCONN; + } + return mgrclient.service_daemon_update_status(status); +}