xref: /freebsd/tools/regression/iscsi/iscsi-test.sh (revision cab6a39d7b343596a5823e65c0f7b426551ec22d)
1#!/bin/sh
2#
3# Copyright (c) 2012 The FreeBSD Foundation
4#
5# This software was developed by Edward Tomasz Napierala under sponsorship
6# from the FreeBSD Foundation.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29# $FreeBSD$
30#
31
32#
33# This expects that the iSCSI server being tested is at $TARGETIP and exports
34# two targets: $TARGET1 and $TARGET2; the former requiring no authentication,
35# and the latter using CHAP with user $USER and secret $SECRET.  Discovery
36# must be permitted without authentication.  Each target must contain exactly
37# two LUNs, 4GB each.  For example, ctl.conf(5) should look like this:
38#
39# auth-group meh {
40# 	chap user secretsecret
41# }
42#
43# portal-group meh {
44# 	listen 0.0.0.0
45# 	discovery-auth-group no-authentication
46# }
47#
48# target iqn.2012-06.com.example:1 {
49# 	auth-group no-authentication
50# 	portal-group meh
51# 	lun 0 {
52# 		path /var/tmp/example_t1l0
53# 		size 4G
54# 	}
55# 	lun 1 {
56# 		path /var/tmp/example_t1l1
57# 		size 4G
58# 	}
59# }
60#
61# target iqn.2012-06.com.example:2 {
62# 	auth-group meh
63# 	portal-group meh
64# 	lun 0 {
65# 		path /var/tmp/example_t2l0
66# 		size 4G
67# 	}
68# 	lun 1 {
69# 		path /var/tmp/example_t2l1
70# 		size 4G
71# 	}
72# }
73#
74# Remember to create the backing files (/var/tmp/example_t1l0 etcc)
75#
76# On the initiator, $MNTDIR will be used for testing.
77#
78
79TARGETIP=192.168.56.101
80TARGET1=iqn.2012-06.com.example:1
81TARGET2=iqn.2012-06.com.example:2
82USER=user
83SECRET=secretsecret
84MNTDIR=/mnt
85TMPDIR=/tmp
86
87die() {
88	echo "$*"
89	exit 1
90}
91
92case `uname` in
93	FreeBSD)
94		LUN0=/dev/da0
95		LUN1=/dev/da1
96		LUN2=/dev/da2
97		LUN3=/dev/da3
98		ZFSPOOL=iscsipool
99		;;
100	Linux)
101		LUN0=/dev/sdb
102		LUN1=/dev/sdc
103		LUN2=/dev/sdd
104		LUN3=/dev/sde
105		;;
106	SunOS)
107		# LUN names are being set later, during attach.
108		ZFSPOOL=iscsipool
109		;;
110	*)
111		die "unsupported system"
112		;;
113esac
114
115check() {
116	echo "# $@" > /dev/stderr
117	$@ || die "$@ failed"
118}
119
120banner() {
121	echo "Will try to attach to $TARGET1 and $TARGET2 on $TARGETIP,"
122	echo "user $USER, secret $SECRET.  Will use mountpoint $MNTDIR, temporary dir $TMPDIR,"
123	if [ -n "$LUN0" ]; then
124		echo "scratch disks $LUN0, $LUN1, $LUN2, $LUN3."
125	else
126		echo "scratch disks unknown at this stage."
127	fi
128	echo
129	echo "This script is NOT safe to run on multiuser system."
130	echo
131	echo "Press ^C to interrupt; will proceed in 5 seconds."
132	sleep 5
133}
134
135test_discovery_freebsd_9() {
136	kldload iscsi_initiator
137	check iscontrol -dt $TARGETIP > $TMPDIR/discovered
138	cat $TMPDIR/discovered
139	echo "TargetName=$TARGET1" > $TMPDIR/expected
140	echo "TargetName=$TARGET2" >> $TMPDIR/expected
141	check cmp $TMPDIR/expected $TMPDIR/discovered
142	rm -f $TMPDIR/expected $TMPDIR/discovered
143}
144
145test_discovery_freebsd() {
146	/etc/rc.d/iscsid onestart
147	check iscsictl -Ad $TARGETIP
148	sleep 1
149	iscsictl | awk '{ print $1 }' | sort > $TMPDIR/discovered
150	printf "Target\n$TARGET1\n$TARGET2\n" | sort > $TMPDIR/expected
151	check cmp $TMPDIR/expected $TMPDIR/discovered
152	rm -f $TMPDIR/expected $TMPDIR/discovered
153	check iscsictl -Ra
154	sleep 1
155}
156
157test_discovery_linux() {
158	cat > /etc/iscsi/iscsid.conf << END
159
160discovery.sendtargets.auth.authmethod = None
161node.startup = manual
162
163END
164
165	check iscsiadm  -m discovery -t sendtargets -p $TARGETIP > $TMPDIR/discovered
166	cat $TMPDIR/discovered
167	echo "$TARGETIP:3260,-1 $TARGET1" > $TMPDIR/expected
168	echo "$TARGETIP:3260,-1 $TARGET2" >> $TMPDIR/expected
169	check cmp $TMPDIR/expected $TMPDIR/discovered
170	rm -f $TMPDIR/expected $TMPDIR/discovered
171
172}
173
174test_discovery_solaris() {
175	check iscsiadm add discovery-address $TARGETIP
176	check iscsiadm modify discovery --sendtargets enable
177	check iscsiadm modify discovery --static enable
178	check iscsiadm list target | awk '/^Target/ { print $2 }' | sort > $TMPDIR/discovered
179	check iscsiadm remove discovery-address $TARGETIP
180	cat $TMPDIR/discovered
181	echo "$TARGET1" > $TMPDIR/expected
182	echo "$TARGET2" >> $TMPDIR/expected
183	check cmp $TMPDIR/expected $TMPDIR/discovered
184	rm -f $TMPDIR/expected $TMPDIR/discovered
185}
186
187test_discovery() {
188	echo "*** discovery test ***"
189	case `uname` in
190		FreeBSD)
191			case `uname -r` in
192				9*)
193					test_discovery_freebsd_9
194					;;
195				*)
196					test_discovery_freebsd
197					;;
198			esac
199			;;
200		Linux)
201			test_discovery_linux
202			;;
203		SunOS)
204			test_discovery_solaris
205			;;
206		*)
207			die "unsupported system"
208			;;
209	esac
210}
211
212test_attach_freebsd_9() {
213	[ ! -e LUN0 ] || die "$LUN0 already exists"
214	[ ! -e LUN1 ] || die "$LUN1 already exists"
215	[ ! -e LUN2 ] || die "$LUN2 already exists"
216	[ ! -e LUN3 ] || die "$LUN3 already exists"
217
218	cat > $TMPDIR/iscsi.conf << END
219
220target1 {
221	TargetName = $TARGET1
222	TargetAddress = $TARGETIP
223}
224
225target2 {
226	TargetName = $TARGET2
227	TargetAddress = $TARGETIP
228	AuthMethod = CHAP
229	chapIName = $USER
230	chapSecret = $SECRET
231}
232
233END
234	check iscontrol -c $TMPDIR/iscsi.conf -n target1
235	check iscontrol -c $TMPDIR/iscsi.conf -n target2
236
237	echo "Waiting 10 seconds for attach to complete."
238	sleep 10
239
240	[ -e $LUN0 ] || die "$LUN0 doesn't exist"
241	[ -e $LUN1 ] || die "$LUN1 doesn't exist"
242	[ -e $LUN2 ] || die "$LUN2 doesn't exist"
243	[ -e $LUN3 ] || die "$LUN3 doesn't exist"
244
245	rm $TMPDIR/iscsi.conf
246}
247
248test_attach_freebsd() {
249	[ ! -e LUN0 ] || die "$LUN0 already exists"
250	[ ! -e LUN1 ] || die "$LUN1 already exists"
251	[ ! -e LUN2 ] || die "$LUN2 already exists"
252	[ ! -e LUN3 ] || die "$LUN3 already exists"
253
254	cat > $TMPDIR/iscsi.conf << END
255
256target1 {
257	TargetName = $TARGET1
258	TargetAddress = $TARGETIP
259}
260
261target2 {
262	TargetName = $TARGET2
263	TargetAddress = $TARGETIP
264	AuthMethod = CHAP
265	chapIName = $USER
266	chapSecret = $SECRET
267}
268
269END
270	check iscsictl -Ac $TMPDIR/iscsi.conf -n target1
271	check iscsictl -Ac $TMPDIR/iscsi.conf -n target2
272
273	echo "Waiting 10 seconds for attach to complete."
274	sleep 10
275
276	[ -e $LUN0 ] || die "$LUN0 doesn't exist"
277	[ -e $LUN1 ] || die "$LUN1 doesn't exist"
278	[ -e $LUN2 ] || die "$LUN2 doesn't exist"
279	[ -e $LUN3 ] || die "$LUN3 doesn't exist"
280
281	rm $TMPDIR/iscsi.conf
282}
283
284test_attach_linux() {
285	check iscsiadm --mode node --targetname "$TARGET1"  -p "$TARGETIP:3260" --op=update --name node.session.auth.authmethod --value=None
286	check iscsiadm --mode node --targetname "$TARGET1"  -p "$TARGETIP:3260" --login
287	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --op=update --name node.session.auth.authmethod --value=CHAP
288	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --op=update --name node.session.auth.username --value="$USER"
289	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --op=update --name node.session.auth.password --value="$SECRET"
290	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --login
291}
292
293test_attach_solaris() {
294	# XXX: How to enter the CHAP secret from the script?  For now,
295	# just use the first target, and thus first two LUNs.
296	#check iscsiadm modify initiator-node --authentication CHAP
297	#check iscsiadm modify initiator-node --CHAP-name $USER
298	#check iscsiadm modify initiator-node --CHAP-secret $SECRET
299	iscsiadm add static-config $TARGET1,$TARGETIP
300	LUN0=`iscsiadm list target -S | awk '/OS Device Name/ { print $4 }' | sed -n 1p`
301	LUN1=`iscsiadm list target -S | awk '/OS Device Name/ { print $4 }' | sed -n 2p`
302	LUN0=`echo ${LUN0}2 | sed 's/rdsk/dsk/'`
303	LUN1=`echo ${LUN1}2 | sed 's/rdsk/dsk/'`
304	[ -n "$LUN0" -a -n "LUN1" ] || die "attach failed"
305	echo "Scratch disks: $LUN0, $LUN1"
306}
307
308test_attach() {
309	echo "*** attach test ***"
310	case `uname` in
311		FreeBSD)
312			case `uname -r` in
313				9*)
314					test_attach_freebsd_9
315					;;
316				*)
317					test_attach_freebsd
318					;;
319			esac
320			;;
321		Linux)
322			test_attach_linux
323			;;
324		SunOS)
325			test_attach_solaris
326			;;
327		*)
328			die "unsupported system"
329			;;
330	esac
331}
332
333test_newfs_freebsd_ufs() {
334	echo "*** UFS filesystem smoke test ***"
335	check newfs $LUN0
336	check newfs $LUN1
337	check newfs $LUN2
338	check newfs $LUN3
339	check fsck -t ufs $LUN0
340	check fsck -t ufs $LUN1
341	check fsck -t ufs $LUN2
342	check fsck -t ufs $LUN3
343}
344
345test_newfs_freebsd_zfs() {
346	echo "*** ZFS filesystem smoke test ***"
347	check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
348	check zpool destroy -f $ZFSPOOL
349}
350
351test_newfs_linux_ext4() {
352	echo "*** ext4 filesystem smoke test ***"
353	yes | check mkfs $LUN0
354	yes | check mkfs $LUN1
355	yes | check mkfs $LUN2
356	yes | check mkfs $LUN3
357	check fsck -f $LUN0
358	check fsck -f $LUN1
359	check fsck -f $LUN2
360	check fsck -f $LUN3
361}
362
363test_newfs_linux_btrfs() {
364	echo "*** btrfs filesystem smoke test ***"
365	check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
366}
367
368
369test_newfs_solaris_ufs() {
370	echo "*** UFS filesystem smoke test ***"
371	yes | check newfs $LUN0
372	yes | check newfs $LUN1
373	check fsck -F ufs $LUN0
374	check fsck -F ufs $LUN1
375}
376
377test_newfs_solaris_zfs() {
378	echo "*** ZFS filesystem smoke test ***"
379	check zpool create -f $ZFSPOOL $LUN0 $LUN1
380	check zpool destroy -f $ZFSPOOL
381}
382
383test_newfs() {
384	case `uname` in
385		FreeBSD)
386			test_newfs_freebsd_ufs
387			test_newfs_freebsd_zfs
388			;;
389		Linux)
390			test_newfs_linux_ext4
391			test_newfs_linux_btrfs
392			;;
393		SunOS)
394			test_newfs_solaris_ufs
395			test_newfs_solaris_zfs
396			;;
397		*)
398			die "unsupported system"
399			;;
400	esac
401}
402
403test_cp() {
404	echo "*** basic filesystem test ***"
405	case `uname` in
406		FreeBSD)
407			check newfs $LUN0
408			check mount -t ufs $LUN0 $MNTDIR
409			check dd if=/dev/urandom of=$MNTDIR/1 bs=1m count=500
410			check cp $MNTDIR/1 $MNTDIR/2
411			check umount $MNTDIR
412			check fsck -t ufs $LUN0
413			check mount -t ufs $LUN0 $MNTDIR
414			check cmp $MNTDIR/1 $MNTDIR/2
415			check umount $MNTDIR
416
417			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
418			check dd if=/dev/urandom of=/$ZFSPOOL/1 bs=1m count=500
419			check zpool scrub $ZFSPOOL
420			check cp /$ZFSPOOL/1 /$ZFSPOOL/2
421			check cmp /$ZFSPOOL/1 /$ZFSPOOL/2
422			check zpool destroy -f $ZFSPOOL
423			;;
424		Linux)
425			yes | check mkfs $LUN0
426			check mount $LUN0 $MNTDIR
427			check dd if=/dev/urandom of=$MNTDIR/1 bs=1M count=500
428			check cp $MNTDIR/1 $MNTDIR/2
429			check umount $MNTDIR
430			check fsck -f $LUN0
431			check mount $LUN0 $MNTDIR
432			check cmp $MNTDIR/1 $MNTDIR/2
433			check umount $MNTDIR
434
435			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
436			check mount $LUN0 $MNTDIR
437			check dd if=/dev/urandom of=$MNTDIR/1 bs=1M count=500
438			check cp $MNTDIR/1 $MNTDIR/2
439			check umount $MNTDIR
440			check mount $LUN0 $MNTDIR
441			check cmp $MNTDIR/1 $MNTDIR/2
442			check umount $MNTDIR
443			;;
444		SunOS)
445			yes | check newfs $LUN0
446			check mount -F ufs $LUN0 $MNTDIR
447			check dd if=/dev/urandom of=$MNTDIR/1 bs=1024k count=500
448			check cp $MNTDIR/1 $MNTDIR/2
449			check umount $MNTDIR
450			check fsck -yF ufs $LUN0
451			check mount -F ufs $LUN0 $MNTDIR
452			check cmp $MNTDIR/1 $MNTDIR/2
453			check umount $MNTDIR
454
455			check zpool create -f $ZFSPOOL $LUN0 $LUN1
456			check dd if=/dev/urandom of=/$ZFSPOOL/1 bs=1024k count=500
457			check zpool scrub $ZFSPOOL
458			check cp /$ZFSPOOL/1 /$ZFSPOOL/2
459			check cmp /$ZFSPOOL/1 /$ZFSPOOL/2
460			check zpool destroy -f $ZFSPOOL
461			;;
462		*)
463			die "unsupported system"
464			;;
465	esac
466}
467
468test_bonnie() {
469	echo "*** bonnie++ ***"
470	case `uname` in
471		FreeBSD)
472			check newfs $LUN0
473			check mount -t ufs $LUN0 $MNTDIR
474			check cd $MNTDIR
475			check bonnie++ -u root -s 2g -r 1g -n0
476			check bonnie++ -u root -s 0
477			check cd -
478			check umount $MNTDIR
479			check fsck -t ufs $LUN0
480
481			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
482			check cd /$ZFSPOOL
483			check bonnie++ -u root -s 2g -r 1g -n0
484			check bonnie++ -u root -s 0
485			check cd -
486			check zpool destroy -f $ZFSPOOL
487			;;
488		Linux)
489			yes | check mkfs $LUN0
490			check mount $LUN0 $MNTDIR
491			check cd $MNTDIR
492			check bonnie++ -u root -s 2g -r 1g -n0
493			check bonnie++ -u root -s 0
494			check cd -
495			check umount $MNTDIR
496			check fsck -f $LUN0
497
498			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
499			check mount $LUN0 $MNTDIR
500			check cd $MNTDIR
501			check bonnie++ -u root -s 2g -r 1g -n0
502			check bonnie++ -u root -s 0
503			check cd -
504			check umount $MNTDIR
505			;;
506		SunOS)
507			yes | check newfs $LUN0
508			check mount -F ufs $LUN0 $MNTDIR
509			check cd $MNTDIR
510			check bonnie++ -u root -s 2g -r 1g -n0
511			check bonnie++ -u root -s 0
512			check cd -
513			check umount $MNTDIR
514			check fsck -yF ufs $LUN0
515
516			check zpool create -f $ZFSPOOL $LUN0 $LUN1
517			check cd /$ZFSPOOL
518			check bonnie++ -u root -s 2g -r 1g -n0
519			check bonnie++ -u root -s 0
520			check cd -
521			check zpool destroy -f $ZFSPOOL
522			;;
523		*)
524			die "unsupported system"
525			;;
526	esac
527}
528
529test_iozone() {
530	echo "*** iozone ***"
531	case `uname` in
532		FreeBSD)
533			check newfs $LUN0
534			check mount -t ufs $LUN0 $MNTDIR
535			check cd $MNTDIR
536			check iozone -a
537			check cd -
538			check umount $MNTDIR
539			check fsck -t ufs $LUN0
540
541			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
542			check cd /$ZFSPOOL
543			check iozone -a
544			check cd -
545			check zpool destroy -f $ZFSPOOL
546			;;
547		Linux)
548			yes | check mkfs $LUN0
549			check mount $LUN0 $MNTDIR
550			check cd $MNTDIR
551			check iozone -a
552			check cd -
553			check umount $MNTDIR
554			check fsck -f $LUN0
555
556			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
557			check mount $LUN0 $MNTDIR
558			check cd $MNTDIR
559			check iozone -a
560			check cd -
561			check umount $MNTDIR
562			;;
563		SunOS)
564			yes | check newfs $LUN0
565			check mount -F ufs $LUN0 $MNTDIR
566			check cd $MNTDIR
567			check iozone -a
568			check cd -
569			check umount $MNTDIR
570			check fsck -yF ufs $LUN0
571
572			check zpool create -f $ZFSPOOL $LUN0 $LUN1
573			check cd /$ZFSPOOL
574			check iozone -a
575			check cd -
576			check zpool destroy -f $ZFSPOOL
577			;;
578		*)
579			die "unsupported system"
580			;;
581	esac
582
583}
584
585test_postmark() {
586	echo "*** postmark ***"
587	case `uname` in
588		FreeBSD)
589			check newfs $LUN0
590			check mount -t ufs $LUN0 $MNTDIR
591			check cd $MNTDIR
592			printf "set number 10000\nrun\n" | check postmark
593			check cd -
594			check umount $MNTDIR
595			check fsck -t ufs $LUN0
596
597			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
598			check cd /$ZFSPOOL
599			printf "set number 10000\nrun\n" | check postmark
600			check cd -
601			check zpool destroy -f $ZFSPOOL
602			;;
603		Linux)
604			yes | check mkfs $LUN0
605			check mount $LUN0 $MNTDIR
606			check cd $MNTDIR
607			printf "set number 10000\nrun\n" | check postmark
608			check cd -
609			check umount $MNTDIR
610			check fsck -f $LUN0
611
612			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
613			check mount $LUN0 $MNTDIR
614			check cd $MNTDIR
615			printf "set number 10000\nrun\n" | check postmark
616			check cd -
617			check umount $MNTDIR
618			;;
619		SunOS)
620			yes | check newfs $LUN0
621			check mount -F ufs $LUN0 $MNTDIR
622			check cd $MNTDIR
623			printf "set number 10000\nrun\n" | check postmark
624			check cd -
625			check umount $MNTDIR
626			check fsck -yF ufs $LUN0
627
628			check zpool create -f $ZFSPOOL $LUN0 $LUN1
629			check cd /$ZFSPOOL
630			printf "set number 10000\nrun\n" | check postmark
631			check cd -
632			check zpool destroy -f $ZFSPOOL
633			;;
634		*)
635			die "unsupported system"
636			;;
637	esac
638}
639
640test_postgresql_freebsd() {
641	check newfs $LUN0
642	check mount -t ufs $LUN0 $MNTDIR
643	check chown pgsql $MNTDIR
644	check chmod 755 $MNTDIR
645	check cd /
646	# XXX: How to make 'check' work here?
647	su -m pgsql -c "initdb -D $MNTDIR/db"
648	su -m pgsql -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
649	check sleep 10
650	su -m pgsql -c "pgbench -i postgres"
651	su -m pgsql -c "pgbench -t 10000 postgres"
652	su -m pgsql -c "pg_ctl -D $MNTDIR/db stop"
653	check cd -
654	check umount $MNTDIR
655	check fsck -t ufs $LUN0
656
657	check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
658	check chown pgsql /$ZFSPOOL
659	check chmod 755 /$ZFSPOOL
660	check cd /
661	# XXX: How to make 'check' work here?
662	su -m pgsql -c "initdb -D /$ZFSPOOL/db"
663	su -m pgsql -c "pg_ctl -D /$ZFSPOOL/db -l /tmp/log start"
664	check sleep 10
665	su -m pgsql -c "pgbench -i postgres"
666	su -m pgsql -c "pgbench -t 10000 postgres"
667	su -m pgsql -c "pg_ctl -D /$ZFSPOOL/db stop"
668	check cd -
669	check zpool destroy -f $ZFSPOOL
670}
671
672test_postgresql_linux() {
673	yes | check mkfs $LUN0
674	check mount $LUN0 $MNTDIR
675	check chown postgres $MNTDIR
676	check chmod 755 $MNTDIR
677	check cd /
678	# XXX: How to make 'check' work here?
679	su -m postgres -c "initdb -D $MNTDIR/db"
680	su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
681	check sleep 5
682	su -m postgres -c "pgbench -i"
683	su -m postgres -c "pgbench -t 10000"
684	su -m postgres -c "pg_ctl -D $MNTDIR/db stop"
685	check cd -
686	check umount $MNTDIR
687	check fsck -f $LUN0
688
689	check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
690	check mount $LUN0 $MNTDIR
691	check chown postgres $MNTDIR
692	check chmod 755 $MNTDIR
693	check cd /
694	su -m postgres -c "initdb -D $MNTDIR/db"
695	su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
696	check sleep 5
697	su -m postgres -c "pgbench -i"
698	su -m postgres -c "pgbench -t 10000"
699	su -m postgres -c "pg_ctl -D $MNTDIR/db stop"
700	check cd -
701	check umount $MNTDIR
702}
703
704test_postgresql_solaris() {
705	PATH="$PATH:/usr/postgres/9.2-pgdg/bin" export PATH
706	yes | check newfs $LUN0
707	check mount -F ufs $LUN0 $MNTDIR
708	check chown postgres $MNTDIR
709	check chmod 755 $MNTDIR
710	check cd /
711	# XXX: How to make 'check' work here?
712	su postgres -c "initdb -D $MNTDIR/db"
713	su postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
714	check sleep 10
715	su postgres -c "pgbench -i postgres"
716	su postgres -c "pgbench -t 10000 postgres"
717	su postgres -c "pg_ctl -D $MNTDIR/db stop"
718	check cd -
719	check umount $MNTDIR
720	check fsck -yF ufs $LUN0
721
722	check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
723	check chown postgres /$ZFSPOOL
724	check chmod 755 /$ZFSPOOL
725	check cd /
726	# XXX: How to make 'check' work here?
727	su postgres -c "initdb -D /$ZFSPOOL/db"
728	su postgres -c "pg_ctl -D /$ZFSPOOL/db -l /tmp/log start"
729	check sleep 10
730	su postgres -c "pgbench -i postgres"
731	su postgres -c "pgbench -t 10000 postgres"
732	su postgres -c "pg_ctl -D /$ZFSPOOL/db stop"
733	check cd -
734	check zpool destroy -f $ZFSPOOL
735}
736
737test_postgresql() {
738	echo "*** postgresql ***"
739	case `uname` in
740		FreeBSD)
741			test_postgresql_freebsd
742			;;
743		Linux)
744			test_postgresql_linux
745			;;
746		SunOS)
747			test_postgresql_solaris
748			;;
749		*)
750			die "unsupported system"
751			;;
752	esac
753}
754
755test_detach() {
756	echo "*** detach ***"
757	case `uname` in
758		FreeBSD)
759			case `uname -r` in
760				9*)
761					echo "*** detaching not supported on FreeBSD 9 ***"
762					echo "*** please reboot the initiator VM before trying to run this script again ***"
763					;;
764				*)
765					check iscsictl -Ra
766					;;
767			esac
768			;;
769		Linux)
770			check iscsiadm -m node --logout
771			;;
772		SunOS)
773			check iscsiadm remove static-config $TARGET1,$TARGETIP
774			;;
775		*)
776			die "unsupported system"
777			;;
778	esac
779}
780
781banner
782test_discovery
783test_attach
784test_newfs
785test_cp
786test_bonnie
787test_iozone
788test_postmark
789test_postgresql
790test_detach
791
792echo "*** done ***"
793
794