diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 68475b6d16..9c42b60224 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1,7 +1,7 @@ /* * xen_internal.c: direct access to Xen hypervisor level * - * Copyright (C) 2005-2012 Red Hat, Inc. + * Copyright (C) 2005-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1067,7 +1067,9 @@ xenHypervisorDoV2Dom(int handle, xen_op_v2_dom* op) * Returns the number of domains or -1 in case of failure */ static int -virXen_getdomaininfolist(int handle, int first_domain, int maxids, +virXen_getdomaininfolist(int handle, + int first_domain, + int maxids, xen_getdomaininfolist *dominfos) { int ret = -1; @@ -1134,8 +1136,8 @@ virXen_getdomaininfolist(int handle, int first_domain, int maxids, } static int -virXen_getdomaininfo(int handle, int first_domain, - xen_getdomaininfo *dominfo) { +virXen_getdomaininfo(int handle, int first_domain, xen_getdomaininfo *dominfo) +{ xen_getdomaininfolist dominfos; if (hv_versions.hypervisor < 2) { @@ -1161,15 +1163,8 @@ char * xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) { char *schedulertype = NULL; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("domain or conn is NULL")); - return NULL; - } - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("priv->handle invalid")); @@ -1240,17 +1235,11 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) */ int xenHypervisorGetSchedulerParameters(virDomainPtr domain, - virTypedParameterPtr params, int *nparams) + virTypedParameterPtr params, + int *nparams) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("domain or conn is NULL")); - return -1; - } - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("priv->handle invalid")); @@ -1343,19 +1332,14 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain, */ int xenHypervisorSetSchedulerParameters(virDomainPtr domain, - virTypedParameterPtr params, int nparams) + virTypedParameterPtr params, + int nparams) { int i; unsigned int val; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; char buf[256]; - if (domain->conn == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("domain or conn is NULL")); - return -1; - } - if (nparams == 0) { /* nothing to do, exit early */ return 0; @@ -1369,7 +1353,6 @@ xenHypervisorSetSchedulerParameters(virDomainPtr domain, NULL) < 0) return -1; - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("priv->handle invalid")); @@ -1467,10 +1450,9 @@ xenHypervisorDomainBlockStats(virDomainPtr dom, struct _virDomainBlockStats *stats) { #ifdef __linux__ - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = dom->conn->privateData; int ret; - priv = (xenUnifiedPrivatePtr) dom->conn->privateData; xenUnifiedLock(priv); /* Need to lock because it hits the xenstore handle :-( */ ret = xenLinuxDomainBlockStats(priv, dom, path, stats); @@ -1739,8 +1721,11 @@ virXen_setmaxvcpus(int handle, int id, unsigned int vcpus) * Returns 0 or -1 in case of failure */ static int -virXen_setvcpumap(int handle, int id, unsigned int vcpu, - unsigned char * cpumap, int maplen) +virXen_setvcpumap(int handle, + int id, + unsigned int vcpu, + unsigned char * cpumap, + int maplen) { int ret = -1; unsigned char *new = NULL; @@ -1838,8 +1823,12 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu, * Returns 0 or -1 in case of failure */ static int -virXen_getvcpusinfo(int handle, int id, unsigned int vcpu, virVcpuInfoPtr ipt, - unsigned char *cpumap, int maplen) +virXen_getvcpusinfo(int handle, + int id, + unsigned int vcpu, + virVcpuInfoPtr ipt, + unsigned char *cpumap, + int maplen) { int ret = -1; @@ -2220,7 +2209,7 @@ xenHypervisorOpen(virConnectPtr conn, unsigned int flags) { int ret; - xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + xenUnifiedPrivatePtr priv = conn->privateData; virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); @@ -2252,12 +2241,7 @@ int xenHypervisorClose(virConnectPtr conn) { int ret; - xenUnifiedPrivatePtr priv; - - if (conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) conn->privateData; + xenUnifiedPrivatePtr priv = conn->privateData; if (priv->handle < 0) return -1; @@ -2282,12 +2266,9 @@ xenHypervisorClose(virConnectPtr conn) int xenHypervisorGetVersion(virConnectPtr conn, unsigned long *hvVer) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; - if (conn == NULL) - return -1; - priv = (xenUnifiedPrivatePtr) conn->privateData; - if (priv->handle < 0 || hvVer == NULL) + if (priv->handle < 0) return -1; *hvVer = (hv_versions.hv >> 16) * 1000000 + (hv_versions.hv & 0xFFFF) * 1000; return 0; @@ -2312,12 +2293,12 @@ static int xenDefaultConsoleType(const char *ostype, } static virCapsPtr -xenHypervisorBuildCapabilities(virConnectPtr conn, - virArch hostarch, +xenHypervisorBuildCapabilities(virConnectPtr conn, virArch hostarch, int host_pae, const char *hvm_type, struct guest_arch *guest_archs, - int nr_guest_archs) { + int nr_guest_archs) +{ virCapsPtr caps; int i; int hv_major = hv_versions.hv >> 16; @@ -2567,7 +2548,8 @@ xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn) virCapsPtr xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn, virArch hostarch, - FILE *cpuinfo, FILE *capabilities) + FILE *cpuinfo, + FILE *capabilities) { char line[1024], *str, *token; regmatch_t subs[4]; @@ -2776,7 +2758,7 @@ cleanup: char * xenHypervisorGetCapabilities(virConnectPtr conn) { - xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData; + xenUnifiedPrivatePtr priv = conn->privateData; char *xml; if (!(xml = virCapabilitiesFormatXML(priv->caps))) { @@ -2803,11 +2785,8 @@ xenHypervisorNumOfDomains(virConnectPtr conn) int ret, nbids; static int last_maxids = 2; int maxids = last_maxids; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; - if (conn == NULL) - return -1; - priv = (xenUnifiedPrivatePtr) conn->privateData; if (priv->handle < 0) return -1; @@ -2860,14 +2839,9 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids) { xen_getdomaininfolist dominfos; int ret, nbids, i; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; - if (conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) conn->privateData; - if (priv->handle < 0 || - (ids == NULL) || (maxids < 0)) + if (priv->handle < 0) return -1; if (maxids == 0) @@ -2906,11 +2880,10 @@ xenHypervisorListDomains(virConnectPtr conn, int *ids, int maxids) char * xenHypervisorDomainGetOSType(virDomainPtr dom) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = dom->conn->privateData; xen_getdomaininfo dominfo; char *ostype = NULL; - priv = (xenUnifiedPrivatePtr) dom->conn->privateData; if (priv->handle < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("domain shut off or invalid")); @@ -2951,13 +2924,11 @@ xenHypervisorDomainGetOSType(virDomainPtr dom) } int -xenHypervisorHasDomain(virConnectPtr conn, - int id) +xenHypervisorHasDomain(virConnectPtr conn, int id) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; xen_getdomaininfo dominfo; - priv = (xenUnifiedPrivatePtr) conn->privateData; if (priv->handle < 0) return 0; @@ -2973,15 +2944,13 @@ xenHypervisorHasDomain(virConnectPtr conn, } virDomainPtr -xenHypervisorLookupDomainByID(virConnectPtr conn, - int id) +xenHypervisorLookupDomainByID(virConnectPtr conn, int id) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; xen_getdomaininfo dominfo; virDomainPtr ret; char *name; - priv = (xenUnifiedPrivatePtr) conn->privateData; if (priv->handle < 0) return NULL; @@ -3008,16 +2977,14 @@ xenHypervisorLookupDomainByID(virConnectPtr conn, virDomainPtr -xenHypervisorLookupDomainByUUID(virConnectPtr conn, - const unsigned char *uuid) +xenHypervisorLookupDomainByUUID(virConnectPtr conn, const unsigned char *uuid) { xen_getdomaininfolist dominfos; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; virDomainPtr ret; char *name; int maxids = 100, nids, i, id; - priv = (xenUnifiedPrivatePtr) conn->privateData; if (priv->handle < 0) return NULL; @@ -3081,14 +3048,10 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn, * Returns the maximum of CPU defined by Xen. */ int -xenHypervisorGetMaxVcpus(virConnectPtr conn, - const char *type ATTRIBUTE_UNUSED) +xenHypervisorGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; - if (conn == NULL) - return -1; - priv = (xenUnifiedPrivatePtr) conn->privateData; if (priv->handle < 0) return -1; @@ -3108,14 +3071,10 @@ xenHypervisorGetMaxVcpus(virConnectPtr conn, unsigned long xenHypervisorGetDomMaxMemory(virConnectPtr conn, int id) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; xen_getdomaininfo dominfo; int ret; - if (conn == NULL) - return 0; - - priv = (xenUnifiedPrivatePtr) conn->privateData; if (priv->handle < 0) return 0; @@ -3148,12 +3107,8 @@ xenHypervisorGetDomMaxMemory(virConnectPtr conn, int id) static unsigned long long ATTRIBUTE_NONNULL(1) xenHypervisorGetMaxMemory(virDomainPtr domain) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return 0; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0 || domain->id < 0) return 0; @@ -3173,7 +3128,7 @@ xenHypervisorGetMaxMemory(virDomainPtr domain) int xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = conn->privateData; xen_getdomaininfo dominfo; int ret; uint32_t domain_flags, domain_state, domain_shutdown_cause; @@ -3184,11 +3139,7 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info) kb_per_pages = 4; } - if (conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) conn->privateData; - if (priv->handle < 0 || info == NULL) + if (priv->handle < 0) return -1; memset(info, 0, sizeof(virDomainInfo)); @@ -3256,14 +3207,9 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info) int xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) { - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; - if (priv->handle < 0 || info == NULL || - (domain->id < 0)) + if (priv->handle < 0 || domain->id < 0) return -1; return xenHypervisorGetDomInfo(domain->conn, domain->id, info); @@ -3292,9 +3238,6 @@ xenHypervisorGetDomainState(virDomainPtr domain, virCheckFlags(0, -1); - if (domain->conn == NULL) - return -1; - if (priv->handle < 0 || domain->id < 0) return -1; @@ -3326,19 +3269,14 @@ xenHypervisorGetDomainState(virDomainPtr domain, * Returns the number of entries filled in freeMems, or -1 in case of error. */ int -xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn, unsigned long long *freeMems, - int startCell, int maxCells) +xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn, + unsigned long long *freeMems, + int startCell, + int maxCells) { xen_op_v2_sys op_sys; int i, j, ret; - xenUnifiedPrivatePtr priv; - - if (conn == NULL) { - virReportError(VIR_ERR_INVALID_ARG, "%s", _("invalid argument")); - return -1; - } - - priv = conn->privateData; + xenUnifiedPrivatePtr priv = conn->privateData; if (priv->nbNodeCells < 0) { virReportError(VIR_ERR_XEN_CALL, "%s", @@ -3400,12 +3338,8 @@ int xenHypervisorPauseDomain(virDomainPtr domain) { int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0 || domain->id < 0) return -1; @@ -3427,12 +3361,8 @@ int xenHypervisorResumeDomain(virDomainPtr domain) { int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0 || domain->id < 0) return -1; @@ -3455,18 +3385,13 @@ xenHypervisorResumeDomain(virDomainPtr domain) * Returns 0 in case of success, -1 in case of error. */ int -xenHypervisorDestroyDomainFlags(virDomainPtr domain, - unsigned int flags) +xenHypervisorDestroyDomainFlags(virDomainPtr domain, unsigned int flags) { int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; virCheckFlags(0, -1); - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0 || domain->id < 0) return -1; @@ -3489,12 +3414,8 @@ int xenHypervisorSetMaxMemory(virDomainPtr domain, unsigned long memory) { int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0 || domain->id < 0) return -1; @@ -3519,12 +3440,8 @@ int xenHypervisorSetVcpus(virDomainPtr domain, unsigned int nvcpus) { int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0 || domain->id < 0 || nvcpus < 1) return -1; @@ -3551,14 +3468,9 @@ xenHypervisorPinVcpu(virDomainPtr domain, unsigned int vcpu, unsigned char *cpumap, int maplen) { int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; - if (priv->handle < 0 || (domain->id < 0) || - (cpumap == NULL) || (maplen < 1)) + if (priv->handle < 0 || domain->id < 0) return -1; ret = virXen_setvcpumap(priv->handle, domain->id, vcpu, @@ -3588,31 +3500,24 @@ 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, virVcpuInfoPtr info, int maxinfo, - unsigned char *cpumaps, int maplen) +xenHypervisorGetVcpus(virDomainPtr domain, + virVcpuInfoPtr info, + int maxinfo, + unsigned char *cpumaps, + int maplen) { xen_getdomaininfo dominfo; int ret; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; virVcpuInfoPtr ipt; int nbinfo, i; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; - if (priv->handle < 0 || (domain->id < 0) || - (info == NULL) || (maxinfo < 1) || - (sizeof(cpumap_t) & 7)) { + if (priv->handle < 0 || domain->id < 0 || sizeof(cpumap_t) & 7) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("domain shut off or invalid")); return -1; } - if ((cpumaps != NULL) && (maplen < 1)) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("invalid argument")); - return -1; - } + /* first get the number of virtual CPUs in this domain */ XEN_GETDOMAININFO_CLEAR(dominfo); ret = virXen_getdomaininfo(priv->handle, domain->id, @@ -3667,12 +3572,8 @@ xenHypervisorGetVcpuMax(virDomainPtr domain) xen_getdomaininfo dominfo; int ret; int maxcpu; - xenUnifiedPrivatePtr priv; + xenUnifiedPrivatePtr priv = domain->conn->privateData; - if (domain->conn == NULL) - return -1; - - priv = (xenUnifiedPrivatePtr) domain->conn->privateData; if (priv->handle < 0) return -1;