mirror of
https://github.com/ceph/ceph
synced 2025-02-23 02:57:21 +00:00
rbd: add protected in snap list
Signed-off-by: Zheng Yin <zhengyin@cmss.chinamobile.com>
This commit is contained in:
parent
c25ef2a7ee
commit
76673a76d7
@ -900,13 +900,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": ""
|
||||
}
|
||||
@ -917,24 +918,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)
|
||||
}
|
||||
@ -945,12 +949,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>
|
||||
@ -960,13 +966,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)
|
||||
}
|
||||
@ -977,6 +984,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>
|
||||
|
@ -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, ×tamp);
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user