]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: flush pending AIO after acquiring lock 3812/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 27 Feb 2015 14:46:55 +0000 (09:46 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 2 Mar 2015 13:31:45 +0000 (08:31 -0500)
There was a potential race condition between a delayed AIO
operation waiting on acquiring a lock and a snap_create
flushing all pending IO.  Since snap_create owned md_lock, the
delayed AIO would not be allowed to complete -- deadlocking the
flush.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/internal.cc

index 19645f0f9119e1d13339cbb458e42035a7f500e6..9551332f892245900ebed7e1d8ba10cb3eb564b2 100644 (file)
@@ -454,13 +454,20 @@ namespace librbd {
 
     // need to upgrade to a write lock
     int r = 0;
+    bool acquired_lock = false;
     ictx->owner_lock.put_read();
     {
       RWLock::WLocker l(ictx->owner_lock);
       if (!ictx->image_watcher->is_lock_owner()) {
        r = ictx->image_watcher->try_lock();
+        acquired_lock = ictx->image_watcher->is_lock_owner();
       }
     }
+    if (acquired_lock) {
+      // finish any AIO that was previously waiting on acquiring the
+      // exclusive lock
+      ictx->flush_async_operations();
+    }
     ictx->owner_lock.get_read();
     return r;
   }