Merge pull request #23853 from zy751713126/add_protect_snapshot_list

rbd: add protected in snap list

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2018-09-11 20:47:52 -04:00 committed by GitHub
commit c74432d031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View File

@ -948,13 +948,14 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
</lock>
</locks>
$ rbd snap list foo
SNAPID*NAME*SIZE*TIMESTAMP* (glob)
SNAPID*NAME*SIZE*PROTECTED*TIMESTAMP* (glob)
*snap*1 GiB* (glob)
$ rbd snap list foo --format json | python -mjson.tool | sed 's/,$/, /'
[
{
"id": *, (glob)
"name": "snap",
"protected": "false",
"size": 1073741824,
"timestamp": ""
}
@ -965,24 +966,27 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<id>*</id> (glob)
<name>snap</name>
<size>1073741824</size>
<protected>false</protected>
<timestamp></timestamp>
</snapshot>
</snapshots>
$ rbd snap list bar
SNAPID*NAME*SIZE*TIMESTAMP* (glob)
*snap*512 MiB* (glob)
SNAPID*NAME*SIZE*PROTECTED*TIMESTAMP* (glob)
*snap*512 MiB*yes* (glob)
*snap2*1 GiB* (glob)
$ rbd snap list bar --format json | python -mjson.tool | sed 's/,$/, /'
[
{
"id": *, (glob)
"name": "snap",
"protected": "true",
"size": 536870912,
"timestamp": * (glob)
},
{
"id": *, (glob)
"name": "snap2",
"protected": "false",
"size": 1073741824,
"timestamp": * (glob)
}
@ -993,12 +997,14 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<id>*</id> (glob)
<name>snap</name>
<size>536870912</size>
<protected>true</protected>
<timestamp>*</timestamp> (glob)
</snapshot>
<snapshot>
<id>*</id> (glob)
<name>snap2</name>
<size>1073741824</size>
<protected>false</protected>
<timestamp>*</timestamp> (glob)
</snapshot>
</snapshots>
@ -1008,13 +1014,14 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
$ rbd snap list baz --format xml | xml_pp 2>&1 | grep -v '^new version at /usr/bin/xml_pp'
<snapshots></snapshots>
$ rbd snap list rbd_other/child
SNAPID*NAME*SIZE*TIMESTAMP* (glob)
SNAPID*NAME*SIZE*PROTECTED*TIMESTAMP* (glob)
*snap*512 MiB* (glob)
$ rbd snap list rbd_other/child --format json | python -mjson.tool | sed 's/,$/, /'
[
{
"id": *, (glob)
"name": "snap",
"protected": "false",
"size": 536870912,
"timestamp": * (glob)
}
@ -1025,6 +1032,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros.
<id>*</id> (glob)
<name>snap</name>
<size>536870912</size>
<protected>false</protected>
<timestamp>*</timestamp> (glob)
</snapshot>
</snapshots>

View File

@ -47,7 +47,8 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
t.define_column("SNAPID", TextTable::LEFT, TextTable::RIGHT);
t.define_column("NAME", TextTable::LEFT, TextTable::LEFT);
t.define_column("SIZE", TextTable::LEFT, TextTable::RIGHT);
t.define_column("TIMESTAMP", TextTable::LEFT, TextTable::LEFT);
t.define_column("PROTECTED", TextTable::LEFT, TextTable::LEFT);
t.define_column("TIMESTAMP", TextTable::LEFT, TextTable::RIGHT);
if (all_snaps) {
t.define_column("NAMESPACE", TextTable::LEFT, TextTable::LEFT);
}
@ -60,6 +61,7 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
for (std::vector<librbd::snap_info_t>::iterator s = snaps.begin();
s != snaps.end(); ++s) {
struct timespec timestamp;
bool snap_protected = false;
image.snap_get_timestamp(s->id, &timestamp);
string tt_str = "";
if(timestamp.tv_sec != 0) {
@ -100,11 +102,22 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
s->id, &trash_original_name);
}
std::string protected_str = "";
if (snap_namespace == RBD_SNAP_NAMESPACE_TYPE_USER) {
r = image.snap_is_protected(s->name.c_str(), &snap_protected);
if (r < 0) {
std::cerr << "rbd: unable to retrieve snap protection" << std::endl;
return r;
}
}
if (f) {
protected_str = snap_protected ? "true" : "false";
f->open_object_section("snapshot");
f->dump_unsigned("id", s->id);
f->dump_string("name", s->name);
f->dump_unsigned("size", s->size);
f->dump_string("protected", protected_str);
f->dump_string("timestamp", tt_str);
if (all_snaps) {
f->open_object_section("namespace");
@ -121,7 +134,8 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
}
f->close_section();
} else {
t << s->id << s->name << stringify(byte_u_t(s->size)) << tt_str;
protected_str = snap_protected ? "yes" : "";
t << s->id << s->name << stringify(byte_u_t(s->size)) << protected_str << tt_str;
if (all_snaps) {
ostringstream oss;