Skip to content

Commit 95fc1f8

Browse files
committed
rbd: extend use of "none" placeholder to IMAGES section
Currently if there are no mirror-enabled images, IMAGES section in "rbd mirror pool status --verbose" output isn't terminated: $ rbd mirror pool status data --verbose health: OK daemon health: OK image health: OK images: 0 total DAEMONS service 4388: ... health: OK IMAGES$ DAEMONS section has a "none" placeholder for when there are no rbd-mirror daemons running. Fix some issues with the separator logic and employ the placeholder in IMAGES section: $ rbd mirror pool status data --verbose health: OK daemon health: OK image health: OK images: 0 total DAEMONS service 4388: ... health: OK IMAGES none $ $ rbd mirror pool status data --verbose health: UNKNOWN daemon health: UNKNOWN image health: OK images: 0 total DAEMONS none IMAGES none $ Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 3616888 commit 95fc1f8

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/tools/rbd/action/MirrorPool.cc

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,12 @@ class StatusImageRequest : public ImageRequestBase {
606606
const std::vector<librbd::mirror_peer_site_t>& mirror_peers,
607607
const std::map<std::string, std::string> &peer_mirror_uuids_to_name,
608608
const MirrorDaemonServiceInfo &daemon_service_info,
609-
at::Format::Formatter formatter)
609+
at::Format::Formatter formatter, bool* saw_image)
610610
: ImageRequestBase(io_ctx, throttle, image_name),
611611
m_instance_ids(instance_ids), m_mirror_peers(mirror_peers),
612612
m_peer_mirror_uuids_to_name(peer_mirror_uuids_to_name),
613-
m_daemon_service_info(daemon_service_info), m_formatter(formatter) {
613+
m_daemon_service_info(daemon_service_info), m_formatter(formatter),
614+
m_saw_image(saw_image) {
614615
}
615616

616617
protected:
@@ -692,6 +693,7 @@ class StatusImageRequest : public ImageRequestBase {
692693
}
693694
m_formatter->close_section(); // image
694695
} else {
696+
*m_saw_image = true;
695697
std::cout << std::endl
696698
<< m_mirror_image_global_status.name << ":" << std::endl
697699
<< " global_id: "
@@ -741,6 +743,7 @@ class StatusImageRequest : public ImageRequestBase {
741743
const std::map<std::string, std::string> &m_peer_mirror_uuids_to_name;
742744
const MirrorDaemonServiceInfo &m_daemon_service_info;
743745
at::Format::Formatter m_formatter;
746+
bool *m_saw_image;
744747
std::string m_image_id;
745748
librbd::mirror_image_global_status_t m_mirror_image_global_status;
746749
};
@@ -1642,12 +1645,10 @@ int execute_status(const po::variables_map &vm,
16421645
}
16431646
formatter->close_section(); // daemons
16441647
} else {
1645-
std::cout << std::endl << "DAEMONS" << std::endl;
1646-
if (mirror_services.empty()) {
1647-
std::cout << " none" << std::endl;
1648-
}
1648+
std::cout << std::endl << "DAEMONS";
16491649
for (auto& mirror_service : mirror_services) {
1650-
std::cout << "service " << mirror_service.service_id << ":"
1650+
std::cout << std::endl
1651+
<< "service " << mirror_service.service_id << ":"
16511652
<< std::endl
16521653
<< " instance_id: " << mirror_service.instance_id
16531654
<< std::endl
@@ -1660,7 +1661,9 @@ int execute_status(const po::variables_map &vm,
16601661
if (!mirror_service.callouts.empty()) {
16611662
std::cout << " callouts: " << mirror_service.callouts << std::endl;
16621663
}
1663-
std::cout << std::endl;
1664+
}
1665+
if (mirror_services.empty()) {
1666+
std::cout << std::endl << " none" << std::endl;
16641667
}
16651668
}
16661669

@@ -1675,7 +1678,7 @@ int execute_status(const po::variables_map &vm,
16751678
if (formatter != nullptr) {
16761679
formatter->open_array_section("images");
16771680
} else {
1678-
std::cout << "IMAGES";
1681+
std::cout << std::endl << "IMAGES";
16791682
}
16801683

16811684
std::map<std::string, std::string> instance_ids;
@@ -1702,13 +1705,18 @@ int execute_status(const po::variables_map &vm,
17021705
start_image_id = ids.rbegin()->first;
17031706
}
17041707

1708+
bool saw_image = false;
17051709
ImageRequestGenerator<StatusImageRequest> generator(
17061710
io_ctx, instance_ids, mirror_peers, peer_mirror_uuids_to_name,
1707-
daemon_service_info, formatter);
1711+
daemon_service_info, formatter, &saw_image);
17081712
ret = generator.execute();
17091713

17101714
if (formatter != nullptr) {
17111715
formatter->close_section(); // images
1716+
} else {
1717+
if (saw_image == false) {
1718+
std::cout << std::endl << " none" << std::endl;
1719+
}
17121720
}
17131721
}
17141722

0 commit comments

Comments
 (0)