shithub: gefs

Download patch

ref: d8bf2d13eceed89dc3215daca019ef67683f8d83
parent: f3942a1a181abbaa1287703cc87198a8f16ca356
author: Ori Bernstein <ori@eigenstate.org>
date: Sat May 27 21:26:30 EDT 2023

fs: correct flush behavior

we want to wlock the *old* tag in flush

--- a/fs.c
+++ b/fs.c
@@ -211,11 +211,13 @@
 	qunlock(&m->conn->wrlk);
 	if(w != n)
 		fshangup(m->conn, Eio);
-	lk = &fs->flushq[ihash(m->tag) % Nflushtab];
-	if(m->type == Tflush)
+	if(m->type == Tflush){
+		lk = &fs->flushq[ihash(m->oldtag) % Nflushtab];
 		wunlock(lk);
-	else
+	}else{
+		lk = &fs->flushq[ihash(m->tag) % Nflushtab];
 		runlock(lk);
+	}
 	free(m);
 }
 
@@ -2069,12 +2071,12 @@
 runfs(int, void *pc)
 {
 	char err[128];
-	long old;
-	u32int h;
 	RWLock *lk;
 	Conn *c;
 	Fcall r;
 	Fmsg *m;
+	u32int h;
+	long old;
 
 	c = pc;
 	while(1){
@@ -2098,11 +2100,13 @@
 			fprint(2, "dup incoming tag: %d [type=%ld]\n", m->tag, old);
 			abort();
 		}
-		lk = &fs->flushq[ihash(m->tag) % Nflushtab];
-		if(m->type == Tflush)
+		if(m->type == Tflush){
+			lk = &fs->flushq[ihash(m->oldtag) % Nflushtab];
 			wlock(lk);
-		else
+		}else{
+			lk = &fs->flushq[ihash(m->tag) % Nflushtab];
 			rlock(lk);
+		}
 
 		h = ihash(m->fid) % fs->nreaders;
 		switch(m->type){