DEVEL15-tvolser-locking-updates-20070322
authorDerrick Brashear <shadow@dementia.org>
Thu, 22 Mar 2007 15:59:52 +0000 (15:59 +0000)
committerDerrick Brashear <shadow@dementia.org>
Thu, 22 Mar 2007 15:59:52 +0000 (15:59 +0000)
rework locking in tvolser slightly to avoid potential transaction leak

(cherry picked from commit 1c9ede0bcf892ccc3b9b5cae819c7d94b0407b38)

src/volser/voltrans.c

index b6bad29..0ef9acb 100644 (file)
@@ -137,21 +137,24 @@ DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
     register struct volser_trans *tt, **lt;
     afs_int32 error;
 
+    if (lock) VTRANS_LOCK;
     if (atrans->refCount > 1) {
        /* someone else is using it now */
        atrans->refCount--;
        atrans->tflags |= TTDeleted;
+       if (lock) VTRANS_UNLOCK;
        return 0;
     }
 
     /* otherwise we zap it ourselves */
-    if (lock) VTRANS_LOCK;
     lt = &allTrans;
     for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
        if (tt == atrans) {
            if (tt->volume)
                VDetachVolume(&error, tt->volume);
            tt->volume = NULL;
+           if (tt->rxCallPtr)
+               rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
            *lt = tt->next;
            free(tt);
            if (lock) VTRANS_UNLOCK;
@@ -168,18 +171,22 @@ DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
 afs_int32 
 TRELE(register struct volser_trans *at)
 {
+    VTRANS_LOCK;
     if (at->refCount == 0) {
        Log("TRELE: bad refcount\n");
+       VTRANS_UNLOCK;
        return VOLSERTRELE_ERROR;
     }
 
     at->time = FT_ApproxTime();        /* we're still using it */
     if (at->refCount == 1 && (at->tflags & TTDeleted)) {
-       DeleteTrans(at, 1);
+       DeleteTrans(at, 0);
+       VTRANS_UNLOCK;
        return 0;
     }
     /* otherwise simply drop refcount */
     at->refCount--;
+    VTRANS_UNLOCK;
     return 0;
 }