]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: check cluster features before rule create-erasure 1180/head
authorLoic Dachary <loic@dachary.org>
Tue, 4 Feb 2014 00:31:52 +0000 (01:31 +0100)
committerLoic Dachary <loic@dachary.org>
Tue, 4 Feb 2014 10:48:26 +0000 (11:48 +0100)
Encapsulate the logic used when creating an erasure coded pool into the
check_cluster_features helper.

check_cluster_features(CEPH_FEATURE_CRUSH_V2) is required for crush rule
create-erasure because it is expected that the erasure code plugin will
use indep instead of firstn and expect the V2 behavior and not the
legacy behavior.

The CEPH_FEATURE_CRUSH_V2 is added to CEPH_FEATURE_OSD_ERASURE_CODES
when an erasure coded pool is created. It is necessary because pool
won't function properly if given an indep ruleset that does not
implement the V2 behavior.

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

index a793e40b4a87dd8b8c28cba647310d4f2fdf6856..1142990af24733f198dd03f3e0a84a02887a46c3 100644 (file)
@@ -2760,6 +2760,37 @@ int OSDMonitor::get_erasure_code(const map<string,string> &properties,
   return instance.factory(plugin->second, properties, erasure_code);
 }
 
+int OSDMonitor::check_cluster_features(uint64_t features,
+                                      stringstream &ss)
+{
+  stringstream unsupported_ss;
+  int unsupported_count = 0;
+  if (!(mon->get_quorum_features() & features)) {
+    unsupported_ss << "the monitor cluster";
+    ++unsupported_count;
+  }
+
+  set<int32_t> up_osds;
+  osdmap.get_up_osds(up_osds);
+  for (set<int32_t>::iterator it = up_osds.begin();
+       it != up_osds.end(); it ++) {
+    const osd_xinfo_t &xi = osdmap.get_xinfo(*it);
+    if (!(xi.features & features)) {
+      if (unsupported_count > 0)
+       unsupported_ss << ", ";
+      unsupported_ss << "osd." << *it;
+      unsupported_count ++;
+    }
+  }
+
+  if (unsupported_count > 0) {
+    ss << "features " << features << " unsupported by: "
+       << unsupported_ss.str();
+    return -ENOTSUP;
+  } else {
+    return 0;
+  }
+}
 
 int OSDMonitor::prepare_pool_properties(const unsigned pool_type,
                                        const vector<string> &properties,
@@ -3646,6 +3677,9 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
     return true;
 
   } else if (prefix == "osd crush rule create-erasure") {
+    err = check_cluster_features(CEPH_FEATURE_CRUSH_V2, ss);
+    if (err)
+      goto reply;
     string name, poolstr;
     cmd_getval(g_ceph_context, cmdmap, "name", name);
     vector<string> properties;
@@ -4154,35 +4188,11 @@ done:
     if (pool_type_str == "replicated") {
       pool_type = pg_pool_t::TYPE_REPLICATED;
     } else if (pool_type_str == "erasure") {
-
-      // make sure all the daemons support erasure coding
-      stringstream ec_unsupported_ss;
-      int ec_unsupported_count = 0;
-      if (!(mon->get_quorum_features() & CEPH_FEATURE_OSD_ERASURE_CODES)) {
-        ec_unsupported_ss << "the monitor cluster";
-        ++ec_unsupported_count;
-      }
-
-      set<int32_t> up_osds;
-      osdmap.get_up_osds(up_osds);
-      for (set<int32_t>::iterator it = up_osds.begin();
-           it != up_osds.end(); it ++) {
-        const osd_xinfo_t &xi = osdmap.get_xinfo(*it);
-        if (!(xi.features & CEPH_FEATURE_OSD_ERASURE_CODES)) {
-          if (ec_unsupported_count > 0)
-            ec_unsupported_ss << ", ";
-          ec_unsupported_ss << "osd." << *it;
-          ec_unsupported_count ++;
-        }
-      }
-
-      if (ec_unsupported_count > 0) {
-        ss << "unable to create erasure pool; unsupported by: "
-           << ec_unsupported_ss.str();
-        err = -ENOTSUP;
-        goto reply;
-      }
-
+      err = check_cluster_features(CEPH_FEATURE_CRUSH_V2 |
+                                  CEPH_FEATURE_OSD_ERASURE_CODES,
+                                  ss);
+      if (err)
+       goto reply;
       pool_type = pg_pool_t::TYPE_ERASURE;
     } else {
       ss << "unknown pool type '" << pool_type_str << "'";
index a490d37e5c5a3e75edd85ee7d7d389856235d2ae..e2eadc62a489acb6ba29ce5a2df188b2ba5896a4 100644 (file)
@@ -182,6 +182,7 @@ private:
   void encode_trim_extra(MonitorDBStore::Transaction *tx, version_t first);
 
   void update_msgr_features();
+  int check_cluster_features(uint64_t features, stringstream &ss);
 
   void share_map_with_random_osd();