code: mafs

Download patch

ref: c947228f7cf50bbbeb3f1e1b1808280e9ae9247f
parent: d46674c804f38dc472de8d9f68a946a557d121eb
author: 9ferno <gophone2015@gmail.com>
date: Wed Oct 19 05:04:51 EDT 2022

working writer

--- a/writer.c
+++ b/writer.c
@@ -23,6 +23,7 @@
 } drts = {0};
 
 u8 stopwrites = 0;
+static void stats(void);
 
 static Iobuf *
 pluck(Iobuf *b)
@@ -68,7 +69,15 @@
 	Iobuf *p;
 
 	qlock(&drts.lck);
+	if(chatty9p > 4){
+		dprint("rmwrite start b->blkno %llud\n", b->blkno);
+		stats();
+	}
 	p = pluck(b);
+	if(chatty9p > 4 && p!=nil){
+		dprint("rmwrite removed p->blkno %llud\n", p->blkno);
+		stats();
+	}
 	qunlock(&drts.lck);
 	return p;
 }
@@ -90,24 +99,34 @@
 			return nil;
 		}
 	}
-	b = pluck(drts.head);
+	/* using canwlock() here as getbuf() could
+		have wlock()'ed the Iobuf too */
+	if(drts.head != nil && canwlock(drts.head))
+		b = pluck(drts.head);
+	else
+		b = nil;
+	if(chatty9p > 4 && b!=nil){
+		dprint("getwrite done b->blkno %llud\n", b->blkno);
+		stats();
+	}
 	qunlock(&drts.lck);
 	return b;
 }
 
-static void stats(void);
-
 /* the Iobuf should be wlock()'ed at entry */
 void
 putwrite(Iobuf *b)
 {
-	if(chatty9p > 4)
-		dprint("putwrite p->blkno %llud\n", b->blkno);
 	qlock(&drts.lck);
+	if(chatty9p > 4){
+		dprint("putwrite start p->blkno %llud\n", b->blkno);
+		stats();
+	}
 	if(drts.n > Npendingwrites){
 		if(drts.n < 0)
 			panic("putwrite drts.n < 0\n");
-		stats();
+		if(chatty9p > 4)
+			stats();
 	}
 	b->dirty = 1;
 	if(drts.head == nil){
@@ -117,13 +136,17 @@
 		b->prevdirty = drts.tail;
 		drts.tail = b;
 	}
-	if(drts.head == drts.tail)
+	drts.n++;
+	if(drts.n == 1)
 		rwakeup(&drts.isempty);
 	if(chkwunlock(b) == 0){
 		showbuf(b);
 		panic("putwrite chkwunlock(p) == 0 called by %#p\n", getcallerpc(&b));
 	}
-	drts.n++;
+	if(chatty9p > 4 && b!=nil){
+		dprint("putwrite done b->blkno %llud\n", b->blkno);
+		stats();
+	}
 	qunlock(&drts.lck);
 }
 
@@ -132,9 +155,10 @@
 {
 	u64 n;
 
-	if(chatty9p > 4)
+	if(chatty9p > 4){
 		dprint("dowrite p->blkno %llud\n", p->blkno);
-	wlock(p);
+		stats();
+	}
 	if(chatty9p > 4)
 		dprint("dowrite p->blkno %llud locked\n", p->blkno);
 	p->io->dirty = 1;