]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: fix virtio disk addresses
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 1 Feb 2017 16:19:31 +0000 (20:19 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 7 Feb 2017 15:17:58 +0000 (19:17 +0400)
Like it usually happens, I fixed one thing and broke another:
in 803966c76 address allocation was fixed for SATA disks, but
broke that for virtio disks, because it dropped disk address
assignment completely. It's not needed for SATA disks anymore,
but still needed for the virtio ones.

Bring that back and add a couple of tests to make sure it won't
happen again.

src/bhyve/bhyve_device.c
tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.xml [new file with mode: 0644]
tests/bhyvexml2argvtest.c
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-addr-multiple-virtio-disks.xml [new file with mode: 0644]
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-addr-single-virtio-disk.xml [new file with mode: 0644]
tests/bhyvexml2xmltest.c

index 29528230fd9e495f2f6078eb50ac689a70261085..55ce631ec464d04e08472f223db5843c15f6a8a7 100644 (file)
@@ -129,6 +129,22 @@ bhyveAssignDevicePCISlots(virDomainDefPtr def,
             goto error;
     }
 
+    for (i = 0; i < def->ndisks; i++) {
+        /* We only handle virtio disk addresses as SATA disks are
+         * attached to a controller and don't have their own PCI
+         * addresses */
+        if (def->disks[i]->bus != VIR_DOMAIN_DISK_BUS_VIRTIO)
+            continue;
+
+        if (def->disks[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
+            !virPCIDeviceAddressIsEmpty(&def->disks[i]->info.addr.pci))
+            continue;
+        if (virDomainPCIAddressReserveNextAddr(addrs, &def->disks[i]->info,
+                                               VIR_PCI_CONNECT_TYPE_PCI_DEVICE,
+                                               -1) < 0)
+            goto error;
+    }
+
     return 0;
 
  error:
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.args b/tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.args
new file mode 100644 (file)
index 0000000..8cc1668
--- /dev/null
@@ -0,0 +1,11 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:bc:85:fe \
+-s 2:0,virtio-blk,/tmp/freebsd.img \
+-s 4:0,virtio-blk,/tmp/test.img \
+-s 5:0,virtio-blk,/tmp/test2.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.ldargs
new file mode 100644 (file)
index 0000000..32538b5
--- /dev/null
@@ -0,0 +1,3 @@
+/usr/sbin/bhyveload \
+-m 214 \
+-d /tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-addr-multiple-virtio-disks.xml
new file mode 100644 (file)
index 0000000..9bcd0a6
--- /dev/null
@@ -0,0 +1,32 @@
+<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>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='vda' bus='virtio'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/test.img'/>
+      <target dev='vdb' bus='virtio'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/test2.img'/>
+      <target dev='vdc' bus='virtio'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:bc:85:fe'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.args b/tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.args
new file mode 100644 (file)
index 0000000..4dcc404
--- /dev/null
@@ -0,0 +1,9 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:bc:85:fe \
+-s 2:0,virtio-blk,/tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.ldargs
new file mode 100644 (file)
index 0000000..32538b5
--- /dev/null
@@ -0,0 +1,3 @@
+/usr/sbin/bhyveload \
+-m 214 \
+-d /tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-addr-single-virtio-disk.xml
new file mode 100644 (file)
index 0000000..6be9ae1
--- /dev/null
@@ -0,0 +1,22 @@
+<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>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='vda' bus='virtio'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:bc:85:fe'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
index e80705780a389216bacdba38da7b7c1c89431631..c36b55a0a631d6b3c4916c208c271ed755f49859 100644 (file)
@@ -190,6 +190,8 @@ mymain(void)
     DO_TEST("addr-single-sata-disk");
     DO_TEST("addr-multiple-sata-disks");
     DO_TEST("addr-more-than-32-sata-disks");
+    DO_TEST("addr-single-virtio-disk");
+    DO_TEST("addr-multiple-virtio-disks");
 
     /* The same without 32 devs per controller support */
     driver.bhyvecaps ^= BHYVE_CAP_AHCI32SLOT;
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-addr-multiple-virtio-disks.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-addr-multiple-virtio-disks.xml
new file mode 100644 (file)
index 0000000..542bff1
--- /dev/null
@@ -0,0 +1,42 @@
+<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/freebsd.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/test.img'/>
+      <target dev='vdb' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/test2.img'/>
+      <target dev='vdc' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </disk>
+    <controller type='pci' index='0' model='pci-root'/>
+    <interface type='bridge'>
+      <mac address='52:54:00:bc:85:fe'/>
+      <source bridge='virbr0'/>
+      <model type='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-addr-single-virtio-disk.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-addr-single-virtio-disk.xml
new file mode 100644 (file)
index 0000000..d7abb5a
--- /dev/null
@@ -0,0 +1,30 @@
+<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/freebsd.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <controller type='pci' index='0' model='pci-root'/>
+    <interface type='bridge'>
+      <mac address='52:54:00:bc:85:fe'/>
+      <source bridge='virbr0'/>
+      <model type='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
index 004afda14e70d37adf24d2421edba029870fb61f..ba9af29960e7298890080d5f24ce31cbf0e18cf2 100644 (file)
@@ -109,6 +109,8 @@ mymain(void)
     DO_TEST_DIFFERENT("addr-single-sata-disk");
     DO_TEST_DIFFERENT("addr-multiple-sata-disks");
     DO_TEST_DIFFERENT("addr-more-than-32-sata-disks");
+    DO_TEST_DIFFERENT("addr-single-virtio-disk");
+    DO_TEST_DIFFERENT("addr-multiple-virtio-disks");
 
     /* The same without 32 devs per controller support */
     driver.bhyvecaps ^= BHYVE_CAP_AHCI32SLOT;