git: 9front

Download patch

ref: f60a431a31aa3fa69b866600e675e44f872b6115
parent: f8d145f1fd59dbf0d9da86465e8f8cabd259b771
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Nov 22 11:20:56 EST 2025

gefs: cleanup -- ainc -> aincl

we had mostly been using the atomic api, but
not consistently; clean it up and use it in
all places.

--- a/sys/src/cmd/gefs/blk.c
+++ b/sys/src/cmd/gefs/blk.c
@@ -118,7 +118,7 @@
 		xh = bp.hash;
 		ck = blkhash(b);
 	}
-	if((!flg&GBnochk) && ck != xh)
+	if((flg&GBnochk) == 0 && ck != xh)
 		broke("%s: %ullx %llux != %llux", Ecorrupt, bp.addr, xh, ck);
 	bassert(b, b->magic == Magic);
 }
@@ -128,7 +128,7 @@
 {
 	uint n, r;
 
-	r = ainc(&fs->roundrobin)/2048;
+	r = aincl(&fs->roundrobin, 1)/2048;
 	if(ty == Tdat)
 		n = hint % (fs->narena - 1) + r + 1;
 	else
--- a/sys/src/cmd/gefs/cons.c
+++ b/sys/src/cmd/gefs/cons.c
@@ -245,7 +245,8 @@
 			for(f = c->fidtab[i]; f != nil; f = f->next){
 				rlock(f->dent);
 				fprint(fd, "\tfid[%d] from %#zx: %d [refs=%ld, k=%K, qid=%Q m=%d, dmode:%d duid: %d, dgid: %d]\n",
-					i, getmalloctag(f), f->fid, f->dent->ref, &f->dent->Key, f->dent->qid,
+					i, getmalloctag(f), f->fid,
+					agetl(&f->dent->ref), &f->dent->Key, f->dent->qid,
 					f->mode, f->dmode, f->duid, f->dgid);
 				runlock(f->dent);
 			}
--- a/sys/src/cmd/gefs/dat.h
+++ b/sys/src/cmd/gefs/dat.h
@@ -441,7 +441,7 @@
 
 	/* in-memory */
 	Lock	lk;
-	long	memref;	/* number of in-memory references to this */
+	Along	memref;	/* number of in-memory references to this */
 	vlong	memgen;	/* wip next generation */
 	int	dirty;
 
@@ -525,7 +525,7 @@
 
 	/* arena allocation */
 	Arena	*arenas;
-	long	roundrobin;
+	Along	roundrobin;
 	long	syncing;
 	long	nsyncers;
 	long	nreaders;
@@ -636,7 +636,7 @@
 	QLock	trunclk;
 	Rendez	truncrz;
 	vlong	up;
-	long	ref;
+	Along	ref;
 	char	gone;
 	char	trunc;
 
@@ -659,7 +659,7 @@
 	Limbo;
 	Lock;
 	Mount	*next;
-	long	ref;
+	Along	ref;
 	vlong	gen;
 	char	name[64];
 	Aptr	root;	/* Tree*, EBR protected */
@@ -686,7 +686,7 @@
 	int	authok;
 	int	hangup;
 
-	long	ref;
+	Along	ref;
 
 	/* fid hash table */
 	Lock	fidtablk[Nfidtab];
@@ -710,7 +710,7 @@
 	u32int	fid;
 	vlong	qpath;
 	vlong	pqpath;
-	long	ref;
+	Along	ref;
 	int	mode;
 	int	iounit;
 
--- a/sys/src/cmd/gefs/fs.c
+++ b/sys/src/cmd/gefs/fs.c
@@ -226,7 +226,7 @@
 		if(strcmp(a->old, mnt->name) == 0){
 			t = agetp(&mnt->root);
 			t = updatesnap(t, mnt->name, mnt->flag);
-			ainc(&t->memref);
+			aincl(&t->memref, 1);
 			aswapp(&mnt->root, t);
 			break;
 		}
@@ -243,7 +243,7 @@
 			return;
 		}
 		if(t->nlbl == 1 && t->nref <= 1 && t->succ == -1){
-			ainc(&t->memref);
+			aincl(&t->memref, 1);
 			r = t;
 		}
 		delsnap(t, t->succ, a->old);
@@ -571,7 +571,7 @@
 	lock(&mnt->dtablk);
 	for(de = mnt->dtab[h]; de != nil; de = de->next){
 		if(de->qid.path == d->qid.path){
-			ainc(&de->ref);
+			aincl(&de->ref, 1);
 			goto Out;
 		}
 	}
@@ -581,7 +581,7 @@
 	}
 	de = emalloc(sizeof(Dent), 1);
 	de->Xdir = *d;
-	de->ref = 1;
+	aswapl(&de->ref, 1);
 	de->up = pqid;
 	de->qid = d->qid;
 	de->length = d->length;
@@ -700,7 +700,7 @@
 	int flg;
 
 	if(strcmp(name, "dump") == 0){
-		ainc(&fs->snapmnt->ref);
+		aincl(&fs->snapmnt->ref, 1);
 		return fs->snapmnt;
 	}
 
@@ -708,7 +708,7 @@
 	hd = agetp(&fs->mounts);
 	for(mnt = hd; mnt != nil; mnt = mnt->next){
 		if(strcmp(name, mnt->name) == 0){
-			ainc(&mnt->ref);
+			aincl(&mnt->ref, 1);
 			qunlock(&fs->mountlk);
 			return mnt;
 		}
@@ -719,7 +719,7 @@
 		nexterror();
 	}
 	mnt = emalloc(sizeof(*mnt), 1);
-	mnt->ref = 1;
+	aswapl(&mnt->ref, 1);
 	snprint(mnt->name, sizeof(mnt->name), "%s", name);
 	if((t = opensnap(name, &flg)) == nil)
 		error(Enosnap);
@@ -742,7 +742,7 @@
 	if(mnt == nil)
 		return;
 	qlock(&fs->mountlk);
-	if(adec(&mnt->ref) == 0){
+	if(aincl(&mnt->ref, -1) == 0){
 		pp = nil;
 		for(p = agetp(&fs->mounts); p != nil; p = p->next){
 			if(p == mnt)
@@ -768,7 +768,7 @@
 	if(de == nil)
 		return;
 	if(de->qid.type & QTAUTH){
-		if(adec(&de->ref) == 0){
+		if(aincl(&de->ref, -1) == 0){
 			authfree(de->auth);
 			free(de);
 		}
@@ -775,7 +775,7 @@
 		return;
 	}
 	lock(&mnt->dtablk);
-	if(adec(&de->ref) != 0)
+	if(aincl(&de->ref, -1) != 0)
 		goto Out;
 	h = ihash(de->qid.path) % Ndtab;
 	pe = &mnt->dtab[h];
@@ -801,7 +801,7 @@
 	lock(&c->fidtablk[h]);
 	for(f = c->fidtab[h]; f != nil; f = f->next)
 		if(f->fid == fid){
-			ainc(&f->ref);
+			aincl(&f->ref, 1);
 			break;
 		}
 	unlock(&c->fidtablk[h]);
@@ -811,7 +811,7 @@
 static void
 putfid(Fid *f)
 {
-	if(adec(&f->ref) != 0)
+	if(aincl(&f->ref, -1) != 0)
 		return;
 	clunkdent(f->mnt, f->dent);
 	clunkdent(f->mnt, f->dir);
@@ -832,7 +832,7 @@
 	*n = *f;
 	memset(&n->RWLock, 0, sizeof(RWLock));
 	n->fid = new;
-	n->ref = 2; /* one for dup, one for clunk */
+	aswapl(&n->ref, 2); /* one for dup, one for clunk */
 	n->mode = -1;
 	n->next = nil;
 
@@ -852,9 +852,9 @@
 		return nil;
 	}
 	if(n->mnt != nil)
-		ainc(&n->mnt->ref);
-	ainc(&n->dent->ref);
-	ainc(&n->dir->ref);
+		aincl(&n->mnt->ref, 1);
+	aincl(&n->dent->ref, 1);
+	aincl(&n->dir->ref, 1);
 	setmalloctag(n, getcallerpc(&c));
 	return n;
 }
@@ -878,7 +878,7 @@
 	pf = &c->fidtab[h];
 	for(f = c->fidtab[h]; f != nil; f = f->next){
 		if(f == fid){
-			assert(adec(&f->ref) != 0);
+			assert(aincl(&f->ref, -1) != 0);
 			*pf = f->next;
 			break;
 		}
@@ -903,8 +903,8 @@
 		f->dent->gone = 1;
 		wunlock(f->dent);
 
-		ainc(&f->dent->ref);
-		ainc(&f->mnt->ref);
+		aincl(&f->dent->ref, 1);
+		aincl(&f->mnt->ref, 1);
 		(*ao)->op = AOrclose;
 		(*ao)->mnt = f->mnt;
 		(*ao)->qpath = f->qpath;
@@ -957,7 +957,7 @@
 		free(m);
 		return -1;
 	}
-	ainc(&c->ref);
+	aincl(&c->ref, 1);
 	m->conn = c;
 	m->sz = sz;
 	PBIT32(m->buf, sz);
@@ -1101,7 +1101,7 @@
 		free(de);
 		return;
 	}
-	de->ref = 0;
+	aswapl(&de->ref, 0);
 	de->qid.type = QTAUTH;
 	qlock(&fs->mutlk);
 	de->qid.path = fs->nextqid++;
@@ -1484,7 +1484,7 @@
 		clunkdent(f->mnt, f->dir);
 		if(mnt != f->mnt){
 			clunkmount(f->mnt);
-			ainc(&mnt->ref);
+			aincl(&mnt->ref, 1);
 			f->mnt = mnt;
 		}
 		f->qpath = r.wqid[i-1].path;
@@ -1613,8 +1613,8 @@
 				qlock(&de->trunclk);
 				de->trunc = 1;
 				qunlock(&de->trunclk);
-				ainc(&de->ref);
-				ainc(&f->mnt->ref);
+				aincl(&de->ref, 1);
+				aincl(&f->mnt->ref, 1);
 				(*ao)->op = AOclear;
 				(*ao)->mnt = f->mnt;
 				(*ao)->qpath = f->qpath;
@@ -1962,7 +1962,7 @@
 	}
 	if(f->dent->gone)
 		error(Ephase);
-	if((f->dent->qid.type & QTEXCL) && f->dent->ref != 1)
+	if((f->dent->qid.type & QTEXCL) && agetl(&f->dent->ref) != 1)
 		error(Elocked);
 	/*
 	 * we need a double check that the file is in the tree
@@ -1998,7 +1998,7 @@
 		nm++;
 	}else{
 		*ao = emalloc(sizeof(Amsg), 1);
-		ainc(&f->mnt->ref);
+		aincl(&f->mnt->ref, 1);
 		(*ao)->op = AOclear;
 		(*ao)->mnt = f->mnt;
 		(*ao)->qpath = f->qpath;
@@ -2055,7 +2055,7 @@
 	}
 	if(f->dent->gone)
 		error(Ephase);
-	if((f->dent->qid.type & QTEXCL) && f->dent->ref != 1)
+	if((f->dent->qid.type & QTEXCL) && agetl(&f->dent->ref) != 1)
 		error(Elocked);
 	if(m->mode & ORCLOSE)
 		if((e = candelete(f)) != nil)
@@ -2093,8 +2093,8 @@
 		qlock(&f->dent->trunclk);
 		f->dent->trunc = 1;
 		qunlock(&f->dent->trunclk);
-		ainc(&f->dent->ref);
-		ainc(&f->mnt->ref);
+		aincl(&f->dent->ref, 1);
+		aincl(&f->mnt->ref, 1);
 		(*ao)->op = AOclear;
 		(*ao)->mnt = f->mnt;
 		(*ao)->qpath = f->qpath;
@@ -2472,8 +2472,7 @@
 
 	c->iounit = Max9p;
 
-	c->ref = 1;
-
+	aswapl(&c->ref, 1);
 	lock(&fs->connlk);
 	c->next = fs->conns;
 	fs->conns = c;
@@ -2490,7 +2489,7 @@
 	Fid *f;
 	int i;
 
-	if(adec(&c->ref) != 0)
+	if(aincl(&c->ref, -1) != 0)
 		return;
 
 	lock(&fs->connlk);
@@ -2516,7 +2515,7 @@
 				unlock(&c->fidtablk[i]);
 				break;
 			}
-			ainc(&f->ref);
+			aincl(&f->ref, 1);
 			unlock(&c->fidtablk[i]);
 			
 			wlock(f);
--- a/sys/src/cmd/gefs/load.c
+++ b/sys/src/cmd/gefs/load.c
@@ -81,7 +81,7 @@
 	if(waserror())
 		sysfatal("load fs: %s", errmsg());
 	snprint(dump->name, sizeof(dump->name), "dump");
-	dump->ref = 1;
+	aswapl(&dump->ref, 1);
 	dump->gen = -1;
 	aswapp(&dump->root, &fs->snap);
 
--- a/sys/src/cmd/gefs/snap.c
+++ b/sys/src/cmd/gefs/snap.c
@@ -398,7 +398,7 @@
 			free(n);
 			nexterror();
 		}
-		n->memref = 1;
+		aswapl(&n->memref, 1);
 		n->dirty = 0;
 		n->nlbl = 1;
 		n->nref = 0;
@@ -467,7 +467,7 @@
 		free(t);
 		nexterror();
 	}
-	t->memref = 1;
+	aswapl(&t->memref, 1);
 	t->dirty = 0;
 
 	t->nlbl = 1;
@@ -544,7 +544,7 @@
 	if(!btlookup(&fs->snap, &k, &kv, buf, sizeof(buf)))
 		broke(Efs);
 	unpacktree(t, kv.v, kv.nv);
-	t->memref = 1;
+	aswapl(&t->memref, 1);
 	t->memgen = fs->nextgen++;
 	poperror();
 	return t;
@@ -557,7 +557,7 @@
 void
 closesnap(Tree *t)
 {
-	if(t == nil || adec(&t->memref) != 0)
+	if(t == nil || aincl(&t->memref, -1) != 0)
 		return;
 	limbo(DFtree, t);
 }
--