提交 b5961c53 编写于 作者: D Daniel P. Berrange

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: NDaniel P. Berrange <berrange@redhat.com>
上级 7a802958
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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,
......
......@@ -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);
......
......@@ -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)))
......
......@@ -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);
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册