From: Loic Dachary Date: Sat, 21 Dec 2013 14:49:19 +0000 (+0100) Subject: mon: osd create pool must fail on incompatible type X-Git-Tag: v0.75~48^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=df0d038d7b7b4783bc9d3ce1e4d49afc4c89714e;p=ceph.git mon: osd create pool must fail on incompatible type 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 --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index ee525cb67494..d0c36fb9259f 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -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 diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 1bd7a5e78f1e..0dc36f7c8ae1 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -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 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") { diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index f224e6d864fb..e72c94ca5ccf 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -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)