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