From nobody Mon Feb 9 01:49:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1589556571; cv=none; d=zohomail.com; s=zohoarc; b=Q/LCcSUhmnEdGbPU5X8qODujckFQJ3A+KFcK6GhIg4q/K4KI2p5caBFsOHemflvbQ5IhS/Pwim0mU1ZbJECImqxIlWSnrta8F+FndqUiI06zyqyQK3cFioGqsbLaDZCKR6apxLoYfF7YfxnIiGe58gcWvXhnZ3wwTmk2akwWf0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556571; 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=CZPbR20VWuv5ZhJqzBGRqtHzyZzgOGKSiPyNYVfU1TA=; b=dKYCzHUIfClhZU7dyIT7xLv7Pq12WY8R+55VydaSZip/WHr6+o2tlnoqrYTCR9ZH1V3QevkJ02OOYp4a6Hri3mbhvPyEZC9slkbXuFsenA6qKqv9xw3O6z8MZhIMT8fXMzx3fRYJ0d6bWob6HrxgRefCcdxqz1irDpqyEbAjSts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1589556571457182.6749597594419; Fri, 15 May 2020 08:29:31 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-133-sFOSroepMeiIhMJ71a8vNA-1; Fri, 15 May 2020 11:29:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A813218FF669; Fri, 15 May 2020 15:29:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89D5A5D9F3; Fri, 15 May 2020 15:29:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 590954EA05; Fri, 15 May 2020 15:29:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04FFTItI011400 for ; Fri, 15 May 2020 11:29:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id ADF195D9F5; Fri, 15 May 2020 15:29:18 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 280AD5D9D7 for ; Fri, 15 May 2020 15:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556570; 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=CZPbR20VWuv5ZhJqzBGRqtHzyZzgOGKSiPyNYVfU1TA=; b=bGKlIEZorsfWQxJOaX7r1jre9hsNrHLSguImIHbElRoQhrSvacfpGHO9NSBgHX2s+7f8Rb XfMDTLJ1a083xjeLd0Se4v16YKHGPLoSpDt+VIGsuA1K1/KM5x9wmMS19D967B9Z8RAINp iIJzg41sj73O8SEtWV74yMG/vgU+Iec= X-MC-Unique: sFOSroepMeiIhMJ71a8vNA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/21] virQEMUBuildNetdevCommandlineFromJSON: Prepare for quirky 'guestfwd' Date: Fri, 15 May 2020 17:28:01 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" QEMU models guestfwd as: 'guestfwd': [ { "str": "tcp:10.0.2.1:4600-chardev:charchannel0" }, { "str": "...."}, ] I guess the original idea was to make it extensible while not worrying about adding another object for it. Either way it requires us to add yet another JSON->cmdline convertor for arrays. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virqemu.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 0f8cab29df..f3e9966598 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -109,6 +109,41 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *k= ey, } +/** + * This array convertor is for quirky cases where the QMP schema mandates = an + * array of objects with only one attribute 'str' which needs to be format= ted as + * repeated key-value pairs without the 'str' being printed: + * + * 'guestfwd': [ + * { "str": "tcp:10.0.2.1:4600-chardev:charchannel0" }, + * { "str": "...."}, + * ] + */ +static int +virQEMUBuildCommandLineJSONArrayObjectsStr(const char *key, + virJSONValuePtr array, + virBufferPtr buf, + const char *skipKey G_GNUC_UNUS= ED, + bool onOff G_GNUC_UNUSED) +{ + g_auto(virBuffer) tmp =3D VIR_BUFFER_INITIALIZER; + size_t i; + + for (i =3D 0; i < virJSONValueArraySize(array); i++) { + virJSONValuePtr member =3D virJSONValueArrayGet(array, i); + const char *str =3D virJSONValueObjectGetString(member, "str"); + + if (!str) + return -1; + + virBufferAsprintf(&tmp, "%s=3D%s,", key, str); + } + + virBufferAddBuffer(buf, &tmp); + return 0; +} + + /* internal iterator to handle nested object formatting */ static int virQEMUBuildCommandLineJSONIterate(const char *key, @@ -267,7 +302,8 @@ virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr p= rops) virBufferAsprintf(&buf, "%s,", type); - if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, NULL) < 0) + if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, + virQEMUBuildCommandLineJSONArrayObject= sStr) < 0) return NULL; return virBufferContentAndReset(&buf); --=20 2.26.2