]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/librados/RadosClient.cc
update sources to v12.1.2
[ceph.git] / ceph / src / librados / RadosClient.cc
index e3215c96a025d7a4304e095f6ad31e20126e43ad..7131aa838acd413a646b298b5e63f61ad29801b6 100644 (file)
@@ -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"
@@ -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);
@@ -802,22 +809,21 @@ int librados::RadosClient::mon_command(const vector<string>& cmd,
                                       const bufferlist &inbl,
                                       bufferlist *outbl, string *outs)
 {
-  Mutex mylock("RadosClient::mon_command::mylock");
-  Cond cond;
-  bool done;
-  int rval;
+  C_SaferCond ctx;
+  mon_command_async(cmd, inbl, outbl, outs, &ctx);
+  return ctx.wait();
+}
+
+void librados::RadosClient::mon_command_async(const vector<string>& cmd,
+                                              const bufferlist &inbl,
+                                              bufferlist *outbl, string *outs,
+                                              Context *on_finish)
+{
   lock.Lock();
-  monclient.start_mon_command(cmd, inbl, outbl, outs,
-                              new C_SafeCond(&mylock, &cond, &done, &rval));
+  monclient.start_mon_command(cmd, inbl, outbl, outs, on_finish);
   lock.Unlock();
-  mylock.Lock();
-  while (!done)
-    cond.Wait(mylock);
-  mylock.Unlock();
-  return rval;
 }
 
-
 int librados::RadosClient::mgr_command(const vector<string>& cmd,
                                       const bufferlist &inbl,
                                       bufferlist *outbl, string *outs)
@@ -1001,7 +1007,9 @@ void librados::RadosClient::handle_log(MLog *m)
                 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(), who.c_str(), name.c_str(),
+         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());
       }
@@ -1012,3 +1020,56 @@ 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<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);
+}
+
+mon_feature_t librados::RadosClient::get_required_monitor_features() const
+{
+  return monclient.monmap.get_required_features();
+}