<< 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;
break;
}
}
- std::lock_guard<std::mutex> l(lock);
+ std::lock_guard l(lock);
loc.clear();
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;
+}
#ifndef CEPH_CRUSH_LOCATION_H
#define CEPH_CRUSH_LOCATION_H
+#include <iosfwd>
#include <map>
-#include <mutex>
#include <string>
+#include "common/ceph_mutex.h"
+
class CephContext;
class CrushLocation {
- CephContext *cct;
- std::multimap<std::string,std::string> loc;
- std::mutex lock;
-
- int _parse(const std::string& s);
-
public:
explicit CrushLocation(CephContext *c) : cct(c) {
init_on_startup();
int update_from_hook(); ///< call hook, if present
int init_on_startup();
- std::multimap<std::string,std::string> get_location() {
- std::lock_guard<std::mutex> l(lock);
- return loc;
- }
+ std::multimap<std::string,std::string> get_location() const;
+
+private:
+ int _parse(const std::string& s);
+ CephContext *cct;
+ std::multimap<std::string,std::string> loc;
+ mutable ceph::mutex lock = ceph::make_mutex("CrushLocation");
};
+std::ostream& operator<<(std::ostream& os, const CrushLocation& loc);
+
#endif
double(1ull << 40 /* TB */)));
}
- std::multimap<string,string> loc = cct->crush_location.get_location();
- dout(10) << __func__ << " crush location is " << loc << dendl;
+ dout(10) << __func__ << " crush location is " << cct->crush_location << dendl;
string cmd =
string("{\"prefix\": \"osd crush create-or-move\", ") +
- string("\"id\": ") + stringify(whoami) + string(", ") +
- string("\"weight\":") + weight + string(", ") +
- string("\"args\": [");
- for (multimap<string,string>::iterator p = loc.begin(); p != loc.end(); ++p) {
- if (p != loc.begin())
- cmd += ", ";
- cmd += "\"" + p->first + "=" + p->second + "\"";
- }
- cmd += "]}";
-
+ string("\"id\": ") + stringify(whoami) + ", " +
+ string("\"weight\":") + weight + ", " +
+ string("\"args\": [") + stringify(cct->crush_location) + "]}";
return mon_cmd_maybe_osd_create(cmd);
}