exportfs, oexportfs, iostats: make -d log to stderr

exportfs -d logs 9p traffic to /tmp/exportdb.
-f allows writing to a different file.
exportfs silently continues if it doesn't have
permissions to create or write to /tmp/exportdb.
These are poor behaviors.

A better default is to write to stderr, since it
is 9P debug info that is better immediately printed,
and not user info that is better handled by syslog().
As a result, -f is obsolete and thus removed.
Redirect responsibility is now on rc.
As a side effect, rc will fail if it doesn't
have permissions to write.

exportfs(4) is updated to reflect all changes
and with a better Synopsis.

oexportfs is changed to match exportfs.
oexportfs(4) is updated to reflect all changes.
The Synopsis is not changed due to the number of flags.

Removed -f from iostats.
iostats(4) is updated to reflect all changes.
---
front
amavect 2021-08-18 17:51:40 +00:00
parent 8c228a123f
commit 0f58e47551
10 changed files with 70 additions and 98 deletions

View File

@ -4,7 +4,23 @@ exportfs, srvfs \- file server plumbing
.SH SYNOPSIS .SH SYNOPSIS
.B exportfs .B exportfs
[ [
.I options .B -dsR
]
[
.B -m
.I msize
]
[
.B -r
.I root
]
[
.B -P
.I patternfile
]
[
.B -S
.I srvfile
] ]
.PP .PP
.B srvfs .B srvfs
@ -39,11 +55,8 @@ into a local file tree.
.PP .PP
The options are: The options are:
.TP .TP
.B -d -f \fIdbgfile .B -d
Log all 9P traffic to Log all 9P traffic to standard error.
.I dbgfile
(default
.BR /tmp/exportdb ).
.TP .TP
.B -P \fIpatternfile .B -P \fIpatternfile
Restrict the set of exported files. Restrict the set of exported files.

View File

@ -7,9 +7,6 @@ iostats \- file system to measure I/O
.B -d .B -d
] [ ] [
.B -C .B -C
] [
.B -f
.I dbfile
] ]
.I cmd .I cmd
[ [
@ -17,7 +14,7 @@ iostats \- file system to measure I/O
] ]
.SH DESCRIPTION .SH DESCRIPTION
.I Iostats .I Iostats
is a user-level 9p filter that interposes itself between a program is a user-level 9P filter that interposes itself between a program
and the regular file server, which and the regular file server, which
allows it to gather statistics of file system allows it to gather statistics of file system
use at the level of the Plan 9 file system protocol, 9P. use at the level of the Plan 9 file system protocol, 9P.
@ -51,11 +48,8 @@ by the program in terms of opens, reads and writes.
.PP .PP
If the If the
.B -d .B -d
flag is present, a debugging log including all traffic flag is present, a debugging log including all 9P traffic
is written to is written to standard error.
.I dbfile
(default
.BR iostats.out ).
.PP .PP
The The
.B -C .B -C
@ -73,7 +67,7 @@ iostats ls
Start a new shell, displaying all 9P traffic caused by the shell or its children: Start a new shell, displaying all 9P traffic caused by the shell or its children:
.IP .IP
.EX .EX
iostats -df /fd/1 rc iostats -d rc
.EE .EE
.SH SOURCE .SH SOURCE
.B /sys/src/cmd/iostats.c .B /sys/src/cmd/iostats.c

View File

@ -26,11 +26,8 @@ services.
.PP .PP
The options are: The options are:
.TP .TP
.B -d -f \fIdbgfile .B -d
Log all 9P traffic to Log all 9P traffic to standard error.
.I dbgfile
(default
.BR /tmp/exportdb ).
.TP .TP
.B -P \fIpatternfile .B -P \fIpatternfile
Restrict the set of exported files. Restrict the set of exported files.

View File

@ -10,18 +10,16 @@ int readonly;
void void
usage(void) usage(void)
{ {
fprint(2, "usage: %s [-dsR] [-f dbgfile] [-m msize] [-r root] " fprint(2, "usage: %s [-dsR] [-m msize] [-r root] "
"[-S srvfile] [-P exclusion-file]\n", argv0); "[-P patternfile] [-S srvfile]\n", argv0);
fatal("usage"); fatal("usage");
} }
void void
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *dbfile, *srv, *srvfdfile; char *srv, *srvfdfile;
int n;
dbfile = "/tmp/exportdb";
srv = nil; srv = nil;
srvfd = -1; srvfd = -1;
srvfdfile = nil; srvfdfile = nil;
@ -31,10 +29,6 @@ main(int argc, char **argv)
dbg++; dbg++;
break; break;
case 'f':
dbfile = EARGF(usage());
break;
case 'm': case 'm':
messagesize = strtoul(EARGF(usage()), nil, 0); messagesize = strtoul(EARGF(usage()), nil, 0);
break; break;
@ -82,13 +76,7 @@ main(int argc, char **argv)
exclusions(); exclusions();
if(dbg) { DEBUG(2, "exportfs: started\n");
n = create(dbfile, OWRITE|OTRUNC, 0666);
dup(n, DFD);
close(n);
}
DEBUG(DFD, "exportfs: started\n");
rfork(RFNOTEG|RFREND); rfork(RFNOTEG|RFREND);
@ -106,13 +94,13 @@ main(int argc, char **argv)
char ebuf[ERRMAX]; char ebuf[ERRMAX];
ebuf[0] = '\0'; ebuf[0] = '\0';
errstr(ebuf, sizeof ebuf); errstr(ebuf, sizeof ebuf);
DEBUG(DFD, "chdir(\"%s\"): %s\n", srv, ebuf); DEBUG(2, "chdir(\"%s\"): %s\n", srv, ebuf);
mounterror(ebuf); mounterror(ebuf);
} }
DEBUG(DFD, "invoked as server for %s", srv); DEBUG(2, "invoked as server for %s", srv);
} }
DEBUG(DFD, "\niniting root\n"); DEBUG(2, "\niniting root\n");
initroot(); initroot();
io(); io();
} }

View File

@ -3,7 +3,6 @@
*/ */
#define DEBUG if(!dbg){}else fprint #define DEBUG if(!dbg){}else fprint
#define DFD 9
#define fidhash(s) fhash[s%FHASHSIZE] #define fidhash(s) fhash[s%FHASHSIZE]
typedef struct Fsrpc Fsrpc; typedef struct Fsrpc Fsrpc;

View File

@ -65,7 +65,7 @@ Xflush(Fsrpc *t)
w = m->busy; w = m->busy;
if(w != nil && w->work.tag == t->work.oldtag) { if(w != nil && w->work.tag == t->work.oldtag) {
w->flushtag = t->work.tag; w->flushtag = t->work.tag;
DEBUG(DFD, "\tset flushtag %d\n", t->work.tag); DEBUG(2, "\tset flushtag %d\n", t->work.tag);
postnote(PNPROC, m->pid, "flush"); postnote(PNPROC, m->pid, "flush");
unlock(m); unlock(m);
putsbuf(t); putsbuf(t);
@ -75,7 +75,7 @@ Xflush(Fsrpc *t)
} }
reply(&t->work, &rhdr, 0); reply(&t->work, &rhdr, 0);
DEBUG(DFD, "\tflush reply\n"); DEBUG(2, "\tflush reply\n");
putsbuf(t); putsbuf(t);
} }
@ -359,7 +359,7 @@ Xremove(Fsrpc *t)
} }
path = makepath(f->f, ""); path = makepath(f->f, "");
DEBUG(DFD, "\tremove: %s\n", path); DEBUG(2, "\tremove: %s\n", path);
if(remove(path) < 0) { if(remove(path) < 0) {
free(path); free(path);
errstr(err, sizeof err); errstr(err, sizeof err);
@ -518,7 +518,7 @@ blockingslave(Proc *m)
if(p == nil) /* Swept */ if(p == nil) /* Swept */
break; break;
DEBUG(DFD, "\tslave: %d %F\n", m->pid, &p->work); DEBUG(2, "\tslave: %d %F\n", m->pid, &p->work);
if(p->flushtag != NOTAG) if(p->flushtag != NOTAG)
goto flushme; goto flushme;
@ -629,7 +629,7 @@ slaveopen(Fsrpc *p)
} }
path = makepath(f->f, ""); path = makepath(f->f, "");
DEBUG(DFD, "\topen: %s %d\n", path, work->mode); DEBUG(2, "\topen: %s %d\n", path, work->mode);
f->fid = open(path, work->mode); f->fid = open(path, work->mode);
free(path); free(path);
if(f->fid < 0 || (d = dirfstat(f->fid)) == nil) { if(f->fid < 0 || (d = dirfstat(f->fid)) == nil) {
@ -646,7 +646,7 @@ slaveopen(Fsrpc *p)
goto Error; goto Error;
} }
DEBUG(DFD, "\topen: fd %d\n", f->fid); DEBUG(2, "\topen: fd %d\n", f->fid);
f->mode = work->mode; f->mode = work->mode;
f->offset = 0; f->offset = 0;
rhdr.iounit = getiounit(f->fid); rhdr.iounit = getiounit(f->fid);
@ -688,7 +688,7 @@ slaveread(Fsrpc *p)
reply(work, &rhdr, err); reply(work, &rhdr, err);
return; return;
} }
DEBUG(DFD, "\tread: fd=%d %d bytes\n", f->fid, r); DEBUG(2, "\tread: fd=%d %d bytes\n", f->fid, r);
rhdr.data = data; rhdr.data = data;
rhdr.count = r; rhdr.count = r;
@ -720,7 +720,7 @@ slavewrite(Fsrpc *p)
return; return;
} }
DEBUG(DFD, "\twrite: %d bytes fd=%d\n", n, f->fid); DEBUG(2, "\twrite: %d bytes fd=%d\n", n, f->fid);
rhdr.count = n; rhdr.count = n;
reply(work, &rhdr, 0); reply(work, &rhdr, 0);

View File

@ -49,7 +49,7 @@ io(void)
if(convM2S(r->buf, n, &r->work) != n) if(convM2S(r->buf, n, &r->work) != n)
fatal("convM2S format error"); fatal("convM2S format error");
DEBUG(DFD, "%F\n", &r->work); DEBUG(2, "%F\n", &r->work);
(fcalls[r->work.type])(r); (fcalls[r->work.type])(r);
} }
} }
@ -69,7 +69,7 @@ reply(Fcall *r, Fcall *t, char *err)
else else
t->type = r->type + 1; t->type = r->type + 1;
DEBUG(DFD, "\t%F\n", t); DEBUG(2, "\t%F\n", t);
data = malloc(messagesize); /* not mallocz; no need to clear */ data = malloc(messagesize); /* not mallocz; no need to clear */
if(data == nil) if(data == nil)
@ -224,7 +224,7 @@ freefile(File *f)
while(--f->ref == 0){ while(--f->ref == 0){
freecnt++; freecnt++;
DEBUG(DFD, "free %s\n", f->name); DEBUG(2, "free %s\n", f->name);
/* delete from parent */ /* delete from parent */
parent = f->parent; parent = f->parent;
if(parent->child == f) if(parent->child == f)
@ -250,7 +250,7 @@ file(File *parent, char *name)
char *path; char *path;
File *f; File *f;
DEBUG(DFD, "\tfile: 0x%p %s name %s\n", parent, parent->name, name); DEBUG(2, "\tfile: 0x%p %s name %s\n", parent, parent->name, name);
path = makepath(parent, name); path = makepath(parent, name);
if(patternfile != nil && excludefile(path)){ if(patternfile != nil && excludefile(path)){
@ -429,17 +429,17 @@ uniqueqid(Dir *d)
} }
path = d->qid.path; path = d->qid.path;
while(qidexists(path)){ while(qidexists(path)){
DEBUG(DFD, "collision on %s\n", d->name); DEBUG(2, "collision on %s\n", d->name);
/* collision: find a new one */ /* collision: find a new one */
ncollision++; ncollision++;
path &= QIDPATH; path &= QIDPATH;
++newqid; ++newqid;
if(newqid >= (1<<16)){ if(newqid >= (1<<16)){
DEBUG(DFD, "collision wraparound\n"); DEBUG(2, "collision wraparound\n");
newqid = 1; newqid = 1;
} }
path |= newqid<<48; path |= newqid<<48;
DEBUG(DFD, "assign qid %.16llux\n", path); DEBUG(2, "assign qid %.16llux\n", path);
} }
qidcnt++; qidcnt++;
q = emallocz(sizeof(Qidtab)); q = emallocz(sizeof(Qidtab));
@ -472,7 +472,7 @@ fatal(char *s, ...)
postnote(PNPROC, m->pid, "kill"); postnote(PNPROC, m->pid, "kill");
if(s != nil) { if(s != nil) {
DEBUG(DFD, "%s\n", buf); DEBUG(2, "%s\n", buf);
sysfatal("%s", buf); /* caution: buf could contain '%' */ sysfatal("%s", buf); /* caution: buf could contain '%' */
} else } else
exits(nil); exits(nil);

View File

@ -59,7 +59,7 @@ filter(int fd, char *cmd, char *host)
strecpy(strrchr(addr, '!'), addr+sizeof(addr), s); strecpy(strrchr(addr, '!'), addr+sizeof(addr), s);
} }
DEBUG(DFD, "filter: %s\n", addr); DEBUG(2, "filter: %s\n", addr);
snprint(buf, sizeof(buf), "%s", cmd); snprint(buf, sizeof(buf), "%s", cmd);
argc = tokenize(buf, argv, nelem(argv)-3); argc = tokenize(buf, argv, nelem(argv)-3);
@ -108,7 +108,7 @@ mksecret(char *t, uchar *f)
void void
usage(void) usage(void)
{ {
fprint(2, "usage: %s [-adnsR] [-f dbgfile] [-m msize] [-r root] " fprint(2, "usage: %s [-adnsR] [-m msize] [-r root] "
"[-S srvfile] [-e 'crypt hash'] [-P exclusion-file] " "[-S srvfile] [-e 'crypt hash'] [-P exclusion-file] "
"[-A announce-string] [-B address]\n", argv0); "[-A announce-string] [-B address]\n", argv0);
fatal("usage"); fatal("usage");
@ -118,12 +118,11 @@ void
main(int argc, char **argv) main(int argc, char **argv)
{ {
char buf[ERRMAX], ebuf[ERRMAX], initial[4], *ini, *srvfdfile; char buf[ERRMAX], ebuf[ERRMAX], initial[4], *ini, *srvfdfile;
char *dbfile, *srv, *na, *nsfile, *keyspec; char *srv, *na, *nsfile, *keyspec;
int doauth, n, fd; int doauth, n, fd;
AuthInfo *ai; AuthInfo *ai;
Fsrpc *r; Fsrpc *r;
dbfile = "/tmp/exportdb";
srv = nil; srv = nil;
srvfd = -1; srvfd = -1;
srvfdfile = nil; srvfdfile = nil;
@ -148,10 +147,6 @@ main(int argc, char **argv)
ealgs = nil; ealgs = nil;
break; break;
case 'f':
dbfile = EARGF(usage());
break;
case 'k': case 'k':
keyspec = EARGF(usage()); keyspec = EARGF(usage());
break; break;
@ -254,18 +249,12 @@ main(int argc, char **argv)
exclusions(); exclusions();
if(dbg) {
n = create(dbfile, OWRITE|OTRUNC, 0666);
dup(n, DFD);
close(n);
}
if(srvfd >= 0 && srv != nil){ if(srvfd >= 0 && srv != nil){
fprint(2, "%s: -S cannot be used with -r or -s\n", argv0); fprint(2, "%s: -S cannot be used with -r or -s\n", argv0);
usage(); usage();
} }
DEBUG(DFD, "%s: started\n", argv0); DEBUG(2, "%s: started\n", argv0);
rfork(RFNOTEG|RFREND); rfork(RFNOTEG|RFREND);
@ -289,10 +278,10 @@ main(int argc, char **argv)
if(chdir(srv) < 0) { if(chdir(srv) < 0) {
ebuf[0] = '\0'; ebuf[0] = '\0';
errstr(ebuf, sizeof ebuf); errstr(ebuf, sizeof ebuf);
DEBUG(DFD, "chdir(\"%s\"): %s\n", srv, ebuf); DEBUG(2, "chdir(\"%s\"): %s\n", srv, ebuf);
mounterror(ebuf); mounterror(ebuf);
} }
DEBUG(DFD, "invoked as server for %s", srv); DEBUG(2, "invoked as server for %s", srv);
strncpy(buf, srv, sizeof buf); strncpy(buf, srv, sizeof buf);
} }
else { else {
@ -301,22 +290,22 @@ main(int argc, char **argv)
if(n < 0) { if(n < 0) {
errstr(buf, sizeof buf); errstr(buf, sizeof buf);
fprint(0, "read(0): %s\n", buf); fprint(0, "read(0): %s\n", buf);
DEBUG(DFD, "read(0): %s\n", buf); DEBUG(2, "read(0): %s\n", buf);
exits(buf); exits(buf);
} }
buf[n] = 0; buf[n] = 0;
if(chdir(buf) < 0) { if(chdir(buf) < 0) {
errstr(ebuf, sizeof ebuf); errstr(ebuf, sizeof ebuf);
fprint(0, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); fprint(0, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf);
DEBUG(DFD, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); DEBUG(2, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf);
exits(ebuf); exits(ebuf);
} }
} }
DEBUG(DFD, "\niniting root\n"); DEBUG(2, "\niniting root\n");
initroot(); initroot();
DEBUG(DFD, "%s: %s\n", argv0, buf); DEBUG(2, "%s: %s\n", argv0, buf);
if(srv == nil && srvfd == -1 && write(0, "OK", 2) != 2) if(srv == nil && srvfd == -1 && write(0, "OK", 2) != 2)
fatal("open ack write"); fatal("open ack write");
@ -436,7 +425,7 @@ main(int argc, char **argv)
if(convM2S(r->buf, n, &r->work) != n) if(convM2S(r->buf, n, &r->work) != n)
fatal("convM2S format error"); fatal("convM2S format error");
DEBUG(DFD, "%F\n", &r->work); DEBUG(2, "%F\n", &r->work);
(fcalls[r->work.type])(r); (fcalls[r->work.type])(r);
} }
io(); io();

View File

@ -42,7 +42,7 @@ exclusions(void)
if(include == nil) if(include == nil)
fatal("out of memory"); fatal("out of memory");
} }
DEBUG(DFD, "\tinclude %s\n", line+2); DEBUG(2, "\tinclude %s\n", line+2);
include[ni] = regcomp(line+2); include[ni] = regcomp(line+2);
include[++ni] = nil; include[++ni] = nil;
break; break;
@ -53,12 +53,12 @@ exclusions(void)
if(exclude == nil) if(exclude == nil)
fatal("out of memory"); fatal("out of memory");
} }
DEBUG(DFD, "\texclude %s\n", line+2); DEBUG(2, "\texclude %s\n", line+2);
exclude[ne] = regcomp(line+2); exclude[ne] = regcomp(line+2);
exclude[++ne] = nil; exclude[++ne] = nil;
break; break;
default: default:
DEBUG(DFD, "ignoring pattern %s\n", line); DEBUG(2, "ignoring pattern %s\n", line);
break; break;
} }
} }
@ -76,16 +76,16 @@ excludefile(char *path)
else else
p = path+1; p = path+1;
DEBUG(DFD, "checking %s\n", p); DEBUG(2, "checking %s\n", p);
for(re = include; *re != nil; re++){ for(re = include; *re != nil; re++){
if(regexec(*re, p, nil, 0) != 1){ if(regexec(*re, p, nil, 0) != 1){
DEBUG(DFD, "excluded+ %s\n", p); DEBUG(2, "excluded+ %s\n", p);
return -1; return -1;
} }
} }
for(re = exclude; *re != nil; re++){ for(re = exclude; *re != nil; re++){
if(regexec(*re, p, nil, 0) == 1){ if(regexec(*re, p, nil, 0) == 1){
DEBUG(DFD, "excluded- %s\n", p); DEBUG(2, "excluded- %s\n", p);
return -1; return -1;
} }
} }
@ -98,7 +98,7 @@ preaddir(Fid *f, uchar *data, int n, vlong offset)
int r = 0, m; int r = 0, m;
Dir *d; Dir *d;
DEBUG(DFD, "\tpreaddir n=%d wo=%lld fo=%lld\n", n, offset, f->offset); DEBUG(2, "\tpreaddir n=%d wo=%lld fo=%lld\n", n, offset, f->offset);
if(offset == 0 && f->offset != 0){ if(offset == 0 && f->offset != 0){
if(seek(f->fid, 0, 0) != 0) if(seek(f->fid, 0, 0) != 0)
return -1; return -1;
@ -128,9 +128,9 @@ preaddir(Fid *f, uchar *data, int n, vlong offset)
free(p); free(p);
} }
m = convD2M(d, data, n); m = convD2M(d, data, n);
DEBUG(DFD, "\t\tconvD2M %d\n", m); DEBUG(2, "\t\tconvD2M %d\n", m);
if(m <= BIT16SZ){ if(m <= BIT16SZ){
DEBUG(DFD, "\t\t\tneeded %d\n", GBIT16(data)); DEBUG(2, "\t\t\tneeded %d\n", GBIT16(data));
/* not enough room for full entry; leave for next time */ /* not enough room for full entry; leave for next time */
f->cdir--; f->cdir--;
return r; return r;

View File

@ -6,7 +6,6 @@
#include <auth.h> #include <auth.h>
#include <fcall.h> #include <fcall.h>
#define DEBUGFILE "iostats.out"
#define DONESTR "done" #define DONESTR "done"
enum{ enum{
@ -250,7 +249,7 @@ rio(Fcall *fin, Fcall *fout)
void void
usage(void) usage(void)
{ {
fprint(2, "usage: iostats [-dC] [-f debugfile] cmds [args ...]\n"); fprint(2, "usage: iostats [-dC] cmds [args ...]\n");
exits("usage"); exits("usage");
} }
@ -259,7 +258,6 @@ main(int argc, char **argv)
{ {
Rpc *rpc; Rpc *rpc;
ulong ttime; ulong ttime;
char *dbfile;
char buf[64*1024]; char buf[64*1024];
float brpsec, bwpsec, bppsec; float brpsec, bwpsec, bppsec;
int cpid, fspid, expid, rspid, dbg, n, mflag; int cpid, fspid, expid, rspid, dbg, n, mflag;
@ -270,15 +268,11 @@ main(int argc, char **argv)
dbg = 0; dbg = 0;
mflag = MREPL; mflag = MREPL;
dbfile = DEBUGFILE;
ARGBEGIN{ ARGBEGIN{
case 'd': case 'd':
dbg++; dbg++;
break; break;
case 'f':
dbfile = ARGF();
break;
case 'C': case 'C':
mflag |= MCACHE; mflag |= MCACHE;
break; break;
@ -286,8 +280,6 @@ main(int argc, char **argv)
usage(); usage();
}ARGEND }ARGEND
USED(dbfile);
if(argc == 0) if(argc == 0)
usage(); usage();
@ -359,7 +351,7 @@ main(int argc, char **argv)
close(efd[1]); close(efd[1]);
close(pfd[1]); close(pfd[1]);
if(dbg){ if(dbg){
execl("/bin/exportfs", "exportfs", "-df", dbfile, "-r", "/", nil); execl("/bin/exportfs", "exportfs", "-d", "-r", "/", nil);
} else { } else {
execl("/bin/exportfs", "exportfs", "-r", "/", nil); execl("/bin/exportfs", "exportfs", "-r", "/", nil);
} }