Console using SPICE for VirtIO-GPU

Gustavo Neves

Active Member
Jun 2, 2018
10
10
43
46
This problem is related to this old thread (marked as solved):

As I explained there, the default console button tries to open with virt-viewer/spice when "VirtIO-GPU" or "VirGL GPU" is selected (or SPICE obviously).
When using Standard VGA, or vmware the default console button opens in NoVNC.

The solution proposed was to manually set the default Console viewer in the Datacenter menu, but I dislike this solution because it basically disables the automatic selection of the viewers, forcing ONLY the selected viewer in all VMs, CTs, etc. I would prefer to keep the Default (and automatic) viewer. This way I can have NoVNC for windows VMs and xterm.js for linux CTs when I click in Console (or even spice if I am using that in the VM).

After digging around the proxmox code for a few hours, I think I was able to pinpoint the problem. The API in /nodes/{node}/qemu/{vm-id}/status/current has a "special" check for $vga->{type} =~ /^virtio/ , which makes it return spice=1 when using a VirtIO GPU.

Here is the line in question:
https://github.com/proxmox/qemu-ser...6ebda1000e0e9d5fc7f50f/PVE/API2/Qemu.pm#L3092

I then edited the file /usr/share/perl5/PVE/API2/Qemu.pm in my instance, removing the check for virtio.

So, from this
Perl:
    if ($conf->{vga}) {
        my $vga = PVE::QemuServer::parse_vga($conf->{vga});
        my $spice = defined($vga->{type}) && $vga->{type} =~ /^virtio/;
        $spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});
        $status->{spice} = 1 if $spice;
        $status->{clipboard} = $vga->{clipboard};
    }
To this
Perl:
        if ($conf->{vga}) {
            my $vga = PVE::QemuServer::parse_vga($conf->{vga});
            #my $spice = defined($vga->{type}) && $vga->{type} =~ /^virtio/;
            #$spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});
            my $spice = PVE::QemuServer::vga_conf_has_spice($conf->{vga});
            $status->{spice} = 1 if $spice;
            $status->{clipboard} = $vga->{clipboard};
        }
Then we restart some services to make sure the change sticks
Code:
systemctl restart pvedaemon.service pveproxy.service

And voilá. It works.

A simple sed command to change the file
(use at your own risk, do NOT use this in production servers)
Bash:
sed -i.bak -e 's/my $spice = defined($vga->{type}) \&\& $vga->{type} =~ \/^virtio\/;/\#my $spice = defined($vga->{type}) \&\& $vga->{type} =~ \/^virtio\/;/g' -e 's/$spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});/\#$spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});\n        my $spice = PVE::QemuServer::vga_conf_has_spice($conf->{vga});/g' /usr/share/perl5/PVE/API2/Qemu.pm

Check the changes
Code:
# diff /usr/share/perl5/PVE/API2/Qemu.pm /usr/share/perl5/PVE/API2/Qemu.pm.bak
3092,3094c3092,3093
<           #my $spice = defined($vga->{type}) && $vga->{type} =~ /^virtio/;
<           #$spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});
<           my $spice = PVE::QemuServer::vga_conf_has_spice($conf->{vga});
---
>           my $spice = defined($vga->{type}) && $vga->{type} =~ /^virtio/;
>           $spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});

I am not sure why that check is there.

Is there a reason to use SPICE as the default viewer for VirtIO-GPU hardware? I wonder if someone can clarify that one.

Also, should I open a ticket? Or is this post enough for the changes to reach the development team?

Cheers!
Gus
 
Last edited:
  • Like
Reactions: fba
Hi,

Is there a reason to use SPICE as the default viewer for VirtIO-GPU hardware? I wonder if someone can clarify that one.

AFAIR this was done because the experience with virgl + spice is vastly better than with novnc

i guess what would be better is a per vm console option instead of a global one?
not sure about that though....
 
i guess what would be better is a per vm console option instead of a global one?

Yep. The ideal scenario would be to have a VM/CT setting for its preferred Console in the Web GUI.

At least for Windows, RDP is probably the best choice for the experience. However, many VMs I just open to do maintenance, and the noVNC Console is more than good enough. And it works in any browser, without needing virt-viewer or spice guest tools installed.

Then for terminal emulation xterm.js is better, but for extended use you can use ssh. Same mechanics. My point is that for the web GUI, noVNC is the one that always works, without it needing anything installed. But it is nice to have xterm.js as the default for terminal emulation.

About Virtio-GPU, can it use SPICE for acceleration like QXL-SPICE does?