From: "Daniel P. Berrange" <berrange(a)redhat.com>
Introduce use of a virDomainDefPtr in the domain VCPU
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 | 84 ++++++++++++++++++++++++++++++++++++++++--------
src/xen/xen_hypervisor.c | 42 ++++++++++++------------
src/xen/xen_hypervisor.h | 9 ++++--
src/xen/xend_internal.c | 81 ++++++++++++++++++++++++++--------------------
src/xen/xend_internal.h | 17 ++++++----
src/xen/xm_internal.c | 30 +++++++++--------
src/xen/xm_internal.h | 19 ++++++++---
7 files changed, 187 insertions(+), 95 deletions(-)
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 8b7dec9..04cb69d 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -647,11 +647,30 @@ xenUnifiedConnectNumOfDomains(virConnectPtr conn)
static virDomainPtr
xenUnifiedDomainCreateXML(virConnectPtr conn,
- const char *xmlDesc, unsigned int flags)
+ const char *xml,
+ unsigned int flags)
{
+ xenUnifiedPrivatePtr priv = conn->privateData;
+ virDomainDefPtr def = NULL;
+ virDomainPtr ret = NULL;
+
virCheckFlags(0, NULL);
- return xenDaemonCreateXML(conn, xmlDesc);
+ if (!(def = virDomainDefParseString(xml, priv->caps, priv->xmlopt,
+ 1 << VIR_DOMAIN_VIRT_XEN,
+ VIR_DOMAIN_XML_INACTIVE)))
+ goto cleanup;
+
+ if (xenDaemonCreateXML(conn, def) < 0)
+ goto cleanup;
+
+ ret = virGetDomain(conn, def->name, def->uuid);
+ if (ret)
+ ret->id = def->id;
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static virDomainPtr
@@ -1182,6 +1201,8 @@ xenUnifiedDomainSetVcpusFlags(virDomainPtr dom, unsigned int
nvcpus,
unsigned int flags)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ virDomainDefPtr def = NULL;
+ int ret = -1;
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
VIR_DOMAIN_VCPU_CONFIG |
@@ -1202,13 +1223,20 @@ xenUnifiedDomainSetVcpusFlags(virDomainPtr dom, unsigned int
nvcpus,
return -1;
}
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
/* Try non-hypervisor methods first, then hypervisor direct method
* as a last resort.
*/
if (dom->id < 0 && priv->xendConfigVersion <
XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainSetVcpusFlags(dom, nvcpus, flags);
+ ret = xenXMDomainSetVcpusFlags(dom->conn, def, nvcpus, flags);
else
- return xenDaemonDomainSetVcpusFlags(dom, nvcpus, flags);
+ ret = xenDaemonDomainSetVcpusFlags(dom->conn, def, nvcpus, flags);
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
@@ -1231,15 +1259,24 @@ xenUnifiedDomainPinVcpu(virDomainPtr dom, unsigned int vcpu,
unsigned char *cpumap, int maplen)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ virDomainDefPtr def = NULL;
+ int ret = -1;
+
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
if (dom->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainPinVcpu(dom, vcpu, cpumap, maplen);
+ ret = xenXMDomainPinVcpu(dom->conn, def, vcpu, cpumap, maplen);
else
- return xenDaemonDomainPinVcpu(dom, vcpu, cpumap, maplen);
+ ret = xenDaemonDomainPinVcpu(dom->conn, def, vcpu, cpumap, maplen);
} else {
- return xenHypervisorPinVcpu(dom, vcpu, cpumap, maplen);
+ ret = xenHypervisorPinVcpu(dom->conn, def, vcpu, cpumap, maplen);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
@@ -1248,39 +1285,58 @@ xenUnifiedDomainGetVcpus(virDomainPtr dom,
unsigned char *cpumaps, int maplen)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ virDomainDefPtr def = NULL;
+ int ret = -1;
+
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
if (dom->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get VCPUs of inactive domain"));
- return -1;
+ goto cleanup;
} else {
- return xenDaemonDomainGetVcpus(dom, info, maxinfo, cpumaps, maplen);
+ ret = xenDaemonDomainGetVcpus(dom->conn, def, info, maxinfo, cpumaps,
maplen);
}
} else {
- return xenHypervisorGetVcpus(dom, info, maxinfo, cpumaps, maplen);
+ ret = xenHypervisorGetVcpus(dom->conn, def, info, maxinfo, cpumaps, maplen);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
xenUnifiedDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
{
xenUnifiedPrivatePtr priv = dom->conn->privateData;
+ virDomainDefPtr def = NULL;
+ int ret = -1;
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
VIR_DOMAIN_VCPU_CONFIG |
VIR_DOMAIN_VCPU_MAXIMUM, -1);
+ if (!(def = xenGetDomainDefForDom(dom)))
+ goto cleanup;
+
if (dom->id < 0) {
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return xenXMDomainGetVcpusFlags(dom, flags);
+ ret = xenXMDomainGetVcpusFlags(dom->conn, def, flags);
else
- return xenDaemonDomainGetVcpusFlags(dom, flags);
+ ret = xenDaemonDomainGetVcpusFlags(dom->conn, def, flags);
} else {
if (flags == (VIR_DOMAIN_VCPU_CONFIG | VIR_DOMAIN_VCPU_MAXIMUM))
- return xenHypervisorGetVcpuMax(dom);
+ ret = xenHypervisorGetVcpuMax(dom->conn, def);
else
- return xenDaemonDomainGetVcpusFlags(dom, flags);
+ ret = xenDaemonDomainGetVcpusFlags(dom->conn, def, flags);
}
+
+cleanup:
+ virDomainDefFree(def);
+ return ret;
}
static int
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 423ce85..b97b329 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2931,16 +2931,16 @@ xenHypervisorSetMaxMemory(virConnectPtr conn,
*/
int
-xenHypervisorPinVcpu(virDomainPtr domain, unsigned int vcpu,
- unsigned char *cpumap, int maplen)
+xenHypervisorPinVcpu(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned int vcpu,
+ unsigned char *cpumap,
+ int maplen)
{
int ret;
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
-
- if (domain->id < 0)
- return -1;
+ xenUnifiedPrivatePtr priv = conn->privateData;
- ret = virXen_setvcpumap(priv->handle, domain->id, vcpu,
+ ret = virXen_setvcpumap(priv->handle, def->id, vcpu,
cpumap, maplen);
if (ret < 0)
return -1;
@@ -2967,7 +2967,8 @@ xenHypervisorPinVcpu(virDomainPtr domain, unsigned int vcpu,
* Returns the number of info filled in case of success, -1 in case of failure.
*/
int
-xenHypervisorGetVcpus(virDomainPtr domain,
+xenHypervisorGetVcpus(virConnectPtr conn,
+ virDomainDefPtr def,
virVcpuInfoPtr info,
int maxinfo,
unsigned char *cpumaps,
@@ -2975,22 +2976,22 @@ xenHypervisorGetVcpus(virDomainPtr domain,
{
xen_getdomaininfo dominfo;
int ret;
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
virVcpuInfoPtr ipt;
int nbinfo, i;
- if (domain->id < 0 || sizeof(cpumap_t) & 7) {
+ if (sizeof(cpumap_t) & 7) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("domain shut off or invalid"));
+ _("invalid cpumap_t size"));
return -1;
}
/* first get the number of virtual CPUs in this domain */
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(priv->handle, domain->id,
+ ret = virXen_getdomaininfo(priv->handle, def->id,
&dominfo);
- if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != domain->id)) {
+ if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != def->id)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get domain details"));
return -1;
@@ -3003,7 +3004,7 @@ xenHypervisorGetVcpus(virDomainPtr domain,
for (i = 0, ipt = info; i < nbinfo; i++, ipt++) {
if ((cpumaps != NULL) && (i < maxinfo)) {
- ret = virXen_getvcpusinfo(priv->handle, domain->id, i,
+ ret = virXen_getvcpusinfo(priv->handle, def->id, i,
ipt,
(unsigned char *)VIR_GET_CPUMAP(cpumaps, maplen,
i),
maplen);
@@ -3013,7 +3014,7 @@ xenHypervisorGetVcpus(virDomainPtr domain,
return -1;
}
} else {
- ret = virXen_getvcpusinfo(priv->handle, domain->id, i,
+ ret = virXen_getvcpusinfo(priv->handle, def->id, i,
ipt, NULL, 0);
if (ret < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -3034,22 +3035,23 @@ xenHypervisorGetVcpus(virDomainPtr domain,
* the maximum number of virtual CPUs the guest was booted with.
*/
int
-xenHypervisorGetVcpuMax(virDomainPtr domain)
+xenHypervisorGetVcpuMax(virConnectPtr conn,
+ virDomainDefPtr def)
{
xen_getdomaininfo dominfo;
int ret;
int maxcpu;
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
/* inactive domain */
- if (domain->id < 0) {
+ if (def->id < 0) {
maxcpu = MAX_VIRT_CPUS;
} else {
XEN_GETDOMAININFO_CLEAR(dominfo);
- ret = virXen_getdomaininfo(priv->handle, domain->id,
+ ret = virXen_getdomaininfo(priv->handle, def->id,
&dominfo);
- if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != domain->id))
+ if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != def->id))
return -1;
maxcpu = XEN_GETDOMAININFO_MAXCPUID(dominfo) + 1;
}
diff --git a/src/xen/xen_hypervisor.h b/src/xen/xen_hypervisor.h
index 9ee1f13..1cf1e14 100644
--- a/src/xen/xen_hypervisor.h
+++ b/src/xen/xen_hypervisor.h
@@ -89,18 +89,21 @@ int xenHypervisorSetMaxMemory (virConnectPtr conn,
ATTRIBUTE_NONNULL (1);
int xenHypervisorCheckID (virConnectPtr conn,
int id);
-int xenHypervisorPinVcpu (virDomainPtr domain,
+int xenHypervisorPinVcpu (virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpu,
unsigned char *cpumap,
int maplen)
ATTRIBUTE_NONNULL (1);
-int xenHypervisorGetVcpus (virDomainPtr domain,
+int xenHypervisorGetVcpus (virConnectPtr conn,
+ virDomainDefPtr def,
virVcpuInfoPtr info,
int maxinfo,
unsigned char *cpumaps,
int maplen)
ATTRIBUTE_NONNULL (1);
-int xenHypervisorGetVcpuMax (virDomainPtr domain)
+int xenHypervisorGetVcpuMax (virConnectPtr conn,
+ virDomainDefPtr def)
ATTRIBUTE_NONNULL (1);
char * xenHypervisorGetSchedulerType (virDomainPtr domain,
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 77c4dec..75c980c 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -1772,7 +1772,8 @@ xenDaemonNodeGetTopology(virConnectPtr conn, virCapsPtr caps)
* Returns 0 on success, -1 if an error message was issued
*/
int
-xenDaemonDomainSetVcpusFlags(virDomainPtr domain,
+xenDaemonDomainSetVcpusFlags(virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpus,
unsigned int flags)
{
@@ -1788,7 +1789,7 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain,
return -1;
}
- if (domain->id < 0) {
+ if (def->id < 0) {
if (flags & VIR_DOMAIN_VCPU_LIVE) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain not running"));
@@ -1806,7 +1807,7 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain,
/* Unfortunately, xend_op does not validate whether this exceeds
* the maximum. */
flags |= VIR_DOMAIN_VCPU_MAXIMUM;
- if ((max = xenDaemonDomainGetVcpusFlags(domain, flags)) < 0) {
+ if ((max = xenDaemonDomainGetVcpusFlags(conn, def, flags)) < 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("could not determine max vcpus for the domain"));
return -1;
@@ -1819,7 +1820,7 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain,
}
snprintf(buf, sizeof(buf), "%d", vcpus);
- return xend_op(domain->conn, domain->name, "op",
"set_vcpus", "vcpus",
+ return xend_op(conn, def->name, "op", "set_vcpus",
"vcpus",
buf, NULL);
}
@@ -1840,14 +1841,15 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain,
* Returns 0 for success; -1 (with errno) on error
*/
int
-xenDaemonDomainPinVcpu(virDomainPtr domain,
+xenDaemonDomainPinVcpu(virConnectPtr conn,
+ virDomainDefPtr minidef,
unsigned int vcpu,
unsigned char *cpumap,
int maplen)
{
char buf[VIR_UUID_BUFLEN], mapstr[sizeof(cpumap_t) * 64];
int i, j, ret;
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
virDomainDefPtr def = NULL;
if (maplen > (int)sizeof(cpumap_t)) {
@@ -1875,12 +1877,12 @@ xenDaemonDomainPinVcpu(virDomainPtr domain,
snprintf(buf, sizeof(buf), "%d", vcpu);
- ret = xend_op(domain->conn, domain->name, "op", "pincpu",
"vcpu", buf,
+ ret = xend_op(conn, minidef->name, "op", "pincpu",
"vcpu", buf,
"cpumap", mapstr, NULL);
- if (!(def = xenDaemonDomainFetch(domain->conn,
- domain->id,
- domain->name,
+ if (!(def = xenDaemonDomainFetch(conn,
+ minidef->id,
+ minidef->name,
NULL)))
goto cleanup;
@@ -1922,7 +1924,9 @@ cleanup:
*/
int
-xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
+xenDaemonDomainGetVcpusFlags(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned int flags)
{
struct sexpr *root;
int ret;
@@ -1931,13 +1935,13 @@ xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int
flags)
VIR_DOMAIN_VCPU_CONFIG |
VIR_DOMAIN_VCPU_MAXIMUM, -1);
- if (domain->id < 0 && (flags & VIR_DOMAIN_VCPU_LIVE)) {
+ if (def->id < 0 && (flags & VIR_DOMAIN_VCPU_LIVE)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain not active"));
return -1;
}
- 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;
@@ -1973,7 +1977,8 @@ xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int
flags)
* Returns the number of info filled in case of success, -1 in case of failure.
*/
int
-xenDaemonDomainGetVcpus(virDomainPtr domain,
+xenDaemonDomainGetVcpus(virConnectPtr conn,
+ virDomainDefPtr def,
virVcpuInfoPtr info,
int maxinfo,
unsigned char *cpumaps,
@@ -1985,7 +1990,7 @@ xenDaemonDomainGetVcpus(virDomainPtr domain,
unsigned char *cpumap;
int vcpu, cpu;
- root = sexpr_get(domain->conn, "/xend/domain/%s?op=vcpuinfo",
domain->name);
+ root = sexpr_get(conn, "/xend/domain/%s?op=vcpuinfo", def->name);
if (root == NULL)
return -1;
@@ -2128,25 +2133,25 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char
*uuid)
*
* Returns a new domain object or NULL in case of failure
*/
-virDomainPtr
-xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc)
+int
+xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def)
{
int ret;
char *sexpr;
- virDomainPtr dom = NULL;
+ const char *tmp;
+ struct sexpr *root;
xenUnifiedPrivatePtr priv = conn->privateData;
- virDomainDefPtr def;
- if (!(def = virDomainDefParseString(xmlDesc, priv->caps, priv->xmlopt,
- 1 << VIR_DOMAIN_VIRT_XEN,
- VIR_DOMAIN_XML_INACTIVE)))
- return NULL;
-
- if (!(sexpr = xenFormatSxpr(conn, def, priv->xendConfigVersion))) {
- virDomainDefFree(def);
- return NULL;
+ if (def->id != -1) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("Domain %s is already running"),
+ def->name);
+ return -1;
}
+ if (!(sexpr = xenFormatSxpr(conn, def, priv->xendConfigVersion)))
+ return -1;
+
ret = xenDaemonDomainCreateXML(conn, sexpr);
VIR_FREE(sexpr);
if (ret != 0) {
@@ -2155,8 +2160,19 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc)
/* This comes before wait_for_devices, to ensure that latter
cleanup will destroy the domain upon failure */
- if (!(dom = virDomainLookupByName(conn, def->name)))
+ root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
+ if (root == NULL)
+ goto error;
+
+ tmp = sexpr_node(root, "domain/domid");
+ if (!tmp) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Domain %s did not start"),
+ def->name);
goto error;
+ }
+ if (tmp)
+ def->id = sexpr_int(root, "domain/domid");
if (xend_wait_for_devices(conn, def->name) < 0)
goto error;
@@ -2165,16 +2181,13 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc)
goto error;
virDomainDefFree(def);
- return dom;
+ return 0;
error:
/* Make sure we don't leave a still-born domain around */
- if (dom != NULL) {
+ if (def->id != -1)
xenDaemonDomainDestroy(conn, def);
- virObjectUnref(dom);
- }
- virDomainDefFree(def);
- return NULL;
+ return -1;
}
/**
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 1284db3..b78145c 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -140,18 +140,23 @@ int xenDaemonDomainCreate(virConnectPtr conn,
int xenDaemonDomainUndefine(virConnectPtr conn,
virDomainDefPtr def);
-int xenDaemonDomainSetVcpus (virDomainPtr domain,
+int xenDaemonDomainSetVcpus (virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpus);
-int xenDaemonDomainSetVcpusFlags (virDomainPtr domain,
+int xenDaemonDomainSetVcpusFlags (virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpus,
unsigned int flags);
-int xenDaemonDomainPinVcpu (virDomainPtr domain,
+int xenDaemonDomainPinVcpu (virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpu,
unsigned char *cpumap,
int maplen);
-int xenDaemonDomainGetVcpusFlags (virDomainPtr domain,
+int xenDaemonDomainGetVcpusFlags (virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int flags);
-int xenDaemonDomainGetVcpus (virDomainPtr domain,
+int xenDaemonDomainGetVcpus (virConnectPtr conn,
+ virDomainDefPtr def,
virVcpuInfoPtr info,
int maxinfo,
unsigned char *cpumaps,
@@ -163,7 +168,7 @@ int xenDaemonDomainGetAutostart (virDomainPtr dom,
int xenDaemonDomainSetAutostart (virDomainPtr domain,
int autostart);
-virDomainPtr xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc);
+int xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def);
virDomainDefPtr xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
virDomainDefPtr xenDaemonLookupByName(virConnectPtr conn, const char *domname);
int xenDaemonDomainMigratePrepare (virConnectPtr dconn,
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 79f773d..76425dd 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -656,11 +656,12 @@ cleanup:
* Returns 0 on success, -1 if an error message was issued
*/
int
-xenXMDomainSetVcpusFlags(virDomainPtr domain,
+xenXMDomainSetVcpusFlags(virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpus,
unsigned int flags)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
int ret = -1;
@@ -678,14 +679,14 @@ xenXMDomainSetVcpusFlags(virDomainPtr domain,
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name)))
goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename)))
goto cleanup;
/* Hypervisor maximum. */
- if ((max = xenUnifiedConnectGetMaxVcpus(domain->conn, NULL)) < 0) {
+ if ((max = xenUnifiedConnectGetMaxVcpus(conn, NULL)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("could not determine max vcpus for the domain"));
goto cleanup;
@@ -712,7 +713,7 @@ xenXMDomainSetVcpusFlags(virDomainPtr domain,
/* 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;
@@ -732,12 +733,14 @@ cleanup:
* issued
*/
int
-xenXMDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
+xenXMDomainGetVcpusFlags(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned int flags)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
- int ret = -2;
+ int ret = -1;
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
VIR_DOMAIN_VCPU_CONFIG |
@@ -750,7 +753,7 @@ xenXMDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name)))
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name)))
goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename)))
@@ -776,12 +779,13 @@ cleanup:
* Returns 0 for success; -1 (with errno) on error
*/
int
-xenXMDomainPinVcpu(virDomainPtr domain,
+xenXMDomainPinVcpu(virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int vcpu ATTRIBUTE_UNUSED,
unsigned char *cpumap,
int maplen)
{
- xenUnifiedPrivatePtr priv = domain->conn->privateData;
+ xenUnifiedPrivatePtr priv = conn->privateData;
const char *filename;
xenXMConfCachePtr entry;
int ret = -1;
@@ -793,7 +797,7 @@ xenXMDomainPinVcpu(virDomainPtr domain,
xenUnifiedLock(priv);
- if (!(filename = virHashLookup(priv->nameConfigMap, domain->name))) {
+ if (!(filename = virHashLookup(priv->nameConfigMap, def->name))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("virHashLookup"));
goto cleanup;
}
@@ -807,7 +811,7 @@ xenXMDomainPinVcpu(virDomainPtr domain,
entry->def->cpumask = virBitmapNewData(cpumap, maplen);
if (!entry->def->cpumask)
goto cleanup;
- if (xenXMConfigSaveFile(domain->conn, entry->filename, entry->def) < 0)
+ if (xenXMConfigSaveFile(conn, entry->filename, entry->def) < 0)
goto cleanup;
ret = 0;
diff --git a/src/xen/xm_internal.h b/src/xen/xm_internal.h
index 5a434b9..28087d3 100644
--- a/src/xen/xm_internal.h
+++ b/src/xen/xm_internal.h
@@ -54,12 +54,21 @@ int xenXMDomainSetMaxMemory(virConnectPtr conn,
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,
+int xenXMDomainSetVcpus(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned int vcpus);
+int xenXMDomainSetVcpusFlags(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned int vcpus,
+ unsigned int flags);
+int xenXMDomainGetVcpusFlags(virConnectPtr conn,
+ virDomainDefPtr def,
unsigned int flags);
-int xenXMDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags);
-int xenXMDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
- unsigned char *cpumap, int maplen);
+int xenXMDomainPinVcpu(virConnectPtr conn,
+ virDomainDefPtr def,
+ unsigned int vcpu,
+ unsigned char *cpumap,
+ int maplen);
virDomainDefPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname);
virDomainDefPtr xenXMDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
--
1.8.1.4