]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: list parent info with "--long" when image child is in trash
authorsongweibin <song.weibin@zte.com.cn>
Tue, 5 Dec 2017 01:53:31 +0000 (09:53 +0800)
committersongweibin <song.weibin@zte.com.cn>
Tue, 5 Dec 2017 08:41:52 +0000 (16:41 +0800)
We can get child's parent information even it's in
trash bin if "--long" flag is specified.

Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/tools/rbd/action/Trash.cc

index 136ebfacda21eecc0234ff8a01a14196020da002..b023d5c890acef800ce2eb50d68767bb00ee3ba9 100644 (file)
@@ -197,6 +197,7 @@ int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool long_flag,
     tbl.define_column("SOURCE", TextTable::LEFT, TextTable::LEFT);
     tbl.define_column("DELETED_AT", TextTable::LEFT, TextTable::LEFT);
     tbl.define_column("STATUS", TextTable::LEFT, TextTable::LEFT);
+    tbl.define_column("PARENT", TextTable::LEFT, TextTable::LEFT);
   }
 
   for (const auto& entry : trash_entries) {
@@ -233,6 +234,16 @@ int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool long_flag,
     std::string time_str = ctime(&entry.deletion_time);
     time_str = time_str.substr(0, time_str.length() - 1);
 
+    std::string pool, image, snap, parent;
+    r = im.parent_info(&pool, &image, &snap);
+    if (r < 0 && r != -ENOENT)
+      return r;
+    bool has_parent = false;
+    if (r != -ENOENT) {
+      parent = pool + "/" + image + "@" + snap;
+      has_parent = true;
+    }
+
     if (f) {
       f->open_object_section("image");
       f->dump_string("id", entry.id);
@@ -241,14 +252,23 @@ int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool long_flag,
       f->dump_string("deleted_at", time_str);
       f->dump_string("status",
                      delete_status(entry.deferment_end_time));
+      if (has_parent) {
+        f->open_object_section("parent");
+        f->dump_string("pool", pool);
+        f->dump_string("image", image);
+        f->dump_string("snapshot", snap);
+        f->close_section();
+      }
       f->close_section();
     } else {
       tbl << entry.id
           << entry.name
           << del_source
           << time_str
-          << delete_status(entry.deferment_end_time)
-          << TextTable::endrow;
+          << delete_status(entry.deferment_end_time);
+      if (has_parent)
+        tbl << parent;
+      tbl << TextTable::endrow;
     }
   }