Skip to content

Commit

Permalink
crush/CrushTester: check if any item id is too large
Browse files Browse the repository at this point in the history
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit e640d89)
  • Loading branch information
tchaikov committed Jul 10, 2015
1 parent cc1cc03 commit f041bbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/crush/CrushTester.cc
Expand Up @@ -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()) {
Expand All @@ -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)) {
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/crush/CrushTester.h
Expand Up @@ -335,9 +335,12 @@ class CrushTester {

/**
* 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);
Expand Down

0 comments on commit f041bbe

Please sign in to comment.