From: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
Subject: [PATCH qemu-server 2/3] api: create disks: update TPM size on creation
Date: Tue, 27 Oct 2026 11:17:22 +0100 [thread overview]
Message-ID: <20261027101723.144576-3-t.ellmenreich@proxmox.com> (raw)
In-Reply-To: <20261027101723.144576-1-t.ellmenreich@proxmox.com>
When creating a TPM drive, the default size is 4MiB. This default is
constant and cannot be changed, unless the backing storage has a bigger
granularity, in which case it is forcibly changed to the bigger size.
To directly show the correct size of a TPM drive, query its size after
creation, and set that as the drive size.
Suggested-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/API2/Qemu.pm | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index f4dbd2a1..cb5c17f0 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -34,7 +34,11 @@ use PVE::QemuServer::Blockdev;
use PVE::QemuServer::BlockJob;
use PVE::QemuServer::Cloudinit;
use PVE::QemuServer::CPUConfig;
-use PVE::QemuServer::Drive qw(checked_volume_format checked_parse_volname);
+use PVE::QemuServer::Drive qw(
+ checked_volume_format
+ checked_parse_volname
+ get_tpmstate_size
+);
use PVE::QemuServer::Helpers;
use PVE::QemuServer::ImportDisk;
use PVE::QemuServer::Monitor qw(mon_cmd vm_qmp_peer);
@@ -669,13 +673,18 @@ my sub create_disks : prototype($$$$$$$$$$$) {
$storecfg, $storeid, $vmid, $fmt, $arch, $disk, $smm, $cvm_type,
);
} elsif ($ds eq 'tpmstate0') {
- # A fixed size is used for TPM state volumes
- $size = PVE::Tools::convert_size(
+ # A fixed size is requested for TPM state volumes, but the
+ # storage might increase it up to its allocation granularity
+ my $target_size = PVE::Tools::convert_size(
PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE,
'b' => 'kb',
);
- $volid =
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size);
+ $volid = PVE::Storage::vdisk_alloc(
+ $storecfg, $storeid, $vmid, $fmt, undef, $target_size,
+ );
+ $size = PVE::Tools::convert_size(
+ get_tpmstate_size($volid, $storecfg), 'b' => 'kb',
+ );
} else {
$volid =
PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size);
--
2.47.3
next prev parent reply other threads:[~2026-10-27 10:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 10:17 [PATCH qemu-server 0/3] drive: account for differing TPM sizes Thomas Ellmenreich
2026-10-27 10:17 ` [PATCH qemu-server 1/3] drive: update TPM size as max of current and minimum size Thomas Ellmenreich
2026-10-27 10:17 ` Thomas Ellmenreich [this message]
2026-10-27 10:17 ` [PATCH qemu-server 3/3] clone disk: read actual size when cloning TPM drive Thomas Ellmenreich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027101723.144576-3-t.ellmenreich@proxmox.com \
--to=t.ellmenreich@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox