fmtventi 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/rc
  2. # desc: initialize disks for a venti server
  3. # prereq: mountdist
  4. switch($1){
  5. case checkready checkdone
  6. if(! ~ $fstype fossil+venti){
  7. fmtventi=notdone
  8. export fmtventi
  9. exit
  10. }
  11. if(! test -e /bin/venti/fmtarenas || ! test -e /bin/venti/fmtisect || ! test -e /bin/venti/fmtindex){
  12. bind -a /n/dist/386/bin/venti /bin/venti
  13. if(! test -e /bin/venti/fmtarenas || ! test -e /bin/venti/fmtisect || ! test -e /bin/venti/fmtindex){
  14. fmtventi=notdone
  15. export fmtventi
  16. exit
  17. }
  18. }
  19. ff=`{ls /dev/sd*/arenas* /dev/fs/arenas* >[2]/dev/null}
  20. if(~ $#ff 0){
  21. fmtventi=notdone
  22. export fmtventi
  23. exit
  24. }
  25. gg=()
  26. for(f in $ff)
  27. if(isventi $f)
  28. gg=($gg $f)
  29. if(~ $#gg 0){
  30. fmtventi=ready
  31. export fmtventi
  32. exit
  33. }
  34. ventiarena=$gg(1)
  35. export ventiarena
  36. fmtventi=done
  37. export fmtventi
  38. exit
  39. case go
  40. ff=`{ls /dev/sd*/arenas* /dev/fs/arenas* >[2]/dev/null}
  41. if(~ $#ff 0){
  42. echo 'You need to create a partition or partitions to hold the Venti arenas.'
  43. echo 'The arena partition names must begin with "arenas".'
  44. echo
  45. fmtventi=notdone
  46. export fmtventi
  47. exit
  48. }
  49. default=(-d $"ff)
  50. if(! ~ $#ventiarena 0){
  51. default=(-d $"ventiarena)
  52. }
  53. echo You have the following Venti arena partitions.
  54. ls -l $ff
  55. echo
  56. prompt $default 'Venti arena partitions to use'
  57. aa=`{echo $rd}
  58. bad=no
  59. for(a in $aa){
  60. if(! ~ $a $ff){
  61. echo 'Bad venti arena partition' $a
  62. fmtventi=notdone
  63. export fmtventi
  64. exit
  65. }
  66. }
  67. ventiarena=$aa
  68. export ventiarena
  69. gg=`{ls /dev/sd*/isect* /dev/fs/isect* >[2]/dev/null}
  70. if(~ $#gg 0){
  71. echo 'You need to create a partition or partitions to hold the Venti indices.'
  72. echo 'The index partition names must begin with "isect".'
  73. echo
  74. fmtventi=notdone
  75. export fmtventi
  76. exit
  77. }
  78. default=(-d $"gg)
  79. if(! ~ $#ventiindex 0){
  80. default=(-d $"ventiindex)
  81. }
  82. echo You have the following Venti index partitions.
  83. ls -l $gg
  84. echo
  85. prompt $default 'Venti index partitions to use'
  86. aa=`{echo $rd}
  87. bad=no
  88. for(a in $aa){
  89. if(! ~ $a $gg){
  90. echo 'Bad venti index partition' $a
  91. fmtventi=notdone
  92. export fmtventi
  93. exit
  94. }
  95. }
  96. ventiindex=$aa
  97. export ventiindex
  98. n=-1
  99. fmta=()
  100. for(a in $ventiarena){
  101. do=yes
  102. n=`{hoc -e 1+$n}
  103. if(isventiarenas $a){
  104. echo File $a is already formatted as a Venti arenas partition.
  105. prompt -d no 'Reformat '$a yes no
  106. do=$rd
  107. }
  108. if(~ $do yes)
  109. fmta=($fmta arenas$n:$a)
  110. }
  111. n=-1
  112. fmti=()
  113. for(a in $ventiindex){
  114. do=yes
  115. n=`{hoc -e 1+$n}
  116. if(isventiisect $a){
  117. echo File $a is already formatted as a Venti index section.
  118. prompt -d no 'Reformat '$a yes no
  119. do=$rd
  120. }
  121. if(~ $do yes)
  122. fmti=($fmti isect$n:$a)
  123. }
  124. echo Formatting Venti arenas and indices (this takes a while).
  125. # do each disk in parallel
  126. echo good >/tmp/fmt
  127. dd=()
  128. for(a in $fmta $fmti){
  129. d=`{echo $a | sed 's!.*:(/.*/).*!\1!'}
  130. if(! ~ $d $dd)
  131. dd=($dd $d)
  132. }
  133. for(d in $dd){
  134. {
  135. for(a in $fmta){
  136. i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'}
  137. if(~ $i(2) $d){
  138. echo $i(3) ...
  139. venti/fmtarenas $i(1) $i(3) || echo bad >/tmp/fmt
  140. echo done with $i(3)
  141. }
  142. }
  143. for(a in $fmti){
  144. i=`{echo $a | sed 's!(.*):(/.*/)(.*)!\1 \2 \2\3!'}
  145. if(~ $i(2) $d){
  146. echo $i(3) ...
  147. venti/fmtisect $i(1) $i(3) || echo bad >/tmp/fmt
  148. echo done with $i(3)
  149. }
  150. }
  151. } &
  152. }
  153. wait
  154. if(~ bad `{cat /tmp/fmt}){
  155. echo There were errors formatting the indices and arenas.
  156. fmtventi=ready
  157. export fmtventi
  158. exit errors
  159. }
  160. echo Done formatting Venti arenas and indices.
  161. v=$ventiarena(1)
  162. echo Storing Venti config on $v...
  163. {
  164. echo index main
  165. for(i in $ventiindex)
  166. echo isect $i
  167. for(a in $ventiarena)
  168. echo arenas $a
  169. } | venti/conf -w $v
  170. echo Initializing index...
  171. venti/fmtindex $v
  172. echo Done with Venti!
  173. }