]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add 'size' arg to `osd pool create`
authorSage Weil <sage@redhat.com>
Mon, 26 Nov 2018 20:55:06 +0000 (14:55 -0600)
committerSage Weil <sage@redhat.com>
Tue, 18 Dec 2018 19:30:54 +0000 (13:30 -0600)
Take advantage of keyword arguments to extend
what we can do in a single command during pool creation.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/config.h
src/common/config_proxy.h
src/common/options.cc
src/crimson/common/config_proxy.h
src/mon/MonCommands.h
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h
src/osd/OSDMap.cc

index 0a6ef80372fd153da038ea6715fa3780d9f22df9..49a88f4d3023c11c299d1924686b2a8d932067eb 100644 (file)
@@ -344,9 +344,9 @@ public:
   string data_dir_option;  ///< data_dir config option, if any
 
 public:
-  unsigned get_osd_pool_default_min_size(const ConfigValues& values) const {
-    auto min_size = get_val<uint64_t>(values, "osd_pool_default_min_size");
-    auto size = get_val<uint64_t>(values, "osd_pool_default_size");
+  unsigned get_osd_pool_default_min_size(const ConfigValues& values,
+                                         uint8_t size) const {
+    uint8_t min_size = get_val<uint64_t>(values, "osd_pool_default_min_size");
     return min_size ? std::min(min_size, size) : (size - size / 2);
   }
 
index 70e373f13ba09a22a76e16ad6d3af036bac7023d..174ce4ad3d924398f7ff99aab945d2ee05ff189e 100644 (file)
@@ -101,8 +101,8 @@ public:
     return config.get_val_from_conf_file(values,
                                         sections, key, out, emeta);
   }
-  unsigned get_osd_pool_default_min_size() const {
-    return config.get_osd_pool_default_min_size(values);
+  unsigned get_osd_pool_default_min_size(uint8_t size) const {
+    return config.get_osd_pool_default_min_size(values, size);
   }
   void early_expand_meta(std::string &val,
                         std::ostream *oss) const {
index 0daa306c13b061d7a26275c46427ed1cd7fc9a8f..e97c30b02cf871bdb125dae765a11fbec769a5f9 100644 (file)
@@ -2384,12 +2384,14 @@ std::vector<Option> get_global_options() {
 
     Option("osd_pool_default_size", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
     .set_default(3)
+    .set_min_max(0, 255)
     .set_flag(Option::FLAG_RUNTIME)
     .set_description("the number of copies of an object")
     .add_service("mon"),
 
     Option("osd_pool_default_min_size", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
     .set_default(0)
+    .set_min_max(0, 255)
     .set_flag(Option::FLAG_RUNTIME)
     .set_description("the minimal number of copies allowed to write to a degraded pool")
     .set_long_description("0 means no specific default; ceph will use size-size/2")
index 6a63f30f53bdc6eb75c3660be266e72f35fb203a..f8277a33ee6efc1768e134406edd887c606b2520 100644 (file)
@@ -122,8 +122,8 @@ public:
                                               out, expand_meta);
   }
 
-  unsigned get_osd_pool_default_min_size() const {
-    return get_config().get_osd_pool_default_min_size(*values);
+  unsigned get_osd_pool_default_min_size(uint8_t size) const {
+    return get_config().get_osd_pool_default_min_size(*values, size);
   }
 
   seastar::future<> set_mon_vals(const std::map<std::string,std::string>& kv) {
index 1588528e9d49e0259115d35b7ad3b5dcda83bccf..184a5aed11458502eee7d662baacfa7d605d092a 100644 (file)
@@ -939,7 +939,8 @@ COMMAND("osd pool create " \
         "name=pool_type,type=CephChoices,strings=replicated|erasure,req=false " \
        "name=erasure_code_profile,type=CephString,req=false,goodchars=[A-Za-z0-9-_.] " \
        "name=rule,type=CephString,req=false " \
-        "name=expected_num_objects,type=CephInt,req=false", \
+        "name=expected_num_objects,type=CephInt,req=false " \
+        "name=size,type=CephInt,req=false", \
        "create pool", "osd", "rw")
 COMMAND_WITH_FLAG("osd pool delete " \
        "name=pool,type=CephPoolname " \
index f94aba1937a0003a06f4aa042e1abd104571de59..b9a64849d1bd32030b087aad5445b3bbca7805a2 100644 (file)
@@ -6128,7 +6128,7 @@ int OSDMonitor::prepare_new_pool(MonOpRequestRef op)
   string rule_name;
   int ret = 0;
   ret = prepare_new_pool(m->name, m->crush_rule, rule_name,
-                        0, 0,
+                        0, 0, 0,
                         erasure_code_profile,
                         pg_pool_t::TYPE_REPLICATED, 0, FAST_READ_OFF, &ss);
 
@@ -6441,14 +6441,18 @@ int OSDMonitor::parse_erasure_code_profile(const vector<string> &erasure_code_pr
 
 int OSDMonitor::prepare_pool_size(const unsigned pool_type,
                                  const string &erasure_code_profile,
+                                  uint8_t repl_size,
                                  unsigned *size, unsigned *min_size,
                                  ostream *ss)
 {
   int err = 0;
   switch (pool_type) {
   case pg_pool_t::TYPE_REPLICATED:
-    *size = g_conf().get_val<uint64_t>("osd_pool_default_size");
-    *min_size = g_conf().get_osd_pool_default_min_size();
+    if (repl_size == 0) {
+      repl_size = g_conf().get_val<uint64_t>("osd_pool_default_size");
+    }
+    *size = repl_size;
+    *min_size = g_conf().get_osd_pool_default_min_size(repl_size);
     break;
   case pg_pool_t::TYPE_ERASURE:
     {
@@ -6633,6 +6637,7 @@ int OSDMonitor::check_pg_num(int64_t pool, int pg_num, int size, ostream *ss)
  * @param crush_rule_name The crush rule to use, if crush_rulset <0
  * @param pg_num The pg_num to use. If set to 0, will use the system default
  * @param pgp_num The pgp_num to use. If set to 0, will use the system default
+ * @param repl_size Replication factor, or 0 for default
  * @param erasure_code_profile The profile name in OSDMap to be used for erasure code
  * @param pool_type TYPE_ERASURE, or TYPE_REP
  * @param expected_num_objects expected number of objects on the pool
@@ -6645,6 +6650,7 @@ int OSDMonitor::prepare_new_pool(string& name,
                                 int crush_rule,
                                 const string &crush_rule_name,
                                  unsigned pg_num, unsigned pgp_num,
+                                 const uint64_t repl_size,
                                 const string &erasure_code_profile,
                                  const unsigned pool_type,
                                  const uint64_t expected_num_objects,
@@ -6700,7 +6706,8 @@ int OSDMonitor::prepare_new_pool(string& name,
              << duration << dendl;
   }
   unsigned size, min_size;
-  r = prepare_pool_size(pool_type, erasure_code_profile, &size, &min_size, ss);
+  r = prepare_pool_size(pool_type, erasure_code_profile, repl_size,
+                        &size, &min_size, ss);
   if (r) {
     dout(10) << "prepare_pool_size returns " << r << dendl;
     return r;
@@ -11576,11 +11583,15 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
       fast_read = FAST_READ_OFF;
     else if (fast_read_param > 0)
       fast_read = FAST_READ_ON;
-    
+
+    int64_t repl_size = 0;
+    cmd_getval(cct, cmdmap, "size", repl_size);
+
     err = prepare_new_pool(poolstr,
                           -1, // default crush rule
                           rule_name,
                           pg_num, pgp_num,
+                           repl_size,
                           erasure_code_profile, pool_type,
                            (uint64_t)expected_num_objects,
                            fast_read,
index 03bfab807b159596e730afee12e06391c7975ecd..efb0589d89c6034a8f82a38b6a84381094ca44e4 100644 (file)
@@ -443,6 +443,7 @@ private:
                                 ostream *ss);
   int prepare_pool_size(const unsigned pool_type,
                        const string &erasure_code_profile,
+                        uint8_t repl_size,
                        unsigned *size, unsigned *min_size,
                        ostream *ss);
   int prepare_pool_stripe_width(const unsigned pool_type,
@@ -454,6 +455,7 @@ private:
                       int crush_rule,
                       const string &crush_rule_name,
                        unsigned pg_num, unsigned pgp_num,
+                       uint64_t repl_size,
                       const string &erasure_code_profile,
                        const unsigned pool_type,
                        const uint64_t expected_num_objects,
index 1b51e2cc3ffecfabed917ffb4bab40a7b281a952..26856d2b56abe35c50112c2ae6d4fb7b8dc045e8 100644 (file)
@@ -3849,7 +3849,8 @@ int OSDMap::build_simple_optioned(CephContext *cct, epoch_t e, uuid_d &fsid,
       if (cct->_conf->osd_pool_default_flag_nosizechange)
        pools[pool].set_flag(pg_pool_t::FLAG_NOSIZECHANGE);
       pools[pool].size = cct->_conf.get_val<uint64_t>("osd_pool_default_size");
-      pools[pool].min_size = cct->_conf.get_osd_pool_default_min_size();
+      pools[pool].min_size = cct->_conf.get_osd_pool_default_min_size(
+                                 pools[pool].size);
       pools[pool].crush_rule = default_replicated_rule;
       pools[pool].object_hash = CEPH_STR_HASH_RJENKINS;
       pools[pool].set_pg_num(poolbase << pg_bits);