From patchwork Tue Jan 22 15:53:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10776267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 497F5746 for ; Tue, 22 Jan 2019 21:04:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 393A02900E for ; Tue, 22 Jan 2019 21:04:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C4CE2A0FE; Tue, 22 Jan 2019 21:04:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A88629E76 for ; Tue, 22 Jan 2019 21:04:54 +0000 (UTC) Received: from localhost ([127.0.0.1]:49793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm3E5-0001EQ-Ou for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Jan 2019 16:04:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm1wQ-0008TX-0y for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:42:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm1wN-0001UH-W7 for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:42:33 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:58080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gm1wL-0001Q8-Uu; Tue, 22 Jan 2019 14:42:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=OZ8n/qJLbfwe43gkjCASVFZNwa7d8OoxEwSMdDPefYw=; b=ps7fV2PxRydoxNNVnF4lhRDaKcfURKWRW9PNGSRoosbOMHLeU5riEGiwvB9Sgq4GSm4IoQnrkmwaoXqMoEjbZC/0eBVUYwEfqNL/vx+yUcUxGGtL7uYqZ1wBj0EXJuXpcWmvLt86+B/d2yrKW2ax+erJGkbFJg2OQdxQquHbw5NC28FjZ7RvOBu2JvWqk9pJVEHkqhJsQByN0Zn9WhuGgx41v98ulVlJ5TUk2QoP47npTZ73ipaLDmOibj8+lU1+8hRnViVqPxpZDOA8E3wBcPLHB7Hak0XtzO9B0Zu36tDDa1taxmoXMrpEV+x+MAOk8Tor7qP30IlsOnV0Gm4J0Q==; Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1glyN1-0003Ul-9i; Tue, 22 Jan 2019 16:53:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1glyMl-0003ox-Kp; Tue, 22 Jan 2019 17:53:31 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 22 Jan 2019 17:53:21 +0200 Message-Id: <98776952d40d436b2741f6c141ae618bdf6f83a5.1548171741.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 1/3] virtio-scsi: Move BlockBackend back to the main AioContext on unplug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This fixes a crash when attaching a disk to a SCSI device using iothreads, then detaching it and reattaching it again. Test case included. Signed-off-by: Alberto Garcia --- hw/scsi/virtio-scsi.c | 6 ++++ tests/qemu-iotests/240 | 89 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/240.out | 18 ++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 114 insertions(+) create mode 100755 tests/qemu-iotests/240 create mode 100644 tests/qemu-iotests/240.out diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 3aa99717e2..e1f7b208c7 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -824,6 +824,12 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev, virtio_scsi_release(s); } + if (s->ctx) { + virtio_scsi_acquire(s); + blk_set_aio_context(sd->conf.blk, qemu_get_aio_context()); + virtio_scsi_release(s); + } + qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); } diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240 new file mode 100755 index 0000000000..ead7ee08eb --- /dev/null +++ b/tests/qemu-iotests/240 @@ -0,0 +1,89 @@ +#!/bin/bash +# +# Test hot plugging and unplugging with iothreads +# +# Copyright (C) 2019 Igalia, S.L. +# Author: Alberto Garcia +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=berto@igalia.com + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto generic +_supported_os Linux + +do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +# Remove QMP events from (pretty-printed) output. Doesn't handle +# nested dicts correctly, but we don't get any of those in this test. +_filter_qmp_events() +{ + tr '\n' '\t' | sed -e \ + 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \ + | tr '\t' '\n' +} + +run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events +} + +case "$QEMU_DEFAULT_MACHINE" in + s390-ccw-virtio) + virtio_scsi=virtio-scsi-ccw + ;; + *) + virtio_scsi=virtio-scsi-pci + ;; +esac + +echo +echo === Unplug a SCSI disk and then plug it again === +echo + +run_qemu < X-Patchwork-Id: 10776261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BB7E1399 for ; Tue, 22 Jan 2019 20:57:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AACA2B7D4 for ; Tue, 22 Jan 2019 20:57:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E5992B81D; Tue, 22 Jan 2019 20:57:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C1D432B7D4 for ; Tue, 22 Jan 2019 20:57:30 +0000 (UTC) Received: from localhost ([127.0.0.1]:49626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm36v-0003h9-Rd for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Jan 2019 15:57:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm1wL-0008Pi-Vg for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:42:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm1wK-0001Ph-16 for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:42:29 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:58004) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gm1wI-0001DH-1U; Tue, 22 Jan 2019 14:42:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=38NtCjNg+R49mnrNby/Va4IgsMHnUSM68R6XI1Yp2Xg=; b=EoFBV7O+haHU5M5QQA3/YuZnnUO5Cw8uRIN75nyMSaLvwXAAlH6mHv7pm8msJUbEYKzDV3SS9+ijTqVUdnKhA84OXRzkzV2LLUZBjBNvrdOWhbnpkqdugpHA+Ma+afrSIcTrrnV/vt0gEN2nDqjbo3ZnafkXvQii1YphhgBhtzqHCH+hUYOOupHwwGTjyIKl2lLvDCfGsf0a5PJz/I8wmYuHaPn99qc0FijTS2IrDh7kpVeou5gEIZ9ceZscYLl2t049OKXxgTjlFy2RQI/5HscI4xVJvMLXsv8+oDaOhgpsf+Lq/KufWAIx4cWa7VQv4Sm3ReQMYg01Yg/zFomlmA==; Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1glyN1-0003Uy-T5; Tue, 22 Jan 2019 16:53:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1glyMl-0003oz-Ls; Tue, 22 Jan 2019 17:53:31 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 22 Jan 2019 17:53:22 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 2/3] scsi-disk: Acquire the AioContext in scsi_*_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This fixes a crash when attaching two disks with the same blockdev to a SCSI device that is using iothreads. Test case included. Signed-off-by: Alberto Garcia --- hw/scsi/scsi-disk.c | 23 ++++++++++++++++++++--- tests/qemu-iotests/240 | 18 ++++++++++++++++++ tests/qemu-iotests/240.out | 16 ++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 0e9027c8f3..b049026219 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2381,10 +2381,13 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) static void scsi_hd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx = NULL; /* can happen for devices without drive. The error message for missing * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { + ctx = blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); blkconf_blocksizes(&s->qdev.conf); } s->qdev.blocksize = s->qdev.conf.logical_block_size; @@ -2393,11 +2396,15 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) s->product = g_strdup("QEMU HARDDISK"); } scsi_realize(&s->qdev, errp); + if (ctx) { + aio_context_release(ctx); + } } static void scsi_cd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int ret; if (!dev->conf.blk) { @@ -2408,6 +2415,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp) assert(ret == 0); } + ctx = blk_get_aio_context(dev->conf.blk); + aio_context_acquire(ctx); s->qdev.blocksize = 2048; s->qdev.type = TYPE_ROM; s->features |= 1 << SCSI_DISK_F_REMOVABLE; @@ -2415,6 +2424,7 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp) s->product = g_strdup("QEMU CD-ROM"); } scsi_realize(&s->qdev, errp); + aio_context_release(ctx); } static void scsi_disk_realize(SCSIDevice *dev, Error **errp) @@ -2553,6 +2563,7 @@ static int get_device_type(SCSIDiskState *s) static void scsi_block_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int sg_version; int rc; @@ -2567,6 +2578,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) "be removed in a future version"); } + ctx = blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); + /* check we are using a driver managing SG_IO (version 3 and after) */ rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version); if (rc < 0) { @@ -2574,18 +2588,18 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) if (rc != -EPERM) { error_append_hint(errp, "Is this a SCSI device?\n"); } - return; + goto out; } if (sg_version < 30000) { error_setg(errp, "scsi generic interface too old"); - return; + goto out; } /* get device type from INQUIRY data */ rc = get_device_type(s); if (rc < 0) { error_setg(errp, "INQUIRY failed"); - return; + goto out; } /* Make a guess for the block size, we'll fix it when the guest sends. @@ -2605,6 +2619,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) scsi_realize(&s->qdev, errp); scsi_generic_read_device_inquiry(&s->qdev); + +out: + aio_context_release(ctx); } typedef struct SCSIBlockReq { diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240 index ead7ee08eb..5d499c9a00 100755 --- a/tests/qemu-iotests/240 +++ b/tests/qemu-iotests/240 @@ -83,6 +83,24 @@ run_qemu < X-Patchwork-Id: 10776263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 906621390 for ; Tue, 22 Jan 2019 21:00:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81E7528D65 for ; Tue, 22 Jan 2019 21:00:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F9BB2BC65; Tue, 22 Jan 2019 21:00:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 150D22BC57 for ; Tue, 22 Jan 2019 21:00:20 +0000 (UTC) Received: from localhost ([127.0.0.1]:49703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm39f-00064X-7d for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Jan 2019 16:00:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm1wR-0008VH-PA for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:42:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm1wQ-0001XS-Gm for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:42:35 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:58083) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gm1wQ-0001Ue-28; Tue, 22 Jan 2019 14:42:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=PmiB8gJjNwvCcThPwk3UusXlZAJqIGnqvhbtrhpklDA=; b=d/ztQ/L25q/ITrG7MVFU98Va0xbCYfRNaxpb7ybzCMzJcErHN7tXScXeLrEtfHMTb1rcZfWXFYwUhNTZsLD9jQ7YCcTa2D7LMNVlFxNt1ycaQrdQvilvoC8KyOv88Mfk4JY3JE8TKK3bRzgoEE5qFF2wu9fRT2wAwpp3q/0QhxuZ9hfkGvLmTyJtwRXgWwyYuSuA+RbwmvhtD7Z1D42XJmjMGxAG/yL3piTsqX0A986ogAZUdcqT6z3Bywf4DMI/wjTS1QNio0jxHhLoGd8Nwkyaa+y1iJdXpsqQ6VNm6GBRbm9yO9mvIpI6L0U8ulr1pq3Rgg+G/6vulvzMTziS1g==; Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1glyN1-0003Uk-8h; Tue, 22 Jan 2019 16:53:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1glyMl-0003p1-Mp; Tue, 22 Jan 2019 17:53:31 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 22 Jan 2019 17:53:23 +0200 Message-Id: <6ad371df66eecffccce29a0bd14695f40edd6120.1548171741.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 3/3] virtio-scsi: Forbid devices with different iothreads sharing a blockdev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch forbids attaching a disk to a SCSI device if its using a different AioContext. Test case included. Signed-off-by: Alberto Garcia --- hw/scsi/virtio-scsi.c | 7 +++++++ tests/qemu-iotests/240 | 22 ++++++++++++++++++++++ tests/qemu-iotests/240.out | 20 ++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index e1f7b208c7..eb90288f47 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -791,9 +791,16 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev, SCSIDevice *sd = SCSI_DEVICE(dev); if (s->ctx && !s->dataplane_fenced) { + AioContext *ctx; if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) { return; } + ctx = blk_get_aio_context(sd->conf.blk); + if (ctx != s->ctx && ctx != qemu_get_aio_context()) { + error_setg(errp, "Cannot attach a blockdev that is using " + "a different iothread"); + return; + } virtio_scsi_acquire(s); blk_set_aio_context(sd->conf.blk, s->ctx); virtio_scsi_release(s); diff --git a/tests/qemu-iotests/240 b/tests/qemu-iotests/240 index 5d499c9a00..65cc3b39b1 100755 --- a/tests/qemu-iotests/240 +++ b/tests/qemu-iotests/240 @@ -101,6 +101,28 @@ run_qemu <