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