volser: Delete timed-out temporary volumes
[openafs.git] / src / volser / voltrans.c
index 23294f8..b350fa3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afs/vnode.h>
 #include <afs/volume.h>
 
+#include "volint.h"
 #include "volser.h"
-
-/*@printflike@*/ extern void Log(const char *format, ...);
+#include "volser_internal.h"
 
 static struct volser_trans *allTrans = 0;
 static afs_int32 transCounter = 1;
 
 /* create a new transaction, returning ptr to same with high ref count */
 struct volser_trans *
-NewTrans(afs_int32 avol, afs_int32 apart)
+NewTrans(afs_uint32 avol, afs_int32 apart)
 {
     /* set volid, next, partition */
     struct volser_trans *tt, *newtt;
@@ -98,6 +98,7 @@ NewTrans(afs_int32 avol, afs_int32 apart)
     tt->time = FT_ApproxTime();
     tt->tid = transCounter++;
     tt->next = allTrans;
+    VTRANS_OBJ_LOCK_INIT(tt);
     allTrans = tt;
     VTRANS_UNLOCK;
     return tt;
@@ -105,9 +106,9 @@ NewTrans(afs_int32 avol, afs_int32 apart)
 
 /* find a trans, again returning with high ref count */
 struct volser_trans *
-FindTrans(register afs_int32 atrans)
+FindTrans(afs_int32 atrans)
 {
-    register struct volser_trans *tt;
+    struct volser_trans *tt;
     VTRANS_LOCK;
     for (tt = allTrans; tt; tt = tt->next) {
        if (tt->tid == atrans) {
@@ -122,11 +123,11 @@ FindTrans(register afs_int32 atrans)
 }
 
 /* delete transaction if refcount == 1, otherwise queue delete for later.  Does implicit TRELE */
-afs_int32 
-DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
+afs_int32
+DeleteTrans(struct volser_trans *atrans, afs_int32 lock)
 {
-    register struct volser_trans *tt, **lt;
-    afs_int32 error;
+    struct volser_trans *tt, **lt;
+    Error error;
 
     if (lock) VTRANS_LOCK;
     if (atrans->refCount > 1) {
@@ -147,6 +148,7 @@ DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
            if (tt->rxCallPtr)
                rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
            *lt = tt->next;
+            VTRANS_OBJ_LOCK_DESTROY(tt);
            free(tt);
            if (lock) VTRANS_UNLOCK;
            return 0;
@@ -159,8 +161,8 @@ DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
 /* THOLD is a macro defined in volser.h */
 
 /* put a transaction back */
-afs_int32 
-TRELE(register struct volser_trans *at)
+afs_int32
+TRELE(struct volser_trans *at)
 {
     VTRANS_LOCK;
     if (at->refCount == 0) {
@@ -186,9 +188,9 @@ TRELE(register struct volser_trans *at)
 #define        OLDTRANSWARN        300 /* seconds */
 static int GCDeletes = 0;
 afs_int32
-GCTrans()
+GCTrans(void)
 {
-    register struct volser_trans *tt, *nt;
+    struct volser_trans *tt, *nt;
     afs_int32 now;
 
     now = FT_ApproxTime();
@@ -206,7 +208,26 @@ GCTrans()
            continue;
        if (tt->time + OLDTRANSTIME < now) {
            Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
+
            tt->refCount++;     /* we're using it now */
+
+           if (tt->volume && V_destroyMe(tt->volume) == DESTROY_ME
+               && !(tt->vflags & VTDeleted)) {
+
+               Error error;
+
+               Log("Deleting timed-out temporary volume %lu\n",
+                   (long unsigned) tt->volid);
+
+               VTRANS_OBJ_LOCK(tt);
+               tt->vflags |= VTDeleted;
+               VTRANS_OBJ_UNLOCK(tt);
+
+               VTRANS_UNLOCK;
+               VPurgeVolume(&error, tt->volume);
+               VTRANS_LOCK;
+           }
+
            DeleteTrans(tt, 0); /* drops refCount or deletes it */
            GCDeletes++;
        }
@@ -217,7 +238,7 @@ GCTrans()
 
 /*return the head of the transaction list */
 struct volser_trans *
-TransList()
+TransList(void)
 {
     return (allTrans);
 }