#include "common/errno.h"
#include "include/buffer.h"
#include "include/stringify.h"
+#include "include/util.h"
#include "messages/MLog.h"
#include "msg/Messenger.h"
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")
{
}
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);
}
bool need_objecter = false;
- if (objecter && objecter->initialized.read()) {
+ if (objecter && objecter->initialized) {
need_objecter = true;
}
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);
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;
}
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;
if (log_last_version < m->version) {
log_last_version = m->version;
- if (log_cb) {
+ if (log_cb || log_cb2) {
for (std::deque<LogEntry>::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());
}
}
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<std::string,std::string>& 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<std::string,std::string>& status)
+{
+ if (state != CONNECTED) {
+ return -ENOTCONN;
+ }
+ return mgrclient.service_daemon_update_status(status);
+}