Skip to content

Commit

Permalink
Merge pull request #12018: hammer: librbd: request exclusive lock if …
Browse files Browse the repository at this point in the history
…current owner cannot execute op

Reviewed-by: Nathan Cutler <ncutler@suse.com>
  • Loading branch information
smithfarm committed Nov 21, 2016
2 parents 0a7fcae + d89b1f8 commit b872dbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librbd/AioCompletion.cc
Expand Up @@ -79,6 +79,8 @@ namespace librbd {
ictx->perfcounter->tinc(l_librbd_aio_discard_latency, elapsed); break;
case AIO_TYPE_FLUSH:
ictx->perfcounter->tinc(l_librbd_aio_flush_latency, elapsed); break;
case AIO_TYPE_NONE:
break;
default:
lderr(cct) << "completed invalid aio_type: " << aio_type << dendl;
break;
Expand Down
27 changes: 27 additions & 0 deletions src/librbd/internal.cc
Expand Up @@ -87,6 +87,23 @@ int prepare_image_update(ImageCtx *ictx) {
return r;
}

void acquire_lock(ImageCtx *ictx) {
assert(ictx->owner_lock.is_locked());
AioCompletion *comp = aio_create_completion();
comp->add_request();
comp->finish_adding_requests(ictx->cct);

ictx->image_watcher->request_lock(
boost::bind(&AioCompletion::complete_request, _1, ictx->cct, 0),
comp);

ictx->owner_lock.put_read();
int r = comp->wait_for_complete();
assert(r == 0);
comp->release();
ictx->owner_lock.get_read();
}

int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
bool permit_snapshot,
const boost::function<int(Context*)>& local_request,
Expand All @@ -104,15 +121,25 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
}
}

bool request_lock = false;
while (ictx->image_watcher->is_lock_supported()) {
if (request_lock) {
acquire_lock(ictx);
}
r = prepare_image_update(ictx);
if (r < 0) {
return -EROFS;
} else if (ictx->image_watcher->is_lock_owner()) {
break;
} else if (request_lock) {
return -EOPNOTSUPP;
}

r = remote_request();
if (r == -EOPNOTSUPP) {
request_lock = true;
continue;
}
if (r != -ETIMEDOUT && r != -ERESTART) {
return r;
}
Expand Down

0 comments on commit b872dbb

Please sign in to comment.