]> git.proxmox.com Git - qemu-server.git/commitdiff
config: enable VNC clipboard parameter in vga_fmt
authorMarkus Frank <m.frank@proxmox.com>
Tue, 14 Nov 2023 09:22:51 +0000 (10:22 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Nov 2023 15:20:08 +0000 (16:20 +0100)
add option to use the qemu vdagent implementation to enable the VNC
clipboard. When enabled with SPICE the spice-vdagent gets replaced
with the QEMU implementation.

This patch does not solve #1406, but does allow copy and paste with a
running X-session, when spice-vdagent is installed on the guest.

Signed-off-by: Markus Frank <m.frank@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuServer.pm

index 38bdaabd26e9c3dadbf4279b255bcaf46f2ca93a..01774899ce04e2ac141d626c6a2bafccbe45b1ea 100644 (file)
@@ -1035,6 +1035,9 @@ __PACKAGE__->register_method({
                        $conf->{boot} = PVE::QemuServer::print_bootorder($devs);
                    }
 
+                   my $vga = PVE::QemuServer::parse_vga($conf->{vga});
+                   PVE::QemuServer::assert_clipboard_config($vga);
+
                    # auto generate uuid if user did not specify smbios1 option
                    if (!$conf->{smbios1}) {
                        $conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
@@ -1857,6 +1860,10 @@ my $update_vm_api  = sub {
                        die "only root can modify '$opt' config for real devices\n";
                    }
                    $conf->{pending}->{$opt} = $param->{$opt};
+               } elsif ($opt eq 'vga') {
+                   my $vga = PVE::QemuServer::parse_vga($param->{$opt});
+                   PVE::QemuServer::assert_clipboard_config($vga);
+                   $conf->{pending}->{$opt} = $param->{$opt};
                } elsif ($opt =~ m/^usb\d+/) {
                    if (my $olddevice = $conf->{$opt}) {
                        check_usb_perm($rpcenv, $authuser, $vmid, undef, $opt, $conf->{$opt});
index c465fb6f64ae30dec5112fc4439f9181c2eba4e9..e9d0a94e364b8242cb7ac48a4bb1256919baf69d 100644 (file)
@@ -199,6 +199,13 @@ my $vga_fmt = {
        minimum => 4,
        maximum => 512,
     },
+    clipboard => {
+       description => 'Enable a specific clipboard. If not set, depending on'
+           .' the display type the SPICE one will be added.',
+       type => 'string',
+       enum => ['vnc'],
+       optional => 1,
+    },
 };
 
 my $ivshmem_fmt = {
@@ -1342,6 +1349,21 @@ sub pve_verify_hotplug_features {
     die "unable to parse hotplug option\n";
 }
 
+sub assert_clipboard_config {
+    my ($vga) = @_;
+
+    my $clipboard_regex = qr/^(std|cirrus|vmware|virtio|qxl)/;
+
+    if (
+       $vga->{'clipboard'}
+       && $vga->{'clipboard'} eq 'vnc'
+       && $vga->{type}
+       && $vga->{type} !~ $clipboard_regex
+    ) {
+       die "vga type $vga->{type} is not compatible with VNC clipboard\n";
+    }
+}
+
 sub scsi_inquiry {
     my($fh, $noerr) = @_;
 
@@ -3892,7 +3914,10 @@ sub config_to_command {
 
     my $spice_port;
 
-    if ($qxlnum || $vga->{type} =~ /^virtio/) {
+    assert_clipboard_config($vga);
+    my $is_spice = $qxlnum || $vga->{type} =~ /^virtio/;
+
+    if ($is_spice || ($vga->{'clipboard'} && $vga->{'clipboard'} eq 'vnc')) {
        if ($qxlnum > 1) {
            if ($winversion){
                for (my $i = 1; $i < $qxlnum; $i++){
@@ -3913,29 +3938,34 @@ sub config_to_command {
 
        my $pciaddr = print_pci_addr("spice", $bridges, $arch, $machine_type);
 
-       my $pfamily = PVE::Tools::get_host_address_family($nodename);
-       my @nodeaddrs = PVE::Tools::getaddrinfo_all('localhost', family => $pfamily);
-       die "failed to get an ip address of type $pfamily for 'localhost'\n" if !@nodeaddrs;
-
        push @$devices, '-device', "virtio-serial,id=spice$pciaddr";
-       push @$devices, '-chardev', "spicevmc,id=vdagent,name=vdagent";
+       if ($vga->{'clipboard'} && $vga->{'clipboard'} eq 'vnc') {
+           push @$devices, '-chardev', 'qemu-vdagent,id=vdagent,name=vdagent,clipboard=on';
+       } else {
+           push @$devices, '-chardev', 'spicevmc,id=vdagent,name=vdagent';
+       }
        push @$devices, '-device', "virtserialport,chardev=vdagent,name=com.redhat.spice.0";
 
-       my $localhost = PVE::Network::addr_to_ip($nodeaddrs[0]->{addr});
-       $spice_port = PVE::Tools::next_spice_port($pfamily, $localhost);
+       if ($is_spice) {
+           my $pfamily = PVE::Tools::get_host_address_family($nodename);
+           my @nodeaddrs = PVE::Tools::getaddrinfo_all('localhost', family => $pfamily);
+           die "failed to get an ip address of type $pfamily for 'localhost'\n" if !@nodeaddrs;
 
-       my $spice_enhancement_str = $conf->{spice_enhancements} // '';
-       my $spice_enhancement = parse_property_string($spice_enhancements_fmt, $spice_enhancement_str);
-       if ($spice_enhancement->{foldersharing}) {
-           push @$devices, '-chardev', "spiceport,id=foldershare,name=org.spice-space.webdav.0";
-           push @$devices, '-device', "virtserialport,chardev=foldershare,name=org.spice-space.webdav.0";
-       }
+           my $localhost = PVE::Network::addr_to_ip($nodeaddrs[0]->{addr});
+           $spice_port = PVE::Tools::next_spice_port($pfamily, $localhost);
 
-       my $spice_opts = "tls-port=${spice_port},addr=$localhost,tls-ciphers=HIGH,seamless-migration=on";
-       $spice_opts .= ",streaming-video=$spice_enhancement->{videostreaming}"
-           if $spice_enhancement->{videostreaming};
+           my $spice_enhancement_str = $conf->{spice_enhancements} // '';
+           my $spice_enhancement = parse_property_string($spice_enhancements_fmt, $spice_enhancement_str);
+           if ($spice_enhancement->{foldersharing}) {
+               push @$devices, '-chardev', "spiceport,id=foldershare,name=org.spice-space.webdav.0";
+               push @$devices, '-device', "virtserialport,chardev=foldershare,name=org.spice-space.webdav.0";
+           }
 
-       push @$devices, '-spice', "$spice_opts";
+           my $spice_opts = "tls-port=${spice_port},addr=$localhost,tls-ciphers=HIGH,seamless-migration=on";
+           $spice_opts .= ",streaming-video=$spice_enhancement->{videostreaming}"
+               if $spice_enhancement->{videostreaming};
+           push @$devices, '-spice', "$spice_opts";
+       }
     }
 
     # enable balloon by default, unless explicitly disabled