31c3011c733f6690f73248a6ff53bde2e54eebd9
[zfs.git] / scripts / zconfig.sh
1 #!/bin/bash
2 #
3 # ZFS/ZPOOL configuration test script.
4
5 basedir="$(dirname $0)"
6
7 SCRIPT_COMMON=common.sh
8 if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
9 . "${basedir}/${SCRIPT_COMMON}"
10 else
11 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
12 fi
13
14 PROG=zconfig.sh
15
16 usage() {
17 cat << EOF
18 USAGE:
19 $0 [hvc]
20
21 DESCRIPTION:
22         ZFS/ZPOOL configuration tests
23
24 OPTIONS:
25         -h      Show this message
26         -v      Verbose
27         -c      Cleanup lo+file devices at start
28
29 EOF
30 }
31
32 while getopts 'hvct:s:?' OPTION; do
33         case $OPTION in
34         h)
35                 usage
36                 exit 1
37                 ;;
38         v)
39                 VERBOSE=1
40                 ;;
41         c)
42                 CLEANUP=1
43                 ;;
44         t)
45                 TESTS_RUN=($OPTARG)
46                 ;;
47         s)
48                 TESTS_SKIP=($OPTARG)
49                 ;;
50         ?)
51                 usage
52                 exit
53                 ;;
54         esac
55 done
56
57 if [ $(id -u) != 0 ]; then
58         die "Must run as root"
59 fi
60
61 # Perform pre-cleanup is requested
62 if [ ${CLEANUP} ]; then
63         ${ZFS_SH} -u
64         cleanup_md_devices
65         cleanup_loop_devices
66         rm -f /tmp/zpool.cache.*
67 fi
68
69 # Check if we need to skip the tests that require scsi_debug and lsscsi.
70 SCSI_DEBUG=0
71 ${INFOMOD} scsi_debug &>/dev/null && SCSI_DEBUG=1
72 HAVE_LSSCSI=0
73 test -f ${LSSCSI} && HAVE_LSSCSI=1
74 if [ ${SCSI_DEBUG} -eq 0 ] || [ ${HAVE_LSSCSI} -eq 0 ]; then
75         echo "Skipping test 10 which requires the scsi_debug " \
76                 "module and the ${LSSCSI} utility"
77 fi
78
79 zconfig_partition() {
80         local DEVICE=$1
81         local START=$2
82         local END=$3
83         local TMP_FILE=`mktemp`
84
85         /sbin/sfdisk -q ${DEVICE} << EOF &>${TMP_FILE} || fail 4
86 ${START},${END}
87 ;
88 ;
89 ;
90 EOF
91
92         rm ${TMP_FILE}
93 }
94
95 # Validate persistent zpool.cache configuration.
96 test_1() {
97         local POOL_NAME=test1
98         local TMP_FILE1=`mktemp`
99         local TMP_FILE2=`mktemp`
100         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
101
102         # Create a pool save its status for comparison.
103         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
104         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
105         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
106
107         # Unload/load the module stack and verify the pool persists.
108         ${ZFS_SH} -u || fail 4
109         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 5
110         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 6
111         cmp ${TMP_FILE1} ${TMP_FILE2} || fail 7
112
113         # Cleanup the test pool and temporary files
114         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 8
115         rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_CACHE} || fail 9
116         ${ZFS_SH} -u || fail 10
117
118         pass
119 }
120 run_test 1 "persistent zpool.cache"
121
122 # Validate ZFS disk scanning and import w/out zpool.cache configuration.
123 test_2() {
124         local POOL_NAME=test2
125         local TMP_FILE1=`mktemp`
126         local TMP_FILE2=`mktemp`
127         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
128
129         # Create a pool save its status for comparison.
130         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
131         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
132         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
133
134         # Unload the module stack, remove the cache file, load the module
135         # stack and attempt to probe the disks to import the pool.  As
136         # a cross check verify the old pool state against the imported.
137         ${ZFS_SH} -u || fail 4
138         rm -f ${TMP_CACHE} || fail 5
139         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 6
140         ${ZPOOL} import | grep ${POOL_NAME} >/dev/null || fail 7
141         ${ZPOOL} import ${POOL_NAME} || fail 8
142         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 9
143         cmp ${TMP_FILE1} ${TMP_FILE2} || fail 10
144
145         # Cleanup the test pool and temporary files
146         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 11
147         rm -f ${TMP_FILE1} ${TMP_FILE2} || fail 12
148         ${ZFS_SH} -u || fail 13
149
150         pass
151 }
152 run_test 2 "scan disks for pools to import"
153
154 zconfig_zvol_device_stat() {
155         local EXPECT=$1
156         local POOL_NAME=/dev/$2
157         local ZVOL_NAME=/dev/$3
158         local SNAP_NAME=/dev/$4
159         local CLONE_NAME=/dev/$5
160         local COUNT=0
161
162         # Briefly delay for udev
163         sleep 3
164
165         # Pool exists
166         stat ${POOL_NAME} &>/dev/null   && let COUNT=$COUNT+1
167
168         # Volume and partitions
169         stat ${ZVOL_NAME}  &>/dev/null  && let COUNT=$COUNT+1
170         stat ${ZVOL_NAME}1 &>/dev/null  && let COUNT=$COUNT+1
171         stat ${ZVOL_NAME}2 &>/dev/null  && let COUNT=$COUNT+1
172
173         # Snapshot with partitions
174         stat ${SNAP_NAME}  &>/dev/null  && let COUNT=$COUNT+1
175         stat ${SNAP_NAME}1 &>/dev/null  && let COUNT=$COUNT+1
176         stat ${SNAP_NAME}2 &>/dev/null  && let COUNT=$COUNT+1
177
178         # Clone with partitions
179         stat ${CLONE_NAME}  &>/dev/null && let COUNT=$COUNT+1
180         stat ${CLONE_NAME}1 &>/dev/null && let COUNT=$COUNT+1
181         stat ${CLONE_NAME}2 &>/dev/null && let COUNT=$COUNT+1
182
183         if [ $EXPECT -ne $COUNT ]; then
184                 return 1
185         fi
186
187         return 0
188 }
189
190 # zpool import/export device check
191 # (1 volume, 2 partitions, 1 snapshot, 1 clone)
192 test_3() {
193         local POOL_NAME=tank
194         local ZVOL_NAME=volume
195         local SNAP_NAME=snap
196         local CLONE_NAME=clone
197         local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
198         local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
199         local FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
200         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
201
202         # Create a pool, volume, partition, snapshot, and clone.
203         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
204         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
205         ${ZFS} create -V 100M ${FULL_ZVOL_NAME} || fail 3
206         zconfig_partition /dev/${FULL_ZVOL_NAME} 0 64 || fail 4
207         ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 5
208         ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 6
209
210         # Verify the devices were created
211         zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
212             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 7
213
214         # Export the pool
215         ${ZPOOL} export ${POOL_NAME} || fail 8
216
217         # verify the devices were removed
218         zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
219             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
220
221         # Import the pool, wait 1 second for udev
222         ${ZPOOL} import ${POOL_NAME} || fail 10
223
224         # Verify the devices were created
225         zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
226             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 11
227
228         # Destroy the pool and consequently the devices
229         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 12
230
231         # verify the devices were removed
232         zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
233             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 13
234
235         ${ZFS_SH} -u || fail 14
236         rm -f ${TMP_CACHE} || fail 15
237
238         pass
239 }
240 run_test 3 "zpool import/export device"
241
242 # zpool insmod/rmmod device check (1 volume, 1 snapshot, 1 clone)
243 test_4() {
244         POOL_NAME=tank
245         ZVOL_NAME=volume
246         SNAP_NAME=snap
247         CLONE_NAME=clone
248         FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
249         FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
250         FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
251         TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
252
253         # Create a pool, volume, snapshot, and clone
254         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
255         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
256         ${ZFS} create -V 100M ${FULL_ZVOL_NAME} || fail 3
257         zconfig_partition /dev/${FULL_ZVOL_NAME} 0 64 || fail 4
258         ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 5
259         ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 6
260
261         # Verify the devices were created
262         zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
263             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 7
264
265         # Unload the modules
266         ${ZFS_SH} -u || fail 8
267
268         # Verify the devices were removed
269         zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
270             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
271
272         # Load the modules, wait 1 second for udev
273         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 10
274
275         # Verify the devices were created
276         zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
277             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 11
278
279         # Destroy the pool and consequently the devices
280         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 12
281
282         # Verify the devices were removed
283         zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
284             ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 13
285
286         ${ZFS_SH} -u || fail 14
287         rm -f ${TMP_CACHE} || fail 15
288
289         pass
290 }
291 run_test 4 "zpool insmod/rmmod device"
292
293 # ZVOL volume sanity check
294 test_5() {
295         local POOL_NAME=tank
296         local ZVOL_NAME=fish
297         local FULL_NAME=${POOL_NAME}/${ZVOL_NAME}
298         local SRC_DIR=/bin/
299         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
300
301         # Create a pool and volume.
302         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
303         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
304         ${ZFS} create -V 400M ${FULL_NAME} || fail 3
305
306         # Partition the volume, for a 400M volume there will be
307         # 812 cylinders, 16 heads, and 63 sectors per track.
308         zconfig_partition /dev/${FULL_NAME} 0 812
309
310         # Format the partition with ext3.
311         /sbin/mkfs.ext3 -q /dev/${FULL_NAME}1 || fail 5
312
313         # Mount the ext3 filesystem and copy some data to it.
314         mkdir -p /tmp/${ZVOL_NAME}1 || fail 6
315         mount /dev/${FULL_NAME}1 /tmp/${ZVOL_NAME}1 || fail 7
316         cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}1 || fail 8
317         sync
318
319         # Verify the copied files match the original files.
320         diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}1${SRC_DIR} &>/dev/null || fail 9
321
322         # Remove the files, umount, destroy the volume and pool.
323         rm -Rf /tmp/${ZVOL_NAME}1${SRC_DIR}* || fail 10
324         umount /tmp/${ZVOL_NAME}1 || fail 11
325         rmdir /tmp/${ZVOL_NAME}1 || fail 12
326
327         ${ZFS} destroy ${FULL_NAME} || fail 13
328         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 14
329         ${ZFS_SH} -u || fail 15
330         rm -f ${TMP_CACHE} || fail 16
331
332         pass
333 }
334 run_test 5 "zvol+ext3 volume"
335
336 # ZVOL snapshot sanity check
337 test_6() {
338         local POOL_NAME=tank
339         local ZVOL_NAME=fish
340         local SNAP_NAME=pristine
341         local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
342         local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
343         local SRC_DIR=/bin/
344         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
345
346         # Create a pool and volume.
347         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
348         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
349         ${ZFS} create -V 400M ${FULL_ZVOL_NAME} || fail 3
350
351         # Partition the volume, for a 400M volume there will be
352         # 812 cylinders, 16 heads, and 63 sectors per track.
353         zconfig_partition /dev/${FULL_ZVOL_NAME} 0 812
354
355         # Format the partition with ext2 (no journal).
356         /sbin/mkfs.ext2 -q /dev/${FULL_ZVOL_NAME}1 || fail 5
357
358         # Mount the ext3 filesystem and copy some data to it.
359         mkdir -p /tmp/${ZVOL_NAME}1 || fail 6
360         mount /dev/${FULL_ZVOL_NAME}1 /tmp/${ZVOL_NAME}1 || fail 7
361
362         # Snapshot the pristine ext2 filesystem and mount it read-only.
363         ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 8
364         wait_udev /dev/${FULL_SNAP_NAME}1 30 || fail 8
365         mkdir -p /tmp/${SNAP_NAME}1 || fail 9
366         mount /dev/${FULL_SNAP_NAME}1 /tmp/${SNAP_NAME}1 &>/dev/null || fail 10
367
368         # Copy to original volume
369         cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}1 || fail 11
370         sync
371
372         # Verify the copied files match the original files,
373         # and the copied files do NOT appear in the snapshot.
374         diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}1${SRC_DIR} &>/dev/null || fail 12
375         diff -ur ${SRC_DIR} /tmp/${SNAP_NAME}1${SRC_DIR} &>/dev/null && fail 13
376
377         # umount, destroy the snapshot, volume, and pool.
378         umount /tmp/${SNAP_NAME}1 || fail 14
379         rmdir /tmp/${SNAP_NAME}1 || fail 15
380         ${ZFS} destroy ${FULL_SNAP_NAME} || fail 16
381
382         umount /tmp/${ZVOL_NAME}1 || fail 17
383         rmdir /tmp/${ZVOL_NAME}1 || fail 18
384         ${ZFS} destroy ${FULL_ZVOL_NAME} || fail 19
385
386         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 20
387         ${ZFS_SH} -u || fail 21
388         rm -f ${TMP_CACHE} || fail 22
389
390         pass
391 }
392 run_test 6 "zvol+ext2 snapshot"
393
394 # ZVOL clone sanity check
395 test_7() {
396         local POOL_NAME=tank
397         local ZVOL_NAME=fish
398         local SNAP_NAME=pristine
399         local CLONE_NAME=clone
400         local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
401         local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
402         local FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
403         local SRC_DIR=/bin/
404         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
405
406         # Create a pool and volume.
407         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
408         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
409         ${ZFS} create -V 300M ${FULL_ZVOL_NAME} || fail 3
410
411         # Partition the volume, for a 300M volume there will be
412         # 609 cylinders, 16 heads, and 63 sectors per track.
413         zconfig_partition /dev/${FULL_ZVOL_NAME} 0 609
414
415         # Format the partition with ext2 (no journal).
416         /sbin/mkfs.ext2 -q /dev/${FULL_ZVOL_NAME}1 || fail 5
417
418         # Mount the ext3 filesystem and copy some data to it.
419         mkdir -p /tmp/${ZVOL_NAME}1 || fail 6
420         mount /dev/${FULL_ZVOL_NAME}1 /tmp/${ZVOL_NAME}1 || fail 7
421
422         # Snapshot the pristine ext2 filesystem and mount it read-only.
423         ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 8
424         wait_udev /dev/${FULL_SNAP_NAME}1 30 || fail 8
425         mkdir -p /tmp/${SNAP_NAME}1 || fail 9
426         mount /dev/${FULL_SNAP_NAME}1 /tmp/${SNAP_NAME}1 &>/dev/null || fail 10
427
428         # Copy to original volume.
429         cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}1 || fail 11
430         sync
431
432         # Verify the copied files match the original files,
433         # and the copied files do NOT appear in the snapshot.
434         diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}1${SRC_DIR} &>/dev/null || fail 12
435         diff -ur ${SRC_DIR} /tmp/${SNAP_NAME}1${SRC_DIR} &>/dev/null && fail 13
436
437         # Clone from the original pristine snapshot
438         ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 14
439         wait_udev /dev/${FULL_CLONE_NAME}1 30 || fail 14
440         mkdir -p /tmp/${CLONE_NAME}1 || fail 15
441         mount /dev/${FULL_CLONE_NAME}1 /tmp/${CLONE_NAME}1 || fail 16
442
443         # Verify the clone matches the pristine snapshot,
444         # and the files copied to the original volume are NOT there.
445         diff -ur /tmp/${SNAP_NAME}1 /tmp/${CLONE_NAME}1 &>/dev/null || fail 17
446         diff -ur /tmp/${ZVOL_NAME}1 /tmp/${CLONE_NAME}1 &>/dev/null && fail 18
447
448         # Copy to cloned volume.
449         cp -RL ${SRC_DIR} /tmp/${CLONE_NAME}1 || fail 19
450         sync
451
452         # Verify the clone matches the modified original volume.
453         diff -ur /tmp/${ZVOL_NAME}1 /tmp/${CLONE_NAME}1 &>/dev/null || fail 20
454
455         # umount, destroy the snapshot, volume, and pool.
456         umount /tmp/${CLONE_NAME}1 || fail 21
457         rmdir /tmp/${CLONE_NAME}1 || fail 22
458         ${ZFS} destroy ${FULL_CLONE_NAME} || fail 23
459
460         umount /tmp/${SNAP_NAME}1 || fail 24
461         rmdir /tmp/${SNAP_NAME}1 || fail 25
462         ${ZFS} destroy ${FULL_SNAP_NAME} || fail 26
463
464         umount /tmp/${ZVOL_NAME}1 || fail 27
465         rmdir /tmp/${ZVOL_NAME}1 || fail 28
466         ${ZFS} destroy ${FULL_ZVOL_NAME} || fail 29
467
468         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 30
469         ${ZFS_SH} -u || fail 31
470         rm -f ${TMP_CACHE} || fail 32
471
472         pass
473 }
474 run_test 7 "zvol+ext2 clone"
475
476 # Send/Receive sanity check
477 test_8() {
478         local POOL_NAME1=tank1
479         local POOL_NAME2=tank2
480         local ZVOL_NAME=fish
481         local SNAP_NAME=snap
482         local FULL_ZVOL_NAME1=${POOL_NAME1}/${ZVOL_NAME}
483         local FULL_ZVOL_NAME2=${POOL_NAME2}/${ZVOL_NAME}
484         local FULL_SNAP_NAME1=${POOL_NAME1}/${ZVOL_NAME}@${SNAP_NAME}
485         local FULL_SNAP_NAME2=${POOL_NAME2}/${ZVOL_NAME}@${SNAP_NAME}
486         local SRC_DIR=/bin/
487         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
488
489         # Create two pools and a volume
490         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
491         ${ZPOOL_CREATE_SH} -p ${POOL_NAME1} -c lo-raidz2 || fail 2
492         ${ZPOOL_CREATE_SH} -p ${POOL_NAME2} -c lo-raidz2 || fail 3
493         ${ZFS} create -V 300M ${FULL_ZVOL_NAME1} || fail 4
494
495         # Partition the volume, for a 300M volume there will be
496         # 609 cylinders, 16 heads, and 63 sectors per track.
497         zconfig_partition /dev/${FULL_ZVOL_NAME1} 0 609
498
499         # Format the partition with ext2.
500         /sbin/mkfs.ext2 -q /dev/${FULL_ZVOL_NAME1}1 || fail 5
501
502         # Mount the ext3 filesystem and copy some data to it.
503         mkdir -p /tmp/${FULL_ZVOL_NAME1}1 || fail 6
504         mount /dev/${FULL_ZVOL_NAME1}1 /tmp/${FULL_ZVOL_NAME1}1 || fail 7
505         cp -RL ${SRC_DIR} /tmp/${FULL_ZVOL_NAME1}1 || fail 8
506         sync || fail 9
507
508         # Snapshot the ext3 filesystem so it may be sent.
509         ${ZFS} snapshot ${FULL_SNAP_NAME1} || fail 11
510         wait_udev /dev/${FULL_SNAP_NAME1} 30 || fail 11
511
512         # Send/receive the snapshot from POOL_NAME1 to POOL_NAME2
513         (${ZFS} send ${FULL_SNAP_NAME1} | \
514         ${ZFS} receive ${FULL_ZVOL_NAME2}) || fail 12
515         wait_udev /dev/${FULL_ZVOL_NAME2}1 30 || fail 12
516
517         # Mount the sent ext3 filesystem.
518         mkdir -p /tmp/${FULL_ZVOL_NAME2}1 || fail 13
519         mount /dev/${FULL_ZVOL_NAME2}1 /tmp/${FULL_ZVOL_NAME2}1 || fail 14
520
521         # Verify the contents of the volumes match
522         diff -ur /tmp/${FULL_ZVOL_NAME1}1 /tmp/${FULL_ZVOL_NAME2}1 \
523             &>/dev/null || fail 15
524
525         # Umount, destroy the volume and pool.
526         umount /tmp/${FULL_ZVOL_NAME1}1 || fail 16
527         umount /tmp/${FULL_ZVOL_NAME2}1 || fail 17
528         rmdir /tmp/${FULL_ZVOL_NAME1}1 || fail 18
529         rmdir /tmp/${FULL_ZVOL_NAME2}1 || fail 19
530         rmdir /tmp/${POOL_NAME1} || fail 20
531         rmdir /tmp/${POOL_NAME2} || fail 21
532
533         ${ZFS} destroy ${FULL_SNAP_NAME1} || fail 22
534         ${ZFS} destroy ${FULL_SNAP_NAME2} || fail 23
535         ${ZFS} destroy ${FULL_ZVOL_NAME1} || fail 24
536         ${ZFS} destroy ${FULL_ZVOL_NAME2} || fail 25
537         ${ZPOOL_CREATE_SH} -p ${POOL_NAME1} -c lo-raidz2 -d || fail 26
538         ${ZPOOL_CREATE_SH} -p ${POOL_NAME2} -c lo-raidz2 -d || fail 27
539         ${ZFS_SH} -u || fail 28
540         rm -f ${TMP_CACHE} || fail 29
541
542         pass
543 }
544 run_test 8 "zfs send/receive"
545
546 # zpool event sanity check
547 test_9() {
548         local POOL_NAME=tank
549         local ZVOL_NAME=fish
550         local FULL_NAME=${POOL_NAME}/${ZVOL_NAME}
551         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
552         local TMP_EVENTS=`mktemp -p /tmp zpool.events.XXXXXXXX`
553
554         # Create a pool and volume.
555         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
556         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
557         ${ZFS} create -V 300M ${FULL_NAME} || fail 3
558
559         # Dump the events, there should be at least 5 lines.
560         ${ZPOOL} events >${TMP_EVENTS} || fail 4
561         EVENTS=`wc -l ${TMP_EVENTS} | cut -f1 -d' '`
562         [ $EVENTS -lt 5 ] && fail 5
563
564         # Clear the events and ensure there are none.
565         ${ZPOOL} events -c >/dev/null || fail 6
566         ${ZPOOL} events >${TMP_EVENTS} || fail 7
567         EVENTS=`wc -l ${TMP_EVENTS} | cut -f1 -d' '`
568         [ $EVENTS -gt 1 ] && fail 8
569
570         ${ZFS} destroy ${FULL_NAME} || fail 9
571         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 10
572         ${ZFS_SH} -u || fail 11
573         rm -f ${TMP_CACHE} || fail 12
574         rm -f ${TMP_EVENTS} || fail 13
575
576         pass
577 }
578 run_test 9 "zpool events"
579
580 zconfig_add_vdev() {
581         local POOL_NAME=$1
582         local TYPE=$2
583         local DEVICE=$3
584         local TMP_FILE1=`mktemp`
585         local TMP_FILE2=`mktemp`
586         local TMP_FILE3=`mktemp`
587
588         BASE_DEVICE=`basename ${DEVICE}`
589
590         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1}
591         ${ZPOOL} add -f ${POOL_NAME} ${TYPE} ${DEVICE} 2>/dev/null || return 1
592         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2}
593         diff ${TMP_FILE1} ${TMP_FILE2} > ${TMP_FILE3}
594
595         [ `wc -l ${TMP_FILE3}|${AWK} '{print $1}'` -eq 3 ] || return 1
596
597         PARENT_VDEV=`tail -2 ${TMP_FILE3} | head -1 | ${AWK} '{print $NF}'`
598         case $TYPE in
599         cache)
600                 [ "${PARENT_VDEV}" = "${TYPE}" ] || return 1
601                 ;;
602         log)
603                 [ "${PARENT_VDEV}" = "logs" ] || return 1
604                 ;;
605         esac
606
607         if ! tail -1 ${TMP_FILE3} |
608             egrep -q "^>[[:space:]]+${BASE_DEVICE}[[:space:]]+ONLINE" ; then
609                 return 1
610         fi
611         rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_FILE3}
612
613         return 0
614 }
615
616 # zpool add and remove sanity check
617 test_10() {
618         local POOL_NAME=tank
619         local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
620         local TMP_FILE1=`mktemp`
621         local TMP_FILE2=`mktemp`
622
623         if [ ${SCSI_DEBUG} -eq 0 ] || [ ${HAVE_LSSCSI} -eq 0 ] ; then
624                 skip
625                 return
626         fi
627
628         test `${LSMOD} | grep -c scsi_debug` -gt 0 && \
629                 (${RMMOD} scsi_debug || exit 1)
630
631         /sbin/modprobe scsi_debug dev_size_mb=128 ||
632                 die "Error $? creating scsi_debug device"
633         udev_trigger
634
635         SDDEVICE=`${LSSCSI}|${AWK} '/scsi_debug/ { print $6; exit }'`
636         BASE_SDDEVICE=`basename $SDDEVICE`
637
638         # Create a pool
639         ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
640         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
641         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
642
643         # Add and remove a cache vdev by full path
644         zconfig_add_vdev ${POOL_NAME} cache ${SDDEVICE} || fail 4
645         ${ZPOOL} remove ${POOL_NAME} ${SDDEVICE} || fail 5
646         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 6
647         cmp ${TMP_FILE1} ${TMP_FILE2} || fail 7
648
649         # Add and remove a cache vdev by shorthand path
650         zconfig_add_vdev ${POOL_NAME} cache ${BASE_SDDEVICE} || fail 8
651         ${ZPOOL} remove ${POOL_NAME} ${BASE_SDDEVICE} || fail 9
652         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 10
653         cmp ${TMP_FILE1} ${TMP_FILE2} || fail 11
654
655         # Add and remove a log vdev
656         zconfig_add_vdev ${POOL_NAME} log ${BASE_SDDEVICE} || fail 12
657         ${ZPOOL} remove ${POOL_NAME} ${BASE_SDDEVICE} || fail 13
658         ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 14
659         cmp ${TMP_FILE1} ${TMP_FILE2} || fail 15
660
661         ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 16
662         ${ZFS_SH} -u || fail 17
663         ${RMMOD} scsi_debug || fail 18
664
665         rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_CACHE} || fail 19
666
667         pass
668 }
669 run_test 10 "zpool add/remove vdev"
670
671 exit 0
672