From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342404; cv=none; d=zohomail.com; s=zohoarc; b=REEWV7uBl++yat44PqUEmHCs9uh1rRPvYVT02/OE9uuVgYZV97IKyLllLmJcSkE06A3o3DoBxrFYLMnMlFqv9WE0Iv7vwcbOzP18mRL2/KAczRBobpMGuIvZf0VxdG6vjWBW7vr0kYAFtY9YmxvAskWYkibju1RyHsLEH4BwCuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342404; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pgtNqd1DPjR5WMspqcarUQwt0vxcrVbWV0LqFSCnTb4=; b=Mgp1cpWCiINGWcm4gqV3eHygu9jbtFKNFp43z7EkPfnqEJ8pIFvhkbJ54KUm3bBbFJ6Z/QorJDHvXzYWoFDVTnWa+y55DecMyNwt+WAgkqzOi6OsFQyjdrim3x4XhEX2uRWKGtJGKurB2r3n46Wm89AxuWD1NYnadKvikEUlHyI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342404496602.2879549495244; Wed, 17 May 2023 09:53:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNA-0003vp-V8; Wed, 17 May 2023 12:51:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKN9-0003uV-LE for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKN6-0001O7-UH for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:31 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-stwK-pfJOEKLJadNFw6wmA-1; Wed, 17 May 2023 12:51:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F047185A79C; Wed, 17 May 2023 16:51:24 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1641440C6EC4; Wed, 17 May 2023 16:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pgtNqd1DPjR5WMspqcarUQwt0vxcrVbWV0LqFSCnTb4=; b=EjXDz417toJRqANL6LP3pEsvYc7tT4F0RMo+AVRmDcxqvmgsYCOxcNBd4DFCSgysOdCiCH K1bI5oUOLXHc7xTR1wjqGfomY7Rlyg6volAJKWmREw4IfCCz2/fqT/KlDdu+s/4phzv2yh jQ1SsMBYvz/uMmVvoBEKEh9uvbgYLYU= X-MC-Unique: stwK-pfJOEKLJadNFw6wmA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 01/18] blockdev: refactor transaction to use Transaction API Date: Wed, 17 May 2023 18:50:59 +0200 Message-Id: <20230517165116.475123-2-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342406440100019 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We are going to add more block-graph modifying transaction actions, and block-graph modifying functions are already based on Transaction API. Next, we'll need to separately update permissions after several graph-modifying actions, and this would be simple with help of Transaction API. So, now let's just transform what we have into new-style transaction actions. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20230510150624.310640-2-vsementsov@yandex-team.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- blockdev.c | 309 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 178 insertions(+), 131 deletions(-) diff --git a/blockdev.c b/blockdev.c index d141ca7a2d..3c72d40f51 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1210,10 +1210,7 @@ typedef struct BlkActionState BlkActionState; */ typedef struct BlkActionOps { size_t instance_size; - void (*prepare)(BlkActionState *common, Error **errp); - void (*commit)(BlkActionState *common); - void (*abort)(BlkActionState *common); - void (*clean)(BlkActionState *common); + void (*action)(BlkActionState *common, Transaction *tran, Error **errp= ); } BlkActionOps; =20 /** @@ -1245,6 +1242,12 @@ typedef struct InternalSnapshotState { bool created; } InternalSnapshotState; =20 +static void internal_snapshot_abort(void *opaque); +static void internal_snapshot_clean(void *opaque); +TransactionActionDrv internal_snapshot_drv =3D { + .abort =3D internal_snapshot_abort, + .clean =3D internal_snapshot_clean, +}; =20 static int action_check_completion_mode(BlkActionState *s, Error **errp) { @@ -1259,8 +1262,8 @@ static int action_check_completion_mode(BlkActionStat= e *s, Error **errp) return 0; } =20 -static void internal_snapshot_prepare(BlkActionState *common, - Error **errp) +static void internal_snapshot_action(BlkActionState *common, + Transaction *tran, Error **errp) { Error *local_err =3D NULL; const char *device; @@ -1279,6 +1282,8 @@ static void internal_snapshot_prepare(BlkActionState = *common, internal =3D common->action->u.blockdev_snapshot_internal_sync.data; state =3D DO_UPCAST(InternalSnapshotState, common, common); =20 + tran_add(tran, &internal_snapshot_drv, state); + /* 1. parse input */ device =3D internal->device; name =3D internal->name; @@ -1363,10 +1368,9 @@ out: aio_context_release(aio_context); } =20 -static void internal_snapshot_abort(BlkActionState *common) +static void internal_snapshot_abort(void *opaque) { - InternalSnapshotState *state =3D - DO_UPCAST(InternalSnapshotState, common, comm= on); + InternalSnapshotState *state =3D opaque; BlockDriverState *bs =3D state->bs; QEMUSnapshotInfo *sn =3D &state->sn; AioContext *aio_context; @@ -1390,10 +1394,9 @@ static void internal_snapshot_abort(BlkActionState *= common) aio_context_release(aio_context); } =20 -static void internal_snapshot_clean(BlkActionState *common) +static void internal_snapshot_clean(void *opaque) { - InternalSnapshotState *state =3D DO_UPCAST(InternalSnapshotState, - common, common); + g_autofree InternalSnapshotState *state =3D opaque; AioContext *aio_context; =20 if (!state->bs) { @@ -1416,8 +1419,17 @@ typedef struct ExternalSnapshotState { bool overlay_appended; } ExternalSnapshotState; =20 -static void external_snapshot_prepare(BlkActionState *common, - Error **errp) +static void external_snapshot_commit(void *opaque); +static void external_snapshot_abort(void *opaque); +static void external_snapshot_clean(void *opaque); +TransactionActionDrv external_snapshot_drv =3D { + .commit =3D external_snapshot_commit, + .abort =3D external_snapshot_abort, + .clean =3D external_snapshot_clean, +}; + +static void external_snapshot_action(BlkActionState *common, Transaction *= tran, + Error **errp) { int ret; int flags =3D 0; @@ -1436,6 +1448,8 @@ static void external_snapshot_prepare(BlkActionState = *common, AioContext *aio_context; uint64_t perm, shared; =20 + tran_add(tran, &external_snapshot_drv, state); + /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar * purpose but a different set of parameters */ switch (action->type) { @@ -1588,10 +1602,9 @@ out: aio_context_release(aio_context); } =20 -static void external_snapshot_commit(BlkActionState *common) +static void external_snapshot_commit(void *opaque) { - ExternalSnapshotState *state =3D - DO_UPCAST(ExternalSnapshotState, common, comm= on); + ExternalSnapshotState *state =3D opaque; AioContext *aio_context; =20 aio_context =3D bdrv_get_aio_context(state->old_bs); @@ -1607,10 +1620,9 @@ static void external_snapshot_commit(BlkActionState = *common) aio_context_release(aio_context); } =20 -static void external_snapshot_abort(BlkActionState *common) +static void external_snapshot_abort(void *opaque) { - ExternalSnapshotState *state =3D - DO_UPCAST(ExternalSnapshotState, common, comm= on); + ExternalSnapshotState *state =3D opaque; if (state->new_bs) { if (state->overlay_appended) { AioContext *aio_context; @@ -1650,10 +1662,9 @@ static void external_snapshot_abort(BlkActionState *= common) } } =20 -static void external_snapshot_clean(BlkActionState *common) +static void external_snapshot_clean(void *opaque) { - ExternalSnapshotState *state =3D - DO_UPCAST(ExternalSnapshotState, common, comm= on); + g_autofree ExternalSnapshotState *state =3D opaque; AioContext *aio_context; =20 if (!state->old_bs) { @@ -1681,7 +1692,17 @@ static BlockJob *do_backup_common(BackupCommon *back= up, AioContext *aio_context, JobTxn *txn, Error **errp); =20 -static void drive_backup_prepare(BlkActionState *common, Error **errp) +static void drive_backup_commit(void *opaque); +static void drive_backup_abort(void *opaque); +static void drive_backup_clean(void *opaque); +TransactionActionDrv drive_backup_drv =3D { + .commit =3D drive_backup_commit, + .abort =3D drive_backup_abort, + .clean =3D drive_backup_clean, +}; + +static void drive_backup_action(BlkActionState *common, Transaction *tran, + Error **errp) { DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); DriveBackup *backup; @@ -1698,6 +1719,8 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) bool set_backing_hd =3D false; int ret; =20 + tran_add(tran, &drive_backup_drv, state); + assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); backup =3D common->action->u.drive_backup.data; =20 @@ -1828,9 +1851,9 @@ out: aio_context_release(aio_context); } =20 -static void drive_backup_commit(BlkActionState *common) +static void drive_backup_commit(void *opaque) { - DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + DriveBackupState *state =3D opaque; AioContext *aio_context; =20 aio_context =3D bdrv_get_aio_context(state->bs); @@ -1842,18 +1865,18 @@ static void drive_backup_commit(BlkActionState *com= mon) aio_context_release(aio_context); } =20 -static void drive_backup_abort(BlkActionState *common) +static void drive_backup_abort(void *opaque) { - DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + DriveBackupState *state =3D opaque; =20 if (state->job) { job_cancel_sync(&state->job->job, true); } } =20 -static void drive_backup_clean(BlkActionState *common) +static void drive_backup_clean(void *opaque) { - DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); + g_autofree DriveBackupState *state =3D opaque; AioContext *aio_context; =20 if (!state->bs) { @@ -1874,7 +1897,17 @@ typedef struct BlockdevBackupState { BlockJob *job; } BlockdevBackupState; =20 -static void blockdev_backup_prepare(BlkActionState *common, Error **errp) +static void blockdev_backup_commit(void *opaque); +static void blockdev_backup_abort(void *opaque); +static void blockdev_backup_clean(void *opaque); +TransactionActionDrv blockdev_backup_drv =3D { + .commit =3D blockdev_backup_commit, + .abort =3D blockdev_backup_abort, + .clean =3D blockdev_backup_clean, +}; + +static void blockdev_backup_action(BlkActionState *common, Transaction *tr= an, + Error **errp) { BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); BlockdevBackup *backup; @@ -1884,6 +1917,8 @@ static void blockdev_backup_prepare(BlkActionState *c= ommon, Error **errp) AioContext *old_context; int ret; =20 + tran_add(tran, &blockdev_backup_drv, state); + assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); backup =3D common->action->u.blockdev_backup.data; =20 @@ -1922,9 +1957,9 @@ static void blockdev_backup_prepare(BlkActionState *c= ommon, Error **errp) aio_context_release(aio_context); } =20 -static void blockdev_backup_commit(BlkActionState *common) +static void blockdev_backup_commit(void *opaque) { - BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + BlockdevBackupState *state =3D opaque; AioContext *aio_context; =20 aio_context =3D bdrv_get_aio_context(state->bs); @@ -1936,18 +1971,18 @@ static void blockdev_backup_commit(BlkActionState *= common) aio_context_release(aio_context); } =20 -static void blockdev_backup_abort(BlkActionState *common) +static void blockdev_backup_abort(void *opaque) { - BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + BlockdevBackupState *state =3D opaque; =20 if (state->job) { job_cancel_sync(&state->job->job, true); } } =20 -static void blockdev_backup_clean(BlkActionState *common) +static void blockdev_backup_clean(void *opaque) { - BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); + g_autofree BlockdevBackupState *state =3D opaque; AioContext *aio_context; =20 if (!state->bs) { @@ -1971,14 +2006,22 @@ typedef struct BlockDirtyBitmapState { bool was_enabled; } BlockDirtyBitmapState; =20 -static void block_dirty_bitmap_add_prepare(BlkActionState *common, - Error **errp) +static void block_dirty_bitmap_add_abort(void *opaque); +TransactionActionDrv block_dirty_bitmap_add_drv =3D { + .abort =3D block_dirty_bitmap_add_abort, + .clean =3D g_free, +}; + +static void block_dirty_bitmap_add_action(BlkActionState *common, + Transaction *tran, Error **errp) { Error *local_err =3D NULL; BlockDirtyBitmapAdd *action; BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); =20 + tran_add(tran, &block_dirty_bitmap_add_drv, state); + if (action_check_completion_mode(common, errp) < 0) { return; } @@ -1998,13 +2041,12 @@ static void block_dirty_bitmap_add_prepare(BlkActio= nState *common, } } =20 -static void block_dirty_bitmap_add_abort(BlkActionState *common) +static void block_dirty_bitmap_add_abort(void *opaque) { BlockDirtyBitmapAdd *action; - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 - action =3D common->action->u.block_dirty_bitmap_add.data; + action =3D state->common.action->u.block_dirty_bitmap_add.data; /* Should not be able to fail: IF the bitmap was added via .prepare(), * then the node reference and bitmap name must have been valid. */ @@ -2013,13 +2055,23 @@ static void block_dirty_bitmap_add_abort(BlkActionS= tate *common) } } =20 -static void block_dirty_bitmap_clear_prepare(BlkActionState *common, - Error **errp) +static void block_dirty_bitmap_restore(void *opaque); +static void block_dirty_bitmap_free_backup(void *opaque); +TransactionActionDrv block_dirty_bitmap_clear_drv =3D { + .abort =3D block_dirty_bitmap_restore, + .commit =3D block_dirty_bitmap_free_backup, + .clean =3D g_free, +}; + +static void block_dirty_bitmap_clear_action(BlkActionState *common, + Transaction *tran, Error **err= p) { BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); BlockDirtyBitmap *action; =20 + tran_add(tran, &block_dirty_bitmap_clear_drv, state); + if (action_check_completion_mode(common, errp) < 0) { return; } @@ -2040,31 +2092,37 @@ static void block_dirty_bitmap_clear_prepare(BlkAct= ionState *common, bdrv_clear_dirty_bitmap(state->bitmap, &state->backup); } =20 -static void block_dirty_bitmap_restore(BlkActionState *common) +static void block_dirty_bitmap_restore(void *opaque) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 if (state->backup) { bdrv_restore_dirty_bitmap(state->bitmap, state->backup); } } =20 -static void block_dirty_bitmap_free_backup(BlkActionState *common) +static void block_dirty_bitmap_free_backup(void *opaque) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 hbitmap_free(state->backup); } =20 -static void block_dirty_bitmap_enable_prepare(BlkActionState *common, - Error **errp) +static void block_dirty_bitmap_enable_abort(void *opaque); +TransactionActionDrv block_dirty_bitmap_enable_drv =3D { + .abort =3D block_dirty_bitmap_enable_abort, + .clean =3D g_free, +}; + +static void block_dirty_bitmap_enable_action(BlkActionState *common, + Transaction *tran, Error **er= rp) { BlockDirtyBitmap *action; BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); =20 + tran_add(tran, &block_dirty_bitmap_enable_drv, state); + if (action_check_completion_mode(common, errp) < 0) { return; } @@ -2086,23 +2144,30 @@ static void block_dirty_bitmap_enable_prepare(BlkAc= tionState *common, bdrv_enable_dirty_bitmap(state->bitmap); } =20 -static void block_dirty_bitmap_enable_abort(BlkActionState *common) +static void block_dirty_bitmap_enable_abort(void *opaque) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 if (!state->was_enabled) { bdrv_disable_dirty_bitmap(state->bitmap); } } =20 -static void block_dirty_bitmap_disable_prepare(BlkActionState *common, - Error **errp) +static void block_dirty_bitmap_disable_abort(void *opaque); +TransactionActionDrv block_dirty_bitmap_disable_drv =3D { + .abort =3D block_dirty_bitmap_disable_abort, + .clean =3D g_free, +}; + +static void block_dirty_bitmap_disable_action(BlkActionState *common, + Transaction *tran, Error **e= rrp) { BlockDirtyBitmap *action; BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); =20 + tran_add(tran, &block_dirty_bitmap_disable_drv, state); + if (action_check_completion_mode(common, errp) < 0) { return; } @@ -2124,23 +2189,30 @@ static void block_dirty_bitmap_disable_prepare(BlkA= ctionState *common, bdrv_disable_dirty_bitmap(state->bitmap); } =20 -static void block_dirty_bitmap_disable_abort(BlkActionState *common) +static void block_dirty_bitmap_disable_abort(void *opaque) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 if (state->was_enabled) { bdrv_enable_dirty_bitmap(state->bitmap); } } =20 -static void block_dirty_bitmap_merge_prepare(BlkActionState *common, - Error **errp) +TransactionActionDrv block_dirty_bitmap_merge_drv =3D { + .commit =3D block_dirty_bitmap_free_backup, + .abort =3D block_dirty_bitmap_restore, + .clean =3D g_free, +}; + +static void block_dirty_bitmap_merge_action(BlkActionState *common, + Transaction *tran, Error **err= p) { BlockDirtyBitmapMerge *action; BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); =20 + tran_add(tran, &block_dirty_bitmap_merge_drv, state); + if (action_check_completion_mode(common, errp) < 0) { return; } @@ -2152,13 +2224,23 @@ static void block_dirty_bitmap_merge_prepare(BlkAct= ionState *common, errp); } =20 -static void block_dirty_bitmap_remove_prepare(BlkActionState *common, - Error **errp) +static void block_dirty_bitmap_remove_commit(void *opaque); +static void block_dirty_bitmap_remove_abort(void *opaque); +TransactionActionDrv block_dirty_bitmap_remove_drv =3D { + .commit =3D block_dirty_bitmap_remove_commit, + .abort =3D block_dirty_bitmap_remove_abort, + .clean =3D g_free, +}; + +static void block_dirty_bitmap_remove_action(BlkActionState *common, + Transaction *tran, Error **er= rp) { BlockDirtyBitmap *action; BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, common, common); =20 + tran_add(tran, &block_dirty_bitmap_remove_drv, state); + if (action_check_completion_mode(common, errp) < 0) { return; } @@ -2173,10 +2255,9 @@ static void block_dirty_bitmap_remove_prepare(BlkAct= ionState *common, } } =20 -static void block_dirty_bitmap_remove_abort(BlkActionState *common) +static void block_dirty_bitmap_remove_abort(void *opaque) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 if (state->bitmap) { bdrv_dirty_bitmap_skip_store(state->bitmap, false); @@ -2184,21 +2265,28 @@ static void block_dirty_bitmap_remove_abort(BlkActi= onState *common) } } =20 -static void block_dirty_bitmap_remove_commit(BlkActionState *common) +static void block_dirty_bitmap_remove_commit(void *opaque) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D opaque; =20 bdrv_dirty_bitmap_set_busy(state->bitmap, false); bdrv_release_dirty_bitmap(state->bitmap); } =20 -static void abort_prepare(BlkActionState *common, Error **errp) +static void abort_commit(void *opaque); +TransactionActionDrv abort_drv =3D { + .commit =3D abort_commit, + .clean =3D g_free, +}; + +static void abort_action(BlkActionState *common, Transaction *tran, + Error **errp) { + tran_add(tran, &abort_drv, common); error_setg(errp, "Transaction aborted using Abort action"); } =20 -static void abort_commit(BlkActionState *common) +static void abort_commit(void *opaque) { g_assert_not_reached(); /* this action never succeeds */ } @@ -2206,75 +2294,51 @@ static void abort_commit(BlkActionState *common) static const BlkActionOps actions[] =3D { [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT] =3D { .instance_size =3D sizeof(ExternalSnapshotState), - .prepare =3D external_snapshot_prepare, - .commit =3D external_snapshot_commit, - .abort =3D external_snapshot_abort, - .clean =3D external_snapshot_clean, + .action =3D external_snapshot_action, }, [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] =3D { .instance_size =3D sizeof(ExternalSnapshotState), - .prepare =3D external_snapshot_prepare, - .commit =3D external_snapshot_commit, - .abort =3D external_snapshot_abort, - .clean =3D external_snapshot_clean, + .action =3D external_snapshot_action, }, [TRANSACTION_ACTION_KIND_DRIVE_BACKUP] =3D { .instance_size =3D sizeof(DriveBackupState), - .prepare =3D drive_backup_prepare, - .commit =3D drive_backup_commit, - .abort =3D drive_backup_abort, - .clean =3D drive_backup_clean, + .action =3D drive_backup_action, }, [TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP] =3D { .instance_size =3D sizeof(BlockdevBackupState), - .prepare =3D blockdev_backup_prepare, - .commit =3D blockdev_backup_commit, - .abort =3D blockdev_backup_abort, - .clean =3D blockdev_backup_clean, + .action =3D blockdev_backup_action, }, [TRANSACTION_ACTION_KIND_ABORT] =3D { .instance_size =3D sizeof(BlkActionState), - .prepare =3D abort_prepare, - .commit =3D abort_commit, + .action =3D abort_action, }, [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC] =3D { .instance_size =3D sizeof(InternalSnapshotState), - .prepare =3D internal_snapshot_prepare, - .abort =3D internal_snapshot_abort, - .clean =3D internal_snapshot_clean, + .action =3D internal_snapshot_action, }, [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_ADD] =3D { .instance_size =3D sizeof(BlockDirtyBitmapState), - .prepare =3D block_dirty_bitmap_add_prepare, - .abort =3D block_dirty_bitmap_add_abort, + .action =3D block_dirty_bitmap_add_action, }, [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_CLEAR] =3D { .instance_size =3D sizeof(BlockDirtyBitmapState), - .prepare =3D block_dirty_bitmap_clear_prepare, - .commit =3D block_dirty_bitmap_free_backup, - .abort =3D block_dirty_bitmap_restore, + .action =3D block_dirty_bitmap_clear_action, }, [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_ENABLE] =3D { .instance_size =3D sizeof(BlockDirtyBitmapState), - .prepare =3D block_dirty_bitmap_enable_prepare, - .abort =3D block_dirty_bitmap_enable_abort, + .action =3D block_dirty_bitmap_enable_action, }, [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_DISABLE] =3D { .instance_size =3D sizeof(BlockDirtyBitmapState), - .prepare =3D block_dirty_bitmap_disable_prepare, - .abort =3D block_dirty_bitmap_disable_abort, + .action =3D block_dirty_bitmap_disable_action, }, [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_MERGE] =3D { .instance_size =3D sizeof(BlockDirtyBitmapState), - .prepare =3D block_dirty_bitmap_merge_prepare, - .commit =3D block_dirty_bitmap_free_backup, - .abort =3D block_dirty_bitmap_restore, + .action =3D block_dirty_bitmap_merge_action, }, [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_REMOVE] =3D { .instance_size =3D sizeof(BlockDirtyBitmapState), - .prepare =3D block_dirty_bitmap_remove_prepare, - .commit =3D block_dirty_bitmap_remove_commit, - .abort =3D block_dirty_bitmap_remove_abort, + .action =3D block_dirty_bitmap_remove_action, }, /* Where are transactions for MIRROR, COMMIT and STREAM? * Although these blockjobs use transaction callbacks like the backup = job, @@ -2316,14 +2380,11 @@ void qmp_transaction(TransactionActionList *dev_lis= t, TransactionActionList *dev_entry =3D dev_list; bool has_props =3D !!props; JobTxn *block_job_txn =3D NULL; - BlkActionState *state, *next; Error *local_err =3D NULL; + Transaction *tran =3D tran_new(); =20 GLOBAL_STATE_CODE(); =20 - QTAILQ_HEAD(, BlkActionState) snap_bdrv_states; - QTAILQ_INIT(&snap_bdrv_states); - /* Does this transaction get canceled as a group on failure? * If not, we don't really need to make a JobTxn. */ @@ -2339,6 +2400,7 @@ void qmp_transaction(TransactionActionList *dev_list, while (NULL !=3D dev_entry) { TransactionAction *dev_info =3D NULL; const BlkActionOps *ops; + BlkActionState *state; =20 dev_info =3D dev_entry->value; dev_entry =3D dev_entry->next; @@ -2353,38 +2415,23 @@ void qmp_transaction(TransactionActionList *dev_lis= t, state->action =3D dev_info; state->block_job_txn =3D block_job_txn; state->txn_props =3D props; - QTAILQ_INSERT_TAIL(&snap_bdrv_states, state, entry); =20 - state->ops->prepare(state, &local_err); + state->ops->action(state, tran, &local_err); if (local_err) { error_propagate(errp, local_err); goto delete_and_fail; } } =20 - QTAILQ_FOREACH(state, &snap_bdrv_states, entry) { - if (state->ops->commit) { - state->ops->commit(state); - } - } + tran_commit(tran); =20 /* success */ goto exit; =20 delete_and_fail: /* failure, and it is all-or-none; roll back all operations */ - QTAILQ_FOREACH_REVERSE(state, &snap_bdrv_states, entry) { - if (state->ops->abort) { - state->ops->abort(state); - } - } + tran_abort(tran); exit: - QTAILQ_FOREACH_SAFE(state, &snap_bdrv_states, entry, next) { - if (state->ops->clean) { - state->ops->clean(state); - } - g_free(state); - } if (!has_props) { qapi_free_TransactionProperties(props); } --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342398; cv=none; d=zohomail.com; s=zohoarc; b=fx2ZFn+3pGHTngNWRwl3ustxiR78lE4ERn0adNg8tcHkyFefAPl7wIxac0PuqC5/ZhBZP/usSXyzNVblC1rwpZmrYT2EUag8v0491c+wsjAdZqeGfkTxyUasZHMYVLNqXQP5ffumMw0LJMIj3JWX0WjBylQtvbe0N6z2b8qLgWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342398; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rx2tAbxgvTISt6mI/zbELu5EFon9m9vMd7d3sRwfDjM=; b=hIP8vXUSn4DJVswjB31f8ZvuYZIxJ+dgjdheRtLGiZrlrhZf4W0iKTBygBzovWo3B51zLaOgYMeeQ2t1SMIcUVdzZ7x4Pcr2VXjiMT9GzKlpi7F/vaDVi/B7iIg7kmee+v2BzBi3pourJVCoOg1KmHsNAFIhcWuABGFWraHpVmQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342398934476.71949751026943; Wed, 17 May 2023 09:53:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNB-0003w2-2O; Wed, 17 May 2023 12:51:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKN9-0003uW-O4 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKN7-0001OR-NS for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:31 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-112-j_dKzCoMNoODfbH7BoN4eQ-1; Wed, 17 May 2023 12:51:26 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8BF94185A7A4; Wed, 17 May 2023 16:51:25 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id D492D40C6EC4; Wed, 17 May 2023 16:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rx2tAbxgvTISt6mI/zbELu5EFon9m9vMd7d3sRwfDjM=; b=IXxoBXO+LiQ2DjSC1GtY21oT5qBRMIBc+xoXR+4hX5pP6NczizwbkwHDpl3alNT2PbET9p H1Eul2c+pZ7W1dvuDUAPX6JgEQp181QGMKJwpHL3dnnxZd7GSFIjkaOO0DP5I0pIaAMLNo 78iTGn42JYxxgIIwxMgpOaAU4molceQ= X-MC-Unique: j_dKzCoMNoODfbH7BoN4eQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 02/18] blockdev: transactions: rename some things Date: Wed, 17 May 2023 18:51:00 +0200 Message-Id: <20230517165116.475123-3-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342400389100003 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Look at qmp_transaction(): dev_list is not obvious name for list of actions. Let's look at qapi spec, this argument is "actions". Let's follow the common practice of using same argument names in qapi scheme and code. To be honest, rename props to properties for same reason. Next, we have to rename global map of actions, to not conflict with new name for function argument. Rename also dev_entry loop variable accordingly to new name of the list. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Message-Id: <20230510150624.310640-3-vsementsov@yandex-team.ru> Signed-off-by: Kevin Wolf --- blockdev.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3c72d40f51..75e313f403 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2291,7 +2291,7 @@ static void abort_commit(void *opaque) g_assert_not_reached(); /* this action never succeeds */ } =20 -static const BlkActionOps actions[] =3D { +static const BlkActionOps actions_map[] =3D { [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT] =3D { .instance_size =3D sizeof(ExternalSnapshotState), .action =3D external_snapshot_action, @@ -2373,12 +2373,12 @@ static TransactionProperties *get_transaction_prope= rties( * * Always run under BQL. */ -void qmp_transaction(TransactionActionList *dev_list, - struct TransactionProperties *props, +void qmp_transaction(TransactionActionList *actions, + struct TransactionProperties *properties, Error **errp) { - TransactionActionList *dev_entry =3D dev_list; - bool has_props =3D !!props; + TransactionActionList *act =3D actions; + bool has_properties =3D !!properties; JobTxn *block_job_txn =3D NULL; Error *local_err =3D NULL; Transaction *tran =3D tran_new(); @@ -2388,8 +2388,8 @@ void qmp_transaction(TransactionActionList *dev_list, /* Does this transaction get canceled as a group on failure? * If not, we don't really need to make a JobTxn. */ - props =3D get_transaction_properties(props); - if (props->completion_mode !=3D ACTION_COMPLETION_MODE_INDIVIDUAL) { + properties =3D get_transaction_properties(properties); + if (properties->completion_mode !=3D ACTION_COMPLETION_MODE_INDIVIDUAL= ) { block_job_txn =3D job_txn_new(); } =20 @@ -2397,24 +2397,24 @@ void qmp_transaction(TransactionActionList *dev_lis= t, bdrv_drain_all(); =20 /* We don't do anything in this loop that commits us to the operations= */ - while (NULL !=3D dev_entry) { + while (NULL !=3D act) { TransactionAction *dev_info =3D NULL; const BlkActionOps *ops; BlkActionState *state; =20 - dev_info =3D dev_entry->value; - dev_entry =3D dev_entry->next; + dev_info =3D act->value; + act =3D act->next; =20 - assert(dev_info->type < ARRAY_SIZE(actions)); + assert(dev_info->type < ARRAY_SIZE(actions_map)); =20 - ops =3D &actions[dev_info->type]; + ops =3D &actions_map[dev_info->type]; assert(ops->instance_size > 0); =20 state =3D g_malloc0(ops->instance_size); state->ops =3D ops; state->action =3D dev_info; state->block_job_txn =3D block_job_txn; - state->txn_props =3D props; + state->txn_props =3D properties; =20 state->ops->action(state, tran, &local_err); if (local_err) { @@ -2432,8 +2432,8 @@ delete_and_fail: /* failure, and it is all-or-none; roll back all operations */ tran_abort(tran); exit: - if (!has_props) { - qapi_free_TransactionProperties(props); + if (!has_properties) { + qapi_free_TransactionProperties(properties); } job_txn_unref(block_job_txn); } --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342434; cv=none; d=zohomail.com; s=zohoarc; b=KHIMTo3O/9YBQJHv9fD0XGpfKhT3QJD7+g6ExyTjSX8MCq7ZZv2wauSCNKJagGwV0rJa9fs5+xiRcGEQDt50+kZYHR4yv/8nybhEB45kxOnp+vso6QjzQWvxrUTZ7JsVprpbKvn+URJDh7tAmsffDpmJHVPqrHLSsij/if9xYRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342434; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6e1NXSVOx2m7m4NsziCXQ9EHgjqJ3GRk3+Mf5iJu2z0=; b=KJz8S+BwS7kVhcNvOtJLbl6TqTD79oJs3ySyS0eye85RsqgSVoOdYiiTkADmtrXo+WcVwJeuPYC7AcxsaNxfjnd8c4TrDwEi/AVjK6tjgbnnsaAU4pxXIMqtUUdQE848Oo6z7+S/cEYtiEEkiQ0padZsfozYsYWEx00s7mHAKOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342434211137.72833417531922; Wed, 17 May 2023 09:53:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNB-0003w6-Ku; Wed, 17 May 2023 12:51:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNA-0003vM-Fe for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKN9-0001Ol-2a for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:32 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-439-lIc9xJE2OH-bObnAuvZfqg-1; Wed, 17 May 2023 12:51:26 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EB5C1C05AC0; Wed, 17 May 2023 16:51:26 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id C338C40C6EC4; Wed, 17 May 2023 16:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6e1NXSVOx2m7m4NsziCXQ9EHgjqJ3GRk3+Mf5iJu2z0=; b=dXSknIxSXz8kybx8y6hWAc+IOoAcVHZnMPEoSuOWLlk/0+NcVYHKZU+lDbtk5/NTJwjMQF pJWjvlnnB5k+XIHsfhbsoGGtQdpBsx8cSLXZh374pzpAtTQbvTVhyR+1n3DdYR04/yUSeI WurznlRqLBKz+rfTnak0advRfII+u6s= X-MC-Unique: lIc9xJE2OH-bObnAuvZfqg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 03/18] blockdev: qmp_transaction: refactor loop to classic for Date: Wed, 17 May 2023 18:51:01 +0200 Message-Id: <20230517165116.475123-4-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342435386100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Message-Id: <20230510150624.310640-4-vsementsov@yandex-team.ru> Signed-off-by: Kevin Wolf --- blockdev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index 75e313f403..dd0e98bbe1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2377,7 +2377,7 @@ void qmp_transaction(TransactionActionList *actions, struct TransactionProperties *properties, Error **errp) { - TransactionActionList *act =3D actions; + TransactionActionList *act; bool has_properties =3D !!properties; JobTxn *block_job_txn =3D NULL; Error *local_err =3D NULL; @@ -2397,14 +2397,11 @@ void qmp_transaction(TransactionActionList *actions, bdrv_drain_all(); =20 /* We don't do anything in this loop that commits us to the operations= */ - while (NULL !=3D act) { - TransactionAction *dev_info =3D NULL; + for (act =3D actions; act; act =3D act->next) { + TransactionAction *dev_info =3D act->value; const BlkActionOps *ops; BlkActionState *state; =20 - dev_info =3D act->value; - act =3D act->next; - assert(dev_info->type < ARRAY_SIZE(actions_map)); =20 ops =3D &actions_map[dev_info->type]; --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342381; cv=none; d=zohomail.com; s=zohoarc; b=gMJANDg4wLEBR7UIVDGRAyb78mr/9fSbJD6wprpjG4UvkbBmCJ7PT7eYbN4FrN3vcZ8xCRc7NiXry2kzdXbXdrYKooRgJ4fcNPcYFSeUTn+QbFFETjkiKIC7f2ulNIK2oZWm6n4840d6BzD4X9J/nEAT+6WBHGO63bS4VYb7ZCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342381; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1NPelW5IDJXJ2o/9bNIKHzZoOvy+9AbOLEGuqhH/VqI=; b=bFlZisVDWzlSOxtQ/iXPIH5H2bFLrpmffp4Csfr02f9eSDxRYCrQ8sevs4ZUlzldJlioFThIrmZqBQEad9+jSJOkO7gYZh8iQJdROuTmp7X24RbkfCIyIDXRFbqNA1OmT4CwmvliHZmq/3OjckZE0Mf8xPq5IsUMksHa0S5nTD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342381828462.1193360278962; Wed, 17 May 2023 09:53:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNG-0003yA-6b; Wed, 17 May 2023 12:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNE-0003xS-4n for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNB-0001Pj-76 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:35 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-jjvCa4q9MGCGrHpXmpqc-w-1; Wed, 17 May 2023 12:51:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6DD7C3C10221; Wed, 17 May 2023 16:51:27 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5ACE4078908; Wed, 17 May 2023 16:51:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1NPelW5IDJXJ2o/9bNIKHzZoOvy+9AbOLEGuqhH/VqI=; b=Sa3Vj08tj/wg+3VGJ8ZDRsYO/n1hp/4IVIjHYfuoeUPvG9vV3Pm2rOcCA0rp4JoopuP05J Ajb9pcEea2kFcxgLkR1XM0nLK6MfHbAT0ruxHX13IfjoWTmnz3C6M/dXGXvFg+BhI9x6ZG bfJlxxLePwR/XcPtD6hr/xnNOVEaHYc= X-MC-Unique: jjvCa4q9MGCGrHpXmpqc-w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 04/18] blockdev: transaction: refactor handling transaction properties Date: Wed, 17 May 2023 18:51:02 +0200 Message-Id: <20230517165116.475123-5-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342382293100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Only backup supports GROUPED mode. Make this logic more clear. And avoid passing extra thing to each action. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20230510150624.310640-5-vsementsov@yandex-team.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- blockdev.c | 96 +++++++++++++----------------------------------------- 1 file changed, 22 insertions(+), 74 deletions(-) diff --git a/blockdev.c b/blockdev.c index dd0e98bbe1..a2ebaa5afc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1230,7 +1230,6 @@ struct BlkActionState { TransactionAction *action; const BlkActionOps *ops; JobTxn *block_job_txn; - TransactionProperties *txn_props; QTAILQ_ENTRY(BlkActionState) entry; }; =20 @@ -1249,19 +1248,6 @@ TransactionActionDrv internal_snapshot_drv =3D { .clean =3D internal_snapshot_clean, }; =20 -static int action_check_completion_mode(BlkActionState *s, Error **errp) -{ - if (s->txn_props->completion_mode !=3D ACTION_COMPLETION_MODE_INDIVIDU= AL) { - error_setg(errp, - "Action '%s' does not support Transaction property " - "completion-mode =3D %s", - TransactionActionKind_str(s->action->type), - ActionCompletionMode_str(s->txn_props->completion_mode)= ); - return -1; - } - return 0; -} - static void internal_snapshot_action(BlkActionState *common, Transaction *tran, Error **errp) { @@ -1284,15 +1270,9 @@ static void internal_snapshot_action(BlkActionState = *common, =20 tran_add(tran, &internal_snapshot_drv, state); =20 - /* 1. parse input */ device =3D internal->device; name =3D internal->name; =20 - /* 2. check for validation */ - if (action_check_completion_mode(common, errp) < 0) { - return; - } - bs =3D qmp_get_root_bs(device, errp); if (!bs) { return; @@ -1476,9 +1456,6 @@ static void external_snapshot_action(BlkActionState *= common, Transaction *tran, } =20 /* start processing */ - if (action_check_completion_mode(common, errp) < 0) { - return; - } =20 state->old_bs =3D bdrv_lookup_bs(device, node_name, errp); if (!state->old_bs) { @@ -2022,10 +1999,6 @@ static void block_dirty_bitmap_add_action(BlkActionS= tate *common, =20 tran_add(tran, &block_dirty_bitmap_add_drv, state); =20 - if (action_check_completion_mode(common, errp) < 0) { - return; - } - action =3D common->action->u.block_dirty_bitmap_add.data; /* AIO context taken and released within qmp_block_dirty_bitmap_add */ qmp_block_dirty_bitmap_add(action->node, action->name, @@ -2072,10 +2045,6 @@ static void block_dirty_bitmap_clear_action(BlkActio= nState *common, =20 tran_add(tran, &block_dirty_bitmap_clear_drv, state); =20 - if (action_check_completion_mode(common, errp) < 0) { - return; - } - action =3D common->action->u.block_dirty_bitmap_clear.data; state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, @@ -2123,10 +2092,6 @@ static void block_dirty_bitmap_enable_action(BlkActi= onState *common, =20 tran_add(tran, &block_dirty_bitmap_enable_drv, state); =20 - if (action_check_completion_mode(common, errp) < 0) { - return; - } - action =3D common->action->u.block_dirty_bitmap_enable.data; state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, @@ -2168,10 +2133,6 @@ static void block_dirty_bitmap_disable_action(BlkAct= ionState *common, =20 tran_add(tran, &block_dirty_bitmap_disable_drv, state); =20 - if (action_check_completion_mode(common, errp) < 0) { - return; - } - action =3D common->action->u.block_dirty_bitmap_disable.data; state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, @@ -2213,10 +2174,6 @@ static void block_dirty_bitmap_merge_action(BlkActio= nState *common, =20 tran_add(tran, &block_dirty_bitmap_merge_drv, state); =20 - if (action_check_completion_mode(common, errp) < 0) { - return; - } - action =3D common->action->u.block_dirty_bitmap_merge.data; =20 state->bitmap =3D block_dirty_bitmap_merge(action->node, action->targe= t, @@ -2241,10 +2198,6 @@ static void block_dirty_bitmap_remove_action(BlkActi= onState *common, =20 tran_add(tran, &block_dirty_bitmap_remove_drv, state); =20 - if (action_check_completion_mode(common, errp) < 0) { - return; - } - action =3D common->action->u.block_dirty_bitmap_remove.data; =20 state->bitmap =3D block_dirty_bitmap_remove(action->node, action->name, @@ -2348,25 +2301,6 @@ static const BlkActionOps actions_map[] =3D { */ }; =20 -/** - * Allocate a TransactionProperties structure if necessary, and fill - * that structure with desired defaults if they are unset. - */ -static TransactionProperties *get_transaction_properties( - TransactionProperties *props) -{ - if (!props) { - props =3D g_new0(TransactionProperties, 1); - } - - if (!props->has_completion_mode) { - props->has_completion_mode =3D true; - props->completion_mode =3D ACTION_COMPLETION_MODE_INDIVIDUAL; - } - - return props; -} - /* * 'Atomic' group operations. The operations are performed as a set, and = if * any fail then we roll back all operations in the group. @@ -2378,24 +2312,42 @@ void qmp_transaction(TransactionActionList *actions, Error **errp) { TransactionActionList *act; - bool has_properties =3D !!properties; JobTxn *block_job_txn =3D NULL; Error *local_err =3D NULL; - Transaction *tran =3D tran_new(); + Transaction *tran; + ActionCompletionMode comp_mode =3D + properties ? properties->completion_mode : + ACTION_COMPLETION_MODE_INDIVIDUAL; =20 GLOBAL_STATE_CODE(); =20 /* Does this transaction get canceled as a group on failure? * If not, we don't really need to make a JobTxn. */ - properties =3D get_transaction_properties(properties); - if (properties->completion_mode !=3D ACTION_COMPLETION_MODE_INDIVIDUAL= ) { + if (comp_mode !=3D ACTION_COMPLETION_MODE_INDIVIDUAL) { + for (act =3D actions; act; act =3D act->next) { + TransactionActionKind type =3D act->value->type; + + if (type !=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP && + type !=3D TRANSACTION_ACTION_KIND_DRIVE_BACKUP) + { + error_setg(errp, + "Action '%s' does not support transaction prope= rty " + "completion-mode =3D %s", + TransactionActionKind_str(type), + ActionCompletionMode_str(comp_mode)); + return; + } + } + block_job_txn =3D job_txn_new(); } =20 /* drain all i/o before any operations */ bdrv_drain_all(); =20 + tran =3D tran_new(); + /* We don't do anything in this loop that commits us to the operations= */ for (act =3D actions; act; act =3D act->next) { TransactionAction *dev_info =3D act->value; @@ -2411,7 +2363,6 @@ void qmp_transaction(TransactionActionList *actions, state->ops =3D ops; state->action =3D dev_info; state->block_job_txn =3D block_job_txn; - state->txn_props =3D properties; =20 state->ops->action(state, tran, &local_err); if (local_err) { @@ -2429,9 +2380,6 @@ delete_and_fail: /* failure, and it is all-or-none; roll back all operations */ tran_abort(tran); exit: - if (!has_properties) { - qapi_free_TransactionProperties(properties); - } job_txn_unref(block_job_txn); } =20 --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342343; cv=none; d=zohomail.com; s=zohoarc; b=S362kYQHg/zG6Qlj21Rwlg3H2FZk9Trmrif0O0z8dNar2SDLtZUWRUjxHYQsKat3Gt1+CAONZWo1LbJoKlofQIns7vczAF53dNnIFuqhlUP6unBNX5FMspxmjeqC4jTqc38XupANDPj9IlMMcEbmTHpUZL+WTupz6CaMHKJdTHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342343; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rtYEhNwoqKmyFYlOKgNH+j3C8ts0K1Kmcu9S3dJv66Y=; b=F27QanJvvoNHEgGYUFbu+gYadudFWuYEnKj6zwEv+5KzId2Q0zvV5eVr3QPkTFg8U8/yPGf3Aazgvs8+q+tkenAQJItOkiS+5Uz8U96C99FoDZlfrV9NVd271gTAKY1oxXbJJevU2qsffFW4O4CxJRMXDThGb+T+51kxr0ZwfMU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342343606903.7650842305094; Wed, 17 May 2023 09:52:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNF-0003y3-R1; Wed, 17 May 2023 12:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKND-0003wv-S2 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNA-0001PS-RG for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:35 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-65-ipqEFAU7NcCCWS1qWPf6Ow-1; Wed, 17 May 2023 12:51:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EAC938184E4; Wed, 17 May 2023 16:51:28 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4ACD40C6EC4; Wed, 17 May 2023 16:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtYEhNwoqKmyFYlOKgNH+j3C8ts0K1Kmcu9S3dJv66Y=; b=Y3yMA8sKQpSNDINWP0e6OKFBbirXGQF4zXV2yGoLRnjgzQY9Q4Tz1gVBjj+WnSUfShG8UF 6wNdriuxCDfCPsbpzF5hntkd684RRrsG5hg5FzJlqPUAJzX1Nkmbhs1/d8Ip2OcwAy27ct mC2bgAhd4uW0lPErfDKULjkU0oRYeQc= X-MC-Unique: ipqEFAU7NcCCWS1qWPf6Ow-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 05/18] blockdev: use state.bitmap in block-dirty-bitmap-add action Date: Wed, 17 May 2023 18:51:03 +0200 Message-Id: <20230517165116.475123-6-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342345874100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Other bitmap related actions use the .bitmap pointer in .abort action, let's do same here: 1. It helps further refactoring, as bitmap-add is the only bitmap action that uses state.action in .abort 2. It must be safe: transaction actions rely on the fact that on .abort() the state is the same as at the end of .prepare(), so that in .abort() we could precisely rollback the changes done by .prepare(). The only way to remove the bitmap during transaction should be block-dirty-bitmap-remove action, but it postpones actual removal to .commit(), so we are OK on any rollback path. (Note also that bitmap-remove is the only bitmap action that has .commit() phase, except for simple g_free the state on .clean()) 3. Again, other bitmap actions behave this way: keep the bitmap pointer during the transaction. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20230510150624.310640-6-vsementsov@yandex-team.ru> [kwolf: Also remove the now unused BlockDirtyBitmapState.prepared] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- blockdev.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/blockdev.c b/blockdev.c index a2ebaa5afc..4bf15566b2 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1979,7 +1979,6 @@ typedef struct BlockDirtyBitmapState { BdrvDirtyBitmap *bitmap; BlockDriverState *bs; HBitmap *backup; - bool prepared; bool was_enabled; } BlockDirtyBitmapState; =20 @@ -2008,7 +2007,8 @@ static void block_dirty_bitmap_add_action(BlkActionSt= ate *common, &local_err); =20 if (!local_err) { - state->prepared =3D true; + state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->= name, + NULL, &error_abort); } else { error_propagate(errp, local_err); } @@ -2016,15 +2016,10 @@ static void block_dirty_bitmap_add_action(BlkAction= State *common, =20 static void block_dirty_bitmap_add_abort(void *opaque) { - BlockDirtyBitmapAdd *action; BlockDirtyBitmapState *state =3D opaque; =20 - action =3D state->common.action->u.block_dirty_bitmap_add.data; - /* Should not be able to fail: IF the bitmap was added via .prepare(), - * then the node reference and bitmap name must have been valid. - */ - if (state->prepared) { - qmp_block_dirty_bitmap_remove(action->node, action->name, &error_a= bort); + if (state->bitmap) { + bdrv_release_dirty_bitmap(state->bitmap); } } =20 --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342375; cv=none; d=zohomail.com; s=zohoarc; b=XU1v8C11Hsm4RM5bnC1KhLkDqkKEfbrfe0RkAf0GY0fw1heghLekro7F6dTOBjiyZSKxrlUMGgdZWVzcfU4eVdLCMJrB8HeBdxSOHBJLkv3qD+J2N91R5+vKTZ4OOFzUVyZQ5rW9gAnEnYW8o2dNvyZS4UlXRjEjpE72LvfmFeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342375; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qhMv5NzwHttqaQUeeSf8xX8q9cynsPcI2TdbA7/N4p8=; b=H843BxDz+PkbwSXFTSofHC8Y2X4H7yqBYlkhlOz/Y3TqgVveQSi/7O90t3n4uFRlIqu8ujZfnobLpjCRe1N/2BOarDMx3/RtDxwEy0Y5zGOKpVg6fpyxOaY4ZXOfuGPSqsHhW5lV0necUNo35fjjX0s2L7y5o6JRQSpwVlMbX5E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342375814532.9838966826403; Wed, 17 May 2023 09:52:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNJ-00041a-84; Wed, 17 May 2023 12:51:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNH-0003zT-8F for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNC-0001Q5-JC for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-68-Lccu88P6OdKH-FeQHdvKeA-1; Wed, 17 May 2023 12:51:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 694F2185A790; Wed, 17 May 2023 16:51:29 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95EC740C6EC4; Wed, 17 May 2023 16:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qhMv5NzwHttqaQUeeSf8xX8q9cynsPcI2TdbA7/N4p8=; b=M6TzDdebhGdF1CR4LZ2VIBHP7euLUaKuWk+KNbNJtUEggXme+yebXnoXrGEStRDrVcXspu 6rFm32R38mJd8P/WmYKPV59zWqFs++EjDg8F186gzED3VL31ET2blJc5jvcQqH+ARQ0pbI wx350cGzii0ed/9scUEkitpJDeLs6wg= X-MC-Unique: Lccu88P6OdKH-FeQHdvKeA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 06/18] blockdev: qmp_transaction: drop extra generic layer Date: Wed, 17 May 2023 18:51:04 +0200 Message-Id: <20230517165116.475123-7-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342376123100002 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Let's simplify things: First, actions generally don't need access to common BlkActionState structure. The only exclusion are backup actions that need block_job_txn. Next, for transaction actions of Transaction API is more native to allocated state structure in the action itself. So, do the following transformation: 1. Let all actions be represented by a function with corresponding structure as arguments. 2. Instead of array-map marshaller, let's make a function, that calls corresponding action directly. 3. BlkActionOps and BlkActionState structures become unused Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20230510150624.310640-7-vsementsov@yandex-team.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- blockdev.c | 265 +++++++++++++++++------------------------------------ 1 file changed, 85 insertions(+), 180 deletions(-) diff --git a/blockdev.c b/blockdev.c index 4bf15566b2..5d56b79df4 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1188,54 +1188,8 @@ out_aio_context: return NULL; } =20 -/* New and old BlockDriverState structs for atomic group operations */ - -typedef struct BlkActionState BlkActionState; - -/** - * BlkActionOps: - * Table of operations that define an Action. - * - * @instance_size: Size of state struct, in bytes. - * @prepare: Prepare the work, must NOT be NULL. - * @commit: Commit the changes, can be NULL. - * @abort: Abort the changes on fail, can be NULL. - * @clean: Clean up resources after all transaction actions have called - * commit() or abort(). Can be NULL. - * - * Only prepare() may fail. In a single transaction, only one of commit() = or - * abort() will be called. clean() will always be called if it is present. - * - * Always run under BQL. - */ -typedef struct BlkActionOps { - size_t instance_size; - void (*action)(BlkActionState *common, Transaction *tran, Error **errp= ); -} BlkActionOps; - -/** - * BlkActionState: - * Describes one Action's state within a Transaction. - * - * @action: QAPI-defined enum identifying which Action to perform. - * @ops: Table of ActionOps this Action can perform. - * @block_job_txn: Transaction which this action belongs to. - * @entry: List membership for all Actions in this Transaction. - * - * This structure must be arranged as first member in a subclassed type, - * assuming that the compiler will also arrange it to the same offsets as = the - * base class. - */ -struct BlkActionState { - TransactionAction *action; - const BlkActionOps *ops; - JobTxn *block_job_txn; - QTAILQ_ENTRY(BlkActionState) entry; -}; - /* internal snapshot private data */ typedef struct InternalSnapshotState { - BlkActionState common; BlockDriverState *bs; QEMUSnapshotInfo sn; bool created; @@ -1248,7 +1202,7 @@ TransactionActionDrv internal_snapshot_drv =3D { .clean =3D internal_snapshot_clean, }; =20 -static void internal_snapshot_action(BlkActionState *common, +static void internal_snapshot_action(BlockdevSnapshotInternal *internal, Transaction *tran, Error **errp) { Error *local_err =3D NULL; @@ -1258,16 +1212,10 @@ static void internal_snapshot_action(BlkActionState= *common, QEMUSnapshotInfo old_sn, *sn; bool ret; int64_t rt; - BlockdevSnapshotInternal *internal; - InternalSnapshotState *state; + InternalSnapshotState *state =3D g_new0(InternalSnapshotState, 1); AioContext *aio_context; int ret1; =20 - g_assert(common->action->type =3D=3D - TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC); - internal =3D common->action->u.blockdev_snapshot_internal_sync.data; - state =3D DO_UPCAST(InternalSnapshotState, common, common); - tran_add(tran, &internal_snapshot_drv, state); =20 device =3D internal->device; @@ -1393,7 +1341,6 @@ static void internal_snapshot_clean(void *opaque) =20 /* external snapshot private data */ typedef struct ExternalSnapshotState { - BlkActionState common; BlockDriverState *old_bs; BlockDriverState *new_bs; bool overlay_appended; @@ -1408,8 +1355,8 @@ TransactionActionDrv external_snapshot_drv =3D { .clean =3D external_snapshot_clean, }; =20 -static void external_snapshot_action(BlkActionState *common, Transaction *= tran, - Error **errp) +static void external_snapshot_action(TransactionAction *action, + Transaction *tran, Error **errp) { int ret; int flags =3D 0; @@ -1422,9 +1369,7 @@ static void external_snapshot_action(BlkActionState *= common, Transaction *tran, const char *snapshot_ref; /* File name of the new image (for 'blockdev-snapshot-sync') */ const char *new_image_file; - ExternalSnapshotState *state =3D - DO_UPCAST(ExternalSnapshotState, common, comm= on); - TransactionAction *action =3D common->action; + ExternalSnapshotState *state =3D g_new0(ExternalSnapshotState, 1); AioContext *aio_context; uint64_t perm, shared; =20 @@ -1658,7 +1603,6 @@ static void external_snapshot_clean(void *opaque) } =20 typedef struct DriveBackupState { - BlkActionState common; BlockDriverState *bs; BlockJob *job; } DriveBackupState; @@ -1678,11 +1622,11 @@ TransactionActionDrv drive_backup_drv =3D { .clean =3D drive_backup_clean, }; =20 -static void drive_backup_action(BlkActionState *common, Transaction *tran, - Error **errp) +static void drive_backup_action(DriveBackup *backup, + JobTxn *block_job_txn, + Transaction *tran, Error **errp) { - DriveBackupState *state =3D DO_UPCAST(DriveBackupState, common, common= ); - DriveBackup *backup; + DriveBackupState *state =3D g_new0(DriveBackupState, 1); BlockDriverState *bs; BlockDriverState *target_bs; BlockDriverState *source =3D NULL; @@ -1698,9 +1642,6 @@ static void drive_backup_action(BlkActionState *commo= n, Transaction *tran, =20 tran_add(tran, &drive_backup_drv, state); =20 - assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_DRIVE_BACKU= P); - backup =3D common->action->u.drive_backup.data; - if (!backup->has_mode) { backup->mode =3D NEW_IMAGE_MODE_ABSOLUTE_PATHS; } @@ -1820,7 +1761,7 @@ static void drive_backup_action(BlkActionState *commo= n, Transaction *tran, =20 state->job =3D do_backup_common(qapi_DriveBackup_base(backup), bs, target_bs, aio_context, - common->block_job_txn, errp); + block_job_txn, errp); =20 unref: bdrv_unref(target_bs); @@ -1869,7 +1810,6 @@ static void drive_backup_clean(void *opaque) } =20 typedef struct BlockdevBackupState { - BlkActionState common; BlockDriverState *bs; BlockJob *job; } BlockdevBackupState; @@ -1883,11 +1823,11 @@ TransactionActionDrv blockdev_backup_drv =3D { .clean =3D blockdev_backup_clean, }; =20 -static void blockdev_backup_action(BlkActionState *common, Transaction *tr= an, - Error **errp) +static void blockdev_backup_action(BlockdevBackup *backup, + JobTxn *block_job_txn, + Transaction *tran, Error **errp) { - BlockdevBackupState *state =3D DO_UPCAST(BlockdevBackupState, common, = common); - BlockdevBackup *backup; + BlockdevBackupState *state =3D g_new0(BlockdevBackupState, 1); BlockDriverState *bs; BlockDriverState *target_bs; AioContext *aio_context; @@ -1896,9 +1836,6 @@ static void blockdev_backup_action(BlkActionState *co= mmon, Transaction *tran, =20 tran_add(tran, &blockdev_backup_drv, state); =20 - assert(common->action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_BA= CKUP); - backup =3D common->action->u.blockdev_backup.data; - bs =3D bdrv_lookup_bs(backup->device, backup->device, errp); if (!bs) { return; @@ -1929,7 +1866,7 @@ static void blockdev_backup_action(BlkActionState *co= mmon, Transaction *tran, =20 state->job =3D do_backup_common(qapi_BlockdevBackup_base(backup), bs, target_bs, aio_context, - common->block_job_txn, errp); + block_job_txn, errp); =20 aio_context_release(aio_context); } @@ -1975,7 +1912,6 @@ static void blockdev_backup_clean(void *opaque) } =20 typedef struct BlockDirtyBitmapState { - BlkActionState common; BdrvDirtyBitmap *bitmap; BlockDriverState *bs; HBitmap *backup; @@ -1988,17 +1924,14 @@ TransactionActionDrv block_dirty_bitmap_add_drv =3D= { .clean =3D g_free, }; =20 -static void block_dirty_bitmap_add_action(BlkActionState *common, +static void block_dirty_bitmap_add_action(BlockDirtyBitmapAdd *action, Transaction *tran, Error **errp) { Error *local_err =3D NULL; - BlockDirtyBitmapAdd *action; - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D g_new0(BlockDirtyBitmapState, 1); =20 tran_add(tran, &block_dirty_bitmap_add_drv, state); =20 - action =3D common->action->u.block_dirty_bitmap_add.data; /* AIO context taken and released within qmp_block_dirty_bitmap_add */ qmp_block_dirty_bitmap_add(action->node, action->name, action->has_granularity, action->granularit= y, @@ -2031,16 +1964,13 @@ TransactionActionDrv block_dirty_bitmap_clear_drv = =3D { .clean =3D g_free, }; =20 -static void block_dirty_bitmap_clear_action(BlkActionState *common, +static void block_dirty_bitmap_clear_action(BlockDirtyBitmap *action, Transaction *tran, Error **err= p) { - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); - BlockDirtyBitmap *action; + BlockDirtyBitmapState *state =3D g_new0(BlockDirtyBitmapState, 1); =20 tran_add(tran, &block_dirty_bitmap_clear_drv, state); =20 - action =3D common->action->u.block_dirty_bitmap_clear.data; state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, &state->bs, @@ -2078,16 +2008,13 @@ TransactionActionDrv block_dirty_bitmap_enable_drv = =3D { .clean =3D g_free, }; =20 -static void block_dirty_bitmap_enable_action(BlkActionState *common, +static void block_dirty_bitmap_enable_action(BlockDirtyBitmap *action, Transaction *tran, Error **er= rp) { - BlockDirtyBitmap *action; - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D g_new0(BlockDirtyBitmapState, 1); =20 tran_add(tran, &block_dirty_bitmap_enable_drv, state); =20 - action =3D common->action->u.block_dirty_bitmap_enable.data; state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, NULL, @@ -2119,16 +2046,13 @@ TransactionActionDrv block_dirty_bitmap_disable_drv= =3D { .clean =3D g_free, }; =20 -static void block_dirty_bitmap_disable_action(BlkActionState *common, +static void block_dirty_bitmap_disable_action(BlockDirtyBitmap *action, Transaction *tran, Error **e= rrp) { - BlockDirtyBitmap *action; - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D g_new0(BlockDirtyBitmapState, 1); =20 tran_add(tran, &block_dirty_bitmap_disable_drv, state); =20 - action =3D common->action->u.block_dirty_bitmap_disable.data; state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, NULL, @@ -2160,17 +2084,13 @@ TransactionActionDrv block_dirty_bitmap_merge_drv = =3D { .clean =3D g_free, }; =20 -static void block_dirty_bitmap_merge_action(BlkActionState *common, +static void block_dirty_bitmap_merge_action(BlockDirtyBitmapMerge *action, Transaction *tran, Error **err= p) { - BlockDirtyBitmapMerge *action; - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D g_new0(BlockDirtyBitmapState, 1); =20 tran_add(tran, &block_dirty_bitmap_merge_drv, state); =20 - action =3D common->action->u.block_dirty_bitmap_merge.data; - state->bitmap =3D block_dirty_bitmap_merge(action->node, action->targe= t, action->bitmaps, &state->back= up, errp); @@ -2184,16 +2104,13 @@ TransactionActionDrv block_dirty_bitmap_remove_drv = =3D { .clean =3D g_free, }; =20 -static void block_dirty_bitmap_remove_action(BlkActionState *common, +static void block_dirty_bitmap_remove_action(BlockDirtyBitmap *action, Transaction *tran, Error **er= rp) { - BlockDirtyBitmap *action; - BlockDirtyBitmapState *state =3D DO_UPCAST(BlockDirtyBitmapState, - common, common); + BlockDirtyBitmapState *state =3D g_new0(BlockDirtyBitmapState, 1); =20 tran_add(tran, &block_dirty_bitmap_remove_drv, state); =20 - action =3D common->action->u.block_dirty_bitmap_remove.data; =20 state->bitmap =3D block_dirty_bitmap_remove(action->node, action->name, false, &state->bs, errp); @@ -2224,13 +2141,11 @@ static void block_dirty_bitmap_remove_commit(void *= opaque) static void abort_commit(void *opaque); TransactionActionDrv abort_drv =3D { .commit =3D abort_commit, - .clean =3D g_free, }; =20 -static void abort_action(BlkActionState *common, Transaction *tran, - Error **errp) +static void abort_action(Transaction *tran, Error **errp) { - tran_add(tran, &abort_drv, common); + tran_add(tran, &abort_drv, NULL); error_setg(errp, "Transaction aborted using Abort action"); } =20 @@ -2239,62 +2154,66 @@ static void abort_commit(void *opaque) g_assert_not_reached(); /* this action never succeeds */ } =20 -static const BlkActionOps actions_map[] =3D { - [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT] =3D { - .instance_size =3D sizeof(ExternalSnapshotState), - .action =3D external_snapshot_action, - }, - [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] =3D { - .instance_size =3D sizeof(ExternalSnapshotState), - .action =3D external_snapshot_action, - }, - [TRANSACTION_ACTION_KIND_DRIVE_BACKUP] =3D { - .instance_size =3D sizeof(DriveBackupState), - .action =3D drive_backup_action, - }, - [TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP] =3D { - .instance_size =3D sizeof(BlockdevBackupState), - .action =3D blockdev_backup_action, - }, - [TRANSACTION_ACTION_KIND_ABORT] =3D { - .instance_size =3D sizeof(BlkActionState), - .action =3D abort_action, - }, - [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC] =3D { - .instance_size =3D sizeof(InternalSnapshotState), - .action =3D internal_snapshot_action, - }, - [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_ADD] =3D { - .instance_size =3D sizeof(BlockDirtyBitmapState), - .action =3D block_dirty_bitmap_add_action, - }, - [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_CLEAR] =3D { - .instance_size =3D sizeof(BlockDirtyBitmapState), - .action =3D block_dirty_bitmap_clear_action, - }, - [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_ENABLE] =3D { - .instance_size =3D sizeof(BlockDirtyBitmapState), - .action =3D block_dirty_bitmap_enable_action, - }, - [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_DISABLE] =3D { - .instance_size =3D sizeof(BlockDirtyBitmapState), - .action =3D block_dirty_bitmap_disable_action, - }, - [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_MERGE] =3D { - .instance_size =3D sizeof(BlockDirtyBitmapState), - .action =3D block_dirty_bitmap_merge_action, - }, - [TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_REMOVE] =3D { - .instance_size =3D sizeof(BlockDirtyBitmapState), - .action =3D block_dirty_bitmap_remove_action, - }, - /* Where are transactions for MIRROR, COMMIT and STREAM? +static void transaction_action(TransactionAction *act, JobTxn *block_job_t= xn, + Transaction *tran, Error **errp) +{ + switch (act->type) { + case TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT: + case TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC: + external_snapshot_action(act, tran, errp); + return; + case TRANSACTION_ACTION_KIND_DRIVE_BACKUP: + drive_backup_action(act->u.drive_backup.data, + block_job_txn, tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP: + blockdev_backup_action(act->u.blockdev_backup.data, + block_job_txn, tran, errp); + return; + case TRANSACTION_ACTION_KIND_ABORT: + abort_action(tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC: + internal_snapshot_action(act->u.blockdev_snapshot_internal_sync.da= ta, + tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_ADD: + block_dirty_bitmap_add_action(act->u.block_dirty_bitmap_add.data, + tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_CLEAR: + block_dirty_bitmap_clear_action(act->u.block_dirty_bitmap_clear.da= ta, + tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_ENABLE: + block_dirty_bitmap_enable_action(act->u.block_dirty_bitmap_enable.= data, + tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_DISABLE: + block_dirty_bitmap_disable_action( + act->u.block_dirty_bitmap_disable.data, tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_MERGE: + block_dirty_bitmap_merge_action(act->u.block_dirty_bitmap_merge.da= ta, + tran, errp); + return; + case TRANSACTION_ACTION_KIND_BLOCK_DIRTY_BITMAP_REMOVE: + block_dirty_bitmap_remove_action(act->u.block_dirty_bitmap_remove.= data, + tran, errp); + return; + /* + * Where are transactions for MIRROR, COMMIT and STREAM? * Although these blockjobs use transaction callbacks like the backup = job, * these jobs do not necessarily adhere to transaction semantics. * These jobs may not fully undo all of their actions on abort, nor do= they * necessarily work in transactions with more than one job in them. */ -}; + case TRANSACTION_ACTION_KIND__MAX: + default: + g_assert_not_reached(); + }; +} + =20 /* * 'Atomic' group operations. The operations are performed as a set, and = if @@ -2345,21 +2264,7 @@ void qmp_transaction(TransactionActionList *actions, =20 /* We don't do anything in this loop that commits us to the operations= */ for (act =3D actions; act; act =3D act->next) { - TransactionAction *dev_info =3D act->value; - const BlkActionOps *ops; - BlkActionState *state; - - assert(dev_info->type < ARRAY_SIZE(actions_map)); - - ops =3D &actions_map[dev_info->type]; - assert(ops->instance_size > 0); - - state =3D g_malloc0(ops->instance_size); - state->ops =3D ops; - state->action =3D dev_info; - state->block_job_txn =3D block_job_txn; - - state->ops->action(state, tran, &local_err); + transaction_action(act->value, block_job_txn, tran, &local_err); if (local_err) { error_propagate(errp, local_err); goto delete_and_fail; --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342439; cv=none; d=zohomail.com; s=zohoarc; b=F2b4N8EP09s/ZU7RXcqhVAf+0FLoDc7U6jtw26CBrB0fH1ofjq5kJIWYxht5SWLljgyRcN+HeSMm6RPwZP8W5/XkMvhSY1pyYA0IepeF/ORlJ8Tk9W6ZAxGqau80hHnFcOQMPPKIFuTVIjgtzvk7SID9pL+2NKNvIcnl8XCf+zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342439; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zstI19rKVNa+kdrsTIs7vlvr1F7iq82cM+TZD7FBpS8=; b=m5QF+AHHImSNjSq1cqmoYDKS6AaJcUnz3iSPjJO9P+KhUYIv/HCkw/CXdlZln62yJv0tvfm6XheJDRjeMEZKs4Z6vnAOTDOHoMX+xhkzYrXMWs27+fOdyJh25as1lCFPEAUZPVukPAxiWxbGhRemogjhwY4YCwnb1CbLmYSU+9E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342439420644.1516881954092; Wed, 17 May 2023 09:53:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKND-0003wt-8Y; Wed, 17 May 2023 12:51:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNC-0003we-CF for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNA-0001PO-P0 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:34 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-458-3iiP3wSYMvi2nMagyPFIJA-1; Wed, 17 May 2023 12:51:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 57AF529AB3EC; Wed, 17 May 2023 16:51:30 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id A054940C6EC4; Wed, 17 May 2023 16:51:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zstI19rKVNa+kdrsTIs7vlvr1F7iq82cM+TZD7FBpS8=; b=BeLH7y8LoceW1UsWJvhHfdLTb4yHsfis26UI1j79vXVX859pwAX3exlj806MZV3H9+LV+Q YxGjBmaKv3t5RPfyOlOrJAqELUvjMehiszboVgfhf8XSEuP4HZdM86VU5vtJlmm4719mZi j2+XSceEXsdnQ5jC1TPiozTEHgfmt5U= X-MC-Unique: 3iiP3wSYMvi2nMagyPFIJA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 07/18] docs/interop/qcow2.txt: fix description about "zlib" clusters Date: Wed, 17 May 2023 18:51:05 +0200 Message-Id: <20230517165116.475123-8-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342441303100007 Content-Type: text/plain; charset="utf-8" From: Akihiro Suda "zlib" clusters are actually raw deflate (RFC1951) clusters without zlib headers. Signed-off-by: Akihiro Suda Message-Id: <168424874322.11954.1340942046351859521-0@git.sr.ht> Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- docs/interop/qcow2.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index f7dc304ff6..e7f036c286 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -214,14 +214,18 @@ version 2. type. =20 If the incompatible bit "Compression type" is set: the= field - must be present and non-zero (which means non-zlib + must be present and non-zero (which means non-deflate compression type). Otherwise, this field must not be p= resent - or must be zero (which means zlib). + or must be zero (which means deflate). =20 Available compression type values: - 0: zlib + 0: deflate 1: zstd =20 + The deflate compression type is called "zlib" + in QEMU. However, clusters wit= h the + deflate compression type do not have zlib headers. + =20 =3D=3D=3D Header padding =3D=3D=3D =20 --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342418; cv=none; d=zohomail.com; s=zohoarc; b=SflH4puSZuBfH1NXTgMgQZziq4rbT2Kd06o0PFXEOwloGLag1kDUA2Xf2IW8d4ppsbZp/04B7CemyawLZkkqyef5taZdxn5u1WcHMFwPwPKdOT4fLG06RsMy1AHSB8WIUQfgn8nUzaBojN35+eOuF4eravtwWZi2jXRG9329eaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342418; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=j89rRWHLEF5CD6pklWntVXwdDuYUd1+NGlsXOv3pBNA=; b=keVmjsq6IXjtCff88ptZkfhRjqR64K2ihhu96TMawTL0r7ceI/t0nmCXd3GslNWvV3gYW50a+Xo+Oqx3RjmpDMh3tGiGxaIfDkNej4ImRFEUOp5k17IRk2TNKwzbYSCzzZ3WJh/hvqadSoyJCbZ6kwGFP6TIIOLGKG+SaCL/uJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342418541419.706168620221; Wed, 17 May 2023 09:53:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNI-00040O-Ai; Wed, 17 May 2023 12:51:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNG-0003yc-EQ for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKND-0001QU-BT for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:37 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-294-Vt8hDlv6NNar8RPvx3K6sA-1; Wed, 17 May 2023 12:51:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4723B85A5B1; Wed, 17 May 2023 16:51:31 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EDFE40C6EC4; Wed, 17 May 2023 16:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j89rRWHLEF5CD6pklWntVXwdDuYUd1+NGlsXOv3pBNA=; b=RHK2lES4mIFuw9/70JZ0TwHLdgJQWYzrP7R7jq3wFnloiz71kbJ0pzit4nKutwLjx+veX9 /wyZZIkTHtLOk6bxOQC98U+2UIFe+ctgrdydzXxNkWZ1TdfgfOEW2BsdovM85RSg3MOGrr b+jeFV89t8wFhzN3u+KmruCSSBHBfZ0= X-MC-Unique: Vt8hDlv6NNar8RPvx3K6sA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 08/18] block: Call .bdrv_co_create(_opts) unlocked Date: Wed, 17 May 2023 18:51:06 +0200 Message-Id: <20230517165116.475123-9-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342419321100002 Content-Type: text/plain; charset="utf-8" These are functions that modify the graph, so they must be able to take a writer lock. This is impossible if they already hold the reader lock. If they need a reader lock for some of their operations, they should take it internally. Many of them go through blk_*(), which will always take the lock itself. Direct calls of bdrv_*() need to take the reader lock. Note that while locking for bdrv_co_*() calls is checked by TSA, this is not the case for the mixed_coroutine_fns bdrv_*(). Holding the lock is still required when they are called from coroutine context like here! This effectively reverts 4ec8df0183, but adds some internal locking instead. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-2-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 8 +++---- include/block/block_int-common.h | 4 ++-- block.c | 1 - block/create.c | 1 - block/crypto.c | 25 ++++++++++---------- block/parallels.c | 6 ++--- block/qcow.c | 6 ++--- block/qcow2.c | 37 +++++++++++++++++++----------- block/qed.c | 6 ++--- block/raw-format.c | 2 +- block/vdi.c | 11 +++++---- block/vhdx.c | 8 ++++--- block/vmdk.c | 27 ++++++++++------------ block/vpc.c | 6 ++--- 14 files changed, 78 insertions(+), 70 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 2d93423d35..f347199bff 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -58,14 +58,14 @@ BlockDriver *bdrv_find_protocol(const char *filename, Error **errp); BlockDriver *bdrv_find_format(const char *format_name); =20 -int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_UNLOCKED bdrv_co_create(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp); =20 -int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filen= ame, - QemuOpts *opts, Error **errp); +int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp); =20 -int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_UNLOCKED bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp); =20 BlockDriverState *bdrv_new(void); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index dbec0e3bb4..6492a1e538 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -250,10 +250,10 @@ struct BlockDriver { BlockDriverState *bs, QDict *options, int flags, Error **errp); void (*bdrv_close)(BlockDriverState *bs); =20 - int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)( + int coroutine_fn GRAPH_UNLOCKED_PTR (*bdrv_co_create)( BlockdevCreateOptions *opts, Error **errp); =20 - int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)( + int coroutine_fn GRAPH_UNLOCKED_PTR (*bdrv_co_create_opts)( BlockDriver *drv, const char *filename, QemuOpts *opts, Error **er= rp); =20 int (*bdrv_amend_options)(BlockDriverState *bs, diff --git a/block.c b/block.c index f04a6ad4e8..a2f8d5a0c0 100644 --- a/block.c +++ b/block.c @@ -533,7 +533,6 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const= char *filename, int ret; GLOBAL_STATE_CODE(); ERRP_GUARD(); - assert_bdrv_graph_readable(); =20 if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation", diff --git a/block/create.c b/block/create.c index bf67b9947c..6b23a21675 100644 --- a/block/create.c +++ b/block/create.c @@ -43,7 +43,6 @@ static int coroutine_fn blockdev_create_run(Job *job, Err= or **errp) int ret; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD(); =20 job_progress_set_remaining(&s->common, 1); ret =3D s->drv->bdrv_co_create(s->opts, errp); diff --git a/block/crypto.c b/block/crypto.c index 30093cff9b..6ee8d46d30 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -99,12 +99,10 @@ struct BlockCryptoCreateData { }; =20 =20 -static int block_crypto_create_write_func(QCryptoBlock *block, - size_t offset, - const uint8_t *buf, - size_t buflen, - void *opaque, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +block_crypto_create_write_func(QCryptoBlock *block, size_t offset, + const uint8_t *buf, size_t buflen, void *op= aque, + Error **errp) { struct BlockCryptoCreateData *data =3D opaque; ssize_t ret; @@ -117,10 +115,9 @@ static int block_crypto_create_write_func(QCryptoBlock= *block, return 0; } =20 -static int block_crypto_create_init_func(QCryptoBlock *block, - size_t headerlen, - void *opaque, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +block_crypto_create_init_func(QCryptoBlock *block, size_t headerlen, + void *opaque, Error **errp) { struct BlockCryptoCreateData *data =3D opaque; Error *local_error =3D NULL; @@ -314,7 +311,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, } =20 =20 -static int coroutine_fn +static int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_generic(BlockDriverState *bs, int64_t size, QCryptoBlockCreateOptions *opts, PreallocMode prealloc, Error **errp) @@ -627,7 +624,7 @@ static int block_crypto_open_luks(BlockDriverState *bs, bs, options, flags, errp); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error *= *errp) { BlockdevCreateOptionsLUKS *luks_opts; @@ -665,7 +662,7 @@ fail: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { @@ -727,7 +724,9 @@ fail: * beforehand, it has been truncated and corrupted in the process. */ if (ret) { + bdrv_graph_co_rdlock(); bdrv_co_delete_file_noerr(bs); + bdrv_graph_co_rdunlock(); } =20 bdrv_co_unref(bs); diff --git a/block/parallels.c b/block/parallels.c index b49c35929e..d8a3f13e24 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -522,8 +522,8 @@ out: } =20 =20 -static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +parallels_co_create(BlockdevCreateOptions* opts, Error **errp) { BlockdevCreateOptionsParallels *parallels_opts; BlockDriverState *bs; @@ -622,7 +622,7 @@ exit: goto out; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED parallels_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/qcow.c b/block/qcow.c index a0c701f578..3644bbf5cb 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -800,8 +800,8 @@ static void qcow_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 -static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +qcow_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsQcow *qcow_opts; int header_size, backing_filename_len, l1_size, shift, i; @@ -921,7 +921,7 @@ exit: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED qcow_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/qcow2.c b/block/qcow2.c index 5bde3b8401..73f36447f9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -118,8 +118,9 @@ static int qcow2_crypto_hdr_read_func(QCryptoBlock *blo= ck, size_t offset, } =20 =20 -static int qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerle= n, - void *opaque, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen, void *op= aque, + Error **errp) { BlockDriverState *bs =3D opaque; BDRVQcow2State *s =3D bs->opaque; @@ -144,9 +145,7 @@ static int qcow2_crypto_hdr_init_func(QCryptoBlock *blo= ck, size_t headerlen, */ clusterlen =3D size_to_clusters(s, headerlen) * s->cluster_size; assert(qcow2_pre_write_overlap_check(bs, 0, ret, clusterlen, false) = =3D=3D 0); - ret =3D bdrv_pwrite_zeroes(bs->file, - ret, - clusterlen, 0); + ret =3D bdrv_co_pwrite_zeroes(bs->file, ret, clusterlen, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Could not zero fill encryption heade= r"); return -1; @@ -156,9 +155,11 @@ static int qcow2_crypto_hdr_init_func(QCryptoBlock *bl= ock, size_t headerlen, } =20 =20 -static int qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, - const uint8_t *buf, size_t buflen, - void *opaque, Error **errp) +/* The graph lock must be held when called in coroutine context */ +static int coroutine_mixed_fn +qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, + const uint8_t *buf, size_t buflen, + void *opaque, Error **errp) { BlockDriverState *bs =3D opaque; BDRVQcow2State *s =3D bs->opaque; @@ -3137,9 +3138,10 @@ static int qcow2_change_backing_file(BlockDriverStat= e *bs, return qcow2_update_header(bs); } =20 -static int qcow2_set_up_encryption(BlockDriverState *bs, - QCryptoBlockCreateOptions *cryptoopts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_set_up_encryption(BlockDriverState *bs, + QCryptoBlockCreateOptions *cryptoopts, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; QCryptoBlock *crypto =3D NULL; @@ -3426,7 +3428,7 @@ static uint64_t qcow2_opt_get_refcount_bits_del(QemuO= pts *opts, int version, return refcount_bits; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_UNLOCKED qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) { BlockdevCreateOptionsQcow2 *qcow2_opts; @@ -3724,8 +3726,10 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) goto out; } =20 + bdrv_graph_co_rdlock(); ret =3D qcow2_alloc_clusters(blk_bs(blk), 3 * cluster_size); if (ret < 0) { + bdrv_graph_co_rdunlock(); error_setg_errno(errp, -ret, "Could not allocate clusters for qcow= 2 " "header and refcount table"); goto out; @@ -3743,6 +3747,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) =20 /* Create a full header (including things like feature table) */ ret =3D qcow2_update_header(blk_bs(blk)); + bdrv_graph_co_rdunlock(); + if (ret < 0) { error_setg_errno(errp, -ret, "Could not update qcow2 header"); goto out; @@ -3776,7 +3782,10 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) =20 /* Want encryption? There you go. */ if (qcow2_opts->encrypt) { + bdrv_graph_co_rdlock(); ret =3D qcow2_set_up_encryption(blk_bs(blk), qcow2_opts->encrypt, = errp); + bdrv_graph_co_rdunlock(); + if (ret < 0) { goto out; } @@ -3813,7 +3822,7 @@ out: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opt= s, Error **errp) { @@ -3933,8 +3942,10 @@ qcow2_co_create_opts(BlockDriver *drv, const char *f= ilename, QemuOpts *opts, ret =3D qcow2_co_create(create_options, errp); finish: if (ret < 0) { + bdrv_graph_co_rdlock(); bdrv_co_delete_file_noerr(bs); bdrv_co_delete_file_noerr(data_bs); + bdrv_graph_co_rdunlock(); } else { ret =3D 0; } diff --git a/block/qed.c b/block/qed.c index be9ff0fb34..9a0350b534 100644 --- a/block/qed.c +++ b/block/qed.c @@ -630,8 +630,8 @@ static void bdrv_qed_close(BlockDriverState *bs) qemu_vfree(s->l1_table); } =20 -static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +bdrv_qed_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsQed *qed_opts; BlockBackend *blk =3D NULL; @@ -751,7 +751,7 @@ out: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/raw-format.c b/block/raw-format.c index 3a3946213f..918fe4fb7e 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -457,7 +457,7 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs->file->bs); } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED raw_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/vdi.c b/block/vdi.c index 08331d2dd7..6c35309e04 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -734,8 +734,9 @@ nonallocating_write: return ret; } =20 -static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_opt= ions, - size_t block_size, Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +vdi_co_do_create(BlockdevCreateOptions *create_options, size_t block_size, + Error **errp) { BlockdevCreateOptionsVdi *vdi_opts; int ret =3D 0; @@ -892,13 +893,13 @@ exit: return ret; } =20 -static int coroutine_fn vdi_co_create(BlockdevCreateOptions *create_option= s, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +vdi_co_create(BlockdevCreateOptions *create_options, Error **errp) { return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp); } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vdi_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/vhdx.c b/block/vhdx.c index b20b1edf11..89913cba87 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1506,7 +1506,7 @@ exit: * There are 2 headers, and the highest sequence number will represent * the active header */ -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size, uint32_t log_size) { @@ -1515,6 +1515,8 @@ vhdx_create_new_headers(BlockBackend *blk, uint64_t i= mage_size, int ret =3D 0; VHDXHeader *hdr =3D NULL; =20 + GRAPH_RDLOCK_GUARD(); + hdr =3D g_new0(VHDXHeader, 1); =20 hdr->signature =3D VHDX_HEADER_SIGNATURE; @@ -1898,7 +1900,7 @@ exit: * .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------. * 1MB */ -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vhdx_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsVhdx *vhdx_opts; @@ -2060,7 +2062,7 @@ delete_and_exit: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vhdx_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { diff --git a/block/vmdk.c b/block/vmdk.c index fddbd1c86c..e3e86608ec 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2165,10 +2165,9 @@ vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t = offset, int64_t bytes, return ret; } =20 -static int vmdk_init_extent(BlockBackend *blk, - int64_t filesize, bool flat, - bool compress, bool zeroed_grain, - Error **errp) +static int GRAPH_UNLOCKED +vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool comp= ress, + bool zeroed_grain, Error **errp) { int ret, i; VMDK4Header header; @@ -2277,7 +2276,7 @@ exit: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_create_extent(const char *filename, int64_t filesize, bool flat, bool compress, bool zeroed_grain, BlockBackend **pbb, QemuOpts *opts, Error **errp) @@ -2358,7 +2357,7 @@ static int filename_decompose(const char *filename, c= har *path, char *prefix, * non-split format. * idx >=3D 1: get the n-th extent if in a split subformat */ -typedef BlockBackend * coroutine_fn /* GRAPH_RDLOCK */ +typedef BlockBackend * coroutine_fn GRAPH_UNLOCKED_PTR (*vmdk_create_extent_fn)(int64_t size, int idx, bool flat, bool split, bool compress, bool zeroed_grain, void *opaqu= e, Error **errp); @@ -2374,7 +2373,7 @@ static void vmdk_desc_add_extent(GString *desc, g_free(basename); } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_co_do_create(int64_t size, BlockdevVmdkSubformat subformat, BlockdevVmdkAdapterType adapter_type, @@ -2605,7 +2604,7 @@ typedef struct { QemuOpts *opts; } VMDKCreateOptsData; =20 -static BlockBackend * coroutine_fn GRAPH_RDLOCK +static BlockBackend * coroutine_fn GRAPH_UNLOCKED vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split, bool compress, bool zeroed_grain, void *opaque, Error **errp) @@ -2647,7 +2646,7 @@ exit: return blk; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { @@ -2756,11 +2755,9 @@ exit: return ret; } =20 -static BlockBackend * coroutine_fn vmdk_co_create_cb(int64_t size, int idx, - bool flat, bool split, - bool compress, - bool zeroed_grain, - void *opaque, Error *= *errp) +static BlockBackend * coroutine_fn GRAPH_UNLOCKED +vmdk_co_create_cb(int64_t size, int idx, bool flat, bool split, bool compr= ess, + bool zeroed_grain, void *opaque, Error **errp) { int ret; BlockDriverState *bs; @@ -2809,7 +2806,7 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(= int64_t size, int idx, return blk; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vmdk_co_create(BlockdevCreateOptions *create_options, Error **errp) { BlockdevCreateOptionsVmdk *opts; diff --git a/block/vpc.c b/block/vpc.c index 07ddda5b99..7ee7c7b4e0 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -967,8 +967,8 @@ static int calculate_rounded_image_size(BlockdevCreateO= ptionsVpc *vpc_opts, return 0; } =20 -static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_UNLOCKED +vpc_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsVpc *vpc_opts; BlockBackend *blk =3D NULL; @@ -1087,7 +1087,7 @@ out: return ret; } =20 -static int coroutine_fn GRAPH_RDLOCK +static int coroutine_fn GRAPH_UNLOCKED vpc_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342456; cv=none; d=zohomail.com; s=zohoarc; b=JvB70aNBjUH3y5ep7v0GDHPGdWDtEaJMLO7yyIjLENez5SypTnVIqCoCSCmkKG/8bZdJKcmA2di6eT4p1y0gaVsqAlnsl53TcrL5qtM4DNr/++CuXlBiacl4Am/eKW86KOfMxQ6P8TYGtDixngZKpqeMPsTUPEYYsEdlZ6Ikf6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342456; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tx+qYlE8xKIGeYOqmcaS/dqt7uqb6gVj6jPjOw4sl3M=; b=Tker65J7e09cu1TzJojoONDP3lz82bf+SKh1vKGDGtB/YxvXvciQvZ0Q7fnv6MlHrFTGunJm429sne18vuzEHiElt6Md4yeFD6XEpftcT2bkZVOHdoMS4jlXWjaewzycFLq0/IVJSaLNQrcPj0oQWeDe+H5Bgu6mVC7/GnLhSs4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342456212378.88350583975193; Wed, 17 May 2023 09:54:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNK-00042G-43; Wed, 17 May 2023 12:51:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNH-0003zV-AK for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNE-0001RM-La for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:39 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-170-nULxxuSNOV2pDKNzXOh46Q-1; Wed, 17 May 2023 12:51:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35FFD38184E5; Wed, 17 May 2023 16:51:32 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E4434078908; Wed, 17 May 2023 16:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tx+qYlE8xKIGeYOqmcaS/dqt7uqb6gVj6jPjOw4sl3M=; b=JyVFgsws5trzT9jdA+4kv4+aYQRxZGrQehj0gQ9KeBXk6gSUHcLOxHNBjq1owOOcqMHVvq 0JvVP4Z4TCBIaU5c0HdXcEyZZDtdNgqZ51AMJ1uuZsmaKLaIsztAP9B3a+/wN7e8S+FYN9 HugZo7NTE22Kc7nYWex3ZWUNdfpbwFg= X-MC-Unique: nULxxuSNOV2pDKNzXOh46Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 09/18] block/export: Fix null pointer dereference in error path Date: Wed, 17 May 2023 18:51:07 +0200 Message-Id: <20230517165116.475123-10-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342456980100003 Content-Type: text/plain; charset="utf-8" There are some error paths in blk_exp_add() that jump to 'fail:' before 'exp' is even created. So we can't just unconditionally access exp->blk. Add a NULL check, and switch from exp->blk to blk, which is available earlier, just to be extra sure that we really cover all cases where BlockDevOps could have been set for it (in practice, this only happens in drv->create() today, so this part of the change isn't strictly necessary). Fixes: Coverity CID 1509238 Fixes: de79b52604e43fdeba6cee4f5af600b62169f2d2 Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-3-kwolf@redhat.com> Reviewed-by: Eric Blake Tested-by: Eric Blake Signed-off-by: Kevin Wolf --- block/export/export.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index 62c7c22d45..a5c8f42f53 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -192,8 +192,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return exp; =20 fail: - blk_set_dev_ops(exp->blk, NULL, NULL); - blk_unref(blk); + if (blk) { + blk_set_dev_ops(blk, NULL, NULL); + blk_unref(blk); + } aio_context_release(ctx); if (exp) { g_free(exp->id); --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342439; cv=none; d=zohomail.com; s=zohoarc; b=faPFN0gkEcrLsRVEWoa1Yd9Nxepa8VDQ5bYnrsX+Z5T4CzHK/pdKkPmZQOyAMiC1pFAOoLSoSkdmEU3/B2ImCfvf9t9gUwK0qICOMo8BnUZypVyXKyTpIhtrn5DrlAdul0zPeyh/Gm2AXFAk9rvTlccJxVlLBVg3uCtumvBc6G8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342439; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rr1TucJqp+IIm096jK8/R7QHSZpWnM6VF3aeyatA+MI=; b=g2m+3VELuGGRr0BYzzgsd6jOZ5Ujajlb9Nk13AikHb6AswXNOWpiTASGg3I8oCbxF4WnS8U8RJwXmIJXdhfLdQJ1MOks400P5dK/lHcNqg/o/lNPg6YTCtsDE1KKDvYPZoEhE0fK/O6CzjnfvQnE9QU8qhNSmnt1I23S8jUjMvE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342439378784.5337804118172; Wed, 17 May 2023 09:53:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNN-00044n-1a; Wed, 17 May 2023 12:51:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNI-00040W-FQ for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNG-0001S3-Js for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:40 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-232-MuELR3u2Pcmthli_9v3r9w-1; Wed, 17 May 2023 12:51:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2593D29AB3F0; Wed, 17 May 2023 16:51:33 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D4B340C6EC4; Wed, 17 May 2023 16:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342296; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rr1TucJqp+IIm096jK8/R7QHSZpWnM6VF3aeyatA+MI=; b=g+FgdexKY6ubV2htbVm/mHb2GBP/HqobvEqd+yNLd0dCN9nYuYD1KfKjWCpKaojlx6J40d 3UCHfcjOL2x4KLtfcu65gTINBsvAAoEpBl5o+UWJ+knFaHkCY0gAjWybxffeiRf+ZwAvLN iIUViF02bQByO5wpBzVsQiZ7Q/ikdHg= X-MC-Unique: MuELR3u2Pcmthli_9v3r9w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 10/18] qcow2: Unlock the graph in qcow2_do_open() where necessary Date: Wed, 17 May 2023 18:51:08 +0200 Message-Id: <20230517165116.475123-11-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342440850100003 Content-Type: text/plain; charset="utf-8" qcow2_do_open() calls a few no_co_wrappers that wrap functions taking the graph lock internally as a writer. Therefore, it can't hold the reader lock across these calls, it causes deadlocks. Drop the lock temporarily around the calls. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-4-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 73f36447f9..b00b4e7575 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1619,9 +1619,11 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, = int flags, =20 if (open_data_file) { /* Open external data file */ + bdrv_graph_co_rdunlock(); s->data_file =3D bdrv_co_open_child(NULL, options, "data-file", bs, &child_of_bds, BDRV_CHILD_DATA, true, errp); + bdrv_graph_co_rdlock(); if (*errp) { ret =3D -EINVAL; goto fail; @@ -1629,10 +1631,12 @@ qcow2_do_open(BlockDriverState *bs, QDict *options,= int flags, =20 if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { if (!s->data_file && s->image_data_file) { + bdrv_graph_co_rdunlock(); s->data_file =3D bdrv_co_open_child(s->image_data_file, op= tions, "data-file", bs, &child_of_bds, BDRV_CHILD_DATA, false, = errp); + bdrv_graph_co_rdlock(); if (!s->data_file) { ret =3D -EINVAL; goto fail; @@ -1857,7 +1861,9 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, i= nt flags, fail: g_free(s->image_data_file); if (open_data_file && has_data_file(bs)) { + bdrv_graph_co_rdunlock(); bdrv_unref_child(bs, s->data_file); + bdrv_graph_co_rdlock(); s->data_file =3D NULL; } g_free(s->unknown_header_fields); --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342402; cv=none; d=zohomail.com; s=zohoarc; b=CTvqV2QtuQGZBi4fn/LtsutSsstysnDy80qaFsrWkO8AJs404qmx2iqtnzOUjOXkrQZGjXqatw0bRkNKD2ggH7JHO2hhwe4FPKpu1g2Vog8Mtaaqus9L4ELroldrwvqbKyL5U5xe3/7Oqmu2jeorwnb6m+bVJNiZydniEFAA+2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342402; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CNWzPU7pGQLYS7VpRfgExLTx8ajdrV+obUyytQcMbTE=; b=XF4uRXZFDyixhOlPzHtfOYVmWKAopuQqBYYyTNqHSMjt35Cid4k76i915lgrfXcpoHnFtU+TpFGMkyE/IpYIR7KcYHl0qrHykYPrkdk8sQj8upUJJrlRrGkOJCcJj5Wm/iYoiENmFh3i9tpGLPn5aSwcpqpuTtEeb48aqVbz7VE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342402557960.3846917167388; Wed, 17 May 2023 09:53:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNM-00043k-2r; Wed, 17 May 2023 12:51:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNI-0003zz-0o for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNG-0001SE-61 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-42-prXHn0HjNK-W0K6EVhQDMQ-1; Wed, 17 May 2023 12:51:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 14F961824602; Wed, 17 May 2023 16:51:34 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CE3640C6EC4; Wed, 17 May 2023 16:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CNWzPU7pGQLYS7VpRfgExLTx8ajdrV+obUyytQcMbTE=; b=XhK9zjWiLOunSJUvhkl9SqsZWThwRZu4JJHSXIB7e29QV3PvM6RYjCjhZtmRAhCHM074Ew +maywOcuiiHEqCH+QTk4dx7bcwAuE/iByzEoSoW6BXXuuztFr1HixM+JUzUJjH9445SLsA vp3QT0b3qQlBK3XHzOG5skbWtn+tHIg= X-MC-Unique: prXHn0HjNK-W0K6EVhQDMQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 11/18] qemu-img: Take graph lock more selectively Date: Wed, 17 May 2023 18:51:09 +0200 Message-Id: <20230517165116.475123-12-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342403114100009 Content-Type: text/plain; charset="utf-8" If we take a reader lock, we can't call any functions that take a writer lock internally without causing deadlocks once the reader lock is actually enforced in the main thread, too. Take the reader lock only where it is actually needed. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-5-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- qemu-img.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 9f9f0a7629..27f48051b0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2938,8 +2938,6 @@ static BlockGraphInfoList *collect_image_info_list(bo= ol image_opts, } bs =3D blk_bs(blk); =20 - GRAPH_RDLOCK_GUARD_MAINLOOP(); - /* * Note that the returned BlockGraphInfo object will not have * information about this image's backing node, because we have op= ened @@ -2947,7 +2945,10 @@ static BlockGraphInfoList *collect_image_info_list(b= ool image_opts, * duplicate the backing chain information that we obtain by walki= ng * the chain manually here. */ + bdrv_graph_rdlock_main_loop(); bdrv_query_block_graph_info(bs, &info, &err); + bdrv_graph_rdunlock_main_loop(); + if (err) { error_report_err(err); blk_unref(blk); --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342455; cv=none; d=zohomail.com; s=zohoarc; b=ZblS20hBlo0voIDefsYBNM6Ou/fOzdgvtclro8cKq+DC5giWrvQ3iZtG1/k4fO+HOvssn0qNAOt9Byd60PbhYNRka2wH8iCVhWxKJjJz1iqBmfEHYdeYzlFQ5uGITX2wxgxIb44/MJZ5A8Y0oTa/ZEtEaXUoJwOtB7R3Mpxb4OA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342455; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0IxlrbCsJ6QGGIw5uAuyCW2NhGqKdohEzjYBCgpT0EQ=; b=cOPWd8DuarBeYQwft7oVmOahH5/ctwk8mdkftqnFcwcN5amhYky++qpo80pkBP4e2W3Gz/M1YXgkfzi/3wE8rgvbJcspoTtoFPCSTkIV9eRFVKH2kcJP/V0Q6Zzgw3yIMxZD8Qc6Ct68o+d1rRtTJ3mhC6TpjLWOO8gn+cHASD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16843424558251003.2334055052254; Wed, 17 May 2023 09:54:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNK-00042Y-CF; Wed, 17 May 2023 12:51:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNJ-00041b-7n for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNH-0001TR-CG for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-393-sg4OjQndOmWauYZ7M0R5tQ-1; Wed, 17 May 2023 12:51:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 03C0C800047; Wed, 17 May 2023 16:51:35 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B49540C6EC4; Wed, 17 May 2023 16:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342298; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0IxlrbCsJ6QGGIw5uAuyCW2NhGqKdohEzjYBCgpT0EQ=; b=RZw7Vax0B0pX2F9T7g+P9o+vW1WLdOMlOLSs34W1bvbO0JksXfjzJ+niuOHYm6I9tyLFwp w2xC1xpLwr3eqGK7qeo9RYAldTGNnrOpdPYee9CvSVDV0qcPKE+KYnaHDZ7u9F8CoC45Tf 44q9AmlVxTvV1MQZxP1M0o7w/AmGkII= X-MC-Unique: sg4OjQndOmWauYZ7M0R5tQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 12/18] test-bdrv-drain: Take graph lock more selectively Date: Wed, 17 May 2023 18:51:10 +0200 Message-Id: <20230517165116.475123-13-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342456492100001 Content-Type: text/plain; charset="utf-8" If we take a reader lock, we can't call any functions that take a writer lock internally without causing deadlocks once the reader lock is actually enforced in the main thread, too. Take the reader lock only where it is actually needed. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-6-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/unit/test-bdrv-drain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 9a4c5e59d6..ae4299ccfa 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1004,8 +1004,6 @@ static void coroutine_fn test_co_delete_by_drain(void= *opaque) void *buffer =3D g_malloc(65536); QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buffer, 65536); =20 - GRAPH_RDLOCK_GUARD(); - /* Pretend some internal write operation from parent to child. * Important: We have to read from the child, not from the parent! * Draining works by first propagating it all up the tree to the @@ -1014,7 +1012,9 @@ static void coroutine_fn test_co_delete_by_drain(void= *opaque) * everything will be drained before we go back down the tree, but * we do not want that. We want to be in the middle of draining * when this following requests returns. */ + bdrv_graph_co_rdlock(); bdrv_co_preadv(tts->wait_child, 0, 65536, &qiov, 0); + bdrv_graph_co_rdunlock(); =20 g_assert_cmpint(bs->refcnt, =3D=3D, 1); =20 --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342434; cv=none; d=zohomail.com; s=zohoarc; b=Vo+sKEjMSKtpPcx92JTRi/VDbjSkvw2B63KUal9XzBP8so0M8ugRjePIBiiunNFCK1jVczKPFAAOI8p3MRdQRGmqhRo303HJupPkOVBChe9GPgkX7EMjZpn6sJV8r5KoBJLDp8GK/enOhqjhK0rvkZKF/TIwrajUlljmiXZ6khU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342434; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ea2U1Vf1cNrohGgr0t72oPyF1ruvZrlLGmw60rIdyfA=; b=UYgEssWVc0KWKI6Pfyg1dukS4/Zbj7jrS4p6akWsr1oCPU1aVNFbXizt7lHo6RgkCYYiJQGiQ6MH5PM/7AAxnnUWascEZSc3C9Tnpur+gr3LmdSjy70Z5vF7ZfSKmhs6YoEOIUowRWfc+OMtAxmi2I9azwJWMsd3rlWyLqnND08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342434621960.3978254777724; Wed, 17 May 2023 09:53:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNN-00045P-B5; Wed, 17 May 2023 12:51:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNL-000434-F3 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNK-0001WL-08 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:43 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-8-3_NGevE-NaWnWe7w8rb-jQ-1; Wed, 17 May 2023 12:51:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E628038184E3; Wed, 17 May 2023 16:51:35 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3ABA040C6EC4; Wed, 17 May 2023 16:51:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ea2U1Vf1cNrohGgr0t72oPyF1ruvZrlLGmw60rIdyfA=; b=DRvJLs933/9BaiEtC1qPrTrJ7I/ZI87MUJA6+2vmgMTn8HNZ0PZ8sarVF9dCBtE+4oF5Ed cqgBGIUJDU3KG2B1Ljpe+LGLK0VJzgx17AxadWzWehJcQIoyl20gkXDGMTlsVcI6OxrmRH jQ6VPizOIxiSzB5SA9SEIgrkXaCDwRs= X-MC-Unique: 3_NGevE-NaWnWe7w8rb-jQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 13/18] test-bdrv-drain: Call bdrv_co_unref() in coroutine context Date: Wed, 17 May 2023 18:51:11 +0200 Message-Id: <20230517165116.475123-14-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342436750100005 Content-Type: text/plain; charset="utf-8" bdrv_unref() is a no_coroutine_fn, so calling it from coroutine context is invalid. Use bdrv_co_unref() instead. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-7-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/unit/test-bdrv-drain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index ae4299ccfa..08bb0f9984 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1019,7 +1019,7 @@ static void coroutine_fn test_co_delete_by_drain(void= *opaque) g_assert_cmpint(bs->refcnt, =3D=3D, 1); =20 if (!dbdd->detach_instead_of_delete) { - blk_unref(blk); + blk_co_unref(blk); } else { BdrvChild *c, *next_c; QLIST_FOREACH_SAFE(c, &bs->children, next, next_c) { --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342403; cv=none; d=zohomail.com; s=zohoarc; b=VilZtCt/dVMbTIYy7QCfJS4gbYI5xXPt+JjZemc0zeAoM48zc13soFpPPK0pNwrdJfTo+uKuGJP+CaBIXWiuVzx7+PQ7G+82yB/tlQbKXSkwP68HkkRvrWm+ZYSOM7EaB9ZDebAA8wt9XqyTpReJiWHUo4m0QMWW+6M9jreH5sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342403; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5kPtbJb0tidbQu+RP75JRK8WweAJ9YC1/xKnt9hfbn4=; b=O8eKc6ocxJp0X8tdlaLHJ6Eld92OtFYB5i8pR6cku+17x8fHxvTiCFz309TN28QXiCV2gNZ9wk0mPl+QR8U9gHrA+qNpfiE7jVY/HNWyFEpIEii3CPD/Ky847ckhoReVitkLwqvm36M+QN8pAUXfK+AVWTWjQfKBpMoWRLooJAM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342403193643.8233145746563; Wed, 17 May 2023 09:53:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNP-00046e-10; Wed, 17 May 2023 12:51:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNM-00043x-3g for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNK-0001WO-AA for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-574-wuIUyhqGM6GQG6pF0T06Rw-1; Wed, 17 May 2023 12:51:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D891688B770; Wed, 17 May 2023 16:51:36 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A33740C6EC4; Wed, 17 May 2023 16:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5kPtbJb0tidbQu+RP75JRK8WweAJ9YC1/xKnt9hfbn4=; b=T3mOK2cnjioOmdbolCXfDoPCsaUZzyWWD/8E5BZhx3kfeXXirOgOpIQs7IxwHEE0D6vcwb qG2w6MaaM0YGqnwGmVh6XfbnHK+OPHznjmxPq2OJgqfEHcXAWqSZZKERnk1qGceBxDl+09 8snXdojGcvhEY9eZ7ZvK7I8r+mCHOIo= X-MC-Unique: wuIUyhqGM6GQG6pF0T06Rw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 14/18] blockjob: Adhere to rate limit even when reentered early Date: Wed, 17 May 2023 18:51:12 +0200 Message-Id: <20230517165116.475123-15-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342404448100013 Content-Type: text/plain; charset="utf-8" When jobs are sleeping, for example to enforce a given rate limit, they can be reentered early, in particular in order to get paused, to update the rate limit or to get cancelled. Before this patch, they behave in this case as if they had fully completed their rate limiting delay. This means that requests are sped up beyond their limit, violating the constraints that the user gave us. Change the block jobs to sleep in a loop until the necessary delay is completed, while still allowing cancelling them immediately as well pausing (handled by the pause point in job_sleep_ns()) and updating the rate limit. This change is also motivated by iotests cases being prone to fail because drain operations pause and unpause them so often that block jobs complete earlier than they are supposed to. In particular, the next commit would fail iotests 030 without this change. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-8-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- include/block/blockjob_int.h | 14 ++++++++++---- block/commit.c | 7 ++----- block/mirror.c | 23 ++++++++++------------- block/stream.c | 7 ++----- blockjob.c | 22 ++++++++++++++++++++-- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index f008446285..104824040c 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -126,12 +126,18 @@ void block_job_user_resume(Job *job); */ =20 /** - * block_job_ratelimit_get_delay: + * block_job_ratelimit_processed_bytes: * - * Calculate and return delay for the next request in ns. See the document= ation - * of ratelimit_calculate_delay() for details. + * To be called after some work has been done. Adjusts the delay for the n= ext + * request. See the documentation of ratelimit_calculate_delay() for detai= ls. */ -int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n); +void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n); + +/** + * Put the job to sleep (assuming that it wasn't canceled) to throttle it = to the + * right speed according to its rate limiting. + */ +void block_job_ratelimit_sleep(BlockJob *job); =20 /** * block_job_error_action: diff --git a/block/commit.c b/block/commit.c index 2b20fd0fd4..aa45beb0f0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -116,7 +116,6 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); int64_t offset; - uint64_t delay_ns =3D 0; int ret =3D 0; int64_t n =3D 0; /* bytes */ QEMU_AUTO_VFREE void *buf =3D NULL; @@ -149,7 +148,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ - job_sleep_ns(&s->common.job, delay_ns); + block_job_ratelimit_sleep(&s->common); if (job_is_cancelled(&s->common.job)) { break; } @@ -184,9 +183,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) job_progress_update(&s->common.job, n); =20 if (copy) { - delay_ns =3D block_job_ratelimit_get_delay(&s->common, n); - } else { - delay_ns =3D 0; + block_job_ratelimit_processed_bytes(&s->common, n); } } =20 diff --git a/block/mirror.c b/block/mirror.c index 717442ca4d..b7d92d1378 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -471,12 +471,11 @@ static unsigned mirror_perform(MirrorBlockJob *s, int= 64_t offset, return bytes_handled; } =20 -static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) +static void coroutine_fn mirror_iteration(MirrorBlockJob *s) { BlockDriverState *source =3D s->mirror_top_bs->backing->bs; MirrorOp *pseudo_op; int64_t offset; - uint64_t delay_ns =3D 0, ret =3D 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks =3D 1; bool write_zeroes_ok =3D bdrv_can_write_zeroes_with_unmap(blk_bs(s->ta= rget)); @@ -608,16 +607,13 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) assert(io_bytes); offset +=3D io_bytes; nb_chunks -=3D DIV_ROUND_UP(io_bytes, s->granularity); - delay_ns =3D block_job_ratelimit_get_delay(&s->common, io_bytes_ac= ct); + block_job_ratelimit_processed_bytes(&s->common, io_bytes_acct); } =20 - ret =3D delay_ns; fail: QTAILQ_REMOVE(&s->ops_in_flight, pseudo_op, next); qemu_co_queue_restart_all(&pseudo_op->waiting_requests); g_free(pseudo_op); - - return ret; } =20 static void mirror_free_init(MirrorBlockJob *s) @@ -1011,7 +1007,6 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) assert(!s->dbi); s->dbi =3D bdrv_dirty_iter_new(s->dirty_bitmap); for (;;) { - uint64_t delay_ns =3D 0; int64_t cnt, delta; bool should_complete; =20 @@ -1051,7 +1046,7 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) mirror_wait_for_free_in_flight_slot(s); continue; } else if (cnt !=3D 0) { - delay_ns =3D mirror_iteration(s); + mirror_iteration(s); } } =20 @@ -1114,12 +1109,14 @@ static int coroutine_fn mirror_run(Job *job, Error = **errp) } =20 if (job_is_ready(&s->common.job) && !should_complete) { - delay_ns =3D (s->in_flight =3D=3D 0 && - cnt =3D=3D 0 ? BLOCK_JOB_SLICE_TIME : 0); + if (s->in_flight =3D=3D 0 && cnt =3D=3D 0) { + trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.= job), + BLOCK_JOB_SLICE_TIME); + job_sleep_ns(&s->common.job, BLOCK_JOB_SLICE_TIME); + } + } else { + block_job_ratelimit_sleep(&s->common); } - trace_mirror_before_sleep(s, cnt, job_is_ready(&s->common.job), - delay_ns); - job_sleep_ns(&s->common.job, delay_ns); s->last_pause_ns =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); } =20 diff --git a/block/stream.c b/block/stream.c index 7f9e1ecdbb..e522bbdec5 100644 --- a/block/stream.c +++ b/block/stream.c @@ -131,7 +131,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) BlockDriverState *unfiltered_bs =3D bdrv_skip_filters(s->target_bs); int64_t len; int64_t offset =3D 0; - uint64_t delay_ns =3D 0; int error =3D 0; int64_t n =3D 0; /* bytes */ =20 @@ -155,7 +154,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. */ - job_sleep_ns(&s->common.job, delay_ns); + block_job_ratelimit_sleep(&s->common); if (job_is_cancelled(&s->common.job)) { break; } @@ -204,9 +203,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) /* Publish progress */ job_progress_update(&s->common.job, n); if (copy) { - delay_ns =3D block_job_ratelimit_get_delay(&s->common, n); - } else { - delay_ns =3D 0; + block_job_ratelimit_processed_bytes(&s->common, n); } } =20 diff --git a/blockjob.c b/blockjob.c index 659c3cb9de..913da3cbf7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -319,10 +319,28 @@ static bool block_job_set_speed(BlockJob *job, int64_= t speed, Error **errp) return block_job_set_speed_locked(job, speed, errp); } =20 -int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n) +void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n) { IO_CODE(); - return ratelimit_calculate_delay(&job->limit, n); + ratelimit_calculate_delay(&job->limit, n); +} + +void block_job_ratelimit_sleep(BlockJob *job) +{ + uint64_t delay_ns; + + /* + * Sleep at least once. If the job is reentered early, keep waiting un= til + * we've waited for the full time that is necessary to keep the job at= the + * right speed. + * + * Make sure to recalculate the delay after each (possibly interrupted) + * sleep because the speed can change while the job has yielded. + */ + do { + delay_ns =3D ratelimit_calculate_delay(&job->limit, 0); + job_sleep_ns(&job->job, delay_ns); + } while (delay_ns && !job_is_cancelled(&job->job)); } =20 BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp) --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342509; cv=none; d=zohomail.com; s=zohoarc; b=J8ADsZ+4MpAwz5bX6lJNY2hFnIfvHMTZcCRMpEMpQzLaAh5cpt//lVVtzSAjeTCSpTpimBnvyUojqqHNpDxwafRIfZt16iTdckU+5sIybxR0BIXskBWvo0YfAEgQpeyAsHRgLnCYAabPKT0TtPGChODIFkUI4UP1uEzvaHrcE8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342509; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Av32Y6A1PHT9iibZFDzdKTmo58adQORDsDeRO0je8OY=; b=T2LO8XUee3KE1RTaevJt8L5KUwasN/Fqe63/dv5wso+69DYhWju8lcbPy0GmkEPcCxAQZrXuoGpW/loUiOmUdce8kGsaaT9rK5K0VPjtk6tbB0dLMqyCxfGRneEINv13Zr4PqtCGFKyaVfmUm/fVTMSCCBOIzKLW0RrE1qfUVmA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342509661547.3752146644487; Wed, 17 May 2023 09:55:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNP-00047B-LK; Wed, 17 May 2023 12:51:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNM-00044T-IF for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNK-0001XC-M2 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:44 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-iZ9C7nZMPCeJT5igbn01ag-1; Wed, 17 May 2023 12:51:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C6F4788B771; Wed, 17 May 2023 16:51:37 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B8964078908; Wed, 17 May 2023 16:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Av32Y6A1PHT9iibZFDzdKTmo58adQORDsDeRO0je8OY=; b=NSQdGU5+P3GZMLx9KgMYcgbyq6U7ZANs4inQhxVMKkccCmWDCB2/X3YMDe/lXYcJPJbvGG gEk7i9Zaez94ikPfrrT1+kFgx7/O4HZwE4+kCoM3XIgyRBy1vIzImIAxxMWcsw6LM4cSSl bqURH7fCl7oAqkEjvkMiw8jrkC7nuPk= X-MC-Unique: iZ9C7nZMPCeJT5igbn01ag-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 15/18] graph-lock: Honour read locks even in the main thread Date: Wed, 17 May 2023 18:51:13 +0200 Message-Id: <20230517165116.475123-16-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342511654100001 Content-Type: text/plain; charset="utf-8" There are some conditions under which we don't actually need to do anything for taking a reader lock: Writing the graph is only possible from the main context while holding the BQL. So if a reader is running in the main context under the BQL and knows that it won't be interrupted until the next writer runs, we don't actually need to do anything. This is the case if the reader code neither has a nested event loop (this is forbidden anyway while you hold the lock) nor is a coroutine (because a writer could run when the coroutine has yielded). These conditions are exactly what bdrv_graph_rdlock_main_loop() asserts. They are not fulfilled in bdrv_graph_co_rdlock(), which always runs in a coroutine. This deletes the shortcuts in bdrv_graph_co_rdlock() that skip taking the reader lock in the main thread. Reported-by: Fiona Ebner Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-9-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/graph-lock.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/block/graph-lock.c b/block/graph-lock.c index 377884c3a9..9c42bd9799 100644 --- a/block/graph-lock.c +++ b/block/graph-lock.c @@ -162,11 +162,6 @@ void coroutine_fn bdrv_graph_co_rdlock(void) BdrvGraphRWlock *bdrv_graph; bdrv_graph =3D qemu_get_current_aio_context()->bdrv_graph; =20 - /* Do not lock if in main thread */ - if (qemu_in_main_thread()) { - return; - } - for (;;) { qatomic_set(&bdrv_graph->reader_count, bdrv_graph->reader_count + 1); @@ -230,11 +225,6 @@ void coroutine_fn bdrv_graph_co_rdunlock(void) BdrvGraphRWlock *bdrv_graph; bdrv_graph =3D qemu_get_current_aio_context()->bdrv_graph; =20 - /* Do not lock if in main thread */ - if (qemu_in_main_thread()) { - return; - } - qatomic_store_release(&bdrv_graph->reader_count, bdrv_graph->reader_count - 1); /* make sure writer sees reader_count before we check has_writer */ --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342413; cv=none; d=zohomail.com; s=zohoarc; b=dns8Luypd0eWHhVdeuR4myeKjn6xIkrs5mxglzQu5Qwv3+0i+X9qOIjl8vAvTUsqOJUmfS1HvAC/N9hPBhUy1bIuZH3TTqAlWKaL5lGNp5OpOHAOHEwmKPYP+E2qh8IWpJZB5Ep1s+Ho4Zb48yc1wY8ZcNKuBFBFqFiZ1tr92m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342413; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6HiFJsun4DvczkId8/hzkLX1Wz6i1p32cpQ72Lh7oqs=; b=YNG/ckwpNBRZY7HJ3RBkgvzVGTuBdnQNx+10HKupTz+aGE/rC8bNkhonp3rxfHlCKXPRh6bb3+19PRsqHKHrJOS00G9MSVKKajfrkSV1XJRttjIbgfIQhXAk2+b2qWEBJ5H1GV1g9PaKmMk6Z8itJi7uYGMsIW2SvAOwpENWYBk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168434241386091.8243241978704; Wed, 17 May 2023 09:53:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNM-00043w-4z; Wed, 17 May 2023 12:51:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNK-00042b-Ib for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNI-0001Va-Vb for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:42 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-rP_bh_OAPu-80TrxgVFnyg-1; Wed, 17 May 2023 12:51:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5C2E85A5A3; Wed, 17 May 2023 16:51:38 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09ABA40C6EC4; Wed, 17 May 2023 16:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6HiFJsun4DvczkId8/hzkLX1Wz6i1p32cpQ72Lh7oqs=; b=FvYI8Zz3IgMB16X/njfKF/PVBvPKkI54+2s3U7kHGaEcA2yhsVpPQWnRumGJlsUjHE81ez jIPELct7iwnKP4K7Kg4MulS/wRU4EWydkiHN9VY+kyTemFRSpd28GX2nuuhyXCrhYrnlOQ VOTHJ4RkJM0OvkZOK8+WaSmz40+eMqM= X-MC-Unique: rP_bh_OAPu-80TrxgVFnyg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 16/18] iotests/245: Check if 'compress' driver is available Date: Wed, 17 May 2023 18:51:14 +0200 Message-Id: <20230517165116.475123-17-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342414319100001 Content-Type: text/plain; charset="utf-8" Skip TestBlockdevReopen.test_insert_compress_filter() if the 'compress' driver isn't available. In order to make the test succeed when the case is skipped, we also need to remove any output from it (which would be missing in the case where we skip it). This is done by replacing qemu_io_log() with qemu_io(). In case of failure, qemu_io() raises an exception with the output of the qemu-io binary in its message, so we don't actually lose anything. Signed-off-by: Kevin Wolf Message-Id: <20230511143801.255021-1-kwolf@redhat.com> Signed-off-by: Kevin Wolf --- tests/qemu-iotests/245 | 7 ++++--- tests/qemu-iotests/245.out | 9 +-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index edaf29094b..92b28c79be 100755 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -611,6 +611,7 @@ class TestBlockdevReopen(iotests.QMPTestCase): self.reopen(hd0_opts, {'file': 'hd0-file'}) =20 # Insert (and remove) a compress filter + @iotests.skip_if_unsupported(['compress']) def test_insert_compress_filter(self): # Add an image to the VM: hd (raw) -> hd0 (qcow2) -> hd0-file (fil= e) opts =3D {'driver': 'raw', 'node-name': 'hd', 'file': hd_opts(0)} @@ -650,9 +651,9 @@ class TestBlockdevReopen(iotests.QMPTestCase): =20 # Check the first byte of the first three L2 entries and verify th= at # the second one is compressed (0x40) while the others are not (0x= 80) - iotests.qemu_io_log('-f', 'raw', '-c', 'read -P 0x80 0x40000 1', - '-c', 'read -P 0x40 0x40008 1', - '-c', 'read -P 0x80 0x40010 1', h= d_path[0]) + iotests.qemu_io('-f', 'raw', '-c', 'read -P 0x80 0x40000 1', + '-c', 'read -P 0x40 0x40008 1', + '-c', 'read -P 0x80 0x40010 1', hd_pa= th[0]) =20 # Swap the disk images of two active block devices def test_swap_files(self): diff --git a/tests/qemu-iotests/245.out b/tests/qemu-iotests/245.out index a4e04a3266..0970ced62a 100644 --- a/tests/qemu-iotests/245.out +++ b/tests/qemu-iotests/245.out @@ -10,14 +10,7 @@ {"return": {}} {"data": {"id": "stream0", "type": "stream"}, "event": "BLOCK_JOB_PENDING"= , "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"device": "stream0", "len": 3145728, "offset": 3145728, "speed":= 0, "type": "stream"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"micro= seconds": "USECS", "seconds": "SECS"}} -....read 1/1 bytes at offset 262144 -1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -read 1/1 bytes at offset 262152 -1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -read 1/1 bytes at offset 262160 -1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -................ +.................... ---------------------------------------------------------------------- Ran 26 tests =20 --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342375; cv=none; d=zohomail.com; s=zohoarc; b=b04nfNMR13InhtZnHrjcHuZhe4kagSI81Z5CgN8Lx4L+MocA9JbXhZNf3kXTbicTnIeKi08oEMd6xRxS8D/J1jQiG3ztMumpiehymvPzZTeFKPBcPuhrkOO9+gVHvRUSr6GYca+y5gF14jn0KDFxPVO+xHuMKu6JvgvtJaJd+Jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342375; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HsRPOLR/XFxYJAvyW2yUzBvwsZ6u1liscUcw81KHa0g=; b=GOejVdA6PT4bs1xiCegohmbSU0Mnbn8bR4lzSovKRbTIuhjhQrV14q0lbfM9pFZDf2vvnnx6HIwqUNpwsdLX7lb0OLEg/pn7OlznGDd2UfSerwvtSrW7VWQxlGd4bGgOiw6xwG5SXRtv36658zzxXXf+fUmS2CDHZhW4op4Kskw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16843423750701005.8592851463338; Wed, 17 May 2023 09:52:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNS-00049V-Cj; Wed, 17 May 2023 12:51:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNO-00046C-1Q for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNL-0001Ys-Vn for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:45 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-546-HqQlDo7EO_6tGaR1hgzH0A-1; Wed, 17 May 2023 12:51:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4A50811E7C; Wed, 17 May 2023 16:51:39 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC8F940C6EC4; Wed, 17 May 2023 16:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HsRPOLR/XFxYJAvyW2yUzBvwsZ6u1liscUcw81KHa0g=; b=M+n2Bj/hcRpXbtkqRmbOUlA8UNLQhsqpQJgtn5E+R/pate6dT6cjGEmO1+ONbVLCzoLPZZ kc0x/JHjVdZzDKtAJgHnkltr4niMqgrz6vRjfo6lxLtKaZ+orHYvv89wckRp6VVrQGyZnY e1CAud5tJRlVMpOZneuZ/iDv/DzqqyQ= X-MC-Unique: HqQlDo7EO_6tGaR1hgzH0A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 17/18] aio-posix: do not nest poll handlers Date: Wed, 17 May 2023 18:51:15 +0200 Message-Id: <20230517165116.475123-18-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342376181100004 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi QEMU's event loop supports nesting, which means that event handler functions may themselves call aio_poll(). The condition that triggered a handler must be reset before the nested aio_poll() call, otherwise the same handler will be called and immediately re-enter aio_poll. This leads to an infinite loop and stack exhaustion. Poll handlers are especially prone to this issue, because they typically reset their condition by finishing the processing of pending work. Unfortunately it is during the processing of pending work that nested aio_poll() calls typically occur and the condition has not yet been reset. Disable a poll handler during ->io_poll_ready() so that a nested aio_poll() call cannot invoke ->io_poll_ready() again. As a result, the disabled poll handler and its associated fd handler do not run during the nested aio_poll(). Calling aio_set_fd_handler() from inside nested aio_poll() could cause it to run again. If the fd handler is pending inside nested aio_poll(), then it will also run again. In theory fd handlers can be affected by the same issue, but they are more likely to reset the condition before calling nested aio_poll(). This is a special case and it's somewhat complex, but I don't see a way around it as long as nested aio_poll() is supported. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D2186181 Fixes: c38270692593 ("block: Mark bdrv_co_io_(un)plug() and callers GRAPH_R= DLOCK") Cc: Kevin Wolf Cc: Emanuele Giuseppe Esposito Cc: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Message-Id: <20230502184134.534703-2-stefanha@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- util/aio-posix.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/aio-posix.c b/util/aio-posix.c index a8be940f76..34bc2a64d8 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -353,8 +353,19 @@ static bool aio_dispatch_handler(AioContext *ctx, AioH= andler *node) poll_ready && revents =3D=3D 0 && aio_node_check(ctx, node->is_external) && node->io_poll_ready) { + /* + * Remove temporarily to avoid infinite loops when ->io_poll_ready= () + * calls aio_poll() before clearing the condition that made the po= ll + * handler become ready. + */ + QLIST_SAFE_REMOVE(node, node_poll); + node->io_poll_ready(node->opaque); =20 + if (!QLIST_IS_INSERTED(node, node_poll)) { + QLIST_INSERT_HEAD(&ctx->poll_aio_handlers, node, node_poll); + } + /* * Return early since revents was zero. aio_notify() does not coun= t as * progress. --=20 2.40.1 From nobody Sat May 18 09:01:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684342401; cv=none; d=zohomail.com; s=zohoarc; b=aXvFoa52mO7XEFO1zw6TpmCD6AAMblhMGBwAhIjqp5zaf8VGkYJqGwlY2Z99ebLwC4hfb1M04h+PbUXKEVlNYEfTQcxPQsZKTEqDFVRZgsJQoWt9gvP1cTcnbsi1+XRkCNbh26k94LjsVRxNb5QY/PO/QrgL1M3kZotTsbepTms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684342401; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SSwCeO8zJBYXyQ1mZfi7jfoxgA087Gw9juqpPvR203E=; b=SEffhzQU9x/XMxCt+goQPEabX9qUlm94bU584w647z0+XyqrMh3zYkSKFeQDPCFDeBAGAeWqdXnPr6vEkqpMCCOH2dHGSeiLIRRYRdgFQ15HGOg97+Owc9g5c7zBTPI8D7B75u5OfND+wyXl9T+XutWbJFx0JFz8LfYt39n2tpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684342401649242.3658933942819; Wed, 17 May 2023 09:53:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzKNQ-00048M-IN; Wed, 17 May 2023 12:51:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNO-00046U-Ic for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzKNM-0001Zj-V8 for qemu-devel@nongnu.org; Wed, 17 May 2023 12:51:46 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-C4DbK-QWNYOjmaXsPBpTXw-1; Wed, 17 May 2023 12:51:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9429A1C05ABF; Wed, 17 May 2023 16:51:40 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC23C40C6EC4; Wed, 17 May 2023 16:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684342304; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SSwCeO8zJBYXyQ1mZfi7jfoxgA087Gw9juqpPvR203E=; b=JtpVrj5KbcGQDDP6YLhE/hCjIZ+Qx4tfhCRYBWm66pn8vgZKImLKRzeEpyXmv/ZC9XfTDr ohzSDk0wSakDeuBqTG2nE+uZpgiZXg5mU31UV/fegQbpoWpuZZb4NacG4boTRttodXwBYa z2S6xabLgylzyt/lbmPWxY2cZ/v0xW8= X-MC-Unique: C4DbK-QWNYOjmaXsPBpTXw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 18/18] tested: add test for nested aio_poll() in poll handlers Date: Wed, 17 May 2023 18:51:16 +0200 Message-Id: <20230517165116.475123-19-kwolf@redhat.com> In-Reply-To: <20230517165116.475123-1-kwolf@redhat.com> References: <20230517165116.475123-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1684342402267100005 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-Id: <20230502184134.534703-3-stefanha@redhat.com> Tested-by: Kevin Wolf Signed-off-by: Kevin Wolf --- tests/unit/test-nested-aio-poll.c | 130 ++++++++++++++++++++++++++++++ tests/unit/meson.build | 1 + 2 files changed, 131 insertions(+) create mode 100644 tests/unit/test-nested-aio-poll.c diff --git a/tests/unit/test-nested-aio-poll.c b/tests/unit/test-nested-aio= -poll.c new file mode 100644 index 0000000000..9bbe18b839 --- /dev/null +++ b/tests/unit/test-nested-aio-poll.c @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Test that poll handlers are not re-entrant in nested aio_poll() + * + * Copyright Red Hat + * + * Poll handlers are usually level-triggered. That means they continue fir= ing + * until the condition is reset (e.g. a virtqueue becomes empty). If a poll + * handler calls nested aio_poll() before the condition is reset, then inf= inite + * recursion occurs. + * + * aio_poll() is supposed to prevent this by disabling poll handlers in ne= sted + * aio_poll() calls. This test case checks that this is indeed what happen= s. + */ +#include "qemu/osdep.h" +#include "block/aio.h" +#include "qapi/error.h" + +typedef struct { + AioContext *ctx; + + /* This is the EventNotifier that drives the test */ + EventNotifier poll_notifier; + + /* This EventNotifier is only used to wake aio_poll() */ + EventNotifier dummy_notifier; + + bool nested; +} TestData; + +static void io_read(EventNotifier *notifier) +{ + fprintf(stderr, "%s %p\n", __func__, notifier); + event_notifier_test_and_clear(notifier); +} + +static bool io_poll_true(void *opaque) +{ + fprintf(stderr, "%s %p\n", __func__, opaque); + return true; +} + +static bool io_poll_false(void *opaque) +{ + fprintf(stderr, "%s %p\n", __func__, opaque); + return false; +} + +static void io_poll_ready(EventNotifier *notifier) +{ + TestData *td =3D container_of(notifier, TestData, poll_notifier); + + fprintf(stderr, "> %s\n", __func__); + + g_assert(!td->nested); + td->nested =3D true; + + /* Wake the following nested aio_poll() call */ + event_notifier_set(&td->dummy_notifier); + + /* This nested event loop must not call io_poll()/io_poll_ready() */ + g_assert(aio_poll(td->ctx, true)); + + td->nested =3D false; + + fprintf(stderr, "< %s\n", __func__); +} + +/* dummy_notifier never triggers */ +static void io_poll_never_ready(EventNotifier *notifier) +{ + g_assert_not_reached(); +} + +static void test(void) +{ + TestData td =3D { + .ctx =3D aio_context_new(&error_abort), + }; + + qemu_set_current_aio_context(td.ctx); + + /* Enable polling */ + aio_context_set_poll_params(td.ctx, 1000000, 2, 2, &error_abort); + + /* + * The GSource is unused but this has the side-effect of changing the = fdmon + * that AioContext uses. + */ + aio_get_g_source(td.ctx); + + /* Make the event notifier active (set) right away */ + event_notifier_init(&td.poll_notifier, 1); + aio_set_event_notifier(td.ctx, &td.poll_notifier, false, + io_read, io_poll_true, io_poll_ready); + + /* This event notifier will be used later */ + event_notifier_init(&td.dummy_notifier, 0); + aio_set_event_notifier(td.ctx, &td.dummy_notifier, false, + io_read, io_poll_false, io_poll_never_ready); + + /* Consume aio_notify() */ + g_assert(!aio_poll(td.ctx, false)); + + /* + * Run the io_read() handler. This has the side-effect of activating + * polling in future aio_poll() calls. + */ + g_assert(aio_poll(td.ctx, true)); + + /* The second time around the io_poll()/io_poll_ready() handler runs */ + g_assert(aio_poll(td.ctx, true)); + + /* Run io_poll()/io_poll_ready() one more time to show it keeps workin= g */ + g_assert(aio_poll(td.ctx, true)); + + aio_set_event_notifier(td.ctx, &td.dummy_notifier, false, + NULL, NULL, NULL); + aio_set_event_notifier(td.ctx, &td.poll_notifier, false, NULL, NULL, N= ULL); + event_notifier_cleanup(&td.dummy_notifier); + event_notifier_cleanup(&td.poll_notifier); + aio_context_unref(td.ctx); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/nested-aio-poll", test); + return g_test_run(); +} diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 3bc78d8660..a314f82baa 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -67,6 +67,7 @@ if have_block 'test-coroutine': [testblock], 'test-aio': [testblock], 'test-aio-multithread': [testblock], + 'test-nested-aio-poll': [testblock], 'test-throttle': [testblock], 'test-thread-pool': [testblock], 'test-hbitmap': [testblock], --=20 2.40.1