From nobody Mon Feb 9 10:27:19 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=1633623975; cv=none; d=zohomail.com; s=zohoarc; b=LIjKcNunSQnFFjGzKrxgH3zU9BUfkiOFIJYNgFBbNPdhvJXv1PqCFeFIPG4JeX7v1kOEqoEq5unTBo7oyKwgqWfW+kbJ2j+owg3Pl6W9XvJwAk7/uv8y582IF6WFuikHTGUXEGXXKMTHFjmwtlw8XkH1qqzmhBXt5rV7qQdl0/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633623975; 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=dlU9EBQR5u9KAJ1p8vCYXmgz/GHB07yPByHLRJvcNe4=; b=PhATSad4xa8cvO94CEeWuqNL5wj2DbEPMSSPjjpJRzqXMJadUscRP7Vc6n17yFj+Yl8YEKd6xIXaRN8hGWrePRkNzpD5RQGSL+asHcd/26Ji5NuffAwvmyPaGQ4CC0/oTM3Ok21xVYdsFZ4P5QdxOPEI8sRnlBgN6n7Ybr07Lbo= 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 1633623975841152.17645714289733; Thu, 7 Oct 2021 09:26:15 -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-571-ZEjvLGSSNxSb8gjlJX9vBA-1; Thu, 07 Oct 2021 12:26:13 -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 F22D78EDEF7; Thu, 7 Oct 2021 15:58:22 +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 8C5A610DE18; Thu, 7 Oct 2021 15:57:35 +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 5C9AF1803B30; Thu, 7 Oct 2021 15:57:35 +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 197FLE7d024552 for ; Thu, 7 Oct 2021 11:21:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id B3B8B5D6BA; Thu, 7 Oct 2021 15:21:14 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 173E95F4E7 for ; Thu, 7 Oct 2021 15:21:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633623974; 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=dlU9EBQR5u9KAJ1p8vCYXmgz/GHB07yPByHLRJvcNe4=; b=DOSF7Ev/GMCfxH2N8cAo7FKgH1mPgWY9BZ68CXqBaJVHcs22l5rcQeTExftI8t6fRbXLca qQA43kj+iwBhRbx3AvaUPr91Fx2r0x/21qee0T5kdAUqVbK+ovdlKgfkVXeBFaFpxIT0+R /yYmIjP6FQ+8xHr1YSr0URlpjCnWIA0= X-MC-Unique: ZEjvLGSSNxSb8gjlJX9vBA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 092/103] qemuBuildHostdevCommandLine: Generate via JSON Date: Thu, 7 Oct 2021 17:18:20 +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.14 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: 1633623976671100001 Content-Type: text/plain; charset="utf-8" Build the properties of 'vhost-scsi' device via JSON. In comparison to previous similar refactors this also modifies the hotplug code to attach the vhost fd handle explicitly rather than using 'qemuMonitorAddDeviceWithFd'. The 'vhost-scsi' device doesn't have any special (non-string) properties. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 44 +++++++++++++++++++++-------------------- src/qemu/qemu_command.h | 10 +++++----- src/qemu/qemu_hotplug.c | 31 ++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 954513ce83..a92bdd62f9 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4964,30 +4964,33 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDef= *dev) return virBufferContentAndReset(&buf); } -char * -qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def, - virDomainHostdevDef *dev, - virQEMUCaps *qemuCaps, - char *vhostfdName) + +virJSONValue * +qemuBuildSCSIVHostHostdevDevProps(const virDomainDef *def, + virDomainHostdevDef *dev, + virQEMUCaps *qemuCaps, + char *vhostfdName) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) props =3D NULL; virDomainHostdevSubsysSCSIVHost *hostsrc =3D &dev->source.subsys.u.scs= i_host; - if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_HOSTDEV, d= ev) < 0) { + if (!(props =3D qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_HOSTDEV, dev= , qemuCaps))) return NULL; - } - virBufferAsprintf(&buf, ",wwpn=3D%s,vhostfd=3D%s,id=3D%s", - hostsrc->wwpn, - vhostfdName, - dev->info->alias); + if (virJSONValueObjectAdd(props, + "s:wwpn", hostsrc->wwpn, + "s:vhostfd", vhostfdName, + "s:id", dev->info->alias, + NULL) < 0) + return NULL; - if (qemuBuildDeviceAddressStr(&buf, def, dev->info) < 0) + if (qemuBuildDeviceAddressProps(props, def, dev->info) < 0) return NULL; - return virBufferContentAndReset(&buf); + return g_steal_pointer(&props); } + static char * qemuBuildSCSIHostdevDrvStr(virDomainHostdevDef *dev) { @@ -5550,7 +5553,6 @@ qemuBuildHostdevCommandLine(virCommand *cmd, virDomainHostdevDef *hostdev =3D def->hostdevs[i]; virDomainHostdevSubsys *subsys =3D &hostdev->source.subsys; virDomainHostdevSubsysMediatedDev *mdevsrc =3D &subsys->u.mdev; - g_autofree char *devstr =3D NULL; g_autoptr(virJSONValue) devprops =3D NULL; g_autofree char *vhostfdName =3D NULL; int vhostfd =3D -1; @@ -5603,14 +5605,14 @@ qemuBuildHostdevCommandLine(virCommand *cmd, virCommandPassFD(cmd, vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - virCommandAddArg(cmd, "-device"); - if (!(devstr =3D qemuBuildSCSIVHostHostdevDevStr(def, - hostdev, - qemuCaps, - vhostfdName= ))) + if (!(devprops =3D qemuBuildSCSIVHostHostdevDevProps(def, + hostdev, + qemuCap= s, + vhostfd= Name))) return -1; - virCommandAddArg(cmd, devstr); + if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemu= Caps) < 0) + return -1; } break; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 65e896b634..2a87a8a929 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -195,11 +195,11 @@ qemuBlockStorageSourceAttachData * qemuBuildHostdevSCSIDetachPrepare(virDomainHostdevDef *hostdev, virQEMUCaps *qemuCaps); -char * -qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def, - virDomainHostdevDef *dev, - virQEMUCaps *qemuCaps, - char *vhostfdName); +virJSONValue * +qemuBuildSCSIVHostHostdevDevProps(const virDomainDef *def, + virDomainHostdevDef *dev, + virQEMUCaps *qemuCaps, + char *vhostfdName); virJSONValue * qemuBuildHostdevMediatedDevProps(const virDomainDef *def, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c7da38b49b..1e91fb393e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2743,7 +2743,9 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriver *driver, virDomainCCWAddressSet *ccwaddrs =3D NULL; g_autofree char *vhostfdName =3D NULL; int vhostfd =3D -1; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; + bool removeextension =3D false; + bool removehandle =3D false; bool teardowncgroup =3D false; bool teardownlabel =3D false; bool teardowndevice =3D false; @@ -2790,10 +2792,10 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriver *driv= er, if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) <= 0) goto cleanup; - if (!(devstr =3D qemuBuildSCSIVHostHostdevDevStr(vm->def, - hostdev, - priv->qemuCaps, - vhostfdName))) + if (!(devprops =3D qemuBuildSCSIVHostHostdevDevProps(vm->def, + hostdev, + priv->qemuCaps, + vhostfdName))) goto cleanup; VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1); @@ -2803,13 +2805,24 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriver *driv= er, if ((ret =3D qemuDomainAttachExtensionDevice(priv->mon, hostdev->info)= ) < 0) goto exit_monitor; - if ((ret =3D qemuMonitorAddDeviceWithFd(priv->mon, devstr, vhostfd, - vhostfdName)) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->i= nfo)); + removeextension =3D true; + + if ((ret =3D qemuMonitorSendFileHandle(priv->mon, vhostfdName, vhostfd= ))) goto exit_monitor; - } + + removehandle =3D true; + + if ((ret =3D qemuMonitorAddDeviceProps(priv->mon, &devprops)) < 0) + goto exit_monitor; + + removeextension =3D false; + removehandle =3D false; exit_monitor: + if (removehandle) + ignore_value(qemuMonitorCloseFileHandle(priv->mon, vhostfdName)); + if (removeextension) + ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->i= nfo)); if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) goto audit; --=20 2.31.1