public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server 1/2] migrate: add log for guest fstrim
@ 2022-04-25 12:31 Fabian Ebner
  2022-04-25 12:31 ` [pve-devel] [PATCH qemu-server 2/2] migrate: resume initially running VM when failing after convergence Fabian Ebner
  2022-04-26 10:16 ` [pve-devel] applied-series: [PATCH qemu-server 1/2] migrate: add log for guest fstrim Fabian Grünbichler
  0 siblings, 2 replies; 3+ messages in thread
From: Fabian Ebner @ 2022-04-25 12:31 UTC (permalink / raw)
  To: pve-devel

and make a failure noticable.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/QemuMigrate.pm | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 891edfb2..c293e294 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -1170,14 +1170,23 @@ sub phase3_cleanup {
 		    $self->{errors} = 1;
 		}
 	    }
+	}
 
-	    if (
-		$self->{storage_migration}
-		&& PVE::QemuServer::parse_guest_agent($conf)->{fstrim_cloned_disks}
-		&& $self->{running}
-	    ) {
+	if (
+	    $self->{storage_migration}
+	    && PVE::QemuServer::parse_guest_agent($conf)->{fstrim_cloned_disks}
+	    && $self->{running}
+	) {
+	    if (!$self->{vm_was_paused}) {
+		$self->log('info', "issuing guest fstrim");
 		my $cmd = [@{$self->{rem_ssh}}, 'qm', 'guest', 'cmd', $vmid, 'fstrim'];
-		eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
+		eval { PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
+		if (my $err = $@) {
+		    $self->log('err', "fstrim failed - $err");
+		    $self->{errors} = 1;
+		}
+	    } else {
+		$self->log('info', "skipping guest fstrim, because VM is paused");
 	    }
 	}
     }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] [PATCH qemu-server 2/2] migrate: resume initially running VM when failing after convergence
  2022-04-25 12:31 [pve-devel] [PATCH qemu-server 1/2] migrate: add log for guest fstrim Fabian Ebner
@ 2022-04-25 12:31 ` Fabian Ebner
  2022-04-26 10:16 ` [pve-devel] applied-series: [PATCH qemu-server 1/2] migrate: add log for guest fstrim Fabian Grünbichler
  1 sibling, 0 replies; 3+ messages in thread
From: Fabian Ebner @ 2022-04-25 12:31 UTC (permalink / raw)
  To: pve-devel

When phase2() is aborted after the migration already converged, then
after migrate_cancel, the VM might be in POSTMIGRATE state.

(There also is a conditional for SHUTDOWN state in QEMU's
migration_iteration_finish(), so it's likely possible to end up there
if the VM is shut down at the right time during migration, but no need
to resume then).

Detect the POSTMIGRATE state and resume the VM if it wasn't paused at
the beginning of the migration. There is no direct way to go to
PAUSED, so just print an error if the VM was paused at the beginning
of the migration.

Reported-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/QemuMigrate.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index c293e294..dfe92325 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -1056,6 +1056,22 @@ sub phase2_cleanup {
     };
     $self->log('info', "migrate_cancel error: $@") if $@;
 
+    my $vm_status = eval {
+	mon_cmd($vmid, 'query-status')->{status} or die "no 'status' in result\n";
+    };
+    $self->log('err', "query-status error: $@") if $@;
+
+    # Can end up in POSTMIGRATE state if failure occurred after convergence. Try going back to
+    # original state. Unfortunately, direct transition from POSTMIGRATE to PAUSED is not possible.
+    if ($vm_status && $vm_status eq 'postmigrate') {
+	if (!$self->{vm_was_paused}) {
+	    eval { mon_cmd($vmid, 'cont'); };
+	    $self->log('err', "resuming VM failed: $@") if $@;
+	} else {
+	    $self->log('err', "VM was paused, but ended in postmigrate state");
+	}
+    }
+
     my $conf = $self->{vmconf};
     delete $conf->{lock};
     eval { PVE::QemuConfig->write_config($vmid, $conf) };
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied-series: [PATCH qemu-server 1/2] migrate: add log for guest fstrim
  2022-04-25 12:31 [pve-devel] [PATCH qemu-server 1/2] migrate: add log for guest fstrim Fabian Ebner
  2022-04-25 12:31 ` [pve-devel] [PATCH qemu-server 2/2] migrate: resume initially running VM when failing after convergence Fabian Ebner
@ 2022-04-26 10:16 ` Fabian Grünbichler
  1 sibling, 0 replies; 3+ messages in thread
From: Fabian Grünbichler @ 2022-04-26 10:16 UTC (permalink / raw)
  To: Proxmox VE development discussion

thanks!

On April 25, 2022 2:31 pm, Fabian Ebner wrote:
> and make a failure noticable.
> 
> Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
>  PVE/QemuMigrate.pm | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
> index 891edfb2..c293e294 100644
> --- a/PVE/QemuMigrate.pm
> +++ b/PVE/QemuMigrate.pm
> @@ -1170,14 +1170,23 @@ sub phase3_cleanup {
>  		    $self->{errors} = 1;
>  		}
>  	    }
> +	}
>  
> -	    if (
> -		$self->{storage_migration}
> -		&& PVE::QemuServer::parse_guest_agent($conf)->{fstrim_cloned_disks}
> -		&& $self->{running}
> -	    ) {
> +	if (
> +	    $self->{storage_migration}
> +	    && PVE::QemuServer::parse_guest_agent($conf)->{fstrim_cloned_disks}
> +	    && $self->{running}
> +	) {
> +	    if (!$self->{vm_was_paused}) {
> +		$self->log('info', "issuing guest fstrim");
>  		my $cmd = [@{$self->{rem_ssh}}, 'qm', 'guest', 'cmd', $vmid, 'fstrim'];
> -		eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
> +		eval { PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
> +		if (my $err = $@) {
> +		    $self->log('err', "fstrim failed - $err");
> +		    $self->{errors} = 1;
> +		}
> +	    } else {
> +		$self->log('info', "skipping guest fstrim, because VM is paused");
>  	    }
>  	}
>      }
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-26 10:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25 12:31 [pve-devel] [PATCH qemu-server 1/2] migrate: add log for guest fstrim Fabian Ebner
2022-04-25 12:31 ` [pve-devel] [PATCH qemu-server 2/2] migrate: resume initially running VM when failing after convergence Fabian Ebner
2022-04-26 10:16 ` [pve-devel] applied-series: [PATCH qemu-server 1/2] migrate: add log for guest fstrim Fabian Grünbichler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal