]> git.proxmox.com Git - qemu-server.git/commitdiff
add statestorage parameter to suspend API
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 14 Mar 2019 16:04:50 +0000 (17:04 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 19 Mar 2019 07:53:14 +0000 (08:53 +0100)
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@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuConfig.pm
PVE/QemuServer.pm

index 7c6288fbf7b2ac62067270818a5b468b5999cd0b..3c0ad2393b0c959633526948560a815314e95093 100644 (file)
@@ -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@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;
        };
index 6693585016fb7f53ce485d4aa8940aee6a85f581..b2d4e4544150949430db8379fe8ec329aa11fe86 100644 (file)
@@ -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);
index a30533bd4dd36429dfa2267946b3aebf69a86af3..b3b95ef460c004291f25c536eb0531fc8de4c653 100644 (file)
@@ -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 {