summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Dillaman <dillaman@redhat.com>2018-05-10 20:55:38 +0200
committerJason Dillaman <dillaman@redhat.com>2018-05-10 20:55:53 +0200
commitce7afd435e039265671fe4a2685c88785cb8d57c (patch)
treed47690c2bcca351b2d07faca8a2601cb02b1e3fb
parentceph_release: nautilus (diff)
parentrbd/info: add snapshot count in rbd info (diff)
downloadceph-ce7afd435e039265671fe4a2685c88785cb8d57c.tar.xz
ceph-ce7afd435e039265671fe4a2685c88785cb8d57c.zip
Merge pull request #21292 from zy751713126/snapshot_count
rbd: add snapshot count in rbd info Reviewed-by: Jason Dillaman <dillaman@redhat.com>
-rw-r--r--src/test/cli-integration/rbd/formatted-output.t55
-rw-r--r--src/tools/rbd/action/Info.cc8
2 files changed, 52 insertions, 11 deletions
diff --git a/src/test/cli-integration/rbd/formatted-output.t b/src/test/cli-integration/rbd/formatted-output.t
index 697af56fd3f..9c50d2d34fb 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.
<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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -350,6 +370,7 @@ 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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
@@ -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'
<image>
@@ -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>
diff --git a/src/tools/rbd/action/Info.cc b/src/tools/rbd/action/Info.cc
index 0cd29ca67e8..79440bda8d8 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<librbd::snap_info_t> 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;