mirror of
https://github.com/ceph/ceph
synced 2024-12-29 06:52:35 +00:00
rbd: resolve names of snapshot namespaces
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
parent
e69ca3a01a
commit
afc9274e63
@ -40,8 +40,10 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
|
||||
int r;
|
||||
|
||||
r = image.snap_list(snaps);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
std::cerr << "rbd: unable to list snapshots" << std::endl;
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!all_snaps) {
|
||||
snaps.erase(remove_if(snaps.begin(),
|
||||
@ -76,9 +78,33 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
|
||||
tt_str = ctime(&tt);
|
||||
tt_str = tt_str.substr(0, tt_str.length() - 1);
|
||||
}
|
||||
|
||||
librbd::snap_namespace_type_t snap_namespace;
|
||||
r = image.snap_get_namespace_type(s->id, &snap_namespace);
|
||||
if (r < 0) {
|
||||
std::cerr << "rbd: unable to retrieve snap namespace" << std::endl;
|
||||
return r;
|
||||
}
|
||||
|
||||
std::string snap_namespace_name = "Unknown";
|
||||
switch (snap_namespace) {
|
||||
case RBD_SNAP_NAMESPACE_TYPE_USER:
|
||||
snap_namespace_name = "user";
|
||||
break;
|
||||
case RBD_SNAP_NAMESPACE_TYPE_GROUP:
|
||||
snap_namespace_name = "group";
|
||||
break;
|
||||
case RBD_SNAP_NAMESPACE_TYPE_TRASH:
|
||||
snap_namespace_name = "trash";
|
||||
break;
|
||||
}
|
||||
|
||||
int get_group_res = -ENOENT;
|
||||
librbd::snap_group_namespace_t group_snap;
|
||||
int get_group_res = image.snap_get_group_namespace(s->id, &group_snap,
|
||||
sizeof(group_snap));
|
||||
if (snap_namespace == RBD_SNAP_NAMESPACE_TYPE_GROUP) {
|
||||
get_group_res = image.snap_get_group_namespace(s->id, &group_snap,
|
||||
sizeof(group_snap));
|
||||
}
|
||||
|
||||
if (f) {
|
||||
f->open_object_section("snapshot");
|
||||
@ -88,6 +114,7 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
|
||||
f->dump_string("timestamp", tt_str);
|
||||
if (all_snaps) {
|
||||
f->open_object_section("namespace");
|
||||
f->dump_string("type", snap_namespace_name);
|
||||
if (get_group_res == 0) {
|
||||
std::string pool_name = pool_map[group_snap.group_pool];
|
||||
f->dump_string("pool", pool_name);
|
||||
@ -98,19 +125,20 @@ int do_list_snaps(librbd::Image& image, Formatter *f, bool all_snaps, librados::
|
||||
}
|
||||
f->close_section();
|
||||
} else {
|
||||
std::string namespace_string;
|
||||
if (all_snaps && (get_group_res == 0)) {
|
||||
ostringstream oss;
|
||||
std::string pool_name = pool_map[group_snap.group_pool];
|
||||
oss << "group snapshot (" << pool_name << "/" <<
|
||||
group_snap.group_name << "@" <<
|
||||
group_snap.group_snap_name << ")";
|
||||
|
||||
namespace_string = oss.str();
|
||||
}
|
||||
t << s->id << s->name << stringify(prettybyte_t(s->size)) << tt_str;
|
||||
|
||||
if (all_snaps) {
|
||||
t << namespace_string;
|
||||
ostringstream oss;
|
||||
oss << snap_namespace_name;
|
||||
|
||||
if (get_group_res == 0) {
|
||||
std::string pool_name = pool_map[group_snap.group_pool];
|
||||
oss << " (" << pool_name << "/"
|
||||
<< group_snap.group_name << "@"
|
||||
<< group_snap.group_snap_name << ")";
|
||||
}
|
||||
|
||||
t << oss.str();
|
||||
}
|
||||
t << TextTable::endrow;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user