3 # Copyright (c) 2012 The FreeBSD Foundation
5 # This software was developed by Edward Tomasz Napierala under sponsorship
6 # from the FreeBSD Foundation.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
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.
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
32 # This expects that the iSCSI server being tested is at $TARGETIP and exports
33 # two targets: $TARGET1 and $TARGET2; the former requiring no authentication,
34 # and the latter using CHAP with user $USER and secret $SECRET. Discovery
35 # must be permitted without authentication. Each target must contain exactly
36 # two LUNs, 4GB each. For example, ctl.conf(5) should look like this:
39 # chap user secretsecret
44 # discovery-auth-group no-authentication
47 # target iqn.2012-06.com.example:1 {
48 # auth-group no-authentication
51 # path /var/tmp/example_t1l0
55 # path /var/tmp/example_t1l1
60 # target iqn.2012-06.com.example:2 {
64 # path /var/tmp/example_t2l0
68 # path /var/tmp/example_t2l1
73 # Remember to create the backing files (/var/tmp/example_t1l0 etcc)
75 # On the initiator, $MNTDIR will be used for testing.
78 TARGETIP=192.168.56.101
79 TARGET1=iqn.2012-06.com.example:1
80 TARGET2=iqn.2012-06.com.example:2
106 # LUN names are being set later, during attach.
110 die "unsupported system"
115 echo "# $@" > /dev/stderr
116 $@ || die "$@ failed"
120 echo "Will try to attach to $TARGET1 and $TARGET2 on $TARGETIP,"
121 echo "user $USER, secret $SECRET. Will use mountpoint $MNTDIR, temporary dir $TMPDIR,"
122 if [ -n "$LUN0" ]; then
123 echo "scratch disks $LUN0, $LUN1, $LUN2, $LUN3."
125 echo "scratch disks unknown at this stage."
128 echo "This script is NOT safe to run on multiuser system."
130 echo "Press ^C to interrupt; will proceed in 5 seconds."
134 test_discovery_freebsd_9() {
135 kldload iscsi_initiator
136 check iscontrol -dt $TARGETIP > $TMPDIR/discovered
137 cat $TMPDIR/discovered
138 echo "TargetName=$TARGET1" > $TMPDIR/expected
139 echo "TargetName=$TARGET2" >> $TMPDIR/expected
140 check cmp $TMPDIR/expected $TMPDIR/discovered
141 rm -f $TMPDIR/expected $TMPDIR/discovered
144 test_discovery_freebsd() {
145 /etc/rc.d/iscsid onestart
146 check iscsictl -Ad $TARGETIP
148 iscsictl | awk '{ print $1 }' | sort > $TMPDIR/discovered
149 printf "Target\n$TARGET1\n$TARGET2\n" | sort > $TMPDIR/expected
150 check cmp $TMPDIR/expected $TMPDIR/discovered
151 rm -f $TMPDIR/expected $TMPDIR/discovered
156 test_discovery_linux() {
157 cat > /etc/iscsi/iscsid.conf << END
159 discovery.sendtargets.auth.authmethod = None
160 node.startup = manual
164 check iscsiadm -m discovery -t sendtargets -p $TARGETIP > $TMPDIR/discovered
165 cat $TMPDIR/discovered
166 echo "$TARGETIP:3260,-1 $TARGET1" > $TMPDIR/expected
167 echo "$TARGETIP:3260,-1 $TARGET2" >> $TMPDIR/expected
168 check cmp $TMPDIR/expected $TMPDIR/discovered
169 rm -f $TMPDIR/expected $TMPDIR/discovered
173 test_discovery_solaris() {
174 check iscsiadm add discovery-address $TARGETIP
175 check iscsiadm modify discovery --sendtargets enable
176 check iscsiadm modify discovery --static enable
177 check iscsiadm list target | awk '/^Target/ { print $2 }' | sort > $TMPDIR/discovered
178 check iscsiadm remove discovery-address $TARGETIP
179 cat $TMPDIR/discovered
180 echo "$TARGET1" > $TMPDIR/expected
181 echo "$TARGET2" >> $TMPDIR/expected
182 check cmp $TMPDIR/expected $TMPDIR/discovered
183 rm -f $TMPDIR/expected $TMPDIR/discovered
187 echo "*** discovery test ***"
192 test_discovery_freebsd_9
195 test_discovery_freebsd
203 test_discovery_solaris
206 die "unsupported system"
211 test_attach_freebsd_9() {
212 [ ! -e LUN0 ] || die "$LUN0 already exists"
213 [ ! -e LUN1 ] || die "$LUN1 already exists"
214 [ ! -e LUN2 ] || die "$LUN2 already exists"
215 [ ! -e LUN3 ] || die "$LUN3 already exists"
217 cat > $TMPDIR/iscsi.conf << END
220 TargetName = $TARGET1
221 TargetAddress = $TARGETIP
225 TargetName = $TARGET2
226 TargetAddress = $TARGETIP
233 check iscontrol -c $TMPDIR/iscsi.conf -n target1
234 check iscontrol -c $TMPDIR/iscsi.conf -n target2
236 echo "Waiting 10 seconds for attach to complete."
239 [ -e $LUN0 ] || die "$LUN0 doesn't exist"
240 [ -e $LUN1 ] || die "$LUN1 doesn't exist"
241 [ -e $LUN2 ] || die "$LUN2 doesn't exist"
242 [ -e $LUN3 ] || die "$LUN3 doesn't exist"
244 rm $TMPDIR/iscsi.conf
247 test_attach_freebsd() {
248 [ ! -e LUN0 ] || die "$LUN0 already exists"
249 [ ! -e LUN1 ] || die "$LUN1 already exists"
250 [ ! -e LUN2 ] || die "$LUN2 already exists"
251 [ ! -e LUN3 ] || die "$LUN3 already exists"
253 cat > $TMPDIR/iscsi.conf << END
256 TargetName = $TARGET1
257 TargetAddress = $TARGETIP
261 TargetName = $TARGET2
262 TargetAddress = $TARGETIP
269 check iscsictl -Ac $TMPDIR/iscsi.conf -n target1
270 check iscsictl -Ac $TMPDIR/iscsi.conf -n target2
272 echo "Waiting 10 seconds for attach to complete."
275 [ -e $LUN0 ] || die "$LUN0 doesn't exist"
276 [ -e $LUN1 ] || die "$LUN1 doesn't exist"
277 [ -e $LUN2 ] || die "$LUN2 doesn't exist"
278 [ -e $LUN3 ] || die "$LUN3 doesn't exist"
280 rm $TMPDIR/iscsi.conf
283 test_attach_linux() {
284 check iscsiadm --mode node --targetname "$TARGET1" -p "$TARGETIP:3260" --op=update --name node.session.auth.authmethod --value=None
285 check iscsiadm --mode node --targetname "$TARGET1" -p "$TARGETIP:3260" --login
286 check iscsiadm --mode node --targetname "$TARGET2" -p "$TARGETIP:3260" --op=update --name node.session.auth.authmethod --value=CHAP
287 check iscsiadm --mode node --targetname "$TARGET2" -p "$TARGETIP:3260" --op=update --name node.session.auth.username --value="$USER"
288 check iscsiadm --mode node --targetname "$TARGET2" -p "$TARGETIP:3260" --op=update --name node.session.auth.password --value="$SECRET"
289 check iscsiadm --mode node --targetname "$TARGET2" -p "$TARGETIP:3260" --login
292 test_attach_solaris() {
293 # XXX: How to enter the CHAP secret from the script? For now,
294 # just use the first target, and thus first two LUNs.
295 #check iscsiadm modify initiator-node --authentication CHAP
296 #check iscsiadm modify initiator-node --CHAP-name $USER
297 #check iscsiadm modify initiator-node --CHAP-secret $SECRET
298 iscsiadm add static-config $TARGET1,$TARGETIP
299 LUN0=`iscsiadm list target -S | awk '/OS Device Name/ { print $4 }' | sed -n 1p`
300 LUN1=`iscsiadm list target -S | awk '/OS Device Name/ { print $4 }' | sed -n 2p`
301 LUN0=`echo ${LUN0}2 | sed 's/rdsk/dsk/'`
302 LUN1=`echo ${LUN1}2 | sed 's/rdsk/dsk/'`
303 [ -n "$LUN0" -a -n "LUN1" ] || die "attach failed"
304 echo "Scratch disks: $LUN0, $LUN1"
308 echo "*** attach test ***"
313 test_attach_freebsd_9
327 die "unsupported system"
332 test_newfs_freebsd_ufs() {
333 echo "*** UFS filesystem smoke test ***"
338 check fsck -t ufs $LUN0
339 check fsck -t ufs $LUN1
340 check fsck -t ufs $LUN2
341 check fsck -t ufs $LUN3
344 test_newfs_freebsd_zfs() {
345 echo "*** ZFS filesystem smoke test ***"
346 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
347 check zpool destroy -f $ZFSPOOL
350 test_newfs_linux_ext4() {
351 echo "*** ext4 filesystem smoke test ***"
352 yes | check mkfs $LUN0
353 yes | check mkfs $LUN1
354 yes | check mkfs $LUN2
355 yes | check mkfs $LUN3
362 test_newfs_linux_btrfs() {
363 echo "*** btrfs filesystem smoke test ***"
364 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
368 test_newfs_solaris_ufs() {
369 echo "*** UFS filesystem smoke test ***"
370 yes | check newfs $LUN0
371 yes | check newfs $LUN1
372 check fsck -F ufs $LUN0
373 check fsck -F ufs $LUN1
376 test_newfs_solaris_zfs() {
377 echo "*** ZFS filesystem smoke test ***"
378 check zpool create -f $ZFSPOOL $LUN0 $LUN1
379 check zpool destroy -f $ZFSPOOL
385 test_newfs_freebsd_ufs
386 test_newfs_freebsd_zfs
389 test_newfs_linux_ext4
390 test_newfs_linux_btrfs
393 test_newfs_solaris_ufs
394 test_newfs_solaris_zfs
397 die "unsupported system"
403 echo "*** basic filesystem test ***"
407 check mount -t ufs $LUN0 $MNTDIR
408 check dd if=/dev/urandom of=$MNTDIR/1 bs=1m count=500
409 check cp $MNTDIR/1 $MNTDIR/2
411 check fsck -t ufs $LUN0
412 check mount -t ufs $LUN0 $MNTDIR
413 check cmp $MNTDIR/1 $MNTDIR/2
416 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
417 check dd if=/dev/urandom of=/$ZFSPOOL/1 bs=1m count=500
418 check zpool scrub $ZFSPOOL
419 check cp /$ZFSPOOL/1 /$ZFSPOOL/2
420 check cmp /$ZFSPOOL/1 /$ZFSPOOL/2
421 check zpool destroy -f $ZFSPOOL
424 yes | check mkfs $LUN0
425 check mount $LUN0 $MNTDIR
426 check dd if=/dev/urandom of=$MNTDIR/1 bs=1M count=500
427 check cp $MNTDIR/1 $MNTDIR/2
430 check mount $LUN0 $MNTDIR
431 check cmp $MNTDIR/1 $MNTDIR/2
434 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
435 check mount $LUN0 $MNTDIR
436 check dd if=/dev/urandom of=$MNTDIR/1 bs=1M count=500
437 check cp $MNTDIR/1 $MNTDIR/2
439 check mount $LUN0 $MNTDIR
440 check cmp $MNTDIR/1 $MNTDIR/2
444 yes | check newfs $LUN0
445 check mount -F ufs $LUN0 $MNTDIR
446 check dd if=/dev/urandom of=$MNTDIR/1 bs=1024k count=500
447 check cp $MNTDIR/1 $MNTDIR/2
449 check fsck -yF ufs $LUN0
450 check mount -F ufs $LUN0 $MNTDIR
451 check cmp $MNTDIR/1 $MNTDIR/2
454 check zpool create -f $ZFSPOOL $LUN0 $LUN1
455 check dd if=/dev/urandom of=/$ZFSPOOL/1 bs=1024k count=500
456 check zpool scrub $ZFSPOOL
457 check cp /$ZFSPOOL/1 /$ZFSPOOL/2
458 check cmp /$ZFSPOOL/1 /$ZFSPOOL/2
459 check zpool destroy -f $ZFSPOOL
462 die "unsupported system"
468 echo "*** bonnie++ ***"
472 check mount -t ufs $LUN0 $MNTDIR
474 check bonnie++ -u root -s 2g -r 1g -n0
475 check bonnie++ -u root -s 0
478 check fsck -t ufs $LUN0
480 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
482 check bonnie++ -u root -s 2g -r 1g -n0
483 check bonnie++ -u root -s 0
485 check zpool destroy -f $ZFSPOOL
488 yes | check mkfs $LUN0
489 check mount $LUN0 $MNTDIR
491 check bonnie++ -u root -s 2g -r 1g -n0
492 check bonnie++ -u root -s 0
497 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
498 check mount $LUN0 $MNTDIR
500 check bonnie++ -u root -s 2g -r 1g -n0
501 check bonnie++ -u root -s 0
506 yes | check newfs $LUN0
507 check mount -F ufs $LUN0 $MNTDIR
509 check bonnie++ -u root -s 2g -r 1g -n0
510 check bonnie++ -u root -s 0
513 check fsck -yF ufs $LUN0
515 check zpool create -f $ZFSPOOL $LUN0 $LUN1
517 check bonnie++ -u root -s 2g -r 1g -n0
518 check bonnie++ -u root -s 0
520 check zpool destroy -f $ZFSPOOL
523 die "unsupported system"
529 echo "*** iozone ***"
533 check mount -t ufs $LUN0 $MNTDIR
538 check fsck -t ufs $LUN0
540 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
544 check zpool destroy -f $ZFSPOOL
547 yes | check mkfs $LUN0
548 check mount $LUN0 $MNTDIR
555 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
556 check mount $LUN0 $MNTDIR
563 yes | check newfs $LUN0
564 check mount -F ufs $LUN0 $MNTDIR
569 check fsck -yF ufs $LUN0
571 check zpool create -f $ZFSPOOL $LUN0 $LUN1
575 check zpool destroy -f $ZFSPOOL
578 die "unsupported system"
585 echo "*** postmark ***"
589 check mount -t ufs $LUN0 $MNTDIR
591 printf "set number 10000\nrun\n" | check postmark
594 check fsck -t ufs $LUN0
596 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
598 printf "set number 10000\nrun\n" | check postmark
600 check zpool destroy -f $ZFSPOOL
603 yes | check mkfs $LUN0
604 check mount $LUN0 $MNTDIR
606 printf "set number 10000\nrun\n" | check postmark
611 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
612 check mount $LUN0 $MNTDIR
614 printf "set number 10000\nrun\n" | check postmark
619 yes | check newfs $LUN0
620 check mount -F ufs $LUN0 $MNTDIR
622 printf "set number 10000\nrun\n" | check postmark
625 check fsck -yF ufs $LUN0
627 check zpool create -f $ZFSPOOL $LUN0 $LUN1
629 printf "set number 10000\nrun\n" | check postmark
631 check zpool destroy -f $ZFSPOOL
634 die "unsupported system"
639 test_postgresql_freebsd() {
641 check mount -t ufs $LUN0 $MNTDIR
642 check chown pgsql $MNTDIR
643 check chmod 755 $MNTDIR
645 # XXX: How to make 'check' work here?
646 su -m pgsql -c "initdb -D $MNTDIR/db"
647 su -m pgsql -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
649 su -m pgsql -c "pgbench -i postgres"
650 su -m pgsql -c "pgbench -t 10000 postgres"
651 su -m pgsql -c "pg_ctl -D $MNTDIR/db stop"
654 check fsck -t ufs $LUN0
656 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
657 check chown pgsql /$ZFSPOOL
658 check chmod 755 /$ZFSPOOL
660 # XXX: How to make 'check' work here?
661 su -m pgsql -c "initdb -D /$ZFSPOOL/db"
662 su -m pgsql -c "pg_ctl -D /$ZFSPOOL/db -l /tmp/log start"
664 su -m pgsql -c "pgbench -i postgres"
665 su -m pgsql -c "pgbench -t 10000 postgres"
666 su -m pgsql -c "pg_ctl -D /$ZFSPOOL/db stop"
668 check zpool destroy -f $ZFSPOOL
671 test_postgresql_linux() {
672 yes | check mkfs $LUN0
673 check mount $LUN0 $MNTDIR
674 check chown postgres $MNTDIR
675 check chmod 755 $MNTDIR
677 # XXX: How to make 'check' work here?
678 su -m postgres -c "initdb -D $MNTDIR/db"
679 su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
681 su -m postgres -c "pgbench -i"
682 su -m postgres -c "pgbench -t 10000"
683 su -m postgres -c "pg_ctl -D $MNTDIR/db stop"
688 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
689 check mount $LUN0 $MNTDIR
690 check chown postgres $MNTDIR
691 check chmod 755 $MNTDIR
693 su -m postgres -c "initdb -D $MNTDIR/db"
694 su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
696 su -m postgres -c "pgbench -i"
697 su -m postgres -c "pgbench -t 10000"
698 su -m postgres -c "pg_ctl -D $MNTDIR/db stop"
703 test_postgresql_solaris() {
704 PATH="$PATH:/usr/postgres/9.2-pgdg/bin" export PATH
705 yes | check newfs $LUN0
706 check mount -F ufs $LUN0 $MNTDIR
707 check chown postgres $MNTDIR
708 check chmod 755 $MNTDIR
710 # XXX: How to make 'check' work here?
711 su postgres -c "initdb -D $MNTDIR/db"
712 su postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
714 su postgres -c "pgbench -i postgres"
715 su postgres -c "pgbench -t 10000 postgres"
716 su postgres -c "pg_ctl -D $MNTDIR/db stop"
719 check fsck -yF ufs $LUN0
721 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
722 check chown postgres /$ZFSPOOL
723 check chmod 755 /$ZFSPOOL
725 # XXX: How to make 'check' work here?
726 su postgres -c "initdb -D /$ZFSPOOL/db"
727 su postgres -c "pg_ctl -D /$ZFSPOOL/db -l /tmp/log start"
729 su postgres -c "pgbench -i postgres"
730 su postgres -c "pgbench -t 10000 postgres"
731 su postgres -c "pg_ctl -D /$ZFSPOOL/db stop"
733 check zpool destroy -f $ZFSPOOL
737 echo "*** postgresql ***"
740 test_postgresql_freebsd
743 test_postgresql_linux
746 test_postgresql_solaris
749 die "unsupported system"
755 echo "*** detach ***"
760 echo "*** detaching not supported on FreeBSD 9 ***"
761 echo "*** please reboot the initiator VM before trying to run this script again ***"
769 check iscsiadm -m node --logout
772 check iscsiadm remove static-config $TARGET1,$TARGETIP
775 die "unsupported system"