]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: ls -l format tweaks:
authorDan Mick <dan.mick@inktank.com>
Fri, 5 Oct 2012 18:29:39 +0000 (11:29 -0700)
committerDan Mick <dan.mick@inktank.com>
Fri, 5 Oct 2012 21:57:08 +0000 (14:57 -0700)
Add PROT and LOCK columns, for protection status and presence of any
locks of type "excl" or "shr" (lock list for the gory details)

Shrink FORMAT to FMT

Remove TYPE column; one can infer type from presence of @ in name (snap)
or presence of parent (clone)

Dump prettybyte_t in favor of new si_t for compactness

Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
src/rbd.cc

index de37955680e22f5b29d15f3018a438571fb12c31..67a260d65f4e03f32437f260211c06a471446808 100644 (file)
@@ -178,10 +178,11 @@ static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool lflag)
 
   TextTable tbl;
   tbl.define_column("NAME", TextTable::LEFT, TextTable::LEFT);
-  tbl.define_column("TYPE", TextTable::LEFT, TextTable::LEFT);
   tbl.define_column("SIZE", TextTable::RIGHT, TextTable::RIGHT);
   tbl.define_column("PARENT", TextTable::LEFT, TextTable::LEFT);
-  tbl.define_column("FORMAT", TextTable::RIGHT, TextTable::RIGHT);
+  tbl.define_column("FMT", TextTable::RIGHT, TextTable::RIGHT);
+  tbl.define_column("PROT", TextTable::LEFT, TextTable::LEFT);
+  tbl.define_column("LOCK", TextTable::LEFT, TextTable::LEFT);
 
   string pool, image, snap, parent;
 
@@ -207,27 +208,43 @@ static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool lflag)
     uint8_t old_format;
     im.old_format(&old_format);
 
+    list<librbd::locker_t> lockers;
+    bool exclusive;
+    r = im.list_lockers(&lockers, &exclusive, NULL);
+    if (r < 0)
+      return r;
+    string lockstr;
+    if (lockers.size()) {
+      lockstr = (exclusive) ? "excl" : "shr";
+    }
+
     tbl << *i
-       << ((parent.length()) ? "clone" : "image")
-       << stringify(prettybyte_t(info.size))
+       << stringify(si_t(info.size))
        << parent
        << ((old_format) ? '1' : '2')
+       << ""                           // protect doesn't apply to images
+       << lockstr
        << TextTable::endrow;
 
     vector<librbd::snap_info_t> snaplist;
     if (im.snap_list(snaplist) >= 0 && !snaplist.empty()) {
       for (std::vector<librbd::snap_info_t>::iterator s = snaplist.begin();
            s != snaplist.end(); ++s) {
+       bool is_protected;
        parent.clear();
        im.snap_set(s->name.c_str());
+        r = im.snap_is_protected(s->name.c_str(), &is_protected);
+       if (r < 0)
+         return r;
        if (im.parent_info(&pool, &image, &snap) >= 0) {
          parent = pool + "/" + image + "@" + snap;
        }
         tbl << *i + "@" + s->name
-            << "snap"
-           << stringify(prettybyte_t(s->size))
+           << stringify(si_t(s->size))
            << parent
            << ((old_format) ? '1' : '2')
+           << (is_protected ? "yes" : "")
+           << ""                       // locks don't apply to snaps
            << TextTable::endrow;
       }
     }