shithub: gefs

Download patch

ref: 5d7489fe70cf6163ca96a6e0b9d9bb53557602e3
parent: 3cd02d7caba79a9b680b4685d963c812d6eeda58
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Apr 20 15:48:57 EDT 2022

flags: remove direct access

we'll need to do atomics properly soon; putting it in
one function will be useful.

--- a/blk.c
+++ b/blk.c
@@ -28,14 +28,20 @@
 
 static Blk magic;
 
+int
+checkflag(Blk *b, int f)
+{
+	return (b->flag & f) == f;
+}
+
 void
-setflag(Blk *b, int flg)
+setflag(Blk *b, int f)
 {
 	long ov, nv;
 
 	while(1){
 		ov = b->flag;
-		nv = ov | flg;
+		nv = ov | f;
 		if(cas(&b->flag, ov, nv))
 			break;
 	}
@@ -42,13 +48,13 @@
 }
 
 void
-clrflag(Blk *b, int flg)
+clrflag(Blk *b, int f)
 {
 	long ov, nv;
 
 	while(1){
 		ov = b->flag;
-		nv = ov & ~flg;
+		nv = ov & ~f;
 		if(cas(&b->flag, ov, nv))
 			break;
 	}
@@ -57,7 +63,7 @@
 int
 syncblk(Blk *b)
 {
-	assert(b->flag & Bfinal);
+	assert(checkflag(b, Bfinal));
 	clrflag(b, Bqueued|Bdirty);
 	return pwrite(fs->fd, b->buf, Blksz, b->bp.addr);
 }
@@ -820,8 +826,8 @@
 {
 	if(b == nil || adec(&b->ref) != 0)
 		return;
-	assert(!(b->flag & Bcached));
-	assert((b->flag & Bfreed) || !(b->flag & Bdirty));
+	assert(checkflag(b, Bcached));
+	assert(checkflag(b, Bfreed) || !checkflag(b, Bdirty));
 	free(b);
 }
 
@@ -927,7 +933,7 @@
 	Arena *a;
 
 	a = getarena(b->bp.addr);
-	assert(b->flag & Bdirty);
+	assert(checkflag(b, Bdirty));
 	refblk(b);
 	finalize(b);
 	chsend(a->sync, b);
@@ -1011,7 +1017,7 @@
 		}
 	
 		b = qpop(&q);
-		if(!(b->flag & Bfreed)){
+		if(!checkflag(b, Bfreed)){
 			if(syncblk(b) == -1){
 				ainc(&fs->broken);
 				fprint(2, "write: %r");
--- a/cache.c
+++ b/cache.c
@@ -82,7 +82,7 @@
 	b->cnext = fs->chead;
 	b->cprev = nil;
 	fs->chead = b;
-	if((b->flag & Bcached) == 0){
+	if(!checkflag(b, Bcached)){
 		setflag(b, Bcached);
 		fs->ccount++;
 		refblk(b);
--- a/fns.h
+++ b/fns.h
@@ -62,6 +62,7 @@
 char*	btnext(Scan*, Kvp*, int*);
 void	btdone(Scan*);
 
+int	checkflag(Blk *b, int);
 void	setflag(Blk *b, int);
 void	clrflag(Blk *b, int);
 
--- a/pack.c
+++ b/pack.c
@@ -432,7 +432,7 @@
 		dl = &t->dead[i];
 		bp = dl->head;
 		if(dl->ins != nil){
-			assert(dl->ins->flag & Bfinal);
+			assert(checkflag(dl->ins, Bfinal));
 			bp = dl->ins->bp;
 		}
 		PBIT64(p, dl->prev);	p += 8;
--- a/ream.c
+++ b/ream.c
@@ -98,7 +98,7 @@
 	b->bp.addr = addr;
 	b->logsz = 32;
 	b->data = b->buf + _Loghdsz;
-	b->flag |= Bdirty;
+	setflag(b, Bdirty);
 
 	p = b->data + Loghashsz;
 	PBIT64(p, addr|LogFree);	p += 8;	/* addr */