[pve-devel] [PATCH qemu-server 01/10] add vtype to vdisk_alloc and vdisk_clone calls

Wolfgang Bumiller
2025-07-29T11:16:17Z

src/PVE/API2/Qemu.pm | 15 +++++++++------
src/PVE/QemuConfig.pm | 2 +-
src/PVE/QemuServer.pm | 18 ++++++++----------
src/PVE/QemuServer/Cloudinit.pm | 2 +-
src/PVE/QemuServer/ImportDisk.pm | 7 +------
src/PVE/QemuServer/OVMF.pm | 3 ++-
src/PVE/VZDump/QemuServer.pm | 8 +++++++-
src/bin/qmextract | 3 ++-
8 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 09d4411b..a3f967f3 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -474,8 +474,9 @@ my sub create_disks : prototype($$$$$$$$$$$) {

# Initial disk created with 4 MB and aligned to 4MB on regeneration
my $ci_size = PVE::QemuServer::Cloudinit::CLOUDINIT_DISK_SIZE;
- my $volid =
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, $name, $ci_size / 1024);
+ my $volid = PVE::Storage::vdisk_alloc(
+ $storecfg, $storeid, $vmid, $fmt, $name, $ci_size / 1024, 'vm-vol',
+ );
$disk->{file} = $volid;
$disk->{media} = 'cdrom';
push @$vollist, $volid;
@@ -631,11 +632,13 @@ my sub create_disks : prototype($$$$$$$$$$$) {
PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE,
'b' => 'kb',
);
- $volid =
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, "raw", undef, $size);
+ $volid = PVE::Storage::vdisk_alloc(
+ $storecfg, $storeid, $vmid, "raw", undef, $size, 'vm-vol',
+ );
} else {
- $volid =
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size);
+ $volid = PVE::Storage::vdisk_alloc(
+ $storecfg, $storeid, $vmid, $fmt, undef, $size, 'vm-vol',
+ );
}

# change created disk to a base volume in case the VM is a template
diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index e0853d65..79a46e45 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -239,7 +239,7 @@ sub __snapshot_save_vmstate {
$name .= ".raw" if $scfg->{path}; # add filename extension for file base storage

my $statefile =
- PVE::Storage::vdisk_alloc($storecfg, $target, $vmid, 'raw', $name, $size * 1024);
+ PVE::Storage::vdisk_alloc($storecfg, $target, $vmid, 'raw', $name, $size * 1024, 'vm-vol');
my $runningmachine = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);

# get current QEMU -cpu argument to ensure consistency of custom CPU models
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 5a4f8120..d004dd55 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -5359,7 +5359,8 @@ sub vm_migrate_alloc_nbd_disks {
$format = PVE::Storage::resolve_format_hint($storecfg, $storeid, $format);

my $size = $drive->{size} / 1024;
- my $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, undef, $size);
+ my $newvolid =
+ PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, undef, $size, 'vm-vol');
my $newdrive = $drive;
$newdrive->{format} = $format;
$newdrive->{file} = $newvolid;
@@ -6482,8 +6483,9 @@ my $restore_allocate_devices = sub {
}
}

- my $volid =
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $d->{format}, $name, $alloc_size);
+ my $volid = PVE::Storage::vdisk_alloc(
+ $storecfg, $storeid, $vmid, $d->{format}, $name, $alloc_size, 'vm-vol',
+ );

print STDERR "new volume ID is '$volid'\n";
$d->{volid} = $volid;
@@ -7763,7 +7765,8 @@ sub clone_disk {
print "($drive->{file})\n";

if (!$full) {
- $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newvmid, $snapname);
+ $newvolid =
+ PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newvmid, $snapname, 'vm-vol');
push @$newvollist, $newvolid;
} else {
my ($src_storeid) = PVE::Storage::parse_volume_id($drive->{file});
@@ -7794,12 +7797,7 @@ sub clone_disk {
$size = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 10);
}
$newvolid = PVE::Storage::vdisk_alloc(
- $storecfg,
- $storeid,
- $newvmid,
- $dst_format,
- $name,
- ($size / 1024),
+ $storecfg, $storeid, $newvmid, $dst_format, $name, ($size / 1024), 'vm-vol',
);
push @$newvollist, $newvolid;

diff --git a/src/PVE/QemuServer/Cloudinit.pm b/src/PVE/QemuServer/Cloudinit.pm
index 349cf90b..9e5fc63e 100644
--- a/src/PVE/QemuServer/Cloudinit.pm
+++ b/src/PVE/QemuServer/Cloudinit.pm
@@ -44,7 +44,7 @@ sub commit_cloudinit_disk {
$volname =~ m/(vm-$vmid-cloudinit(.\Q$format\E)?)/;
my $name = $1;
$size = 4 * 1024;
- PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, $size);
+ PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, $size, 'vm-vol');
$size *= 1024; # vdisk alloc takes KB, qemu-img dd's osize takes byte
}
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
diff --git a/src/PVE/QemuServer/ImportDisk.pm b/src/PVE/QemuServer/ImportDisk.pm
index 75a54aa2..d14537ae 100755
--- a/src/PVE/QemuServer/ImportDisk.pm
+++ b/src/PVE/QemuServer/ImportDisk.pm
@@ -33,12 +33,7 @@ sub do_import {
if $format && $format ne $dst_format;

my $dst_volid = PVE::Storage::vdisk_alloc(
- $storecfg,
- $storage_id,
- $vmid,
- $dst_format,
- undef,
- $src_size / 1024,
+ $storecfg, $storage_id, $vmid, $dst_format, undef, $src_size / 1024, 'vm-vol',
);

my $zeroinit = PVE::Storage::volume_has_feature($storecfg, 'sparseinit', $dst_volid);
diff --git a/src/PVE/QemuServer/OVMF.pm b/src/PVE/QemuServer/OVMF.pm
index 8948651c..9bdeaff7 100644
--- a/src/PVE/QemuServer/OVMF.pm
+++ b/src/PVE/QemuServer/OVMF.pm
@@ -135,7 +135,8 @@ sub create_efidisk($$$$$$$$) {

my $vars_size_b = -s $ovmf_vars;
my $vars_size = PVE::Tools::convert_size($vars_size_b, 'b' => 'kb');
- my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $vars_size);
+ my $volid =
+ PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $vars_size, 'vm-vol');
PVE::Storage::activate_volumes($storecfg, [$volid]);

PVE::QemuServer::QemuImage::convert($ovmf_vars, $volid, $vars_size_b);
diff --git a/src/PVE/VZDump/QemuServer.pm b/src/PVE/VZDump/QemuServer.pm
index 5b94c369..3da54359 100644
--- a/src/PVE/VZDump/QemuServer.pm
+++ b/src/PVE/VZDump/QemuServer.pm
@@ -604,7 +604,13 @@ my sub allocate_fleecing_images {
}

$di->{'fleece-volid'} = PVE::Storage::vdisk_alloc(
- $self->{storecfg}, $fleecing_storeid, $vmid, $format, $name, $size,
+ $self->{storecfg},
+ $fleecing_storeid,
+ $vmid,
+ $format,
+ $name,
+ $size,
+ 'vm-vol',
);

push $fleece_volids->@*, $di->{'fleece-volid'};
diff --git a/src/bin/qmextract b/src/bin/qmextract
index 76538f97..ac9ccc13 100755
--- a/src/bin/qmextract
+++ b/src/bin/qmextract
@@ -173,7 +173,8 @@ sub extract_archive {
if $format ne 'raw';
}

- my $volid = PVE::Storage::vdisk_alloc($cfg, $storeid, $vmid, $format, undef, $alloc_size);
+ my $volid =
+ PVE::Storage::vdisk_alloc($cfg, $storeid, $vmid, $format, undef, $alloc_size, 'vm-vol');

print STDERR "new volume ID is '$volid'\n";