hjfs: various changes

This commit is contained in:
aiju 2012-08-08 23:14:42 +02:00
parent 2e19497159
commit 34bf0ce496
5 changed files with 61 additions and 34 deletions

View file

@ -76,15 +76,15 @@ tqueue(Req *req)
if(ch->lreq != nil) if(ch->lreq != nil)
((Req *) ch->lreq)->aux = req; ((Req *) ch->lreq)->aux = req;
ch->lreq = req; ch->lreq = req;
if(ch->qnext == nil){ if(ch->qnext == nil && (ch->wflags & CHWBUSY) == 0){
ch->qnext = &readych; ch->qnext = &readych;
ch->qprev = ch->qnext->qprev; ch->qprev = ch->qnext->qprev;
ch->qnext->qprev = ch; ch->qnext->qprev = ch;
ch->qprev->qnext = ch; ch->qprev->qnext = ch;
rwakeup(&chanre);
} }
if(req->ifcall.type == Tremove) if(req->ifcall.type == Tremove)
req->fid->aux = nil; req->fid->aux = nil;
rwakeup(&chanre);
qunlock(&chanqu); qunlock(&chanqu);
} }
@ -100,9 +100,17 @@ tdestroyfid(Fid *fid)
qlock(&chanqu); qlock(&chanqu);
ch = fid->aux; ch = fid->aux;
fid->aux = nil; fid->aux = nil;
if(ch != nil){
ch->wflags |= CHWCLUNK;
if(ch->qnext == nil && (ch->wflags & CHWBUSY) == 0){
ch->qnext = &readych;
ch->qprev = ch->qnext->qprev;
ch->qnext->qprev = ch;
ch->qprev->qnext = ch;
rwakeup(&chanre);
}
}
qunlock(&chanqu); qunlock(&chanqu);
if(ch != nil)
chanclunk(ch);
} }
static void static void
@ -137,31 +145,29 @@ start9p(char *service, int stdio)
threadpostmountsrv(&mysrv, service, nil, 0); threadpostmountsrv(&mysrv, service, nil, 0);
} }
static char * static int
tclone(Fid *old, Fid *new, void *) twalk(Chan *ch, Fid *fid, Fid *nfid, int n, char **name, Qid *qid)
{ {
Chan *ch; int i;
ch = old->aux;
if(ch->open != 0)
return "trying to clone an open fid";
new->aux = chanclone(ch);
return nil;
}
static char * if(nfid != fid){
twalk(Fid *fid, char *name, void *) if(ch->open != 0){
{ werrstr("trying to clone an open fid");
Chan *ch; return -1;
char buf[ERRMAX]; }
ch = chanclone(ch);
ch = fid->aux; if(ch == nil)
if(chanwalk(ch, name) < 0){ return -1;
rerrstr(buf, ERRMAX); nfid->aux = ch;
return strdup(buf); nfid->qid = ch->loc->Qid;
} }
fid->qid = ch->loc->Qid; for(i = 0; i < n; i++){
return nil; if(chanwalk(ch, name[i]) <= 0)
return i > 0 ? i : -1;
qid[i] = ch->loc->Qid;
nfid->qid = ch->loc->Qid;
}
return n;
} }
static void static void
@ -181,6 +187,8 @@ workerproc(void *)
ch->qprev->qnext = ch->qnext; ch->qprev->qnext = ch->qnext;
ch->qprev = nil; ch->qprev = nil;
ch->qnext = nil; ch->qnext = nil;
assert((ch->wflags & CHWBUSY) == 0);
ch->wflags |= CHWBUSY;
while(ch != nil && ch->freq != nil){ while(ch != nil && ch->freq != nil){
req = ch->freq; req = ch->freq;
ch->freq = req->aux; ch->freq = req->aux;
@ -188,12 +196,15 @@ workerproc(void *)
ch->lreq = nil; ch->lreq = nil;
req->aux = nil; req->aux = nil;
qunlock(&chanqu); qunlock(&chanqu);
assert(req->responded == 0);
i = &req->ifcall; i = &req->ifcall;
o = &req->ofcall; o = &req->ofcall;
switch(req->ifcall.type){ switch(req->ifcall.type){
case Twalk: case Twalk:
walkandclone(req, twalk, tclone, nil); rc = twalk(ch, req->fid, req->newfid, i->nwname, i->wname, o->wqid);
goto noret; if(rc >= 0)
o->nwqid = rc;
break;
case Topen: case Topen:
rc = chanopen(ch, i->mode); rc = chanopen(ch, i->mode);
break; break;
@ -228,9 +239,13 @@ workerproc(void *)
responderror(req); responderror(req);
else else
respond(req, nil); respond(req, nil);
noret:
qlock(&chanqu); qlock(&chanqu);
} }
if(ch != nil){
ch->wflags &= ~CHWBUSY;
if((ch->wflags & CHWCLUNK) != 0)
chanclunk(ch);
}
} }
} }

View file

@ -191,7 +191,7 @@ userssave(Fs *fs, Chan *ch)
{ {
User *u, *v; User *u, *v;
int nu, i; int nu, i;
char buf[512], *p, *e; char buf[512], *p, *e, *s;
uvlong off; uvlong off;
rlock(&fs->udatal); rlock(&fs->udatal);
@ -206,8 +206,11 @@ userssave(Fs *fs, Chan *ch)
p = buf; p = buf;
e = buf + sizeof(buf); e = buf + sizeof(buf);
p = seprint(p, e, "%d:%s:", v->uid, v->name); p = seprint(p, e, "%d:%s:", v->uid, v->name);
if(v->lead != NOUID) if(v->lead != NOUID){
p = strecpy(p, e, uid2name(fs, v->lead)); s = uid2name(fs, v->lead);
p = strecpy(p, e, s);
free(s);
}
if(p < e) if(p < e)
*p++ = ':'; *p++ = ':';
for(i = 0; i < v->nmemb; i++){ for(i = 0; i < v->nmemb; i++){
@ -215,7 +218,9 @@ userssave(Fs *fs, Chan *ch)
continue; continue;
if(p < e && i > 0) if(p < e && i > 0)
*p++ = ','; *p++ = ',';
p = strecpy(p, e, uid2name(fs, v->memb[i])); s = uid2name(fs, v->memb[i]);
p = strecpy(p, e, s);
free(s);
} }
*p++ = '\n'; *p++ = '\n';
if(ch == nil) if(ch == nil)

View file

@ -185,6 +185,9 @@ enum {
CHFDUMP = 1, CHFDUMP = 1,
CHFNOLOCK = 2, CHFNOLOCK = 2,
CHFRO = 4, CHFRO = 4,
CHWBUSY = 1,
CHWCLUNK = 2,
}; };
@ -203,6 +206,7 @@ struct Chan {
/* workers */ /* workers */
void *freq, *lreq; void *freq, *lreq;
Chan *qnext, *qprev; Chan *qnext, *qprev;
int wflags;
}; };
extern QLock chanqu; extern QLock chanqu;

View file

@ -111,7 +111,7 @@ chancreat(Chan *ch, char *name, int perm, int mode)
chend(ch); chend(ch);
return -1; return -1;
} }
if(!namevalid || ch->open != 0){ if(!namevalid(name) || ch->open != 0){
werrstr(Einval); werrstr(Einval);
chend(ch); chend(ch);
return -1; return -1;
@ -520,6 +520,7 @@ chandirread(Chan *ch, void *buf, ulong n, uvlong off)
free(di.uid); free(di.uid);
free(di.gid); free(di.gid);
free(di.muid); free(di.muid);
free(di.name);
if(rc <= BIT16SZ) if(rc <= BIT16SZ)
break; break;
wr += rc; wr += rc;

View file

@ -13,6 +13,8 @@ char Eperm[] = "permission denied";
char Eexists[] = "file exists"; char Eexists[] = "file exists";
char Elocked[] = "file locked"; char Elocked[] = "file locked";
int mainstacksize = 65536;
void* void*
emalloc(int c) emalloc(int c)
{ {