]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushTester: check if any item id is too large
authorKefu Chai <kchai@redhat.com>
Tue, 26 May 2015 07:34:33 +0000 (15:34 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 31 May 2015 17:24:54 +0000 (01:24 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crush/CrushTester.cc
src/crush/CrushTester.h

index 9a37ca51c1e725d5a07c6f68d53aa8ed8d559def..47d094ad860728f4731aeb764f688be303b5bc2a 100644 (file)
@@ -395,9 +395,10 @@ namespace {
   class CrushWalker : public CrushTreeDumper::Dumper<void> {
     typedef void DumbFormatter;
     typedef CrushTreeDumper::Dumper<DumbFormatter> Parent;
+    unsigned max_id;
   public:
-    CrushWalker(const CrushWrapper *crush)
-      : Parent(crush) {}
+    CrushWalker(const CrushWrapper *crush, unsigned max_id)
+      : Parent(crush), max_id(max_id) {}
     void dump_item(const CrushTreeDumper::Item &qi, DumbFormatter *) {
       int type = -1;
       if (qi.is_bucket()) {
@@ -406,6 +407,9 @@ namespace {
        }
        type = crush->get_bucket_type(qi.id);
       } else {
+       if (max_id > 0 && qi.id >= max_id) {
+         throw BadCrushMap("item id too large", qi.id);
+       }
        type = 0;
       }
       if (!crush->get_type_name(type)) {
@@ -415,9 +419,9 @@ namespace {
   };
 }
 
-bool CrushTester::check_name_maps() const
+bool CrushTester::check_name_maps(unsigned max_id) const
 {
-  CrushWalker crush_walker(&crush);
+  CrushWalker crush_walker(&crush, max_id);
   try {
     // walk through the crush, to see if its self-contained
     crush_walker.dump(NULL);
index 271ff2a2f3292843807ae1afd9558b4cf930ce3d..4522fdfdca9daa6c94d011434a15754dbbd94cb9 100644 (file)
@@ -335,9 +335,12 @@ public:
 
   /**
    * check if any bucket/nodes is referencing an unknown name or type
-   * @return false if an dangling name/type is referenced, true otherwise
+   * @param max_id rejects any non-bucket items with id less than this number,
+   *               pass 0 to disable this check
+   * @return false if an dangling name/type is referenced or an item id is too
+   *         large, true otherwise
    */
-  bool check_name_maps() const;
+  bool check_name_maps(unsigned max_id = 0) const;
   int test();
   int test_with_crushtool(const char *crushtool_cmd = "crushtool",
                          int timeout = 0);