]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: operations should return -EROFS if disabled 19903/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 12 Jan 2018 15:46:33 +0000 (10:46 -0500)
committerJason Dillaman <dillaman@redhat.com>
Fri, 12 Jan 2018 15:46:33 +0000 (10:46 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/Operations.cc
src/librbd/image/CloneRequest.cc
src/librbd/image/RemoveRequest.cc

index 1c052eb129a7e43e8981e4c8cd6b3f06096cbfe9..7fe6cb6b9e33c845f5ce56de6b14adbf22f8b010 100644 (file)
@@ -373,7 +373,7 @@ void Operations<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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<I> *req =
       new operation::EnableFeaturesRequest<I>(
@@ -1402,6 +1444,11 @@ void Operations<I>::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<I> *request =
     new operation::MetadataSetRequest<I>(m_image_ctx,
                                         new C_NotifyUpdate<I>(m_image_ctx, on_finish),
@@ -1462,6 +1509,11 @@ void Operations<I>::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<I> *request =
     new operation::MetadataRemoveRequest<I>(
        m_image_ctx,
index d1ab9e4f19e9c6a55f547c2a66c51a40554890db..abf3b86fd07ab7c5ec65239f98477b9e674dbc74 100644 (file)
@@ -90,6 +90,12 @@ template <typename I>
 void CloneRequest<I>::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);
index 5782702d78f926640edc68b57e7088764e181e16..83e3b48be70a368f378d34a991e1ca577f026569 100644 (file)
@@ -90,6 +90,12 @@ void RemoveRequest<I>::handle_open_image(int r) {
 
 template<typename I>
 void RemoveRequest<I>::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) {