]> git.apps.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>
Fri, 10 Jul 2015 07:40:01 +0000 (15:40 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit e640d89240017956b8c7411babb86be0f1e2b172)

src/crush/CrushTester.cc
src/crush/CrushTester.h

index 85ba693aa4bf4249dd72af42d78bc1166230bcc0..2b60c22d40914e39a7bf5c6fc841c62fac1f9e5d 100644 (file)
@@ -445,9 +445,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()) {
@@ -456,6 +457,9 @@ namespace {
        }
        type = crush->get_bucket_type(qi.id);
       } else {
+       if (max_id > 0 && qi.id >= (int)max_id) {
+         throw BadCrushMap("item id too large", qi.id);
+       }
        type = 0;
       }
       if (!crush->get_type_name(type)) {
@@ -465,9 +469,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 cc7c7825d14211b77b5bc578ebd7f4f32d4c97f3..22424757f6ed645d70ece0b1c7a4b998146db2b7 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 string& crushtool,
                          int timeout);