Re: [libvirt] [PATCH 29/34] Convert PCI device assignment over to -device

2010-01-15 Thread Daniel Veillard
On Fri, Jan 08, 2010 at 05:23:25PM +, Daniel P. Berrange wrote:
 The old syntax is
 
   -pcidevice host=BUS:SLOT:FUNCTION
 
 The new syntax is
 
   -device pci-assign,host=BUS:SLOT:FUNCTION,addr=PCI SLOT,id=host0
 ---
  src/qemu/qemu_conf.c   |   51 
 +++-
  .../qemuxml2argv-hostdev-pci-address-device.args   |1 +
  .../qemuxml2argv-hostdev-pci-address-device.xml|   27 ++
  tests/qemuxml2argvtest.c   |1 +
  4 files changed, 68 insertions(+), 12 deletions(-)
  create mode 100644 
 tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args
  create mode 100644 
 tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml
 

  ACK,

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 29/34] Convert PCI device assignment over to -device

2010-01-08 Thread Daniel P. Berrange
The old syntax is

  -pcidevice host=BUS:SLOT:FUNCTION

The new syntax is

  -device pci-assign,host=BUS:SLOT:FUNCTION,addr=PCI SLOT,id=host0
---
 src/qemu/qemu_conf.c   |   51 +++-
 .../qemuxml2argv-hostdev-pci-address-device.args   |1 +
 .../qemuxml2argv-hostdev-pci-address-device.xml|   27 ++
 tests/qemuxml2argvtest.c   |1 +
 4 files changed, 68 insertions(+), 12 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 3b39a91..a09fb62 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -2326,6 +2326,32 @@ error:
 }
 
 
+static char *
+qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev)
+{
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+virBufferAddLit(buf, pci-assign);
+virBufferVSprintf(buf, ,host=%.2x:%.2x.%.1x,
+  dev-source.subsys.u.pci.bus,
+  dev-source.subsys.u.pci.slot,
+  dev-source.subsys.u.pci.function);
+virBufferVSprintf(buf, ,id=%s, dev-info.alias);
+if (qemuBuildDeviceAddressStr(buf, dev-info)  0)
+goto error;
+
+if (virBufferError(buf)) {
+virReportOOMError(NULL);
+goto error;
+}
+
+return virBufferContentAndReset(buf);
+
+error:
+virBufferFreeAndReset(buf);
+return NULL;
+}
+
 /* This function outputs a -chardev command line option which describes only 
the
  * host side of the character device */
 static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
@@ -3575,22 +3601,23 @@ int qemudBuildCommandLine(virConnectPtr conn,
 /* PCI */
 if (hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
 hostdev-source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) 
{
-if (!(qemuCmdFlags  QEMUD_CMD_FLAG_PCIDEVICE)) {
+if (qemuCmdFlags  QEMUD_CMD_FLAG_DEVICE) {
+ADD_ARG_LIT(-device);
+if (!(pcidev = qemuBuildPCIHostdevDevStr(hostdev)))
+goto error;
+} else if (qemuCmdFlags  QEMUD_CMD_FLAG_PCIDEVICE) {
+ADD_ARG_LIT(-pcidevice);
+if (virAsprintf(pcidev, host=%.2x:%.2x.%.1x,
+hostdev-source.subsys.u.pci.bus,
+hostdev-source.subsys.u.pci.slot,
+hostdev-source.subsys.u.pci.function)  0)
+goto no_memory;
+} else {
 qemudReportError(conn, NULL, NULL, VIR_ERR_NO_SUPPORT, %s,
  _(PCI device assignment is not supported by 
this version of qemu));
 goto error;
 }
-ret = virAsprintf(pcidev, host=%.2x:%.2x.%.1x,
-   hostdev-source.subsys.u.pci.bus,
-   hostdev-source.subsys.u.pci.slot,
-   hostdev-source.subsys.u.pci.function);
-if (ret  0) {
-pcidev = NULL;
-goto no_memory;
-}
-ADD_ARG_LIT(-pcidevice);
-ADD_ARG_LIT(pcidev);
-VIR_FREE(pcidev);
+ADD_ARG(pcidev);
 }
 }
 
diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args
new file mode 100644
index 000..f1865ee
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M 
pc -m 214 -smp 1 -nographic -nodefaults -monitor 
unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda 
/dev/HostVG/QEMUGuest2 -usb -device pci-assign,host=06:12.5,id=hostpci0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml
new file mode 100644
index 000..ac5ad47
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml
@@ -0,0 +1,27 @@
+domain type='qemu'
+  nameQEMUGuest2/name
+  uuidc7a5fdbd-edaf-9466-926a-d65c16db1809/uuid
+  memory219200/memory
+  currentMemory219200/currentMemory
+  vcpu1/vcpu
+  os
+type arch='i686' machine='pc'hvm/type
+boot dev='hd'/
+  /os
+  clock offset='utc'/
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashdestroy/on_crash
+  devices
+emulator/usr/bin/qemu/emulator
+disk type='block' device='disk'
+  source dev='/dev/HostVG/QEMUGuest2'/
+  target dev='hda' bus='ide'/
+/disk
+hostdev mode='subsystem' type='pci' managed='yes'
+  source
+address domain='0x' bus='0x06' slot='0x12' function='0x5'/
+  /source
+/hostdev
+  /devices
+/domain
diff --git