From patchwork Tue Nov 12 11:30:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B58DD13B1 for ; Tue, 12 Nov 2019 11:37:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B87D21783 for ; Tue, 12 Nov 2019 11:37:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="C3DQJy+W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B87D21783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUTk-0003by-ID for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:37:00 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 *common, Error **errp) if (!backup->has_format) { backup->format = backup->mode == NEW_IMAGE_MODE_EXISTING ? - NULL : (char*) bs->drv->format_name; + NULL : (char *) bs->drv->format_name; } /* Early check to avoid creating target */ @@ -3602,8 +3602,10 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) flags = bs->open_flags | BDRV_O_RDWR; - /* 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 == MIRROR_SYNC_MODE_TOP) { source = backing_bs(bs); if (!source) { From patchwork Tue Nov 12 11:30:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5645013B1 for ; Tue, 12 Nov 2019 11:41:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2BB4421783 for ; Tue, 12 Nov 2019 11:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eU/cGuOF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BB4421783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUXc-0007a2-B1 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:41:00 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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; -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 = DO_UPCAST(DriveBackupState, common, common); + DriveBackup *backup; + BlockDriverState *bs; + BlockDriverState *target_bs; + BlockDriverState *source = NULL; + AioContext *aio_context; + QDict *options; + Error *local_err = NULL; + int flags; + int64_t size; + bool set_backing_hd = false; + + assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); + backup = common->action->u.drive_backup.data; + + if (!backup->has_mode) { + backup->mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; + } + + bs = bdrv_lookup_bs(backup->device, backup->device, errp); + if (!bs) { + return; + } + + if (!bs->drv) { + error_setg(errp, "Device has no medium"); + return; + } + + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + + /* Paired with .clean() */ + bdrv_drained_begin(bs); + + if (!backup->has_format) { + backup->format = backup->mode == 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 = 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 == MIRROR_SYNC_MODE_TOP) { + source = backing_bs(bs); + if (!source) { + backup->sync = MIRROR_SYNC_MODE_FULL; + } + } + if (backup->sync == MIRROR_SYNC_MODE_NONE) { + source = bs; + flags |= BDRV_O_NO_BACKING; + set_backing_hd = true; + } + + size = bdrv_getlength(bs); + if (size < 0) { + error_setg_errno(errp, -size, "bdrv_getlength failed"); + goto out; + } + + if (backup->mode != NEW_IMAGE_MODE_EXISTING) { + assert(backup->format); + if (source) { + bdrv_refresh_filename(source); + bdrv_img_create(backup->target, backup->format, source->filename, + source->drv->format_name, NULL, + size, flags, false, &local_err); + } else { + bdrv_img_create(backup->target, backup->format, NULL, NULL, NULL, + size, flags, false, &local_err); + } + } + + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + + options = 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 = 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 = bs; + + state->job = 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); +} static void drive_backup_commit(BlkActionState *common) { @@ -3553,126 +3676,6 @@ static BlockJob *do_backup_common(BackupCommon *backup, return job; } -static void drive_backup_prepare(BlkActionState *common, Error **errp) -{ - DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); - DriveBackup *backup; - BlockDriverState *bs; - BlockDriverState *target_bs; - BlockDriverState *source = NULL; - AioContext *aio_context; - QDict *options; - Error *local_err = NULL; - int flags; - int64_t size; - bool set_backing_hd = false; - - assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); - backup = common->action->u.drive_backup.data; - - if (!backup->has_mode) { - backup->mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; - } - - bs = bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - if (!bs->drv) { - error_setg(errp, "Device has no medium"); - return; - } - - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - /* Paired with .clean() */ - bdrv_drained_begin(bs); - - if (!backup->has_format) { - backup->format = backup->mode == 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 = 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 == MIRROR_SYNC_MODE_TOP) { - source = backing_bs(bs); - if (!source) { - backup->sync = MIRROR_SYNC_MODE_FULL; - } - } - if (backup->sync == MIRROR_SYNC_MODE_NONE) { - source = bs; - flags |= BDRV_O_NO_BACKING; - set_backing_hd = true; - } - - size = bdrv_getlength(bs); - if (size < 0) { - error_setg_errno(errp, -size, "bdrv_getlength failed"); - goto out; - } - - if (backup->mode != NEW_IMAGE_MODE_EXISTING) { - assert(backup->format); - if (source) { - bdrv_refresh_filename(source); - bdrv_img_create(backup->target, backup->format, source->filename, - source->drv->format_name, NULL, - size, flags, false, &local_err); - } else { - bdrv_img_create(backup->target, backup->format, NULL, NULL, NULL, - size, flags, false, &local_err); - } - } - - if (local_err) { - error_propagate(errp, local_err); - goto out; - } - - options = 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 = 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 = bs; - - state->job = 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) { From patchwork Tue Nov 12 11:30:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2ACA01515 for ; Tue, 12 Nov 2019 11:36:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F414121783 for ; Tue, 12 Nov 2019 11:36:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VTD74spj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F414121783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUTQ-0003Ki-S4 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:36:40 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 *backup, return job; } -void qmp_drive_backup(DriveBackup *arg, Error **errp) +void qmp_drive_backup(DriveBackup *backup, Error **errp) { - - BlockJob *job; - job = do_drive_backup(arg, NULL, errp); - if (job) { - job_start(&job->job); - } + TransactionAction action = { + .type = TRANSACTION_ACTION_KIND_DRIVE_BACKUP, + .u.drive_backup.data = backup, + }; + blockdev_do_action(&action, errp); } BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp) From patchwork Tue Nov 12 11:30:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A53A713B1 for ; Tue, 12 Nov 2019 11:39:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7ABB921783 for ; Tue, 12 Nov 2019 11:39:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H0x5pcnp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7ABB921783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUWG-00062i-Mw for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:39:36 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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; -static BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, - Error **errp); - -static void blockdev_backup_prepare(BlkActionState *common, Error **errp) -{ - BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); - BlockdevBackup *backup; - BlockDriverState *bs, *target; - AioContext *aio_context; - Error *local_err = NULL; - - assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); - backup = common->action->u.blockdev_backup.data; - - bs = bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - target = bdrv_lookup_bs(backup->target, backup->target, errp); - if (!target) { - return; - } - - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - state->bs = bs; - - /* Paired with .clean() */ - bdrv_drained_begin(state->bs); - - state->job = do_blockdev_backup(backup, common->block_job_txn, &local_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 = 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); } -BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, - Error **errp) +static void blockdev_backup_prepare(BlkActionState *common, Error **errp) { + BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); + BlockdevBackup *backup; BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; - BlockJob *job; + + assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); + backup = common->action->u.blockdev_backup.data; bs = bdrv_lookup_bs(backup->device, backup->device, errp); if (!bs) { - return NULL; + return; } target_bs = bdrv_lookup_bs(backup->target, backup->target, errp); if (!target_bs) { - return NULL; + return; } aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); + state->bs = bs; - job = do_backup_common(qapi_BlockdevBackup_base(backup), - bs, target_bs, aio_context, txn, errp); + /* Paired with .clean() */ + bdrv_drained_begin(state->bs); + + state->job = do_backup_common(qapi_BlockdevBackup_base(backup), + bs, target_bs, aio_context, + common->block_job_txn, errp); aio_context_release(aio_context); - return job; } void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) From patchwork Tue Nov 12 11:30:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92BF618B6 for ; Tue, 12 Nov 2019 11:34:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 67F1C21783 for ; Tue, 12 Nov 2019 11:34:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OAndAIb2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67F1C21783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUR2-0000au-K8 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:34:12 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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; +static void blockdev_backup_prepare(BlkActionState *common, Error **errp) +{ + BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); + BlockdevBackup *backup; + BlockDriverState *bs; + BlockDriverState *target_bs; + AioContext *aio_context; + + assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); + backup = common->action->u.blockdev_backup.data; + + bs = bdrv_lookup_bs(backup->device, backup->device, errp); + if (!bs) { + return; + } + + target_bs = bdrv_lookup_bs(backup->target, backup->target, errp); + if (!target_bs) { + return; + } + + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + state->bs = bs; + + /* Paired with .clean() */ + bdrv_drained_begin(state->bs); + + state->job = 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 = 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); } -static void blockdev_backup_prepare(BlkActionState *common, Error **errp) -{ - BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); - BlockdevBackup *backup; - BlockDriverState *bs; - BlockDriverState *target_bs; - AioContext *aio_context; - - assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); - backup = common->action->u.blockdev_backup.data; - - bs = bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return; - } - - target_bs = bdrv_lookup_bs(backup->target, backup->target, errp); - if (!target_bs) { - return; - } - - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - state->bs = bs; - - /* Paired with .clean() */ - bdrv_drained_begin(state->bs); - - state->job = 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; From patchwork Tue Nov 12 11:30:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 244BD15AB for ; Tue, 12 Nov 2019 11:34:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF0EF21783 for ; Tue, 12 Nov 2019 11:34:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CQJEUXGY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF0EF21783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUURg-0001X9-Il for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:34:52 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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); } -void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp) +void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp) { - BlockJob *job; - job = do_blockdev_backup(arg, NULL, errp); - if (job) { - job_start(&job->job); - } + TransactionAction action = { + .type = TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP, + .u.blockdev_backup.data = backup, + }; + blockdev_do_action(&action, errp); } /* Parameter check and block job starting for drive mirroring. From patchwork Tue Nov 12 11:30:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 11239123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D86F31515 for ; Tue, 12 Nov 2019 11:38:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE94121783 for ; Tue, 12 Nov 2019 11:38:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PTXUB5xD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE94121783 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUUVH-00054i-Tb for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Nov 2019 06:38:35 -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 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= 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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, common); TransactionAction *action = common->action; AioContext *aio_context; + AioContext *old_context; int ret; /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar @@ -1675,11 +1676,20 @@ static void external_snapshot_prepare(BlkActionState *common, goto out; } + /* Honor bdrv_try_set_aio_context() context acquisition requirements. */ + old_context = bdrv_get_aio_context(state->new_bs); + aio_context_release(aio_context); + aio_context_acquire(old_context); + ret = bdrv_try_set_aio_context(state->new_bs, aio_context, errp); if (ret < 0) { - goto out; + aio_context_release(old_context); + return; } + aio_context_release(old_context); + aio_context_acquire(aio_context); + /* This removes our old bs and adds the new bs. This is an operation that * 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 *common, Error **errp) BlockDriverState *target_bs; BlockDriverState *source = NULL; AioContext *aio_context; + AioContext *old_context; QDict *options; Error *local_err = NULL; int flags; int64_t size; bool set_backing_hd = false; + int ret; assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); backup = common->action->u.drive_backup.data; @@ -1868,6 +1880,20 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) goto out; } + /* Honor bdrv_try_set_aio_context() context acquisition requirements. */ + old_context = bdrv_get_aio_context(target_bs); + aio_context_release(aio_context); + aio_context_acquire(old_context); + + ret = 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 *common, Error **errp) BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; + AioContext *old_context; + int ret; assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); backup = common->action->u.blockdev_backup.data; @@ -1961,7 +1989,18 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp) return; } + /* Honor bdrv_try_set_aio_context() context acquisition requirements. */ aio_context = bdrv_get_aio_context(bs); + old_context = bdrv_get_aio_context(target_bs); + aio_context_acquire(old_context); + + ret = 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 = bs; @@ -3562,7 +3601,6 @@ static BlockJob *do_backup_common(BackupCommon *backup, BlockJob *job = NULL; BdrvDirtyBitmap *bmap = NULL; int job_flags = JOB_DEFAULT; - int ret; if (!backup->has_speed) { backup->speed = 0; @@ -3586,11 +3624,6 @@ static BlockJob *do_backup_common(BackupCommon *backup, backup->compress = false; } - ret = bdrv_try_set_aio_context(target_bs, aio_context, errp); - if (ret < 0) { - return NULL; - } - if ((backup->sync == MIRROR_SYNC_MODE_BITMAP) || (backup->sync == 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 = NULL; QDict *options = NULL; @@ -3937,12 +3971,22 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) (arg->mode == NEW_IMAGE_MODE_EXISTING || !bdrv_has_zero_init(target_bs))); + + /* Honor bdrv_try_set_aio_context() context acquisition requirements. */ + old_context = bdrv_get_aio_context(target_bs); + aio_context_release(aio_context); + aio_context_acquire(old_context); + ret = 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; } + aio_context_release(old_context); + aio_context_acquire(aio_context); + blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_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 = MIRROR_LEAVE_BACKING_CHAIN; Error *local_err = NULL; bool zero_target; @@ -4001,14 +4046,18 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id, zero_target = (sync == MIRROR_SYNC_MODE_FULL); + /* Honor bdrv_try_set_aio_context() context acquisition requirements. */ + old_context = bdrv_get_aio_context(target_bs); aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); + aio_context_acquire(old_context); ret = bdrv_try_set_aio_context(target_bs, aio_context, errp); if (ret < 0) { goto out; } + 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,