shithub: gefs

Download patch

ref: 316027876e3aec127a377f75dc98bec3faf2a329
parent: da92726a25879c4e00f7bd6399d07b24cc43597b
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Dec 29 13:38:33 EST 2023

blk: when clearing the log, clear out the old logbuf

this prevents us from removing the block we cleared out
from cache later, which can lead to crashes if we've
reused the block, muated it, and reenqueued it, due
to getting block version skew

--- a/blk.c
+++ b/blk.c
@@ -301,7 +301,6 @@
 		PACK64(p, o|LogAlloc1);
 		lb->logsz += 8;
 		lb->logp = nl->bp;
-		setflag(lb, Bdirty);
 		finalize(lb);
 		syncblk(lb);
 		a->logtl = nl;
@@ -449,8 +448,12 @@
 	/* fill up the log with the ranges from the tree */
 	i = 0;
 	hd = (Bptr){blks[0], -1, -1};
-	b = cachepluck();
+	b = a->logbuf[a->lbidx++ % nelem(a->logbuf)];
+	a->logbuf[a->lbidx % nelem(a->logbuf)]->bp = Zb;
+	if(b->bp.addr != -1)
+		cachedel(b->bp.addr);
 	initblk(b, blks[i++], -1, Tlog);
+	finalize(b);
 	for(r = (Arange*)avlmin(a->free); r != nil; r = (Arange*)avlnext(r)){
 		if(b->logsz >= Logspc - Logslop){
 			a->nlog++;
@@ -467,9 +470,7 @@
 		p = b->data + b->logsz;
 		PACK64(p+0, r->off|LogFree);
 		PACK64(p+8, r->len);
-		setflag(b, Bdirty);
 		b->logsz += 16;
-		setflag(b, Bdirty);
 	}
 	finalize(b);
 	syncblk(b);