Currently, the bhyve driver hardcodes PCI function 0
for several controllers, specifically: ahci, virtio-blk,
virtio-scsi, and nvme. There is no specific reason for that,
so use the configured PCI function instead.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
 src/bhyve/bhyve_command.c                     | 12 +++--
 .../x86_64/bhyvexml2argv-disk-pci-addr.args   | 12 +++++
 .../x86_64/bhyvexml2argv-disk-pci-addr.ldargs |  4 ++
 .../x86_64/bhyvexml2argv-disk-pci-addr.xml    | 40 +++++++++++++++
 tests/bhyvexml2argvtest.c                     |  1 +
 .../x86_64/bhyvexml2xmlout-disk-pci-addr.xml  | 50 +++++++++++++++++++
 tests/bhyvexml2xmltest.c                      |  1 +
 7 files changed, 116 insertions(+), 4 deletions(-)
 create mode 100644 
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.args
 create mode 100644 
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.ldargs
 create mode 100644 
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.xml
 create mode 100644 
tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-disk-pci-addr.xml

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index f5ee2b041f..be66d26c50 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -394,8 +394,9 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
     }
 
     virCommandAddArg(cmd, "-s");
-    virCommandAddArgFormat(cmd, "%d:0,ahci%s",
+    virCommandAddArgFormat(cmd, "%d:%d,ahci%s",
                            controller->info.addr.pci.slot,
+                           controller->info.addr.pci.function,
                            virBufferCurrentContent(&buf));
 
     return 0;
@@ -447,8 +448,9 @@ bhyveBuildSCSIControllerArgStr(const virDomainDef *def,
         }
 
         virCommandAddArg(cmd, "-s");
-        virCommandAddArgFormat(cmd, "%d:0,virtio-scsi,%s",
+        virCommandAddArgFormat(cmd, "%d:%d,virtio-scsi,%s",
                                controller->info.addr.pci.slot,
+                               controller->info.addr.pci.function,
                                virDomainDiskGetSource(disk));
 
         return 0;
@@ -544,8 +546,9 @@ bhyveBuildNVMeControllerArgStr(const virDomainDef *def,
         nvme_opts = virBufferContentAndReset(&opt);
 
         virCommandAddArg(cmd, "-s");
-        virCommandAddArgFormat(cmd, "%d:0,nvme,%s%s",
+        virCommandAddArgFormat(cmd, "%d:%d,nvme,%s%s",
                                controller->info.addr.pci.slot,
+                               controller->info.addr.pci.function,
                                disk_source,
                                NULLSTR_EMPTY(nvme_opts));
 
@@ -623,8 +626,9 @@ bhyveBuildVirtIODiskArgStr(const virDomainDef *def 
G_GNUC_UNUSED,
     bhyveBuildCommonDiskOpts(disk, &opts);
 
     virCommandAddArg(cmd, "-s");
-    virCommandAddArgFormat(cmd, "%d:0,virtio-blk,%s%s",
+    virCommandAddArgFormat(cmd, "%d:%d,virtio-blk,%s%s",
                            disk->info.addr.pci.slot,
+                           disk->info.addr.pci.function,
                            disk_source,
                            virBufferCurrentContent(&opts));
 
diff --git a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.args 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.args
new file mode 100644
index 0000000000..8d171d5c2a
--- /dev/null
+++ b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.args
@@ -0,0 +1,12 @@
+bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:1,ahci,hd:/tmp/sata.img \
+-s 3:2,virtio-scsi,/dev/cam/ctl \
+-s 4:3,nvme,/tmp/nvme.img \
+-s 5:4,virtio-blk,/tmp/virtio.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.ldargs 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.ldargs
new file mode 100644
index 0000000000..efd5638b23
--- /dev/null
+++ b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.ldargs
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/sata.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.xml 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.xml
new file mode 100644
index 0000000000..48f45ff1dd
--- /dev/null
+++ b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-disk-pci-addr.xml
@@ -0,0 +1,40 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <controller type='sata' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' 
function='0x1'/>
+    </controller>
+    <controller type='scsi' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' 
function='0x2'/>
+    </controller>
+    <controller type='nvme' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' 
function='0x3'/>
+    </controller>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/sata.img'/>
+      <target dev='hda' bus='sata'/>
+    </disk>
+    <disk type='ctl'>
+      <source dev='/dev/cam/ctl'/>
+      <target dev='sda' bus='scsi'/>
+    </disk>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/nvme.img'/>
+      <target dev='nvme0n1' bus='nvme'/>
+    </disk>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/virtio.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' 
function='0x4'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index c86929b308..f5df8a0265 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -240,6 +240,7 @@ mymain(void)
     DO_TEST("disk-block");
     DO_TEST("disk-cdrom");
     DO_TEST("disk-virtio");
+    DO_TEST("disk-pci-addr");
     DO_TEST("disk-readonly");
     DO_TEST("disk-options");
     DO_TEST_FAILURE("disk-blockio-invalid");
diff --git a/tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-disk-pci-addr.xml 
b/tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-disk-pci-addr.xml
new file mode 100644
index 0000000000..67a78a51e3
--- /dev/null
+++ b/tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-disk-pci-addr.xml
@@ -0,0 +1,50 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/sata.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <disk type='ctl' device='disk'>
+      <source dev='/dev/cam/ctl'/>
+      <target dev='sda' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/nvme.img'/>
+      <target dev='nvme0n1' bus='nvme'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/virtio.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' 
function='0x4'/>
+    </disk>
+    <controller type='sata' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' 
function='0x1'/>
+    </controller>
+    <controller type='scsi' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' 
function='0x2'/>
+    </controller>
+    <controller type='nvme' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' 
function='0x3'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c
index 208d87b280..03cdb5dd92 100644
--- a/tests/bhyvexml2xmltest.c
+++ b/tests/bhyvexml2xmltest.c
@@ -112,6 +112,7 @@ mymain(void)
     DO_TEST_DIFFERENT("console-master-slave-not-specified");
     DO_TEST_DIFFERENT("custom-loader");
     DO_TEST_DIFFERENT("disk-block");
+    DO_TEST_DIFFERENT("disk-pci-addr");
     DO_TEST_DIFFERENT("disk-cdrom");
     DO_TEST_DIFFERENT("disk-cdrom-grub");
     DO_TEST_DIFFERENT("disk-virtio");
-- 
2.55.0

Reply via email to