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

[libvirt] [PATCHv5 06/11] virCaps: get rid of emulatorRequired



This patch removes the emulatorRequired field and associated
infrastructure from the virCaps object. Instead the driver specific
callbacks are used as this field isn't enforced by all drivers.

This patch implements the appropriate callbacks in the qemu and lxc
driver and moves to check to that location.
---

Notes:
    Version 5:
    - removed spurious newline addition
    - ACKed by Eric in v4
    
    Version 4:
    - rename virDomainDefDefaultEmulator to virDomainDefGetDefaultEmulator
    - changed names of functions to comply with the rest
    Version 3:
    - new in the series

 src/conf/capabilities.c              | 10 ----------
 src/conf/capabilities.h              |  7 -------
 src/conf/domain_conf.c               | 17 +++++++----------
 src/conf/domain_conf.h               |  2 ++
 src/libvirt_private.syms             |  3 +--
 src/lxc/lxc_conf.c                   |  6 ++----
 src/lxc/lxc_domain.c                 | 17 +++++++++++++++++
 src/lxc/lxc_domain.h                 |  1 +
 src/qemu/qemu_capabilities.c         |  3 ---
 src/qemu/qemu_domain.c               | 15 +++++++++++++++
 tests/lxcxml2xmldata/lxc-hostdev.xml |  1 +
 tests/lxcxml2xmldata/lxc-systemd.xml |  1 +
 12 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index d53d5a3..1d29ce6 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -935,13 +935,3 @@ virCapabilitiesGenerateMac(virCapsPtr caps,
 {
     virMacAddrGenerate(caps->macPrefix, mac);
 }
-
-extern void
-virCapabilitiesSetEmulatorRequired(virCapsPtr caps) {
-    caps->emulatorRequired = 1;
-}
-
-extern unsigned int
-virCapabilitiesIsEmulatorRequired(virCapsPtr caps) {
-    return caps->emulatorRequired;
-}
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 5fd1bb5..dcf38a8 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -163,7 +163,6 @@ struct _virCaps {

     /* Move to virDomainXMLConf later */
     unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
-    unsigned int emulatorRequired : 1;
     int defaultDiskDriverType; /* enum virStorageFileFormat */
     int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
     bool hasWideScsiBus;
@@ -186,12 +185,6 @@ extern void
 virCapabilitiesGenerateMac(virCapsPtr caps,
                            virMacAddrPtr mac);

-extern void
-virCapabilitiesSetEmulatorRequired(virCapsPtr caps);
-
-extern unsigned int
-virCapabilitiesIsEmulatorRequired(virCapsPtr caps);
-
 extern int
 virCapabilitiesAddHostFeature(virCapsPtr caps,
                               const char *name);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5d3b0c7..22b4f85 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9165,8 +9165,10 @@ virDomainLeaseRemove(virDomainDefPtr def,
 }


-static char *virDomainDefDefaultEmulator(virDomainDefPtr def,
-                                         virCapsPtr caps) {
+char *
+virDomainDefGetDefaultEmulator(virDomainDefPtr def,
+                               virCapsPtr caps)
+{
     const char *type;
     const char *emulator;
     char *retemu;
@@ -9185,13 +9187,13 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def,

     if (!emulator) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("no emulator for domain %s os type %s on architecture %s"),
+                       _("no emulator for domain %s os type %s "
+                         "on architecture %s"),
                        type, def->os.type, virArchToString(def->os.arch));
         return NULL;
     }

-    retemu = strdup(emulator);
-    if (!retemu)
+    if (!(retemu = strdup(emulator)))
         virReportOOMError();

     return retemu;
@@ -10350,11 +10352,6 @@ virDomainDefParseXML(xmlDocPtr xml,
     }

     def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
-    if (!def->emulator && virCapabilitiesIsEmulatorRequired(caps)) {
-        def->emulator = virDomainDefDefaultEmulator(def, caps);
-        if (!def->emulator)
-            goto error;
-    }

     /* analysis of the disk devices */
     if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a2a17bd..724770e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2477,4 +2477,6 @@ int virDomainObjListExport(virDomainObjListPtr doms,
 virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def,
                                               int vcpuid);

+char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
+
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 96eea0a..38d082e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -21,9 +21,7 @@ virCapabilitiesFormatXML;
 virCapabilitiesFreeMachines;
 virCapabilitiesFreeNUMAInfo;
 virCapabilitiesGenerateMac;
-virCapabilitiesIsEmulatorRequired;
 virCapabilitiesNew;
-virCapabilitiesSetEmulatorRequired;
 virCapabilitiesSetHostCPU;
 virCapabilitiesSetMacPrefix;

@@ -118,6 +116,7 @@ virDomainDefFormat;
 virDomainDefFormatInternal;
 virDomainDefFree;
 virDomainDefGenSecurityLabelDef;
+virDomainDefGetDefaultEmulator;
 virDomainDefGetSecurityLabelDef;
 virDomainDefParseFile;
 virDomainDefParseNode;
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index dbc0b42..71b8916 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -119,9 +119,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
             goto error;
     }

-    /* LXC Requires an emulator in the XML */
-    virCapabilitiesSetEmulatorRequired(caps);
-
     if (driver) {
         /* Security driver data */
         const char *doi, *model;
@@ -159,11 +156,12 @@ error:
 virDomainXMLConfPtr
 lxcDomainXMLConfInit(void)
 {
-    return virDomainXMLConfNew(NULL,
+    return virDomainXMLConfNew(&virLXCDriverDomainDefParserConfig,
                                &virLXCDriverPrivateDataCallbacks,
                                NULL);
 }

+
 int lxcLoadDriverConfig(virLXCDriverPtr driver)
 {
     char *filename;
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 08cf8f6..8090789 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -79,3 +79,20 @@ virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = {
     .format = virLXCDomainObjPrivateXMLFormat,
     .parse  = virLXCDomainObjPrivateXMLParse,
 };
+
+static int
+virLXCDomainDefPostParse(virDomainDefPtr def,
+                         virCapsPtr caps,
+                         void *opaque ATTRIBUTE_UNUSED)
+{
+    /* check for emulator and create a default one if needed */
+    if (!def->emulator &&
+        !(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
+        return -1;
+
+    return 0;
+}
+
+virDomainDefParserConfig virLXCDriverDomainDefParserConfig = {
+    .domainPostParseCallback = virLXCDomainDefPostParse,
+};
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index 007ea84..12753aa 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -39,5 +39,6 @@ struct _virLXCDomainObjPrivate {
 };

 extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
+extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig;

 #endif /* __LXC_DOMAIN_H__ */
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 861d3c4..4db85a1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -906,9 +906,6 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
                                  i) < 0)
             goto error;

-    /* QEMU Requires an emulator in the XML */
-    virCapabilitiesSetEmulatorRequired(caps);
-
     caps->defaultConsoleTargetType = virQEMUCapsDefaultConsoleType;

     return caps;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b1b50c9..50a4c8c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -663,6 +663,20 @@ virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = {


 static int
+qemuDomainDefPostParse(virDomainDefPtr def,
+                       virCapsPtr caps,
+                       void *opaque ATTRIBUTE_UNUSED)
+{
+    /* check for emulator and create a default one if needed */
+    if (!def->emulator &&
+        !(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
+        return -1;
+
+    return 0;
+}
+
+
+static int
 qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
                              virDomainDefPtr def ATTRIBUTE_UNUSED,
                              virCapsPtr caps ATTRIBUTE_UNUSED,
@@ -703,6 +717,7 @@ no_memory:

 virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
     .devicesPostParseCallback = qemuDomainDeviceDefPostParse,
+    .domainPostParseCallback = qemuDomainDefPostParse,
 };


diff --git a/tests/lxcxml2xmldata/lxc-hostdev.xml b/tests/lxcxml2xmldata/lxc-hostdev.xml
index 02a87a7..b022cc7 100644
--- a/tests/lxcxml2xmldata/lxc-hostdev.xml
+++ b/tests/lxcxml2xmldata/lxc-hostdev.xml
@@ -13,6 +13,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/root/container'/>
       <target dir='/'/>
diff --git a/tests/lxcxml2xmldata/lxc-systemd.xml b/tests/lxcxml2xmldata/lxc-systemd.xml
index 2f36eee..fd3a606 100644
--- a/tests/lxcxml2xmldata/lxc-systemd.xml
+++ b/tests/lxcxml2xmldata/lxc-systemd.xml
@@ -15,6 +15,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/root/container'/>
       <target dir='/'/>
-- 
1.8.1.5


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