xref: /qemu/tests/qemu-iotests/241 (revision f3d07ce8f449986e9a5c30f2a9f124e2ad8b7c22)
1*f3d07ce8SThomas Huth#!/usr/bin/env bash
2e9dce9cbSEric Blake#
3e9dce9cbSEric Blake# Test qemu-nbd vs. unaligned images
4e9dce9cbSEric Blake#
5e9dce9cbSEric Blake# Copyright (C) 2018-2019 Red Hat, Inc.
6e9dce9cbSEric Blake#
7e9dce9cbSEric Blake# This program is free software; you can redistribute it and/or modify
8e9dce9cbSEric Blake# it under the terms of the GNU General Public License as published by
9e9dce9cbSEric Blake# the Free Software Foundation; either version 2 of the License, or
10e9dce9cbSEric Blake# (at your option) any later version.
11e9dce9cbSEric Blake#
12e9dce9cbSEric Blake# This program is distributed in the hope that it will be useful,
13e9dce9cbSEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of
14e9dce9cbSEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e9dce9cbSEric Blake# GNU General Public License for more details.
16e9dce9cbSEric Blake#
17e9dce9cbSEric Blake# You should have received a copy of the GNU General Public License
18e9dce9cbSEric Blake# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19e9dce9cbSEric Blake#
20e9dce9cbSEric Blake
21e9dce9cbSEric Blakeseq="$(basename $0)"
22e9dce9cbSEric Blakeecho "QA output created by $seq"
23e9dce9cbSEric Blake
24e9dce9cbSEric Blakestatus=1 # failure is the default!
25e9dce9cbSEric Blake
26e9dce9cbSEric Blakenbd_unix_socket=$TEST_DIR/test_qemu_nbd_socket
27e9dce9cbSEric Blake
28e9dce9cbSEric Blake_cleanup()
29e9dce9cbSEric Blake{
30e9dce9cbSEric Blake    _cleanup_test_img
319749636bSEric Blake    rm -f "$TEST_DIR/server.log"
32e9dce9cbSEric Blake    nbd_server_stop
33e9dce9cbSEric Blake}
34e9dce9cbSEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15
35e9dce9cbSEric Blake
36e9dce9cbSEric Blake# get standard environment, filters and checks
37e9dce9cbSEric Blake. ./common.rc
38e9dce9cbSEric Blake. ./common.filter
39e9dce9cbSEric Blake. ./common.nbd
40e9dce9cbSEric Blake
41e9dce9cbSEric Blake_supported_fmt raw
42e9dce9cbSEric Blake_supported_proto nbd
43e9dce9cbSEric Blake_supported_os Linux
44e9dce9cbSEric Blake_require_command QEMU_NBD
45e9dce9cbSEric Blake
46e9dce9cbSEric Blake# can't use _make_test_img, because qemu-img rounds image size up,
47e9dce9cbSEric Blake# and because we want to use Unix socket rather than TCP port. Likewise,
48e9dce9cbSEric Blake# we have to redirect TEST_IMG to our server.
49e9dce9cbSEric Blake# This tests that we can deal with the hole at the end of an unaligned
50e9dce9cbSEric Blake# raw file (either because the server doesn't advertise alignment too
51e9dce9cbSEric Blake# large, or because the client ignores the server's noncompliance - even
52e9dce9cbSEric Blake# though we can't actually wire iotests into checking trace messages).
53e9dce9cbSEric Blakeprintf %01000d 0 > "$TEST_IMG_FILE"
54e9dce9cbSEric BlakeTEST_IMG="nbd:unix:$nbd_unix_socket"
55e9dce9cbSEric Blake
56e9dce9cbSEric Blakeecho
57e9dce9cbSEric Blakeecho "=== Exporting unaligned raw image, natural alignment ==="
58e9dce9cbSEric Blakeecho
59e9dce9cbSEric Blake
60e9dce9cbSEric Blakenbd_server_start_unix_socket -f $IMGFMT "$TEST_IMG_FILE"
61e9dce9cbSEric Blake
62e9dce9cbSEric Blake$QEMU_NBD_PROG --list -k $nbd_unix_socket | grep '\(size\|min\)'
63e9dce9cbSEric Blake$QEMU_IMG map -f raw --output=json "$TEST_IMG" | _filter_qemu_img_map
64e9dce9cbSEric Blake$QEMU_IO -f raw -c map "$TEST_IMG"
65e9dce9cbSEric Blakenbd_server_stop
66e9dce9cbSEric Blake
67e9dce9cbSEric Blakeecho
68e9dce9cbSEric Blakeecho "=== Exporting unaligned raw image, forced server sector alignment ==="
69e9dce9cbSEric Blakeecho
70e9dce9cbSEric Blake
71e9dce9cbSEric Blake# Intentionally omit '-f' to force image probing, which in turn forces
72e9dce9cbSEric Blake# sector alignment, here at the server.
739749636bSEric Blakenbd_server_start_unix_socket "$TEST_IMG_FILE" 2> "$TEST_DIR/server.log"
74e9dce9cbSEric Blake
75e9dce9cbSEric Blake$QEMU_NBD_PROG --list -k $nbd_unix_socket | grep '\(size\|min\)'
76e9dce9cbSEric Blake$QEMU_IMG map -f raw --output=json "$TEST_IMG" | _filter_qemu_img_map
77e9dce9cbSEric Blake$QEMU_IO -f raw -c map "$TEST_IMG"
78e9dce9cbSEric Blakenbd_server_stop
799749636bSEric Blakecat "$TEST_DIR/server.log" | _filter_testdir
80e9dce9cbSEric Blake
81e9dce9cbSEric Blakeecho
82e9dce9cbSEric Blakeecho "=== Exporting unaligned raw image, forced client sector alignment ==="
83e9dce9cbSEric Blakeecho
84e9dce9cbSEric Blake
85e9dce9cbSEric Blake# Now force sector alignment at the client.
86e9dce9cbSEric Blakenbd_server_start_unix_socket -f $IMGFMT "$TEST_IMG_FILE"
87e9dce9cbSEric Blake
88e9dce9cbSEric Blake$QEMU_NBD_PROG --list -k $nbd_unix_socket | grep '\(size\|min\)'
89e9dce9cbSEric Blake$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
90e9dce9cbSEric Blake$QEMU_IO -c map "$TEST_IMG"
91e9dce9cbSEric Blakenbd_server_stop
92e9dce9cbSEric Blake
93e9dce9cbSEric Blake# Not tested yet: we also want to ensure that qemu as NBD client does
94e9dce9cbSEric Blake# not access beyond the end of a server's advertised unaligned size:
95e9dce9cbSEric Blake#  nbdkit -U - memory size=513 --run 'qemu-io -f raw -c "r 512 512" $nbd'
96e9dce9cbSEric Blake# However, since qemu as server always rounds up to a sector alignment,
97e9dce9cbSEric Blake# we would have to use nbdkit to provoke the current client failures.
98e9dce9cbSEric Blake
99e9dce9cbSEric Blake# success, all done
100e9dce9cbSEric Blakeecho '*** done'
101e9dce9cbSEric Blakerm -f $seq.full
102e9dce9cbSEric Blakestatus=0
103