From: "Daniel P. Berrange" <berra...@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 <berra...@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 | 34 ++++++++++---------- src/xen/xm_internal.h | 19 ++++++++--- 7 files changed, 187 insertions(+), 99 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 1566077..e68ed6c 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -645,11 +645,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 @@ -1178,6 +1197,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 | @@ -1198,13 +1219,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 @@ -1227,15 +1255,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 @@ -1244,39 +1281,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 f37f48a..3cdc0fc 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 527f717..ebafa56 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1773,7 +1773,8 @@ xenDaemonNodeGetTopology(virConnectPtr conn, virCapsPtr caps) * the unified driver should keep trying. */ int -xenDaemonDomainSetVcpusFlags(virDomainPtr domain, +xenDaemonDomainSetVcpusFlags(virConnectPtr conn, + virDomainDefPtr def, unsigned int vcpus, unsigned int flags) { @@ -1789,7 +1790,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")); @@ -1807,7 +1808,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; @@ -1820,7 +1821,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); } @@ -1841,14 +1842,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)) { @@ -1876,12 +1878,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; @@ -1923,7 +1925,9 @@ cleanup: */ int -xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) +xenDaemonDomainGetVcpusFlags(virConnectPtr conn, + virDomainDefPtr def, + unsigned int flags) { struct sexpr *root; int ret; @@ -1932,13 +1936,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; @@ -1974,7 +1978,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, @@ -1986,7 +1991,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; @@ -2129,25 +2134,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) { @@ -2156,8 +2161,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; @@ -2166,16 +2182,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 ee3557f..9bb204a 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -657,11 +657,12 @@ cleanup: * the unified driver should keep trying. */ 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; @@ -671,8 +672,6 @@ xenXMDomainSetVcpusFlags(virDomainPtr domain, VIR_DOMAIN_VCPU_CONFIG | VIR_DOMAIN_VCPU_MAXIMUM, -1); - if (domain->id != -1) - return -2; if (flags & VIR_DOMAIN_VCPU_LIVE) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); @@ -681,14 +680,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; @@ -715,7 +714,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; @@ -735,19 +734,19 @@ cleanup: * issued, and -2 if the unified driver should keep trying. */ 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 | VIR_DOMAIN_VCPU_MAXIMUM, -1); - if (domain->id != -1) - return -2; if (flags & VIR_DOMAIN_VCPU_LIVE) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("domain not active")); return -1; @@ -755,7 +754,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))) @@ -781,12 +780,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; @@ -798,7 +798,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; } @@ -812,7 +812,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 fbe06b3..8b74ee6 100644 --- a/src/xen/xm_internal.h +++ b/src/xen/xm_internal.h @@ -55,12 +55,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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list