code: mafs

Download patch

ref: 940fed7b16dbe39ba1f9f52ec3aca14392199145
parent: b7192df9832868f246dfd7210585fbd3a1db9880
author: 9ferno <gophone2015@gmail.com>
date: Mon Nov 28 21:06:16 EST 2022

flush when there is a flush function available and there are no available extents

--- a/9p.c
+++ b/9p.c
@@ -9,7 +9,6 @@
 s32 readfile(u64 dblkno, u64 qpath, char *rbuf, s32 rbufsize, u64 offset);
 s32 writefile(u64 dblkno, u64 qpath, s16 uid, char *wbuf, s32 wbufsize, u64 offset);
 s32 writeallappend(Iobuf *dbuf, Dentry *d, u64 dblkno);
-static void fsflush(void);
 
 Aux*
 newaux(u64 addr, u16 uid)
@@ -1060,7 +1059,7 @@
 	worker[id].pid = 0;
 }
 
-static void
+void
 fsflush(void)
 {
 	if(canwlock(&flushlck)){
--- a/all.h
+++ b/all.h
@@ -104,6 +104,7 @@
 void	initmemunitpool(u64 nunits);
 u8*		allocmemunits(u16 len);
 void	freememunits(u8 *m, u16 len);
+void	fsflush(void);
 int		checktag(Iobuf *p, u16 len, u8 tag, u64 qpath);
 Iobuf*	getbuf(u64 blkno, u16 len, u8 readonly, u8 freshalloc);
 Iobuf*	getbufchk(u64 blkno, u16 len, u8 readonly, int tag, u64 qpath);
--- a/extents.c
+++ b/extents.c
@@ -467,7 +467,12 @@
 	if(e == nil){
 		snprint(msg, 64, "balloc() %llud %s: waiting\n", n, es->name);
 		showextents(2, msg, es);
-		rsleep(&es->isempty);
+		if(es->flush){
+			qunlock(&es->lck);
+			(*es->flush)();
+			qlock(&es->lck);
+		}else
+			rsleep(&es->isempty);
 		goto again;
 	}
 	else if(e->len == n)
@@ -681,11 +686,12 @@
 }
 
 void
-initextents(Extents *es, char *name)
+initextents(Extents *es, char *name, void (*flush)(void))
 {
 	es->isempty.l = &es->lck;
 	if(name != nil)
 		strncpy(es->name, name, 32);
+	es->flush = flush;
 }
 
 /* obsolete */
--- a/extents.h
+++ b/extents.h
@@ -28,6 +28,8 @@
 	u8 nlru;		/* number of items in the lru linked list */
 	Extent *lru;	/* least recently used extent in the circular lru linked list */
 	char name[32];
+
+	void (*flush)(void);
 };
 
 extern int chatty9p;
@@ -48,4 +50,4 @@
 u64	 nfrees(Extents *es);
 
 Extent *lowest(Extents *es);
-void	initextents(Extents *es, char *name);
+void	initextents(Extents *es, char *name, void (*flush)(void));
--- a/free.c
+++ b/free.c
@@ -50,7 +50,7 @@
 		print("%s %llud bytes %llud blocks\n", devfile, size, size/Blocksize);
 
 	checkdentry(Bdfrees, Tdentry, Qpfrees);
-	initextents(&frees, "frees");
+	initextents(&frees, "frees", nil);
 	getfrees(Bdfrees);
 	showextents(1, "", &frees);
 	// showblocknos(1, &frees);
--- a/iobuf.c
+++ b/iobuf.c
@@ -19,7 +19,7 @@
 {
 	memunitstart = sbrk((nunits+1) * Blocksize);
 	memunitpool = memunitstart+Blocksize- ((u64)memunitstart%Blocksize);
-	initextents(&memunits, "memunits");
+	initextents(&memunits, "memunits", fsflush);
 	if(chatty9p > 4)
 		dprint("initmemunitpool: memunitpool %p nunits*Blocksize %p\n",
 				memunitpool, nunits*Blocksize);
--- a/mafs.c
+++ b/mafs.c
@@ -98,7 +98,7 @@
 
 	formatinit();
 	initmemunitpool(nmemunits);
-	initextents(&frees, "blocks");
+	initextents(&frees, "blocks", nil);
 	iobufinit();
 
 	/*
--- a/reconcile.c
+++ b/reconcile.c
@@ -165,7 +165,7 @@
 	if(debug)
 		print("collect %s ", s->name);
 	s->es = emalloc(sizeof(Extents));
-	initextents(s->es, s->name);
+	initextents(s->es, s->name, nil);
 	while((s->buf = Brdstr(&s->bp, '\n', 1)) != nil) {
 		p = s->buf;
 		start = strtoull(p, &ep, 10);
--- a/unused.c
+++ b/unused.c
@@ -97,7 +97,7 @@
 		show(&u);
 
 	/* identify unused blocks */
-	initextents(&unused, "unused");
+	initextents(&unused, "unused", nil);
 	for(i = 0; i < nblocks; i++){
 		if(find(u.es, i) == 0){
 			add(&unused, i, 1);
@@ -136,7 +136,7 @@
 	if(debug)
 		print("collect %s ", s->name);
 	s->es = emalloc(sizeof(Extents));
-	initextents(s->es, s->name);
+	initextents(s->es, s->name, nil);
 	while((s->buf = Brdstr(&s->bp, '\n', 1)) != nil) {
 		p = s->buf;
 		start = strtoull(p, &ep, 10);
--- a/used.c
+++ b/used.c
@@ -51,7 +51,7 @@
 	if(chatty9p)
 		print("%s %llud bytes %llud blocks\n", devfile, size, size/Blocksize);
 
-	initextents(&useds, "useds");
+	initextents(&useds, "useds", nil);
 	checkdentry(Bdmagic, Tdentry, Qpmagic);
 	walkdirectory(Bdroot);
 	close(devfd);