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

[libvirt] [PATCH 1/3] libxl: determine device model version from emulator name



libxl exposes a setting for specifying a device model version. The default
is LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN, aka upstream qemu. But users can
specify LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL if they are using
the old forked qemu, aka qemu-dm. libvirt only supports specifying an
emulator by name, specifying a version is not supported.

Prior to this change libvirt would invoke the specified emulator with
'--help' option in an attempt to determine the version. If the help output
included the string "Options specific to the Xen version:" it was assumed
the emulator was the old forked qemu-dm. This approach works well when
creating libxl_domain_config to start a VM, but is problematic when simply
creating libxl_domain_config for unit test purposes. Build/development
systems running unit tests may not have the emulator installed. Even if
installed, invoking the emulator during unit tests is bad form.

This change takes the simple-minded approach of determining the device
model version based on the emulator name. If it contains "qemu-dm" it is
assumed to be LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL, otherwise
LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN.

Signed-off-by: Jim Fehlig <jfehlig suse com>
---
 src/libxl/libxl_capabilities.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 2bbd2d1b4..7ad8e7b57 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -723,35 +723,28 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
     return 0;
 }
 
-#define LIBXL_QEMU_DM_STR  "Options specific to the Xen version:"
 
+#define LIBXL_QEMU_DM_STR  "qemu-dm"
+
+/*
+ * libxl exposes a setting for specifying a device model version. The default
+ * is LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN (aka upstream qemu). But users can
+ * specify LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL if they are using
+ * the old, forked qemu (aka qemu-dm). libvirt only supports specifying an
+ * emulator. This function makes a poor attempt at determining the device
+ * model version based on the emulator name. If the emulator name contains
+ * "qemu-dm", it is assumed to be a
+ * LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL emulator.
+ */
 int
 libxlDomainGetEmulatorType(const virDomainDef *def)
 {
-    int ret = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
-    virCommandPtr cmd = NULL;
-    char *output = NULL;
-
     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (def->emulator) {
-            if (!virFileExists(def->emulator))
-                goto cleanup;
-
-            cmd = virCommandNew(def->emulator);
-
-            virCommandAddArgList(cmd, "-help", NULL);
-            virCommandSetOutputBuffer(cmd, &output);
-
-            if (virCommandRun(cmd, NULL) < 0)
-                goto cleanup;
-
-            if (strstr(output, LIBXL_QEMU_DM_STR))
-                ret = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
+            if (strstr(def->emulator, LIBXL_QEMU_DM_STR))
+                return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
         }
     }
 
- cleanup:
-    VIR_FREE(output);
-    virCommandFree(cmd);
-    return ret;
+    return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
 }
-- 
2.11.0


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