Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jewel: mon: osd crush set crushmap need sanity check #16144

Merged
merged 2 commits into from Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/mon/OSDMonitor.cc
Expand Up @@ -5514,8 +5514,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
// This should be used as a general guideline for most commands handled
// in this function. Adapt as you see fit, but please bear in mind that
// this is the expected behavior.


if (prefix == "osd setcrushmap" ||
(prefix == "osd crush set" && !osdid_present)) {
dout(10) << "prepare_command setting new crush map" << dendl;
Expand All @@ -5535,6 +5535,19 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
err = -EINVAL;
goto reply;
}

const map<int64_t,pg_pool_t> &osdmap_pools = osdmap.get_pools();
map<int64_t,pg_pool_t>::const_iterator pit;
for (pit = osdmap_pools.begin(); pit != osdmap_pools.end(); ++pit) {
const int64_t pool_id = pit->first;
const pg_pool_t &pool = pit->second;
int ruleno = pool.get_crush_ruleset();
if (!crush.rule_exists(ruleno)) {
ss << " the crush rule no "<< ruleno << " for pool id " << pool_id << " is in use";
err = -EINVAL;
goto reply;
}
}

// sanity check: test some inputs to make sure this map isn't totally broken
dout(10) << " testing map" << dendl;
Expand Down
9 changes: 9 additions & 0 deletions src/test/mon/osd-crush.sh
Expand Up @@ -258,8 +258,17 @@ function TEST_crush_repair_faulty_crushmap() {

local crushtool_path_old=`ceph-conf --show-config-value crushtool`
ceph tell mon.\* injectargs --crushtool "true"


#import empty crushmap should failture.because the default pool rbd use the rule
ceph osd setcrushmap -i $empty_map.map 2>&1|grep "Error EINVAL: the crush rule no"|| return 1

#remove the default pool rbd
ceph osd pool delete rbd rbd --yes-i-really-really-mean-it || return 1

#now it can be successful to set the empty crush map
ceph osd setcrushmap -i $empty_map.map || return 1

# should be an empty crush map without any buckets
! test $(ceph osd crush dump --format=xml | \
$XMLSTARLET sel -t -m "//buckets/bucket" -v .) || return 1
Expand Down