mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-13 18:18:22 +00:00
migration: add check_non_migratable_resources function
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>
This commit is contained in:
parent
5d7288a415
commit
5fc635cc6d
@ -4626,7 +4626,7 @@ __PACKAGE__->register_method({
|
|||||||
$res->{running} = PVE::QemuServer::check_running($vmid) ? 1:0;
|
$res->{running} = PVE::QemuServer::check_running($vmid) ? 1:0;
|
||||||
|
|
||||||
my ($local_resources, $mapped_resources, $missing_mappings_by_node) =
|
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};
|
delete $missing_mappings_by_node->{$localnode};
|
||||||
|
|
||||||
my $vga = PVE::QemuServer::parse_vga($vmconf->{vga});
|
my $vga = PVE::QemuServer::parse_vga($vmconf->{vga});
|
||||||
@ -5314,6 +5314,9 @@ __PACKAGE__->register_method({
|
|||||||
die "unable to use snapshot name 'pending' (reserved name)\n"
|
die "unable to use snapshot name 'pending' (reserved name)\n"
|
||||||
if lc($snapname) eq 'pending';
|
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 {
|
my $realcmd = sub {
|
||||||
PVE::Cluster::log_msg('info', $authuser, "snapshot VM $vmid: $snapname");
|
PVE::Cluster::log_msg('info', $authuser, "snapshot VM $vmid: $snapname");
|
||||||
PVE::QemuConfig->snapshot_create($vmid, $snapname, $param->{vmstate},
|
PVE::QemuConfig->snapshot_create($vmid, $snapname, $param->{vmstate},
|
||||||
|
@ -199,6 +199,11 @@ sub get_backup_volumes {
|
|||||||
return $return_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 {
|
sub __snapshot_save_vmstate {
|
||||||
my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
|
my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ sub prepare {
|
|||||||
$self->{vm_was_paused} = 1 if PVE::QemuServer::vm_is_paused($vmid, 0);
|
$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 = [];
|
my $blocking_resources = [];
|
||||||
for my $res ($loc_res->@*) {
|
for my $res ($loc_res->@*) {
|
||||||
if (!grep($res, $mapped_res->@*)) {
|
if (!grep($res, $mapped_res->@*)) {
|
||||||
|
@ -2571,13 +2571,32 @@ sub config_list {
|
|||||||
return $res;
|
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)
|
# test if VM uses local resources (to prevent migration)
|
||||||
sub check_local_resources {
|
sub check_local_resources {
|
||||||
my ($conf, $noerr) = @_;
|
my ($conf, $state, $noerr) = @_;
|
||||||
|
|
||||||
my @loc_res = ();
|
my @loc_res = ();
|
||||||
my $mapped_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 $nodelist = PVE::Cluster::get_nodelist();
|
||||||
my $pci_map = PVE::Mapping::PCI::config();
|
my $pci_map = PVE::Mapping::PCI::config();
|
||||||
my $usb_map = PVE::Mapping::USB::config();
|
my $usb_map = PVE::Mapping::USB::config();
|
||||||
@ -6455,6 +6474,8 @@ sub vm_suspend {
|
|||||||
die "cannot suspend to disk during backup\n"
|
die "cannot suspend to disk during backup\n"
|
||||||
if $is_backing_up && $includestate;
|
if $is_backing_up && $includestate;
|
||||||
|
|
||||||
|
check_non_migratable_resources($conf, $includestate, 0);
|
||||||
|
|
||||||
if ($includestate) {
|
if ($includestate) {
|
||||||
$conf->{lock} = 'suspending';
|
$conf->{lock} = 'suspending';
|
||||||
my $date = strftime("%Y-%m-%d", localtime(time()));
|
my $date = strftime("%Y-%m-%d", localtime(time()));
|
||||||
|
Loading…
Reference in New Issue
Block a user