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()) {
}
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)) {
};
}
-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);
/**
* 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);