From fe283813b44a7c45def6768ea0788a3a0635957e Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 11 Feb 2013 17:08:55 -0800 Subject: [PATCH] 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 Reviewed-by: Dan Mick --- src/librbd/ImageCtx.cc | 13 +++++++++++++ src/librbd/ImageCtx.h | 1 + src/librbd/internal.cc | 13 +++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index cffc556c1d45b..7909f8c620ca2 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::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 ed03846fcde3b..b24639906b2f7 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 663556e49a3c5..fdadf6f6753f2 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, -- 2.39.5