]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: owner_lock should be held while opening parent image
authorJason Dillaman <dillaman@redhat.com>
Wed, 18 Nov 2015 19:51:31 +0000 (14:51 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 19 Nov 2015 01:34:43 +0000 (20:34 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/internal.cc

index 76b5fee113318f8bdc9bab08d43f25ca1c718c8d..9c25ba3add7819bbd613fabef10d5529b50fa397 100644 (file)
@@ -1889,32 +1889,30 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
       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_parent(ictx);
-      return r;
+    {
+      RWLock::RLocker owner_locker(ictx->parent->owner_lock);
+      Mutex::Locker cache_locker(ictx->parent->cache_lock);
+      RWLock::WLocker snap_locker(ictx->parent->snap_lock);
+      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;
+      } else {
+        ictx->parent->snap_set(ictx->parent->snap_name);
+
+        RWLock::WLocker parent_locker(ictx->parent->parent_lock);
+        r = refresh_parent(ictx->parent);
+        if (r < 0) {
+          lderr(ictx->cct) << "error refreshing parent snapshot "
+                          << ictx->parent->id << " "
+                          << ictx->parent->snap_name << dendl;
+        }
+      }
     }
-    ictx->parent->snap_set(ictx->parent->snap_name);
-    ictx->parent->parent_lock.get_write();
-    r = refresh_parent(ictx->parent);
+
     if (r < 0) {
-      lderr(ictx->cct) << "error refreshing parent snapshot "
-                      << ictx->parent->id << " "
-                      << ictx->parent->snap_name << dendl;
-      ictx->parent->parent_lock.put_write();
-      ictx->parent->snap_lock.put_write();
-      ictx->parent->cache_lock.Unlock();
       close_parent(ictx);
       return r;
     }
-    ictx->parent->parent_lock.put_write();
-    ictx->parent->snap_lock.put_write();
-    ictx->parent->cache_lock.Unlock();
 
     return 0;
   }