From 28b49df3542a635cca788f3de213385f3fcb6334 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 18 Jul 2006 15:26:33 +0000 Subject: assorted changes from Plan 9 --- src/cmd/venti/srv/httpd.c | 219 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 198 insertions(+), 21 deletions(-) (limited to 'src/cmd/venti/srv/httpd.c') diff --git a/src/cmd/venti/srv/httpd.c b/src/cmd/venti/srv/httpd.c index ad7222dd..04d19d9d 100644 --- a/src/cmd/venti/srv/httpd.c +++ b/src/cmd/venti/srv/httpd.c @@ -9,7 +9,7 @@ extern QLock memdrawlock; enum { ObjNameSize = 64, - MaxObjs = 16 + MaxObjs = 64 }; struct HttpObj @@ -28,6 +28,12 @@ static int dindex(HConnect *c); static int xindex(HConnect *c); static int xlog(HConnect *c); static int sindex(HConnect *c); +static int hempty(HConnect *c); +static int hlcacheempty(HConnect *c); +static int hdcacheempty(HConnect *c); +static int hicacheempty(HConnect *c); +static int hicachekick(HConnect *c); +static int hdcachekick(HConnect *c); static int hicacheflush(HConnect *c); static int hdcacheflush(HConnect *c); static int notfound(HConnect *c); @@ -53,10 +59,17 @@ httpdinit(char *address, char *dir) httpdobj("/xindex", xindex); httpdobj("/flushicache", hicacheflush); httpdobj("/flushdcache", hdcacheflush); + httpdobj("/kickicache", hicachekick); + httpdobj("/kickdcache", hdcachekick); httpdobj("/graph/", xgraph); + httpdobj("/set", xset); httpdobj("/set/", xset); httpdobj("/log", xlog); httpdobj("/log/", xlog); + httpdobj("/empty", hempty); + httpdobj("/emptyicache", hicacheempty); + httpdobj("/emptylumpcache", hlcacheempty); + httpdobj("/emptydcache", hdcacheempty); if(vtproc(listenproc, address) < 0) return -1; @@ -105,8 +118,6 @@ listenproc(void *vaddress) char *address, ndir[NETPATHLEN], dir[NETPATHLEN]; int ctl, nctl, data; -/*sleep(1000); // let strace find us */ - address = vaddress; ctl = announce(address, dir); if(ctl < 0){ @@ -148,7 +159,6 @@ httpproc(void *v) HConnect *c; int ok, i, n; -/*sleep(1000); // let strace find us */ c = v; for(;;){ @@ -182,7 +192,7 @@ httpproc(void *v) } static int -percent(long v, long total) +percent(ulong v, ulong total) { if(total == 0) total = 1; @@ -239,6 +249,31 @@ preqtext(HConnect *c) return preqtype(c, "text/plain"); } +static int +herror(HConnect *c) +{ + int n; + Hio *hout; + + hout = &c->hout; + n = snprint(c->xferbuf, HBufSize, "Error\n

Error

\n
%r
\n"); + hprint(hout, "%s %s\r\n", hversion, "400 Bad Request"); + hprint(hout, "Date: %D\r\n", time(nil)); + hprint(hout, "Server: Venti\r\n"); + hprint(hout, "Content-Type: text/html\r\n"); + hprint(hout, "Content-Length: %d\r\n", n); + if(c->head.closeit) + hprint(hout, "Connection: close\r\n"); + else if(!http11(c)) + hprint(hout, "Connection: Keep-Alive\r\n"); + hprint(hout, "\r\n"); + + if(c->req.meth == nil || strcmp(c->req.meth, "HEAD") != 0) + hwrite(hout, c->xferbuf, n); + + return hflush(hout); +} + static int notfound(HConnect *c) { @@ -325,21 +360,53 @@ static struct "logging", &ventilogging, "stats", &collectstats, "icachesleeptime", &icachesleeptime, + "minicachesleeptime", &minicachesleeptime, "arenasumsleeptime", &arenasumsleeptime, + "l0quantum", &l0quantum, + "l1quantum", &l1quantum, + "manualscheduling", &manualscheduling, + "ignorebloom", &ignorebloom, + "syncwrites", &syncwrites, + "icacheprefetch", &icacheprefetch, 0 }; +static int +xsetlist(HConnect *c) +{ + int i; + + if(preqtype(c, "text/plain") < 0) + return -1; + for(i=0; namedints[i].name; i++) + print("%s = %d\n", namedints[i].name, *namedints[i].p); + hflush(&c->hout); + return 0; +} + + + static int xset(HConnect *c) { int i, nf, r; char *f[10], *s; + if(strcmp(c->req.uri, "/set") == 0 || strcmp(c->req.uri, "/set/") == 0) + return xsetlist(c); + s = estrdup(c->req.uri); nf = getfields(s+strlen("/set/"), f, nelem(f), 1, "/"); - if(nf < 1) - return notfound(c); + if(nf < 1){ + r = preqtext(c); + if(r < 0) + return r; + for(i=0; namedints[i].name; i++) + hprint(&c->hout, "%s = %d\n", namedints[i].name, *namedints[i].p); + hflush(&c->hout); + return 0; + } for(i=0; namedints[i].name; i++){ if(strcmp(f[0], namedints[i].name) == 0){ if(nf >= 2) @@ -494,6 +561,108 @@ darena(Hio *hout, Arena *arena) arena->diskstats.used + arena->diskstats.clumps * ClumpInfoSize); } +static int +hempty(HConnect *c) +{ + Hio *hout; + int r; + + r = preqtext(c); + if(r < 0) + return r; + hout = &c->hout; + + emptylumpcache(); + emptydcache(); + emptyicache(); + hprint(hout, "emptied all caches\n"); + hflush(hout); + return 0; +} + +static int +hlcacheempty(HConnect *c) +{ + Hio *hout; + int r; + + r = preqtext(c); + if(r < 0) + return r; + hout = &c->hout; + + emptylumpcache(); + hprint(hout, "emptied lumpcache\n"); + hflush(hout); + return 0; +} + +static int +hicacheempty(HConnect *c) +{ + Hio *hout; + int r; + + r = preqtext(c); + if(r < 0) + return r; + hout = &c->hout; + + emptyicache(); + hprint(hout, "emptied icache\n"); + hflush(hout); + return 0; +} + +static int +hdcacheempty(HConnect *c) +{ + Hio *hout; + int r; + + r = preqtext(c); + if(r < 0) + return r; + hout = &c->hout; + + emptydcache(); + hprint(hout, "emptied dcache\n"); + hflush(hout); + return 0; +} +static int +hicachekick(HConnect *c) +{ + Hio *hout; + int r; + + r = preqtext(c); + if(r < 0) + return r; + hout = &c->hout; + + kickicache(); + hprint(hout, "kicked icache\n"); + hflush(hout); + return 0; +} + +static int +hdcachekick(HConnect *c) +{ + Hio *hout; + int r; + + r = preqtext(c); + if(r < 0) + return r; + hout = &c->hout; + + kickdcache(); + hprint(hout, "kicked dcache\n"); + hflush(hout); + return 0; +} static int hicacheflush(HConnect *c) { @@ -569,6 +738,7 @@ rawgraph(Stats *s, Stats *t, void *va) { Arg *a; + USED(s); a = va; return t->n[a->index]; } @@ -587,6 +757,7 @@ pctgraph(Stats *s, Stats *t, void *va) { Arg *a; + USED(s); a = va; return percent(t->n[a->index], t->n[a->index2]); } @@ -722,7 +893,7 @@ static char* graphname[] = "isectwritebyte", "sumread", - "sumreadbyte" + "sumreadbyte", }; static int @@ -733,7 +904,6 @@ findname(char *s) for(i=0; iname : "<nil>"; -fprint(2, "hdump xfer %d\n", h->xferenc); hprint(h, "\n"); hprint(h, "Venti Server Log: %s\n", name); hprint(h, "\n"); -- cgit v1.2.3