From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 720F81FF183 for ; Wed, 18 Jun 2025 15:08:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8486513327; Wed, 18 Jun 2025 15:09:05 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Wed, 18 Jun 2025 15:02:09 +0200 Message-Id: <20250618130209.90649-33-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250618130209.90649-1-f.ebner@proxmox.com> References: <20250618130209.90649-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm] Subject: [pve-devel] [RFC qemu-server v2 32/32] command line: switch to blockdev starting with machine version 10.0 X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Co-developed-by: Alexandre Derumier Signed-off-by: Fiona Ebner --- 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel