From: Adam Wolfe Gordon Date: Thu, 23 Nov 2017 23:02:22 +0000 (+0000) Subject: rbd: Use Image::list_watchers to get watchers in 'rbd status' X-Git-Tag: v13.0.2~846^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=79fadbe2f218dbc5a642239a5d360db37c979762;p=ceph.git rbd: Use Image::list_watchers to get watchers in 'rbd status' Signed-off-by: Adam Wolfe Gordon --- diff --git a/src/tools/rbd/action/Status.cc b/src/tools/rbd/action/Status.cc index 7cd438a6ee7..0b6f9945926 100644 --- a/src/tools/rbd/action/Status.cc +++ b/src/tools/rbd/action/Status.cc @@ -17,32 +17,12 @@ namespace status { namespace at = argument_types; namespace po = boost::program_options; -static int do_show_status(librados::IoCtx &io_ctx, librbd::Image &image, - const char *imgname, Formatter *f) +static int do_show_status(librbd::Image &image, Formatter *f) { - uint8_t old_format; int r; - std::string header_oid; - std::list watchers; + std::list watchers; - r = image.old_format(&old_format); - if (r < 0) - return r; - - if (old_format) { - header_oid = imgname; - header_oid += RBD_SUFFIX; - } else { - std::string id; - r = image.get_id(&id); - if (r < 0) { - return r; - } - - header_oid = RBD_HEADER_PREFIX + id; - } - - r = io_ctx.list_watchers(header_oid, &watchers); + r = image.list_watchers(watchers); if (r < 0) return r; @@ -51,21 +31,20 @@ static int do_show_status(librados::IoCtx &io_ctx, librbd::Image &image, if (f) { f->open_array_section("watchers"); - for (std::list::iterator i = watchers.begin(); i != watchers.end(); ++i) { + for (auto &watcher : watchers) { f->open_object_section("watcher"); - f->dump_string("address", i->addr); - f->dump_unsigned("client", i->watcher_id); - f->dump_unsigned("cookie", i->cookie); + f->dump_string("address", watcher.addr); + f->dump_unsigned("client", watcher.id); + f->dump_unsigned("cookie", watcher.cookie); f->close_section(); } f->close_section(); } else { if (watchers.size()) { std::cout << "Watchers:" << std::endl; - for (std::list::iterator i = watchers.begin(); - i != watchers.end(); ++i) { - std::cout << "\twatcher=" << i->addr << " client." << i->watcher_id - << " cookie=" << i->cookie << std::endl; + for (auto &watcher : watchers) { + std::cout << "\twatcher=" << watcher.addr << " client." << watcher.id + << " cookie=" << watcher.cookie << std::endl; } } else { std::cout << "Watchers: none" << std::endl; @@ -112,7 +91,7 @@ int execute(const po::variables_map &vm) { return r; } - r = do_show_status(io_ctx, image, image_name.c_str(), formatter.get()); + r = do_show_status(image, formatter.get()); if (r < 0) { std::cerr << "rbd: show status failed: " << cpp_strerror(r) << std::endl; return r;