mon: create crush_ruleset_create_erasure helper

Move the code bloc verbatim, from "osd crush rule create-erasure" to the
new crush_ruleset_create_erasure() method helper. This step helps
separate the code changes from the code moving around unmodified.

Signed-off-by: Loic Dachary <loic@dachary.org>
This commit is contained in:
Loic Dachary 2014-03-03 14:36:50 +01:00
parent bf7f773b46
commit 6a16eac7fe
2 changed files with 42 additions and 31 deletions

View File

@ -2807,6 +2807,44 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
properties, pg_pool_t::TYPE_REPLICATED, ss);
}
int OSDMonitor::crush_ruleset_create_erasure(const string &name,
const map<string,string> &properties,
int *ruleset,
stringstream &ss)
{
if (osdmap.crush->rule_exists(name)) {
ss << "rule " << name << " already exists";
err = 0;
goto reply;
}
CrushWrapper newcrush;
_get_pending_crush(newcrush);
if (newcrush.rule_exists(name)) {
ss << "rule " << name << " already exists";
err = 0;
} else {
ErasureCodeInterfaceRef erasure_code;
err = get_erasure_code(properties_map, &erasure_code, ss);
if (err) {
ss << "failed to load plugin using properties " << properties_map;
goto reply;
}
int rule = erasure_code->create_ruleset(name, newcrush, &ss);
erasure_code.reset();
if (rule < 0) {
err = rule;
goto reply;
}
ss << "created rule " << name << " at " << rule;
pending_inc.crush.clear();
newcrush.encode(pending_inc.crush);
}
}
int OSDMonitor::get_erasure_code(const map<string,string> &properties,
ErasureCodeInterfaceRef *erasure_code,
stringstream &ss)
@ -3860,43 +3898,12 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
vector<string> properties;
cmd_getval(g_ceph_context, cmdmap, "properties", properties);
if (osdmap.crush->rule_exists(name)) {
ss << "rule " << name << " already exists";
err = 0;
goto reply;
}
map<string,string> properties_map;
err = prepare_pool_properties(pg_pool_t::TYPE_ERASURE,
properties, &properties_map, ss);
if (err)
goto reply;
CrushWrapper newcrush;
_get_pending_crush(newcrush);
if (newcrush.rule_exists(name)) {
ss << "rule " << name << " already exists";
err = 0;
} else {
ErasureCodeInterfaceRef erasure_code;
err = get_erasure_code(properties_map, &erasure_code, ss);
if (err) {
ss << "failed to load plugin using properties " << properties_map;
goto reply;
}
int rule = erasure_code->create_ruleset(name, newcrush, &ss);
erasure_code.reset();
if (rule < 0) {
err = rule;
goto reply;
}
ss << "created rule " << name << " at " << rule;
pending_inc.crush.clear();
newcrush.encode(pending_inc.crush);
}
getline(ss, rs);
wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs,
get_last_committed() + 1));

View File

@ -240,6 +240,10 @@ private:
bool prepare_pool_op (MPoolOp *m);
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,
int *ruleset,
stringstream &ss);
int get_erasure_code(const map<string,string> &properties,
ErasureCodeInterfaceRef *erasure_code,
stringstream &ss);