]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/crush/CrushLocation.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / crush / CrushLocation.cc
index 2032bf71c98fe316c5e54b8a57f484310b4f49a9..c53769aa1bd0056f070d8a41ff4508df2230bf9f 100644 (file)
@@ -9,12 +9,15 @@
 #include "include/str_list.h"
 #include "common/debug.h"
 #include "common/errno.h"
+#include "include/common_fwd.h"
 #include "include/compat.h"
 
 #include "common/SubProcess.h"
 
 #include <vector>
 
+namespace TOPNSPC::crush {
+
 int CrushLocation::update_from_conf()
 {
   if (cct->_conf->crush_location.length())
@@ -34,7 +37,7 @@ int CrushLocation::_parse(const std::string& s)
               << loc << dendl;
     return -EINVAL;
   }
-  std::lock_guard<std::mutex> l(lock);
+  std::lock_guard l(lock);
   loc.swap(new_crush_location);
   lgeneric_dout(cct, 10) << "crush_location is " << loc << dendl;
   return 0;
@@ -67,13 +70,13 @@ int CrushLocation::update_from_hook()
     return ret;
   }
 
-  bufferlist bl;
+  ceph::buffer::list bl;
   ret = bl.read_fd(hook.get_stdout(), 100 * 1024);
   if (ret < 0) {
     lderr(cct) << "error: failed read stdout from "
               << cct->_conf->crush_location_hook
               << ": " << cpp_strerror(-ret) << dendl;
-    bufferlist err;
+    ceph::buffer::list err;
     err.read_fd(hook.get_stderr(), 100 * 1024);
     lderr(cct) << "stderr:\n";
     err.hexdump(*_dout);
@@ -89,7 +92,7 @@ int CrushLocation::update_from_hook()
     return ret;
 
   std::string out;
-  bl.copy(0, bl.length(), out);
+  bl.begin().copy(bl.length(), out);
   out.erase(out.find_last_not_of(" \n\r\t")+1);
   return _parse(out);
 }
@@ -115,10 +118,32 @@ int CrushLocation::init_on_startup()
       break;
     }
   }
-  std::lock_guard<std::mutex> l(lock);
+  std::lock_guard l(lock);
   loc.clear();
-  loc.insert(make_pair<std::string,std::string>("host", hostname));
-  loc.insert(make_pair<std::string,std::string>("root", "default"));
+  loc.insert(std::make_pair<std::string,std::string>("host", hostname));
+  loc.insert(std::make_pair<std::string,std::string>("root", "default"));
   lgeneric_dout(cct, 10) << "crush_location is (default) " << loc << dendl;
   return 0;
 }
+
+std::multimap<std::string,std::string> CrushLocation::get_location() const
+{
+  std::lock_guard l(lock);
+  return loc;
+}
+
+std::ostream& operator<<(std::ostream& os, const CrushLocation& loc)
+{
+  bool first = true;
+  for (auto& [type, pos] : loc.get_location()) {
+    if (first) {
+      first = false;
+    } else {
+      os << ", ";
+    }
+    os << '"' << type << '=' << pos << '"';
+  }
+  return os;
+}
+
+}