From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v6 1/2] hotplug: factor out cleanup of disk devices
Date: Wed, 4 Nov 2026 07:48:56 +0100 [thread overview]
Message-ID: <20261104065043.286417-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261104065043.286417-1-d.csapak@proxmox.com>
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 <d.csapak@proxmox.com>
---
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
next prev parent reply other threads:[~2026-11-04 6:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 6:48 [PATCH qemu-server v6 0/2] hotplug: improve and fix cleanup/error handling Dominik Csapak
2026-11-04 6:48 ` Dominik Csapak [this message]
2026-11-04 6:48 ` [PATCH qemu-server v6 2/2] hotplug: clean up disk devices/objects if adding them failed Dominik Csapak
2026-11-05 8:27 ` superseded: [PATCH qemu-server v6 0/2] hotplug: improve and fix cleanup/error handling Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261104065043.286417-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.