]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add key[=value] ... to osd pool create 578/head
authorLoic Dachary <loic@dachary.org>
Mon, 9 Sep 2013 11:23:42 +0000 (13:23 +0200)
committerLoic Dachary <loic@dachary.org>
Tue, 10 Sep 2013 11:53:57 +0000 (13:53 +0200)
With the introduction of the erasure code pool, arguments to be
interpreted depending on the pool type must be introduced.
For instance the erasure code pool loads a plugin at run time will
use easure-code-k=10 to split each object in 10.

The arguments are described as

  name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]

If key=value it is stored in the new properties data member of pg_pool_t
as properties[key] = value, otherwise the value is the empty string.

The pg_pool_t version is bumped to 10 and the encode/decode methods
modified to take the properties into account. The
generate_test_instances method creates a two entries map, one of which
is the empty string to cover the case when no value is specified.

http://tracker.ceph.com/issues/6113 refs #6113

Signed-off-by: Loic Dachary <loic@dachary.org>
src/mon/MonCommands.h
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h
src/osd/osd_types.cc
src/osd/osd_types.h

index 28fa80e00b798989fd1d8cc63d211c2a09533563..2949f863888ff6c9c3b30df17252f33244fd7c20 100644 (file)
@@ -479,7 +479,8 @@ COMMAND("osd pool rmsnap " \
 COMMAND("osd pool create " \
        "name=pool,type=CephPoolname " \
        "name=pg_num,type=CephInt,range=0 " \
-       "name=pgp_num,type=CephInt,range=0,req=false", \
+       "name=pgp_num,type=CephInt,range=0,req=false" \
+       "name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]", \
        "create pool", "osd", "rw", "cli,rest")
 COMMAND("osd pool delete " \
        "name=pool,type=CephPoolname " \
index 5450532e46d1f8eb3b6f001dbca84005a4d38d0c..8eb88a829b1ea9be6a9e4696c910ef4b010c4af2 100644 (file)
@@ -2473,10 +2473,11 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
   MonSession *session = m->get_session();
   if (!session)
     return -EPERM;
+  vector<string> properties;
   if (m->auid)
-    return prepare_new_pool(m->name, m->auid, m->crush_rule, 0, 0);
+    return prepare_new_pool(m->name, m->auid, m->crush_rule, 0, 0, properties);
   else
-    return prepare_new_pool(m->name, session->auid, m->crush_rule, 0, 0);
+    return prepare_new_pool(m->name, session->auid, m->crush_rule, 0, 0, properties);
 }
 
 /**
@@ -2485,11 +2486,13 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
  * @param crush_rule The crush rule to use. If <0, will use the system default
  * @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 properties An opaque list of key[=value] pairs for pool configuration
  *
  * @return 0 in all cases. That's silly.
  */
 int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_rule,
-                                 unsigned pg_num, unsigned pgp_num)
+                                 unsigned pg_num, unsigned pgp_num,
+                                const vector<string> &properties)
 {
   for (map<int64_t,string>::iterator p = pending_inc.new_pool_names.begin();
        p != pending_inc.new_pool_names.end();
@@ -2519,6 +2522,18 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_rule,
   pi->set_pgp_num(pgp_num ? pgp_num : g_conf->osd_pool_default_pgp_num);
   pi->last_change = pending_inc.epoch;
   pi->auid = auid;
+  for (vector<string>::const_iterator i = properties.begin();
+       i != properties.end();
+       i++) {
+    size_t equal = i->find('=');
+    if (equal != string::npos)
+      pi->properties[*i] = string();
+    else {
+      const string key = i->substr(0, equal);
+      const string value = i->substr(equal);
+      pi->properties[key] = value;
+    }
+  }
   pending_inc.new_pool_names[pool] = name;
   return 0;
 }
@@ -3480,9 +3495,13 @@ done:
       goto reply;
     }
 
+    vector<string> properties;
+    cmd_getval(g_ceph_context, cmdmap, "properties", properties);
+
     err = prepare_new_pool(poolstr, 0, // auid=0 for admin created pool
                           -1,         // default crush rule
-                          pg_num, pgp_num);
+                          pg_num, pgp_num,
+                          properties);
     if (err < 0 && err != -EEXIST) {
       goto reply;
     }
index 04f7cf5b1963db07b7cefc5166e9f3010da98ab0..304f9c4f609f0a68fe03f15d41e33150b4fb80f8 100644 (file)
@@ -235,7 +235,8 @@ private:
   bool prepare_pool_op_create (MPoolOp *m);
   bool prepare_pool_op_delete(MPoolOp *m);
   int prepare_new_pool(string& name, uint64_t auid, int crush_rule,
-                       unsigned pg_num, unsigned pgp_num);
+                       unsigned pg_num, unsigned pgp_num,
+                      const vector<string> &properties);
   int prepare_new_pool(MPoolOp *m);
 
   void update_pool_flags(int64_t pool_id, uint64_t flags);
index 3451d520ff2805b2f1726bfd0b40c84aef5ac931..34ae75b12b9e08fff83abd67e14cefe9193b8d3e 100644 (file)
@@ -649,6 +649,14 @@ void pg_pool_t::dump(Formatter *f) const
   f->dump_int("read_tier", read_tier);
   f->dump_int("write_tier", write_tier);
   f->dump_string("cache_mode", get_cache_mode_name());
+  f->open_array_section("properties");
+  for (map<string,string>::const_iterator i = properties.begin();
+       i != properties.end();
+       ++i) {
+    string name = i->first;
+    f->dump_string(name.c_str(), i->second);
+  }
+  f->close_section();
 }
 
 
@@ -853,7 +861,7 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const
     return;
   }
 
-  ENCODE_START(9, 5, bl);
+  ENCODE_START(10, 5, bl);
   ::encode(type, bl);
   ::encode(size, bl);
   ::encode(crush_ruleset, bl);
@@ -880,6 +888,7 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const
   ::encode(c, bl);
   ::encode(read_tier, bl);
   ::encode(write_tier, bl);
+  ::encode(properties, bl);
   ENCODE_FINISH(bl);
 }
 
@@ -947,6 +956,9 @@ void pg_pool_t::decode(bufferlist::iterator& bl)
     ::decode(read_tier, bl);
     ::decode(write_tier, bl);
   }
+  if (struct_v >= 10) {
+    ::decode(properties, bl);
+  }
   DECODE_FINISH(bl);
   calc_pg_masks();
 }
@@ -988,6 +1000,8 @@ void pg_pool_t::generate_test_instances(list<pg_pool_t*>& o)
   a.cache_mode = CACHEMODE_WRITEBACK;
   a.read_tier = 1;
   a.write_tier = 1;
+  a.properties["p-1"] = "v-1";
+  a.properties["empty"] = string();
   o.push_back(new pg_pool_t(a));
 }
 
index da139b853b16e567e87b6d93fcd3e3884772e39e..91ab89a63afdec1939030685ac81565d5ff2dc53 100644 (file)
@@ -778,6 +778,7 @@ private:
 
 
 public:
+  map<string,string> properties;  /// interpreted according to the pool type
   epoch_t last_change;      /// most recent epoch changed, exclusing snapshot changes
   snapid_t snap_seq;        /// seq for per-pool snapshot
   epoch_t snap_epoch;       /// osdmap epoch of last snap