code: mafs

Download patch

ref: 1149d44033da561c89489db28f5f95d81f7251e1
parent: 9cf2807db9e8268a4dfbce19561bd712e4430a39
author: 9ferno <gophone2015@gmail.com>
date: Thu Nov 17 21:36:37 EST 2022

respond before putting the directory Iobuf

--- a/9p.c
+++ b/9p.c
@@ -5,8 +5,8 @@
 extern int mpstarted;
 extern u8 synchronouswrites;
 
-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 readfile(u64 dblkno, u64 qpath, char *rbuf, s32 rbufsize, u64 offset, Req *req);
+s32 writefile(u64 dblkno, u64 qpath, s16 uid, char *wbuf, s32 wbufsize, u64 offset, Req *req);
 
 Aux*
 newaux(u64 addr, u16 uid)
@@ -292,11 +292,9 @@
 		return;
 	}
 
-	n = readfile(((Aux*)req->fid->aux)->dblkno, req->fid->qid.path,
-				 req->ofcall.data, req->ifcall.count, req->ifcall.offset);
-	req->ofcall.count = n;
-	req->ofcall.offset = req->ifcall.offset+n;
-	respond(req, nil);
+	readfile(((Aux*)req->fid->aux)->dblkno, req->fid->qid.path,
+				 req->ofcall.data, req->ifcall.count, req->ifcall.offset,
+				 req);
 }
 
 
@@ -303,8 +301,6 @@
 static void
 fswrite(Req *req)
 {
-	int n;
-
 	if(shuttingdown){
 		respond(req, errstring[Eshutdown]);
 		return;
@@ -325,18 +321,9 @@
 		return;
 	}
 
-	n = writefile(((Aux*)req->fid->aux)->dblkno, req->fid->qid.path,
+	writefile(((Aux*)req->fid->aux)->dblkno, req->fid->qid.path,
 					((Aux*)req->fid->aux)->uid,
-					req->ifcall.data, req->ifcall.count, req->ifcall.offset);
-	if(n == -3)
-		respond(req, errstring[Efull]);
-	else if(n == -1 || n == -2)
-		respond(req, errstring[Ephase]);
-	else{
-		req->ofcall.count = n;
-		req->ofcall.offset = req->ifcall.offset+n;
-		respond(req, nil);
-	}
+					req->ifcall.data, req->ifcall.count, req->ifcall.offset, req);
 }
 
 static void
@@ -1230,7 +1217,7 @@
 	return filesize;
 }
 s32
-readfile(u64 dblkno, u64 qpath, char *rbuf, s32 rbufsize, u64 offset)
+readfile(u64 dblkno, u64 qpath, char *rbuf, s32 rbufsize, u64 offset, Req *req)
 {
 	Dentry *d;
 	s64 tosend, sent, filesize;
@@ -1269,6 +1256,11 @@
 		sent += n;
 		putbuf(buf);
 	}
+	if(req != nil){
+		req->ofcall.count = sent;
+		req->ofcall.offset = req->ifcall.offset+sent;
+		respond(req, nil);
+	}
 	putbuf(dbuf);
 	return sent;
 }
@@ -1407,7 +1399,7 @@
 			data blocks from offset until offset+wbufsize
  */
 s32
-writefile(u64 dblkno, u64 qpath, s16 uid, char *wbuf, s32 wbufsize, u64 offset)
+writefile(u64 dblkno, u64 qpath, s16 uid, char *wbuf, s32 wbufsize, u64 offset, Req *req)
 {
 	Dentry *d;
 	s64 written;
@@ -1511,6 +1503,17 @@
 
 writeend:
 	d->mtime = nsec();
+	if(req != nil){
+		if(written == -3)
+			respond(req, errstring[Efull]);
+		else if(written == -1 || written == -2)
+			respond(req, errstring[Ephase]);
+		else{
+			req->ofcall.count = written;
+			req->ofcall.offset = req->ifcall.offset+written;
+			respond(req, nil);
+		}
+	}
 	putbuf(dbuf);
 	return written;
 }
--- a/all.h
+++ b/all.h
@@ -142,11 +142,11 @@
 u64 	addrelative(Dentry *d, u64 dblkno, u64 reli, u64 blkno);
 Iobuf*	getdatablkat(Dentry *d, u64 reli, int flags);
 void	loadfrees(u64 dblkno);
-s32		readfile(u64 dblkno, u64 qpath, char *rbuf, s32 rbufsize, u64 offset);
+s32		readfile(u64 dblkno, u64 qpath, char *rbuf, s32 rbufsize, u64 offset, Req *req);
 s32		readfilesize(u64 dblkno, u64 qpath);
 void	savefrees(u64 dblkno);
 void	truncatefile(u64 qpath, u64 dblkno, s16 uid);
-s32		writefile(u64 dblkno, u64 qpath, s16 uid, char *wbuf, s32 wbufsize, u64 offset);
+s32		writefile(u64 dblkno, u64 qpath, s16 uid, char *wbuf, s32 wbufsize, u64 offset, Req *req);
 
 /* user access routines */
 int	byname(void*, void*);
--- a/dentry.c
+++ b/dentry.c
@@ -534,7 +534,7 @@
 		panic("savefrees nbuf not enough");
 
 	/* writing the actual extents now */
-	writefile(dblkno, Qpfrees, -1, buf, nbuf, 0);
+	writefile(dblkno, Qpfrees, -1, buf, nbuf, 0, nil);
 	free(buf);
 }
 
@@ -553,7 +553,7 @@
 	buf = emalloc(size);
 	if(buf == nil)
 		panic("loadfrees: nil emalloc of %llud bytes", size);
-	if(readfile(dblkno, Qpfrees, buf, size, 0) != size)
+	if(readfile(dblkno, Qpfrees, buf, size, 0, nil) != size)
 		panic("loadfrees: could not load frees");
 	n = loadextents(&frees, buf, size);
 	if(chatty9p > 2)
--- a/user.c
+++ b/user.c
@@ -428,7 +428,7 @@
 	buf = emalloc9p(usize);
 	putbuf(ubuf);
 
-	readfile(Bdusersinuse, Qpusersinuse, buf, usize, 0);
+	readfile(Bdusersinuse, Qpusersinuse, buf, usize, 0, nil);
 	if((rv=parseusers(&us, buf, usize)) != 0)
 		panic("could not parse /adm/users/inuse rv %d\n", rv);
 	free(buf);
@@ -456,13 +456,13 @@
 	buf = emalloc9p(usize);
 	putbuf(ubuf);
 
-	readfile(Bdusersstaging, Qpusersstaging, buf, usize, 0);
+	readfile(Bdusersstaging, Qpusersstaging, buf, usize, 0, nil);
 	if(parseusers(&us, buf, usize) != 0)
 		panic("could not parse /adm/users/staging\n");
 
 	wlock(&userslock);
 	old = lruuser;
-	writefile(Bdusersinuse, Qpusersinuse, -1, buf, usize, 0);
+	writefile(Bdusersinuse, Qpusersinuse, -1, buf, usize, 0, nil);
 	lruuser = us;
 	wunlock(&userslock);