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