Skip to content

Commit

Permalink
librbd: only update image flags when holding exclusive lock
Browse files Browse the repository at this point in the history
It was possible for a client to open an image while another client
was shrinking an image.  This would result in the former invalidating
the object map on-disk if it openned the image between updating the
image header and resizing the object map.

Fixes: #11791
Backport: hammer
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit eb81a6a)
  • Loading branch information
Jason Dillaman committed Jul 19, 2015
1 parent ef45363 commit 27c99ea
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/librbd/ObjectMap.cc
Expand Up @@ -338,13 +338,25 @@ void ObjectMap::invalidate() {
m_image_ctx.update_flags(m_image_ctx.snap_id, RBD_FLAG_OBJECT_MAP_INVALID,
true);

// do not update on-disk flags if not image owner
if (m_image_ctx.image_watcher->is_lock_supported(m_image_ctx.snap_lock) &&
!m_image_ctx.image_watcher->is_lock_owner()) {
return;
}

librados::ObjectWriteOperation op;
if (m_image_ctx.snap_id == CEPH_NOSNAP) {
m_image_ctx.image_watcher->assert_header_locked(&op);
}
cls_client::set_flags(&op, m_image_ctx.snap_id, m_image_ctx.flags,
RBD_FLAG_OBJECT_MAP_INVALID);

int r = m_image_ctx.md_ctx.operate(m_image_ctx.header_oid, &op);
if (r < 0) {
lderr(cct) << "failed to invalidate object map: " << cpp_strerror(r)
if (r == -EBUSY) {
ldout(cct, 5) << "skipping on-disk object map invalidation: "
<< "image not locked by client" << dendl;
} else if (r < 0) {
lderr(cct) << "failed to invalidate on-disk object map: " << cpp_strerror(r)
<< dendl;
}
}
Expand Down Expand Up @@ -403,6 +415,7 @@ bool ObjectMap::Request::invalidate() {
m_image_ctx.flags |= RBD_FLAG_OBJECT_MAP_INVALID;

librados::ObjectWriteOperation op;
m_image_ctx.image_watcher->assert_header_locked(&op);
cls_client::set_flags(&op, CEPH_NOSNAP, m_image_ctx.flags,
RBD_FLAG_OBJECT_MAP_INVALID);

Expand Down

0 comments on commit 27c99ea

Please sign in to comment.