code: mafs

Download patch

ref: cd418647069ac658a93491cd2b1b2fcd4112f606
parent: 9807465425b73988f6c9933a74e0518aa1296d86
author: 9ferno <gophone2015@gmail.com>
date: Thu Oct 20 06:24:06 EDT 2022

fix bug when freeing used blocks

--- a/iobuf.c
+++ b/iobuf.c
@@ -286,7 +286,6 @@
 		if(chatty9p > 4)
 		dprint(" .. runlock()'ed\n");
 	}else{
-
 		if(canwlock(p)){
 			panic("putbuf: buffer not locked %llud\n", p->blkno);
 		}
@@ -340,8 +339,8 @@
 
 	if(p->readers){
 		chkrunlock(p);
-		if(chatty9p > 4)
-		dprint(" .. runlock()'ed\n");
+		// if(chatty9p > 4)
+		panic(" .. runlock()'ed\n");
 	}else{
 		if(canwlock(p)){
 			panic("putbuffree: buffer not locked %llud\n", p->blkno);
--- a/sub.c
+++ b/sub.c
@@ -121,13 +121,12 @@
 	if(buf->readers)
 		panic("freeblockbuf without Bwritable");
 
+	/* clear the buf to avoid leaks on reuse */
+	memset(buf->io, 0, buf->len*Rawblocksize);
 	if(buf->dirties)
 		buf->tofree = 1;
-	else{
-		/* clear the buf to avoid leaks on reuse */
-		memset(buf->io, 0, buf->len*Rawblocksize);
+	else
 		bfree(&frees, buf->blkno, buf->len);
-	}
 	putbuffree(buf);
 }
 
--- a/writer.c
+++ b/writer.c
@@ -174,10 +174,11 @@
 	dprint("dowrite %llud wunlock()'ed\n", n);
 	wlock(p->iobuf);
 	p->iobuf->dirties--;
-	if(p->iobuf->tofree && p->iobuf->dirties == 0)
-		freeblockbuf(p->iobuf);
-	else
-		wunlock(p->iobuf);
+	if(p->iobuf->tofree && p->iobuf->dirties == 0){
+		p->iobuf->tofree = 0;
+		bfree(&frees, p->iobuf->blkno, p->iobuf->len);
+	}
+	wunlock(p->iobuf);
 	free(p);
 }