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

[libvirt] [PATCH 26/40] Simplify the Xen domain attach/dettach driver methods



From: "Daniel P. Berrange" <berrange redhat com>

Make the domain attach/dettach driver methods directly call
into either the XenD or XM drivers

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 src/xen/xen_driver.c    | 55 +++++++++++++++++--------------------------------
 src/xen/xen_driver.h    |  2 --
 src/xen/xend_internal.c | 27 ++----------------------
 src/xen/xend_internal.h |  6 ++++++
 src/xen/xm_internal.c   | 13 ++----------
 src/xen/xm_internal.h   | 10 +++++++--
 6 files changed, 37 insertions(+), 76 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 6643a97..2262713 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -84,7 +84,6 @@ xenUnifiedDomainGetVcpus(virDomainPtr dom,
 static struct xenUnifiedDriver const * const drivers[XEN_UNIFIED_NR_DRIVERS] = {
     [XEN_UNIFIED_HYPERVISOR_OFFSET] = &xenHypervisorDriver,
     [XEN_UNIFIED_XEND_OFFSET] = &xenDaemonDriver,
-    [XEN_UNIFIED_XM_OFFSET] = &xenXMDriver,
 };
 
 static bool inside_daemon = false;
@@ -1397,7 +1396,6 @@ static int
 xenUnifiedDomainAttachDevice(virDomainPtr dom, const char *xml)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i;
     unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
 
     /*
@@ -1405,14 +1403,13 @@ xenUnifiedDomainAttachDevice(virDomainPtr dom, const char *xml)
      * config without touching persistent config, we add the extra flag here
      * to make this API work
      */
-    if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
-        priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
+    if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
         flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->xenDomainAttachDeviceFlags &&
-            drivers[i]->xenDomainAttachDeviceFlags(dom, xml, flags) == 0)
-            return 0;
+    if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
+        return xenXMDomainAttachDeviceFlags(dom, xml, flags);
+    else
+        return xenDaemonAttachDeviceFlags(dom, xml, flags);
 
     return -1;
 }
@@ -1422,21 +1419,17 @@ xenUnifiedDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
                                   unsigned int flags)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->xenDomainAttachDeviceFlags &&
-            drivers[i]->xenDomainAttachDeviceFlags(dom, xml, flags) == 0)
-            return 0;
-
-    return -1;
+    if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
+        return xenXMDomainAttachDeviceFlags(dom, xml, flags);
+    else
+        return xenDaemonAttachDeviceFlags(dom, xml, flags);
 }
 
 static int
 xenUnifiedDomainDetachDevice(virDomainPtr dom, const char *xml)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i;
     unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
 
     /*
@@ -1444,16 +1437,13 @@ xenUnifiedDomainDetachDevice(virDomainPtr dom, const char *xml)
      * config without touching persistent config, we add the extra flag here
      * to make this API work
      */
-    if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
-        priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
+    if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
         flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->xenDomainDetachDeviceFlags &&
-            drivers[i]->xenDomainDetachDeviceFlags(dom, xml, flags) == 0)
-            return 0;
-
-    return -1;
+    if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
+        return xenXMDomainDetachDeviceFlags(dom, xml, flags);
+    else
+        return xenDaemonDetachDeviceFlags(dom, xml, flags);
 }
 
 static int
@@ -1461,25 +1451,18 @@ xenUnifiedDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
                                   unsigned int flags)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i;
-
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
-        if (priv->opened[i] && drivers[i]->xenDomainDetachDeviceFlags &&
-            drivers[i]->xenDomainDetachDeviceFlags(dom, xml, flags) == 0)
-            return 0;
 
-    return -1;
+    if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
+        return xenXMDomainDetachDeviceFlags(dom, xml, flags);
+    else
+        return xenDaemonDetachDeviceFlags(dom, xml, flags);
 }
 
 static int
 xenUnifiedDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
                                   unsigned int flags)
 {
-    xenUnifiedPrivatePtr priv = dom->conn->privateData;
-
-    if (priv->opened[XEN_UNIFIED_XEND_OFFSET])
-        return xenDaemonUpdateDeviceFlags(dom, xml, flags);
-    return -1;
+    return xenDaemonUpdateDeviceFlags(dom, xml, flags);
 }
 
 static int
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index 254c2f5..e8c2958 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -93,8 +93,6 @@ extern int xenRegister (void);
  * structure with direct calls in xen_unified.c.
  */
 struct xenUnifiedDriver {
-    virDrvDomainAttachDeviceFlags xenDomainAttachDeviceFlags;
-    virDrvDomainDetachDeviceFlags xenDomainDetachDeviceFlags;
     virDrvDomainGetSchedulerType xenDomainGetSchedulerType;
     virDrvDomainGetSchedulerParameters xenDomainGetSchedulerParameters;
     virDrvDomainSetSchedulerParameters xenDomainSetSchedulerParameters;
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index f9b43b8..49ef256 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2196,7 +2196,7 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc)
  *
  * Returns 0 in case of success, -1 in case of failure.
  */
-static int
+int
 xenDaemonAttachDeviceFlags(virDomainPtr domain,
                            const char *xml,
                            unsigned int flags)
@@ -2219,13 +2219,6 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
                            _("Cannot modify live config if domain is inactive"));
             return -1;
         }
-        /* If xendConfigVersion < 3 only live config can be changed */
-        if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("Xend version does not support modifying "
-                           "persistent config"));
-            return -1;
-        }
     } else {
         /* Only live config can be changed if xendConfigVersion < 3 */
         if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
@@ -2379,13 +2372,6 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain,
                            _("Cannot modify live config if domain is inactive"));
             return -1;
         }
-        /* If xendConfigVersion < 3 only live config can be changed */
-        if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("Xend version does not support modifying "
-                           "persistent config"));
-            return -1;
-        }
     } else {
         /* Only live config can be changed if xendConfigVersion < 3 */
         if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
@@ -2464,7 +2450,7 @@ cleanup:
  *
  * Returns 0 in case of success, -1 in case of failure.
  */
-static int
+int
 xenDaemonDetachDeviceFlags(virDomainPtr domain,
                            const char *xml,
                            unsigned int flags)
@@ -2486,13 +2472,6 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain,
                            _("Cannot modify live config if domain is inactive"));
             return -1;
         }
-        /* If xendConfigVersion < 3 only live config can be changed */
-        if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("Xend version does not support modifying "
-                             "persistent config"));
-            return -1;
-        }
     } else {
         /* Only live config can be changed if xendConfigVersion < 3 */
         if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
@@ -3353,8 +3332,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain,
 }
 
 struct xenUnifiedDriver xenDaemonDriver = {
-    .xenDomainAttachDeviceFlags = xenDaemonAttachDeviceFlags,
-    .xenDomainDetachDeviceFlags = xenDaemonDetachDeviceFlags,
     .xenDomainGetSchedulerType = xenDaemonGetSchedulerType,
     .xenDomainGetSchedulerParameters = xenDaemonGetSchedulerParameters,
     .xenDomainSetSchedulerParameters = xenDaemonSetSchedulerParameters,
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index d773ef9..4a8578b 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -114,6 +114,12 @@ int xenDaemonListDefinedDomains(virConnectPtr conn,
                                 char **const names,
                                 int maxnames);
 
+int xenDaemonAttachDeviceFlags(virDomainPtr domain,
+                               const char *xml,
+                               unsigned int flags);
+int xenDaemonDetachDeviceFlags(virDomainPtr domain,
+                               const char *xml,
+                               unsigned int flags);
 
 virDomainPtr xenDaemonDomainDefineXML(virConnectPtr xend, const char *sexpr);
 int xenDaemonDomainCreate(virDomainPtr domain);
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index bb79c63..fa0392b 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -66,10 +66,6 @@
 #define XEN_MAX_PHYSICAL_CPU 1024
 
 char * xenXMAutoAssignMac(void);
-static int xenXMDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
-                                        unsigned int flags);
-static int xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
-                                        unsigned int flags);
 
 #define XM_REFRESH_INTERVAL 10
 
@@ -80,11 +76,6 @@ static int xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
 #define QEMU_IF_SCRIPT "qemu-ifup"
 #define XM_XML_ERROR "Invalid xml"
 
-struct xenUnifiedDriver xenXMDriver = {
-    .xenDomainAttachDeviceFlags = xenXMDomainAttachDeviceFlags,
-    .xenDomainDetachDeviceFlags = xenXMDomainDetachDeviceFlags,
-};
-
 #ifndef WITH_XEN_INOTIFY
 static int xenInotifyActive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
@@ -1241,7 +1232,7 @@ cleanup:
  *
  * Returns 0 in case of success, -1 in case of failure.
  */
-static int
+int
 xenXMDomainAttachDeviceFlags(virDomainPtr domain,
                              const char *xml,
                              unsigned int flags)
@@ -1331,7 +1322,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
  *
  * Returns 0 in case of success, -1 in case of failure.
  */
-static int
+int
 xenXMDomainDetachDeviceFlags(virDomainPtr domain,
                              const char *xml,
                              unsigned int flags)
diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h
index 257b663..731a126 100644
--- a/src/xen/xm_internal.h
+++ b/src/xen/xm_internal.h
@@ -30,8 +30,6 @@
 # include "virconf.h"
 # include "domain_conf.h"
 
-extern struct xenUnifiedDriver xenXMDriver;
-
 int xenXMConfigCacheRefresh (virConnectPtr conn);
 int xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename);
 int xenXMConfigCacheRemoveFile(virConnectPtr conn, const char *filename);
@@ -70,4 +68,12 @@ int xenXMDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long
 int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart);
 int xenXMDomainSetAutostart(virDomainPtr dom, int autostart);
 
+int xenXMDomainAttachDeviceFlags(virDomainPtr domain,
+                                 const char *xml,
+                                 unsigned int flags);
+
+int xenXMDomainDetachDeviceFlags(virDomainPtr domain,
+                                 const char *xml,
+                                 unsigned int flags);
+
 #endif
-- 
1.8.1.4


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