From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id A271B1FF0DF for ; Thu, 05 Nov 2026 09:25:30 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D4AC32145B; Thu, 05 Nov 2026 09:25:27 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v7 1/2] hotplug: factor out cleanup of disk devices Date: Thu, 5 Nov 2026 09:22:14 +0100 Message-ID: <20261105082524.428152-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261105082524.428152-1-d.csapak@proxmox.com> References: <20261105082524.428152-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.323 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: X5GOIMQPLLEYWXHLRORH42NUE5ZR3LEW X-Message-ID-Hash: X5GOIMQPLLEYWXHLRORH42NUE5ZR3LEW X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Unplugging a disk or SCSI controller removes the same parts that need to be removed when hotplugging one of them failed. Factor this out into a helper, so it can be reused for cleaning up after a failed hotplug in a following commit. Pass the parsed drive to qemu_deletescsihw instead of parsing it from the config again, since a disk that failed to hotplug is still pending and not in the config yet. No functional change intended. Signed-off-by: Dominik Csapak --- src/PVE/QemuServer.pm | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 69a2bd64..5bed6afa 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -3854,6 +3854,20 @@ sub vm_devices_list { return $devices; } +# clean up disks and their controllers (if unused afterwards) +sub delete_disk_hardware { + my ($conf, $vmid, $deviceid, $device, $timeout) = @_; + + qemu_devicedel($vmid, $deviceid); + qemu_devicedelverify($vmid, $deviceid, $timeout); + qemu_drivedel($vmid, $deviceid) if $deviceid =~ m/^(virtio|scsi)\d+$/; + # the iothread of a virtio-scsi-single disk belongs to its controller and is removed there + qemu_deletescsihw($conf, $vmid, $device) if $deviceid =~ m/^scsi\d+$/; + qemu_iothread_del($vmid, $deviceid) if $deviceid =~ m/^virtio(scsi)?\d+$/; + + return; +} + sub vm_deviceplug { my ($storecfg, $conf, $vmid, $deviceid, $device, $arch, $machine_type) = @_; @@ -3972,20 +3986,12 @@ sub vm_deviceunplug { qemu_devicedel($vmid, $deviceid); qemu_devicedelverify($vmid, $deviceid); } elsif ($deviceid =~ m/^(virtio)(\d+)$/) { - qemu_devicedel($vmid, $deviceid); - qemu_devicedelverify($vmid, $deviceid); - qemu_drivedel($vmid, $deviceid); - qemu_iothread_del($vmid, $deviceid); + delete_disk_hardware($conf, $vmid, $deviceid); } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) { - qemu_devicedel($vmid, $deviceid); - qemu_devicedelverify($vmid, $deviceid, 15); - qemu_iothread_del($vmid, $deviceid) if $deviceid =~ m/^virtioscsi\d+$/; + delete_disk_hardware($conf, $vmid, $deviceid, undef, 15); } elsif ($deviceid =~ m/^(scsi)(\d+)$/) { - qemu_devicedel($vmid, $deviceid); - qemu_devicedelverify($vmid, $deviceid); - qemu_drivedel($vmid, $deviceid); - # the iothread of a virtio-scsi-single disk belongs to its controller and is removed there - qemu_deletescsihw($conf, $vmid, $deviceid); + my $device = parse_drive($deviceid, $conf->{$deviceid}); + delete_disk_hardware($conf, $vmid, $deviceid, $device); } elsif ($deviceid =~ m/^(net)(\d+)$/) { qemu_devicedel($vmid, $deviceid); qemu_devicedelverify($vmid, $deviceid); @@ -4124,9 +4130,7 @@ sub qemu_findorcreatescsihw { } sub qemu_deletescsihw { - my ($conf, $vmid, $opt) = @_; - - my $device = parse_drive($opt, $conf->{$opt}); + my ($conf, $vmid, $device) = @_; if ($conf->{scsihw} && ($conf->{scsihw} eq 'virtio-scsi-single')) { vm_deviceunplug($vmid, $conf, "virtioscsi$device->{index}"); -- 2.47.3