[PATCH qemu-server 4/6] migration: refresh remote disk size before resume

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Mon Aug 26 13:00:27 CEST 2024


A blockextend occur on source just before the switch.

we want to be sure that lvm size on target is correctly refreshed,

or we could have io-error is the vm is writing to non available
sectors

Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 PVE/CLI/qm.pm                         | 26 ++++++++++++++++++++++++++
 PVE/QemuMigrate.pm                    | 13 +++++++++++++
 test/MigrationTest/QemuMigrateMock.pm |  2 ++
 3 files changed, 41 insertions(+)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 1410ad5..6e258f3 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -553,6 +553,30 @@ __PACKAGE__->register_method ({
 	return;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'refresh',
+    path => 'refresh',
+    method => 'POST',
+    description => "Force storage volume size cache refresh.",
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $vmid = extract_param($param, 'vmid');
+	my $conf = PVE::QemuConfig->load_config($vmid);
+	my $storecfg = PVE::Storage::config();
+	my $vols = PVE::QemuServer::get_vm_volumes($conf);
+	PVE::Storage::refresh_volumes($storecfg, $vols);
+
+	return;
+    }});
+
 __PACKAGE__->register_method ({
     name => 'importdisk',
     path => 'importdisk',
@@ -1192,6 +1216,7 @@ our $cmddef = {
     'move-disk' => { alias => 'disk move' },
     move_disk => { alias => 'disk move' },
     rescan => { alias => 'disk rescan' },
+    refresh => { alias => 'disk refresh' },
     resize => { alias => 'disk resize' },
     unlink => { alias => 'disk unlink' },
 
@@ -1202,6 +1227,7 @@ our $cmddef = {
 	resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { %node } ],
 	unlink => [ "PVE::API2::Qemu", 'unlink', ['vmid'], { %node } ],
 	blockextend => [ __PACKAGE__, 'blockextend', ['vmid', 'disk'], { %node }],
+	refresh => [ __PACKAGE__, 'refresh', ['vmid']],
     },
 
     monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index bdcc2e5..9ae9ea1 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -1503,6 +1503,19 @@ sub phase3_cleanup {
 	PVE::QemuServer::del_nets_bridge_fdb($conf, $vmid);
 
 	if (!$self->{vm_was_paused}) {
+
+	    # refresh remote volumes size if extend have occured
+            my $cmd = [@{$self->{rem_ssh}}, 'qm', 'disk', 'refresh', $vmid];
+	    my $logf = sub {
+		my $line = shift;
+		$self->log('err', $line);
+	    };
+	    eval { PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => $logf); };
+	    if (my $err = $@) {
+		$self->log('err', $err);
+		$self->{errors} = 1;
+	    }
+
 	    # config moved and nbd server stopped - now we can resume vm on target
 	    if ($tunnel && $tunnel->{version} && $tunnel->{version} >= 1) {
 		my $cmd = $tunnel->{version} == 1 ? "resume $vmid" : "resume";
diff --git a/test/MigrationTest/QemuMigrateMock.pm b/test/MigrationTest/QemuMigrateMock.pm
index 1efabe2..0057868 100644
--- a/test/MigrationTest/QemuMigrateMock.pm
+++ b/test/MigrationTest/QemuMigrateMock.pm
@@ -306,6 +306,8 @@ $MigrationTest::Shared::tools_module->mock(
 			return 0;
 		    } elsif ($cmd eq 'resume') {
 			return 0;
+		    } elsif ($cmd eq 'disk') {
+			return 0;
 		    } elsif ($cmd eq 'unlock') {
 			my $vmid = shift @{$cmd_tail};;
 			die "unlocking wrong vmid: $vmid\n" if $vmid ne $test_vmid;
-- 
2.39.2




More information about the pve-devel mailing list