summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Durgin <josh.durgin@inktank.com>2013-02-11 17:08:55 -0800
committerSage Weil <sage@inktank.com>2013-02-12 21:44:20 -0800
commitf21543f0d88f7bacb69cef3712b0ce087f386e93 (patch)
tree4564e22b8e3c3f9a03ebce8d4e1426cdb5dd9e15
parent65969f8fbef02ee39f6c2365fffbcd3f633f4b37 (diff)
downloadceph-f21543f0d88f7bacb69cef3712b0ce087f386e93.tar.gz
librbd: unprotect any non-unprotected snapshot
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> (cherry picked from commit fe283813b44a7c45def6768ea0788a3a0635957e)
-rw-r--r--src/librbd/ImageCtx.cc13
-rw-r--r--src/librbd/ImageCtx.h1
-rw-r--r--src/librbd/internal.cc13
3 files changed, 23 insertions, 4 deletions
diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc
index 7a44a6a53e8..75ccccbc67c 100644
--- a/src/librbd/ImageCtx.cc
+++ b/src/librbd/ImageCtx.cc
@@ -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());
diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h
index ed03846fcde..b24639906b2 100644
--- a/src/librbd/ImageCtx.h
+++ b/src/librbd/ImageCtx.h
@@ -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;
diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc
index c12b653a01d..9fdfcd85c5a 100644
--- a/src/librbd/internal.cc
+++ b/src/librbd/internal.cc
@@ -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,