#!/bin/rc
# desc: initialize disks for a venti server
# prereq: mountdist
switch($1){
case checkready checkdone
if(! ~ $fstype fossil+venti){
fmtventi=notdone
export fmtventi
exit
}
if(! test -e /bin/venti/fmtarenas || ! test -e /bin/venti/fmtisect || ! test -e /bin/venti/fmtindex || ! test -e /bin/venti/fmtbloom){
bind -a /n/dist/386/bin/venti /bin/venti
if(! test -e /bin/venti/fmtarenas || ! test -e /bin/venti/fmtisect || ! test -e /bin/venti/fmtindex || ! test -e /bin/venti/fmtbloom){
fmtventi=notdone
export fmtventi
exit
}
}
ff=`{ls /dev/sd*/arenas* /dev/fs/arenas* >[2]/dev/null}
if(~ $#ff 0){
fmtventi=notdone
export fmtventi
exit
}
gg=()
for(f in $ff)
if(isventi $f)
gg=($gg $f)
if(~ $#gg 0){
fmtventi=ready
export fmtventi
exit
}
ventiarena=$gg(1)
export ventiarena
fmtventi=done
export fmtventi
exit
case go
ff=`{ls /dev/sd*/arenas* /dev/fs/arenas* >[2]/dev/null}
if(~ $#ff 0){
echo 'You need to create a partition or partitions to hold the Venti arenas.'
echo 'The arena partition names must begin with "arenas".'
echo
fmtventi=notdone
export fmtventi
exit
}
default=(-d $"ff)
if(! ~ $#ventiarena 0){
default=(-d $"ventiarena)
}
echo You have the following Venti arena partitions.
ls -l $ff
echo
prompt $default 'Venti arena partitions to use'
aa=`{echo $rd}
bad=no
for(a in $aa){
if(! ~ $a $ff){
echo 'Bad venti arena partition' $a
fmtventi=notdone
export fmtventi
exit
}
}
ventiarena=$aa
export ventiarena
gg=`{ls /dev/sd*/isect* /dev/fs/isect* >[2]/dev/null}
if(~ $#gg 0){
echo 'You need to create a partition or partitions to hold the Venti indices.'
echo 'The index partition names must begin with "isect".'
echo
fmtventi=notdone
export fmtventi
exit
}
default=(-d $"gg)
if(! ~ $#ventiindex 0){
default=(-d $"ventiindex)
}
echo You have the following Venti index partitions.
ls -l $gg
echo
prompt $default 'Venti index partitions to use'
aa=`{echo $rd}
bad=no
for(a in $aa){
if(! ~ $a $gg){
echo 'Bad venti index partition' $a
fmtventi=notdone
export fmtventi
exit
}
}
ventiindex=$aa
export ventiindex
hh=`{ls /dev/sd*/bloom* /dev/fs/bloom* >[2]/dev/null}
if(~ $#hh 0){
echo 'You need to create a partition or partitions to hold the Venti bloom.'
echo 'The bloom partition names must begin with "bloom".'
echo
fmtventi=notdone
export fmtventi
exit
}
default=(-d $"hh)
if(! ~ $#ventibloom 0){
default=(-d $"ventibloom)
}
echo You have the following Venti bloom partitions.
ls -l $hh
echo
prompt $default 'Venti bloom partitions to use'
aa=`{echo $rd}
bad=no
for(a in $aa){
if(! ~ $a $hh){
echo 'Bad venti bloom partition' $a
fmtventi=notdone
export fmtventi
exit
}
}
ventibloom=$aa
export ventibloom
n=-1
fmta=()
for(a in $ventiarena){
do=yes
n=`{hoc -e 1+$n}
if(isventiarenas $a){
echo File $a is already formatted as a Venti arenas partition.
prompt -d no 'Reformat '$a yes no
do=$rd
}
if(~ $do yes)
fmta=($fmta arenas$n:$a)
}
n=-1
fmti=()
for(a in $ventiindex){
do=yes
n=`{hoc -e 1+$n}
if(isventiisect $a){
echo File $a is already formatted as a Venti index section.
prompt -d no 'Reformat '$a yes no
do=$rd
}
if(~ $do yes)
fmti=($fmti isect$n:$a)
}
n=-1
fmtb=()
for(a in $ventibloom){
do=yes
n=`{hoc -e 1+$n}
if(isventibloom $a){
echo File $a is already formatted as a Venti bloom section.
prompt -d no 'Reformat '$a yes no
do=$rd
}
if(~ $do yes)
fmtb=($fmtb bloom$n:$a)
}
echo Formatting Venti arenas and indices (this takes a while).
# do each disk in parallel
echo good >/tmp/fmt
dd=()
for(a in $fmta $fmti $fmtb){
d=`{echo $a | sed 's!.*:(/.*/).*!\1!'}
if(! ~ $d $dd)
dd=($dd $d)
}
for(d in $dd){
{
for(a in $fmta){
i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'}
if(~ $i(2) $d){
echo $i(3) ...
venti/fmtarenas $i(1) $i(3) || echo bad >/tmp/fmt
echo done with $i(3)
}
}
for(a in $fmti){
i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'}
if(~ $i(2) $d){
echo $i(3) ...
venti/fmtisect $i(1) $i(3) || echo bad >/tmp/fmt
echo done with $i(3)
}
}
for(a in $fmtb){
i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'}
pgsize=`{grep pagesize /dev/swap | sed 's/^([0-9]+) .*$/\1/'}
userused=`{grep user /dev/swap | sed 's/^([0-9]+)\/([0-9]+) .*$/\1/'}
userpgs=`{grep user /dev/swap | sed 's/^([0-9]+)\/([0-9]+) .*$/\2/'}
userfree=`{hoc -e '('$userpgs-$userused')'*$pgsize}
bloomsize=`{hoc -e 2'^(int(log('$userfree/1024/1024*20/100*1/3')/log(2)))'}
partsize=`{ls -l $i(3) | awk '{print int($6/1024/1024)}' | hoc}
if(test $bloomsize -gt $partsize)
bloomsize=$partsize
if(test $bloomsize -lt 1)
bloomsize=1
if(~ $i(2) $d){
echo $i(3) ...
venti/fmtbloom -s $bloomsize^m $i(3) || echo bad >/tmp/fmt
echo done with $i(3)
}
}
} &
}
wait
if(~ bad `{cat /tmp/fmt}){
echo There were errors formatting the indices and arenas.
fmtventi=ready
export fmtventi
exit errors
}
echo Done formatting Venti arenas and indices.
v=$ventiarena(1)
echo Storing Venti config on $v...
{
echo index main
for(i in $ventiindex)
echo isect $i
for(b in $ventibloom)
echo bloom $b
for(a in $ventiarena)
echo arenas $a
} | venti/conf -w $v
echo Initializing index...
venti/fmtindex $v
echo Done with Venti!
}
|