changeset 56: | 2e60a35e2b3c |
---|---|
parent 55: | fd50afc99c21 |
child 63: | 9519bb640170 |
child 64: | 7665dba2f577 |
author: | Mechiel Lukkien <mechiel@ueber.net> |
date: | Fri, 13 Jul 2007 15:40:18 +0200 |
files: | appl/cmd/venti/get.b appl/cmd/venti/mkfile appl/cmd/venti/ping.b appl/cmd/venti/put.b appl/cmd/venti/sync.b man/1/vacget man/1/vcache man/1/venti man/4/vacfs man/8/ventisrv |
description: | new programs (and their manual pages): venti/(sync ping get put) - venti/(sync ping) syncs/pings a venti server - venti/put writes data from stdin to venti, resulting in the score of the 40-byte venti entry - venti/get reads data from the venti entry and writes it to stdout |
1.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2+++ b/appl/cmd/venti/get.b Fri Jul 13 15:40:18 2007 +0200 1.3@@ -0,0 +1,124 @@ 1.4+implement Ventiget; 1.5+ 1.6+include "sys.m"; 1.7+ sys: Sys; 1.8+include "draw.m"; 1.9+include "bufio.m"; 1.10+ bufio: Bufio; 1.11+ Iobuf: import bufio; 1.12+include "arg.m"; 1.13+include "string.m"; 1.14+include "venti.m"; 1.15+include "vac.m"; 1.16+ 1.17+str: String; 1.18+venti: Venti; 1.19+vac: Vac; 1.20+ 1.21+print, sprint, fprint, fildes: import sys; 1.22+Score, Session: import venti; 1.23+Dirtype, Datatype: import venti; 1.24+Entry, Entrysize, Vacfile: import vac; 1.25+ 1.26+Ventiget: module { 1.27+ init: fn(nil: ref Draw->Context, args: list of string); 1.28+}; 1.29+ 1.30+addr := "net!$venti!venti"; 1.31+dflag := 0; 1.32+session: ref Session; 1.33+ 1.34+init(nil: ref Draw->Context, args: list of string) 1.35+{ 1.36+ sys = load Sys Sys->PATH; 1.37+ bufio = load Bufio Bufio->PATH; 1.38+ arg := load Arg Arg->PATH; 1.39+ str = load String String->PATH; 1.40+ venti = load Venti Venti->PATH; 1.41+ vac = load Vac Vac->PATH; 1.42+ if(venti == nil || vac == nil) 1.43+ error("loading venti,vac"); 1.44+ venti->init(); 1.45+ vac->init(); 1.46+ 1.47+ arg->init(args); 1.48+ arg->setusage(sprint("%s [-d] [-a addr] [entry:]score", arg->progname())); 1.49+ while((c := arg->opt()) != 0) 1.50+ case c { 1.51+ 'a' => addr = arg->earg(); 1.52+ 'd' => dflag++; 1.53+ vac->dflag++; 1.54+ * => fprint(fildes(2), "bad option: -%c\n", c); 1.55+ arg->usage(); 1.56+ } 1.57+ args = arg->argv(); 1.58+ if(len args != 1) 1.59+ arg->usage(); 1.60+ 1.61+ (tag, scorestr) := str->splitstrr(hd args, ":"); 1.62+ if(tag != nil) 1.63+ tag = tag[:len tag-1]; 1.64+ if(tag == nil) 1.65+ tag = "entry"; 1.66+ if(tag != "entry") 1.67+ error("bad score type: "+tag); 1.68+ 1.69+ (sok, score) := Score.parse(scorestr); 1.70+ if(sok != 0) 1.71+ error("bad score: "+scorestr); 1.72+ say("have score"); 1.73+ 1.74+ (cok, conn) := sys->dial(addr, nil); 1.75+ if(cok < 0) 1.76+ error(sprint("dialing %s: %r", addr)); 1.77+ say("have connection"); 1.78+ 1.79+ fd := conn.dfd; 1.80+ session = Session.new(fd); 1.81+ if(session == nil) 1.82+ error(sprint("handshake: %r")); 1.83+ say("have handshake"); 1.84+ 1.85+ d := session.read(score, Dirtype, Entrysize); 1.86+ if(d == nil) 1.87+ error(sprint("reading entry: %r")); 1.88+ e := Entry.unpack(d); 1.89+ if(e == nil) 1.90+ error(sprint("unpacking entry: %r")); 1.91+ say("have entry"); 1.92+ 1.93+ bio := bufio->fopen(fildes(1), bufio->OWRITE); 1.94+ if(bio == nil) 1.95+ error(sprint("bufio fopen: %r")); 1.96+ 1.97+ say("reading"); 1.98+ buf := array[sys->ATOMICIO] of byte; 1.99+ vf := Vacfile.new(session, e); 1.100+ for(;;) { 1.101+ rn := vf.read(buf, len buf); 1.102+ if(rn == 0) 1.103+ break; 1.104+ if(rn < 0) 1.105+ error(sprint("reading: %r")); 1.106+ wn := bio.write(buf, rn); 1.107+ if(wn != rn) 1.108+ error(sprint("writing: %r")); 1.109+ } 1.110+ bok := bio.flush(); 1.111+ bio.close(); 1.112+ if(bok == bufio->ERROR || bok == bufio->EOF) 1.113+ error(sprint("bufio close: %r")); 1.114+ say("done"); 1.115+} 1.116+ 1.117+error(s: string) 1.118+{ 1.119+ fprint(fildes(2), "%s\n", s); 1.120+ raise "fail:"+s; 1.121+} 1.122+ 1.123+say(s: string) 1.124+{ 1.125+ if(dflag) 1.126+ fprint(fildes(2), "%s\n", s); 1.127+}
2.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2+++ b/appl/cmd/venti/mkfile Fri Jul 13 15:40:18 2007 +0200 2.3@@ -0,0 +1,25 @@ 2.4+<../../../mkconfig 2.5+ 2.6+TARG=\ 2.7+ sync.dis\ 2.8+ ping.dis\ 2.9+ get.dis\ 2.10+ put.dis\ 2.11+ 2.12+SYSMODULES=\ 2.13+ arg.m\ 2.14+ bufio.m\ 2.15+ daytime.m\ 2.16+ draw.m\ 2.17+ keyring.m\ 2.18+ string.m\ 2.19+ styx.m\ 2.20+ styxservers.m\ 2.21+ sys.m\ 2.22+ vac.m\ 2.23+ venti.m\ 2.24+ 2.25+DISBIN=$ROOT/dis/venti 2.26+ 2.27+<$ROOT/mkfiles/mkdis 2.28+<$ROOT/mkfiles/mksubdirs
3.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2+++ b/appl/cmd/venti/ping.b Fri Jul 13 15:40:18 2007 +0200 3.3@@ -0,0 +1,81 @@ 3.4+implement Ventiping; 3.5+ 3.6+include "sys.m"; 3.7+include "draw.m"; 3.8+include "arg.m"; 3.9+include "venti.m"; 3.10+ 3.11+sys: Sys; 3.12+venti: Venti; 3.13+ 3.14+print, sprint, fprint, fildes: import sys; 3.15+Score, Session, Vmsg: import venti; 3.16+ 3.17+Ventiping: module { 3.18+ init: fn(nil: ref Draw->Context, args: list of string); 3.19+}; 3.20+ 3.21+addr := "net!$venti!venti"; 3.22+dflag := 0; 3.23+n := 3; 3.24+ 3.25+init(nil: ref Draw->Context, args: list of string) 3.26+{ 3.27+ sys = load Sys Sys->PATH; 3.28+ arg := load Arg Arg->PATH; 3.29+ venti = load Venti Venti->PATH; 3.30+ venti->init(); 3.31+ 3.32+ arg->init(args); 3.33+ arg->setusage(arg->progname() + " [-d] [-n count] [-a addr]"); 3.34+ while((c := arg->opt()) != 0) 3.35+ case c { 3.36+ 'a' => addr = arg->earg(); 3.37+ 'd' => dflag++; 3.38+ 'n' => n = int arg->earg(); 3.39+ * => fprint(fildes(2), "bad option: -%c", c); 3.40+ arg->usage(); 3.41+ } 3.42+ args = arg->argv(); 3.43+ if(len args != 0) 3.44+ arg->usage(); 3.45+ 3.46+ say("dialing"); 3.47+ (cok, conn) := sys->dial(addr, nil); 3.48+ if(cok < 0) 3.49+ fail(sprint("dialing %s: %r", addr)); 3.50+ fd := conn.dfd; 3.51+ say("have connection"); 3.52+ 3.53+ session := Session.new(fd); 3.54+ if(session == nil) 3.55+ fail(sprint("handshake: %r")); 3.56+ say("have handshake"); 3.57+ 3.58+ tm := ref Vmsg.Tping(1, 0); 3.59+ i := 0; 3.60+ for(;;) { 3.61+ t0 := sys->millisec(); 3.62+ (rm, err) := session.rpc(tm); 3.63+ if(rm == nil) 3.64+ fail("ping: "+err); 3.65+ t1 := sys->millisec(); 3.66+ print("%d ms\n", t1-t0); 3.67+ i++; 3.68+ if(i == n) 3.69+ break; 3.70+ sys->sleep(1*1000); 3.71+ } 3.72+} 3.73+ 3.74+fail(s: string) 3.75+{ 3.76+ fprint(fildes(2), "%s\n", s); 3.77+ raise "fail:"+s; 3.78+} 3.79+ 3.80+say(s: string) 3.81+{ 3.82+ if(dflag) 3.83+ fprint(fildes(2), "%s\n", s); 3.84+}
4.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2+++ b/appl/cmd/venti/put.b Fri Jul 13 15:40:18 2007 +0200 4.3@@ -0,0 +1,118 @@ 4.4+implement Ventiput; 4.5+ 4.6+include "sys.m"; 4.7+ sys: Sys; 4.8+include "draw.m"; 4.9+include "bufio.m"; 4.10+ bufio: Bufio; 4.11+ Iobuf: import bufio; 4.12+include "arg.m"; 4.13+include "venti.m"; 4.14+include "vac.m"; 4.15+ 4.16+venti: Venti; 4.17+vac: Vac; 4.18+ 4.19+print, sprint, fprint, fildes: import sys; 4.20+Score, Session: import venti; 4.21+Dirtype, Datatype: import venti; 4.22+Entry, File: import vac; 4.23+ 4.24+Ventiput: module { 4.25+ init: fn(nil: ref Draw->Context, args: list of string); 4.26+}; 4.27+ 4.28+addr := "net!$venti!venti"; 4.29+dflag := 0; 4.30+blocksize := vac->Dsize; 4.31+session: ref Session; 4.32+ 4.33+init(nil: ref Draw->Context, args: list of string) 4.34+{ 4.35+ sys = load Sys Sys->PATH; 4.36+ bufio = load Bufio Bufio->PATH; 4.37+ arg := load Arg Arg->PATH; 4.38+ venti = load Venti Venti->PATH; 4.39+ vac = load Vac Vac->PATH; 4.40+ if(venti == nil || vac == nil) 4.41+ error("loading venti,vac"); 4.42+ venti->init(); 4.43+ vac->init(); 4.44+ 4.45+ arg->init(args); 4.46+ arg->setusage(sprint("%s [-d] [-a addr] [-b blocksize]", arg->progname())); 4.47+ while((c := arg->opt()) != 0) 4.48+ case c { 4.49+ 'a' => addr = arg->earg(); 4.50+ 'b' => blocksize = int arg->earg(); 4.51+ 'd' => dflag++; 4.52+ vac->dflag++; 4.53+ * => fprint(fildes(2), "bad option: -%c", c); 4.54+ arg->usage(); 4.55+ } 4.56+ args = arg->argv(); 4.57+ if(len args != 0) 4.58+ arg->usage(); 4.59+ 4.60+ (cok, conn) := sys->dial(addr, nil); 4.61+ if(cok < 0) 4.62+ error(sprint("dialing %s: %r", addr)); 4.63+ say("have connection"); 4.64+ 4.65+ session = Session.new(conn.dfd); 4.66+ if(session == nil) 4.67+ error(sprint("handshake: %r")); 4.68+ say("have handshake"); 4.69+ 4.70+ bio := bufio->fopen(fildes(0), bufio->OREAD); 4.71+ if(bio == nil) 4.72+ error(sprint("bufio open: %r")); 4.73+ 4.74+ say("writing"); 4.75+ f := File.new(session, Datatype, blocksize, 0); 4.76+ for(;;) { 4.77+ buf := array[blocksize] of byte; 4.78+ n := 0; 4.79+ while(n < len buf) { 4.80+ want := len buf - n; 4.81+ have := bio.read(buf[n:], want); 4.82+ if(have == 0) 4.83+ break; 4.84+ if(have < 0) 4.85+ error(sprint("reading: %r")); 4.86+ n += have; 4.87+ } 4.88+ if(dflag) say(sprint("have buf, length %d", n)); 4.89+ 4.90+ if(f.write(buf[:n]) < 0) 4.91+ error(sprint("writing: %r")); 4.92+ if(n != len buf) 4.93+ break; 4.94+ } 4.95+ bio.close(); 4.96+ e := f.finish(); 4.97+ if(e == nil) 4.98+ error(sprint("flushing: %r")); 4.99+ d := e.pack(); 4.100+ 4.101+ (rok, rscore) := session.write(Dirtype, d); 4.102+ if(rok < 0) 4.103+ error(sprint("writing root score: %r")); 4.104+ say("entry written, "+rscore.text()); 4.105+ print("entry:%s\n", rscore.text()); 4.106+ 4.107+ if(session.sync() < 0) 4.108+ error(sprint("syncing server: %r")); 4.109+} 4.110+ 4.111+error(s: string) 4.112+{ 4.113+ fprint(fildes(2), "%s\n", s); 4.114+ raise "fail:"+s; 4.115+} 4.116+ 4.117+say(s: string) 4.118+{ 4.119+ if(dflag) 4.120+ fprint(fildes(2), "%s\n", s); 4.121+}
5.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2+++ b/appl/cmd/venti/sync.b Fri Jul 13 15:40:18 2007 +0200 5.3@@ -0,0 +1,68 @@ 5.4+implement Ventisync; 5.5+ 5.6+include "sys.m"; 5.7+include "draw.m"; 5.8+include "arg.m"; 5.9+include "venti.m"; 5.10+ 5.11+sys: Sys; 5.12+venti: Venti; 5.13+ 5.14+print, sprint, fprint, fildes: import sys; 5.15+Score, Session: import venti; 5.16+ 5.17+Ventisync: module { 5.18+ init: fn(nil: ref Draw->Context, args: list of string); 5.19+}; 5.20+ 5.21+addr := "net!$venti!venti"; 5.22+dflag := 0; 5.23+ 5.24+init(nil: ref Draw->Context, args: list of string) 5.25+{ 5.26+ sys = load Sys Sys->PATH; 5.27+ arg := load Arg Arg->PATH; 5.28+ venti = load Venti Venti->PATH; 5.29+ venti->init(); 5.30+ 5.31+ arg->init(args); 5.32+ arg->setusage(arg->progname() + " [-d] [-a addr]"); 5.33+ while((c := arg->opt()) != 0) 5.34+ case c { 5.35+ 'a' => addr = arg->earg(); 5.36+ 'd' => dflag++; 5.37+ * => fprint(fildes(2), "bad option: -%c", c); 5.38+ arg->usage(); 5.39+ } 5.40+ args = arg->argv(); 5.41+ if(len args != 0) 5.42+ arg->usage(); 5.43+ 5.44+ say("dialing"); 5.45+ (cok, conn) := sys->dial(addr, nil); 5.46+ if(cok < 0) 5.47+ fail(sprint("dialing %s: %r", addr)); 5.48+ fd := conn.dfd; 5.49+ say("have connection"); 5.50+ 5.51+ session := Session.new(fd); 5.52+ if(session == nil) 5.53+ fail(sprint("handshake: %r")); 5.54+ say("have handshake"); 5.55+ 5.56+ if(session.sync() < 0) 5.57+ fail(sprint("sync: %r")); 5.58+ say("synced"); 5.59+} 5.60+ 5.61+fail(s: string) 5.62+{ 5.63+ fprint(fildes(2), "%s\n", s); 5.64+ raise "fail:"+s; 5.65+} 5.66+ 5.67+say(s: string) 5.68+{ 5.69+ if(dflag) 5.70+ fprint(fildes(2), "%s\n", s); 5.71+}
6.1--- a/man/1/vacget Fri Jul 13 15:01:42 2007 +0200 6.2+++ b/man/1/vacget Fri Jul 13 15:40:18 2007 +0200 6.3@@ -67,6 +67,9 @@ 6.4 .br 6.5 .B /appl/cmd/vacput.b 6.6 .SH SEE ALSO 6.7+.IR venti (1), 6.8+.IR vacget (1), 6.9+.IR vacput (1), 6.10 .IR vcache (1), 6.11 .IR venti (2), 6.12 .IR vacfs (4),
7.1--- a/man/1/vcache Fri Jul 13 15:01:42 2007 +0200 7.2+++ b/man/1/vcache Fri Jul 13 15:40:18 2007 +0200 7.3@@ -53,6 +53,7 @@ 7.4 .SH SOURCE 7.5 .B /appl/cmd/vcache.b 7.6 .SH SEE ALSO 7.7+.IR venti (1), 7.8 .IR vacget (1), 7.9 .IR vacput (1), 7.10 .IR venti (2),
8.1--- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2+++ b/man/1/venti Fri Jul 13 15:40:18 2007 +0200 8.3@@ -0,0 +1,93 @@ 8.4+.TH VENTI 1 8.5+.SH NAME 8.6+venti/sync, venti/ping, venti/get, venti/put \- venti utilities 8.7+.SH SYNOPSIS 8.8+.B venti/sync 8.9+[ 8.10+.B -d 8.11+] [ 8.12+.B -a 8.13+.I addr 8.14+] 8.15+.br 8.16+.B venti/ping 8.17+[ 8.18+.B -d 8.19+] [ 8.20+.B -a 8.21+.I addr 8.22+] [ 8.23+.B -n 8.24+.I count 8.25+] 8.26+.br 8.27+.B venti/put 8.28+[ 8.29+.B -d 8.30+] [ 8.31+.B -a 8.32+.I addr 8.33+] [ 8.34+.B -b 8.35+.I blocksize 8.36+] 8.37+.br 8.38+.B venti/get 8.39+[ 8.40+.B -d 8.41+] [ 8.42+.B -a 8.43+.I addr 8.44+] 8.45+.I entry:score 8.46+.SH DESCRIPTION 8.47+.I Venti/sync 8.48+sends a sync messages to a venti server. When it returns, the venti server has flushed its data to stable storage. 8.49+.PP 8.50+.I Venti/ping 8.51+pings a venti server. Option 8.52+.B -n 8.53+sets the number of ping messages to send. The round trip time for each message is printed. 8.54+.PP 8.55+.I Venti/put 8.56+reads data from standard input and writes it to venti. When done, the score of the resulting venti entry is printed. 8.57+.I Venti/get 8.58+reads the data from the venti entry referenced by 8.59+.I score 8.60+and writes it to standard output. 8.61+.PP 8.62+The options the programs understand are: 8.63+.TP 8.64+.B -d 8.65+Print debug messages. 8.66+.TP 8.67+.BI -a " address" 8.68+Dial 8.69+.I address 8.70+instead of the default venti server. 8.71+.TP 8.72+.BI -b " blocksize" 8.73+Use blocks with 8.74+.I blocksize 8.75+bytes instead of the default 8192 byte blocks. Only for 8.76+.IR venti/put . 8.77+.TP 8.78+.BI -n " count" 8.79+Send 8.80+.I count 8.81+pings to the venti server. The default is three. When set to zero, 8.82+.I venti/ping 8.83+pings until interrupted. 8.84+.SH SOURCE 8.85+.B /appl/cmd/venti/sync.b 8.86+.br 8.87+.B /appl/cmd/venti/ping.b 8.88+.br 8.89+.B /appl/cmd/venti/get.b 8.90+.br 8.91+.B /appl/cmd/venti/put.b 8.92+.SH SEE ALSO 8.93+.IR vcache (1), 8.94+.IR venti (2), 8.95+.IR vacfs (4), 8.96+.IR ventisrv (8)
9.1--- a/man/4/vacfs Fri Jul 13 15:01:42 2007 +0200 9.2+++ b/man/4/vacfs Fri Jul 13 15:40:18 2007 +0200 9.3@@ -36,6 +36,7 @@ 9.4 .SH SOURCE 9.5 .B /appl/cmd/vacfs.b 9.6 .SH SEE ALSO 9.7+.IR venti (1), 9.8 .IR vacget (1), 9.9 .IR vacput (1), 9.10 .IR vcache (1),
10.1--- a/man/8/ventisrv Fri Jul 13 15:01:42 2007 +0200 10.2+++ b/man/8/ventisrv Fri Jul 13 15:40:18 2007 +0200 10.3@@ -94,6 +94,7 @@ 10.4 .SH SOURCE 10.5 .B /appl/cmd/ventisrv.b 10.6 .SH SEE ALSO 10.7+.IR venti (1), 10.8 .IR vacget (1), 10.9 .IR vacput (1), 10.10 .IR vcache (1),