[pve-devel] [PATCH qemu-server 2/3] Make agent a property string, add fstrim_cloned_disks

Stoiko Ivanov s.ivanov at proxmox.com
Thu Jul 5 19:42:34 CEST 2018


Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 PVE/API2/Qemu.pm  |  3 +--
 PVE/QemuConfig.pm |  2 +-
 PVE/QemuServer.pm | 38 +++++++++++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index db28ed0..6dc2489 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1875,8 +1875,7 @@ __PACKAGE__->register_method({
 	$status->{ha} = PVE::HA::Config::get_service_status("vm:$param->{vmid}");
 
 	$status->{spice} = 1 if PVE::QemuServer::vga_conf_has_spice($conf->{vga});
-
-	$status->{agent} = 1 if $conf->{agent};
+	$status->{agent} = 1 if (PVE::QemuServer::parse_guest_agent($conf)->{enabled});
 
 	return $status;
     }});
diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 9a29b53..b24773c 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -161,7 +161,7 @@ sub __snapshot_check_freeze_needed {
 
     my $running = $class->__snapshot_check_running($vmid);
     if (!$save_vmstate) {
-	return ($running, $running && $config->{agent} && PVE::QemuServer::qga_check_running($vmid));
+	return ($running, $running && PVE::QemuServer::parse_guest_agent($config)->{enabled} && PVE::QemuServer::qga_check_running($vmid));
     } else {
 	return ($running, 0);
     }
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 5829e4c..8a8fdb6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -200,6 +200,21 @@ my $watchdog_fmt = {
 };
 PVE::JSONSchema::register_format('pve-qm-watchdog', $watchdog_fmt);
 
+my $agent_fmt = {
+    enabled => {
+	description => "Enable/disable Qemu GuestAgent.",
+	type => 'boolean',
+	default => 0,
+	default_key => 1,
+    },
+    fstrim_cloned_disks => {
+	description => "Run fstrim after cloning/moving a disk.",
+	type => 'boolean',
+	optional => 1,
+	default => 0
+    },
+};
+
 my $confdesc = {
     onboot => {
 	optional => 1,
@@ -380,9 +395,9 @@ EODESC
     },
     agent => {
 	optional => 1,
-	type => 'boolean',
-	description => "Enable/disable Qemu GuestAgent.",
-	default => 0,
+	description => "Enable/disable Qemu GuestAgent and its properties.",
+	type => 'string',
+	format => $agent_fmt,
     },
     kvm => {
 	optional => 1,
@@ -2211,6 +2226,19 @@ sub parse_watchdog {
     return $res;
 }
 
+sub parse_guest_agent {
+    my ($value) = @_;
+
+    return {} if !defined($value->{agent});
+
+    my $res = eval { PVE::JSONSchema::parse_property_string($agent_fmt, $value->{agent}) };
+    warn $@ if $@;
+
+    # if the agent is disabled ignore the other potentially set properties
+    return {} if !$res->{enabled};
+    return $res;
+}
+
 PVE::JSONSchema::register_format('pve-qm-usb-device', \&verify_usb_device);
 sub verify_usb_device {
     my ($value, $noerr) = @_;
@@ -3395,7 +3423,7 @@ sub config_to_command {
     #push @$cmd, '-soundhw', 'es1370';
     #push @$cmd, '-soundhw', $soundhw if $soundhw;
 
-    if($conf->{agent}) {
+    if (parse_guest_agent($conf)->{enabled}) {
 	my $qgasocket = qmp_socket($vmid, 1);
 	my $pciaddr = print_pci_addr("qga0", $bridges);
 	push @$devices, '-chardev', "socket,path=$qgasocket,server,nowait,id=qga0";
@@ -5095,7 +5123,7 @@ sub vm_stop {
 
 	eval {
 	    if ($shutdown) {
-		if (defined($conf) && $conf->{agent}) {
+		if (defined($conf) && parse_guest_agent($conf)->{enabled}) {
 		    vm_qmp_command($vmid, { execute => "guest-shutdown" }, $nocheck);
 		} else {
 		    vm_qmp_command($vmid, { execute => "system_powerdown" }, $nocheck);
-- 
2.11.0





More information about the pve-devel mailing list