From 2c79a4939090d445a8172dbbe4d4072a4851ddcf Mon Sep 17 00:00:00 2001 From: songweibin Date: Sat, 18 Aug 2018 08:50:24 +0800 Subject: [PATCH 1/2] rbd: fix error purging non-user snapshots Fixes: [root@ ~]# rbd snap rm img1@snap1 [root@ ~]# rbd snap ls img1 -a SNAPID NAME SIZE TIMESTAMP NAMESPACE 4 f2e82bd1-e2ff-4a6b-aaef-5a12a2b23a30 100 MiB Sat Aug 18 08:48:34 2018 trash (snap1) [root@ ~]# rbd snap purge img1 Removing all snapshots: 0% complete...failed. rbd: removing snaps failed: (2) No such file or directory Signed-off-by: songweibin --- src/tools/rbd/action/Snap.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/rbd/action/Snap.cc b/src/tools/rbd/action/Snap.cc index df337b66b91..b08891908d2 100644 --- a/src/tools/rbd/action/Snap.cc +++ b/src/tools/rbd/action/Snap.cc @@ -204,6 +204,10 @@ int do_purge_snaps(librbd::Image& image, bool no_progress) return 0; } else { list 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) { From 91c67b2a8d12ac03173a8e060dec1278f26b338a Mon Sep 17 00:00:00 2001 From: songweibin Date: Sat, 18 Aug 2018 09:05:03 +0800 Subject: [PATCH 2/2] rbd: fix error processing images which have non-user snapshots Signed-off-by: songweibin --- src/tools/rbd/action/List.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tools/rbd/action/List.cc b/src/tools/rbd/action/List.cc index f6b26c032ca..ce67396b694 100644 --- a/src/tools/rbd/action/List.cc +++ b/src/tools/rbd/action/List.cc @@ -11,6 +11,7 @@ #include "common/Formatter.h" #include "common/TextTable.h" #include +#include #include #include "global/global_context.h" @@ -101,6 +102,10 @@ int list_process_image(librados::Rados* rados, WorkerEntry* w, bool lflag, Forma std::vector 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::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("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; }