Skip to content

Commit

Permalink
librbd: operations should return -EROFS if disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Jan 12, 2018
1 parent fef8975 commit ffdb653
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
58 changes: 55 additions & 3 deletions src/librbd/Operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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>(
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/librbd/image/CloneRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/librbd/image/RemoveRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ffdb653

Please sign in to comment.