From f05c977bbcd310a83e6df03344a72d4cc06e1cc3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 10 Sep 2014 08:07:53 -0700 Subject: [PATCH] mon: add 'osd pool ls [detail]' command This is much friendlier than ceph osd dump | grep ^pool Signed-off-by: Sage Weil --- qa/workunits/cephtool/test.sh | 7 +++++++ src/mon/MonCommands.h | 3 +++ src/mon/OSDMonitor.cc | 31 +++++++++++++++++++++++++++++++ src/osd/OSDMap.cc | 27 ++++++++++++++++----------- src/osd/OSDMap.h | 1 + 5 files changed, 58 insertions(+), 11 deletions(-) diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 97b2b3d3c4eb..1c81b8f74811 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -185,6 +185,11 @@ function test_tiering() ceph osd tier add slow cache2 --force-nonempty ceph osd tier remove slow cache2 + ceph osd pool ls | grep cache2 + ceph osd pool ls -f json-pretty | grep cache2 + ceph osd pool ls detail | grep cache2 + ceph osd pool ls detail -f json-pretty | grep cache2 + ceph osd pool delete cache cache --yes-i-really-really-mean-it ceph osd pool delete cache2 cache2 --yes-i-really-really-mean-it @@ -193,7 +198,9 @@ function test_tiering() ceph osd tier add-cache slow cache3 1024000 ceph osd dump | grep cache3 | grep bloom | grep 'false_positive_probability: 0.05' | grep 'target_bytes 1024000' | grep '1200s x4' ceph osd tier remove slow cache3 + ceph osd pool ls | grep cache3 ceph osd pool delete cache3 cache3 --yes-i-really-really-mean-it + expect_false ceph osd pool ls | grep cache3 ceph osd pool delete slow2 slow2 --yes-i-really-really-mean-it ceph osd pool delete slow slow --yes-i-really-really-mean-it diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index d7026150bd56..3436fdc81184 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -554,6 +554,9 @@ COMMAND("osd pool rmsnap " \ "name=pool,type=CephPoolname " \ "name=snap,type=CephString", \ "remove snapshot from ", "osd", "rw", "cli,rest") +COMMAND("osd pool ls " \ + "name=detail,type=CephChoices,strings=detail,req=false", \ + "list pools", "osd", "r", "cli,rest") COMMAND("osd pool create " \ "name=pool,type=CephPoolname " \ "name=pg_num,type=CephInt,range=0 " \ diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 25a5bc7fc05c..6c2255fdfa1a 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2568,6 +2568,37 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) } ss << "listed " << osdmap.blacklist.size() << " entries"; + } else if (prefix == "osd pool ls") { + string detail; + cmd_getval(g_ceph_context, cmdmap, "detail", detail); + if (!f && detail == "detail") { + ostringstream ss; + osdmap.print_pools(ss); + rdata.append(ss.str()); + } else { + if (f) + f->open_array_section("pools"); + for (map::const_iterator it = osdmap.get_pools().begin(); + it != osdmap.get_pools().end(); + ++it) { + if (f) { + if (detail == "detail") { + f->open_object_section("pool"); + f->dump_string("pool_name", osdmap.get_pool_name(it->first)); + it->second.dump(f.get()); + f->close_section(); + } else { + f->dump_string("pool_name", osdmap.get_pool_name(it->first)); + } + } else { + rdata.append(osdmap.get_pool_name(it->first) + "\n"); + } + } + if (f) { + f->close_section(); + f->flush(rdata); + } + } } else if (prefix == "osd pool get") { string poolstr; cmd_getval(g_ceph_context, cmdmap, "pool", poolstr); diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index fb55a8150d9d..a8bfdfcac63f 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -2237,18 +2237,8 @@ struct qi { qi(int i, int d, float w) : item(i), depth(d), weight(w) {} }; -void OSDMap::print(ostream& out) const +void OSDMap::print_pools(ostream& out) const { - out << "epoch " << get_epoch() << "\n" - << "fsid " << get_fsid() << "\n" - << "created " << get_created() << "\n" - << "modified " << get_modified() << "\n"; - - out << "flags " << get_flag_string() << "\n"; - if (get_cluster_snapshot().length()) - out << "cluster_snapshot " << get_cluster_snapshot() << "\n"; - out << "\n"; - for (map::const_iterator p = pools.begin(); p != pools.end(); ++p) { std::string name(""); map::const_iterator pni = pool_name.find(p->first); @@ -2265,6 +2255,21 @@ void OSDMap::print(ostream& out) const out << "\tremoved_snaps " << p->second.removed_snaps << "\n"; } out << std::endl; +} + +void OSDMap::print(ostream& out) const +{ + out << "epoch " << get_epoch() << "\n" + << "fsid " << get_fsid() << "\n" + << "created " << get_created() << "\n" + << "modified " << get_modified() << "\n"; + + out << "flags " << get_flag_string() << "\n"; + if (get_cluster_snapshot().length()) + out << "cluster_snapshot " << get_cluster_snapshot() << "\n"; + out << "\n"; + + print_pools(out); out << "max_osd " << get_max_osd() << "\n"; for (int i=0; i