[pve-devel] [POC qemu-server 1/6] create vmstate_size helper

Fabian Ebner f.ebner at proxmox.com
Thu Apr 8 12:33:11 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/QemuConfig.pm | 10 ++--------
 PVE/QemuServer.pm | 13 +++++++++++++
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 7ee8876..01c51b0 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -208,14 +208,8 @@ sub __snapshot_save_vmstate {
 	$target = PVE::QemuServer::find_vmstate_storage($conf, $storecfg);
     }
 
-    my $defaults = PVE::QemuServer::load_defaults();
-    my $mem_size = $conf->{memory} // $defaults->{memory};
-    my $driver_state_size = 500; # assume 500MB is enough to safe all driver state;
-    # our savevm-start does live-save of the memory until the space left in the
-    # volume is just enough for the remaining memory content + internal state
-    # then it stops the vm and copies the rest so we reserve twice the
-    # memory content + state to minimize vm downtime
-    my $size = $mem_size*2 + $driver_state_size;
+    my $size = PVE::QemuServer::vmstate_size($conf);
+
     my $scfg = PVE::Storage::storage_config($storecfg, $target);
 
     my $name = "vm-$vmid-state-$snapname";
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index fdb2ac9..5a89853 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7710,4 +7710,17 @@ sub vm_is_paused {
     return $qmpstatus && $qmpstatus->{status} eq "paused";
 }
 
+sub vmstate_size {
+    my ($conf) = @_;
+
+    my $defaults = PVE::QemuServer::load_defaults();
+    my $mem_size = $conf->{memory} // $defaults->{memory};
+    my $driver_state_size = 500; # assume 500MB is enough to safe all driver state;
+    # our savevm-start does live-save of the memory until the space left in the
+    # volume is just enough for the remaining memory content + internal state
+    # then it stops the vm and copies the rest so we reserve twice the
+    # memory content + state to minimize vm downtime
+    return $mem_size*2 + $driver_state_size;
+}
+
 1;
-- 
2.20.1






More information about the pve-devel mailing list