From 96eb0a9887897195dd15601658f3f1cc67cfb53e Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Fri, 21 Jul 2017 15:08:44 +0800 Subject: [PATCH] mon/OSDMonitor: apply new 'destroyed' status to 'osd tree' filter Signed-off-by: xie xingguo --- qa/workunits/cephtool/test.sh | 4 ++++ src/mon/MonCommands.h | 2 +- src/mon/OSDMonitor.cc | 18 ++++++++++++++---- src/osd/OSDMap.cc | 32 ++++++++++++++++++++------------ src/osd/OSDMap.h | 9 +++++---- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 84fd9cc97398f..e6e84e08e3b31 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -1618,12 +1618,16 @@ function test_mon_osd() ceph osd tree down ceph osd tree in ceph osd tree out + ceph osd tree destroyed ceph osd tree up in ceph osd tree up out ceph osd tree down in ceph osd tree down out ceph osd tree out down expect_false ceph osd tree up down + expect_false ceph osd tree up destroyed + expect_false ceph osd tree down destroyed + expect_false ceph osd tree up down destroyed expect_false ceph osd tree in out expect_false ceph osd tree up foo diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index e5152928c17bc..41e3f79f1175a 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -460,7 +460,7 @@ COMMAND("osd dump " \ "print summary of OSD map", "osd", "r", "cli,rest") COMMAND("osd tree " \ "name=epoch,type=CephInt,range=0,req=false " \ - "name=states,type=CephChoices,strings=up|down|in|out,n=N,req=false", \ + "name=states,type=CephChoices,strings=up|down|in|out|destroyed,n=N,req=false", \ "print OSD tree", "osd", "r", "cli,rest") COMMAND("osd ls " \ "name=epoch,type=CephInt,range=0,req=false", \ diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 86f70cf099462..94b0e5b7936c1 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -4137,6 +4137,8 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) filter |= OSDMap::DUMP_IN; } else if (s == "out") { filter |= OSDMap::DUMP_OUT; + } else if (s == "destroyed") { + filter |= OSDMap::DUMP_DESTROYED; } else { ss << "unrecognized state '" << s << "'"; r = -EINVAL; @@ -4144,10 +4146,18 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) } } if ((filter & (OSDMap::DUMP_IN|OSDMap::DUMP_OUT)) == - (OSDMap::DUMP_IN|OSDMap::DUMP_OUT) || - (filter & (OSDMap::DUMP_UP|OSDMap::DUMP_DOWN)) == - (OSDMap::DUMP_UP|OSDMap::DUMP_DOWN)) { - ss << "cannot specify both up and down or both in and out"; + (OSDMap::DUMP_IN|OSDMap::DUMP_OUT)) { + ss << "cannot specify both 'in' and 'out'"; + r = -EINVAL; + goto reply; + } + if (((filter & (OSDMap::DUMP_UP|OSDMap::DUMP_DOWN)) == + (OSDMap::DUMP_UP|OSDMap::DUMP_DOWN)) || + ((filter & (OSDMap::DUMP_UP|OSDMap::DUMP_DESTROYED)) == + (OSDMap::DUMP_UP|OSDMap::DUMP_DESTROYED)) || + ((filter & (OSDMap::DUMP_DOWN|OSDMap::DUMP_DESTROYED)) == + (OSDMap::DUMP_DOWN|OSDMap::DUMP_DESTROYED))) { + ss << "can specify only one of 'up', 'down' and 'destroyed'"; r = -EINVAL; goto reply; } diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index d3cc2774a03a5..57035c4c8ea8e 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -3056,13 +3056,17 @@ public: : Parent(crush, osdmap_->get_pool_names()), osdmap(osdmap_), filter(f) { } bool should_dump_leaf(int i) const override { - if (((filter & OSDMap::DUMP_UP) && !osdmap->is_up(i)) || - ((filter & OSDMap::DUMP_DOWN) && !osdmap->is_down(i)) || - ((filter & OSDMap::DUMP_IN) && !osdmap->is_in(i)) || - ((filter & OSDMap::DUMP_OUT) && !osdmap->is_out(i))) { - return false; + if (!filter) { + return true; // normal case + } + if (((filter & OSDMap::DUMP_UP) && osdmap->is_up(i)) || + ((filter & OSDMap::DUMP_DOWN) && osdmap->is_down(i)) || + ((filter & OSDMap::DUMP_IN) && osdmap->is_in(i)) || + ((filter & OSDMap::DUMP_OUT) && osdmap->is_out(i)) || + ((filter & OSDMap::DUMP_DESTROYED) && osdmap->is_destroyed(i))) { + return true; } - return true; + return false; } bool should_dump_empty_bucket() const override { @@ -3142,13 +3146,17 @@ public: : Parent(crush, osdmap_->get_pool_names()), osdmap(osdmap_), filter(f) { } bool should_dump_leaf(int i) const override { - if (((filter & OSDMap::DUMP_UP) && !osdmap->is_up(i)) || - ((filter & OSDMap::DUMP_DOWN) && !osdmap->is_down(i)) || - ((filter & OSDMap::DUMP_IN) && !osdmap->is_in(i)) || - ((filter & OSDMap::DUMP_OUT) && !osdmap->is_out(i))) { - return false; + if (!filter) { + return true; // normal case + } + if (((filter & OSDMap::DUMP_UP) && osdmap->is_up(i)) || + ((filter & OSDMap::DUMP_DOWN) && osdmap->is_down(i)) || + ((filter & OSDMap::DUMP_IN) && osdmap->is_in(i)) || + ((filter & OSDMap::DUMP_OUT) && osdmap->is_out(i)) || + ((filter & OSDMap::DUMP_DESTROYED) && osdmap->is_destroyed(i))) { + return true; } - return true; + return false; } bool should_dump_empty_bucket() const override { diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index aeda1813fc8b5..268c420152ec1 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -1345,10 +1345,11 @@ public: void print_oneline_summary(ostream& out) const; enum { - DUMP_IN = 1, // only 'in' osds - DUMP_OUT = 2, // only 'out' osds - DUMP_UP = 4, // only 'up' osds - DUMP_DOWN = 8, // only 'down' osds + DUMP_IN = 1, // only 'in' osds + DUMP_OUT = 2, // only 'out' osds + DUMP_UP = 4, // only 'up' osds + DUMP_DOWN = 8, // only 'down' osds + DUMP_DESTROYED = 16, // only 'destroyed' osds }; void print_tree(Formatter *f, ostream *out, unsigned dump_flags=0) const; -- 2.39.5