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