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>
23 #include <afs/afsutil.h>
29 #include <sys/types.h>
37 #include <netinet/in.h>
42 #include <afs/afsint.h>
44 #include <afs/afs_assert.h>
45 #include <afs/prs_fs.h>
49 #include <afs/cellconfig.h>
53 #include <afs/ihandle.h>
55 #include <afs/ntops.h>
57 #include <afs/vnode.h>
58 #include <afs/volume.h>
62 #include "volser_internal.h"
64 static struct volser_trans *allTrans = 0;
65 static afs_int32 transCounter = 1;
67 /* create a new transaction, returning ptr to same with high ref count */
69 NewTrans(afs_uint32 avol, afs_int32 apart)
71 /* set volid, next, partition */
72 struct volser_trans *tt, *newtt;
76 newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
78 /* don't allow the same volume to be attached twice */
79 for (tt = allTrans; tt; tt = tt->next) {
80 if ((tt->volid == avol) && (tt->partition == apart)) {
83 return (struct volser_trans *)0; /* volume busy */
87 memset(tt, 0, sizeof(struct volser_trans));
89 tt->partition = apart;
91 tt->rxCallPtr = (struct rx_call *)0;
92 strcpy(tt->lastProcName, "");
93 gettimeofday(&tp, &tzp);
94 tt->creationTime = tp.tv_sec;
95 tt->time = FT_ApproxTime();
96 tt->tid = transCounter++;
98 VTRANS_OBJ_LOCK_INIT(tt);
104 /* find a trans, again returning with high ref count */
105 struct volser_trans *
106 FindTrans(afs_int32 atrans)
108 struct volser_trans *tt;
110 for (tt = allTrans; tt; tt = tt->next) {
111 if (tt->tid == atrans) {
112 tt->time = FT_ApproxTime();
119 return (struct volser_trans *)0;
122 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
124 DeleteTrans(struct volser_trans *atrans, afs_int32 lock)
126 struct volser_trans *tt, **lt;
129 if (lock) VTRANS_LOCK;
130 if (atrans->refCount > 1) {
131 /* someone else is using it now */
133 atrans->tflags |= TTDeleted;
134 if (lock) VTRANS_UNLOCK;
138 /* otherwise we zap it ourselves */
140 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
143 VDetachVolume(&error, tt->volume);
146 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
148 VTRANS_OBJ_LOCK_DESTROY(tt);
150 if (lock) VTRANS_UNLOCK;
154 if (lock) VTRANS_UNLOCK;
155 return -1; /* failed to find the transaction in the generic list */
158 /* THOLD is a macro defined in volser.h */
160 /* put a transaction back */
162 TRELE(struct volser_trans *at)
165 if (at->refCount == 0) {
166 Log("TRELE: bad refcount\n");
168 return VOLSERTRELE_ERROR;
171 at->time = FT_ApproxTime(); /* we're still using it */
172 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
177 /* otherwise simply drop refcount */
183 /* look for old transactions and delete them */
184 #define OLDTRANSTIME 600 /* seconds */
185 #define OLDTRANSWARN 300 /* seconds */
186 static int GCDeletes = 0;
190 struct volser_trans *tt, *nt;
193 now = FT_ApproxTime();
196 for (tt = allTrans; tt; tt = nt) {
197 nt = tt->next; /* remember in case we zap it */
198 if (tt->time + OLDTRANSWARN < now) {
199 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
201 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
202 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
204 if (tt->refCount > 0)
206 if (tt->time + OLDTRANSTIME < now) {
207 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
209 tt->refCount++; /* we're using it now */
211 if (tt->volume && V_destroyMe(tt->volume) == DESTROY_ME
212 && !(tt->vflags & VTDeleted)) {
216 Log("Deleting timed-out temporary volume %lu\n",
217 (long unsigned) tt->volid);
220 tt->vflags |= VTDeleted;
221 VTRANS_OBJ_UNLOCK(tt);
224 VPurgeVolume(&error, tt->volume);
228 DeleteTrans(tt, 0); /* drops refCount or deletes it */
236 /*return the head of the transaction list */
237 struct volser_trans *