r = 0;
}
else if (m->cmd[1] == "dump" ||
+ m->cmd[1] == "dump_json" ||
m->cmd[1] == "tree" ||
m->cmd[1] == "getmap" ||
m->cmd[1] == "getcrushmap") {
p->print(ds);
rdata.append(ds);
ss << "dumped osdmap epoch " << p->get_epoch();
+ } else if (m->cmd[1] == "dump_json") {
+ stringstream ds;
+ p->dump_json(ds);
+ rdata.append(ds);
+ ss << "dumped osdmap tree epoch " << p->get_epoch();
} else if (m->cmd[1] == "tree") {
stringstream ds;
p->print_tree(ds);
#include "OSDMap.h"
#include "common/config.h"
+#include "common/Formatter.h"
+void osd_info_t::dump(Formatter *f) const
+{
+ f->dump_int("last_clean_first", last_clean_first);
+ f->dump_int("last_clean_last", last_clean_last);
+ f->dump_int("up_from", up_from);
+ f->dump_int("up_thru", up_thru);
+ f->dump_int("down_at", down_at);
+ f->dump_int("lost_at", lost_at);
+}
+
+void OSDMap::dump_json(ostream& out) const
+{
+ JSONFormatter jsf(true);
+ jsf.open_object_section("osdmap");
+ dump(&jsf);
+ jsf.close_section();
+ jsf.flush(out);
+}
+
+void OSDMap::dump(Formatter *f) const
+{
+ f->dump_int("epoch", get_epoch());
+ f->dump_stream("fsid") << get_fsid();
+ f->dump_stream("created") << get_created();
+ f->dump_stream("modified") << get_modified();
+ f->dump_string("flags", get_flag_string());
+ f->dump_string("cluster_snapshot", get_cluster_snapshot());
+ f->dump_int("max_osd", get_max_osd());
+
+ f->open_array_section("pools");
+ for (map<int,pg_pool_t>::const_iterator p = pools.begin(); p != pools.end(); ++p) {
+ f->open_object_section("pool");
+ f->dump_int("pool", p->first);
+ p->second.dump(f);
+ f->close_section();
+ }
+ f->close_section();
+
+ f->open_array_section("osds");
+ for (int i=0; i<get_max_osd(); i++)
+ if (exists(i)) {
+ f->open_object_section("osd_info");
+ f->dump_int("osd", i);
+ get_info(i).dump(f);
+ f->close_section();
+ }
+ f->close_section();
+
+ f->open_array_section("pg_temp");
+ for (map<pg_t,vector<int> >::const_iterator p = pg_temp.begin();
+ p != pg_temp.end();
+ p++) {
+ f->open_array_section("osds");
+ for (vector<int>::const_iterator q = p->second.begin(); q != p->second.end(); ++q)
+ f->dump_int("osd", *q);
+ f->close_section();
+ }
+ f->close_section();
+
+ f->open_array_section("blacklist");
+ for (hash_map<entity_addr_t,utime_t>::const_iterator p = blacklist.begin();
+ p != blacklist.end();
+ p++) {
+ stringstream ss;
+ ss << p->first;
+ f->dump_stream(ss.str().c_str()) << p->second;
+ }
+ f->close_section();
+}
+
+string OSDMap::get_flag_string() const
+{
+ string s;
+ if (test_flag(CEPH_OSDMAP_NEARFULL))
+ s += ",nearfull";
+ if (test_flag(CEPH_OSDMAP_FULL))
+ s += ",full";
+ if (test_flag(CEPH_OSDMAP_PAUSERD))
+ s += ",pauserd";
+ if (test_flag(CEPH_OSDMAP_PAUSEWR))
+ s += ",pausewr";
+ if (test_flag(CEPH_OSDMAP_PAUSEREC))
+ s += ",pauserec";
+ if (s.length())
+ s = s.erase(0, 1);
+ return s;
+}
+
struct qi {
int item;
int depth;
qi(int i, int d, float w) : item(i), depth(d), weight(w) {}
};
-
void OSDMap::print(ostream& out) const
{
out << "epoch " << get_epoch() << "\n"
<< "created " << get_created() << "\n"
<< "modifed " << get_modified() << "\n";
- out << "flags";
- if (test_flag(CEPH_OSDMAP_NEARFULL))
- out << " nearfull";
- if (test_flag(CEPH_OSDMAP_FULL))
- out << " full";
- if (test_flag(CEPH_OSDMAP_PAUSERD))
- out << " pauserd";
- if (test_flag(CEPH_OSDMAP_PAUSEWR))
- out << " pausewr";
- if (test_flag(CEPH_OSDMAP_PAUSEREC))
- out << " pauserec";
- out << "\n";
+ out << "flags " << get_flag_string() << "\n";
if (get_cluster_snapshot().length())
out << "cluster_snapshot " << get_cluster_snapshot() << "\n";
out << "\n";
osd_info_t() : last_clean_first(0), last_clean_last(0),
up_from(0), up_thru(0), down_at(0), lost_at(0) {}
+
+ void dump(Formatter *f) const;
+
void encode(bufferlist& bl) const {
__u8 struct_v = 1;
::encode(struct_v, bl);
void print_summary(ostream& out) const;
void print_tree(ostream& out) const;
+ string get_flag_string() const;
+ void dump_json(ostream& out) const;
+ void dump(Formatter *f) const;
+
};
inline ostream& operator<<(ostream& out, const OSDMap& m) {
#include "include/types.h"
#include "include/CompatSet.h"
#include "include/interval_set.h"
-
+#include "common/Formatter.h"
utime_t stamp;
string name;
+ void dump(Formatter *f) const {
+ f->dump_unsigned("snapid", snapid);
+ f->dump_stream("stamp") << stamp;
+ f->dump_string("name", name);
+ }
+
void encode(bufferlist& bl) const {
__u8 struct_v = 1;
::encode(struct_v, bl);
memset(&v, 0, sizeof(v));
}
+ void dump(Formatter *f) const {
+ f->dump_int("type", get_type());
+ f->dump_int("size", get_size());
+ f->dump_int("crush_ruleset", get_crush_ruleset());
+ f->dump_int("object_hash", get_object_hash());
+ f->dump_int("pg_num", get_pg_num());
+ f->dump_int("pg_placement_num", get_pgp_num());
+ f->dump_int("localized_pg_num", get_lpg_num());
+ f->dump_int("localized_pg_placement_num", get_lpgp_num());
+ f->dump_stream("last_change") << get_last_change();
+ f->dump_unsigned("auid", get_auid());
+ f->dump_string("snap_mode", is_pool_snaps_mode() ? "pool" : "selfmanaged");
+ f->dump_unsigned("snap_seq", get_snap_seq());
+ f->dump_unsigned("snap_epoch", get_snap_epoch());
+ f->open_object_section("pool_snaps");
+ for (map<snapid_t, pool_snap_info_t>::const_iterator p = snaps.begin(); p != snaps.end(); ++p) {
+ f->open_object_section("pool_snap_info");
+ p->second.dump(f);
+ f->close_section();
+ }
+ f->close_section();
+ f->dump_stream("removed_snaps") << removed_snaps;
+ }
+
unsigned get_type() const { return v.type; }
unsigned get_size() const { return v.size; }
int get_crush_ruleset() const { return v.crush_ruleset; }
epoch_t get_last_change() const { return v.last_change; }
epoch_t get_snap_epoch() const { return v.snap_epoch; }
snapid_t get_snap_seq() const { return snapid_t(v.snap_seq); }
+ uint64_t get_auid() const { return v.auid; }
void set_snap_seq(snapid_t s) { v.snap_seq = s; }
void set_snap_epoch(epoch_t e) { v.snap_epoch = e; }
const char *fn = 0;
bool print = false;
+ bool print_json = false;
bool tree = false;
bool createsimple = false;
int num_osd = 0, num_dom = 0;
usage();
} else if (CEPH_ARGPARSE_EQ("print", 'p')) {
CEPH_ARGPARSE_SET_ARG_VAL(&print, OPT_BOOL);
+ } else if (CEPH_ARGPARSE_EQ("dump_json", '\0')) {
+ CEPH_ARGPARSE_SET_ARG_VAL(&print_json, OPT_BOOL);
} else if (CEPH_ARGPARSE_EQ("tree", '\0')) {
CEPH_ARGPARSE_SET_ARG_VAL(&tree, OPT_BOOL);
} else if (CEPH_ARGPARSE_EQ("createsimple", '\0')) {
}
}
- if (!print && !tree && !modified && !export_crush && !import_crush && !test_map_pg && !test_map_object) {
+ if (!print && !print_json && !tree && !modified && !export_crush && !import_crush && !test_map_pg && !test_map_object) {
cerr << me << ": no action specified?" << std::endl;
usage();
}
if (print)
osdmap.print(cout);
+ if (print_json)
+ osdmap.dump_json(cout);
if (tree)
osdmap.print_tree(cout);