From 780b0c120580c9258584900e39d7658573928994 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 5 Feb 2020 16:54:00 -0600 Subject: [PATCH] mon/OSDMonitor: accept 'autoscale_mode' argument to 'osd pool create' Allow the autoscale mode to be set atomically with pool creation. Fixes: https://tracker.ceph.com/issues/42638 Signed-off-by: Sage Weil --- qa/workunits/cephtool/test.sh | 10 ++++++++++ src/mon/MonCommands.h | 1 + src/mon/OSDMonitor.cc | 12 +++++++++++- src/mon/OSDMonitor.h | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 4828e198f23..9a3a98b8dca 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -1945,6 +1945,16 @@ function test_mon_osd_pool() ceph osd crush rule rm foo ceph osd erasure-code-profile rm foo + # autoscale mode + ceph osd pool create modeon --autoscale-mode=on + ceph osd dump | grep modeon | grep 'autoscale_mode on' + ceph osd pool create modewarn --autoscale-mode=warn + ceph osd dump | grep modewarn | grep 'autoscale_mode warn' + ceph osd pool create modeoff --autoscale-mode=off + ceph osd dump | grep modeoff | grep 'autoscale_mode off' + ceph osd pool delete modeon modeon --yes-i-really-really-mean-it + ceph osd pool delete modewarn modewarn --yes-i-really-really-mean-it + ceph osd pool delete modeoff modeoff --yes-i-really-really-mean-it } function test_mon_osd_pool_quota() diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index b0525333989..4f2ffa93240 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -999,6 +999,7 @@ COMMAND("osd pool create " "name=expected_num_objects,type=CephInt,range=0,req=false " "name=size,type=CephInt,range=0,req=false " "name=pg_num_min,type=CephInt,range=0,req=false " + "name=autoscale_mode,type=CephChoices,strings=on|off|warn,req=false " "name=target_size_bytes,type=CephInt,range=0,req=false " "name=target_size_ratio,type=CephFloat,range=0|1,req=false",\ "create pool", "osd", "rw") diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 25c8fa2bc59..8761d77a9b0 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -7100,7 +7100,8 @@ int OSDMonitor::prepare_new_pool(MonOpRequestRef op) ret = prepare_new_pool(m->name, m->crush_rule, rule_name, 0, 0, 0, 0, 0, 0.0, erasure_code_profile, - pg_pool_t::TYPE_REPLICATED, 0, FAST_READ_OFF, &ss); + pg_pool_t::TYPE_REPLICATED, 0, FAST_READ_OFF, {}, + &ss); if (ret < 0) { dout(10) << __func__ << " got " << ret << " " << ss.str() << dendl; @@ -7632,6 +7633,7 @@ int OSDMonitor::prepare_new_pool(string& name, const unsigned pool_type, const uint64_t expected_num_objects, FastReadType fast_read, + const string& pg_autoscale_mode, ostream *ss) { if (name.length() == 0) @@ -7781,6 +7783,10 @@ int OSDMonitor::prepare_new_pool(string& name, pg_num_min) { pi->opts.set(pool_opts_t::PG_NUM_MIN, static_cast(pg_num_min)); } + if (auto m = pg_pool_t::get_pg_autoscale_mode_by_name( + pg_autoscale_mode); m != pg_pool_t::pg_autoscale_mode_t::UNKNOWN) { + pi->pg_autoscale_mode = m; + } pi->last_change = pending_inc.epoch; pi->auid = 0; @@ -12538,6 +12544,9 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, cmd_getval(cmdmap, "target_size_bytes", target_size_bytes); cmd_getval(cmdmap, "target_size_ratio", target_size_ratio); + string pg_autoscale_mode; + cmd_getval(cmdmap, "autoscale_mode", pg_autoscale_mode); + err = prepare_new_pool(poolstr, -1, // default crush rule rule_name, @@ -12546,6 +12555,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, erasure_code_profile, pool_type, (uint64_t)expected_num_objects, fast_read, + pg_autoscale_mode, &ss); if (err < 0) { switch(err) { diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index 14cf446de02..2b3a47bfc1b 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -531,6 +531,7 @@ private: const unsigned pool_type, const uint64_t expected_num_objects, FastReadType fast_read, + const string& pg_autoscale_mode, ostream *ss); int prepare_new_pool(MonOpRequestRef op); -- 2.39.5