4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
26 . $STF_SUITE/include/libtest.shlib
27 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
28 . $STF_SUITE/tests/functional/zvol/zvol_common.shlib
31 # Wait for udev to settle, completely.
32 # This is quite discomforting, but there's a race condition here
33 # (Amazon 2015.09 x86_64 Release (TEST) is good at triggering this) where the
34 # kernel tries to remove zvol device nodes while they're open by [blkid],
35 # [zvol_id] or other udev related processes.
36 # Calling 'udevadm settle' is not enough: wait for those processes "manually".
41 udevadm trigger --action=change
44 blkid="$(pgrep blkid | wc -l)"
45 zvol_id="$(pgrep zvol_id | wc -l)"
46 [[ "0" == "$zvol_id" && "0" == "$blkid" ]] && return
49 log_fail "Wait timeout reached for udev_wait"
53 # Clean up udev status
54 # This is also a problem on "Amazon 2015.09 x86_64 Release (TEST)" where udev,
55 # sometimes, does not clean up /dev/zvol symlinks correctly for removed ZVOLs.
56 # Prune those links manually, then tell udev to forget them.
60 log_note "Pruning broken ZVOL symlinks ..."
62 # find all dangling links and delete them
63 find -L "${ZVOL_DEVDIR}" -type l -print -delete
64 # purge those links from udev database
65 udevadm info --cleanup-db
69 # Verify $device exists and is a block device
71 function blockdev_exists # device
75 # we wait here instead of doing it in a wrapper around 'zfs set snapdev'
76 # because there are other commands (zfs snap, zfs inherit, zfs destroy)
77 # that can affect device nodes
80 [[ -b "$device" ]] && return 0
82 log_fail "$device does not exist as a block device"
86 # Verify $device does not exist
88 function blockdev_missing # device
92 # we wait here instead of doing it in a wrapper around 'zfs set snapdev'
93 # because there are other commands (zfs snap, zfs inherit, zfs destroy)
94 # that can affect device nodes
97 [[ ! -e "$device" ]] && return 0
99 log_fail "$device exists when not expected"
103 # Verify $property on $dataset is inherited by $parent and is set to $value
105 function verify_inherited # property value dataset parent
107 typeset property="$1"
112 typeset val=$(get_prop "$property" "$dataset")
113 typeset src=$(get_source "$property" "$dataset")
114 if [[ "$val" != "$value" || "$src" != "inherited from $parent" ]]; then
115 log_fail "Dataset $dataset did not inherit $property properly:"\
116 "expected=$value, value=$val, source=$src."
121 # Create a small partition on $device, then verify if we can access it
123 function verify_partition # device
127 if [[ ! -b "$device" ]]; then
128 log_fail "$device is not a block device"
130 # create a small dummy partition
131 set_partition 0 1 1m $device
132 # verify we can access the partition on the device
133 devname="$(readlink -f "$device")"
135 [[ -b "$devname""p1" ]]
137 [[ -b "$devname""s0" ]]