Commit Graph

3459 Commits

Author SHA1 Message Date
Dominik Csapak
21cacf5c92 vm stop-cleanup: allow callers to decide error behavior
and keep it the same for all current callers as before by setting the
additional 'noerr' parameter to '1'.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2025-03-06 16:33:14 +01:00
Dominik Csapak
45f67709ea api: termproxy/vncproxy: fix 'use of uninitialized value' when checking vga type
in our schema for 'vga' the type is optional, so a config like

 vga: memory=64

is valid. When checking the type we have to check if the type is defined
before accessing it.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
[FE: add 'termproxy/vncproxy' prefix to commit title]
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-03-05 14:42:42 +01:00
Fiona Ebner
664c50a1c6 hotplug pending: disallow deleting tpmstate and efidisk from configuration
When the VM is running, after deleting the tpmstate from the
configuration, the TPM drive will still be active, because it is used
by swtpm and QEMU will still have the TPM socket.

Also, a subsequent live migration will fail, because the
commandline for the target instance does not match the one for the
source:
> kvm: Unknown ramblock "tpm-ppi", cannot accept migration

For efidisk, hotunplug would already fail with
> can't unplug device 'efidisk0'
but it's better to catch this early and queue the change as pending
instead.

For modifying the 'tpmstate0' and 'efidisk0' options, there are
already checks to disallow live changes.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-03-03 13:19:53 +01:00
Daniel Kral
c68ee66c37 api: remove unused size variable in check_storage_access
Remove variable `$size`, which is not used here and likely a copy-paste
redundancy from the `create_disks` subroutine.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
2025-02-20 14:36:40 +01:00
Daniel Kral
767dea05da fix #5284: api: clone_vm: assert content type support for target storage
Asserts whether the target storage supports storing VM images before
cloning a VM and its volumes to the target storage.

Without the check in place, a VMs volumes can be cloned to a storage,
which does not support VM images, but won't be able to start since any
attached volume must be stored on a supported storage.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
2025-02-20 14:36:40 +01:00
Daniel Kral
b17e33788d fix #5284: api: move-disk: assert content type support for target storage
Asserts whether the target storage supports storing VM images before
moving a VM volume to the target storage.

Without the check in place, a VM volume can be moved to a storage, which
does not support VM images, but won't be able to start since any
attached volume must be stored on a supported storage.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
2025-02-20 14:36:40 +01:00
Daniel Kral
295d0be11c test: cfg2cmd: expect error for invalid volume's storage content type
Tests whether when running `config_to_command` it will correctly fail
with an error message that a volume cannot be used if the underlying
storage does not support its content type.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
[FE: add 'content' key to storage hash to be slightly more realistic]
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-20 14:35:30 +01:00
Fabian Grünbichler
78a0c43e7c bump version to 8.3.8
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2025-02-18 15:06:04 +01:00
Fabian Grünbichler
92d2ffdd9b config: make attempts at writing out NoWrite configs fatal
attempting to write such a config is already a bug, and execution should not
continue in this case. very often a write of the config will be followed by
reloading it, expecting changes to be persisted and possibly missing
re-checking of the original reason for marking the config as NoWrite.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-18 15:06:04 +01:00
Fabian Grünbichler
275a6f477c config: revamp NoWrite interface
instead of blessing a passed-in config and returning it, explicitly only bless
without returning to make it more obvious to callers that this affects the
argument.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-18 15:06:04 +01:00
Fiona Ebner
3d32c4e588 vzdump: align behavior for vma backup with PBS backup for templates
For PBS, templates are started in 'prelaunch' mode for backup and the
same can be done for VMA for consistency.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-18 15:06:04 +01:00
Fiona Ebner
a52f3dd3b0 fix #6007: template backup: use minimized configuration for handling the full vm start
Previously, the template's configuration was used as-is for the rest
of handling the VM start even if config_to_command() uses a minimized
configuration to build the command. This can lead to issues with a
network device with the 'link_down' flag set, because the network
device will not be present, but the start handling will still issue a
QMP command for it, leading to a failed backup operation.

Use the minimized configuration for the whole start-up handling to
avoid such issues.

Use the special QemuConfig::NoWrite class to safeguard against
accidentally writing out the temporarily modified config.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-18 15:06:04 +01:00
Fiona Ebner
1afbefb2d0 config: add special class that prevents writing the configuration
To be used in the context of template backup, where a minimized
temporary configuration is created to start the VM in 'prelaunch'
mode. Issue a warning, so that code paths where this happens will be
noted and can be evaluated and adapted.

Since the code currently doesn't use blessed config objects, special
dispatching is needed to potentially defer to the new child class in
the write_config() method.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-18 15:06:04 +01:00
Fiona Ebner
4db7e8612a backup: also restore VM power state for early failures
A failure during enforce_vm_running_for_backup() would result in
restore_vm_power_state() not being called, but the VM might already
have been started before the failure. In particular, this could happen
in the context of bug #6007 [0], where the 'set_link' QMP command
fails right after VM start.

If the failure happens before successful start, there will be an
additional error message issued by restore_vm_power_state() (that the
VM is not running). This could be avoided by returning early if the VM
is not running anymore, but that would mean not warning about it in
other scenarios where it is not expected and keeping track of whether
the VM was actually started or not does not seem to be worth it just
for avoiding that error message in this edge case.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=6007

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-02-18 15:06:04 +01:00
Fabian Grünbichler
5c15c65f1d resume: error out if VM is a template
Template-VMs might be started in 'prelaunch' state when creating a
backup, but they must never be actually started fully, to avoid
modifying their disks.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-02-18 15:03:25 +01:00
Thomas Lamprecht
7a6c664fb2 bump version to 8.3.7
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-02-04 17:12:28 +01:00
Fiona Ebner
48333b4d6a qmp helpers: device add/del: use HMP interface
Fixes device hotplug in combination with QEMU 9.2.

QEMU commit be93fd5372 ("qdev-monitor: avoid QemuOpts in QMP device_add")
notes:

> This patch changes the behavior of QMP device_add but not HMP
> device_add. QMP clients that sent incorrectly typed device_add QMP
> commands no longer work. This is a breaking change but clients should be
> using the correct types already.

The qemu_deviceadd() helper does not have the required type
information right now, so switch to using HMP, which still behaves the
same when passing a device commandline string. QEMU commit be93fd5372
fixes passing in complex properties via JSON, but the qemu_deviceadd()
helper never uses any such, as it already only received a string (and
naively split it up).

Use HMP for 'device_del' too, simply to keep the qemu_deviceadd() and
qemu_devicedel() helpers consistent.

Switching back to QMP using the correct types in the JSON can still be
done later. Unfortunately, 'qmp-query-schema' does not provide
device-specific types, so another way is needed.

A timeout of 25 seconds is used rather then relying on the low default
like before, since device plug operations require actions by the guest
kernel and might require IO. Device plug is often an interactive
operation, so a too high timeout could lead to bad UX. For now stay a
few seconds under the default timeout of 30 seconds of our web UI's
API request handler. Should specific devices need a higher timeout, it
can still be increased further for them in the future.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
 [TL: reduce timeout from 30s to 25s to ensure sync API requests
      (without a task worker) do not run into the frontend timeout]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-02-04 17:07:19 +01:00
Fiona Ebner
0fc03fc18d api: fix ova live import by using correct format for source image
Commit c8ed1ac2 ("api: create disks: live import: use format from
storage layer") broke live import from an OVA containing a disk,
because a combined format like 'ova+vmdk' was used for the live-import
disk mapping, leading to failure:

> invalid format 'ova+vmdk' for 'scsi0' mapping

There was also an informational message about the confusion earlier:

> file_size_info: '/mnt/pve/dir/images/135/vm-135-disk-0.vmdk': \
> falling back to 'raw' from unknown format 'ova+vmdk

Fixes: c8ed1ac2 ("api: create disks: live import: use format from storage layer")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-20 18:49:41 +01:00
Fabian Grünbichler
9ebec81f01 bump version to 8.3.6
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2025-01-20 14:46:45 +01:00
Fiona Ebner
ae1da616a7 api: create/update vm: avoid printing empty machine string
While no problem is known with having an empty machine string in the
configuration and it was already possible setting an empty machine
manually via 'qm set', the behavior changed because of commit 919e69d0
("machine: add check_and_pin_machine_string() helper") and there is
potential for problematic edge cases. Restore the previous behavior.

Pinning is also required when there is no given machine type, so the
call to check_and_pin_machine_string() should stay unconditional.

For update, pinning was recently added by commit 7a9570f3 ("api:
update vm config: pin machine version when switching to windows os
type"), so bring that in-line with the behavior for create too.

Another idea would've been to just return the default machine in
check_and_pin_machine_string(), but that would also be a change in
behavior. In particular, the default depends on the arch, so an empty
machine type will pick the default machine for the currently
configured arch even when the arch is later changed.

Reported-by: Daniel Herzig <d.herzig@proxmox.com>
Fixes: 919e69d0 ("machine: add check_and_pin_machine_string() helper")
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-20 14:43:07 +01:00
Fabian Grünbichler
b41549af09 bump version to 8.3.5
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2025-01-20 11:22:29 +01:00
Fiona Ebner
74139e72b0 drive: commandline info: re-use drive_id variable in error message
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
2025-01-20 11:20:55 +01:00
Fiona Ebner
098d94739b print drive commandline: code cleanup
Drop unused $volname variable and in-line single-use $volid variable.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
2025-01-20 11:20:55 +01:00
Fiona Ebner
b9677ce1ee CD-ROM change: re-use get_path_and_format() helper
While the path for changing a CD-ROM medium was already consistent
with the path for an already inserted CD-ROM at VM start, i.e. the one
from print_drive_commandline_full(), this makes that fact more
explicit. While at it, make sure the format is also consistent with
how it is determined in print_drive_commandline_full(). Do the same
for cloud-init drives, which often are in non-raw format.

Reported-by: Friedrich Weber <f.weber@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
2025-01-20 11:20:55 +01:00
Fiona Ebner
edaf48cf55 drive: add get_path_and_format() helper
To allow re-using it for CD-ROM hotplug.

No functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
2025-01-20 11:20:55 +01:00
Fiona Ebner
9f95aa78c7 move get_drive_id() helper to drive module
No functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
2025-01-20 11:20:55 +01:00
Fiona Ebner
caddaa62c7 move CD-ROM related helpers to drive module
This was the only user of List::Util, so move that too.

No functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Friedrich Weber <f.weber@proxmox.com>
2025-01-20 11:20:55 +01:00
Thomas Lamprecht
d55f7ced32 bump version to 8.3.4
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-01-17 19:34:47 +01:00
Fiona Ebner
93c7a7a57b machine: code cleanup: avoid superfluous augmented assignment operator
Suggested by perlcritic.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
c5d4b11f3e machine: rename machine_version() function to is_machine_version_at_least()
The old name does not make it clear what exactly the function does.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
55b277d224 machine: log informational line when pinning machine version for Windows guest
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
7a9570f33e api: update vm config: pin machine version when switching to windows os type
During virtual machine creation, the machine version is pinned when
the guest OS is Windows. The same should be done when the guest OS
type is newly set to Windows for consistency.

NOTE RFC

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
919e69d0d3 machine: add check_and_pin_machine_string() helper
Extract the logic for guest OS-type dependent machine version pinning
into a dedicated helper, so it can be re-used.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
455e12636f machine: fallback to creation QEMU version for windows starting with 9.1
Starting from QEMU creation version 9.1, pin to the creation version
instead. Support for machine version 5.1 is expected to drop with QEMU
11.1 and it would still be good to handle Windows VMs that do not have
explicit machine version for whatever reason. For example, explicitly
setting the machine without a version on the CLI/API after creation is
one way to end up with such a machine.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
8c4f436b3c move meta information handling to its own module
Like this, it can be used by modules that cannot depend on
QemuServer.pm without creating a cyclic dependency.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
db528966c9 move get_vm_machine() function to machine module
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
5c8407b0dc move windows_get_pinned_machine_version() function to machine module
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
85d47ae2fe move get_installed_machine_version() helper to machine module
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
8532a50890 machine: add default_machine_for_arch() helper
There are already other places where 'aarch64' and 'x86_64' are
checked to be the only valid architectures, for example, the
get_command_for_arch() helper, so the new error scenario for an
unknown arch should not cause any regressions.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
82dff842f0 move get_vm_arch() helper to helpers module
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
1715febd33 move kvm_user_version() function to helpers module
Add an export, since the function is rather commonly used (in
particular inlined in function calls, where prefixing with the module
name would hurt readability) and there won't be much potential for
confusion name-wise.

This was the only user of stat(), so remove the File::stat include.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
0050aa8735 move get_command_for_arch() helper to helpers module
Cannot use the is_native_arch() helper inside the function anymore,
to avoid a cyclic dependency between the 'CPUConfig' and 'Helpers'
modules, inline it.

While at it, improve the variable name for the mapping.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Fiona Ebner
1cb9f2cb89 machine: drop unused parameter from assert_valid_machine_property() helper
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2025-01-17 19:24:02 +01:00
Daniel Kral
3aa377c9fe api: create disks: also convert tpmstate and efidisk to base image for templates
The commit 37a1f42a introduced a conversion step for newly allocated
volume disks to base volumes for VM templates. This wrongly excluded
efidisk and tmpstate volumes from this conversion, even though those
should be converted to base volumes too.

Therefore, include efidisks and tpmstate volumes to be converted to base
volumes when newly allocating them.

Suggested-by: Fiona Ebner <f.ebner@proxmox.com>
Fixes: 37a1f42a ("fix #5301: convert added volume disks to base images for templates")
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
2025-01-13 16:29:36 +01:00
Daniel Kral
6b2091da7f vmstatus: make memory description consistent with pve-container
Fixes a small typo and uses the same wording as used in pve-container's
description of the `mem` property.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
2024-12-18 16:41:23 +01:00
Dominik Csapak
f6c7916749 api: migration preconditions: add more return type information
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-12-18 13:43:59 +01:00
Dominik Csapak
1b0df64e87 vmstatus: document more return types
namely 'cpu' and 'mem'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-12-17 14:21:42 +01:00
Fabio Fantoni via pve-devel
03614a8992 fix vm shutdown when agent conf is enabled but is not running in the vm
Checking only vm configuration for choose the shutdown method causes it
to always fail, after reaching the timeout, if the qemu agent option in
the vm configuration is enabled but the agent is not installed and
active in the guest.
As I seen in the windows vm the agent also crashes in some cases, so
shutdown don't fail only if qemu guest agent is not installed or not
started.

Added check that agent is active when choosing agent shutdown method to
avoid certain shutdown failure in those cases.

Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
[FE: do not set flag to suppress warning when agent is not running]
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-17 13:50:20 +01:00
Thomas Lamprecht
fa7e48662c bump version to 8.3.3
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-12-15 14:26:36 +01:00
Fabian Grünbichler
9ed5a3371b create_disks: disallow adding of non-raw tpmstate0 volumes
when creating new ones, we already force raw as format, but adding existing
volumes as tpmstate0 had no such checks.

Suggested-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-12-12 11:37:59 +01:00