From: zhengyin Date: Mon, 9 Apr 2018 02:50:38 +0000 (+0800) Subject: rbd/info: add snapshot count in rbd info X-Git-Tag: v14.0.0~155^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a7fa1cbb7ec0622d50a038c7be625f79194dc359;p=ceph.git rbd/info: add snapshot count in rbd info Signed-off-by: Zheng Yin --- diff --git a/src/test/cli-integration/rbd/formatted-output.t b/src/test/cli-integration/rbd/formatted-output.t index 697af56fd3f0..9c50d2d34fb7 100644 --- a/src/test/cli-integration/rbd/formatted-output.t +++ b/src/test/cli-integration/rbd/formatted-output.t @@ -58,6 +58,7 @@ For now, use a more inclusive regex. rbd image 'foo': \tsize 1GiB in 256 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 1 (esc) [^^]+ (re) \tformat: 1 (esc) $ rbd info foo --format json | python -mjson.tool | sed 's/,$/, /' @@ -69,7 +70,8 @@ For now, use a more inclusive regex. "object_size": 4194304, "objects": 256, "order": 22, - "size": 1073741824 + "size": 1073741824, + "snapshot_count": 1 } The version of xml_pp included in ubuntu precise always prints a 'warning' whenever it is run. grep -v to ignore it, but still work on other distros. @@ -81,6 +83,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 256 22 4194304 + 1 rb.0.* (glob) 1 @@ -88,6 +91,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'foo': \tsize 1GiB in 256 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 1 (esc) [^^]+ (re) \tformat: 1 (esc) \tprotected: False (esc) @@ -101,7 +105,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "objects": 256, "order": 22, "protected": "false", - "size": 1073741824 + "size": 1073741824, + "snapshot_count": 1 } $ rbd info foo@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -111,6 +116,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 256 22 4194304 + 1 rb.0* (glob) 1 false @@ -119,6 +125,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'bar': \tsize 1GiB in 256 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 2 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -145,7 +152,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "objects": 256, "op_features": [], "order": 22, - "size": 1073741824 + "size": 1073741824, + "snapshot_count": 2 } $ rbd info bar --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -155,6 +163,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 256 22 4194304 + 2 rbd_data.* (glob) 2 @@ -172,6 +181,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'bar': \tsize 512MiB in 128 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 2 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -200,7 +210,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "op_features": [], "order": 22, "protected": "true", - "size": 536870912 + "size": 536870912, + "snapshot_count": 2 } $ rbd info bar@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -210,6 +221,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 128 22 4194304 + 2 rbd_data.* (glob) 2 @@ -228,6 +240,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'bar': \tsize 1GiB in 256 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 2 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -256,7 +269,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "op_features": [], "order": 22, "protected": "false", - "size": 1073741824 + "size": 1073741824, + "snapshot_count": 2 } $ rbd info bar@snap2 --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -266,6 +280,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 256 22 4194304 + 2 rbd_data.* (glob) 2 @@ -284,6 +299,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'baz': \tsize 2GiB in 512 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 0 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -306,7 +322,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "objects": 512, "op_features": [], "order": 22, - "size": 2147483648 + "size": 2147483648, + "snapshot_count": 0 } $ rbd info baz --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -316,6 +333,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 512 22 4194304 + 0 rbd_data.* (glob) 2 @@ -329,6 +347,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'quux': \tsize 1MiB in 1 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 0 (esc) [^^]+ (re) \tformat: 1 (esc) $ rbd info quux --format json | python -mjson.tool | sed 's/,$/, /' @@ -340,7 +359,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "object_size": 4194304, "objects": 1, "order": 22, - "size": 1048576 + "size": 1048576, + "snapshot_count": 0 } $ rbd info quux --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -350,6 +370,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 1 22 4194304 + 0 rb.0.* (glob) 1 @@ -357,6 +378,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'child': \tsize 512MiB in 128 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 1 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -382,7 +404,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "objects": 128, "op_features": [], "order": 22, - "size": 536870912 + "size": 536870912, + "snapshot_count": 1 } $ rbd info rbd_other/child --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -392,6 +415,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 128 22 4194304 + 1 rbd_data.* (glob) 2 @@ -408,6 +432,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'child': \tsize 512MiB in 128 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 1 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -443,7 +468,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "snapshot": "snap" }, "protected": "false", - "size": 536870912 + "size": 536870912, + "snapshot_count": 1 } $ rbd info rbd_other/child@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -453,6 +479,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 128 22 4194304 + 1 rbd_data.* (glob) 2 @@ -476,6 +503,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'deep-flatten-child': \tsize 512MiB in 128 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 1 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -502,7 +530,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "objects": 128, "op_features": [], "order": 22, - "size": 536870912 + "size": 536870912, + "snapshot_count": 1 } $ rbd info rbd_other/deep-flatten-child --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -512,6 +541,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 128 22 4194304 + 1 rbd_data.* (glob) 2 @@ -529,6 +559,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. rbd image 'deep-flatten-child': \tsize 512MiB in 128 objects (esc) \torder 22 (4MiB objects) (esc) + \tsnapshot_count: 1 (esc) \tid:* (glob) [^^]+ (re) \tformat: 2 (esc) @@ -557,7 +588,8 @@ whenever it is run. grep -v to ignore it, but still work on other distros. "op_features": [], "order": 22, "protected": "false", - "size": 536870912 + "size": 536870912, + "snapshot_count": 1 } $ rbd info rbd_other/deep-flatten-child@snap --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp' @@ -567,6 +599,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. 128 22 4194304 + 1 rbd_data.* (glob) 2 diff --git a/src/tools/rbd/action/Info.cc b/src/tools/rbd/action/Info.cc index 0cd29ca67e86..79440bda8d8d 100644 --- a/src/tools/rbd/action/Info.cc +++ b/src/tools/rbd/action/Info.cc @@ -82,6 +82,7 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image, uint64_t overlap, features, flags, snap_limit; bool snap_protected = false; librbd::mirror_image_info_t mirror_image; + std::vector snaps; int r; std::string imgname; @@ -89,6 +90,10 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image, if (r < 0) return r; + r = image.snap_list(snaps); + if (r < 0) + return r; + r = image.stat(info, sizeof(info)); if (r < 0) return r; @@ -197,6 +202,7 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image, f->dump_unsigned("objects", info.num_objs); f->dump_int("order", info.order); f->dump_unsigned("object_size", info.obj_size); + f->dump_int("snapshot_count", snaps.size()); if (!data_pool.empty()) { f->dump_string("data_pool", data_pool); } @@ -209,6 +215,8 @@ static int do_show_info(librados::IoCtx &io_ctx, librbd::Image& image, << std::endl << "\torder " << info.order << " (" << byte_u_t(info.obj_size) << " objects)" + << std::endl + << "\tsnapshot_count: " << snaps.size() << std::endl; if (!imgid.empty()) { std::cout << "\tid: " << imgid << std::endl;