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 A25011FF09B for ; Mon, 14 Sep 2026 10:58:08 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 84C0921643; Mon, 14 Sep 2026 10:57:33 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v2 6/6] hotplug: remove iothread if adding drive device failed Date: Mon, 14 Sep 2026 10:54:35 +0200 Message-ID: <20260914085725.1299009-7-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260914085725.1299009-1-d.csapak@proxmox.com> References: <20260914085725.1299009-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.472 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: VBPLHRUBBUNE2AYZ65U6XFIKPK7BZFOS X-Message-ID-Hash: VBPLHRUBBUNE2AYZ65U6XFIKPK7BZFOS 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: Otherwise it is left over after a failed attempt to add a drive with iothreads. This also happens with virtio-scsi-single devices. Modify the relevant test that highlighted this problem. The failure can be tested by disabling hotplug, e.g. for a i440fx guest one can use the following commandline 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 --- src/PVE/QemuServer.pm | 11 ++++++++++- src/test/hotplug/disk-add-fail.conf | 19 +++++++++++++++++++ src/test/hotplug/disk-add-fail.conf.expected | 9 +++++++++ .../hotplug/disk-add-scsi-single-fail.conf | 19 +++++++++++++++++++ .../disk-add-scsi-single-fail.conf.expected | 4 ++++ 5 files changed, 61 insertions(+), 1 deletion(-) 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-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 13318198..62fcc3db 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -3906,6 +3906,8 @@ sub vm_deviceplug { if (my $err = $@) { eval { qemu_drivedel($vmid, $deviceid); }; warn $@ if $@; + eval { qemu_iothread_del($vmid, $deviceid, $device) }; + warn $@ if $@; die $err; } } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) { @@ -3925,7 +3927,14 @@ sub vm_deviceplug { } qemu_deviceadd($vmid, $devicefull); - qemu_deviceaddverify($vmid, $deviceid); + eval { qemu_deviceaddverify($vmid, $deviceid) }; + if (my $err = $@) { + if ($deviceid =~ m/^virtioscsi(\d+)$/ && $device->{iothread}) { + eval { qemu_iothread_del($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); 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..fb9d5de1 --- /dev/null +++ b/src/test/hotplug/disk-add-fail.conf.expected @@ -0,0 +1,9 @@ +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 +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-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..a2864a74 --- /dev/null +++ b/src/test/hotplug/disk-add-scsi-single-fail.conf.expected @@ -0,0 +1,4 @@ +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":"iothread-virtioscsi1"} -- 2.47.3