aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2012-09-03 09:40:38 +0200
committerJan Beulich <jbeulich@suse.com>2012-09-03 09:40:38 +0200
commit8e66050e3223a9aa55ca29ec32b2e78c3e69e085 (patch)
tree22bf4997c2366565228de8bb0a31c0eaf4873be5 /xen/common
parentf1297904185f73262522b6277252bfb699644766 (diff)
downloadxen-8e66050e3223a9aa55ca29ec32b2e78c3e69e085.tar.gz
xen-8e66050e3223a9aa55ca29ec32b2e78c3e69e085.tar.bz2
xen-8e66050e3223a9aa55ca29ec32b2e78c3e69e085.zip
make domain_create() return a proper error code
While triggered by the XSA-9 fix, this really is of more general use; that fix just pointed out very sharply that the current situation with all domain creation failures reported to user (tools) space as -ENOMEM is very unfortunate (actively misleading users _and_ support personnel). Pull over the pointer <-> error code conversion infrastructure from Linux, and use it in domain_create() and all it callers. Signed-off-by: Jan Beulich <jbeulich@suse.com> Acked-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/common')
-rw-r--r--xen/common/cpupool.c8
-rw-r--r--xen/common/domain.c24
-rw-r--r--xen/common/domctl.c7
-rw-r--r--xen/common/schedule.c4
4 files changed, 26 insertions, 17 deletions
diff --git a/xen/common/cpupool.c b/xen/common/cpupool.c
index c9cc123a40..c036c2c841 100644
--- a/xen/common/cpupool.c
+++ b/xen/common/cpupool.c
@@ -370,14 +370,18 @@ out:
int cpupool_add_domain(struct domain *d, int poolid)
{
struct cpupool *c;
- int rc = 1;
+ int rc;
int n_dom = 0;
if ( poolid == CPUPOOLID_NONE )
return 0;
spin_lock(&cpupool_lock);
c = cpupool_find_by_id(poolid);
- if ( (c != NULL) && cpumask_weight(c->cpu_valid) )
+ if ( c == NULL )
+ rc = -ESRCH;
+ else if ( !cpumask_weight(c->cpu_valid) )
+ rc = -ENODEV;
+ else
{
c->n_dom++;
n_dom = c->n_dom;
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 4c5d241a2b..a1aa05e03b 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -9,7 +9,7 @@
#include <xen/init.h>
#include <xen/lib.h>
#include <xen/ctype.h>
-#include <xen/errno.h>
+#include <xen/err.h>
#include <xen/sched.h>
#include <xen/sched-if.h>
#include <xen/domain.h>
@@ -196,17 +196,17 @@ struct domain *domain_create(
struct domain *d, **pd;
enum { INIT_xsm = 1u<<0, INIT_watchdog = 1u<<1, INIT_rangeset = 1u<<2,
INIT_evtchn = 1u<<3, INIT_gnttab = 1u<<4, INIT_arch = 1u<<5 };
- int init_status = 0;
+ int err, init_status = 0;
int poolid = CPUPOOLID_NONE;
if ( (d = alloc_domain_struct()) == NULL )
- return NULL;
+ return ERR_PTR(-ENOMEM);
d->domain_id = domid;
lock_profile_register_struct(LOCKPROF_TYPE_PERDOM, d, domid, "Domain");
- if ( xsm_alloc_security_domain(d) != 0 )
+ if ( (err = xsm_alloc_security_domain(d)) != 0 )
goto fail;
init_status |= INIT_xsm;
@@ -226,6 +226,7 @@ struct domain *domain_create(
spin_lock_init(&d->shutdown_lock);
d->shutdown_code = -1;
+ err = -ENOMEM;
if ( !zalloc_cpumask_var(&d->domain_dirty_cpumask) )
goto fail;
@@ -251,7 +252,7 @@ struct domain *domain_create(
if ( !is_idle_domain(d) )
{
- if ( xsm_domain_create(d, ssidref) != 0 )
+ if ( (err = xsm_domain_create(d, ssidref)) != 0 )
goto fail;
d->is_paused_by_controller = 1;
@@ -266,29 +267,30 @@ struct domain *domain_create(
radix_tree_init(&d->pirq_tree);
- if ( evtchn_init(d) != 0 )
+ if ( (err = evtchn_init(d)) != 0 )
goto fail;
init_status |= INIT_evtchn;
- if ( grant_table_create(d) != 0 )
+ if ( (err = grant_table_create(d)) != 0 )
goto fail;
init_status |= INIT_gnttab;
poolid = 0;
+ err = -ENOMEM;
d->mem_event = xzalloc(struct mem_event_per_domain);
if ( !d->mem_event )
goto fail;
}
- if ( arch_domain_create(d, domcr_flags) != 0 )
+ if ( (err = arch_domain_create(d, domcr_flags)) != 0 )
goto fail;
init_status |= INIT_arch;
- if ( cpupool_add_domain(d, poolid) != 0 )
+ if ( (err = cpupool_add_domain(d, poolid)) != 0 )
goto fail;
- if ( sched_init_domain(d) != 0 )
+ if ( (err = sched_init_domain(d)) != 0 )
goto fail;
if ( !is_idle_domain(d) )
@@ -329,7 +331,7 @@ struct domain *domain_create(
xsm_free_security_domain(d);
free_cpumask_var(d->domain_dirty_cpumask);
free_domain_struct(d);
- return NULL;
+ return ERR_PTR(err);
}
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 7ca6b08fa5..2b1f1829da 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -9,6 +9,7 @@
#include <xen/config.h>
#include <xen/types.h>
#include <xen/lib.h>
+#include <xen/err.h>
#include <xen/mm.h>
#include <xen/sched.h>
#include <xen/sched-if.h>
@@ -455,10 +456,12 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domctl_t) u_domctl)
if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off )
domcr_flags |= DOMCRF_oos_off;
- ret = -ENOMEM;
d = domain_create(dom, domcr_flags, op->u.createdomain.ssidref);
- if ( d == NULL )
+ if ( IS_ERR(d) )
+ {
+ ret = PTR_ERR(d);
break;
+ }
ret = 0;
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index 0854f55bf5..eee74be50f 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -28,7 +28,7 @@
#include <xen/softirq.h>
#include <xen/trace.h>
#include <xen/mm.h>
-#include <xen/errno.h>
+#include <xen/err.h>
#include <xen/guest_access.h>
#include <xen/multicall.h>
#include <xen/cpu.h>
@@ -1323,7 +1323,7 @@ void __init scheduler_init(void)
panic("scheduler returned error on init\n");
idle_domain = domain_create(DOMID_IDLE, 0, 0);
- BUG_ON(idle_domain == NULL);
+ BUG_ON(IS_ERR(idle_domain));
idle_domain->vcpu = idle_vcpu;
idle_domain->max_vcpus = nr_cpu_ids;
if ( alloc_vcpu(idle_domain, 0, 0) == NULL )