From: LOLi Date: Tue, 20 Nov 2018 18:22:53 +0000 (+0100) Subject: zpool: allow split with whole-disk devices X-Git-Tag: zfs-0.8.0-rc3~61 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0cd5c941d097ec170177e1a5f97f08ebd32eff85;p=zfs zpool: allow split with whole-disk devices This change allows 'zpool split' to work with whole-disk devices and updates the ZFS Test Suite with a new script to exercise this functionality. Reviewed by: Brian Behlendorf Signed-off-by: loli10K Closes #6643 Closes #8133 --- diff --git a/cmd/zpool/zpool_vdev.c b/cmd/zpool/zpool_vdev.c index 5134553a5..7ea9d7420 100644 --- a/cmd/zpool/zpool_vdev.c +++ b/cmd/zpool/zpool_vdev.c @@ -1286,7 +1286,7 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv) * symbolic link will be removed, partition table created, * and then block until udev creates the new link. */ - if (!is_exclusive || !is_spare(NULL, udevpath)) { + if (!is_exclusive && !is_spare(NULL, udevpath)) { char *devnode = strrchr(devpath, '/') + 1; ret = strncmp(udevpath, UDISK_ROOT, strlen(UDISK_ROOT)); diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 225e9bc8b..a4c6769db 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -440,7 +440,7 @@ tags = ['functional', 'cli_root', 'zpool_set'] [tests/functional/cli_root/zpool_split] tests = ['zpool_split_cliargs', 'zpool_split_devices', 'zpool_split_encryption', 'zpool_split_props', 'zpool_split_vdevs', - 'zpool_split_resilver'] + 'zpool_split_resilver', 'zpool_split_wholedisk'] tags = ['functional', 'cli_root', 'zpool_split'] [tests/functional/cli_root/zpool_status] diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_split/Makefile.am index b2a7fec10..d00f39d35 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/Makefile.am @@ -10,4 +10,8 @@ dist_pkgdata_SCRIPTS = \ zpool_split_encryption.ksh \ zpool_split_props.ksh \ zpool_split_vdevs.ksh \ - zpool_split_resilver.ksh + zpool_split_resilver.ksh \ + zpool_split_wholedisk.ksh + +dist_pkgdata_DATA = \ + zpool_split.cfg diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split.cfg new file mode 100644 index 000000000..5833a420c --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split.cfg @@ -0,0 +1,18 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2018, loli10K . All rights reserved. +# + +export DISKSARRAY=$DISKS +export DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}') +set_device_dir diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_cliargs.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_cliargs.ksh index 4a779a225..ae9ad1354 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_cliargs.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_cliargs.ksh @@ -15,6 +15,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg # # DESCRIPTION: diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_devices.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_devices.ksh index c9e9d807b..d64c30d5c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_devices.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_devices.ksh @@ -15,6 +15,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg # # DESCRIPTION: @@ -91,7 +92,7 @@ do # Verify "good" devices ended up in the new pool log_must poolexists $TESTPOOL2 for filedev in ${gooddevs[$i]}; do - log_must check_vdev_state $TESTPOOL2 $filedev "" + log_must check_vdev_state $TESTPOOL2 $filedev "ONLINE" done cleanup ((i = i + 1)) diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_encryption.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_encryption.ksh index dc686c73f..768466983 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_encryption.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_encryption.ksh @@ -15,6 +15,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg # # DESCRIPTION: diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_props.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_props.ksh index 6176adf8b..67dbed693 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_props.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_props.ksh @@ -15,6 +15,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg . $STF_SUITE/tests/functional/mmp/mmp.kshlib # diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_resilver.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_resilver.ksh index 4fa1d925e..ffc841f76 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_resilver.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_resilver.ksh @@ -15,6 +15,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg # # DESCRIPTION: diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh index a9a407f8e..b7ebe55cb 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh @@ -15,6 +15,7 @@ # . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg . $STF_SUITE/include/math.shlib # diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_wholedisk.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_wholedisk.ksh new file mode 100755 index 000000000..085856c42 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_wholedisk.ksh @@ -0,0 +1,84 @@ +#!/bin/ksh -p +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2018, loli10K . All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg + +# +# DESCRIPTION: +# 'zpool split' should work with whole-disk devices. +# +# STRATEGY: +# 1. Create a mirror with a whole-disk device +# 2. Verify 'zpool split' works and successfully split the mirror +# 3. Cleanup and create the same mirror +# 4. Verify 'zpool split' using the other device +# + +verify_runnable "both" + +if is_linux; then + # Add one 512b spare device (4Kn would generate IO errors on replace) + # NOTE: must be larger than other "file" vdevs and minimum SPA devsize: + # add 32m of fudge + load_scsi_debug $(($SPA_MINDEVSIZE/1024/1024+32)) 1 1 1 '512b' +else + log_unsupported "scsi debug module unsupported" +fi + +function cleanup +{ + destroy_pool $TESTPOOL + destroy_pool $TESTPOOL2 + unload_scsi_debug + rm -f "$FILE_DEVICE" +} + +function setup_mirror +{ + # NOTE: "-f" is required to create a mixed (file and disk device) mirror + log_must truncate -s $SPA_MINDEVSIZE $FILE_DEVICE + log_must zpool create -f $TESTPOOL mirror $FILE_DEVICE $DISK_DEVICE + # NOTE: verify disk is actually a "whole-disk" device + log_must test "$(zdb -PC $TESTPOOL | grep -c 'whole_disk: 1')" == 1 +} + +log_assert "'zpool split' should work with whole-disk devices" +log_onexit cleanup + +FILE_DEVICE="$TEST_BASE_DIR/file-device" +DISK_DEVICE="$(get_debug_device)" +ALTROOT="$TEST_BASE_DIR/altroot-$TESTPOOL2" + +# 1. Create a mirror with a whole-disk device +setup_mirror + +# 2. Verify 'zpool split' works and successfully split the mirror +log_must zpool split -R "$ALTROOT" $TESTPOOL $TESTPOOL2 $DISK_DEVICE +log_must check_vdev_state $TESTPOOL $FILE_DEVICE "ONLINE" +log_must check_vdev_state $TESTPOOL2 $DISK_DEVICE "ONLINE" + +# 3. Cleanup and create the same mirror +destroy_pool $TESTPOOL +destroy_pool $TESTPOOL2 +setup_mirror + +# 4. Verify 'zpool split' using the other device +log_must zpool split -R "$ALTROOT" $TESTPOOL $TESTPOOL2 $FILE_DEVICE +log_must check_vdev_state $TESTPOOL $DISK_DEVICE "ONLINE" +log_must check_vdev_state $TESTPOOL2 $FILE_DEVICE "ONLINE" + +log_pass "'zpool split' works with whole-disk devices"