From bf96b30eaf552148249953ed4fb654cbb101c3d0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 28 Nov 2016 14:35:53 -0500 Subject: [PATCH] crush/CrushWrapper: encode with features No behavior change yet; just fixing callers. Signed-off-by: Sage Weil (cherry picked from commit b7c9e055848c8aa951bc48c957cff3ef323ea441) [Updated write_file to use all feaetures] [Updated OSDMonitor.cc to use mon->quorum_features instead of the mon->get_quorum_con_featuers() helper] [trivial conflict from removed write_file and read_file] Conflicts: src/crush/CrushWrapper.h src/mgr/PyModules.cc src/mon/OSDMonitor.cc src/tools/ceph_monstore_tool.cc --- src/crush/CrushTester.cc | 3 ++- src/crush/CrushWrapper.cc | 2 +- src/crush/CrushWrapper.h | 7 ++++--- src/mon/OSDMonitor.cc | 36 ++++++++++++++++----------------- src/osd/OSDMap.cc | 10 ++++----- src/test/encoding/types.h | 2 +- src/tools/ceph_monstore_tool.cc | 10 +++++---- src/tools/crushtool.cc | 2 +- src/tools/osdmaptool.cc | 2 +- 9 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/crush/CrushTester.cc b/src/crush/CrushTester.cc index 2ebe8c23d87ee..a879171d58420 100644 --- a/src/crush/CrushTester.cc +++ b/src/crush/CrushTester.cc @@ -4,6 +4,7 @@ #include "include/stringify.h" #include "CrushTester.h" #include "CrushTreeDumper.h" +#include "include/ceph_features.h" #include #include @@ -383,7 +384,7 @@ int CrushTester::test_with_crushtool(const char *crushtool_cmd, } bufferlist bl; - ::encode(crush, bl); + ::encode(crush, bl, CEPH_FEATURES_SUPPORTED_DEFAULT); bl.write_fd(crushtool.get_stdin()); crushtool.close_stdin(); bl.clear(); diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index f254ac0336afc..4ea39b8cbd2c6 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1118,7 +1118,7 @@ int CrushWrapper::remove_rule(int ruleno) return 0; } -void CrushWrapper::encode(bufferlist& bl) const +void CrushWrapper::encode(bufferlist& bl, uint64_t features) const { assert(crush); diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 7b6f94150ca3b..07c32e13cefd3 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -22,6 +22,7 @@ extern "C" { #include "include/err.h" #include "include/encoding.h" +#include "include/ceph_features.h" #include "common/Mutex.h" @@ -1132,11 +1133,11 @@ public: } int write_to_file(const char *fn) { bufferlist bl; - encode(bl); + encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT); return bl.write_file(fn); } - void encode(bufferlist &bl) const; + void encode(bufferlist &bl, uint64_t features) const; void decode(bufferlist::iterator &blp); void decode_crush_bucket(crush_bucket** bptr, bufferlist::iterator &blp); void dump(Formatter *f) const; @@ -1156,6 +1157,6 @@ public: static bool is_valid_crush_loc(CephContext *cct, const map& loc); }; -WRITE_CLASS_ENCODER(CrushWrapper) +WRITE_CLASS_ENCODER_FEATURES(CrushWrapper) #endif diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index d4408edd2eb8a..6d156176b6cb5 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -97,7 +97,7 @@ void OSDMonitor::_get_pending_crush(CrushWrapper& newcrush) if (pending_inc.crush.length()) bl = pending_inc.crush; else - osdmap.crush->encode(bl); + osdmap.crush->encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT); bufferlist::iterator p = bl.begin(); newcrush.decode(p); @@ -3269,7 +3269,7 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) rdata.append(osdmap_bl); ss << "got osdmap epoch " << p->get_epoch(); } else if (prefix == "osd getcrushmap") { - p->crush->encode(rdata); + p->crush->encode(rdata, mon->quorum_features); ss << "got crush map from osdmap epoch " << p->get_epoch(); } if (p != &osdmap) @@ -4421,7 +4421,7 @@ int OSDMonitor::crush_rename_bucket(const string& srcname, return ret; pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); *ss << "renamed bucket " << srcname << " into " << dstname; return 0; } @@ -4471,7 +4471,7 @@ int OSDMonitor::crush_ruleset_create_erasure(const string &name, return err; *ruleset = err; pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); return 0; } } @@ -4546,7 +4546,7 @@ bool OSDMonitor::validate_crush_against_features(const CrushWrapper *newcrush, stringstream& ss) { OSDMap::Incremental new_pending = pending_inc; - ::encode(*newcrush, new_pending.crush); + ::encode(*newcrush, new_pending.crush, mon->quorum_features); OSDMap newmap; newmap.deepish_copy_from(osdmap); newmap.apply_incremental(new_pending); @@ -5569,7 +5569,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "added bucket " << name << " type " << typestr << " to crush map"; goto update; @@ -5648,7 +5648,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << action << " item id " << osdid << " name '" << name << "' weight " << weight << " at location " << loc << " to crush map"; getline(ss, rs); @@ -5693,7 +5693,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } if (err > 0) { pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "create-or-move updating item name '" << name << "' weight " << weight << " at location " << loc << " to crush map"; getline(ss, rs); @@ -5730,7 +5730,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, if (err >= 0) { ss << "moved item id " << id << " name '" << name << "' to location " << loc << " in crush map"; pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, get_last_committed() + 1)); @@ -5783,7 +5783,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, ss << "linked item id " << id << " name '" << name << "' to location " << loc << " in crush map"; pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); } else { ss << "cannot link item id " << id << " name '" << name << "' to location " << loc; @@ -5844,7 +5844,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } if (err == 0) { pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "removed item id " << id << " name '" << name << "' from crush map"; getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, @@ -5860,7 +5860,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, newcrush.reweight(g_ceph_context); pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "reweighted crush hierarchy"; getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, @@ -5897,7 +5897,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, if (err < 0) goto reply; pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "reweighted item id " << id << " name '" << name << "' to " << w << " in crush map"; getline(ss, rs); @@ -5935,7 +5935,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, if (err < 0) goto reply; pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "reweighted subtree id " << id << " name '" << name << "' to " << w << " in crush map"; getline(ss, rs); @@ -5975,7 +5975,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "adjusted tunables profile to " << profile; getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, @@ -6015,7 +6015,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); ss << "adjusted tunable " << tunable << " to " << value; getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, @@ -6056,7 +6056,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); } getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, @@ -6268,7 +6268,7 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, } pending_inc.crush.clear(); - newcrush.encode(pending_inc.crush); + newcrush.encode(pending_inc.crush, mon->quorum_features); } getline(ss, rs); wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, 0, rs, diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 45dc6d47e4efb..d2fb34f7fe2d1 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1154,8 +1154,8 @@ void OSDMap::dedup(const OSDMap *o, OSDMap *n) // does crush match? bufferlist oc, nc; - ::encode(*o->crush, oc); - ::encode(*n->crush, nc); + ::encode(*o->crush, oc, CEPH_FEATURES_SUPPORTED_DEFAULT); + ::encode(*n->crush, nc, CEPH_FEATURES_SUPPORTED_DEFAULT); if (oc.contents_equal(nc)) { n->crush = o->crush; } @@ -1826,7 +1826,7 @@ void OSDMap::encode_client_old(bufferlist& bl) const // crush bufferlist cbl; - crush->encode(cbl); + crush->encode(cbl, 0 /* legacy (no) features */); ::encode(cbl, bl); } @@ -1861,7 +1861,7 @@ void OSDMap::encode_classic(bufferlist& bl, uint64_t features) const // crush bufferlist cbl; - crush->encode(cbl); + crush->encode(cbl, 0 /* legacy (no) features */); ::encode(cbl, bl); // extended @@ -1929,7 +1929,7 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const // crush bufferlist cbl; - crush->encode(cbl); + crush->encode(cbl, features); ::encode(cbl, bl); ::encode(erasure_code_profiles, bl); ENCODE_FINISH(bl); // client-usable data diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index 22919bd970f1a..7bed2f3f47bf3 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -43,7 +43,7 @@ TYPE_FEATUREFUL_STRAYDATA(OSDMap) TYPE_FEATUREFUL_STRAYDATA(OSDMap::Incremental) #include "crush/CrushWrapper.h" -TYPE_NOCOPY(CrushWrapper) +TYPE_FEATUREFUL_NOCOPY(CrushWrapper) #include "common/histogram.h" TYPE(pow2_hist_t) diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index e2aec2ae95b8c..75fb95b6d13e8 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -272,7 +272,7 @@ int update_osdmap(MonitorDBStore& store, version_t ver, bool copy, OSDMap::Incremental inc(bl); if (inc.crush.length()) { inc.crush.clear(); - crush->encode(inc.crush); + crush->encode(inc.crush, CEPH_FEATURES_SUPPORTED_DEFAULT); } if (inc.fullmap.length()) { OSDMap fullmap; @@ -889,9 +889,11 @@ int main(int argc, char **argv) { } else if (map_type == "crushmap") { bufferlist tmp; r = st.get("osdmap", st.combine_strings("full", v), tmp); - OSDMap osdmap; - osdmap.decode(tmp); - osdmap.crush->encode(bl); + if (r >= 0) { + OSDMap osdmap; + osdmap.decode(tmp); + osdmap.crush->encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT); + } } else { r = st.get(map_type, v, bl); } diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index b1f5aaabf42b1..03ff4dacd37fe 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -879,7 +879,7 @@ int main(int argc, const char **argv) cout << me << " successfully built or modified map. Use '-o ' to write it out." << std::endl; } else { bufferlist bl; - crush.encode(bl); + crush.encode(bl, CEPH_FEATURES_SUPPORTED_DEFAULT); int r = bl.write_file(outfn.c_str()); if (r < 0) { cerr << me << ": error writing '" << outfn << "': " << cpp_strerror(r) << std::endl; diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index 810f82adcc893..c5dfcc6555c94 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -269,7 +269,7 @@ int main(int argc, const char **argv) if (!export_crush.empty()) { bufferlist cbl; - osdmap.crush->encode(cbl); + osdmap.crush->encode(cbl, CEPH_FEATURES_SUPPORTED_DEFAULT); r = cbl.write_file(export_crush.c_str()); if (r < 0) { cerr << me << ": error writing crush map to " << import_crush << std::endl; -- 2.39.5