shithub: gefs

Download patch

ref: a35dbf7f6fb9a9ae24d1064d065a1d374d1bfc1b
parent: 922b66759f87b90aa243a1cc666f64568439158a
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Mar 2 17:05:50 EST 2024

blk: error when running out of space during log compression

--- a/blk.c
+++ b/blk.c
@@ -390,7 +390,7 @@
 	}
 }
 
-int
+void
 compresslog(Arena *a)
 {
 
@@ -431,19 +431,15 @@
 	 */
 	nblks = (sz+Logspc)/(Logspc - Logslop) + 16*nr/(Logspc-Logslop) + 1;
 	if((blks = calloc(nblks, sizeof(vlong))) == nil)
-		return -1;
+		error(Enomem);
 	if(waserror()){
 		free(blks);
-		return -1;
+		nexterror();
 	}
 	for(i = 0; i < nblks; i++){
 		blks[i] = blkalloc_lk(a);
-		if(blks[i] == -1){
-			fprint(2, "out of space to compress log\n");
-			free(blks);
-			poperror();
-			return -1;
-		}
+		if(blks[i] == -1)
+			error(Estuffed);
 	}
 	/* fill up the log with the ranges from the tree */
 	i = 0;
@@ -477,8 +473,8 @@
 
 	/*
 	 * now we have a valid freelist, and we can start
-	 * appending stuff to it. Clean up the old logs
-	 * and the eagerly allocated extra blocks.
+	 * appending stuff to it. Clean up the eagerly
+	 * allocated extra blocks.
 	 */
 	a->loghd = hd;
 	a->logtl = b;
@@ -488,7 +484,6 @@
 	}
 	poperror();
 	free(blks);
-	return 0;
 }
 
 int
@@ -990,7 +985,7 @@
 	int i;
 
 	if(qe.op == Qfree || qe.op == Qwrite)
-		assert((qe.bp.addr & (Blksz-1)) == 0);
+		assert(qe.bp.addr != 0 && (qe.bp.addr & (Blksz-1)) == 0);
 	else if(qe.op == Qfence)
 		assert(fs->syncing > 0);
 	else
--- a/fns.h
+++ b/fns.h
@@ -88,7 +88,7 @@
 void	loadlog(Arena*, Bptr);
 int	scandead(Dlist*, int, void(*)(Bptr, void*), void*);
 int	endfs(void);
-int	compresslog(Arena*);
+void	compresslog(Arena*);
 void	dlsync(void);
 void	setval(Blk*, Kvp*);
 
--- a/fs.c
+++ b/fs.c
@@ -2348,7 +2348,7 @@
 		sysfatal("malloc log heads");
 	while(1){
 		am = chrecv(fs->admchan);
-		if(fs->rdonly){
+		if(agetl(&fs->rdonly)){
 			fprint(2, "spurious adm message\n");
 			break;
 		}
@@ -2376,31 +2376,35 @@
 					qunlock(a);
 					continue;
 				}
+				if(waserror()){
+					qunlock(&fs->mutlk);
+					qunlock(a);
+					nexterror();
+				}
 				oldhd[i] = a->loghd;
 				epochstart(id);
-				if(compresslog(a) == -1)
-					fprint(2, "compress log: %r");
+				compresslog(a);
 				qunlock(a);
 				epochend(id);
 				epochclean();
+				poperror();
 			}
 			qunlock(&fs->mutlk);
 			sync();
 
-			qlock(&fs->mutlk);
 			for(i = 0; i < fs->narena; i++){
 				for(bp = oldhd[i]; bp.addr != -1; bp = nb){
+					qlock(&fs->mutlk);
 					epochstart(id);
-					if((b = getblk(bp, 0)) == nil)
-						broke("reading %B: %s", bp, errmsg());
+					b = getblk(bp, 0);
 					nb = b->logp;
 					freeblk(nil, b, b->bp);
 					dropblk(b);
 					epochend(id);
 					epochclean();
+					qunlock(&fs->mutlk);
 				}
 			}
-			qunlock(&fs->mutlk);
 
 			if(am->halt){
 				postnote(PNGROUP, getpid(), "halted");