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=1568305140; cv=none; d=zoho.com; s=zohoarc; b=fFhA02pH7mvsn6zl4iOtDE6+xJ+AzBrD7ligF9xZf71QdWR9lsiNOsfRH5Ur2zd0MVwE7NmxFOFE2fNtNshiLWtb1KTg6YwcrJdX3SfZ5LkBBqynVTkqbK8v5coMGWzpcwYQcCRYBSPjKEzE1F9/ISF5HRJ9mn3lnWTpEZmgKWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568305140; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=n/1h7JvZj2LPb4IpBxM7V+stXIfn4EEh2AaogASom7o=; b=iz0YqgGF5F0Ck98rrcRHsM93CV0DEGHuBRUTMkYcfQzg7AJhh7BYdFA0zzjCnRf214PRLcoxtfRLYvgCCvYcoHapfv/wDu2b3//jM5Qq18/tK2K5Wjl0OmPqzUMvaRQR4TJkI1Q/5psvV/byi7UdzMrl1Ela/C15epo5vbTtKso= 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 1568305140584875.9379638095587; Thu, 12 Sep 2019 09:19:00 -0700 (PDT) Received: from localhost ([::1]:36878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8RoA-0001rf-H6 for importer@patchew.org; Thu, 12 Sep 2019 12:18:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53929) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Rn8-0001Ci-Fv for qemu-devel@nongnu.org; Thu, 12 Sep 2019 12:17:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Rn5-00033d-9h for qemu-devel@nongnu.org; Thu, 12 Sep 2019 12:17:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49208) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Rmy-0002xw-IU; Thu, 12 Sep 2019 12:17:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECF795AFF8; Thu, 12 Sep 2019 16:17:42 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id C46B43DB2; Thu, 12 Sep 2019 16:17:38 +0000 (UTC) From: Sergio Lopez To: qemu-block@nongnu.org Date: Thu, 12 Sep 2019 18:16:25 +0200 Message-Id: <20190912161624.40886-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 12 Sep 2019 16:17:42 +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] blockdev: avoid acquiring AioContext lock twice at do_drive_backup() 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() acquires the AioContext lock of the corresponding BlockDriverState. This is not a problem when it's called from qmp_drive_backup(), but drive_backup_prepare() also acquires the lock before calling it. This change adds a BlockDriverState argument to do_drive_backup(), which is used to signal that the context lock is already acquired and to save a couple of redundant calls. Signed-off-by: Sergio Lopez --- blockdev.c | 54 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/blockdev.c b/blockdev.c index fbef6845c8..0cc6c69ceb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1762,8 +1762,10 @@ typedef struct DriveBackupState { BlockJob *job; } DriveBackupState; =20 -static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, - Error **errp); +static BlockJob *do_drive_backup(DriveBackup *backup, + BlockDriverState *backup_bs, + JobTxn *txn, + Error **errp); =20 static void drive_backup_prepare(BlkActionState *common, Error **errp) { @@ -1781,6 +1783,11 @@ static void drive_backup_prepare(BlkActionState *com= mon, Error **errp) return; } =20 + if (!bs->drv) { + error_setg(errp, "Device has no medium"); + return; + } + aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 @@ -1789,7 +1796,9 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) =20 state->bs =3D bs; =20 - state->job =3D do_drive_backup(backup, common->block_job_txn, &local_e= rr); + state->job =3D do_drive_backup(backup, bs, + common->block_job_txn, + &local_err); if (local_err) { error_propagate(errp, local_err); goto out; @@ -3607,7 +3616,9 @@ static BlockJob *do_backup_common(BackupCommon *backu= p, return job; } =20 -static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, +static BlockJob *do_drive_backup(DriveBackup *backup, + BlockDriverState *backup_bs, + JobTxn *txn, Error **errp) { BlockDriverState *bs; @@ -3625,18 +3636,27 @@ static BlockJob *do_drive_backup(DriveBackup *backu= p, JobTxn *txn, backup->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; } =20 - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return NULL; - } + if (backup_bs) { + bs =3D backup_bs; + /* + * If the caller passes us a BDS, we assume it has already + * acquired the context lock. + */ + aio_context =3D bdrv_get_aio_context(bs); + } else { + bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); + if (!bs) { + return NULL; + } =20 - if (!bs->drv) { - error_setg(errp, "Device has no medium"); - return NULL; - } + if (!bs->drv) { + error_setg(errp, "Device has no medium"); + return NULL; + } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + } =20 if (!backup->has_format) { backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? @@ -3713,7 +3733,9 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, unref: bdrv_unref(target_bs); out: - aio_context_release(aio_context); + if (!backup_bs) { + aio_context_release(aio_context); + } return job; } =20 @@ -3721,7 +3743,7 @@ void qmp_drive_backup(DriveBackup *arg, Error **errp) { =20 BlockJob *job; - job =3D do_drive_backup(arg, NULL, errp); + job =3D do_drive_backup(arg, NULL, NULL, errp); if (job) { job_start(&job->job); } --=20 2.21.0