#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())
<< 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;
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);
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);
}
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;
+}
+
+}