From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id E23891FF170
	for <inbox@lore.proxmox.com>; Thu, 12 Jun 2025 16:04:28 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id CF5BC1F587;
	Thu, 12 Jun 2025 16:03:12 +0200 (CEST)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 12 Jun 2025 16:02:53 +0200
Message-Id: <20250612140253.106555-23-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250612140253.106555-1-f.ebner@proxmox.com>
References: <20250612140253.106555-1-f.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.082 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
 PROLO_LEO1                0.1 Meta Catches all Leo drug variations so far
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [RFC qemu-server 22/22] 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 <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Co-developed-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
Signed-off-by: Fiona Ebner <f.ebner@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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel