1 #! /usr/bin/ksh -p
2 #
3 #
4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
7 # 1.0 of the CDDL.
8 #
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 #
13
14 #
15 # Copyright 2017 Nexenta Systems, Inc. All rights reserved.
16 #
17
18 . $STF_SUITE/tests/functional/wbc/wbc.cfg
19 . $STF_SUITE/tests/functional/wbc/wbc.kshlib
20
21 #
22 # DESCRIPTION:
23 # Special vdev cannot be removed from pool with enabled meta
24 # properties or active wbc feature flag. Error message should
25 # be more descriptive and precise.
26 #
27 # STRATEGY:
28 # 1. Create pool with mirrored special device.
29 # 2. Try to remove redundant device from special vdev.
30 # 3. Verify that 'zpool remove' fails and issue valid error message.
31 # 4. Create child filesystem.
32 # 5. Enable wbc for given filesystem.
33 # 6. Write random data into given filesystem.
34 # 7. Try to remove mirrored special device.
35 # 8. Verify that 'zpool remove' fails and issue valid error message.
36 # 9. Destroy given filesystem.
37 # 10. Enable meta properties to store pool metadata on special device.
38 # 11. Create child filesystem.
39 # 12. Write random data into given filesystem
40 # 13, Try to remove mirrored special device.
41 # 14. Verify that 'zpool remove' fails and issue valid error message.
42 #
43
44 typeset cfs="$TESTPOOL/fs.$$"
45 typeset err="/tmp/err.$$"
46 typeset disk="$SSD_DISK2"
47 typeset vdev="mirror-1"
48 typeset -A msg
49
50 msg[ENOTSUP]="cannot remove $disk: operation not supported on this type of pool"
51 msg[EBUSY]="cannot remove $vdev: wbc feature flag is active"
52 msg[EEXIST]="cannot remove $vdev: special device contains metadata"
53
54 function random_data
55 {
56 typeset dst=$1
57 typeset dir=$(get_prop mountpoint $dst)
58 typeset bs=$(get_random_recordsize)
59 typeset count=$(( RANDOM % 16 + 1 ))
60
61 if [[ -z "$dir" ]]; then
62 log_fail "unable to get mountpoint for '$dst'"
63 fi
64
65 log_must eval "dd if=/dev/urandom of=$dir/file.$$ bs=$bs count=$count"
66 }
67
68 verify_runnable "global"
69 log_assert "Verify that 'zpool remove' fails and issue valid error message."
70 log_onexit cleanup
71 log_must create_pool_special $TESTPOOL "none" "raidz" "mirror"
72 log_mustnot eval "zpool remove $TESTPOOL $disk 2>$err"
73 log_must grep "^${msg[ENOTSUP]}$" $err
74 log_must zfs create $cfs
75 log_must set_wbc_mode $cfs "on"
76 random_data $cfs
77 log_mustnot eval "zpool remove $TESTPOOL "$vdev" 2>$err"
78 log_must grep "^${msg[EBUSY]}$" $err
79 log_must zfs destroy -Rf $cfs
80 log_must zfs create $cfs
81 log_must zpool set meta_placement=on $TESTPOOL
82 log_must zpool set zfs_meta_to_metadev=on $TESTPOOL
83 random_data $cfs
84 log_mustnot eval "zpool remove $TESTPOOL "$vdev" 2>$err"
85 log_must grep "^${msg[EEXIST]}$" $err
86 log_must rm -f $err
87 log_must destroy_pool $TESTPOOL
88 log_pass "'zpool remove' fails as expected with valid error message."