3 # Copyright (c) 2017 Spectra Logic Corporation
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions, and the following disclaimer,
11 # without modification.
12 # 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 # substantially similar to the "NO WARRANTY" disclaimer below
14 # ("Disclaimer") and any redistribution must be conditioned upon
15 # including a substantially similar Disclaimer requirement for further
16 # binary redistribution.
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGES.
35 # Routines that use gnop(8) to simulate devices that can disappear at any time
38 # Create a gnop device on top of a real device. Don't use the full extent; use
39 # a portion in the middle so that any ZFS label present on the real device
40 # won't be present on the gnop device and vice versa.
43 # Name of disk to use, with or without /dev/
45 # Optional physical path to use
47 # size of disk in bytes
49 # disk size, rounded down to multiple of 16384
50 typeset -li disk_size_rounded
51 # size of the nop device in bytes
53 # offset of the beginning of the nop device in bytes
54 typeset -li nop_offset
57 disk_size=`diskinfo $disk | cut -f 3`
58 # Round it down so the nop device will be 4k-aligned
59 disk_size_rounded=$(( ${disk_size} / 16384 * 16384 ))
60 nop_size=$(( ${disk_size_rounded} / 4 ))
61 nop_offset=${nop_size}
62 args="-s ${nop_size} -o ${nop_offset}"
63 if [ -n "$physpath" ]; then
64 args="$args -z $physpath"
67 gnop create ${args} ${disk}
70 # Create multiple gnop devices
75 create_gnop "$disk" || return 1
80 # Destroy a gnop device.
83 # Name of the underlying (non-gnop) device
86 # Use "-f" so we can destroy a gnop with a consumer (like ZFS)
87 gnop destroy -f ${disk}.nop
90 # Destroy multiple gnop devices. Attempt to destroy them all, ignoring errors
91 function destroy_gnops