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
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:
40 # chap user secretsecret
45 # discovery-auth-group no-authentication
48 # target iqn.2012-06.com.example:1 {
49 # auth-group no-authentication
52 # path /var/tmp/example_t1l0
56 # path /var/tmp/example_t1l1
61 # target iqn.2012-06.com.example:2 {
65 # path /var/tmp/example_t2l0
69 # path /var/tmp/example_t2l1
74 # Remember to create the backing files (/var/tmp/example_t1l0 etcc)
76 # On the initiator, $MNTDIR will be used for testing.
79 TARGETIP=192.168.56.101
80 TARGET1=iqn.2012-06.com.example:1
81 TARGET2=iqn.2012-06.com.example:2
107 # LUN names are being set later, during attach.
111 die "unsupported system"
116 echo "# $@" > /dev/stderr
117 $@ || die "$@ failed"
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."
126 echo "scratch disks unknown at this stage."
129 echo "This script is NOT safe to run on multiuser system."
131 echo "Press ^C to interrupt; will proceed in 5 seconds."
135 test_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
145 test_discovery_freebsd() {
146 /etc/rc.d/iscsid onestart
147 check iscsictl -Ad $TARGETIP
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
157 test_discovery_linux() {
158 cat > /etc/iscsi/iscsid.conf << END
160 discovery.sendtargets.auth.authmethod = None
161 node.startup = manual
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
174 test_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
188 echo "*** discovery test ***"
193 test_discovery_freebsd_9
196 test_discovery_freebsd
204 test_discovery_solaris
207 die "unsupported system"
212 test_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"
218 cat > $TMPDIR/iscsi.conf << END
221 TargetName = $TARGET1
222 TargetAddress = $TARGETIP
226 TargetName = $TARGET2
227 TargetAddress = $TARGETIP
234 check iscontrol -c $TMPDIR/iscsi.conf -n target1
235 check iscontrol -c $TMPDIR/iscsi.conf -n target2
237 echo "Waiting 10 seconds for attach to complete."
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"
245 rm $TMPDIR/iscsi.conf
248 test_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"
254 cat > $TMPDIR/iscsi.conf << END
257 TargetName = $TARGET1
258 TargetAddress = $TARGETIP
262 TargetName = $TARGET2
263 TargetAddress = $TARGETIP
270 check iscsictl -Ac $TMPDIR/iscsi.conf -n target1
271 check iscsictl -Ac $TMPDIR/iscsi.conf -n target2
273 echo "Waiting 10 seconds for attach to complete."
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"
281 rm $TMPDIR/iscsi.conf
284 test_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
293 test_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"
309 echo "*** attach test ***"
314 test_attach_freebsd_9
328 die "unsupported system"
333 test_newfs_freebsd_ufs() {
334 echo "*** UFS filesystem smoke test ***"
339 check fsck -t ufs $LUN0
340 check fsck -t ufs $LUN1
341 check fsck -t ufs $LUN2
342 check fsck -t ufs $LUN3
345 test_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
351 test_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
363 test_newfs_linux_btrfs() {
364 echo "*** btrfs filesystem smoke test ***"
365 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
369 test_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
377 test_newfs_solaris_zfs() {
378 echo "*** ZFS filesystem smoke test ***"
379 check zpool create -f $ZFSPOOL $LUN0 $LUN1
380 check zpool destroy -f $ZFSPOOL
386 test_newfs_freebsd_ufs
387 test_newfs_freebsd_zfs
390 test_newfs_linux_ext4
391 test_newfs_linux_btrfs
394 test_newfs_solaris_ufs
395 test_newfs_solaris_zfs
398 die "unsupported system"
404 echo "*** basic filesystem test ***"
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
412 check fsck -t ufs $LUN0
413 check mount -t ufs $LUN0 $MNTDIR
414 check cmp $MNTDIR/1 $MNTDIR/2
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
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
431 check mount $LUN0 $MNTDIR
432 check cmp $MNTDIR/1 $MNTDIR/2
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
440 check mount $LUN0 $MNTDIR
441 check cmp $MNTDIR/1 $MNTDIR/2
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
450 check fsck -yF ufs $LUN0
451 check mount -F ufs $LUN0 $MNTDIR
452 check cmp $MNTDIR/1 $MNTDIR/2
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
463 die "unsupported system"
469 echo "*** bonnie++ ***"
473 check mount -t ufs $LUN0 $MNTDIR
475 check bonnie++ -u root -s 2g -r 1g -n0
476 check bonnie++ -u root -s 0
479 check fsck -t ufs $LUN0
481 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
483 check bonnie++ -u root -s 2g -r 1g -n0
484 check bonnie++ -u root -s 0
486 check zpool destroy -f $ZFSPOOL
489 yes | check mkfs $LUN0
490 check mount $LUN0 $MNTDIR
492 check bonnie++ -u root -s 2g -r 1g -n0
493 check bonnie++ -u root -s 0
498 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
499 check mount $LUN0 $MNTDIR
501 check bonnie++ -u root -s 2g -r 1g -n0
502 check bonnie++ -u root -s 0
507 yes | check newfs $LUN0
508 check mount -F ufs $LUN0 $MNTDIR
510 check bonnie++ -u root -s 2g -r 1g -n0
511 check bonnie++ -u root -s 0
514 check fsck -yF ufs $LUN0
516 check zpool create -f $ZFSPOOL $LUN0 $LUN1
518 check bonnie++ -u root -s 2g -r 1g -n0
519 check bonnie++ -u root -s 0
521 check zpool destroy -f $ZFSPOOL
524 die "unsupported system"
530 echo "*** iozone ***"
534 check mount -t ufs $LUN0 $MNTDIR
539 check fsck -t ufs $LUN0
541 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
545 check zpool destroy -f $ZFSPOOL
548 yes | check mkfs $LUN0
549 check mount $LUN0 $MNTDIR
556 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
557 check mount $LUN0 $MNTDIR
564 yes | check newfs $LUN0
565 check mount -F ufs $LUN0 $MNTDIR
570 check fsck -yF ufs $LUN0
572 check zpool create -f $ZFSPOOL $LUN0 $LUN1
576 check zpool destroy -f $ZFSPOOL
579 die "unsupported system"
586 echo "*** postmark ***"
590 check mount -t ufs $LUN0 $MNTDIR
592 printf "set number 10000\nrun\n" | check postmark
595 check fsck -t ufs $LUN0
597 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
599 printf "set number 10000\nrun\n" | check postmark
601 check zpool destroy -f $ZFSPOOL
604 yes | check mkfs $LUN0
605 check mount $LUN0 $MNTDIR
607 printf "set number 10000\nrun\n" | check postmark
612 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
613 check mount $LUN0 $MNTDIR
615 printf "set number 10000\nrun\n" | check postmark
620 yes | check newfs $LUN0
621 check mount -F ufs $LUN0 $MNTDIR
623 printf "set number 10000\nrun\n" | check postmark
626 check fsck -yF ufs $LUN0
628 check zpool create -f $ZFSPOOL $LUN0 $LUN1
630 printf "set number 10000\nrun\n" | check postmark
632 check zpool destroy -f $ZFSPOOL
635 die "unsupported system"
640 test_postgresql_freebsd() {
642 check mount -t ufs $LUN0 $MNTDIR
643 check chown pgsql $MNTDIR
644 check chmod 755 $MNTDIR
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"
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"
655 check fsck -t ufs $LUN0
657 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
658 check chown pgsql /$ZFSPOOL
659 check chmod 755 /$ZFSPOOL
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"
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"
669 check zpool destroy -f $ZFSPOOL
672 test_postgresql_linux() {
673 yes | check mkfs $LUN0
674 check mount $LUN0 $MNTDIR
675 check chown postgres $MNTDIR
676 check chmod 755 $MNTDIR
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"
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"
689 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
690 check mount $LUN0 $MNTDIR
691 check chown postgres $MNTDIR
692 check chmod 755 $MNTDIR
694 su -m postgres -c "initdb -D $MNTDIR/db"
695 su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
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"
704 test_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
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"
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"
720 check fsck -yF ufs $LUN0
722 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
723 check chown postgres /$ZFSPOOL
724 check chmod 755 /$ZFSPOOL
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"
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"
734 check zpool destroy -f $ZFSPOOL
738 echo "*** postgresql ***"
741 test_postgresql_freebsd
744 test_postgresql_linux
747 test_postgresql_solaris
750 die "unsupported system"
756 echo "*** detach ***"
761 echo "*** detaching not supported on FreeBSD 9 ***"
762 echo "*** please reboot the initiator VM before trying to run this script again ***"
770 check iscsiadm -m node --logout
773 check iscsiadm remove static-config $TARGET1,$TARGETIP
776 die "unsupported system"