From nobody Tue Feb 10 05:39:38 2026 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1655203018; cv=none; d=zohomail.com; s=zohoarc; b=FcAK2vUd7T2thVJX2jUM8dJSL79jfOwjf824/J8cEHGzMTo3TdwhQiQmMSiqrIrEDqBLqN07x7uaWaovC9g/KQP+Uaaz8Gfdc673fg4X9g7EaQhtofkbnRnc/xJ2KKx2wBGSCtwSlUGbxATGLsM9H34CZddA1NhQHz+zSB9y2NA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655203018; 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=R9dXA4ELgeiEDcwtM2G/dcJ4f7RwrhTVkAo1g2RPYSc=; b=Vz+br8ds/PMBZHlipwU3/EFOkrO9nVo6RNpol4KSYogzRiuSHL3GizTU0O5XoCyxRWGzOfL985FHKR8x5K0zUqh1kY34TMi6x8gME5r6h6AAoLFrYeCyuwDsZvG1nurtdURkbSaEJKza57V38yFdQq0i2cM9HmnefvLDtNJme98= 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 16552030180681005.3204753771671; Tue, 14 Jun 2022 03:36:58 -0700 (PDT) Received: from localhost ([::1]:57476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o13uq-0004fC-3O for importer@patchew.org; Tue, 14 Jun 2022 06:36:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o13nm-0001E5-KU; Tue, 14 Jun 2022 06:29:38 -0400 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:57570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o13nf-0000kG-0j; Tue, 14 Jun 2022 06:29:38 -0400 Received: from sas1-9c28cd37d27b.qloud-c.yandex.net (sas1-9c28cd37d27b.qloud-c.yandex.net [IPv6:2a02:6b8:c14:309b:0:640:9c28:cd37]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id F03AA2E1A95; Tue, 14 Jun 2022 13:29:19 +0300 (MSK) Received: from sas1-c73b4b4f4b95.qloud-c.yandex.net (sas1-c73b4b4f4b95.qloud-c.yandex.net [2a02:6b8:c08:12a9:0:640:c73b:4b4f]) by sas1-9c28cd37d27b.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id Laao1vUIuq-TJJSSZe9; Tue, 14 Jun 2022 13:29:19 +0300 Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:a427::1:2e]) by sas1-c73b4b4f4b95.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 15x97ivcvu-TIMmIZCB; Tue, 14 Jun 2022 13:29:19 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1655202559; bh=R9dXA4ELgeiEDcwtM2G/dcJ4f7RwrhTVkAo1g2RPYSc=; h=Message-Id:References:Date:Subject:In-Reply-To:Cc:To:From; b=d4wP5oOfbOonl73Df0s7/9/xUNOIDrupkj5I9Dr+SDPYm23hyVcT5NlMo9mCOToHO uczBFttSgow1lT6IfpJ5imWRyxbzN+QJ4Jq4vYNUc0MeWnAiUbM8JHGoln0Pv2qgHl DNuVpPD6YeHiY2nh5OedwLQeCHPD0BA8G/b1DTMA= Authentication-Results: sas1-9c28cd37d27b.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, stefanha@redhat.com, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, peter.maydell@linaro.org, Vladimir Sementsov-Ogievskiy Subject: [PULL 01/10] block/copy-before-write: refactor option parsing Date: Tue, 14 Jun 2022 13:29:01 +0300 Message-Id: <20220614102910.1431380-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614102910.1431380-1-vsementsov@yandex-team.ru> References: <20220614102910.1431380-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:0:1619::183; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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" X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1655203019512100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We are going to add one more option of enum type. Let's refactor option parsing so that we can simply work with BlockdevOptionsCbw object. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/copy-before-write.c | 56 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index a8a06fdc09..e29c46cd7a 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -24,6 +24,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/qmp/qjson.h" =20 #include "sysemu/block-backend.h" #include "qemu/cutils.h" @@ -328,46 +329,34 @@ static void cbw_child_perm(BlockDriverState *bs, Bdrv= Child *c, } } =20 -static bool cbw_parse_bitmap_option(QDict *options, BdrvDirtyBitmap **bitm= ap, - Error **errp) +static BlockdevOptions *cbw_parse_options(QDict *options, Error **errp) { - QDict *bitmap_qdict =3D NULL; - BlockDirtyBitmap *bmp_param =3D NULL; + BlockdevOptions *opts =3D NULL; Visitor *v =3D NULL; - bool ret =3D false; =20 - *bitmap =3D NULL; + qdict_put_str(options, "driver", "copy-before-write"); =20 - qdict_extract_subqdict(options, &bitmap_qdict, "bitmap."); - if (!qdict_size(bitmap_qdict)) { - ret =3D true; - goto out; - } - - v =3D qobject_input_visitor_new_flat_confused(bitmap_qdict, errp); + v =3D qobject_input_visitor_new_flat_confused(options, errp); if (!v) { goto out; } =20 - visit_type_BlockDirtyBitmap(v, NULL, &bmp_param, errp); - if (!bmp_param) { + visit_type_BlockdevOptions(v, NULL, &opts, errp); + if (!opts) { goto out; } =20 - *bitmap =3D block_dirty_bitmap_lookup(bmp_param->node, bmp_param->name= , NULL, - errp); - if (!*bitmap) { - goto out; - } - - ret =3D true; + /* + * Delete options which we are going to parse through BlockdevOptions + * object for original options. + */ + qdict_extract_subqdict(options, NULL, "bitmap"); =20 out: - qapi_free_BlockDirtyBitmap(bmp_param); visit_free(v); - qobject_unref(bitmap_qdict); + qdict_del(options, "driver"); =20 - return ret; + return opts; } =20 static int cbw_open(BlockDriverState *bs, QDict *options, int flags, @@ -376,6 +365,15 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, BDRVCopyBeforeWriteState *s =3D bs->opaque; BdrvDirtyBitmap *bitmap =3D NULL; int64_t cluster_size; + g_autoptr(BlockdevOptions) full_opts =3D NULL; + BlockdevOptionsCbw *opts; + + full_opts =3D cbw_parse_options(options, errp); + if (!full_opts) { + return -EINVAL; + } + assert(full_opts->driver =3D=3D BLOCKDEV_DRIVER_COPY_BEFORE_WRITE); + opts =3D &full_opts->u.copy_before_write; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, @@ -390,8 +388,12 @@ static int cbw_open(BlockDriverState *bs, QDict *optio= ns, int flags, return -EINVAL; } =20 - if (!cbw_parse_bitmap_option(options, &bitmap, errp)) { - return -EINVAL; + if (opts->has_bitmap) { + bitmap =3D block_dirty_bitmap_lookup(opts->bitmap->node, + opts->bitmap->name, NULL, errp); + if (!bitmap) { + return -EINVAL; + } } =20 bs->total_sectors =3D bs->file->bs->total_sectors; --=20 2.25.1