xref: /openbmc/qemu/tests/qemu-iotests/140 (revision 57284d2ada481fe557c9a2f00228eca2a83e1d60)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
216dee418SMax Reitz#
343e15ed4SSascha Silbe# Test case for ejecting a BlockBackend with an NBD server attached to it
443e15ed4SSascha Silbe#
543e15ed4SSascha Silbe# Verify that the NBD server stops offering the drive when ejecting a
643e15ed4SSascha Silbe# BlockDriverState tree from a BlockBackend (that is, a medium from a
743e15ed4SSascha Silbe# drive) exposed via an NBD server.
816dee418SMax Reitz#
916dee418SMax Reitz# Copyright (C) 2016 Red Hat, Inc.
1016dee418SMax Reitz#
1116dee418SMax Reitz# This program is free software; you can redistribute it and/or modify
1216dee418SMax Reitz# it under the terms of the GNU General Public License as published by
1316dee418SMax Reitz# the Free Software Foundation; either version 2 of the License, or
1416dee418SMax Reitz# (at your option) any later version.
1516dee418SMax Reitz#
1616dee418SMax Reitz# This program is distributed in the hope that it will be useful,
1716dee418SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
1816dee418SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1916dee418SMax Reitz# GNU General Public License for more details.
2016dee418SMax Reitz#
2116dee418SMax Reitz# You should have received a copy of the GNU General Public License
2216dee418SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2316dee418SMax Reitz#
2416dee418SMax Reitz
2516dee418SMax Reitz# creator
2616dee418SMax Reitzowner=mreitz@redhat.com
2716dee418SMax Reitz
2816dee418SMax Reitzseq="$(basename $0)"
2916dee418SMax Reitzecho "QA output created by $seq"
3016dee418SMax Reitz
3116dee418SMax Reitzstatus=1	# failure is the default!
3216dee418SMax Reitz
3316dee418SMax Reitz_cleanup()
3416dee418SMax Reitz{
35ecfa1854SJeff Cody    _cleanup_qemu
3616dee418SMax Reitz    _cleanup_test_img
3746cabce6SMax Reitz    rm -f "$SOCK_DIR/nbd"
3816dee418SMax Reitz}
3916dee418SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
4016dee418SMax Reitz
4116dee418SMax Reitz# get standard environment, filters and checks
4216dee418SMax Reitz. ./common.rc
4316dee418SMax Reitz. ./common.filter
4416dee418SMax Reitz. ./common.qemu
4516dee418SMax Reitz
4616dee418SMax Reitz_supported_fmt generic
47*57284d2aSMax Reitz_supported_proto file fuse
4816dee418SMax Reitz_supported_os Linux
4916dee418SMax Reitz
5016dee418SMax Reitz_make_test_img 64k
5116dee418SMax Reitz
5216dee418SMax Reitz$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
5316dee418SMax Reitz
5413a1d4a7SDaniel P. Berrangeif test "$IMGOPTSSYNTAX" = "true"
5513a1d4a7SDaniel P. Berrangethen
5613a1d4a7SDaniel P. Berrange    SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,"$TEST_IMG"
5713a1d4a7SDaniel P. Berrangeelse
5813a1d4a7SDaniel P. Berrange    SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,file="$TEST_IMG",driver=$IMGFMT
5913a1d4a7SDaniel P. Berrangefi
6013a1d4a7SDaniel P. Berrange
6116dee418SMax Reitzkeep_stderr=y \
6213a1d4a7SDaniel P. Berrange_launch_qemu -drive $SYSEMU_DRIVE_ARG \
6316dee418SMax Reitz    2> >(_filter_nbd)
6416dee418SMax Reitz
6516dee418SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
6616dee418SMax Reitz    "{ 'execute': 'qmp_capabilities' }" \
6716dee418SMax Reitz    'return'
6816dee418SMax Reitz
6916dee418SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
7016dee418SMax Reitz    "{ 'execute': 'nbd-server-start',
7116dee418SMax Reitz       'arguments': { 'addr': { 'type': 'unix',
7246cabce6SMax Reitz                                'data': { 'path': '$SOCK_DIR/nbd' }}}}" \
7316dee418SMax Reitz    'return'
7416dee418SMax Reitz
7516dee418SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
7616dee418SMax Reitz    "{ 'execute': 'nbd-server-add',
7716dee418SMax Reitz       'arguments': { 'device': 'drv' }}" \
7816dee418SMax Reitz    'return'
7916dee418SMax Reitz
801104d83cSEric Blake$QEMU_IO_PROG -f raw -r -c 'read -P 42 0 64k' \
8146cabce6SMax Reitz    "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
8216dee418SMax Reitz    | _filter_qemu_io | _filter_nbd
8316dee418SMax Reitz
841a9f7a80SKevin Wolf# The order of 'return' and the BLOCK_EXPORT_DELETED event is undefined. Just
851a9f7a80SKevin Wolf# wait until we've twice seen one of them. Filter the 'return' line out so that
861a9f7a80SKevin Wolf# the output is defined.
8716dee418SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
8816dee418SMax Reitz    "{ 'execute': 'eject',
8916dee418SMax Reitz       'arguments': { 'device': 'drv' }}" \
901a9f7a80SKevin Wolf    'return\|BLOCK_EXPORT_DELETED' |
911a9f7a80SKevin Wolf    grep -v 'return'
921a9f7a80SKevin Wolf
931a9f7a80SKevin Wolf_send_qemu_cmd $QEMU_HANDLE '' 'return\|BLOCK_EXPORT_DELETED' |
941a9f7a80SKevin Wolf    grep -v 'return'
9516dee418SMax Reitz
961104d83cSEric Blake$QEMU_IO_PROG -f raw -r -c close \
9746cabce6SMax Reitz    "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
9816dee418SMax Reitz    | _filter_qemu_io | _filter_nbd
9916dee418SMax Reitz
10016dee418SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
10116dee418SMax Reitz    "{ 'execute': 'quit' }" \
10216dee418SMax Reitz    'return'
10316dee418SMax Reitz
10416dee418SMax Reitzwait=1 _cleanup_qemu
10516dee418SMax Reitz
10616dee418SMax Reitz# success, all done
10716dee418SMax Reitzecho '*** done'
10816dee418SMax Reitzrm -f $seq.full
10916dee418SMax Reitzstatus=0
110