3 # Copyright (C) 2018-2019 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
38 requires qemu-img
--version
39 requires qemu-img map
--help
41 out
="test-sh-extents.out"
42 expected
="test-sh-extents.expected"
43 files
="$out $expected"
45 cleanup_fn
rm -f $files
49 # We use jq to normalize the output and convert it to plain text.
50 nbdkit
-v -U - sh
- --run 'qemu-img map -f raw --output=json $nbd' |
51 jq
-c '.[] | {start:.start, length:.length, data:.data, zero:.zero}' \
53 if ! cmp $out $expected; then
54 echo "$0: output did not match expected data"
63 # Completely sparse disk.
64 cat > $expected <<'EOF'
65 {"start":0,"length":65536,"data":false,"zero":true}
69 thread_model) echo parallel ;;
71 can_extents) exit 0 ;;
73 echo "0 64K hole,zero"
79 # Completely allocated disk.
80 # type field missing means allocated data.
81 cat > $expected <<'EOF'
82 {"start":0,"length":65536,"data":true,"zero":false}
86 thread_model) echo parallel ;;
88 can_extents) exit 0 ;;
96 # Completely allocated disk.
98 cat > $expected <<'EOF'
99 {"start":0,"length":65536,"data":true,"zero":false}
103 thread_model) echo parallel ;;
104 get_size) echo 64K ;;
105 can_extents) exit 0 ;;
113 # Allocated data at the start of a 1M disk.
114 cat > $expected <<'EOF'
115 {"start":0,"length":32768,"data":true,"zero":false}
116 {"start":32768,"length":1015808,"data":false,"zero":true}
120 thread_model) echo parallel ;;
122 can_extents) exit 0 ;;
125 echo "32K 1015808 hole,zero"
131 # Zeroes at the start of a 1M disk.
132 cat > $expected <<'EOF'
133 {"start":0,"length":32768,"data":true,"zero":true}
134 {"start":32768,"length":32768,"data":false,"zero":true}
135 {"start":65536,"length":983040,"data":true,"zero":false}
139 thread_model) echo parallel ;;
141 can_extents) exit 0 ;;
144 echo "32K 32K hole,zero"
151 # If can_extents is not defined, extents should never be called.
152 cat > $expected <<'EOF'
153 {"start":0,"length":65536,"data":true,"zero":false}
157 thread_model) echo parallel ;;
158 get_size) echo 64K ;;