From f22997e24bda4e6476e15d5d4ad9737861f9741f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 27 May 2017 15:09:16 -0400 Subject: [PATCH] osd/OSDMap: switch [require_]min_compat_client to CEPH_RELEASE_* values Instead of using a string, use the defined CEPH_RELEASE_* values. This is simpler. We allow decoding of post-kraken pre-luminous maps that use the string values. Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 101 +++++++++++++++++++++++++----------------- src/osd/OSDMap.cc | 67 +++++++++++++++------------- src/osd/OSDMap.h | 8 ++-- 3 files changed, 102 insertions(+), 74 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 7b0cb1869c0..01a34a66d88 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -230,7 +230,12 @@ void OSDMonitor::create_initial() if (newmap.backfillfull_ratio > 1.0) newmap.backfillfull_ratio /= 100; newmap.nearfull_ratio = g_conf->mon_osd_nearfull_ratio; if (newmap.nearfull_ratio > 1.0) newmap.nearfull_ratio /= 100; - newmap.require_min_compat_client = g_conf->mon_osd_initial_require_min_compat_client; + int r = ceph_release_from_name( + g_conf->mon_osd_initial_require_min_compat_client.c_str()); + if (r <= 0) { + assert(0 == "mon_osd_initial_require_min_compat_client is not valid"); + } + newmap.require_min_compat_client = r; } // encode into pending incremental @@ -1189,13 +1194,13 @@ void OSDMonitor::encode_pending(MonitorDBStore::TransactionRef t) } // min_compat_client? - if (tmp.require_min_compat_client.empty()) { + if (tmp.require_min_compat_client == 0) { auto mv = tmp.get_min_compat_client(); - dout(1) << __func__ << " setting require_min_compat_client to current " << mv - << dendl; - mon->clog->info() << "setting require_min_compat_client to currently required " - << mv; - pending_inc.new_require_min_compat_client = mv.first; + dout(1) << __func__ << " setting require_min_compat_client to currently " + << "required " << ceph_release_name(mv) << dendl; + mon->clog->info() << "setting require_min_compat_client to currently " + << "required " << ceph_release_name(mv); + pending_inc.new_require_min_compat_client = mv; } } } @@ -5392,12 +5397,12 @@ bool OSDMonitor::validate_crush_against_features(const CrushWrapper *newcrush, newmap.apply_incremental(new_pending); // client compat - if (newmap.require_min_compat_client.length()) { + if (newmap.require_min_compat_client > 0) { auto mv = newmap.get_min_compat_client(); - if (mv.first > newmap.require_min_compat_client) { - ss << "new crush map requires client version " << mv + if (mv > newmap.require_min_compat_client) { + ss << "new crush map requires client version " << ceph_release_name(mv) << " but require_min_compat_client is " - << newmap.require_min_compat_client; + << ceph_release_name(newmap.require_min_compat_client); return false; } } @@ -7483,9 +7488,8 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } string v; cmd_getval(g_ceph_context, cmdmap, "version", v); - if (v != "luminous" && v != "kraken" && v != "jewel" && v != "infernalis" && - v != "hammer" && v != "giant" && v != "firefly" && v != "emperor" && - v != "dumpling" && v != "cuttlefish" && v != "bobtail" && v != "argonaut") { + int vno = ceph_release_from_name(v.c_str()); + if (vno <= 0) { ss << "version " << v << " is not recognized"; err = -EINVAL; goto reply; @@ -7493,16 +7497,18 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, OSDMap newmap; newmap.deepish_copy_from(osdmap); newmap.apply_incremental(pending_inc); - newmap.require_min_compat_client = v; - auto mv = newmap.get_min_compat_client(); - if (v < mv.first) { - ss << "osdmap current utilizes features that require " << mv - << "; cannot set require_min_compat_client below that to " << v; + newmap.require_min_compat_client = vno; + auto mvno = newmap.get_min_compat_client(); + if (vno < mvno) { + ss << "osdmap current utilizes features that require " + << ceph_release_name(mvno) + << "; cannot set require_min_compat_client below that to " + << ceph_release_name(vno); err = -EPERM; goto reply; } - ss << "set require_min_compat_client to " << v; - pending_inc.new_require_min_compat_client = v; + ss << "set require_min_compat_client to " << ceph_release_name(vno); + pending_inc.new_require_min_compat_client = vno; getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, get_last_committed() + 1)); @@ -7629,17 +7635,26 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -EPERM; goto reply; } - int rel = -1; - if (release == "luminous") { + int rel = ceph_release_from_name(release.c_str()); + if (rel <= 0) { + ss << "unrecognized release " << release; + err = -EINVAL; + goto reply; + } + if (rel < CEPH_RELEASE_LUMINOUS) { + ss << "use this command only for luminous and later"; + err = -EINVAL; + goto reply; + } + if (rel == CEPH_RELEASE_LUMINOUS) { if (!HAVE_FEATURE(osdmap.get_up_osd_features(), SERVER_LUMINOUS)) { ss << "not all up OSDs have CEPH_FEATURE_SERVER_LUMINOUS feature"; err = -EPERM; goto reply; } - rel = CEPH_RELEASE_LUMINOUS; } else { - ss << "unrecognized release " << release; - err = -EINVAL; + ss << "not supported for this release yet"; + err = -EPERM; goto reply; } if (rel < osdmap.require_osd_release) { @@ -7816,9 +7831,10 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, goto reply; } - if (osdmap.require_min_compat_client.length() && - osdmap.require_min_compat_client < "firefly") { - ss << "require_min_compat_client " << osdmap.require_min_compat_client + if (osdmap.require_min_compat_client > 0 && + osdmap.require_min_compat_client < CEPH_RELEASE_FIREFLY) { + ss << "require_min_compat_client " + << ceph_release_name(osdmap.require_min_compat_client) << " < firefly, which is required for primary-temp"; err = -EPERM; goto reply; @@ -7838,8 +7854,9 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -EPERM; goto reply; } - if (osdmap.require_min_compat_client < "luminous") { - ss << "min_compat_client " << osdmap.require_min_compat_client + if (osdmap.require_min_compat_client < CEPH_RELEASE_LUMINOUS) { + ss << "min_compat_client " + << ceph_release_name(osdmap.require_min_compat_client) << " < luminous, which is required for pg-upmap"; err = -EPERM; goto reply; @@ -7901,8 +7918,9 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -EPERM; goto reply; } - if (osdmap.require_min_compat_client < "luminous") { - ss << "require_min_compat_client " << osdmap.require_min_compat_client + if (osdmap.require_min_compat_client < CEPH_RELEASE_LUMINOUS) { + ss << "require_min_compat_client " + << ceph_release_name(osdmap.require_min_compat_client) << " < luminous, which is required for pg-upmap"; err = -EPERM; goto reply; @@ -7942,8 +7960,9 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -EPERM; goto reply; } - if (osdmap.require_min_compat_client < "luminous") { - ss << "require_min_compat_client " << osdmap.require_min_compat_client + if (osdmap.require_min_compat_client < CEPH_RELEASE_LUMINOUS) { + ss << "require_min_compat_client " + << ceph_release_name(osdmap.require_min_compat_client) << " < luminous, which is required for pg-upmap"; err = -EPERM; goto reply; @@ -8018,8 +8037,9 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -EPERM; goto reply; } - if (osdmap.require_min_compat_client < "luminous") { - ss << "require_min_compat_client " << osdmap.require_min_compat_client + if (osdmap.require_min_compat_client < CEPH_RELEASE_LUMINOUS) { + ss << "require_min_compat_client " + << ceph_release_name(osdmap.require_min_compat_client) << " < luminous, which is required for pg-upmap"; err = -EPERM; goto reply; @@ -8073,9 +8093,10 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -EINVAL; goto reply; } - if (osdmap.require_min_compat_client.length() && - osdmap.require_min_compat_client < "firefly") { - ss << "require_min_compat_client " << osdmap.require_min_compat_client + if (osdmap.require_min_compat_client > 0 && + osdmap.require_min_compat_client < CEPH_RELEASE_FIREFLY) { + ss << "require_min_compat_client " + << ceph_release_name(osdmap.require_min_compat_client) << " < firefly, which is required for primary-affinity"; err = -EPERM; goto reply; diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 572dbb4d87f..fc5a426da14 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -501,10 +501,9 @@ void OSDMap::Incremental::encode(bufferlist& bl, uint64_t features) const ::encode(new_full_ratio, bl); ::encode(new_backfillfull_ratio, bl); } - if (target_v >= 5) { - ::encode(new_require_min_compat_client, bl); - } + // 5 was string-based new_require_min_compat_client if (target_v >= 6) { + ::encode(new_require_min_compat_client, bl); ::encode(new_require_osd_release, bl); } ENCODE_FINISH(bl); // osd-only data @@ -718,10 +717,15 @@ void OSDMap::Incremental::decode(bufferlist::iterator& bl) } else { new_backfillfull_ratio = -1; } - if (struct_v >= 5) { - ::decode(new_require_min_compat_client, bl); + if (struct_v == 5) { + string r; + ::decode(r, bl); + if (r.length()) { + new_require_min_compat_client = ceph_release_from_name(r.c_str()); + } } if (struct_v >= 6) { + ::decode(new_require_min_compat_client, bl); ::decode(new_require_osd_release, bl); } else { if (new_flags >= 0 && (new_flags & CEPH_OSDMAP_REQUIRE_LUMINOUS)) { @@ -780,7 +784,7 @@ void OSDMap::Incremental::dump(Formatter *f) const f->dump_float("new_full_ratio", new_full_ratio); f->dump_float("new_nearfull_ratio", new_nearfull_ratio); f->dump_float("new_backfillfull_ratio", new_backfillfull_ratio); - f->dump_string("new_require_min_compat_client", new_require_min_compat_client); + f->dump_int("new_require_min_compat_client", new_require_min_compat_client); f->dump_int("new_require_osd_release", new_require_osd_release); if (fullmap.length()) { @@ -1307,34 +1311,34 @@ uint64_t OSDMap::get_features(int entity_type, uint64_t *pmask) const return features; } -pair OSDMap::get_min_compat_client() const +uint8_t OSDMap::get_min_compat_client() const { uint64_t f = get_features(CEPH_ENTITY_TYPE_CLIENT, nullptr); if (HAVE_FEATURE(f, OSDMAP_PG_UPMAP) || // v12.0.0-1733-g27d6f43 - HAVE_FEATURE(f, CRUSH_CHOOSE_ARGS)) { // v12.0.1-2172-gef1ef28 - return make_pair("luminous", "12.2.0"); + HAVE_FEATURE(f, CRUSH_CHOOSE_ARGS)) { // v12.0.1-2172-gef1ef28 + return CEPH_RELEASE_LUMINOUS; // v12.2.0 } if (HAVE_FEATURE(f, CRUSH_TUNABLES5)) { // v10.0.0-612-g043a737 - return make_pair("jewel", "10.2.0"); + return CEPH_RELEASE_JEWEL; // v10.2.0 } if (HAVE_FEATURE(f, CRUSH_V4)) { // v0.91-678-g325fc56 - return make_pair("hammer", "0.94"); + return CEPH_RELEASE_HAMMER; // v0.94.0 } if (HAVE_FEATURE(f, OSD_PRIMARY_AFFINITY) || // v0.76-553-gf825624 HAVE_FEATURE(f, CRUSH_TUNABLES3) || // v0.76-395-ge20a55d HAVE_FEATURE(f, OSD_ERASURE_CODES) || // v0.73-498-gbfc86a8 HAVE_FEATURE(f, OSD_CACHEPOOL)) { // v0.67-401-gb91c1c5 - return make_pair("firefly", "0.80"); + return CEPH_RELEASE_FIREFLY; // v0.80.0 } if (HAVE_FEATURE(f, CRUSH_TUNABLES2) || // v0.54-684-g0cc47ff HAVE_FEATURE(f, OSDHASHPSPOOL)) { // v0.57-398-g8cc2b0f - return make_pair("dumpling", "0.67"); + return CEPH_RELEASE_DUMPLING; // v0.67.0 } if (HAVE_FEATURE(f, CRUSH_TUNABLES)) { // v0.48argonaut-206-g6f381af - return make_pair("argonaut", "0.48argonaut-207"); + return CEPH_RELEASE_ARGONAUT; // v0.48argonaut-206-g6f381af } - return make_pair("argonaut", "0.48"); + return CEPH_RELEASE_ARGONAUT; // v0.48argonaut-206-g6f381af } void OSDMap::_calc_up_osd_features() @@ -1703,7 +1707,7 @@ int OSDMap::apply_incremental(const Incremental &inc) if (inc.new_full_ratio >= 0) { full_ratio = inc.new_full_ratio; } - if (inc.new_require_min_compat_client.length()) { + if (inc.new_require_min_compat_client > 0) { require_min_compat_client = inc.new_require_min_compat_client; } if (inc.new_require_osd_release >= 0) { @@ -2314,10 +2318,9 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const ::encode(full_ratio, bl); ::encode(backfillfull_ratio, bl); } - if (target_v >= 4) { - ::encode(require_min_compat_client, bl); - } + // 4 was string-based new_require_min_compat_client if (target_v >= 5) { + ::encode(require_min_compat_client, bl); ::encode(require_osd_release, bl); } ENCODE_FINISH(bl); // osd-only data @@ -2558,10 +2561,14 @@ void OSDMap::decode(bufferlist::iterator& bl) } else { backfillfull_ratio = 0; } - if (struct_v >= 4) { - ::decode(require_min_compat_client, bl); + if (struct_v == 4) { + string r; + ::decode(r, bl); + if (r.length()) + require_min_compat_client = ceph_release_from_name(r.c_str()); } if (struct_v >= 5) { + ::decode(require_min_compat_client, bl); ::decode(require_osd_release, bl); if (require_osd_release >= CEPH_RELEASE_LUMINOUS) { flags &= ~(CEPH_OSDMAP_LEGACY_REQUIRE_FLAGS); @@ -2653,11 +2660,10 @@ void OSDMap::dump(Formatter *f) const f->dump_string("cluster_snapshot", get_cluster_snapshot()); f->dump_int("pool_max", get_pool_max()); f->dump_int("max_osd", get_max_osd()); - f->dump_string("require_min_compat_client", require_min_compat_client); - auto mv = get_min_compat_client(); - f->dump_string("min_compat_client", mv.first); - f->dump_string("min_compat_client_version", mv.second); - f->dump_int("require_osd_release", require_osd_release); + f->dump_string("require_min_compat_client", + ceph_release_name(require_min_compat_client)); + f->dump_string("min_compat_client", + ceph_release_name(get_min_compat_client())); f->dump_string("require_osd_release", ceph_release_name(require_osd_release)); @@ -2873,11 +2879,12 @@ void OSDMap::print(ostream& out) const out << "full_ratio " << full_ratio << "\n"; out << "backfillfull_ratio " << backfillfull_ratio << "\n"; out << "nearfull_ratio " << nearfull_ratio << "\n"; - if (require_min_compat_client.length()) { - out << "require_min_compat_client " << require_min_compat_client << "\n"; + if (require_min_compat_client > 0) { + out << "require_min_compat_client " + << ceph_release_name(require_min_compat_client) << "\n"; } - auto mv = get_min_compat_client(); - out << "min_compat_client " << mv.first << " " << mv.second << "\n"; + out << "min_compat_client " << ceph_release_name(get_min_compat_client()) + << "\n"; if (get_cluster_snapshot().length()) out << "cluster_snapshot " << get_cluster_snapshot() << "\n"; out << "\n"; diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index bef30bf2cb5..849569e8e7f 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -173,7 +173,7 @@ public: float new_backfillfull_ratio = -1; float new_full_ratio = -1; - string new_require_min_compat_client; + int8_t new_require_min_compat_client = -1; mutable bool have_crc; ///< crc values are defined uint32_t full_crc; ///< crc of the resulting OSDMap @@ -274,11 +274,11 @@ private: float full_ratio = 0, backfillfull_ratio = 0, nearfull_ratio = 0; /// min compat client we want to support - string require_min_compat_client; + uint8_t require_min_compat_client = 0; // CEPH_RELEASE_* public: /// require osds to run at least this release - uint8_t require_osd_release = 0; + uint8_t require_osd_release = 0; // CEPH_RELEASE_* private: mutable uint64_t cached_up_osd_features; @@ -625,7 +625,7 @@ public: * get oldest *client* version (firefly, hammer, etc.) that can connect given * the feature bits required (according to get_features()). */ - pair get_min_compat_client() const; + uint8_t get_min_compat_client() const; /** * get intersection of features supported by up osds -- 2.39.5