hw/block/fdc: Kludge missing floppy drive to fix CVE-2021-20196
[qemu.git] / tests / qemu-iotests / 241
blobc962c8b6075d85e739ab34cac8c57900a1f3ea38
1 #!/usr/bin/env bash
2 # group: rw quick
4 # Test qemu-nbd vs. unaligned images
6 # Copyright (C) 2018-2019 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/>.
22 seq="$(basename $0)"
23 echo "QA output created by $seq"
25 status=1 # failure is the default!
27 _cleanup()
29 _cleanup_test_img
30 rm -f "$TEST_DIR/server.log"
31 nbd_server_stop
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.nbd
40 _supported_fmt raw
41 _supported_proto nbd
42 _supported_os Linux
43 _require_command QEMU_NBD
45 # can't use _make_test_img, because qemu-img rounds image size up,
46 # and because we want to use Unix socket rather than TCP port. Likewise,
47 # we have to redirect TEST_IMG to our server.
48 # This tests that we can deal with the hole at the end of an unaligned
49 # raw file (either because the server doesn't advertise alignment too
50 # large, or because the client ignores the server's noncompliance - even
51 # though we can't actually wire iotests into checking trace messages).
52 printf %01000d 0 > "$TEST_IMG_FILE"
53 TEST_IMG="nbd:unix:$nbd_unix_socket"
55 echo
56 echo "=== Exporting unaligned raw image, natural alignment ==="
57 echo
59 nbd_server_start_unix_socket -f $IMGFMT "$TEST_IMG_FILE"
61 $QEMU_NBD_PROG --list -k $nbd_unix_socket | grep '\(size\|min\)'
62 $QEMU_IMG map -f raw --output=json "$TEST_IMG" | _filter_qemu_img_map
63 $QEMU_IO -f raw -c map "$TEST_IMG"
64 nbd_server_stop
66 echo
67 echo "=== Exporting unaligned raw image, forced server sector alignment ==="
68 echo
70 # Intentionally omit '-f' to force image probing, which in turn forces
71 # sector alignment, here at the server.
72 nbd_server_start_unix_socket "$TEST_IMG_FILE" 2> "$TEST_DIR/server.log"
74 $QEMU_NBD_PROG --list -k $nbd_unix_socket | grep '\(size\|min\)'
75 $QEMU_IMG map -f raw --output=json "$TEST_IMG" | _filter_qemu_img_map
76 $QEMU_IO -f raw -c map "$TEST_IMG"
77 nbd_server_stop
78 cat "$TEST_DIR/server.log" | _filter_testdir
80 echo
81 echo "=== Exporting unaligned raw image, forced client sector alignment ==="
82 echo
84 # Now force sector alignment at the client.
85 nbd_server_start_unix_socket -f $IMGFMT "$TEST_IMG_FILE"
87 $QEMU_NBD_PROG --list -k $nbd_unix_socket | grep '\(size\|min\)'
88 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
89 $QEMU_IO -c map "$TEST_IMG"
90 nbd_server_stop
92 # Not tested yet: we also want to ensure that qemu as NBD client does
93 # not access beyond the end of a server's advertised unaligned size:
94 # nbdkit -U - memory size=513 --run 'qemu-io -f raw -c "r 512 512" $nbd'
95 # However, since qemu as server always rounds up to a sector alignment,
96 # we would have to use nbdkit to provoke the current client failures.
98 # success, all done
99 echo '*** done'
100 rm -f $seq.full
101 status=0