]>
Commit | Line | Data |
---|---|---|
16dee418 HR |
1 | #!/bin/bash |
2 | # | |
43e15ed4 SS |
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. | |
16dee418 HR |
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 | [email protected] | |
27 | ||
28 | seq="$(basename $0)" | |
29 | echo "QA output created by $seq" | |
30 | ||
31 | here="$PWD" | |
16dee418 HR |
32 | status=1 # failure is the default! |
33 | ||
34 | _cleanup() | |
35 | { | |
36 | _cleanup_test_img | |
37 | rm -f "$TEST_DIR/nbd" | |
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 | ||
54 | keep_stderr=y \ | |
4b84fc70 | 55 | _launch_qemu -drive if=none,media=cdrom,id=drv,file="$TEST_IMG",format=$IMGFMT \ |
16dee418 HR |
56 | 2> >(_filter_nbd) |
57 | ||
58 | _send_qemu_cmd $QEMU_HANDLE \ | |
59 | "{ 'execute': 'qmp_capabilities' }" \ | |
60 | 'return' | |
61 | ||
62 | _send_qemu_cmd $QEMU_HANDLE \ | |
63 | "{ 'execute': 'nbd-server-start', | |
64 | 'arguments': { 'addr': { 'type': 'unix', | |
65 | 'data': { 'path': '$TEST_DIR/nbd' }}}}" \ | |
66 | 'return' | |
67 | ||
68 | _send_qemu_cmd $QEMU_HANDLE \ | |
69 | "{ 'execute': 'nbd-server-add', | |
70 | 'arguments': { 'device': 'drv' }}" \ | |
71 | 'return' | |
72 | ||
73 | $QEMU_IO_PROG -f raw -c 'read -P 42 0 64k' \ | |
74 | "nbd+unix:///drv?socket=$TEST_DIR/nbd" 2>&1 \ | |
75 | | _filter_qemu_io | _filter_nbd | |
76 | ||
77 | _send_qemu_cmd $QEMU_HANDLE \ | |
78 | "{ 'execute': 'eject', | |
79 | 'arguments': { 'device': 'drv' }}" \ | |
80 | 'return' | |
81 | ||
82 | $QEMU_IO_PROG -f raw -c close \ | |
83 | "nbd+unix:///drv?socket=$TEST_DIR/nbd" 2>&1 \ | |
84 | | _filter_qemu_io | _filter_nbd | |
85 | ||
86 | _send_qemu_cmd $QEMU_HANDLE \ | |
87 | "{ 'execute': 'quit' }" \ | |
88 | 'return' | |
89 | ||
90 | wait=1 _cleanup_qemu | |
91 | ||
92 | # success, all done | |
93 | echo '*** done' | |
94 | rm -f $seq.full | |
95 | status=0 |