volser: combine GCTrans conditional clauses
[openafs.git] / src / volser / voltrans.c
index bb182c1..158fec6 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 <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#ifdef AFS_NT40_ENV
-#include <afs/afsutil.h>
-#else
-#include <sys/time.h>
+#include <afs/opr.h>
+#ifdef AFS_PTHREAD_ENV
+# include <opr/lock.h>
 #endif
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <string.h>
 #ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <winsock2.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <unistd.h>
+#include <afs/afsutil.h>
 #endif
-#include <dirent.h>
-#include <sys/stat.h>
+
+#include <rx/rx_queue.h>
 #include <afs/afsint.h>
-#include <signal.h>
-#ifdef AFS_PTHREAD_ENV
-#include <assert.h>
-#else /* AFS_PTHREAD_ENV */
-#include <afs/assert.h>
-#endif /* AFS_PTHREAD_ENV */
 #include <afs/prs_fs.h>
 #include <afs/nfs.h>
 #include <lwp.h>
@@ -69,14 +54,13 @@ static afs_int32 transCounter = 1;
 
 /* create a new transaction, returning ptr to same with high ref count */
 struct volser_trans *
-NewTrans(afs_uint32 avol, afs_int32 apart)
+NewTrans(VolumeId avol, afs_int32 apart)
 {
     /* set volid, next, partition */
     struct volser_trans *tt, *newtt;
     struct timeval tp;
-    struct timezone tzp;
 
-    newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
+    newtt = calloc(1, sizeof(struct volser_trans));
     VTRANS_LOCK;
     /* don't allow the same volume to be attached twice */
     for (tt = allTrans; tt; tt = tt->next) {
@@ -87,13 +71,12 @@ NewTrans(afs_uint32 avol, afs_int32 apart)
        }
     }
     tt = newtt;
-    memset(tt, 0, sizeof(struct volser_trans));
     tt->volid = avol;
     tt->partition = apart;
     tt->refCount = 1;
     tt->rxCallPtr = (struct rx_call *)0;
     strcpy(tt->lastProcName, "");
-    gettimeofday(&tp, &tzp);
+    gettimeofday(&tp, NULL);
     tt->creationTime = tp.tv_sec;
     tt->time = FT_ApproxTime();
     tt->tid = transCounter++;
@@ -106,9 +89,9 @@ NewTrans(afs_uint32 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) {
@@ -123,10 +106,10 @@ 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;
+    struct volser_trans *tt, **lt;
     Error error;
 
     if (lock) VTRANS_LOCK;
@@ -161,8 +144,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) {
@@ -190,7 +173,7 @@ static int GCDeletes = 0;
 afs_int32
 GCTrans(void)
 {
-    register struct volser_trans *tt, *nt;
+    struct volser_trans *tt, *nt;
     afs_int32 now;
 
     now = FT_ApproxTime();
@@ -199,16 +182,33 @@ GCTrans(void)
     for (tt = allTrans; tt; tt = nt) {
        nt = tt->next;          /* remember in case we zap it */
        if (tt->time + OLDTRANSWARN < now) {
-           Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
-               tt->volid,
+           Log("trans %u on volume %" AFS_VOLID_FMT " %s than %d seconds\n", tt->tid,
+               afs_printable_VolumeId_lu(tt->volid),
                ((tt->refCount > 0) ? "is older" : "has been idle for more"),
                (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
        }
-       if (tt->refCount > 0)
-           continue;
-       if (tt->time + OLDTRANSTIME < now) {
-           Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
+       if ((tt->refCount <= 0) && (tt->time + OLDTRANSTIME < now)) {
+           Log("trans %u on volume %" AFS_VOLID_FMT " has timed out\n", tt->tid, afs_printable_VolumeId_lu(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++;
        }