#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)
<< "(" << 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();
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");
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());
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;
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());
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()) {
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;
}
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.
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;
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;