From d00891f9a2bc041963cc1f60d0b4a2ea30133b75 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 2 Feb 2015 23:37:35 -0500 Subject: [PATCH] rbd: add image flags to 'rbd info' The 'rbd info' CLI tool now includes the image's flags. Signed-off-by: Jason Dillaman --- src/rbd.cc | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/rbd.cc b/src/rbd.cc index dee1367c420aa..806b739287776 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -208,6 +209,39 @@ static void format_features(Formatter *f, uint64_t features) f->close_section(); } +static void format_flags(Formatter *f, uint64_t flags) +{ + int count = 0; + std::map flag_mapping = boost::assign::map_list_of( + RBD_FLAG_OBJECT_MAP_INVALID, "object map invalid"); + + if (f == NULL) { + cout << "\tflags: "; + } else { + f->open_array_section("flags"); + } + for (std::map::iterator it = flag_mapping.begin(); + it != flag_mapping.end(); ++it) { + if ((it->first & flags) == 0) { + continue; + } + + if (f == NULL) { + if (count++ > 0) { + cout << ", "; + } + cout << it->second; + } else { + f->dump_string("flag", it->second); + } + } + if (f == NULL) { + cout << std::endl; + } else { + f->close_section(); + } +} + struct MyProgressContext : public librbd::ProgressContext { const char *operation; int last_pc; @@ -504,7 +538,7 @@ static int do_show_info(const char *imgname, librbd::Image& image, librbd::image_info_t info; string parent_pool, parent_name, parent_snapname; uint8_t old_format; - uint64_t overlap, features; + uint64_t overlap, features, flags; bool snap_protected = false; int r; @@ -524,6 +558,11 @@ static int do_show_info(const char *imgname, librbd::Image& image, if (r < 0) return r; + r = image.get_flags(&flags); + if (r < 0) { + return r; + } + if (snapname) { r = image.snap_is_protected(snapname, &snap_protected); if (r < 0) @@ -562,6 +601,7 @@ static int do_show_info(const char *imgname, librbd::Image& image, format_features(f, features); else cout << "\tfeatures: " << features_str(features) << std::endl; + format_flags(f, flags); } // snapshot info, if present -- 2.39.5