all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Markus Frank <m.frank@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v9 1/5] enable VNC clipboard parameter in vga_fmt
Date: Mon, 22 May 2023 12:09:45 +0200	[thread overview]
Message-ID: <20230522100949.80363-2-m.frank@proxmox.com> (raw)
In-Reply-To: <20230522100949.80363-1-m.frank@proxmox.com>

added 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.

added vnc-clipboard variable to return at status/current

By that noVNC is able to check if clipboard is active.

Signed-off-by: Markus Frank <m.frank@proxmox.com>
---
 PVE/API2/Qemu.pm  | 13 ++++++++++
 PVE/QemuServer.pm | 61 ++++++++++++++++++++++++++++++++---------------
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 587bb22..a785693 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -970,6 +970,9 @@ __PACKAGE__->register_method({
 			$conf->{boot} = PVE::QemuServer::print_bootorder($devs);
 		    }
 
+		    my $vga = PVE::QemuServer::parse_vga($conf->{vga});
+		    PVE::QemuServer::assert_vnc_clipboard_config($vga);
+
 		    # auto generate uuid if user did not specify smbios1 option
 		    if (!$conf->{smbios1}) {
 			$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
@@ -1760,6 +1763,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_vnc_clipboard_config($vga);
+		    $conf->{pending}->{$opt} = $param->{$opt};
 		} elsif ($opt =~ m/^usb\d+/) {
 		    if ((!defined($conf->{$opt}) || $conf->{$opt} =~ m/spice/) && $param->{$opt} =~ m/spice/) {
 			$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType']);
@@ -2580,6 +2587,11 @@ __PACKAGE__->register_method({
 		type => 'boolean',
 		optional => 1,
 	    },
+	    'vnc-clipboard' => {
+		description => "QEMU clipboard for noVNC is enabled in config.",
+		type => 'boolean',
+		optional => 1,
+	    },
 	},
     },
     code => sub {
@@ -2598,6 +2610,7 @@ __PACKAGE__->register_method({
 	    my $spice = defined($vga->{type}) && $vga->{type} =~ /^virtio/;
 	    $spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});
 	    $status->{spice} = 1 if $spice;
+	    $status->{'vnc-clipboard'} = $vga->{'vnc-clipboard'};
 	}
 	$status->{agent} = 1 if PVE::QemuServer::get_qga_key($conf, 'enabled');
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 40be44d..8d30f7c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -193,8 +193,16 @@ my $vga_fmt = {
 	minimum => 4,
 	maximum => 512,
     },
+    'vnc-clipboard' => {
+	description => "enable VNC clipboard (requires spice tools in the guest)",
+	type => 'boolean',
+	optional => 1,
+	default => 0
+    }
 };
 
+my $vnc_clipboard_regex = qr/^(std|cirrus|vmware|virtio|qxl)/;
+
 my $ivshmem_fmt = {
     size => {
 	type => 'integer',
@@ -1405,6 +1413,14 @@ sub pve_verify_hotplug_features {
     die "unable to parse hotplug option\n";
 }
 
+sub assert_vnc_clipboard_config {
+    my ($vga) = @_;
+
+    if ($vga->{'vnc-clipboard'} && $vga->{type} && $vga->{type} !~ $vnc_clipboard_regex) {
+	die "vga type $vga->{type} is not compatible with VNC clipboard\n";
+    }
+}
+
 sub scsi_inquiry {
     my($fh, $noerr) = @_;
 
@@ -3935,7 +3951,10 @@ sub config_to_command {
 
     my $spice_port;
 
-    if ($qxlnum || $vga->{type} =~ /^virtio/) {
+    assert_vnc_clipboard_config($vga);
+    my $is_spice = $qxlnum || $vga->{type} =~ /^virtio/;
+
+    if ($is_spice || $vga->{'vnc-clipboard'}) {
 	if ($qxlnum > 1) {
 	    if ($winversion){
 		for (my $i = 1; $i < $qxlnum; $i++){
@@ -3953,32 +3972,36 @@ sub config_to_command {
 		push @$cmd, '-global', "qxl-vga.vram_size=$vram";
 	    }
 	}
-
 	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->{'vnc-clipboard'}) {
+	    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
-- 
2.30.2





  reply	other threads:[~2023-05-22 10:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 10:09 [pve-devel] [PATCH qemu-server/novnc/manager/docs v9 0/5] Feature VNC-Clipboard Markus Frank
2023-05-22 10:09 ` Markus Frank [this message]
2023-08-21 14:05   ` [pve-devel] [PATCH qemu-server v9 1/5] enable VNC clipboard parameter in vga_fmt Fiona Ebner
2023-05-22 10:09 ` [pve-devel] [PATCH qemu-server v9 2/5] test cases for clipboard spice & std Markus Frank
2023-05-22 10:09 ` [pve-devel] [PATCH novnc v9 3/5] added show clipboard button patch to series Markus Frank
2023-05-22 10:09 ` [pve-devel] [PATCH manager v9 4/5] added clipboard checkbox to VM Options Markus Frank
2023-05-22 10:09 ` [pve-devel] [PATCH docs v9 5/5] added noVNC clipboard documentation Markus Frank
2023-06-15 12:11 ` [pve-devel] [PATCH qemu-server/novnc/manager/docs v9 0/5] Feature VNC-Clipboard Dominik Csapak
2023-07-17 13:50   ` Thomas Lamprecht
2023-07-14  8:27 ` Markus Frank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522100949.80363-2-m.frank@proxmox.com \
    --to=m.frank@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal