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>
22 #include <afs/afsutil.h>
28 #include <sys/types.h>
36 #include <netinet/in.h>
41 #include <afs/afsint.h>
43 #ifdef AFS_PTHREAD_ENV
45 #else /* AFS_PTHREAD_ENV */
46 #include <afs/assert.h>
47 #endif /* AFS_PTHREAD_ENV */
48 #include <afs/prs_fs.h>
52 #include <afs/cellconfig.h>
56 #include <afs/ihandle.h>
58 #include <afs/ntops.h>
60 #include <afs/vnode.h>
61 #include <afs/volume.h>
65 #include "volser_internal.h"
67 static struct volser_trans *allTrans = 0;
68 static afs_int32 transCounter = 1;
70 /* create a new transaction, returning ptr to same with high ref count */
72 NewTrans(afs_uint32 avol, afs_int32 apart)
74 /* set volid, next, partition */
75 struct volser_trans *tt, *newtt;
79 newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
81 /* don't allow the same volume to be attached twice */
82 for (tt = allTrans; tt; tt = tt->next) {
83 if ((tt->volid == avol) && (tt->partition == apart)) {
86 return (struct volser_trans *)0; /* volume busy */
90 memset(tt, 0, sizeof(struct volser_trans));
92 tt->partition = apart;
94 tt->rxCallPtr = (struct rx_call *)0;
95 strcpy(tt->lastProcName, "");
96 gettimeofday(&tp, &tzp);
97 tt->creationTime = tp.tv_sec;
98 tt->time = FT_ApproxTime();
99 tt->tid = transCounter++;
101 VTRANS_OBJ_LOCK_INIT(tt);
107 /* find a trans, again returning with high ref count */
108 struct volser_trans *
109 FindTrans(afs_int32 atrans)
111 struct volser_trans *tt;
113 for (tt = allTrans; tt; tt = tt->next) {
114 if (tt->tid == atrans) {
115 tt->time = FT_ApproxTime();
122 return (struct volser_trans *)0;
125 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
127 DeleteTrans(struct volser_trans *atrans, afs_int32 lock)
129 struct volser_trans *tt, **lt;
132 if (lock) VTRANS_LOCK;
133 if (atrans->refCount > 1) {
134 /* someone else is using it now */
136 atrans->tflags |= TTDeleted;
137 if (lock) VTRANS_UNLOCK;
141 /* otherwise we zap it ourselves */
143 for (tt = *lt; tt; lt = &tt->next, tt = *lt) {
146 VDetachVolume(&error, tt->volume);
149 rxi_CallError(tt->rxCallPtr, RX_CALL_DEAD);
151 VTRANS_OBJ_LOCK_DESTROY(tt);
153 if (lock) VTRANS_UNLOCK;
157 if (lock) VTRANS_UNLOCK;
158 return -1; /* failed to find the transaction in the generic list */
161 /* THOLD is a macro defined in volser.h */
163 /* put a transaction back */
165 TRELE(struct volser_trans *at)
168 if (at->refCount == 0) {
169 Log("TRELE: bad refcount\n");
171 return VOLSERTRELE_ERROR;
174 at->time = FT_ApproxTime(); /* we're still using it */
175 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
180 /* otherwise simply drop refcount */
186 /* look for old transactions and delete them */
187 #define OLDTRANSTIME 600 /* seconds */
188 #define OLDTRANSWARN 300 /* seconds */
189 static int GCDeletes = 0;
193 struct volser_trans *tt, *nt;
196 now = FT_ApproxTime();
199 for (tt = allTrans; tt; tt = nt) {
200 nt = tt->next; /* remember in case we zap it */
201 if (tt->time + OLDTRANSWARN < now) {
202 Log("trans %u on volume %u %s than %d seconds\n", tt->tid,
204 ((tt->refCount > 0) ? "is older" : "has been idle for more"),
205 (((now - tt->time) / GCWAKEUP) * GCWAKEUP));
207 if (tt->refCount > 0)
209 if (tt->time + OLDTRANSTIME < now) {
210 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
212 tt->refCount++; /* we're using it now */
214 if (tt->volume && V_destroyMe(tt->volume) == DESTROY_ME
215 && !(tt->vflags & VTDeleted)) {
219 Log("Deleting timed-out temporary volume %lu\n",
220 (long unsigned) tt->volid);
223 tt->vflags |= VTDeleted;
224 VTRANS_OBJ_UNLOCK(tt);
227 VPurgeVolume(&error, tt->volume);
231 DeleteTrans(tt, 0); /* drops refCount or deletes it */
239 /*return the head of the transaction list */
240 struct volser_trans *