xref: /openbmc/qemu/tests/qemu-iotests/240 (revision 99d423e5)
1#!/usr/bin/env bash
2#
3# Test hot plugging and unplugging with iothreads
4#
5# Copyright (C) 2019 Igalia, S.L.
6# Author: Alberto Garcia <berto@igalia.com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=berto@igalia.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
28status=1	# failure is the default!
29
30_cleanup()
31{
32    rm -f "$TEST_DIR/nbd"
33}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39
40_supported_fmt generic
41_supported_proto generic
42
43do_run_qemu()
44{
45    echo Testing: "$@"
46    $QEMU -nographic -qmp stdio -serial none "$@"
47    echo
48}
49
50# Remove QMP events from (pretty-printed) output. Doesn't handle
51# nested dicts correctly, but we don't get any of those in this test.
52_filter_qmp_events()
53{
54    tr '\n' '\t' | sed -e \
55	's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
56	| tr '\t' '\n'
57}
58
59run_qemu()
60{
61    do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events
62}
63
64case "$QEMU_DEFAULT_MACHINE" in
65  s390-ccw-virtio)
66      virtio_scsi=virtio-scsi-ccw
67      ;;
68  *)
69      virtio_scsi=virtio-scsi-pci
70      ;;
71esac
72
73echo
74echo === Unplug a SCSI disk and then plug it again ===
75echo
76
77run_qemu <<EOF
78{ "execute": "qmp_capabilities" }
79{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}}
80{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
81{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
82{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
83{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
84{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
85{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
86{ "execute": "device_del", "arguments": {"id": "scsi0"}}
87{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
88{ "execute": "quit"}
89EOF
90
91echo
92echo === Attach two SCSI disks using the same block device and the same iothread ===
93echo
94
95run_qemu <<EOF
96{ "execute": "qmp_capabilities" }
97{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
98{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
99{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
100{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
101{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}}
102{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
103{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
104{ "execute": "device_del", "arguments": {"id": "scsi0"}}
105{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
106{ "execute": "quit"}
107EOF
108
109echo
110echo === Attach two SCSI disks using the same block device but different iothreads ===
111echo
112
113run_qemu <<EOF
114{ "execute": "qmp_capabilities" }
115{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
116{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
117{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}}
118{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
119{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}}
120{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
121{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
122{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
123{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
124{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
125{ "execute": "device_del", "arguments": {"id": "scsi0"}}
126{ "execute": "device_del", "arguments": {"id": "scsi1"}}
127{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
128{ "execute": "quit"}
129EOF
130
131echo
132echo === Attach a SCSI disks using the same block device as a NBD server ===
133echo
134
135run_qemu <<EOF
136{ "execute": "qmp_capabilities" }
137{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
138{ "execute": "nbd-server-start", "arguments": {"addr":{"type":"unix","data":{"path":"$TEST_DIR/nbd"}}}}
139{ "execute": "nbd-server-add", "arguments": {"device":"hd0"}}
140{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
141{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
142{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
143{ "execute": "quit"}
144EOF
145
146# success, all done
147echo "*** done"
148rm -f $seq.full
149status=0
150