Skip to content

Commit

Permalink
Add 'zpool split' coverage to the ZFS Test Suite
Browse files Browse the repository at this point in the history
This change adds five new tests to the ZTS:

 * zpool_split_cliargs: verify command line options and arguments
 * zpool_split_devices: verify zpool split accepts a device list
 * zpool_split_encryption: verify zpool can split encrypted pools
 * zpool_split_props: verify zpool split can set property values
 * zpool_split_vdevs: verify vdev layout when splitting the pool

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: loli10K <[email protected]>
Closes #7409
  • Loading branch information
loli10K authored and behlendorf committed Apr 12, 2018
1 parent 8111eb4 commit 7fab636
Show file tree
Hide file tree
Showing 12 changed files with 529 additions and 1 deletion.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/cli_root/zpool_replace/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_scrub/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_set/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_split/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_status/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_sync/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/Makefile
Expand Down
10 changes: 9 additions & 1 deletion lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot,
nvlist_t **varray = NULL, *zc_props = NULL;
uint_t c, children, newchildren, lastlog = 0, vcount, found = 0;
libzfs_handle_t *hdl = zhp->zpool_hdl;
uint64_t vers;
uint64_t vers, readonly = B_FALSE;
boolean_t freelist = B_FALSE, memory_err = B_TRUE;
int retval = 0;

Expand All @@ -3044,6 +3044,14 @@ zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot,
if ((zc_props = zpool_valid_proplist(hdl, zhp->zpool_name,
props, vers, flags, msg)) == NULL)
return (-1);
(void) nvlist_lookup_uint64(zc_props,
zpool_prop_to_name(ZPOOL_PROP_READONLY), &readonly);
if (readonly) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"property %s can only be set at import time"),
zpool_prop_to_name(ZPOOL_PROP_READONLY));
return (-1);
}
}

if (nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN, &child,
Expand Down
5 changes: 5 additions & 0 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg',
'zpool_set_ashift', 'zpool_set_features']
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']
tags = ['functional', 'cli_root', 'zpool_split']

[tests/functional/cli_root/zpool_status]
tests = ['zpool_status_001_pos', 'zpool_status_002_pos','zpool_status_003_pos',
'zpool_status_-c_disable', 'zpool_status_-c_homedir',
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/cli_root/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SUBDIRS = \
zpool_replace \
zpool_scrub \
zpool_set \
zpool_split \
zpool_status \
zpool_sync \
zpool_upgrade
12 changes: 12 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zpool_split/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include $(top_srcdir)/config/Rules.am

pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_split

dist_pkgdata_SCRIPTS = \
cleanup.ksh \
setup.ksh \
zpool_split_cliargs.ksh \
zpool_split_devices.ksh \
zpool_split_encryption.ksh \
zpool_split_props.ksh \
zpool_split_vdevs.ksh
19 changes: 19 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zpool_split/cleanup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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 <[email protected]>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

default_cleanup
17 changes: 17 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zpool_split/setup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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 <[email protected]>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/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 <[email protected]>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# 'zpool split' should only work with supported options and parameters.
#
# STRATEGY:
# 1. Verify every supported option is accepted
# 2. Verify other unsupported options raise an error
# 3. Verify we cannot split a pool if the destination already exists
#

verify_runnable "both"

function cleanup
{
destroy_pool $TESTPOOL
destroy_pool $TESTPOOL2
rm -f $DEVICE1 $DEVICE2 $DEVICE3
}

function setup_mirror
{
truncate -s $SPA_MINDEVSIZE $DEVICE1
truncate -s $SPA_MINDEVSIZE $DEVICE2
log_must zpool create -f $TESTPOOL mirror $DEVICE1 $DEVICE2
}

log_assert "'zpool split' should only work with supported options and parameters."
log_onexit cleanup

typeset goodopts=(
"" "-g" "-L" "-n" "-P" "-o comment=ok" "-o ro -R /mnt" "-l -R /mnt" "-gLnP")
typeset badopts=(
"-f" "-h" "-x" "-Pp" "-l" "-G" "-o" "-o ro" "-o comment" "-R" "-R dir" "=")

DEVICE1="$TEST_BASE_DIR/device-1"
DEVICE2="$TEST_BASE_DIR/device-2"
DEVICE3="$TEST_BASE_DIR/device-3"

# 1. Verify every supported option and/or parameter is accepted
for opt in "${goodopts[@]}"
do
setup_mirror
log_must zpool split $opt $TESTPOOL $TESTPOOL2
cleanup
done

# 2. Verify other unsupported options and/or parameters raise an error
setup_mirror
for opt in "${badopts[@]}"
do
log_mustnot zpool split $opt $TESTPOOL $TESTPOOL2
done
cleanup

# 3. Verify we cannot split a pool if the destination already exists
setup_mirror
truncate -s $SPA_MINDEVSIZE $DEVICE3
log_must zpool create $TESTPOOL2 $DEVICE3
log_mustnot zpool split $TESTPOOL $TESTPOOL2

log_pass "'zpool split' only works with supported options and parameters."
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/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 <[email protected]>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# 'zpool split' should use the provided devices to split the pool
#
# STRATEGY:
# 1. Create various (mirror-only) pools
# 2. Verify 'zpool split' can provide a list of devices to be included in the
# new pool. At most one disk from each mirror can be specified.
#

verify_runnable "both"

function cleanup
{
destroy_pool $TESTPOOL
destroy_pool $TESTPOOL2
rm -f $FILEDEV_PREFIX*
}

function setup_mirror # <conf>
{
for filedev in "${fd[@]}"; do
truncate -s $SPA_MINDEVSIZE "$filedev"
done
log_must zpool create -f $TESTPOOL $conf
}

log_assert "'zpool split' should use the provided devices to split the pool"
log_onexit cleanup

typeset altroot="$TESTDIR/altroot-$TESTPOOL2"
typeset FILEDEV_PREFIX="$TEST_BASE_DIR/filedev"
typeset -A fd
fd[01]="$FILEDEV_PREFIX-01"
fd[02]="$FILEDEV_PREFIX-02"
fd[03]="$FILEDEV_PREFIX-03"
fd[11]="$FILEDEV_PREFIX-11"
fd[12]="$FILEDEV_PREFIX-12"
fd[13]="$FILEDEV_PREFIX-13"

# Base pool configurations
typeset poolconfs=("mirror ${fd[01]} ${fd[02]}"
"mirror ${fd[01]} ${fd[02]} ${fd[03]}"
"mirror ${fd[01]} ${fd[02]} mirror ${fd[11]} ${fd[12]}"
"mirror ${fd[01]} ${fd[02]} ${fd[03]} mirror ${fd[11]} ${fd[12]}"
"mirror ${fd[01]} ${fd[02]} mirror ${fd[11]} ${fd[12]} ${fd[13]}"
"mirror ${fd[01]} ${fd[02]} ${fd[03]} mirror ${fd[11]} ${fd[12]} ${fd[13]}"
)
# "good" device specifications
typeset gooddevs=("${fd[01]}"
"${fd[02]}"
"${fd[02]} ${fd[11]}"
"${fd[12]}"
"${fd[02]}"
"${fd[03]} ${fd[12]}"
)
# "bad" device specifications
typeset baddevs=("${fd[01]} ${fd[02]}"
"${fd[02]} ${fd[03]}"
"${fd[02]} baddev"
"baddev ${fd[11]}"
"${fd[11]} ${fd[12]} ${fd[13]}"
"${fd[01]} ${fd[02]} ${fd[13]}"
)

typeset -i i=0;
while [ $i -lt "${#poolconfs[@]}" ]
do
typeset conf=${poolconfs[$i]}
setup_mirror $conf
log_mustnot zpool split $TESTPOOL $TESTPOOL2 ${baddevs[$i]}
log_must zpool split -R $altroot $TESTPOOL $TESTPOOL2 ${gooddevs[$i]}
# 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 ""
done
cleanup
((i = i + 1))
done

log_pass "'zpool split' can use the provided devices to split the pool"
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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 <[email protected]>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# 'zpool split' should be able to split encrypted pools
#
# STRATEGY:
# 1. Create an encrypted pool
# 2. Split and re-import the pool, verify altroot is mounted.
#

verify_runnable "both"

function cleanup
{
destroy_pool $TESTPOOL
destroy_pool $TESTPOOL2
rm -f $DEVICE1 $DEVICE2
}

log_assert "'zpool split' should be able to split encrypted pools"
log_onexit cleanup

DEVICE1="$TEST_BASE_DIR/device-1"
DEVICE2="$TEST_BASE_DIR/device-2"
passphrase="password"
altroot="$TESTDIR/zpool-split-$RANDOM"

# 1. Create an encrypted pool
truncate -s $SPA_MINDEVSIZE $DEVICE1
truncate -s $SPA_MINDEVSIZE $DEVICE2
log_must eval "echo "$passphrase" | zpool create -O encryption=aes-256-ccm " \
"-O keyformat=passphrase $TESTPOOL mirror $DEVICE1 $DEVICE2"

# 2. Split and re-import the pool, verify altroot is mounted.
log_must eval "echo "$passphrase" | zpool split -l -R $altroot " \
"$TESTPOOL $TESTPOOL2"
log_must test "$(get_prop 'encryption' $TESTPOOL2)" == "aes-256-ccm"
log_must test "$(get_pool_prop 'altroot' $TESTPOOL2)" == "$altroot"
log_must mounted $altroot/$TESTPOOL2

log_pass "'zpool split' can split encrypted pools"
Loading

0 comments on commit 7fab636

Please sign in to comment.