]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: cleanup ictx_check's handling of owner_lock
authorJason Dillaman <dillaman@redhat.com>
Wed, 8 Jul 2015 00:00:18 +0000 (20:00 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 13 Nov 2015 01:17:53 +0000 (20:17 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/internal.cc
src/librbd/internal.h

index a94597971e0d4dbfaf70ceec4fb9fe8466b9edab..c4e982831a077667ae88d8db7b19443feb115ae5 100644 (file)
@@ -768,7 +768,7 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     ldout(ictx->cct, 20) << "snap_create_helper " << ictx << " " << snap_name
                          << dendl;
 
-    int r = ictx_check(ictx, true);
+    int r = ictx_check(ictx, ictx->owner_lock);
     if (r < 0) {
       return r;
     }
@@ -842,7 +842,7 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     ldout(ictx->cct, 20) << __func__ << " " << ictx << " from " 
                         << src_snap_id << " to " << dst_name << dendl;
 
-    int r = ictx_check(ictx, true);
+    int r = ictx_check(ictx, ictx->owner_lock);
     if (r < 0) {
       return r;
     }
@@ -933,7 +933,7 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     ldout(ictx->cct, 20) << "snap_remove_helper " << ictx << " " << snap_name
                          << dendl;
 
-    int r = ictx_check(ictx, true);
+    int r = ictx_check(ictx, ictx->owner_lock);
     if (r < 0) {
       return r;
     }
@@ -2258,7 +2258,7 @@ reprotect_and_return_err:
                   << size << dendl;
     ictx->snap_lock.put_read();
 
-    int r = ictx_check(ictx, true);
+    int r = ictx_check(ictx, ictx->owner_lock);
     if (r < 0) {
       return r;
     }
@@ -2452,8 +2452,14 @@ reprotect_and_return_err:
     return 0;
   }
 
-  int ictx_check(ImageCtx *ictx, bool owner_locked)
+  int ictx_check(ImageCtx *ictx) {
+    RWLock::RLocker owner_locker(ictx->owner_lock);
+    return ictx_check(ictx, ictx->owner_lock);
+  }
+
+  int ictx_check(ImageCtx *ictx, const RWLock &owner_lock)
   {
+    assert(ictx->owner_lock.is_locked());
     CephContext *cct = ictx->cct;
     ldout(cct, 20) << "ictx_check " << ictx << dendl;
 
@@ -2462,17 +2468,11 @@ reprotect_and_return_err:
     ictx->refresh_lock.Unlock();
 
     if (needs_refresh) {
-      int r;
-      if (owner_locked) {
-        r = ictx_refresh(ictx);
-      } else {
-        RWLock::RLocker owner_lock(ictx->owner_lock);
-        r = ictx_refresh(ictx);
-      }
+      int r = ictx_refresh(ictx);
       if (r < 0) {
        lderr(cct) << "Error re-reading rbd header: " << cpp_strerror(-r)
                   << dendl;
-       return r;
+        return r;
       }
     }
     return 0;
@@ -3189,7 +3189,7 @@ reprotect_and_return_err:
 
     int r;
     // ictx_check also updates parent data
-    if ((r = ictx_check(ictx, true)) < 0) {
+    if ((r = ictx_check(ictx, ictx->owner_lock)) < 0) {
       lderr(cct) << "ictx_check failed" << dendl;
       return r;
     }
@@ -3274,7 +3274,7 @@ reprotect_and_return_err:
       return -EINVAL;
     }
 
-    int r = ictx_check(ictx, true);
+    int r = ictx_check(ictx, ictx->owner_lock);
     if (r < 0) {
       return r;
     }
index 2dc0aa0ef984d92d9f44b296515ae178ee8395b6..7965c9db85405b6204a2b22c41a56f4095689b5d 100644 (file)
@@ -143,7 +143,8 @@ namespace librbd {
   int rm_snap(ImageCtx *ictx, const char *snap_name, uint64_t snap_id);
   int rename_snap(ImageCtx *ictx, uint64_t src_snap_id, const char *dst_name);
   int refresh_parent(ImageCtx *ictx);
-  int ictx_check(ImageCtx *ictx, bool owner_locked=false);
+  int ictx_check(ImageCtx *ictx);
+  int ictx_check(ImageCtx *ictx, const RWLock &owner_lock);
   int ictx_refresh(ImageCtx *ictx);
   int copy(ImageCtx *ictx, IoCtx& dest_md_ctx, const char *destname,
           ImageOptions& opts, ProgressContext &prog_ctx);