[pve-devel] [PATCH qemu-server 29/31] command line: switch to blockdev starting with machine version 10.0
Fiona Ebner
f.ebner at proxmox.com
Mon Jun 30 12:57:42 CEST 2025
Am 30.06.25 um 12:15 schrieb Fabian Grünbichler:
> On June 27, 2025 5:57 pm, Fiona Ebner wrote:
>> @@ -4050,28 +4069,63 @@ sub qemu_iothread_del {
>> sub qemu_driveadd {
>> my ($storecfg, $vmid, $device) = @_;
>>
>> - 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);
>> + my $machine_type = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
>>
>> - # If the command succeeds qemu prints: "OK"
>> - return 1 if $ret =~ m/OK/s;
>> + # for the switch to -blockdev
>> + if (PVE::QemuServer::Machine::is_machine_version_at_least($machine_type, 10, 0)) {
>
> isn't this part here basically Blockdev::attach?
>
>> + my $throttle_group = PVE::QemuServer::Blockdev::generate_throttle_group($device);
>> + mon_cmd($vmid, 'object-add', %$throttle_group);
>>
>> - die "adding drive failed: $ret\n";
>> + eval {
>> + my $blockdev =
>> + PVE::QemuServer::Blockdev::generate_drive_blockdev($storecfg, $device, {});
>> + mon_cmd($vmid, 'blockdev-add', %$blockdev);
>> + };
>> + if (my $err = $@) {
>> + my $drive_id = PVE::QemuServer::Drive::get_drive_id($device);
>> + eval { mon_cmd($vmid, 'object-del', id => "throttle-drive-$drive_id"); };
>> + warn $@ if $@;
>> + die $err;
>> + }
>> +
>> + 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";
>> + }
>> }
>>
>> sub qemu_drivedel {
>> my ($vmid, $deviceid) = @_;
>>
>> - my $ret = PVE::QemuServer::Monitor::hmp_cmd($vmid, "drive_del drive-$deviceid", 10 * 60);
>> - $ret =~ s/^\s+//;
>> + my $machine_type = PVE::QemuServer::Machine::get_current_qemu_machine($vmid);
>>
>> - return 1 if $ret eq "";
>> + # for the switch to -blockdev
>> + if (PVE::QemuServer::Machine::is_machine_version_at_least($machine_type, 10, 0)) {
>
> and this here Blockdev::detach?
Yes, sorry! I forgot to switch to using the helpers here.
More information about the pve-devel
mailing list