From nobody Mon Feb 9 09:15:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633623153; cv=none; d=zohomail.com; s=zohoarc; b=PVcifO6PooKejB8UrcI1B2Y4W8l7HxcgXB/R2xDyTu7OUYboBZ6xUrF3mtroOPCvXpl2hxaY0Pq5NgFnIld7IXyNzxwObXDuWYpdnmOhwq0x/W/29F7MQnD+IGQz5eeVru2Q6Q6pnMSPS/pZ6CMo6SCadQOg42H0+246IX3jm7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633623153; 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=YQAAHkv/+0XEMV1sIz+cJdxDB5SaPYdrudNjxLMP+zw=; b=THDqqko1z8K6ypCMlc2vp7SsHxSxv5sES4Etu+NbVuCtFxpYJkPv4Gg/n7///Kh/1XEEtzOF9VUk7brJDJKX8Gl9c1SZeDMUkzpw2VNXMhMLq8RbmOa+z2mIx+XPov9SiVY/c+mRd03MJK0Prgctesd0BjApJuiKIpYwAy0U6Bw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633623153647981.9790922819012; Thu, 7 Oct 2021 09:12: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-188-KcQ5E8q0MEmjwSiJw6J54Q-1; Thu, 07 Oct 2021 12:12:31 -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 245E91B94F82; Thu, 7 Oct 2021 15:52:41 +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 A30A653222; Thu, 7 Oct 2021 15:51:58 +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 21DDE4EA39; Thu, 7 Oct 2021 15:51:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197FJqMh024059 for ; Thu, 7 Oct 2021 11:19:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A6045F4F9; Thu, 7 Oct 2021 15:19:52 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id C12945F4FF for ; Thu, 7 Oct 2021 15:19:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633623152; 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=YQAAHkv/+0XEMV1sIz+cJdxDB5SaPYdrudNjxLMP+zw=; b=IiA7qTpzoP4gQP1CieBhZflFnOttvsEFdnxh65r8xJrYx3hLZsM6d6lE1KWwuR7ilddf2/ +AtF2ZXHqZ2bSw9Ug6Q2Y+1NS5FdH/F5Vy6SmDDfCKRz1r8PF7J2oxVawsl/O1MQssGkbk OUTrsC3HK4rjSn8olgdibeeUXehe0q4= X-MC-Unique: KcQ5E8q0MEmjwSiJw6J54Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 053/103] qemu: command: Introduce JSON variant of qemuBuildVirtioDevStr Date: Thu, 7 Oct 2021 17:17:41 +0200 Message-Id: <5df2ae93482f791b28932445788c163c19336034.1633619630.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633623154024100001 Content-Type: text/plain; charset="utf-8" Add a JSON variant of the generator of properties for virtio devices. For convenience both the old and new are for now marked as unused, which will be removed once the conversion is complete. The formatted properties have following types according to QEMU. 'virtio-blk-pci' was used as an example: disable-legacy=3D - on/off/auto (default: "auto") disable-modern=3D - (default: false) iommu_platform=3D - on/off (default: false) ats=3D - on/off (default: false) packed=3D - on/off (default: false) Note that is an enum type without alternates in QMP so it must be represented as a string in JSON. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 58 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 95395805e5..d27e8b2648 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -155,6 +155,16 @@ VIR_ENUM_IMPL(qemuAudioDriver, ); +static const char * +qemuOnOffAuto(virTristateSwitch s) +{ + if (s =3D=3D VIR_TRISTATE_SWITCH_ABSENT) + return NULL; + + return virTristateSwitchTypeToString(s); +} + + static int qemuBuildObjectCommandlineFromJSON(virCommand *cmd, virJSONValue *props, @@ -980,6 +990,52 @@ qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device, } +/** + * qemuBuildVirtioDevProps + * @devtype: virDomainDeviceType of the device. Ex: VIR_DOMAIN_DEVICE_TYPE= _RNG + * @devdata: *Def * of the device definition + * @qemuCaps: qemu capabilities + * + * Build the qemu virtio -device JSON properties name from the passed para= meters. + */ +static G_GNUC_UNUSED virJSONValue * +qemuBuildVirtioDevProps(virDomainDeviceType devtype, + void *devdata, + virQEMUCaps *qemuCaps) +{ + g_autoptr(virJSONValue) props =3D NULL; + virDomainDeviceDef device =3D { .type =3D devtype }; + g_autofree char *model =3D NULL; + virTristateSwitch disableLegacy =3D VIR_TRISTATE_SWITCH_ABSENT; + virTristateSwitch disableModern =3D VIR_TRISTATE_SWITCH_ABSENT; + virDomainVirtioOptions *virtioOptions =3D NULL; + + virDomainDeviceSetData(&device, devdata); + + if (qemuBuildVirtioDevGetConfig(&device, qemuCaps, &model, &virtioOpti= ons, + &disableLegacy, &disableModern) < 0) + return NULL; + + if (virJSONValueObjectCreate(&props, + "s:driver", model, + "S:disable-legacy", qemuOnOffAuto(disable= Legacy), + "T:disable-modern", disableModern, + NULL) < 0) + return NULL; + + if (virtioOptions) { + if (virJSONValueObjectAdd(props, + "T:iommu_platform", virtioOptions->iommu, + "T:ats", virtioOptions->ats, + "T:packed", virtioOptions->packed, + NULL) < 0) + return NULL; + } + + return g_steal_pointer(&props); +} + + /** * qemuBuildVirtioDevStr * @buf: virBuffer * to append the built string @@ -994,7 +1050,7 @@ qemuBuildVirtioDevGetConfig(virDomainDeviceDef *device, * * Returns: -1 on failure, 0 on success */ -static int +static G_GNUC_UNUSED int qemuBuildVirtioDevStr(virBuffer *buf, virQEMUCaps *qemuCaps, virDomainDeviceType devtype, --=20 2.31.1