Commit Graph

595 Commits

Author SHA1 Message Date
Stefan Hanreich
76b29aafd7 fix #4228: add start parameter to rollback endpoint for automatic restarting of VM
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
2022-11-08 18:15:49 +01:00
Thomas Lamprecht
058fe7bc48 api: update cloudinit: line reduction/small cleanups
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-11-08 17:38:18 +01:00
Thomas Lamprecht
92f4be45d2 api: add cloudinit to available subdirs index
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-11-08 17:35:04 +01:00
Alexandre Derumier
9687287bb3 api2: add cloudinit_update
This allow to regenerate the config drive with 1 api call.

This also avoid to delete drive first, and recreate it again.

As it's a readonly drive, we can simply live update it,
and eject/replace it with qemu monitor

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2022-11-08 17:31:59 +01:00
Alexandre Derumier
2be1fb0af4 api2: add cloudinit config api
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2022-11-08 17:24:59 +01:00
Fiona Ebner
dbc45fdf9f api: create/update vm: clamp cpuunit value
While the clamping already happens before setting the actual systemd
CPU{Shares, Weight}, it can be done here too, to avoid writing new
out-of-range values into the config.

Can't use a validator enforcing this because existing out-of-range
values should not become errors upon parsing the config.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-11-08 16:21:27 +01:00
Fabian Ebner
39b56b169a api: create disks: avoid adding secondary cloud-init drives
This will break possibly existing workflows like
1. add second cloud-init
2. remove first cloud-init
to change the cloud-init storage.

On the other hand, it avoids unintended misconfiguration of having
mutliple cloud-init drives with potentially different settings.

Also in preparation for adding cloud-init-related API calls, where
not being able to assume that there's only one cloud-init drive/state
would complicate things quite a bit.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-09-12 18:04:59 +02:00
Thomas Lamprecht
161c2dde4b expand error for suspend with pcie pass through a bit
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-08-30 08:34:50 +02:00
Thomas Lamprecht
876b24f228 shorten and subjectively improve code comment
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-08-30 08:32:43 +02:00
Dominik Csapak
227a298f7f fix #3577: prevent suspension for VMs with pci passthrough
Prevent the user from suspending the vm at all, as while suspension
itself may finish, the saved state is incomplete as we can neither
save nor restore PCIe device state in any generic fashion, so
resuming will almost certainly break.

The single case when it could work is when the guest OS didn't uses
the passed through device at all, so there's no state, but that's
really odd (as why bother passing through then), and the user should
rather remove the hostpci entry in that case.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ T: reword commit message slightly ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-08-30 08:32:43 +02:00
Fabian Grünbichler
e88ceecac1 fix uninitialized value
if the configured display hardware has the (optional) default type, but
some other attribute is set, this would match against `undef` and spew
lots of warnings in the logs.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-05-30 12:12:08 +02:00
Thomas Lamprecht
96670745a6 api: reassign disk: drop moved disk from boot order
Reported-by: Matthias Heiserer <m.heiserer@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-05-02 13:28:08 +02:00
Fabian Ebner
13d121d79b fix #3861: migrate: fix live migration when cloud-init changes storage
Generalizes fd95d780 ("migrate: send updated TPM state volid to target
node") to also handle other offline migrated disks appearing in the
VM config, which currently should only be cloud-init.

Breaks migration new -> old under similar (edge-case-)conditions as
fd95d780 did.

Keep sending the 'tpmstate0' STDIN parameter to avoid breaking new ->
old in the scenario fd95d780 fixed.

Keep parsing the vm_start 'tpmstate0' STDIN parameter to avoid
breaking old -> new, and to be able to keep sending it.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-28 18:29:12 +02:00
Thomas Lamprecht
f8ea1b30ce enable spice also for virtio-gpu display
same spirit as commit 3591b62b85

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-04-28 17:47:07 +02:00
Fabian Ebner
202a2a0bee api: create: allow overriding non-disk options during restore
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-28 08:43:09 +02:00
Fabian Ebner
325b32cc40 api: create: refactor parameter check logic
In preparation to allow passing along certain parameters together with
'archive'. Moving the parameter checks to after the
conflicts-with-'archive' to ensure that the more telling error will
trigger first.

All check helpers should handle empty params fine, but check first
just to make sure and to avoid all the superfluous function calls.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-28 08:43:09 +02:00
Thomas Lamprecht
3591b62b85 api: status: report spice also for virtio-gl display
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-04-28 08:16:02 +02:00
Fabian Ebner
db81c00754 api: create/modify: fix content type checks by re-allowing iso images
Fixes: f9be9137 ("api: create/modify: add content type checks"
Reported-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-22 14:28:49 +02:00
Fabian Ebner
3e7d9fac7c api: update vm: print drive string for newly allocated/imported drives
In the spirit of c75bf16 ("qm importdisk: tell user to what VM disk we
actually imported"), and so that the information is not lost once qm
importdisk switches to re-using the API call.

Added for cloudinit too, because a new disk is allocated.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-04 16:41:13 +02:00
Dominic Jäger
e6ac9fed7b api: support VM disk import
Extend qm importdisk functionality to the API.

Co-authored-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Co-authored-by: Dominic Jäger <d.jaeger@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-04 16:41:13 +02:00
Fabian Ebner
c1accf9db9 schema: drive: use separate schema when disk allocation is possible
via the special syntax <storeid>:<size>.

Not worth it by itself, but this is anticipating a new 'import-from'
parameter which is only used upon import/allocation, but shouldn't be
part of the schema for the config or other API enpoints.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-04 16:41:13 +02:00
Fabian Ebner
e4a70a41fb api: clone vm: check against cloning running TPM state early
Drive keys are sorted when cloning and 'tpmstate0' comes late, so it
was likely that potentially large disks were already copied just to be
removed again, because of the TPM state restriction at the end.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-01 10:24:59 +02:00
Fabian Ebner
f9be9137fc api: create/modify: add content type checks
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-01 09:58:01 +02:00
Fabian Grünbichler
1770b70fdf api: snapshot delete: prefix lock-fail error
otherwise users might get confused if they just get a message about a
migrate lock not being available..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-03-15 13:28:27 +01:00
Fabian Ebner
fdbbed2fac fix #3424: api: snapshot delete: wait for active replication
A to-be-deleted snapshot might be actively used by replication,
resulting in a not (or only partially) removed snapshot and locked
(snapshot-delete) VM. Simply wait a few seconds for any ongoing
replication.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-15 12:06:21 +01:00
Fabian Ebner
7979bbcd43 api: factor out check/cleanup for drive params
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-14 16:28:55 +01:00
Fabian Ebner
25166060ae clone disk: allow cloning from an unused or unreferenced disk
and also when source and target drivename are different. In those
cases, it is done via qemu-img convert/dd.

In preparation to allow import from existing PVE-managed disks.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-11 10:45:59 +01:00
Fabian Ebner
7344af7bf8 clone disk: pass in efi vars size rather than config
It's confusing that the config associated to the destination is
actually a reference to the source config for both existing callers.

Also, disk import will need to base the calculation on the passed-in
drive parameters and not just the current config, so this change is in
preparation for that too.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-11 10:45:59 +01:00
Fabian Ebner
1196086ff1 clone disk: group source and target parameters
to make the interface more digestible.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-11 10:45:59 +01:00
Fabian Ebner
367e6bf4b7 api: update: pass correct config when creating disks
While the new options should be written to the pending config, the
decisions (currently only one) in create_disks needs to be made for
the current config.

Seems to fix EFI disk creation, but actually, it's only
future-proofing, because, currently, the same OVMF_VARS file is
used independently of $smm.

The correct config is also needed to determine the correct size for
the EFI disk for the upcoming import-from feature.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-11 10:45:59 +01:00
Fabian Ebner
fe19840a56 api: create disks: always activate/update size when attaching existing volume
For creation, activation and size update never triggered, because the
passed in $conf is essentially the same as the creation $settings, so
the disk was always detected to be the same as the "existing" one. But
actually, all disks are new, so it makes sense to do it.

For update, activation and size update nearly always triggered,
because only the pending changes are passed in as $conf. The case
where it didn't trigger is when the same pending change was made twice
(there are cases where hotplug isn't done, but makes it even more
unlikely).

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-03-11 10:45:59 +01:00
Oguz Bektas
6ab41628b2 api: vm_start: 'force-cpu' is for internal migration use only
'force-cpu' parameter was introduced to allow live-migration of VMs with
custom CPU models; it does not need to be allowed for general use on
vm_start for regular users, since they would be able to set arbitrary
cpu types or cpuid parameters that aren't supported.

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
2022-03-08 15:16:09 +01:00
Fabian Grünbichler
c9c32c1ba4 update_vm: allow simultaneous setting of boot-order and dev
else this fails if we check 'boot' before the device was put into
the config or pending section.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-02-09 18:48:29 +01:00
Fabian Grünbichler
4df8fe45b2 clone: repeat more checks after locking
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-02-08 09:00:31 +01:00
Fabian Ebner
bdf6ba1e7d api: move disk: fork before locking
using the familiar early+repeated checks pattern from other API calls.
Only intended functional changes are with regard to locking/forking.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-01-31 13:10:33 +01:00
Fabian Ebner
dbecb46f2a api: clone: fork before locking
using the familiar early+repeated checks pattern from other API calls.
Only intended functional changes are with regard to locking/forking.

For a full clone of a running VM without guest agent, this also fixes
issuing vm_{resume,suspend} calls for drive mirror completion.
Previously, those just timed out, because of not getting the lock:

> create full clone of drive scsi0 (rbdkvm:vm-104-disk-0)
> Formatting '/var/lib/vz/images/105/vm-105-disk-0.raw', fmt=raw
> size=4294967296 preallocation=off
> drive mirror is starting for drive-scsi0
> drive-scsi0: transferred 2.0 MiB of 4.0 GiB (0.05%) in 0s
> drive-scsi0: transferred 635.0 MiB of 4.0 GiB (15.50%) in 1s
> drive-scsi0: transferred 1.6 GiB of 4.0 GiB (40.50%) in 2s
> drive-scsi0: transferred 3.6 GiB of 4.0 GiB (90.23%) in 3s
> drive-scsi0: transferred 4.0 GiB of 4.0 GiB (100.00%) in 4s, ready
> all 'mirror' jobs are ready
> suspend vm
> trying to acquire lock...
> can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout
> drive-scsi0: Cancelling block job
> drive-scsi0: Done.
> resume vm
> trying to acquire lock...
> can't lock file '/var/lock/qemu-server/lock-104.conf' - got timeout

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-01-31 13:10:33 +01:00
Fabian Grünbichler
fd95d780a2 migrate: send updated TPM state volid to target node
The volid may change if local-storage migration is involved, we need
to tell the target node the new one and update the in-memory config
for starting the target VM accordingly.

Reported here: https://forum.proxmox.com/threads/99906/#post-431345

this possibly breaks migration new -> old iff
- spice is not used (else the explicit ticket wins because it comes
  later)
- a local TPM state volume is used
- that local TPM state volume has a different volume id on the target
  node (switched storage, volname already taken, ..)

because the target node will then mis-interpret the tpmstate0 line as
spice ticket and set it accordingly. if the old tpm state volume ID does
not exist on the target node, migration will fail. if it exists by
chance, it might work albeit with a wrong spice ticket (new because of
this patch) and tpm state volume (pre-existing breakage).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-22 16:55:17 +01:00
Fabian Grünbichler
399ca0d66e migrate: improve start STDIN-parameter parsing
only do the compat fallback if no explicit spice ticket was given, and
warn on unknown parameters on STDIN.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-22 16:53:09 +01:00
Thomas Lamprecht
ce3fbcd456 api: update: fix missing newline in background-delayed task error
this error path is mostly used for re-attaching disks and the like,
and the "check if task is already done" part uses a method to read
the task status that will never include a trailing newline, so add it
our self to avoid "... at /usr/share/perl5/PVE/API2/Qemu.pm line
1480. (500)"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-15 09:21:50 +01:00
Thomas Lamprecht
f519ab0b76 api: move disk: schema indentation and style-nit fixes
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-11 14:01:04 +01:00
Fabian Grünbichler
9fb295d095 migrate: factor out storage checks
to re-use them for incoming remote migrations.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fabian Ebner <f.ebner@proxmox.com>
2021-11-11 10:47:26 +01:00
Aaron Lauterer
bf67da2bf7 disk reassign: add unused disks directly to config
Using $update_vm_api for unused disks will cause them to end up as a
pending change if the VM is running.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
2021-11-11 10:08:26 +01:00
Fabian Grünbichler
f4e4c77984 disk reassign: fix assigning to unused slot
this broke with the previous simplification.

Tested-by: Aaron Lauterer <a.lauterer@proxmox.com>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-10 12:41:04 +01:00
Fabian Grünbichler
a6273aa8bf reassign disk: more cleanup
avoid re-using the toplevel variable name

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-10 12:11:03 +01:00
Fabian Grünbichler
441024921e reassign disk: fix permission checks
with `storage` being optional (and not allowed for reassign operations),
the ACL path in the schema can end up as `/storage/-`, which is wrong.
replace it with an explicit check:

- target `storage` for move disk
- storage from source disk for reassign disk (we only rename here, but
  it's still a new volume on that storage after all)

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-10 11:49:36 +01:00
Fabian Grünbichler
dbc817ba4a reassign disk: various improvements
some style, some missing checks. some duplication reduced a bit.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-10 11:49:36 +01:00
Aaron Lauterer
70c0ad6687 api: move-disk: cleanup very long lines
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
2021-11-09 16:16:00 +01:00
Aaron Lauterer
a94532188d api: move-disk: add move to other VM
The goal of this is to expand the move-disk API endpoint to make it
possible to move a disk to another VM. Previously this was only possible
with manual intervertion either by renaming the VM disk or by manually
adding the disks volid to the config of the other VM.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
2021-11-09 16:16:00 +01:00
Thomas Lamprecht
26b443c846 config: add new meta property with the VM creation time
currently we only add the creation time (ctime), that was requested
as low priority wish from some users from time to time.

Note that the meta info is not available in the update API endpoints,
and at the moment the code should not change/add/delete it either in
any place.

We may want to update in on actions like clone or backup-restore in
the future, e.g., to also save the time of that event and possibly
the original source VMID, put that can be thought out later.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-04 15:30:22 +01:00
Dominik Csapak
90b20b152c use non SMM ovmf code file for i440fx machines
ovmf with SMM enabled will not boot on i440fx (hangs on graphics
initialization), so load the non SMM variant.

should be no issue regarding live-migration since it never worked with
this anyway.

adapts the test and adds one with q35

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Stefan Reiter <s.reiter@proxmox.com>
Reviewed-by: Stefan Reiter <s.reiter@proxmox.com>
2021-10-21 12:38:58 +02:00