]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: unprotect any non-unprotected snapshot
authorJosh Durgin <josh.durgin@inktank.com>
Tue, 12 Feb 2013 01:08:55 +0000 (17:08 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Wed, 13 Feb 2013 00:43:36 +0000 (16:43 -0800)
Include snapshots in the UNPROTECTING state as well, which can occur
after an unprotect is interrupted.

Fixes: #4100
Backport: bobtail
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/internal.cc

index cffc556c1d45b75cfffe17da45712ec99506ffb6..7909f8c620ca2207c513b93b3507a1f06065ea9a 100644 (file)
@@ -332,6 +332,19 @@ namespace librbd {
     return -ENOENT;
   }
 
+  int ImageCtx::is_snap_unprotected(string in_snap_name,
+                                   bool *is_unprotected) const
+  {
+    assert(snap_lock.is_locked());
+    map<string, SnapInfo>::const_iterator it = snaps_by_name.find(in_snap_name);
+    if (it != snaps_by_name.end()) {
+      *is_unprotected =
+       (it->second.protection_status == RBD_PROTECTION_STATUS_UNPROTECTED);
+      return 0;
+    }
+    return -ENOENT;
+  }
+
   int ImageCtx::get_snap_size(string in_snap_name, uint64_t *out_size) const
   {
     assert(snap_lock.is_locked());
index ed03846fcde3b1ab9cefde4cfcbc83fb55716281..b24639906b2f7efc6b83c55492b41fc7b928beb0 100644 (file)
@@ -104,6 +104,7 @@ namespace librbd {
     int get_parent_spec(snapid_t snap_id, parent_spec *pspec);
     int get_snap_size(std::string in_snap_name, uint64_t *out_size) const;
     int is_snap_protected(string in_snap_name, bool *is_protected) const;
+    int is_snap_unprotected(string in_snap_name, bool *is_unprotected) const;
 
     uint64_t get_current_size() const;
     uint64_t get_object_size() const;
index 663556e49a3c5021d9db355223a0a459644d3b65..fdadf6f6753f2c459cf6ba65068d193510c92b17 100644 (file)
@@ -585,12 +585,12 @@ namespace librbd {
     if (snap_id == CEPH_NOSNAP)
       return -ENOENT;
 
-    bool is_protected;
-    r = ictx->is_snap_protected(snap_name, &is_protected);
+    bool is_unprotected;
+    r = ictx->is_snap_unprotected(snap_name, &is_unprotected);
     if (r < 0)
       return r;
 
-    if (!is_protected)
+    if (is_unprotected)
       return -EINVAL;
 
     r = cls_client::set_protection_status(&ictx->md_ctx,
@@ -662,7 +662,12 @@ reprotect_and_return_err:
       return r;
 
     Mutex::Locker l(ictx->snap_lock);
-    return ictx->is_snap_protected(snap_name, is_protected);
+    bool is_unprotected;
+    r = ictx->is_snap_unprotected(snap_name, &is_unprotected);
+    // consider both PROTECTED or UNPROTECTING to be 'protected',
+    // since in either state they can't be deleted
+    *is_protected = !is_unprotected;
+    return r;
   }
 
   int create_v1(IoCtx& io_ctx, const char *imgname, uint64_t bid,