Merge pull request #4807 from dachary/wip-11814-erasure-code-ruleset

mon: validate implicit erasure code crush ruleset

Reviewed-by: Takeshi Miyamae <miyamae.takeshi@jp.fujitsu.com>
Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2015-07-17 18:25:42 +08:00
commit ab4fa2a3e6
3 changed files with 21 additions and 0 deletions

View File

@ -53,6 +53,7 @@ int ErasureCodeShec::create_ruleset(const string &name,
if (ruleid < 0) {
return ruleid;
} else {
crush.set_rule_mask_max_size(ruleid, get_chunk_count());
return crush.get_rule_mask_ruleset(ruleid);
}
}

View File

@ -4266,6 +4266,7 @@ int OSDMonitor::prepare_pool_crush_ruleset(const unsigned pool_type,
int *crush_ruleset,
ostream *ss)
{
if (*crush_ruleset < 0) {
switch (pool_type) {
case pg_pool_t::TYPE_REPLICATED:
@ -4394,6 +4395,14 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid,
crush_ruleset_name, &crush_ruleset, ss);
if (r)
return r;
CrushWrapper newcrush;
_get_pending_crush(newcrush);
CrushTester tester(newcrush, *ss);
r = tester.test_with_crushtool(g_conf->crushtool.c_str(),
osdmap.get_max_osd(),
g_conf->mon_lease);
if (r)
return r;
unsigned size, min_size;
r = prepare_pool_size(pool_type, erasure_code_profile, &size, &min_size, ss);
if (r)

View File

@ -86,6 +86,8 @@ function TEST_crush_rule_create_erasure() {
local dir=$1
run_mon $dir a || return 1
# should have at least one OSD
run_osd $dir 0 || return 1
local ruleset=ruleset3
#
@ -117,6 +119,15 @@ function TEST_crush_rule_create_erasure() {
./ceph osd erasure-code-profile ls | grep default || return 1
./ceph osd crush rule rm $ruleset || return 1
! ./ceph osd crush rule ls | grep $ruleset || return 1
#
# create a bugous ruleset and verify it cannot be used
# to create a pool.
#
ceph osd erasure-code-profile set myprofile plugin=lrc mapping=__DD__DD layers='[[ "_cDD_cDD", "" ],[ "cDDD____", "" ],[ "____cDDD", "" ],]' ruleset-steps='[ [ "choose", "datacenter", 3 ], [ "chooseleaf", "osd", 0] ]'
expect_failure $dir "Error EINVAL" \
./ceph osd pool create mypool 1 1 erasure myprofile || return 1
./ceph osd crush rule rm mypool || return 1
./ceph osd erasure-code-profile rm myprofile || return 1
}
function check_ruleset_id_match_rule_id() {