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
39 requires qemu-img
--version
40 requires qemu-img map
--help
42 out
="test-sh-extents.out"
43 expected
="test-sh-extents.expected"
44 files
="$out $expected"
46 cleanup_fn
rm -f $files
50 # We use jq to normalize the output and convert it to plain text.
51 nbdkit
-v -U - sh
- --run 'qemu-img map -f raw --output=json $nbd' |
52 jq
-c '.[] | {start:.start, length:.length, data:.data, zero:.zero}' \
54 if ! cmp $out $expected; then
55 echo "$0: output did not match expected data"
64 # Completely sparse disk.
65 cat > $expected <<'EOF'
66 {"start":0,"length":65536,"data":false,"zero":true}
70 thread_model) echo parallel ;;
72 can_extents) exit 0 ;;
74 echo "0 64K hole,zero"
80 # Completely allocated disk.
81 # type field missing means allocated data.
82 cat > $expected <<'EOF'
83 {"start":0,"length":65536,"data":true,"zero":false}
87 thread_model) echo parallel ;;
89 can_extents) exit 0 ;;
97 # Completely allocated disk.
99 cat > $expected <<'EOF'
100 {"start":0,"length":65536,"data":true,"zero":false}
104 thread_model) echo parallel ;;
105 get_size) echo 64K ;;
106 can_extents) exit 0 ;;
114 # Allocated data at the start of a 1M disk.
115 cat > $expected <<'EOF'
116 {"start":0,"length":32768,"data":true,"zero":false}
117 {"start":32768,"length":1015808,"data":false,"zero":true}
121 thread_model) echo parallel ;;
123 can_extents) exit 0 ;;
126 echo "32K 1015808 hole,zero"
132 # Zeroes at the start of a 1M disk.
133 cat > $expected <<'EOF'
134 {"start":0,"length":32768,"data":true,"zero":true}
135 {"start":32768,"length":32768,"data":false,"zero":true}
136 {"start":65536,"length":983040,"data":true,"zero":false}
140 thread_model) echo parallel ;;
142 can_extents) exit 0 ;;
145 echo "32K 32K hole,zero"
152 # If can_extents is not defined, extents should never be called.
153 cat > $expected <<'EOF'
154 {"start":0,"length":65536,"data":true,"zero":false}
158 thread_model) echo parallel ;;
159 get_size) echo 64K ;;