From: "Daniel P. Berrange" <berrange(a)redhat.com>
Introduce use of a virDomainDefPtr in the domain property
APIs to simplify introduction of ACL security checks.
The virDomainPtr cannot be safely used, since the app
may have supplied mis-matching name/uuid/id fields. eg
the name points to domain X, while the uuid points to
domain Y. Resolving the virDomainPtr to a virDomainDefPtr
ensures a consistent name/uuid/id set.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/xen/xen_driver.c | 98 +++++++++++++++++++++++++++++++++++++-----------
src/xen/xen_hypervisor.c | 42 +++++++++++----------
src/xen/xen_hypervisor.h | 18 +++++----
src/xen/xend_internal.c | 44 +++++++++++++---------
src/xen/xend_internal.h | 21 ++++++++---
src/xen/xm_internal.c | 41 +++++++++++---------
src/xen/xm_internal.h | 18 ++++++---
7 files changed, 187 insertions(+), 95 deletions(-)
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 37107ff..68a86b7 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -889,18 +889,27 @@ static char *
xenUnifiedDomainGetOSType(virDomainPtr dom)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ char *ret = NULL;
+ virDomainDefPtr def;
- if (dom->id < 0) {
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (def->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to query OS type for inactive domain"));
return NULL;
} else {
- return xenDaemonDomainGetOSType(dom);
+ ret = xenHypervisorDomainGetOSType(dom->conn, def);
}
} else {
- return xenHypervisorDomainGetOSType(dom);
+ ret = xenDaemonDomainGetOSType(dom->conn, def);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
@@ -908,56 +917,92 @@ static unsigned long long
xenUnifiedDomainGetMaxMemory(virDomainPtr dom)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ unsigned long long ret = 0;
+ virDomainDefPtr def;
- if (dom->id < 0) {
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (def->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainGetMaxMemory(dom);
+ ret = xenXMDomainGetMaxMemory(dom->conn, def);
else
- return xenDaemonDomainGetMaxMemory(dom);
+ ret = xenDaemonDomainGetMaxMemory(dom->conn, def);
} else {
- return xenHypervisorGetMaxMemory(dom);
+ ret = xenHypervisorGetMaxMemory(dom->conn, def);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
xenUnifiedDomainSetMaxMemory(virDomainPtr dom, unsigned long memory)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ int ret = -1;
+ virDomainDefPtr def;
- if (dom->id < 0) {
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (def->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainSetMaxMemory(dom, memory);
+ ret = xenXMDomainSetMaxMemory(dom->conn, def, memory);
else
- return xenDaemonDomainSetMaxMemory(dom, memory);
+ ret = xenDaemonDomainSetMaxMemory(dom->conn, def, memory);
} else {
- return xenHypervisorSetMaxMemory(dom, memory);
+ ret = xenHypervisorSetMaxMemory(dom->conn, def, memory);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
xenUnifiedDomainSetMemory(virDomainPtr dom, unsigned long memory)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ int ret = -1;
+ virDomainDefPtr def;
- if (dom->id < 0 && priv->xendConfigVersion <
XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainSetMemory(dom, memory);
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (def->id < 0 && priv->xendConfigVersion <
XEND_CONFIG_VERSION_3_0_4)
+ ret = xenXMDomainSetMemory(dom->conn, def, memory);
else
- return xenDaemonDomainSetMemory(dom, memory);
+ ret = xenDaemonDomainSetMemory(dom->conn, def, memory);
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
xenUnifiedDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ int ret = -1;
+ virDomainDefPtr def;
- if (dom->id < 0) {
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (def->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainGetInfo(dom, info);
+ ret = xenXMDomainGetInfo(dom->conn, def, info);
else
- return xenDaemonDomainGetInfo(dom, info);
+ ret = xenDaemonDomainGetInfo(dom->conn, def, info);
} else {
- return xenHypervisorGetDomainInfo(dom, info);
+ ret = xenHypervisorGetDomainInfo(dom->conn, def, info);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
@@ -967,17 +1012,26 @@ xenUnifiedDomainGetState(virDomainPtr dom,
unsigned int flags)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ int ret = -1;
+ virDomainDefPtr def;
virCheckFlags(0, -1);
- if (dom->id < 0) {
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
+ if (def->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainGetState(dom, state, reason);
+ ret = xenXMDomainGetState(dom->conn, def, state, reason);
else
- return xenDaemonDomainGetState(dom, state, reason);
+ ret = xenDaemonDomainGetState(dom->conn, def, state, reason);
} else {
- return xenHypervisorGetDomainState(dom, state, reason);
+ ret = xenHypervisorGetDomainState(dom->conn, def, state, reason);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 55b0930..423ce85 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2508,27 +2508,28 @@ xenHypervisorGetCapabilities(virConnectPtr conn)
char *
-xenHypervisorDomainGetOSType(virDomainPtr dom)
+xenHypervisorDomainGetOSType(virConnectPtr conn,
+ virDomainDefPtr def)
{
- xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
xen_getdomaininfo dominfo;
char *ostype = NULL;
/* HV's earlier than 3.1.0 don't include the HVM flags in guests status*/
if (hv_versions.hypervisor < 2 ||
hv_versions.dom_interface < 4) {
- return xenDaemonDomainGetOSType(dom);
+ return xenDaemonDomainGetOSType(conn, def);
}
XEN_GETDOMAININFO_CLEAR(dominfo);
- if (virXen_getdomaininfo(priv->handle, dom->id, &dominfo) < 0) {
+ if (virXen_getdomaininfo(priv->handle, def->id, &dominfo) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get domain details"));
return NULL;
}
- if (XEN_GETDOMAININFO_DOMAIN(dominfo) != dom->id) {
+ if (XEN_GETDOMAININFO_DOMAIN(dominfo) != def->id) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get domain details"));
return NULL;
@@ -2678,9 +2679,10 @@ xenHypervisorGetMaxVcpus(virConnectPtr conn ATTRIBUTE_UNUSED,
* Returns the memory size in kilobytes or 0 in case of error.
*/
unsigned long
-xenHypervisorGetMaxMemory(virDomainPtr dom)
+xenHypervisorGetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def)
{
- xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
xen_getdomaininfo dominfo;
int ret;
@@ -2692,9 +2694,9 @@ xenHypervisorGetMaxMemory(virDomainPtr dom)
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(priv->handle, dom->id, &dominfo);
+ ret = virXen_getdomaininfo(priv->handle, def->id, &dominfo);
- if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != dom->id))
+ if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != def->id))
return 0;
return (unsigned long) XEN_GETDOMAININFO_MAX_PAGES(dominfo) * kb_per_pages;
@@ -2788,9 +2790,11 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id,
virDomainInfoPtr info)
* Returns 0 in case of success, -1 in case of error.
*/
int
-xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
+xenHypervisorGetDomainInfo(virConnectPtr conn,
+ virDomainDefPtr def,
+ virDomainInfoPtr info)
{
- return xenHypervisorGetDomInfo(domain->conn, domain->id, info);
+ return xenHypervisorGetDomInfo(conn, def->id, info);
}
/**
@@ -2804,13 +2808,14 @@ xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr
info)
* Returns 0 in case of success, -1 in case of error.
*/
int
-xenHypervisorGetDomainState(virDomainPtr domain,
+xenHypervisorGetDomainState(virConnectPtr conn,
+ virDomainDefPtr def,
int *state,
int *reason)
{
virDomainInfo info;
- if (xenHypervisorGetDomInfo(domain->conn, domain->id, &info) < 0)
+ if (xenHypervisorGetDomInfo(conn, def->id, &info) < 0)
return -1;
*state = info.state;
@@ -2899,15 +2904,14 @@ xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn,
* Returns 0 in case of success, -1 in case of error.
*/
int
-xenHypervisorSetMaxMemory(virDomainPtr domain, unsigned long memory)
+xenHypervisorSetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory)
{
int ret;
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
-
- if (domain->id < 0)
- return -1;
+ xenUnifiedPrivatePtr priv = conn->privateData;
- ret = virXen_setmaxmem(priv->handle, domain->id, memory);
+ ret = virXen_setmaxmem(priv->handle, def->id, memory);
if (ret < 0)
return -1;
return 0;
diff --git a/src/xen/xen_hypervisor.h b/src/xen/xen_hypervisor.h
index 1d44a92..9ee1f13 100644
--- a/src/xen/xen_hypervisor.h
+++ b/src/xen/xen_hypervisor.h
@@ -50,7 +50,8 @@ virDomainDefPtr
xenHypervisorLookupDomainByUUID (virConnectPtr conn,
const unsigned char *uuid);
char *
- xenHypervisorDomainGetOSType (virDomainPtr dom);
+ xenHypervisorDomainGetOSType (virConnectPtr conn,
+ virDomainDefPtr def);
int
xenHypervisorOpen (virConnectPtr conn,
@@ -64,23 +65,26 @@ virCapsPtr
virArch hostarch,
FILE *cpuinfo,
FILE *capabilities);
-char *
- xenHypervisorGetCapabilities (virConnectPtr conn);
+char * xenHypervisorGetCapabilities (virConnectPtr conn);
unsigned long
- xenHypervisorGetMaxMemory(virDomainPtr dom);
+ xenHypervisorGetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def);
int xenHypervisorGetMaxVcpus (virConnectPtr conn,
const char *type);
-int xenHypervisorGetDomainInfo (virDomainPtr domain,
+int xenHypervisorGetDomainInfo (virConnectPtr conn,
+ virDomainDefPtr def,
virDomainInfoPtr info)
ATTRIBUTE_NONNULL (1);
-int xenHypervisorGetDomainState (virDomainPtr domain,
+int xenHypervisorGetDomainState (virConnectPtr conn,
+ virDomainDefPtr def,
int *state,
int *reason)
ATTRIBUTE_NONNULL (1);
int xenHypervisorGetDomInfo (virConnectPtr conn,
int id,
virDomainInfoPtr info);
-int xenHypervisorSetMaxMemory (virDomainPtr domain,
+int xenHypervisorSetMaxMemory (virConnectPtr conn,
+ virDomainDefPtr def,
unsigned long memory)
ATTRIBUTE_NONNULL (1);
int xenHypervisorCheckID (virConnectPtr conn,
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index f8bd72b..c10567c 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -890,7 +890,7 @@ xend_detect_config_version(virConnectPtr conn)
*/
static int
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
-sexpr_to_xend_domain_state(virDomainPtr domain, const struct sexpr *root)
+sexpr_to_xend_domain_state(virDomainDefPtr def, const struct sexpr *root)
{
const char *flags;
int state = VIR_DOMAIN_NOSTATE;
@@ -908,7 +908,7 @@ sexpr_to_xend_domain_state(virDomainPtr domain, const struct sexpr
*root)
state = VIR_DOMAIN_BLOCKED;
else if (strchr(flags, 'r'))
state = VIR_DOMAIN_RUNNING;
- } else if (domain->id < 0 || sexpr_int(root, "domain/status") == 0)
{
+ } else if (def->id < 0 || sexpr_int(root, "domain/status") == 0) {
/* As far as I can see the domain->id is a bad sign for checking
* inactive domains as this is inaccurate after the domain has
* been running once. However domain/status from xend seems to
@@ -933,13 +933,13 @@ sexpr_to_xend_domain_state(virDomainPtr domain, const struct sexpr
*root)
* Returns 0 in case of success, -1 in case of error
*/
static int
-sexpr_to_xend_domain_info(virDomainPtr domain,
+sexpr_to_xend_domain_info(virDomainDefPtr def,
const struct sexpr *root,
virDomainInfoPtr info)
{
int vcpus;
- info->state = sexpr_to_xend_domain_state(domain, root);
+ info->state = sexpr_to_xend_domain_state(def, root);
info->memory = sexpr_u64(root, "domain/memory") << 10;
info->maxMem = sexpr_u64(root, "domain/maxmem") << 10;
info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
@@ -1374,13 +1374,14 @@ xenDaemonDomainDestroy(virConnectPtr conn, virDomainDefPtr def)
* freed by the caller.
*/
char *
-xenDaemonDomainGetOSType(virDomainPtr domain)
+xenDaemonDomainGetOSType(virConnectPtr conn,
+ virDomainDefPtr def)
{
char *type;
struct sexpr *root;
/* can we ask for a subset ? worth it ? */
- root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1",
domain->name);
+ root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
if (root == NULL)
return NULL;
@@ -1489,13 +1490,13 @@ xenDaemonDomainRestore(virConnectPtr conn, const char *filename)
* Returns the memory size in kilobytes or 0 in case of error.
*/
unsigned long long
-xenDaemonDomainGetMaxMemory(virDomainPtr domain)
+xenDaemonDomainGetMaxMemory(virConnectPtr conn, virDomainDefPtr def)
{
unsigned long long ret = 0;
struct sexpr *root;
/* can we ask for a subset ? worth it ? */
- root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1",
domain->name);
+ root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
if (root == NULL)
return 0;
@@ -1518,12 +1519,14 @@ xenDaemonDomainGetMaxMemory(virDomainPtr domain)
* Returns 0 for success; -1 (with errno) on error
*/
int
-xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
+xenDaemonDomainSetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory)
{
char buf[1024];
snprintf(buf, sizeof(buf), "%lu", VIR_DIV_UP(memory, 1024));
- return xend_op(domain->conn, domain->name, "op",
"maxmem_set", "memory",
+ return xend_op(conn, def->name, "op", "maxmem_set",
"memory",
buf, NULL);
}
@@ -1544,12 +1547,14 @@ xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long
memory)
* Returns 0 for success; -1 (with errno) on error
*/
int
-xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory)
+xenDaemonDomainSetMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory)
{
char buf[1024];
snprintf(buf, sizeof(buf), "%lu", VIR_DIV_UP(memory, 1024));
- return xend_op(domain->conn, domain->name, "op",
"mem_target_set",
+ return xend_op(conn, def->name, "op", "mem_target_set",
"target", buf, NULL);
}
@@ -1640,16 +1645,18 @@ xenDaemonDomainGetXMLDesc(virDomainPtr domain,
* Returns 0 in case of success, -1 in case of error
*/
int
-xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
+xenDaemonDomainGetInfo(virConnectPtr conn,
+ virDomainDefPtr def,
+ virDomainInfoPtr info)
{
struct sexpr *root;
int ret;
- root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1",
domain->name);
+ root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
if (root == NULL)
return -1;
- ret = sexpr_to_xend_domain_info(domain, root, info);
+ ret = sexpr_to_xend_domain_info(def, root, info);
sexpr_free(root);
return ret;
}
@@ -1666,17 +1673,18 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr
info)
* Returns 0 in case of success, -1 in case of error
*/
int
-xenDaemonDomainGetState(virDomainPtr domain,
+xenDaemonDomainGetState(virConnectPtr conn,
+ virDomainDefPtr def,
int *state,
int *reason)
{
struct sexpr *root;
- root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1",
domain->name);
+ root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
if (!root)
return -1;
- *state = sexpr_to_xend_domain_state(domain, root);
+ *state = sexpr_to_xend_domain_state(def, root);
if (reason)
*reason = 0;
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 4a6b406..87e0a0f 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -96,18 +96,27 @@ int xenDaemonDomainSave(virDomainPtr domain, const char *filename);
int xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename,
unsigned int flags);
int xenDaemonDomainRestore(virConnectPtr conn, const char *filename);
-int xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory);
-int xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory);
-int xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
-int xenDaemonDomainGetState(virDomainPtr domain,
+int xenDaemonDomainSetMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory);
+int xenDaemonDomainSetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory);
+int xenDaemonDomainGetInfo(virConnectPtr conn,
+ virDomainDefPtr def,
+ virDomainInfoPtr info);
+int xenDaemonDomainGetState(virConnectPtr conn,
+ virDomainDefPtr def,
int *state,
int *reason);
char *xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags,
const char *cpus);
-unsigned long long xenDaemonDomainGetMaxMemory(virDomainPtr domain);
+unsigned long long xenDaemonDomainGetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def);
char **xenDaemonListDomainsOld(virConnectPtr xend);
-char *xenDaemonDomainGetOSType(virDomainPtr domain);
+char *xenDaemonDomainGetOSType(virConnectPtr conn,
+ virDomainDefPtr def);
int xenDaemonNumOfDefinedDomains(virConnectPtr conn);
int xenDaemonListDefinedDomains(virConnectPtr conn,
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index f4e8ea0..ce44e39 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -446,7 +446,8 @@ xenXMClose(virConnectPtr conn)
* Since these are all offline domains, the state is always SHUTOFF.
*/
int
-xenXMDomainGetState(virDomainPtr domain ATTRIBUTE_UNUSED,
+xenXMDomainGetState(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainDefPtr def ATTRIBUTE_UNUSED,
int *state,
int *reason)
{
@@ -463,15 +464,17 @@ xenXMDomainGetState(virDomainPtr domain ATTRIBUTE_UNUSED,
* VCPUs and memory.
*/
int
-xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
+xenXMDomainGetInfo(virConnectPtr conn,
+ virDomainDefPtr def,
+ virDomainInfoPtr info)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name)))
goto error;
if (!(entry = virHashLookup(priv->configCache, filename)))
@@ -530,9 +533,11 @@ cleanup:
* Update amount of memory in the config file
*/
int
-xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory)
+xenXMDomainSetMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
int ret = -1;
@@ -546,7 +551,7 @@ xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory)
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name)))
goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename)))
@@ -559,7 +564,7 @@ xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory)
/* If this fails, should we try to undo our changes to the
* in-memory representation of the config file. I say not!
*/
- if (xenXMConfigSaveFile(domain->conn, entry->filename, entry->def) < 0)
+ if (xenXMConfigSaveFile(conn, entry->filename, entry->def) < 0)
goto cleanup;
ret = 0;
@@ -572,9 +577,11 @@ cleanup:
* Update maximum memory limit in config
*/
int
-xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
+xenXMDomainSetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
int ret = -1;
@@ -588,7 +595,7 @@ xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name)))
goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename)))
@@ -601,7 +608,7 @@ xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
/* If this fails, should we try to undo our changes to the
* in-memory representation of the config file. I say not!
*/
- if (xenXMConfigSaveFile(domain->conn, entry->filename, entry->def) < 0)
+ if (xenXMConfigSaveFile(conn, entry->filename, entry->def) < 0)
goto cleanup;
ret = 0;
@@ -614,19 +621,17 @@ cleanup:
* Get max memory limit from config
*/
unsigned long long
-xenXMDomainGetMaxMemory(virDomainPtr domain)
+xenXMDomainGetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
unsigned long long ret = 0;
- if (domain->id != -1)
- return 0;
-
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name)))
goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename)))
diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h
index 0e55897..0ae32bc 100644
--- a/src/xen/xm_internal.h
+++ b/src/xen/xm_internal.h
@@ -37,14 +37,22 @@ int xenXMConfigCacheRemoveFile(virConnectPtr conn, const char
*filename);
int xenXMOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags);
int xenXMClose(virConnectPtr conn);
const char *xenXMGetType(virConnectPtr conn);
-int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
-int xenXMDomainGetState(virDomainPtr domain,
+int xenXMDomainGetInfo(virConnectPtr conn,
+ virDomainDefPtr def,
+ virDomainInfoPtr info);
+int xenXMDomainGetState(virConnectPtr conn,
+ virDomainDefPtr def,
int *state,
int *reason);
char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags);
-int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory);
-int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory);
-unsigned long long xenXMDomainGetMaxMemory(virDomainPtr domain);
+int xenXMDomainSetMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory);
+int xenXMDomainSetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned long memory);
+unsigned long long xenXMDomainGetMaxMemory(virConnectPtr conn,
+ virDomainDefPtr def);
int xenXMDomainSetVcpus(virDomainPtr domain, unsigned int vcpus);
int xenXMDomainSetVcpusFlags(virDomainPtr domain, unsigned int vcpus,
unsigned int flags);
--
1.8.1.4