1a6f230c8SAlberto Garcia#!/bin/bash 2a6f230c8SAlberto Garcia# 3a6f230c8SAlberto Garcia# Test hot plugging and unplugging with iothreads 4a6f230c8SAlberto Garcia# 5a6f230c8SAlberto Garcia# Copyright (C) 2019 Igalia, S.L. 6a6f230c8SAlberto Garcia# Author: Alberto Garcia <berto@igalia.com> 7a6f230c8SAlberto Garcia# 8a6f230c8SAlberto Garcia# This program is free software; you can redistribute it and/or modify 9a6f230c8SAlberto Garcia# it under the terms of the GNU General Public License as published by 10a6f230c8SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or 11a6f230c8SAlberto Garcia# (at your option) any later version. 12a6f230c8SAlberto Garcia# 13a6f230c8SAlberto Garcia# This program is distributed in the hope that it will be useful, 14a6f230c8SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a6f230c8SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a6f230c8SAlberto Garcia# GNU General Public License for more details. 17a6f230c8SAlberto Garcia# 18a6f230c8SAlberto Garcia# You should have received a copy of the GNU General Public License 19a6f230c8SAlberto Garcia# along with this program. If not, see <http://www.gnu.org/licenses/>. 20a6f230c8SAlberto Garcia# 21a6f230c8SAlberto Garcia 22a6f230c8SAlberto Garcia# creator 23a6f230c8SAlberto Garciaowner=berto@igalia.com 24a6f230c8SAlberto Garcia 25a6f230c8SAlberto Garciaseq=`basename $0` 26a6f230c8SAlberto Garciaecho "QA output created by $seq" 27a6f230c8SAlberto Garcia 28a6f230c8SAlberto Garciastatus=1 # failure is the default! 29a6f230c8SAlberto Garcia 30a6f230c8SAlberto Garcia# get standard environment, filters and checks 31a6f230c8SAlberto Garcia. ./common.rc 32a6f230c8SAlberto Garcia. ./common.filter 33a6f230c8SAlberto Garcia 34a6f230c8SAlberto Garcia_supported_fmt generic 35a6f230c8SAlberto Garcia_supported_proto generic 36a6f230c8SAlberto Garcia_supported_os Linux 37a6f230c8SAlberto Garcia 38a6f230c8SAlberto Garciado_run_qemu() 39a6f230c8SAlberto Garcia{ 40a6f230c8SAlberto Garcia echo Testing: "$@" 41a6f230c8SAlberto Garcia $QEMU -nographic -qmp stdio -serial none "$@" 42a6f230c8SAlberto Garcia echo 43a6f230c8SAlberto Garcia} 44a6f230c8SAlberto Garcia 45a6f230c8SAlberto Garcia# Remove QMP events from (pretty-printed) output. Doesn't handle 46a6f230c8SAlberto Garcia# nested dicts correctly, but we don't get any of those in this test. 47a6f230c8SAlberto Garcia_filter_qmp_events() 48a6f230c8SAlberto Garcia{ 49a6f230c8SAlberto Garcia tr '\n' '\t' | sed -e \ 50a6f230c8SAlberto Garcia 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \ 51a6f230c8SAlberto Garcia | tr '\t' '\n' 52a6f230c8SAlberto Garcia} 53a6f230c8SAlberto Garcia 54a6f230c8SAlberto Garciarun_qemu() 55a6f230c8SAlberto Garcia{ 56a6f230c8SAlberto Garcia do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events 57a6f230c8SAlberto Garcia} 58a6f230c8SAlberto Garcia 59a6f230c8SAlberto Garciacase "$QEMU_DEFAULT_MACHINE" in 60a6f230c8SAlberto Garcia s390-ccw-virtio) 61a6f230c8SAlberto Garcia virtio_scsi=virtio-scsi-ccw 62a6f230c8SAlberto Garcia ;; 63a6f230c8SAlberto Garcia *) 64a6f230c8SAlberto Garcia virtio_scsi=virtio-scsi-pci 65a6f230c8SAlberto Garcia ;; 66a6f230c8SAlberto Garciaesac 67a6f230c8SAlberto Garcia 68a6f230c8SAlberto Garciaecho 69a6f230c8SAlberto Garciaecho === Unplug a SCSI disk and then plug it again === 70a6f230c8SAlberto Garciaecho 71a6f230c8SAlberto Garcia 72a6f230c8SAlberto Garciarun_qemu <<EOF 73a6f230c8SAlberto Garcia{ "execute": "qmp_capabilities" } 74a6f230c8SAlberto Garcia{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}} 75a6f230c8SAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}} 76a6f230c8SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}} 77a6f230c8SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}} 78a6f230c8SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}} 79a6f230c8SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}} 80a6f230c8SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}} 81a6f230c8SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi0"}} 82a6f230c8SAlberto Garcia{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}} 83a6f230c8SAlberto Garcia{ "execute": "quit"} 84a6f230c8SAlberto GarciaEOF 85a6f230c8SAlberto Garcia 863ff35ba3SAlberto Garciaecho 873ff35ba3SAlberto Garciaecho === Attach two SCSI disks using the same block device and the same iothread === 883ff35ba3SAlberto Garciaecho 893ff35ba3SAlberto Garcia 903ff35ba3SAlberto Garciarun_qemu <<EOF 913ff35ba3SAlberto Garcia{ "execute": "qmp_capabilities" } 923ff35ba3SAlberto Garcia{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}} 933ff35ba3SAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}} 943ff35ba3SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}} 953ff35ba3SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}} 963ff35ba3SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}} 973ff35ba3SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}} 983ff35ba3SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}} 993ff35ba3SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi0"}} 1003ff35ba3SAlberto Garcia{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}} 1013ff35ba3SAlberto Garcia{ "execute": "quit"} 1023ff35ba3SAlberto GarciaEOF 1033ff35ba3SAlberto Garcia 104*eb97813fSAlberto Garciaecho 105*eb97813fSAlberto Garciaecho === Attach two SCSI disks using the same block device but different iothreads === 106*eb97813fSAlberto Garciaecho 107*eb97813fSAlberto Garcia 108*eb97813fSAlberto Garciarun_qemu <<EOF 109*eb97813fSAlberto Garcia{ "execute": "qmp_capabilities" } 110*eb97813fSAlberto Garcia{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}} 111*eb97813fSAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}} 112*eb97813fSAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}} 113*eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}} 114*eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}} 115*eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}} 116*eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}} 117*eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}} 118*eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}} 119*eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}} 120*eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi0"}} 121*eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi1"}} 122*eb97813fSAlberto Garcia{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}} 123*eb97813fSAlberto Garcia{ "execute": "quit"} 124*eb97813fSAlberto GarciaEOF 125*eb97813fSAlberto Garcia 126a6f230c8SAlberto Garcia# success, all done 127a6f230c8SAlberto Garciaecho "*** done" 128a6f230c8SAlberto Garciarm -f $seq.full 129a6f230c8SAlberto Garciastatus=0 130