[pve-devel] [RFC qemu-server 22/22] command line: switch to blockdev starting with machine version 10.0
Fiona Ebner
f.ebner at proxmox.com
Thu Jun 12 16:02:53 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 it should be applied together with properly supporting
all operations.
PVE/QemuServer.pm | 119 ++++++++++++++++++++++++++++------------------
1 file changed, 72 insertions(+), 47 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index bfadba98..40ccafe8 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3948,14 +3948,27 @@ sub config_to_command {
my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
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);
});
@@ -4328,16 +4341,21 @@ sub qemu_driveadd {
my $drive_id = PVE::QemuServer::Drive::get_drive_id($device);
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 {
@@ -4346,18 +4364,26 @@ sub qemu_drivedel {
my $machine_type = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
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
+ 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 {
@@ -4620,29 +4646,28 @@ 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