Commit Graph

1532 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Fabian Grünbichler
4182c3da78 swtpm: drop unused $volname variable
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-12 10:47:44 +01:00
Fabian Grünbichler
1fe55a9f6c swtpm: check that format of tpmstate volume is raw
since swtpm currently doesn't support anything else, and might overwrite a file
using qcow2 or vmdk format by accident..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-12 10:47:42 +01:00
Fiona Ebner
034768882f remove dead qemu_img_format() helper
All callers have been switched to get the format from the storage
layer using checked_volume_format() and friends.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
1f961e51a8 resolve destination disk format helper: use volume format from storage layer
Avoid using the extension based qemu_img_format() helper.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
9cefe5d7bf drive mirror: use volume format from storage layer
Avoid using the extension based qemu_img_format() helper.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
2d62759f6c backup: parse backup hints: use volume format from storage layer
Avoid using the extension based qemu_img_format() helper. Failure is
not critical, because this is just the hint for what format the
restored target image should be allocated with, so fallback to 'raw'.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
0da8f110e8 migration: get nbd disks helper: use volume format from storage layer
Avoid using the extension based qemu_img_format() helper.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
d6e76d1b60 cfg2cmd: ovmf drive: use volume format from storage layer
Avoid using the extension based qemu_img_format() helper.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
9c5e02e5dd image convert: use volume format from storage layer
Avoid using the extension based qemu_img_format() helper.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
c9398d15ff clone: be explicit about source format when cloning EFI disk
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 09:07:17 +01:00
Fiona Ebner
9f887d3738 cfg2cmd: print drive commandline: improve format detection
For a Proxmox VE managed volume, prefer the format from the storage
layer rather than the 'format' option set on the drive. Fail if there
is a mismatch between the detected and configured format, because this
is not expected for managed volumes. Having this early hard failure
protects against undesirable issues with live migration and reboot
where the format of a drive would suddenly be different.

For a not Proxmox VE managed volume, use the same logic as before,
i.e. use the 'format' option for the drive with 'raw' as a fallback:
Only root can configure such devices.

Both also apply to the case where the 'cdrom' flag is set to avoid
autodetection by QEMU.

Reported-by: Friedrich Weber <f.weber@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
FG: typo fix in comment
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-12-09 09:07:08 +01:00
Fiona Ebner
7dc33415e1 resolve destination disk format helper: fix indentation
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-05 17:27:05 +01:00
Fiona Ebner
1cd6990f9b print drive commandline: fix indentation
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-05 15:43:41 +01:00
Thomas Lamprecht
8770febbef tree-wide: fix various typos in comments
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-12-05 12:33:24 +01:00
Fiona Ebner
c2f1e06ab9 cfg2cmd: drop superfluous check for QEMU binary version 4.1
The minimum supported version for Proxmox VE 8 nodes is QEMU 8.0 and
the beginning of the config_to_command() function already has a check
for at least version 5.0. No other caller of get_vm_machine() passes
in the parameter, so it can be removed from there as well.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Daniel Kral <d.kral@proxmox.com>
Tested-by: Daniel Kral <d.kral@proxmox.com>
2024-12-05 12:13:20 +01:00
Fiona Ebner
86b1f1c24c cfg2cmd: require at least QEMU binary version 5.0
The minimum supported version for a Proxmox VE 8 node is QEMU 8.0.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Daniel Kral <d.kral@proxmox.com>
Tested-by: Daniel Kral <d.kral@proxmox.com>
2024-12-05 12:13:20 +01:00
Fiona Ebner
2263b8548d cfg2cmd: require at least QEMU binary version 4.0
The minimum supported version for a Proxmox VE 8 node is QEMU 8.0.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Daniel Kral <d.kral@proxmox.com>
Tested-by: Daniel Kral <d.kral@proxmox.com>
2024-12-05 12:13:20 +01:00
Fiona Ebner
e1bdb0ad44 code cleanup: drop unused parameter from get_vm_machine()
The parameter was added by ac0077cc ("Use 'QEMU version' ->
'+pve-version' mapping for machine types") but it doesn't seem like
there ever was a caller. In particular, none of the current callers
pass in a value and it's not clear when one would require passing a
different version than the KVM binary version.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Daniel Kral <d.kral@proxmox.com>
Tested-by: Daniel Kral <d.kral@proxmox.com>
2024-12-05 12:13:20 +01:00
Thomas Lamprecht
136eb3bce8 config: non-migratable resource check: join blockers when printing them
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 21:56:15 +01:00
Thomas Lamprecht
9304dc09e5 Revert "schema: add fleecing-images config property"
This reverts commit fca0ba5d77, quoting
Fiona in verbatim:

> Regarding the patch "schema: add fleecing-images config property",
> Fabian off-list suggested using a config section "special:fleecing"
> instead of a property, so that it is truly internal-only. If we go for
> that, the commit should be reverted. Which approach do you prefer?
-- https://lore.proxmox.com/pve-devel/5126c251-64fd-44fe-b1a6-fda9074eb9a1@proxmox.com/

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 21:29:48 +01:00
Markus Frank
5fc635cc6d migration: add check_non_migratable_resources function
The function checks for resources that cannot be migrated, snapshoted,
or suspended.

To run this function while the snapshot lock is active, the
pve-guest-common patch 'AbstractConfig: add abstract method to check for
resources preventing a snapshot.' is required.

Signed-off-by: Markus Frank <m.frank@proxmox.com>
2024-11-18 21:26:39 +01:00
Markus Frank
5d7288a415 config: add AMD SEV support
This patch is for enabling AMD SEV (Secure Encrypted Virtualization)
support in QEMU.

VM-Config-Examples:
amd_sev: type=std,no-debug=1,no-key-sharing=1
amd_sev: es,no-debug=1,kernel-hashes=1

kernel-hashes, reduced-phys-bits & cbitpos correspond to the variables
with the same name in QEMU.

kernel-hashes=1 adds kernel hashes to enable measured linux kernel
launch since it is per default off for backward compatibility.

reduced-phys-bios and cbitpos are system specific and are read out by
the query-machine-capabilities c program and saved to the
/run/qemu-server/host-hw-capabilities.json file. This file is parsed
and than used by qemu-server to correctly start a AMD SEV VM.

type=std stands for standard sev to differentiate it from sev-es (es)
or sev-snp (snp) when support is upstream.

QEMU's sev-guest policy gets calculated with the parameters no-debug
& no-key-sharing. These parameters correspond to policy-bits 0 & 1.
If type is 'es' than policy-bit 2 gets set to 1 to activate SEV-ES.
Policy bit 3 (nosend) is always set to 1, because migration features
for sev are not upstream yet and are attackable.

SEV-ES is highly experimental since it could not be tested.

see coherent doc patch

Signed-off-by: Markus Frank <m.frank@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 21:26:39 +01:00
Dominik Csapak
0d41c7f5a5 api: create: implement extracting disks when needed for import-from
when 'import-from' contains a disk image that needs extraction
(currently only from an 'ova' archive), do that in 'create_disks'
and overwrite the '$source' volid.

Collect the names into a 'delete_sources' list, that we use later
to clean it up again (either when we're finished with importing or in an
error case).

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2024-11-18 18:55:54 +01:00
Daniel Kral
68b82f021f templates: add documentation to template_create
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
2024-11-17 19:53:08 +01:00
Fiona Ebner
fca0ba5d77 schema: add fleecing-images config property
to be used internally to record volume IDs of fleecing images
allocated during backup.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-17 19:38:32 +01:00
Fiona Ebner
f6a390ed08 parse config: allow config keys with minus sign
In preparation for the upcoming 'fleecing-images' key. To avoid mixing
of options with - and options with _, which is not very user-friendly,
it would be nice to add aliases for existing options with _. And
long-term, backup restore handlers could switch to the modern keys
with -.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-17 19:38:29 +01:00
Fiona Ebner
30681f147e restore: die early when there is no size for a device
Makes it a clean error for buggy (external) backup providers where the
size might not be set at all.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-12 10:27:52 +01:00
Fiona Ebner
dde471e142 move nbd_stop helper to QMPHelpers module
Like this nbd_stop() can be called from a module that cannot include
QemuServer.pm.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-11 14:54:06 +01:00