make filesystem handling of read9pmsg() consistent

This commit is contained in:
cinap_lenrek 2013-06-16 06:26:31 +02:00
parent d84aeddee7
commit e36d9f5c4e
17 changed files with 46 additions and 27 deletions

View file

@ -44,6 +44,8 @@ again:
clog("xmesg read error: %r\n");
return -1;
}
if(n == 0)
goto again;
if(convM2S(s->data, n, &s->f) <= 0){
clog("xmesg bad convM2S %d %.2x %.2x %.2x %.2x\n",
n, ((uchar*)s->data)[0], ((uchar*)s->data)[1],

View file

@ -148,7 +148,8 @@ fsysproc(void *)
x = nil;
for(;;){
buf = emalloc(messagesize+UTFmax); /* overflow for appending partial rune in xfidwrite */
n = read9pmsg(sfd, buf, messagesize);
while((n = read9pmsg(sfd, buf, messagesize)) == 0 && !closing)
;
if(n <= 0){
if(closing)
break;

View file

@ -681,8 +681,9 @@ fsrun(void *v)
}
free(d);
r = allocreq(fs, messagesize);
n = read9pmsg(fs->fd, r->buf, messagesize);
if(n <= 0)
while((n = read9pmsg(fs->fd, r->buf, messagesize)) == 0)
;
if(n < 0)
fatal("unmounted");
if(convM2S(r->buf, n, &r->f) == 0){

View file

@ -365,9 +365,10 @@ fsrun(void *a)
for(;;){
r = allocreq(messagesize);
qlock(&iolock);
n = read9pmsg(fs->fd, r->buf, messagesize);
while((n = read9pmsg(fs->fd, r->buf, messagesize)) == 0)
;
qunlock(&iolock);
if(n <= 0)
if(n < 0)
fatal("read9pmsg error: %r");
if(convM2S(r->buf, n, &r->f) == 0){

View file

@ -808,8 +808,9 @@ rcvmsg(P9fs *p, Fcall *f)
char buf[128];
olen = p->len;
p->len = read9pmsg(p->fd[0], datarcv, sizeof(datarcv));
if(p->len <= 0){
while((p->len = read9pmsg(p->fd[0], datarcv, sizeof(datarcv))) == 0)
;
if(p->len < 0){
snprint(buf, sizeof buf, "read9pmsg(%d)->%ld: %r",
p->fd[0], p->len);
error(buf);

View file

@ -1090,11 +1090,13 @@ notefs(int fd)
ncpunote = 0;
for(;;){
n = read9pmsg(fd, buf, sizeof(buf));
if(n <= 0){
if(n < 0){
if(dbg)
fprint(2, "read9pmsg(%d) returns %d: %r\n", fd, n);
break;
}
if(n == 0)
continue;
if(convM2S(buf, n, &f) <= BIT16SZ)
break;
if(dbg)

View file

@ -388,8 +388,9 @@ main(int argc, char **argv)
if(r == 0)
fatal("Out of service buffers");
n = localread9pmsg(netfd, r->buf, messagesize, ini);
if(n <= 0)
while((n = localread9pmsg(netfd, r->buf, messagesize, ini)) == 0)
;
if(n < 0)
fatal(nil);
if(convM2S(r->buf, n, &r->work) == 0)
fatal("convM2S format error");

View file

@ -164,7 +164,8 @@ main(int argc, char **argv)
if(r == 0)
fatal("Out of service buffers");
n = read9pmsg(p[1], r->buf, sizeof(r->buf));
while((n = read9pmsg(p[1], r->buf, sizeof(r->buf))) == 0 && !done)
;
if(done)
break;
if(n < 0)

View file

@ -262,12 +262,14 @@ io(void)
while(!dying){
n = read9pmsg(mfd, mdata, messagesize);
if(n <= 0){
if(n < 0){
errstr(buf, sizeof buf);
if(buf[0]=='\0' || strstr(buf, "hungup"))
exits("");
fatal("mount read: %s\n", buf);
}
if(n == 0)
continue;
if(convM2S(mdata, n, &thdr) == 0)
continue;

View file

@ -444,8 +444,10 @@ io(void)
for(;;){
n = read9pmsg(mfd[0], mdata, sizeof mdata);
if(n<=0)
if(n < 0)
error("mount read");
if(n == 0)
continue;
job = newjob();
if(convM2S(mdata, n, &job->request) != n){
syslog(1, logfile, "format error %ux %ux %ux %ux %ux",

View file

@ -430,8 +430,9 @@ io(void)
while(!stop){
procsetname("%d %s/dns Twrites of %d 9p rpcs read; %d alarms",
stats.qrecvd9p, mntpt, stats.qrecvd9prpc, stats.alarms);
n = read9pmsg(mfd[0], mdata, sizeof mdata);
if(n<=0){
while((n = read9pmsg(mfd[0], mdata, sizeof mdata)) == 0)
;
if(n < 0){
dnslog("error reading 9P from %s: %r", mntpt);
sleep(2000); /* don't thrash after read error */
return;

View file

@ -817,7 +817,7 @@ io(int fd)
if(n < 0)
sysfatal("mount read");
if(n == 0)
break;
continue;
if(convM2S(mdata, n, &rhdr) == 0)
continue;

View file

@ -237,12 +237,10 @@ fsysproc(void*)
if(buf == nil)
error("malloc failed: %r");
qlock(&readlock);
n = read9pmsg(srvfd, buf, messagesize);
if(n <= 0){
if(n < 0)
error("i/o error on server channel");
while((n = read9pmsg(srvfd, buf, messagesize)) == 0)
;
if(n < 0)
threadexitsall("unmounted");
}
if(readlock.head == nil) /* no other processes waiting to read; start one */
proccreate(fsysproc, nil, Stack);
qunlock(&readlock);

View file

@ -194,8 +194,9 @@ filsysproc(void *arg)
x = nil;
for(;;){
buf = emalloc(messagesize+UTFmax); /* UTFmax for appending partial rune in xfidwrite */
n = read9pmsg(fs->sfd, buf, messagesize);
if(n <= 0){
while((n = read9pmsg(fs->sfd, buf, messagesize)) == 0)
yield();
if(n < 0){
yield(); /* if threadexitsall'ing, will not return */
fprint(2, "rio: %d: read9pmsg: %d %r\n", getpid(), n);
errorshouldabort = 0;

View file

@ -706,8 +706,10 @@ io(void)
for(;;){
n = read9pmsg(mfd[0], mdata, sizeof mdata);
if(n <= 0)
if(n < 0)
break;
if(n == 0)
continue;
if(convM2Su(mdata, n, &rhdr, dotu) != n)
sysfatal("convM2S conversion error");

View file

@ -149,8 +149,9 @@ exportproc(Export *fs)
errdepth(ed);
q = smalloc(sizeof(Exq));
n = read9pmsg(fs->io, q->buf, Maxrpc);
if(n <= 0 || convM2S(q->buf, n, &q->rpc) != n)
while((n = read9pmsg(fs->io, q->buf, Maxrpc)) == 0)
;
if(n < 0 || convM2S(q->buf, n, &q->rpc) != n)
goto bad;
if(exdebug)

View file

@ -59,7 +59,9 @@ getreq(Srv *s)
Req *r;
qlock(&s->rlock);
if((n = read9pmsg(s->infd, s->rbuf, s->msize)) <= 0){
while((n = read9pmsg(s->infd, s->rbuf, s->msize)) == 0)
;
if(n < 0){
qunlock(&s->rlock);
return nil;
}