public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v3 4/8] code cleanup: hot-plug: simplify getting bridge for device
Date: Tue,  8 Sep 2026 15:52:04 +0200	[thread overview]
Message-ID: <20260908135729.3869365-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260908135729.3869365-1-d.csapak@proxmox.com>

Instead of routing through `print_pci_addr` and checking which bridges
are needed, simply expose a new function that does exactly return which
`bus` (which translates to a bridge) is used for the device.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PVE/QemuServer.pm     | 10 +---------
 src/PVE/QemuServer/PCI.pm | 11 +++++++++++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 8c8d3df8..ce3eea4d 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -4218,15 +4218,7 @@ sub qemu_deletescsihw {
 sub qemu_add_pci_bridge {
     my ($storecfg, $conf, $vmid, $device, $arch, $machine_type) = @_;
 
-    my $bridges = {};
-
-    my $bridgeid;
-
-    print_pci_addr($device, $bridges, $arch);
-
-    while (my ($k, $v) = each %$bridges) {
-        $bridgeid = $k;
-    }
+    my $bridgeid = PVE::QemuServer::PCI::get_pci_bridge_for_device($device);
     return 1 if !defined($bridgeid) || $bridgeid < 1;
 
     my $bridge = "pci.$bridgeid";
diff --git a/src/PVE/QemuServer/PCI.pm b/src/PVE/QemuServer/PCI.pm
index bae46cb7..8069f104 100644
--- a/src/PVE/QemuServer/PCI.pm
+++ b/src/PVE/QemuServer/PCI.pm
@@ -291,6 +291,17 @@ my $get_addr_mapping_from_id = sub {
     return { bus => $d->{bus}, addr => sprintf("0x%x", $d->{addr}) };
 };
 
+sub get_pci_bridge_for_device {
+    my ($id) = @_;
+
+    my $map = get_pci_addr_map();
+    if (my $d = $get_addr_mapping_from_id->($map, $id)) {
+        return $d->{bus};
+    }
+
+    return;
+}
+
 sub print_pci_addr {
     my ($id, $bridges, $arch) = @_;
 
-- 
2.47.3





  parent reply	other threads:[~2026-09-08 13:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 13:52 [PATCH qemu-server v3 0/8] pci: bridges: cleanup and hotplug fix Dominik Csapak
2026-09-08 13:52 ` [PATCH qemu-server v3 1/8] tests: cfg2cmd: add test for ivshmem with q35 Dominik Csapak
2026-09-08 13:52 ` [PATCH qemu-server v3 2/8] tests: cfg2cmd: add q35 + win7 + hostpci test Dominik Csapak
2026-09-08 13:52 ` [PATCH qemu-server v3 3/8] code cleanup: pci: don't export print_pcie_root_port Dominik Csapak
2026-09-08 13:52 ` Dominik Csapak [this message]
2026-09-08 13:52 ` [PATCH qemu-server v3 5/8] hotplug: don't try to hotplug bridges Dominik Csapak
2026-09-08 13:52 ` [PATCH qemu-server v3 6/8] cfg2cmd: reject guests with machine version below 5.0 Dominik Csapak
2026-09-08 13:52 ` [PATCH qemu-server v3 7/8] cfg2cmd: pci: add bridges to device list up front Dominik Csapak
2026-09-08 13:52 ` [PATCH qemu-server v3 8/8] cfg2cmd: pci: add pci.4 by default starting with machine version 11.1 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=20260908135729.3869365-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal