[pve-devel] [PATCH qemu-server v3 5/5] add statestorage parameter to suspend API

Dominik Csapak d.csapak at proxmox.com
Thu Mar 14 17:04:50 CET 2019


this makes it possible to give a storage for state saving, if one
wants to use a different storage than for snapshots or does not
want to save this info into the config

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Qemu.pm  | 10 +++++++++-
 PVE/QemuConfig.pm |  5 +++--
 PVE/QemuServer.pm |  4 ++--
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 7c6288f..3c0ad23 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2355,6 +2355,12 @@ __PACKAGE__->register_method({
 		optional => 1,
 		description => 'If set, suspends the VM to disk. Will be resumed on next VM start.',
 	    },
+	    statestorage => get_standard_option('pve-storage-id', {
+		description => "The storage for the VM state",
+		requires => 'todisk',
+		optional => 1,
+		completion => \&PVE::Storage::complete_storage_enabled,
+	    }),
 	},
     },
     returns => {
@@ -2373,6 +2379,8 @@ __PACKAGE__->register_method({
 
 	my $todisk = extract_param($param, 'todisk') // 0;
 
+	my $statestorage = extract_param($param, 'statestorage');
+
 	my $skiplock = extract_param($param, 'skiplock');
 	raise_param_exc({ skiplock => "Only root may use this option." })
 	    if $skiplock && $authuser ne 'root at pam';
@@ -2387,7 +2395,7 @@ __PACKAGE__->register_method({
 
 	    syslog('info', "suspend VM $vmid: $upid\n");
 
-	    PVE::QemuServer::vm_suspend($vmid, $skiplock, $todisk);
+	    PVE::QemuServer::vm_suspend($vmid, $skiplock, $todisk, $statestorage);
 
 	    return;
 	};
diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 6693585..b2d4e45 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -116,10 +116,11 @@ sub get_replicatable_volumes {
 }
 
 sub __snapshot_save_vmstate {
-    my ($class, $vmid, $conf, $snapname, $storecfg, $suspend) = @_;
+    my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
 
     # first, use explicitly configured storage
-    my $target = $conf->{vmstatestorage};
+    # either directly via API, or via conf
+    my $target = $statestorage // $conf->{vmstatestorage};
 
     if (!$target) {
 	my ($shared, $local);
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a30533b..b3b95ef 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5679,7 +5679,7 @@ sub vm_stop {
 }
 
 sub vm_suspend {
-    my ($vmid, $skiplock, $includestate) = @_;
+    my ($vmid, $skiplock, $includestate, $statestorage) = @_;
 
     my $conf;
     my $path;
@@ -5701,7 +5701,7 @@ sub vm_suspend {
 	    $conf->{lock} = 'suspending';
 	    my $date = strftime("%Y-%m-%d", localtime(time()));
 	    $storecfg = PVE::Storage::config();
-	    $vmstate = PVE::QemuConfig->__snapshot_save_vmstate($vmid, $conf, "suspend-$date", $storecfg, 1);
+	    $vmstate = PVE::QemuConfig->__snapshot_save_vmstate($vmid, $conf, "suspend-$date", $storecfg, $statestorage, 1);
 	    $path = PVE::Storage::path($storecfg, $vmstate);
 	    PVE::QemuConfig->write_config($vmid, $conf);
 	} else {
-- 
2.11.0




More information about the pve-devel mailing list