]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: drop snap_lock before invalidating cache
authorJosh Durgin <josh.durgin@inktank.com>
Mon, 25 Feb 2013 19:33:48 +0000 (11:33 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Mon, 25 Feb 2013 19:36:58 +0000 (11:36 -0800)
Writeback will take the snap_lock, so read everything we need under it
before invalidating the cache. This avoids a recursive lock when writeback
uses snap_lock while snap_rollback() was holding it.

Remove a not-very-useful debugging message that depended on snap_lock being held.

Fixes: #4249
Backport: bobtail
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/librbd/internal.cc

index 33b948d231043bd557c1426bbf2191263b38c1ad..a4c25dfaa524a9c66e2b114090cf885ef3b0d95f 100644 (file)
@@ -1749,17 +1749,23 @@ reprotect_and_return_err:
       return r;
 
     Mutex::Locker l(ictx->md_lock);
-    Mutex::Locker l2(ictx->snap_lock);
-    if (!ictx->snap_exists)
-      return -ENOENT;
+    snap_t snap_id;
+    uint64_t new_size;
+    {
+      // need to drop snap_lock before invalidating cache
+      Mutex::Locker l2(ictx->snap_lock);
+      if (!ictx->snap_exists)
+       return -ENOENT;
 
-    if (ictx->snap_id != CEPH_NOSNAP || ictx->read_only)
-      return -EROFS;
+      if (ictx->snap_id != CEPH_NOSNAP || ictx->read_only)
+       return -EROFS;
 
-    snap_t snap_id = ictx->get_snap_id(snap_name);
-    if (snap_id == CEPH_NOSNAP) {
-      lderr(cct) << "No such snapshot found." << dendl;
-      return -ENOENT;
+      snap_id = ictx->get_snap_id(snap_name);
+      if (snap_id == CEPH_NOSNAP) {
+       lderr(cct) << "No such snapshot found." << dendl;
+       return -ENOENT;
+      }
+      new_size = ictx->get_image_size(ictx->snap_id);
     }
 
     // need to flush any pending writes before resizing and rolling back -
@@ -1767,9 +1773,6 @@ reprotect_and_return_err:
     // the current version, so we have to invalidate that too.
     ictx->invalidate_cache();
 
-    uint64_t new_size = ictx->get_image_size(ictx->snap_id);
-    ictx->get_snap_size(snap_name, &new_size);
-
     ldout(cct, 2) << "resizing to snapshot size..." << dendl;
     NoOpProgressContext no_op;
     r = resize_helper(ictx, new_size, no_op);
@@ -1785,10 +1788,6 @@ reprotect_and_return_err:
       return r;
     }
 
-    snap_t new_snap_id = ictx->get_snap_id(snap_name);
-    ldout(cct, 20) << "snap_id is " << ictx->snap_id << " new snap_id is "
-                  << new_snap_id << dendl;
-
     notify_change(ictx->md_ctx, ictx->header_oid, NULL, ictx);
 
     ictx->perfcounter->inc(l_librbd_snap_rollback);