Export the libxl emulator checks with ATTRIBUTE_NOINLINE so
they can be mocked in the test suite. While add it, change the
function names to conform to naming standards.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/libxl/libxl_capabilities.c | 30 +++++++++++++++++++++++++++++-
src/libxl/libxl_capabilities.h | 5 ++++-
src/libxl/libxl_conf.c | 17 +++--------------
src/libxl/libxl_domain.c | 2 +-
4 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index e0959202b..501ebf477 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -743,7 +743,7 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
#define LIBXL_QEMU_DM_STR "Options specific to the Xen version:"
int
-libxlDomainGetEmulatorType(const virDomainDef *def)
+libxlCapsGetEmulatorType(const virDomainDef *def)
{
int ret = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
virCommandPtr cmd = NULL;
@@ -772,3 +772,31 @@ libxlDomainGetEmulatorType(const virDomainDef *def)
virCommandFree(cmd);
return ret;
}
+
+
+/*
+ * Returns 0 if an <emulator> is defined, exists, and is executable.
+ * Returns -1 otherwise.
+ */
+int
+libxlCapsCheckEmulator(const virDomainDef *def)
+{
+ if (def->emulator == NULL)
+ return 0;
+
+ if (!virFileExists(def->emulator)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("emulator '%s' not found"),
+ def->emulator);
+ return -1;
+ }
+
+ if (!virFileIsExecutable(def->emulator)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("emulator '%s' is not executable"),
+ def->emulator);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/libxl/libxl_capabilities.h b/src/libxl/libxl_capabilities.h
index 992b78077..28a58d36b 100644
--- a/src/libxl/libxl_capabilities.h
+++ b/src/libxl/libxl_capabilities.h
@@ -52,6 +52,9 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
size_t nfirmwares);
int
-libxlDomainGetEmulatorType(const virDomainDef *def);
+libxlCapsGetEmulatorType(const virDomainDef *def) ATTRIBUTE_NOINLINE;
+
+int
+libxlCapsCheckEmulator(const virDomainDef *def) ATTRIBUTE_NOINLINE;
#endif /* LIBXL_CAPABILITIES_H */
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 4416a09dd..f8ebd88e0 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -472,25 +472,14 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
b_info->u.hvm.bios = LIBXL_BIOS_TYPE_OVMF;
if (def->emulator) {
- if (!virFileExists(def->emulator)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("emulator '%s' not found"),
- def->emulator);
+ if (libxlCapsCheckEmulator(def) < 0)
return -1;
- }
-
- if (!virFileIsExecutable(def->emulator)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("emulator '%s' is not executable"),
- def->emulator);
- return -1;
- }
VIR_FREE(b_info->device_model);
if (VIR_STRDUP(b_info->device_model, def->emulator) < 0)
return -1;
- b_info->device_model_version = libxlDomainGetEmulatorType(def);
+ b_info->device_model_version = libxlCapsGetEmulatorType(def);
}
if (def->nserials) {
@@ -2082,7 +2071,7 @@ libxlMakeVideo(virDomainDefPtr def, libxl_domain_config *d_config)
{
libxl_domain_build_info *b_info = &d_config->b_info;
- int dm_type = libxlDomainGetEmulatorType(def);
+ int dm_type = libxlCapsGetEmulatorType(def);
if (d_config->c_info.type != LIBXL_DOMAIN_TYPE_HVM)
return 0;
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 7caa67474..1bc9045bf 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -335,7 +335,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
}
if (dev->type == VIR_DOMAIN_DEVICE_VIDEO && def->os.type ==
VIR_DOMAIN_OSTYPE_HVM) {
- int dm_type = libxlDomainGetEmulatorType(def);
+ int dm_type = libxlCapsGetEmulatorType(def);
switch (dev->data.video->type) {
case VIR_DOMAIN_VIDEO_TYPE_VGA:
--
2.13.1