Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 2 | # |
Sascha Silbe | 43e15ed | 2016-02-18 21:37:33 +0100 | [diff] [blame] | 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. |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 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 |
| 26 | owner=mreitz@redhat.com |
| 27 | |
| 28 | seq="$(basename $0)" |
| 29 | echo "QA output created by $seq" |
| 30 | |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 31 | status=1 # failure is the default! |
| 32 | |
| 33 | _cleanup() |
| 34 | { |
Jeff Cody | ecfa185 | 2017-04-18 15:42:41 -0400 | [diff] [blame] | 35 | _cleanup_qemu |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 36 | _cleanup_test_img |
Max Reitz | 46cabce | 2019-10-17 15:31:39 +0200 | [diff] [blame] | 37 | rm -f "$SOCK_DIR/nbd" |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 38 | } |
| 39 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 40 | |
| 41 | # get standard environment, filters and checks |
| 42 | . ./common.rc |
| 43 | . ./common.filter |
| 44 | . ./common.qemu |
| 45 | |
| 46 | _supported_fmt generic |
| 47 | _supported_proto file |
| 48 | _supported_os Linux |
| 49 | |
| 50 | _make_test_img 64k |
| 51 | |
| 52 | $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io |
| 53 | |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 54 | if test "$IMGOPTSSYNTAX" = "true" |
| 55 | then |
| 56 | SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,"$TEST_IMG" |
| 57 | else |
| 58 | SYSEMU_DRIVE_ARG=if=none,media=cdrom,id=drv,file="$TEST_IMG",driver=$IMGFMT |
| 59 | fi |
| 60 | |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 61 | keep_stderr=y \ |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 62 | _launch_qemu -drive $SYSEMU_DRIVE_ARG \ |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 63 | 2> >(_filter_nbd) |
| 64 | |
| 65 | _send_qemu_cmd $QEMU_HANDLE \ |
| 66 | "{ 'execute': 'qmp_capabilities' }" \ |
| 67 | 'return' |
| 68 | |
| 69 | _send_qemu_cmd $QEMU_HANDLE \ |
| 70 | "{ 'execute': 'nbd-server-start', |
| 71 | 'arguments': { 'addr': { 'type': 'unix', |
Max Reitz | 46cabce | 2019-10-17 15:31:39 +0200 | [diff] [blame] | 72 | 'data': { 'path': '$SOCK_DIR/nbd' }}}}" \ |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 73 | 'return' |
| 74 | |
| 75 | _send_qemu_cmd $QEMU_HANDLE \ |
| 76 | "{ 'execute': 'nbd-server-add', |
| 77 | 'arguments': { 'device': 'drv' }}" \ |
| 78 | 'return' |
| 79 | |
Eric Blake | 1104d83 | 2017-11-08 15:56:58 -0600 | [diff] [blame] | 80 | $QEMU_IO_PROG -f raw -r -c 'read -P 42 0 64k' \ |
Max Reitz | 46cabce | 2019-10-17 15:31:39 +0200 | [diff] [blame] | 81 | "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \ |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 82 | | _filter_qemu_io | _filter_nbd |
| 83 | |
| 84 | _send_qemu_cmd $QEMU_HANDLE \ |
| 85 | "{ 'execute': 'eject', |
| 86 | 'arguments': { 'device': 'drv' }}" \ |
| 87 | 'return' |
| 88 | |
Eric Blake | 1104d83 | 2017-11-08 15:56:58 -0600 | [diff] [blame] | 89 | $QEMU_IO_PROG -f raw -r -c close \ |
Max Reitz | 46cabce | 2019-10-17 15:31:39 +0200 | [diff] [blame] | 90 | "nbd+unix:///drv?socket=$SOCK_DIR/nbd" 2>&1 \ |
Max Reitz | 16dee41 | 2016-01-29 16:36:02 +0100 | [diff] [blame] | 91 | | _filter_qemu_io | _filter_nbd |
| 92 | |
| 93 | _send_qemu_cmd $QEMU_HANDLE \ |
| 94 | "{ 'execute': 'quit' }" \ |
| 95 | 'return' |
| 96 | |
| 97 | wait=1 _cleanup_qemu |
| 98 | |
| 99 | # success, all done |
| 100 | echo '*** done' |
| 101 | rm -f $seq.full |
| 102 | status=0 |