2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 * Instituition: ITC, CMU
17 #include <afsconfig.h>
18 #include <afs/param.h>
22 #include <afs/afsutil.h>
28 #include <sys/types.h>
36 #include <netinet/in.h>
41 #include <afs/afsint.h>
43 #ifdef AFS_PTHREAD_ENV
45 #else /* AFS_PTHREAD_ENV */
46 #include <afs/assert.h>
47 #endif /* AFS_PTHREAD_ENV */
48 #include <afs/prs_fs.h>
52 #include <afs/cellconfig.h>
56 #include <afs/ihandle.h>
58 #include <afs/ntops.h>
60 #include <afs/vnode.h>
61 #include <afs/volume.h>
65 #include "volser_prototypes.h"
67 static struct volser_trans *allTrans = 0;
68 static afs_int32 transCounter = 1;
70 /* create a new transaction, returning ptr to same with high ref count */
72 NewTrans(afs_int32 avol, afs_int32 apart)
74 /* set volid, next, partition */
75 struct volser_trans *tt, *newtt;
79 newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
81 /* don't allow the same volume to be attached twice */
82 for (tt = allTrans; tt; tt = tt->next) {
83 if ((tt->volid == avol) && (tt->partition == apart)) {
86 return (struct volser_trans *)0; /* volume busy */
90 memset(tt, 0, sizeof(struct volser_trans));
92 tt->partition = apart;
94 tt->rxCallPtr = (struct rx_call *)0;
95 strcpy(tt->lastProcName, "");
96 gettimeofday(&tp, &tzp);
97 tt->creationTime = tp.tv_sec;
98 tt->time = FT_ApproxTime();
99 tt->tid = transCounter++;
106 /* find a trans, again returning with high ref count */
107 struct volser_trans *
108 FindTrans(register afs_int32 atrans)
110 register struct volser_trans *tt;
112 for (tt = allTrans; tt; tt = tt->next) {
113 if (tt->tid == atrans) {
114 tt->time = FT_ApproxTime();
121 return (struct volser_trans *)0;
124 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
126 DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
128 register struct volser_trans *tt, **lt;
131 if (lock) VTRANS_LOCK;
132 if (atrans->refCount > 1) {
133 /* someone else is using it now */
135 atrans->tflags |= TTDeleted;
136 if (lock) VTRANS_UNLOCK;
140 /* otherwise we zap it ourselves */
142 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
145 VDetachVolume(&error, tt->volume);
148 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
151 if (lock) VTRANS_UNLOCK;
155 if (lock) VTRANS_UNLOCK;
156 return -1; /* failed to find the transaction in the generic list */
159 /* THOLD is a macro defined in volser.h */
161 /* put a transaction back */
163 TRELE(register struct volser_trans *at)
166 if (at->refCount == 0) {
167 Log("TRELE: bad refcount\n");
169 return VOLSERTRELE_ERROR;
172 at->time = FT_ApproxTime(); /* we're still using it */
173 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
178 /* otherwise simply drop refcount */
184 /* look for old transactions and delete them */
185 #define OLDTRANSTIME 600 /* seconds */
186 #define OLDTRANSWARN 300 /* seconds */
187 static int GCDeletes = 0;
191 register struct volser_trans *tt, *nt;
194 now = FT_ApproxTime();
197 for (tt = allTrans; tt; tt = nt) {
198 nt = tt->next; /* remember in case we zap it */
199 if (tt->time + OLDTRANSWARN < now) {
200 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
202 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
203 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
205 if (tt->refCount > 0)
207 if (tt->time + OLDTRANSTIME < now) {
208 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
209 tt->refCount++; /* we're using it now */
210 DeleteTrans(tt, 0); /* drops refCount or deletes it */
218 /*return the head of the transaction list */
219 struct volser_trans *