background-fsync-consistency-issues-20090522
authorDerrick Brashear <shadow@dementia.org>
Fri, 22 May 2009 17:00:26 +0000 (17:00 +0000)
committerDerrick Brashear <shadow@dementia.org>
Fri, 22 May 2009 17:00:26 +0000 (17:00 +0000)
LICENSE IPL10
FIXES 124359

avoid either reopening closed vnodes and leaving cached descriptors around,
or discarding a reference we're not holding; instead, sync changes when the
fd is closed, and note such has been done; otherwise, no changes from older
code.

src/vol/ihandle.c
src/vol/vnode.c

index 743ddb8..b61c2b0 100644 (file)
@@ -803,10 +803,32 @@ ih_reallyclose(IHandle_t * ihP)
        return 0;
 
     IH_LOCK;
+    ihP->ih_refcnt++;   /* must not disappear over unlock */
+    if (ihP->ih_synced) {
+       FdHandle_t *fdP;
+       IH_UNLOCK;
+       
+       fdP = IH_OPEN(ihP);
+       if (fdP) { 
+           OS_SYNC(fdP->fd_fd);
+           FDH_CLOSE(fdP);
+       }
+       
+       IH_LOCK;
+    }
+
     assert(ihP->ih_refcnt > 0);
+    ihP->ih_synced = 0;
+
     ih_fdclose(ihP);
 
-    IH_UNLOCK;
+    if (ihP->ih_refcnt > 1) {
+       ihP->ih_refcnt--;
+       IH_UNLOCK;
+    } else {
+       IH_UNLOCK;
+       ih_release(ihP);
+    }
     return 0;
 }
 
@@ -885,8 +907,10 @@ ih_sync_all(void) {
                IH_UNLOCK;
 
                fdP = IH_OPEN(ihP);
-               if (fdP) OS_SYNC(fdP->fd_fd);
-               FDH_CLOSE(fdP);
+               if (fdP) { 
+                   OS_SYNC(fdP->fd_fd);
+                   FDH_CLOSE(fdP);
+               }
 
                IH_LOCK;
            }
index 9c1677b..c7cf6c9 100644 (file)
@@ -1659,7 +1659,6 @@ VCloseVnodeFiles_r(Volume * vp)
 
     for (i = 0; i < vec_len; i++) {
        IH_REALLYCLOSE(ih_vec[i]);
-        IH_RELEASE(ih_vec[i]);
     }
 
     free(ih_vec);