#include "include/neorados/RADOS.hpp"
#include "include/rbd/features.h"
#include "common/dout.h"
+#include "common/errno.h"
#include "librbd/ImageCtx.h"
#include "librbd/Features.h"
+#include <boost/algorithm/string/predicate.hpp>
#include <bitset>
#include <random>
namespace librbd {
namespace util {
+namespace {
+
+const std::string CONFIG_KEY_URI_PREFIX{"config://"};
+
+} // anonymous namespace
const std::string group_header_name(const std::string &group_id)
{
return ++async_request_seq;
}
+bool is_config_key_uri(const std::string& uri) {
+ return boost::starts_with(uri, CONFIG_KEY_URI_PREFIX);
+}
+
+int get_config_key(librados::Rados& rados, const std::string& uri,
+ std::string* value) {
+ auto cct = reinterpret_cast<CephContext*>(rados.cct());
+
+ if (!is_config_key_uri(uri)) {
+ return -EINVAL;
+ }
+
+ std::string key = uri.substr(CONFIG_KEY_URI_PREFIX.size());
+ std::string cmd =
+ "{"
+ "\"prefix\": \"config-key get\", "
+ "\"key\": \"" + key + "\""
+ "}";
+
+ bufferlist in_bl;
+ bufferlist out_bl;
+ int r = rados.mon_command(cmd, in_bl, &out_bl, nullptr);
+ if (r < 0) {
+ lderr(cct) << "failed to retrieve MON config key " << key << ": "
+ << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ *value = std::string(out_bl.c_str(), out_bl.length());
+ return 0;
+}
+
} // namespace util
} // namespace librbd