From 8fba03fe42a4981cb40c58c5f8b8c6f7524f6178 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Tue, 21 Nov 2023 15:39:23 -0800 Subject: [PATCH] mon/OSDMonitor: generalize rule type check for pools Add rule_valid_for_pool_type to CrushWrapper to generalize rule type <-> pool type mapping to include the new MSR types. Signed-off-by: Samuel Just --- src/crush/CrushWrapper.h | 14 ++++++++++++++ src/mon/OSDMonitor.cc | 6 +++--- src/osd/OSDMap.cc | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index f71f6d6ea79b6..77f70d10049e6 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -602,6 +602,20 @@ public: if (have_rmaps) rule_name_rmap[name] = i; } + bool rule_valid_for_pool_type(int rule_id, int ptype) const { + auto rule_type = get_rule_type(rule_id); + switch (ptype) { + case CEPH_PG_TYPE_REPLICATED: + return rule_type == CRUSH_RULE_TYPE_REPLICATED || + rule_type == CRUSH_RULE_TYPE_MSR_FIRSTN; + case CEPH_PG_TYPE_ERASURE: + return rule_type == CRUSH_RULE_TYPE_ERASURE || + rule_type == CRUSH_RULE_TYPE_MSR_INDEP; + default: + ceph_abort_msg("impossible"); + } + } + bool is_shadow_item(int id) const { const char *name = get_item_name(id); return name && !is_valid_crush_name(name); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index f8e379326f25f..5e5cd0bfbebca 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -8072,7 +8072,7 @@ int OSDMonitor::prepare_new_pool(string& name, return r; } - if (osdmap.crush->get_rule_type(crush_rule) != (int)pool_type) { + if (!osdmap.crush->rule_valid_for_pool_type(crush_rule, pool_type)) { *ss << "crush rule " << crush_rule << " type does not match pool"; return -EINVAL; } @@ -8344,7 +8344,7 @@ int OSDMonitor::prepare_command_pool_set(const cmdmap_t& cmdmap, return -EPERM; } } - if (osdmap.crush->get_rule_type(p.get_crush_rule()) != (int)p.type) { + if (!osdmap.crush->rule_valid_for_pool_type(p.get_crush_rule(), p.type)) { ss << "crush rule " << p.get_crush_rule() << " type does not match pool"; return -EINVAL; } @@ -8577,7 +8577,7 @@ int OSDMonitor::prepare_command_pool_set(const cmdmap_t& cmdmap, ss << cpp_strerror(id); return -ENOENT; } - if (osdmap.crush->get_rule_type(id) != (int)p.get_type()) { + if (!osdmap.crush->rule_valid_for_pool_type(id, p.get_type())) { ss << "crush rule " << id << " type does not match pool"; return -EINVAL; } diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index a6dd32c554d3c..9853a0c8b2df8 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -4530,7 +4530,7 @@ int OSDMap::validate_crush_rules(CrushWrapper *newcrush, << " but it is not present"; return -EINVAL; } - if (newcrush->get_rule_type(ruleno) != (int)pool.get_type()) { + if (!newcrush->rule_valid_for_pool_type(ruleno, pool.get_type())) { *ss << "pool " << i.first << " type does not match rule " << ruleno; return -EINVAL; } -- 2.39.5