From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v7 2/2] hotplug: clean up disk devices/objects if adding them failed
Date: Thu, 5 Nov 2026 09:22:15 +0100 [thread overview]
Message-ID: <20261105082524.428152-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261105082524.428152-1-d.csapak@proxmox.com>
Otherwise, parts of a disk are left over after a failed attempt to add
it. For VirtIO block disks this was the iothread. For SCSI disks, the
newly added controller was left over, including its iothread in case
of virtio-scsi-single, and if adding the controller itself failed, its
iothread too.
Use the same cleanup as for unplugging, so that all parts that might
have been added are removed again.
Also verify that a hotplugged SCSI disk actually shows up, like for
VirtIO block disks. Since errors of the HMP device_add command are not
reported, a failure was not noticed and the disk was moved from the
pending section into the config.
For SCSI disks, call print_drivedevice_full before adding any hardware,
which avoids either a leftover controller or an unnecessary controller
plug/unplug cycle if it fails. This can happen, for example, when the
storage vanished after the disk was put in the PENDING section. Add a
test for that, which would fail if we'd put print_drivedevice_full after
qemu_findorcreatescsihw but before the eval.
The failure can be tested by disabling hotplug, e.g. for an i440fx guest
one can use the following command line switches:
-global PIIX4_PM.acpi-root-pci-hotplug=off
-global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=off
-global pci-bridge.shpc=off
to disable hotplug on all PCI bridges and the PCI root bus.
The added regression tests would have failed without the code change.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PVE/QemuServer.pm | 41 ++++++++++++-------
src/test/hotplug/disk-add-fail.conf | 19 +++++++++
src/test/hotplug/disk-add-fail.conf.expected | 10 +++++
src/test/hotplug/disk-add-fail2.conf | 17 ++++++++
src/test/hotplug/disk-add-fail2.conf.expected | 1 +
.../disk-add-scsi-shared-controller-fail.conf | 19 +++++++++
...-scsi-shared-controller-fail.conf.expected | 8 ++++
.../disk-add-scsi-single-disk-fail.conf | 19 +++++++++
...sk-add-scsi-single-disk-fail.conf.expected | 12 ++++++
.../hotplug/disk-add-scsi-single-fail.conf | 19 +++++++++
.../disk-add-scsi-single-fail.conf.expected | 5 +++
11 files changed, 156 insertions(+), 14 deletions(-)
create mode 100644 src/test/hotplug/disk-add-fail.conf
create mode 100644 src/test/hotplug/disk-add-fail.conf.expected
create mode 100644 src/test/hotplug/disk-add-fail2.conf
create mode 100644 src/test/hotplug/disk-add-fail2.conf.expected
create mode 100644 src/test/hotplug/disk-add-scsi-shared-controller-fail.conf
create mode 100644 src/test/hotplug/disk-add-scsi-shared-controller-fail.conf.expected
create mode 100644 src/test/hotplug/disk-add-scsi-single-disk-fail.conf
create mode 100644 src/test/hotplug/disk-add-scsi-single-disk-fail.conf.expected
create mode 100644 src/test/hotplug/disk-add-scsi-single-fail.conf
create mode 100644 src/test/hotplug/disk-add-scsi-single-fail.conf.expected
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 5bed6afa..8045c07e 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3891,16 +3891,18 @@ sub vm_deviceplug {
PVE::QemuServer::USB::print_usbdevice_full($conf, $deviceid, $device, {}, $1 + 1),
);
} elsif ($deviceid =~ m/^(virtio)(\d+)$/) {
- qemu_iothread_add($vmid, $deviceid, $device);
-
- qemu_driveadd($storecfg, $vmid, $device);
my $devicefull =
print_drivedevice_full($storecfg, $conf, $vmid, $device, $arch, $machine_type);
- qemu_deviceadd($vmid, $devicefull);
- eval { qemu_deviceaddverify($vmid, $deviceid); };
+ eval {
+ qemu_iothread_add($vmid, $deviceid, $device);
+ qemu_driveadd($storecfg, $vmid, $device);
+ qemu_deviceadd($vmid, $devicefull);
+ qemu_deviceaddverify($vmid, $deviceid);
+ };
+
if (my $err = $@) {
- eval { qemu_drivedel($vmid, $deviceid); };
+ eval { delete_disk_hardware($conf, $vmid, $deviceid, $device); };
warn $@ if $@;
die $err;
}
@@ -3912,7 +3914,6 @@ sub vm_deviceplug {
my $devicefull = "$scsihw_type,id=$deviceid$pciaddr";
if ($deviceid =~ m/^virtioscsi(\d+)$/ && $device->{iothread}) {
- qemu_iothread_add($vmid, $deviceid, $device);
$devicefull .= ",iothread=iothread-$deviceid";
}
@@ -3920,17 +3921,29 @@ sub vm_deviceplug {
$devicefull .= ",num_queues=$device->{queues}";
}
- qemu_deviceadd($vmid, $devicefull);
- qemu_deviceaddverify($vmid, $deviceid);
+ eval {
+ qemu_iothread_add($vmid, $deviceid, $device) if $deviceid =~ m/^virtioscsi/;
+ qemu_deviceadd($vmid, $devicefull);
+ qemu_deviceaddverify($vmid, $deviceid);
+ };
+ if (my $err = $@) {
+ eval { delete_disk_hardware($conf, $vmid, $deviceid, $device); };
+ warn $@ if $@;
+ die $err;
+ }
} elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
- qemu_findorcreatescsihw($storecfg, $conf, $vmid, $device, $arch, $machine_type);
- qemu_driveadd($storecfg, $vmid, $device);
-
my $devicefull =
print_drivedevice_full($storecfg, $conf, $vmid, $device, $arch, $machine_type);
- eval { qemu_deviceadd($vmid, $devicefull); };
+
+ qemu_findorcreatescsihw($storecfg, $conf, $vmid, $device, $arch, $machine_type);
+
+ eval {
+ qemu_driveadd($storecfg, $vmid, $device);
+ qemu_deviceadd($vmid, $devicefull);
+ qemu_deviceaddverify($vmid, $deviceid);
+ };
if (my $err = $@) {
- eval { qemu_drivedel($vmid, $deviceid); };
+ eval { delete_disk_hardware($conf, $vmid, $deviceid, $device); };
warn $@ if $@;
die $err;
}
diff --git a/src/test/hotplug/disk-add-fail.conf b/src/test/hotplug/disk-add-fail.conf
new file mode 100644
index 00000000..800b113e
--- /dev/null
+++ b/src/test/hotplug/disk-add-fail.conf
@@ -0,0 +1,19 @@
+# TEST: a disk that does not show up after hotplug is detached again
+# FAIL_DEVICE_ADD: virtio1
+# EXPECTED_ERROR: virtio1: hotplug problem - error on hotplug device 'virtio1'
+# STAYS_PENDING: 1
+bootdisk: scsi0
+cores: 2
+machine: pc-i440fx-10.1
+memory: 2048
+name: hotplug
+net0: virtio=A2:C0:43:77:08:A0,bridge=vmbr0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.qcow2,size=32G
+scsihw: virtio-scsi-pci
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+sockets: 1
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
+
+[PENDING]
+virtio1: local:8006/vm-8006-disk-1.qcow2,iothread=1,size=32G
diff --git a/src/test/hotplug/disk-add-fail.conf.expected b/src/test/hotplug/disk-add-fail.conf.expected
new file mode 100644
index 00000000..30946720
--- /dev/null
+++ b/src/test/hotplug/disk-add-fail.conf.expected
@@ -0,0 +1,10 @@
+storage activate_volumes ["local:8006/vm-8006-disk-1.qcow2"]
+qmp object-add {"id":"iothread-virtio1","qom-type":"iothread"}
+qmp object-del {"id":"throttle-drive-virtio1"}
+qmp object-add {"id":"throttle-drive-virtio1","limits":{},"qom-type":"throttle-group"}
+qmp blockdev-add {"detect-zeroes":"on","discard":"ignore","driver":"throttle","file":{"cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"qcow2","file":{"aio":"io_uring","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vz/images/8006/vm-8006-disk-1.qcow2","node-name":"ef4c217a7f08cf59741edc1790023f5","read-only":false},"node-name":"ff4c217a7f08cf59741edc1790023f5","read-only":false},"node-name":"drive-virtio1","read-only":false,"throttle-group":"throttle-drive-virtio1"}
+hmp device_add driver=virtio-blk-pci,drive=drive-virtio1,id=virtio1,bus=pci.0,addr=0xb,iothread=iothread-virtio1,write-cache=on
+hmp device_del virtio1
+qmp blockdev-del {"node-name":"drive-virtio1"}
+qmp object-del {"id":"throttle-drive-virtio1"}
+qmp object-del {"id":"iothread-virtio1"}
diff --git a/src/test/hotplug/disk-add-fail2.conf b/src/test/hotplug/disk-add-fail2.conf
new file mode 100644
index 00000000..bfa33eac
--- /dev/null
+++ b/src/test/hotplug/disk-add-fail2.conf
@@ -0,0 +1,17 @@
+# TEST: a disk where the storage vanishes after being put in PENDING
+# EXPECTED_ERROR: scsi7: hotplug problem - storage 'non-existing' does not exist
+# STAYS_PENDING: 1
+bootdisk: scsi0
+cores: 2
+machine: pc-i440fx-10.1
+memory: 2048
+name: hotplug
+net0: virtio=A2:C0:43:77:08:A0,bridge=vmbr0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.qcow2,size=32G
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+sockets: 1
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
+
+[PENDING]
+scsi7: non-existing:8006/vm-8006-disk-1.qcow2,iothread=1,size=32G
diff --git a/src/test/hotplug/disk-add-fail2.conf.expected b/src/test/hotplug/disk-add-fail2.conf.expected
new file mode 100644
index 00000000..49b6ac67
--- /dev/null
+++ b/src/test/hotplug/disk-add-fail2.conf.expected
@@ -0,0 +1 @@
+storage activate_volumes ["non-existing:8006/vm-8006-disk-1.qcow2"]
diff --git a/src/test/hotplug/disk-add-scsi-shared-controller-fail.conf b/src/test/hotplug/disk-add-scsi-shared-controller-fail.conf
new file mode 100644
index 00000000..5e148309
--- /dev/null
+++ b/src/test/hotplug/disk-add-scsi-shared-controller-fail.conf
@@ -0,0 +1,19 @@
+# TEST: a disk on a shared SCSI controller that does not show up after hotplug is detached again, but the controller is kept for the other disks
+# FAIL_DEVICE_ADD: scsi1
+# EXPECTED_ERROR: scsi1: hotplug problem - error on hotplug device 'scsi1'
+# STAYS_PENDING: 1
+bootdisk: scsi0
+cores: 2
+machine: pc-i440fx-10.1
+memory: 2048
+name: hotplug
+net0: virtio=A2:C0:43:77:08:A0,bridge=vmbr0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.qcow2,size=32G
+scsihw: virtio-scsi-pci
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+sockets: 1
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
+
+[PENDING]
+scsi1: local:8006/vm-8006-disk-1.qcow2,size=32G
diff --git a/src/test/hotplug/disk-add-scsi-shared-controller-fail.conf.expected b/src/test/hotplug/disk-add-scsi-shared-controller-fail.conf.expected
new file mode 100644
index 00000000..84f38e83
--- /dev/null
+++ b/src/test/hotplug/disk-add-scsi-shared-controller-fail.conf.expected
@@ -0,0 +1,8 @@
+storage activate_volumes ["local:8006/vm-8006-disk-1.qcow2"]
+qmp object-del {"id":"throttle-drive-scsi1"}
+qmp object-add {"id":"throttle-drive-scsi1","limits":{},"qom-type":"throttle-group"}
+qmp blockdev-add {"detect-zeroes":"on","discard":"ignore","driver":"throttle","file":{"cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"qcow2","file":{"aio":"io_uring","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vz/images/8006/vm-8006-disk-1.qcow2","node-name":"e70a10e5fb0473d3fc55686f720db61","read-only":false},"node-name":"f70a10e5fb0473d3fc55686f720db61","read-only":false},"node-name":"drive-scsi1","read-only":false,"throttle-group":"throttle-drive-scsi1"}
+hmp device_add driver=scsi-hd,bus=scsihw0.0,channel=0,scsi-id=0,lun=1,drive=drive-scsi1,id=scsi1,device_id=drive-scsi1,write-cache=on
+hmp device_del scsi1
+qmp blockdev-del {"node-name":"drive-scsi1"}
+qmp object-del {"id":"throttle-drive-scsi1"}
diff --git a/src/test/hotplug/disk-add-scsi-single-disk-fail.conf b/src/test/hotplug/disk-add-scsi-single-disk-fail.conf
new file mode 100644
index 00000000..f493f589
--- /dev/null
+++ b/src/test/hotplug/disk-add-scsi-single-disk-fail.conf
@@ -0,0 +1,19 @@
+# TEST: a disk on virtio-scsi-single that does not show up after hotplug has its controller and iothread removed again
+# FAIL_DEVICE_ADD: scsi1
+# EXPECTED_ERROR: scsi1: hotplug problem - error on hotplug device 'scsi1'
+# STAYS_PENDING: 1
+bootdisk: scsi0
+cores: 2
+machine: pc-i440fx-10.1
+memory: 2048
+name: hotplug
+net0: virtio=A2:C0:43:77:08:A0,bridge=vmbr0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.qcow2,iothread=1,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+sockets: 1
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
+
+[PENDING]
+scsi1: local:8006/vm-8006-disk-1.qcow2,iothread=1,size=32G
diff --git a/src/test/hotplug/disk-add-scsi-single-disk-fail.conf.expected b/src/test/hotplug/disk-add-scsi-single-disk-fail.conf.expected
new file mode 100644
index 00000000..a5da2480
--- /dev/null
+++ b/src/test/hotplug/disk-add-scsi-single-disk-fail.conf.expected
@@ -0,0 +1,12 @@
+storage activate_volumes ["local:8006/vm-8006-disk-1.qcow2"]
+qmp object-add {"id":"iothread-virtioscsi1","qom-type":"iothread"}
+hmp device_add driver=virtio-scsi-pci,id=virtioscsi1,bus=pci.3,addr=0x2,iothread=iothread-virtioscsi1
+qmp object-del {"id":"throttle-drive-scsi1"}
+qmp object-add {"id":"throttle-drive-scsi1","limits":{},"qom-type":"throttle-group"}
+qmp blockdev-add {"detect-zeroes":"on","discard":"ignore","driver":"throttle","file":{"cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"qcow2","file":{"aio":"io_uring","cache":{"direct":true,"no-flush":false},"detect-zeroes":"on","discard":"ignore","driver":"file","filename":"/var/lib/vz/images/8006/vm-8006-disk-1.qcow2","node-name":"e70a10e5fb0473d3fc55686f720db61","read-only":false},"node-name":"f70a10e5fb0473d3fc55686f720db61","read-only":false},"node-name":"drive-scsi1","read-only":false,"throttle-group":"throttle-drive-scsi1"}
+hmp device_add driver=scsi-hd,bus=virtioscsi1.0,channel=0,scsi-id=0,lun=1,drive=drive-scsi1,id=scsi1,device_id=drive-scsi1,write-cache=on
+hmp device_del scsi1
+qmp blockdev-del {"node-name":"drive-scsi1"}
+qmp object-del {"id":"throttle-drive-scsi1"}
+hmp device_del virtioscsi1
+qmp object-del {"id":"iothread-virtioscsi1"}
diff --git a/src/test/hotplug/disk-add-scsi-single-fail.conf b/src/test/hotplug/disk-add-scsi-single-fail.conf
new file mode 100644
index 00000000..d9a9a30f
--- /dev/null
+++ b/src/test/hotplug/disk-add-scsi-single-fail.conf
@@ -0,0 +1,19 @@
+# TEST: a virtio-scsi-single controller that does not show up after hotplug has its iothread removed again
+# FAIL_DEVICE_ADD: virtioscsi1
+# EXPECTED_ERROR: scsi1: hotplug problem - error on hotplug device 'virtioscsi1'
+# STAYS_PENDING: 1
+bootdisk: scsi0
+cores: 2
+machine: pc-i440fx-10.1
+memory: 2048
+name: hotplug
+net0: virtio=A2:C0:43:77:08:A0,bridge=vmbr0
+ostype: l26
+scsi0: local:8006/vm-8006-disk-0.qcow2,iothread=1,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+sockets: 1
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
+
+[PENDING]
+scsi1: local:8006/vm-8006-disk-1.qcow2,iothread=1,size=32G
diff --git a/src/test/hotplug/disk-add-scsi-single-fail.conf.expected b/src/test/hotplug/disk-add-scsi-single-fail.conf.expected
new file mode 100644
index 00000000..fc291ec6
--- /dev/null
+++ b/src/test/hotplug/disk-add-scsi-single-fail.conf.expected
@@ -0,0 +1,5 @@
+storage activate_volumes ["local:8006/vm-8006-disk-1.qcow2"]
+qmp object-add {"id":"iothread-virtioscsi1","qom-type":"iothread"}
+hmp device_add driver=virtio-scsi-pci,id=virtioscsi1,bus=pci.3,addr=0x2,iothread=iothread-virtioscsi1
+hmp device_del virtioscsi1
+qmp object-del {"id":"iothread-virtioscsi1"}
--
2.47.3
prev parent reply other threads:[~2026-11-05 8:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 8:22 [PATCH qemu-server v7 0/2] hotplug: improve and fix cleanup/error handling Dominik Csapak
2026-11-05 8:22 ` [PATCH qemu-server v7 1/2] hotplug: factor out cleanup of disk devices Dominik Csapak
2026-11-05 8:22 ` Dominik Csapak [this message]
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=20261105082524.428152-3-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.