From b8e77deeeff011b5ca9ef891d4335ff72d7986f6 Mon Sep 17 00:00:00 2001
From: Jeffrey Zhang <zhang.lei.fly@gmail.com>
Date: Wed, 23 Dec 2020 13:42:16 +0800
Subject: [PATCH] Configure Nova libvirt.num_pcie_ports to 16 by default

When using the 'q35' machine type, by default, it allows only
a single PCIe device to be hotplugged. Nova currently sets
'num_pcie_ports' to "0" (defaults to libvirt's "1"), which is
not sufficient for hotplug use.

The max value is 28, but 16 is enough in most cases.

More info please check

* [0] https://libvirt.org/pci-hotplug.html
* [1] https://marcin.juszkiewicz.com.pl/2018/02/19/hotplug-in-vm-easy-to-say/
* [2] https://review.opendev.org/c/openstack/nova/+/545034

Co-Authored-By: Bartosz Bezak <bartosz@stackhpc.com>

Change-Id: I7b8063566837aeb947927b7d6858417982b63deb
Closes-Bug: 1909063
---
 .../nova-cell/templates/nova.conf.d/libvirt.conf.j2    |  1 +
 .../fix-q35-pcie-hotplug-libvirt-50b1879d61b1df72.yaml | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 releasenotes/notes/fix-q35-pcie-hotplug-libvirt-50b1879d61b1df72.yaml

diff --git a/ansible/roles/nova-cell/templates/nova.conf.d/libvirt.conf.j2 b/ansible/roles/nova-cell/templates/nova.conf.d/libvirt.conf.j2
index 3f599c051a..2a81411319 100644
--- a/ansible/roles/nova-cell/templates/nova.conf.d/libvirt.conf.j2
+++ b/ansible/roles/nova-cell/templates/nova.conf.d/libvirt.conf.j2
@@ -27,5 +27,6 @@ cpu_mode = {{ nova_libvirt_cpu_mode }}
 {% if enable_multipathd | bool %}
 volume_use_multipath = True
 {% endif %}
+num_pcie_ports = 16
 [workarounds]
 skip_cpu_compare_on_dest = True
diff --git a/releasenotes/notes/fix-q35-pcie-hotplug-libvirt-50b1879d61b1df72.yaml b/releasenotes/notes/fix-q35-pcie-hotplug-libvirt-50b1879d61b1df72.yaml
new file mode 100644
index 0000000000..380a4404b6
--- /dev/null
+++ b/releasenotes/notes/fix-q35-pcie-hotplug-libvirt-50b1879d61b1df72.yaml
@@ -0,0 +1,10 @@
+---
+upgrade:
+  - |
+    Configure Nova libvirt.num_pcie_ports to 16 by default. Nova currently
+    sets 'num_pcie_ports' to "0" (defaults to libvirt's "1"), which is
+    not sufficient for hotplug use with 'q35' machine type.
+fixes:
+  - |
+    Fixes an issue where 'q35' libvirt machine type VM could not hotplug
+    more than one PCIe device at a time.