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>
37 #include <netinet/in.h>
42 #include <afs/afsint.h>
44 #ifdef AFS_PTHREAD_ENV
46 #else /* AFS_PTHREAD_ENV */
47 #include <afs/assert.h>
48 #endif /* AFS_PTHREAD_ENV */
49 #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>
75 /*@printflike@*/ extern void Log(const char *format, ...);
77 static struct volser_trans *allTrans = 0;
78 static afs_int32 transCounter = 1;
80 /* create a new transaction, returning ptr to same with high ref count */
82 NewTrans(afs_int32 avol, afs_int32 apart)
84 /* set volid, next, partition */
85 register struct volser_trans *tt;
90 /* don't allow the same volume to be attached twice */
91 for (tt = allTrans; tt; tt = tt->next) {
92 if ((tt->volid == avol) && (tt->partition == apart)) {
94 return (struct volser_trans *)0; /* volume busy */
98 tt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
99 memset(tt, 0, sizeof(struct volser_trans));
101 tt->partition = apart;
103 tt->rxCallPtr = (struct rx_call *)0;
104 strcpy(tt->lastProcName, "");
105 gettimeofday(&tp, &tzp);
106 tt->creationTime = tp.tv_sec;
107 tt->time = FT_ApproxTime();
109 tt->tid = transCounter++;
116 /* find a trans, again returning with high ref count */
117 struct volser_trans *
118 FindTrans(register afs_int32 atrans)
120 register struct volser_trans *tt;
122 for (tt = allTrans; tt; tt = tt->next) {
123 if (tt->tid == atrans) {
124 tt->time = FT_ApproxTime();
131 return (struct volser_trans *)0;
134 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
136 DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
138 register struct volser_trans *tt, **lt;
141 if (atrans->refCount > 1) {
142 /* someone else is using it now */
144 atrans->tflags |= TTDeleted;
148 /* otherwise we zap it ourselves */
149 if (lock) VTRANS_LOCK;
151 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
154 VDetachVolume(&error, tt->volume);
158 if (lock) VTRANS_UNLOCK;
162 if (lock) VTRANS_UNLOCK;
163 return -1; /* failed to find the transaction in the generic list */
166 /* THOLD is a macro defined in volser.h */
168 /* put a transaction back */
170 TRELE(register struct volser_trans *at)
172 if (at->refCount == 0) {
173 Log("TRELE: bad refcount\n");
174 return VOLSERTRELE_ERROR;
177 at->time = FT_ApproxTime(); /* we're still using it */
178 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
182 /* otherwise simply drop refcount */
187 /* look for old transactions and delete them */
188 #define OLDTRANSTIME 600 /* seconds */
189 #define OLDTRANSWARN 300 /* seconds */
190 static int GCDeletes = 0;
194 register struct volser_trans *tt, *nt;
197 now = FT_ApproxTime();
200 for (tt = allTrans; tt; tt = nt) {
201 nt = tt->next; /* remember in case we zap it */
202 if (tt->time + OLDTRANSWARN < now) {
203 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
205 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
206 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
208 if (tt->refCount > 0)
210 if (tt->time + OLDTRANSTIME < now) {
211 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
212 tt->refCount++; /* we're using it now */
213 DeleteTrans(tt, 0); /* drops refCount or deletes it */
221 /*return the head of the transaction list */
222 struct volser_trans *