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>
24 #include <afs/afsutil.h>
30 #include <sys/types.h>
38 #include <netinet/in.h>
43 #include <afs/afsint.h>
45 #ifdef AFS_PTHREAD_ENV
47 #else /* AFS_PTHREAD_ENV */
48 #include <afs/assert.h>
49 #endif /* AFS_PTHREAD_ENV */
50 #include <afs/prs_fs.h>
54 #include <afs/cellconfig.h>
58 #include <afs/ihandle.h>
60 #include <afs/ntops.h>
62 #include <afs/vnode.h>
63 #include <afs/volume.h>
67 /*@printflike@*/ extern void Log(const char *format, ...);
69 static struct volser_trans *allTrans = 0;
70 static afs_int32 transCounter = 1;
72 /* create a new transaction, returning ptr to same with high ref count */
74 NewTrans(afs_int32 avol, afs_int32 apart)
76 /* set volid, next, partition */
77 register struct volser_trans *tt;
82 /* don't allow the same volume to be attached twice */
83 for (tt = allTrans; tt; tt = tt->next) {
84 if ((tt->volid == avol) && (tt->partition == apart)) {
86 return (struct volser_trans *)0; /* volume busy */
90 tt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
91 memset(tt, 0, sizeof(struct volser_trans));
93 tt->partition = apart;
95 tt->rxCallPtr = (struct rx_call *)0;
96 strcpy(tt->lastProcName, "");
97 gettimeofday(&tp, &tzp);
98 tt->creationTime = tp.tv_sec;
99 tt->time = FT_ApproxTime();
101 tt->tid = transCounter++;
108 /* find a trans, again returning with high ref count */
109 struct volser_trans *
110 FindTrans(register afs_int32 atrans)
112 register struct volser_trans *tt;
114 for (tt = allTrans; tt; tt = tt->next) {
115 if (tt->tid == atrans) {
116 tt->time = FT_ApproxTime();
123 return (struct volser_trans *)0;
126 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
128 DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
130 register struct volser_trans *tt, **lt;
133 if (lock) VTRANS_LOCK;
134 if (atrans->refCount > 1) {
135 /* someone else is using it now */
137 atrans->tflags |= TTDeleted;
138 if (lock) VTRANS_UNLOCK;
142 /* otherwise we zap it ourselves */
144 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
147 VDetachVolume(&error, tt->volume);
150 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
153 if (lock) VTRANS_UNLOCK;
157 if (lock) VTRANS_UNLOCK;
158 return -1; /* failed to find the transaction in the generic list */
161 /* THOLD is a macro defined in volser.h */
163 /* put a transaction back */
165 TRELE(register struct volser_trans *at)
168 if (at->refCount == 0) {
169 Log("TRELE: bad refcount\n");
171 return VOLSERTRELE_ERROR;
174 at->time = FT_ApproxTime(); /* we're still using it */
175 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
180 /* otherwise simply drop refcount */
186 /* look for old transactions and delete them */
187 #define OLDTRANSTIME 600 /* seconds */
188 #define OLDTRANSWARN 300 /* seconds */
189 static int GCDeletes = 0;
193 register struct volser_trans *tt, *nt;
196 now = FT_ApproxTime();
199 for (tt = allTrans; tt; tt = nt) {
200 nt = tt->next; /* remember in case we zap it */
201 if (tt->time + OLDTRANSWARN < now) {
202 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
204 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
205 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
207 if (tt->refCount > 0)
209 if (tt->time + OLDTRANSTIME < now) {
210 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
211 tt->refCount++; /* we're using it now */
212 DeleteTrans(tt, 0); /* drops refCount or deletes it */
220 /*return the head of the transaction list */
221 struct volser_trans *