add statestorage parameter to suspend API

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>
This commit is contained in:
Dominik Csapak 2019-03-14 17:04:50 +01:00 committed by Thomas Lamprecht
parent 22371fe00e
commit 48b4cdc210
3 changed files with 14 additions and 5 deletions

View 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;
};

View 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);

View 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 {