From nobody Wed Nov 12 03:42:20 2025 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568388671; cv=none; d=zoho.com; s=zohoarc; b=FkBqirl7PZ1ri/Z0vQgNe9tKBK3Bz7LOoU57waw8diCde6oWaK9GvHYj1pZfdeKI91CUPkx+/FeO480bc/kD1ttXnA/Kd6McLzf6xFu+1LuQw1sy790tjHl8KS76bl/vLeTLfUK6ENU+5K0kMIC+hTvx9vso2ZBOOGWHkB3jiS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568388671; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=p9Z6fOhvtIUum/I1HVCNPVeMRR2aY0NOF4v/W0r7m2Y=; b=e0up33hrx6mr/bQV5Wq1zx4EttqAQDth+FiuqbO3l82pYGIN0A/Jg+XzhtY2FSrXIrzP3DAM67Go5BQqjyLo8TiIcR/cOBhcAzWI8ueUHMvfs4Yf4xrBDS2MF8jJxPawICt13kULF2JJ4LG/DlPAcIq9JqMqckA7ZbwkBatjXRQ= ARC-Authentication-Results: i=1; mx.zoho.com; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568388671983533.1829573349087; Fri, 13 Sep 2019 08:31:11 -0700 (PDT) Received: from localhost ([::1]:45321 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8nXP-0003zx-8Q for importer@patchew.org; Fri, 13 Sep 2019 11:31:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53172) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8nSN-0006my-C6 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 11:25:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8nSM-0003T3-Ai for qemu-devel@nongnu.org; Fri, 13 Sep 2019 11:25:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45312) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8nSK-0003QD-DI; Fri, 13 Sep 2019 11:25:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A67F3898102; Fri, 13 Sep 2019 15:25:51 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16D021001959; Fri, 13 Sep 2019 15:25:49 +0000 (UTC) From: Sergio Lopez To: qemu-block@nongnu.org Date: Fri, 13 Sep 2019 17:25:07 +0200 Message-Id: <20190913152507.56197-2-slp@redhat.com> In-Reply-To: <20190913152507.56197-1-slp@redhat.com> References: <20190913152507.56197-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Fri, 13 Sep 2019 15:25:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] blockdev: release the AioContext at drive_backup_prepare X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, Sergio Lopez , mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" do_drive_backup() already acquires the AioContext, so release it before the call. Signed-off-by: Sergio Lopez --- blockdev.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index fbef6845c8..3927fdab80 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1783,20 +1783,16 @@ static void drive_backup_prepare(BlkActionState *co= mmon, Error **errp) =20 aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - /* Paired with .clean() */ bdrv_drained_begin(bs); + aio_context_release(aio_context); =20 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); - goto out; } - -out: - aio_context_release(aio_context); } =20 static void drive_backup_commit(BlkActionState *common) --=20 2.21.0 From nobody Wed Nov 12 03:42:20 2025 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568388540; cv=none; d=zoho.com; s=zohoarc; b=GuRrWR8I1K4RfdPyqZ7w8OElvBMGiayNLF1+muPYCWp1GJGt5+jfZYuW2QEexWuYCLVWkFIbG8GnB1oRiguiM7swfuPKssd9rNhZCc5CfBzdjsYLo5EEJrH1J60ifRMMMCIVnQhDxbQ13IwJw3ymqA8YZFvhyNb4dhmFCRj1veU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568388540; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=XWQxG05x3B9/1JCL2yJzyhcnIHuym4AGPyacmpZUZOs=; b=POSuM+z8jy7/yTp1S0iEFHe1561C5/Yi5Lrtv589OVS34urVtZ8fdMGs3lN3MZa0y47emwww3WqY6eBD8gt4jw+XOjMGi9hXNuVDo9otGgvq6PwGwVzB+quf/X3fcoHyldNbUm2AynqJ9V/nJJ2lXG8KHzzhRECQ+5GRSvQW774= ARC-Authentication-Results: i=1; mx.zoho.com; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568388540016842.1622094920607; Fri, 13 Sep 2019 08:29:00 -0700 (PDT) Received: from localhost ([::1]:45252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8nVI-0000zk-DN for importer@patchew.org; Fri, 13 Sep 2019 11:28:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53202) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8nSS-0006u8-GV for qemu-devel@nongnu.org; Fri, 13 Sep 2019 11:26:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8nSQ-0003WU-D4 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 11:26:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8nSM-0003Sz-Fx; Fri, 13 Sep 2019 11:25:54 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9F9A315C007; Fri, 13 Sep 2019 15:25:53 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A36F1001938; Fri, 13 Sep 2019 15:25:51 +0000 (UTC) From: Sergio Lopez To: qemu-block@nongnu.org Date: Fri, 13 Sep 2019 17:25:08 +0200 Message-Id: <20190913152507.56197-3-slp@redhat.com> In-Reply-To: <20190913152507.56197-1-slp@redhat.com> References: <20190913152507.56197-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 13 Sep 2019 15:25:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/2] blockdev: honor bdrv_try_set_aio_context() context requirements X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, Sergio Lopez , mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_try_set_aio_context() requires that the old context is held, and the new context is not held. Fix all the ocurrences where it's not done this way. Suggested-by: Max Reitz Signed-off-by: Sergio Lopez --- blockdev.c | 121 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 46 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3927fdab80..2534fef389 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1536,6 +1536,7 @@ static void external_snapshot_prepare(BlkActionState = *common, DO_UPCAST(ExternalSnapshotState, common, comm= on); TransactionAction *action =3D common->action; AioContext *aio_context; + AioContext *old_context; int ret; =20 /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar @@ -1575,30 +1576,30 @@ static void external_snapshot_prepare(BlkActionStat= e *common, =20 aio_context =3D bdrv_get_aio_context(state->old_bs); aio_context_acquire(aio_context); - /* Paired with .clean() */ bdrv_drained_begin(state->old_bs); + aio_context_release(aio_context); =20 if (!bdrv_is_inserted(state->old_bs)) { error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); - goto out; + return; } =20 if (bdrv_op_is_blocked(state->old_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, errp)) { - goto out; + return; } =20 if (!bdrv_is_read_only(state->old_bs)) { if (bdrv_flush(state->old_bs)) { error_setg(errp, QERR_IO_ERROR); - goto out; + return; } } =20 if (!bdrv_is_first_non_filter(state->old_bs)) { error_setg(errp, QERR_FEATURE_DISABLED, "snapshot"); - goto out; + return; } =20 if (action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC= ) { @@ -1610,13 +1611,13 @@ static void external_snapshot_prepare(BlkActionStat= e *common, =20 if (node_name && !snapshot_node_name) { error_setg(errp, "New overlay node name missing"); - goto out; + return; } =20 if (snapshot_node_name && bdrv_lookup_bs(snapshot_node_name, snapshot_node_name, NULL)) { error_setg(errp, "New overlay node name already in use"); - goto out; + return; } =20 flags =3D state->old_bs->open_flags; @@ -1629,7 +1630,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"); - goto out; + return; } bdrv_refresh_filename(state->old_bs); bdrv_img_create(new_image_file, format, @@ -1638,7 +1639,7 @@ static void external_snapshot_prepare(BlkActionState = *common, NULL, size, flags, false, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out; + return; } } =20 @@ -1653,34 +1654,41 @@ 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) { - goto out; + return; } =20 if (bdrv_has_blk(state->new_bs)) { error_setg(errp, "The overlay is already in use"); - goto out; + return; } =20 if (bdrv_op_is_blocked(state->new_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, errp)) { - goto out; + return; } =20 if (state->new_bs->backing !=3D NULL) { error_setg(errp, "The overlay already has a backing image"); - goto out; + return; } =20 if (!state->new_bs->drv->supports_backing) { error_setg(errp, "The overlay does not support backing images"); - goto out; + return; } =20 + old_context =3D bdrv_get_aio_context(state->new_bs); + aio_context_acquire(old_context); + ret =3D bdrv_try_set_aio_context(state->new_bs, aio_context, errp); if (ret < 0) { - goto out; + aio_context_release(old_context); + return; } =20 + aio_context_release(old_context); + aio_context_acquire(aio_context); + /* 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 * always possible. */ @@ -1688,11 +1696,10 @@ 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); - goto out; + } else { + state->overlay_appended =3D true; } - state->overlay_appended =3D true; =20 -out: aio_context_release(aio_context); } =20 @@ -3490,13 +3497,11 @@ out: static BlockJob *do_backup_common(BackupCommon *backup, BlockDriverState *bs, BlockDriverState *target_bs, - AioContext *aio_context, JobTxn *txn, Error **errp) { BlockJob *job =3D NULL; BdrvDirtyBitmap *bmap =3D NULL; int job_flags =3D JOB_DEFAULT; - int ret; =20 if (!backup->has_speed) { backup->speed =3D 0; @@ -3520,11 +3525,6 @@ static BlockJob *do_backup_common(BackupCommon *back= up, backup->compress =3D false; } =20 - ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); - if (ret < 0) { - return NULL; - } - if ((backup->sync =3D=3D MIRROR_SYNC_MODE_BITMAP) || (backup->sync =3D=3D MIRROR_SYNC_MODE_INCREMENTAL)) { /* done before desugaring 'incremental' to print the right message= */ @@ -3611,11 +3611,13 @@ static BlockJob *do_drive_backup(DriveBackup *backu= p, JobTxn *txn, BlockDriverState *source =3D NULL; BlockJob *job =3D NULL; AioContext *aio_context; + AioContext *old_context; QDict *options; Error *local_err =3D NULL; int flags; int64_t size; bool set_backing_hd =3D false; + int ret; =20 if (!backup->has_mode) { backup->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; @@ -3631,9 +3633,6 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, return NULL; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - if (!backup->has_format) { backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? NULL : (char*) bs->drv->format_name; @@ -3641,7 +3640,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, =20 /* Early check to avoid creating target */ if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { - goto out; + return NULL; } =20 flags =3D bs->open_flags | BDRV_O_RDWR; @@ -3663,7 +3662,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, size =3D bdrv_getlength(bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); - goto out; + return NULL; } =20 if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { @@ -3681,7 +3680,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, =20 if (local_err) { error_propagate(errp, local_err); - goto out; + return NULL; } =20 options =3D qdict_new(); @@ -3693,22 +3692,34 @@ static BlockJob *do_drive_backup(DriveBackup *backu= p, JobTxn *txn, =20 target_bs =3D bdrv_open(backup->target, NULL, options, flags, errp); if (!target_bs) { - goto out; + return NULL; + } + + aio_context =3D bdrv_get_aio_context(bs); + old_context =3D bdrv_get_aio_context(target_bs); + aio_context_acquire(old_context); + + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + if (ret < 0) { + aio_context_release(old_context); + return NULL; } =20 + aio_context_release(old_context); + aio_context_acquire(aio_context); + if (set_backing_hd) { bdrv_set_backing_hd(target_bs, source, &local_err); if (local_err) { - goto unref; + goto out; } } =20 job =3D do_backup_common(qapi_DriveBackup_base(backup), - bs, target_bs, aio_context, txn, errp); + bs, target_bs, txn, errp); =20 -unref: - bdrv_unref(target_bs); out: + bdrv_unref(target_bs); aio_context_release(aio_context); return job; } @@ -3739,7 +3750,9 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup, = JobTxn *txn, BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; + AioContext *old_context; BlockJob *job; + int ret; =20 bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); if (!bs) { @@ -3752,10 +3765,20 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup= , JobTxn *txn, } =20 aio_context =3D bdrv_get_aio_context(bs); + old_context =3D bdrv_get_aio_context(target_bs); + aio_context_acquire(old_context); + + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + if (ret < 0) { + aio_context_release(old_context); + return NULL; + } + + aio_context_release(old_context); aio_context_acquire(aio_context); =20 job =3D do_backup_common(qapi_BlockdevBackup_base(backup), - bs, target_bs, aio_context, txn, errp); + bs, target_bs, txn, errp); =20 aio_context_release(aio_context); return job; @@ -3897,6 +3920,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) BlockDriverState *bs; BlockDriverState *source, *target_bs; AioContext *aio_context; + AioContext *old_context; BlockMirrorBackingMode backing_mode; Error *local_err =3D NULL; QDict *options =3D NULL; @@ -3916,9 +3940,6 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) return; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - if (!arg->has_mode) { arg->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; } @@ -3940,14 +3961,14 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) size =3D bdrv_getlength(bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); - goto out; + return; } =20 if (arg->has_replaces) { if (!arg->has_node_name) { error_setg(errp, "a node-name must be provided when replacing = a" " named node of the graph"); - goto out; + return; } } =20 @@ -3986,7 +4007,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) =20 if (local_err) { error_propagate(errp, local_err); - goto out; + return; } =20 options =3D qdict_new(); @@ -4002,19 +4023,27 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) */ target_bs =3D bdrv_open(arg->target, NULL, options, flags, errp); if (!target_bs) { - goto out; + return; } =20 zero_target =3D (arg->sync =3D=3D MIRROR_SYNC_MODE_FULL && (arg->mode =3D=3D NEW_IMAGE_MODE_EXISTING || !bdrv_has_zero_init(target_bs))); =20 + aio_context =3D bdrv_get_aio_context(bs); + old_context =3D bdrv_get_aio_context(target_bs); + aio_context_acquire(old_context); + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); if (ret < 0) { bdrv_unref(target_bs); - goto out; + aio_context_release(old_context); + return; } =20 + aio_context_release(old_context); + aio_context_acquire(aio_context); + blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, targe= t_bs, arg->has_replaces, arg->replaces, arg->sync, backing_mode, zero_target, @@ -4031,7 +4060,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) &local_err); bdrv_unref(target_bs); error_propagate(errp, local_err); -out: + aio_context_release(aio_context); } =20 --=20 2.21.0