3 # ZFS/ZPOOL configuration test script.
5 basedir="$(dirname $0)"
7 SCRIPT_COMMON=common.sh
8 if [ -f "${basedir}/${SCRIPT_COMMON}" ]; then
9 . "${basedir}/${SCRIPT_COMMON}"
11 echo "Missing helper script ${SCRIPT_COMMON}" && exit 1
22 ZFS/ZPOOL configuration tests
27 -c Cleanup lo+file devices at start
28 -t <#> Run listed tests
29 -s <#> Skip listed tests
34 while getopts 'hvct:s:?' OPTION; do
59 if [ $(id -u) != 0 ]; then
60 die "Must run as root"
63 # Initialize the test suite
66 # Perform pre-cleanup is requested
67 if [ ${CLEANUP} ]; then
71 rm -f /tmp/zpool.cache.*
74 # Check if we need to skip the tests that require scsi_debug and lsscsi.
76 ${INFOMOD} scsi_debug &>/dev/null && SCSI_DEBUG=1
78 test -f ${LSSCSI} && HAVE_LSSCSI=1
79 if [ ${SCSI_DEBUG} -eq 0 ] || [ ${HAVE_LSSCSI} -eq 0 ]; then
80 echo "Skipping test 10 which requires the scsi_debug " \
81 "module and the ${LSSCSI} utility"
88 local TMP_FILE=`mktemp`
90 /sbin/sfdisk -q ${DEVICE} << EOF &>${TMP_FILE} || fail 4
101 # Validate persistent zpool.cache configuration.
103 local POOL_NAME=test1
104 local TMP_FILE1=`mktemp`
105 local TMP_FILE2=`mktemp`
106 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
108 # Create a pool save its status for comparison.
109 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
110 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
111 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
113 # Unload/load the module stack and verify the pool persists.
114 ${ZFS_SH} -u || fail 4
115 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 5
116 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 6
117 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 7
119 # Cleanup the test pool and temporary files
120 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 8
121 rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_CACHE} || fail 9
122 ${ZFS_SH} -u || fail 10
126 run_test 1 "persistent zpool.cache"
128 # Validate ZFS disk scanning and import w/out zpool.cache configuration.
130 local POOL_NAME=test2
131 local TMP_FILE1=`mktemp`
132 local TMP_FILE2=`mktemp`
133 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
135 # Create a pool save its status for comparison.
136 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
137 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
138 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
140 # Unload the module stack, remove the cache file, load the module
141 # stack and attempt to probe the disks to import the pool. As
142 # a cross check verify the old pool state against the imported.
143 ${ZFS_SH} -u || fail 4
144 rm -f ${TMP_CACHE} || fail 5
145 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 6
146 ${ZPOOL} import | grep ${POOL_NAME} >/dev/null || fail 7
147 ${ZPOOL} import -f ${POOL_NAME} || fail 8
148 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 9
149 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 10
151 # Cleanup the test pool and temporary files
152 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 11
153 rm -f ${TMP_FILE1} ${TMP_FILE2} || fail 12
154 ${ZFS_SH} -u || fail 13
158 run_test 2 "scan disks for pools to import"
160 zconfig_zvol_device_stat() {
162 local POOL_NAME=/dev/zvol/$2
163 local ZVOL_NAME=/dev/zvol/$3
164 local SNAP_NAME=/dev/zvol/$4
165 local CLONE_NAME=/dev/zvol/$5
168 # Briefly delay for udev
172 stat ${POOL_NAME} &>/dev/null && let COUNT=$COUNT+1
174 # Volume and partitions
175 stat ${ZVOL_NAME} &>/dev/null && let COUNT=$COUNT+1
176 stat ${ZVOL_NAME}-part1 &>/dev/null && let COUNT=$COUNT+1
177 stat ${ZVOL_NAME}-part2 &>/dev/null && let COUNT=$COUNT+1
179 # Snapshot with partitions
180 stat ${SNAP_NAME} &>/dev/null && let COUNT=$COUNT+1
181 stat ${SNAP_NAME}-part1 &>/dev/null && let COUNT=$COUNT+1
182 stat ${SNAP_NAME}-part2 &>/dev/null && let COUNT=$COUNT+1
184 # Clone with partitions
185 stat ${CLONE_NAME} &>/dev/null && let COUNT=$COUNT+1
186 stat ${CLONE_NAME}-part1 &>/dev/null && let COUNT=$COUNT+1
187 stat ${CLONE_NAME}-part2 &>/dev/null && let COUNT=$COUNT+1
189 if [ $EXPECT -ne $COUNT ]; then
196 # zpool import/export device check
197 # (1 volume, 2 partitions, 1 snapshot, 1 clone)
200 local ZVOL_NAME=volume
202 local CLONE_NAME=clone
203 local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
204 local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
205 local FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
206 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
208 # Create a pool, volume, partition, snapshot, and clone.
209 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
210 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
211 ${ZFS} create -V 100M ${FULL_ZVOL_NAME} || fail 3
212 zconfig_partition /dev/zvol/${FULL_ZVOL_NAME} 0 64 || fail 4
213 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 5
214 ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 6
216 # Verify the devices were created
217 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
218 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 7
221 ${ZPOOL} export ${POOL_NAME} || fail 8
223 # verify the devices were removed
224 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
225 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
227 # Import the pool, wait 1 second for udev
228 ${ZPOOL} import ${POOL_NAME} || fail 10
230 # Verify the devices were created
231 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
232 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 11
234 # Destroy the pool and consequently the devices
235 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 12
237 # verify the devices were removed
238 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
239 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 13
241 ${ZFS_SH} -u || fail 14
242 rm -f ${TMP_CACHE} || fail 15
246 run_test 3 "zpool import/export device"
248 # zpool insmod/rmmod device check (1 volume, 1 snapshot, 1 clone)
254 FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
255 FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
256 FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
257 TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
259 # Create a pool, volume, snapshot, and clone
260 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
261 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
262 ${ZFS} create -V 100M ${FULL_ZVOL_NAME} || fail 3
263 zconfig_partition /dev/zvol/${FULL_ZVOL_NAME} 0 64 || fail 4
264 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 5
265 ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 6
267 # Verify the devices were created
268 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
269 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 7
272 ${ZFS_SH} -u || fail 8
274 # Verify the devices were removed
275 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
276 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
278 # Load the modules, wait 1 second for udev
279 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 10
281 # Verify the devices were created
282 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
283 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 11
285 # Destroy the pool and consequently the devices
286 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 12
288 # Verify the devices were removed
289 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
290 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 13
292 ${ZFS_SH} -u || fail 14
293 rm -f ${TMP_CACHE} || fail 15
297 run_test 4 "zpool insmod/rmmod device"
299 # ZVOL volume sanity check
303 local FULL_NAME=${POOL_NAME}/${ZVOL_NAME}
305 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
307 # Create a pool and volume.
308 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
309 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raid0 || fail 2
310 ${ZFS} create -V 800M ${FULL_NAME} || fail 3
312 # Partition the volume, for a 800M volume there will be
313 # 1624 cylinders, 16 heads, and 63 sectors per track.
314 zconfig_partition /dev/zvol/${FULL_NAME} 0 1624
316 # Format the partition with ext3.
317 /sbin/mkfs.ext3 -q /dev/zvol/${FULL_NAME}-part1 || fail 5
319 # Mount the ext3 filesystem and copy some data to it.
320 mkdir -p /tmp/${ZVOL_NAME}-part1 || fail 6
321 mount /dev/zvol/${FULL_NAME}-part1 /tmp/${ZVOL_NAME}-part1 || fail 7
322 cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}-part1 || fail 8
325 # Verify the copied files match the original files.
326 diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}-part1${SRC_DIR} \
327 &>/dev/null || fail 9
329 # Remove the files, umount, destroy the volume and pool.
330 rm -Rf /tmp/${ZVOL_NAME}-part1${SRC_DIR}* || fail 10
331 umount /tmp/${ZVOL_NAME}-part1 || fail 11
332 rmdir /tmp/${ZVOL_NAME}-part1 || fail 12
334 ${ZFS} destroy ${FULL_NAME} || fail 13
335 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 14
336 ${ZFS_SH} -u || fail 15
337 rm -f ${TMP_CACHE} || fail 16
341 run_test 5 "zvol+ext3 volume"
343 # ZVOL snapshot sanity check
347 local SNAP_NAME=pristine
348 local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
349 local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
351 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
353 # Create a pool and volume.
354 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
355 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raid0 || fail 2
356 ${ZFS} create -V 800M ${FULL_ZVOL_NAME} || fail 3
358 # Partition the volume, for a 800M volume there will be
359 # 1624 cylinders, 16 heads, and 63 sectors per track.
360 zconfig_partition /dev/zvol/${FULL_ZVOL_NAME} 0 1624
362 # Format the partition with ext2 (no journal).
363 /sbin/mkfs.ext2 -q /dev/zvol/${FULL_ZVOL_NAME}-part1 || fail 5
365 # Mount the ext3 filesystem and copy some data to it.
366 mkdir -p /tmp/${ZVOL_NAME}-part1 || fail 6
367 mount /dev/zvol/${FULL_ZVOL_NAME}-part1 /tmp/${ZVOL_NAME}-part1 \
370 # Snapshot the pristine ext2 filesystem and mount it read-only.
371 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 8
372 wait_udev /dev/zvol/${FULL_SNAP_NAME}-part1 30 || fail 8
373 mkdir -p /tmp/${SNAP_NAME}-part1 || fail 9
374 mount /dev/zvol/${FULL_SNAP_NAME}-part1 /tmp/${SNAP_NAME}-part1 \
375 &>/dev/null || fail 10
377 # Copy to original volume
378 cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}-part1 || fail 11
381 # Verify the copied files match the original files,
382 # and the copied files do NOT appear in the snapshot.
383 diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}-part1${SRC_DIR} \
384 &>/dev/null || fail 12
385 diff -ur ${SRC_DIR} /tmp/${SNAP_NAME}-part1${SRC_DIR} \
386 &>/dev/null && fail 13
388 # umount, destroy the snapshot, volume, and pool.
389 umount /tmp/${SNAP_NAME}-part1 || fail 14
390 rmdir /tmp/${SNAP_NAME}-part1 || fail 15
391 ${ZFS} destroy ${FULL_SNAP_NAME} || fail 16
393 umount /tmp/${ZVOL_NAME}-part1 || fail 17
394 rmdir /tmp/${ZVOL_NAME}-part1 || fail 18
395 ${ZFS} destroy ${FULL_ZVOL_NAME} || fail 19
397 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 20
398 ${ZFS_SH} -u || fail 21
399 rm -f ${TMP_CACHE} || fail 22
403 run_test 6 "zvol+ext2 snapshot"
405 # ZVOL clone sanity check
409 local SNAP_NAME=pristine
410 local CLONE_NAME=clone
411 local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
412 local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
413 local FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
415 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
417 # Create a pool and volume.
418 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
419 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
420 ${ZFS} create -V 300M ${FULL_ZVOL_NAME} || fail 3
422 # Partition the volume, for a 300M volume there will be
423 # 609 cylinders, 16 heads, and 63 sectors per track.
424 zconfig_partition /dev/zvol/${FULL_ZVOL_NAME} 0 609
426 # Format the partition with ext2 (no journal).
427 /sbin/mkfs.ext2 -q /dev/zvol/${FULL_ZVOL_NAME}-part1 || fail 5
429 # Mount the ext3 filesystem and copy some data to it.
430 mkdir -p /tmp/${ZVOL_NAME}-part1 || fail 6
431 mount /dev/zvol/${FULL_ZVOL_NAME}-part1 /tmp/${ZVOL_NAME}-part1 \
434 # Snapshot the pristine ext2 filesystem and mount it read-only.
435 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 8
436 wait_udev /dev/zvol/${FULL_SNAP_NAME}-part1 30 || fail 8
437 mkdir -p /tmp/${SNAP_NAME}-part1 || fail 9
438 mount /dev/zvol/${FULL_SNAP_NAME}-part1 \
439 /tmp/${SNAP_NAME}-part1 &>/dev/null || fail 10
441 # Copy to original volume.
442 cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}-part1 || fail 11
445 # Verify the copied files match the original files,
446 # and the copied files do NOT appear in the snapshot.
447 diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}-part1${SRC_DIR} \
448 &>/dev/null || fail 12
449 diff -ur ${SRC_DIR} /tmp/${SNAP_NAME}-part1${SRC_DIR} \
450 &>/dev/null && fail 13
452 # Clone from the original pristine snapshot
453 ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 14
454 wait_udev /dev/zvol/${FULL_CLONE_NAME}-part1 30 || fail 14
455 mkdir -p /tmp/${CLONE_NAME}-part1 || fail 15
456 mount /dev/zvol/${FULL_CLONE_NAME}-part1 \
457 /tmp/${CLONE_NAME}-part1 || fail 16
459 # Verify the clone matches the pristine snapshot,
460 # and the files copied to the original volume are NOT there.
461 diff -ur /tmp/${SNAP_NAME}-part1 /tmp/${CLONE_NAME}-part1 \
462 &>/dev/null || fail 17
463 diff -ur /tmp/${ZVOL_NAME}-part1 /tmp/${CLONE_NAME}-part1 \
464 &>/dev/null && fail 18
466 # Copy to cloned volume.
467 cp -RL ${SRC_DIR} /tmp/${CLONE_NAME}-part1 || fail 19
470 # Verify the clone matches the modified original volume.
471 diff -ur /tmp/${ZVOL_NAME}-part1 /tmp/${CLONE_NAME}-part1 \
472 &>/dev/null || fail 20
474 # umount, destroy the snapshot, volume, and pool.
475 umount /tmp/${CLONE_NAME}-part1 || fail 21
476 rmdir /tmp/${CLONE_NAME}-part1 || fail 22
477 ${ZFS} destroy ${FULL_CLONE_NAME} || fail 23
479 umount /tmp/${SNAP_NAME}-part1 || fail 24
480 rmdir /tmp/${SNAP_NAME}-part1 || fail 25
481 ${ZFS} destroy ${FULL_SNAP_NAME} || fail 26
483 umount /tmp/${ZVOL_NAME}-part1 || fail 27
484 rmdir /tmp/${ZVOL_NAME}-part1 || fail 28
485 ${ZFS} destroy ${FULL_ZVOL_NAME} || fail 29
487 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 30
488 ${ZFS_SH} -u || fail 31
489 rm -f ${TMP_CACHE} || fail 32
493 run_test 7 "zvol+ext2 clone"
495 # Send/Receive sanity check
497 local POOL_NAME1=tank1
498 local POOL_NAME2=tank2
501 local FULL_ZVOL_NAME1=${POOL_NAME1}/${ZVOL_NAME}
502 local FULL_ZVOL_NAME2=${POOL_NAME2}/${ZVOL_NAME}
503 local FULL_SNAP_NAME1=${POOL_NAME1}/${ZVOL_NAME}@${SNAP_NAME}
504 local FULL_SNAP_NAME2=${POOL_NAME2}/${ZVOL_NAME}@${SNAP_NAME}
506 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
508 # Create two pools and a volume
509 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
510 ${ZPOOL_CREATE_SH} -p ${POOL_NAME1} -c lo-raidz2 || fail 2
511 ${ZPOOL_CREATE_SH} -p ${POOL_NAME2} -c lo-raidz2 || fail 3
512 ${ZFS} create -V 300M ${FULL_ZVOL_NAME1} || fail 4
514 # Partition the volume, for a 300M volume there will be
515 # 609 cylinders, 16 heads, and 63 sectors per track.
516 zconfig_partition /dev/zvol/${FULL_ZVOL_NAME1} 0 609
518 # Format the partition with ext2.
519 /sbin/mkfs.ext2 -q /dev/zvol/${FULL_ZVOL_NAME1}-part1 || fail 5
521 # Mount the ext3 filesystem and copy some data to it.
522 mkdir -p /tmp/${FULL_ZVOL_NAME1}-part1 || fail 6
523 mount /dev/zvol/${FULL_ZVOL_NAME1}-part1 \
524 /tmp/${FULL_ZVOL_NAME1}-part1 || fail 7
525 cp -RL ${SRC_DIR} /tmp/${FULL_ZVOL_NAME1}-part1 || fail 8
528 # Snapshot the ext3 filesystem so it may be sent.
529 ${ZFS} snapshot ${FULL_SNAP_NAME1} || fail 11
530 wait_udev /dev/zvol/${FULL_SNAP_NAME1} 30 || fail 11
532 # Send/receive the snapshot from POOL_NAME1 to POOL_NAME2
533 (${ZFS} send ${FULL_SNAP_NAME1} | \
534 ${ZFS} receive ${FULL_ZVOL_NAME2}) || fail 12
535 wait_udev /dev/zvol/${FULL_ZVOL_NAME2}-part1 30 || fail 12
537 # Mount the sent ext3 filesystem.
538 mkdir -p /tmp/${FULL_ZVOL_NAME2}-part1 || fail 13
539 mount /dev/zvol/${FULL_ZVOL_NAME2}-part1 \
540 /tmp/${FULL_ZVOL_NAME2}-part1 || fail 14
542 # Verify the contents of the volumes match
543 diff -ur /tmp/${FULL_ZVOL_NAME1}-part1 /tmp/${FULL_ZVOL_NAME2}-part1 \
544 &>/dev/null || fail 15
546 # Umount, destroy the volume and pool.
547 umount /tmp/${FULL_ZVOL_NAME1}-part1 || fail 16
548 umount /tmp/${FULL_ZVOL_NAME2}-part1 || fail 17
549 rmdir /tmp/${FULL_ZVOL_NAME1}-part1 || fail 18
550 rmdir /tmp/${FULL_ZVOL_NAME2}-part1 || fail 19
551 rmdir /tmp/${POOL_NAME1} || fail 20
552 rmdir /tmp/${POOL_NAME2} || fail 21
554 ${ZFS} destroy ${FULL_SNAP_NAME1} || fail 22
555 ${ZFS} destroy ${FULL_SNAP_NAME2} || fail 23
556 ${ZFS} destroy ${FULL_ZVOL_NAME1} || fail 24
557 ${ZFS} destroy ${FULL_ZVOL_NAME2} || fail 25
558 ${ZPOOL_CREATE_SH} -p ${POOL_NAME1} -c lo-raidz2 -d || fail 26
559 ${ZPOOL_CREATE_SH} -p ${POOL_NAME2} -c lo-raidz2 -d || fail 27
560 ${ZFS_SH} -u || fail 28
561 rm -f ${TMP_CACHE} || fail 29
565 run_test 8 "zfs send/receive"
567 # zpool event sanity check
571 local FULL_NAME=${POOL_NAME}/${ZVOL_NAME}
572 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
573 local TMP_EVENTS=`mktemp -p /tmp zpool.events.XXXXXXXX`
575 # Create a pool and volume.
576 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
577 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
578 ${ZFS} create -V 300M ${FULL_NAME} || fail 3
580 # Dump the events, there should be at least 5 lines.
581 ${ZPOOL} events >${TMP_EVENTS} || fail 4
582 EVENTS=`wc -l ${TMP_EVENTS} | cut -f1 -d' '`
583 [ $EVENTS -lt 5 ] && fail 5
585 # Clear the events and ensure there are none.
586 ${ZPOOL} events -c >/dev/null || fail 6
587 ${ZPOOL} events >${TMP_EVENTS} || fail 7
588 EVENTS=`wc -l ${TMP_EVENTS} | cut -f1 -d' '`
589 [ $EVENTS -gt 1 ] && fail 8
591 ${ZFS} destroy ${FULL_NAME} || fail 9
592 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 10
593 ${ZFS_SH} -u || fail 11
594 rm -f ${TMP_CACHE} || fail 12
595 rm -f ${TMP_EVENTS} || fail 13
599 run_test 9 "zpool events"
605 local TMP_FILE1=`mktemp`
606 local TMP_FILE2=`mktemp`
607 local TMP_FILE3=`mktemp`
609 BASE_DEVICE=`basename ${DEVICE}`
611 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1}
612 ${ZPOOL} add -f ${POOL_NAME} ${TYPE} ${DEVICE} 2>/dev/null || return 1
613 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2}
614 diff ${TMP_FILE1} ${TMP_FILE2} > ${TMP_FILE3}
616 [ `wc -l ${TMP_FILE3}|${AWK} '{print $1}'` -eq 3 ] || return 1
618 PARENT_VDEV=`tail -2 ${TMP_FILE3} | head -1 | ${AWK} '{print $NF}'`
621 [ "${PARENT_VDEV}" = "${TYPE}" ] || return 1
624 [ "${PARENT_VDEV}" = "logs" ] || return 1
628 if ! tail -1 ${TMP_FILE3} |
629 egrep -q "^>[[:space:]]+${BASE_DEVICE}[[:space:]]+ONLINE" ; then
632 rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_FILE3}
637 # zpool add and remove sanity check
640 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
641 local TMP_FILE1=`mktemp`
642 local TMP_FILE2=`mktemp`
644 if [ ${SCSI_DEBUG} -eq 0 ] || [ ${HAVE_LSSCSI} -eq 0 ] ; then
649 test `${LSMOD} | grep -c scsi_debug` -gt 0 && \
650 (${RMMOD} scsi_debug || exit 1)
652 /sbin/modprobe scsi_debug dev_size_mb=128 ||
653 die "Error $? creating scsi_debug device"
656 SDDEVICE=`${LSSCSI}|${AWK} '/scsi_debug/ { print $6; exit }'`
657 BASE_SDDEVICE=`basename $SDDEVICE`
660 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
661 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
662 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
664 # Add and remove a cache vdev by full path
665 zconfig_add_vdev ${POOL_NAME} cache ${SDDEVICE} || fail 4
666 ${ZPOOL} remove ${POOL_NAME} ${SDDEVICE} || fail 5
667 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 6
668 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 7
671 # Add and remove a cache vdev by shorthand path
672 zconfig_add_vdev ${POOL_NAME} cache ${BASE_SDDEVICE} || fail 8
673 ${ZPOOL} remove ${POOL_NAME} ${BASE_SDDEVICE} || fail 9
674 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 10
675 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 11
678 # Add and remove a log vdev
679 zconfig_add_vdev ${POOL_NAME} log ${BASE_SDDEVICE} || fail 12
680 ${ZPOOL} remove ${POOL_NAME} ${BASE_SDDEVICE} || fail 13
681 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 14
682 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 15
684 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 16
685 ${ZFS_SH} -u || fail 17
686 ${RMMOD} scsi_debug || fail 18
688 rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_CACHE} || fail 19
692 run_test 10 "zpool add/remove vdev"