From cdf819f820b6637490d39c3c4056c7b1ad444b6e Mon Sep 17 00:00:00 2001 From: Tobias Stein Date: Mon, 28 Apr 2025 21:07:52 +0200 Subject: [PATCH] Fix adding pci_bridges to qemu vms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Offset pci_device_id for network devices by 32 (formerly 4) to reserve first 32 IDs for non-netdev devices * This implies a new pci_bridge for the netdevs and the pci_device_ids starting at 0 (using modulo) * Fixes a bug in the creation of the qemu command when the number of qemu pcie devices (storage_controller, disks, …) was greater than 4 and the number of network devices saturated the 32 pcie ids of the root bridge causing qemu not to start. --- gns3server/compute/qemu/qemu_vm.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index af982841..a2c51935 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -2445,7 +2445,12 @@ class QemuVM(BaseNode): ) # we do not want any user networking back-end if no adapter is connected. # Each 32 PCI device we need to add a PCI bridge with max 9 bridges - pci_devices = 4 + len(self._ethernet_adapters) # 4 PCI devices are use by default by qemu + # Reserve 32 devices on root pci_bridge, + # since the number of devices used by templates may differ significantly + # and pci_bridges also consume IDs. + # Move network devices to their own bridge + pci_devices_reserved = 32 + pci_devices = pci_devices_reserved + len(self._ethernet_adapters) pci_bridges = math.floor(pci_devices / 32) pci_bridges_created = 0 if pci_bridges >= 1: @@ -2454,7 +2459,7 @@ class QemuVM(BaseNode): "Qemu version 2.4 or later is required to run this VM with a large number of network adapters" ) - pci_device_id = 4 + pci_bridges # Bridge consume PCI ports + pci_device_id = pci_devices_reserved for adapter_number, adapter in enumerate(self._ethernet_adapters): mac = int_to_macaddress(macaddress_to_int(self._mac_address) + adapter_number)