From nobody Fri May 17 09:18:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671440705; cv=none; d=zohomail.com; s=zohoarc; b=m690piY7V+xoXRYtccm8r7Y6YtoEifljsZRaO4q4cg1F8KOZ6ENGv0NzmkihLIxbnK+yfZWtDz/8KaKviItmUJh0zneNXA92mKyGgY8kkyoDS+ZZARUSrdUDxNNa6DxAKN38CaSlcAGPMEI2ZFa+vqxhNjhw3dS2UdFnKOWEXy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671440705; h=Content-Type:Content-Transfer-Encoding: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=b9HpRvEbikjd5pcbgsHfWLa6kdi8mYUY+ZXt7P6DN2c=; b=Lb7Ckjjr8Xgrs1qb0n/NRAdfkeTN0fpPTM9vWAGypxcDS4MsvRZlvI1lV0R1zagNeEDyo/k2OsibU+3opL+9+9CEgZIgvhvn60Fogqh3bDCTrux6WOZ5QPnb8y+6DsKSmkQ4Ep3pg+gOKbXQM4w9m7l0xjj0XyJmrrymTaXAdl0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1671440705033792.6786569036295; Mon, 19 Dec 2022 01:05:05 -0800 (PST) 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-201-HDnoEU35PuKCZ4O21SEY0A-1; Mon, 19 Dec 2022 04:04:10 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4000A280607C; Mon, 19 Dec 2022 09:04:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64E75C16020; Mon, 19 Dec 2022 09:04:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4C4BF19465B7; Mon, 19 Dec 2022 09:04:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5B319194658D for ; Mon, 19 Dec 2022 09:04:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 504D81121315; Mon, 19 Dec 2022 09:04:04 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEFC81121314 for ; Mon, 19 Dec 2022 09:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671440704; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=b9HpRvEbikjd5pcbgsHfWLa6kdi8mYUY+ZXt7P6DN2c=; b=QpdFsbp67wiRdcmFnd+Vv7NkOujfUm8qPcA4zAbYjJkGKWTF09SxQ9X2a9UHDGQtebcUni 9rt+PN7WBj9wkcVztQp12xkqZItefxg3aElUlYcwrawzp7OHQrQHoZoUj4jcvXcmTjD3w2 izmfWW5o/coGBnCT4gzvabD/0+uAJAM= X-MC-Unique: HDnoEU35PuKCZ4O21SEY0A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] virqemu: Don't strip the requested key from nested objects Date: Mon, 19 Dec 2022 10:04:00 +0100 Message-Id: <0429ee4abaf4b11ed693f97b95d1beaec69d55aa.1671440529.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671440706883100001 Content-Type: text/plain; charset="utf-8" Skipping of a specific key is needed only for the top level object to specially handle the object type. We must not pass it to any recursed printing of nested objects as skipping keys there might be surprising and also is unhandlable later when formatting the commandline. Until now this did not pose a problem but was discovered when adding a new netdev backend which has a nested config object which also has the 'type' key which was being skipped. Modern usage will prefer JSON directly but fix the commandline generator to prevent surprises. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virqemu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 9dc0eab386..15602e30db 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -163,8 +163,7 @@ virQEMUBuildCommandLineJSONIterate(const char *key, if (data->prefix) key =3D tmpkey =3D g_strdup_printf("%s.%s", data->prefix, key); - return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, - data->skipKey, + return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, NULL, data->arrayFunc, false); } @@ -222,14 +221,14 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, return -1; } - if (arrayFunc(key, value, buf, skipKey) < 0) { + if (arrayFunc(key, value, buf, NULL) < 0) { /* fallback, treat the array as a non-bitmap, adding the key * for each member */ for (i =3D 0; i < virJSONValueArraySize(value); i++) { elem =3D virJSONValueArrayGet((virJSONValue *)value, i); /* recurse to avoid duplicating code */ - if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, ski= pKey, + if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, NUL= L, arrayFunc, true) < = 0) return -1; } @@ -257,7 +256,8 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, * virQEMUBuildCommandLineJSON: * @value: json object containing the value * @buf: otuput buffer - * @skipKey: name of key that will be handled separately by caller + * @skipKey: name of key inside the top level object that will be handled + * separately by caller * @arrayFunc: array formatter function to allow for different syntax * * Formats JSON value object into command line parameters suitable for use= with --=20 2.38.1 From nobody Fri May 17 09:18:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671440655; cv=none; d=zohomail.com; s=zohoarc; b=KsUuWPwHLPw6OXAJWWmDpiKI7cG0H6ZF5NoxbfrOVAfLMfZtPZ++iOltNygE07BsLfty6vD0BmcklcB1+5dle4mOPH2+jN3mfYhwqkcWcchvPU4skv43bxxcqGzQL32a0E4C8KTNOfgHo8RXQXOVFqz3AmBrtBgjr44GRLNLTSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671440655; h=Content-Type:Content-Transfer-Encoding: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=EET+cPAy1BFJdnvOTetfC5y2yujxZcvveUfCJiqqxSk=; b=PIHwIcHDkLs6gfwi5JrphuH6XxigWyTI7biLiJRoRItt/HmsrYs03i8yFLYhYg1wT1FRuL9YcnEd0NxiN9R4ozWWNtlbSfL6jBbuWXw3R/tIrg4s8cRyppo287sooZ9I8OG04wD3GvueJ0slxSYoBsysn5uzOVoZiXhSIqNXfo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1671440655476132.95336415491954; Mon, 19 Dec 2022 01:04:15 -0800 (PST) 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-290-2rlqdM3hO0WTAHEgdpE0Pw-1; Mon, 19 Dec 2022 04:04:10 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4008B100F91E; Mon, 19 Dec 2022 09:04:07 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7A2E2166B2B; Mon, 19 Dec 2022 09:04:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 88F751946594; Mon, 19 Dec 2022 09:04:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5C0041946A6C for ; Mon, 19 Dec 2022 09:04:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 40F871121314; Mon, 19 Dec 2022 09:04:05 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF1AD1121315 for ; Mon, 19 Dec 2022 09:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671440653; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EET+cPAy1BFJdnvOTetfC5y2yujxZcvveUfCJiqqxSk=; b=gZ6pjvY0ef5rZQWjhhhfz1E+2J8oEJYLntcqVmVHVFPErq+eVMxMZnD5ZVo5tTsI6jWjm7 KI77Rv+JT7Hj+83620wMbRlRiLTAd49m7Xe/suDL8w7Yq5O7BFQgIFaUHNvxEHxXIC1zPk 9JRW+6Mhffu6pEZjXBV7zEUe/cRnG0U= X-MC-Unique: 2rlqdM3hO0WTAHEgdpE0Pw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/2] util: qemu: Remove 'skipKey' argument from virQEMUBuildCommandLineJSONArrayFormatFunc prototype Date: Mon, 19 Dec 2022 10:04:01 +0100 Message-Id: <0215cbf4b0f0313719da6a7b97f0f1d8433b0e91.1671440529.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671440656828100001 Content-Type: text/plain; charset="utf-8" Since we really only need to handle key skipping in the top level object the caller doesn't at this point even pass it to the array formatting helper function. Remove the unused argument. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virqemu.c | 13 +++++-------- src/util/virqemu.h | 12 ++++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 15602e30db..b9e57a6f4c 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -53,8 +53,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValue *array, - virBuffer *buf, - const char *skipKey G_GNUC_UNUSED) + virBuffer *buf) { ssize_t pos =3D -1; ssize_t end; @@ -90,8 +89,7 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValue *array, - virBuffer *buf, - const char *skipKey) + virBuffer *buf) { virJSONValue *member; size_t i; @@ -102,7 +100,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *ke= y, member =3D virJSONValueArrayGet((virJSONValue *) array, i); prefix =3D g_strdup_printf("%s.%zu", key, i); - if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKe= y, + if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, NULL, virQEMUBuildCommandLineJSON= ArrayNumbered, true) < 0) return 0; @@ -127,8 +125,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *ke= y, int virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key, virJSONValue *array, - virBuffer *buf, - const char *skipKey G_GNUC_UNUS= ED) + virBuffer *buf) { g_auto(virBuffer) tmp =3D VIR_BUFFER_INITIALIZER; size_t i; @@ -221,7 +218,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, return -1; } - if (arrayFunc(key, value, buf, NULL) < 0) { + if (arrayFunc(key, value, buf) < 0) { /* fallback, treat the array as a non-bitmap, adding the key * for each member */ for (i =3D 0; i < virJSONValueArraySize(value); i++) { diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 472f24de53..be083d7545 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -28,20 +28,16 @@ typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key, virJSONValue *ar= ray, - virBuffer *buf, - const char *skip= Key); + virBuffer *buf); int virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key, virJSONValue *array, - virBuffer *buf, - const char *skipKey); + virBuffer *buf); int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValue *array, - virBuffer *buf, - const char *skipKey); + virBuffer *buf); int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValue *array, - virBuffer *buf, - const char *skipKey); + virBuffer *buf); int virQEMUBuildCommandLineJSON(virJSONValue *value, virBuffer *buf, --=20 2.38.1