From nobody Thu Dec 18 13:28:38 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=1559575310; cv=none; d=zoho.com; s=zohoarc; b=Kqx/M6eV3B+FfiQtk/nAJC0BeKUs8UEIMojw8BX+fmwl5IwrLUsqwyh9XbnMLQ9R1Fq1AVwfBpei9ykHUvX0wsuT7vjFhWOYcIr0fBY8A228fnSNQAHJ5hhUFYkjesjTGyzQsJAz4R0cHu4aZWm+6J7AR3mTzB1hOPstf8JsSAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559575310; 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=RutF0aj+7GkurfDm4PZHIYFCA5CMN+TXGuFDP88Suxo=; b=TswzY6Lf4Jr8XZ9P34ryrS2PO1oORsj1KwN95o6Zf8/2CATLJX1w33vBMi5u6dwIQcUiIJ/u29F2+jUSxdoHi0x+Mjw9xenP8BZsHIEUSk4UhZ32HIrS9o31Q3An9bfITWQcwKREDnSWoIkBRgql7xt+E/budWxVK8ziRNcglBA= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559575310985524.6973797904457; Mon, 3 Jun 2019 08:21:50 -0700 (PDT) Received: from localhost ([127.0.0.1]:36563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXomL-0006ks-SI for importer@patchew.org; Mon, 03 Jun 2019 11:21:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXoVv-0001Rt-L5 for qemu-devel@nongnu.org; Mon, 03 Jun 2019 11:04:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hXoVu-0001D0-64 for qemu-devel@nongnu.org; Mon, 03 Jun 2019 11:04:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hXoVk-0000R3-Jr; Mon, 03 Jun 2019 11:04:34 -0400 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 B491B30860AF; Mon, 3 Jun 2019 15:04:15 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-129.ams2.redhat.com [10.36.116.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51D1D6727B; Mon, 3 Jun 2019 15:04:11 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 3 Jun 2019 17:02:25 +0200 Message-Id: <20190603150233.6614-21-kwolf@redhat.com> In-Reply-To: <20190603150233.6614-1-kwolf@redhat.com> References: <20190603150233.6614-1-kwolf@redhat.com> MIME-Version: 1.0 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.44]); Mon, 03 Jun 2019 15:04:15 +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] [PULL 20/28] blockdev: Use bdrv_try_set_aio_context() for monitor commands 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Monitor commands can handle errors, so they can easily be converted to using the safer bdrv_try_set_aio_context() function. Signed-off-by: Kevin Wolf --- blockdev.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/blockdev.c b/blockdev.c index 80dad6d117..a138ca9dbe 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1535,6 +1535,7 @@ static void external_snapshot_prepare(BlkActionState = *common, DO_UPCAST(ExternalSnapshotState, common, comm= on); TransactionAction *action =3D common->action; AioContext *aio_context; + int ret; =20 /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar * purpose but a different set of parameters */ @@ -1674,7 +1675,10 @@ static void external_snapshot_prepare(BlkActionState= *common, goto out; } =20 - bdrv_set_aio_context(state->new_bs, aio_context); + ret =3D bdrv_try_set_aio_context(state->new_bs, aio_context, errp); + if (ret < 0) { + goto out; + } =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 @@ -3440,6 +3444,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, int flags, job_flags =3D JOB_DEFAULT; int64_t size; bool set_backing_hd =3D false; + int ret; =20 if (!backup->has_speed) { backup->speed =3D 0; @@ -3541,7 +3546,11 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, goto out; } =20 - bdrv_set_aio_context(target_bs, aio_context); + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + if (ret < 0) { + bdrv_unref(target_bs); + goto out; + } =20 if (set_backing_hd) { bdrv_set_backing_hd(target_bs, source, &local_err); @@ -3613,6 +3622,7 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup, = JobTxn *txn, AioContext *aio_context; BlockJob *job =3D NULL; int job_flags =3D JOB_DEFAULT; + int ret; =20 if (!backup->has_speed) { backup->speed =3D 0; @@ -3649,16 +3659,9 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup,= JobTxn *txn, goto out; } =20 - if (bdrv_get_aio_context(target_bs) !=3D aio_context) { - if (!bdrv_has_blk(target_bs)) { - /* The target BDS is not attached, we can safely move it to an= other - * AioContext. */ - bdrv_set_aio_context(target_bs, aio_context); - } else { - error_setg(errp, "Target is attached to a different thread fro= m " - "source."); - goto out; - } + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + if (ret < 0) { + goto out; } =20 if (backup->has_bitmap) { @@ -3831,6 +3834,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) int flags; int64_t size; const char *format =3D arg->format; + int ret; =20 bs =3D qmp_get_root_bs(arg->device, errp); if (!bs) { @@ -3931,7 +3935,11 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) goto out; } =20 - bdrv_set_aio_context(target_bs, aio_context); + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + if (ret < 0) { + bdrv_unref(target_bs); + goto out; + } =20 blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, targe= t_bs, arg->has_replaces, arg->replaces, arg->sync, @@ -3975,6 +3983,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, AioContext *aio_context; BlockMirrorBackingMode backing_mode =3D MIRROR_LEAVE_BACKING_CHAIN; Error *local_err =3D NULL; + int ret; =20 bs =3D qmp_get_root_bs(device, errp); if (!bs) { @@ -3989,7 +3998,10 @@ void qmp_blockdev_mirror(bool has_job_id, const char= *job_id, aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 - bdrv_set_aio_context(target_bs, aio_context); + ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + if (ret < 0) { + goto out; + } =20 blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs, has_replaces, replaces, sync, backing_mode, @@ -4005,7 +4017,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, has_auto_dismiss, auto_dismiss, &local_err); error_propagate(errp, local_err); - +out: aio_context_release(aio_context); } =20 @@ -4495,7 +4507,7 @@ void qmp_x_blockdev_set_iothread(const char *node_nam= e, StrOrNull *iothread, old_context =3D bdrv_get_aio_context(bs); aio_context_acquire(old_context); =20 - bdrv_set_aio_context(bs, new_context); + bdrv_try_set_aio_context(bs, new_context, errp); =20 aio_context_release(old_context); } --=20 2.20.1