fmtventi 3.3 KB

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