Merge pull request #23638 from Songweibin/wip-filter-user-snapshots

rbd: filter out group/trash snapshots from snap_list

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2018-08-21 14:37:25 -04:00 committed by GitHub
commit 4d7c6cc111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -11,6 +11,7 @@
#include "common/Formatter.h"
#include "common/TextTable.h"
#include <iostream>
#include <boost/bind.hpp>
#include <boost/program_options.hpp>
#include "global/global_context.h"
@ -101,6 +102,10 @@ int list_process_image(librados::Rados* rados, WorkerEntry* w, bool lflag, Forma
std::vector<librbd::snap_info_t> snaplist;
if (w->img.snap_list(snaplist) >= 0 && !snaplist.empty()) {
snaplist.erase(remove_if(snaplist.begin(),
snaplist.end(),
boost::bind(utils::is_not_user_snap_namespace, &w->img, _1)),
snaplist.end());
for (std::vector<librbd::snap_info_t>::iterator s = snaplist.begin();
s != snaplist.end(); ++s) {
bool is_protected;
@ -245,7 +250,7 @@ int do_list(const std::string &pool_name, const std::string& namespace_name,
}
r = list_process_image(&rados, comp, lflag, f, tbl);
if (r < 0) {
std::cerr << "rbd: error processing image " << comp->name << ": " << cpp_strerror(r)
std::cerr << "rbd: error processing image " << comp->name << ": " << cpp_strerror(r)
<< std::endl;
}
comp->completion = new librbd::RBD::AioCompletion(nullptr, nullptr);
@ -300,7 +305,7 @@ int execute(const po::variables_map &vm,
g_conf().get_val<int64_t>("rbd_concurrent_management_ops"),
formatter.get());
if (r < 0) {
std::cerr << "rbd: list: " << cpp_strerror(r) << std::endl;
std::cerr << "rbd: listing images failed : " << cpp_strerror(r) << std::endl;
return r;
}

View File

@ -204,6 +204,10 @@ int do_purge_snaps(librbd::Image& image, bool no_progress)
return 0;
} else {
list<std::string> protect;
snaps.erase(remove_if(snaps.begin(),
snaps.end(),
boost::bind(utils::is_not_user_snap_namespace, &image, _1)),
snaps.end());
for (auto it = snaps.begin(); it != snaps.end();) {
r = image.snap_is_protected(it->name.c_str(), &is_protected);
if (r < 0) {