On Fri, Jun 11, 2021 at 4:55 PM Michal Prívozník <mprivozn@redhat.com> wrote:
On 6/9/21 10:32 AM, Han Han wrote:
> QEMU 6.1 will add virtio-gpu-gl-pci device to replace the virgl property
> of virtio-gpu-pci device. Adapt to that change.
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1967356
>
> Signed-off-by: Han Han <hhan@redhat.com>
> ---
>  src/qemu/qemu_command.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 7834fc2130..6b9f13b219 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -4228,6 +4228,11 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
>      }

>      if (STREQ(model, "virtio-gpu") || STREQ(model, "vhost-user-gpu")) {
> +        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_GL_PCI) &&
> +            (video->accel->accel3d == VIR_TRISTATE_SWITCH_ON) &&

Please note, that video->accel might be NULL (if there's no
<acceleration/>). Since there's already a similar check we can do the
following:

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6b9f13b219..a7dbe4584c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4203,6 +4203,10 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
 {
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     const char *model = NULL;
+    virTristateSwitch accel3d = VIR_TRISTATE_SWITCH_ABSENT;
+
+    if (video->accel)
+        accel3d = video->accel->accel3d;

     /* We try to chose the best model for primary video device by preferring
      * model with VGA compatibility mode.  For some video devices on some
@@ -4229,7 +4233,7 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,

     if (STREQ(model, "virtio-gpu") || STREQ(model, "vhost-user-gpu")) {
         if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_GL_PCI) &&
-            (video->accel->accel3d == VIR_TRISTATE_SWITCH_ON) &&
+            accel3d == VIR_TRISTATE_SWITCH_ON &&
             STREQ(model, "virtio-gpu"))
             model = "virtio-gpu-gl";

@@ -4247,8 +4251,8 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
         video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO) {
         if (video->accel &&
             virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL) &&
-            (video->accel->accel3d == VIR_TRISTATE_SWITCH_ON ||
-             video->accel->accel3d == VIR_TRISTATE_SWITCH_OFF)) {
+            (accel3d == VIR_TRISTATE_SWITCH_ON ||
+             accel3d == VIR_TRISTATE_SWITCH_OFF)) {
             virBufferAsprintf(&buf, ",virgl=%s",
                               virTristateSwitchTypeToString(video->accel->accel3d));
Here it can be replaced by accel3d, too. Then no 'video->accel->accel3d' in the scope of qemuBuildDeviceVideoStr()
         }


Michal