[pve-devel] [PATCH qemu-server] Fix #1242 : clone_disk : call qga fstrim after clone

Alexandre Derumier aderumier at odiso.com
Mon May 28 17:36:50 CEST 2018


Some storage like rbd or lvm can't keep thin-provising after a qemu-mirror.

Call qga guest-fstrim if qga is available
---
 PVE/API2/Qemu.pm   | 8 ++++++++
 PVE/QemuMigrate.pm | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 8d4b10d..86fac9d 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2741,6 +2741,10 @@ __PACKAGE__->register_method({
 
 		    PVE::QemuConfig->write_config($newid, $newconf);
 
+		    if ($running && $conf->{agent} && PVE::QemuServer::qga_check_running($vmid)) {
+			eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fstrim"); };
+		    }
+
                     if ($target) {
 			# always deactivate volumes - avoid lvm LVs to be active on several nodes
 			PVE::Storage::deactivate_volumes($storecfg, $vollist, $snapname) if !$running;
@@ -2918,6 +2922,10 @@ __PACKAGE__->register_method({
 
 		    PVE::QemuConfig->write_config($vmid, $conf);
 
+		    if ($running && $conf->{agent} && PVE::QemuServer::qga_check_running($vmid)) {
+			eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fstrim"); };
+		    }
+
 		    eval {
 			# try to deactivate volumes - avoid lvm LVs to be active on several nodes
 			PVE::Storage::deactivate_volumes($storecfg, [ $newdrive->{file} ])
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 27cf7e3..ab2258d 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -966,6 +966,11 @@ sub phase3_cleanup {
 		$self->{errors} = 1;
 	    }
 	}
+
+	if ($self->{storage_migration} && $conf->{qga} && $self->{running}) {
+	    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'agent','fstrim'];
+	    eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
+	}
     }
 
     # close tunnel on successful migration, on error phase2_cleanup closed it
-- 
2.11.0



More information about the pve-devel mailing list