Merge pull request #2452 from ceph/wip-pool-ls

mon: add 'osd pool ls [detail]' command

Reviewed-by: Joao Eduardo Luis <joao@redhat.com>
This commit is contained in:
João Eduardo Luís 2014-10-01 16:22:42 +00:00
commit 46166eefe6
5 changed files with 58 additions and 11 deletions

View File

@ -203,6 +203,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
@ -211,7 +216,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

View File

@ -554,6 +554,9 @@ COMMAND("osd pool rmsnap " \
"name=pool,type=CephPoolname " \
"name=snap,type=CephString", \
"remove snapshot <snap> from <pool>", "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 " \

View File

@ -2582,6 +2582,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<int64_t,pg_pool_t>::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);

View File

@ -2248,18 +2248,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<int64_t,pg_pool_t>::const_iterator p = pools.begin(); p != pools.end(); ++p) {
std::string name("<unknown>");
map<int64_t,string>::const_iterator pni = pool_name.find(p->first);
@ -2276,6 +2266,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<get_max_osd(); i++) {

View File

@ -810,6 +810,7 @@ private:
void print_osd_line(int cur, ostream *out, Formatter *f) const;
public:
void print(ostream& out) const;
void print_pools(ostream& out) const;
void print_summary(Formatter *f, ostream& out) const;
void print_oneline_summary(ostream& out) const;
void print_tree(ostream *out, Formatter *f) const;