From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id CF5FE1FF15F for ; Mon, 18 Nov 2024 12:17:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CEBD2DF4E; Mon, 18 Nov 2024 12:17:13 +0100 (CET) From: Markus Frank To: pve-devel@lists.proxmox.com Date: Mon, 18 Nov 2024 12:16:58 +0100 Message-Id: <20241118111700.110077-4-m.frank@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241118111700.110077-1-m.frank@proxmox.com> References: <20241118111700.110077-1-m.frank@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server v13 3/5] migration: add check_non_migratable_resources function X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- 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 c50c42be..ece98a30 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -4550,7 +4550,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}); @@ -5238,6 +5238,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 a3446c3d..fe42122a 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2571,13 +2571,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(); @@ -6455,6 +6474,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