]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/mon/ConfigKeyService.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / mon / ConfigKeyService.cc
index 6d23ff6bac93413c24859bedaff9b418cabca835..38a22d16496e5a37e68ac7d5e11389d644704a14 100644 (file)
@@ -23,6 +23,7 @@
 #include "common/errno.h"
 #include "include/stringify.h"
 
+#include "include/ceph_assert.h" // re-clobber ceph_assert()
 #define dout_subsys ceph_subsys_mon
 #undef dout_prefix
 #define dout_prefix _prefix(_dout, mon, this)
@@ -33,22 +34,22 @@ static ostream& _prefix(std::ostream *_dout, const Monitor *mon,
                 << "(" << service->get_epoch() << ") ";
 }
 
-const string ConfigKeyService::STORE_PREFIX = "mon_config_key";
+const string CONFIG_PREFIX = "mon_config_key";
 
 int ConfigKeyService::store_get(const string &key, bufferlist &bl)
 {
-  return mon->store->get(STORE_PREFIX, key, bl);
+  return mon->store->get(CONFIG_PREFIX, key, bl);
 }
 
-void ConfigKeyService::get_store_prefixes(set<string>& s)
+void ConfigKeyService::get_store_prefixes(set<string>& s) const
 {
-  s.insert(STORE_PREFIX);
+  s.insert(CONFIG_PREFIX);
 }
 
 void ConfigKeyService::store_put(const string &key, bufferlist &bl, Context *cb)
 {
   MonitorDBStore::TransactionRef t = paxos->get_pending_transaction();
-  t->put(STORE_PREFIX, key, bl);
+  t->put(CONFIG_PREFIX, key, bl);
   if (cb)
     paxos->queue_pending_finisher(cb);
   paxos->trigger_propose();
@@ -67,18 +68,18 @@ void ConfigKeyService::store_delete(
     MonitorDBStore::TransactionRef t,
     const string &key)
 {
-  t->erase(STORE_PREFIX, key);
+  t->erase(CONFIG_PREFIX, key);
 }
 
 bool ConfigKeyService::store_exists(const string &key)
 {
-  return mon->store->exists(STORE_PREFIX, key);
+  return mon->store->exists(CONFIG_PREFIX, key);
 }
 
 void ConfigKeyService::store_list(stringstream &ss)
 {
   KeyValueDB::Iterator iter =
-    mon->store->get_iterator(STORE_PREFIX);
+    mon->store->get_iterator(CONFIG_PREFIX);
 
   JSONFormatter f(true);
   f.open_array_section("keys");
@@ -95,7 +96,7 @@ void ConfigKeyService::store_list(stringstream &ss)
 bool ConfigKeyService::store_has_prefix(const string &prefix)
 {
   KeyValueDB::Iterator iter =
-    mon->store->get_iterator(STORE_PREFIX);
+    mon->store->get_iterator(CONFIG_PREFIX);
 
   while (iter->valid()) {
     string key(iter->key());
@@ -119,15 +120,24 @@ static bool is_binary_string(const string& s)
   return false;
 }
 
-void ConfigKeyService::store_dump(stringstream &ss)
+void ConfigKeyService::store_dump(stringstream &ss, const string& prefix)
 {
   KeyValueDB::Iterator iter =
-    mon->store->get_iterator(STORE_PREFIX);
+    mon->store->get_iterator(CONFIG_PREFIX);
+
+  dout(10) << __func__ << " prefix '" << prefix << "'" << dendl;
+  if (prefix.size()) {
+    iter->lower_bound(prefix);
+  }
 
   JSONFormatter f(true);
   f.open_object_section("config-key store");
 
   while (iter->valid()) {
+    if (prefix.size() &&
+       iter->key().find(prefix) != 0) {
+      break;
+    }
     string s = iter->value().to_str();
     if (is_binary_string(s)) {
       ostringstream ss;
@@ -147,7 +157,7 @@ void ConfigKeyService::store_delete_prefix(
     const string &prefix)
 {
   KeyValueDB::Iterator iter =
-    mon->store->get_iterator(STORE_PREFIX);
+    mon->store->get_iterator(CONFIG_PREFIX);
 
   while (iter->valid()) {
     string key(iter->key());
@@ -163,7 +173,7 @@ void ConfigKeyService::store_delete_prefix(
 bool ConfigKeyService::service_dispatch(MonOpRequestRef op)
 {
   Message *m = op->get_req();
-  assert(m != NULL);
+  ceph_assert(m != NULL);
   dout(10) << __func__ << " " << *m << dendl;
 
   if (!in_quorum()) {
@@ -172,31 +182,31 @@ bool ConfigKeyService::service_dispatch(MonOpRequestRef op)
     return false;
   }
 
-  assert(m->get_type() == MSG_MON_COMMAND);
+  ceph_assert(m->get_type() == MSG_MON_COMMAND);
 
   MMonCommand *cmd = static_cast<MMonCommand*>(m);
 
-  assert(!cmd->cmd.empty());
+  ceph_assert(!cmd->cmd.empty());
 
   int ret = 0;
   stringstream ss;
   bufferlist rdata;
 
   string prefix;
-  map<string, cmd_vartype> cmdmap;
+  cmdmap_t cmdmap;
 
   if (!cmdmap_from_json(cmd->cmd, &cmdmap, ss)) {
     return false;
   }
 
-  cmd_getval_throws(g_ceph_context, cmdmap, "prefix", prefix);
+  cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
   string key;
-  cmd_getval_throws(g_ceph_context, cmdmap, "key", key);
+  cmd_getval(g_ceph_context, cmdmap, "key", key);
 
   if (prefix == "config-key get") {
     ret = store_get(key, rdata);
     if (ret < 0) {
-      assert(!rdata.length());
+      ceph_assert(!rdata.length());
       ss << "error obtaining '" << key << "': " << cpp_strerror(ret);
       goto out;
     }
@@ -212,22 +222,36 @@ bool ConfigKeyService::service_dispatch(MonOpRequestRef op)
 
     bufferlist data;
     string val;
-    if (cmd_getval_throws(g_ceph_context, cmdmap, "val", val)) {
+    if (cmd_getval(g_ceph_context, cmdmap, "val", val)) {
       // they specified a value in the command instead of a file
       data.append(val);
     } else if (cmd->get_data_len() > 0) {
       // they specified '-i <file>'
       data = cmd->get_data();
     }
-    if (data.length() > (size_t) g_conf->mon_config_key_max_entry_size) {
+    if (data.length() > (size_t) g_conf()->mon_config_key_max_entry_size) {
       ret = -EFBIG; // File too large
       ss << "error: entry size limited to "
-         << g_conf->mon_config_key_max_entry_size << " bytes. "
+         << g_conf()->mon_config_key_max_entry_size << " bytes. "
          << "Use 'mon config key max entry size' to manually adjust";
       goto out;
     }
-    // we'll reply to the message once the proposal has been handled
+
+    std::string mgr_prefix = "mgr/";
+    if (key.size() >= mgr_prefix.size() &&
+        key.substr(0, mgr_prefix.size()) == mgr_prefix) {
+      // In <= mimic, we used config-key for mgr module configuration,
+      // and we bring values forward in an upgrade, but subsequent
+      // `set` operations will not be picked up.  Warn user about this.
+      ss << "WARNING: it looks like you might be trying to set a ceph-mgr "
+            "module configuration key.  Since Ceph 13.0.0 (Mimic), mgr module "
+            "configuration is done with `config set`, and new values "
+            "set using `config-key set` will be ignored.\n";
+    }
+
     ss << "set " << key;
+
+    // we'll reply to the message once the proposal has been handled
     store_put(key, data,
              new Monitor::C_Command(mon, op, 0, ss.str(), 0));
     // return for now; we'll put the message once it's done.
@@ -268,8 +292,10 @@ bool ConfigKeyService::service_dispatch(MonOpRequestRef op)
     ret = 0;
 
   } else if (prefix == "config-key dump") {
+    string prefix;
+    cmd_getval(g_ceph_context, cmdmap, "key", prefix);
     stringstream tmp_ss;
-    store_dump(tmp_ss);
+    store_dump(tmp_ss, prefix);
     rdata.append(tmp_ss);
     ret = 0;
 
@@ -349,7 +375,7 @@ void ConfigKeyService::do_osd_new(
     const uuid_d& uuid,
     const string& dmcrypt_key)
 {
-  assert(paxos->is_plugged());
+  ceph_assert(paxos->is_plugged());
 
   string dmcrypt_key_prefix = _get_dmcrypt_prefix(uuid, "luks");
   bufferlist dmcrypt_key_value;