shithub: gefs

Download patch

ref: 3c0cb629fe2956046ab1aab819e1baf5b5993457
parent: af2971215e13a03253283408038931f5924abf07
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Oct 16 22:50:15 EDT 2022

fs: implement Tflush

--- a/dat.h
+++ b/dat.h
@@ -41,6 +41,7 @@
 	Nsec	= 1000LL*1000*1000,	/* nanoseconds to the second */
 	Maxname	= 256,			/* maximum size of a name element */
 	Maxent	= 9+Maxname+1,		/* maximum size of ent key, with terminator */
+	Maxtag	= 1<<16,		/* maximum tag in 9p */
 
 	/*
 	 * Kpmax must be no more than 1/4 of pivspc, or
@@ -351,6 +352,7 @@
 	Fcall;
 	Conn	*conn;
 	int	sz;	/* the size of the message buf */
+	Fmsg	*flush;	/* the flush message */
 	Amsg	*a;	/* admin messages */
 	uchar	buf[];
 };
@@ -463,6 +465,9 @@
 	Blk	*ctail;
 	usize	ccount;
 	usize	cmax;
+
+	Lock	mflushlk;
+	Fmsg	*mflush[Maxtag];
 
 	Stats	stats;
 };
--- a/fs.c
+++ b/fs.c
@@ -166,6 +166,7 @@
 static void
 respond(Fmsg *m, Fcall *r)
 {
+	Fcall rf;
 	uchar buf[Max9p];
 	int w, n;
 
@@ -176,6 +177,14 @@
 	w = write(m->conn->fd, buf, n);
 	if(w != n)
 		fshangup(m->conn->fd, Eio);
+	if(m->type != Tflush) {
+		lock(&fs->mflushlk);
+		fs->mflush[m->tag] = nil;
+		rf.type = Rflush;
+		if(m->flush != nil)
+			respond(m->flush, &rf);
+		unlock(&fs->mflushlk);
+	}
 	free(m);
 }
 
@@ -603,6 +612,7 @@
 	m->conn = c;
 	m->sz = sz;
 	m->a = nil;
+	m->flush = nil;
 	PBIT32(m->buf, sz);
 	*pm = m;
 	return 0;
@@ -1819,6 +1829,21 @@
 }
 
 void
+fsflush(Fmsg *m)
+{
+	Fcall r;
+
+	lock(&fs->mflushlk);
+	if(fs->mflush[m->oldtag] != nil)
+		fs->mflush[m->oldtag]->flush = m;
+	else{
+		r.type = Rflush;
+		respond(m, &r);
+	}
+	unlock(&fs->mflushlk);
+}
+
+void
 runfs(int, void *pfd)
 {
 	Conn *c;
@@ -1854,6 +1879,11 @@
 			return;
 		}
 		dprint("← %F\n", &m->Fcall);
+
+		lock(&fs->mflushlk);
+		fs->mflush[m->tag] = m;
+		unlock(&fs->mflushlk);
+
 		switch(m->type){
 		/* sync setup */
 		case Tversion:	fsversion(m);	break;