]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: when take place the crush map should consider the rule is in used 8384/head
authorsongbaisen <song.baisen@zte.com.cn>
Thu, 31 Mar 2016 03:39:44 +0000 (11:39 +0800)
committersongbaisen <song.baisen@zte.com.cn>
Tue, 5 Apr 2016 02:36:58 +0000 (10:36 +0800)
Signed-off-by: song baisen song.baisen@zte.com.cn
src/mon/OSDMonitor.cc
src/test/mon/osd-crush.sh

index 5908ca4c6a83229d69608c8f31838498ecbff644..706b5749ed177e2a0800383f3caf1b1e1bd612e2 100644 (file)
@@ -5289,8 +5289,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
   // This should be used as a general guideline for most commands handled
   // in this function.  Adapt as you see fit, but please bear in mind that
   // this is the expected behavior.
-
-
+   
   if (prefix == "osd setcrushmap" ||
       (prefix == "osd crush set" && !osdid_present)) {
     dout(10) << "prepare_command setting new crush map" << dendl;
@@ -5310,6 +5310,21 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
       err = -EINVAL;
       goto reply;
     }
+    
+    if (prefix == "osd setcrushmap") {
+      const map<int64_t,pg_pool_t> &osdmap_pools = osdmap.get_pools();
+      map<int64_t,pg_pool_t>::const_iterator pit;
+      for (pit = osdmap_pools.begin(); pit != osdmap_pools.end(); ++pit) {
+        const int64_t pool_id = pit->first;
+        const pg_pool_t &pool = pit->second;
+        int ruleno = pool.get_crush_ruleset();
+        if (!crush.rule_exists(ruleno)) {
+          ss << " the crush rule no "<< ruleno << " for pool id " << pool_id << " is in use";
+          err = -EINVAL;
+          goto reply;
+        }
+      }
+    }
 
     // sanity check: test some inputs to make sure this map isn't totally broken
     dout(10) << " testing map" << dendl;
index 4dbbd0442d919c664d61d4e53123c19cfb1f9851..5fc69b6fe52de82b1ecd05e4ea8d893d04fded27 100755 (executable)
@@ -258,8 +258,17 @@ function TEST_crush_repair_faulty_crushmap() {
 
     local crushtool_path_old=`ceph-conf --show-config-value crushtool`
     ceph tell mon.\* injectargs --crushtool "true"
+    
+    
+    #import empty crushmap should failture.because the default pool rbd use the rule
+    ceph osd setcrushmap -i $empty_map.map  2>&1|grep "Error EINVAL:  the crush rule no"|| return 1
 
+    #remove the default pool rbd
+    ceph osd pool delete rbd rbd --yes-i-really-really-mean-it || return 1
+
+    #now it can be successful to set the empty crush map
     ceph osd setcrushmap -i $empty_map.map || return 1
+
     # should be an empty crush map without any buckets
     ! test $(ceph osd crush dump --format=xml | \
            $XMLSTARLET sel -t -m "//buckets/bucket" -v .) || return 1