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 # Perform pre-cleanup is requested
64 if [ ${CLEANUP} ]; then
68 rm -f /tmp/zpool.cache.*
71 # Check if we need to skip the tests that require scsi_debug and lsscsi.
73 ${INFOMOD} scsi_debug &>/dev/null && SCSI_DEBUG=1
75 test -f ${LSSCSI} && HAVE_LSSCSI=1
76 if [ ${SCSI_DEBUG} -eq 0 ] || [ ${HAVE_LSSCSI} -eq 0 ]; then
77 echo "Skipping test 10 which requires the scsi_debug " \
78 "module and the ${LSSCSI} utility"
85 local TMP_FILE=`mktemp`
87 /sbin/sfdisk -q ${DEVICE} << EOF &>${TMP_FILE} || fail 4
97 # Validate persistent zpool.cache configuration.
100 local TMP_FILE1=`mktemp`
101 local TMP_FILE2=`mktemp`
102 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
104 # Create a pool save its status for comparison.
105 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
106 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
107 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
109 # Unload/load the module stack and verify the pool persists.
110 ${ZFS_SH} -u || fail 4
111 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 5
112 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 6
113 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 7
115 # Cleanup the test pool and temporary files
116 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 8
117 rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_CACHE} || fail 9
118 ${ZFS_SH} -u || fail 10
122 run_test 1 "persistent zpool.cache"
124 # Validate ZFS disk scanning and import w/out zpool.cache configuration.
126 local POOL_NAME=test2
127 local TMP_FILE1=`mktemp`
128 local TMP_FILE2=`mktemp`
129 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
131 # Create a pool save its status for comparison.
132 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
133 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
134 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
136 # Unload the module stack, remove the cache file, load the module
137 # stack and attempt to probe the disks to import the pool. As
138 # a cross check verify the old pool state against the imported.
139 ${ZFS_SH} -u || fail 4
140 rm -f ${TMP_CACHE} || fail 5
141 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 6
142 ${ZPOOL} import | grep ${POOL_NAME} >/dev/null || fail 7
143 ${ZPOOL} import ${POOL_NAME} || fail 8
144 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 9
145 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 10
147 # Cleanup the test pool and temporary files
148 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 11
149 rm -f ${TMP_FILE1} ${TMP_FILE2} || fail 12
150 ${ZFS_SH} -u || fail 13
154 run_test 2 "scan disks for pools to import"
156 zconfig_zvol_device_stat() {
158 local POOL_NAME=/dev/$2
159 local ZVOL_NAME=/dev/$3
160 local SNAP_NAME=/dev/$4
161 local CLONE_NAME=/dev/$5
164 # Briefly delay for udev
168 stat ${POOL_NAME} &>/dev/null && let COUNT=$COUNT+1
170 # Volume and partitions
171 stat ${ZVOL_NAME} &>/dev/null && let COUNT=$COUNT+1
172 stat ${ZVOL_NAME}1 &>/dev/null && let COUNT=$COUNT+1
173 stat ${ZVOL_NAME}2 &>/dev/null && let COUNT=$COUNT+1
175 # Snapshot with partitions
176 stat ${SNAP_NAME} &>/dev/null && let COUNT=$COUNT+1
177 stat ${SNAP_NAME}1 &>/dev/null && let COUNT=$COUNT+1
178 stat ${SNAP_NAME}2 &>/dev/null && let COUNT=$COUNT+1
180 # Clone with partitions
181 stat ${CLONE_NAME} &>/dev/null && let COUNT=$COUNT+1
182 stat ${CLONE_NAME}1 &>/dev/null && let COUNT=$COUNT+1
183 stat ${CLONE_NAME}2 &>/dev/null && let COUNT=$COUNT+1
185 if [ $EXPECT -ne $COUNT ]; then
192 # zpool import/export device check
193 # (1 volume, 2 partitions, 1 snapshot, 1 clone)
196 local ZVOL_NAME=volume
198 local CLONE_NAME=clone
199 local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
200 local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
201 local FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
202 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
204 # Create a pool, volume, partition, snapshot, and clone.
205 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
206 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
207 ${ZFS} create -V 100M ${FULL_ZVOL_NAME} || fail 3
208 zconfig_partition /dev/${FULL_ZVOL_NAME} 0 64 || fail 4
209 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 5
210 ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 6
212 # Verify the devices were created
213 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
214 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 7
217 ${ZPOOL} export ${POOL_NAME} || fail 8
219 # verify the devices were removed
220 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
221 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
223 # Import the pool, wait 1 second for udev
224 ${ZPOOL} import ${POOL_NAME} || fail 10
226 # Verify the devices were created
227 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
228 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 11
230 # Destroy the pool and consequently the devices
231 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 12
233 # verify the devices were removed
234 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
235 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 13
237 ${ZFS_SH} -u || fail 14
238 rm -f ${TMP_CACHE} || fail 15
242 run_test 3 "zpool import/export device"
244 # zpool insmod/rmmod device check (1 volume, 1 snapshot, 1 clone)
250 FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
251 FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
252 FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
253 TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
255 # Create a pool, volume, snapshot, and clone
256 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
257 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
258 ${ZFS} create -V 100M ${FULL_ZVOL_NAME} || fail 3
259 zconfig_partition /dev/${FULL_ZVOL_NAME} 0 64 || fail 4
260 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 5
261 ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 6
263 # Verify the devices were created
264 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
265 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 7
268 ${ZFS_SH} -u || fail 8
270 # Verify the devices were removed
271 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
272 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
274 # Load the modules, wait 1 second for udev
275 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 10
277 # Verify the devices were created
278 zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
279 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 11
281 # Destroy the pool and consequently the devices
282 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 12
284 # Verify the devices were removed
285 zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
286 ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 13
288 ${ZFS_SH} -u || fail 14
289 rm -f ${TMP_CACHE} || fail 15
293 run_test 4 "zpool insmod/rmmod device"
295 # ZVOL volume sanity check
299 local FULL_NAME=${POOL_NAME}/${ZVOL_NAME}
301 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
303 # Create a pool and volume.
304 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
305 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
306 ${ZFS} create -V 400M ${FULL_NAME} || fail 3
308 # Partition the volume, for a 400M volume there will be
309 # 812 cylinders, 16 heads, and 63 sectors per track.
310 zconfig_partition /dev/${FULL_NAME} 0 812
312 # Format the partition with ext3.
313 /sbin/mkfs.ext3 -q /dev/${FULL_NAME}1 || fail 5
315 # Mount the ext3 filesystem and copy some data to it.
316 mkdir -p /tmp/${ZVOL_NAME}1 || fail 6
317 mount /dev/${FULL_NAME}1 /tmp/${ZVOL_NAME}1 || fail 7
318 cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}1 || fail 8
321 # Verify the copied files match the original files.
322 diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}1${SRC_DIR} &>/dev/null || fail 9
324 # Remove the files, umount, destroy the volume and pool.
325 rm -Rf /tmp/${ZVOL_NAME}1${SRC_DIR}* || fail 10
326 umount /tmp/${ZVOL_NAME}1 || fail 11
327 rmdir /tmp/${ZVOL_NAME}1 || fail 12
329 ${ZFS} destroy ${FULL_NAME} || fail 13
330 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 14
331 ${ZFS_SH} -u || fail 15
332 rm -f ${TMP_CACHE} || fail 16
336 run_test 5 "zvol+ext3 volume"
338 # ZVOL snapshot sanity check
342 local SNAP_NAME=pristine
343 local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
344 local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
346 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
348 # Create a pool and volume.
349 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
350 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
351 ${ZFS} create -V 400M ${FULL_ZVOL_NAME} || fail 3
353 # Partition the volume, for a 400M volume there will be
354 # 812 cylinders, 16 heads, and 63 sectors per track.
355 zconfig_partition /dev/${FULL_ZVOL_NAME} 0 812
357 # Format the partition with ext2 (no journal).
358 /sbin/mkfs.ext2 -q /dev/${FULL_ZVOL_NAME}1 || fail 5
360 # Mount the ext3 filesystem and copy some data to it.
361 mkdir -p /tmp/${ZVOL_NAME}1 || fail 6
362 mount /dev/${FULL_ZVOL_NAME}1 /tmp/${ZVOL_NAME}1 || fail 7
364 # Snapshot the pristine ext2 filesystem and mount it read-only.
365 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 8
366 wait_udev /dev/${FULL_SNAP_NAME}1 30 || fail 8
367 mkdir -p /tmp/${SNAP_NAME}1 || fail 9
368 mount /dev/${FULL_SNAP_NAME}1 /tmp/${SNAP_NAME}1 &>/dev/null || fail 10
370 # Copy to original volume
371 cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}1 || fail 11
374 # Verify the copied files match the original files,
375 # and the copied files do NOT appear in the snapshot.
376 diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}1${SRC_DIR} &>/dev/null || fail 12
377 diff -ur ${SRC_DIR} /tmp/${SNAP_NAME}1${SRC_DIR} &>/dev/null && fail 13
379 # umount, destroy the snapshot, volume, and pool.
380 umount /tmp/${SNAP_NAME}1 || fail 14
381 rmdir /tmp/${SNAP_NAME}1 || fail 15
382 ${ZFS} destroy ${FULL_SNAP_NAME} || fail 16
384 umount /tmp/${ZVOL_NAME}1 || fail 17
385 rmdir /tmp/${ZVOL_NAME}1 || fail 18
386 ${ZFS} destroy ${FULL_ZVOL_NAME} || fail 19
388 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 20
389 ${ZFS_SH} -u || fail 21
390 rm -f ${TMP_CACHE} || fail 22
394 run_test 6 "zvol+ext2 snapshot"
396 # ZVOL clone sanity check
400 local SNAP_NAME=pristine
401 local CLONE_NAME=clone
402 local FULL_ZVOL_NAME=${POOL_NAME}/${ZVOL_NAME}
403 local FULL_SNAP_NAME=${POOL_NAME}/${ZVOL_NAME}@${SNAP_NAME}
404 local FULL_CLONE_NAME=${POOL_NAME}/${CLONE_NAME}
406 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
408 # Create a pool and volume.
409 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
410 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
411 ${ZFS} create -V 300M ${FULL_ZVOL_NAME} || fail 3
413 # Partition the volume, for a 300M volume there will be
414 # 609 cylinders, 16 heads, and 63 sectors per track.
415 zconfig_partition /dev/${FULL_ZVOL_NAME} 0 609
417 # Format the partition with ext2 (no journal).
418 /sbin/mkfs.ext2 -q /dev/${FULL_ZVOL_NAME}1 || fail 5
420 # Mount the ext3 filesystem and copy some data to it.
421 mkdir -p /tmp/${ZVOL_NAME}1 || fail 6
422 mount /dev/${FULL_ZVOL_NAME}1 /tmp/${ZVOL_NAME}1 || fail 7
424 # Snapshot the pristine ext2 filesystem and mount it read-only.
425 ${ZFS} snapshot ${FULL_SNAP_NAME} || fail 8
426 wait_udev /dev/${FULL_SNAP_NAME}1 30 || fail 8
427 mkdir -p /tmp/${SNAP_NAME}1 || fail 9
428 mount /dev/${FULL_SNAP_NAME}1 /tmp/${SNAP_NAME}1 &>/dev/null || fail 10
430 # Copy to original volume.
431 cp -RL ${SRC_DIR} /tmp/${ZVOL_NAME}1 || fail 11
434 # Verify the copied files match the original files,
435 # and the copied files do NOT appear in the snapshot.
436 diff -ur ${SRC_DIR} /tmp/${ZVOL_NAME}1${SRC_DIR} &>/dev/null || fail 12
437 diff -ur ${SRC_DIR} /tmp/${SNAP_NAME}1${SRC_DIR} &>/dev/null && fail 13
439 # Clone from the original pristine snapshot
440 ${ZFS} clone ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 14
441 wait_udev /dev/${FULL_CLONE_NAME}1 30 || fail 14
442 mkdir -p /tmp/${CLONE_NAME}1 || fail 15
443 mount /dev/${FULL_CLONE_NAME}1 /tmp/${CLONE_NAME}1 || fail 16
445 # Verify the clone matches the pristine snapshot,
446 # and the files copied to the original volume are NOT there.
447 diff -ur /tmp/${SNAP_NAME}1 /tmp/${CLONE_NAME}1 &>/dev/null || fail 17
448 diff -ur /tmp/${ZVOL_NAME}1 /tmp/${CLONE_NAME}1 &>/dev/null && fail 18
450 # Copy to cloned volume.
451 cp -RL ${SRC_DIR} /tmp/${CLONE_NAME}1 || fail 19
454 # Verify the clone matches the modified original volume.
455 diff -ur /tmp/${ZVOL_NAME}1 /tmp/${CLONE_NAME}1 &>/dev/null || fail 20
457 # umount, destroy the snapshot, volume, and pool.
458 umount /tmp/${CLONE_NAME}1 || fail 21
459 rmdir /tmp/${CLONE_NAME}1 || fail 22
460 ${ZFS} destroy ${FULL_CLONE_NAME} || fail 23
462 umount /tmp/${SNAP_NAME}1 || fail 24
463 rmdir /tmp/${SNAP_NAME}1 || fail 25
464 ${ZFS} destroy ${FULL_SNAP_NAME} || fail 26
466 umount /tmp/${ZVOL_NAME}1 || fail 27
467 rmdir /tmp/${ZVOL_NAME}1 || fail 28
468 ${ZFS} destroy ${FULL_ZVOL_NAME} || fail 29
470 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 30
471 ${ZFS_SH} -u || fail 31
472 rm -f ${TMP_CACHE} || fail 32
476 run_test 7 "zvol+ext2 clone"
478 # Send/Receive sanity check
480 local POOL_NAME1=tank1
481 local POOL_NAME2=tank2
484 local FULL_ZVOL_NAME1=${POOL_NAME1}/${ZVOL_NAME}
485 local FULL_ZVOL_NAME2=${POOL_NAME2}/${ZVOL_NAME}
486 local FULL_SNAP_NAME1=${POOL_NAME1}/${ZVOL_NAME}@${SNAP_NAME}
487 local FULL_SNAP_NAME2=${POOL_NAME2}/${ZVOL_NAME}@${SNAP_NAME}
489 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
491 # Create two pools and a volume
492 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
493 ${ZPOOL_CREATE_SH} -p ${POOL_NAME1} -c lo-raidz2 || fail 2
494 ${ZPOOL_CREATE_SH} -p ${POOL_NAME2} -c lo-raidz2 || fail 3
495 ${ZFS} create -V 300M ${FULL_ZVOL_NAME1} || fail 4
497 # Partition the volume, for a 300M volume there will be
498 # 609 cylinders, 16 heads, and 63 sectors per track.
499 zconfig_partition /dev/${FULL_ZVOL_NAME1} 0 609
501 # Format the partition with ext2.
502 /sbin/mkfs.ext2 -q /dev/${FULL_ZVOL_NAME1}1 || fail 5
504 # Mount the ext3 filesystem and copy some data to it.
505 mkdir -p /tmp/${FULL_ZVOL_NAME1}1 || fail 6
506 mount /dev/${FULL_ZVOL_NAME1}1 /tmp/${FULL_ZVOL_NAME1}1 || fail 7
507 cp -RL ${SRC_DIR} /tmp/${FULL_ZVOL_NAME1}1 || fail 8
510 # Snapshot the ext3 filesystem so it may be sent.
511 ${ZFS} snapshot ${FULL_SNAP_NAME1} || fail 11
512 wait_udev /dev/${FULL_SNAP_NAME1} 30 || fail 11
514 # Send/receive the snapshot from POOL_NAME1 to POOL_NAME2
515 (${ZFS} send ${FULL_SNAP_NAME1} | \
516 ${ZFS} receive ${FULL_ZVOL_NAME2}) || fail 12
517 wait_udev /dev/${FULL_ZVOL_NAME2}1 30 || fail 12
519 # Mount the sent ext3 filesystem.
520 mkdir -p /tmp/${FULL_ZVOL_NAME2}1 || fail 13
521 mount /dev/${FULL_ZVOL_NAME2}1 /tmp/${FULL_ZVOL_NAME2}1 || fail 14
523 # Verify the contents of the volumes match
524 diff -ur /tmp/${FULL_ZVOL_NAME1}1 /tmp/${FULL_ZVOL_NAME2}1 \
525 &>/dev/null || fail 15
527 # Umount, destroy the volume and pool.
528 umount /tmp/${FULL_ZVOL_NAME1}1 || fail 16
529 umount /tmp/${FULL_ZVOL_NAME2}1 || fail 17
530 rmdir /tmp/${FULL_ZVOL_NAME1}1 || fail 18
531 rmdir /tmp/${FULL_ZVOL_NAME2}1 || fail 19
532 rmdir /tmp/${POOL_NAME1} || fail 20
533 rmdir /tmp/${POOL_NAME2} || fail 21
535 ${ZFS} destroy ${FULL_SNAP_NAME1} || fail 22
536 ${ZFS} destroy ${FULL_SNAP_NAME2} || fail 23
537 ${ZFS} destroy ${FULL_ZVOL_NAME1} || fail 24
538 ${ZFS} destroy ${FULL_ZVOL_NAME2} || fail 25
539 ${ZPOOL_CREATE_SH} -p ${POOL_NAME1} -c lo-raidz2 -d || fail 26
540 ${ZPOOL_CREATE_SH} -p ${POOL_NAME2} -c lo-raidz2 -d || fail 27
541 ${ZFS_SH} -u || fail 28
542 rm -f ${TMP_CACHE} || fail 29
546 run_test 8 "zfs send/receive"
548 # zpool event sanity check
552 local FULL_NAME=${POOL_NAME}/${ZVOL_NAME}
553 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
554 local TMP_EVENTS=`mktemp -p /tmp zpool.events.XXXXXXXX`
556 # Create a pool and volume.
557 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
558 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
559 ${ZFS} create -V 300M ${FULL_NAME} || fail 3
561 # Dump the events, there should be at least 5 lines.
562 ${ZPOOL} events >${TMP_EVENTS} || fail 4
563 EVENTS=`wc -l ${TMP_EVENTS} | cut -f1 -d' '`
564 [ $EVENTS -lt 5 ] && fail 5
566 # Clear the events and ensure there are none.
567 ${ZPOOL} events -c >/dev/null || fail 6
568 ${ZPOOL} events >${TMP_EVENTS} || fail 7
569 EVENTS=`wc -l ${TMP_EVENTS} | cut -f1 -d' '`
570 [ $EVENTS -gt 1 ] && fail 8
572 ${ZFS} destroy ${FULL_NAME} || fail 9
573 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 10
574 ${ZFS_SH} -u || fail 11
575 rm -f ${TMP_CACHE} || fail 12
576 rm -f ${TMP_EVENTS} || fail 13
580 run_test 9 "zpool events"
586 local TMP_FILE1=`mktemp`
587 local TMP_FILE2=`mktemp`
588 local TMP_FILE3=`mktemp`
590 BASE_DEVICE=`basename ${DEVICE}`
592 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1}
593 ${ZPOOL} add -f ${POOL_NAME} ${TYPE} ${DEVICE} 2>/dev/null || return 1
594 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2}
595 diff ${TMP_FILE1} ${TMP_FILE2} > ${TMP_FILE3}
597 [ `wc -l ${TMP_FILE3}|${AWK} '{print $1}'` -eq 3 ] || return 1
599 PARENT_VDEV=`tail -2 ${TMP_FILE3} | head -1 | ${AWK} '{print $NF}'`
602 [ "${PARENT_VDEV}" = "${TYPE}" ] || return 1
605 [ "${PARENT_VDEV}" = "logs" ] || return 1
609 if ! tail -1 ${TMP_FILE3} |
610 egrep -q "^>[[:space:]]+${BASE_DEVICE}[[:space:]]+ONLINE" ; then
613 rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_FILE3}
618 # zpool add and remove sanity check
621 local TMP_CACHE=`mktemp -p /tmp zpool.cache.XXXXXXXX`
622 local TMP_FILE1=`mktemp`
623 local TMP_FILE2=`mktemp`
625 if [ ${SCSI_DEBUG} -eq 0 ] || [ ${HAVE_LSSCSI} -eq 0 ] ; then
630 test `${LSMOD} | grep -c scsi_debug` -gt 0 && \
631 (${RMMOD} scsi_debug || exit 1)
633 /sbin/modprobe scsi_debug dev_size_mb=128 ||
634 die "Error $? creating scsi_debug device"
637 SDDEVICE=`${LSSCSI}|${AWK} '/scsi_debug/ { print $6; exit }'`
638 BASE_SDDEVICE=`basename $SDDEVICE`
641 ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 1
642 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 || fail 2
643 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE1} || fail 3
645 # Add and remove a cache vdev by full path
646 zconfig_add_vdev ${POOL_NAME} cache ${SDDEVICE} || fail 4
647 ${ZPOOL} remove ${POOL_NAME} ${SDDEVICE} || fail 5
648 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 6
649 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 7
651 # Add and remove a cache vdev by shorthand path
652 zconfig_add_vdev ${POOL_NAME} cache ${BASE_SDDEVICE} || fail 8
653 ${ZPOOL} remove ${POOL_NAME} ${BASE_SDDEVICE} || fail 9
654 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 10
655 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 11
657 # Add and remove a log vdev
658 zconfig_add_vdev ${POOL_NAME} log ${BASE_SDDEVICE} || fail 12
659 ${ZPOOL} remove ${POOL_NAME} ${BASE_SDDEVICE} || fail 13
660 ${ZPOOL} status ${POOL_NAME} >${TMP_FILE2} || fail 14
661 cmp ${TMP_FILE1} ${TMP_FILE2} || fail 15
663 ${ZPOOL_CREATE_SH} -p ${POOL_NAME} -c lo-raidz2 -d || fail 16
664 ${ZFS_SH} -u || fail 17
665 ${RMMOD} scsi_debug || fail 18
667 rm -f ${TMP_FILE1} ${TMP_FILE2} ${TMP_CACHE} || fail 19
671 run_test 10 "zpool add/remove vdev"