From: Markus Frank <m.frank@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v12 4/6] migration: add check_non_migratable_resources function
Date: Mon, 11 Nov 2024 14:57:11 +0100 [thread overview]
Message-ID: <20241111135713.212601-5-m.frank@proxmox.com> (raw)
In-Reply-To: <20241111135713.212601-1-m.frank@proxmox.com>
The function checks for resources that cannot be migrated, snapshoted,
or suspended.
To run this function while the snapshot lock is active, the
pve-guest-common patch 'AbstractConfig: add abstract method to check for
resources preventing a snapshot.' is required.
Signed-off-by: Markus Frank <m.frank@proxmox.com>
---
changes v12:
* added overwrite of abstract method __snapshot_assert_no_blockers in
QemuConfig
* renamed non_migr_res to blockers and non_migratable_resources
PVE/API2/Qemu.pm | 5 ++++-
PVE/QemuConfig.pm | 5 +++++
PVE/QemuMigrate.pm | 2 +-
PVE/QemuServer.pm | 23 ++++++++++++++++++++++-
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 848001b6..d16b8baa 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -4531,7 +4531,7 @@ __PACKAGE__->register_method({
$res->{running} = PVE::QemuServer::check_running($vmid) ? 1:0;
my ($local_resources, $mapped_resources, $missing_mappings_by_node) =
- PVE::QemuServer::check_local_resources($vmconf, 1);
+ PVE::QemuServer::check_local_resources($vmconf, $res->{running}, 1);
delete $missing_mappings_by_node->{$localnode};
my $vga = PVE::QemuServer::parse_vga($vmconf->{vga});
@@ -5219,6 +5219,9 @@ __PACKAGE__->register_method({
die "unable to use snapshot name 'pending' (reserved name)\n"
if lc($snapname) eq 'pending';
+ my $vmconf = PVE::QemuConfig->load_config($vmid);
+ PVE::QemuServer::check_non_migratable_resources($vmconf, $param->{vmstate}, 0);
+
my $realcmd = sub {
PVE::Cluster::log_msg('info', $authuser, "snapshot VM $vmid: $snapname");
PVE::QemuConfig->snapshot_create($vmid, $snapname, $param->{vmstate},
diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 8e8a7828..ffdf9f03 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -199,6 +199,11 @@ sub get_backup_volumes {
return $return_volumes;
}
+sub __snapshot_assert_no_blockers {
+ my ($class, $vmconf, $save_vmstate) = @_;
+ PVE::QemuServer::check_non_migratable_resources($vmconf, $save_vmstate, 0);
+}
+
sub __snapshot_save_vmstate {
my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 6591f3f7..09e97268 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -233,7 +233,7 @@ sub prepare {
$self->{vm_was_paused} = 1 if PVE::QemuServer::vm_is_paused($vmid, 0);
}
- my ($loc_res, $mapped_res, $missing_mappings_by_node) = PVE::QemuServer::check_local_resources($conf, 1);
+ my ($loc_res, $mapped_res, $missing_mappings_by_node) = PVE::QemuServer::check_local_resources($conf, $running, 1);
my $blocking_resources = [];
for my $res ($loc_res->@*) {
if (!grep($res, $mapped_res->@*)) {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index dd6ae93f..e94f6d0d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2563,13 +2563,32 @@ sub config_list {
return $res;
}
+sub check_non_migratable_resources {
+ my ($conf, $state, $noerr) = @_;
+
+ my @blockers = ();
+ if ($state && $conf->{amd_sev}) {
+ push @blockers, "amd_sev";
+ }
+
+ if (scalar(@blockers) && !$noerr) {
+ die "Cannot live-migrate, snapshot (with RAM), or hibernate a VM with:"
+ ." @blockers\n";
+ }
+
+ return @blockers;
+}
+
# test if VM uses local resources (to prevent migration)
sub check_local_resources {
- my ($conf, $noerr) = @_;
+ my ($conf, $state, $noerr) = @_;
my @loc_res = ();
my $mapped_res = [];
+ my @non_migratable_resources = check_non_migratable_resources($conf, $state, $noerr);
+ push(@loc_res, @non_migratable_resources);
+
my $nodelist = PVE::Cluster::get_nodelist();
my $pci_map = PVE::Mapping::PCI::config();
my $usb_map = PVE::Mapping::USB::config();
@@ -6445,6 +6464,8 @@ sub vm_suspend {
die "cannot suspend to disk during backup\n"
if $is_backing_up && $includestate;
+ check_non_migratable_resources($conf, $includestate, 0);
+
if ($includestate) {
$conf->{lock} = 'suspending';
my $date = strftime("%Y-%m-%d", localtime(time()));
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2024-11-11 13:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-11 13:57 [pve-devel] [PATCH guest-common/qemu-server/docs/manager v12 0/6] AMD SEV Markus Frank
2024-11-11 13:57 ` [pve-devel] [PATCH guest-common v12 1/6] AbstractConfig: add abstract method to check for resources preventing a snapshot Markus Frank
2024-11-11 13:57 ` [pve-devel] [PATCH qemu-server v12 2/6] add C program to get hardware capabilities from CPUID Markus Frank
2024-11-11 13:57 ` [pve-devel] [PATCH qemu-server v12 3/6] config: add AMD SEV support Markus Frank
2024-11-11 13:57 ` Markus Frank [this message]
2024-11-11 13:57 ` [pve-devel] [PATCH docs v12 5/6] add AMD SEV documentation Markus Frank
2024-11-11 13:57 ` [pve-devel] [PATCH manager v12 6/6] ui: add AMD SEV configuration to Options 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=20241111135713.212601-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox