From nobody Wed May 1 21:03:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489511538286248.04835962710115; Tue, 14 Mar 2017 10:12:18 -0700 (PDT) Received: from localhost ([::1]:60836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnpzV-0000g7-U6 for importer@patchew.org; Tue, 14 Mar 2017 13:12:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnpyv-0000eH-Fn for qemu-devel@nongnu.org; Tue, 14 Mar 2017 13:11:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnpyq-0000Nc-J3 for qemu-devel@nongnu.org; Tue, 14 Mar 2017 13:11:33 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:37918 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnpyq-0000Mz-7G for qemu-devel@nongnu.org; Tue, 14 Mar 2017 13:11:28 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v2EHBKtH026108; Tue, 14 Mar 2017 20:11:20 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 14 Mar 2017 20:11:20 +0300 Message-Id: <20170314171120.80741-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH] blk: fix aio context loss on media change 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: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If we have separate iothread for cdrom, we lose connection to it on qmp_blockdev_change_medium, as aio_context is on bds which is dropped and switched with new one. As an example result, after such media change we have crash on virtio_scsi_ctx_check: Assertion `blk_get_aio_context(d->conf.blk) =3D=3D s= ->ctx' failed. Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! We've faced into this assert, and there some kind of fix. I don't sure that such fix doesn't break some conceptions, in this case, I hope, someone will propose a true-way solution. =3D=3D=3D=3D=3D=3D Also, on master branch I can't reproduce it as vm crashed earlier, without = any eject/change, on assert(s->ctx && s->dataplane_started) in virtio_scsi_data_plane_handle_ctrl(). It looks like race with virtio_scsi_dataplane_start(), and for test (to reproduce assert described = above), I've "fixed" it with just: @@ -63,6 +63,7 @@ static bool virtio_scsi_data_plane_handle_ctrl(VirtIODevi= ce *vdev, { VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 + sleep(10); assert(s->ctx && s->dataplane_started); return virtio_scsi_handle_ctrl_vq(s, vq); } This race is not reproduced for me in our 2.6 based branch. block/block-backend.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 5742c09c2c..6d5044228e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -65,6 +65,8 @@ struct BlockBackend { bool allow_write_beyond_eof; =20 NotifierList remove_bs_notifiers, insert_bs_notifiers; + + AioContext *aio_context; }; =20 typedef struct BlockBackendAIOCB { @@ -559,6 +561,10 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState = *bs, Error **errp) } bdrv_ref(bs); =20 + if (blk->aio_context !=3D NULL) { + bdrv_set_aio_context(bs, blk->aio_context); + } + notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { throttle_timers_attach_aio_context( @@ -1607,6 +1613,7 @@ void blk_set_aio_context(BlockBackend *blk, AioContex= t *new_context) { BlockDriverState *bs =3D blk_bs(blk); =20 + blk->aio_context =3D new_context; if (bs) { if (blk->public.throttle_state) { throttle_timers_detach_aio_context(&blk->public.throttle_timer= s); --=20 2.11.1