From nobody Fri May 17 14:34:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547477669667303.65828664131936; Mon, 14 Jan 2019 06:54:29 -0800 (PST) Received: from localhost ([127.0.0.1]:45602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3dD-0000cp-Ti for importer@patchew.org; Mon, 14 Jan 2019 09:54:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3At-0001jG-QZ for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008VX-Dg for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:11 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52464) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LS-Ql; Mon, 14 Jan 2019 09:25:06 -0500 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 1gj3AV-0002jO-Rk; Mon, 14 Jan 2019 15:24:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-000380-0w; Mon, 14 Jan 2019 16:24:15 +0200 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=B1rpo0I7gQ2eNbWZ+IneXopvQLkOTUafi3SU1162728=; b=kulWYUclw+GPHMEwHjArrTVSfIg6frW+groC864J6C3qbJpQBhxy73PQbahxwBUYfCHvjM9Z7pBqaSkEFwTZWnEZ18d72JNUaIweRU/6sdAhSouD43yKqVugwP1iPkUttxAzb7RrA/Aaot1VKGI/hF38vpBQxAQXUzfww1rVACd4W/Cg/1fe0LZU5S1oGHM3+/aK5MpLRyfBaJcs+aVDYtNDswDp4MNbhoXvP+7D/Vv4GOSZEB7Qa6SaEtPapvGN+lexo5VmpvyEjlJiO3slSOgxs2pvPOnN4CQdFwEjK63Z4xupx6/8q8w0JZNVmZk/h/ziQptLvoQOdqVyQ75nWg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:23:59 +0200 Message-Id: <5086004667e4a962e10e29ccb402705d0962dbcf.1547475602.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 v2 1/6] block: Acquire the AioContext in virtio_blk_device_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes a crash when adding a virtio-blk device with a drive that is using an iothread. Test case included. Signed-off-by: Alberto Garcia --- hw/block/virtio-blk.c | 22 ++++++++----- tests/qemu-iotests/236 | 78 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/236.out | 16 ++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 110 insertions(+), 7 deletions(-) create mode 100755 tests/qemu-iotests/236 create mode 100644 tests/qemu-iotests/236.out diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f208c6ddb9..5357da82af 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -912,6 +912,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOBlock *s =3D VIRTIO_BLK(dev); VirtIOBlkConf *conf =3D &s->conf; + AioContext *ctx; Error *err =3D NULL; unsigned i; =20 @@ -919,30 +920,34 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) error_setg(errp, "drive property not set"); return; } + + ctx =3D blk_get_aio_context(conf->conf.blk); + aio_context_acquire(ctx); + if (!blk_is_inserted(conf->conf.blk)) { error_setg(errp, "Device needs media, but drive is empty"); - return; + goto out; } if (!conf->num_queues) { error_setg(errp, "num-queues property must be larger than 0"); - return; + goto out; } if (!is_power_of_2(conf->queue_size) || conf->queue_size > VIRTQUEUE_MAX_SIZE) { error_setg(errp, "invalid queue-size property (%" PRIu16 "), " "must be a power of 2 (max %d)", conf->queue_size, VIRTQUEUE_MAX_SIZE); - return; + goto out; } =20 if (!blkconf_apply_backend_options(&conf->conf, blk_is_read_only(conf->conf.blk), t= rue, errp)) { - return; + goto out; } s->original_wce =3D blk_enable_write_cache(conf->conf.blk); if (!blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, errp)) { - return; + goto out; } =20 blkconf_blocksizes(&conf->conf); @@ -951,7 +956,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) conf->conf.physical_block_size) { error_setg(errp, "logical_block_size > physical_block_size not supported= "); - return; + goto out; } =20 virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, @@ -968,7 +973,7 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) if (err !=3D NULL) { error_propagate(errp, err); virtio_cleanup(vdev); - return; + goto out; } =20 s->change =3D qemu_add_vm_change_state_handler(virtio_blk_dma_restart_= cb, s); @@ -976,6 +981,9 @@ static void virtio_blk_device_realize(DeviceState *dev,= Error **errp) blk_set_guest_block_size(s->blk, s->conf.conf.logical_block_size); =20 blk_iostatus_enable(s->blk); + +out: + aio_context_release(ctx); } =20 static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236 new file mode 100755 index 0000000000..c6a3415ffe --- /dev/null +++ b/tests/qemu-iotests/236 @@ -0,0 +1,78 @@ +#!/bin/bash +# +# Test deletion of devices that are using 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=3Dberto@igalia.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # 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 +} + +echo +echo =3D=3D=3D Try adding and removing a virtio-blk device =3D=3D=3D +echo + +run_qemu < Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547476521364180.551480759892; Mon, 14 Jan 2019 06:35:21 -0800 (PST) Received: from localhost ([127.0.0.1]:40880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3Ki-0000Xg-8z for importer@patchew.org; Mon, 14 Jan 2019 09:35:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3At-0001iv-L2 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008Vp-E8 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:11 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52463) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LO-Ql; Mon, 14 Jan 2019 09:25:06 -0500 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 1gj3AV-0002jQ-Up; Mon, 14 Jan 2019 15:24:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-000383-20; Mon, 14 Jan 2019 16:24:15 +0200 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=VkAexFNG2apua1mSheMqjpENsQLKSY4KQLcRVXmJorE=; b=a0Zxqd5F8CF8npWasQLtgAJPQorGbjKuNXPcwdXfCqVi6U0QFg8erSNKBneijCO6kQLccxiNpPC3g1E4xOSrI+Xt88BS3m6V72rF0a7o0zFXoH1TR4naXTBO+t9YZAl3o8B79iM8iUd47ccMd+l0d0+bmxBiJlO6nFDrGIvG2x6CV67qWy9apibAijnLhqfNS5P4WI+98uVZYJ8TzCnbZfa590pRFN75YYjQXnVCw2nVcQbIiCYCGNK3LGRNKy34XJO/+i3LDnvwZpDQ8JJil1ez9iXx4nVjZeGouCHoiaLbUPREtI6+E8SmtRtwxkkWNSA/J4TN6a9D6Ho36hlhGw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:24:00 +0200 Message-Id: <804cf3cff9712467993929d7563b510f77c5401f.1547475602.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 v2 2/6] block: 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes a crash when adding a virtio-scsi device with a drive that is using an iothread. Test case included. Signed-off-by: Alberto Garcia --- hw/scsi/scsi-disk.c | 23 ++++++++++++++++++++--- tests/qemu-iotests/236 | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/236.out | 30 ++++++++++++++++++++++++++++++ 3 files changed, 93 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 **e= rrp) static void scsi_hd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx =3D 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 =3D blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); blkconf_blocksizes(&s->qdev.conf); } s->qdev.blocksize =3D s->qdev.conf.logical_block_size; @@ -2393,11 +2396,15 @@ static void scsi_hd_realize(SCSIDevice *dev, Error = **errp) s->product =3D g_strdup("QEMU HARDDISK"); } scsi_realize(&s->qdev, errp); + if (ctx) { + aio_context_release(ctx); + } } =20 static void scsi_cd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int ret; =20 if (!dev->conf.blk) { @@ -2408,6 +2415,8 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) assert(ret =3D=3D 0); } =20 + ctx =3D blk_get_aio_context(dev->conf.blk); + aio_context_acquire(ctx); s->qdev.blocksize =3D 2048; s->qdev.type =3D TYPE_ROM; s->features |=3D 1 << SCSI_DISK_F_REMOVABLE; @@ -2415,6 +2424,7 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **= errp) s->product =3D g_strdup("QEMU CD-ROM"); } scsi_realize(&s->qdev, errp); + aio_context_release(ctx); } =20 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 =3D DO_UPCAST(SCSIDiskState, qdev, dev); + AioContext *ctx; int sg_version; int rc; =20 @@ -2567,6 +2578,9 @@ static void scsi_block_realize(SCSIDevice *dev, Error= **errp) "be removed in a future version"); } =20 + ctx =3D 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 =3D 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, Err= or **errp) if (rc !=3D -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; } =20 /* get device type from INQUIRY data */ rc =3D get_device_type(s); if (rc < 0) { error_setg(errp, "INQUIRY failed"); - return; + goto out; } =20 /* 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) =20 scsi_realize(&s->qdev, errp); scsi_generic_read_device_inquiry(&s->qdev); + +out: + aio_context_release(ctx); } =20 typedef struct SCSIBlockReq { diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236 index c6a3415ffe..c2bf425491 100755 --- a/tests/qemu-iotests/236 +++ b/tests/qemu-iotests/236 @@ -72,6 +72,49 @@ run_qemu < Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547476309550650.7311308354074; Mon, 14 Jan 2019 06:31:49 -0800 (PST) Received: from localhost ([127.0.0.1]:40102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3HH-0006Rj-Sh for importer@patchew.org; Mon, 14 Jan 2019 09:31:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3Ar-0001f8-7A for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008Vq-EB for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:09 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LM-Qf; Mon, 14 Jan 2019 09:25:06 -0500 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 1gj3AV-0002jR-TI; Mon, 14 Jan 2019 15:24:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-000386-3F; Mon, 14 Jan 2019 16:24:15 +0200 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=m2WBlCimuDjftw+8ixiiiYkdpLsUiwuy4ahzX9WwfLg=; b=m9DNPlJ4aISUwii+Y0mGtB8wIZBikB/XDMXoVyi2gxXnqLOSgdtgavz45XxQw9Rpg+S60k+V0lMCUdayPlUYF+BuCr2Z7CTni3DyPbbQWi0cQP6HnLRuXip9SqGlFqWmR91+3bOs2TjZ4zY1L2JgDSaRI2pHtxt2bia2iZW7aMEmud7cAG3EmdmcaQ8BpTAXKiV/Tu52B3dA8RJfpoHHtflaU+DMiLo1Snx5Drow1hgkQIy5Ni9T7RPnixyJ3Ujwr0vNhGJx7fAsMBebYWmqjtruHuvjrFFNGkDjeTxU5Z8gvsymzj2NyXCoaPFueofK5vj8IvU/qJSB89/hWKVY6Q==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:24:01 +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 v2 3/6] block: Acquire the AioContext in floppy_drive_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- hw/block/fdc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 6f19f127a5..d9bc80de83 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -512,6 +512,7 @@ static void floppy_drive_realize(DeviceState *qdev, Err= or **errp) { FloppyDrive *dev =3D FLOPPY_DRIVE(qdev); FloppyBus *bus =3D FLOPPY_BUS(qdev->parent_bus); + AioContext *ctx; FDrive *drive; int ret; =20 @@ -543,13 +544,16 @@ static void floppy_drive_realize(DeviceState *qdev, E= rror **errp) assert(ret =3D=3D 0); } =20 + ctx =3D blk_get_aio_context(dev->conf.blk); + aio_context_acquire(ctx); + blkconf_blocksizes(&dev->conf); if (dev->conf.logical_block_size !=3D 512 || dev->conf.physical_block_size !=3D 512) { error_setg(errp, "Physical and logical block size must " "be 512 for floppy"); - return; + goto out; } =20 /* rerror/werror aren't supported by fdc and therefore not even regist= ered @@ -561,7 +565,7 @@ static void floppy_drive_realize(DeviceState *qdev, Err= or **errp) if (!blkconf_apply_backend_options(&dev->conf, blk_is_read_only(dev->conf.blk), false, errp)) { - return; + goto out; } =20 /* 'enospc' is the default for -drive, 'report' is what blk_new() give= s us @@ -569,11 +573,11 @@ static void floppy_drive_realize(DeviceState *qdev, E= rror **errp) if (blk_get_on_error(dev->conf.blk, 0) !=3D BLOCKDEV_ON_ERROR_ENOSPC && blk_get_on_error(dev->conf.blk, 0) !=3D BLOCKDEV_ON_ERROR_REPORT) { error_setg(errp, "fdc doesn't support drive option werror"); - return; + goto out; } if (blk_get_on_error(dev->conf.blk, 1) !=3D BLOCKDEV_ON_ERROR_REPORT) { error_setg(errp, "fdc doesn't support drive option rerror"); - return; + goto out; } =20 drive->conf =3D &dev->conf; @@ -589,6 +593,9 @@ static void floppy_drive_realize(DeviceState *qdev, Err= or **errp) dev->type =3D drive->drive; =20 fd_revalidate(drive); + +out: + aio_context_release(ctx); } =20 static void floppy_drive_class_init(ObjectClass *klass, void *data) --=20 2.11.0 From nobody Fri May 17 14:34:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547477502986560.7490996230982; Mon, 14 Jan 2019 06:51:42 -0800 (PST) Received: from localhost ([127.0.0.1]:44861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3aX-00072g-QV for importer@patchew.org; Mon, 14 Jan 2019 09:51:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3Ap-0001dR-Tt for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008Vj-E6 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:07 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52456) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3Ao-0008LP-2a; Mon, 14 Jan 2019 09:25:06 -0500 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 1gj3AV-0002jS-UM; Mon, 14 Jan 2019 15:24:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-000389-4G; Mon, 14 Jan 2019 16:24:15 +0200 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=2aMwKPnI9IS6rxkTuyf5yBvVNXJewJfksZj5pzl1vHY=; b=QujABnCb/XNr9Y2gbI+39yjouCaU8iNLREDw0eGVkVEUUWyBnYJv12qD5UxSHAqlG8OTwn1v+cnwL6fbSICgWc1f2/UkAVqkWWU78vxwoDULLSxo5WpC2YR3KsH+u2PsQsizo2cxqQ3vbC220Qs+ll+x5XKPhLTaUvhWceJVLlvCBmBD3I5LtHV/YRvONOaBCbwROIi5MyMCwvGDKKn3hO2ZorngiDWdC76/SuDdXsnJMcco4TeONfPemcD1RWNzvbVPIueocs/r2Ojmmjap668qutnX/NM2M4oV/HY8Ca4fmv++soTn2zzy8rimezHwJvE8/v7fuEk+UDdsm68LbA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:24:02 +0200 Message-Id: <8e40a9c26445563f719b4b89e0ed82ef1c8b50f1.1547475602.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 v2 4/6] block: Acquire the AioContext in nvme_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- hw/block/nvme.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 7c8c63e8f5..72e94aff86 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1203,6 +1203,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) { NvmeCtrl *n =3D NVME(pci_dev); NvmeIdCtrl *id =3D &n->id_ctrl; + AioContext *ctx; =20 int i; int64_t bs_size; @@ -1213,20 +1214,23 @@ static void nvme_realize(PCIDevice *pci_dev, Error = **errp) return; } =20 + ctx =3D blk_get_aio_context(n->conf.blk); + aio_context_acquire(ctx); + bs_size =3D blk_getlength(n->conf.blk); if (bs_size < 0) { error_setg(errp, "could not get backing file size"); - return; + goto out; } =20 if (!n->serial) { error_setg(errp, "serial property not set"); - return; + goto out; } blkconf_blocksizes(&n->conf); if (!blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.= blk), false, errp)) { - return; + goto out; } =20 pci_conf =3D pci_dev->config; @@ -1323,6 +1327,9 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) cpu_to_le64(n->ns_size >> id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); } + +out: + aio_context_release(ctx); } =20 static void nvme_exit(PCIDevice *pci_dev) --=20 2.11.0 From nobody Fri May 17 14:34:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547477312011374.8275841478471; Mon, 14 Jan 2019 06:48:32 -0800 (PST) Received: from localhost ([127.0.0.1]:44081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3XS-0004Wo-Q1 for importer@patchew.org; Mon, 14 Jan 2019 09:48:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3Ap-0001db-B4 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008Va-Du for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:07 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52460) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LQ-Qj; Mon, 14 Jan 2019 09:25:06 -0500 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 1gj3AV-0002jU-Vo; Mon, 14 Jan 2019 15:24:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-00038C-5B; Mon, 14 Jan 2019 16:24:15 +0200 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=W7LVq02B3oJ0WAICRK2gxqTMWcXU/5rEQ6zaeITmus4=; b=eHXuBO4hRTmAkN7SHYDy/NAD2aXRt4DD1cLM9csOM7KkbtkUndwa1yKoR8dzvP1oqHhUHDXepoGsOMXYXlIpAfyTeNG1wwR5Q+2eX9ZSu2R3oJNSJ7bjLkdBydmmSKWvLPINMsPGPVMn33b5bK1nhPJWQnKKEhG/XCS/fkmZSbYBu4JFGyWaZfwTbpPPceg3cKxYqYdqX66M+6rz7g34Mdh0agmpgpJK7mvY1NmLdgqTqO5NNr3QhRAywwbYZt9WKGy87iVVcpj9Vw8WuS7QiMOnvjgSscoH5A1g3c4UwMX80wiupEAE+8GRRX1/MlsoJXVILXL1zJn5iVh8n7niig==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:24:03 +0200 Message-Id: <8bb7fd0e9188316446270873e10d6049b9a7d358.1547475602.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 v2 5/6] block: Acquire the AioContext in ide_dev_initfn() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- hw/ide/qdev.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 573b022e1e..f355f2a352 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -160,6 +160,7 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind= kind, Error **errp) { IDEBus *bus =3D DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); IDEState *s =3D bus->ifs + dev->unit; + AioContext *ctx; int ret; =20 if (!dev->conf.blk) { @@ -174,36 +175,39 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKi= nd kind, Error **errp) } } =20 + ctx =3D blk_get_aio_context(dev->conf.blk); + aio_context_acquire(ctx); + if (dev->conf.discard_granularity =3D=3D -1) { dev->conf.discard_granularity =3D 512; } else if (dev->conf.discard_granularity && dev->conf.discard_granularity !=3D 512) { error_setg(errp, "discard_granularity must be 512 for ide"); - return; + goto out; } =20 blkconf_blocksizes(&dev->conf); if (dev->conf.logical_block_size !=3D 512) { error_setg(errp, "logical_block_size must be 512 for IDE"); - return; + goto out; } =20 if (kind !=3D IDE_CD) { if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, errp)) { - return; + goto out; } } if (!blkconf_apply_backend_options(&dev->conf, kind =3D=3D IDE_CD, kind !=3D IDE_CD, errp)) { - return; + goto out; } =20 if (ide_init_drive(s, dev->conf.blk, kind, dev->version, dev->serial, dev->model, dev->wwn, dev->conf.cyls, dev->conf.heads, dev->conf.secs, dev->chs_trans, errp) < 0) { - return; + goto out; } =20 if (!dev->version) { @@ -215,6 +219,9 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind= kind, Error **errp) =20 add_boot_device_path(dev->conf.bootindex, &dev->qdev, dev->unit ? "/disk@1" : "/disk@0"); + +out: + aio_context_release(ctx); } =20 static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *nam= e, --=20 2.11.0 From nobody Fri May 17 14:34:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547476931905740.822284014474; Mon, 14 Jan 2019 06:42:11 -0800 (PST) Received: from localhost ([127.0.0.1]:42599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3RG-00060W-Sw for importer@patchew.org; Mon, 14 Jan 2019 09:42:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gj3Ap-0001dS-Tu for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gj3Ao-0008VL-D7 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 09:25:07 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52458) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gj3An-0008LR-Qk; Mon, 14 Jan 2019 09:25:06 -0500 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 1gj3AW-0002jV-02; Mon, 14 Jan 2019 15:24:48 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gj39z-00038G-68; Mon, 14 Jan 2019 16:24:15 +0200 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=L9HmUY97OyxWpLBVGHyd1eTDvesw+Ee02jTzh2ZhCVw=; b=QJfBnQ5kGeTIigKTzX3DjtHSy9B0Z345j6+D24xH0P6S+VKma1kkMTJoxDpaslhHIhYg26zeLD2fcCzO+WkHWxMnlzWy6TKk0qlRrN0uMWEnRXzQeD+p98i8uVRZaIeIJDLYkj/2hdLscuwRt/k4YKXEiBCGBRJou2dL9rFDWCNUSkYKvwx8BXTBSk4e+mlYRORA1iRza1oVhKsuCdIdAdmWNHdYxeyUYBvYDh7K/CJH+JrEw9DT0ZNhPpMOWQLlLIyV86Zq2eCBachLVM4RX1R2PzlQDapfdptH35UbKiA913AptMrVew5NwKsyfuFlpR1C1bMfMkpvaktm8O5juw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 16:24:04 +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 v2 6/6] block: Acquire the AioContext in usb_msd_storage_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alberto Garcia --- hw/usb/dev-storage.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index cd5551d94f..fa6e552f0f 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -593,13 +593,18 @@ static void usb_msd_storage_realize(USBDevice *dev, E= rror **errp) MSDState *s =3D USB_STORAGE_DEV(dev); BlockBackend *blk =3D s->conf.blk; SCSIDevice *scsi_dev; + AioContext *ctx; =20 if (!blk) { error_setg(errp, "drive property not set"); return; } =20 + ctx =3D blk_get_aio_context(blk); + aio_context_acquire(ctx); blkconf_blocksizes(&s->conf); + aio_context_release(ctx); + if (!blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), tr= ue, errp)) { return; --=20 2.11.0