summaryrefslogtreecommitdiffstats
path: root/tools/regression/iscsi/iscsi-test.sh
blob: 6a9ea23bb8c2c12a4d86f803d44cc31b94accfbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
#!/bin/sh
#
# Copyright (c) 2012 The FreeBSD Foundation
# All rights reserved.
#
# This software was developed by Edward Tomasz Napierala under sponsorship
# from the FreeBSD Foundation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#

#
# This expects that the iSCSI server being tested is at $TARGETIP and exports
# two targets: $TARGET1 and $TARGET2; the former requiring no authentication,
# and the latter using CHAP with user $USER and secret $SECRET.  Discovery
# must be permitted without authentication.  Each target must contain exactly
# two LUNs, 4GB each.  For example, ctl.conf(5) should look like this:
# 
# auth-group meh {
# 	chap user secretsecret
# }
# 
# portal-group meh {
# 	listen 0.0.0.0
# 	discovery-auth-group no-authentication
# }
# 
# target iqn.2012-06.com.example:1 {
# 	auth-group no-authentication
# 	portal-group meh
# 	lun 0 {
# 		path /var/tmp/example_t1l0
# 		size 4G
# 	}
# 	lun 1 {
# 		path /var/tmp/example_t1l1
# 		size 4G
# 	}
# }
# 
# target iqn.2012-06.com.example:2 {
# 	auth-group meh
# 	portal-group meh
# 	lun 0 {
# 		path /var/tmp/example_t2l0
# 		size 4G
# 	}
# 	lun 1 {
# 		path /var/tmp/example_t2l1
# 		size 4G
# 	}
# }
# 
# Remember to create the backing files (/var/tmp/example_t1l0 etcc)
#
# On the initiator, $MNTDIR will be used for testing.
#

TARGETIP=192.168.56.101
TARGET1=iqn.2012-06.com.example:1
TARGET2=iqn.2012-06.com.example:2
USER=user
SECRET=secretsecret
MNTDIR=/mnt
TMPDIR=/tmp

die() {
	echo "$*"
	exit 1
}

case `uname` in
	FreeBSD)
		LUN0=/dev/da0
		LUN1=/dev/da1
		LUN2=/dev/da2
		LUN3=/dev/da3
		ZFSPOOL=iscsipool
		;;
	Linux)
		LUN0=/dev/sdb
		LUN1=/dev/sdc
		LUN2=/dev/sdd
		LUN3=/dev/sde
		;;
	SunOS)
		# LUN names are being set later, during attach.
		ZFSPOOL=iscsipool
		;;
	*)
		die "unsupported system"
		;;
esac

check() {
	echo "# $@" > /dev/stderr
	$@ || die "$@ failed"
}

banner() {
	echo "Will try to attach to $TARGET1 and $TARGET2 on $TARGETIP,"
	echo "user $USER, secret $SECRET.  Will use mountpoint $MNTDIR, temporary dir $TMPDIR,"
	if [ -n "$LUN0" ]; then
		echo "scratch disks $LUN0, $LUN1, $LUN2, $LUN3."
	else
		echo "scratch disks unknown at this stage."
	fi
	echo
	echo "This script is NOT safe to run on multiuser system."
	echo
	echo "Press ^C to interrupt; will proceed in 5 seconds."
	sleep 5
}

test_discovery_freebsd_9() {
	kldload iscsi_initiator
	check iscontrol -dt $TARGETIP > $TMPDIR/discovered
	cat $TMPDIR/discovered
	echo "TargetName=$TARGET1" > $TMPDIR/expected
	echo "TargetName=$TARGET2" >> $TMPDIR/expected
	check cmp $TMPDIR/expected $TMPDIR/discovered
	rm -f $TMPDIR/expected $TMPDIR/discovered
}

test_discovery_freebsd() {
	/etc/rc.d/iscsid onestart
	check iscsictl -Ad $TARGETIP
	sleep 1
	iscsictl | awk '{ print $1 }' | sort > $TMPDIR/discovered
	printf "Target\n$TARGET1\n$TARGET2\n" | sort > $TMPDIR/expected
	check cmp $TMPDIR/expected $TMPDIR/discovered
	rm -f $TMPDIR/expected $TMPDIR/discovered
	check iscsictl -Ra
	sleep 1
}

test_discovery_linux() {
	cat > /etc/iscsi/iscsid.conf << END

discovery.sendtargets.auth.authmethod = None
node.startup = manual

END

	check iscsiadm  -m discovery -t sendtargets -p $TARGETIP > $TMPDIR/discovered
	cat $TMPDIR/discovered
	echo "$TARGETIP:3260,-1 $TARGET1" > $TMPDIR/expected
	echo "$TARGETIP:3260,-1 $TARGET2" >> $TMPDIR/expected
	check cmp $TMPDIR/expected $TMPDIR/discovered
	rm -f $TMPDIR/expected $TMPDIR/discovered

}

test_discovery_solaris() {
	check iscsiadm add discovery-address $TARGETIP
	check iscsiadm modify discovery --sendtargets enable
	check iscsiadm modify discovery --static enable
	check iscsiadm list target | awk '/^Target/ { print $2 }' | sort > $TMPDIR/discovered
	check iscsiadm remove discovery-address $TARGETIP
	cat $TMPDIR/discovered
	echo "$TARGET1" > $TMPDIR/expected
	echo "$TARGET2" >> $TMPDIR/expected
	check cmp $TMPDIR/expected $TMPDIR/discovered
	rm -f $TMPDIR/expected $TMPDIR/discovered
}

test_discovery() {
	echo "*** discovery test ***"
	case `uname` in
		FreeBSD)
			case `uname -r` in
				9*)
					test_discovery_freebsd_9
					;;
				*)
					test_discovery_freebsd
					;;
			esac
			;;
		Linux)
			test_discovery_linux
			;;
		SunOS)
			test_discovery_solaris
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_attach_freebsd_9() {
	[ ! -e LUN0 ] || die "$LUN0 already exists"
	[ ! -e LUN1 ] || die "$LUN1 already exists"
	[ ! -e LUN2 ] || die "$LUN2 already exists"
	[ ! -e LUN3 ] || die "$LUN3 already exists"

	cat > $TMPDIR/iscsi.conf << END

target1 {
	TargetName = $TARGET1
	TargetAddress = $TARGETIP
}

target2 {
	TargetName = $TARGET2
	TargetAddress = $TARGETIP
	AuthMethod = CHAP
	chapIName = $USER
	chapSecret = $SECRET
}

END
	check iscontrol -c $TMPDIR/iscsi.conf -n target1
	check iscontrol -c $TMPDIR/iscsi.conf -n target2

	echo "Waiting 10 seconds for attach to complete."
	sleep 10

	[ -e $LUN0 ] || die "$LUN0 doesn't exist"
	[ -e $LUN1 ] || die "$LUN1 doesn't exist"
	[ -e $LUN2 ] || die "$LUN2 doesn't exist"
	[ -e $LUN3 ] || die "$LUN3 doesn't exist"

	rm $TMPDIR/iscsi.conf
}

test_attach_freebsd() {
	[ ! -e LUN0 ] || die "$LUN0 already exists"
	[ ! -e LUN1 ] || die "$LUN1 already exists"
	[ ! -e LUN2 ] || die "$LUN2 already exists"
	[ ! -e LUN3 ] || die "$LUN3 already exists"

	cat > $TMPDIR/iscsi.conf << END

target1 {
	TargetName = $TARGET1
	TargetAddress = $TARGETIP
}

target2 {
	TargetName = $TARGET2
	TargetAddress = $TARGETIP
	AuthMethod = CHAP
	chapIName = $USER
	chapSecret = $SECRET
}

END
	check iscsictl -Ac $TMPDIR/iscsi.conf -n target1
	check iscsictl -Ac $TMPDIR/iscsi.conf -n target2

	echo "Waiting 10 seconds for attach to complete."
	sleep 10

	[ -e $LUN0 ] || die "$LUN0 doesn't exist"
	[ -e $LUN1 ] || die "$LUN1 doesn't exist"
	[ -e $LUN2 ] || die "$LUN2 doesn't exist"
	[ -e $LUN3 ] || die "$LUN3 doesn't exist"

	rm $TMPDIR/iscsi.conf
}

test_attach_linux() {
	check iscsiadm --mode node --targetname "$TARGET1"  -p "$TARGETIP:3260" --op=update --name node.session.auth.authmethod --value=None
	check iscsiadm --mode node --targetname "$TARGET1"  -p "$TARGETIP:3260" --login
	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --op=update --name node.session.auth.authmethod --value=CHAP
	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --op=update --name node.session.auth.username --value="$USER"
	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --op=update --name node.session.auth.password --value="$SECRET"
	check iscsiadm --mode node --targetname "$TARGET2"  -p "$TARGETIP:3260" --login
}

test_attach_solaris() {
	# XXX: How to enter the CHAP secret from the script?  For now,
	# just use the first target, and thus first two LUNs.
	#check iscsiadm modify initiator-node --authentication CHAP
	#check iscsiadm modify initiator-node --CHAP-name $USER
	#check iscsiadm modify initiator-node --CHAP-secret $SECRET
	iscsiadm add static-config $TARGET1,$TARGETIP
	LUN0=`iscsiadm list target -S | awk '/OS Device Name/ { print $4 }' | sed -n 1p`
	LUN1=`iscsiadm list target -S | awk '/OS Device Name/ { print $4 }' | sed -n 2p`
	LUN0=`echo ${LUN0}2 | sed 's/rdsk/dsk/'`
	LUN1=`echo ${LUN1}2 | sed 's/rdsk/dsk/'`
	[ -n "$LUN0" -a -n "LUN1" ] || die "attach failed"
	echo "Scratch disks: $LUN0, $LUN1"
}

test_attach() {
	echo "*** attach test ***"
	case `uname` in
		FreeBSD)
			case `uname -r` in
				9*)
					test_attach_freebsd_9
					;;
				*)
					test_attach_freebsd
					;;
			esac
			;;
		Linux)
			test_attach_linux
			;;
		SunOS)
			test_attach_solaris
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_newfs_freebsd_ufs() {
	echo "*** UFS filesystem smoke test ***"
	check newfs $LUN0
	check newfs $LUN1
	check newfs $LUN2
	check newfs $LUN3
	check fsck -t ufs $LUN0
	check fsck -t ufs $LUN1
	check fsck -t ufs $LUN2
	check fsck -t ufs $LUN3
}

test_newfs_freebsd_zfs() {
	echo "*** ZFS filesystem smoke test ***"
	check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
	check zpool destroy -f $ZFSPOOL
}

test_newfs_linux_ext4() {
	echo "*** ext4 filesystem smoke test ***"
	yes | check mkfs $LUN0
	yes | check mkfs $LUN1
	yes | check mkfs $LUN2
	yes | check mkfs $LUN3
	check fsck -f $LUN0
	check fsck -f $LUN1
	check fsck -f $LUN2
	check fsck -f $LUN3
}

test_newfs_linux_btrfs() {
	echo "*** btrfs filesystem smoke test ***"
	check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
}


test_newfs_solaris_ufs() {
	echo "*** UFS filesystem smoke test ***"
	yes | check newfs $LUN0
	yes | check newfs $LUN1
	check fsck -F ufs $LUN0
	check fsck -F ufs $LUN1
}

test_newfs_solaris_zfs() {
	echo "*** ZFS filesystem smoke test ***"
	check zpool create -f $ZFSPOOL $LUN0 $LUN1
	check zpool destroy -f $ZFSPOOL
}

test_newfs() {
	case `uname` in
		FreeBSD)
			test_newfs_freebsd_ufs
			test_newfs_freebsd_zfs
			;;
		Linux)
			test_newfs_linux_ext4
			test_newfs_linux_btrfs
			;;
		SunOS)
			test_newfs_solaris_ufs
			test_newfs_solaris_zfs
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_cp() {
	echo "*** basic filesystem test ***"
	case `uname` in
		FreeBSD)
			check newfs $LUN0
			check mount -t ufs $LUN0 $MNTDIR
			check dd if=/dev/urandom of=$MNTDIR/1 bs=1m count=500
			check cp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR
			check fsck -t ufs $LUN0
			check mount -t ufs $LUN0 $MNTDIR
			check cmp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR

			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
			check dd if=/dev/urandom of=/$ZFSPOOL/1 bs=1m count=500
			check zpool scrub $ZFSPOOL
			check cp /$ZFSPOOL/1 /$ZFSPOOL/2
			check cmp /$ZFSPOOL/1 /$ZFSPOOL/2
			check zpool destroy -f $ZFSPOOL
			;;
		Linux)
			yes | check mkfs $LUN0
			check mount $LUN0 $MNTDIR
			check dd if=/dev/urandom of=$MNTDIR/1 bs=1M count=500
			check cp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR
			check fsck -f $LUN0
			check mount $LUN0 $MNTDIR
			check cmp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR

			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
			check mount $LUN0 $MNTDIR
			check dd if=/dev/urandom of=$MNTDIR/1 bs=1M count=500
			check cp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR
			check mount $LUN0 $MNTDIR
			check cmp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR
			;;
		SunOS)
			yes | check newfs $LUN0
			check mount -F ufs $LUN0 $MNTDIR
			check dd if=/dev/urandom of=$MNTDIR/1 bs=1024k count=500
			check cp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR
			check fsck -yF ufs $LUN0
			check mount -F ufs $LUN0 $MNTDIR
			check cmp $MNTDIR/1 $MNTDIR/2
			check umount $MNTDIR

			check zpool create -f $ZFSPOOL $LUN0 $LUN1
			check dd if=/dev/urandom of=/$ZFSPOOL/1 bs=1024k count=500
			check zpool scrub $ZFSPOOL
			check cp /$ZFSPOOL/1 /$ZFSPOOL/2
			check cmp /$ZFSPOOL/1 /$ZFSPOOL/2
			check zpool destroy -f $ZFSPOOL
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_bonnie() {
	echo "*** bonnie++ ***"
	case `uname` in
		FreeBSD)
			check newfs $LUN0
			check mount -t ufs $LUN0 $MNTDIR
			check cd $MNTDIR
			check bonnie++ -u root -s 2g -r 1g -n0
			check bonnie++ -u root -s 0
			check cd -
			check umount $MNTDIR
			check fsck -t ufs $LUN0

			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
			check cd /$ZFSPOOL
			check bonnie++ -u root -s 2g -r 1g -n0
			check bonnie++ -u root -s 0
			check cd -
			check zpool destroy -f $ZFSPOOL
			;;
		Linux)
			yes | check mkfs $LUN0
			check mount $LUN0 $MNTDIR
			check cd $MNTDIR
			check bonnie++ -u root -s 2g -r 1g -n0
			check bonnie++ -u root -s 0
			check cd -
			check umount $MNTDIR
			check fsck -f $LUN0

			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
			check mount $LUN0 $MNTDIR
			check cd $MNTDIR
			check bonnie++ -u root -s 2g -r 1g -n0
			check bonnie++ -u root -s 0
			check cd -
			check umount $MNTDIR
			;;
		SunOS)
			yes | check newfs $LUN0
			check mount -F ufs $LUN0 $MNTDIR
			check cd $MNTDIR
			check bonnie++ -u root -s 2g -r 1g -n0
			check bonnie++ -u root -s 0
			check cd -
			check umount $MNTDIR
			check fsck -yF ufs $LUN0

			check zpool create -f $ZFSPOOL $LUN0 $LUN1
			check cd /$ZFSPOOL
			check bonnie++ -u root -s 2g -r 1g -n0
			check bonnie++ -u root -s 0
			check cd -
			check zpool destroy -f $ZFSPOOL
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_iozone() {
	echo "*** iozone ***"
	case `uname` in
		FreeBSD)
			check newfs $LUN0
			check mount -t ufs $LUN0 $MNTDIR
			check cd $MNTDIR
			check iozone -a
			check cd -
			check umount $MNTDIR
			check fsck -t ufs $LUN0

			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
			check cd /$ZFSPOOL
			check iozone -a
			check cd -
			check zpool destroy -f $ZFSPOOL
			;;
		Linux)
			yes | check mkfs $LUN0
			check mount $LUN0 $MNTDIR
			check cd $MNTDIR
			check iozone -a
			check cd -
			check umount $MNTDIR
			check fsck -f $LUN0

			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
			check mount $LUN0 $MNTDIR
			check cd $MNTDIR
			check iozone -a
			check cd -
			check umount $MNTDIR
			;;
		SunOS)
			yes | check newfs $LUN0
			check mount -F ufs $LUN0 $MNTDIR
			check cd $MNTDIR
			check iozone -a
			check cd -
			check umount $MNTDIR
			check fsck -yF ufs $LUN0

			check zpool create -f $ZFSPOOL $LUN0 $LUN1
			check cd /$ZFSPOOL
			check iozone -a
			check cd -
			check zpool destroy -f $ZFSPOOL
			;;
		*)
			die "unsupported system"
			;;
	esac

}

test_postmark() {
	echo "*** postmark ***"
	case `uname` in
		FreeBSD)
			check newfs $LUN0
			check mount -t ufs $LUN0 $MNTDIR
			check cd $MNTDIR
			printf "set number 10000\nrun\n" | check postmark
			check cd -
			check umount $MNTDIR
			check fsck -t ufs $LUN0

			check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
			check cd /$ZFSPOOL
			printf "set number 10000\nrun\n" | check postmark
			check cd -
			check zpool destroy -f $ZFSPOOL
			;;
		Linux)
			yes | check mkfs $LUN0
			check mount $LUN0 $MNTDIR
			check cd $MNTDIR
			printf "set number 10000\nrun\n" | check postmark
			check cd -
			check umount $MNTDIR
			check fsck -f $LUN0

			check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
			check mount $LUN0 $MNTDIR
			check cd $MNTDIR
			printf "set number 10000\nrun\n" | check postmark
			check cd -
			check umount $MNTDIR
			;;
		SunOS)
			yes | check newfs $LUN0
			check mount -F ufs $LUN0 $MNTDIR
			check cd $MNTDIR
			printf "set number 10000\nrun\n" | check postmark
			check cd -
			check umount $MNTDIR
			check fsck -yF ufs $LUN0

			check zpool create -f $ZFSPOOL $LUN0 $LUN1
			check cd /$ZFSPOOL
			printf "set number 10000\nrun\n" | check postmark
			check cd -
			check zpool destroy -f $ZFSPOOL
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_postgresql_freebsd() {
	check newfs $LUN0
	check mount -t ufs $LUN0 $MNTDIR
	check chown pgsql $MNTDIR
	check chmod 755 $MNTDIR
	check cd /
	# XXX: How to make 'check' work here?
	su -m pgsql -c "initdb -D $MNTDIR/db"
	su -m pgsql -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
	check sleep 10
	su -m pgsql -c "pgbench -i postgres"
	su -m pgsql -c "pgbench -t 10000 postgres"
	su -m pgsql -c "pg_ctl -D $MNTDIR/db stop"
	check cd -
	check umount $MNTDIR
	check fsck -t ufs $LUN0

	check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
	check chown pgsql /$ZFSPOOL
	check chmod 755 /$ZFSPOOL
	check cd /
	# XXX: How to make 'check' work here?
	su -m pgsql -c "initdb -D /$ZFSPOOL/db"
	su -m pgsql -c "pg_ctl -D /$ZFSPOOL/db -l /tmp/log start"
	check sleep 10
	su -m pgsql -c "pgbench -i postgres"
	su -m pgsql -c "pgbench -t 10000 postgres"
	su -m pgsql -c "pg_ctl -D /$ZFSPOOL/db stop"
	check cd -
	check zpool destroy -f $ZFSPOOL
}

test_postgresql_linux() {
	yes | check mkfs $LUN0
	check mount $LUN0 $MNTDIR
	check chown postgres $MNTDIR
	check chmod 755 $MNTDIR
	check cd /
	# XXX: How to make 'check' work here?
	su -m postgres -c "initdb -D $MNTDIR/db"
	su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
	check sleep 5
	su -m postgres -c "pgbench -i"
	su -m postgres -c "pgbench -t 10000"
	su -m postgres -c "pg_ctl -D $MNTDIR/db stop"
	check cd -
	check umount $MNTDIR
	check fsck -f $LUN0

	check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
	check mount $LUN0 $MNTDIR
	check chown postgres $MNTDIR
	check chmod 755 $MNTDIR
	check cd /
	su -m postgres -c "initdb -D $MNTDIR/db"
	su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
	check sleep 5
	su -m postgres -c "pgbench -i"
	su -m postgres -c "pgbench -t 10000"
	su -m postgres -c "pg_ctl -D $MNTDIR/db stop"
	check cd -
	check umount $MNTDIR
}

test_postgresql_solaris() {
	PATH="$PATH:/usr/postgres/9.2-pgdg/bin" export PATH
	yes | check newfs $LUN0
	check mount -F ufs $LUN0 $MNTDIR
	check chown postgres $MNTDIR
	check chmod 755 $MNTDIR
	check cd /
	# XXX: How to make 'check' work here?
	su postgres -c "initdb -D $MNTDIR/db"
	su postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
	check sleep 10
	su postgres -c "pgbench -i postgres"
	su postgres -c "pgbench -t 10000 postgres"
	su postgres -c "pg_ctl -D $MNTDIR/db stop"
	check cd -
	check umount $MNTDIR
	check fsck -yF ufs $LUN0

	check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
	check chown postgres /$ZFSPOOL
	check chmod 755 /$ZFSPOOL
	check cd /
	# XXX: How to make 'check' work here?
	su postgres -c "initdb -D /$ZFSPOOL/db"
	su postgres -c "pg_ctl -D /$ZFSPOOL/db -l /tmp/log start"
	check sleep 10
	su postgres -c "pgbench -i postgres"
	su postgres -c "pgbench -t 10000 postgres"
	su postgres -c "pg_ctl -D /$ZFSPOOL/db stop"
	check cd -
	check zpool destroy -f $ZFSPOOL
}

test_postgresql() {
	echo "*** postgresql ***"
	case `uname` in
		FreeBSD)
			test_postgresql_freebsd
			;;
		Linux)
			test_postgresql_linux
			;;
		SunOS)
			test_postgresql_solaris
			;;
		*)
			die "unsupported system"
			;;
	esac
}

test_detach() {
	echo "*** detach ***"
	case `uname` in
		FreeBSD)
			case `uname -r` in
				9*)
					echo "*** detaching not supported on FreeBSD 9 ***"
					echo "*** please reboot the initiator VM before trying to run this script again ***"
					;;
				*)
					check iscsictl -Ra
					;;
			esac
			;;
		Linux)
			check iscsiadm -m node --logout
			;;
		SunOS)
			check iscsiadm remove static-config $TARGET1,$TARGETIP
			;;
		*)
			die "unsupported system"
			;;
	esac
}

banner
test_discovery
test_attach
test_newfs
test_cp
test_bonnie
test_iozone
test_postmark
test_postgresql
test_detach

echo "*** done ***"

OpenPOWER on IntegriCloud