]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: add is_v[23]_rule(ruleid) methods
authorSage Weil <sage@redhat.com>
Fri, 15 Aug 2014 15:52:37 +0000 (08:52 -0700)
committerSage Weil <sage@redhat.com>
Fri, 15 Aug 2014 15:55:27 +0000 (08:55 -0700)
Add methods to check if a *specific* rule uses v2 or v3 features.  Refactor
the existing checks to use these.

Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index ca7a47e7f139aeb5aad5c58efc60d58deb9ba3d4..8965f8bf69a0768bbe561088a3199d42ffa00377 100644 (file)
 
 bool CrushWrapper::has_v2_rules() const
 {
-  // check rules for use of indep or new SET_* rule steps
   for (unsigned i=0; i<crush->max_rules; i++) {
-    crush_rule *r = crush->rules[i];
-    if (!r)
-      continue;
-    for (unsigned j=0; j<r->len; j++) {
-      if (r->steps[j].op == CRUSH_RULE_CHOOSE_INDEP ||
-         r->steps[j].op == CRUSH_RULE_CHOOSELEAF_INDEP ||
-         r->steps[j].op == CRUSH_RULE_SET_CHOOSE_TRIES ||
-         r->steps[j].op == CRUSH_RULE_SET_CHOOSELEAF_TRIES)
-       return true;
+    if (is_v2_rule(i)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+bool CrushWrapper::is_v2_rule(unsigned ruleid) const
+{
+  // check rule for use of indep or new SET_* rule steps
+  if (ruleid >= crush->max_rules)
+    return false;
+  crush_rule *r = crush->rules[ruleid];
+  if (!r)
+    return false;
+  for (unsigned j=0; j<r->len; j++) {
+    if (r->steps[j].op == CRUSH_RULE_CHOOSE_INDEP ||
+       r->steps[j].op == CRUSH_RULE_CHOOSELEAF_INDEP ||
+       r->steps[j].op == CRUSH_RULE_SET_CHOOSE_TRIES ||
+       r->steps[j].op == CRUSH_RULE_SET_CHOOSELEAF_TRIES) {
+      return true;
     }
   }
   return false;
@@ -28,14 +39,25 @@ bool CrushWrapper::has_v2_rules() const
 
 bool CrushWrapper::has_v3_rules() const
 {
-  // check rules for use of SET_CHOOSELEAF_VARY_R step
   for (unsigned i=0; i<crush->max_rules; i++) {
-    crush_rule *r = crush->rules[i];
-    if (!r)
-      continue;
-    for (unsigned j=0; j<r->len; j++) {
-      if (r->steps[j].op == CRUSH_RULE_SET_CHOOSELEAF_VARY_R)
-       return true;
+    if (is_v3_rule(i)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+bool CrushWrapper::is_v3_rule(unsigned ruleid) const
+{
+  // check rule for use of SET_CHOOSELEAF_VARY_R step
+  if (ruleid >= crush->max_rules)
+    return false;
+  crush_rule *r = crush->rules[ruleid];
+  if (!r)
+    return false;
+  for (unsigned j=0; j<r->len; j++) {
+    if (r->steps[j].op == CRUSH_RULE_SET_CHOOSELEAF_VARY_R) {
+      return true;
     }
   }
   return false;
index 1b5e830fd501d4c36a09ea31c184105350d200de..d6e4fa43c6db90bfd45df95e98bf19d542577108 100644 (file)
@@ -216,6 +216,8 @@ public:
   bool has_v2_rules() const;
   bool has_v3_rules() const;
 
+  bool is_v2_rule(unsigned ruleid) const;
+  bool is_v3_rule(unsigned ruleid) const;
 
   // bucket types
   int get_num_type_names() const {