]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: Use Image::list_watchers to get watchers in 'rbd status'
authorAdam Wolfe Gordon <awg@digitalocean.com>
Thu, 23 Nov 2017 23:02:22 +0000 (23:02 +0000)
committerAdam Wolfe Gordon <awg@digitalocean.com>
Mon, 27 Nov 2017 16:31:39 +0000 (16:31 +0000)
Signed-off-by: Adam Wolfe Gordon <awg@digitalocean.com>
src/tools/rbd/action/Status.cc

index 7cd438a6ee7a7f96c9e6c5451c9fe3849407f89f..0b6f9945926d50ca111e5a8384b78e67de06deb2 100644 (file)
@@ -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<obj_watch_t> watchers;
+  std::list<librbd::image_watcher_t> 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<obj_watch_t>::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<obj_watch_t>::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;