1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15#
16
17. $STF_SUITE/include/libtest.shlib
18. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg
19. $STF_SUITE/tests/functional/mmp/mmp.kshlib
20
21#
22# DESCRIPTION:
23# 'zpool split' can set new property values on the new pool
24#
25# STRATEGY:
26# 1. Create a mirror pool
27# 2. Verify 'zpool split' can set property values on the new pool, but only if
28#    they are valid.
29#
30
31verify_runnable "both"
32
33function cleanup
34{
35	destroy_pool $TESTPOOL
36	destroy_pool $TESTPOOL2
37	rm -f $DEVICE1 $DEVICE2
38	! is_freebsd && log_must mmp_clear_hostid
39}
40
41function setup_mirror
42{
43	truncate -s $SPA_MINDEVSIZE $DEVICE1
44	truncate -s $SPA_MINDEVSIZE $DEVICE2
45	log_must zpool create -f $TESTPOOL mirror $DEVICE1 $DEVICE2
46}
47
48log_assert "'zpool split' can set new property values on the new pool"
49log_onexit cleanup
50
51DEVICE1="$TEST_BASE_DIR/device-1"
52DEVICE2="$TEST_BASE_DIR/device-2"
53
54typeset good_props=('comment=text' 'ashift=12' 'multihost=on'
55    'listsnapshots=on' 'autoexpand=on' 'autoreplace=on'
56    'delegation=off' 'failmode=continue')
57typeset bad_props=("bootfs=$TESTPOOL2/bootfs" 'version=28' 'ashift=4'
58    'allocated=1234' 'capacity=5678' 'multihost=none'
59    'feature@async_destroy=disabled' 'feature@xxx_fake_xxx=enabled'
60    'propname=propval' 'readonly=on')
61if ! is_freebsd; then
62	good_props+=('multihost=on')
63	bad_props+=('multihost=none')
64	if [ -e $HOSTID_FILE ]; then
65		log_unsupported "System has existing $HOSTID_FILE file"
66	fi
67	# Needed to set multihost=on
68	log_must mmp_set_hostid $HOSTID1
69fi
70
71# Verify we can set a combination of valid property values on the new pool
72for prop in "${good_props[@]}"
73do
74	IFS='=' read -r propname propval <<<"$prop"
75	setup_mirror
76	log_must zpool split -o $prop $TESTPOOL $TESTPOOL2
77	log_must zpool import -N -d $TEST_BASE_DIR $TESTPOOL2
78	log_must test "$(get_pool_prop $propname $TESTPOOL2)" = "$propval"
79
80	destroy_pool $TESTPOOL
81	destroy_pool $TESTPOOL2
82	rm -f $DEVICE1 $DEVICE2
83done
84
85# Verify we cannot set invalid property values
86setup_mirror
87zfs create $TESTPOOL/bootfs
88for prop in "${bad_props[@]}"
89do
90	log_mustnot zpool split -o $prop $TESTPOOL $TESTPOOL2
91	log_mustnot zpool import -N -d $TEST_BASE_DIR $TESTPOOL2
92done
93
94log_pass "'zpool split' can set new property values on the new pool"
95