Re: [PATCH 2/3] qemu: improve device flag parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ä 2011å01æ14æ 03:10, Eric Blake åé:
* src/qemu/qemu_capabilities.h (qemuCapsParseDeviceStr): New
prototype.
* src/qemu/qemu_capabilities.c (qemuCapsParsePCIDeviceStrs)
Rename and split...
(qemuCapsExtractDeviceStr, qemuCapsParseDeviceStr): ...to make it
easier to add and test device-specific checks.
(qemuCapsExtractVersionInfo): Update caller.
* tests/qemuhelptest.c (testHelpStrParsing): Also test parsing of
device-related flags.
(mymain): Update expected flags.
* tests/qemuhelpdata/qemu-0.12.1-device: New file.
* tests/qemuhelpdata/qemu-kvm-0.12.1.2-rhel60-device: New file.
* tests/qemuhelpdata/qemu-kvm-0.12.3-device: New file.
* tests/qemuhelpdata/qemu-kvm-0.13.0-device: New file.
---
  src/qemu/qemu_capabilities.c                       |   41 ++++++++---
  src/qemu/qemu_capabilities.h                       |    2 +
  tests/qemuhelpdata/qemu-kvm-0.12.1.2-rhel60-device |   57 ++++++++++++++++
  tests/qemuhelpdata/qemu-kvm-0.13.0-device          |   70 ++++++++++++++++++++
  tests/qemuhelptest.c                               |   48 ++++++++++----
  5 files changed, 195 insertions(+), 23 deletions(-)
  create mode 100644 tests/qemuhelpdata/qemu-0.12.1-device
  create mode 100644 tests/qemuhelpdata/qemu-kvm-0.12.1.2-rhel60-device
  create mode 100644 tests/qemuhelpdata/qemu-kvm-0.12.3-device
  create mode 100644 tests/qemuhelpdata/qemu-kvm-0.13.0-device

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 9bab317..f967255 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1032,28 +1032,46 @@ fail:
      return -1;
  }

-static void
-qemuCapsParsePCIDeviceStrs(const char *qemu,
-                           unsigned long long *flags)
+static int
+qemuCapsExtractDeviceStr(const char *qemu,
+                         unsigned long long *flags)
  {
-    char *pciassign = NULL;
+    char *output = NULL;
      virCommandPtr cmd;
+    int ret = -1;

-    cmd = virCommandNewArgList(qemu, "-device", "pci-assign,?", NULL);
+    /* Cram together all device-related queries into one invocation;
+     * the output format makes it possible to distinguish what we
+     * need.  Unrecognized '-device bogus,?' cause an error in
+     * isolation, but are silently ignored in combination with
+     * '-device ?'.  */
+    cmd = virCommandNewArgList(qemu,
+                               "-device", "pci-assign,?",
+                               NULL);
      virCommandAddEnvPassCommon(cmd);
      /* qemu -help goes to stdout, but qemu -device ? goes to stderr.  */
-    virCommandSetErrorBuffer(cmd,&pciassign);
+    virCommandSetErrorBuffer(cmd,&output);
      virCommandClearCaps(cmd);

      if (virCommandRun(cmd, NULL)<  0)
          goto cleanup;

-    if (strstr(pciassign, "pci-assign.configfd"))
-        *flags |= QEMUD_CMD_FLAG_PCI_CONFIGFD;
+    ret = qemuCapsParseDeviceStr(output, flags);

  cleanup:
-    VIR_FREE(pciassign);
+    VIR_FREE(output);
      virCommandFree(cmd);
+    return ret;
+}
+
+
+int
+qemuCapsParseDeviceStr(const char *str, unsigned long long *flags)
+{
+    if (strstr(str, "pci-assign.configfd"))
+        *flags |= QEMUD_CMD_FLAG_PCI_CONFIGFD;
+
+    return 0;
  }

  int qemuCapsExtractVersionInfo(const char *qemu,
@@ -1092,8 +1110,9 @@ int qemuCapsExtractVersionInfo(const char *qemu,
                               &version,&is_kvm,&kvm_version) == -1)
          goto cleanup;

-    if (flags&  QEMUD_CMD_FLAG_DEVICE)
-        qemuCapsParsePCIDeviceStrs(qemu,&flags);
+    if ((flags&  QEMUD_CMD_FLAG_DEVICE)&&
+        qemuCapsExtractDeviceStr(qemu,&flags)<  0)
+        goto cleanup;

This causes problem? older qemu which doesn't support
"-device pci-assign,?" or "-device virtio-blk-pci,?"
won't work anymore. (raised by nikunj in #virt).

Regards
Osier

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]