[libvirt] [PATCH v3] QEMU: parse '-device vfio-pci' and '-device pci-assign'

Hong-Hua.Yin at freescale.com Hong-Hua.Yin at freescale.com
Mon Jun 16 07:22:16 UTC 2014


Ping.



> -----Original Message-----
> From: Olivia Yin [mailto:Hong-Hua.Yin at freescale.com]
> Sent: Tuesday, June 10, 2014 12:23 PM
> To: libvir-list at redhat.com; laine at laine.org
> Cc: Yin Olivia-R63875
> Subject: [PATCH v3] QEMU: parse '-device vfio-pci' and '-device pci-assign'
> 
> Signed-off-by: Olivia Yin <Hong-Hua.Yin at freescale.com>
> Signed-off-by: Laine Stump <laine at laine.org>
> 
> Modify the existing function qemuParseCommandLinePCI(), which works with  -
> pcidevice, to support for "-device pci-assign" and "-device pci-assign".
> 
> Change test cases 'hostdev-vfio' and 'hostdev-pci-address-device' to
> validate the new function.
> 
> The case related to QEMU_CAPS_HOST_PCI_MULTIDOMAIN which uses
> 'host=domain:bus:slot.func' is not supported yet.
> ---
>  src/qemu/qemu_command.c                            | 50
> +++++++++++++++++++---
>  tests/qemuargv2xmltest.c                           |  3 +-
>  .../qemuxml2argv-hostdev-pci-address-device.xml    |  6 +++
>  .../qemuxml2argvdata/qemuxml2argv-hostdev-vfio.xml |  1 +
>  4 files changed, 53 insertions(+), 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index
> e1d7e1b..3a4bc61 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -10193,7 +10193,8 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr
> xmlopt,
>   * Tries to parse a QEMU PCI device
>   */
>  static virDomainHostdevDefPtr
> -qemuParseCommandLinePCI(const char *val)
> +qemuParseCommandLinePCI(const char *val,
> +                        virDomainHostdevSubsysPCIBackendType backend)
>  {
>      int bus = 0, slot = 0, func = 0;
>      const char *start;
> @@ -10222,10 +10223,20 @@ qemuParseCommandLinePCI(const char *val)
>          goto error;
>      }
>      start = end + 1;
> -    if (virStrToLong_i(start, NULL, 16, &func) < 0) {
> -        virReportError(VIR_ERR_INTERNAL_ERROR,
> -                       _("cannot extract PCI device function '%s'"), val);
> -        goto error;
> +
> +    if (backend) {
> +        if (virStrToLong_i(start, &end, 16, &func) < 0 || *end != ',') {
> +            virReportError(VIR_ERR_INTERNAL_ERROR,
> +                           _("cannot extract PCI device function '%s'"),
> val);
> +            goto error;
> +        } else
> +            def->source.subsys.u.pci.backend = backend;
> +    } else {
> +        if (virStrToLong_i(start, NULL, 16, &func) < 0) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR,
> +                           _("cannot extract PCI device function '%s'"),
> val);
> +            goto error;
> +        }
>      }
> 
>      def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; @@ -11347,7 +11358,34 @@
> qemuParseCommandLine(virCapsPtr qemuCaps,
>          } else if (STREQ(arg, "-pcidevice")) {
>              virDomainHostdevDefPtr hostdev;
>              WANT_VALUE();
> -            if (!(hostdev = qemuParseCommandLinePCI(val)))
> +            if (!(hostdev = qemuParseCommandLinePCI(val,
> +                            VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)))
> +                goto error;
> +            if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev)
> < 0) {
> +                virDomainHostdevDefFree(hostdev);
> +                goto error;
> +            }
> +        } else if (STREQ(arg, "-device") && progargv[i+1] &&
> +                   STRPREFIX(progargv[i+1], "vfio-pci")) {
> +            const char *start;
> +            virDomainHostdevDefPtr hostdev;
> +            WANT_VALUE();
> +            start = val + strlen("vfio-pci,");
> +            if (!(hostdev = qemuParseCommandLinePCI(start,
> +                            VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO)))
> +                goto error;
> +            if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev)
> < 0) {
> +                virDomainHostdevDefFree(hostdev);
> +                goto error;
> +            }
> +        } else if (STREQ(arg, "-device") && progargv[i+1] &&
> +                   STRPREFIX(progargv[i+1], "pci-assign")) {
> +            const char *start;
> +            virDomainHostdevDefPtr hostdev;
> +            WANT_VALUE();
> +            start = val + strlen("pci-assign,");
> +            if (!(hostdev = qemuParseCommandLinePCI(start,
> +                            VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM)))
>                  goto error;
>              if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev)
> < 0) {
>                  virDomainHostdevDefFree(hostdev); diff --git
> a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index
> 2cbbe3d..80188be 100644
> --- a/tests/qemuargv2xmltest.c
> +++ b/tests/qemuargv2xmltest.c
> @@ -274,8 +274,9 @@ mymain(void)
>      DO_TEST("watchdog");
> 
>      DO_TEST("hostdev-usb-address");
> -
>      DO_TEST("hostdev-pci-address");
> +    DO_TEST("hostdev-pci-address-device");
> +    DO_TEST("hostdev-vfio");
> 
>      DO_TEST("smp");
> 
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-
> device.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-
> device.xml
> index b29ef58..b9a221a 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.xml
> @@ -15,10 +15,16 @@
>    <devices>
>      <emulator>/usr/bin/qemu</emulator>
>      <disk type='block' device='disk'>
> +      <driver name='qemu' type='raw'/>
>        <source dev='/dev/HostVG/QEMUGuest2'/>
>        <target dev='hda' bus='ide'/>
> +      <address type='drive' controller='0' bus='0' target='0'
> + unit='0'/>
>      </disk>
> +    <controller type='usb' index='0'/>
> +    <controller type='ide' index='0'/>
> +    <controller type='pci' index='0' model='pci-root'/>
>      <hostdev mode='subsystem' type='pci' managed='yes'>
> +      <driver name='kvm'/>
>        <source>
>          <address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>
>        </source>
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-vfio.xml
> b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-vfio.xml
> index 8daa53a..b99f798 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-vfio.xml
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-vfio.xml
> @@ -15,6 +15,7 @@
>    <devices>
>      <emulator>/usr/bin/qemu</emulator>
>      <disk type='block' device='disk'>
> +      <driver name='qemu' type='raw'/>
>        <source dev='/dev/HostVG/QEMUGuest2'/>
>        <target dev='hda' bus='ide'/>
>        <address type='drive' controller='0' bus='0' target='0' unit='0'/>
> --
> 1.8.5





More information about the libvir-list mailing list