3 # Copyright (C) 2018-2020 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # Demonstrate a fix for a bug where blocksize used to cause extents failures
41 requires nbdsh
--base-allocation
43 # Script a server that requires 512-byte aligned requests, reports only one
44 # extent at a time, and with a hole placed unaligned to 4k bounds
46 if test $3 -gt $(( 32 * 1024 )); then
47 echo "EINVAL request too large" 2>&1
50 if test $(( ($3|$4) & 511 )) != 0; then
51 echo "EINVAL request unaligned" 2>&1
55 if test $(( $4 >= 512 && $4 < 8 * 1024 )) = 1; then
61 # We also need an nbdsh script to parse all extents, coalescing adjacent
62 # types for simplicity, as well as testing some unaligned probes.
67 def f(metacontext, offset, e, err):
71 for length, flags in zip(*[iter(e)] * 2):
72 if entries and flags == entries[-1][1]:
73 entries[-1] = (entries[-1][0] + length, flags)
75 entries.append((length, flags))
78 # Test a loop over the entire device
80 h.block_status(size - offs, offs, f)
81 assert entries == [(4096, 0), (4096, 3), (57344, 0)]
83 # Unaligned status queries must also work
86 h.block_status(1, offs, f, nbd.CMD_FLAG_REQ_ONE)
87 assert entries == [(1, 0)]
91 h.block_status(512, offs, f)
92 assert entries == [(3584, 0)]
97 h.block_status(4097 - offs, offs, f, nbd.CMD_FLAG_REQ_ONE)
98 assert entries == [(1, 0), (1, 3)]
102 nbdkit
-U - --filter=blocksize
eval minblock
=4k maxlen
=32k \
103 get_size
='echo 64k' pread
='exit 1' extents
="$exts" \
104 --run 'nbdsh --base-allocation -u "$uri" -c "$script"'