From 075c321a7a1fd6e288f68d30125d4de245c9eaa6 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Fri, 5 Oct 2012 11:29:39 -0700 Subject: [PATCH] rbd: ls -l format tweaks: 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 Reviewed-by: Josh Durgin --- src/rbd.cc | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/rbd.cc b/src/rbd.cc index de37955680e..67a260d65f4 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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 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 snaplist; if (im.snap_list(snaplist) >= 0 && !snaplist.empty()) { for (std::vector::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; } }