From 454c116d38a005fc91c9d3e70258b4dac8a80547 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 9 Sep 2013 13:23:42 +0200 Subject: [PATCH] mon: add key[=value] ... to osd pool create With the introduction of the erasure code pool, arguments to be interpreted depending on the pool type must be introduced. For instance the erasure code pool loads a plugin at run time will use easure-code-k=10 to split each object in 10. The arguments are described as name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=] If key=value it is stored in the new properties data member of pg_pool_t as properties[key] = value, otherwise the value is the empty string. The pg_pool_t version is bumped to 10 and the encode/decode methods modified to take the properties into account. The generate_test_instances method creates a two entries map, one of which is the empty string to cover the case when no value is specified. http://tracker.ceph.com/issues/6113 refs #6113 Signed-off-by: Loic Dachary --- src/mon/MonCommands.h | 3 ++- src/mon/OSDMonitor.cc | 27 +++++++++++++++++++++++---- src/mon/OSDMonitor.h | 3 ++- src/osd/osd_types.cc | 16 +++++++++++++++- src/osd/osd_types.h | 1 + 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 28fa80e00b798..2949f863888ff 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -479,7 +479,8 @@ COMMAND("osd pool rmsnap " \ COMMAND("osd pool create " \ "name=pool,type=CephPoolname " \ "name=pg_num,type=CephInt,range=0 " \ - "name=pgp_num,type=CephInt,range=0,req=false", \ + "name=pgp_num,type=CephInt,range=0,req=false" \ + "name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]", \ "create pool", "osd", "rw", "cli,rest") COMMAND("osd pool delete " \ "name=pool,type=CephPoolname " \ diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 5450532e46d1f..8eb88a829b1ea 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2473,10 +2473,11 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m) MonSession *session = m->get_session(); if (!session) return -EPERM; + vector properties; if (m->auid) - return prepare_new_pool(m->name, m->auid, m->crush_rule, 0, 0); + return prepare_new_pool(m->name, m->auid, m->crush_rule, 0, 0, properties); else - return prepare_new_pool(m->name, session->auid, m->crush_rule, 0, 0); + return prepare_new_pool(m->name, session->auid, m->crush_rule, 0, 0, properties); } /** @@ -2485,11 +2486,13 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m) * @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 * * @return 0 in all cases. That's silly. */ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_rule, - unsigned pg_num, unsigned pgp_num) + unsigned pg_num, unsigned pgp_num, + const vector &properties) { for (map::iterator p = pending_inc.new_pool_names.begin(); p != pending_inc.new_pool_names.end(); @@ -2519,6 +2522,18 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_rule, pi->set_pgp_num(pgp_num ? pgp_num : g_conf->osd_pool_default_pgp_num); pi->last_change = pending_inc.epoch; pi->auid = auid; + for (vector::const_iterator i = properties.begin(); + i != properties.end(); + i++) { + size_t equal = i->find('='); + if (equal != string::npos) + pi->properties[*i] = string(); + else { + const string key = i->substr(0, equal); + const string value = i->substr(equal); + pi->properties[key] = value; + } + } pending_inc.new_pool_names[pool] = name; return 0; } @@ -3480,9 +3495,13 @@ done: goto reply; } + vector properties; + cmd_getval(g_ceph_context, cmdmap, "properties", properties); + err = prepare_new_pool(poolstr, 0, // auid=0 for admin created pool -1, // default crush rule - pg_num, pgp_num); + pg_num, pgp_num, + properties); if (err < 0 && err != -EEXIST) { goto reply; } diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index 04f7cf5b1963d..304f9c4f609f0 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -235,7 +235,8 @@ private: bool prepare_pool_op_create (MPoolOp *m); bool prepare_pool_op_delete(MPoolOp *m); int prepare_new_pool(string& name, uint64_t auid, int crush_rule, - unsigned pg_num, unsigned pgp_num); + unsigned pg_num, unsigned pgp_num, + const vector &properties); int prepare_new_pool(MPoolOp *m); void update_pool_flags(int64_t pool_id, uint64_t flags); diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 3451d520ff280..34ae75b12b9e0 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -649,6 +649,14 @@ void pg_pool_t::dump(Formatter *f) const f->dump_int("read_tier", read_tier); f->dump_int("write_tier", write_tier); f->dump_string("cache_mode", get_cache_mode_name()); + f->open_array_section("properties"); + for (map::const_iterator i = properties.begin(); + i != properties.end(); + ++i) { + string name = i->first; + f->dump_string(name.c_str(), i->second); + } + f->close_section(); } @@ -853,7 +861,7 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const return; } - ENCODE_START(9, 5, bl); + ENCODE_START(10, 5, bl); ::encode(type, bl); ::encode(size, bl); ::encode(crush_ruleset, bl); @@ -880,6 +888,7 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const ::encode(c, bl); ::encode(read_tier, bl); ::encode(write_tier, bl); + ::encode(properties, bl); ENCODE_FINISH(bl); } @@ -947,6 +956,9 @@ void pg_pool_t::decode(bufferlist::iterator& bl) ::decode(read_tier, bl); ::decode(write_tier, bl); } + if (struct_v >= 10) { + ::decode(properties, bl); + } DECODE_FINISH(bl); calc_pg_masks(); } @@ -988,6 +1000,8 @@ void pg_pool_t::generate_test_instances(list& o) a.cache_mode = CACHEMODE_WRITEBACK; a.read_tier = 1; a.write_tier = 1; + a.properties["p-1"] = "v-1"; + a.properties["empty"] = string(); o.push_back(new pg_pool_t(a)); } diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index da139b853b16e..91ab89a63afde 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -778,6 +778,7 @@ private: public: + map properties; /// interpreted according to the pool type epoch_t last_change; /// most recent epoch changed, exclusing snapshot changes snapid_t snap_seq; /// seq for per-pool snapshot epoch_t snap_epoch; /// osdmap epoch of last snap -- 2.39.5