[pve-devel] [RFC qemu-server v2 32/32] command line: switch to blockdev starting with machine version 10.0
Fiona Ebner
f.ebner at proxmox.com
Wed Jun 18 15:02:09 CEST 2025
Co-developed-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
RFC, because this should come together with supporting all operations.
No changes in v2.
src/PVE/QemuServer.pm | 131 ++++++++++++++++++++++++++----------------
1 file changed, 81 insertions(+), 50 deletions(-)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1b8d42a3..b9d18899 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -4104,15 +4104,30 @@ sub config_to_command {
if (min_version($machine_version, 10, 0)) { # for the switch to -blockdev
my $throttle_group = PVE::QemuServer::Blockdev::generate_throttle_group($drive);
push @$cmd, '-object', to_json($throttle_group, { canonical => 1 });
+
+ die "FIXME: blockdev for live restore not yet implemented"
+ if $live_blockdev_name;
+
+ my $extra_blockdev_options = {};
+ # extra protection for templates, but SATA and IDE don't support it..
+ $extra_blockdev_options->{'read-only'} = 1 if drive_is_read_only($conf, $drive);
+
+ if ($drive->{file} ne 'none') {
+ my $blockdev = PVE::QemuServer::Blockdev::generate_drive_blockdev(
+ $storecfg, $drive, $extra_blockdev_options,
+ );
+ push @$devices, '-blockdev', to_json($blockdev, { canonical => 1 });
+ }
+ } else {
+ my $drive_cmd =
+ print_drive_commandline_full($storecfg, $vmid, $drive, $live_blockdev_name);
+
+ # extra protection for templates, but SATA and IDE don't support it..
+ $drive_cmd .= ',readonly=on' if drive_is_read_only($conf, $drive);
+
+ push @$devices, '-drive', $drive_cmd;
}
- my $drive_cmd =
- print_drive_commandline_full($storecfg, $vmid, $drive, $live_blockdev_name);
-
- # extra protection for templates, but SATA and IDE don't support it..
- $drive_cmd .= ',readonly=on' if drive_is_read_only($conf, $drive);
-
- push @$devices, '-drive', $drive_cmd;
push @$devices, '-device',
print_drivedevice_full(
$storecfg, $conf, $vmid, $drive, $bridges, $arch, $machine_type,
@@ -4522,16 +4537,21 @@ sub qemu_driveadd {
if (PVE::QemuServer::Machine::is_machine_version_at_least($machine_type, 10, 0)) {
my $throttle_group = PVE::QemuServer::Blockdev::generate_throttle_group($device);
mon_cmd($vmid, 'object-add', %$throttle_group);
+
+ my $blockdev = PVE::QemuServer::Blockdev::generate_drive_blockdev($storecfg, $device, {});
+ mon_cmd($vmid, 'blockdev-add', %$blockdev, timeout => 60);
+
+ return 1;
+ } else {
+ my $drive = print_drive_commandline_full($storecfg, $vmid, $device, undef);
+ $drive =~ s/\\/\\\\/g;
+ my $ret = PVE::QemuServer::Monitor::hmp_cmd($vmid, "drive_add auto \"$drive\"", 60);
+
+ # If the command succeeds qemu prints: "OK"
+ return 1 if $ret =~ m/OK/s;
+
+ die "adding drive failed: $ret\n";
}
-
- my $drive = print_drive_commandline_full($storecfg, $vmid, $device, undef);
- $drive =~ s/\\/\\\\/g;
- my $ret = PVE::QemuServer::Monitor::hmp_cmd($vmid, "drive_add auto \"$drive\"", 60);
-
- # If the command succeeds qemu prints: "OK"
- return 1 if $ret =~ m/OK/s;
-
- die "adding drive failed: $ret\n";
}
sub qemu_drivedel {
@@ -4541,18 +4561,30 @@ sub qemu_drivedel {
# for the switch to -blockdev
if (PVE::QemuServer::Machine::is_machine_version_at_least($machine_type, 10, 0)) {
+ # QEMU recursively auto-removes the file children, i.e. file and format node below the top
+ # node and also implicit backing children referenced by a qcow2 image.
+ eval {
+ mon_cmd(
+ $vmid, 'blockdev-del',
+ 'node-name' => "drive-$deviceid",
+ timeout => 10 * 60,
+ );
+ };
+ die "deleting blockdev $deviceid failed : $@\n" if $@;
+ # FIXME ignore already removed scenario like below?
+
mon_cmd($vmid, 'object-del', id => "throttle-drive-$deviceid");
+ } else {
+ my $ret = PVE::QemuServer::Monitor::hmp_cmd($vmid, "drive_del drive-$deviceid", 10 * 60);
+ $ret =~ s/^\s+//;
+
+ return 1 if $ret eq "";
+
+ # NB: device not found errors mean the drive was auto-deleted and we ignore the error
+ return 1 if $ret =~ m/Device \'.*?\' not found/s;
+
+ die "deleting drive $deviceid failed : $ret\n";
}
-
- my $ret = PVE::QemuServer::Monitor::hmp_cmd($vmid, "drive_del drive-$deviceid", 10 * 60);
- $ret =~ s/^\s+//;
-
- return 1 if $ret eq "";
-
- # NB: device not found errors mean the drive was auto-deleted and we ignore the error
- return 1 if $ret =~ m/Device \'.*?\' not found/s;
-
- die "deleting drive $deviceid failed : $ret\n";
}
sub qemu_deviceaddverify {
@@ -4838,31 +4870,30 @@ sub qemu_block_set_io_throttle {
'iops-write-max-length' => int($iops_wr_max_length),
},
);
+ } else {
+ mon_cmd(
+ $vmid, "block_set_io_throttle",
+ device => $deviceid,
+ bps => int($bps),
+ bps_rd => int($bps_rd),
+ bps_wr => int($bps_wr),
+ iops => int($iops),
+ iops_rd => int($iops_rd),
+ iops_wr => int($iops_wr),
+ bps_max => int($bps_max),
+ bps_rd_max => int($bps_rd_max),
+ bps_wr_max => int($bps_wr_max),
+ iops_max => int($iops_max),
+ iops_rd_max => int($iops_rd_max),
+ iops_wr_max => int($iops_wr_max),
+ bps_max_length => int($bps_max_length),
+ bps_rd_max_length => int($bps_rd_max_length),
+ bps_wr_max_length => int($bps_wr_max_length),
+ iops_max_length => int($iops_max_length),
+ iops_rd_max_length => int($iops_rd_max_length),
+ iops_wr_max_length => int($iops_wr_max_length),
+ );
}
-
- mon_cmd(
- $vmid, "block_set_io_throttle",
- device => $deviceid,
- bps => int($bps),
- bps_rd => int($bps_rd),
- bps_wr => int($bps_wr),
- iops => int($iops),
- iops_rd => int($iops_rd),
- iops_wr => int($iops_wr),
- bps_max => int($bps_max),
- bps_rd_max => int($bps_rd_max),
- bps_wr_max => int($bps_wr_max),
- iops_max => int($iops_max),
- iops_rd_max => int($iops_rd_max),
- iops_wr_max => int($iops_wr_max),
- bps_max_length => int($bps_max_length),
- bps_rd_max_length => int($bps_rd_max_length),
- bps_wr_max_length => int($bps_wr_max_length),
- iops_max_length => int($iops_max_length),
- iops_rd_max_length => int($iops_rd_max_length),
- iops_wr_max_length => int($iops_wr_max_length),
- );
-
}
sub qemu_block_resize {
--
2.39.5
More information about the pve-devel
mailing list