[pve-devel] [PATCH qemu-server 1/1] migration : forbid migration if target host memory < migration_targethost_freememory
Alexandre Derumier
aderumier at odiso.com
Mon Jan 15 10:12:47 CET 2018
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 0983ce6..d114d23 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -26,6 +26,7 @@ use PVE::INotify;
use PVE::Network;
use PVE::Firewall;
use PVE::API2::Firewall::VM;
+use PVE::API2Tools;
BEGIN {
if (!$ENV{PVE_GENERATING_DOCS}) {
@@ -2956,6 +2957,27 @@ __PACKAGE__->register_method({
PVE::QemuServer::check_storage_availability($storecfg, $conf, $target);
}
+ my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+ my $migration_targethost_freememory = $dc->{migration_targethost_freememory};
+
+ if($migration_targethost_freememory) {
+
+ $migration_targethost_freememory *= 1024 * 1024;
+
+ my $members = PVE::Cluster::get_members();
+ my $rrd = PVE::Cluster::rrd_dump();
+ my $node_stats = PVE::API2Tools::extract_node_stats($target, $members, $rrd);
+
+ my $vmlist = PVE::Cluster::get_vmlist();
+ my $idlist = $vmlist->{ids} || {};
+ my $vmdata = $idlist->{$vmid};
+ my $vm_stats = PVE::API2Tools::extract_vm_stats($vmid, $vmdata, $rrd);
+
+ if($node_stats->{maxmem} && $node_stats->{mem} && $vm_stats->{mem}) {
+ die "not enough memory on target host" if ( ($node_stats->{maxmem} - $node_stats->{mem} - $vm_stats->{mem}) < $migration_targethost_freememory );
+ }
+ }
+
if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
my $hacmd = sub {
--
2.11.0
More information about the pve-devel
mailing list