From a00720d9aac309a34801b5ef68e28bed1a7501ea Mon Sep 17 00:00:00 2001 From: Vikhyat Umrao Date: Thu, 2 Jun 2016 22:45:48 +0530 Subject: [PATCH] rbd: add error message "snapshot is already protected" Fixes: http://tracker.ceph.com/issues/15807 Signed-off-by: Vikhyat Umrao --- src/tools/rbd/action/Snap.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tools/rbd/action/Snap.cc b/src/tools/rbd/action/Snap.cc index 345e747fb9c..1818e4ed313 100644 --- a/src/tools/rbd/action/Snap.cc +++ b/src/tools/rbd/action/Snap.cc @@ -365,6 +365,17 @@ int execute_protect(const po::variables_map &vm) { return r; } + bool is_protected = false; + r = image.snap_is_protected(snap_name.c_str(), &is_protected); + if (r < 0) { + std::cerr << "rbd: protecting snap failed: " << cpp_strerror(r) + << std::endl; + return r; + } else if (is_protected) { + std::cerr << "rbd: snap is already protected" << std::endl; + return -EBUSY; + } + r = do_protect_snap(image, snap_name.c_str()); if (r < 0) { std::cerr << "rbd: protecting snap failed: " << cpp_strerror(r) @@ -399,6 +410,17 @@ int execute_unprotect(const po::variables_map &vm) { if (r < 0) { return r; } + + bool is_protected = false; + r = image.snap_is_protected(snap_name.c_str(), &is_protected); + if (r < 0) { + std::cerr << "rbd: unprotecting snap failed: " << cpp_strerror(r) + << std::endl; + return r; + } else if (!is_protected) { + std::cerr << "rbd: snap is already unprotected" << std::endl; + return -EINVAL; + } r = do_unprotect_snap(image, snap_name.c_str()); if (r < 0) {