From nobody Mon Feb 9 10:32:28 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=1633622959; cv=none; d=zohomail.com; s=zohoarc; b=H71bg3SIj88czIGt+l3j6vzWx8aW9W8GQYqC7foLjqWZgsTbH0E9xkquxVa06j2rypjjVZuMsKuoEQ64f9DU4pJ9bjQV/wi+b+PHnS1kWbsSA0w61jQJ07iIGNtVZBzjAhqcyqXE8BmKq7hBOAKirp2L/OhWE3pFFJgBuWrgZcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633622959; 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=CahxU/IeyxQvTROW90A4dCXxRyw9hfPsotfFQmS6LrI=; b=GNvVKDTg/vYr5fxB1z4ZBKtm+IsKysHbAs40/Quc0jh6J3P5fFJrrwd3h8ejsXgSfK8XbpHQ8I1bCeOqWD8ldaB5OMi0Ps6cnorbL1UWsza6zFe8IPcEo2h3BWIWy97MDVYswJOsEZO9g0fa7RsC/ahiBGuRxvnVBfr4Fy8clAw= 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 1633622959843565.9964505345066; Thu, 7 Oct 2021 09:09:19 -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-600-Vkcq9f6-PZOPYxJ3xEmI4g-1; Thu, 07 Oct 2021 12:09: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 E12ED10925E1; Thu, 7 Oct 2021 15:51:07 +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 193BB2AAFF6; Thu, 7 Oct 2021 15:50: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 D11301800B8B; Thu, 7 Oct 2021 15:50:34 +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 197FLG4O024560 for ; Thu, 7 Oct 2021 11:21:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id C461B6CA33; Thu, 7 Oct 2021 15:21:15 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C72C5F4F3 for ; Thu, 7 Oct 2021 15:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633622957; 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=CahxU/IeyxQvTROW90A4dCXxRyw9hfPsotfFQmS6LrI=; b=WLjq8iqSgmyfDwiK8KzdViVHDP9h0wo84h6zAey7IXuYZNaD/ybBinvq/3e8pbIeJaGaBW f8imkt5Z9Wdc0fHXi+WnAScjlXMHB4Xw80NVqZQzf2z5j105qUwCPXHVr9AXRcGidGvfmb lxgILN4pz1w3ahSfRJ1m5JINay0AVVA= X-MC-Unique: Vkcq9f6-PZOPYxJ3xEmI4g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 093/103] qemuBuildVsockCommandLine: Generate via JSON Date: Thu, 7 Oct 2021 17:18:21 +0200 Message-Id: <6b1c0fbc0d6aee0643513df41a7bb899f7b12b7b.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.15 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: 1633622960798100001 Content-Type: text/plain; charset="utf-8" Build the properties of 'vhost-vsock' 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 properties of vhost-vsock have the following types according to QEMU: guest-cid=3D - (default: 0) vhostfd=3D Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 36 ++++++++++++++++++++---------------- src/qemu/qemu_command.h | 12 +++++------- src/qemu/qemu_hotplug.c | 21 ++++++++++++++++----- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a92bdd62f9..c566ab7bd5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10553,27 +10553,30 @@ qemuBuildSeccompSandboxCommandLine(virCommand *cm= d, } -char * -qemuBuildVsockDevStr(virDomainDef *def, - virDomainVsockDef *vsock, - virQEMUCaps *qemuCaps, - const char *fdprefix) +virJSONValue * +qemuBuildVsockDevProps(virDomainDef *def, + virDomainVsockDef *vsock, + virQEMUCaps *qemuCaps, + const char *fdprefix) { qemuDomainVsockPrivate *priv =3D (qemuDomainVsockPrivate *)vsock->priv= ateData; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) props =3D NULL; + g_autofree char *vhostfd =3D g_strdup_printf("%s%u", fdprefix, priv->v= hostfd); - if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_VSOCK, vso= ck) < 0) { + if (!(props =3D qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_VSOCK, vsock= , qemuCaps))) return NULL; - } - virBufferAsprintf(&buf, ",id=3D%s", vsock->info.alias); - virBufferAsprintf(&buf, ",guest-cid=3D%u", vsock->guest_cid); - virBufferAsprintf(&buf, ",vhostfd=3D%s%u", fdprefix, priv->vhostfd); + if (virJSONValueObjectAdd(props, + "s:id", vsock->info.alias, + "u:guest-cid", vsock->guest_cid, + "s:vhostfd", vhostfd, + NULL) < 0) + return NULL; - if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info) < 0) + if (qemuBuildDeviceAddressProps(props, def, &vsock->info) < 0) return NULL; - return virBufferContentAndReset(&buf); + return g_steal_pointer(&props); } @@ -10584,9 +10587,9 @@ qemuBuildVsockCommandLine(virCommand *cmd, virQEMUCaps *qemuCaps) { qemuDomainVsockPrivate *priv =3D (qemuDomainVsockPrivate *)vsock->priv= ateData; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; - if (!(devstr =3D qemuBuildVsockDevStr(def, vsock, qemuCaps, ""))) + if (!(devprops =3D qemuBuildVsockDevProps(def, vsock, qemuCaps, ""))) return -1; virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); @@ -10595,7 +10598,8 @@ qemuBuildVsockCommandLine(virCommand *cmd, if (qemuCommandAddExtDevice(cmd, &vsock->info, qemuCaps) < 0) return -1; - virCommandAddArgList(cmd, "-device", devstr, NULL); + if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0) + return -1; return 0; } diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 2a87a8a929..56999b7424 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -248,13 +248,11 @@ virJSONValue * qemuBuildInputUSBDevProps(const virDomainDef *def, virDomainInputDef *dev); -char * -qemuBuildVsockDevStr(virDomainDef *def, - virDomainVsockDef *vsock, - virQEMUCaps *qemuCaps, - const char *fdprefix) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) - ATTRIBUTE_NONNULL(4); +virJSONValue * +qemuBuildVsockDevProps(virDomainDef *def, + virDomainVsockDef *vsock, + virQEMUCaps *qemuCaps, + const char *fdprefix); /* this function is exported so that tests can mock the FDs */ int diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1e91fb393e..b9937220db 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3349,7 +3349,9 @@ qemuDomainAttachVsockDevice(virQEMUDriver *driver, const char *fdprefix =3D "vsockfd"; bool releaseaddr =3D false; g_autofree char *fdname =3D NULL; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; + bool removeextension =3D false; + bool removehandle =3D false; int ret =3D -1; if (vm->def->vsock) { @@ -3369,7 +3371,7 @@ qemuDomainAttachVsockDevice(virQEMUDriver *driver, fdname =3D g_strdup_printf("%s%u", fdprefix, vsockPriv->vhostfd); - if (!(devstr =3D qemuBuildVsockDevStr(vm->def, vsock, priv->qemuCaps, = fdprefix))) + if (!(devprops =3D qemuBuildVsockDevProps(vm->def, vsock, priv->qemuCa= ps, fdprefix))) goto cleanup; qemuDomainObjEnterMonitor(driver, vm); @@ -3377,10 +3379,15 @@ qemuDomainAttachVsockDevice(virQEMUDriver *driver, if (qemuDomainAttachExtensionDevice(priv->mon, &vsock->info) < 0) goto exit_monitor; - if (qemuMonitorAddDeviceWithFd(priv->mon, devstr, vsockPriv->vhostfd, = fdname) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &vsock->in= fo)); + removeextension =3D true; + + if ((ret =3D qemuMonitorSendFileHandle(priv->mon, fdname, vsockPriv->v= hostfd)) < 0) + goto exit_monitor; + + removehandle =3D true; + + if ((ret =3D qemuMonitorAddDeviceProps(priv->mon, &devprops)) < 0) goto exit_monitor; - } if (qemuDomainObjExitMonitor(driver, vm) < 0) { releaseaddr =3D false; @@ -3402,6 +3409,10 @@ qemuDomainAttachVsockDevice(virQEMUDriver *driver, return ret; exit_monitor: + if (removehandle) + ignore_value(qemuMonitorCloseFileHandle(priv->mon, fdname)); + if (removeextension) + ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &vsock->in= fo)); if (qemuDomainObjExitMonitor(driver, vm) < 0) releaseaddr =3D false; goto cleanup; --=20 2.31.1