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

[libvirt] [PATCH 27/40] Simplify the Xen domain scheduler parameter driver methods



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

Make the Xen domain scheduler parameter methods directly
call into XenD or Xen hypervisor drivers

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 src/xen/xen_driver.c     | 54 +++++++++++++++++++++---------------------------
 src/xen/xen_driver.h     | 15 --------------
 src/xen/xen_hypervisor.c | 25 ----------------------
 src/xen/xen_hypervisor.h |  1 -
 src/xen/xend_internal.c  | 12 +++--------
 src/xen/xend_internal.h  | 12 +++++++----
 6 files changed, 35 insertions(+), 84 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 2262713..ac61677 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -80,12 +80,6 @@ xenUnifiedDomainGetVcpus(virDomainPtr dom,
                          unsigned char *cpumaps, int maplen);
 
 
-/* The five Xen drivers below us. */
-static struct xenUnifiedDriver const * const drivers[XEN_UNIFIED_NR_DRIVERS] = {
-    [XEN_UNIFIED_HYPERVISOR_OFFSET] = &xenHypervisorDriver,
-    [XEN_UNIFIED_XEND_OFFSET] = &xenDaemonDriver,
-};
-
 static bool inside_daemon = false;
 
 /**
@@ -1503,17 +1497,17 @@ static char *
 xenUnifiedDomainGetSchedulerType(virDomainPtr dom, int *nparams)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i;
-    char *schedulertype;
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; i++) {
-        if (priv->opened[i] && drivers[i]->xenDomainGetSchedulerType) {
-            schedulertype = drivers[i]->xenDomainGetSchedulerType(dom, nparams);
-            if (schedulertype != NULL)
-                return schedulertype;
+    if (dom->id < 0) {
+        if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Cannot change scheduler parameters"));
+            return NULL;
         }
+        return xenDaemonGetSchedulerType(dom, nparams);
+    } else {
+        return xenHypervisorGetSchedulerType(dom, nparams);
     }
-    return NULL;
 }
 
 static int
@@ -1523,18 +1517,19 @@ xenUnifiedDomainGetSchedulerParametersFlags(virDomainPtr dom,
                                             unsigned int flags)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i, ret;
 
     virCheckFlags(0, -1);
 
-    for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) {
-        if (priv->opened[i] && drivers[i]->xenDomainGetSchedulerParameters) {
-           ret = drivers[i]->xenDomainGetSchedulerParameters(dom, params, nparams);
-           if (ret == 0)
-               return 0;
+    if (dom->id < 0) {
+        if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Cannot change scheduler parameters"));
+            return -1;
         }
+        return xenDaemonGetSchedulerParameters(dom, params, nparams);
+    } else {
+        return xenHypervisorGetSchedulerParameters(dom, params, nparams);
     }
-    return -1;
 }
 
 static int
@@ -1553,20 +1548,19 @@ xenUnifiedDomainSetSchedulerParametersFlags(virDomainPtr dom,
                                             unsigned int flags)
 {
     xenUnifiedPrivatePtr priv = dom->conn->privateData;
-    int i, ret;
 
     virCheckFlags(0, -1);
 
-    /* do the hypervisor call last to get better error */
-    for (i = XEN_UNIFIED_NR_DRIVERS - 1; i >= 0; i--) {
-        if (priv->opened[i] && drivers[i]->xenDomainSetSchedulerParameters) {
-           ret = drivers[i]->xenDomainSetSchedulerParameters(dom, params, nparams);
-           if (ret == 0)
-               return 0;
+    if (dom->id < 0) {
+        if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Cannot change scheduler parameters"));
+            return -1;
         }
+        return xenDaemonSetSchedulerParameters(dom, params, nparams);
+    } else {
+        return xenHypervisorSetSchedulerParameters(dom, params, nparams);
     }
-
-    return -1;
 }
 
 static int
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index e8c2958..e33610d 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -82,21 +82,6 @@ extern int xenRegister (void);
      VIR_MIGRATE_PAUSED |                       \
      VIR_MIGRATE_PERSIST_DEST)
 
-/* _xenUnifiedDriver:
- *
- * Entry points into the underlying Xen drivers.  This structure
- * will eventually go away and instead xen unified will make direct
- * calls to the underlying Xen drivers.
- *
- * To reiterate - the goal is to remove elements from this structure
- * until it is empty, replacing indirect calls through this
- * structure with direct calls in xen_unified.c.
- */
-struct xenUnifiedDriver {
-    virDrvDomainGetSchedulerType xenDomainGetSchedulerType;
-    virDrvDomainGetSchedulerParameters xenDomainGetSchedulerParameters;
-    virDrvDomainSetSchedulerParameters xenDomainSetSchedulerParameters;
-};
 
 typedef struct xenXMConfCache *xenXMConfCachePtr;
 typedef struct xenXMConfCache {
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index df2a93f..d7b7cfc 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -849,12 +849,6 @@ typedef struct xen_op_v2_dom xen_op_v2_dom;
 # error "unsupported platform"
 #endif
 
-struct xenUnifiedDriver xenHypervisorDriver = {
-    .xenDomainGetSchedulerType = xenHypervisorGetSchedulerType,
-    .xenDomainGetSchedulerParameters = xenHypervisorGetSchedulerParameters,
-    .xenDomainSetSchedulerParameters = xenHypervisorSetSchedulerParameters,
-};
-
 /**
  * xenHypervisorDoV0Op:
  * @handle: the handle to the Xen hypervisor
@@ -1124,12 +1118,6 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams)
     char *schedulertype = NULL;
     xenUnifiedPrivatePtr priv = domain->conn->privateData;
 
-    if (domain->id < 0) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("domain is not running"));
-        return NULL;
-    }
-
     /*
      * Support only hv_versions.dom_interface >=5
      * (Xen3.1.0 or later)
@@ -1194,13 +1182,6 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
 {
     xenUnifiedPrivatePtr priv = domain->conn->privateData;
 
-
-    if (domain->id < 0) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("domain is not running"));
-        return -1;
-    }
-
     /*
      * Support only hv_versions.dom_interface >=5
      * (Xen3.1.0 or later)
@@ -1303,12 +1284,6 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain,
                                        NULL) < 0)
         return -1;
 
-    if (domain->id < 0) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("domain is not running"));
-        return -1;
-    }
-
     /*
      * Support only hv_versions.dom_interface >=5
      * (Xen3.1.0 or later)
diff --git a/src/xen/xen_hypervisor.h b/src/xen/xen_hypervisor.h
index bd36bf7..8507bd0 100644
--- a/src/xen/xen_hypervisor.h
+++ b/src/xen/xen_hypervisor.h
@@ -36,7 +36,6 @@ struct xenHypervisorVersions {
     int dom_interface; /* -1,3,4,5,6,7 */
 };
 
-extern struct xenUnifiedDriver xenHypervisorDriver;
 int xenHypervisorInit(struct xenHypervisorVersions *override_versions);
 
 virCapsPtr xenHypervisorMakeCapabilities (virConnectPtr conn);
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 49ef256..87b8875 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2975,7 +2975,7 @@ error:
  * Returns a scheduler name (credit or sedf) which must be freed by the
  * caller or NULL in case of failure
  */
-static char *
+char *
 xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
 {
     xenUnifiedPrivatePtr priv = domain->conn->privateData;
@@ -3040,7 +3040,7 @@ error:
  *
  * Returns 0 or -1 in case of failure
  */
-static int
+int
 xenDaemonGetSchedulerParameters(virDomainPtr domain,
                                 virTypedParameterPtr params,
                                 int *nparams)
@@ -3142,7 +3142,7 @@ error:
  *
  * Returns 0 or -1 in case of failure
  */
-static int
+int
 xenDaemonSetSchedulerParameters(virDomainPtr domain,
                                 virTypedParameterPtr params,
                                 int nparams)
@@ -3331,12 +3331,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain,
     return ret;
 }
 
-struct xenUnifiedDriver xenDaemonDriver = {
-    .xenDomainGetSchedulerType = xenDaemonGetSchedulerType,
-    .xenDomainGetSchedulerParameters = xenDaemonGetSchedulerParameters,
-    .xenDomainSetSchedulerParameters = xenDaemonSetSchedulerParameters,
-};
-
 
 /**
  * virDomainXMLDevID:
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 4a8578b..7332303 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -148,10 +148,6 @@ int xenDaemonDomainGetAutostart          (virDomainPtr dom,
 int xenDaemonDomainSetAutostart          (virDomainPtr domain,
                                           int autostart);
 
-/* xen_unified calls through here. */
-extern struct xenUnifiedDriver xenDaemonDriver;
-int xenDaemonInit (void);
-
 virDomainPtr xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc);
 virDomainPtr xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
 virDomainPtr xenDaemonLookupByName(virConnectPtr conn, const char *domname);
@@ -160,4 +156,12 @@ int xenDaemonDomainMigratePerform (virDomainPtr domain, const char *cookie, int
 
 int xenDaemonDomainBlockPeek (virDomainPtr domain, const char *path, unsigned long long offset, size_t size, void *buffer);
 
+char * xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams);
+int xenDaemonGetSchedulerParameters(virDomainPtr domain,
+                                    virTypedParameterPtr params,
+                                    int *nparams);
+int xenDaemonSetSchedulerParameters(virDomainPtr domain,
+                                    virTypedParameterPtr params,
+                                    int nparams);
+
 #endif /* __XEND_INTERNAL_H_ */
-- 
1.8.1.4


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