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 #include <afs/afs_assert.h>
44 #include <afs/prs_fs.h>
48 #include <afs/cellconfig.h>
52 #include <afs/ihandle.h>
54 #include <afs/ntops.h>
56 #include <afs/vnode.h>
57 #include <afs/volume.h>
61 #include "volser_internal.h"
63 static struct volser_trans
*allTrans
= 0;
64 static afs_int32 transCounter
= 1;
66 /* create a new transaction, returning ptr to same with high ref count */
68 NewTrans(afs_uint32 avol
, afs_int32 apart
)
70 /* set volid, next, partition */
71 struct volser_trans
*tt
, *newtt
;
75 newtt
= (struct volser_trans
*)malloc(sizeof(struct volser_trans
));
77 /* don't allow the same volume to be attached twice */
78 for (tt
= allTrans
; tt
; tt
= tt
->next
) {
79 if ((tt
->volid
== avol
) && (tt
->partition
== apart
)) {
82 return (struct volser_trans
*)0; /* volume busy */
86 memset(tt
, 0, sizeof(struct volser_trans
));
88 tt
->partition
= apart
;
90 tt
->rxCallPtr
= (struct rx_call
*)0;
91 strcpy(tt
->lastProcName
, "");
92 gettimeofday(&tp
, &tzp
);
93 tt
->creationTime
= tp
.tv_sec
;
94 tt
->time
= FT_ApproxTime();
95 tt
->tid
= transCounter
++;
97 VTRANS_OBJ_LOCK_INIT(tt
);
103 /* find a trans, again returning with high ref count */
104 struct volser_trans
*
105 FindTrans(afs_int32 atrans
)
107 struct volser_trans
*tt
;
109 for (tt
= allTrans
; tt
; tt
= tt
->next
) {
110 if (tt
->tid
== atrans
) {
111 tt
->time
= FT_ApproxTime();
118 return (struct volser_trans
*)0;
121 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
123 DeleteTrans(struct volser_trans
*atrans
, afs_int32 lock
)
125 struct volser_trans
*tt
, **lt
;
128 if (lock
) VTRANS_LOCK
;
129 if (atrans
->refCount
> 1) {
130 /* someone else is using it now */
132 atrans
->tflags
|= TTDeleted
;
133 if (lock
) VTRANS_UNLOCK
;
137 /* otherwise we zap it ourselves */
139 for (tt
= *lt
; tt
; lt
= &tt
->next
, tt
= *lt
) {
142 VDetachVolume(&error
, tt
->volume
);
145 rxi_CallError(tt
->rxCallPtr
, RX_CALL_DEAD
);
147 VTRANS_OBJ_LOCK_DESTROY(tt
);
149 if (lock
) VTRANS_UNLOCK
;
153 if (lock
) VTRANS_UNLOCK
;
154 return -1; /* failed to find the transaction in the generic list */
157 /* THOLD is a macro defined in volser.h */
159 /* put a transaction back */
161 TRELE(struct volser_trans
*at
)
164 if (at
->refCount
== 0) {
165 Log("TRELE: bad refcount\n");
167 return VOLSERTRELE_ERROR
;
170 at
->time
= FT_ApproxTime(); /* we're still using it */
171 if (at
->refCount
== 1 && (at
->tflags
& TTDeleted
)) {
176 /* otherwise simply drop refcount */
182 /* look for old transactions and delete them */
183 #define OLDTRANSTIME 600 /* seconds */
184 #define OLDTRANSWARN 300 /* seconds */
185 static int GCDeletes
= 0;
189 struct volser_trans
*tt
, *nt
;
192 now
= FT_ApproxTime();
195 for (tt
= allTrans
; tt
; tt
= nt
) {
196 nt
= tt
->next
; /* remember in case we zap it */
197 if (tt
->time
+ OLDTRANSWARN
< now
) {
198 Log("trans %u on volume %u %s than %d seconds\n", tt
->tid
,
200 ((tt
->refCount
> 0) ? "is older" : "has been idle for more"),
201 (((now
- tt
->time
) / GCWAKEUP
) * GCWAKEUP
));
203 if (tt
->refCount
> 0)
205 if (tt
->time
+ OLDTRANSTIME
< now
) {
206 Log("trans %u on volume %u has timed out\n", tt
->tid
, tt
->volid
);
208 tt
->refCount
++; /* we're using it now */
210 if (tt
->volume
&& V_destroyMe(tt
->volume
) == DESTROY_ME
211 && !(tt
->vflags
& VTDeleted
)) {
215 Log("Deleting timed-out temporary volume %lu\n",
216 (long unsigned) tt
->volid
);
219 tt
->vflags
|= VTDeleted
;
220 VTRANS_OBJ_UNLOCK(tt
);
223 VPurgeVolume(&error
, tt
->volume
);
227 DeleteTrans(tt
, 0); /* drops refCount or deletes it */
235 /*return the head of the transaction list */
236 struct volser_trans
*