]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add error message "snapshot is already protected" 9464/head
authorVikhyat Umrao <vumrao@redhat.com>
Thu, 2 Jun 2016 17:15:48 +0000 (22:45 +0530)
committerVikhyat Umrao <vumrao@redhat.com>
Tue, 7 Jun 2016 03:36:25 +0000 (09:06 +0530)
Fixes: http://tracker.ceph.com/issues/15807
Signed-off-by: Vikhyat Umrao <vumrao@redhat.com>
src/tools/rbd/action/Snap.cc

index 345e747fb9ca11d28cd82da1bc84331a041db1e5..1818e4ed313b0bd1cb357790a41494f5fffdbae9 100644 (file)
@@ -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) {