[PATCH v3 qemu-server 05/11] blockdev: convert cdrom media eject/insert

Alexandre Derumier alexandre.derumier at groupe-cyllene.com
Mon Dec 16 10:12:23 CET 2024


Signed-off-by: Alexandre Derumier <alexandre.derumier at groupe-cyllene.com>
---
 PVE/QemuServer.pm | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 3b33fd7d..758c8240 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5694,7 +5694,10 @@ sub vmconfig_update_disk {
 	} else { # cdrom
 
 	    if ($drive->{file} eq 'none') {
-		mon_cmd($vmid, "eject", force => JSON::true, id => "$opt");
+		mon_cmd($vmid, "blockdev-open-tray", force => JSON::true, id => $opt);
+		mon_cmd($vmid, "blockdev-remove-medium", id => $opt);
+		qemu_drivedel($vmid, $opt);
+
 		if (drive_is_cloudinit($old_drive)) {
 		    vmconfig_register_unused_drive($storecfg, $vmid, $conf, $old_drive);
 		}
@@ -5702,14 +5705,16 @@ sub vmconfig_update_disk {
 		my $path = get_iso_path($storecfg, $vmid, $drive->{file});
 
 		# force eject if locked
-		mon_cmd($vmid, "eject", force => JSON::true, id => "$opt");
+		mon_cmd($vmid, "blockdev-open-tray", force => JSON::true, id => $opt);
+		mon_cmd($vmid, "blockdev-remove-medium", id => $opt);
+		eval { qemu_drivedel($vmid, $opt) };
 
 		if ($path) {
-		    mon_cmd($vmid, "blockdev-change-medium",
-			id => "$opt", filename => "$path");
+		    qemu_driveadd($storecfg, $vmid, $drive);
+		    mon_cmd($vmid, "blockdev-insert-medium", id => $opt, 'node-name' => "drive-$opt");
+		    mon_cmd($vmid, "blockdev-close-tray", id => $opt);
 		}
 	    }
-
 	    return 1;
 	}
     }
-- 
2.39.5




More information about the pve-devel mailing list