3 # Copyright (c) 2012 The FreeBSD Foundation
6 # This software was developed by Edward Tomasz Napierala under sponsorship
7 # from the FreeBSD Foundation.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
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.
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
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:
41 # chap user secretsecret
46 # discovery-auth-group no-authentication
49 # target iqn.2012-06.com.example:1 {
50 # auth-group no-authentication
53 # path /var/tmp/example_t1l0
57 # path /var/tmp/example_t1l1
62 # target iqn.2012-06.com.example:2 {
66 # path /var/tmp/example_t2l0
70 # path /var/tmp/example_t2l1
75 # Remember to create the backing files (/var/tmp/example_t1l0 etcc)
77 # On the initiator, $MNTDIR will be used for testing.
80 TARGETIP=192.168.56.101
81 TARGET1=iqn.2012-06.com.example:1
82 TARGET2=iqn.2012-06.com.example:2
108 # LUN names are being set later, during attach.
112 die "unsupported system"
117 echo "# $@" > /dev/stderr
118 $@ || die "$@ failed"
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."
127 echo "scratch disks unknown at this stage."
130 echo "This script is NOT safe to run on multiuser system."
132 echo "Press ^C to interrupt; will proceed in 5 seconds."
136 test_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
146 test_discovery_freebsd() {
147 /etc/rc.d/iscsid onestart
148 check iscsictl -Ad $TARGETIP
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
158 test_discovery_linux() {
159 cat > /etc/iscsi/iscsid.conf << END
161 discovery.sendtargets.auth.authmethod = None
162 node.startup = manual
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
175 test_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
189 echo "*** discovery test ***"
194 test_discovery_freebsd_9
197 test_discovery_freebsd
205 test_discovery_solaris
208 die "unsupported system"
213 test_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"
219 cat > $TMPDIR/iscsi.conf << END
222 TargetName = $TARGET1
223 TargetAddress = $TARGETIP
227 TargetName = $TARGET2
228 TargetAddress = $TARGETIP
235 check iscontrol -c $TMPDIR/iscsi.conf -n target1
236 check iscontrol -c $TMPDIR/iscsi.conf -n target2
238 echo "Waiting 10 seconds for attach to complete."
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"
246 rm $TMPDIR/iscsi.conf
249 test_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"
255 cat > $TMPDIR/iscsi.conf << END
258 TargetName = $TARGET1
259 TargetAddress = $TARGETIP
263 TargetName = $TARGET2
264 TargetAddress = $TARGETIP
271 check iscsictl -Ac $TMPDIR/iscsi.conf -n target1
272 check iscsictl -Ac $TMPDIR/iscsi.conf -n target2
274 echo "Waiting 10 seconds for attach to complete."
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"
282 rm $TMPDIR/iscsi.conf
285 test_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
294 test_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"
310 echo "*** attach test ***"
315 test_attach_freebsd_9
329 die "unsupported system"
334 test_newfs_freebsd_ufs() {
335 echo "*** UFS filesystem smoke test ***"
340 check fsck -t ufs $LUN0
341 check fsck -t ufs $LUN1
342 check fsck -t ufs $LUN2
343 check fsck -t ufs $LUN3
346 test_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
352 test_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
364 test_newfs_linux_btrfs() {
365 echo "*** btrfs filesystem smoke test ***"
366 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
370 test_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
378 test_newfs_solaris_zfs() {
379 echo "*** ZFS filesystem smoke test ***"
380 check zpool create -f $ZFSPOOL $LUN0 $LUN1
381 check zpool destroy -f $ZFSPOOL
387 test_newfs_freebsd_ufs
388 test_newfs_freebsd_zfs
391 test_newfs_linux_ext4
392 test_newfs_linux_btrfs
395 test_newfs_solaris_ufs
396 test_newfs_solaris_zfs
399 die "unsupported system"
405 echo "*** basic filesystem test ***"
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
413 check fsck -t ufs $LUN0
414 check mount -t ufs $LUN0 $MNTDIR
415 check cmp $MNTDIR/1 $MNTDIR/2
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
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
432 check mount $LUN0 $MNTDIR
433 check cmp $MNTDIR/1 $MNTDIR/2
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
441 check mount $LUN0 $MNTDIR
442 check cmp $MNTDIR/1 $MNTDIR/2
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
451 check fsck -yF ufs $LUN0
452 check mount -F ufs $LUN0 $MNTDIR
453 check cmp $MNTDIR/1 $MNTDIR/2
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
464 die "unsupported system"
470 echo "*** bonnie++ ***"
474 check mount -t ufs $LUN0 $MNTDIR
476 check bonnie++ -u root -s 2g -r 1g -n0
477 check bonnie++ -u root -s 0
480 check fsck -t ufs $LUN0
482 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
484 check bonnie++ -u root -s 2g -r 1g -n0
485 check bonnie++ -u root -s 0
487 check zpool destroy -f $ZFSPOOL
490 yes | check mkfs $LUN0
491 check mount $LUN0 $MNTDIR
493 check bonnie++ -u root -s 2g -r 1g -n0
494 check bonnie++ -u root -s 0
499 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
500 check mount $LUN0 $MNTDIR
502 check bonnie++ -u root -s 2g -r 1g -n0
503 check bonnie++ -u root -s 0
508 yes | check newfs $LUN0
509 check mount -F ufs $LUN0 $MNTDIR
511 check bonnie++ -u root -s 2g -r 1g -n0
512 check bonnie++ -u root -s 0
515 check fsck -yF ufs $LUN0
517 check zpool create -f $ZFSPOOL $LUN0 $LUN1
519 check bonnie++ -u root -s 2g -r 1g -n0
520 check bonnie++ -u root -s 0
522 check zpool destroy -f $ZFSPOOL
525 die "unsupported system"
531 echo "*** iozone ***"
535 check mount -t ufs $LUN0 $MNTDIR
540 check fsck -t ufs $LUN0
542 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
546 check zpool destroy -f $ZFSPOOL
549 yes | check mkfs $LUN0
550 check mount $LUN0 $MNTDIR
557 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
558 check mount $LUN0 $MNTDIR
565 yes | check newfs $LUN0
566 check mount -F ufs $LUN0 $MNTDIR
571 check fsck -yF ufs $LUN0
573 check zpool create -f $ZFSPOOL $LUN0 $LUN1
577 check zpool destroy -f $ZFSPOOL
580 die "unsupported system"
587 echo "*** postmark ***"
591 check mount -t ufs $LUN0 $MNTDIR
593 printf "set number 10000\nrun\n" | check postmark
596 check fsck -t ufs $LUN0
598 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
600 printf "set number 10000\nrun\n" | check postmark
602 check zpool destroy -f $ZFSPOOL
605 yes | check mkfs $LUN0
606 check mount $LUN0 $MNTDIR
608 printf "set number 10000\nrun\n" | check postmark
613 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
614 check mount $LUN0 $MNTDIR
616 printf "set number 10000\nrun\n" | check postmark
621 yes | check newfs $LUN0
622 check mount -F ufs $LUN0 $MNTDIR
624 printf "set number 10000\nrun\n" | check postmark
627 check fsck -yF ufs $LUN0
629 check zpool create -f $ZFSPOOL $LUN0 $LUN1
631 printf "set number 10000\nrun\n" | check postmark
633 check zpool destroy -f $ZFSPOOL
636 die "unsupported system"
641 test_postgresql_freebsd() {
643 check mount -t ufs $LUN0 $MNTDIR
644 check chown pgsql $MNTDIR
645 check chmod 755 $MNTDIR
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"
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"
656 check fsck -t ufs $LUN0
658 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
659 check chown pgsql /$ZFSPOOL
660 check chmod 755 /$ZFSPOOL
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"
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"
670 check zpool destroy -f $ZFSPOOL
673 test_postgresql_linux() {
674 yes | check mkfs $LUN0
675 check mount $LUN0 $MNTDIR
676 check chown postgres $MNTDIR
677 check chmod 755 $MNTDIR
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"
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"
690 check mkfs.btrfs $LUN0 $LUN1 $LUN2 $LUN3
691 check mount $LUN0 $MNTDIR
692 check chown postgres $MNTDIR
693 check chmod 755 $MNTDIR
695 su -m postgres -c "initdb -D $MNTDIR/db"
696 su -m postgres -c "pg_ctl -D $MNTDIR/db -l /tmp/log start"
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"
705 test_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
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"
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"
721 check fsck -yF ufs $LUN0
723 check zpool create -f $ZFSPOOL $LUN0 $LUN1 $LUN2 $LUN3
724 check chown postgres /$ZFSPOOL
725 check chmod 755 /$ZFSPOOL
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"
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"
735 check zpool destroy -f $ZFSPOOL
739 echo "*** postgresql ***"
742 test_postgresql_freebsd
745 test_postgresql_linux
748 test_postgresql_solaris
751 die "unsupported system"
757 echo "*** detach ***"
762 echo "*** detaching not supported on FreeBSD 9 ***"
763 echo "*** please reboot the initiator VM before trying to run this script again ***"
771 check iscsiadm -m node --logout
774 check iscsiadm remove static-config $TARGET1,$TARGETIP
777 die "unsupported system"