[libvirt] [PATCH 3/8] Detect KVM's PCI device assignment support

Daniel P. Berrange berrange at redhat.com
Thu Aug 13 18:41:19 UTC 2009


On Thu, Aug 13, 2009 at 05:44:32PM +0100, Mark McLoughlin wrote:
> PCI device assignment is only supported in KVM's fork of qemu, so we
> should really detect its availability and give a nice error if its
> not supported.
> 
> * src/qemu_conf.[ch]: introduce QEMUD_CMD_FLAG_PCIDEVICE indicating
>   that the -pcidevice command line option is available
> 
> * tests/*: update the tests
> ---
>  src/qemu_conf.c          |    8 ++++++++
>  src/qemu_conf.h          |    2 ++
>  tests/qemuargv2xmltest.c |    2 +-
>  tests/qemuhelptest.c     |    6 ++++--
>  tests/qemuxml2argvtest.c |    2 +-
>  5 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/src/qemu_conf.c b/src/qemu_conf.c
> index 6b0b404..1b160c9 100644
> --- a/src/qemu_conf.c
> +++ b/src/qemu_conf.c
> @@ -771,6 +771,9 @@ static unsigned int qemudComputeCmdFlags(const char *help,
>          flags |= QEMUD_CMD_FLAG_VGA;
>      if (strstr(help, "boot=on"))
>          flags |= QEMUD_CMD_FLAG_DRIVE_BOOT;
> +    if (strstr(help, "-pcidevice"))
> +        flags |= QEMUD_CMD_FLAG_PCIDEVICE;
> +
>      if (version >= 9000)
>          flags |= QEMUD_CMD_FLAG_VNC_COLON;
>  
> @@ -2070,6 +2073,11 @@ 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)) {
> +                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,
> diff --git a/src/qemu_conf.h b/src/qemu_conf.h
> index 517626a..aea9843 100644
> --- a/src/qemu_conf.h
> +++ b/src/qemu_conf.h
> @@ -64,6 +64,8 @@ enum qemud_cmd_flags {
>      QEMUD_CMD_FLAG_0_10         = (1 << 16),
>      QEMUD_CMD_FLAG_NET_NAME     = QEMUD_CMD_FLAG_0_10, /* -net ...,name=str */
>      QEMUD_CMD_FLAG_HOST_NET_ADD = QEMUD_CMD_FLAG_0_10, /* host_net_add monitor command */
> +
> +    QEMUD_CMD_FLAG_PCIDEVICE     = (1 << 17), /* PCI device assignment only supported by qemu-kvm */
>  };
>  
>  /* Main driver state */
> diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
> index f2537b7..7861520 100644
> --- a/tests/qemuargv2xmltest.c
> +++ b/tests/qemuargv2xmltest.c
> @@ -216,7 +216,7 @@ mymain(int argc, char **argv)
>      DO_TEST("hostdev-usb-product", 0);
>      DO_TEST("hostdev-usb-address", 0);
>  
> -    DO_TEST("hostdev-pci-address", 0);
> +    DO_TEST("hostdev-pci-address", QEMUD_CMD_FLAG_PCIDEVICE);
>  
>      DO_TEST_FULL("restore-v1", QEMUD_CMD_FLAG_MIGRATE_KVM_STDIO, "stdio");
>      DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "stdio");
> diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
> index 1948bd1..ad2045f 100644
> --- a/tests/qemuhelptest.c
> +++ b/tests/qemuhelptest.c
> @@ -135,7 +135,8 @@ mymain(int argc, char **argv)
>              QEMUD_CMD_FLAG_KVM |
>              QEMUD_CMD_FLAG_DRIVE_FORMAT |
>              QEMUD_CMD_FLAG_VGA |
> -            QEMUD_CMD_FLAG_0_10,
> +            QEMUD_CMD_FLAG_0_10 |
> +            QEMUD_CMD_FLAG_PCIDEVICE,
>              10005, 1,  0);
>      DO_TEST("kvm-86",
>              QEMUD_CMD_FLAG_VNC_COLON |
> @@ -151,7 +152,8 @@ mymain(int argc, char **argv)
>              QEMUD_CMD_FLAG_KVM |
>              QEMUD_CMD_FLAG_DRIVE_FORMAT |
>              QEMUD_CMD_FLAG_VGA |
> -            QEMUD_CMD_FLAG_0_10,
> +            QEMUD_CMD_FLAG_0_10 |
> +            QEMUD_CMD_FLAG_PCIDEVICE,
>              10050, 1,  0);
>  
>      return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> index 73a6709..6f25e7d 100644
> --- a/tests/qemuxml2argvtest.c
> +++ b/tests/qemuxml2argvtest.c
> @@ -263,7 +263,7 @@ mymain(int argc, char **argv)
>      DO_TEST("hostdev-usb-product", 0);
>      DO_TEST("hostdev-usb-address", 0);
>  
> -    DO_TEST("hostdev-pci-address", 0);
> +    DO_TEST("hostdev-pci-address", QEMUD_CMD_FLAG_PCIDEVICE);
>  
>      DO_TEST_FULL("restore-v1", QEMUD_CMD_FLAG_MIGRATE_KVM_STDIO, "stdio");
>      DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC, "stdio");

ACK


Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list