From f041bbebf98a2aff2ad542e8d0c12c46af427573 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 26 May 2015 15:34:33 +0800 Subject: [PATCH] crush/CrushTester: check if any item id is too large Signed-off-by: Kefu Chai (cherry picked from commit e640d89240017956b8c7411babb86be0f1e2b172) --- src/crush/CrushTester.cc | 12 ++++++++---- src/crush/CrushTester.h | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/crush/CrushTester.cc b/src/crush/CrushTester.cc index 85ba693aa4bf4..2b60c22d40914 100644 --- a/src/crush/CrushTester.cc +++ b/src/crush/CrushTester.cc @@ -445,9 +445,10 @@ namespace { class CrushWalker : public CrushTreeDumper::Dumper { typedef void DumbFormatter; typedef CrushTreeDumper::Dumper 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); diff --git a/src/crush/CrushTester.h b/src/crush/CrushTester.h index cc7c7825d1421..22424757f6ed6 100644 --- a/src/crush/CrushTester.h +++ b/src/crush/CrushTester.h @@ -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); -- 2.39.5