6 # Copyright (C) 2018-2020 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 echo "QA output created by $seq"
25 status
=1 # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # get standard environment, filters and checks
42 _require_command QEMU_NBD
45 echo "=== Initial image setup ==="
48 TEST_IMG
="$TEST_IMG.base" _make_test_img
4M
49 $QEMU_IO -c 'w 0 2M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io
50 _make_test_img
-b "$TEST_IMG.base" -F $IMGFMT 4M
51 $QEMU_IO -c 'w 1M 2M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
54 echo "=== Check allocation over NBD ==="
57 $QEMU_IMG map
--output=json
-f qcow2
"$TEST_IMG"
58 IMG
="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
59 nbd_server_start_unix_socket
-r -f qcow2
-A "$TEST_IMG"
60 # Normal -f raw NBD block status loses access to allocation information
61 $QEMU_IMG map
--output=json
--image-opts \
62 "$IMG" | _filter_qemu_img_map
63 # But when we use -A, coupled with x-dirty-bitmap in the client for feeding
64 # 2-bit block status from an alternative NBD metadata context (note that
65 # the client code for x-dirty-bitmap intentionally collapses all depths
66 # beyond 2 into a single value), we can determine:
67 # unallocated (depth 0) => "zero":false, "data":true
68 # local (depth 1) => "zero":false, "data":false
69 # backing (depth 2+) => "zero":true, "data":true
70 $QEMU_IMG map
--output=json
--image-opts \
71 "$IMG,x-dirty-bitmap=qemu:allocation-depth" | _filter_qemu_img_map
72 # More accurate results can be obtained by other NBD clients such as
73 # libnbd, but this test works without such external dependencies.