Skip to content

Commit

Permalink
mon: OSDMonitor use erasure_code_profile instead of properties
Browse files Browse the repository at this point in the history
The prepare_pool_properties is replaced with the
parse_erasure_code_profile method which looks up the same content from
OSDMap::erasure_code_profiles instead of the argument vector.

The type and name substitution is applied in OSDMonitor and the
MonCommand prototypes for osd pool create and osd create-erasure are
updated.

The behavior is not modified.

Signed-off-by: Loic Dachary <[email protected]>
  • Loading branch information
Loic Dachary committed Mar 17, 2014
1 parent 063de51 commit 173e958
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/common/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ OPTION(osd_pool_default_min_size, OPT_INT, 0) // 0 means no specific default; c
OPTION(osd_pool_default_pg_num, OPT_INT, 8) // number of PGs for new pools. Configure in global or mon section of ceph.conf
OPTION(osd_pool_default_pgp_num, OPT_INT, 8) // number of PGs for placement purposes. Should be equal to pg_num
OPTION(osd_pool_default_erasure_code_directory, OPT_STR, CEPH_PKGLIBDIR"/erasure-code") // default for the erasure-code-directory=XXX property of osd pool create
OPTION(osd_pool_default_erasure_code_properties,
OPTION(osd_pool_default_erasure_code_profile,
OPT_STR,
"plugin=jerasure "
"technique=reed_sol_van "
Expand Down
6 changes: 3 additions & 3 deletions src/mon/MonCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ COMMAND("osd crush rule create-simple " \
"osd", "rw", "cli,rest")
COMMAND("osd crush rule create-erasure " \
"name=name,type=CephString,goodchars=[A-Za-z0-9-_.] " \
"name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]", \
"create crush rule <name> suitable for erasure coded pool created with <properties>", \
"name=profile,type=CephString,req=false,goodchars=[A-Za-z0-9-_.=]", \
"create crush rule <name> for erasure coded pool created with <profile> (default default)", \
"osd", "rw", "cli,rest")
COMMAND("osd crush rule rm " \
"name=name,type=CephString,goodchars=[A-Za-z0-9-_.] ", \
Expand Down Expand Up @@ -527,7 +527,7 @@ COMMAND("osd pool create " \
"name=pg_num,type=CephInt,range=0 " \
"name=pgp_num,type=CephInt,range=0,req=false " \
"name=pool_type,type=CephChoices,strings=replicated|erasure,req=false " \
"name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]", \
"name=erasure_code_profile,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
96 changes: 45 additions & 51 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2846,18 +2846,20 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
MonSession *session = m->get_session();
if (!session)
return -EPERM;
vector<string> properties;
string erasure_code_profile;
stringstream ss;
if (m->auid)
return prepare_new_pool(m->name, m->auid, m->crush_rule, 0, 0,
properties, pg_pool_t::TYPE_REPLICATED, ss);
erasure_code_profile,
else
return prepare_new_pool(m->name, session->auid, m->crush_rule, 0, 0,
properties, pg_pool_t::TYPE_REPLICATED, ss);
erasure_code_profile,
}

int OSDMonitor::crush_ruleset_create_erasure(const string &name,
const map<string,string> &properties,
const string &profile,
int *ruleset,
stringstream &ss)
{
Expand All @@ -2873,9 +2875,9 @@ int OSDMonitor::crush_ruleset_create_erasure(const string &name,
return -EALREADY;
} else {
ErasureCodeInterfaceRef erasure_code;
int err = get_erasure_code(properties, &erasure_code, ss);
int err = get_erasure_code(profile, &erasure_code, ss);
if (err) {
ss << "failed to load plugin using properties " << properties;
ss << "failed to load plugin using profile " << profile;
return err;
}

Expand All @@ -2890,16 +2892,20 @@ int OSDMonitor::crush_ruleset_create_erasure(const string &name,
}
}

int OSDMonitor::get_erasure_code(const map<string,string> &properties,
int OSDMonitor::get_erasure_code(const string &erasure_code_profile,
ErasureCodeInterfaceRef *erasure_code,
stringstream &ss)
{
if (pending_inc.has_erasure_code_profile(erasure_code_profile))
return -EAGAIN;
const map<string,string> &profile =
osdmap.get_erasure_code_profile(erasure_code_profile);
map<string,string>::const_iterator plugin =
profile.find("plugin");
if (plugin == profile.end()) {
ss << "cannot determine the erasure code plugin"
<< " because erasure-code-plugin is not in the properties "
<< properties;
<< " because there is no 'plugin' entry in the erasure_code_profile "
<< profile;
return -EINVAL;
}
ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
Expand Down Expand Up @@ -2973,35 +2979,33 @@ int OSDMonitor::parse_erasure_code_profile(const vector<string> &erasure_code_pr
map<string,string> *erasure_code_profile_map,
stringstream &ss)
{
if (pool_type == pg_pool_t::TYPE_ERASURE) {
int r = get_str_map(g_conf->osd_pool_default_erasure_code_properties,
ss,
properties_map);
if (r)
return r;
(*properties_map)["erasure-code-directory"] =
g_conf->osd_pool_default_erasure_code_directory;
}

for (vector<string>::const_iterator i = properties.begin();
i != properties.end();
int r = get_str_map(g_conf->osd_pool_default_erasure_code_profile,
ss,
erasure_code_profile_map);
if (r)
return r;
(*erasure_code_profile_map)["directory"] =
g_conf->osd_pool_default_erasure_code_directory;

for (vector<string>::const_iterator i = erasure_code_profile.begin();
i != erasure_code_profile.end();
++i) {
size_t equal = i->find('=');
if (equal == string::npos)
(*properties_map)[*i] = string();
(*erasure_code_profile_map)[*i] = string();
else {
const string key = i->substr(0, equal);
equal++;
const string value = i->substr(equal);
(*properties_map)[key] = value;
(*erasure_code_profile_map)[key] = value;
}
}

return 0;
}

int OSDMonitor::prepare_pool_size(const unsigned pool_type,
const map<string,string> &properties,
const string &erasure_code_profile,
unsigned *size,
stringstream &ss)
{
Expand All @@ -3013,7 +3017,7 @@ int OSDMonitor::prepare_pool_size(const unsigned pool_type,
case pg_pool_t::TYPE_ERASURE:
{
ErasureCodeInterfaceRef erasure_code;
err = get_erasure_code(properties, &erasure_code, ss);
err = get_erasure_code(erasure_code_profile, &erasure_code, ss);
if (err == 0)
*size = erasure_code->get_chunk_count();
}
Expand All @@ -3027,7 +3031,7 @@ int OSDMonitor::prepare_pool_size(const unsigned pool_type,
}

int OSDMonitor::prepare_pool_stripe_width(const unsigned pool_type,
const map<string,string> &properties,
const string &erasure_code_profile,
uint32_t *stripe_width,
stringstream &ss)
{
Expand All @@ -3039,7 +3043,7 @@ int OSDMonitor::prepare_pool_stripe_width(const unsigned pool_type,
case pg_pool_t::TYPE_ERASURE:
{
ErasureCodeInterfaceRef erasure_code;
err = get_erasure_code(properties, &erasure_code, ss);
err = get_erasure_code(erasure_code_profile, &erasure_code, ss);
uint32_t desired_stripe_width = g_conf->osd_pool_erasure_code_stripe_width;
if (err == 0)
*stripe_width = erasure_code->get_data_chunk_count() *
Expand All @@ -3057,7 +3061,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 map<string,string> &properties,
const string &erasure_code_profile,
int *crush_ruleset,
stringstream &ss)
{
Expand All @@ -3079,7 +3083,8 @@ int OSDMonitor::prepare_pool_crush_ruleset(const string &poolstr,
ruleset = i->second;
}

int err = crush_ruleset_create_erasure(ruleset, properties,
int err = crush_ruleset_create_erasure(ruleset_name,
erasure_code_profile,
crush_ruleset, ss);
switch (err) {
case -EALREADY:
Expand Down Expand Up @@ -3112,32 +3117,28 @@ int OSDMonitor::prepare_pool_crush_ruleset(const string &poolstr,
* @param crush_rule The crush rule to use. If <0, will use the system default
* @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 properties An opaque list of key[=value] pairs for pool configuration
* @param erasure_code_profile The profile name in OSDMap to be used for erasure code
* @param pool_type TYPE_ERASURE, TYPE_REP or TYPE_RAID4
* @param ss human readable error message, if any.
*
* @return 0 on success, negative errno on failure.
*/
int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
unsigned pg_num, unsigned pgp_num,
const vector<string> &properties,
const string &erasure_code_profile,
const unsigned pool_type,
stringstream &ss)
{
map<string,string> properties_map;
int r = prepare_pool_properties(pool_type, properties, &properties_map, ss);
if (r)
return r;
r = prepare_pool_crush_ruleset(name, pool_type, properties_map,
&crush_ruleset, ss);
int r;
r = prepare_pool_crush_ruleset(pool_type, erasure_code_profile,
if (r)
return r;
unsigned size;
r = prepare_pool_size(pool_type, properties_map, &size, ss);
r = prepare_pool_size(pool_type, erasure_code_profile, &size, ss);
if (r)
return r;
uint32_t stripe_width = 0;
r = prepare_pool_stripe_width(pool_type, properties_map, &stripe_width, ss);
r = prepare_pool_stripe_width(pool_type, erasure_code_profile, &stripe_width, ss);
if (r)
return r;

Expand Down Expand Up @@ -3166,7 +3167,7 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
pi->set_pgp_num(pgp_num ? pgp_num : g_conf->osd_pool_default_pgp_num);
pi->last_change = pending_inc.epoch;
pi->auid = auid;
pi->properties = properties_map;
pi->erasure_code_profile = erasure_code_profile;
pi->stripe_width = stripe_width;
pi->cache_target_dirty_ratio_micro =
g_conf->osd_pool_default_cache_target_dirty_ratio * 1000000;
Expand Down Expand Up @@ -4028,17 +4029,13 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
goto reply;
string name, poolstr;
cmd_getval(g_ceph_context, cmdmap, "name", name);
vector<string> properties;
cmd_getval(g_ceph_context, cmdmap, "properties", properties);

map<string,string> properties_map;
err = prepare_pool_properties(pg_pool_t::TYPE_ERASURE,
properties, &properties_map, ss);
if (err)
goto reply;
string profile;
cmd_getval(g_ceph_context, cmdmap, "profile", profile);
if (profile == "")
profile = "default";

int ruleset;
err = crush_ruleset_create_erasure(name, properties_map, &ruleset, ss);
err = crush_ruleset_create_erasure(name, profile, &ruleset, ss);
if (err < 0) {
switch(err) {
case -EEXIST: // return immediately
Expand Down Expand Up @@ -4552,9 +4549,6 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
goto reply;
}

vector<string> properties;
cmd_getval(g_ceph_context, cmdmap, "properties", properties);

int pool_type;
if (pool_type_str == "replicated") {
pool_type = pg_pool_t::TYPE_REPLICATED;
Expand All @@ -4576,7 +4570,7 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
err = prepare_new_pool(poolstr, 0, // auid=0 for admin created pool
-1, // default crush rule
pg_num, pgp_num,
properties, pool_type,
erasure_code_profile, pool_type,
ss);
if (err < 0) {
switch(err) {
Expand Down
16 changes: 6 additions & 10 deletions src/mon/OSDMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,15 @@ class OSDMonitor : public PaxosService {
bool prepare_pool_op_create (MPoolOp *m);
bool prepare_pool_op_delete(MPoolOp *m);
int crush_ruleset_create_erasure(const string &name,
const map<string,string> &properties,
const string &profile,
int *ruleset,
stringstream &ss);
int get_erasure_code(const map<string,string> &properties,
int get_erasure_code(const string &erasure_code_profile,
ErasureCodeInterfaceRef *erasure_code,
stringstream &ss);
int prepare_pool_properties(const unsigned pool_type,
const vector<string> &properties,
map<string,string> *properties_map,
stringstream &ss);
int prepare_pool_crush_ruleset(const string &poolstr,
const unsigned pool_type,
const map<string,string> &properties,
const string &erasure_code_profile,
int *crush_ruleset,
stringstream &ss);
bool erasure_code_profile_in_use(const map<int64_t, pg_pool_t> &pools,
Expand All @@ -266,16 +262,16 @@ class OSDMonitor : public PaxosService {
map<string,string> *erasure_code_profile_map,
stringstream &ss);
int prepare_pool_size(const unsigned pool_type,
const map<string,string> &properties,
const string &erasure_code_profile,
unsigned *size,
stringstream &ss);
int prepare_pool_stripe_width(const unsigned pool_type,
const map<string,string> &properties,
const string &erasure_code_profile,
unsigned *stripe_width,
stringstream &ss);
int prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
unsigned pg_num, unsigned pgp_num,
const vector<string> &properties,
const string &erasure_code_profile,
const unsigned pool_type,
stringstream &ss);
int prepare_new_pool(MPoolOp *m);
Expand Down
8 changes: 8 additions & 0 deletions src/test/pybind/test_ceph_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,18 @@ def test_crush_rule_create_simple(self):
'toomany']))

def test_crush_rule_create_erasure(self):
self.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
'AZaz09-_.'])
self.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
'AZaz09-_.', 'whatever'])
assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
'create-erasure']))
assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
'create-erasure',
'!!!']))
assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
'create-erasure',
'name', '!!!']))

def test_crush_rule_rm(self):
self.assert_valid_command(['osd', 'crush', 'rule', 'rm', 'AZaz09-_.'])
Expand Down

0 comments on commit 173e958

Please sign in to comment.