From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558465; cv=none; d=zoho.com; s=zohoarc; b=eO/+QSG2wH4h9F0IpvgT7IbCqO5QKPxyluQ+xzcWHdV4KalsktqNG6sz0OQZHwxGn9rpjCtPN7TQrfTEzO6ccdAtR/CevuLuZojdT4NjyBw49YL8KnOojMH1YCLNuwLU1YOh0q/ELRI4+yrikWueRKb1Qf4XXMmnu48z+ffE5O0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558465; h=Content-Type: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; bh=Gb1RH33aSR0RM4IoeQcShNydzzy0Bqn3bnB1YpWv//o=; b=ntBTGpkDWE/bR95LlQeYKfB7aqTXm14LEKRdWS2CmUNjBEZnWiQbXD1i3aba5macgvAXxAVNMu/1InjOvcCjqf4OwV8JFU1dXWxB++H4Eht2qShWoWhSEgDlfQoL5Q6f30iFXOHtAsdrn6b7ulO67FGBW215Y5V4fozdzVUhpAU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 157355846540877.49288778393793; Tue, 12 Nov 2019 03:34:25 -0800 (PST) Received: from localhost ([::1]:33622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUURD-0008UZ-I4 for importer@patchew.org; Tue, 12 Nov 2019 06:34:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUOU-0006as-3z for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:31:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUOP-00011a-36 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:31:34 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:36495 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOO-00011P-G1 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:31:28 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-cW7v-wWnOP6HWPzoekkNUA-1; Tue, 12 Nov 2019 06:30:20 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 624FD800C61; Tue, 12 Nov 2019 11:30:19 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFB3A60D5C; Tue, 12 Nov 2019 11:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gb1RH33aSR0RM4IoeQcShNydzzy0Bqn3bnB1YpWv//o=; b=Ov2fEOrYobjWyM5iV9x4FgcXQexyMPTkxTBGEqbe1gQCtMru8bvu+sK3bGKIQhQomf59Iz OKX+cm5eape6ERuaWTfFSKe1zSQK5cjVd8T/HCY8u0QU/EFkLSspNptskP/a9QVuMdm1cI LfLRyz0T9ILKC/kusEvRraf2uTRu2Fc= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 1/8] blockdev: merge drive_backup_prepare with do_drive_backup Date: Tue, 12 Nov 2019 12:30:05 +0100 Message-Id: <20191112113012.71136-2-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: cW7v-wWnOP6HWPzoekkNUA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Consolidate drive_backup_prepare() with do_drive_backup() as a first step towards streamlining all functionality through transactions. Signed-off-by: Sergio Lopez --- blockdev.c | 58 +++++++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/blockdev.c b/blockdev.c index 8e029e9c01..5d30aff1e5 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1764,40 +1764,6 @@ typedef struct DriveBackupState { static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, Error **errp); =20 -static void drive_backup_prepare(BlkActionState *common, Error **errp) -{ - DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); - BlockDriverState *bs; - DriveBackup *backup; - AioContext *aio_context; - Error *local_err =3D NULL; - - assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); - backup =3D common->action->u.drive_backup.data; - - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - /* Paired with .clean() */ - bdrv_drained_begin(bs); - - state->bs =3D bs; - - 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); -} - static void drive_backup_commit(BlkActionState *common) { DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); @@ -3587,13 +3553,13 @@ static BlockJob *do_backup_common(BackupCommon *bac= kup, return job; } =20 -static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, - Error **errp) +static void drive_backup_prepare(BlkActionState *common, Error **errp) { + DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + DriveBackup *backup; BlockDriverState *bs; BlockDriverState *target_bs; BlockDriverState *source =3D NULL; - BlockJob *job =3D NULL; AioContext *aio_context; QDict *options; Error *local_err =3D NULL; @@ -3601,23 +3567,29 @@ static BlockJob *do_drive_backup(DriveBackup *backu= p, JobTxn *txn, int64_t size; bool set_backing_hd =3D false; =20 + assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); + backup =3D common->action->u.drive_backup.data; + if (!backup->has_mode) { backup->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; } =20 bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); if (!bs) { - return NULL; + return; } =20 if (!bs->drv) { error_setg(errp, "Device has no medium"); - return NULL; + return; } =20 aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 + /* Paired with .clean() */ + bdrv_drained_begin(bs); + if (!backup->has_format) { backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? NULL : (char*) bs->drv->format_name; @@ -3687,14 +3659,16 @@ static BlockJob *do_drive_backup(DriveBackup *backu= p, JobTxn *txn, } } =20 - job =3D do_backup_common(qapi_DriveBackup_base(backup), - bs, target_bs, aio_context, txn, errp); + state->bs =3D bs; + + state->job =3D do_backup_common(qapi_DriveBackup_base(backup), + bs, target_bs, aio_context, + common->block_job_txn, errp); =20 unref: bdrv_unref(target_bs); out: aio_context_release(aio_context); - return job; } =20 void qmp_drive_backup(DriveBackup *arg, Error **errp) --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558647; cv=none; d=zoho.com; s=zohoarc; b=lDi/ZSnw9Ova8T+HDd/UNof2sNdXqQEMC6h2kWlj6MpiCc3K8EaMUWLYB/ncoYptlF2ezvNtZz3PSxa+HB7mTNAosxU3+mvLjWA4yB8Dx6uAkoZ753xnUeB32UJl5WTuZto6xJWtyFXvYdgVZApPLFEXquSTPcGF/0bM1i0c4Cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558647; h=Content-Type: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; bh=6lW7FaNY79zsFV9+XLGaGBYg6heTfL4IuCc6Bq9FTHg=; b=f30vUAv5SCcfIRQ+RB6nMAdUHX98NdRCYJmj9S+hC0TTbLXFLbrOdVJeae2KObKzO8IJSYTIyyzQnhvFNAyrjWW1k8pDDwJLBUfndDImAtxIhuIy6Vko4GPWd+wwDBJdCSbPc12LH0qfaqZt7s1tOpnO4P/pMKqt6aTFHv4Cksc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573558647925794.2152733786364; Tue, 12 Nov 2019 03:37:27 -0800 (PST) Received: from localhost ([::1]:33682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUUA-0003by-LL for importer@patchew.org; Tue, 12 Nov 2019 06:37:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35579) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUP2-0007GC-7n for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUOy-000195-57 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31243 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOw-000189-1o for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:02 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-n0LTeF1gOB6W5R6BJ_0HfQ-1; Tue, 12 Nov 2019 06:30:22 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C26F8017E0; Tue, 12 Nov 2019 11:30:21 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBB1760A89; Tue, 12 Nov 2019 11:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6lW7FaNY79zsFV9+XLGaGBYg6heTfL4IuCc6Bq9FTHg=; b=C3DQJy+W1wmR4Ise3F6X2gkgez8M4HKH3I+byW4PgUYAydg7xDWhG4dCwPr2hjwyQtpbgu LSdD8EGWU678AYEo6RQVWpZtzWxkieKQilXp1Kyj9N+s5asfZB9PdIL615KNyt3ulfv2jw rkCZKzl5gLrx8nT8ke+eW5/GiE9CQjA= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 2/8] blockdev: fix coding style issues in drive_backup_prepare Date: Tue, 12 Nov 2019 12:30:06 +0100 Message-Id: <20191112113012.71136-3-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: n0LTeF1gOB6W5R6BJ_0HfQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fix a couple of minor coding style issues in drive_backup_prepare. Signed-off-by: Sergio Lopez --- blockdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5d30aff1e5..e8b673c5f3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3592,7 +3592,7 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) =20 if (!backup->has_format) { backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? - NULL : (char*) bs->drv->format_name; + NULL : (char *) bs->drv->format_name; } =20 /* Early check to avoid creating target */ @@ -3602,8 +3602,10 @@ static void drive_backup_prepare(BlkActionState *com= mon, Error **errp) =20 flags =3D bs->open_flags | BDRV_O_RDWR; =20 - /* See if we have a backing HD we can use to create our new image - * on top of. */ + /* + * See if we have a backing HD we can use to create our new image + * on top of. + */ if (backup->sync =3D=3D MIRROR_SYNC_MODE_TOP) { source =3D backing_bs(bs); if (!source) { --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558879; cv=none; d=zoho.com; s=zohoarc; b=Ui9kfJ86JBsh4wYyZLfitYypgWNj/5iVTpN0M0FFuFvKceiVPAG/f8WU/e6PpwFZ6m1aDCba/sSeLYu671Adro9holg5YzQJH0AhEEbA0XjplITP5kTmL7NWmVf/C3mJKYOCSwOWRmNoq2TkDOTgmIhncejTuku9PfQcVg2UYvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558879; h=Content-Type: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; bh=XrXr/+SNgujjOhRg7OiEQAfxJshPf36cCDpafuAMPIY=; b=Zh7iDyTvDiwam74uBJwf+jr/o5OidkLCfq8sqcLVJkg66jSMMc/HA12MiE20s3l9Wh0J4MaA5Qq2CMAUxZqY6V2I4R7JtpofHsfjhyI9cTWQ+FHvVBlzm9aJdY3Hb17ybVn4m+TS2srzmmIqTP/LgpX7MAKYR98LFY2S+rNXzDw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573558879609414.26468863087325; Tue, 12 Nov 2019 03:41:19 -0800 (PST) Received: from localhost ([::1]:33742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUXt-0007a2-GR for importer@patchew.org; Tue, 12 Nov 2019 06:41:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35644) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUP9-0007Hy-8h for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUP2-0001BO-4u for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:33562 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUP0-00018I-0L for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:08 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-uiLl8FzrM8aprZmLn920DQ-1; Tue, 12 Nov 2019 06:30:24 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B125107ACC5; Tue, 12 Nov 2019 11:30:23 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id B79C46091D; Tue, 12 Nov 2019 11:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XrXr/+SNgujjOhRg7OiEQAfxJshPf36cCDpafuAMPIY=; b=eU/cGuOFOHAe47Jac3DDNW10+7Je5YDrCbOJ6B1KX/tLOzg8o0sGG0F2PTBqVnnFZoteYI P4luRe1CeL+qD+hD7bChLTc6epf9Uc9SimAHyZbfbjf4pp+JarZNxzKywrJM/HWrsIrONZ jBvvoB7FMpaVLiGmENwjoRjuIXnOiFA= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 3/8] blockdev: place drive_backup_prepare with the other related transaction functions Date: Tue, 12 Nov 2019 12:30:07 +0100 Message-Id: <20191112113012.71136-4-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: uiLl8FzrM8aprZmLn920DQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move drive_backup_prepare() to be side by side with the other related transaction helper functions. Signed-off-by: Sergio Lopez --- blockdev.c | 247 +++++++++++++++++++++++++++-------------------------- 1 file changed, 125 insertions(+), 122 deletions(-) diff --git a/blockdev.c b/blockdev.c index e8b673c5f3..b32855f702 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1761,8 +1761,131 @@ typedef struct DriveBackupState { BlockJob *job; } DriveBackupState; =20 -static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, - Error **errp); +static BlockJob *do_backup_common(BackupCommon *backup, + BlockDriverState *bs, + BlockDriverState *target_bs, + AioContext *aio_context, + JobTxn *txn, Error **errp); + +static void drive_backup_prepare(BlkActionState *common, Error **errp) +{ + DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + DriveBackup *backup; + BlockDriverState *bs; + BlockDriverState *target_bs; + BlockDriverState *source =3D NULL; + AioContext *aio_context; + QDict *options; + Error *local_err =3D NULL; + int flags; + int64_t size; + bool set_backing_hd =3D false; + + assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); + backup =3D common->action->u.drive_backup.data; + + if (!backup->has_mode) { + backup->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; + } + + bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); + if (!bs) { + return; + } + + if (!bs->drv) { + error_setg(errp, "Device has no medium"); + return; + } + + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + /* Paired with .clean() */ + bdrv_drained_begin(bs); + + if (!backup->has_format) { + backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? + NULL : (char *) bs->drv->format_name; + } + + /* Early check to avoid creating target */ + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { + goto out; + } + + flags =3D bs->open_flags | BDRV_O_RDWR; + + /* + * See if we have a backing HD we can use to create our new image + * on top of. + */ + if (backup->sync =3D=3D MIRROR_SYNC_MODE_TOP) { + source =3D backing_bs(bs); + if (!source) { + backup->sync =3D MIRROR_SYNC_MODE_FULL; + } + } + if (backup->sync =3D=3D MIRROR_SYNC_MODE_NONE) { + source =3D bs; + flags |=3D BDRV_O_NO_BACKING; + set_backing_hd =3D true; + } + + size =3D bdrv_getlength(bs); + if (size < 0) { + error_setg_errno(errp, -size, "bdrv_getlength failed"); + goto out; + } + + if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { + assert(backup->format); + if (source) { + bdrv_refresh_filename(source); + bdrv_img_create(backup->target, backup->format, source->filena= me, + source->drv->format_name, NULL, + size, flags, false, &local_err); + } else { + bdrv_img_create(backup->target, backup->format, NULL, NULL, NU= LL, + size, flags, false, &local_err); + } + } + + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + + options =3D qdict_new(); + qdict_put_str(options, "discard", "unmap"); + qdict_put_str(options, "detect-zeroes", "unmap"); + if (backup->format) { + qdict_put_str(options, "driver", backup->format); + } + + target_bs =3D bdrv_open(backup->target, NULL, options, flags, errp); + if (!target_bs) { + goto out; + } + + if (set_backing_hd) { + bdrv_set_backing_hd(target_bs, source, &local_err); + if (local_err) { + goto unref; + } + } + + state->bs =3D bs; + + state->job =3D do_backup_common(qapi_DriveBackup_base(backup), + bs, target_bs, aio_context, + common->block_job_txn, errp); + +unref: + bdrv_unref(target_bs); +out: + aio_context_release(aio_context); +} =20 static void drive_backup_commit(BlkActionState *common) { @@ -3553,126 +3676,6 @@ static BlockJob *do_backup_common(BackupCommon *bac= kup, return job; } =20 -static void drive_backup_prepare(BlkActionState *common, Error **errp) -{ - DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); - DriveBackup *backup; - BlockDriverState *bs; - BlockDriverState *target_bs; - BlockDriverState *source =3D NULL; - AioContext *aio_context; - QDict *options; - Error *local_err =3D NULL; - int flags; - int64_t size; - bool set_backing_hd =3D false; - - assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); - backup =3D common->action->u.drive_backup.data; - - if (!backup->has_mode) { - backup->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; - } - - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - if (!bs->drv) { - error_setg(errp, "Device has no medium"); - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - /* Paired with .clean() */ - bdrv_drained_begin(bs); - - if (!backup->has_format) { - backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? - NULL : (char *) bs->drv->format_name; - } - - /* Early check to avoid creating target */ - if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { - goto out; - } - - flags =3D bs->open_flags | BDRV_O_RDWR; - - /* - * See if we have a backing HD we can use to create our new image - * on top of. - */ - if (backup->sync =3D=3D MIRROR_SYNC_MODE_TOP) { - source =3D backing_bs(bs); - if (!source) { - backup->sync =3D MIRROR_SYNC_MODE_FULL; - } - } - if (backup->sync =3D=3D MIRROR_SYNC_MODE_NONE) { - source =3D bs; - flags |=3D BDRV_O_NO_BACKING; - set_backing_hd =3D true; - } - - size =3D bdrv_getlength(bs); - if (size < 0) { - error_setg_errno(errp, -size, "bdrv_getlength failed"); - goto out; - } - - if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { - assert(backup->format); - if (source) { - bdrv_refresh_filename(source); - bdrv_img_create(backup->target, backup->format, source->filena= me, - source->drv->format_name, NULL, - size, flags, false, &local_err); - } else { - bdrv_img_create(backup->target, backup->format, NULL, NULL, NU= LL, - size, flags, false, &local_err); - } - } - - if (local_err) { - error_propagate(errp, local_err); - goto out; - } - - options =3D qdict_new(); - qdict_put_str(options, "discard", "unmap"); - qdict_put_str(options, "detect-zeroes", "unmap"); - if (backup->format) { - qdict_put_str(options, "driver", backup->format); - } - - target_bs =3D bdrv_open(backup->target, NULL, options, flags, errp); - if (!target_bs) { - goto out; - } - - if (set_backing_hd) { - bdrv_set_backing_hd(target_bs, source, &local_err); - if (local_err) { - goto unref; - } - } - - state->bs =3D bs; - - state->job =3D do_backup_common(qapi_DriveBackup_base(backup), - bs, target_bs, aio_context, - common->block_job_txn, errp); - -unref: - bdrv_unref(target_bs); -out: - aio_context_release(aio_context); -} - void qmp_drive_backup(DriveBackup *arg, Error **errp) { =20 --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558630; cv=none; d=zoho.com; s=zohoarc; b=BQtgnCuGDCtcZgATb6H20VyUf07m3rTliqS7acDD48jSMnaU+C8ViNBOlVbGLgI9frRpNbg2bktOF/gOSaa5WVIbcoHvXg1ZJjBc2RKTY0DtWFyKsrvNRWyxJGFDL4iJRZKS5o+h00epxio5JWu0pCs7xWXpXUpG4z0Zk5djjOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558630; h=Content-Type: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; bh=5LGBVIQ/R/42vB7yC5tkdK8vF6kJeXx+rZ4aMMk6u34=; b=TInZam4u7C5uxNZiA//0+EaPOCcXQW+5VG0EAd/SZczIAi8PAcGTDGHJOVT9+pLHt72+InDXL29QQniJj9OAysjX/dmy6eo5aD2h7X4sz4kZXc/+0nKbhB4U/b3/T9ATj6kPlQwdf60ZMiC5GiAtak2nBYujsI8P4pNpw99YWq4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573558630085226.72209271346037; Tue, 12 Nov 2019 03:37:10 -0800 (PST) Received: from localhost ([::1]:33676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUTs-0003Ki-Lg for importer@patchew.org; Tue, 12 Nov 2019 06:37:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35492) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUOc-0006m5-Mb for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:31:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUOb-00013W-MH for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:31:42 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:47651 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOb-00013E-8E for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:31:41 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-F7qM-4elPfC_Y0Rn68TwmQ-1; Tue, 12 Nov 2019 06:30:28 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 857AA801FD2; Tue, 12 Nov 2019 11:30:27 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id B43EB60600; Tue, 12 Nov 2019 11:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5LGBVIQ/R/42vB7yC5tkdK8vF6kJeXx+rZ4aMMk6u34=; b=VTD74spjRrETWa0JMPz4Ns633jGe9MecXpqQV/gc/0zy6caO4Vb7nGeHVqeok07a541LqA KDGd7QSU5co3VbZxlQWTJk4VopDnIxwUJlIUnqwfGkxGkFTWiTmkFZg3Z7tGydggNe2t9+ cwS1fn7WxBGJHzX96FBCS84AbLUKY64= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 4/8] blockdev: change qmp_drive_backup to make use of transactions Date: Tue, 12 Nov 2019 12:30:08 +0100 Message-Id: <20191112113012.71136-5-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: F7qM-4elPfC_Y0Rn68TwmQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Change qmp_drive_backup() to create and start a transaction instead of calling do_drive_backup directly. Signed-off-by: Sergio Lopez --- blockdev.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/blockdev.c b/blockdev.c index b32855f702..5e85fc042e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3676,14 +3676,13 @@ static BlockJob *do_backup_common(BackupCommon *bac= kup, return job; } =20 -void qmp_drive_backup(DriveBackup *arg, Error **errp) +void qmp_drive_backup(DriveBackup *backup, Error **errp) { - - BlockJob *job; - job =3D do_drive_backup(arg, NULL, errp); - if (job) { - job_start(&job->job); - } + TransactionAction action =3D { + .type =3D TRANSACTION_ACTION_KIND_DRIVE_BACKUP, + .u.drive_backup.data =3D backup, + }; + blockdev_do_action(&action, errp); } =20 BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp) --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558789; cv=none; d=zoho.com; s=zohoarc; b=TpBd4JfbwCHp9Vcm2hxN5KBmAjVKUxXl6Uui1qiMNMxDsnUob6rusTM1O4QaXBDbaC71LxgSGSLriTOdD1Gsvy9LkE+bDjiYhB3WK5TxJVOtT98SCfDKyppBraVSTb6RjMMlbTHNu2A/IbpsESNqh2cpjc8gU1vhMzu4Q7ibQQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558789; h=Content-Type: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; bh=fw8sl+1CgmcCR7p4mfbvS51RM3jOkynBnHJ/+9qXwQQ=; b=j3PSJbGfVLfwDLaKVjwHSLfoIAui/focSrPr4m4yf+0OwyJTtJKwgExeOxcYLn+qeqiTumke0gyYFlTPUH6+oJM0MNJUdmty8AmDAPW+hS38EtmUFZILwgTsz1WBDUJheqaAhtw3odrKdlMSTsrZu4dBKWoaymtmI/iR0zyi40A= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573558789835477.89267559450457; Tue, 12 Nov 2019 03:39:49 -0800 (PST) Received: from localhost ([::1]:33728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUWR-00062i-FE for importer@patchew.org; Tue, 12 Nov 2019 06:39:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35643) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUP9-0007Hx-80 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUP2-0001BU-53 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51846 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOy-00018T-9N for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:08 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-Mxi0ETbjP_qVFDJrNjeibg-1; Tue, 12 Nov 2019 06:30:30 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BF78800EB3; Tue, 12 Nov 2019 11:30:29 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE40C60A89; Tue, 12 Nov 2019 11:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fw8sl+1CgmcCR7p4mfbvS51RM3jOkynBnHJ/+9qXwQQ=; b=H0x5pcnpTbDfHqk4PBBdbvm5gLrg+GrphHj8uzo6s71xodjs4tBT0ZtsWBYOsXL+YgRf0r W1x2hmggIT6XHOqejXyepvVr3ZzGVUiVv9LQ5iy0nw3DbSGD43qDSQicF+ECTZu4sRReoi AfkvcjlG3W9Ho5MpOEajPMw7D4SSO28= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 5/8] blockdev: merge blockdev_backup_prepare with do_blockdev_backup Date: Tue, 12 Nov 2019 12:30:09 +0100 Message-Id: <20191112113012.71136-6-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: Mxi0ETbjP_qVFDJrNjeibg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Consolidate blockdev_backup_prepare() with do_blockdev_backup() as a first step towards streamlining all functionality through transactions. Signed-off-by: Sergio Lopez --- blockdev.c | 64 +++++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 49 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5e85fc042e..128707cdc6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1940,47 +1940,6 @@ typedef struct BlockdevBackupState { BlockJob *job; } BlockdevBackupState; =20 -static BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, - Error **errp); - -static void blockdev_backup_prepare(BlkActionState *common, Error **errp) -{ - BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); - BlockdevBackup *backup; - BlockDriverState *bs, *target; - AioContext *aio_context; - Error *local_err =3D NULL; - - assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); - backup =3D common->action->u.blockdev_backup.data; - - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - target =3D bdrv_lookup_bs(backup->target, backup->target, errp); - if (!target) { - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - state->bs =3D bs; - - /* Paired with .clean() */ - bdrv_drained_begin(state->bs); - - state->job =3D do_blockdev_backup(backup, common->block_job_txn, &loca= l_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; - } - -out: - aio_context_release(aio_context); -} - static void blockdev_backup_commit(BlkActionState *common) { BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); @@ -3695,32 +3654,39 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error= **errp) return bdrv_get_xdbg_block_graph(errp); } =20 -BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, - Error **errp) +static void blockdev_backup_prepare(BlkActionState *common, Error **errp) { + BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + BlockdevBackup *backup; BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; - BlockJob *job; + + assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); + backup =3D common->action->u.blockdev_backup.data; =20 bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); if (!bs) { - return NULL; + return; } =20 target_bs =3D bdrv_lookup_bs(backup->target, backup->target, errp); if (!target_bs) { - return NULL; + return; } =20 aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); + state->bs =3D bs; =20 - job =3D do_backup_common(qapi_BlockdevBackup_base(backup), - bs, target_bs, aio_context, txn, errp); + /* Paired with .clean() */ + bdrv_drained_begin(state->bs); + + state->job =3D do_backup_common(qapi_BlockdevBackup_base(backup), + bs, target_bs, aio_context, + common->block_job_txn, errp); =20 aio_context_release(aio_context); - return job; } =20 void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558483; cv=none; d=zoho.com; s=zohoarc; b=DURj1JJ1IsQFx/6ErrowfA1pK9ttiAHJlx9EfGunQAlXYm277JXq+f0ulcdILsdhzhsHDr3BYh85fpIiGqguYqj4hY4MyEHOcOH4zXmGUZoTu3WFZ8mbFaH+Vs+H+nDRcchCpdePukMCAHKKt5HdaXrlQR0EIisFSM5ijJ8ZORY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558483; h=Content-Type: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; bh=wbvPC0j2Q4yaXtsYW/Ngr7jfFhiP1PPYm5HSHEmn2Q0=; b=itqUHmrTjZ1zrrwL483yWvgEj6HBO854K/UxmdOTjLQRQDFWKePhHIcdPK3ZImdTbLXGOy8dtMAlGXOs9XnTMCrW43vZSwnIA8p3I863AqcQYaAUDTj9Ql/lFs0d7kLBl5RqiKAUZGmQAx/l8D7P9qDJWrNOY47pTT50KRHqkaQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573558483293994.3372010076753; Tue, 12 Nov 2019 03:34:43 -0800 (PST) Received: from localhost ([::1]:33628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUURT-0000au-TX for importer@patchew.org; Tue, 12 Nov 2019 06:34:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35573) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUP2-0007G9-82 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUOy-00019c-AQ for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20320 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOy-00018K-0E for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-9tauDOo0MqibY3ubE9t7Rw-1; Tue, 12 Nov 2019 06:30:32 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 780B3DC20; Tue, 12 Nov 2019 11:30:31 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id D864D6090D; Tue, 12 Nov 2019 11:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wbvPC0j2Q4yaXtsYW/Ngr7jfFhiP1PPYm5HSHEmn2Q0=; b=OAndAIb2R7B1D681Jw+jGWUiQvtjkiBbzygPAdRdgOfYrvx7xcUwIZJuPD7Bo3uo3uv6+j eeIgvv6Y6vLh/FG3qUws0ZQe7HANwrWjpuTIDWshIGjMZld+3vG4cdvvN3YP9Kn64jaH0i Om8jiItZYFl4WoSRtI8bJQh79S5HVcc= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 6/8] blockdev: place blockdev_backup_prepare with the other related transaction helpers Date: Tue, 12 Nov 2019 12:30:10 +0100 Message-Id: <20191112113012.71136-7-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 9tauDOo0MqibY3ubE9t7Rw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move blockdev_backup_prepare() to be side by side with the other related transaction helper functions. Signed-off-by: Sergio Lopez --- blockdev.c | 70 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/blockdev.c b/blockdev.c index 128707cdc6..f94aaa98f0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1940,6 +1940,41 @@ typedef struct BlockdevBackupState { BlockJob *job; } BlockdevBackupState; =20 +static void blockdev_backup_prepare(BlkActionState *common, Error **errp) +{ + BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + BlockdevBackup *backup; + BlockDriverState *bs; + BlockDriverState *target_bs; + AioContext *aio_context; + + assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); + backup =3D common->action->u.blockdev_backup.data; + + bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); + if (!bs) { + return; + } + + target_bs =3D bdrv_lookup_bs(backup->target, backup->target, errp); + if (!target_bs) { + return; + } + + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + state->bs =3D bs; + + /* Paired with .clean() */ + bdrv_drained_begin(state->bs); + + state->job =3D do_backup_common(qapi_BlockdevBackup_base(backup), + bs, target_bs, aio_context, + common->block_job_txn, errp); + + aio_context_release(aio_context); +} + static void blockdev_backup_commit(BlkActionState *common) { BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); @@ -3654,41 +3689,6 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error = **errp) return bdrv_get_xdbg_block_graph(errp); } =20 -static void blockdev_backup_prepare(BlkActionState *common, Error **errp) -{ - BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); - BlockdevBackup *backup; - BlockDriverState *bs; - BlockDriverState *target_bs; - AioContext *aio_context; - - assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); - backup =3D common->action->u.blockdev_backup.data; - - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - target_bs =3D bdrv_lookup_bs(backup->target, backup->target, errp); - if (!target_bs) { - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - state->bs =3D bs; - - /* Paired with .clean() */ - bdrv_drained_begin(state->bs); - - state->job =3D do_backup_common(qapi_BlockdevBackup_base(backup), - bs, target_bs, aio_context, - common->block_job_txn, errp); - - aio_context_release(aio_context); -} - void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) { BlockJob *job; --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558520; cv=none; d=zoho.com; s=zohoarc; b=gRP2pcqajJ/uFcNoTaSbQ9j98BwaLZ9/bjxxNcQJCimQDuqHjEwG40LEsabK49XGV8hKwlRPjBk00RfWF+vAQYoTs2SaCF+TG+ZyRpCTat/Xq+EZ6kPNwnE+W4PoPxIpjweOTUfhSUMY/64skPROYTZHp8sTQp6+XS9TsRqMWuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558520; h=Content-Type: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; bh=tYXVAdmI2Yij9l24SfYiKOe4TibLH70qfactyLGf88g=; b=grudklupB7tbCEH05YdZWGiwgGoyW9qmWnt+gPeUiz8guqrh67jpiXrPkUM9j//oU37U5x++RsJjHlwjPBpZ6BZpDvn1+rNWoac09l/GFas1exVy0/urxIN210caXr0Oknfh+hXy/k8pBropXPwPtE82Vhbs0XFt10MJZe1mFYM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573558520258916.99821313842; Tue, 12 Nov 2019 03:35:20 -0800 (PST) Received: from localhost ([::1]:33634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUS6-0001X9-VC for importer@patchew.org; Tue, 12 Nov 2019 06:35:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35576) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUP2-0007GB-75 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUOy-00019W-9I for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:08 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30617 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOw-00018Q-8q for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-0C_wC0neN52SLwaMzv8S3w-1; Tue, 12 Nov 2019 06:30:43 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EB711800D7A; Tue, 12 Nov 2019 11:30:42 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id D227660600; Tue, 12 Nov 2019 11:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tYXVAdmI2Yij9l24SfYiKOe4TibLH70qfactyLGf88g=; b=CQJEUXGYsL/u85Qyvy8PpMvjCY2PjYcLWo1F9vjB3tv20pt4Y2ww1RIsraEmvUi9rNaPd7 CvHsViecLl2alz3NhJnAkVG7xzHEq4vn/VMjrbDfQlgjIWrDK1hPQm++hI4WihmvzVpuQZ BVVHsXq6OmhAEcg7GV62de6Uf5rsmpY= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 7/8] blockdev: change qmp_blockdev_backup to make use of transactions Date: Tue, 12 Nov 2019 12:30:11 +0100 Message-Id: <20191112113012.71136-8-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 0C_wC0neN52SLwaMzv8S3w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Change qmp_blockdev_backup() to create and start a transaction instead of calling do_blockdev_backup() directly. Signed-off-by: Sergio Lopez --- blockdev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index f94aaa98f0..152a0f7454 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3689,13 +3689,13 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error= **errp) return bdrv_get_xdbg_block_graph(errp); } =20 -void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) +void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp) { - BlockJob *job; - job =3D do_blockdev_backup(arg, NULL, errp); - if (job) { - job_start(&job->job); - } + TransactionAction action =3D { + .type =3D TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP, + .u.blockdev_backup.data =3D backup, + }; + blockdev_do_action(&action, errp); } =20 /* Parameter check and block job starting for drive mirroring. --=20 2.23.0 From nobody Thu May 16 23:34:30 2024 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; dkim=fail; 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=1573558727; cv=none; d=zoho.com; s=zohoarc; b=m70Iorttg4zv6TbbRrmF1pY7TvGA+Cc3d1wkrY3oTL9qoVEMB6oZ2BNPMt0ij28btt60YsrQSokdhs7ldKEZOwVNI855WKOuQQ+0RP8aL89kgaQOgoJCb96wlCFnPB+lHwGsM5K9A5zMRp6+hFxIqRqUFPQGFHvLDURO60S7850= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573558727; h=Content-Type: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; bh=uP29D3i3Jo/HrZeAJm59V6dRbMwu73JzUIZJLFx40Vw=; b=PW2YeHCvrb0XedAY2nIr51o3z5qWN+rn1k4AZX+GCvH/OBKZ5xxQk7anB4aHzgLYS11w88bj6lu5PhVCQP+PyCuOPUYGyCYNUFD0OlK+KsmCLAPi9+C/qggq0G7FDZlvz7jdH6xKwvTNnM1wnX/jjbhg61/NAjI20HMikcmlEzU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 157355872752527.136272714939764; Tue, 12 Nov 2019 03:38:47 -0800 (PST) Received: from localhost ([::1]:33716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUVS-00054i-DG for importer@patchew.org; Tue, 12 Nov 2019 06:38:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35581) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUP2-0007GE-7X for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUUOy-00019E-5K for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:08 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:49634 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUUOw-00018A-1O for qemu-devel@nongnu.org; Tue, 12 Nov 2019 06:32:02 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-169-k0alqf7pMEmQc89YZMda8A-1; Tue, 12 Nov 2019 06:30:46 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 375AA85B6F8; Tue, 12 Nov 2019 11:30:45 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBA1660A89; Tue, 12 Nov 2019 11:30:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573558321; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uP29D3i3Jo/HrZeAJm59V6dRbMwu73JzUIZJLFx40Vw=; b=PTXUB5xDDmxhn43LoMp60vkYr9Am2h3FWutRz8dVO0dklvbgq8PVUuMVs69wYC+fBVhy7r 0tooxxNIpkJ3RTNlhHaZf25NQtjK60zhnGOYVaG44gQR58CBMADp2ooGbFN9icPs4bBb2B l2vzTIPLj5O26VzvBh+mBUlP/GsaHBk= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v3 8/8] blockdev: honor bdrv_try_set_aio_context() context requirements Date: Tue, 12 Nov 2019 12:30:12 +0100 Message-Id: <20191112113012.71136-9-slp@redhat.com> In-Reply-To: <20191112113012.71136-1-slp@redhat.com> References: <20191112113012.71136-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: k0alqf7pMEmQc89YZMda8A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Kevin Wolf , Sergio Lopez , Markus Armbruster , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 occurrences where it's not done this way. Suggested-by: Max Reitz Signed-off-by: Sergio Lopez --- blockdev.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/blockdev.c b/blockdev.c index 152a0f7454..b0647d8d33 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; + AioContext *old_context; int ret; =20 /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar @@ -1675,11 +1676,20 @@ static void external_snapshot_prepare(BlkActionStat= e *common, goto out; } =20 + /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + old_context =3D bdrv_get_aio_context(state->new_bs); + aio_context_release(aio_context); + 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. */ @@ -1775,11 +1785,13 @@ static void drive_backup_prepare(BlkActionState *co= mmon, Error **errp) BlockDriverState *target_bs; BlockDriverState *source =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 assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); backup =3D common->action->u.drive_backup.data; @@ -1868,6 +1880,20 @@ static void drive_backup_prepare(BlkActionState *com= mon, Error **errp) goto out; } =20 + /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + old_context =3D bdrv_get_aio_context(target_bs); + aio_context_release(aio_context); + 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; + } + + 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) { @@ -1947,6 +1973,8 @@ static void blockdev_backup_prepare(BlkActionState *c= ommon, Error **errp) BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; + AioContext *old_context; + int ret; =20 assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); backup =3D common->action->u.blockdev_backup.data; @@ -1961,7 +1989,18 @@ static void blockdev_backup_prepare(BlkActionState *= common, Error **errp) return; } =20 + /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ 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; + } + + aio_context_release(old_context); aio_context_acquire(aio_context); state->bs =3D bs; =20 @@ -3562,7 +3601,6 @@ static BlockJob *do_backup_common(BackupCommon *backu= p, 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; @@ -3586,11 +3624,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= */ @@ -3825,6 +3858,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; @@ -3937,12 +3971,22 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) (arg->mode =3D=3D NEW_IMAGE_MODE_EXISTING || !bdrv_has_zero_init(target_bs))); =20 + + /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + old_context =3D bdrv_get_aio_context(target_bs); + aio_context_release(aio_context); + 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, @@ -3984,6 +4028,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char = *job_id, BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; + AioContext *old_context; BlockMirrorBackingMode backing_mode =3D MIRROR_LEAVE_BACKING_CHAIN; Error *local_err =3D NULL; bool zero_target; @@ -4001,14 +4046,18 @@ void qmp_blockdev_mirror(bool has_job_id, const cha= r *job_id, =20 zero_target =3D (sync =3D=3D MIRROR_SYNC_MODE_FULL); =20 + /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + old_context =3D bdrv_get_aio_context(target_bs); aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); + aio_context_acquire(old_context); =20 ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); if (ret < 0) { goto out; } =20 + aio_context_acquire(aio_context); + blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs, has_replaces, replaces, sync, backing_mode, zero_target, has_speed, speed, --=20 2.23.0