Skip to content

Commit

Permalink
mon: add crush ruleset name to osd pool create
Browse files Browse the repository at this point in the history
The ruleset to be used for the new erasure coded pool was expected in
the properties, under the name crush_ruleset. It does not belong to the
erasure code profile and needs to be added to the prototype explicitly.

The crush ruleset name is added to the prototype of the prepare_new_pool
and prepare_pool_crush_ruleset methods.

Signed-off-by: Loic Dachary <[email protected]>
  • Loading branch information
Loic Dachary committed Mar 17, 2014
1 parent 4f1b372 commit 5774344
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/mon/MonCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ COMMAND("osd pool create " \
"name=pgp_num,type=CephInt,range=0,req=false " \
"name=pool_type,type=CephChoices,strings=replicated|erasure,req=false " \
"name=erasure_code_profile,type=CephString,req=false,goodchars=[A-Za-z0-9-_.=] " \
"name=ruleset,type=CephString,req=false,goodchars=[A-Za-z0-9-_.=]", \
"create pool", "osd", "rw", "cli,rest")
COMMAND("osd pool delete " \
"name=pool,type=CephPoolname " \
Expand Down
38 changes: 20 additions & 18 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2848,14 +2848,17 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
return -EPERM;
string erasure_code_profile;
stringstream ss;
string ruleset_name;
if (m->auid)
return prepare_new_pool(m->name, m->auid, m->crush_rule, 0, 0,
properties, pg_pool_t::TYPE_REPLICATED, ss);
return prepare_new_pool(m->name, m->auid, m->crush_rule, ruleset_name,
0, 0,
erasure_code_profile,
pg_pool_t::TYPE_REPLICATED, ss);
else
return prepare_new_pool(m->name, session->auid, m->crush_rule, 0, 0,
properties, pg_pool_t::TYPE_REPLICATED, ss);
return prepare_new_pool(m->name, session->auid, m->crush_rule, ruleset_name,
0, 0,
erasure_code_profile,
pg_pool_t::TYPE_REPLICATED, ss);
}

int OSDMonitor::crush_ruleset_create_erasure(const string &name,
Expand Down Expand Up @@ -3062,6 +3065,7 @@ int OSDMonitor::prepare_pool_stripe_width(const unsigned pool_type,
int OSDMonitor::prepare_pool_crush_ruleset(const string &poolstr,
const unsigned pool_type,
const string &erasure_code_profile,
const string &ruleset_name,
int *crush_ruleset,
stringstream &ss)
{
Expand All @@ -3073,23 +3077,13 @@ int OSDMonitor::prepare_pool_crush_ruleset(const string &poolstr,
break;
case pg_pool_t::TYPE_ERASURE:
{
string ruleset;
map<string,string>::const_iterator i = properties.find("crush_ruleset");
if (i == properties.end()) {
dout(1) << "prepare_pool_crush_ruleset: implicitly use ruleset "
<< "named after the pool: " << poolstr << dendl;
ruleset = poolstr;
} else {
ruleset = i->second;
}

int err = crush_ruleset_create_erasure(ruleset_name,
erasure_code_profile,
crush_ruleset, ss);
switch (err) {
case -EALREADY:
dout(20) << "prepare_pool_crush_ruleset: ruleset "
<< ruleset << " try again" << dendl;
<< ruleset_name << " try again" << dendl;
case 0:
// need to wait for the crush rule to be proposed before proceeding
err = -EAGAIN;
Expand All @@ -3114,7 +3108,8 @@ int OSDMonitor::prepare_pool_crush_ruleset(const string &poolstr,
/**
* @param name The name of the new pool
* @param auid The auid of the pool owner. Can be -1
* @param crush_rule The crush rule to use. If <0, will use the system default
* @param crush_ruleset The crush rule to use. If <0, will use the system default
* @param crush_ruleset_name The crush rule to use, if crush_rulset <0
* @param pg_num The pg_num to use. If set to 0, will use the system default
* @param pgp_num The pgp_num to use. If set to 0, will use the system default
* @param erasure_code_profile The profile name in OSDMap to be used for erasure code
Expand All @@ -3123,14 +3118,17 @@ int OSDMonitor::prepare_pool_crush_ruleset(const string &poolstr,
*
* @return 0 on success, negative errno on failure.
*/
int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
int OSDMonitor::prepare_new_pool(string& name, uint64_t auid,
int crush_ruleset,
const string &crush_ruleset_name,
unsigned pg_num, unsigned pgp_num,
const string &erasure_code_profile,
const unsigned pool_type,
stringstream &ss)
{
int r;
r = prepare_pool_crush_ruleset(pool_type, erasure_code_profile,
crush_ruleset_name, &crush_ruleset, ss);
if (r)
return r;
unsigned size;
Expand Down Expand Up @@ -4567,8 +4565,12 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
goto reply;
}

string ruleset_name;
cmd_getval(g_ceph_context, cmdmap, "ruleset", ruleset_name);

err = prepare_new_pool(poolstr, 0, // auid=0 for admin created pool
-1, // default crush rule
-1, // default crush rule
ruleset_name,
pg_num, pgp_num,
erasure_code_profile, pool_type,
ss);
Expand Down
5 changes: 4 additions & 1 deletion src/mon/OSDMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class OSDMonitor : public PaxosService {
int prepare_pool_crush_ruleset(const string &poolstr,
const unsigned pool_type,
const string &erasure_code_profile,
const string &ruleset_name,
int *crush_ruleset,
stringstream &ss);
bool erasure_code_profile_in_use(const map<int64_t, pg_pool_t> &pools,
Expand All @@ -269,7 +270,9 @@ class OSDMonitor : public PaxosService {
const string &erasure_code_profile,
unsigned *stripe_width,
stringstream &ss);
int prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
int prepare_new_pool(string& name, uint64_t auid,
int crush_ruleset,
const string &crush_ruleset_name,
unsigned pg_num, unsigned pgp_num,
const string &erasure_code_profile,
const unsigned pool_type,
Expand Down
19 changes: 18 additions & 1 deletion src/test/pybind/test_ceph_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,12 +944,29 @@ def test_pool_create(self):
'poolname', '128', '128'])
self.assert_valid_command(['osd', 'pool', 'create',
'poolname', '128', '128',
'whatever'])
'replicated'])
self.assert_valid_command(['osd', 'pool', 'create',
'poolname', '128', '128',
'erasure', 'profile', 'ruleset'])
assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create']))
assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
'poolname']))
assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
'poolname', '-1']))
assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
'poolname',
'128', '128',
'erasure', '!!!']))
assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
'poolname',
'128', '128',
'erasure', 'profile',
'!!!']))
assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
'poolname',
'128', '128',
'INVALID', 'profile',
'ruleset']))

def test_pool_delete(self):
self.assert_valid_command(['osd', 'pool', 'delete',
Expand Down

0 comments on commit 5774344

Please sign in to comment.