From nobody Sun Feb 8 14:12:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=openvz.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648806532706576.1448635178523; Fri, 1 Apr 2022 02:48:52 -0700 (PDT) Received: from localhost ([::1]:59102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1naDtj-0006sK-M7 for importer@patchew.org; Fri, 01 Apr 2022 05:48:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1naDRW-0000Gf-NM for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:44 -0400 Received: from [2a00:1450:4864:20::22e] (port=43859 helo=mail-lj1-x22e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1naDRU-0006se-Uq for qemu-devel@nongnu.org; Fri, 01 Apr 2022 05:19:42 -0400 Received: by mail-lj1-x22e.google.com with SMTP id b43so3057382ljr.10 for ; Fri, 01 Apr 2022 02:19:36 -0700 (PDT) Received: from fedora.. ([185.215.60.153]) by smtp.gmail.com with ESMTPSA id d16-20020a2eb050000000b002461d8f365bsm155135ljl.38.2022.04.01.02.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 02:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=63KOcHkFUD4WLCydVmQXmoksEDdiR3xCGd3+SRNPvy4=; b=YC5zoMu5N14vxV6JFMDQSRZRKYC2L7P9k/hMWjgr8IJ5dfoWvtSRwXCeXl5e9QNhxJ p/Yh4zgFf02ASAxslGB25Dicxnk2Xe3nD73CPqn1+u2WWFkMtIgrMHcu9degneL/Iw8R DV56K//pdnSJeA4+T2FA6nmFqqQRjJ3kPAZCbwz3XLVfmqnIxVkZ1DLdkXV9BqxsEw/A z2xKF9yzu3dbnLDCzfS17d3youLUe+KTgQFTRf9TUmGf2aLDeQaIB/b/xNnKKn98bsRx YhWkmJys94Mgl6Mrhsy3KM3yiD2UvJRqNYbaKl3qjnXxcSKEl5u5aQkCapEae+Xup2w0 0fww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=63KOcHkFUD4WLCydVmQXmoksEDdiR3xCGd3+SRNPvy4=; b=iTMBTsUxuNgaA4Wt+QWloaaEbOpiGe2LvbX2kNeJKj59y78ZT1oVYApCzXw5nJYAZG FrfE/9kktbSkupeRtiffm5PFqKJUWcnUQ9z3MIeYY1TtyyJN63054BQ5vDBYKR03GANd A2xRkElC+yx+EDKrwdMFoGeurauFycA/dRUT7CzsGgzyE1zr3qgozspiZnL3WZ/RPaD/ 4GcqGOlRPqbidc7zdLWmeeYTUbI+sUgffD52I8gkZTxfbrt/MET5aJNujDOv6SVuyTY8 yFeAgXS3ZSBvc2RfdoJ8oyt7hfEoxhFYoTfFpIl1B4CrbT98+CB4HOHSX44PCLdAyaO9 PgNQ== X-Gm-Message-State: AOAM531Ahgo8WYFJDcjUckfAun16Vhs3cdpvrizAW5ysCJ/mKJS/hSo9 QZ4TVCbK57gC/EKNSOdsJIVDhw== X-Google-Smtp-Source: ABdhPJyJZNrKghyQU8lIbJVCUUIVWnsMPoIPCmfxIvK6o/1OjJDGuyk4pHFxwbK0y1hZKDBb3G9Hxw== X-Received: by 2002:a2e:2e16:0:b0:24a:f25e:41e with SMTP id u22-20020a2e2e16000000b0024af25e041emr6422545lju.45.1648804774864; Fri, 01 Apr 2022 02:19:34 -0700 (PDT) From: Vladimir Sementsov-Ogievskiy X-Google-Original-From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 1/7] block/copy-before-write: refactor option parsing Date: Fri, 1 Apr 2022 12:19:14 +0300 Message-Id: <20220401091920.287612-2-vsementsov@openvz.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220401091920.287612-1-vsementsov@openvz.org> References: <20220401091920.287612-1-vsementsov@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::22e (failed) 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=2a00:1450:4864:20::22e; envelope-from=vladimir.sementsov-ogievskiy@openvz.org; helo=mail-lj1-x22e.google.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: kwolf@redhat.com, v.sementsov-og@mail.ru, jsnow@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, hreitz@redhat.com, vsementsov@openvz.org, stefanha@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1648806533445100001 Content-Type: text/plain; charset="utf-8" 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 --- block/copy-before-write.c | 68 +++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index a8a06fdc09..394e73b094 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,49 @@ 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 BlockdevOptionsCbw *cbw_parse_options(QDict *options, Error **errp) { - QDict *bitmap_qdict =3D NULL; - BlockDirtyBitmap *bmp_param =3D NULL; + QDict *cbw_qdict =3D NULL; + BlockdevOptionsCbw *opts =3D NULL; Visitor *v =3D NULL; - bool ret =3D false; =20 - *bitmap =3D NULL; + cbw_qdict =3D qdict_clone_shallow(options); =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); + /* + * Delete BlockdevOptions base fields, that are not part of + * BlockdevOptionsCbw. + */ + qdict_del(cbw_qdict, "driver"); + qdict_del(cbw_qdict, "node-name"); + qdict_del(cbw_qdict, "discard"); + qdict_del(cbw_qdict, "cache"); + qdict_extract_subqdict(cbw_qdict, NULL, "cache."); + qdict_del(cbw_qdict, "read-only"); + qdict_del(cbw_qdict, "auto-read-only"); + qdict_del(cbw_qdict, "force-share"); + qdict_del(cbw_qdict, "detect-zeroes"); + + v =3D qobject_input_visitor_new_flat_confused(cbw_qdict, errp); if (!v) { goto out; } =20 - visit_type_BlockDirtyBitmap(v, NULL, &bmp_param, errp); - if (!bmp_param) { - goto out; - } - - *bitmap =3D block_dirty_bitmap_lookup(bmp_param->node, bmp_param->name= , NULL, - errp); - if (!*bitmap) { + visit_type_BlockdevOptionsCbw(v, NULL, &opts, errp); + if (!opts) { goto out; } =20 - ret =3D true; + /* + * Delete options which we are going to parse through BlockdevOptionsC= bw + * object for original options. + */ + qdict_extract_subqdict(options, NULL, "bitmap"); =20 out: - qapi_free_BlockDirtyBitmap(bmp_param); visit_free(v); - qobject_unref(bitmap_qdict); + qobject_unref(cbw_qdict); =20 - return ret; + return opts; } =20 static int cbw_open(BlockDriverState *bs, QDict *options, int flags, @@ -376,6 +380,12 @@ 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(BlockdevOptionsCbw) opts =3D NULL; + + opts =3D cbw_parse_options(options, errp); + if (!opts) { + return -EINVAL; + } =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, @@ -390,8 +400,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.35.1