volser-newtrans-racy-20081012

LICENSE IPL10
FIXES 121263

avoid a race on creating new transactions in volserver
This commit is contained in:
Jeffrey Hutzelman 2008-10-12 18:53:06 +00:00 committed by Derrick Brashear
parent 4b72f8765c
commit 322f7e0e9f

View File

@ -74,20 +74,21 @@ struct volser_trans *
NewTrans(afs_int32 avol, afs_int32 apart)
{
/* set volid, next, partition */
register struct volser_trans *tt;
struct volser_trans *tt, *newtt;
struct timeval tp;
struct timezone tzp;
newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
VTRANS_LOCK;
/* don't allow the same volume to be attached twice */
for (tt = allTrans; tt; tt = tt->next) {
if ((tt->volid == avol) && (tt->partition == apart)) {
VTRANS_UNLOCK;
free(newtt);
return (struct volser_trans *)0; /* volume busy */
}
}
VTRANS_UNLOCK;
tt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
newtt = tt;
memset(tt, 0, sizeof(struct volser_trans));
tt->volid = avol;
tt->partition = apart;
@ -97,7 +98,6 @@ NewTrans(afs_int32 avol, afs_int32 apart)
gettimeofday(&tp, &tzp);
tt->creationTime = tp.tv_sec;
tt->time = FT_ApproxTime();
VTRANS_LOCK;
tt->tid = transCounter++;
tt->next = allTrans;
allTrans = tt;