From nobody Tue May 7 15:59: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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151257171816224.700445102020808; Wed, 6 Dec 2017 06:48:38 -0800 (PST) Received: from localhost ([::1]:56027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMazj-00014b-LN for importer@patchew.org; Wed, 06 Dec 2017 09:48:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMaxh-00070u-4K for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMaxg-0003Dm-85 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54776) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMaxa-000367-VW; Wed, 06 Dec 2017 09:46:07 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 237DE49007; Wed, 6 Dec 2017 14:46:06 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FB97675AB; Wed, 6 Dec 2017 14:45:58 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:42 +0000 Message-Id: <20171206144550.22295-2-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 06 Dec 2017 14:46:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/9] blockdev: hold AioContext for bdrv_unref() in external_snapshot_clean() 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org 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" bdrv_unref() requires the AioContext lock because bdrv_flush() uses BDRV_POLL_WHILE(), which assumes the AioContext is currently held. If BDRV_POLL_WHILE() runs without AioContext held the pthread_mutex_unlock() call in aio_context_release() fails. This patch moves bdrv_unref() into the AioContext locked region to solve the following pthread_mutex_unlock() failure: #0 0x00007f566181969b in raise () at /lib64/libc.so.6 #1 0x00007f566181b3b1 in abort () at /lib64/libc.so.6 #2 0x00005592cd590458 in error_exit (err=3D, msg=3Dmsg@en= try=3D0x5592cdaf6d60 <__func__.23977> "qemu_mutex_unlock") at util/qemu-thr= ead-posix.c:36 #3 0x00005592cd96e738 in qemu_mutex_unlock (mutex=3Dmutex@entry=3D0x5592= ce9505e0) at util/qemu-thread-posix.c:96 #4 0x00005592cd969b69 in aio_context_release (ctx=3Dctx@entry=3D0x5592ce= 950580) at util/async.c:507 #5 0x00005592cd8ead78 in bdrv_flush (bs=3Dbs@entry=3D0x5592cfa87210) at = block/io.c:2478 #6 0x00005592cd89df30 in bdrv_close (bs=3D0x5592cfa87210) at block.c:3207 #7 0x00005592cd89df30 in bdrv_delete (bs=3D0x5592cfa87210) at block.c:33= 95 #8 0x00005592cd89df30 in bdrv_unref (bs=3D0x5592cfa87210) at block.c:4418 #9 0x00005592cd6b7f86 in qmp_transaction (dev_list=3D, ha= s_props=3D, props=3D, errp=3Derrp@entry=3D0x7= ffe4a1fc9d8) at blockdev.c:2308 Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- blockdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 56a6b24a0b..3c8d994ced 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1812,8 +1812,8 @@ static void external_snapshot_clean(BlkActionState *c= ommon) DO_UPCAST(ExternalSnapshotState, common, comm= on); if (state->aio_context) { bdrv_drained_end(state->old_bs); - aio_context_release(state->aio_context); bdrv_unref(state->new_bs); + aio_context_release(state->aio_context); } } =20 --=20 2.14.3 From nobody Tue May 7 15:59:58 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512571752199148.66463563909133; Wed, 6 Dec 2017 06:49:12 -0800 (PST) Received: from localhost ([::1]:56028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb0F-0001TZ-8f for importer@patchew.org; Wed, 06 Dec 2017 09:48:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMay2-0007Gd-UE for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMay1-0003W9-Dt for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMaxv-0003R7-2y; Wed, 06 Dec 2017 09:46:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A5E861BB2; Wed, 6 Dec 2017 14:46:26 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 576685F939; Wed, 6 Dec 2017 14:46:08 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:43 +0000 Message-Id: <20171206144550.22295-3-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 06 Dec 2017 14:46:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/9] block: don't keep AioContext acquired after external_snapshot_prepare() 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is not necessary to hold AioContext across transactions anymore since bdrv_drained_begin/end() is used to keep the nodes quiesced. In fact, using the AioContext lock for this purpose was always buggy. This patch reduces the scope of AioContext locked regions. This is not just a cleanup but also fixes hangs that occur in BDRV_POLL_WHILE() because it is unware of recursive locking and does not release the AioContext the necessary number of times to allow progress to be made. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- blockdev.c | 71 ++++++++++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3c8d994ced..3b598f8f0e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1606,7 +1606,6 @@ typedef struct ExternalSnapshotState { BlkActionState common; BlockDriverState *old_bs; BlockDriverState *new_bs; - AioContext *aio_context; bool overlay_appended; } ExternalSnapshotState; =20 @@ -1626,6 +1625,7 @@ static void external_snapshot_prepare(BlkActionState = *common, ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); TransactionAction *action =3D common->action; + AioContext *aio_context; =20 /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar * purpose but a different set of parameters */ @@ -1662,31 +1662,32 @@ static void external_snapshot_prepare(BlkActionStat= e *common, return; } =20 - /* Acquire AioContext now so any threads operating on old_bs stop */ - state->aio_context =3D bdrv_get_aio_context(state->old_bs); - aio_context_acquire(state->aio_context); + aio_context =3D bdrv_get_aio_context(state->old_bs); + aio_context_acquire(aio_context); + + /* Paired with .clean() */ bdrv_drained_begin(state->old_bs); =20 if (!bdrv_is_inserted(state->old_bs)) { error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); - return; + goto out; } =20 if (bdrv_op_is_blocked(state->old_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, errp)) { - return; + goto out; } =20 if (!bdrv_is_read_only(state->old_bs)) { if (bdrv_flush(state->old_bs)) { error_setg(errp, QERR_IO_ERROR); - return; + goto out; } } =20 if (!bdrv_is_first_non_filter(state->old_bs)) { error_setg(errp, QERR_FEATURE_DISABLED, "snapshot"); - return; + goto out; } =20 if (action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC= ) { @@ -1698,13 +1699,13 @@ static void external_snapshot_prepare(BlkActionStat= e *common, =20 if (node_name && !snapshot_node_name) { error_setg(errp, "New snapshot node name missing"); - return; + goto out; } =20 if (snapshot_node_name && bdrv_lookup_bs(snapshot_node_name, snapshot_node_name, NULL)) { error_setg(errp, "New snapshot node name already in use"); - return; + goto out; } =20 flags =3D state->old_bs->open_flags; @@ -1717,7 +1718,7 @@ static void external_snapshot_prepare(BlkActionState = *common, int64_t size =3D bdrv_getlength(state->old_bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); - return; + goto out; } bdrv_img_create(new_image_file, format, state->old_bs->filename, @@ -1725,7 +1726,7 @@ static void external_snapshot_prepare(BlkActionState = *common, NULL, size, flags, false, &local_err); if (local_err) { error_propagate(errp, local_err); - return; + goto out; } } =20 @@ -1740,30 +1741,30 @@ static void external_snapshot_prepare(BlkActionStat= e *common, errp); /* We will manually add the backing_hd field to the bs later */ if (!state->new_bs) { - return; + goto out; } =20 if (bdrv_has_blk(state->new_bs)) { error_setg(errp, "The snapshot is already in use"); - return; + goto out; } =20 if (bdrv_op_is_blocked(state->new_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, errp)) { - return; + goto out; } =20 if (state->new_bs->backing !=3D NULL) { error_setg(errp, "The snapshot already has a backing image"); - return; + goto out; } =20 if (!state->new_bs->drv->supports_backing) { error_setg(errp, "The snapshot does not support backing images"); - return; + goto out; } =20 - bdrv_set_aio_context(state->new_bs, state->aio_context); + bdrv_set_aio_context(state->new_bs, aio_context); =20 /* This removes our old bs and adds the new bs. This is an operation t= hat * can fail, so we need to do it in .prepare; undoing it for abort is @@ -1772,15 +1773,22 @@ static void external_snapshot_prepare(BlkActionStat= e *common, bdrv_append(state->new_bs, state->old_bs, &local_err); if (local_err) { error_propagate(errp, local_err); - return; + goto out; } state->overlay_appended =3D true; + +out: + aio_context_release(aio_context); } =20 static void external_snapshot_commit(BlkActionState *common) { ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); + AioContext *aio_context; + + aio_context =3D bdrv_get_aio_context(state->old_bs); + aio_context_acquire(aio_context); =20 /* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we @@ -1789,6 +1797,8 @@ static void external_snapshot_commit(BlkActionState *= common) bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDW= R, NULL); } + + aio_context_release(aio_context); } =20 static void external_snapshot_abort(BlkActionState *common) @@ -1797,11 +1807,18 @@ static void external_snapshot_abort(BlkActionState = *common) DO_UPCAST(ExternalSnapshotState, common, comm= on); if (state->new_bs) { if (state->overlay_appended) { + AioContext *aio_context; + + aio_context =3D bdrv_get_aio_context(state->old_bs); + aio_context_acquire(aio_context); + bdrv_ref(state->old_bs); /* we can't let bdrv_set_backind_hd= () close state->old_bs; we need it = */ bdrv_set_backing_hd(state->new_bs, NULL, &error_abort); bdrv_replace_node(state->new_bs, state->old_bs, &error_abort); bdrv_unref(state->old_bs); /* bdrv_replace_node() ref'ed old_b= s */ + + aio_context_release(aio_context); } } } @@ -1810,11 +1827,19 @@ static void external_snapshot_clean(BlkActionState = *common) { ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); - if (state->aio_context) { - bdrv_drained_end(state->old_bs); - bdrv_unref(state->new_bs); - aio_context_release(state->aio_context); + AioContext *aio_context; + + if (!state->old_bs) { + return; } + + aio_context =3D bdrv_get_aio_context(state->old_bs); + aio_context_acquire(aio_context); + + bdrv_drained_end(state->old_bs); + bdrv_unref(state->new_bs); + + aio_context_release(aio_context); } =20 typedef struct DriveBackupState { --=20 2.14.3 From nobody Tue May 7 15:59: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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15125718368302.1350051710356865; Wed, 6 Dec 2017 06:50:36 -0800 (PST) Received: from localhost ([::1]:56038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb1i-0002i1-VQ for importer@patchew.org; Wed, 06 Dec 2017 09:50:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMayD-0007Pq-MN for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMayC-0003ia-S1 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMay5-0003Z1-5h; Wed, 06 Dec 2017 09:46:37 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C5526A7D4; Wed, 6 Dec 2017 14:46:36 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94EED78410; Wed, 6 Dec 2017 14:46:27 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:44 +0000 Message-Id: <20171206144550.22295-4-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 06 Dec 2017 14:46:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/9] block: don't keep AioContext acquired after drive_backup_prepare() 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org 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" Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- blockdev.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3b598f8f0e..5a56a1abf2 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1845,7 +1845,6 @@ static void external_snapshot_clean(BlkActionState *c= ommon) typedef struct DriveBackupState { BlkActionState common; BlockDriverState *bs; - AioContext *aio_context; BlockJob *job; } DriveBackupState; =20 @@ -1857,6 +1856,7 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); BlockDriverState *bs; DriveBackup *backup; + AioContext *aio_context; Error *local_err =3D NULL; =20 assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); @@ -1867,24 +1867,36 @@ static void drive_backup_prepare(BlkActionState *co= mmon, Error **errp) return; } =20 - /* AioContext is released in .clean() */ - state->aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(state->aio_context); + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + /* Paired with .clean() */ bdrv_drained_begin(bs); + state->bs =3D bs; =20 state->job =3D do_drive_backup(backup, common->block_job_txn, &local_e= rr); if (local_err) { error_propagate(errp, local_err); - return; + goto out; } + +out: + aio_context_release(aio_context); } =20 static void drive_backup_commit(BlkActionState *common) { DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + AioContext *aio_context; + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + assert(state->job); block_job_start(state->job); + + aio_context_release(aio_context); } =20 static void drive_backup_abort(BlkActionState *common) @@ -1892,18 +1904,32 @@ static void drive_backup_abort(BlkActionState *comm= on) DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); =20 if (state->job) { + AioContext *aio_context; + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + block_job_cancel_sync(state->job); + + aio_context_release(aio_context); } } =20 static void drive_backup_clean(BlkActionState *common) { DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + AioContext *aio_context; =20 - if (state->aio_context) { - bdrv_drained_end(state->bs); - aio_context_release(state->aio_context); + if (!state->bs) { + return; } + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + + bdrv_drained_end(state->bs); + + aio_context_release(aio_context); } =20 typedef struct BlockdevBackupState { --=20 2.14.3 From nobody Tue May 7 15:59:58 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512572067119194.25136991304294; Wed, 6 Dec 2017 06:54:27 -0800 (PST) Received: from localhost ([::1]:56080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb5P-0006Cd-AG for importer@patchew.org; Wed, 06 Dec 2017 09:54:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMayL-0007VA-8w for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMayF-0003kN-9x for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:46:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMay7-0003bp-VC; Wed, 06 Dec 2017 09:46:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AFE24903D; Wed, 6 Dec 2017 14:46:39 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id A390C60841; Wed, 6 Dec 2017 14:46:38 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:45 +0000 Message-Id: <20171206144550.22295-5-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 06 Dec 2017 14:46:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/9] block: don't keep AioContext acquired after blockdev_backup_prepare() 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- blockdev.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5a56a1abf2..d7ad76416e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1936,7 +1936,6 @@ typedef struct BlockdevBackupState { BlkActionState common; BlockDriverState *bs; BlockJob *job; - AioContext *aio_context; } BlockdevBackupState; =20 static BlockJob *do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *t= xn, @@ -1947,6 +1946,7 @@ static void blockdev_backup_prepare(BlkActionState *c= ommon, Error **errp) BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); BlockdevBackup *backup; BlockDriverState *bs, *target; + AioContext *aio_context; Error *local_err =3D NULL; =20 assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); @@ -1962,29 +1962,39 @@ static void blockdev_backup_prepare(BlkActionState = *common, Error **errp) return; } =20 - /* AioContext is released in .clean() */ - state->aio_context =3D bdrv_get_aio_context(bs); - if (state->aio_context !=3D bdrv_get_aio_context(target)) { - state->aio_context =3D NULL; + aio_context =3D bdrv_get_aio_context(bs); + if (aio_context !=3D bdrv_get_aio_context(target)) { error_setg(errp, "Backup between two IO threads is not implemented= "); return; } - aio_context_acquire(state->aio_context); + aio_context_acquire(aio_context); state->bs =3D bs; + + /* Paired with .clean() */ bdrv_drained_begin(state->bs); =20 state->job =3D do_blockdev_backup(backup, common->block_job_txn, &loca= l_err); if (local_err) { error_propagate(errp, local_err); - return; + goto out; } + +out: + aio_context_release(aio_context); } =20 static void blockdev_backup_commit(BlkActionState *common) { BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + AioContext *aio_context; + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + assert(state->job); block_job_start(state->job); + + aio_context_release(aio_context); } =20 static void blockdev_backup_abort(BlkActionState *common) @@ -1992,18 +2002,32 @@ static void blockdev_backup_abort(BlkActionState *c= ommon) BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); =20 if (state->job) { + AioContext *aio_context; + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + block_job_cancel_sync(state->job); + + aio_context_release(aio_context); } } =20 static void blockdev_backup_clean(BlkActionState *common) { BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + AioContext *aio_context; =20 - if (state->aio_context) { - bdrv_drained_end(state->bs); - aio_context_release(state->aio_context); + if (!state->bs) { + return; } + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + + bdrv_drained_end(state->bs); + + aio_context_release(aio_context); } =20 typedef struct BlockDirtyBitmapState { --=20 2.14.3 From nobody Tue May 7 15:59: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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512571943039829.4602120878824; Wed, 6 Dec 2017 06:52:23 -0800 (PST) Received: from localhost ([::1]:56052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb3G-00042c-7u for importer@patchew.org; Wed, 06 Dec 2017 09:51:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMayU-0007eh-Lj for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMayR-0003qT-JH for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMayF-0003ji-0R; Wed, 06 Dec 2017 09:46:47 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 183CEC04AC5F; Wed, 6 Dec 2017 14:46:46 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71FCF5F93B; Wed, 6 Dec 2017 14:46:40 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:46 +0000 Message-Id: <20171206144550.22295-6-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 06 Dec 2017 14:46:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/9] block: don't keep AioContext acquired after internal_snapshot_prepare() 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org 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" Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- blockdev.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/blockdev.c b/blockdev.c index d7ad76416e..6332a249ea 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1454,7 +1454,6 @@ struct BlkActionState { typedef struct InternalSnapshotState { BlkActionState common; BlockDriverState *bs; - AioContext *aio_context; QEMUSnapshotInfo sn; bool created; } InternalSnapshotState; @@ -1485,6 +1484,7 @@ static void internal_snapshot_prepare(BlkActionState = *common, qemu_timeval tv; BlockdevSnapshotInternal *internal; InternalSnapshotState *state; + AioContext *aio_context; int ret1; =20 g_assert(common->action->type =3D=3D @@ -1506,32 +1506,33 @@ static void internal_snapshot_prepare(BlkActionStat= e *common, return; } =20 - /* AioContext is released in .clean() */ - state->aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(state->aio_context); + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); =20 state->bs =3D bs; + + /* Paired with .clean() */ bdrv_drained_begin(bs); =20 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) { - return; + goto out; } =20 if (bdrv_is_read_only(bs)) { error_setg(errp, "Device '%s' is read only", device); - return; + goto out; } =20 if (!bdrv_can_snapshot(bs)) { error_setg(errp, "Block format '%s' used by device '%s' " "does not support internal snapshots", bs->drv->format_name, device); - return; + goto out; } =20 if (!strlen(name)) { error_setg(errp, "Name is empty"); - return; + goto out; } =20 /* check whether a snapshot with name exist */ @@ -1539,12 +1540,12 @@ static void internal_snapshot_prepare(BlkActionStat= e *common, &local_err); if (local_err) { error_propagate(errp, local_err); - return; + goto out; } else if (ret) { error_setg(errp, "Snapshot with name '%s' already exists on device '%s'", name, device); - return; + goto out; } =20 /* 3. take the snapshot */ @@ -1560,11 +1561,14 @@ static void internal_snapshot_prepare(BlkActionStat= e *common, error_setg_errno(errp, -ret1, "Failed to create snapshot '%s' on device '%s'", name, device); - return; + goto out; } =20 /* 4. succeed, mark a snapshot is created */ state->created =3D true; + +out: + aio_context_release(aio_context); } =20 static void internal_snapshot_abort(BlkActionState *common) @@ -1573,12 +1577,16 @@ static void internal_snapshot_abort(BlkActionState = *common) DO_UPCAST(InternalSnapshotState, common, comm= on); BlockDriverState *bs =3D state->bs; QEMUSnapshotInfo *sn =3D &state->sn; + AioContext *aio_context; Error *local_error =3D NULL; =20 if (!state->created) { return; } =20 + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) { error_reportf_err(local_error, "Failed to delete snapshot with id '%s' and " @@ -1586,19 +1594,26 @@ static void internal_snapshot_abort(BlkActionState = *common) sn->id_str, sn->name, bdrv_get_device_name(bs)); } + + aio_context_release(aio_context); } =20 static void internal_snapshot_clean(BlkActionState *common) { InternalSnapshotState *state =3D DO_UPCAST(InternalSnapshotState, common, common); + AioContext *aio_context; =20 - if (state->aio_context) { - if (state->bs) { - bdrv_drained_end(state->bs); - } - aio_context_release(state->aio_context); + if (!state->bs) { + return; } + + aio_context =3D bdrv_get_aio_context(state->bs); + aio_context_acquire(aio_context); + + bdrv_drained_end(state->bs); + + aio_context_release(aio_context); } =20 /* external snapshot private data */ --=20 2.14.3 From nobody Tue May 7 15:59: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.zohomail.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 1512571901589315.39927773109457; Wed, 6 Dec 2017 06:51:41 -0800 (PST) Received: from localhost ([::1]:56049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb2t-0003jS-NC for importer@patchew.org; Wed, 06 Dec 2017 09:51:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMayg-00087l-G1 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMaya-0003uq-VH for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMayS-0003qo-Q1; Wed, 06 Dec 2017 09:47:00 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5FC225C38; Wed, 6 Dec 2017 14:46:59 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68D6E68D69; Wed, 6 Dec 2017 14:46:47 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:47 +0000 Message-Id: <20171206144550.22295-7-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 06 Dec 2017 14:46:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 6/9] block: drop unused BlockDirtyBitmapState->aio_context field 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org 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" The dirty bitmap actions in qmp_transaction have not used AioContext since the dirty bitmap locking discipline was introduced in commit 2119882c7eb7e2c612b24fc0c8d86f5887d6f1c3 ("block: introduce dirty_bitmap_mutex"). Remove the unused field. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- blockdev.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6332a249ea..e865ae4873 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2049,7 +2049,6 @@ typedef struct BlockDirtyBitmapState { BlkActionState common; BdrvDirtyBitmap *bitmap; BlockDriverState *bs; - AioContext *aio_context; HBitmap *backup; bool prepared; } BlockDirtyBitmapState; @@ -2128,7 +2127,6 @@ static void block_dirty_bitmap_clear_prepare(BlkActio= nState *common, } =20 bdrv_clear_dirty_bitmap(state->bitmap, &state->backup); - /* AioContext is released in .clean() */ } =20 static void block_dirty_bitmap_clear_abort(BlkActionState *common) @@ -2149,16 +2147,6 @@ static void block_dirty_bitmap_clear_commit(BlkActio= nState *common) hbitmap_free(state->backup); } =20 -static void block_dirty_bitmap_clear_clean(BlkActionState *common) -{ - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); - - if (state->aio_context) { - aio_context_release(state->aio_context); - } -} - static void abort_prepare(BlkActionState *common, Error **errp) { error_setg(errp, "Transaction aborted using Abort action"); @@ -2219,7 +2207,6 @@ static const BlkActionOps actions[] =3D { .prepare =3D block_dirty_bitmap_clear_prepare, .commit =3D block_dirty_bitmap_clear_commit, .abort =3D block_dirty_bitmap_clear_abort, - .clean =3D block_dirty_bitmap_clear_clean, } }; =20 --=20 2.14.3 From nobody Tue May 7 15:59:58 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) 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 151257204340940.51323587950003; Wed, 6 Dec 2017 06:54:03 -0800 (PST) Received: from localhost ([::1]:56079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb4z-0005tj-Ew for importer@patchew.org; Wed, 06 Dec 2017 09:53:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMayy-0000js-G8 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMayx-0004CE-Qg for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMayp-00046a-K4; Wed, 06 Dec 2017 09:47:23 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4CC140F07; Wed, 6 Dec 2017 14:47:22 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3140B6E711; Wed, 6 Dec 2017 14:47:00 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:48 +0000 Message-Id: <20171206144550.22295-8-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 06 Dec 2017 14:47:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 7/9] iothread: add iothread_by_id() API 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Encapsulate IOThread QOM object lookup so that callers don't need to know how and where IOThread objects live. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- include/sysemu/iothread.h | 1 + iothread.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index 110329b2b4..55de1715c7 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -42,6 +42,7 @@ typedef struct { OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD) =20 char *iothread_get_id(IOThread *iothread); +IOThread *iothread_by_id(const char *id); AioContext *iothread_get_aio_context(IOThread *iothread); void iothread_stop_all(void); GMainContext *iothread_get_g_main_context(IOThread *iothread); diff --git a/iothread.c b/iothread.c index 27a4288578..e7b93e02a3 100644 --- a/iothread.c +++ b/iothread.c @@ -380,3 +380,10 @@ void iothread_destroy(IOThread *iothread) { object_unparent(OBJECT(iothread)); } + +/* Lookup IOThread by its id. Only finds user-created objects, not intern= al + * iothread_create() objects. */ +IOThread *iothread_by_id(const char *id) +{ + return IOTHREAD(object_resolve_path_type(id, TYPE_IOTHREAD, NULL)); +} --=20 2.14.3 From nobody Tue May 7 15:59: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.zohomail.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 1512572212630632.4026900847201; Wed, 6 Dec 2017 06:56:52 -0800 (PST) Received: from localhost ([::1]:56102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb7l-00081s-IG for importer@patchew.org; Wed, 06 Dec 2017 09:56:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMaz5-0000yU-7L for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMayz-0004Cs-3D for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMayu-00049e-9n; Wed, 06 Dec 2017 09:47:28 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CECF6016B; Wed, 6 Dec 2017 14:47:27 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 214235F91A; Wed, 6 Dec 2017 14:47:23 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:49 +0000 Message-Id: <20171206144550.22295-9-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Dec 2017 14:47:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 8/9] blockdev: add x-blockdev-set-iothread testing command 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org 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" Currently there is no easy way for iotests to ensure that a BDS is bound to a particular IOThread. Normally the virtio-blk device calls blk_set_aio_context() when dataplane is enabled during guest driver initialization. This never happens in iotests since -machine accel=3Dqtest means there is no guest activity (including device driver initialization). This patch adds a QMP command to explicitly assign IOThreads in test cases. See qapi/block-core.json for a description of the command. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- qapi/block-core.json | 36 ++++++++++++++++++++++++++++++++++++ blockdev.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index dd763dcf87..741d6c4367 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3949,3 +3949,39 @@ 'data' : { 'parent': 'str', '*child': 'str', '*node': 'str' } } + +## +# @x-blockdev-set-iothread: +# +# Move @node and its children into the @iothread. If @iothread is null th= en +# move @node and its children into the main loop. +# +# The node must not be attached to a BlockBackend. +# +# @node-name: the name of the block driver node +# +# @iothread: the name of the IOThread object or null for the main loop +# +# Note: this command is experimental and intended for test cases that need +# control over IOThreads only. +# +# Since: 2.12 +# +# Example: +# +# 1. Move a node into an IOThread +# -> { "execute": "x-blockdev-set-iothread", +# "arguments": { "node-name": "disk1", +# "iothread": "iothread0" } } +# <- { "return": {} } +# +# 2. Move a node into the main loop +# -> { "execute": "x-blockdev-set-iothread", +# "arguments": { "node-name": "disk1", +# "iothread": null } } +# <- { "return": {} } +# +## +{ 'command': 'x-blockdev-set-iothread', + 'data' : { 'node-name': 'str', + 'iothread': 'StrOrNull' } } diff --git a/blockdev.c b/blockdev.c index e865ae4873..f75c01f664 100644 --- a/blockdev.c +++ b/blockdev.c @@ -45,6 +45,7 @@ #include "qapi/qmp/qerror.h" #include "qapi/qobject-output-visitor.h" #include "sysemu/sysemu.h" +#include "sysemu/iothread.h" #include "block/block_int.h" #include "qmp-commands.h" #include "block/trace.h" @@ -4129,6 +4130,46 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp) return head; } =20 +void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothrea= d, + Error **errp) +{ + AioContext *old_context; + AioContext *new_context; + BlockDriverState *bs; + + bs =3D bdrv_find_node(node_name); + if (!bs) { + error_setg(errp, "Cannot find node %s", node_name); + return; + } + + /* If we want to allow more extreme test scenarios this guard could be + * removed. For now it protects against accidents. */ + if (bdrv_has_blk(bs)) { + error_setg(errp, "Node %s is in use", node_name); + return; + } + + if (iothread->type =3D=3D QTYPE_QSTRING) { + IOThread *obj =3D iothread_by_id(iothread->u.s); + if (!obj) { + error_setg(errp, "Cannot find iothread %s", iothread->u.s); + return; + } + + new_context =3D iothread_get_aio_context(obj); + } else { + new_context =3D qemu_get_aio_context(); + } + + old_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(old_context); + + bdrv_set_aio_context(bs, new_context); + + aio_context_release(old_context); +} + QemuOptsList qemu_common_drive_opts =3D { .name =3D "drive", .head =3D QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head), --=20 2.14.3 From nobody Tue May 7 15:59: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.zohomail.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 1512572153278569.8327614211191; Wed, 6 Dec 2017 06:55:53 -0800 (PST) Received: from localhost ([::1]:56096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMb6t-0007Nz-JD for importer@patchew.org; Wed, 06 Dec 2017 09:55:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMaz8-00012D-H1 for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMaz7-0004Jz-8R for qemu-devel@nongnu.org; Wed, 06 Dec 2017 09:47:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49424) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMaz2-0004Fj-4u; Wed, 06 Dec 2017 09:47:36 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D3E5C047B97; Wed, 6 Dec 2017 14:47:35 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE2C06062E; Wed, 6 Dec 2017 14:47:28 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 14:45:50 +0000 Message-Id: <20171206144550.22295-10-stefanha@redhat.com> In-Reply-To: <20171206144550.22295-1-stefanha@redhat.com> References: <20171206144550.22295-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 06 Dec 2017 14:47:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 9/9] qemu-iotests: add 202 external snapshots IOThread test 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 , John Snow , Stefan Hajnoczi , qemu-block@nongnu.org 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" QMP 'transaction' blockdev-snapshot-sync with multiple disks in an IOThread is an untested code path. Several bugs have been found in connection with this command. This patch adds a test case to prevent future regressions. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini --- tests/qemu-iotests/202 | 95 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/202.out | 11 ++++++ tests/qemu-iotests/group | 1 + 3 files changed, 107 insertions(+) create mode 100755 tests/qemu-iotests/202 create mode 100644 tests/qemu-iotests/202.out diff --git a/tests/qemu-iotests/202 b/tests/qemu-iotests/202 new file mode 100755 index 0000000000..581ca34d79 --- /dev/null +++ b/tests/qemu-iotests/202 @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# +# Copyright (C) 2017 Red Hat, Inc. +# +# 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: Stefan Hajnoczi +# +# Check that QMP 'transaction' blockdev-snapshot-sync with multiple drives= on a +# single IOThread completes successfully. This particular command trigger= ed a +# hang due to recursive AioContext locking and BDRV_POLL_WHILE(). Protect +# against regressions. + +import iotests + +iotests.verify_image_format(supported_fmts=3D['qcow2']) +iotests.verify_platform(['linux']) + +with iotests.FilePath('disk0.img') as disk0_img_path, \ + iotests.FilePath('disk1.img') as disk1_img_path, \ + iotests.FilePath('disk0-snap.img') as disk0_snap_img_path, \ + iotests.FilePath('disk1-snap.img') as disk1_snap_img_path, \ + iotests.VM() as vm: + + img_size =3D '10M' + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk0_img_path, = img_size) + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk1_img_path, = img_size) + + iotests.log('Launching VM...') + vm.launch() + + iotests.log('Adding IOThread...') + iotests.log(vm.qmp('object-add', + qom_type=3D'iothread', + id=3D'iothread0')) + + iotests.log('Adding blockdevs...') + iotests.log(vm.qmp('blockdev-add', + driver=3Diotests.imgfmt, + node_name=3D'disk0', + file=3D{ + 'driver': 'file', + 'filename': disk0_img_path, + })) + iotests.log(vm.qmp('blockdev-add', + driver=3Diotests.imgfmt, + node_name=3D'disk1', + file=3D{ + 'driver': 'file', + 'filename': disk1_img_path, + })) + + iotests.log('Setting iothread...') + iotests.log(vm.qmp('x-blockdev-set-iothread', + node_name=3D'disk0', + iothread=3D'iothread0')) + iotests.log(vm.qmp('x-blockdev-set-iothread', + node_name=3D'disk1', + iothread=3D'iothread0')) + + iotests.log('Creating external snapshots...') + iotests.log(vm.qmp( + 'transaction', + actions=3D[ + { + 'data': { + 'node-name': 'disk0', + 'snapshot-file': disk0_snap_img_path, + 'snapshot-node-name': 'disk0-snap', + 'mode': 'absolute-paths', + 'format': iotests.imgfmt, + }, + 'type': 'blockdev-snapshot-sync' + }, { + 'data': { + 'node-name': 'disk1', + 'snapshot-file': disk1_snap_img_path, + 'snapshot-node-name': 'disk1-snap', + 'mode': 'absolute-paths', + 'format': iotests.imgfmt + }, + 'type': 'blockdev-snapshot-sync' + } + ])) diff --git a/tests/qemu-iotests/202.out b/tests/qemu-iotests/202.out new file mode 100644 index 0000000000..d5ea374e17 --- /dev/null +++ b/tests/qemu-iotests/202.out @@ -0,0 +1,11 @@ +Launching VM... +Adding IOThread... +{u'return': {}} +Adding blockdevs... +{u'return': {}} +{u'return': {}} +Setting iothread... +{u'return': {}} +{u'return': {}} +Creating external snapshots... +{u'return': {}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 3e688678dd..d0ee1e2e55 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -197,3 +197,4 @@ 197 rw auto quick 198 rw auto 200 rw auto +202 rw auto quick --=20 2.14.3