1#!/bin/bash 2# 3# Test case for ejecting a BlockBackend with an NBD server attached to it 4# 5# Verify that the NBD server stops offering the drive when ejecting a 6# BlockDriverState tree from a BlockBackend (that is, a medium from a 7# drive) exposed via an NBD server. 8# 9# Copyright (C) 2016 Red Hat, Inc. 10# 11# This program is free software; you can redistribute it and/or modify 12# it under the terms of the GNU General Public License as published by 13# the Free Software Foundation; either version 2 of the License, or 14# (at your option) any later version. 15# 16# This program is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU General Public License for more details. 20# 21# You should have received a copy of the GNU General Public License 22# along with this program. If not, see <http://www.gnu.org/licenses/>. 23# 24 25# creator 26owner=mreitz@redhat.com 27 28seq="$(basename $0)" 29echo "QA output created by $seq" 30 31here="$PWD" 32status=1 # failure is the default! 33 34_cleanup() 35{ 36 _cleanup_qemu 37 _cleanup_test_img 38 rm -f "$TEST_DIR/nbd" 39} 40trap "_cleanup; exit \$status" 0 1 2 3 15 41 42# get standard environment, filters and checks 43. ./common.rc 44. ./common.filter 45. ./common.qemu 46 47_supported_fmt generic 48_supported_proto file 49_supported_os Linux 50 51_make_test_img 64k 52 53$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io 54 55keep_stderr=y \ 56_launch_qemu -drive if=none,media=cdrom,id=drv,file="$TEST_IMG",format=$IMGFMT \ 57 2> >(_filter_nbd) 58 59_send_qemu_cmd $QEMU_HANDLE \ 60 "{ 'execute': 'qmp_capabilities' }" \ 61 'return' 62 63_send_qemu_cmd $QEMU_HANDLE \ 64 "{ 'execute': 'nbd-server-start', 65 'arguments': { 'addr': { 'type': 'unix', 66 'data': { 'path': '$TEST_DIR/nbd' }}}}" \ 67 'return' 68 69_send_qemu_cmd $QEMU_HANDLE \ 70 "{ 'execute': 'nbd-server-add', 71 'arguments': { 'device': 'drv' }}" \ 72 'return' 73 74$QEMU_IO_PROG -f raw -c 'read -P 42 0 64k' \ 75 "nbd+unix:///drv?socket=$TEST_DIR/nbd" 2>&1 \ 76 | _filter_qemu_io | _filter_nbd 77 78_send_qemu_cmd $QEMU_HANDLE \ 79 "{ 'execute': 'eject', 80 'arguments': { 'device': 'drv' }}" \ 81 'return' 82 83$QEMU_IO_PROG -f raw -c close \ 84 "nbd+unix:///drv?socket=$TEST_DIR/nbd" 2>&1 \ 85 | _filter_qemu_io | _filter_nbd 86 87_send_qemu_cmd $QEMU_HANDLE \ 88 "{ 'execute': 'quit' }" \ 89 'return' 90 91wait=1 _cleanup_qemu 92 93# success, all done 94echo '*** done' 95rm -f $seq.full 96status=0 97