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>
53 #include <afs/cellconfig.h>
57 #include <afs/ihandle.h>
59 #include <afs/ntops.h>
61 #include <afs/vnode.h>
62 #include <afs/volume.h>
74 /*@printflike@*/ extern void Log(const char *format, ...);
76 static struct volser_trans *allTrans = 0;
77 static afs_int32 transCounter = 1;
79 /* create a new transaction, returning ptr to same with high ref count */
81 NewTrans(afs_int32 avol, afs_int32 apart)
83 /* set volid, next, partition */
84 register struct volser_trans *tt;
89 /* don't allow the same volume to be attached twice */
90 for (tt = allTrans; tt; tt = tt->next) {
91 if ((tt->volid == avol) && (tt->partition == apart)) {
93 return (struct volser_trans *)0; /* volume busy */
97 tt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
98 memset(tt, 0, sizeof(struct volser_trans));
100 tt->partition = apart;
102 tt->rxCallPtr = (struct rx_call *)0;
103 strcpy(tt->lastProcName, "");
104 gettimeofday(&tp, &tzp);
105 tt->creationTime = tp.tv_sec;
106 tt->time = FT_ApproxTime();
108 tt->tid = transCounter++;
115 /* find a trans, again returning with high ref count */
116 struct volser_trans *
117 FindTrans(register afs_int32 atrans)
119 register struct volser_trans *tt;
121 for (tt = allTrans; tt; tt = tt->next) {
122 if (tt->tid == atrans) {
123 tt->time = FT_ApproxTime();
130 return (struct volser_trans *)0;
133 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
135 DeleteTrans(register struct volser_trans *atrans, afs_int32 lock)
137 register struct volser_trans *tt, **lt;
140 if (lock) VTRANS_LOCK;
141 if (atrans->refCount > 1) {
142 /* someone else is using it now */
144 atrans->tflags |= TTDeleted;
145 if (lock) VTRANS_UNLOCK;
149 /* otherwise we zap it ourselves */
151 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
154 VDetachVolume(&error, tt->volume);
157 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
160 if (lock) VTRANS_UNLOCK;
164 if (lock) VTRANS_UNLOCK;
165 return -1; /* failed to find the transaction in the generic list */
168 /* THOLD is a macro defined in volser.h */
170 /* put a transaction back */
172 TRELE(register struct volser_trans *at)
175 if (at->refCount == 0) {
176 Log("TRELE: bad refcount\n");
178 return VOLSERTRELE_ERROR;
181 at->time = FT_ApproxTime(); /* we're still using it */
182 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
187 /* otherwise simply drop refcount */
193 /* look for old transactions and delete them */
194 #define OLDTRANSTIME 600 /* seconds */
195 #define OLDTRANSWARN 300 /* seconds */
196 static int GCDeletes = 0;
200 register struct volser_trans *tt, *nt;
203 now = FT_ApproxTime();
206 for (tt = allTrans; tt; tt = nt) {
207 nt = tt->next; /* remember in case we zap it */
208 if (tt->time + OLDTRANSWARN < now) {
209 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
211 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
212 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
214 if (tt->refCount > 0)
216 if (tt->time + OLDTRANSTIME < now) {
217 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
218 tt->refCount++; /* we're using it now */
219 DeleteTrans(tt, 0); /* drops refCount or deletes it */
227 /*return the head of the transaction list */
228 struct volser_trans *