code: mafs

Download patch

ref: f4efa27b0a01aa1a2ae6a8b8a070d03182354b4b
parent: da43b39403be2916501997c130ad0c377be7d2c8
author: 9ferno <gophone2015@gmail.com>
date: Fri Nov 25 08:57:17 EST 2022

fixed the deadlock while getting a buffer and flush on close

--- a/9p.c
+++ b/9p.c
@@ -90,12 +90,17 @@
 		}
 		qunlock(&tlock);
 	}
-/*	dbuf = getmetachk(((Aux*)fid->aux)->dblkno,
-						Bwritable, Tdentry, fid->qid.path);
+
+	/* allocate on flush as many as possible */
+	dbuf = getmeta(((Aux*)fid->aux)->dblkno, Bwritable, Bused);
 	if(dbuf != nil){
-		writeallappend(dbuf, (Dentry*)dbuf->new, ((Aux*)fid->aux)->dblkno);
-		putbuf(dbuf, 1);
-	} */
+		if(p->xiobuf != nil &&
+			p->xiobuf[0] == Tdentry &&
+			p->append != nil)
+			flush(p);
+		else
+			putbuf(dbuf, 0);
+	}
 	freeaux(fid->aux);
 }
 
--- a/dentry.c
+++ b/dentry.c
@@ -1,5 +1,6 @@
 #include	"all.h"
 
+/* b shoud be wlock'ed */
 s8
 flush(Iobuf *b)
 {
--- a/iobuf.c
+++ b/iobuf.c
@@ -245,17 +245,11 @@
 Another:
 		do{
 			p = s->back;
-			if(p->ref == 0 && canwlock(p)){
-				if(p->ref > 0){
+			if(p->ref == 0 && p->append != nil && canwlock(p)){
+				if(p->ref > 0 || p->append != nil){
 					wunlock(p);
 					goto Another;
 				}
-				/* allocate on flush as many as possible */
-				if(p->xiobuf[0] == Tdentry &&
-					p->append != nil){
-					if(flush(p))
-						goto Another;
-				}
 				if(p->len != len){
 					freememunits(p->xiobuf, p->len);
 					p->xiobuf = allocmemunits(len);
@@ -430,7 +424,7 @@
 		}else if(p->xiobuf[0] > Tdata && p->xiobuf[0] < MAXTAG){
 			/*
 				make the new->ver below the cur->ver so the new gets
-				overwritten the next time instead of a memcpy() to
+				overwritten on the next access instead of a memcpy() to
 				copy the contents over.
 			 */
 			p->new->verd = p->cur->verd-1;