From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1589556507; cv=none; d=zohomail.com; s=zohoarc; b=EJOn87dP/AJCi4CNg7ui39HFs4CUg5qNu1DUug/WD3f5iP3TEr+6mfn0zGNnhjbVjUbetjCFIyxtLFoG2skW/BX/8Z8fEr4fjwJtTo7Mfqz70RKm0eCjnmZVB6AuEMHvtSImDC1+cXILrP5l6ib1IpjB2/9kMwoeGESpFZUb9X0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556507; 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=MOeM8vE9oYFXHA+B9KPt4+oKkgmOKaPd1WECwCeA0Ag=; b=MusXZyQiVcsUKs70hP6ycRAMt3JcvohyTf34tmEzU8Pfnb+vnf0OFd44sfkE0X8P1SNGHjzVEW073Otbiy3PJ2g0qR2p44BIaEd5Olc69SYFqexaZqXx+vLU2ijzZzUZK4RdKNmH7pQ/ANMwq1ozYFXina3s491sRYXzgKX5+ug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1589556507606440.0905617200252; Fri, 15 May 2020 08:28:27 -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-61-h-QMPySiMz6LBoVWXLdoNQ-1; Fri, 15 May 2020 11:28:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B1E08005AD; Fri, 15 May 2020 15:28:15 +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 5678460C05; Fri, 15 May 2020 15:28:15 +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 2954B4E9E5; Fri, 15 May 2020 15:28:15 +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 04FFSDQt011113 for ; Fri, 15 May 2020 11:28:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id A8BD65D9D7; Fri, 15 May 2020 15:28:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FCE85D9C9 for ; Fri, 15 May 2020 15:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556505; 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=MOeM8vE9oYFXHA+B9KPt4+oKkgmOKaPd1WECwCeA0Ag=; b=iWYHfK/acQPMA1dZ8bk8kxbAJXW+iRYyEtK/c1WgrFWV2UWUhDGBueorzf2rhUZZ4s9Uqj iYvyO01HIIv0qgTprXtwF7a+wti1XYgSM/9sZnuvKqkCv48v/OelzL+kiVjlL3VXe+uHh4 NrdOH2TnmhIXeLy0IZYx+89bKqogB2Q= X-MC-Unique: h-QMPySiMz6LBoVWXLdoNQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/21] qemu: domain: Forbid unsupported 'tftp' protocol and handle tests Date: Fri, 15 May 2020 17:27:47 +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.12 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" 'tftp' storage protocol was supported by qemu until 2.7.0. Add an interlock when blockdev is used and drop the test case for it as it's IMO not worth adding another test file just for that. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_domain.c | 10 ++++++++++ tests/qemuxml2argvdata/disk-cdrom-network.args | 3 --- .../disk-cdrom-network.x86_64-2.12.0.args | 3 --- .../disk-cdrom-network.x86_64-latest.args | 17 ++++++----------- tests/qemuxml2argvdata/disk-cdrom-network.xml | 9 --------- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d0528dbfe0..d5e3d1a3cc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5319,6 +5319,16 @@ qemuDomainValidateStorageSource(virStorageSourcePtr = src, return -1; } + /* TFTP protocol was not supported for some time, lock it out at least= with + * -blockdev */ + if (actualType =3D=3D VIR_STORAGE_TYPE_NETWORK && + src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_TFTP && + blockdev) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'tftp' protocol is not supported with this QEMU = binary")); + return -1; + } + return 0; } diff --git a/tests/qemuxml2argvdata/disk-cdrom-network.args b/tests/qemuxml= 2argvdata/disk-cdrom-network.args index 81ff324a0f..794fdecdcb 100644 --- a/tests/qemuxml2argvdata/disk-cdrom-network.args +++ b/tests/qemuxml2argvdata/disk-cdrom-network.args @@ -33,7 +33,4 @@ id=3Ddrive-ide0-0-1,readonly=3Don \ -drive 'file=3Dhttps://host.name:443/url/path/file.iso?test=3Dval,format= =3Draw,\ if=3Dnone,id=3Ddrive-ide0-1-0,readonly=3Don' \ -device ide-cd,bus=3Dide.1,unit=3D0,drive=3Ddrive-ide0-1-0,id=3Dide0-1-0 \ --drive file=3Dtftp://host.name:69/url/path/file.iso,format=3Draw,if=3Dnone= ,\ -id=3Ddrive-ide0-1-1,readonly=3Don \ --device ide-cd,bus=3Dide.1,unit=3D1,drive=3Ddrive-ide0-1-1,id=3Dide0-1-1 \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/disk-cdrom-network.x86_64-2.12.0.args b= /tests/qemuxml2argvdata/disk-cdrom-network.x86_64-2.12.0.args index 81f6b400aa..fa5c0ba087 100644 --- a/tests/qemuxml2argvdata/disk-cdrom-network.x86_64-2.12.0.args +++ b/tests/qemuxml2argvdata/disk-cdrom-network.x86_64-2.12.0.args @@ -35,9 +35,6 @@ id=3Ddrive-ide0-0-1,readonly=3Don \ -drive 'file=3Dhttps://host.name:443/url/path/file.iso?test=3Dval,format= =3Draw,\ if=3Dnone,id=3Ddrive-ide0-1-0,readonly=3Don' \ -device ide-cd,bus=3Dide.1,unit=3D0,drive=3Ddrive-ide0-1-0,id=3Dide0-1-0 \ --drive file=3Dtftp://host.name:69/url/path/file.iso,format=3Draw,if=3Dnone= ,\ -id=3Ddrive-ide0-1-1,readonly=3Don \ --device ide-cd,bus=3Dide.1,unit=3D1,drive=3Ddrive-ide0-1-1,id=3Dide0-1-1 \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x2 \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ resourcecontrol=3Ddeny \ diff --git a/tests/qemuxml2argvdata/disk-cdrom-network.x86_64-latest.args b= /tests/qemuxml2argvdata/disk-cdrom-network.x86_64-latest.args index 2515b256d0..1a102949df 100644 --- a/tests/qemuxml2argvdata/disk-cdrom-network.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-cdrom-network.x86_64-latest.args @@ -28,26 +28,21 @@ file=3D/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -boot strict=3Don \ -device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ -blockdev '{"driver":"ftp","url":"ftp://host.name:21/url/path/file.iso",\ -"node-name":"libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"node-name":"libvirt-4-format","read-only":true,"driver":"raw"= ,\ -"file":"libvirt-4-storage"}' \ --device ide-cd,bus=3Dide.0,unit=3D0,drive=3Dlibvirt-4-format,id=3Dide0-0-0= ,bootindex=3D1 \ --blockdev '{"driver":"ftps","url":"ftps://host.name:990/url/path/file.iso"= ,\ "node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-3-format","read-only":true,"driver":"raw"= ,\ "file":"libvirt-3-storage"}' \ --device ide-cd,bus=3Dide.0,unit=3D1,drive=3Dlibvirt-3-format,id=3Dide0-0-1= \ --blockdev '{"driver":"https",\ -"url":"https://host.name:443/url/path/file.iso?test=3Dval",\ +-device ide-cd,bus=3Dide.0,unit=3D0,drive=3Dlibvirt-3-format,id=3Dide0-0-0= ,bootindex=3D1 \ +-blockdev '{"driver":"ftps","url":"ftps://host.name:990/url/path/file.iso"= ,\ "node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"raw"= ,\ "file":"libvirt-2-storage"}' \ --device ide-cd,bus=3Dide.1,unit=3D0,drive=3Dlibvirt-2-format,id=3Dide0-1-0= \ --blockdev '{"driver":"tftp","url":"tftp://host.name:69/url/path/file.iso",\ +-device ide-cd,bus=3Dide.0,unit=3D1,drive=3Dlibvirt-2-format,id=3Dide0-0-1= \ +-blockdev '{"driver":"https",\ +"url":"https://host.name:443/url/path/file.iso?test=3Dval",\ "node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":true,"driver":"raw"= ,\ "file":"libvirt-1-storage"}' \ --device ide-cd,bus=3Dide.1,unit=3D1,drive=3Dlibvirt-1-format,id=3Dide0-1-1= \ +-device ide-cd,bus=3Dide.1,unit=3D0,drive=3Dlibvirt-1-format,id=3Dide0-1-0= \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x2 \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ resourcecontrol=3Ddeny \ diff --git a/tests/qemuxml2argvdata/disk-cdrom-network.xml b/tests/qemuxml2= argvdata/disk-cdrom-network.xml index 44473f8ad4..18a56f7156 100644 --- a/tests/qemuxml2argvdata/disk-cdrom-network.xml +++ b/tests/qemuxml2argvdata/disk-cdrom-network.xml @@ -46,15 +46,6 @@
- - - - - - - -
- --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556508; cv=none; d=zohomail.com; s=zohoarc; b=JZnNzOE8Di4x6s90Q6ubiLcFZQWqcDfMDAfyepzuzlVWBHjPIf+OqVfD2jFX7fhvsF/q7VHsObw+VclpjSru4pu8+RPVl03EI1nvDV6hKX1zOwAxyTnuVk/pe7dN3Ch2ScxKynhebqHSMOonhjAlx/T9mhqOL0PmaGSW9eY53a0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556508; 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=Xin8fWNuc4GIW220dw52IOtzhDkHSHmNM9dnB0723Ww=; b=QCcmMlW0E1MRNjAxIgOINbyTNddpAQglosweEUFT2IVOdTMTwK6MzrZxuPiD4PpdINhRBpb7r2M4K4PD1PyrDekiNWcA3KbTDGnDtO6t9c5FjaK7ewudFg/PGXUb8OQL3Y1rf/ZvV6/DWVXEWpYkZpmc29XhoI7Qc/1VNSk4xJY= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1589556508004476.4154099889953; Fri, 15 May 2020 08:28:28 -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-303-ufz4h2XdMdekpmBu9C4JhA-1; Fri, 15 May 2020 11:28:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E9478018AC; Fri, 15 May 2020 15:28:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 895A360C05; Fri, 15 May 2020 15:28:17 +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 5B9221809554; Fri, 15 May 2020 15:28:17 +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 04FFSEtx011122 for ; Fri, 15 May 2020 11:28:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9A3F5D9D7; Fri, 15 May 2020 15:28:14 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B2945D9C9 for ; Fri, 15 May 2020 15:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556506; 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=Xin8fWNuc4GIW220dw52IOtzhDkHSHmNM9dnB0723Ww=; b=Wc5LWBGNZ/yZI6JC4G6/9EkeDHjnLbujFMhCuMWaCnKhj60+CO7T5IdYNnH1r3fP7k49Wm iI4wAVX9QhJ9cx52j9NTWmYvN7uSHwGk+1enL5sQcDNHKy6cptBCVCn5RHzhmFy+ib86bS E6GH2WghuWzPQSUIi32k9YkhNOynZY8= X-MC-Unique: ufz4h2XdMdekpmBu9C4JhA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/21] qemuMonitorJSONParseKeywords: remove constant argument Date: Fri, 15 May 2020 17:27:48 +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.12 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" There's just one caller that always passes '1'. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_monitor_json.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 505b31a78a..66422a8489 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -604,16 +604,15 @@ qemuMonitorJSONParseKeywordsFree(int nkeywords, /* * Takes a string containing a set of key=3Dvalue,key=3Dvalue,key... * parameters and splits them up, returning two arrays with - * the individual keys and values. If allowEmptyValue is nonzero, - * the "=3Dvalue" part is optional and if a key with no value is found, + * the individual keys and values. + * The "=3Dvalue" part is optional and if a key with no value is found, * NULL is be placed into corresponding place in retvalues. */ static int qemuMonitorJSONParseKeywords(const char *str, char ***retkeywords, char ***retvalues, - int *retnkeywords, - int allowEmptyValue) + int *retnkeywords) { int keywordCount =3D 0; int keywordAlloc =3D 0; @@ -645,14 +644,8 @@ qemuMonitorJSONParseKeywords(const char *str, if (!(separator =3D strchr(start, '=3D'))) separator =3D end; - if (separator >=3D endmark) { - if (!allowEmptyValue) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("malformed keyword arguments in '%s'"), s= tr); - goto error; - } + if (separator >=3D endmark) separator =3D endmark; - } keyword =3D g_strndup(start, separator - start); @@ -708,7 +701,7 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, con= st char *firstkeyword) int nkeywords =3D 0; size_t i; - if (qemuMonitorJSONParseKeywords(str, &keywords, &values, &nkeywords, = 1) < 0) + if (qemuMonitorJSONParseKeywords(str, &keywords, &values, &nkeywords) = < 0) goto error; for (i =3D 0; i < nkeywords; i++) { --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556507; cv=none; d=zohomail.com; s=zohoarc; b=N2y4l9G6bZ3j1XCnWgE1QTcn1QuJdaFtHMbvVvwiT4el77Lm/Of/ieEOolIw3l7pRy9jM4qlHpvzLh3aHVcszh6wARdr4WouxmaDHHsts/k8KAtjRzLH1vac0uLrREZBlltn0t5kO4g3l9s9GL6n0fkb09wtHvWP+VhBwmw2Sl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556507; 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=sQJuJn6FTWNzxL8rbmC2Y35RaIK4/KIVNkjF4IqZxpk=; b=eKkqDxkirbg5pASOAmc0GPFMuW8B7pwspDZ5w1zVKP8IyM+/BxgJQ+bEz3n0Oq2Zymp0cmsoxe7VCuakQeoHhryGsuEzJGT73nGEX68QMzKPhh4XVMCRX9RwQY/4KjSHgDEWIePh9MKY/5e+HUigHXvDBtArWWepTohNVZrdejM= 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 1589556507430876.8542622711042; Fri, 15 May 2020 08:28:27 -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-513-dJ46RKbLPBqveVLNzGbGbA-1; Fri, 15 May 2020 11:28:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E69911054F97; Fri, 15 May 2020 15:28:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C64EB5C241; Fri, 15 May 2020 15:28:17 +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 9791B1809561; Fri, 15 May 2020 15:28:17 +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 04FFSFRt011133 for ; Fri, 15 May 2020 11:28:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id C43A05D9C9; Fri, 15 May 2020 15:28:15 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 327545D9D7 for ; Fri, 15 May 2020 15:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556505; 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=sQJuJn6FTWNzxL8rbmC2Y35RaIK4/KIVNkjF4IqZxpk=; b=LDKuaJGTheic9+smxA5E8yM0KFRRphNe08GQ2i3XibDTW4rd1Bcy93IPj5HgFvlBXLGjAT aHryMQzpRfQjJZJpKCjsZkUcLW8eg3KY/zQiXB7TshJbOyO4sR4E3Q3f+TKLfRpPLQlY4N wh9e/DtJK3/5TRYNR0av/lp/DYQWH2U= X-MC-Unique: dJ46RKbLPBqveVLNzGbGbA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/21] qemuBuildChannelsCommandLine: Use typecasted switch for channel type Date: Fri, 15 May 2020 17:27:49 +0200 Message-Id: <47045d540986bb7246ce917b877ec9f53adad5aa.1589556042.git.pkrempa@redhat.com> 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.16 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" Cover all cases of the enum. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index bfe70ed228..06568ae585 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8523,7 +8523,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMana= ger, virDomainChrDefPtr channel =3D def->channels[i]; char *devstr; - switch (channel->targetType) { + switch ((virDomainChrChannelTargetType) channel->targetType) { case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: if (!(devstr =3D qemuBuildChrChardevStr(logManager, secManager, cmd, cfg, def, @@ -8555,6 +8555,11 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMan= ager, if (qemuBuildChrDeviceCommandLine(cmd, def, channel, qemuCaps)= < 0) return -1; break; + + case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN: + case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE: + case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST: + return -1; } } --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1589556515; cv=none; d=zohomail.com; s=zohoarc; b=Yi7XqB6knccQijwOtQ46ERj7Piao2i0Z7bhfMpAEi9Ar0fwL9i4Stik8XFow+bLn6jr+vXRH3SM52qxADE3vR4Mir4v2hy+JxkPEFAq80J9FQXGsCoflVslkMJwnUTqUCIYJXEo/qW+te7qWHVoxfapDgH7q43wiiDDkExTWnQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556515; 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=1RjWfZ3xJYA4YoArH9M0Nx+g0C2QGJlRKzZhmBlKQlw=; b=Lbo21rpWX71b25H14xLWudlvZKfc0wMKXJUFZg/EhpljhKYP2jiqF6uCP6/enE+5p9btLefqy5adDQCJJXw6s4RxJjd8FhkcAQDB6vi+envQWLvupNkLB9U7WVoxC4OxSlS4yrfJzaLpyhPvKpX6kKpxDxirs7TwVYYGOdOt3Oo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1589556515251611.8380649951632; Fri, 15 May 2020 08:28:35 -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-477-1LTDZWvgPSaZnkK9i3E14g-1; Fri, 15 May 2020 11:28:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B88D107AD62; Fri, 15 May 2020 15:28:26 +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 19038272A3; Fri, 15 May 2020 15:28:26 +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 DEFEA4CAB0; Fri, 15 May 2020 15:28:25 +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 04FFSPr2011164 for ; Fri, 15 May 2020 11:28:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 141E15D9F5; Fri, 15 May 2020 15:28:25 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D3EE5D9F1 for ; Fri, 15 May 2020 15:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556513; 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=1RjWfZ3xJYA4YoArH9M0Nx+g0C2QGJlRKzZhmBlKQlw=; b=hNBzeMdw/dgnxY92WXNGNvLR063Xm71E83VXSeCnsyrxH0TjkJXlN6sff1u8aOcjdhnoxy uGNnyZ5QNgeGo80tfbeP1rV9NTQbCG1aneEAibQfrM7Hs8/gW5F4pBQIv3t1RWa5tO5tHb eeUziOrbe/PL9diHZl0/RsVUXnzBrJA= X-MC-Unique: 1LTDZWvgPSaZnkK9i3E14g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/21] qemuBuildChannelsCommandLine: Extract common formatting of 'chardev' Date: Fri, 15 May 2020 17:27:50 +0200 Message-Id: <6f67f32d8ad87a140873750a5e5639d23cae573c.1589556042.git.pkrempa@redhat.com> 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.84 on 10.5.11.23 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" Both active branches create the same backend chardev. Since there is no other case, extract it before the switch so that we don't have to duplicate it. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 06568ae585..56b4aae1dd 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8521,37 +8521,27 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMa= nager, for (i =3D 0; i < def->nchannels; i++) { virDomainChrDefPtr channel =3D def->channels[i]; - char *devstr; + g_autofree char *chardevstr =3D NULL; + g_autofree char *netdevstr =3D NULL; - switch ((virDomainChrChannelTargetType) channel->targetType) { - case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: - if (!(devstr =3D qemuBuildChrChardevStr(logManager, secManager, + if (!(chardevstr =3D qemuBuildChrChardevStr(logManager, secManager, cmd, cfg, def, channel->source, channel->info.alias, qemuCaps, cdevflags))) - return -1; - virCommandAddArg(cmd, "-chardev"); - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + return -1; - if (qemuBuildChrDeviceStr(&devstr, def, channel, qemuCaps) < 0) + virCommandAddArg(cmd, "-chardev"); + virCommandAddArg(cmd, chardevstr); + + switch ((virDomainChrChannelTargetType) channel->targetType) { + case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: + if (qemuBuildChrDeviceStr(&netdevstr, def, channel, qemuCaps) = < 0) return -1; - virCommandAddArgList(cmd, "-netdev", devstr, NULL); - VIR_FREE(devstr); + virCommandAddArgList(cmd, "-netdev", netdevstr, NULL); break; case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: - if (!(devstr =3D qemuBuildChrChardevStr(logManager, secManager, - cmd, cfg, def, - channel->source, - channel->info.alias, - qemuCaps, cdevflags))) - return -1; - virCommandAddArg(cmd, "-chardev"); - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); - if (qemuBuildChrDeviceCommandLine(cmd, def, channel, qemuCaps)= < 0) return -1; break; --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1589556532; cv=none; d=zohomail.com; s=zohoarc; b=DmzqSPHCcneOria6TcaPM2i5J/6v4Aqd31lFIjhFKTLjOPInJCpEXkLlZtD/hOxQ4RiQw9IMEoNKznZQvUI7TbXBOcufmpZB7eVUdm/9/ml5oOKcmkFgQ7YE858MfznoU2Nn5PkeKSHKhck9waUkj5a4KJfe68KCYHm1GVtNKcI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556532; 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=8Bb89BoPRa/nzNoHXMe314PkSNiEfoSnlDFyBWIEEWY=; b=H6+IUXQL0kJuxcGIG3YoPETMV4Ml4oNWjlHRc5nKjbsP7HRGBTtJzzOASG3ebvMYEtOMcmues8P/Wfp1KM2GQOpucKNOJMRzCoOVXWcCSJmtddrMm/eUg6/MkrtkB/qfKe2bUni5IUT5iGkdcEJ7WVX09pSiSPVOP2wsFSh5WIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589556532588978.9586947843046; Fri, 15 May 2020 08:28:52 -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-468-EVB6yi3OPpWPQK9PgvbVug-1; Fri, 15 May 2020 11:28:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 178001054F8F; Fri, 15 May 2020 15:28:42 +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 E94E35C1D6; Fri, 15 May 2020 15:28:41 +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 B8B964E9E1; Fri, 15 May 2020 15:28:41 +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 04FFSeH7011208 for ; Fri, 15 May 2020 11:28:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 511865D9F1; Fri, 15 May 2020 15:28:40 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id B84BD5D9D7 for ; Fri, 15 May 2020 15:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556531; 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=8Bb89BoPRa/nzNoHXMe314PkSNiEfoSnlDFyBWIEEWY=; b=KHcUotGbVNIeWCdFJykq8C7x6mgBFvsVl82dyFUzdMpryT6oFdImYVsgJYnCw8e3nuTrtV zMDFtMVo0qeWjop3+y058kivwiOiq1jgu8H3NcPEZyJFEkHqtHsDXFjZ64RBNSvNqqfkKR 1JwSNg39lHhyZ/GsHYKo2vjKKnChmoo= X-MC-Unique: EVB6yi3OPpWPQK9PgvbVug-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/21] qemuBuildChannelChrDeviceStr: Remove formatting of properties for -netdev Date: Fri, 15 May 2020 17:27:51 +0200 Message-Id: <40bbf19ec4cef10d0fafeccfedd04f56ca963c77.1589556042.git.pkrempa@redhat.com> 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.16 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" The output of the function is fed as argument to '-device' command line argument or 'device_add' monitor command except for 'guestfwd' channels where it needs to be fed to -netdev/netdev_add. This is confusing and error prone. Split it up since the caller needs to know which command/option to use anyways, so the caller can call the appropriate function without any magic. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 36 ++++++++++++++++++++---------------- src/qemu/qemu_command.h | 3 +++ src/qemu/qemu_hotplug.c | 18 +++++++++++++----- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 56b4aae1dd..c20176f619 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8536,7 +8536,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMana= ger, switch ((virDomainChrChannelTargetType) channel->targetType) { case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: - if (qemuBuildChrDeviceStr(&netdevstr, def, channel, qemuCaps) = < 0) + if (!(netdevstr =3D qemuBuildChannelGuestfwdNetdevProps(channe= l))) return -1; virCommandAddArgList(cmd, "-netdev", netdevstr, NULL); break; @@ -9804,36 +9804,40 @@ qemuBuildParallelChrDeviceStr(char **deviceStr, return 0; } -static int -qemuBuildChannelChrDeviceStr(char **deviceStr, - const virDomainDef *def, - virDomainChrDefPtr chr) + +char * +qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr) { - int ret =3D -1; g_autofree char *addr =3D NULL; int port; - switch ((virDomainChrChannelTargetType)chr->targetType) { - case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: + if (!(addr =3D virSocketAddrFormat(chr->target.addr))) + return NULL; - addr =3D virSocketAddrFormat(chr->target.addr); - if (!addr) - return ret; - port =3D virSocketAddrGetPort(chr->target.addr); + port =3D virSocketAddrGetPort(chr->target.addr); + + return g_strdup_printf("user,guestfwd=3Dtcp:%s:%i-chardev:char%s,id=3D= %s", + addr, port, chr->info.alias, chr->info.alias); +} - *deviceStr =3D g_strdup_printf("user,guestfwd=3Dtcp:%s:%i-chardev:= char%s,id=3D%s", - addr, port, chr->info.alias, chr->inf= o.alias); - break; +static int +qemuBuildChannelChrDeviceStr(char **deviceStr, + const virDomainDef *def, + virDomainChrDefPtr chr) +{ + switch ((virDomainChrChannelTargetType)chr->targetType) { case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: if (!(*deviceStr =3D qemuBuildVirtioSerialPortDevStr(def, chr))) return -1; break; + case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: + /* guestfwd is as a netdev handled separately */ case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN: case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE: case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST: - return ret; + return -1; } return 0; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 53e05777e7..7665b68548 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -86,6 +86,9 @@ qemuBuildChrDeviceStr(char **deviceStr, virDomainChrDefPtr chr, virQEMUCapsPtr qemuCaps); +char * +qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr); + char *qemuBuildHostNetStr(virDomainNetDefPtr net, char **tapfd, size_t tapfdSize, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ab5a7aef84..2976ba7647 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2108,6 +2108,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, virErrorPtr orig_err; virDomainDefPtr vmdef =3D vm->def; g_autofree char *devstr =3D NULL; + g_autofree char *netdevstr =3D NULL; virDomainChrSourceDefPtr dev =3D chr->source; g_autofree char *charAlias =3D NULL; bool chardevAttached =3D false; @@ -2146,8 +2147,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr drive= r, goto cleanup; teardowncgroup =3D true; - if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0) - goto cleanup; + if (guestfwd) { + if (!(netdevstr =3D qemuBuildChannelGuestfwdNetdevProps(chr))) + goto cleanup; + } else { + if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0) + goto cleanup; + } if (!(charAlias =3D qemuAliasChardevFromDevAlias(chr->info.alias))) goto cleanup; @@ -2166,11 +2172,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driv= er, goto exit_monitor; chardevAttached =3D true; - if (guestfwd) { - if (qemuMonitorAddNetdev(priv->mon, devstr, + if (netdevstr) { + if (qemuMonitorAddNetdev(priv->mon, netdevstr, NULL, NULL, 0, NULL, NULL, 0, -1, NULL) <= 0) goto exit_monitor; - } else { + } + + if (devstr) { if (qemuMonitorAddDevice(priv->mon, devstr) < 0) goto exit_monitor; } --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1589556537; cv=none; d=zohomail.com; s=zohoarc; b=F+W5SQlehp8+WYMGK5gOZ44ewhWq98sanh0deuIpwUKrtByvQh7/QFlCG6VLjqgUf3/W8FurOhpPk25ak9ACR4QHg/BICsv9jYqlDWujXWF/n30M+l0urCMXlMWBAgz4eQZ4XXzAgzTdB8Ed4gfQCbsaYrPK3fHtnRHKflh9txI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556537; 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=DxkHqV6YrG47CxGLEkVqmWqR6TH3D6UDDwDfTyaKeXk=; b=TFLfOUoNIyn0S171U1LvwKf4UTS3cqSnGG+AgNLjYzxbbU+KhjW/ElsgoHFOG5GDiJHIegzDM8ileNgINjWvF8raLclL537D9WPXyT9PjjskGT0RLjpIZ2epH/As+YTi2PvKfn03Vcks87XKCdCrbFts4ntR62j/L2XFVshXnr4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 158955653753218.8167362382203; Fri, 15 May 2020 08:28:57 -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-230-yRo1DRIRN8eZXFvUMNN1cA-1; Fri, 15 May 2020 11:28:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23487800053; Fri, 15 May 2020 15:28:47 +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 0285D60C84; Fri, 15 May 2020 15:28:47 +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 CAF9F4E9FA; Fri, 15 May 2020 15:28:46 +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 04FFSkGY011235 for ; Fri, 15 May 2020 11:28:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 32A865D9D7; Fri, 15 May 2020 15:28:46 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CE9B5D9F1 for ; Fri, 15 May 2020 15:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556535; 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=DxkHqV6YrG47CxGLEkVqmWqR6TH3D6UDDwDfTyaKeXk=; b=P9ren77S477E8n+1HugVU3BxhL7VQ9lprNBcfJK3uPjggF9G64ciyZ7qEl4ERxq3m3fKQ8 wubbPttWwaz4CKJRkP/8H/Lx0tbe9XiVtBs59gHSgtTFXVMSOzmvHg6Q2mUuiHiF8VbQ6s jZmeDASKelgh/34AXK159/hROpB3e0M= X-MC-Unique: yRo1DRIRN8eZXFvUMNN1cA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/21] qemuBuildHostNetStr: Stop using 'ipv6-net' convenience argument Date: Fri, 15 May 2020 17:27:52 +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.12 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" In qemu the argument of 'ipv6-net' is split up into 'ipv6-prefix' and 'ipv6-prefixlen'. Additionally now that 'netdev_add' was qapified, only the real properties are allowed. Switch to using them explicitly. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 20 ++++++++++---------- tests/qemuxml2argvdata/net-user-addr.args | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c20176f619..2850953bd0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3645,20 +3645,20 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, for (i =3D 0; i < net->guestIP.nips; i++) { const virNetDevIPAddr *ip =3D net->guestIP.ips[i]; g_autofree char *addr =3D NULL; - const char *prefix =3D ""; if (!(addr =3D virSocketAddrFormat(&ip->address))) return NULL; - if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) - prefix =3D "net=3D"; - if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) - prefix =3D "ipv6-net=3D"; - - virBufferAsprintf(&buf, "%s%s", prefix, addr); - if (ip->prefix) - virBufferAsprintf(&buf, "/%u", ip->prefix); - virBufferAddChar(&buf, ','); + if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { + virBufferAsprintf(&buf, "net=3D%s", addr); + if (ip->prefix) + virBufferAsprintf(&buf, "/%u", ip->prefix); + virBufferAddChar(&buf, ','); + } else if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET= 6)) { + virBufferAsprintf(&buf, "ipv6-prefix=3D%s,", addr); + if (ip->prefix) + virBufferAsprintf(&buf, "ipv6-prefixlen=3D%u,", ip= ->prefix); + } } } break; diff --git a/tests/qemuxml2argvdata/net-user-addr.args b/tests/qemuxml2argv= data/net-user-addr.args index 6cc82d9e62..5f1de305e0 100644 --- a/tests/qemuxml2argvdata/net-user-addr.args +++ b/tests/qemuxml2argvdata/net-user-addr.args @@ -27,6 +27,7 @@ server,nowait \ -usb \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ --netdev user,net=3D172.17.2.0/24,ipv6-net=3D2001:db8:ac10:fd01::/64,id=3Dh= ostnet0 \ +-netdev user,net=3D172.17.2.0/24,ipv6-prefix=3D2001:db8:ac10:fd01::,\ +ipv6-prefixlen=3D64,id=3Dhostnet0 \ -device rtl8139,netdev=3Dhostnet0,id=3Dnet0,mac=3D00:11:22:33:44:55,bus=3D= pci.0,\ addr=3D0x3 --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556542; cv=none; d=zohomail.com; s=zohoarc; b=FB4JgT25THDueupOSFNZTfjguCFkruIhKg22e0LrNbErpwLnf23NXl+vs2yrkNsDQ+x5IsaxNoTPeKA6tjxzq1phP4AEfY/a7iHlZsdi6ENg3BG0djZMswijq3Qe+mL8qeooQ/C7oSDYpt6rRq9xEHlH3N/oCSS0EUCIkA2jLNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556542; 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=awyBP5FphgHESXI8kK5DfqhG4zwjCCgCoNxdvDhKevw=; b=j0/FyP+Ztpix0WDEyha+YhL67z6kI4fkKXEZ4QTOxBSxr2wgDJdjFpg6Feb+uskYb/U6ppHeHcOc3zJPaEaqNZoy7rsw6B+GsjTtacWhZoxIjCGoUrFwrmbW5n3nCWlYSzYChKzHB3a0khENUHJpemqb8WtNL3yMYx/quYgpsfU= 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 1589556542203797.6229666756379; Fri, 15 May 2020 08:29:02 -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-325-jeHFU1w5NNetz0UTT1LVhA-1; Fri, 15 May 2020 11:28:58 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78A5A18FE867; Fri, 15 May 2020 15:28:53 +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 5964D60FB9; Fri, 15 May 2020 15:28:53 +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 28B7D4E9FD; Fri, 15 May 2020 15:28:53 +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 04FFSqSa011262 for ; Fri, 15 May 2020 11:28:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A85C5D9F1; Fri, 15 May 2020 15:28:52 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A74E75D9D7 for ; Fri, 15 May 2020 15:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556540; 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=awyBP5FphgHESXI8kK5DfqhG4zwjCCgCoNxdvDhKevw=; b=ECa88Rrq49SW1aD4sd1VM0tiSZ8jz161wjxrkxSVI6Q8WdhxX34FNDPPTsJq0cwwe1ZtWH Se14tAMbrmVtZE5Xtjk1ilE+P86OEt0nsC5ZInFpIZlxiPhs2Zd4ofE9AggpThu7Cd4jyJ nlLdd8SZDO0LtYRm/a+JUjZZW04zTLE= X-MC-Unique: jeHFU1w5NNetz0UTT1LVhA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/21] virQEMUBuildCommandLineJSON: Allow skipping certain keys Date: Fri, 15 May 2020 17:27:53 +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.12 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" Allow reusing this for formatting of netdev_add arguments into -netdev. We need to be able to skip the 'type' property as it's used without the prefix. Add infrastructure which allows skipping a certainly named property. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virqemu.c | 30 +++++++++++++++++++++--------- src/util/virqemu.h | 10 +++++++--- tests/qemucommandutiltest.c | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 78a9e0480b..0e6fa412bc 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -36,6 +36,7 @@ VIR_LOG_INIT("util.qemu"); struct virQEMUCommandLineJSONIteratorData { const char *prefix; virBufferPtr buf; + const char *skipKey; virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc; }; @@ -44,6 +45,7 @@ static int virQEMUBuildCommandLineJSONRecurse(const char *key, virJSONValuePtr value, virBufferPtr buf, + const char *skipKey, virQEMUBuildCommandLineJSONArrayFormatF= unc arrayFunc, bool nested); @@ -52,7 +54,8 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValuePtr array, - virBufferPtr buf) + virBufferPtr buf, + const char *skipKey G_GNUC_UNUSED) { ssize_t pos =3D -1; ssize_t end; @@ -80,7 +83,8 @@ virQEMUBuildCommandLineJSONArrayBitmap(const char *key, int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValuePtr array, - virBufferPtr buf) + virBufferPtr buf, + const char *skipKey) { virJSONValuePtr member; size_t i; @@ -91,7 +95,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key, prefix =3D g_strdup_printf("%s.%zu", key, i); - if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, + if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKe= y, virQEMUBuildCommandLineJSON= ArrayNumbered, true) < 0) return 0; @@ -109,15 +113,20 @@ virQEMUBuildCommandLineJSONIterate(const char *key, { struct virQEMUCommandLineJSONIteratorData *data =3D opaque; + if (STREQ_NULLABLE(key, data->skipKey)) + return 0; + if (data->prefix) { g_autofree char *tmpkey =3D NULL; tmpkey =3D g_strdup_printf("%s.%s", data->prefix, key); return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, + data->skipKey, data->arrayFunc, false); } else { return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, + data->skipKey, data->arrayFunc, false); } } @@ -127,10 +136,11 @@ static int virQEMUBuildCommandLineJSONRecurse(const char *key, virJSONValuePtr value, virBufferPtr buf, + const char *skipKey, virQEMUBuildCommandLineJSONArrayFormatF= unc arrayFunc, bool nested) { - struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, arrayFu= nc }; + struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, skipKey= , arrayFunc }; virJSONType type =3D virJSONValueGetType(value); virJSONValuePtr elem; bool tmp; @@ -170,14 +180,14 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, return -1; } - if (!arrayFunc || arrayFunc(key, value, buf) < 0) { + if (!arrayFunc || arrayFunc(key, value, buf, skipKey) < 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((virJSONValuePtr)value, i); /* recurse to avoid duplicating code */ - if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, + if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, ski= pKey, arrayFunc, true) < = 0) return -1; } @@ -205,6 +215,7 @@ 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 * @arrayFunc: array formatter function to allow for different syntax * * Formats JSON value object into command line parameters suitable for use= with @@ -215,9 +226,10 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virBufferPtr buf, + const char *skipKey, virQEMUBuildCommandLineJSONArrayFormatFunc arr= ay) { - if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, array, false)= < 0) + if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, arra= y, false) < 0) return -1; virBufferTrim(buf, ","); @@ -243,7 +255,7 @@ virQEMUBuildObjectCommandlineFromJSONInternal(virBuffer= Ptr buf, if (props) { virBufferAddLit(buf, ","); - if (virQEMUBuildCommandLineJSON(props, buf, + if (virQEMUBuildCommandLineJSON(props, buf, NULL, virQEMUBuildCommandLineJSONArrayBitmap) < = 0) return -1; } @@ -270,7 +282,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr sr= cdef) virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *ret =3D NULL; - if (virQEMUBuildCommandLineJSON(srcdef, &buf, + if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, virQEMUBuildCommandLineJSONArrayNumber= ed) < 0) goto cleanup; diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 227325e80e..9d3db7c2a2 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -29,16 +29,20 @@ typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key, virJSONValuePtr = array, - virBufferPtr buf= ); + virBufferPtr buf, + const char *skip= Key); int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValuePtr array, - virBufferPtr buf); + virBufferPtr buf, + const char *skipKey); int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValuePtr array, - virBufferPtr buf); + virBufferPtr buf, + const char *skipKey); int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virBufferPtr buf, + const char *skipKey, virQEMUBuildCommandLineJSONArrayFormatFunc= array); int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index c5b3e7b735..923776e642 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -47,7 +47,7 @@ testQemuCommandBuildFromJSON(const void *opaque) return -1; } - if (virQEMUBuildCommandLineJSON(val, &buf, data->arrayfunc) < 0) { + if (virQEMUBuildCommandLineJSON(val, &buf, NULL, data->arrayfunc) < 0)= { fprintf(stderr, "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n", data->props); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1589556548; cv=none; d=zohomail.com; s=zohoarc; b=fhKRYP0UCh6z5l5dpis/h4l3XlGp7/d475wcAUP9BuoaF55ohyprSs3T332StcWqPNRnKkDG/U2jupOT3JEpP/1RZpeSG6ygTDVzCM/Wcn4sZvcrCc3SeOw7CayZzjNJsJ+0lk2P3MDk5xGeLAiOIL/EZdC607pAmcvHnYIx2eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556548; 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=9y4khby1NoycR9cEQgejBakU4ve500OeBOlJotlPHmY=; b=J+IHltDgF+/mMSo+twU/6jtgZh1iS6SYxxjcJ4Xr5FmXkYI5k1XtN4FkGK3CNUUCqh2kw1jcslsZsljfrZSjXGegwfoOfgVMGG5ct8KOCcaUnnSbPRK852ZSfZMKjMIjgM8JJl/wa/poWAmlk1FnwfwfD3KU0w2mPuNDzHbn4UA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589556548663977.7010852712284; Fri, 15 May 2020 08:29:08 -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-132-F2B_XA0ANEaQ904gMYD_EA-1; Fri, 15 May 2020 11:29:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F9B618FE863; Fri, 15 May 2020 15:28:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5186A63F8F; Fri, 15 May 2020 15:28:59 +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 2021E1809547; Fri, 15 May 2020 15:28:59 +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 04FFSvV8011278 for ; Fri, 15 May 2020 11:28:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9DA15D9F5; Fri, 15 May 2020 15:28:57 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 527425D9D7 for ; Fri, 15 May 2020 15:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556547; 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=9y4khby1NoycR9cEQgejBakU4ve500OeBOlJotlPHmY=; b=UZ8zGe3IMhViYE1/foJyH09LkZxyHW+PzYDbce8wjYAnrzb//mf+S5xIkPdMJteEIdIHzo +LpnhqcEJlkx4GV6y5VBigzPkdgq7r6MOkRI+sF7t75GxE4+IDBWP4MjOKoe3HaUDMADc1 5Zv+4FIp/S5+HzoSngGukU5uKs/auHs= X-MC-Unique: F2B_XA0ANEaQ904gMYD_EA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/21] virQEMUBuildCommandLineJSON: Add possibility for using 'on/off' instead of 'yes/no' Date: Fri, 15 May 2020 17:27:54 +0200 Message-Id: <722fd285ab17e8574213b1d57e97863871455233.1589556042.git.pkrempa@redhat.com> 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.11 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" In some cases we use 'on/off' for command line arguments. Add a switch which will select the prefred spelling for a specific usage. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/util/virqemu.c | 44 ++++++++++++++++++++++++------------- src/util/virqemu.h | 10 ++++++--- tests/qemucommandutiltest.c | 2 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 0e6fa412bc..549f88fcd5 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -37,6 +37,7 @@ struct virQEMUCommandLineJSONIteratorData { const char *prefix; virBufferPtr buf; const char *skipKey; + bool onOff; virQEMUBuildCommandLineJSONArrayFormatFunc arrayFunc; }; @@ -46,6 +47,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatF= unc arrayFunc, bool nested); @@ -55,7 +57,8 @@ int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey G_GNUC_UNUSED) + const char *skipKey G_GNUC_UNUSED, + bool onOff G_GNUC_UNUSED) { ssize_t pos =3D -1; ssize_t end; @@ -84,7 +87,8 @@ int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey) + const char *skipKey, + bool onOff) { virJSONValuePtr member; size_t i; @@ -95,7 +99,7 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key, prefix =3D g_strdup_printf("%s.%zu", key, i); - if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKe= y, + if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKe= y, onOff, virQEMUBuildCommandLineJSON= ArrayNumbered, true) < 0) return 0; @@ -122,11 +126,11 @@ virQEMUBuildCommandLineJSONIterate(const char *key, tmpkey =3D g_strdup_printf("%s.%s", data->prefix, key); return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf, - data->skipKey, + data->skipKey, data->onO= ff, data->arrayFunc, false); } else { return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, - data->skipKey, + data->skipKey, data->onO= ff, data->arrayFunc, false); } } @@ -137,10 +141,11 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatF= unc arrayFunc, bool nested) { - struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, skipKey= , arrayFunc }; + struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, skipKey= , onOff, arrayFunc }; virJSONType type =3D virJSONValueGetType(value); virJSONValuePtr elem; bool tmp; @@ -165,10 +170,17 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, case VIR_JSON_TYPE_BOOLEAN: virJSONValueGetBoolean(value, &tmp); - if (tmp) - virBufferAsprintf(buf, "%s=3Dyes,", key); - else - virBufferAsprintf(buf, "%s=3Dno,", key); + if (onOff) { + if (tmp) + virBufferAsprintf(buf, "%s=3Don,", key); + else + virBufferAsprintf(buf, "%s=3Doff,", key); + } else { + if (tmp) + virBufferAsprintf(buf, "%s=3Dyes,", key); + else + virBufferAsprintf(buf, "%s=3Dno,", key); + } break; @@ -180,7 +192,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, return -1; } - if (!arrayFunc || arrayFunc(key, value, buf, skipKey) < 0) { + if (!arrayFunc || arrayFunc(key, value, buf, skipKey, onOff) < 0) { /* fallback, treat the array as a non-bitmap, adding the key * for each member */ for (i =3D 0; i < virJSONValueArraySize(value); i++) { @@ -188,7 +200,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, /* recurse to avoid duplicating code */ if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, ski= pKey, - arrayFunc, true) < = 0) + onOff, arrayFunc, t= rue) < 0) return -1; } } @@ -216,6 +228,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, * @value: json object containing the value * @buf: otuput buffer * @skipKey: name of key that will be handled separately by caller + * @onOff: Use 'on' and 'off' for boolean values rather than 'yes' and 'no' * @arrayFunc: array formatter function to allow for different syntax * * Formats JSON value object into command line parameters suitable for use= with @@ -227,9 +240,10 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatFunc arr= ay) { - if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, arra= y, false) < 0) + if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, skipKey, onOf= f, array, false) < 0) return -1; virBufferTrim(buf, ","); @@ -255,7 +269,7 @@ virQEMUBuildObjectCommandlineFromJSONInternal(virBuffer= Ptr buf, if (props) { virBufferAddLit(buf, ","); - if (virQEMUBuildCommandLineJSON(props, buf, NULL, + if (virQEMUBuildCommandLineJSON(props, buf, NULL, false, virQEMUBuildCommandLineJSONArrayBitmap) < = 0) return -1; } @@ -282,7 +296,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr sr= cdef) virBuffer buf =3D VIR_BUFFER_INITIALIZER; char *ret =3D NULL; - if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, + if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, false, virQEMUBuildCommandLineJSONArrayNumber= ed) < 0) goto cleanup; diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 9d3db7c2a2..67a5711613 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -30,19 +30,23 @@ typedef int (*virQEMUBuildCommandLineJSONArrayFormatFunc)(const char *key, virJSONValuePtr = array, virBufferPtr buf, - const char *skip= Key); + const char *skip= Key, + bool onOff); int virQEMUBuildCommandLineJSONArrayBitmap(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey); + const char *skipKey, + bool onOff); int virQEMUBuildCommandLineJSONArrayNumbered(const char *key, virJSONValuePtr array, virBufferPtr buf, - const char *skipKey); + const char *skipKey, + bool onOff); int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virBufferPtr buf, const char *skipKey, + bool onOff, virQEMUBuildCommandLineJSONArrayFormatFunc= array); int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index 923776e642..049fd2f0b0 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -47,7 +47,7 @@ testQemuCommandBuildFromJSON(const void *opaque) return -1; } - if (virQEMUBuildCommandLineJSON(val, &buf, NULL, data->arrayfunc) < 0)= { + if (virQEMUBuildCommandLineJSON(val, &buf, NULL, false, data->arrayfun= c) < 0) { fprintf(stderr, "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n", data->props); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556551; cv=none; d=zohomail.com; s=zohoarc; b=WFV7H3LaGoLONWGsbcW/UFXLfOaexRz+L5q7O/o/0+8et2D8fj6YIr0e5G06rMlrCSkH4Cjv3qZS0T9w1p3HiC06zs6dbUsB/PI9UcuOA6PjADM8cF8JP44NfevbI52apIAQzo0dWwkU4hUrqlMVFX4WH+Kb/H7tid72MlCZJWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556551; 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=s+vBExE3mYxQbNBCIr4ZpT9hh2sJPm7sCr6xUtPNkv8=; b=JqJDV9VwSVj+Y1llGpUtRp2U5a9pxt55EBnQjfaWDbxJWrJ/QxEVITsgfxJibdHrvPoVZA066AHKBKBy4n4fS9TJ2eIQkkxB0hRTaon1opOaArpPB1Nn/WrMwQXXejRKxfa/l6Yjg0qlkCqMFQy6b6ppPN2VojcKCZdBO6ssUkU= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1589556551688145.87368795262012; Fri, 15 May 2020 08:29:11 -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-373-JlaVWxY0PoaEZXxPJML58g-1; Fri, 15 May 2020 11:29:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEC86460; Fri, 15 May 2020 15:29:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A09E062491; Fri, 15 May 2020 15:29:02 +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 7021C180954D; Fri, 15 May 2020 15:29:02 +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 04FFT14v011298 for ; Fri, 15 May 2020 11:29:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A1D55D9D7; Fri, 15 May 2020 15:29:01 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 789A95D9F5 for ; Fri, 15 May 2020 15:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556550; 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=s+vBExE3mYxQbNBCIr4ZpT9hh2sJPm7sCr6xUtPNkv8=; b=F9rIz/Yw2hgqsXyaCaYaxeFmMoamDkfPGotYWEoepOy7ji3bcSQCpH7tS2dWEQsC20bIPk er6+wAr9NNOGkW1KRCoHW76Rs/cigsnmzuaEc5Pvfwk3Nv5zBR8uRuK5h7inVZsV5IFHuI hT3ZGmx+mwHusfCxoHjbrAUsScWHyng= X-MC-Unique: JlaVWxY0PoaEZXxPJML58g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/21] virCommand: Introduce virCommandGetArgList Date: Fri, 15 May 2020 17:27:55 +0200 Message-Id: <61711e0e2ac77569b0d91393c68dad6ef40cb7cd.1589556042.git.pkrempa@redhat.com> 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.15 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" The helper returns a list of arguments of a virCommand. This will be useful in tests where we'll inspect certain already formatted arguments. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/libvirt_private.syms | 1 + src/util/vircommand.c | 23 +++++++++++++++++++++++ src/util/vircommand.h | 1 + 3 files changed, 25 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 935ef7303b..31813f177f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1841,6 +1841,7 @@ virCommandDaemonize; virCommandDoAsyncIO; virCommandExec; virCommandFree; +virCommandGetArgList; virCommandGetGID; virCommandGetUID; virCommandHandshakeNotify; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 20f196104f..aae0ddb730 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2132,6 +2132,29 @@ virCommandToString(virCommandPtr cmd, bool linebreak= s) } +int +virCommandGetArgList(virCommandPtr cmd, + char ***args, + size_t *nargs) +{ + size_t i; + + if (cmd->has_error) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid use of command API")); + return -1; + } + + *args =3D g_new0(char *, cmd->nargs); + *nargs =3D cmd->nargs - 1; + + for (i =3D 1; i < cmd->nargs; i++) + (*args)[i - 1] =3D g_strdup(cmd->args[i]); + + return 0; +} + + #ifndef WIN32 /* * Manage input and output to the child process. diff --git a/src/util/vircommand.h b/src/util/vircommand.h index e2be5bcf1c..ff8a785dbe 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -170,6 +170,7 @@ void virCommandWriteArgLog(virCommandPtr cmd, int logfd); char *virCommandToString(virCommandPtr cmd, bool linebreaks) G_GNUC_WARN_U= NUSED_RESULT; +int virCommandGetArgList(virCommandPtr cmd, char ***args, size_t *nargs); int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) G_GNUC_W= ARN_UNUSED_RESULT; --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1589556607; cv=none; d=zohomail.com; s=zohoarc; b=bF58JS7ggS9NAm+ENd7Rvkj3SbtwiuTta9UqK9pAoBX5aD/Y8gmLHm3ouR8oF/R8KyVyY4Mg9jD+U1/FVfQAECOnWvUeqt8pWn1t7DjELZdzOm3LjK6nWMXxEhSDaT2mglwL8eKkqraOozsVcOBhFniMd3hydMkNDOdhtYb4rHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556607; 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=MAVmjCdnlUnaQ9pGkdCi/Ta8qcl07KoHFqr2H8RnMEY=; b=nlC4ZVm2qUiNpruEWhcS7Wait3aaeEG6dC22dba6FzyuWvJq6MmAROP6oRdILwQ9nH5Q/mQJzElrsFv9KyJYNBCctECpCPSzHbo6b65/hBcnpPKxMQErJ2TAxPIDDIt1Ql1gdopDw3qGySNvvpOaZIKY141U7M5fCnNqqY4j9X4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1589556607430617.0558370821551; Fri, 15 May 2020 08:30:07 -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-512-MKTnFJCKNSuFWIoWWhm74Q-1; Fri, 15 May 2020 11:29:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46ED61054F93; Fri, 15 May 2020 15:29:09 +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 27C7362491; Fri, 15 May 2020 15:29:09 +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 EE41A4E9FA; Fri, 15 May 2020 15:29:08 +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 04FFT83U011325 for ; Fri, 15 May 2020 11:29:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15AB45D9F5; Fri, 15 May 2020 15:29:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 826005D9D7 for ; Fri, 15 May 2020 15:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556605; 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=MAVmjCdnlUnaQ9pGkdCi/Ta8qcl07KoHFqr2H8RnMEY=; b=aOOzElFJc9Q1wqX8lnzIgRxYAaQ2kwhUijaFusmGyEnLMtVwhr4RmFxujHEK3V79OMk4fy Px3pcQmals82XoALkRHbniPGoN/A611Q7783uJ4DePeAY2IVnijhdfK4gU4EBrqEuVldb2 KOwJdiQXAMEkBk5KnWKveTgqhcj7/0I= X-MC-Unique: MKTnFJCKNSuFWIoWWhm74Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/21] util: json: Introduce virJSONValueObjectAppendStringPrintf Date: Fri, 15 May 2020 17:27:56 +0200 Message-Id: <05c597710717eabf17748b3c290b2eb76a598192.1589556042.git.pkrempa@redhat.com> 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.15 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" Add a variant similar to virJSONValueObjectAppendString which also formats more complex value strings with printf syntax. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/libvirt_private.syms | 1 + src/util/virjson.c | 17 +++++++++++++++++ src/util/virjson.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 31813f177f..1bd02fd8ee 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2361,6 +2361,7 @@ virJSONValueObjectAppendNumberLong; virJSONValueObjectAppendNumberUint; virJSONValueObjectAppendNumberUlong; virJSONValueObjectAppendString; +virJSONValueObjectAppendStringPrintf; virJSONValueObjectCreate; virJSONValueObjectCreateVArgs; virJSONValueObjectDeflatten; diff --git a/src/util/virjson.c b/src/util/virjson.c index dc662bf8e9..6921eccb60 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -649,6 +649,23 @@ virJSONValueObjectAppendString(virJSONValuePtr object, } +int +virJSONValueObjectAppendStringPrintf(virJSONValuePtr object, + const char *key, + const char *fmt, + ...) +{ + va_list ap; + g_autofree char *str =3D NULL; + + va_start(ap, fmt); + str =3D g_strdup_vprintf(fmt, ap); + va_end(ap); + + return virJSONValueObjectInsertString(object, key, str, false); +} + + int virJSONValueObjectPrependString(virJSONValuePtr object, const char *key, diff --git a/src/util/virjson.h b/src/util/virjson.h index 0894e91b59..588c977650 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -127,6 +127,8 @@ int virJSONValueObjectGetBoolean(virJSONValuePtr object= , const char *key, bool * int virJSONValueObjectIsNull(virJSONValuePtr object, const char *key); int virJSONValueObjectAppendString(virJSONValuePtr object, const char *key= , const char *value); +int virJSONValueObjectAppendStringPrintf(virJSONValuePtr object, const cha= r *key, const char *fmt, ...) + G_GNUC_PRINTF(3, 4); int virJSONValueObjectPrependString(virJSONValuePtr object, const char *ke= y, const char *value); int virJSONValueObjectAppendNumberInt(virJSONValuePtr object, const char *= key, int number); int virJSONValueObjectAppendNumberUint(virJSONValuePtr object, const char = *key, unsigned int number); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556564; cv=none; d=zohomail.com; s=zohoarc; b=VjQ6VFjE1AARUFJUlF9vNijnMBPm0x39ks/u8RCXZEj3CR+NwsL1ydLQKuNpSwrQ0alroPJkIIkNQqYeHzK2cfJKGiXqjXg2SOJ65vidOUhxq6yq+bGVVjoto8jL571oNZQ71/v9s6Dv3u5yiXwZIf6OCGhHXrxJITgV6YR8tE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556564; 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=9elEN5XDQo3UGkuPHKOkKr8mrJE6qteJbRLmY7XgauY=; b=AjbcZ5XGK8O6wVesdCmEwCKGgLOxyAx9z9W77yoEFAucBJOGsZrxA2Nt70mR/oN4mP1RBSG6pqDcMIJvkEY5UuFc9txzottTBG9E6TQSGHe/BQNjrp82gtD8rn2lFkoxgDu/w3w/SRwTyBWWoATR4NnafVKYn3C2grbDNHvOXsU= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1589556564519428.6723413935148; Fri, 15 May 2020 08:29:24 -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-43-BTJPVZnXM0KKmcB-4uMj-w-1; Fri, 15 May 2020 11:29:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC1EC460; Fri, 15 May 2020 15:29:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6C291024837; Fri, 15 May 2020 15:29:12 +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 9612F1809563; Fri, 15 May 2020 15:29:12 +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 04FFTBMk011342 for ; Fri, 15 May 2020 11:29:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23F035D9FC; Fri, 15 May 2020 15:29:11 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 925705D9D7 for ; Fri, 15 May 2020 15:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556562; 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=9elEN5XDQo3UGkuPHKOkKr8mrJE6qteJbRLmY7XgauY=; b=ROT2soeZOK51ayGUYJ/qfHs2q+r3woTEWaMacQXlYfBp6jjnG/wUMvD2H3N6OIDcUS0GpP PBfhLHVuOFmpCvJ/5v/iCi/r6MqOR1IXiiKXf0+MBeLYTp4OcsPTg8XqdW5y7DJTK/gdAw OJiRC6ooK7O3TakZPC/yqmSMYtMQlT4= X-MC-Unique: BTJPVZnXM0KKmcB-4uMj-w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/21] testCompareXMLToArgv: Split out preparation and command formatting Date: Fri, 15 May 2020 17:27:57 +0200 Message-Id: <75386a572194547107d22758e951a887277dd235.1589556042.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" There are multiple steps of setting up the domain definition prior to formatting the command line for the tests. Extract it to a separate function so that it's self-contained and also will allow re-running the command line formatting which will be necessary for QMP schema validation tests. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- tests/qemuxml2argvtest.c | 158 +++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 43e76956cc..9fa1afd9d0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -391,6 +391,90 @@ testCheckExclusiveFlags(int flags) } +static virCommandPtr +testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, + virDomainObjPtr vm, + const char *migrateURI, + struct testQemuInfo *info, + unsigned int flags) +{ + size_t i; + + for (i =3D 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev =3D vm->def->hostdevs[i]; + + if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_T= YPE_PCI && + hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV= _PCI_BACKEND_DEFAULT) { + hostdev->source.subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PC= I_BACKEND_VFIO; + } + } + + for (i =3D 0; i < vm->def->nfss; i++) { + virDomainFSDefPtr fs =3D vm->def->fss[i]; + char *s; + + if (fs->fsdriver !=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS || + QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock) + continue; + + s =3D g_strdup_printf("/tmp/lib/domain--1-guest/fs%zu.vhost-fs.soc= k", i); + QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock =3D s; + } + + if (vm->def->vsock) { + virDomainVsockDefPtr vsock =3D vm->def->vsock; + qemuDomainVsockPrivatePtr vsockPriv =3D + (qemuDomainVsockPrivatePtr)vsock->privateData; + + if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) + vsock->guest_cid =3D 42; + + vsockPriv->vhostfd =3D 6789; + } + + if (vm->def->tpm) { + switch (vm->def->tpm->type) { + case VIR_DOMAIN_TPM_TYPE_EMULATOR: + VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path); + vm->def->tpm->data.emulator.source.data.file.path =3D g_strdup= ("/dev/test"); + vm->def->tpm->data.emulator.source.type =3D VIR_DOMAIN_CHR_TYP= E_FILE; + break; + case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: + case VIR_DOMAIN_TPM_TYPE_LAST: + break; + } + } + + for (i =3D 0; i < vm->def->nvideos; i++) { + virDomainVideoDefPtr video =3D vm->def->videos[i]; + + if (video->backend =3D=3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER)= { + qemuDomainVideoPrivatePtr vpriv =3D QEMU_DOMAIN_VIDEO_PRIVATE(= video); + + vpriv->vhost_user_fd =3D 1729; + } + } + + if (flags & FLAG_SLIRP_HELPER) { + for (i =3D 0; i < vm->def->nnets; i++) { + virDomainNetDefPtr net =3D vm->def->nets[i]; + + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_USER && + virQEMUCapsGet(info->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) { + qemuSlirpPtr slirp =3D qemuSlirpNew(); + slirp->fd[0] =3D 42; + QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp =3D slirp; + } + } + } + + return qemuProcessCreatePretendCmd(drv, vm, migrateURI, + (flags & FLAG_FIPS), false, + VIR_QEMU_PROCESS_START_COLD); +} + + static int testCompareXMLToArgv(const void *data) { @@ -405,7 +489,6 @@ testCompareXMLToArgv(const void *data) virConnectPtr conn; char *log =3D NULL; virCommandPtr cmd =3D NULL; - size_t i; qemuDomainObjPrivatePtr priv =3D NULL; if (info->arch !=3D VIR_ARCH_NONE && info->arch !=3D VIR_ARCH_X86_64) @@ -482,77 +565,8 @@ testCompareXMLToArgv(const void *data) VIR_FREE(log); virResetLastError(); - for (i =3D 0; i < vm->def->nhostdevs; i++) { - virDomainHostdevDefPtr hostdev =3D vm->def->hostdevs[i]; - - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_T= YPE_PCI && - hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV= _PCI_BACKEND_DEFAULT) { - hostdev->source.subsys.u.pci.backend =3D VIR_DOMAIN_HOSTDEV_PC= I_BACKEND_VFIO; - } - } - - for (i =3D 0; i < vm->def->nfss; i++) { - virDomainFSDefPtr fs =3D vm->def->fss[i]; - char *s; - - if (fs->fsdriver !=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) - continue; - - s =3D g_strdup_printf("/tmp/lib/domain--1-guest/fs%zu.vhost-fs.soc= k", i); - QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock =3D s; - } - - if (vm->def->vsock) { - virDomainVsockDefPtr vsock =3D vm->def->vsock; - qemuDomainVsockPrivatePtr vsockPriv =3D - (qemuDomainVsockPrivatePtr)vsock->privateData; - - if (vsock->auto_cid =3D=3D VIR_TRISTATE_BOOL_YES) - vsock->guest_cid =3D 42; - - vsockPriv->vhostfd =3D 6789; - } - - if (vm->def->tpm) { - switch (vm->def->tpm->type) { - case VIR_DOMAIN_TPM_TYPE_EMULATOR: - VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path); - vm->def->tpm->data.emulator.source.data.file.path =3D g_strdup= ("/dev/test"); - vm->def->tpm->data.emulator.source.type =3D VIR_DOMAIN_CHR_TYP= E_FILE; - break; - case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: - case VIR_DOMAIN_TPM_TYPE_LAST: - break; - } - } - - for (i =3D 0; i < vm->def->nvideos; i++) { - virDomainVideoDefPtr video =3D vm->def->videos[i]; - - if (video->backend =3D=3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER)= { - qemuDomainVideoPrivatePtr vpriv =3D QEMU_DOMAIN_VIDEO_PRIVATE(= video); - - vpriv->vhost_user_fd =3D 1729; - } - } - - if (flags & FLAG_SLIRP_HELPER) { - for (i =3D 0; i < vm->def->nnets; i++) { - virDomainNetDefPtr net =3D vm->def->nets[i]; - - if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_USER && - virQEMUCapsGet(info->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) { - qemuSlirpPtr slirp =3D qemuSlirpNew(); - slirp->fd[0] =3D 42; - QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp =3D slirp; - } - } - } - - if (!(cmd =3D qemuProcessCreatePretendCmd(&driver, vm, migrateURI, - (flags & FLAG_FIPS), false, - VIR_QEMU_PROCESS_START_COLD)))= { + if (!(cmd =3D testCompareXMLToArgvCreateArgs(&driver, vm, migrateURI, = info, + flags))) { if (flags & FLAG_EXPECT_FAILURE) goto ok; goto cleanup; --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556564; cv=none; d=zohomail.com; s=zohoarc; b=YOQuPnA+9n0itFs4Qx//EF8Fu9cBkNd0+Dyib5xj4IjXLq7FOg83ExbydasqawkPaF1XcdKH/2PV2t/UwkLXhJIPT1qY9Uzt8Y+iFMGAM1Vqb2hZGSO/Ue7Ioc1uRaJz/vhVwsEDTR6vNk/GKvdfGAlufNvZe+AhWgdTEbWTSck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556564; 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=dUqAaEOBloViLA1zF/ponWt0gEoWt4I1HFjA7JKJYpo=; b=PHcVLVfRzF/gEhNHMzorZN4tL6WBzmfiV0cltWj/up+OnColpI04DKSuGtAvSpy0hGotdLipouMIUc01iVKzfRQhhK+tavW68pvP6VDUEeLh7AlFf9He56Z2CW+KJsBgZq51x/Islc24vKKcBeJ9SQzCJPEUJZMMROD8sHa+fVY= 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 1589556564074448.4716846659113; Fri, 15 May 2020 08:29:24 -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-163-j-qk03g_Ozqfa0CIWNjcIA-1; Fri, 15 May 2020 11:29:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F6B618FE863; Fri, 15 May 2020 15:29:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F20F5C583; Fri, 15 May 2020 15:29:15 +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 EF9F41800430; Fri, 15 May 2020 15:29:14 +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 04FFTCMO011347 for ; Fri, 15 May 2020 11:29:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1163A5D9D7; Fri, 15 May 2020 15:29:12 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CB875D9C9 for ; Fri, 15 May 2020 15:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556562; 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=dUqAaEOBloViLA1zF/ponWt0gEoWt4I1HFjA7JKJYpo=; b=IPnWZZTnPltraTs/GTcSmBV9F+R9kQNip4tNM7qrd8IHjjzSyvFpD8gCjYi9HLNYUiXHhN sv8phjvVucjX38R9nvpBTeG0FsFSmnKzQsZ7YpsmDY+vDxhSkaZSwFGpOZAMZKEAty5r3e KA0Tni2iSO0lwTkNwHBxitfTMepm/2w= X-MC-Unique: j-qk03g_Ozqfa0CIWNjcIA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/21] qemuMonitorJSON(Add|Remove)Netdev: Refactor cleanup Date: Fri, 15 May 2020 17:27:58 +0200 Message-Id: <5dc243add944782a79f9261c52cee1bfecfe3750.1589556042.git.pkrempa@redhat.com> 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.16 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" Use automatic pointer cleanup for virJSONValuePtrs to get rid of the cleanup label and ret variable. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_monitor_json.c | 52 +++++++++++++++--------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 66422a8489..1224d1c9cc 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3984,13 +3984,13 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr m= on, } -int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, - const char *netdevstr) +int +qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, + const char *netdevstr) { - int ret =3D -1; - virJSONValuePtr cmd =3D NULL; - virJSONValuePtr reply =3D NULL; - virJSONValuePtr args =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + g_autoptr(virJSONValue) args =3D NULL; cmd =3D qemuMonitorJSONMakeCommand("netdev_add", NULL); if (!cmd) @@ -3998,49 +3998,41 @@ int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, args =3D qemuMonitorJSONKeywordStringToJSON(netdevstr, "type"); if (!args) - goto cleanup; + return -1; if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) - goto cleanup; + return -1; args =3D NULL; /* obj owns reference to args now */ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - virJSONValueFree(args); - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return 0; } -int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon, - const char *alias) +int +qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon, + const char *alias) { - int ret =3D -1; - virJSONValuePtr cmd =3D qemuMonitorJSONMakeCommand("netdev_del", - "s:id", alias, - NULL); - virJSONValuePtr reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D qemuMonitorJSONMakeCommand("netdev_del= ", + "s:id", alias, + NULL); + g_autoptr(virJSONValue) reply =3D NULL; + if (!cmd) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return 0; } --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556563; cv=none; d=zohomail.com; s=zohoarc; b=cQ/6w94hHF/fUNtfMwzc7iu45hDRvuA6/T8vpgi4UO6SAC52m9SzkIH+eJ4yIb5qXX6L0p26HF/LW0okuOWx/vzgUcnK8dgOf1ujsRhUKk9o/ImkfpURf3zusFHBjsVvcLV0fGspZvlbg1eKgIYrTCDhWuzpZRvbY/3b1H94rsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556563; 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=73w4syxht8171IKgrY0s5Qc0uOeCk41q0p3AOn+ZPGU=; b=T5JDT9wGm/2rplfbWYzag//1TkL4Dqs58nIkD0KO8WB9L+yJu5r24gu6N8ZbGnG9a4evnryAq6/b0klzggFkaxHSafF6/9jPeHvj3HoDQ2Ozwnh5TjSHFvFsMUxfYNkltHi9IJU7z+QugCDlfuhJz0ZRnpNiRcFf7j7soH9/ZoQ= 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 1589556563537949.3912592901265; Fri, 15 May 2020 08:29:23 -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-357-0hLeFZGvMX6fz22FP6g-xw-1; Fri, 15 May 2020 11:29:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85EA2107ACCD; Fri, 15 May 2020 15:29:14 +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 5EC8E1024837; Fri, 15 May 2020 15:29:14 +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 30AD64EA01; Fri, 15 May 2020 15:29:14 +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 04FFTDnA011357 for ; Fri, 15 May 2020 11:29:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 30F0A5D9D7; Fri, 15 May 2020 15:29:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C79D5D9C9 for ; Fri, 15 May 2020 15:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556562; 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=73w4syxht8171IKgrY0s5Qc0uOeCk41q0p3AOn+ZPGU=; b=MM7GhsOyBw8x7N18ai4zThqaIGMpe3wqARHAWMROvRfkkwF6e8KcEFJ6GV5xs64UuHdS0z r1AtxJXrj263IL83qCjw/5jkCKnubs2JfBejt7eb2rlHzfXJDV7jJ8S40VjoE2FkSX8ej0 QYVUxnH+WbWOP5hdamfPi04l95gw6RI= X-MC-Unique: 0hLeFZGvMX6fz22FP6g-xw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/21] util: virqemu: Introduce virQEMUBuildNetdevCommandlineFromJSON Date: Fri, 15 May 2020 17:27:59 +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.84 on 10.5.11.22 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" In preparation for converting the generator of -netdev to generate JSON which will be used to do the command line rather than the other way around we need to introduce a convertor which properly configures virQEMUBuildCommandLineJSON for the quirks of -netdev. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/libvirt_private.syms | 1 + src/util/virqemu.c | 22 ++++++++++++++++++++++ src/util/virqemu.h | 3 +++ 3 files changed, 26 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1bd02fd8ee..fd04fcece3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2915,6 +2915,7 @@ virQEMUBuildCommandLineJSON; virQEMUBuildCommandLineJSONArrayBitmap; virQEMUBuildCommandLineJSONArrayNumbered; virQEMUBuildDriveCommandlineFromJSON; +virQEMUBuildNetdevCommandlineFromJSON; virQEMUBuildObjectCommandlineFromJSON; virQEMUBuildQemuImgKeySecretOpts; diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 549f88fcd5..0f8cab29df 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -252,6 +252,28 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value, } +/** + * virQEMUBuildNetdevCommandlineFromJSON: + * @props: JSON properties describing a netdev + * + * Converts @props into arguments for -netdev including all the quirks and + * differences between the monitor and command line syntax. + */ +char * +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props) +{ + const char *type =3D virJSONValueObjectGetString(props, "type"); + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, "%s,", type); + + if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, NULL) < 0) + return NULL; + + return virBufferContentAndReset(&buf); +} + + static int virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf, const char *type, diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 67a5711613..22f47851df 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -49,6 +49,9 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value, bool onOff, virQEMUBuildCommandLineJSONArrayFormatFunc= array); +char * +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props); + int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, virJSONValuePtr objprops); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1589556569; cv=none; d=zohomail.com; s=zohoarc; b=eCGbgduxgHOhMh4lDtc7X3vdjAMbwhDsueL1NhlByt/Wd0Fg8e6I3s0Ff4Cg0VAMkL6f3wVkwMLhoyMpjKAMslmSeI5TR2WqNHtz9vkz8601hREle8Foxmn1+xKGrkBkWUXeIcv/mLaKrd+lgkZNwthjtI2Jnz+hfNfjX3ssNTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556569; 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=T7XV6Wu+jHKrquorpWTjqEuO1wbQZ9S8RAI3QNGXgxw=; b=ETktP9pdt91u4DX6OnUG8xdy94yo5X8lEMwLvErhZOMLoEBc6hPDuWHvOVZp/aEzvJivbjHaHG0ZREd4E9nxGxCGLw+abobJlnNc5jzVqNj/jW0fQ0qRpzNXuBDeSef9u+txF/XqEDM2h3E/7ktBbEF8DAIDWR4/jSnl95AN6JY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1589556569491393.6488846471701; Fri, 15 May 2020 08:29:29 -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-324-Svpka2IBOimGT8SxbDCNgg-1; Fri, 15 May 2020 11:29:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2756835BC2; Fri, 15 May 2020 15:29:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A2C4763BAD; Fri, 15 May 2020 15:29:19 +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 6CB6B1806B0B; Fri, 15 May 2020 15:29:19 +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 04FFTHYe011386 for ; Fri, 15 May 2020 11:29:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id C247C5D9F5; Fri, 15 May 2020 15:29:17 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 385125D9D7 for ; Fri, 15 May 2020 15:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556568; 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=T7XV6Wu+jHKrquorpWTjqEuO1wbQZ9S8RAI3QNGXgxw=; b=BSqT6IQc2rEB6sDJw7J/9R4f7S3Q/xwaBLHQsVK1GY9XsOwfU16u7M5s9G8UaenfGHUgka ktQ8YmOjpWOShesMc2iiyCv3zkXxdTeLQj4CDD8ysRDDvYWxqTFVr82USCU9pwmI89W0te vqTA/FGutidNNmWVPd0yMiUAEDSjWI4= X-MC-Unique: Svpka2IBOimGT8SxbDCNgg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/21] qemu: command: Generate -netdev command line via JSON->cmdline conversion Date: Fri, 15 May 2020 17:28:00 +0200 Message-Id: <94e6ce557a3c6d1d2d808720cddfcacb63652d70.1589556042.git.pkrempa@redhat.com> 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.11 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" The 'netdev_add' command was recently formally described in qemu via the QMP schema. This means that it also requires the arguments to be properly formatted. Our current approach is to generate the command line and then use qemuMonitorJSONKeywordStringToJSON to get the JSON properties for the monitor. This will not work if we need to pass some fields as numbers or booleans. In this step we re-do internals of qemuBuildHostNetStr to format a JSON object which is converted back via virQEMUBuildNetdevCommandlineFromJSON to the equivalent command line. This will later allow fixing of the monitor code to use the JSON object directly rather than rely on the conversion. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 163 +++++++++++++++++++++++++--------------- src/qemu/qemu_command.h | 12 +-- src/qemu/qemu_hotplug.c | 13 +++- 3 files changed, 119 insertions(+), 69 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2850953bd0..00d1b4121d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3564,7 +3564,7 @@ qemuBuildNicDevStr(virDomainDefPtr def, } -char * +virJSONValuePtr qemuBuildHostNetStr(virDomainNetDefPtr net, char **tapfd, size_t tapfdSize, @@ -3573,10 +3573,11 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, const char *slirpfd) { bool is_tap =3D false; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; virDomainNetType netType =3D virDomainNetGetActualType(net); size_t i; + g_autoptr(virJSONValue) netprops =3D NULL; + if (net->script && netType !=3D VIR_DOMAIN_NET_TYPE_ETHERNET) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("scripts are not supported on interfaces of type = %s"), @@ -3594,54 +3595,75 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_DIRECT: case VIR_DOMAIN_NET_TYPE_ETHERNET: - virBufferAddLit(&buf, "tap,"); + if (virJSONValueObjectCreate(&netprops, "s:type", "tap", NULL) < 0) + return NULL; + /* for one tapfd 'fd=3D' shall be used, * for more than one 'fds=3D' is the right choice */ if (tapfdSize =3D=3D 1) { - virBufferAsprintf(&buf, "fd=3D%s,", tapfd[0]); + if (virJSONValueObjectAdd(netprops, "s:fd", tapfd[0], NULL) < = 0) + return NULL; } else { - virBufferAddLit(&buf, "fds=3D"); - for (i =3D 0; i < tapfdSize; i++) { - if (i) - virBufferAddChar(&buf, ':'); - virBufferAdd(&buf, tapfd[i], -1); - } - virBufferAddChar(&buf, ','); + g_auto(virBuffer) fdsbuf =3D VIR_BUFFER_INITIALIZER; + + for (i =3D 0; i < tapfdSize; i++) + virBufferAsprintf(&fdsbuf, "%s:", tapfd[i]); + + virBufferTrim(&fdsbuf, ":"); + + if (virJSONValueObjectAdd(netprops, + "s:fds", virBufferCurrentContent(&fd= sbuf), + NULL) < 0) + return NULL; } + is_tap =3D true; break; case VIR_DOMAIN_NET_TYPE_CLIENT: - virBufferAsprintf(&buf, "socket,connect=3D%s:%d,", - net->data.socket.address, - net->data.socket.port); + if (virJSONValueObjectCreate(&netprops, "s:type", "socket", NULL) = < 0 || + virJSONValueObjectAppendStringPrintf(netprops, "connect", "%s:= %d", + net->data.socket.address, + net->data.socket.port) < = 0) + return NULL; break; case VIR_DOMAIN_NET_TYPE_SERVER: - virBufferAsprintf(&buf, "socket,listen=3D%s:%d,", - NULLSTR_EMPTY(net->data.socket.address), - net->data.socket.port); + if (virJSONValueObjectCreate(&netprops, "s:type", "socket", NULL) = < 0 || + virJSONValueObjectAppendStringPrintf(netprops, "listen", "%s:%= d", + NULLSTR_EMPTY(net->data.s= ocket.address), + net->data.socket.port) < = 0) + return NULL; break; case VIR_DOMAIN_NET_TYPE_MCAST: - virBufferAsprintf(&buf, "socket,mcast=3D%s:%d,", - net->data.socket.address, - net->data.socket.port); + if (virJSONValueObjectCreate(&netprops, "s:type", "socket", NULL) = < 0 || + virJSONValueObjectAppendStringPrintf(netprops, "mcast", "%s:%d= ", + net->data.socket.address, + net->data.socket.port) < = 0) + return NULL; break; case VIR_DOMAIN_NET_TYPE_UDP: - virBufferAsprintf(&buf, "socket,udp=3D%s:%d,localaddr=3D%s:%d,", - net->data.socket.address, - net->data.socket.port, - net->data.socket.localaddr, - net->data.socket.localport); + if (virJSONValueObjectCreate(&netprops, "s:type", "socket", NULL) = < 0 || + virJSONValueObjectAppendStringPrintf(netprops, "udp", "%s:%d", + net->data.socket.address, + net->data.socket.port) < = 0 || + virJSONValueObjectAppendStringPrintf(netprops, "localaddr", "%= s:%d", + net->data.socket.localadd= r, + net->data.socket.localpor= t) < 0) + return NULL; break; case VIR_DOMAIN_NET_TYPE_USER: if (slirpfd) { - virBufferAsprintf(&buf, "socket,fd=3D%s,", slirpfd); + if (virJSONValueObjectCreate(&netprops, "s:type", "socket", NU= LL) < 0 || + virJSONValueObjectAppendString(netprops, "fd", slirpfd) < = 0) + return NULL; } else { - virBufferAddLit(&buf, "user,"); + if (virJSONValueObjectCreate(&netprops, "s:type", "user", NULL= ) < 0) + return NULL; + for (i =3D 0; i < net->guestIP.nips; i++) { const virNetDevIPAddr *ip =3D net->guestIP.ips[i]; g_autofree char *addr =3D NULL; @@ -3650,29 +3672,40 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, return NULL; if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { - virBufferAsprintf(&buf, "net=3D%s", addr); + g_autofree char *ipv4netaddr =3D NULL; + if (ip->prefix) - virBufferAsprintf(&buf, "/%u", ip->prefix); - virBufferAddChar(&buf, ','); + ipv4netaddr =3D g_strdup_printf("%s/%u", addr, ip-= >prefix); + else + ipv4netaddr =3D g_strdup(addr); + + if (virJSONValueObjectAppendString(netprops, "net", ip= v4netaddr) < 0) + return NULL; } else if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET= 6)) { - virBufferAsprintf(&buf, "ipv6-prefix=3D%s,", addr); - if (ip->prefix) - virBufferAsprintf(&buf, "ipv6-prefixlen=3D%u,", ip= ->prefix); + if (virJSONValueObjectAppendString(netprops, "ipv6-pre= fix", addr) < 0) + return NULL; + if (ip->prefix && + virJSONValueObjectAppendNumberUlong(netprops, "ipv= 6-prefixlen", + ip->prefix) < = 0) + return NULL; } } } break; case VIR_DOMAIN_NET_TYPE_INTERNAL: - virBufferAddLit(&buf, "user,"); + if (virJSONValueObjectCreate(&netprops, "s:type", "user", NULL) < = 0) + return NULL; break; case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - virBufferAsprintf(&buf, "vhost-user,chardev=3Dchar%s,", - net->info.alias); - if (net->driver.virtio.queues > 1) - virBufferAsprintf(&buf, "queues=3D%u,", - net->driver.virtio.queues); + if (virJSONValueObjectCreate(&netprops, "s:type", "vhost-user", NU= LL) < 0 || + virJSONValueObjectAppendStringPrintf(netprops, "chardev", "cha= r%s", net->info.alias) < 0) + return NULL; + + if (net->driver.virtio.queues > 1 && + virJSONValueObjectAppendNumberUlong(netprops, "queues", net->d= river.virtio.queues) < 0) + return NULL; break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: @@ -3681,31 +3714,38 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, break; } - virBufferAsprintf(&buf, "id=3Dhost%s,", net->info.alias); + if (virJSONValueObjectAppendStringPrintf(netprops, "id", "host%s", net= ->info.alias) < 0) + return NULL; if (is_tap) { if (vhostfdSize) { - virBufferAddLit(&buf, "vhost=3Don,"); + if (virJSONValueObjectAppendBoolean(netprops, "vhost", true) <= 0) + return NULL; + if (vhostfdSize =3D=3D 1) { - virBufferAsprintf(&buf, "vhostfd=3D%s,", vhostfd[0]); + if (virJSONValueObjectAdd(netprops, "s:vhostfd", vhostfd[0= ], NULL) < 0) + return NULL; } else { - virBufferAddLit(&buf, "vhostfds=3D"); - for (i =3D 0; i < vhostfdSize; i++) { - if (i) - virBufferAddChar(&buf, ':'); - virBufferAdd(&buf, vhostfd[i], -1); - } - virBufferAddChar(&buf, ','); + g_auto(virBuffer) fdsbuf =3D VIR_BUFFER_INITIALIZER; + + for (i =3D 0; i < vhostfdSize; i++) + virBufferAsprintf(&fdsbuf, "%s:", vhostfd[i]); + + virBufferTrim(&fdsbuf, ":"); + + if (virJSONValueObjectAdd(netprops, + "s:vhostfds", virBufferCurrentCo= ntent(&fdsbuf), + NULL) < 0) + return NULL; } } - if (net->tune.sndbuf_specified) - virBufferAsprintf(&buf, "sndbuf=3D%lu,", net->tune.sndbuf); - } - - virBufferTrim(&buf, ","); + if (net->tune.sndbuf_specified && + virJSONValueObjectAppendNumberUlong(netprops, "sndbuf", net->t= une.sndbuf) < 0) + return NULL; + } - return virBufferContentAndReset(&buf); + return g_steal_pointer(&netprops); } @@ -7670,6 +7710,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, bool requireNicdev =3D false; qemuSlirpPtr slirp; size_t i; + g_autoptr(virJSONValue) hostnetprops =3D NULL; if (!bootindex) @@ -7873,11 +7914,15 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driv= er, if (chardev) virCommandAddArgList(cmd, "-chardev", chardev, NULL); - if (!(host =3D qemuBuildHostNetStr(net, - tapfdName, tapfdSize, - vhostfdName, vhostfdSize, - slirpfdName))) + if (!(hostnetprops =3D qemuBuildHostNetStr(net, + tapfdName, tapfdSize, + vhostfdName, vhostfdSize, + slirpfdName))) goto cleanup; + + if (!(host =3D virQEMUBuildNetdevCommandlineFromJSON(hostnetprops))) + goto cleanup; + virCommandAddArgList(cmd, "-netdev", host, NULL); /* Possible combinations: diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 7665b68548..6cdd9debe0 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -89,12 +89,12 @@ qemuBuildChrDeviceStr(char **deviceStr, char * qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr); -char *qemuBuildHostNetStr(virDomainNetDefPtr net, - char **tapfd, - size_t tapfdSize, - char **vhostfd, - size_t vhostfdSize, - const char *slirpfd); +virJSONValuePtr qemuBuildHostNetStr(virDomainNetDefPtr net, + char **tapfd, + size_t tapfdSize, + char **vhostfd, + size_t vhostfdSize, + const char *slirpfd); /* Current, best practice */ char *qemuBuildNicDevStr(virDomainDefPtr def, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 2976ba7647..c6789dcef3 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -54,6 +54,7 @@ #include "virstoragefile.h" #include "virstring.h" #include "virtime.h" +#include "virqemu.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -1157,6 +1158,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, size_t vhostfdSize =3D 0; size_t queueSize =3D 0; g_autofree char *nicstr =3D NULL; + g_autoptr(virJSONValue) netprops =3D NULL; g_autofree char *netstr =3D NULL; int ret =3D -1; bool releaseaddr =3D false; @@ -1382,10 +1384,13 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, for (i =3D 0; i < vhostfdSize; i++) vhostfdName[i] =3D g_strdup_printf("vhostfd-%s%zu", net->info.alia= s, i); - if (!(netstr =3D qemuBuildHostNetStr(net, - tapfdName, tapfdSize, - vhostfdName, vhostfdSize, - slirpfdName))) + if (!(netprops =3D qemuBuildHostNetStr(net, + tapfdName, tapfdSize, + vhostfdName, vhostfdSize, + slirpfdName))) + goto cleanup; + + if (!(netstr =3D virQEMUBuildNetdevCommandlineFromJSON(netprops))) goto cleanup; qemuDomainObjEnterMonitor(driver, vm); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1589556573; cv=none; d=zohomail.com; s=zohoarc; b=kauyfr5MRL5vhGmmX4yXxH3/kuzNG6xxVIA8PucWq3jbPvigQh8Pne4APp336vWc/j15l48K8G/ZR2ALIbDWh37w8HXwL1HoWL67mwCg+x0Qrz8yVNkWZ0rEBqMVwdO3BvkSgMhilWQ4yUVVIjtgUiN8X0h6DBqDt1+iUp4WbJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556573; 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=f+DTrmA4ap1ixrXkyDKFKeWGpPEzwrolbk39GRsdWVo=; b=EApVn4rjmcp05owiDgR+nurjJFEE/neyQhVbMxbl1vWvjUjDack4+po1NPMx9YoWYJPZuEe6OrL3cgN9niIJ6zZEtnXxleG5dJuBQW5FyYIldIqMvTGMRmfUeBgd/6zZz/VaVuauFcHGZMcc/Me3KBH741HoDbS2KtJ9VZvCQSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1589556573869498.863732916157; Fri, 15 May 2020 08:29:33 -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-47-Bd5DQIPqPB2xMmscGghHDQ-1; Fri, 15 May 2020 11:29:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F081872FEA; 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 F37F6600F5; Fri, 15 May 2020 15:29:21 +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 C469B4E9FC; Fri, 15 May 2020 15:29:21 +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 04FFTJtM011408 for ; Fri, 15 May 2020 11:29:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id B486C5D9F5; Fri, 15 May 2020 15:29:19 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CE765D9D7 for ; Fri, 15 May 2020 15:29:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556572; 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=f+DTrmA4ap1ixrXkyDKFKeWGpPEzwrolbk39GRsdWVo=; b=c3/7mjMGEzHZxbTmGuX4JDqjfcI9GzgOeNz0YHiHlT2SBN9ah/tEX9nQLq3z6jBloj0afE PxtxCj80a97gCsj2vZjnKaVwAAlqGw+A0kuo9r1Iyq5ent+4EDZ8aZfq3bTBu7JQgBy2YZ Q6nnPL4ACfcSDo2EyLWb9VRguj70xrQ= X-MC-Unique: Bd5DQIPqPB2xMmscGghHDQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/21] qemuBuildChannelGuestfwdNetdevProps: Convert to generating JSON props Date: Fri, 15 May 2020 17:28:02 +0200 Message-Id: <2e10b8b04b3d42e70120f0022bdeb238de7eda56.1589556042.git.pkrempa@redhat.com> 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.11 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" Syntax of guestfwd channel also needs to be modified to conform to the QAPI schema. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 37 +++++++++++++++++++++++++++++++------ src/qemu/qemu_command.h | 2 +- src/qemu/qemu_hotplug.c | 6 +++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 00d1b4121d..2ed8e66f66 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8567,6 +8567,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMana= ger, for (i =3D 0; i < def->nchannels; i++) { virDomainChrDefPtr channel =3D def->channels[i]; g_autofree char *chardevstr =3D NULL; + g_autoptr(virJSONValue) netdevprops =3D NULL; g_autofree char *netdevstr =3D NULL; if (!(chardevstr =3D qemuBuildChrChardevStr(logManager, secManager, @@ -8581,8 +8582,12 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMan= ager, switch ((virDomainChrChannelTargetType) channel->targetType) { case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: - if (!(netdevstr =3D qemuBuildChannelGuestfwdNetdevProps(channe= l))) + if (!(netdevprops =3D qemuBuildChannelGuestfwdNetdevProps(chan= nel))) return -1; + + if (!(netdevstr =3D virQEMUBuildNetdevCommandlineFromJSON(netd= evprops))) + return -1; + virCommandAddArgList(cmd, "-netdev", netdevstr, NULL); break; @@ -9850,19 +9855,39 @@ qemuBuildParallelChrDeviceStr(char **deviceStr, } -char * +virJSONValuePtr qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr) { + g_autoptr(virJSONValue) guestfwdarr =3D virJSONValueNewArray(); + g_autoptr(virJSONValue) guestfwdstrobj =3D virJSONValueNewObject(); g_autofree char *addr =3D NULL; - int port; + virJSONValuePtr ret =3D NULL; if (!(addr =3D virSocketAddrFormat(chr->target.addr))) return NULL; - port =3D virSocketAddrGetPort(chr->target.addr); + /* this may seem weird, but qemu indeed decided that 'guestfwd' parame= ter + * is an array of objects which have just one member named 'str' which + * contains the description */ + if (virJSONValueObjectAppendStringPrintf(guestfwdstrobj, "str", + "tcp:%s:%i-chardev:char%s", + addr, + virSocketAddrGetPort(chr->tar= get.addr), + chr->info.alias) < 0) + return NULL; + + if (virJSONValueArrayAppend(guestfwdarr, guestfwdstrobj) < 0) + return NULL; + guestfwdstrobj =3D NULL; - return g_strdup_printf("user,guestfwd=3Dtcp:%s:%i-chardev:char%s,id=3D= %s", - addr, port, chr->info.alias, chr->info.alias); + if (virJSONValueObjectCreate(&ret, + "s:type", "user", + "a:guestfwd", &guestfwdarr, + "s:id", chr->info.alias, + NULL) < 0) + return NULL; + + return ret; } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 6cdd9debe0..1daa07982c 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -86,7 +86,7 @@ qemuBuildChrDeviceStr(char **deviceStr, virDomainChrDefPtr chr, virQEMUCapsPtr qemuCaps); -char * +virJSONValuePtr qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr); virJSONValuePtr qemuBuildHostNetStr(virDomainNetDefPtr net, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c6789dcef3..cd9bc9b2f8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2113,6 +2113,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, virErrorPtr orig_err; virDomainDefPtr vmdef =3D vm->def; g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) netdevprops =3D NULL; g_autofree char *netdevstr =3D NULL; virDomainChrSourceDefPtr dev =3D chr->source; g_autofree char *charAlias =3D NULL; @@ -2153,7 +2154,10 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr drive= r, teardowncgroup =3D true; if (guestfwd) { - if (!(netdevstr =3D qemuBuildChannelGuestfwdNetdevProps(chr))) + if (!(netdevprops =3D qemuBuildChannelGuestfwdNetdevProps(chr))) + goto cleanup; + + if (!(netdevstr =3D virQEMUBuildNetdevCommandlineFromJSON(netdevpr= ops))) goto cleanup; } else { if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0) --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1589556574; cv=none; d=zohomail.com; s=zohoarc; b=WA+AGfazuumZ0J2p+gCSEDfBTCx4GbCqhYBxEwZN7W4bs+iIvuBqwWJGm9QksHoni+CXurbKTW42MaiWtf/635WxENN/mzjfn1eWK6i2mAO/lcrAwKZ2mEw6MgQOi1XkEaL37chqFuT8c6CHi/Ed2UZ6oeHTJnFMPxt6HlzRCqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556574; 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=HEA8Uo9uMPdDiuHs3hwRX0iMVI58IafamYCtRKjSrE0=; b=ZpR2hEs6AOGBHmvonZxwOfEam08XeQHjdeKjGPfyjXa343Xgnfo+BjR4m70lnp38+j+Xezk1aeBV2EXoFq0UC3uuf8+oHnwjDViIuSPwXFNQHe+iClYdHzTQm63SYa0JZiVF1+ekojXab2Bt73WuqiTNn5B0XRWeCxZRybghWQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589556574362726.1455045180243; Fri, 15 May 2020 08:29:34 -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-480-_HktWIGoOVmW5tA3TVPbtQ-1; Fri, 15 May 2020 11:29:30 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 714988730BD; Fri, 15 May 2020 15:29:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B7311036B4B; Fri, 15 May 2020 15:29:24 +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 0819D180530C; Fri, 15 May 2020 15:29:24 +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 04FFTKtY011420 for ; Fri, 15 May 2020 11:29:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id D44115D9F5; Fri, 15 May 2020 15:29:20 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A1005D9D7 for ; Fri, 15 May 2020 15:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556573; 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=HEA8Uo9uMPdDiuHs3hwRX0iMVI58IafamYCtRKjSrE0=; b=BzaIhls5Dm4JA8/MzBtLqhWdww0wix/lI9wmuhu+FOyOyszDaoB01KPUyPXJTxRWcNLmG2 Sn8WOMO16pxDRSSh13NgWfxb1MUqalvqGKtxksE0Iy8u6Hq2dJW2LEkivUwGKJnYbXPMyo EAuhE/s9DzyT3gHBfMt5L0jOgIJKmPw= X-MC-Unique: _HktWIGoOVmW5tA3TVPbtQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/21] qemuMonitorAddNetdev: Convert to the native JSON props object Date: Fri, 15 May 2020 17:28:03 +0200 Message-Id: <530a83c476d96c4c3a558a8a1a61055d8b1f1e43.1589556042.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" Now that all code paths generate JSON props we can remove the conversion to command line arguments and back in the monitor code. Note that the test which is removed in this commit will be replaced by a stronger testsuite later. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_hotplug.c | 14 +++----------- src/qemu/qemu_monitor.c | 8 ++++---- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 15 +++------------ src/qemu/qemu_monitor_json.h | 2 +- tests/qemumonitorjsontest.c | 2 -- 6 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index cd9bc9b2f8..2b0cdad4e7 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1159,7 +1159,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, size_t queueSize =3D 0; g_autofree char *nicstr =3D NULL; g_autoptr(virJSONValue) netprops =3D NULL; - g_autofree char *netstr =3D NULL; int ret =3D -1; bool releaseaddr =3D false; bool iface_connected =3D false; @@ -1390,9 +1389,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, slirpfdName))) goto cleanup; - if (!(netstr =3D virQEMUBuildNetdevCommandlineFromJSON(netprops))) - goto cleanup; - qemuDomainObjEnterMonitor(driver, vm); if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER) { @@ -1404,7 +1400,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, charDevPlugged =3D true; } - if (qemuMonitorAddNetdev(priv->mon, netstr, + if (qemuMonitorAddNetdev(priv->mon, &netprops, tapfd, tapfdName, tapfdSize, vhostfd, vhostfdName, vhostfdSize, slirpfd, slirpfdName) < 0) { @@ -2114,7 +2110,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, virDomainDefPtr vmdef =3D vm->def; g_autofree char *devstr =3D NULL; g_autoptr(virJSONValue) netdevprops =3D NULL; - g_autofree char *netdevstr =3D NULL; virDomainChrSourceDefPtr dev =3D chr->source; g_autofree char *charAlias =3D NULL; bool chardevAttached =3D false; @@ -2156,9 +2151,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, if (guestfwd) { if (!(netdevprops =3D qemuBuildChannelGuestfwdNetdevProps(chr))) goto cleanup; - - if (!(netdevstr =3D virQEMUBuildNetdevCommandlineFromJSON(netdevpr= ops))) - goto cleanup; } else { if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0) goto cleanup; @@ -2181,8 +2173,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, goto exit_monitor; chardevAttached =3D true; - if (netdevstr) { - if (qemuMonitorAddNetdev(priv->mon, netdevstr, + if (netdevprops) { + if (qemuMonitorAddNetdev(priv->mon, &netdevprops, NULL, NULL, 0, NULL, NULL, 0, -1, NULL) <= 0) goto exit_monitor; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 9c853ccb93..2911307f0e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2667,7 +2667,7 @@ qemuMonitorCloseFileHandle(qemuMonitorPtr mon, int qemuMonitorAddNetdev(qemuMonitorPtr mon, - const char *netdevstr, + virJSONValuePtr *props, int *tapfd, char **tapfdName, int tapfdSize, int *vhostfd, char **vhostfdName, int vhostfdSize, int slirpfd, char *slirpfdName) @@ -2675,10 +2675,10 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon, int ret =3D -1; size_t i =3D 0, j =3D 0; - VIR_DEBUG("netdevstr=3D%s tapfd=3D%p tapfdName=3D%p tapfdSize=3D%d" + VIR_DEBUG("props=3D%p tapfd=3D%p tapfdName=3D%p tapfdSize=3D%d" "vhostfd=3D%p vhostfdName=3D%p vhostfdSize=3D%d" "slirpfd=3D%d slirpfdName=3D%s", - netdevstr, tapfd, tapfdName, tapfdSize, + props, tapfd, tapfdName, tapfdSize, vhostfd, vhostfdName, vhostfdSize, slirpfd, slirpfdName); QEMU_CHECK_MONITOR(mon); @@ -2696,7 +2696,7 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon, qemuMonitorSendFileHandle(mon, slirpfdName, slirpfd) < 0) goto cleanup; - ret =3D qemuMonitorJSONAddNetdev(mon, netdevstr); + ret =3D qemuMonitorJSONAddNetdev(mon, props); cleanup: if (ret < 0) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2e35d94bda..378e2532c7 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -881,7 +881,7 @@ int qemuMonitorCloseFileHandle(qemuMonitorPtr mon, const char *fdname); int qemuMonitorAddNetdev(qemuMonitorPtr mon, - const char *netdevstr, + virJSONValuePtr *props, int *tapfd, char **tapfdName, int tapfdSize, int *vhostfd, char **vhostfdName, int vhostfdSize, int slirpfd, char *slirpfdName); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1224d1c9cc..a98479a55d 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3986,23 +3986,14 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr m= on, int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, - const char *netdevstr) + virJSONValuePtr *props) { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - g_autoptr(virJSONValue) args =3D NULL; - - cmd =3D qemuMonitorJSONMakeCommand("netdev_add", NULL); - if (!cmd) - return -1; - - args =3D qemuMonitorJSONKeywordStringToJSON(netdevstr, "type"); - if (!args) - return -1; + virJSONValuePtr pr =3D g_steal_pointer(props); - if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) + if (!(cmd =3D qemuMonitorJSONMakeCommandInternal("netdev_add", pr))) return -1; - args =3D NULL; /* obj owns reference to args now */ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) return -1; diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index d3d46ec2f7..83c5e25ca5 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -210,7 +210,7 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon, const char *fdname); int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon, - const char *netdevstr); + virJSONValuePtr *props); int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon, const char *alias); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f58b18a110..a50b157dbc 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1315,7 +1315,6 @@ GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol", = "elf", true) GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SP= ICE, "localhost", 12345, 12346, "certsubjectval") -GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "id=3Dnet0,type=3Duser") GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0") GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0") GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr") @@ -3226,7 +3225,6 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONMigrate); DO_TEST_GEN(qemuMonitorJSONDump); DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate); - DO_TEST_GEN(qemuMonitorJSONAddNetdev); DO_TEST_GEN(qemuMonitorJSONRemoveNetdev); DO_TEST_GEN(qemuMonitorJSONDelDevice); DO_TEST_GEN(qemuMonitorJSONAddDevice); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1589556692; cv=none; d=zohomail.com; s=zohoarc; b=bVrtOyB58bYj7vYlQyWuIU9xT1LsEBCgoUfHMZOlHVAFNpfFxFQeMoDoLQhCkDscugWW/4K4IzRyHAgy/i/MArJMCAlgCs+eRsx0hbpOArZGvUzwqFKeJEvPuFqguguRU+cYs2JLlQHe3LS7kVgg+J9K3+UVNSaJon5spgo77Ro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556692; 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=BlpPkPSMCEsMbH6hrX114bA/n+i3nT3eQBcbl2klsqs=; b=aF5/n1qWTEYPb1xCtibvXA8oHPsPIS7R5l0mCD+E12BcaGfZzijThW0Qxipt1r4ZtaQLwIezG8GyA/6AM/G5ldLwiWZAjfFGSLFsVjmNyvGE6yhJhn2Yu6yU1qY57iFdT2LtTLi1dzl5mLN+ag8x+JX0E8Ma8TJnl3Taotrh3og= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1589556692678162.74561424348167; Fri, 15 May 2020 08:31:32 -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-56-Te0tRmk2MrmL8l5NJ-WW7A-1; Fri, 15 May 2020 11:29:30 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDC8E18FF660; Fri, 15 May 2020 15:29:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC87B600F5; Fri, 15 May 2020 15:29:24 +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 97C7C180530E; Fri, 15 May 2020 15:29:24 +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 04FFTL1s011438 for ; Fri, 15 May 2020 11:29:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id CBF1F5D9F7; Fri, 15 May 2020 15:29:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A6A15DA36 for ; Fri, 15 May 2020 15:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556691; 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=BlpPkPSMCEsMbH6hrX114bA/n+i3nT3eQBcbl2klsqs=; b=FqNwosG4IdorFIo+B3ClRXXNcloqaVf+1yL4nh7iV0g7Rnu28avXqggNrD7jZiakLMU78q eAaYj9x57ahTx0UF3Avb3acUflxoDfc0Gt4Qm+f/6ypS91BkF1P6aNZ5cnKq7jAPnL5/jg yiyT3hi+vObUOK7uCmj8XjGW73tyNpo= X-MC-Unique: Te0tRmk2MrmL8l5NJ-WW7A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 18/21] qemu: Prepare for testing of 'netdev_add' props via qemuxml2argvtest Date: Fri, 15 May 2020 17:28:04 +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.11 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" qemuxml2argv test suite is way more comprehensive than the hotplug suite. Since we share the code paths for monitor and command line hotplug we can easily test the properties of devices against the QAPI schema. To achieve this we'll need to skip the JSON->commandline conversion for the test run so that we can analyze the pure properties. This patch adds flags for the comand line generator and hook them into the JSON->commandline convertor for -netdev. An upcoming patch will make use of this new infrastructure. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_command.c | 28 +++++++++++++++++----------- src/qemu/qemu_command.h | 7 ++++++- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_process.c | 11 +++++++++-- src/qemu/qemu_process.h | 1 + src/util/virqemu.c | 9 ++++++++- src/util/virqemu.h | 3 ++- tests/qemuxml2argvtest.c | 6 ++++-- 8 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2ed8e66f66..f9a2732587 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7691,7 +7691,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, virNetDevVPortProfileOp vmop, bool standalone, size_t *nnicindexes, - int **nicindexes) + int **nicindexes, + unsigned int flags) { virDomainDefPtr def =3D vm->def; int ret =3D -1; @@ -7920,7 +7921,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, slirpfdName))) goto cleanup; - if (!(host =3D virQEMUBuildNetdevCommandlineFromJSON(hostnetprops))) + if (!(host =3D virQEMUBuildNetdevCommandlineFromJSON(hostnetprops, + (flags & QEMU_BUILD= _COMMANDLINE_VALIDATE_KEEP_JSON)))) goto cleanup; virCommandAddArgList(cmd, "-netdev", host, NULL); @@ -7996,7 +7998,8 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver, bool standalone, size_t *nnicindexes, int **nicindexes, - unsigned int *bootHostdevNet) + unsigned int *bootHostdevNet, + unsigned int flags) { size_t i; int last_good_net =3D -1; @@ -8020,7 +8023,7 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver, if (qemuBuildInterfaceCommandLine(driver, vm, logManager, secM= anager, cmd, net, qemuCaps, bootNet, vmop, standalone, nnicindexes, - nicindexes) < 0) + nicindexes, flags) < 0) goto error; last_good_net =3D i; @@ -8556,7 +8559,8 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMana= ger, virQEMUDriverConfigPtr cfg, const virDomainDef *def, virQEMUCapsPtr qemuCaps, - bool chardevStdioLogd) + bool chardevStdioLogd, + unsigned int flags) { size_t i; unsigned int cdevflags =3D QEMU_BUILD_CHARDEV_TCP_NOWAIT | @@ -8585,7 +8589,8 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logMana= ger, if (!(netdevprops =3D qemuBuildChannelGuestfwdNetdevProps(chan= nel))) return -1; - if (!(netdevstr =3D virQEMUBuildNetdevCommandlineFromJSON(netd= evprops))) + if (!(netdevstr =3D virQEMUBuildNetdevCommandlineFromJSON(netd= evprops, + (flags= & QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON)))) return -1; virCommandAddArgList(cmd, "-netdev", netdevstr, NULL); @@ -9521,7 +9526,8 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, bool standalone, bool enableFips, size_t *nnicindexes, - int **nicindexes) + int **nicindexes, + unsigned int flags) { size_t i; char uuid[VIR_UUID_STRING_BUFLEN]; @@ -9534,9 +9540,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, bool chardevStdioLogd =3D priv->chardevStdioLogd; VIR_DEBUG("driver=3D%p def=3D%p mon=3D%p " - "qemuCaps=3D%p migrateURI=3D%s snapshot=3D%p vmop=3D%d", + "qemuCaps=3D%p migrateURI=3D%s snapshot=3D%p vmop=3D%d flags= =3D0x%x", driver, def, priv->monConfig, - qemuCaps, migrateURI, snapshot, vmop); + qemuCaps, migrateURI, snapshot, vmop, flags); if (qemuBuildCommandLineValidate(driver, def) < 0) return NULL; @@ -9681,7 +9687,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, if (qemuBuildNetCommandLine(driver, vm, logManager, secManager, cmd, qemuCaps, vmop, standalone, - nnicindexes, nicindexes, &bootHostdevNet) = < 0) + nnicindexes, nicindexes, &bootHostdevNet, = flags) < 0) return NULL; if (qemuBuildSmartcardCommandLine(logManager, secManager, cmd, cfg, de= f, qemuCaps, @@ -9697,7 +9703,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, return NULL; if (qemuBuildChannelsCommandLine(logManager, secManager, cmd, cfg, def= , qemuCaps, - chardevStdioLogd) < 0) + chardevStdioLogd, flags) < 0) return NULL; if (qemuBuildConsoleCommandLine(logManager, secManager, cmd, cfg, def,= qemuCaps, diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 1daa07982c..55bc67072a 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -43,6 +43,10 @@ VIR_ENUM_DECL(qemuVideo); VIR_ENUM_DECL(qemuSoundCodec); +typedef enum { + QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON =3D 1 << 0, +} qemuBuildCommandLineFlags; + virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver, virLogManagerPtr logManager, virSecurityManagerPtr secManager, @@ -53,7 +57,8 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr drive= r, bool standalone, bool enableFips, size_t *nnicindexes, - int **nicindexes); + int **nicindexes, + unsigned int flags); /* Generate the object properties for pr-manager */ virJSONValuePtr qemuBuildPRManagerInfoProps(virStorageSourcePtr src); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index db65862163..dd9ae30bb5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7423,7 +7423,7 @@ static char *qemuConnectDomainXMLToNative(virConnectP= tr conn, } if (!(cmd =3D qemuProcessCreatePretendCmd(driver, vm, NULL, - qemuCheckFips(), true, + qemuCheckFips(), true, false, VIR_QEMU_PROCESS_START_COLD))) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f7f6793113..ab32d49d6e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6746,7 +6746,7 @@ qemuProcessLaunch(virConnectPtr conn, snapshot, vmop, false, qemuCheckFips(), - &nnicindexes, &nicindexes))) + &nnicindexes, &nicindexes, 0))) goto cleanup; if (incoming && incoming->fd !=3D -1) @@ -7189,8 +7189,11 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, const char *migrateURI, bool enableFips, bool standalone, + bool jsonPropsValidation, unsigned int flags) { + unsigned int buildflags =3D 0; + virCheckFlags(VIR_QEMU_PROCESS_START_COLD | VIR_QEMU_PROCESS_START_PAUSED | VIR_QEMU_PROCESS_START_AUTODESTROY, NULL); @@ -7200,6 +7203,9 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, if (standalone) flags |=3D VIR_QEMU_PROCESS_START_STANDALONE; + if (jsonPropsValidation) + buildflags =3D QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON; + if (qemuProcessInit(driver, vm, NULL, QEMU_ASYNC_JOB_NONE, !!migrateURI, flags) < 0) return NULL; @@ -7218,7 +7224,8 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, standalone, enableFips, NULL, - NULL); + NULL, + buildflags); } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 3077d3ef9e..15e67b9762 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -101,6 +101,7 @@ virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriver= Ptr driver, const char *migrateURI, bool enableFips, bool standalone, + bool jsonPropsValidation, unsigned int flags); int qemuProcessInit(virQEMUDriverPtr driver, diff --git a/src/util/virqemu.c b/src/util/virqemu.c index f3e9966598..cf76346bfa 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -290,16 +290,23 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value, /** * virQEMUBuildNetdevCommandlineFromJSON: * @props: JSON properties describing a netdev + * @rawjson: don't transform to commandline args, but just stringify json * * Converts @props into arguments for -netdev including all the quirks and * differences between the monitor and command line syntax. + * + * @rawjson is meant for testing of the schema in the xml2argvtest */ char * -virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props) +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props, + bool rawjson) { const char *type =3D virJSONValueObjectGetString(props, "type"); g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + if (rawjson) + return virJSONValueToString(props, false); + virBufferAsprintf(&buf, "%s,", type); if (virQEMUBuildCommandLineJSON(props, &buf, "type", true, diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 22f47851df..b1296cb657 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -50,7 +50,8 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value, virQEMUBuildCommandLineJSONArrayFormatFunc= array); char * -virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props); +virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props, + bool rawjson); int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf, virJSONValuePtr objprops); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 9fa1afd9d0..5123580ee2 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -396,7 +396,8 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, virDomainObjPtr vm, const char *migrateURI, struct testQemuInfo *info, - unsigned int flags) + unsigned int flags, + bool jsonPropsValidation) { size_t i; @@ -471,6 +472,7 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, return qemuProcessCreatePretendCmd(drv, vm, migrateURI, (flags & FLAG_FIPS), false, + jsonPropsValidation, VIR_QEMU_PROCESS_START_COLD); } @@ -566,7 +568,7 @@ testCompareXMLToArgv(const void *data) virResetLastError(); if (!(cmd =3D testCompareXMLToArgvCreateArgs(&driver, vm, migrateURI, = info, - flags))) { + flags, false))) { if (flags & FLAG_EXPECT_FAILURE) goto ok; goto cleanup; --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 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=1589556575; cv=none; d=zohomail.com; s=zohoarc; b=OXiQeD7DGC38vVrWYbJA6XAVLGYKJCqbGvRyq78LfK/WCLcUKlssNsLwvT9ii7igj+o8ejzRMhOeW/zksMKr40REvTIpz53522Qmy+cuIvjz39aESHBrFTVxx8yoofXHVJf1CI1kpDKuS0yewkwbFmGHY9jGgtxSjc4nQ989skg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556575; 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=wL0DrpoqeeYO3tNOtZqAKanb7F2HD+B9moICTkahr/k=; b=GdckXwXDftDWkp+bFNMJLuyUPQTiVbEcjAXOOiO9xNcjPkEnzgzVTJgNkRtlxCWaM3QHLSyV0wv+axRMDmzrDeEQRXsLogxISXfrzkuzfDow0T1hFDaRFen9q8vYAyqmZ/adSFXQn8Zsox/+orCm/A87LtRUWd1P0UBf8TtqbAY= 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 1589556575435979.154022861182; Fri, 15 May 2020 08:29:35 -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-359-C3e8vqQgM5q2GXKoGKMGUw-1; Fri, 15 May 2020 11:29:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BBAD8C7437; Fri, 15 May 2020 15:29:26 +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 9AAF5579A0; Fri, 15 May 2020 15:29:26 +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 6EC954EA00; Fri, 15 May 2020 15:29:26 +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 04FFTNGg011452 for ; Fri, 15 May 2020 11:29:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 117E05D9F3; Fri, 15 May 2020 15:29:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C5DC5D9D7 for ; Fri, 15 May 2020 15:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556574; 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=wL0DrpoqeeYO3tNOtZqAKanb7F2HD+B9moICTkahr/k=; b=I/KE5z1IJjkcVgwOS/zU6nNpUtL0Kv2cJUgusXJFspyMTWVHtIMTWimk20hllV472PC0b8 P0XQL2E1M/s0L5rGJuzAgikBcRLyUqSxwgC/F02DUj4tPIMVB0XlTNkktzz7/hX1Ts3A80 /YOVk0hxpUTFb0H2sBf+Vf59hCY/HAA= X-MC-Unique: C3e8vqQgM5q2GXKoGKMGUw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 19/21] testQEMUSchemaLoad: Rename to testQEMUSchemaLoadLatest Date: Fri, 15 May 2020 17:28:05 +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.13 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" It always loads the latest schema. Prepare for loading others as well. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- tests/qemublocktest.c | 2 +- tests/qemuhotplugtest.c | 2 +- tests/qemumonitorjsontest.c | 4 ++-- tests/testutilsqemuschema.c | 2 +- tests/testutilsqemuschema.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 8057d1e2c0..0cdedb9ad4 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -1056,7 +1056,7 @@ mymain(void) diskxmljsondata.qemuCaps =3D caps_x86_64; imagecreatedata.qemuCaps =3D caps_x86_64; - if (!(qmp_schema_x86_64 =3D testQEMUSchemaLoad("x86_64"))) { + if (!(qmp_schema_x86_64 =3D testQEMUSchemaLoadLatest("x86_64"))) { ret =3D -1; goto cleanup; } diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 1843e79d77..ba3fc4d814 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -636,7 +636,7 @@ mymain(void) if (!(driver.domainEventState =3D virObjectEventStateNew())) return EXIT_FAILURE; - if (!(qmpschema =3D testQEMUSchemaLoad("x86_64"))) { + if (!(qmpschema =3D testQEMUSchemaLoadLatest("x86_64"))) { VIR_TEST_VERBOSE("failed to load qapi schema\n"); return EXIT_FAILURE; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index a50b157dbc..6d5a1d5fe2 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -3124,7 +3124,7 @@ mymain(void) virEventRegisterDefaultImpl(); - if (!(qapiData.schema =3D testQEMUSchemaLoad("x86_64"))) { + if (!(qapiData.schema =3D testQEMUSchemaLoadLatest("x86_64"))) { VIR_TEST_VERBOSE("failed to load qapi schema"); ret =3D -1; goto cleanup; @@ -3394,7 +3394,7 @@ mymain(void) #undef DO_TEST_QUERY_JOBS virHashFree(qapiData.schema); - if (!(qapiData.schema =3D testQEMUSchemaLoad("s390x"))) { + if (!(qapiData.schema =3D testQEMUSchemaLoadLatest("s390x"))) { VIR_TEST_VERBOSE("failed to load qapi schema for s390x"); ret =3D -1; goto cleanup; diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 898be68b0a..060a5d7054 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -661,7 +661,7 @@ testQEMUSchemaGetLatest(const char* arch) virHashTablePtr -testQEMUSchemaLoad(const char* arch) +testQEMUSchemaLoadLatest(const char *arch) { virJSONValuePtr schema; diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index 8b6803afda..acedb77677 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -41,4 +41,4 @@ virJSONValuePtr testQEMUSchemaGetLatest(const char* arch); virHashTablePtr -testQEMUSchemaLoad(const char* arch); +testQEMUSchemaLoadLatest(const char *arch); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1589556617; cv=none; d=zohomail.com; s=zohoarc; b=HT538Cdlo2bC/p8R6PE5AkTiHza2NdE/OnK3xKIvaxxpRkpsOmOzdAmU9tdbxiO3JlJZYrrZmDMTfa/f8blRHeb10cHsVD7lgraYeKEM+yp8+xZAzACVHahcNS7UpltB4Q1zAmwsQMHseV/R3ofREE7e9HIncGCxL1VzojcpY8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556617; 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=Ok62GrsAj9e2Jm7Gt3wAC6BFLAXeu0NKyewYvGsL/5M=; b=ieAZEtfzVkohu2MW/g7e3JcYtT1yLJOtgPUdxg5TGM/4VB8OdcMfj+uILwCOo/J030+KThB2yhFoHL5Ocm1glucupMPYLBqgUY3VwiBz5E+2uxzE8LNa6iCh1OK41G3GpNXxRdKwNxQ+/4RTr8ICqbuukXQz0Frc+Q4k7vbvOi0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1589556617701285.1450293435488; Fri, 15 May 2020 08:30:17 -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-285-_VL0FxIRM8yt9a8ZnFKiMA-1; Fri, 15 May 2020 11:29:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75CFC1054F9B; Fri, 15 May 2020 15:29:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5086F100164D; Fri, 15 May 2020 15:29:28 +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 1DBAC1805312; Fri, 15 May 2020 15:29:28 +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 04FFTOwq011461 for ; Fri, 15 May 2020 11:29:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4554A5D9F5; Fri, 15 May 2020 15:29:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0D865D9D7 for ; Fri, 15 May 2020 15:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556615; 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=Ok62GrsAj9e2Jm7Gt3wAC6BFLAXeu0NKyewYvGsL/5M=; b=VpDvsbpJ/o4BOCFNeL15rCOzmXZblkUoa2B8gU/HUgowApaujrCl24XVVCFHrame1pxA2I 9oodw7GKrRgLpDjKF5ai5kolfZaTlzrwb6sArN0fg4pjk9IN+rdLbgvGzwF+dgYODAlWOP PG3ik8WQt4Pp6fL0TaTcnbEKNs1vsgQ= X-MC-Unique: _VL0FxIRM8yt9a8ZnFKiMA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 20/21] testutilsqemuschema: Allow loading non-latest schema Date: Fri, 15 May 2020 17:28:06 +0200 Message-Id: <964b76cacc0c2d29cc3065f5e66ac984555f562b.1589556042.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" Add testQEMUSchemaLoad and refactor internals so that we can load the QMP schema from an arbitrary caps replies file. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- tests/testutilsqemuschema.c | 64 ++++++++++++++++++++++++------------- tests/testutilsqemuschema.h | 3 ++ 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 060a5d7054..d9b55fd787 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -607,37 +607,23 @@ testQEMUSchemaValidateCommand(const char *command, } -/** - * testQEMUSchemaGetLatest: - * - * Returns the schema data as the qemu monitor would reply from the latest - * replies file used for qemucapabilitiestest for the x86_64 architecture. - */ -virJSONValuePtr -testQEMUSchemaGetLatest(const char* arch) +static virJSONValuePtr +testQEMUSchemaLoadReplies(const char *filename) { - g_autofree char *capsLatestFile =3D NULL; - g_autofree char *capsLatest =3D NULL; + g_autofree char *caps =3D NULL; char *schemaReply; char *end; g_autoptr(virJSONValue) reply =3D NULL; virJSONValuePtr schema =3D NULL; - if (!(capsLatestFile =3D testQemuGetLatestCapsForArch(arch, "replies")= )) { - VIR_TEST_VERBOSE("failed to find latest caps replies"); + if (virTestLoadFile(filename, &caps) < 0) return NULL; - } - VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile); - - if (virTestLoadFile(capsLatestFile, &capsLatest) < 0) - return NULL; - - if (!(schemaReply =3D strstr(capsLatest, "\"execute\": \"query-qmp-sch= ema\"")) || + if (!(schemaReply =3D strstr(caps, "\"execute\": \"query-qmp-schema\""= )) || !(schemaReply =3D strstr(schemaReply, "\n\n")) || !(end =3D strstr(schemaReply + 2, "\n\n"))) { VIR_TEST_VERBOSE("failed to find reply to 'query-qmp-schema' in '%= s'", - capsLatestFile); + filename); return NULL; } @@ -646,13 +632,13 @@ testQEMUSchemaGetLatest(const char* arch) if (!(reply =3D virJSONValueFromString(schemaReply))) { VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%= s'", - capsLatestFile); + filename); return NULL; } if (!(schema =3D virJSONValueObjectStealArray(reply, "return"))) { VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'", - capsLatestFile); + filename); return NULL; } @@ -660,6 +646,28 @@ testQEMUSchemaGetLatest(const char* arch) } +/** + * testQEMUSchemaGetLatest: + * + * Returns the schema data as the qemu monitor would reply from the latest + * replies file used for qemucapabilitiestest for the x86_64 architecture. + */ +virJSONValuePtr +testQEMUSchemaGetLatest(const char *arch) +{ + g_autofree char *capsLatestFile =3D NULL; + + if (!(capsLatestFile =3D testQemuGetLatestCapsForArch(arch, "replies")= )) { + VIR_TEST_VERBOSE("failed to find latest caps replies"); + return NULL; + } + + VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile); + + return testQEMUSchemaLoadReplies(capsLatestFile); +} + + virHashTablePtr testQEMUSchemaLoadLatest(const char *arch) { @@ -670,3 +678,15 @@ testQEMUSchemaLoadLatest(const char *arch) return virQEMUQAPISchemaConvert(schema); } + + +virHashTablePtr +testQEMUSchemaLoad(const char *filename) +{ + virJSONValuePtr schema; + + if (!(schema =3D testQEMUSchemaLoadReplies(filename))) + return NULL; + + return virQEMUQAPISchemaConvert(schema); +} diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index acedb77677..c90a6b626d 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -42,3 +42,6 @@ testQEMUSchemaGetLatest(const char* arch); virHashTablePtr testQEMUSchemaLoadLatest(const char *arch); + +virHashTablePtr +testQEMUSchemaLoad(const char *filename); --=20 2.26.2 From nobody Fri Apr 26 17:38:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1589556596; cv=none; d=zohomail.com; s=zohoarc; b=Q+m/bBn5xVuKpAAkJFDoY2LFVt1gJcIhWxkZQHujl+zo1MvkeM9bjbMF8sG9WyeC6uWfRAtGFfVlLNSTfz7ANiL5aooRnebsKkpJxLuos4OTg9wYIIms76rarbW4gs9V6IGQXt3vUj/T1OAP3BxS+fNEtozrW8H1il3rBCohbKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589556596; 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=yMmKPmeTbZxGFd4l+OWCbBHmzvUTleAsII1d0zM5qMU=; b=fO7o8Wzsn8SwL+t3z1OGelYtUQl4SvizOQk6K21e28VDtbsstxAOPYeRk2OJ8K7PiULPdU5W9a0IqLisdm9BBiXJXD43TlVYyV0vnq/nClGoVeLpn23WPHw3Y1xHcGgDEV1ijd6sz5tbBYeSX7pGS1BOJrxEJm4vlrESpxrucmA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589556596822604.9556281836344; Fri, 15 May 2020 08:29:56 -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-258-Xo_JYW_uOIanyP8mnTJe_Q-1; Fri, 15 May 2020 11:29:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1427F53; Fri, 15 May 2020 15:29:29 +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 E58AB60C05; Fri, 15 May 2020 15:29:28 +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 B79F74EA0C; Fri, 15 May 2020 15:29:28 +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 04FFTPSo011469 for ; Fri, 15 May 2020 11:29:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 330025D9F7; Fri, 15 May 2020 15:29:25 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A09FF5D9F5 for ; Fri, 15 May 2020 15:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589556595; 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=yMmKPmeTbZxGFd4l+OWCbBHmzvUTleAsII1d0zM5qMU=; b=LQYnhmqUw24dbd0XEVpAYs5BqwPX6sLBdukRi+uXQutmp6o0la+LKWDuz3kIkHKXFR3BK+ mZkVigDR1fGsEwXowVH9mcWmLTQU1oecsEagSn25uKvLYFgOvp6dkMsNYi56OkS6FCRXlU q/YKS394UY5kLmA/3ciS9bxkF7SLSfA= X-MC-Unique: Xo_JYW_uOIanyP8mnTJe_Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 21/21] qemuxml2argvtest: Add QAPI/QMP schema validation for -blockdev and -netdev Date: Fri, 15 May 2020 17:28:07 +0200 Message-Id: <08e668a4a0f50b1bdaecff7881de399a68fc3e17.1589556042.git.pkrempa@redhat.com> 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.12 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" Our hotplug test cases are weak in comparison to the xml2arvtest. Use all the the data to also valiadte the arguments for -netdev and -blockdev against the appropriate commands of the QMP schema. Note that currently it's done just for the _CAPS versions of tests but commenting out a line in the test file allows to validate even cases which don't use real capabilities. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- tests/Makefile.am | 2 +- tests/qemuxml2argvtest.c | 76 ++++++++++++++++++++++++++++++++++++++++ tests/testutilsqemu.c | 5 +++ tests/testutilsqemu.h | 1 + 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index fc516376b4..f5766a7790 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -570,7 +570,7 @@ qemuxml2argvtest_SOURCES =3D \ testutils.c testutils.h \ virfilewrapper.c virfilewrapper.h \ $(NULL) -qemuxml2argvtest_LDADD =3D libqemutestdriver.la \ +qemuxml2argvtest_LDADD =3D libqemutestdriver.la libqemumonitortestutils.la= \ $(LDADDS) $(LIBXML_LIBS) libqemuxml2argvmock_la_SOURCES =3D \ diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 5123580ee2..4f613e8f1a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -18,6 +18,7 @@ # include "qemu/qemu_migration.h" # include "qemu/qemu_process.h" # include "qemu/qemu_slirp.h" +# include "qemu/qemu_qapi.h" # include "datatypes.h" # include "conf/storage_conf.h" # include "cpu/cpu_map.h" @@ -26,6 +27,8 @@ # include "virmock.h" # include "virfilewrapper.h" # include "configmake.h" +# include "testutilsqemuschema.h" +# include "qemu/qemu_monitor_json.h" # define LIBVIRT_QEMU_CAPSPRIV_H_ALLOW # include "qemu/qemu_capspriv.h" @@ -477,6 +480,76 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, } +static int +testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv, + virDomainObjPtr vm, + const char *migrateURI, + struct testQemuInfo *info, + unsigned int flags) +{ + VIR_AUTOSTRINGLIST args =3D NULL; + size_t nargs =3D 0; + size_t i; + g_autoptr(virHashTable) schema =3D NULL; + g_autoptr(virCommand) cmd =3D NULL; + + if (info->schemafile) + schema =3D testQEMUSchemaLoad(info->schemafile); + + /* comment out with line comment to enable schema checking for non _CA= PS tests + if (!schema) + schema =3D testQEMUSchemaLoadLatest(virArchToString(info->arch)); + // */ + + if (!schema) + return 0; + + if (!(cmd =3D testCompareXMLToArgvCreateArgs(drv, vm, migrateURI, info= , flags, + true))) + return -1; + + if (virCommandGetArgList(cmd, &args, &nargs) < 0) + return -1; + + for (i =3D 0; i < nargs; i++) { + g_auto(virBuffer) debug =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) jsonargs =3D NULL; + + if (STREQ(args[i], "-blockdev")) { + if (!(jsonargs =3D virJSONValueFromString(args[i + 1]))) + return -1; + + if (testQEMUSchemaValidateCommand("blockdev-add", jsonargs, + schema, false, false, &debug= ) < 0) { + VIR_TEST_VERBOSE("failed to validate -blockdev '%s' agains= t QAPI schema: %s", + args[i + 1], virBufferCurrentContent(&deb= ug)); + return -1; + } + + i++; + } else if (STREQ(args[i], "-netdev")) { + if (!(jsonargs =3D virJSONValueFromString(args[i + 1]))) + return -1; + + /* skip the validation for pre-QAPIfication cases */ + if (virQEMUQAPISchemaPathExists("netdev_add/arg-type/type/!str= ing", schema)) + continue; + + if (testQEMUSchemaValidateCommand("netdev_add", jsonargs, + schema, false, false, &debug= ) < 0) { + VIR_TEST_VERBOSE("failed to validate -netdev '%s' against = QAPI schema: %s", + args[i + 1], virBufferCurrentContent(&deb= ug)); + return -1; + } + + i++; + } + } + + return 0; +} + + static int testCompareXMLToArgv(const void *data) { @@ -578,6 +651,9 @@ testCompareXMLToArgv(const void *data) goto cleanup; } + if (testCompareXMLToArgvValidateSchema(&driver, vm, migrateURI, info, = flags) < 0) + goto cleanup; + if (!(actualargv =3D virCommandToString(cmd, false))) goto cleanup; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 9f9eb4033c..4b83b8ff25 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -768,6 +768,10 @@ testQemuInfoSetArgs(struct testQemuInfo *info, if (stripmachinealiases) virQEMUCapsStripMachineAliases(qemuCaps); info->flags |=3D FLAG_REAL_CAPS; + + /* provide path to the replies file for schema testing */ + capsfile[strlen(capsfile) - 3] =3D '\0'; + info->schemafile =3D g_strdup_printf("%sreplies", capsfile); } if (!qemuCaps) { @@ -794,5 +798,6 @@ testQemuInfoClear(struct testQemuInfo *info) { VIR_FREE(info->infile); VIR_FREE(info->outfile); + VIR_FREE(info->schemafile); virObjectUnref(info->qemuCaps); } diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index edee6e450c..e7c5032012 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -64,6 +64,7 @@ struct testQemuInfo { unsigned int flags; unsigned int parseFlags; virArch arch; + char *schemafile; }; virCapsPtr testQemuCapsInit(void); --=20 2.26.2