From b5961c53d9e6e12d2628b985a46018147914cf0f Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 30 Apr 2013 16:42:29 +0100 Subject: [PATCH] Simplify the Xen domain get info/state driver methods Make the xenUnifiedDomainGetInfo and xenUnifiedDomainGetState drivers call the correct sub-driver APIs directly. Signed-off-by: Daniel P. Berrange --- src/xen/xen_driver.c | 52 +++++------------- src/xen/xen_driver.h | 1 - src/xen/xen_hypervisor.c | 14 +---- src/xen/xen_hypervisor.h | 3 +- src/xen/xend_internal.c | 15 +---- src/xen/xend_internal.h | 3 +- src/xen/xm_internal.c | 15 +---- src/xen/xm_internal.h | 3 +- src/xen/xs_internal.c | 115 --------------------------------------- src/xen/xs_internal.h | 9 --- 10 files changed, 23 insertions(+), 207 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index ee387676b5..64b7c26b9e 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_XS_OFFSET] = &xenStoreDriver, [XEN_UNIFIED_XM_OFFSET] = &xenXMDriver, }; @@ -853,15 +852,15 @@ static int xenUnifiedDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) { xenUnifiedPrivatePtr priv = dom->conn->privateData; - int i; - - for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) - if (priv->opened[i] && - drivers[i]->xenDomainGetInfo && - drivers[i]->xenDomainGetInfo(dom, info) == 0) - return 0; - return -1; + if (dom->id < 0) { + if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) + return xenXMDomainGetInfo(dom, info); + else + return xenDaemonDomainGetInfo(dom, info); + } else { + return xenHypervisorGetDomainInfo(dom, info); + } } static int @@ -871,38 +870,17 @@ xenUnifiedDomainGetState(virDomainPtr dom, unsigned int flags) { xenUnifiedPrivatePtr priv = dom->conn->privateData; - int ret; virCheckFlags(0, -1); - /* trying drivers in the same order as GetInfo for consistent results: - * hypervisor, xend, xs, and xm */ - - if (priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET]) { - ret = xenHypervisorGetDomainState(dom, state, reason, flags); - if (ret >= 0) - return ret; - } - - if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) { - ret = xenDaemonDomainGetState(dom, state, reason, flags); - if (ret >= 0) - return ret; - } - - if (priv->opened[XEN_UNIFIED_XS_OFFSET]) { - ret = xenStoreDomainGetState(dom, state, reason, flags); - if (ret >= 0) - return ret; - } - - if (priv->opened[XEN_UNIFIED_XM_OFFSET]) { - ret = xenXMDomainGetState(dom, state, reason, flags); - if (ret >= 0) - return ret; + if (dom->id < 0) { + if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) + return xenXMDomainGetState(dom, state, reason); + else + return xenDaemonDomainGetState(dom, state, reason); + } else { + return xenHypervisorGetDomainState(dom, state, reason); } - - return -1; } static int diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h index 4509161da5..953da64677 100644 --- a/src/xen/xen_driver.h +++ b/src/xen/xen_driver.h @@ -93,7 +93,6 @@ extern int xenRegister (void); * structure with direct calls in xen_unified.c. */ struct xenUnifiedDriver { - virDrvDomainGetInfo xenDomainGetInfo; virDrvDomainPinVcpu xenDomainPinVcpu; virDrvDomainGetVcpus xenDomainGetVcpus; virDrvConnectListDefinedDomains xenListDefinedDomains; diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 38f0e55b53..3703945cad 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -871,7 +871,6 @@ typedef struct xen_op_v2_dom xen_op_v2_dom; #endif struct xenUnifiedDriver xenHypervisorDriver = { - .xenDomainGetInfo = xenHypervisorGetDomainInfo, .xenDomainPinVcpu = xenHypervisorPinVcpu, .xenDomainGetVcpus = xenHypervisorGetVcpus, .xenDomainGetSchedulerType = xenHypervisorGetSchedulerType, @@ -2880,11 +2879,7 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info) int xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) { - if (domain->id < 0) - return -1; - return xenHypervisorGetDomInfo(domain->conn, domain->id, info); - } /** @@ -2892,7 +2887,6 @@ xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) * @domain: pointer to the domain block * @state: returned state of the domain * @reason: returned reason for the state - * @flags: additional flags, 0 for now * * Do a hypervisor call to get the related set of domain information. * @@ -2901,16 +2895,10 @@ xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) int xenHypervisorGetDomainState(virDomainPtr domain, int *state, - int *reason, - unsigned int flags) + int *reason) { virDomainInfo info; - virCheckFlags(0, -1); - - if (domain->id < 0) - return -1; - if (xenHypervisorGetDomInfo(domain->conn, domain->id, &info) < 0) return -1; diff --git a/src/xen/xen_hypervisor.h b/src/xen/xen_hypervisor.h index 9748cf8b28..b36fcca92a 100644 --- a/src/xen/xen_hypervisor.h +++ b/src/xen/xen_hypervisor.h @@ -76,8 +76,7 @@ int xenHypervisorGetDomainInfo (virDomainPtr domain, ATTRIBUTE_NONNULL (1); int xenHypervisorGetDomainState (virDomainPtr domain, int *state, - int *reason, - unsigned int flags) + int *reason) ATTRIBUTE_NONNULL (1); int xenHypervisorGetDomInfo (virConnectPtr conn, int id, diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index b4f4a92695..d7dc8f18c1 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1648,10 +1648,6 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { struct sexpr *root; int ret; - xenUnifiedPrivatePtr priv = domain->conn->privateData; - - if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) - return -1; root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name); if (root == NULL) @@ -1668,7 +1664,6 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) * @domain: a domain object * @state: returned domain's state * @reason: returned reason for the state - * @flags: additional flags, 0 for now * * This method looks up domain state and reason. * @@ -1677,17 +1672,10 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) int xenDaemonDomainGetState(virDomainPtr domain, int *state, - int *reason, - unsigned int flags) + int *reason) { - xenUnifiedPrivatePtr priv = domain->conn->privateData; struct sexpr *root; - virCheckFlags(0, -1); - - if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) - return -1; - root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name); if (!root) return -1; @@ -3425,7 +3413,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain, } struct xenUnifiedDriver xenDaemonDriver = { - .xenDomainGetInfo = xenDaemonDomainGetInfo, .xenDomainPinVcpu = xenDaemonDomainPinVcpu, .xenDomainGetVcpus = xenDaemonDomainGetVcpus, .xenListDefinedDomains = xenDaemonListDefinedDomains, diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h index 9681068203..fd661c9cdd 100644 --- a/src/xen/xend_internal.h +++ b/src/xen/xend_internal.h @@ -101,8 +101,7 @@ int xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory); int xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info); int xenDaemonDomainGetState(virDomainPtr domain, int *state, - int *reason, - unsigned int flags); + int *reason); char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags, const char *cpus); unsigned long long xenDaemonDomainGetMaxMemory(virDomainPtr domain); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index f37b0e60da..f2349b2101 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -81,7 +81,6 @@ static int xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml, #define XM_XML_ERROR "Invalid xml" struct xenUnifiedDriver xenXMDriver = { - .xenDomainGetInfo = xenXMDomainGetInfo, .xenDomainPinVcpu = xenXMDomainPinVcpu, .xenListDefinedDomains = xenXMListDefinedDomains, .xenNumOfDefinedDomains = xenXMNumOfDefinedDomains, @@ -462,15 +461,10 @@ xenXMClose(virConnectPtr conn) * Since these are all offline domains, the state is always SHUTOFF. */ int -xenXMDomainGetState(virDomainPtr domain, - int *state, int *reason, - unsigned int flags) +xenXMDomainGetState(virDomainPtr domain ATTRIBUTE_UNUSED, + int *state, + int *reason) { - virCheckFlags(0, -1); - - if (domain->id != -1) - return -1; - *state = VIR_DOMAIN_SHUTOFF; if (reason) *reason = 0; @@ -490,9 +484,6 @@ xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) const char *filename; xenXMConfCachePtr entry; - if (domain->id != -1) - return -1; - xenUnifiedLock(priv); if (!(filename = virHashLookup(priv->nameConfigMap, domain->name))) diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h index 3f3bd5172a..2a5d8684e0 100644 --- a/src/xen/xm_internal.h +++ b/src/xen/xm_internal.h @@ -42,8 +42,7 @@ const char *xenXMGetType(virConnectPtr conn); int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info); int xenXMDomainGetState(virDomainPtr domain, int *state, - int *reason, - unsigned int flags); + int *reason); char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags); int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory); int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory); diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c index dd1f2a065b..496c30bd74 100644 --- a/src/xen/xs_internal.c +++ b/src/xen/xs_internal.c @@ -56,32 +56,11 @@ static void xenStoreWatchEvent(int watch, int fd, int events, void *data); static void xenStoreWatchListFree(xenStoreWatchListPtr list); -struct xenUnifiedDriver xenStoreDriver = { - .xenDomainGetInfo = xenStoreGetDomainInfo, -}; - /************************************************************************ * * * Helper internal APIs * * * ************************************************************************/ -/** - * virConnectDoStoreList: - * @conn: pointer to the hypervisor connection - * @path: the absolute path of the directory in the store to list - * @nb: OUT pointer to the number of items found - * - * Internal API querying the Xenstore for a list - * - * Returns a string which must be freed by the caller or NULL in case of error - */ -static char ** -virConnectDoStoreList(virConnectPtr conn, const char *path, unsigned int *nb) -{ - xenUnifiedPrivatePtr priv = conn->privateData; - - return xs_directory(priv->xshandle, 0, path, nb); -} /** * virDomainDoStoreQuery: @@ -234,100 +213,6 @@ xenStoreClose(virConnectPtr conn) return 0; } -/** - * xenStoreGetDomainInfo: - * @domain: pointer to the domain block - * @info: the place where information should be stored - * - * Do a hypervisor call to get the related set of domain information. - * - * Returns 0 in case of success, -1 in case of error. - */ -int -xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) -{ - char *tmp, **tmp2; - unsigned int nb_vcpus; - char request[200]; - xenUnifiedPrivatePtr priv = domain->conn->privateData; - - if (priv->xshandle == NULL || domain->id == -1) - return -1; - - tmp = virDomainDoStoreQuery(domain->conn, domain->id, "running"); - if (tmp != NULL) { - if (tmp[0] == '1') - info->state = VIR_DOMAIN_RUNNING; - VIR_FREE(tmp); - } else { - info->state = VIR_DOMAIN_NOSTATE; - } - tmp = virDomainDoStoreQuery(domain->conn, domain->id, "memory/target"); - if (tmp != NULL) { - info->memory = atol(tmp); - info->maxMem = atol(tmp); - VIR_FREE(tmp); - } else { - info->memory = 0; - info->maxMem = 0; - } -#if 0 - /* doesn't seems to work */ - tmp = virDomainDoStoreQuery(domain->conn, domain->id, "cpu_time"); - if (tmp != NULL) { - info->cpuTime = atol(tmp); - VIR_FREE(tmp); - } else { - info->cpuTime = 0; - } -#endif - snprintf(request, 199, "/local/domain/%d/cpu", domain->id); - request[199] = 0; - tmp2 = virConnectDoStoreList(domain->conn, request, &nb_vcpus); - if (tmp2 != NULL) { - info->nrVirtCpu = nb_vcpus; - VIR_FREE(tmp2); - } - return 0; -} - -/** - * xenStoreDomainGetState: - * @domain: pointer to the domain block - * @state: returned domain's state - * @reason: returned state reason - * @flags: additional flags, 0 for now - * - * Returns 0 in case of success, -1 in case of error. - */ -int -xenStoreDomainGetState(virDomainPtr domain, - int *state, - int *reason, - unsigned int flags) -{ - char *running; - - virCheckFlags(0, -1); - - if (domain->id == -1) - return -1; - - running = virDomainDoStoreQuery(domain->conn, domain->id, "running"); - - if (running && *running == '1') - *state = VIR_DOMAIN_RUNNING; - else - *state = VIR_DOMAIN_NOSTATE; - if (reason) - *reason = 0; - - VIR_FREE(running); - - return 0; -} - - /** * xenStoreNumOfDomains: * @conn: pointer to the hypervisor connection diff --git a/src/xen/xs_internal.h b/src/xen/xs_internal.h index 4390733393..bc5bd8c6b7 100644 --- a/src/xen/xs_internal.h +++ b/src/xen/xs_internal.h @@ -26,19 +26,10 @@ # include "internal.h" # include "driver.h" -extern struct xenUnifiedDriver xenStoreDriver; -int xenStoreInit (void); - int xenStoreOpen (virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags); int xenStoreClose (virConnectPtr conn); -int xenStoreGetDomainInfo (virDomainPtr domain, - virDomainInfoPtr info); -int xenStoreDomainGetState (virDomainPtr domain, - int *state, - int *reason, - unsigned int flags); int xenStoreNumOfDomains (virConnectPtr conn); int xenStoreListDomains (virConnectPtr conn, int *ids, -- GitLab