Skip to content

Commit

Permalink
rbd/info: add snapshot count in rbd info
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Yin <zhengyin@huayun.com>
  • Loading branch information
zhengchengyao committed Apr 27, 2018
1 parent 27e91a9 commit 5e83440
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
55 changes: 44 additions & 11 deletions src/test/cli-integration/rbd/formatted-output.t
Expand Up @@ -59,6 +59,7 @@ For now, use a more inclusive regex.
\tsize 1GiB in 256 objects (esc)
\torder 22 (4MiB objects) (esc)
[^^]+ (re)
\tblock_name_prefix: rb.0.* (glob)
\tformat: 1 (esc)
$ rbd info foo --format json | python -mjson.tool | sed 's/,$/, /'
{
Expand All @@ -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.
Expand All @@ -81,6 +83,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>256</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>1</snapshot_count>
<block_name_prefix>rb.0.*</block_name_prefix> (glob)
<format>1</format>
</image>
Expand All @@ -89,6 +92,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
\tsize 1GiB in 256 objects (esc)
\torder 22 (4MiB objects) (esc)
[^^]+ (re)
\tblock_name_prefix: rb.0.* (glob)
\tformat: 1 (esc)
\tprotected: False (esc)
$ rbd info foo@snap --format json | python -mjson.tool | sed 's/,$/, /'
Expand All @@ -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'
<image>
Expand All @@ -111,6 +116,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>256</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>1</snapshot_count>
<block_name_prefix>rb.0*</block_name_prefix> (glob)
<format>1</format>
<protected>false</protected>
Expand All @@ -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)
Expand All @@ -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'
<image>
Expand All @@ -155,6 +163,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>256</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>2</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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)
Expand Down Expand Up @@ -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'
<image>
Expand All @@ -210,6 +221,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>128</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>2</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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)
Expand Down Expand Up @@ -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'
<image>
Expand All @@ -266,6 +280,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>256</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>2</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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)
Expand All @@ -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'
<image>
Expand All @@ -316,6 +333,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>512</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>0</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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/,$/, /'
Expand All @@ -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'
<image>
Expand All @@ -350,13 +370,15 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>1</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>0</snapshot_count>
<block_name_prefix>rb.0.*</block_name_prefix> (glob)
<format>1</format>
</image>
$ rbd info rbd_other/child
rbd image 'child':
\tsize 512MiB in 128 objects (esc)
\torder 22 (4MiB objects) (esc)
\tsnapshot_count: 1 (esc)
\tid:* (glob)
[^^]+ (re)
\tformat: 2 (esc)
Expand All @@ -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'
<image>
Expand All @@ -392,6 +415,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>128</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>1</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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)
Expand Down Expand Up @@ -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'
<image>
Expand All @@ -453,6 +479,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>128</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>1</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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)
Expand All @@ -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'
<image>
Expand All @@ -512,6 +541,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>128</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>1</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand All @@ -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)
Expand Down Expand Up @@ -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'
<image>
Expand All @@ -567,6 +599,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<objects>128</objects>
<order>22</order>
<object_size>4194304</object_size>
<snapshot_count>1</snapshot_count>
<block_name_prefix>rbd_data.*</block_name_prefix> (glob)
<format>2</format>
<features>
Expand Down
8 changes: 8 additions & 0 deletions src/tools/rbd/action/Info.cc
Expand Up @@ -82,13 +82,18 @@ 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<librbd::snap_info_t> snaps;
int r;

std::string imgname;
r = image.get_name(&imgname);
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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit 5e83440

Please sign in to comment.