}else{
$fmt = 'raw';
}
- # FIXME: Reasonable size? qcow2 shouldn't grow if the space isn't used anyway?
- my $cloudinit_iso_size = 5; # in MB
+ # Initial disk created with 4MB, every time it is regenerated the disk is aligned to 4MB again.
+ my $cloudinit_iso_size = 4; # in MB
my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid,
$fmt, $name, $cloudinit_iso_size*1024);
$disk->{file} = $volid;
};
my $cloudinitoptions = {
+ cicustom => 1,
cipassword => 1,
citype => 1,
ciuser => 1,
description => "Add the VM to the specified pool.",
},
bwlimit => {
- description => "Override i/o bandwidth limit (in KiB/s).",
+ description => "Override I/O bandwidth limit (in KiB/s).",
optional => 1,
type => 'integer',
minimum => '0',
+ default => 'restore limit from datacenter or storage config',
},
start => {
optional => 1,
properties => {
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
- current => {
- description => "Get current values (instead of pending values).",
- optional => 1,
+ current => {
+ description => "Get current values (instead of pending values).",
+ optional => 1,
default => 0,
type => 'boolean',
- },
+ },
snapshot => get_standard_option('pve-snapshot-name', {
description => "Fetch config values from given snapshot.",
optional => 1,
my $conf = PVE::QemuConfig->load_config($param->{vmid});
- my $snapname = $param->{snapshot};
- if ($snapname) {
+ if (my $snapname = $param->{snapshot}) {
my $snapshot = $conf->{snapshots}->{$snapname};
- die "snapshot '$snapname' does not exist\n"
- if !defined($snapshot);
+ die "snapshot '$snapname' does not exist\n" if !defined($snapshot);
+
+ $snapshot->{digest} = $conf->{digest}; # keep file digest for API
- # we need the digest of the file
- $snapshot->{digest} = $conf->{digest};
$conf = $snapshot;
}
if ($param->{$opt} eq '1') {
$param->{$opt} = PVE::QemuServer::generate_uuid();
}
+ } elsif ($opt eq 'hookscript') {
+ eval { PVE::GuestHelpers::check_hookscript($param->{$opt}, $storecfg); };
+ raise_param_exc({ $opt => $@ }) if $@;
}
}
vmid => get_standard_option('pve-vmid',
{ completion => \&PVE::QemuServer::complete_vmid_running }),
skiplock => get_standard_option('skiplock'),
+ todisk => {
+ type => 'boolean',
+ default => 0,
+ 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 => {
my $vmid = extract_param($param, 'vmid');
+ 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';
die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+ die "Cannot suspend HA managed VM to disk\n"
+ if $todisk && PVE::HA::Config::vm_is_ha_managed($vmid);
+
+ my $taskname = $todisk ? 'qmsuspend' : 'qmpause';
+
my $realcmd = sub {
my $upid = shift;
syslog('info', "suspend VM $vmid: $upid\n");
- PVE::QemuServer::vm_suspend($vmid, $skiplock);
+ PVE::QemuServer::vm_suspend($vmid, $skiplock, $todisk, $statestorage);
return;
};
- return $rpcenv->fork_worker('qmsuspend', $vmid, $authuser, $realcmd);
+ return $rpcenv->fork_worker($taskname, $vmid, $authuser, $realcmd);
}});
__PACKAGE__->register_method({
my $nocheck = extract_param($param, 'nocheck');
- die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid, $nocheck);
+ my $to_disk_suspended;
+ eval {
+ PVE::QemuConfig->lock_config($vmid, sub {
+ my $conf = PVE::QemuConfig->load_config($vmid);
+ $to_disk_suspended = PVE::QemuConfig->has_lock($conf, 'suspended');
+ });
+ };
+
+ die "VM $vmid not running\n"
+ if !$to_disk_suspended && !PVE::QemuServer::check_running($vmid, $nocheck);
my $realcmd = sub {
my $upid = shift;
syslog('info', "resume VM $vmid: $upid\n");
- PVE::QemuServer::vm_resume($vmid, $skiplock, $nocheck);
+ if (!$to_disk_suspended) {
+ PVE::QemuServer::vm_resume($vmid, $skiplock, $nocheck);
+ } else {
+ my $storecfg = PVE::Storage::config();
+ PVE::QemuServer::vm_start($storecfg, $vmid, undef, $skiplock);
+ }
return;
};
description => "Target node. Only allowed if the original VM is on shared storage.",
optional => 1,
}),
+ bwlimit => {
+ description => "Override I/O bandwidth limit (in KiB/s).",
+ optional => 1,
+ type => 'integer',
+ minimum => '0',
+ default => 'clone limit from datacenter or storage config',
+ },
},
},
returns => {
PVE::Storage::activate_volumes($storecfg, $vollist, $snapname);
+ my $bwlimit = extract_param($param, 'bwlimit');
+
my $total_jobs = scalar(keys %{$drives});
my $i = 1;
my $drive = $drives->{$opt};
my $skipcomplete = ($total_jobs != $i); # finish after last drive
+ my $src_sid = PVE::Storage::parse_volume_id($drive->{file});
+ my $storage_list = [ $src_sid ];
+ push @$storage_list, $storage if defined($storage);
+ my $clonelimit = PVE::Storage::get_bandwidth_limit('clone', $storage_list, $bwlimit);
+
my $newdrive = PVE::QemuServer::clone_disk($storecfg, $vmid, $running, $opt, $drive, $snapname,
$newid, $storage, $format, $fullclone->{$opt}, $newvollist,
- $jobs, $skipcomplete, $oldconf->{agent});
+ $jobs, $skipcomplete, $oldconf->{agent}, $clonelimit);
$newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $newdrive);
maxLength => 40,
optional => 1,
},
+ bwlimit => {
+ description => "Override I/O bandwidth limit (in KiB/s).",
+ optional => 1,
+ type => 'integer',
+ minimum => '0',
+ default => 'move limit from datacenter or storage config',
+ },
},
},
returns => {
warn "moving disk with snapshots, snapshots will not be moved!\n"
if $snapshotted;
+ my $bwlimit = extract_param($param, 'bwlimit');
+ my $movelimit = PVE::Storage::get_bandwidth_limit('move', [$oldstoreid, $storeid], $bwlimit);
+
my $newdrive = PVE::QemuServer::clone_disk($storecfg, $vmid, $running, $disk, $drive, undef,
- $vmid, $storeid, $format, 1, $newvollist);
+ $vmid, $storeid, $format, 1, $newvollist, undef, undef, undef, $movelimit);
$conf->{$disk} = PVE::QemuServer::print_drive($vmid, $newdrive);
optional => 1,
completion => \&PVE::QemuServer::complete_storage,
}),
+ bwlimit => {
+ description => "Override I/O bandwidth limit (in KiB/s).",
+ optional => 1,
+ type => 'integer',
+ minimum => '0',
+ default => 'migrate limit from datacenter or storage config',
+ },
},
},
returns => {