]> granicus.if.org Git - zfs/blob - tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_wholedisk.ksh
zpool: allow split with whole-disk devices
[zfs] / tests / zfs-tests / tests / functional / cli_root / zpool_split / zpool_split_wholedisk.ksh
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
20 #
21 # DESCRIPTION:
22 # 'zpool split' should work with whole-disk devices.
23 #
24 # STRATEGY:
25 # 1. Create a mirror with a whole-disk device
26 # 2. Verify 'zpool split' works and successfully split the mirror
27 # 3. Cleanup and create the same mirror
28 # 4. Verify 'zpool split' using the other device
29 #
30
31 verify_runnable "both"
32
33 if is_linux; then
34         # Add one 512b spare device (4Kn would generate IO errors on replace)
35         # NOTE: must be larger than other "file" vdevs and minimum SPA devsize:
36         # add 32m of fudge
37         load_scsi_debug $(($SPA_MINDEVSIZE/1024/1024+32)) 1 1 1 '512b'
38 else
39         log_unsupported "scsi debug module unsupported"
40 fi
41
42 function cleanup
43 {
44         destroy_pool $TESTPOOL
45         destroy_pool $TESTPOOL2
46         unload_scsi_debug
47         rm -f "$FILE_DEVICE"
48 }
49
50 function setup_mirror
51 {
52         # NOTE: "-f" is required to create a mixed (file and disk device) mirror
53         log_must truncate -s $SPA_MINDEVSIZE $FILE_DEVICE
54         log_must zpool create -f $TESTPOOL mirror $FILE_DEVICE $DISK_DEVICE
55         # NOTE: verify disk is actually a "whole-disk" device
56         log_must test  "$(zdb -PC $TESTPOOL | grep -c 'whole_disk: 1')" == 1
57 }
58
59 log_assert "'zpool split' should work with whole-disk devices"
60 log_onexit cleanup
61
62 FILE_DEVICE="$TEST_BASE_DIR/file-device"
63 DISK_DEVICE="$(get_debug_device)"
64 ALTROOT="$TEST_BASE_DIR/altroot-$TESTPOOL2"
65
66 # 1. Create a mirror with a whole-disk device
67 setup_mirror
68
69 # 2. Verify 'zpool split' works and successfully split the mirror
70 log_must zpool split -R "$ALTROOT" $TESTPOOL $TESTPOOL2 $DISK_DEVICE
71 log_must check_vdev_state $TESTPOOL $FILE_DEVICE "ONLINE"
72 log_must check_vdev_state $TESTPOOL2 $DISK_DEVICE "ONLINE"
73
74 # 3. Cleanup and create the same mirror
75 destroy_pool $TESTPOOL
76 destroy_pool $TESTPOOL2
77 setup_mirror
78
79 # 4. Verify 'zpool split' using the other device
80 log_must zpool split -R "$ALTROOT" $TESTPOOL $TESTPOOL2 $FILE_DEVICE
81 log_must check_vdev_state $TESTPOOL $DISK_DEVICE "ONLINE"
82 log_must check_vdev_state $TESTPOOL2 $FILE_DEVICE "ONLINE"
83
84 log_pass "'zpool split' works with whole-disk devices"