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>
26 #include <afs/afsint.h>
27 #include <afs/afs_assert.h>
28 #include <afs/prs_fs.h>
32 #include <afs/cellconfig.h>
36 #include <afs/ihandle.h>
38 #include <afs/ntops.h>
40 #include <afs/vnode.h>
41 #include <afs/volume.h>
45 #include "volser_internal.h"
47 static struct volser_trans *allTrans = 0;
48 static afs_int32 transCounter = 1;
50 /* create a new transaction, returning ptr to same with high ref count */
52 NewTrans(afs_uint32 avol, afs_int32 apart)
54 /* set volid, next, partition */
55 struct volser_trans *tt, *newtt;
58 newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
60 /* don't allow the same volume to be attached twice */
61 for (tt = allTrans; tt; tt = tt->next) {
62 if ((tt->volid == avol) && (tt->partition == apart)) {
65 return (struct volser_trans *)0; /* volume busy */
69 memset(tt, 0, sizeof(struct volser_trans));
71 tt->partition = apart;
73 tt->rxCallPtr = (struct rx_call *)0;
74 strcpy(tt->lastProcName, "");
75 gettimeofday(&tp, NULL);
76 tt->creationTime = tp.tv_sec;
77 tt->time = FT_ApproxTime();
78 tt->tid = transCounter++;
80 VTRANS_OBJ_LOCK_INIT(tt);
86 /* find a trans, again returning with high ref count */
88 FindTrans(afs_int32 atrans)
90 struct volser_trans *tt;
92 for (tt = allTrans; tt; tt = tt->next) {
93 if (tt->tid == atrans) {
94 tt->time = FT_ApproxTime();
101 return (struct volser_trans *)0;
104 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
106 DeleteTrans(struct volser_trans *atrans, afs_int32 lock)
108 struct volser_trans *tt, **lt;
111 if (lock) VTRANS_LOCK;
112 if (atrans->refCount > 1) {
113 /* someone else is using it now */
115 atrans->tflags |= TTDeleted;
116 if (lock) VTRANS_UNLOCK;
120 /* otherwise we zap it ourselves */
122 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
125 VDetachVolume(&error, tt->volume);
128 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
130 VTRANS_OBJ_LOCK_DESTROY(tt);
132 if (lock) VTRANS_UNLOCK;
136 if (lock) VTRANS_UNLOCK;
137 return -1; /* failed to find the transaction in the generic list */
140 /* THOLD is a macro defined in volser.h */
142 /* put a transaction back */
144 TRELE(struct volser_trans *at)
147 if (at->refCount == 0) {
148 Log("TRELE: bad refcount\n");
150 return VOLSERTRELE_ERROR;
153 at->time = FT_ApproxTime(); /* we're still using it */
154 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
159 /* otherwise simply drop refcount */
165 /* look for old transactions and delete them */
166 #define OLDTRANSTIME 600 /* seconds */
167 #define OLDTRANSWARN 300 /* seconds */
168 static int GCDeletes = 0;
172 struct volser_trans *tt, *nt;
175 now = FT_ApproxTime();
178 for (tt = allTrans; tt; tt = nt) {
179 nt = tt->next; /* remember in case we zap it */
180 if (tt->time + OLDTRANSWARN < now) {
181 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
183 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
184 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
186 if (tt->refCount > 0)
188 if (tt->time + OLDTRANSTIME < now) {
189 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
191 tt->refCount++; /* we're using it now */
193 if (tt->volume && V_destroyMe(tt->volume) == DESTROY_ME
194 && !(tt->vflags & VTDeleted)) {
198 Log("Deleting timed-out temporary volume %lu\n",
199 (long unsigned) tt->volid);
202 tt->vflags |= VTDeleted;
203 VTRANS_OBJ_UNLOCK(tt);
206 VPurgeVolume(&error, tt->volume);
210 DeleteTrans(tt, 0); /* drops refCount or deletes it */
218 /*return the head of the transaction list */
219 struct volser_trans *