]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: osd create pool must fail on incompatible type
authorLoic Dachary <loic@dachary.org>
Sat, 21 Dec 2013 14:49:19 +0000 (15:49 +0100)
committerLoic Dachary <loic@dachary.org>
Sun, 22 Dec 2013 22:43:50 +0000 (23:43 +0100)
When osd create pool is called twice on the same pool, it will succeed
because the pool already exists. However, if a different type is
specified, it must fail.

Signed-off-by: Loic Dachary <loic@dachary.org>
qa/workunits/cephtool/test.sh
src/mon/OSDMonitor.cc
src/osd/osd_types.h

index ee525cb674941bcb1abc621fc668a4012e32d3a2..d0c36fb9259fc9d41851bde50814ca353f56649f 100755 (executable)
@@ -275,13 +275,13 @@ ceph osd pool create erasurecodes 12 12 erasure
 ceph osd pool create erasurecodes 12 12 erasure
 # should fail because the default type is replicated and 
 # the pool is of type erasure
-#expect_false ceph osd pool create erasurecodes 12 12
+expect_false ceph osd pool create erasurecodes 12 12
 ceph osd pool create replicated 12 12 replicated
 ceph osd pool create replicated 12 12 replicated
 ceph osd pool create replicated 12 12 # default is replicated
 ceph osd pool create replicated 12    # default is replicated, pgp_num = pg_num
 # should fail because the type is not the same
-expect_false ceph osd pool create replicated 12 12 erasure
+expect_false ceph osd pool create replicated 12 12 erasure
 ceph osd lspools | grep erasurecodes
 ceph osd lspools | grep replicated
 ceph osd pool delete erasurecodes erasurecodes --yes-i-really-really-mean-it
index 1bd7a5e78f1e11538b82745dc95f0cff717815a1..0dc36f7c8ae1833fad3c5620535562c426e6ddcb 100644 (file)
@@ -3941,21 +3941,31 @@ done:
       goto reply;
     }
 
+    string pool_type_str;
+    cmd_getval(g_ceph_context, cmdmap, "pool_type", pool_type_str);
+    if (pool_type_str.empty())
+      pool_type_str = pg_pool_t::get_default_type();
+
     string poolstr;
     cmd_getval(g_ceph_context, cmdmap, "pool", poolstr);
-    if (osdmap.name_pool.count(poolstr)) {
-      ss << "pool '" << poolstr << "' already exists";
-      err = 0;
+    int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr);
+    if (pool_id >= 0) {
+      const pg_pool_t *p = osdmap.get_pg_pool(pool_id);
+      if (pool_type_str != p->get_type_name()) {
+       ss << "pool '" << poolstr << "' cannot change to type " << pool_type_str;
+       err = -EINVAL;
+      } else {
+       ss << "pool '" << poolstr << "' already exists";
+       err = 0;
+      }
       goto reply;
     }
 
     vector<string> properties;
     cmd_getval(g_ceph_context, cmdmap, "properties", properties);
 
-    string pool_type_str;
-    cmd_getval(g_ceph_context, cmdmap, "pool_type", pool_type_str);
     int pool_type;
-    if (pool_type_str.empty() || pool_type_str == "replicated") {
+    if (pool_type_str == "replicated") {
       pool_type = pg_pool_t::TYPE_REPLICATED;
     } else if (pool_type_str == "erasure") {
 
index f224e6d864fbfe557196ab3e25b45dbca3d82a96..e72c94ca5ccffb4de1892d7fb4f7be750d1fe878 100644 (file)
@@ -712,6 +712,9 @@ struct pg_pool_t {
   const char *get_type_name() const {
     return get_type_name(type);
   }
+  static const char* get_default_type() {
+    return "replicated";
+  }
 
   enum {
     FLAG_HASHPSPOOL = 1, // hash pg seed and pool together (instead of adding)