Skip to content

Commit

Permalink
osdmap: split osd listing to functions
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Eduardo Luis <[email protected]>
  • Loading branch information
jecluis authored and Joao Eduardo Luis committed Jul 15, 2019
1 parent 35cb8dc commit d8b0896
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 54 deletions.
135 changes: 83 additions & 52 deletions src/osd/OSDMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3371,6 +3371,54 @@ void OSDMap::dump_erasure_code_profiles(
f->close_section();
}

void OSDMap::dump_osds(Formatter *f) const
{
f->open_array_section("osds");
for (int i=0; i<get_max_osd(); i++) {
if (exists(i)) {
dump_osd(i, f);
}
}
f->close_section();
}

void OSDMap::dump_osd(int id, Formatter *f) const
{
ceph_assert(f != nullptr);
if (!exists(id)) {
return;
}

f->open_object_section("osd_info");
f->dump_int("osd", id);
f->dump_stream("uuid") << get_uuid(id);
f->dump_int("up", is_up(id));
f->dump_int("in", is_in(id));
f->dump_float("weight", get_weightf(id));
f->dump_float("primary_affinity", get_primary_affinityf(id));
get_info(id).dump(f);
f->dump_object("public_addrs", get_addrs(id));
f->dump_object("cluster_addrs", get_cluster_addrs(id));
f->dump_object("heartbeat_back_addrs", get_hb_back_addrs(id));
f->dump_object("heartbeat_front_addrs", get_hb_front_addrs(id));
// compat
f->dump_stream("public_addr") << get_addrs(id).get_legacy_str();
f->dump_stream("cluster_addr") << get_cluster_addrs(id).get_legacy_str();
f->dump_stream("heartbeat_back_addr")
<< get_hb_back_addrs(id).get_legacy_str();
f->dump_stream("heartbeat_front_addr")
<< get_hb_front_addrs(id).get_legacy_str();

set<string> st;
get_state(id, st);
f->open_array_section("state");
for (const auto &state : st)
f->dump_string("state", state);
f->close_section();

f->close_section();
}

void OSDMap::dump(Formatter *f) const
{
f->dump_int("epoch", get_epoch());
Expand Down Expand Up @@ -3416,39 +3464,7 @@ void OSDMap::dump(Formatter *f) const
}
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);
f->dump_stream("uuid") << get_uuid(i);
f->dump_int("up", is_up(i));
f->dump_int("in", is_in(i));
f->dump_float("weight", get_weightf(i));
f->dump_float("primary_affinity", get_primary_affinityf(i));
get_info(i).dump(f);
f->dump_object("public_addrs", get_addrs(i));
f->dump_object("cluster_addrs", get_cluster_addrs(i));
f->dump_object("heartbeat_back_addrs", get_hb_back_addrs(i));
f->dump_object("heartbeat_front_addrs", get_hb_front_addrs(i));
// compat
f->dump_stream("public_addr") << get_addrs(i).get_legacy_str();
f->dump_stream("cluster_addr") << get_cluster_addrs(i).get_legacy_str();
f->dump_stream("heartbeat_back_addr")
<< get_hb_back_addrs(i).get_legacy_str();
f->dump_stream("heartbeat_front_addr")
<< get_hb_front_addrs(i).get_legacy_str();

set<string> st;
get_state(i, st);
f->open_array_section("state");
for (const auto &state : st)
f->dump_string("state", state);
f->close_section();

f->close_section();
}
f->close_section();
dump_osds(f);

f->open_array_section("osd_xinfo");
for (int i=0; i<get_max_osd(); i++) {
Expand Down Expand Up @@ -3678,6 +3694,39 @@ void OSDMap::print_pools(ostream& out) const
out << std::endl;
}

void OSDMap::print_osds(ostream& out) const
{
for (int i=0; i<get_max_osd(); i++) {
if (exists(i)) {
print_osd(i, out);
}
}
}
void OSDMap::print_osd(int id, ostream& out) const
{
if (!exists(id)) {
return;
}

out << "osd." << id;
out << (is_up(id) ? " up ":" down");
out << (is_in(id) ? " in ":" out");
out << " weight " << get_weightf(id);
if (get_primary_affinity(id) != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY) {
out << " primary_affinity " << get_primary_affinityf(id);
}
const osd_info_t& info(get_info(id));
out << " " << info;
out << " " << get_addrs(id) << " " << get_cluster_addrs(id);
set<string> st;
get_state(id, st);
out << " " << st;
if (!get_uuid(id).is_zero()) {
out << " " << get_uuid(id);
}
out << "\n";
}

void OSDMap::print(ostream& out) const
{
out << "epoch " << get_epoch() << "\n"
Expand Down Expand Up @@ -3707,25 +3756,7 @@ void OSDMap::print(ostream& out) const
print_pools(out);

out << "max_osd " << get_max_osd() << "\n";
for (int i=0; i<get_max_osd(); i++) {
if (exists(i)) {
out << "osd." << i;
out << (is_up(i) ? " up ":" down");
out << (is_in(i) ? " in ":" out");
out << " weight " << get_weightf(i);
if (get_primary_affinity(i) != CEPH_OSD_DEFAULT_PRIMARY_AFFINITY)
out << " primary_affinity " << get_primary_affinityf(i);
const osd_info_t& info(get_info(i));
out << " " << info;
out << " " << get_addrs(i) << " " << get_cluster_addrs(i);
set<string> st;
get_state(i, st);
out << " " << st;
if (!get_uuid(i).is_zero())
out << " " << get_uuid(i);
out << "\n";
}
}
print_osds(out);
out << std::endl;

for (auto& p : pg_upmap) {
Expand Down
10 changes: 8 additions & 2 deletions src/osd/OSDMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,8 +1504,11 @@ class OSDMap {
void print_osd_line(int cur, std::ostream *out, ceph::Formatter *f) const;
public:
void print(std::ostream& out) const;
void print_osd(int id, std::ostream& out) const;
void print_osds(std::ostream& out) const;
void print_pools(std::ostream& out) const;
void print_summary(ceph::Formatter *f, std::ostream& out, const std::string& prefix, bool extra=false) const;
void print_summary(ceph::Formatter *f, std::ostream& out,
const std::string& prefix, bool extra=false) const;
void print_oneline_summary(std::ostream& out) const;

enum {
Expand All @@ -1515,7 +1518,8 @@ class OSDMap {
DUMP_DOWN = 8, // only 'down' osds
DUMP_DESTROYED = 16, // only 'destroyed' osds
};
void print_tree(ceph::Formatter *f, std::ostream *out, unsigned dump_flags=0, std::string bucket="") const;
void print_tree(ceph::Formatter *f, std::ostream *out,
unsigned dump_flags=0, std::string bucket="") const;

int summarize_mapping_stats(
OSDMap *newmap,
Expand All @@ -1529,6 +1533,8 @@ class OSDMap {
const mempool::osdmap::map<std::string,std::map<std::string,std::string> > &profiles,
ceph::Formatter *f);
void dump(ceph::Formatter *f) const;
void dump_osd(int id, ceph::Formatter *f) const;
void dump_osds(ceph::Formatter *f) const;
static void generate_test_instances(std::list<OSDMap*>& o);
bool check_new_blacklist_entries() const { return new_blacklist_entries; }

Expand Down

0 comments on commit d8b0896

Please sign in to comment.