render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 1298c305b6e4dcb364e8944a60bf2f698eb601ca Mon Sep 17 00:00:00 2001
Message-Id: <1298c305b6e4dcb364e8944a60bf2f698eb601ca@dist-git>
From: Luyao Huang <lhuang@redhat.com>
Date: Thu, 6 Aug 2015 13:09:12 +0200
Subject: [PATCH] qemu: Auto assign pci addresses for shared memory devices

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1165029

Signed-off-by: Luyao Huang <lhuang@redhat.com>
(cherry picked from commit e309ea66580798860154c70f275c56236702c7dc)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_command.c                        | 11 +++++++++++
 tests/qemuxml2argvdata/qemuxml2argv-shmem.args | 19 +++++++++++--------
 tests/qemuxml2argvdata/qemuxml2argv-shmem.xml  |  1 +
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index feba308..1e5e244 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2562,6 +2562,7 @@ qemuAssignDevicePCISlots(virDomainDefPtr def,
                                                flags) < 0)
             goto error;
     }
+
     /* Further non-primary video cards which have to be qxl type */
     for (i = 1; i < def->nvideos; i++) {
         if (def->videos[i]->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
@@ -2575,6 +2576,16 @@ qemuAssignDevicePCISlots(virDomainDefPtr def,
                                                flags) < 0)
             goto error;
     }
+
+    /* Shared Memory */
+    for (i = 0; i < def->nshmems; i++) {
+        if (def->shmems[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+            continue;
+
+        if (virDomainPCIAddressReserveNextSlot(addrs,
+                                               &def->shmems[i]->info, flags) < 0)
+            goto error;
+    }
     for (i = 0; i < def->ninputs; i++) {
         /* Nada - none are PCI based (yet) */
     }
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem.args b/tests/qemuxml2argvdata/qemuxml2argv-shmem.args
index a3d3cc8..7e10fc4 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-shmem.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem.args
@@ -1,16 +1,19 @@
 LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
 /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults \
 -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
--device ivshmem,shm=shmem0 \
--device ivshmem,size=128m,shm=shmem1 \
--device ivshmem,size=256m,shm=shmem2 \
--device ivshmem,size=512m,chardev=charshmem3 \
+-device ivshmem,shm=shmem0,bus=pci.0,addr=0x3 \
+-device ivshmem,size=128m,shm=shmem1,bus=pci.0,addr=0x5 \
+-device ivshmem,size=256m,shm=shmem2,bus=pci.0,addr=0x4 \
+-device ivshmem,size=512m,chardev=charshmem3,bus=pci.0,addr=0x6 \
 -chardev socket,id=charshmem3,path=/var/lib/libvirt/shmem-shmem3-sock \
--device ivshmem,size=1024m,chardev=charshmem4 \
+-device ivshmem,size=1024m,chardev=charshmem4,bus=pci.0,addr=0x7 \
 -chardev socket,id=charshmem4,path=/tmp/shmem4-sock \
--device ivshmem,size=2048m,chardev=charshmem5,msi=on,ioeventfd=off \
+-device ivshmem,size=2048m,chardev=charshmem5,\
+msi=on,ioeventfd=off,bus=pci.0,addr=0x8 \
 -chardev socket,id=charshmem5,path=/tmp/shmem5-sock \
--device ivshmem,size=4096m,chardev=charshmem6,msi=on,vectors=16 \
+-device ivshmem,size=4096m,chardev=charshmem6,\
+msi=on,vectors=16,bus=pci.0,addr=0x9 \
 -chardev socket,id=charshmem6,path=/tmp/shmem6-sock \
--device ivshmem,size=8192m,chardev=charshmem7,msi=on,vectors=32,ioeventfd=on \
+-device ivshmem,size=8192m,chardev=charshmem7,\
+msi=on,vectors=32,ioeventfd=on,bus=pci.0,addr=0xa \
 -chardev socket,id=charshmem7,path=/tmp/shmem7-sock
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml b/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml
index fd79c89..d4b38f9 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-shmem.xml
@@ -23,6 +23,7 @@
     </shmem>
     <shmem name='shmem2'>
       <size unit='M'>256</size>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </shmem>
     <shmem name='shmem3'>
       <size unit='M'>512</size>
-- 
2.5.0