shithub: gefs

Download patch

ref: 4f4c6a98f4cd1a604ec013b7ed1e5ab45095c691
parent: 19d4db9fddeaecaa7017c2557013c776183bcad5
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Nov 2 23:59:42 EDT 2023

blk: fix deadlock with full queues

we should not enqueue anything from the sync proc,
since the sync proc reads from the queue; therefore,
if it blocks inserting into a full queue, it will
never pull anything out of the queue again.

--- a/blk.c
+++ b/blk.c
@@ -249,19 +249,6 @@
 	return lb;
 }
 
-static void
-chainlog(Blk *pb, Bptr nb)
-{
-	if(pb == nil)
-		return;
-	assert(pb->type == Tlog);
-	setflag(pb, Bdirty);
-	pb->logp = nb;
-	finalize(pb);
-	enqueue(pb);
-	return;
-}
-
 /*
  * Logs an allocation. Must be called
  * with arena lock held. Duplicates some
@@ -307,7 +294,13 @@
 		p = lb->data + lb->logsz;
 		PACK64(p, o|LogAlloc1);
 		lb->logsz += 8;
-		chainlog(lb, nl->bp);
+		lb->logp = nl->bp;
+		setflag(lb, Bdirty);
+		finalize(lb);
+		if(syncblk(lb) == -1){
+			fs->broken = 1;
+			return -1;
+		}
 		dropblk(lb);
 		a->logtl = nl;
 		a->nlog++;
@@ -459,7 +452,11 @@
 				return -1;
 			a->nlog++;
 			initblk(nb, blks[i++], -1, Tlog);
-			chainlog(b, nb->bp);
+
+			b->logp = nb->bp;
+			setflag(b, Bdirty);
+			finalize(b);
+			enqueue(b);
 			dropblk(b);
 			b = nb;
 		}
@@ -468,6 +465,7 @@
 		PACK64(p+8, r->len);
 		setflag(b, Bdirty);
 		b->logsz += 16;
+		setflag(b, Bdirty);
 	}
 	finalize(b);
 	enqueue(b);
@@ -484,7 +482,7 @@
 		cachedel(b->bp.addr);
 		blkdealloc_lk(a, blks[i]);
 	}
-	return 0;	
+	return 0;
 }
 
 int
--- a/fs.c
+++ b/fs.c
@@ -2,7 +2,6 @@
 #include <libc.h>
 #include <auth.h>
 #include <fcall.h>
-#include <pool.h>
 #include <avl.h>
 
 #include "dat.h"