ref: 4b8b6b57fdbce99d2962946b7638694594dfe607
parent: fc5add282e0dadcc4a1980cf8376e825b976771e
author: 9ferno <[email protected]>
date: Tue Jan 10 09:23:40 EST 2023
bug fixes for tests
--- a/9p.c
+++ b/9p.c
@@ -2,6 +2,7 @@
Tlock *tlockhead = nil, *tlocktail = nil;
QLock tlock;
+s8 err[ERRMAX];
extern u32 mpsrvpid;
extern u8 noauth;
@@ -82,7 +83,6 @@
Iobuf *dbuf, *cbuf, *pbuf;
u64 chreli, blkno;
s8 v;
- char err[ERRMAX];
if(shuttingdown)
return nil;
@@ -346,9 +346,11 @@
error(errstring[Eshutdown]);
if(req->fid->qid.type == QTAUTH){
+ poperror();
authread(req);
return;
}else if(req->fid->qid.path == Qpctl){
+ poperror();
ctlread(req);
return;
}
@@ -547,12 +549,12 @@
if(readonly)
error(errstring[Eronly]);
if(req->fid->qid.type == QTAUTH){
- authwrite(req);
poperror();
+ authwrite(req);
return;
}else if(req->fid->qid.path == Qpctl){
- ctlwrite(req);
poperror();
+ ctlwrite(req);
return;
}else if(req->fid->qid.path < Qproot)
error(errstring[Eaccess]);
@@ -700,12 +702,9 @@
nexterror();
}
dparent = dbuf->d;
- if(canaccess(((Aux*)req->fid->aux)->uid, dparent, DMWRITE) == 0)
+ if(canaccess(aux->uid, dparent, DMWRITE) == 0)
error(errstring[Eperm]);
- if(canaccess(aux->uid, dparent, DMWRITE) == 0)
- error(errstring[Eaccess]);
-
fid->omode = OREAD;
switch(req->ifcall.mode & 7) {
case OREAD:
@@ -735,6 +734,9 @@
if(dchild->qpath == Qpnone || dchild->tag != Tdentry)
error(errstring[Ephase]);
+ if(canaccess(aux->uid, dchild, DMWRITE) == 0)
+ error(errstring[Eaccess]);
+
/* req->ifcall.name matched, truncate file and use it */
if(permcheck(dchild->uid, dchild->gid, aux->uid, perm, ORDWR) == 0)
error(errstring[Eperm]);
@@ -795,8 +797,6 @@
putbuf(cbuf, 0);
nexterror();
}
- if(canaccess(aux->uid, cbuf->d, DMWRITE) == 0)
- error(errstring[Eaccess]);
}
if(addname(dparent, aux->uid, reli, req->ifcall.name) == 0)
error(errstring[Ephase]);
@@ -1211,18 +1211,13 @@
startproc(Buffer *b, int id, u8 syncer)
{
char name[128];
- Errenv env;
+ // Errenv env = {0};
switch(rfork(RFPROC|RFMEM|RFFDG)){
case -1:
panic("can't fork");
case 0:
- envpp = privalloc();
- if(_nprivates != envpidx)
- panic("_nprivates != envpidx\n");
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
- *envpp = &env;
-
+ // *envpp = &env;
if(chatty9p > 1)
dprint("child %d pid: %d\n", id, getpid());
break;
@@ -1286,13 +1281,29 @@
void
mfsread(Req *r)
{
- put(&buf, fsread, r);
+ /*
+ auth should run on the srv process and not the worker.
+ It returns an auth botch error when the worker does it.
+ */
+ if(r->fid->qid.type == QTAUTH){
+ authread(r);
+ return;
+ }else
+ put(&buf, fsread, r);
}
void
mfswrite(Req *r)
{
- put(&buf, fswrite, r);
+ /*
+ auth should run on the srv process and not the worker.
+ It returns an auth botch error when the worker does it.
+ */
+ if(r->fid->qid.type == QTAUTH){
+ authwrite(r);
+ return;
+ }else
+ put(&buf, fswrite, r);
}
void
--- a/all.h
+++ b/all.h
@@ -119,7 +119,7 @@
void putbuffree(Iobuf *p);
void settag(Iobuf *p, u8 tag, u64 qpath);
void showbuf(Iobuf *p);
-s32 showhashbuckets(s8 *buf, s32 nbuf);
+u32 showhashbuckets(s8 *buf, u32 nbuf);
/* writer functions */
void initwriter(void);
--- a/block.c
+++ b/block.c
@@ -26,10 +26,9 @@
u64 size, blkno;
u8 buf[Maxdatablocksize];
Data *da;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/ctl.c
+++ b/ctl.c
@@ -72,8 +72,8 @@
return 0;
};
-u64
-fillctlmsg(s8 *buf, u64 nbuf)
+u32
+fillctlmsg(s8 *buf, u32 nbuf)
{
u64 nfree, used;
u64 n;
@@ -139,21 +139,24 @@
void
ctlread(Req *req)
{
- if(((Aux*)req->fid->aux)->ctlmsg == nil){
- ((Aux*)req->fid->aux)->ctlmsg = emalloc9p(MiB);
- ((Aux*)req->fid->aux)->nctlmsg = 0;
+ Aux *aux;
+
+ aux = (Aux*)req->fid->aux;
+ if(aux->ctlmsg == nil){
+ aux->ctlmsg = emalloc9p(MiB);
+ aux->nctlmsg = 0;
}
if(req->ifcall.offset == 0)
- ((Aux*)req->fid->aux)->nctlmsg = fillctlmsg(((Aux*)req->fid->aux)->ctlmsg, MiB);
- if(req->ifcall.offset < ((Aux*)req->fid->aux)->nctlmsg){
- req->ofcall.count = min(req->ifcall.count,((Aux*)req->fid->aux)->nctlmsg-req->ifcall.offset);
- memcpy(req->ofcall.data, ((Aux*)req->fid->aux)->ctlmsg+req->ifcall.offset, req->ofcall.count);
+ aux->nctlmsg = fillctlmsg(aux->ctlmsg, MiB);
+ if(req->ifcall.offset < aux->nctlmsg){
+ req->ofcall.count = min(req->ifcall.count,aux->nctlmsg-req->ifcall.offset);
+ memcpy(req->ofcall.data, aux->ctlmsg+req->ifcall.offset, req->ofcall.count);
req->ofcall.offset = req->ifcall.offset+req->ofcall.count;
}
- if(req->ifcall.offset == ((Aux*)req->fid->aux)->nctlmsg){
- free(((Aux*)req->fid->aux)->ctlmsg);
- ((Aux*)req->fid->aux)->ctlmsg = nil;
- ((Aux*)req->fid->aux)->nctlmsg = 0;
+ if(req->ifcall.offset == aux->nctlmsg){
+ free(aux->ctlmsg);
+ aux->ctlmsg = nil;
+ aux->nctlmsg = 0;
}
respond(req, nil);
}
--- a/custom.acid
+++ b/custom.acid
@@ -1,5 +1,5 @@
include("mafs.acid");
-include("extents.acid");
+include("../libextents/extents.acid");
defn
Qid9p1(addr) {
--- a/dat.h
+++ b/dat.h
@@ -131,7 +131,7 @@
Qpfrees = Bdfrees, /* /a/frees block Tag.qpath */
/* system qpaths */
- Qpmagic = Bdroot+1, /* magic block Tag.qpath */
+ Qpmagic = Bdrootlnamesextents+1, /* magic block Tag.qpath, could use Bdroot butt this avoids confusion by keeping the block numbers and qpaths distinct */
Qpconfig0, /* /a/bkp/config.0 block Tag.qpath */
Qpsuper0, /* /a/bkp/super.0 block Tag.qpath */
Qproot0, /* /a/bkp/root.0 block Tag.qpath */
@@ -250,7 +250,7 @@
u8 tlocked; /* for exclusive use files, flag to indicate lock */
u64 dri; /* directory index while reading a directory */
s8 *ctlmsg;
- u64 nctlmsg;
+ u32 nctlmsg;
/* u64 lastreadahead; TODO */
};
@@ -423,11 +423,11 @@
jmp_buf label[16];
u8 nlabel;
};
-extern s8 envpidx; /* the index in _privates holding the Errenv location */
+extern s8 err[ERRMAX];
extern Errenv **envpp;
-extern void **_privates; /* defined in libc */
-extern int _nprivates;
-int waserror(void);
-void poperror(void);
void nexterror(void);
void error(s8 *fmt, ...);
+extern void showerrenv(char *msg);
+#define poperror() (*envpp)->nlabel--
+/* #define waserror() (showerrenv("waserror before\n"), (*envpp)->nlabel++, setjmp((*envpp)->label[(*envpp)->nlabel-1])) */
+#define waserror() ((*envpp)->nlabel++, setjmp((*envpp)->label[(*envpp)->nlabel-1]))
--- a/dentry.c
+++ b/dentry.c
@@ -485,6 +485,7 @@
error("savefrees nbuf not enough");
/* writing the actual extents now */
+ truncatefile(qpath, blkno, uid);
writefile(blkno, qpath, uid, buf, nbuf, 0);
free(buf);
}
--- a/error.c
+++ b/error.c
@@ -5,26 +5,26 @@
s8 envpidx = -1; /* the index in _privates holding the Errenv location. hack: hoping that this will be the same across all processes */
Errenv **envpp = nil;
+extern int dprint(char *fmt, ...);
-int
-waserror(void)
-{
- Errenv *env = _privates[envpidx];
- ++env->nlabel;
- return setjmp(env->label[env->nlabel-1]);
-}
-
void
-poperror(void)
+showerrenv(char *msg)
{
+ u8 i;
Errenv *env = *envpp;
- --env->nlabel;
+
+ dprint("%s", msg);
+ dprint("env 0x%p env->nlabel %hhud\n", env, env->nlabel);
+ for(i = 0; i < env->nlabel; i++){
+ dprint("i %hhud pc 0x%p\n", i, env->label[i][JMPBUFPC]);
+ }
}
void
nexterror(void)
{
- Errenv *env = _privates[envpidx];
+ Errenv *env = *envpp;
+ // showerrenv("nexterror before\n");
longjmp(env->label[--env->nlabel], 1);
}
@@ -37,6 +37,7 @@
va_start(arg, fmt);
vseprint(buf, buf+ERRMAX, fmt, arg);
va_end(arg);
+ // dprint("error: %s\n", buf);
errstr(buf, ERRMAX);
nexterror();
}
--- a/free.c
+++ b/free.c
@@ -31,10 +31,9 @@
main(int argc, char *argv[])
{
u64 size;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/fsok.c
+++ b/fsok.c
@@ -24,10 +24,9 @@
u64 size;
s8 buf[Blocksize];
Dentry *d;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/iobuf.c
+++ b/iobuf.c
@@ -55,14 +55,16 @@
ufree(&memunits, (m-memunitpool)/Blocksize, len);
}
-s32
-showhashbucket(Iobuf *p, s8 *buf, s32 nbuf)
+u32
+showhashbucket(Iobuf *p, s8 *buf, u32 nbuf)
{
- s32 n;
+ u32 n;
char locked[32];
u8 tag;
char *name;
u16 namelen;
+ Iobuf *pdbuf;
+ Dentry *pd;
if(p == nil)
return 0;
@@ -72,6 +74,8 @@
wunlock(p);
}else
strcpy(locked, "locked");
+ name = nil;
+ namelen = 0;
if(p->tag == Tdata)
n = snprint(buf, nbuf, "%s %llud %s\n",
tagnames[p->tag], p->blkno, locked);
@@ -82,11 +86,24 @@
tagnames[tag], p->blkno, (nsec()-p->atime)/Nsec,
locked, p->append!=nil?"data":"nil", p->appendsize);
}else if(tag == Tdentry){
- readname(p->d, p->d->preli, &name, &namelen);
+/* cannot do this here -- It causes a deadlock
+ pdbuf = egetmetachk(p->d->pdblkno, Breadonly, Tdentry, p->d->pqpath);
+ if(waserror()){
+ putbuf(pdbuf, 0);
+ nexterror();
+ }
+ pd = pdbuf->d;
+ readname(pd, p->d->preli, &name, &namelen);
n = snprint(buf, nbuf, "%s %llud %s %lluds %s %s %llud\n",
tagnames[tag], p->blkno, name, (nsec()-p->atime)/Nsec,
locked, p->append!=nil?"data":"nil", p->appendsize);
+ poperror();
+ putbuf(pdbuf, 0);
free(name);
+*/
+ n = snprint(buf, nbuf, "%s %llud %lluds %s %s %llud\n",
+ tagnames[tag], p->blkno, (nsec()-p->atime)/Nsec,
+ locked, p->append!=nil?"data":"nil", p->appendsize);
}else
n = snprint(buf, nbuf, "%s %llud %lluds %s\n",
tagnames[tag], p->blkno, (nsec()-p->atime)/Nsec, locked);
@@ -94,17 +111,21 @@
return n;
}
-s32
-showhashbuckets(s8 *buf, s32 nbuf)
+u32
+showhashbuckets(s8 *buf, u32 nbuf)
{
Iobuf *p;
Hiob *hp;
- s32 n;
+ u32 n;
u64 i;
- for(i = n = 0; i < nbuckets; i++){
+ for(n = 0, i = 0; i < nbuckets; i++){
hp=&hiob[i];
qlock(hp);
+ if(waserror()){
+ qunlock(hp);
+ nexterror();
+ }
if(hp->link != nil){
n += snprint(buf+n, nbuf-n, "i %llud ", i);
n += showhashbucket(hp->link, buf+n, nbuf-n);
@@ -115,6 +136,7 @@
}
// n+=snprint(buf+n,nbuf-n,"\n");
}
+ poperror();
qunlock(hp);
}
return n;
--- a/mafs.c
+++ b/mafs.c
@@ -31,10 +31,9 @@
char buf[Servicelen];
int pid, ctl;
u64 nmemunits, size;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/names.c
+++ b/names.c
@@ -161,7 +161,6 @@
u16
addnamelen(Dentry *pd, u16 uid, u64 preli, s8 *name, u16 namelen)
{
- s8 *buf;
Extents *nes;
s8 esname[32];
u64 start, size;
@@ -187,24 +186,16 @@
loadextentsfile(pd->dblocks[Inle], pd->qpath+1+Inle, nes);
/* reusing */
- buf = emalloc9p(nm.namelen);
- if(waserror()){
- free(buf);
- nexterror();
- }
- strncpy(buf, name, nm.namelen);
if(ualloc(nes, namelen, &start)){
- if(writefile(pd->dblocks[Inl], pd->qpath+1+Inl, uid, buf, nm.namelen, start) != namelen)
+ if(writefile(pd->dblocks[Inl], pd->qpath+1+Inl, uid, name, nm.namelen, start) != namelen)
error(errstring[Einvwrite]);
nm.noffset = start;
saveextentstofile(pd->dblocks[Inle], pd->qpath+1+Inle, uid, nes);
}else{
nm.noffset = size = readfilesize(pd->dblocks[Inl], pd->qpath+1+Inl);
- if(writefile(pd->dblocks[Inl], pd->qpath+1+Inl, uid, buf, nm.namelen, size) != nm.namelen)
+ if(writefile(pd->dblocks[Inl], pd->qpath+1+Inl, uid, name, nm.namelen, size) != nm.namelen)
error(errstring[Einvwrite]);
}
- poperror();
- free(buf);
poperror();
freeextents(nes);
if(writefile(pd->dblocks[In], pd->qpath+1+In, uid,
--- a/reconcile.c
+++ b/reconcile.c
@@ -65,10 +65,9 @@
{
Stream u, f; /* u = used, f = free */
u64 nblocks;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/tests/chkflush.rc
+++ b/tests/chkflush.rc
@@ -5,7 +5,7 @@
dd -if /dev/zero -of flush/disk -bs 512 -count 64
mount -c <{disk/mafs -s -r test.flush flush/disk <[0=1]} /n/mfs_test.flush
> /n/mfs_test.flush/4blocks.file {
- # cat /n/mfs_test.flush/adm/ctl >/tmp//test.flush.file
+ # cat /n/mfs_test.flush/a/ctl >/tmp//test.flush.file
cat flush/2_blocks.file
sleep 15
cat flush/2_blocks.file
@@ -12,10 +12,10 @@
sleep 15
}
# cat /tmp//test.flush.file
-# cat /n/mfs_test.flush/adm/ctl
-echo sync >> /n/mfs_test.flush/adm/ctl
-cat /n/mfs_test.flush/adm/ctl
+# cat /n/mfs_test.flush/a/ctl
+echo sync >> /n/mfs_test.flush/a/ctl
+cat /n/mfs_test.flush/a/ctl
sleep 1
echo '-------sending halt------------'
-echo halt >> /n/mfs_test.flush/adm/ctl
+echo halt >> /n/mfs_test.flush/a/ctl
--- a/tests/regress.rc
+++ b/tests/regress.rc
@@ -35,8 +35,8 @@
test -f $test^/action.rc && $test^/action.rc $service $disk
# tear it down
- test -f /n/^$service^/adm/ctl && {
- echo halt >> /n/^$service^/adm/ctl
+ test -f /n/^$service^/a/ctl && {
+ echo halt >> /n/^$service^/a/ctl
}
unmount /n/^$service
test -f /srv/^$test && rm /srv/^$test
@@ -77,8 +77,8 @@
test -f $test^/action.rc && $test^/action.rc $service $disk
# tear it down
- test -f /n/^$service^/adm/ctl && {
- echo halt >> /n/^$service^/adm/ctl
+ test -f /n/^$service^/a/ctl && {
+ echo halt >> /n/^$service^/a/ctl
}
unmount /n/^$service
test -f /srv/^$test && rm /srv/^$test
@@ -91,7 +91,6 @@
if(~ $#* 0){
chkreli.rc
- chkextents.rc
chkflush.rc
chknlastdatablocks.rc
for (t in test.*){
--- a/tests/test.0/notes
+++ b/tests/test.0/notes
@@ -30,6 +30,6 @@
21 - / dir names entry
22 - / dir names extents entry
-26 - /a/bkp/root.0 dir entry
-28 - /a/bkp/super.0 dir entry
-30 - /a/bkp/config.0 dir entry
+29 - /a/bkp/root.0 dir entry
+30 - /a/bkp/super.0 dir entry
+31 - /a/bkp/config.0 dir entry
--- a/unused.c
+++ b/unused.c
@@ -78,10 +78,9 @@
struct Extents unused;
u64 nblocks;
int listblocks = 0;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/updatefrees.c
+++ b/updatefrees.c
@@ -40,10 +40,9 @@
Data *f;
Dentry *d;
u64 *f64;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
--- a/used.c
+++ b/used.c
@@ -40,10 +40,9 @@
main(int argc, char *argv[])
{
u64 size;
- Errenv env;
+ Errenv env = {0};
envpp = privalloc();
- envpidx = _nprivates; /* the index in _privates holding the Errenv location */
*envpp = &env;
if(waserror()){
panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",