// with default
-template <typename T>
-bool cmd_getval(
- const cmdmap_t& cmdmap, std::string_view k,
- T& val, const T& defval)
+template <typename T, typename V>
+T cmd_getval_or(const cmdmap_t& cmdmap, std::string_view k,
+ const V& defval)
{
auto found = cmdmap.find(k);
if (found == cmdmap.end()) {
- val = defval;
- return true;
+ return T(defval);
}
try {
- val = boost::get<T>(cmdmap.find(k)->second);
- return true;
+ return boost::get<T>(cmdmap.find(k)->second);
} catch (boost::bad_get&) {
throw bad_cmd_get(k, cmdmap);
}
if (boost::algorithm::ends_with(prefix, "_json")) {
format = "json";
} else {
- cmd_getval(cmdctx->cmdmap, "format", format, string("plain"));
+ format = cmd_getval_or<string>(cmdctx->cmdmap, "format", "plain");
}
f.reset(Formatter::create(format));
}
bool dry_run =
prefix == "osd test-reweight-by-pg" ||
prefix == "osd test-reweight-by-utilization";
- int64_t oload;
- cmd_getval(cmdctx->cmdmap, "oload", oload, int64_t(120));
+ int64_t oload = cmd_getval_or<int64_t>(cmdctx->cmdmap, "oload", 120);
set<int64_t> pools;
vector<string> poolnames;
cmd_getval(cmdctx->cmdmap, "pools", poolnames);
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
if (prefix == "auth export") {
cmd_getval(cmdmap, "prefix", prefix);
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
MonSession *session = op->get_session();
mon.reply_command(op, -EINVAL, rs, get_last_committed());
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
string prefix;
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
string prefix;
mon.reply_command(op, -EINVAL, rs, get_last_committed());
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
string prefix;
string prefix;
cmd_getval(cmdmap, "prefix", prefix);
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
if (prefix == "log last") {
if (prefix == "log") {
vector<string> logtext;
- string level_str;
cmd_getval(cmdmap, "logtext", logtext);
LogEntry le;
le.rank = m->get_orig_source();
le.name = session->entity_name;
le.stamp = m->get_recv_stamp();
le.seq = 0;
- cmd_getval(cmdmap, "level", level_str, string("info"));
+ string level_str = cmd_getval_or<string>(cmdmap, "level", "info");
le.prio = LogEntry::str_to_level(level_str);
le.channel = CLOG_CHANNEL_DEFAULT;
le.msg = str_join(logtext, " ");
string prefix;
cmd_getval(cmdmap, "prefix", prefix);
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
std::unique_ptr<Formatter> f(Formatter::create(format));
MonSession *session = op->get_session();
f->close_section();
f->flush(rdata);
} else if (prefix == "mgr dump") {
- int64_t epoch = 0;
- cmd_getval(cmdmap, "epoch", epoch, (int64_t)map.get_epoch());
+ int64_t epoch = cmd_getval_or<int64_t>(cmdmap, "epoch", map.get_epoch());
if (epoch == (int64_t)map.get_epoch()) {
f->dump_object("mgrmap", map);
} else {
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
string prefix;
dout(0) << "handle_command " << *m << dendl;
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
get_str_vec(prefix, fullcmd);
return true;
}
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
if (prefix == "mon stat") {
prefix == "mon dump") {
epoch_t epoch;
- int64_t epochnum;
- cmd_getval(cmdmap, "epoch", epochnum, (int64_t)0);
+ int64_t epochnum = cmd_getval_or<int64_t>(cmdmap, "epoch", 0);
epoch = epochnum;
MonMap *p = mon.monmap;
string prefix;
cmd_getval(cmdmap, "prefix", prefix);
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
if (prefix == "osd stat") {
prefix == "osd ls-tree" ||
prefix == "osd info") {
- epoch_t epoch = 0;
- int64_t epochnum;
- cmd_getval(cmdmap, "epoch", epochnum, (int64_t)osdmap.get_epoch());
- epoch = epochnum;
-
+ epoch_t epoch = cmd_getval_or<int64_t>(cmdmap, "epoch", osdmap.get_epoch());
bufferlist osdmap_bl;
int err = get_version_full(epoch, osdmap_bl);
if (err == -ENOENT) {
bufferlist rdata;
int err = 0;
- string format;
- cmd_getval(cmdmap, "format", format, string("plain"));
+ string format = cmd_getval_or<string>(cmdmap, "format", "plain");
boost::scoped_ptr<Formatter> f(Formatter::create(format));
string prefix;
}
if (blocklistop == "add") {
utime_t expires = ceph_clock_now();
- double d;
// default one hour
- cmd_getval(cmdmap, "expire", d,
+ double d = cmd_getval_or<double>(cmdmap, "expire",
g_conf()->mon_osd_blocklist_default_expire);
expires += d;
get_last_committed() + 1));
return true;
} else if (prefix == "osd pool create") {
- int64_t pg_num, pg_num_min;
- int64_t pgp_num;
- cmd_getval(cmdmap, "pg_num", pg_num, int64_t(0));
- cmd_getval(cmdmap, "pgp_num", pgp_num, pg_num);
- cmd_getval(cmdmap, "pg_num_min", pg_num_min, int64_t(0));
-
+ int64_t pg_num = cmd_getval_or<int64_t>(cmdmap, "pg_num", 0);
+ int64_t pg_num_min = cmd_getval_or<int64_t>(cmdmap, "pg_num_min", 0);
+ int64_t pgp_num = cmd_getval_or<int64_t>(cmdmap, "pgp_num", pg_num);
string pool_type_str;
cmd_getval(cmdmap, "pool_type", pool_type_str);
if (pool_type_str.empty())
rule_name = poolstr;
}
}
- cmd_getval(cmdmap, "expected_num_objects",
- expected_num_objects, int64_t(0));
+ expected_num_objects =
+ cmd_getval_or<int64_t>(cmdmap, "expected_num_objects", 0);
} else {
//NOTE:for replicated pool,cmd_map will put rule_name to erasure_code_profile field
// and put expected_num_objects to rule field
}
rule_name = erasure_code_profile;
} else { // cmd is well-formed
- cmd_getval(cmdmap, "expected_num_objects",
- expected_num_objects, int64_t(0));
+ expected_num_objects =
+ cmd_getval_or<int64_t>(cmdmap, "expected_num_objects", 0);
}
}
}
}
- int64_t fast_read_param;
- cmd_getval(cmdmap, "fast_read", fast_read_param, int64_t(-1));
+ int64_t fast_read_param = cmd_getval_or<int64_t>(cmdmap, "fast_read", -1);
FastReadType fast_read = FAST_READ_DEFAULT;
if (fast_read_param == 0)
fast_read = FAST_READ_OFF;
using ceph::fixed_u_to_string;
using TOPNSPC::common::cmd_getval;
+using TOPNSPC::common::cmd_getval_or;
MEMPOOL_DEFINE_OBJECT_FACTORY(PGMapDigest, pgmap_digest, pgmap);
MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap, pgmap, pgmap);
cmd_getval(cmdmap, "stuckops", stuckop_vec);
if (stuckop_vec.empty())
stuckop_vec.push_back("unclean");
- int64_t threshold;
- cmd_getval(cmdmap, "threshold", threshold,
- g_conf().get_val<int64_t>("mon_pg_stuck_threshold"));
+ const int64_t threshold = cmd_getval_or<int64_t>(
+ cmdmap, "threshold",
+ g_conf().get_val<int64_t>("mon_pg_stuck_threshold"));
if (pg_map.dump_stuck_pg_stats(ds, f, (int)threshold, stuckop_vec) < 0) {
*ss << "failed";
}
if (prefix == "pg debug") {
- string debugop;
- cmd_getval(cmdmap, "debugop", debugop,
- string("unfound_objects_exist"));
+ const string debugop = cmd_getval_or<string>(
+ cmdmap, "debugop",
+ "unfound_objects_exist");
if (debugop == "unfound_objects_exist") {
bool unfound_objects_exist = false;
for (const auto& p : pg_map.pg_stat) {
using namespace ceph::osd::scheduler;
using TOPNSPC::common::cmd_getval;
+using TOPNSPC::common::cmd_getval_or;
static ostream& _prefix(std::ostream* _dout, int whoami, epoch_t epoch) {
return *_dout << "osd." << whoami << " " << epoch << " ";
}
else if (prefix == "bench") {
- int64_t count;
- int64_t bsize;
- int64_t osize, onum;
// default count 1G, size 4MB
- cmd_getval(cmdmap, "count", count, (int64_t)1 << 30);
- cmd_getval(cmdmap, "size", bsize, (int64_t)4 << 20);
- cmd_getval(cmdmap, "object_size", osize, (int64_t)0);
- cmd_getval(cmdmap, "object_num", onum, (int64_t)0);
-
+ int64_t count = cmd_getval_or<int64_t>(cmdmap, "count", 1LL << 30);
+ int64_t bsize = cmd_getval_or<int64_t>(cmdmap, "size", 4LL << 20);
+ int64_t osize = cmd_getval_or<int64_t>(cmdmap, "object_size", 0);
+ int64_t onum = cmd_getval_or<int64_t>(cmdmap, "object_num", 0);
uint32_t duration = cct->_conf->osd_bench_duration;
if (bsize > (int64_t) cct->_conf->osd_bench_max_block_size) {
return;
}
- int64_t shardid;
- cmd_getval(cmdmap, "shardid", shardid, int64_t(shard_id_t::NO_SHARD));
+ int64_t shardid = cmd_getval_or<int64_t>(cmdmap, "shardid", shard_id_t::NO_SHARD);
hobject_t obj(object_t(objname), string(""), CEPH_NOSNAP, rawpg.ps(), pool, nspace);
ghobject_t gobj(obj, ghobject_t::NO_GEN, shard_id_t(uint8_t(shardid)));
spg_t pgid(curmap->raw_pg_to_pg(rawpg), shard_id_t(shardid));
return;
}
if (command == "set_recovery_delay") {
- int64_t delay;
- cmd_getval(cmdmap, "utime", delay, (int64_t)0);
+ int64_t delay = cmd_getval_or<int64_t>(cmdmap, "utime", 0);
ostringstream oss;
oss << delay;
int r = service->cct->_conf.set_val("osd_recovery_delay_start",
return;
}
if (command == "injectfull") {
- int64_t count;
- string type;
+ int64_t count = cmd_getval_or<int64_t>(cmdmap, "count", -1);
+ string type = cmd_getval_or<string>(cmdmap, "type", "full");
OSDService::s_names state;
- cmd_getval(cmdmap, "type", type, string("full"));
- cmd_getval(cmdmap, "count", count, (int64_t)-1);
+
if (type == "none" || count == 0) {
type = "none";
count = 0;
using namespace ceph::osd::scheduler;
using TOPNSPC::common::cmd_getval;
+using TOPNSPC::common::cmd_getval_or;
template <typename T>
static ostream& _prefix(std::ostream *_dout, T *pg) {
else if (prefix == "scrub" ||
prefix == "deep_scrub") {
bool deep = (prefix == "deep_scrub");
- int64_t time;
- cmd_getval(cmdmap, "time", time, (int64_t)0);
+ int64_t time = cmd_getval_or<int64_t>(cmdmap, "time", 0);
if (is_primary()) {
const pg_pool_t *p = &pool.info;