From nobody Thu May 16 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494036; cv=none; d=zohomail.com; s=zohoarc; b=H44DntOh6yf1xbaxEKS4c5mzDJpIMG+laeqrItf8QU2Vic88FCYzgDtQ8h+UU075bUjkz0A/WwVICOTfAK4WuyNotqsx5b82LMnchQ/HPffkdbigZjoajUsr0X7bBvjv5xZYVg8iKzu8bthR+6QJed0JPG8tgEwEETmSxCNnf3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494036; 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=PvYlu68bOy1PzKkK9O/Mmhwh8vYQj/D3MzAyFSyYUnc=; b=b1eFHL/JNyg+vTnwgSN5y8dsHaX8wy8HMTCKwYw7Mq4XKzMPVfwtyNSDyi7M9nB/h7PigaACVdhW/NnbIroCAfmGFM0lNABaHDyd4e+AEhDb7Fn5uYhMJsxurp6nkOPP3WlV2xwL2LCVuPbpZJGvyZwZN6N/04DLBExZv2dSLDk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494036680107.8723016690949; Wed, 8 Jan 2020 06:33:56 -0800 (PST) Received: from localhost ([::1]:44860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCPD-0002SH-9B for importer@patchew.org; Wed, 08 Jan 2020 09:33:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51152) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNI-0000gX-DH for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNG-0005ob-Mr for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:55 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:55366 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 1ipCNG-0005nO-IQ for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:54 -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-165-ysPRWEs5MXesGRm4f3JX-Q-1; Wed, 08 Jan 2020 09:31:49 -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 70006800D41; Wed, 8 Jan 2020 14:31:48 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9517A6FF0F; Wed, 8 Jan 2020 14:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493912; 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=PvYlu68bOy1PzKkK9O/Mmhwh8vYQj/D3MzAyFSyYUnc=; b=DBMa6WyRZJ66TpAlUOPR7kFBY5sG6/95upa8zg2JmEKYzVym05JMdvjLk5uQtUzbybXqM8 7IrDg8D356hJvm2RWMu8Q6cXjiCUYYR68I3fzi1uIXcR4KMPeoFiALD1NoMZ0kP5y3SwnR w/KDjkJrGE6iiTW1OqrvRQSX2pbnxms= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 1/8] blockdev: fix coding style issues in drive_backup_prepare Date: Wed, 8 Jan 2020 15:31:31 +0100 Message-Id: <20200108143138.129909-2-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: ysPRWEs5MXesGRm4f3JX-Q-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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 Reviewed-by: Max Reitz Reviewed-by: Kevin Wolf --- blockdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 8e029e9c01..553e315972 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3620,7 +3620,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, =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 */ @@ -3630,8 +3630,10 @@ static BlockJob *do_drive_backup(DriveBackup *backup= , JobTxn *txn, =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 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494199; cv=none; d=zohomail.com; s=zohoarc; b=Qd1iBRgeSY48TCHfRAhAtogzCQOVK48ICigCUa3rH/GQa9XhhyDyLdbe/MCxShSkE9A6VUtRC4zvPVMOCoa6BbXefBxQQFYD5P/UXEcRVb0RTiu5s5GuPOSCEOY5LwFUffj/C4dIqLshP7KBXE3C2CEzjacut3ooAsgzOg26xQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494199; 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=R4PDYY4drR8SW04eaejEMfh7wey6OLKt5bw/SwLJNlE=; b=hUDwwSL4z49FV1PSqnGwXduTtkKKNWUxgE1ddt1EvesQ4ydzr5EjCusbBL/wy7t3GeP2l2rehnn+yT02UgUZYACWHAY+6P4Gg+GAw6aj+iAia5vIICOO3awvWFO/gFsG8Cic8P79DgvJ8T3EVDPrYKsiQPakdBPshY3zMevQFKI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494199162496.6706330302968; Wed, 8 Jan 2020 06:36:39 -0800 (PST) Received: from localhost ([::1]:44900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCRp-00064h-Kb for importer@patchew.org; Wed, 08 Jan 2020 09:36:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51186) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNJ-0000go-Az for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNG-0005on-No for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:57 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:49213 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 1ipCNG-0005nZ-Ik for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:54 -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-355-rfyr3q0RPdOXPpTWjSPF7g-1; Wed, 08 Jan 2020 09:31:51 -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 A5BE41800D4E; Wed, 8 Jan 2020 14:31:50 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB9C36FF0F; Wed, 8 Jan 2020 14:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493912; 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=R4PDYY4drR8SW04eaejEMfh7wey6OLKt5bw/SwLJNlE=; b=KokFpylGoEtz5vU9ed/PlUxYzuAGylGZEp6WAJuYLHePrI36DoB1+cR0ivnVx8NKIVN8nr 0LpzbQ4p7Y7tbYY7IDjY5tvXQjHJM246oo/47svX4PlC33hMHVQG4m+g7+Q5LCAkI0gqmw A3xkfW7/OFNTwDkfGtjAt0WPjynsdx8= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 2/8] blockdev: unify qmp_drive_backup and drive-backup transaction paths Date: Wed, 8 Jan 2020 15:31:32 +0100 Message-Id: <20200108143138.129909-3-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: rfyr3q0RPdOXPpTWjSPF7g-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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" Issuing a drive-backup from qmp_drive_backup takes a slightly different path than when it's issued from a transaction. In the code, this is manifested as some redundancy between do_drive_backup() and drive_backup_prepare(). This change unifies both paths, merging do_drive_backup() and drive_backup_prepare(), and changing qmp_drive_backup() to create a transaction instead of calling do_backup_common() direcly. As a side-effect, now qmp_drive_backup() is executed inside a drained section, as it happens when creating a drive-backup transaction. This change is visible from the user's perspective, as the job gets paused and immediately resumed before starting the actual work. Also fix tests 141, 185 and 219 to cope with the extra JOB_STATUS_CHANGE lines. Signed-off-by: Sergio Lopez Reviewed-by: Kevin Wolf --- blockdev.c | 224 +++++++++++++++++-------------------- tests/qemu-iotests/141.out | 2 + tests/qemu-iotests/185.out | 2 + tests/qemu-iotests/219 | 7 +- tests/qemu-iotests/219.out | 8 ++ 5 files changed, 117 insertions(+), 126 deletions(-) diff --git a/blockdev.c b/blockdev.c index 553e315972..5e85fc042e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1761,39 +1761,128 @@ 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); =20 static void drive_backup_prepare(BlkActionState *common, Error **errp) { DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); - BlockDriverState *bs; 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; =20 assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); backup =3D common->action->u.drive_backup.data; =20 + 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; } =20 + if (!bs->drv) { + error_setg(errp, "Device has no medium"); + return; + } + aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 /* Paired with .clean() */ bdrv_drained_begin(bs); =20 - state->bs =3D 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); + } + } =20 - state->job =3D do_drive_backup(backup, common->block_job_txn, &local_e= rr); if (local_err) { error_propagate(errp, local_err); goto out; } =20 + 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); } @@ -3587,126 +3676,13 @@ static BlockJob *do_backup_common(BackupCommon *ba= ckup, return job; } =20 -static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, - Error **errp) -{ - BlockDriverState *bs; - BlockDriverState *target_bs; - BlockDriverState *source =3D NULL; - BlockJob *job =3D NULL; - AioContext *aio_context; - QDict *options; - Error *local_err =3D NULL; - int flags; - int64_t size; - bool set_backing_hd =3D false; - - 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 NULL; - } - - if (!bs->drv) { - error_setg(errp, "Device has no medium"); - return NULL; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - if (!backup->has_format) { - backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? - NULL : (char *) bs->drv->format_name; - } - - /* 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; - } - } - - job =3D do_backup_common(qapi_DriveBackup_base(backup), - bs, target_bs, aio_context, txn, errp); - -unref: - bdrv_unref(target_bs); -out: - aio_context_release(aio_context); - return job; -} - -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) diff --git a/tests/qemu-iotests/141.out b/tests/qemu-iotests/141.out index 3645675ce8..263b680bdf 100644 --- a/tests/qemu-iotests/141.out +++ b/tests/qemu-iotests/141.out @@ -13,6 +13,8 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D10485= 76 backing_file=3DTEST_DIR/m. Formatting 'TEST_DIR/o.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3DTEST_DIR/t.IMGFMT backing_fmt=3DIMGFMT {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "paused", "id": "job0"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} {'execute': 'blockdev-del', 'arguments': {'node-name': 'drv0'}} {"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: node is = used as backing hd of 'NODE_NAME'"}} {'execute': 'block-job-cancel', 'arguments': {'device': 'job0'}} diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out index 8379ac5854..9a3b65782b 100644 --- a/tests/qemu-iotests/185.out +++ b/tests/qemu-iotests/185.out @@ -65,6 +65,8 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67= 108864 cluster_size=3D65536 l Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "disk"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "paused", "id": "disk"}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "disk"}} {"return": {}} { 'execute': 'quit' } {"return": {}} diff --git a/tests/qemu-iotests/219 b/tests/qemu-iotests/219 index e0c51662c0..655f54d881 100755 --- a/tests/qemu-iotests/219 +++ b/tests/qemu-iotests/219 @@ -63,7 +63,7 @@ def test_pause_resume(vm): # logged immediately iotests.log(vm.qmp('query-jobs')) =20 -def test_job_lifecycle(vm, job, job_args, has_ready=3DFalse): +def test_job_lifecycle(vm, job, job_args, has_ready=3DFalse, is_mirror=3DF= alse): global img_size =20 iotests.log('') @@ -135,6 +135,9 @@ def test_job_lifecycle(vm, job, job_args, has_ready=3DF= alse): iotests.log('Waiting for PENDING state...') iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS_CHANGE'= ))) iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS_CHANGE'= ))) + if is_mirror: + iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS_CHA= NGE'))) + iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS_CHA= NGE'))) =20 if not job_args.get('auto-finalize', True): # PENDING state: @@ -218,7 +221,7 @@ with iotests.FilePath('disk.img') as disk_path, \ =20 for auto_finalize in [True, False]: for auto_dismiss in [True, False]: - test_job_lifecycle(vm, 'drive-backup', job_args=3D{ + test_job_lifecycle(vm, 'drive-backup', is_mirror=3DTrue, job_a= rgs=3D{ 'device': 'drive0-node', 'target': copy_path, 'sync': 'full', diff --git a/tests/qemu-iotests/219.out b/tests/qemu-iotests/219.out index 8ebd3fee60..0ea5d0b9d5 100644 --- a/tests/qemu-iotests/219.out +++ b/tests/qemu-iotests/219.out @@ -135,6 +135,8 @@ Pause/resume in RUNNING {"return": {}} =20 Waiting for PENDING state... +{"data": {"id": "job0", "status": "paused"}, "event": "JOB_STATUS_CHANGE",= "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"id": "job0", "status": "running"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "waiting"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "pending"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "concluded"}, "event": "JOB_STATUS_CHANG= E", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} @@ -186,6 +188,8 @@ Pause/resume in RUNNING {"return": {}} =20 Waiting for PENDING state... +{"data": {"id": "job0", "status": "paused"}, "event": "JOB_STATUS_CHANGE",= "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"id": "job0", "status": "running"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "waiting"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "pending"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "concluded"}, "event": "JOB_STATUS_CHANG= E", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} @@ -245,6 +249,8 @@ Pause/resume in RUNNING {"return": {}} =20 Waiting for PENDING state... +{"data": {"id": "job0", "status": "paused"}, "event": "JOB_STATUS_CHANGE",= "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"id": "job0", "status": "running"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "waiting"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "pending"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"return": [{"current-progress": 4194304, "id": "job0", "status": "pending= ", "total-progress": 4194304, "type": "backup"}]} @@ -304,6 +310,8 @@ Pause/resume in RUNNING {"return": {}} =20 Waiting for PENDING state... +{"data": {"id": "job0", "status": "paused"}, "event": "JOB_STATUS_CHANGE",= "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"id": "job0", "status": "running"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "waiting"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"id": "job0", "status": "pending"}, "event": "JOB_STATUS_CHANGE"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"return": [{"current-progress": 4194304, "id": "job0", "status": "pending= ", "total-progress": 4194304, "type": "backup"}]} --=20 2.23.0 From nobody Thu May 16 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494172; cv=none; d=zohomail.com; s=zohoarc; b=gtdbY22evkpW7gu3BEGoodAtdx3i1wSYuayDHZ4G5UIDOTSBPX0UysnGTJe0VOeB9lYYjjJrj32JHoOTC3iRcJACf2hV61Yt0lvJbGzaCEkEPNPFzTuzQBf48EFxgOq9FnbPz9UnhTsVVbWN6SgbNw8Mr2945vW3HTLurIE2MPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494172; 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=ww1NfeHtwgyf+gSaFmGXlH4l83bz3xIuBcVd+rifxPI=; b=G7t2SoEUtOwtPFQQOOtg4+4A8aptsb2PR9C426i6rFr+s36W8CdYzyxRbUfv/hzTC3YM5OQWgIQ3i0DIgDsrPICpFktY2NqeZHr8SzEGguHozNpWne52e9eG7204Kj8teFcmC2pFaT3fSkOdFmzyWxYDbx0rhJUjZvvkWUyOaG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494172427753.4174569298876; Wed, 8 Jan 2020 06:36:12 -0800 (PST) Received: from localhost ([::1]:44898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCRP-0005jv-0B for importer@patchew.org; Wed, 08 Jan 2020 09:36:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51203) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNJ-0000hx-Vh for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNI-0005pk-Jp for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:57 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:30558 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 1ipCNI-0005pG-Bw for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:31:56 -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-84-SwTKh0ENMeyWyoOY0kh9Ew-1; Wed, 08 Jan 2020 09:31:54 -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 4AC341005513; Wed, 8 Jan 2020 14:31:53 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E79B81C38; Wed, 8 Jan 2020 14:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493915; 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=ww1NfeHtwgyf+gSaFmGXlH4l83bz3xIuBcVd+rifxPI=; b=RyyCMy28glnZohJrB+2lh90HKHMQ/+9wWk4FOjQ1ryfZ++ZIBl1hTgq7E8tlKT6a0ww1CH 8rXDOf8EUT47PS0f6i3WkDlZpMvFQvyoYUs7maKthJniY+noKoJ6uT3jUus1jPwju9w3zc MgEBIzEnzqZw1XnGHE0bhZHcO2zscaA= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 3/8] blockdev: unify qmp_blockdev_backup and blockdev-backup transaction paths Date: Wed, 8 Jan 2020 15:31:33 +0100 Message-Id: <20200108143138.129909-4-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: SwTKh0ENMeyWyoOY0kh9Ew-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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" Issuing a blockdev-backup from qmp_blockdev_backup takes a slightly different path than when it's issued from a transaction. In the code, this is manifested as some redundancy between do_blockdev_backup() and blockdev_backup_prepare(). This change unifies both paths, merging do_blockdev_backup() and blockdev_backup_prepare(), and changing qmp_blockdev_backup() to create a transaction instead of calling do_backup_common() direcly. As a side-effect, now qmp_blockdev_backup() is executed inside a drained section, as it happens when creating a blockdev-backup transaction. This change is visible from the user's perspective, as the job gets paused and immediately resumed before starting the actual work. Signed-off-by: Sergio Lopez Reviewed-by: Max Reitz Reviewed-by: Kevin Wolf --- blockdev.c | 60 ++++++++++++------------------------------------------ 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5e85fc042e..152a0f7454 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1940,16 +1940,13 @@ 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; + BlockDriverState *bs; + BlockDriverState *target_bs; AioContext *aio_context; - Error *local_err =3D NULL; =20 assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); backup =3D common->action->u.blockdev_backup.data; @@ -1959,8 +1956,8 @@ static void blockdev_backup_prepare(BlkActionState *c= ommon, Error **errp) return; } =20 - target =3D bdrv_lookup_bs(backup->target, backup->target, errp); - if (!target) { + target_bs =3D bdrv_lookup_bs(backup->target, backup->target, errp); + if (!target_bs) { return; } =20 @@ -1971,13 +1968,10 @@ static void blockdev_backup_prepare(BlkActionState = *common, Error **errp) /* Paired with .clean() */ bdrv_drained_begin(state->bs); =20 - state->job =3D do_blockdev_backup(backup, common->block_job_txn, &loca= l_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; - } + state->job =3D do_backup_common(qapi_BlockdevBackup_base(backup), + bs, target_bs, aio_context, + common->block_job_txn, errp); =20 -out: aio_context_release(aio_context); } =20 @@ -3695,41 +3689,13 @@ 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) +void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp) { - BlockDriverState *bs; - BlockDriverState *target_bs; - AioContext *aio_context; - BlockJob *job; - - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); - if (!bs) { - return NULL; - } - - target_bs =3D bdrv_lookup_bs(backup->target, backup->target, errp); - if (!target_bs) { - return NULL; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - job =3D do_backup_common(qapi_BlockdevBackup_base(backup), - bs, target_bs, aio_context, txn, errp); - - aio_context_release(aio_context); - return job; -} - -void qmp_blockdev_backup(BlockdevBackup *arg, 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 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494052; cv=none; d=zohomail.com; s=zohoarc; b=Lm5oxfrhQ6+ktXmNPsnYlyCPF1+DodSJ89iH1tfaKSYrCkbO+jdYBgYSLMMDBDxwPy9KWpjPRx3PSh14TNlLIxTDtBvVZ3SppJIgDLxC1JKLcfRw7ZAR15UbypVrgLyZ/Wn9yV+raAxrvNbMxZXI8BeAUX0ybYTAWTLdXeMYW6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494052; 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=GeR/kB0OOigsbJM+7ZB53eBBcETmade9NqJj0AS9eu8=; b=UEZBeIZ6IrOFz9HLJsq/Dik4RMJJ+sLgF016nrYk7A8uOFb9q7bH3uNHQXFEsbZqGt5ogede3daUSMkJ8tE+GO1CzJmDV5MsKRPZwPxDKyH9eC4YeXlfY3J6sAB8MBKV3/vfrR1OAeT92GUHWXN1+giDJbBP6jbuEMvtQU0BFKQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494052721252.29450184296866; Wed, 8 Jan 2020 06:34:12 -0800 (PST) Received: from localhost ([::1]:44862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCPT-0002nL-5R for importer@patchew.org; Wed, 08 Jan 2020 09:34:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51282) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNN-0000nE-Md for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNM-0005t1-8d for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:01 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:38823 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 1ipCNM-0005sp-4m for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:00 -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-174-R05EYAfIP3m61PEM-IBckA-1; Wed, 08 Jan 2020 09:31:56 -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 80E341005502; Wed, 8 Jan 2020 14:31:55 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id A743460BE2; Wed, 8 Jan 2020 14:31:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493919; 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=GeR/kB0OOigsbJM+7ZB53eBBcETmade9NqJj0AS9eu8=; b=ZprMk4tObF4H1CKVbeRtJ5FokI7r/xYMqeIQyP1v8gLMt9UKvC5/8wU39xP5pW8NosGAou l13wp9Px7UYblamlYb40bD5FV5Wf0Xabiij2m6iF5rgVSdGtPhdRXIOWvZtDU7drWuoLey 2e//8rv+sFp8hOnvzv0iUUksH2y7JeQ= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 4/8] blockdev: honor bdrv_try_set_aio_context() context requirements Date: Wed, 8 Jan 2020 15:31:34 +0100 Message-Id: <20200108143138.129909-5-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: R05EYAfIP3m61PEM-IBckA-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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 | 68 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 152a0f7454..1dacbc20ec 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,7 +1676,16 @@ static void external_snapshot_prepare(BlkActionState= *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); + + aio_context_release(old_context); + aio_context_acquire(aio_context); + if (ret < 0) { goto out; } @@ -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,21 @@ 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) { + bdrv_unref(target_bs); + 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 +1974,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 +1990,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 +3602,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 +3625,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 +3859,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 +3972,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 +4029,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,10 +4047,16 @@ 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); + + aio_context_release(old_context); + aio_context_acquire(aio_context); + if (ret < 0) { goto out; } --=20 2.23.0 From nobody Thu May 16 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494073; cv=none; d=zohomail.com; s=zohoarc; b=aVt7FVTfi/JF5rmmXOxZ2B196jzFrWAoZbLwOBkZsOvRYeRnHpPr3ozNsHEsV3rEE/40pCjkX3aBt62EWovRWVJ23oXG+a3+563QMOeaseec8wqznaUF5IPeR5MLenXUQpZnB+kJLugCbciM4dIBPaBGjs7Nlx3bX+d1Iu+Ucvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494073; 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=/cRUsUVf/jLm9/Px/HSPyHWXSzAEFUErRxsJJGpixac=; b=g83675jR7oiFOm/Wwc+78v6TV9SWX3P9fT1cuNZ7gTXpMxf9GK3Erm8XkwE6x4KDTf4NLwAMl57zHXfM4Vg8z3kUcUdjxo79//3KoaXbJma2830p0FEpWQPE6UnLdd5wPpuVfeBXyFmNCZT7yM/C61REjPcP+kaZI6fEWj20lqc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494073884887.4207251771871; Wed, 8 Jan 2020 06:34:33 -0800 (PST) Received: from localhost ([::1]:44864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCPo-0003Ii-8g for importer@patchew.org; Wed, 08 Jan 2020 09:34:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51535) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNb-000188-U3 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNa-00063e-Bu for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:15 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:47234 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 1ipCNa-00063V-92 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:14 -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-111-s5qUdgiQO4CaU-CJ1n_ERA-1; Wed, 08 Jan 2020 09:32:00 -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 B953C1800D4E; Wed, 8 Jan 2020 14:31:57 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD0756FF0F; Wed, 8 Jan 2020 14:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493933; 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=/cRUsUVf/jLm9/Px/HSPyHWXSzAEFUErRxsJJGpixac=; b=MHfMpFK2eOYMrG0Gy1xukXRRHWU++iZ12hIg0X90DjUP/PYXPms+UO5QFVfPFPE0AMlAeu 2X49UsB0XMI+MIn3NIuGEQtHt0a0Qf38lvwEnIWmvBKsSeqjT0cRQjOJ8J2VUDjuT6QUYE EyyuV0SSoOSyfQCQfTvi2QSPHHVZv5s= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 5/8] block/backup-top: Don't acquire context while dropping top Date: Wed, 8 Jan 2020 15:31:35 +0100 Message-Id: <20200108143138.129909-6-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: s5qUdgiQO4CaU-CJ1n_ERA-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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" All paths that lead to bdrv_backup_top_drop(), except for the call from backup_clean(), imply that the BDS AioContext has already been acquired, so doing it there too can potentially lead to QEMU hanging on AIO_WAIT_WHILE(). An easy way to trigger this situation is by issuing a two actions transaction, with a proper and a bogus blockdev-backup, so the second one will trigger a rollback. This will trigger a hang with an stack trace like this one: #0 0x00007fb680c75016 in __GI_ppoll (fds=3D0x55e74580f7c0, nfds=3D1, time= out=3D, timeout@entry=3D0x0, sigmask=3Dsigmask@entry=3D0x0) at ../sysdeps/unix= /sysv/linux/ppoll.c:39 #1 0x000055e743386e09 in ppoll (__ss=3D0x0, __timeout=3D0x0, __nfds=3D, __fds=3D) at /usr/include/bits/poll2.h:77 #2 0x000055e743386e09 in qemu_poll_ns (fds=3D, nfds=3D, timeout=3D) at util/qemu-timer.c:336 #3 0x000055e743388dc4 in aio_poll (ctx=3D0x55e7458925d0, blocking=3Dblock= ing@entry=3Dtrue) at util/aio-posix.c:669 #4 0x000055e743305dea in bdrv_flush (bs=3Dbs@entry=3D0x55e74593c0d0) at b= lock/io.c:2878 #5 0x000055e7432be58e in bdrv_close (bs=3D0x55e74593c0d0) at block.c:4017 #6 0x000055e7432be58e in bdrv_delete (bs=3D) at block.c:42= 62 #7 0x000055e7432be58e in bdrv_unref (bs=3Dbs@entry=3D0x55e74593c0d0) at b= lock.c:5644 #8 0x000055e743316b9b in bdrv_backup_top_drop (bs=3Dbs@entry=3D0x55e74593= c0d0) at block/backup-top.c:273 #9 0x000055e74331461f in backup_job_create (job_id=3D0x0, bs=3Dbs@entry=3D0x55e7458d5820, target=3Dtarget@entry= =3D0x55e74589f640, speed=3D0, sync_mode=3DMIRROR_SYNC_MODE_FULL, sync_bitma= p=3Dsync_bitmap@entry=3D0x0, bitmap_mode=3DBITMAP_SYNC_MODE_ON_SUCCESS, com= press=3Dfalse, filter_node_name=3D0x0, on_source_error=3DBLOCKDEV_ON_ERROR_= REPORT, on_target_error=3DBLOCKDEV_ON_ERROR_REPORT, creation_flags=3D0, cb= =3D0x0, opaque=3D0x0, txn=3D0x0, errp=3D0x7ffddfd1efb0) at block/backup.c:4= 78 #10 0x000055e74315bc52 in do_backup_common (backup=3Dbackup@entry=3D0x55e746c066d0, bs=3Dbs@entry=3D0x55e7458d582= 0, target_bs=3Dtarget_bs@entry=3D0x55e74589f640, aio_context=3Daio_context@= entry=3D0x55e7458a91e0, txn=3Dtxn@entry=3D0x0, errp=3Derrp@entry=3D0x7ffddf= d1efb0) at blockdev.c:3580 #11 0x000055e74315c37c in do_blockdev_backup (backup=3Dbackup@entry=3D0x55e746c066d0, txn=3D0x0, errp=3Derrp@entry= =3D0x7ffddfd1efb0) at /usr/src/debug/qemu-kvm-4.2.0-2.module+el8.2.0+5135+ed3b2489.x86_64= /./qapi/qapi-types-block-core.h:1492 #12 0x000055e74315c449 in blockdev_backup_prepare (common=3D0x55e746a8de90= , errp=3D0x7ffddfd1f018) at blockdev.c:1885 #13 0x000055e743160152 in qmp_transaction (dev_list=3D, has_props=3D, props=3D0x55= e7467fe2c0, errp=3Derrp@entry=3D0x7ffddfd1f088) at blockdev.c:2340 #14 0x000055e743287ff5 in qmp_marshal_transaction (args=3D, ret=3D, errp=3D0x7ffddfd1f0f8) at qapi/qapi-commands-transaction.c:44 #15 0x000055e74333de6c in do_qmp_dispatch (errp=3D0x7ffddfd1f0f0, allow_oob=3D, request=3D, cmds=3D0x55e743c28d60 ) at qapi/qmp-dispatch.c:132 #16 0x000055e74333de6c in qmp_dispatch (cmds=3D0x55e743c28d60 , request=3D, allo= w_oob=3D) at qapi/qmp-dispatch.c:175 #17 0x000055e74325c061 in monitor_qmp_dispatch (mon=3D0x55e745908030, req= =3D) at monitor/qmp.c:145 #18 0x000055e74325c6fa in monitor_qmp_bh_dispatcher (data=3D) at monitor/qmp.c:234 #19 0x000055e743385866 in aio_bh_call (bh=3D0x55e745807ae0) at util/async.= c:117 #20 0x000055e743385866 in aio_bh_poll (ctx=3Dctx@entry=3D0x55e7458067a0) a= t util/async.c:117 #21 0x000055e743388c54 in aio_dispatch (ctx=3D0x55e7458067a0) at util/aio-= posix.c:459 #22 0x000055e743385742 in aio_ctx_dispatch (source=3D, callback=3D, user_data=3D) at util/async.c:260 #23 0x00007fb68543e67d in g_main_dispatch (context=3D0x55e745893a40) at gm= ain.c:3176 #24 0x00007fb68543e67d in g_main_context_dispatch (context=3Dcontext@entry= =3D0x55e745893a40) at gmain.c:3829 #25 0x000055e743387d08 in glib_pollfds_poll () at util/main-loop.c:219 #26 0x000055e743387d08 in os_host_main_loop_wait (timeout=3D) at util/main-loop.c:242 #27 0x000055e743387d08 in main_loop_wait (nonblocking=3D) a= t util/main-loop.c:518 #28 0x000055e74316a3c1 in main_loop () at vl.c:1828 #29 0x000055e743016a72 in main (argc=3D, argv=3D, envp=3D) at vl.c:4504 Fix this by not acquiring the AioContext there, and ensuring all paths leading to it have it already acquired (backup_clean()). RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1782111 Signed-off-by: Sergio Lopez --- block/backup-top.c | 5 ----- block/backup.c | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/block/backup-top.c b/block/backup-top.c index 818d3f26b4..b8d863ff08 100644 --- a/block/backup-top.c +++ b/block/backup-top.c @@ -255,9 +255,6 @@ append_failed: void bdrv_backup_top_drop(BlockDriverState *bs) { BDRVBackupTopState *s =3D bs->opaque; - AioContext *aio_context =3D bdrv_get_aio_context(bs); - - aio_context_acquire(aio_context); =20 bdrv_drained_begin(bs); =20 @@ -271,6 +268,4 @@ void bdrv_backup_top_drop(BlockDriverState *bs) bdrv_drained_end(bs); =20 bdrv_unref(bs); - - aio_context_release(aio_context); } diff --git a/block/backup.c b/block/backup.c index cf62b1a38c..1383e219f5 100644 --- a/block/backup.c +++ b/block/backup.c @@ -135,8 +135,11 @@ static void backup_abort(Job *job) static void backup_clean(Job *job) { BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); + AioContext *aio_context =3D bdrv_get_aio_context(s->backup_top); =20 + aio_context_acquire(aio_context); bdrv_backup_top_drop(s->backup_top); + aio_context_release(aio_context); } =20 void backup_do_checkpoint(BlockJob *job, Error **errp) --=20 2.23.0 From nobody Thu May 16 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494235; cv=none; d=zohomail.com; s=zohoarc; b=JqNt3gFV4aFxtbOF2ZOoFNzc03eoG1stPTRV19QoleDGuBq4XwQme3CdpYcjySSijLJa6x1AS2sjJMrXyLKGSv1obY21bcYaITnsojYMksrpm1xmlimUet05phbxznQT9rq0sAfyeC7huuTKzhqGQGStKWe4S3SK3FTB0lMV4ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494235; 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=q0ryrbxqwqxBPIPGONKJtab8dVzRHdHjDel4A/DxFF8=; b=eCEyhnQL5S2Au/9+eG5gZ9nhAz8qlfR5DpfuK5+kcW0470/iN0YQkDmVptrYM6r1acraO+rllL5G/Hxpz5ldZg5ebyLRXKkkxEmhSaTc7oyTbCMPhhScs3aHQQOD46jILtRYrB7UPBlA+u+oecAc9vS+EPEzFCRACVGymZosGsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 157849423567198.65753322635669; Wed, 8 Jan 2020 06:37:15 -0800 (PST) Received: from localhost ([::1]:44906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCSQ-0006zD-9S for importer@patchew.org; Wed, 08 Jan 2020 09:37:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51402) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNV-0000zE-J3 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNT-0005xr-Sl for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:09 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60449 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 1ipCNT-0005xU-P8 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:07 -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-88-qHHJYPALPMefmZcGJqgaUA-1; Wed, 08 Jan 2020 09:32:05 -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 08C03800EBF; Wed, 8 Jan 2020 14:32:05 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F8A96FF0F; Wed, 8 Jan 2020 14:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493927; 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=q0ryrbxqwqxBPIPGONKJtab8dVzRHdHjDel4A/DxFF8=; b=HokYtYXAQEfA7nrb4rlvI8LWGv7MRzkXSAxtq+O9H+6YA9FS/g7nGB97ZX/fc8VL/fUqpl SY7nY+/JWzBgx57Smoe3x+yWoADScQPfod12ycErgFKRlBnT7AS+V3EKHd2fbQQhCIVwCG zxFsHGQnNdrvgtJ00q45yTUFWX6lQhg= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 6/8] blockdev: Acquire AioContext on dirty bitmap functions Date: Wed, 8 Jan 2020 15:31:36 +0100 Message-Id: <20200108143138.129909-7-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: qHHJYPALPMefmZcGJqgaUA-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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" Dirty map addition and removal functions are not acquiring to BDS AioContext, while they may call to code that expects it to be acquired. This may trigger a crash with a stack trace like this one: #0 0x00007f0ef146370f in __GI_raise (sig=3Dsig@entry=3D6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007f0ef144db25 in __GI_abort () at abort.c:79 #2 0x0000565022294dce in error_exit (err=3D, msg=3Dmsg@entry=3D0x56502243a730 <__func__.163= 50> "qemu_mutex_unlock_impl") at util/qemu-thread-posix.c:36 #3 0x00005650222950ba in qemu_mutex_unlock_impl (mutex=3Dmutex@entry=3D0x5650244b0240, file=3Dfile@entry=3D0x565022439= adf "util/async.c", line=3Dline@entry=3D526) at util/qemu-thread-posix.c:108 #4 0x0000565022290029 in aio_context_release (ctx=3Dctx@entry=3D0x5650244b01e0) at util/async.c:526 #5 0x000056502221cd08 in bdrv_can_store_new_dirty_bitmap (bs=3Dbs@entry=3D0x5650244dc820, name=3Dname@entry=3D0x56502481d360 "b= itmap1", granularity=3Dgranularity@entry=3D65536, errp=3Derrp@entry=3D0x7ff= f22831718) at block/dirty-bitmap.c:542 #6 0x000056502206ae53 in qmp_block_dirty_bitmap_add (errp=3D0x7fff22831718, disabled=3Dfalse, has_disabled=3D, persistent=3D, has_persistent=3Dtrue, granularity=3D6553= 6, has_granularity=3D, name=3D0x56502481d360 "bitmap1", node= =3D) at blockdev.c:2894 #7 0x000056502206ae53 in qmp_block_dirty_bitmap_add (node=3D, name=3D0x56502481d360 "bitmap1", has_granular= ity=3D, granularity=3D, has_persistent=3Dtrue= , persistent=3D, has_disabled=3Dfalse, disabled=3Dfalse, err= p=3D0x7fff22831718) at blockdev.c:2856 #8 0x00005650221847a3 in qmp_marshal_block_dirty_bitmap_add (args=3D, ret=3D, errp=3D0x7fff22831798) at qapi/qapi-commands-block-core.c:651 #9 0x0000565022247e6c in do_qmp_dispatch (errp=3D0x7fff22831790, allow_oob=3D, request=3D, cmds=3D0x565022b32d60 ) at qapi/qmp-dispatch.c:132 #10 0x0000565022247e6c in qmp_dispatch (cmds=3D0x565022b32d60 , request=3D, allo= w_oob=3D) at qapi/qmp-dispatch.c:175 #11 0x0000565022166061 in monitor_qmp_dispatch (mon=3D0x56502450faa0, req=3D) at monitor/qmp.c:145 #12 0x00005650221666fa in monitor_qmp_bh_dispatcher (data=3D) at monitor/qmp.c:234 #13 0x000056502228f866 in aio_bh_call (bh=3D0x56502440eae0) at util/async.c:117 #14 0x000056502228f866 in aio_bh_poll (ctx=3Dctx@entry=3D0x56502440d7a0) at util/async.c:117 #15 0x0000565022292c54 in aio_dispatch (ctx=3D0x56502440d7a0) at util/aio-posix.c:459 #16 0x000056502228f742 in aio_ctx_dispatch (source=3D, callback=3D, user_data=3D) at util/async.c:260 #17 0x00007f0ef5ce667d in g_main_dispatch (context=3D0x56502449aa40) at gmain.c:3176 #18 0x00007f0ef5ce667d in g_main_context_dispatch (context=3Dcontext@entry=3D0x56502449aa40) at gmain.c:3829 #19 0x0000565022291d08 in glib_pollfds_poll () at util/main-loop.c:219 #20 0x0000565022291d08 in os_host_main_loop_wait (timeout=3D) at util/main-loop.c:242 #21 0x0000565022291d08 in main_loop_wait (nonblocking=3D) at util/main-loop.c:518 #22 0x00005650220743c1 in main_loop () at vl.c:1828 #23 0x0000565021f20a72 in main (argc=3D, argv=3D, envp=3D) at vl.c:4504 Fix this by acquiring the AioContext at qmp_block_dirty_bitmap_add() and qmp_block_dirty_bitmap_add(). RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1782175 Signed-off-by: Sergio Lopez --- blockdev.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 1dacbc20ec..292961a88d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2984,6 +2984,7 @@ void qmp_block_dirty_bitmap_add(const char *node, con= st char *name, { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; + AioContext *aio_context; =20 if (!name || name[0] =3D=3D '\0') { error_setg(errp, "Bitmap name cannot be empty"); @@ -2995,11 +2996,14 @@ void qmp_block_dirty_bitmap_add(const char *node, c= onst char *name, return; } =20 + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (has_granularity) { if (granularity < 512 || !is_power_of_2(granularity)) { error_setg(errp, "Granularity must be power of 2 " "and at least 512"); - return; + goto out; } } else { /* Default to cluster size, if available: */ @@ -3017,12 +3021,12 @@ void qmp_block_dirty_bitmap_add(const char *node, c= onst char *name, if (persistent && !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) { - return; + goto out; } =20 bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); if (bitmap =3D=3D NULL) { - return; + goto out; } =20 if (disabled) { @@ -3030,6 +3034,9 @@ void qmp_block_dirty_bitmap_add(const char *node, con= st char *name, } =20 bdrv_dirty_bitmap_set_persistence(bitmap, persistent); + +out: + aio_context_release(aio_context); } =20 static BdrvDirtyBitmap *do_block_dirty_bitmap_remove( @@ -3038,20 +3045,26 @@ static BdrvDirtyBitmap *do_block_dirty_bitmap_remov= e( { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; + AioContext *aio_context; =20 bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); if (!bitmap || !bs) { return NULL; } =20 + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO, errp)) { + aio_context_release(aio_context); return NULL; } =20 if (bdrv_dirty_bitmap_get_persistence(bitmap) && bdrv_remove_persistent_dirty_bitmap(bs, name, errp) < 0) { + aio_context_release(aio_context); return NULL; } =20 @@ -3063,6 +3076,7 @@ static BdrvDirtyBitmap *do_block_dirty_bitmap_remove( *bitmap_bs =3D bs; } =20 + aio_context_release(aio_context); return release ? NULL : bitmap; } =20 --=20 2.23.0 From nobody Thu May 16 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494306; cv=none; d=zohomail.com; s=zohoarc; b=NjgXA8G8IfFxZLuaYekLMQi7weSJauoxNm5P8NOjlFQJ5yrDq0WJWhBwajwkm6Rjs55f2yh7J78wwi4NvojkCQrzJxvYhFFsU7xil4bPCr79GNDDk9mHBsr9GUjuNFXc89Ypc7JiGfWQQL5qIBDgw+XbouNydUULs305kdJmoIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494306; 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=mMTtFLCmoXcDohIcRMb4cQQJh091sf79PJSYy2RWfNs=; b=QejNnab6csU9spsR2XqUQLChw2F7gEEmhQIpe7HxcBDXAz1S8JRiuyIjNZ3PbRoMIEHDiojt/0SZ4oGLKWqiFO1QhptQeHEyIWS8HDnVusOGYPOyFBQQW4kb/I/xUCCvu07D3zr8+5LIYTUckHkO2QkbuIl2fAlfS/+QaHNHKu0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494306866926.8724824888833; Wed, 8 Jan 2020 06:38:26 -0800 (PST) Received: from localhost ([::1]:44932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCTZ-0000Zk-QJ for importer@patchew.org; Wed, 08 Jan 2020 09:38:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51456) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNY-000136-Ae for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNW-00061B-NF for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:12 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:41971 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 1ipCNW-00060m-JU for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:10 -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-90-IXQVVHF8PCqnD-PzsB_Jtw-1; Wed, 08 Jan 2020 09:32:08 -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 CDB70800D48; Wed, 8 Jan 2020 14:32:07 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63A6E6FF0F; Wed, 8 Jan 2020 14:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493930; 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=mMTtFLCmoXcDohIcRMb4cQQJh091sf79PJSYy2RWfNs=; b=Cku7AyWKhyrnD9gzZ5cUtOH2hoD338PnoRmd7Q6ATmlxV8GvlPQNYuywdJr2yyGUAzMd4H 5joxM1Nx78VNjMPe/EksqA54C/pKXeDlhELUaRp6sB3cKYTKDubIUpOTGjhhjTrUJiMUHE bTezgkLC8jhigc2ZtJXrUDsL0lZh8WA= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 7/8] blockdev: Return bs to the proper context on snapshot abort Date: Wed, 8 Jan 2020 15:31:37 +0100 Message-Id: <20200108143138.129909-8-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: IXQVVHF8PCqnD-PzsB_Jtw-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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" external_snapshot_abort() calls to bdrv_set_backing_hd(), which returns state->old_bs to the main AioContext, as it's intended to be used then the BDS is going to be released. As that's not the case when aborting an external snapshot, return it to the AioContext it was before the call. This issue can be triggered by issuing a transaction with two actions, a proper blockdev-snapshot-sync and a bogus one, so the second will trigger a transaction abort. This results in a crash with an stack trace like this one: #0 0x00007fa1048b28df in __GI_raise (sig=3Dsig@entry=3D6) at ../sysdeps/u= nix/sysv/linux/raise.c:50 #1 0x00007fa10489ccf5 in __GI_abort () at abort.c:79 #2 0x00007fa10489cbc9 in __assert_fail_base (fmt=3D0x7fa104a03300 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", ass= ertion=3D0x5572240b44d8 "bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_c= ontext(new_bs)", file=3D0x557224014d30 "block.c", line=3D2240, function=3D<= optimized out>) at assert.c:92 #3 0x00007fa1048aae96 in __GI___assert_fail (assertion=3Dassertion@entry=3D0x5572240b44d8 "bdrv_get_aio_context(ol= d_bs) =3D=3D bdrv_get_aio_context(new_bs)", file=3Dfile@entry=3D0x557224014= d30 "block.c", line=3Dline@entry=3D2240, function=3Dfunction@entry=3D0x5572= 240b5d60 <__PRETTY_FUNCTION__.31620> "bdrv_replace_child_noperm") at assert= .c:101 #4 0x0000557223e631f8 in bdrv_replace_child_noperm (child=3D0x557225b9c98= 0, new_bs=3Dnew_bs@entry=3D0x557225c42e40) at block.c:2240 #5 0x0000557223e68be7 in bdrv_replace_node (from=3D0x557226951a60, to=3D0= x557225c42e40, errp=3D0x5572247d6138 ) at block.c:4196 #6 0x0000557223d069c4 in external_snapshot_abort (common=3D0x557225d7e170= ) at blockdev.c:1731 #7 0x0000557223d069c4 in external_snapshot_abort (common=3D0x557225d7e170= ) at blockdev.c:1717 #8 0x0000557223d09013 in qmp_transaction (dev_list=3D, has= _props=3D, props=3D0x557225cc7d70, errp=3Derrp@entry=3D0x7ff= e704c0c98) at blockdev.c:2360 #9 0x0000557223e32085 in qmp_marshal_transaction (args=3D,= ret=3D, errp=3D0x7ffe704c0d08) at qapi/qapi-commands-transa= ction.c:44 #10 0x0000557223ee798c in do_qmp_dispatch (errp=3D0x7ffe704c0d00, allow_oo= b=3D, request=3D, cmds=3D0x5572247d3cc0 ) at qapi/qmp-dispatch.c:132 #11 0x0000557223ee798c in qmp_dispatch (cmds=3D0x5572247d3cc0 , request=3D, allow_oob=3D) at qapi/qmp-dis= patch.c:175 #12 0x0000557223e06141 in monitor_qmp_dispatch (mon=3D0x557225c69ff0, req= =3D) at monitor/qmp.c:120 #13 0x0000557223e0678a in monitor_qmp_bh_dispatcher (data=3D) at monitor/qmp.c:209 #14 0x0000557223f2f366 in aio_bh_call (bh=3D0x557225b9dc60) at util/async.= c:117 #15 0x0000557223f2f366 in aio_bh_poll (ctx=3Dctx@entry=3D0x557225b9c840) a= t util/async.c:117 #16 0x0000557223f32754 in aio_dispatch (ctx=3D0x557225b9c840) at util/aio-= posix.c:459 #17 0x0000557223f2f242 in aio_ctx_dispatch (source=3D, call= back=3D, user_data=3D) at util/async.c:260 #18 0x00007fa10913467d in g_main_dispatch (context=3D0x557225c28e80) at gm= ain.c:3176 #19 0x00007fa10913467d in g_main_context_dispatch (context=3Dcontext@entry= =3D0x557225c28e80) at gmain.c:3829 #20 0x0000557223f31808 in glib_pollfds_poll () at util/main-loop.c:219 #21 0x0000557223f31808 in os_host_main_loop_wait (timeout=3D) at util/main-loop.c:242 #22 0x0000557223f31808 in main_loop_wait (nonblocking=3D) a= t util/main-loop.c:518 #23 0x0000557223d13201 in main_loop () at vl.c:1828 #24 0x0000557223bbfb82 in main (argc=3D, argv=3D, envp=3D) at vl.c:4504 RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1779036 Signed-off-by: Sergio Lopez --- blockdev.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/blockdev.c b/blockdev.c index 292961a88d..cfed87f434 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1731,6 +1731,8 @@ static void external_snapshot_abort(BlkActionState *c= ommon) if (state->new_bs) { if (state->overlay_appended) { AioContext *aio_context; + AioContext *tmp_context; + int ret; =20 aio_context =3D bdrv_get_aio_context(state->old_bs); aio_context_acquire(aio_context); @@ -1738,6 +1740,25 @@ static void external_snapshot_abort(BlkActionState *= common) bdrv_ref(state->old_bs); /* we can't let bdrv_set_backind_hd= () close state->old_bs; we need it = */ bdrv_set_backing_hd(state->new_bs, NULL, &error_abort); + + /* + * The call to bdrv_set_backing_hd() above returns state->old_= bs to + * the main AioContext. As we're still going to be using it, r= eturn + * it to the AioContext it was before. + */ + tmp_context =3D bdrv_get_aio_context(state->old_bs); + if (aio_context !=3D tmp_context) { + aio_context_release(aio_context); + aio_context_acquire(tmp_context); + + ret =3D bdrv_try_set_aio_context(state->old_bs, + aio_context, NULL); + assert(ret =3D=3D 0); + + aio_context_release(tmp_context); + aio_context_acquire(aio_context); + } + bdrv_replace_node(state->new_bs, state->old_bs, &error_abort); bdrv_unref(state->old_bs); /* bdrv_replace_node() ref'ed old_b= s */ =20 --=20 2.23.0 From nobody Thu May 16 07:05:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1578494290; cv=none; d=zohomail.com; s=zohoarc; b=QIle5bRnBMr8DmgwJdMpvDXaMkiu5XiDmP7uSvCHaSifa78wGjvzCL6J1skWB3ZM8jUt9j488WmKFD/ht7Zi3OyGkz5nhjlwgZJeQenkv6ZFtWtWAggNW+l0eLCGNixG0hcvHBeKQUxlD+600jK7HC3GwR8yHqStFcX1VP5GVNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578494290; 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=14vK0vgZxcrVgXTApZ8satsEy+e861b7T9N1gndgzGw=; b=QVQXq8GXfidYzmQa7wRqUr24MnlpGLcQmqpBIv0KUzGVeTyJLTC0PQB1v7dzlElx6BrLjtY/80kPaz2t8OfaZVwqqHf9qBvI8B0HZIvsahwj4+0V2pvWHi+fyq/siJD8idF7P4qv0rf3kebJaxon/w+nmoJ0jUOc6hC7NhDfujQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1578494290243184.9372988830902; Wed, 8 Jan 2020 06:38:10 -0800 (PST) Received: from localhost ([::1]:44930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCTJ-00008d-3B for importer@patchew.org; Wed, 08 Jan 2020 09:38:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51523) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCNb-00017R-FA for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCNZ-000636-H1 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:15 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:36995 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 1ipCNZ-00062i-Cg for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:32:13 -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-388-MyVQfuh1NLmtWmuVJelzsA-1; Wed, 08 Jan 2020 09:32:11 -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 71D83800EBF; Wed, 8 Jan 2020 14:32:10 +0000 (UTC) Received: from dritchie.redhat.com (unknown [10.33.36.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36BB56FF0F; Wed, 8 Jan 2020 14:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578493932; 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=14vK0vgZxcrVgXTApZ8satsEy+e861b7T9N1gndgzGw=; b=Zy9tpdDFNCuBWhLdBaJtLsfcTx7liVzmGdlher1ABKtKCCSeSWvD2Ex9MhckvF3PrSewdx gEM9IQMyMbbA7SlObEDCfaYV2iRdFKR3Y1OojQcB0xXvgGBM+gNSa4ssFAJ46KWVDabage y+TxSdPldmY6429EUTAx4aK6YF8RufU= From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH v6 8/8] iotests: Test handling of AioContexts with some blockdev actions Date: Wed, 8 Jan 2020 15:31:38 +0100 Message-Id: <20200108143138.129909-9-slp@redhat.com> In-Reply-To: <20200108143138.129909-1-slp@redhat.com> References: <20200108143138.129909-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: MyVQfuh1NLmtWmuVJelzsA-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 , qemu-block@nongnu.org, Sergio Lopez , Markus Armbruster , Max Reitz , John Snow 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" Includes the following tests: - Adding a dirty bitmap. * RHBZ: 1782175 - Starting a drive-mirror to an NBD-backed target. * RHBZ: 1746217, 1773517 - Aborting an external snapshot transaction. * RHBZ: 1779036 - Aborting a blockdev backup transaction. * RHBZ: 1782111 For each one of them, a VM with a number of disks running in an IOThread AioContext is used. Signed-off-by: Sergio Lopez --- tests/qemu-iotests/281 | 247 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/281.out | 5 + tests/qemu-iotests/group | 1 + 3 files changed, 253 insertions(+) create mode 100755 tests/qemu-iotests/281 create mode 100644 tests/qemu-iotests/281.out diff --git a/tests/qemu-iotests/281 b/tests/qemu-iotests/281 new file mode 100755 index 0000000000..269d583b2c --- /dev/null +++ b/tests/qemu-iotests/281 @@ -0,0 +1,247 @@ +#!/usr/bin/env python +# +# Test cases for blockdev + IOThread interactions +# +# Copyright (C) 2019 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import iotests +from iotests import qemu_img + +image_len =3D 64 * 1024 * 1024 + +# Test for RHBZ#1782175 +class TestDirtyBitmapIOThread(iotests.QMPTestCase): + drive0_img =3D os.path.join(iotests.test_dir, 'drive0.img') + images =3D { 'drive0': drive0_img } + + def setUp(self): + for name in self.images: + qemu_img('create', '-f', iotests.imgfmt, + self.images[name], str(image_len)) + + self.vm =3D iotests.VM() + self.vm.add_object('iothread,id=3Diothread0') + + for name in self.images: + self.vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3D= file_%s' + % (self.images[name], name)) + self.vm.add_blockdev('driver=3Dqcow2,file=3Dfile_%s,node-name= =3D%s' + % (name, name)) + + self.vm.launch() + self.vm.qmp('x-blockdev-set-iothread', + node_name=3D'drive0', iothread=3D'iothread0', + force=3DTrue) + + def tearDown(self): + self.vm.shutdown() + for name in self.images: + os.remove(self.images[name]) + + def test_add_dirty_bitmap(self): + result =3D self.vm.qmp( + 'block-dirty-bitmap-add', + node=3D'drive0', + name=3D'bitmap1', + persistent=3DTrue, + ) + + self.assert_qmp(result, 'return', {}) + + +# Test for RHBZ#1746217 & RHBZ#1773517 +class TestNBDMirrorIOThread(iotests.QMPTestCase): + nbd_sock =3D os.path.join(iotests.sock_dir, 'nbd.sock') + drive0_img =3D os.path.join(iotests.test_dir, 'drive0.img') + mirror_img =3D os.path.join(iotests.test_dir, 'mirror.img') + images =3D { 'drive0': drive0_img, 'mirror': mirror_img } + + def setUp(self): + for name in self.images: + qemu_img('create', '-f', iotests.imgfmt, + self.images[name], str(image_len)) + + self.vm_src =3D iotests.VM(path_suffix=3D'src') + self.vm_src.add_object('iothread,id=3Diothread0') + self.vm_src.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3D= file0' + % (self.drive0_img)) + self.vm_src.add_blockdev('driver=3Dqcow2,file=3Dfile0,node-name=3D= drive0') + self.vm_src.launch() + self.vm_src.qmp('x-blockdev-set-iothread', + node_name=3D'drive0', iothread=3D'iothread0', + force=3DTrue) + + self.vm_tgt =3D iotests.VM(path_suffix=3D'tgt') + self.vm_tgt.add_object('iothread,id=3Diothread0') + self.vm_tgt.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3D= file0' + % (self.mirror_img)) + self.vm_tgt.add_blockdev('driver=3Dqcow2,file=3Dfile0,node-name=3D= drive0') + self.vm_tgt.launch() + self.vm_tgt.qmp('x-blockdev-set-iothread', + node_name=3D'drive0', iothread=3D'iothread0', + force=3DTrue) + + def tearDown(self): + self.vm_src.shutdown() + self.vm_tgt.shutdown() + for name in self.images: + os.remove(self.images[name]) + + def test_nbd_mirror(self): + result =3D self.vm_tgt.qmp( + 'nbd-server-start', + addr=3D{ + 'type': 'unix', + 'data': { 'path': self.nbd_sock } + } + ) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm_tgt.qmp( + 'nbd-server-add', + device=3D'drive0', + writable=3DTrue + ) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm_src.qmp( + 'drive-mirror', + device=3D'drive0', + target=3D'nbd+unix:///drive0?socket=3D' + self.nbd_sock, + sync=3D'full', + mode=3D'existing', + speed=3D64*1024*1024, + job_id=3D'j1' + ) + self.assert_qmp(result, 'return', {}) + + self.vm_src.event_wait(name=3D"BLOCK_JOB_READY") + + +# Test for RHBZ#1779036 +class TestExternalSnapshotAbort(iotests.QMPTestCase): + drive0_img =3D os.path.join(iotests.test_dir, 'drive0.img') + snapshot_img =3D os.path.join(iotests.test_dir, 'snapshot.img') + images =3D { 'drive0': drive0_img, 'snapshot': snapshot_img } + + def setUp(self): + for name in self.images: + qemu_img('create', '-f', iotests.imgfmt, + self.images[name], str(image_len)) + + self.vm =3D iotests.VM() + self.vm.add_object('iothread,id=3Diothread0') + self.vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3Dfile= 0' + % (self.drive0_img)) + self.vm.add_blockdev('driver=3Dqcow2,file=3Dfile0,node-name=3Ddriv= e0') + self.vm.launch() + self.vm.qmp('x-blockdev-set-iothread', + node_name=3D'drive0', iothread=3D'iothread0', + force=3DTrue) + + def tearDown(self): + self.vm.shutdown() + for name in self.images: + os.remove(self.images[name]) + + def test_external_snapshot_abort(self): + # Use a two actions transaction with a bogus values on the second + # one to trigger an abort of the transaction. + result =3D self.vm.qmp('transaction', actions=3D[ + { + 'type': 'blockdev-snapshot-sync', + 'data': { 'node-name': 'drive0', + 'snapshot-file': self.snapshot_img, + 'snapshot-node-name': 'snap1', + 'mode': 'absolute-paths', + 'format': 'qcow2' } + }, + { + 'type': 'blockdev-snapshot-sync', + 'data': { 'node-name': 'drive0', + 'snapshot-file': '/fakesnapshot', + 'snapshot-node-name': 'snap2', + 'mode': 'absolute-paths', + 'format': 'qcow2' } + }, + ]) + + # Crashes on failure, we expect this error. + self.assert_qmp(result, 'error/class', 'GenericError') + + +# Test for RHBZ#1782111 +class TestBlockdevBackupAbort(iotests.QMPTestCase): + drive0_img =3D os.path.join(iotests.test_dir, 'drive0.img') + drive1_img =3D os.path.join(iotests.test_dir, 'drive1.img') + snap0_img =3D os.path.join(iotests.test_dir, 'snap0.img') + snap1_img =3D os.path.join(iotests.test_dir, 'snap1.img') + images =3D { 'drive0': drive0_img, + 'drive1': drive1_img, + 'snap0': snap0_img, + 'snap1': snap1_img } + + def setUp(self): + for name in self.images: + qemu_img('create', '-f', iotests.imgfmt, + self.images[name], str(image_len)) + + self.vm =3D iotests.VM() + self.vm.add_object('iothread,id=3Diothread0') + self.vm.add_device('virtio-scsi,iothread=3Diothread0') + + for name in self.images: + self.vm.add_blockdev('driver=3Dfile,filename=3D%s,node-name=3D= file_%s' + % (self.images[name], name)) + self.vm.add_blockdev('driver=3Dqcow2,file=3Dfile_%s,node-name= =3D%s' + % (name, name)) + + self.vm.add_device('scsi-hd,drive=3Ddrive0') + self.vm.add_device('scsi-hd,drive=3Ddrive1') + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + for name in self.images: + os.remove(self.images[name]) + + def test_blockdev_backup_abort(self): + # Use a two actions transaction with a bogus values on the second + # one to trigger an abort of the transaction. + result =3D self.vm.qmp('transaction', actions=3D[ + { + 'type': 'blockdev-backup', + 'data': { 'device': 'drive0', + 'target': 'snap0', + 'sync': 'full', + 'job-id': 'j1' } + }, + { + 'type': 'blockdev-backup', + 'data': { 'device': 'drive1', + 'target': 'snap1', + 'sync': 'full' } + }, + ]) + + # Hangs on failure, we expect this error. + self.assert_qmp(result, 'error/class', 'GenericError') + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['qcow2'], + supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/281.out b/tests/qemu-iotests/281.out new file mode 100644 index 0000000000..89968f35d7 --- /dev/null +++ b/tests/qemu-iotests/281.out @@ -0,0 +1,5 @@ +.... +---------------------------------------------------------------------- +Ran 4 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index cb2b789e44..e041cc1ee3 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -288,3 +288,4 @@ 277 rw quick 279 rw backing quick 280 rw migration quick +281 rw quick --=20 2.23.0