ref: e808b613b7b70a5b23b25bef22ad0e7d5ab846dc
parent: a57ce705ce68b24a63273caafb7d18d49d866f44
author: Ori Bernstein <ori@eigenstate.org>
date: Wed May 17 16:27:39 EDT 2023
fs: add locking and extra sanity checking
--- a/fs.c
+++ b/fs.c
@@ -9,6 +9,8 @@
#include "fns.h"
#include "atomic.h"
+static long tagtab[65536];
+
static int
walk1(Tree *t, vlong up, char *name, Qid *qid, vlong *len)
{
@@ -198,12 +200,15 @@
uchar buf[Max9p+IOHDRSZ];
int w, n;
+ assert(asetl(&tagtab[m->tag], 0) == m->type);
r->tag = m->tag;
dprint("→ %F\n", r);
- assert(m->type+1 == r->type || r->type == Rerror || r->type == Rflush);
+ assert(m->type+1 == r->type || r->type == Rerror);
if((n = convS2M(r, buf, sizeof(buf))) == 0)
abort();
+ qlock(&m->conn->wrlk);
w = write(m->conn->wfd, buf, n);
+ qunlock(&m->conn->wrlk);
if(w != n)
fshangup(m->conn, Eio);
lk = &fs->flushq[ihash(m->tag) % Nflushtab];
@@ -2088,6 +2093,7 @@
}
dprint("← %F\n", &m->Fcall);
+ assert(asetl(&tagtab[m->tag], m->type) == 0);
lk = &fs->flushq[ihash(m->tag) % Nflushtab];
if(m->type == Tflush)
wlock(lk);