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>
39 static struct volser_trans *allTrans=0;
40 static afs_int32 transCounter = 1;
42 /* create a new transaction, returning ptr to same with high ref count */
43 struct volser_trans *NewTrans(avol, apart)
46 /* set volid, next, partition */
47 register struct volser_trans *tt;
51 /* don't allow the same volume to be attached twice */
52 for(tt=allTrans;tt;tt=tt->next) {
53 if ((tt->volid == avol) && (tt->partition == apart)){
54 return (struct volser_trans *) 0; /* volume busy */
57 tt = (struct volser_trans *) malloc(sizeof(struct volser_trans));
58 memset(tt, 0, sizeof(struct volser_trans));
60 tt->partition = apart;
62 tt->tid = transCounter++;
64 tt->rxCallPtr = (struct rx_call *)0;
65 strcpy(tt->lastProcName,"");
66 gettimeofday(&tp,&tzp);
67 tt->creationTime = tp.tv_sec;
69 tt->time = FT_ApproxTime();
73 /* find a trans, again returning with high ref count */
74 struct volser_trans *FindTrans(atrans)
75 register afs_int32 atrans; {
76 register struct volser_trans *tt;
77 for(tt=allTrans;tt;tt=tt->next) {
78 if (tt->tid == atrans) {
79 tt->time = FT_ApproxTime();
84 return (struct volser_trans *) 0;
87 /* delete transaction if refcount == 1, otherwise queue delete for later. Does implicit TRELE */
89 register struct volser_trans *atrans; {
90 register struct volser_trans *tt, **lt;
93 if (atrans->refCount > 1) {
94 /* someone else is using it now */
96 atrans->tflags |= TTDeleted;
99 /* otherwise we zap it ourselves */
101 for(tt = *lt; tt; lt = &tt->next, tt = *lt) {
104 VDetachVolume(&error, tt->volume);
111 return -1; /* failed to find the transaction in the generic list */
114 /* THOLD is a macro defined in volser.h */
116 /* put a transaction back */
118 register struct volser_trans *at; {
119 if (at->refCount == 0){
120 Log("TRELE: bad refcount\n");
121 return VOLSERTRELE_ERROR;
124 at->time = FT_ApproxTime(); /* we're still using it */
125 if (at->refCount == 1 && (at->tflags & TTDeleted)) {
129 /* otherwise simply drop refcount */
134 /* look for old transactions and delete them */
135 #define OLDTRANSTIME 600 /* seconds */
136 #define OLDTRANSWARN 300 /* seconds */
137 static int GCDeletes = 0;
140 register struct volser_trans *tt, *nt;
143 now = FT_ApproxTime();
145 for(tt = allTrans; tt; tt=nt) {
146 nt = tt->next; /* remember in case we zap it */
147 if (tt->time + OLDTRANSWARN < now) {
148 Log("trans %u on volume %u %s than %d seconds\n",
150 ((tt->refCount>0)?"is older":"has been idle for more"),
151 (((now-tt->time)/GCWAKEUP)*GCWAKEUP));
153 if (tt->refCount > 0) continue;
154 if (tt->time + OLDTRANSTIME < now) {
155 Log("trans %u on volume %u has timed out\n", tt->tid, tt->volid);
156 tt->refCount++; /* we're using it now */
157 DeleteTrans(tt); /* drops refCount or deletes it */
163 /*return the head of the transaction list */
164 struct volser_trans *TransList()