[pve-devel] [PATCH qemu-server v2 6/6] add statestorage parameter to suspend API

Dominik Csapak d.csapak at proxmox.com
Wed Mar 13 09:55:04 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>
---
new in v2

the reordering of the parameters of prepare_save_vmstate is ok since
we just added the last parameter and only use it once (where we fix it)

 PVE/API2/Qemu.pm  | 10 +++++++++-
 PVE/QemuServer.pm |  9 +++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 8448ac4..a3e1ca4 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';
@@ -2384,7 +2392,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/QemuServer.pm b/PVE/QemuServer.pm
index 7dfd52b..f45f201 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) = @_;
 
     PVE::QemuConfig->lock_config($vmid, sub {
 
@@ -5701,7 +5701,7 @@ sub vm_suspend {
 	    # save vm state
 	    my $date = strftime("%Y-%m-%d", localtime(time()));
 	    my $storecfg = PVE::Storage::config();
-	    my $vmstate = prepare_save_vmstate($vmid, $conf, "suspend-$date", $storecfg, 1);
+	    my $vmstate = prepare_save_vmstate($vmid, $conf, "suspend-$date", $storecfg, $statestorage, 1);
 	    my $path = PVE::Storage::path($storecfg, $vmstate);
 	    PVE::Storage::activate_volumes($storecfg, [$vmstate]);
 
@@ -7171,10 +7171,11 @@ sub nbd_stop {
 }
 
 sub prepare_save_vmstate {
-    my ($vmid, $conf, $snapname, $storecfg, $suspend) = @_;
+    my ($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);
-- 
2.11.0





More information about the pve-devel mailing list