From nobody Mon Feb 9 17:59:11 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=1633621466; cv=none; d=zohomail.com; s=zohoarc; b=hn0etVNx8qEvGPBaKDQrVwOIlgDEdXD97K0K2MUYZIzKY3zP+zKiMo71yLdxsooRZ41lHDKL+b3hTdu5MZrlL9pMcOA3Gd7oWG0JwWnj/JYpLHYggCcvU0XXgVpJftxzAxw8BV6f5wcajEVInL8KcbwHf8aMothaI76fN7kYFi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633621466; 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=2wdf3zs989RZDR2AiHOl3sYKVWlooLsu8uWSCasjqNg=; b=VUY/ZYb4aPhAq50VtIoNgwtStFRHisUWgtUQt++Vp78BKbKQcx3ByB+Ze1GxlbiO82C1Kof6wnlEc3PrBu7rrPOZ4JSaC5EdGmA1oHcClP2GmRaCA2U7fyxuqYlqd4vJZvWKc7rlyxurdqPhbC5/OXFUPAOaCo0hC7TdxEyzak8= 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 1633621466777144.3057484793195; Thu, 7 Oct 2021 08:44:26 -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-28-2pqbp9SUPU6FIBwK2Ui92Q-1; Thu, 07 Oct 2021 11:44:23 -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 BC0E9A42381; Thu, 7 Oct 2021 15:33:58 +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 9400813B98F; Thu, 7 Oct 2021 15:33: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 EC4994EA37; Thu, 7 Oct 2021 15:33:57 +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 197FLLUG024608 for ; Thu, 7 Oct 2021 11:21:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1DEF25F4F4; Thu, 7 Oct 2021 15:21:21 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 817B86D000 for ; Thu, 7 Oct 2021 15:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633621465; 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=2wdf3zs989RZDR2AiHOl3sYKVWlooLsu8uWSCasjqNg=; b=gfhvhD5ItR6VYPEiYm1WqdZcoChNhF3bWRhVT4lyWL1vN+yBlFhGtIsaeyQJFUpp02X4yC Mh+43M7zZrjtSnYl95MOAsSPELjCklgX2xz5WqaeoNwciMl3NmZqsTlE0l9uO9fhBU6SlD Sw0PWD+SYORmTC+4RVa4MdLNzA2ufgE= X-MC-Unique: 2pqbp9SUPU6FIBwK2Ui92Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 097/103] qemuBuildVideoCommandLine: Generate via JSON Date: Thu, 7 Oct 2021 17:18:25 +0200 Message-Id: <363477f4974ec88906b50220216704091390aac3.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: 1633621467678100003 Content-Type: text/plain; charset="utf-8" We control the following properties of the devices in question: 'virtio-gpu' virgl=3D - on/off (default: true) 'qxl' ram_size=3D - (default: 67108864) vram_size=3D - (default: 67108864) vram64_size_mb=3D - (default: 4294967295) vgamem_mb=3D - (default: 16) max_outputs=3D - (default: 0) 'vhost-user-gpu' max_outputs=3D - (default: 1) chardev=3D 'VGA' vgamem_mb=3D - (default: 16) 'bochs-display' vgamem=3D - (default: 16777216) common for all devices: xres=3D - (default: 0) yres=3D - (default: 0) The only noticable change is using memory size in bytes for 'bochs-display' instead of kibibytes. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 130 ++++++++++-------- ...eo-bochs-display-device.x86_64-latest.args | 2 +- 2 files changed, 74 insertions(+), 58 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 71816288e5..b9c9027748 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4645,99 +4645,120 @@ qemuBuildSoundCommandLine(virCommand *cmd, } -static char * -qemuBuildDeviceVideoStr(const virDomainDef *def, +static int +qemuBuildDeviceVideoCmd(virCommand *cmd, + const virDomainDef *def, virDomainVideoDef *video, virQEMUCaps *qemuCaps) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; const char *model =3D NULL; - virTristateSwitch accel3d =3D VIR_TRISTATE_SWITCH_ABSENT; + virTristateSwitch virgl =3D VIR_TRISTATE_SWITCH_ABSENT; bool virtio =3D false; bool virtioBusSuffix =3D false; - - if (video->accel) - accel3d =3D video->accel->accel3d; + g_autoptr(virJSONValue) props =3D NULL; if (!(model =3D qemuDeviceVideoGetModel(qemuCaps, video, &virtio, &vir= tioBusSuffix))) - return NULL; + return -1; if (virtio) { - if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_VIDEO,= video) < 0) { - return NULL; - } + if (!(props =3D qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_VIDEO, v= ideo, qemuCaps))) + return -1; } else { - virBufferAsprintf(&buf, "%s", model); + if (virJSONValueObjectCreate(&props, + "s:driver", model, + NULL) < 0) + return -1; } - virBufferAsprintf(&buf, ",id=3D%s", video->info.alias); - if (video->backend !=3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER && video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_VIRTIO) { if (video->accel && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL) && - (accel3d =3D=3D VIR_TRISTATE_SWITCH_ON || - accel3d =3D=3D VIR_TRISTATE_SWITCH_OFF)) { - virBufferAsprintf(&buf, ",virgl=3D%s", - virTristateSwitchTypeToString(accel3d)); + virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL)) { + virgl =3D video->accel->accel3d; } } - if (video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_QXL) { - if (video->ram) { - /* QEMU accepts bytes for ram_size. */ - virBufferAsprintf(&buf, ",ram_size=3D%u", video->ram * 1024); - } + if (virJSONValueObjectAdd(props, + "s:id", video->info.alias, + "T:virgl", virgl, + NULL) < 0) + return -1; - if (video->vram) { - /* QEMU accepts bytes for vram_size. */ - virBufferAsprintf(&buf, ",vram_size=3D%u", video->vram * 1024); - } + if (video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_QXL) { + if (virJSONValueObjectAdd(props, + "p:ram_size", video->ram * 1024, + "p:vram_size", video->vram * 1024, + NULL) < 0) + return -1; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QXL_VRAM64)) { - /* QEMU accepts mebibytes for vram64_size_mb. */ - virBufferAsprintf(&buf, ",vram64_size_mb=3D%u", video->vram64 = / 1024); + if (virJSONValueObjectAdd(props, + "u:vram64_size_mb", video->vram64 / = 1024, + NULL) < 0) + return -1; } if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QXL_VGAMEM)) { - /* QEMU accepts mebibytes for vgamem_mb. */ - virBufferAsprintf(&buf, ",vgamem_mb=3D%u", video->vgamem / 102= 4); + if (virJSONValueObjectAdd(props, + "u:vgamem_mb", video->vgamem / 1024, + NULL) < 0) + return -1; } if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QXL_MAX_OUTPUTS)) { - if (video->heads) - virBufferAsprintf(&buf, ",max_outputs=3D%u", video->heads); + if (virJSONValueObjectAdd(props, + "p:max_outputs", video->heads, + NULL) < 0) + return -1; } } else if (video->backend =3D=3D VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUS= ER) { g_autofree char *alias =3D qemuDomainGetVhostUserChrAlias(video->i= nfo.alias); - if (video->heads) - virBufferAsprintf(&buf, ",max_outputs=3D%u", video->heads); - virBufferAsprintf(&buf, ",chardev=3D%s", alias); + + if (virJSONValueObjectAdd(props, + "p:max_outputs", video->heads, + "s:chardev", alias, + NULL) < 0) + return -1; } else if (video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_VIRTIO) { - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS)) { - if (video->heads) - virBufferAsprintf(&buf, ",max_outputs=3D%u", video->heads); - } + unsigned int heads =3D 0; + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS)) + heads =3D video->heads; + + if (virJSONValueObjectAdd(props, + "p:max_outputs", heads, + NULL) < 0) + return -1; } else if ((video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_VGA && virQEMUCapsGet(qemuCaps, QEMU_CAPS_VGA_VGAMEM)) || (video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_VMVGA && virQEMUCapsGet(qemuCaps, QEMU_CAPS_VMWARE_SVGA_VGAMEM))) { - if (video->vram) - virBufferAsprintf(&buf, ",vgamem_mb=3D%u", video->vram / 1024); + if (virJSONValueObjectAdd(props, + "p:vgamem_mb", video->vram / 1024, + NULL) < 0) + return -1; } else if (video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_BOCHS) { - if (video->vram) - virBufferAsprintf(&buf, ",vgamem=3D%uk", video->vram); + if (virJSONValueObjectAdd(props, + "p:vgamem", video->vram * 1024, + NULL) < 0) + return -1; } - if (video->res && video->res->x && video->res->y) { - /* QEMU accepts resolution xres and yres. */ - virBufferAsprintf(&buf, ",xres=3D%u,yres=3D%u", video->res->x, vid= eo->res->y); + if (video->res) { + if (virJSONValueObjectAdd(props, + "p:xres", video->res->x, + "p:yres", video->res->y, + NULL) < 0) + return -1; } - if (qemuBuildDeviceAddressStr(&buf, def, &video->info) < 0) - return NULL; + if (qemuBuildDeviceAddressProps(props, def, &video->info) < 0) + return -1; - return virBufferContentAndReset(&buf); + if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0) + return -1; + + return 0; } @@ -4786,7 +4807,6 @@ qemuBuildVideoCommandLine(virCommand *cmd, } for (i =3D 0; i < def->nvideos; i++) { - g_autofree char *str =3D NULL; virDomainVideoDef *video =3D def->videos[i]; if (video->type =3D=3D VIR_DOMAIN_VIDEO_TYPE_NONE) @@ -4795,12 +4815,8 @@ qemuBuildVideoCommandLine(virCommand *cmd, if (qemuCommandAddExtDevice(cmd, &def->videos[i]->info, qemuCaps) = < 0) return -1; - virCommandAddArg(cmd, "-device"); - - if (!(str =3D qemuBuildDeviceVideoStr(def, video, qemuCaps))) + if (qemuBuildDeviceVideoCmd(cmd, def, video, qemuCaps) < 0) return -1; - - virCommandAddArg(cmd, str); } return 0; diff --git a/tests/qemuxml2argvdata/video-bochs-display-device.x86_64-lates= t.args b/tests/qemuxml2argvdata/video-bochs-display-device.x86_64-latest.ar= gs index 834986edd1..3af0ecf2b1 100644 --- a/tests/qemuxml2argvdata/video-bochs-display-device.x86_64-latest.args +++ b/tests/qemuxml2argvdata/video-bochs-display-device.x86_64-latest.args @@ -31,7 +31,7 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"dir= ect":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \ -device ide-hd,bus=3Dide.0,unit=3D0,drive=3Dlibvirt-1-format,id=3Dide0-0-0= ,bootindex=3D1,write-cache=3Don \ -audiodev id=3Daudio1,driver=3Dnone \ --device bochs-display,id=3Dvideo0,vgamem=3D16384k,bus=3Dpci.0,addr=3D0x2 \ +-device bochs-display,id=3Dvideo0,vgamem=3D16777216,bus=3Dpci.0,addr=3D0x2= \ -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ -msg timestamp=3Don --=20 2.31.1