Skip to content

Commit

Permalink
Merge pull request #4206 from ceph/wip-5488-firefly
Browse files Browse the repository at this point in the history
librbd: acquire cache_lock before refreshing parent

Reviewed-by: Josh Durgin <jdurgin@redhat.com>
  • Loading branch information
Loic Dachary committed Apr 27, 2015
2 parents dd15e54 + 364563a commit a860e2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/librbd/ImageCtx.cc
Expand Up @@ -603,9 +603,7 @@ namespace librbd {
void ImageCtx::clear_nonexistence_cache() {
if (!object_cacher)
return;
cache_lock.Lock();
object_cacher->clear_nonexistence(object_set);
cache_lock.Unlock();
}

int ImageCtx::register_watch() {
Expand Down
18 changes: 12 additions & 6 deletions src/librbd/internal.cc
Expand Up @@ -1286,11 +1286,13 @@ namespace librbd {
return r;
}

ictx->parent->cache_lock.Lock();
ictx->parent->snap_lock.get_write();
r = ictx->parent->get_snap_name(parent_snap_id, &ictx->parent->snap_name);
if (r < 0) {
lderr(ictx->cct) << "parent snapshot does not exist" << dendl;
ictx->parent->snap_lock.put_write();
ictx->parent->cache_lock.Unlock();
close_image(ictx->parent);
ictx->parent = NULL;
return r;
Expand All @@ -1304,12 +1306,14 @@ namespace librbd {
<< ictx->parent->snap_name << dendl;
ictx->parent->parent_lock.put_write();
ictx->parent->snap_lock.put_write();
ictx->parent->cache_lock.Unlock();
close_image(ictx->parent);
ictx->parent = NULL;
return r;
}
ictx->parent->parent_lock.put_write();
ictx->parent->snap_lock.put_write();
ictx->parent->cache_lock.Unlock();

return 0;
}
Expand Down Expand Up @@ -1707,10 +1711,11 @@ namespace librbd {
vector<parent_info> snap_parents;
vector<uint8_t> snap_protection;
{
RWLock::WLocker l(ictx->snap_lock);
Mutex::Locker cache_locker(ictx->cache_lock);
RWLock::WLocker snap_locker(ictx->snap_lock);
{
int r;
RWLock::WLocker l2(ictx->parent_lock);
int r;
RWLock::WLocker parent_locker(ictx->parent_lock);
ictx->lockers.clear();
if (ictx->old_format) {
r = read_header(ictx->md_ctx, ictx->header_oid, &ictx->header, NULL);
Expand Down Expand Up @@ -1836,7 +1841,7 @@ namespace librbd {
}

ictx->data_ctx.selfmanaged_snap_set_write_ctx(ictx->snapc.seq, ictx->snaps);
} // release snap_lock
} // release snap_lock and cache_lock

if (new_snap) {
_flush(ictx);
Expand Down Expand Up @@ -2068,8 +2073,9 @@ namespace librbd {

int _snap_set(ImageCtx *ictx, const char *snap_name)
{
RWLock::WLocker l1(ictx->snap_lock);
RWLock::WLocker l2(ictx->parent_lock);
Mutex::Locker cache_locker(ictx->cache_lock);
RWLock::WLocker snap_locker(ictx->snap_lock);
RWLock::WLocker parent_locker(ictx->parent_lock);
int r;
if ((snap_name != NULL) && (strlen(snap_name) != 0)) {
r = ictx->snap_set(snap_name);
Expand Down

0 comments on commit a860e2b

Please sign in to comment.