From nobody Mon Feb 9 12:11:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1633621147; cv=none; d=zohomail.com; s=zohoarc; b=WBy34p+MeWg1cUBdSP58RESrYDQh5Mid522EOne8+JFzMJnPjw/c2xeurftoKSj6nel0un9oM9UDUkHJbg9gmFlasOEZn5uh7nRJ1Ko7Yeyoag7gHPd/CixbbdlfnzSaCequ/V+nAqf/8119NolAj1H2EAy8WZBqhxKPNDcX5aU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633621147; 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=RtnxDSSzZv1H/PLc2FTpUGEPEVEsp3Uy9wWSvI0/+iI=; b=DpwdJ7RknhQjKyhU86k+/EMqjPvXcjTdUvAQBmoSrJyCxezcxJ57/0bucUuoX2XXKjlZFzme4qqiyMyKkC8j5JnL0ldCT31AUQ3UqcdtM91MbC1W9qgIHX6S2vHIaF0r4m/O7s5Zv2WayINLbcN8rf1tQ+Ls/FCNsk2V1mgiR38= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633621147191277.3677369986715; Thu, 7 Oct 2021 08:39: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-215-eOqZ44x6PVGg3z5BSiP84g-1; Thu, 07 Oct 2021 11:39:04 -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 771901886A89; Thu, 7 Oct 2021 15:30:32 +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 4DB67780C4; Thu, 7 Oct 2021 15:30:32 +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 168331800B8B; Thu, 7 Oct 2021 15:30:32 +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 197FKiMF024268 for ; Thu, 7 Oct 2021 11:20:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 11D1A5F503; Thu, 7 Oct 2021 15:20:44 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 758C85F4F4 for ; Thu, 7 Oct 2021 15:20:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633621146; 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=RtnxDSSzZv1H/PLc2FTpUGEPEVEsp3Uy9wWSvI0/+iI=; b=UiGtR2esab58t40ayPxwJ0dx11CKAb+NNDWl+0W2znP/YXJkog/s2OEuKZpsy23URdwVGc FmVtHuIVKYCWfJxAIKFOXdzTbPo7nbU0A2FHuZ84fo/YySRz67cruwHU4ZKHYugnmqpmsJ /8tRHI2Ki2pTNrX0cwMkv/OMmKoPCZ4= X-MC-Unique: eOqZ44x6PVGg3z5BSiP84g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 069/103] qemuBuildHostdevCommandLine: Format PCI host devices via JSON Date: Thu, 7 Oct 2021 17:17:57 +0200 Message-Id: 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.16 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: 1633621148375100001 Content-Type: text/plain; charset="utf-8" For properties we use these are the QEMU types: host=3D - Address (bus/device/function) of the host devi= ce, example: 04:10.0 bootindex=3D failover_pair_id=3D Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 69 ++++++++++++++++++++++------------------- src/qemu/qemu_command.h | 6 ++-- src/qemu/qemu_hotplug.c | 6 ++-- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e8043f0055..5a1ad69148 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4721,20 +4721,23 @@ qemuBuildVideoCommandLine(virCommand *cmd, } -char * -qemuBuildPCIHostdevDevStr(const virDomainDef *def, - virDomainHostdevDef *dev, - virQEMUCaps *qemuCaps G_GNUC_UNUSED) +virJSONValue * +qemuBuildPCIHostdevDevProps(const virDomainDef *def, + virDomainHostdevDef *dev) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) props =3D NULL; virDomainHostdevSubsysPCI *pcisrc =3D &dev->source.subsys.u.pci; - int backend =3D pcisrc->backend; virDomainNetTeamingInfo *teaming; + g_autofree char *host =3D g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, + pcisrc->addr.domain, + pcisrc->addr.bus, + pcisrc->addr.slot, + pcisrc->addr.function); + const char *failover_pair_id =3D NULL; /* caller has to assign proper passthrough backend type */ - switch ((virDomainHostdevSubsysPCIBackendType)backend) { + switch ((virDomainHostdevSubsysPCIBackendType) pcisrc->backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: - virBufferAddLit(&buf, "vfio-pci"); break; case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM: @@ -4743,25 +4746,10 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def, case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid PCI passthrough type '%s'"), - virDomainHostdevSubsysPCIBackendTypeToString(backen= d)); + virDomainHostdevSubsysPCIBackendTypeToString(pcisrc= ->backend)); return NULL; } - virBufferAddLit(&buf, ",host=3D"); - virBufferAsprintf(&buf, - VIR_PCI_DEVICE_ADDRESS_FMT, - pcisrc->addr.domain, - pcisrc->addr.bus, - pcisrc->addr.slot, - pcisrc->addr.function); - virBufferAsprintf(&buf, ",id=3D%s", dev->info->alias); - if (dev->info->effectiveBootIndex > 0) - virBufferAsprintf(&buf, ",bootindex=3D%u", dev->info->effectiveBoo= tIndex); - if (qemuBuildDeviceAddressStr(&buf, def, dev->info) < 0) - return NULL; - if (qemuBuildRomStr(&buf, dev->info) < 0) - return NULL; - if (dev->parentnet) teaming =3D dev->parentnet->teaming; else @@ -4769,11 +4757,29 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def, if (teaming && teaming->type =3D=3D VIR_DOMAIN_NET_TEAMING_TYPE_TRANSIENT && - teaming->persistent) { - virBufferAsprintf(&buf, ",failover_pair_id=3D%s", teaming->persis= tent); - } + teaming->persistent) + failover_pair_id =3D teaming->persistent; - return virBufferContentAndReset(&buf); + if (virJSONValueObjectCreate(&props, + "s:driver", "vfio-pci", + "s:host", host, + "s:id", dev->info->alias, + "p:bootindex", dev->info->effectiveBootIn= dex, + NULL) < 0) + return NULL; + + if (qemuBuildDeviceAddressProps(props, def, dev->info) < 0) + return NULL; + + if (qemuBuildRomProps(props, dev->info) < 0) + return NULL; + + if (virJSONValueObjectAdd(props, + "S:failover_pair_id", failover_pair_id, + NULL) < 0) + return NULL; + + return g_steal_pointer(&props); } @@ -5525,12 +5531,11 @@ qemuBuildHostdevCommandLine(virCommand *cmd, if (qemuCommandAddExtDevice(cmd, hostdev->info, qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-device"); - devstr =3D qemuBuildPCIHostdevDevStr(def, hostdev, qemuCaps); - if (!devstr) + if (!(devprops =3D qemuBuildPCIHostdevDevProps(def, hostdev))) return -1; - virCommandAddArg(cmd, devstr); + if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps= ) < 0) + return -1; break; /* SCSI */ diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 81cdbed384..8ad87f4277 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -165,9 +165,9 @@ qemuBuildMemoryDeviceProps(const virDomainDef *def, virDomainMemoryDef *mem); /* Current, best practice */ -char *qemuBuildPCIHostdevDevStr(const virDomainDef *def, - virDomainHostdevDef *dev, - virQEMUCaps *qemuCaps); +virJSONValue * +qemuBuildPCIHostdevDevProps(const virDomainDef *def, + virDomainHostdevDef *dev); virJSONValue * qemuBuildRNGDevProps(const virDomainDef *def, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ea7028eae5..67aed2c128 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1629,7 +1629,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, { .hostdev =3D hostdev } }; virDomainDeviceInfo *info =3D hostdev->info; int ret; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; bool releaseaddr =3D false; bool teardowncgroup =3D false; bool teardownlabel =3D false; @@ -1706,7 +1706,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, goto error; } - if (!(devstr =3D qemuBuildPCIHostdevDevStr(vm->def, hostdev, priv->qem= uCaps))) + if (!(devprops =3D qemuBuildPCIHostdevDevProps(vm->def, hostdev))) goto error; qemuDomainObjEnterMonitor(driver, vm); @@ -1714,7 +1714,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, if ((ret =3D qemuDomainAttachExtensionDevice(priv->mon, hostdev->info)= ) < 0) goto exit_monitor; - if ((ret =3D qemuMonitorAddDevice(priv->mon, devstr)) < 0) + if ((ret =3D qemuMonitorAddDeviceProps(priv->mon, &devprops)) < 0) ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->i= nfo)); exit_monitor: --=20 2.31.1