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