From d54c44350b02f0c7de221237ff16b4b1d36c12ad Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 6 Oct 2016 14:49:25 -0400 Subject: [PATCH] rbd: include data pool name within info command Signed-off-by: Jason Dillaman --- src/tools/rbd/action/Info.cc | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/tools/rbd/action/Info.cc b/src/tools/rbd/action/Info.cc index cb0542bfc3a9c..59ce6c9aefecf 100644 --- a/src/tools/rbd/action/Info.cc +++ b/src/tools/rbd/action/Info.cc @@ -64,8 +64,8 @@ static void format_flags(Formatter *f, uint64_t flags) format_bitmask(f, "flag", mapping, flags); } -static int do_show_info(const char *imgname, librbd::Image& image, - const char *snapname, Formatter *f) +static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image, + const char *imgname, const char *snapname, Formatter *f) { librbd::image_info_t info; std::string parent_pool, parent_name, parent_snapname; @@ -83,6 +83,21 @@ static int do_show_info(const char *imgname, librbd::Image& image, if (r < 0) return r; + std::string data_pool; + if (!old_format) { + int64_t data_pool_id = image.get_data_pool_id(); + if (data_pool_id != io_ctx.get_id()) { + librados::Rados rados(io_ctx); + librados::IoCtx data_io_ctx; + r = rados.ioctx_create2(data_pool_id, data_io_ctx); + if (r < 0) { + data_pool = ""; + } else { + data_pool = data_io_ctx.get_pool_name(); + } + } + } + r = image.overlap(&overlap); if (r < 0) return r; @@ -132,6 +147,9 @@ static int do_show_info(const char *imgname, librbd::Image& image, f->dump_unsigned("objects", info.num_objs); f->dump_int("order", info.order); f->dump_unsigned("object_size", info.obj_size); + if (!data_pool.empty()) { + f->dump_string("data_pool", data_pool); + } f->dump_string("block_name_prefix", prefix); f->dump_int("format", (old_format ? 1 : 2)); } else { @@ -141,8 +159,11 @@ static int do_show_info(const char *imgname, librbd::Image& image, << std::endl << "\torder " << info.order << " (" << prettybyte_t(info.obj_size) << " objects)" - << std::endl - << "\tblock_name_prefix: " << prefix + << std::endl; + if (!data_pool.empty()) { + std::cout << "\tdata_pool: " << data_pool << std::endl; + } + std::cout << "\tblock_name_prefix: " << prefix << std::endl << "\tformat: " << (old_format ? "1" : "2") << std::endl; @@ -282,7 +303,7 @@ int execute(const po::variables_map &vm) { return r; } - r = do_show_info(image_name.c_str(), image, + r = do_show_info(io_ctx, image, image_name.c_str(), snap_name.empty() ? nullptr : snap_name.c_str(), formatter.get()); if (r < 0) { -- 2.39.5