From 6e92ed1ea207a8541d8cc0e99466018d73237fc8 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Wed, 25 Dec 2013 12:59:00 +0100 Subject: [PATCH] osd: factorize build_simple and build_simple_from_conf Signed-off-by: Loic Dachary --- src/osd/OSDMap.cc | 120 +++++++++++++--------------------------- src/osd/OSDMap.h | 19 +++++-- src/tools/osdmaptool.cc | 20 +++---- 3 files changed, 60 insertions(+), 99 deletions(-) diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index d84d4bca7944..d47cc6b43019 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1839,7 +1839,7 @@ bool OSDMap::crush_ruleset_in_use(int ruleset) const return false; } -void OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, +int OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, int nosd, int pg_bits, int pgp_bits) { ldout(cct, 10) << "build_simple on " << num_osd @@ -1849,7 +1849,35 @@ void OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, set_fsid(fsid); created = modified = ceph_clock_now(cct); - set_max_osd(nosd); + if (nosd >= 0) { + set_max_osd(nosd); + } else { + // count osds + int maxosd = 0, numosd = 0; + const md_config_t *conf = cct->_conf; + vector sections; + conf->get_all_sections(sections); + for (vector::iterator i = sections.begin(); i != sections.end(); ++i) { + if (i->find("osd.") != 0) + continue; + + const char *begin = i->c_str() + 4; + char *end = (char*)begin; + int o = strtol(begin, &end, 10); + if (*end != '\0') + continue; + + if (o > cct->_conf->mon_max_osd) { + lderr(cct) << "[osd." << o << "] in config has id > mon_max_osd " << cct->_conf->mon_max_osd << dendl; + return -ERANGE; + } + numosd++; + if (o > maxosd) + maxosd = o; + } + + set_max_osd(maxosd + 1); + } // pgp_num <= pg_num if (pgp_bits > pg_bits) @@ -1861,7 +1889,7 @@ void OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, rulesets[CEPH_METADATA_RULE] = "metadata"; rulesets[CEPH_RBD_RULE] = "rbd"; - int poolbase = nosd ? nosd : 1; + int poolbase = get_max_osd() ? get_max_osd() : 1; for (map::iterator p = rulesets.begin(); p != rulesets.end(); ++p) { int64_t pool = ++pool_max; @@ -1882,12 +1910,17 @@ void OSDMap::build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, name_pool[p->second] = pool; } - build_simple_crush_map(cct, *crush, rulesets, nosd); + if (nosd >= 0) + build_simple_crush_map(cct, *crush, rulesets, nosd); + else + build_simple_crush_map_from_conf(cct, *crush, rulesets); - for (int i=0; i_conf; - - // count osds - int maxosd = 0, numosd = 0; - - vector sections; - conf->get_all_sections(sections); - for (vector::iterator i = sections.begin(); i != sections.end(); ++i) { - if (i->find("osd.") != 0) - continue; - - const char *begin = i->c_str() + 4; - char *end = (char*)begin; - int o = strtol(begin, &end, 10); - if (*end != '\0') - continue; - - if (o > cct->_conf->mon_max_osd) { - lderr(cct) << "[osd." << o << "] in config has id > mon_max_osd " << cct->_conf->mon_max_osd << dendl; - return -ERANGE; - } - numosd++; - if (o > maxosd) - maxosd = o; - } - - set_max_osd(maxosd + 1); - - // pgp_num <= pg_num - if (pgp_bits > pg_bits) - pgp_bits = pg_bits; - - // crush map - map rulesets; - rulesets[CEPH_DATA_RULE] = "data"; - rulesets[CEPH_METADATA_RULE] = "metadata"; - rulesets[CEPH_RBD_RULE] = "rbd"; - - for (map::iterator p = rulesets.begin(); p != rulesets.end(); ++p) { - int64_t pool = ++pool_max; - pools[pool].type = pg_pool_t::TYPE_REPLICATED; - pools[pool].flags = cct->_conf->osd_pool_default_flags; - if (cct->_conf->osd_pool_default_flag_hashpspool) - pools[pool].flags |= pg_pool_t::FLAG_HASHPSPOOL; - pools[pool].size = cct->_conf->osd_pool_default_size; - pools[pool].min_size = cct->_conf->get_osd_pool_default_min_size(); - pools[pool].crush_ruleset = p->first; - pools[pool].object_hash = CEPH_STR_HASH_RJENKINS; - pools[pool].set_pg_num((numosd + 1) << pg_bits); - pools[pool].set_pgp_num((numosd + 1) << pgp_bits); - pools[pool].last_change = epoch; - if (p->first == CEPH_DATA_RULE) - pools[pool].crash_replay_interval = cct->_conf->osd_default_data_pool_replay_window; - pool_name[pool] = p->second; - name_pool[p->second] = pool; - } - - build_simple_crush_map_from_conf(cct, *crush, rulesets); - - for (int i=0; i<=maxosd; i++) { - set_state(i, 0); - set_weight(i, CEPH_OSD_OUT); - } - - return 0; -} - void OSDMap::build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& crush, map& rulesets) { diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 84e1f43a7b5b..20bb77f35eda 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -601,11 +601,20 @@ public: /* * handy helpers to build simple maps... */ - /// build crush bucket types. @return 'root' type id - void build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, - int num_osd, int pg_bits, int pgp_bits); - int build_simple_from_conf(CephContext *cct, epoch_t e, uuid_d &fsid, - int pg_bits, int pgp_bits); + /** + * Build an OSD map suitable for basic usage. If **num_osd** is >= 0 + * it will be initialized with the specified number of OSDs in a + * single host. If **num_osd** is < 0 the layout of the OSD map will + * be built by reading the content of the configuration file. + * + * @param cct [in] in core ceph context + * @param e [in] initial epoch + * @param fsid [in] id of the cluster + * @param num_osd [in] number of OSDs if >= 0 or read from conf if < 0 + * @return **0** on success, negative errno on error. + */ + int build_simple(CephContext *cct, epoch_t e, uuid_d &fsid, + int num_osd, int pg_bits, int pgp_bits); static int _build_crush_types(CrushWrapper& crush); static void build_simple_crush_map(CephContext *cct, CrushWrapper& crush, map& poolsets, int num_osd); diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index edd31284c4d4..e360614ea9a7 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -182,24 +182,20 @@ int main(int argc, const char **argv) return -1; } - if (createsimple) { - if (num_osd < 1) { - cerr << me << ": osd count must be > 0" << std::endl; - exit(1); + if (createsimple || create_from_conf) { + if (createsimple) { + if (num_osd < 1) { + cerr << me << ": osd count must be > 0" << std::endl; + exit(1); + } + } else { + num_osd = -1; } uuid_d fsid; memset(&fsid, 0, sizeof(uuid_d)); osdmap.build_simple(g_ceph_context, 0, fsid, num_osd, pg_bits, pgp_bits); modified = true; } - if (create_from_conf) { - uuid_d fsid; - memset(&fsid, 0, sizeof(uuid_d)); - int r = osdmap.build_simple_from_conf(g_ceph_context, 0, fsid, pg_bits, pgp_bits); - if (r < 0) - return -1; - modified = true; - } if (!import_crush.empty()) { bufferlist cbl; -- 2.47.3