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;
59 newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
61 /* don't allow the same volume to be attached twice */
62 for (tt = allTrans; tt; tt = tt->next) {
63 if ((tt->volid == avol) && (tt->partition == apart)) {
66 return (struct volser_trans *)0; /* volume busy */
70 memset(tt, 0, sizeof(struct volser_trans));
72 tt->partition = apart;
74 tt->rxCallPtr = (struct rx_call *)0;
75 strcpy(tt->lastProcName, "");
76 gettimeofday(&tp, &tzp);
77 tt->creationTime = tp.tv_sec;
78 tt->time = FT_ApproxTime();
79 tt->tid = transCounter++;
81 VTRANS_OBJ_LOCK_INIT(tt);
87 /* find a trans, again returning with high ref count */
89 FindTrans(afs_int32 atrans)
91 struct volser_trans *tt;
93 for (tt = allTrans; tt; tt = tt->next) {
94 if (tt->tid == atrans) {
95 tt->time = FT_ApproxTime();
102 return (struct volser_trans *)0;
105 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
107 DeleteTrans(struct volser_trans *atrans, afs_int32 lock)
109 struct volser_trans *tt, **lt;
112 if (lock) VTRANS_LOCK;
113 if (atrans->refCount > 1) {
114 /* someone else is using it now */
116 atrans->tflags |= TTDeleted;
117 if (lock) VTRANS_UNLOCK;
121 /* otherwise we zap it ourselves */
123 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
126 VDetachVolume(&error, tt->volume);
129 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
131 VTRANS_OBJ_LOCK_DESTROY(tt);
133 if (lock) VTRANS_UNLOCK;
137 if (lock) VTRANS_UNLOCK;
138 return -1; /* failed to find the transaction in the generic list */
141 /* THOLD is a macro defined in volser.h */
143 /* put a transaction back */
145 TRELE(struct volser_trans *at)
148 if (at->refCount == 0) {
149 Log("TRELE: bad refcount\n");
151 return VOLSERTRELE_ERROR;
154 at->time = FT_ApproxTime(); /* we're still using it */
155 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
160 /* otherwise simply drop refcount */
166 /* look for old transactions and delete them */
167 #define OLDTRANSTIME 600 /* seconds */
168 #define OLDTRANSWARN 300 /* seconds */
169 static int GCDeletes = 0;
173 struct volser_trans *tt, *nt;
176 now = FT_ApproxTime();
179 for (tt = allTrans; tt; tt = nt) {
180 nt = tt->next; /* remember in case we zap it */
181 if (tt->time + OLDTRANSWARN < now) {
182 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
184 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
185 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
187 if (tt->refCount > 0)
189 if (tt->time + OLDTRANSTIME < now) {
190 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
192 tt->refCount++; /* we're using it now */
194 if (tt->volume && V_destroyMe(tt->volume) == DESTROY_ME
195 && !(tt->vflags & VTDeleted)) {
199 Log("Deleting timed-out temporary volume %lu\n",
200 (long unsigned) tt->volid);
203 tt->vflags |= VTDeleted;
204 VTRANS_OBJ_UNLOCK(tt);
207 VPurgeVolume(&error, tt->volume);
211 DeleteTrans(tt, 0); /* drops refCount or deletes it */
219 /*return the head of the transaction list */
220 struct volser_trans *