From: Jason Dillaman Date: Fri, 12 Jan 2018 15:46:33 +0000 (-0500) Subject: librbd: operations should return -EROFS if disabled X-Git-Tag: v13.0.2~531^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ffdb65374c9fbd7dc2fc34570852acb97e2f62ec;p=ceph.git librbd: operations should return -EROFS if disabled Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/Operations.cc b/src/librbd/Operations.cc index 1c052eb129a7..7fe6cb6b9e33 100644 --- a/src/librbd/Operations.cc +++ b/src/librbd/Operations.cc @@ -373,7 +373,7 @@ void Operations::execute_flatten(ProgressContext &prog_ctx, CephContext *cct = m_image_ctx.cct; ldout(cct, 20) << "flatten" << dendl; - if (m_image_ctx.read_only) { + if (m_image_ctx.read_only || m_image_ctx.operations_disabled) { on_finish->complete(-EROFS); return; } @@ -452,10 +452,11 @@ void Operations::execute_rebuild_object_map(ProgressContext &prog_ctx, CephContext *cct = m_image_ctx.cct; ldout(cct, 5) << this << " " << __func__ << dendl; - if (m_image_ctx.read_only) { + if (m_image_ctx.read_only || m_image_ctx.operations_disabled) { on_finish->complete(-EROFS); return; } + if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP)) { lderr(cct) << "image must support object-map feature" << dendl; on_finish->complete(-EINVAL); @@ -563,6 +564,11 @@ void Operations::execute_rename(const std::string &dest_name, m_image_ctx.exclusive_lock->is_lock_owner()); } + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); if (m_image_ctx.name == dest_name) { m_image_ctx.snap_lock.put_read(); @@ -646,7 +652,8 @@ void Operations::execute_resize(uint64_t size, bool allow_shrink, ProgressCon << "size=" << m_image_ctx.size << ", " << "new_size=" << size << dendl; - if (m_image_ctx.snap_id != CEPH_NOSNAP || m_image_ctx.read_only) { + if (m_image_ctx.snap_id != CEPH_NOSNAP || m_image_ctx.read_only || + m_image_ctx.operations_disabled) { m_image_ctx.snap_lock.put_read(); on_finish->complete(-EROFS); return; @@ -734,6 +741,11 @@ void Operations::execute_snap_create(const cls::rbd::SnapshotNamespace &snap_ ldout(cct, 5) << this << " " << __func__ << ": snap_name=" << snap_name << dendl; + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); if (m_image_ctx.get_snap_id(snap_namespace, snap_name) != CEPH_NOSNAP) { m_image_ctx.snap_lock.put_read(); @@ -809,6 +821,11 @@ void Operations::execute_snap_rollback(const cls::rbd::SnapshotNamespace& sna ldout(cct, 5) << this << " " << __func__ << ": snap_name=" << snap_name << dendl; + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); uint64_t snap_id = m_image_ctx.get_snap_id(snap_namespace, snap_name); if (snap_id == CEPH_NOSNAP) { @@ -908,6 +925,11 @@ void Operations::execute_snap_remove(const cls::rbd::SnapshotNamespace& snap_ ldout(cct, 5) << this << " " << __func__ << ": snap_name=" << snap_name << dendl; + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); uint64_t snap_id = m_image_ctx.get_snap_id(snap_namespace, snap_name); if (snap_id == CEPH_NOSNAP) { @@ -1002,6 +1024,11 @@ void Operations::execute_snap_rename(const uint64_t src_snap_id, m_image_ctx.exclusive_lock->is_lock_owner()); } + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); if (m_image_ctx.get_snap_id(cls::rbd::UserSnapshotNamespace(), dest_snap_name) != CEPH_NOSNAP) { @@ -1094,6 +1121,11 @@ void Operations::execute_snap_protect(const cls::rbd::SnapshotNamespace& snap m_image_ctx.exclusive_lock->is_lock_owner()); } + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); bool is_protected; int r = m_image_ctx.is_snap_protected(m_image_ctx.get_snap_id(snap_namespace, snap_name), @@ -1184,6 +1216,11 @@ void Operations::execute_snap_unprotect(const cls::rbd::SnapshotNamespace& sn m_image_ctx.exclusive_lock->is_lock_owner()); } + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + m_image_ctx.snap_lock.get_read(); bool is_unprotected; int r = m_image_ctx.is_snap_unprotected(m_image_ctx.get_snap_id(snap_namespace, snap_name), @@ -1333,6 +1370,11 @@ void Operations::execute_update_features(uint64_t features, bool enabled, ldout(cct, 5) << this << " " << __func__ << ": features=" << features << ", enabled=" << enabled << dendl; + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + if (enabled) { operation::EnableFeaturesRequest *req = new operation::EnableFeaturesRequest( @@ -1402,6 +1444,11 @@ void Operations::execute_metadata_set(const std::string &key, ldout(cct, 5) << this << " " << __func__ << ": key=" << key << ", value=" << value << dendl; + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + operation::MetadataSetRequest *request = new operation::MetadataSetRequest(m_image_ctx, new C_NotifyUpdate(m_image_ctx, on_finish), @@ -1462,6 +1509,11 @@ void Operations::execute_metadata_remove(const std::string &key, CephContext *cct = m_image_ctx.cct; ldout(cct, 5) << this << " " << __func__ << ": key=" << key << dendl; + if (m_image_ctx.operations_disabled) { + on_finish->complete(-EROFS); + return; + } + operation::MetadataRemoveRequest *request = new operation::MetadataRemoveRequest( m_image_ctx, diff --git a/src/librbd/image/CloneRequest.cc b/src/librbd/image/CloneRequest.cc index d1ab9e4f19e9..abf3b86fd07a 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -90,6 +90,12 @@ template void CloneRequest::send_validate_parent() { ldout(m_cct, 20) << this << " " << __func__ << dendl; + if (m_p_imctx->operations_disabled) { + lderr(m_cct) << "image operations disabled due to unsupported op features" << dendl; + complete(-EROFS); + return; + } + if (m_p_imctx->snap_id == CEPH_NOSNAP) { lderr(m_cct) << "image to be cloned must be a snapshot" << dendl; complete(-EINVAL); diff --git a/src/librbd/image/RemoveRequest.cc b/src/librbd/image/RemoveRequest.cc index 5782702d78f9..83e3b48be70a 100644 --- a/src/librbd/image/RemoveRequest.cc +++ b/src/librbd/image/RemoveRequest.cc @@ -90,6 +90,12 @@ void RemoveRequest::handle_open_image(int r) { template void RemoveRequest::check_exclusive_lock() { + if (m_image_ctx->operations_disabled) { + lderr(m_cct) << "image operations disabled due to unsupported op features" << dendl; + finish(-EROFS); + return; + } + ldout(m_cct, 20) << dendl; if (m_image_ctx->exclusive_lock == nullptr) {