From nobody Mon Feb 9 09:15:41 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=1633622736; cv=none; d=zohomail.com; s=zohoarc; b=iGHnPiQJiGvmqcopmGBErfBx8CYURkruWRGI7KA5cG5DdWupyaO/v1uQA5tVIgFAmwSPjkqta2jo3UsvXlK1AbxH67Fi1wXB/VOBv3VnoYpwLT6lz357Rwt4yrsO/fQfQQ+aejBYZh5bOAg0ZUwsp26SkY17mZTI6lzqao1iio8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633622736; 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=4JzrFMINvJu9YOLM0QAIKUwH4MCQnUl1+a7zdwennf4=; b=DTSoojRH7j4WhYsYZWk3ufHiYl0/33Cgwiv2ipEKOY1ZgC/ZF0BcrmaO3eNnF9IwPSrNulkwVfUytsPmwaPo87j828jDA8O3mgWYX6CrGOt1bzCha2H6Sani0r5Obd68HAooTS+EozsYpj+CppeZ9HIJu0n5/u7dO2dQ2bn4u0c= 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 1633622736918985.5442663212397; Thu, 7 Oct 2021 09:05:36 -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-320-UjRo-TOcO_G5y_27t4aOMg-1; Thu, 07 Oct 2021 12:05:31 -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 57A97121F77A; Thu, 7 Oct 2021 15:47:52 +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 DBAC192A9A; Thu, 7 Oct 2021 15:47:50 +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 9C3501806D02; Thu, 7 Oct 2021 15:47:50 +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 197FKX8O024156 for ; Thu, 7 Oct 2021 11:20:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id B389C5F503; Thu, 7 Oct 2021 15:20:33 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 239CA5F4F4 for ; Thu, 7 Oct 2021 15:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633622735; 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=4JzrFMINvJu9YOLM0QAIKUwH4MCQnUl1+a7zdwennf4=; b=eW6lbQ/YM5/HP4Kh0rdAqdfoMZ8ReuBSf8uwFiYeXEtLbOcOAbemUgf9+foB6bPK3Y/MyP 1j1+a8fqTieHw0h4J5CXEpTXbjlJ4ovwh1jkId9XIa/kOnI85aqbgLcFbzlL7Flg4j9N4M zcqA5H73T8L15769L4pmpK4jxqKvGn0= X-MC-Unique: UjRo-TOcO_G5y_27t4aOMg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 059/103] qemuBuildShmemCommandLine: Generate via JSON Date: Thu, 7 Oct 2021 17:17:47 +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: 1633622739061100001 Content-Type: text/plain; charset="utf-8" Note that the legacy 'ivshmem' device was already removed upstream, but it's converted so that the code is identical. For the two modern devices QEMU considers the properties being of following types: 'ivshmem-doorbell' chardev=3D - ID of a chardev to use as a backend ioeventfd=3D - on/off (default: true) master=3D - on/off/auto (default: "off") vectors=3D - (default: 1) 'ivshmem-plain' master=3D - on/off/auto (default: "off") memdev=3D> Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 107 ++++++++++++++++++++++------------------ src/qemu/qemu_command.h | 7 ++- src/qemu/qemu_hotplug.c | 6 +-- 3 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 794119a58c..cbd0b2890f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9201,60 +9201,64 @@ qemuBuildSmartcardCommandLine(virLogManager *logMan= ager, } -static char * -qemuBuildShmemDevLegacyStr(virDomainDef *def, - virDomainShmemDef *shmem, - virQEMUCaps *qemuCaps G_GNUC_UNUSED) +static virJSONValue * +qemuBuildShmemDevLegacyProps(virDomainDef *def, + virDomainShmemDef *shmem) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) props =3D NULL; + g_autofree char *size =3D NULL; + const char *shm =3D NULL; + g_autofree char *chardev =3D NULL; - virBufferAddLit(&buf, "ivshmem"); - virBufferAsprintf(&buf, ",id=3D%s", shmem->info.alias); + /* while this would result in a type error with newer qemus, the 'ivsh= mem' + * device was removed in qemu-4.0, so for the sake of not changing the + * commandline we do this hack */ + size =3D g_strdup_printf("%llum", shmem->size >> 20); - if (shmem->size) - virBufferAsprintf(&buf, ",size=3D%llum", shmem->size >> 20); + if (shmem->server.enabled) + chardev =3D g_strdup_printf("char%s", shmem->info.alias); + else + shm =3D shmem->name; - if (!shmem->server.enabled) { - virBufferAsprintf(&buf, ",shm=3D%s", shmem->name); - } else { - virBufferAsprintf(&buf, ",chardev=3Dchar%s", shmem->info.alias); - if (shmem->msi.enabled) { - virBufferAddLit(&buf, ",msi=3Don"); - if (shmem->msi.vectors) - virBufferAsprintf(&buf, ",vectors=3D%u", shmem->msi.vector= s); - if (shmem->msi.ioeventfd) - virBufferAsprintf(&buf, ",ioeventfd=3D%s", - virTristateSwitchTypeToString(shmem->msi= .ioeventfd)); - } - } + if (virJSONValueObjectCreate(&props, + "s:driver", "ivshmem", + "s:id", shmem->info.alias, + "s:size", size, + "S:shm", shm, + "S:chardev", chardev, + "B:msi", shmem->msi.enabled, + "p:vectors", shmem->msi.vectors, + "T:ioeventfd", shmem->msi.ioeventfd, + NULL) < 0) + return NULL; - if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info) < 0) + if (qemuBuildDeviceAddressProps(props, def, &shmem->info) < 0) return NULL; - return virBufferContentAndReset(&buf); + return g_steal_pointer(&props); } -char * -qemuBuildShmemDevStr(virDomainDef *def, - virDomainShmemDef *shmem, - virQEMUCaps *qemuCaps G_GNUC_UNUSED) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - virBufferAdd(&buf, virDomainShmemModelTypeToString(shmem->model), -1); - virBufferAsprintf(&buf, ",id=3D%s", shmem->info.alias); +virJSONValue * +qemuBuildShmemDevProps(virDomainDef *def, + virDomainShmemDef *shmem) +{ + g_autoptr(virJSONValue) props =3D NULL; + g_autofree char *chardev =3D NULL; + g_autofree char *memdev =3D NULL; + virTristateSwitch master =3D VIR_TRISTATE_SWITCH_ABSENT; if (shmem->server.enabled) { - virBufferAsprintf(&buf, ",chardev=3Dchar%s", shmem->info.alias); + chardev =3D g_strdup_printf("char%s", shmem->info.alias); } else { - virBufferAsprintf(&buf, ",memdev=3Dshmmem-%s", shmem->info.alias); + memdev =3D g_strdup_printf("shmmem-%s", shmem->info.alias); switch (shmem->role) { case VIR_DOMAIN_SHMEM_ROLE_MASTER: - virBufferAddLit(&buf, ",master=3Don"); + master =3D VIR_TRISTATE_SWITCH_ON; break; case VIR_DOMAIN_SHMEM_ROLE_PEER: - virBufferAddLit(&buf, ",master=3Doff"); + master =3D VIR_TRISTATE_SWITCH_OFF; break; case VIR_DOMAIN_SHMEM_ROLE_DEFAULT: case VIR_DOMAIN_SHMEM_ROLE_LAST: @@ -9262,17 +9266,21 @@ qemuBuildShmemDevStr(virDomainDef *def, } } - if (shmem->msi.vectors) - virBufferAsprintf(&buf, ",vectors=3D%u", shmem->msi.vectors); - if (shmem->msi.ioeventfd) { - virBufferAsprintf(&buf, ",ioeventfd=3D%s", - virTristateSwitchTypeToString(shmem->msi.ioevent= fd)); - } + if (virJSONValueObjectCreate(&props, + "s:driver", virDomainShmemModelTypeToStri= ng(shmem->model), + "s:id", shmem->info.alias, + "S:chardev", chardev, + "S:memdev", memdev, + "S:master", qemuOnOffAuto(master), + "p:vectors", shmem->msi.vectors, + "T:ioeventfd", shmem->msi.ioeventfd, + NULL) < 0) + return NULL; - if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info) < 0) + if (qemuBuildDeviceAddressProps(props, def, &shmem->info) < 0) return NULL; - return virBufferContentAndReset(&buf); + return g_steal_pointer(&props); } @@ -9308,7 +9316,7 @@ qemuBuildShmemCommandLine(virLogManager *logManager, bool chardevStdioLogd) { g_autoptr(virJSONValue) memProps =3D NULL; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devProps =3D NULL; g_autofree char *chardev =3D NULL; unsigned int cdevflags =3D QEMU_BUILD_CHARDEV_TCP_NOWAIT | QEMU_BUILD_CHARDEV_UNIX_FD_PASS; @@ -9343,7 +9351,7 @@ qemuBuildShmemCommandLine(virLogManager *logManager, switch (shmem->model) { case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: - devstr =3D qemuBuildShmemDevLegacyStr(def, shmem, qemuCaps); + devProps =3D qemuBuildShmemDevLegacyProps(def, shmem); break; case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: @@ -9355,20 +9363,21 @@ qemuBuildShmemCommandLine(virLogManager *logManager, G_GNUC_FALLTHROUGH; case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: - devstr =3D qemuBuildShmemDevStr(def, shmem, qemuCaps); + devProps =3D qemuBuildShmemDevProps(def, shmem); break; case VIR_DOMAIN_SHMEM_MODEL_LAST: break; } - if (!devstr) + if (!devProps) return -1; if (qemuCommandAddExtDevice(cmd, &shmem->info) < 0) return -1; - virCommandAddArgList(cmd, "-device", devstr, NULL); + if (qemuBuildDeviceCommandlineFromJSON(cmd, devProps, qemuCaps) < 0) + return -1; if (shmem->server.enabled) { chardev =3D qemuBuildChrChardevStr(logManager, secManager, diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 86df734c57..3cf1671c79 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -228,10 +228,9 @@ virJSONValue *qemuBuildHotpluggableCPUProps(const virD= omainVcpuDef *vcpu) virJSONValue *qemuBuildShmemBackendMemProps(virDomainShmemDef *shmem) ATTRIBUTE_NONNULL(1); -char *qemuBuildShmemDevStr(virDomainDef *def, - virDomainShmemDef *shmem, - virQEMUCaps *qemuCaps) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +virJSONValue * +qemuBuildShmemDevProps(virDomainDef *def, + virDomainShmemDef *shmem); virJSONValue * qemuBuildWatchdogDevProps(const virDomainDef *def, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3e0c9cf981..3ee0ccd088 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3004,7 +3004,7 @@ qemuDomainAttachShmemDevice(virQEMUDriver *driver, virDomainShmemDef *shmem) { int ret =3D -1; - g_autofree char *shmstr =3D NULL; + g_autoptr(virJSONValue) devProps =3D NULL; g_autofree char *charAlias =3D NULL; g_autofree char *memAlias =3D NULL; bool release_backing =3D false; @@ -3040,7 +3040,7 @@ qemuDomainAttachShmemDevice(virQEMUDriver *driver, (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0)) return -1; - if (!(shmstr =3D qemuBuildShmemDevStr(vm->def, shmem, priv->qemuCaps))) + if (!(devProps =3D qemuBuildShmemDevProps(vm->def, shmem))) goto cleanup; if (shmem->server.enabled) { @@ -3067,7 +3067,7 @@ qemuDomainAttachShmemDevice(virQEMUDriver *driver, if (qemuDomainAttachExtensionDevice(priv->mon, &shmem->info) < 0) goto exit_monitor; - if (qemuMonitorAddDevice(priv->mon, shmstr) < 0) { + if (qemuMonitorAddDeviceProps(priv->mon, &devProps) < 0) { ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &shmem->in= fo)); goto exit_monitor; } --=20 2.31.1