4 # Test case for ejecting a BlockBackend with an NBD server attached to it
6 # Verify that the NBD server stops offering the drive when ejecting a
7 # BlockDriverState tree from a BlockBackend (that is, a medium from a
8 # drive) exposed via an NBD server.
10 # Copyright (C) 2016 Red Hat, Inc.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 owner
=hreitz@redhat.com
30 echo "QA output created by $seq"
32 status
=1 # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # get standard environment, filters and checks
47 _supported_fmt generic
48 _supported_proto
file fuse
53 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
55 if test "$IMGOPTSSYNTAX" = "true"
57 SYSEMU_DRIVE_ARG
=if=none
,media
=cdrom
,id
=drv
,"$TEST_IMG"
59 SYSEMU_DRIVE_ARG
=if=none
,media
=cdrom
,id
=drv
,file="$TEST_IMG",driver
=$IMGFMT
63 _launch_qemu
-drive $SYSEMU_DRIVE_ARG \
66 _send_qemu_cmd
$QEMU_HANDLE \
67 "{ 'execute': 'qmp_capabilities' }" \
70 _send_qemu_cmd
$QEMU_HANDLE \
71 "{ 'execute': 'nbd-server-start',
72 'arguments': { 'addr': { 'type': 'unix',
73 'data': { 'path': '$SOCK_DIR/nbd' }}}}" \
76 _send_qemu_cmd
$QEMU_HANDLE \
77 "{ 'execute': 'nbd-server-add',
78 'arguments': { 'device': 'drv' }}" \
81 $QEMU_IO_PROG -f raw
-r -c 'read -P 42 0 64k' \
82 "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
83 | _filter_qemu_io | _filter_nbd
85 # The order of 'return' and the BLOCK_EXPORT_DELETED event is undefined. Just
86 # wait until we've twice seen one of them. Filter the 'return' line out so that
87 # the output is defined.
88 _send_qemu_cmd
$QEMU_HANDLE \
89 "{ 'execute': 'eject',
90 'arguments': { 'device': 'drv' }}" \
91 'return\|BLOCK_EXPORT_DELETED' |
94 _send_qemu_cmd
$QEMU_HANDLE '' 'return\|BLOCK_EXPORT_DELETED' |
97 $QEMU_IO_PROG -f raw
-r -c close \
98 "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \
99 | _filter_qemu_io | _filter_nbd
101 _send_qemu_cmd
$QEMU_HANDLE \
102 "{ 'execute': 'quit' }" \