Skip to content

Commit

Permalink
librbd: avoid canceling object map / header updates
Browse files Browse the repository at this point in the history
During a resize, reduce the possibility that the object map
and the header will get out-of-sync during a resize operation
that is canceled.

Signed-off-by: Jason Dillaman <[email protected]>
  • Loading branch information
Jason Dillaman authored and jdurgin committed Mar 10, 2015
1 parent 85737ab commit 7f246b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librbd/AsyncRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AsyncRequest
virtual ~AsyncRequest();

void complete(int r) {
if (m_canceled) {
if (m_canceled && safely_cancel(r)) {
m_on_finish->complete(-ERESTART);
delete this;
} else if (should_complete(r)) {
Expand All @@ -44,6 +44,9 @@ class AsyncRequest
librados::AioCompletion *create_callback_completion();
Context *create_callback_context();

virtual bool safely_cancel(int r) {
return true;
}
virtual bool should_complete(int r) = 0;

private:
Expand Down
17 changes: 17 additions & 0 deletions src/librbd/AsyncResizeRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ AsyncResizeRequest::~AsyncResizeRequest() {
}
}

bool AsyncResizeRequest::safely_cancel(int r) {
CephContext *cct = m_image_ctx.cct;
ldout(cct, 5) << this << " safely_cancel: " << " r=" << r << dendl;

// avoid interrupting the object map / header updates
switch (m_state) {
case STATE_GROW_OBJECT_MAP:
case STATE_UPDATE_HEADER:
case STATE_SHRINK_OBJECT_MAP:
ldout(cct, 5) << "delaying cancel request" << dendl;
return false;
default:
break;
}
return true;
}

bool AsyncResizeRequest::should_complete(int r) {
CephContext *cct = m_image_ctx.cct;
ldout(cct, 5) << this << " should_complete: " << " r=" << r << dendl;
Expand Down
1 change: 1 addition & 0 deletions src/librbd/AsyncResizeRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class AsyncResizeRequest : public AsyncRequest

xlist<AsyncResizeRequest *>::item m_xlist_item;

virtual bool safely_cancel(int r);
virtual bool should_complete(int r);

void send_flush();
Expand Down

0 comments on commit 7f246b8

Please sign in to comment.