Clean up domain_create() interface.
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 20 Jun 2008 14:21:26 +0000 (15:21 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 20 Jun 2008 14:21:26 +0000 (15:21 +0100)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/arch/ia64/xen/mm.c
xen/arch/x86/mm.c
xen/common/domain.c
xen/include/xen/domain.h
xen/include/xen/sched.h

index 0a4994ba8bd00d77c6e1bb0ae2bd8c475bcd458e..385cac3189018ee806aa157c70a44040a3a92862 100644 (file)
@@ -207,7 +207,7 @@ alloc_dom_xen_and_dom_io(void)
      * Any Xen-heap pages that we will allow to be mapped will have
      * their domain field set to dom_xen.
      */
-    dom_xen = alloc_domain(DOMID_XEN);
+    dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0);
     BUG_ON(dom_xen == NULL);
 
     /*
@@ -215,7 +215,7 @@ alloc_dom_xen_and_dom_io(void)
      * This domain owns I/O pages that are within the range of the page_info
      * array. Mappings occur at the priv of the caller.
      */
-    dom_io = alloc_domain(DOMID_IO);
+    dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0);
     BUG_ON(dom_io == NULL);
 }
 
@@ -1553,7 +1553,7 @@ expose_p2m_init(void)
      * Initialise our DOMID_P2M domain.
      * This domain owns m2p table pages.
      */
-    dom_p2m = alloc_domain(DOMID_P2M);
+    dom_p2m = domain_create(DOMID_P2M, DOMCRF_dummy, 0);
     BUG_ON(dom_p2m == NULL);
     dom_p2m->max_pages = ~0U;
 
index 305fbdce7451cd27e2d93d37052f1e006f3cd695..54b42efb65e336f5df7ff3f2c28601a0678e08ee 100644 (file)
@@ -219,7 +219,7 @@ void __init arch_init_memory(void)
      * Any Xen-heap pages that we will allow to be mapped will have
      * their domain field set to dom_xen.
      */
-    dom_xen = alloc_domain(DOMID_XEN);
+    dom_xen = domain_create(DOMID_XEN, DOMCRF_dummy, 0);
     BUG_ON(dom_xen == NULL);
 
     /*
@@ -227,7 +227,7 @@ void __init arch_init_memory(void)
      * This domain owns I/O pages that are within the range of the page_info
      * array. Mappings occur at the priv of the caller.
      */
-    dom_io = alloc_domain(DOMID_IO);
+    dom_io = domain_create(DOMID_IO, DOMCRF_dummy, 0);
     BUG_ON(dom_io == NULL);
 
     /* First 1MB of RAM is historically marked as I/O. */
index 2965553ed6de880b66af052b8df6c61c7aa712a4..c5779ca0ffe6ad32b9eb0effe131e5e602b0f250 100644 (file)
@@ -73,36 +73,13 @@ int current_domain_id(void)
     return current->domain->domain_id;
 }
 
-struct domain *alloc_domain(domid_t domid)
+static struct domain *alloc_domain_struct(void)
 {
-    struct domain *d;
-
-    if ( (d = xmalloc(struct domain)) == NULL )
-        return NULL;
-
-    memset(d, 0, sizeof(*d));
-    d->domain_id = domid;
-
-    if ( xsm_alloc_security_domain(d) != 0 )
-    {
-        free_domain(d);
-        return NULL;
-    }
-
-    atomic_set(&d->refcnt, 1);
-    spin_lock_init(&d->domain_lock);
-    spin_lock_init(&d->page_alloc_lock);
-    spin_lock_init(&d->shutdown_lock);
-    spin_lock_init(&d->hypercall_deadlock_mutex);
-    INIT_LIST_HEAD(&d->page_list);
-    INIT_LIST_HEAD(&d->xenpage_list);
-
-    return d;
+    return xmalloc(struct domain);
 }
 
-void free_domain(struct domain *d)
+static void free_domain_struct(struct domain *d)
 {
-    xsm_free_security_domain(d);
     xfree(d);
 }
 
@@ -210,19 +187,39 @@ struct domain *domain_create(
     domid_t domid, unsigned int domcr_flags, ssidref_t ssidref)
 {
     struct domain *d, **pd;
-    enum { INIT_evtchn = 1, INIT_gnttab = 2, INIT_arch = 8 }; 
+    enum { INIT_xsm = 1u<<0, INIT_rangeset = 1u<<1, INIT_evtchn = 1u<<2,
+           INIT_gnttab = 1u<<3, INIT_arch = 1u<<4 };
     int init_status = 0;
 
-    if ( (d = alloc_domain(domid)) == NULL )
+    if ( (d = alloc_domain_struct()) == NULL )
         return NULL;
 
+    memset(d, 0, sizeof(*d));
+    d->domain_id = domid;
+
+    if ( xsm_alloc_security_domain(d) != 0 )
+        goto fail;
+    init_status |= INIT_xsm;
+
+    atomic_set(&d->refcnt, 1);
+    spin_lock_init(&d->domain_lock);
+    spin_lock_init(&d->page_alloc_lock);
+    spin_lock_init(&d->shutdown_lock);
+    spin_lock_init(&d->hypercall_deadlock_mutex);
+    INIT_LIST_HEAD(&d->page_list);
+    INIT_LIST_HEAD(&d->xenpage_list);
+
     if ( domcr_flags & DOMCRF_hvm )
         d->is_hvm = 1;
 
     if ( (domid == 0) && opt_dom0_vcpus_pin )
         d->is_pinned = 1;
 
+    if ( domcr_flags & DOMCRF_dummy )
+        return d;
+
     rangeset_domain_initialise(d);
+    init_status |= INIT_rangeset;
 
     if ( !is_idle_domain(d) )
     {
@@ -278,8 +275,11 @@ struct domain *domain_create(
         grant_table_destroy(d);
     if ( init_status & INIT_evtchn )
         evtchn_destroy(d);
-    rangeset_domain_destroy(d);
-    free_domain(d);
+    if ( init_status & INIT_rangeset )
+        rangeset_domain_destroy(d);
+    if ( init_status & INIT_xsm )
+        xsm_free_security_domain(d);
+    free_domain_struct(d);
     return NULL;
 }
 
@@ -535,7 +535,8 @@ static void complete_domain_destroy(struct rcu_head *head)
     if ( d->target != NULL )
         put_domain(d->target);
 
-    free_domain(d);
+    xsm_free_security_domain(d);
+    free_domain_struct(d);
 
     send_guest_global_virq(dom0, VIRQ_DOM_EXC);
 }
index 8483d42f9ef85042d2d728f741dfeb070e4cfd7d..cf82d07ea065aeeec40db3eff303273c28e737b6 100644 (file)
@@ -16,9 +16,6 @@ int boot_vcpu(
 struct vcpu *alloc_idle_vcpu(unsigned int cpu_id);
 void vcpu_reset(struct vcpu *v);
 
-struct domain *alloc_domain(domid_t domid);
-void free_domain(struct domain *d);
-
 struct xen_domctl_getdomaininfo;
 void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info);
 
index 937ebb295ef3f4e4afe9e21f52c8c049761e825c..1565e659788919459187aa559283ca007ccee334 100644 (file)
@@ -315,10 +315,14 @@ static inline struct domain *get_current_domain(void)
 struct domain *domain_create(
     domid_t domid, unsigned int domcr_flags, ssidref_t ssidref);
  /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */
-#define _DOMCRF_hvm 0
-#define DOMCRF_hvm  (1U<<_DOMCRF_hvm)
-#define _DOMCRF_hap 1
-#define DOMCRF_hap  (1U<<_DOMCRF_hap)
+#define _DOMCRF_hvm   0
+#define DOMCRF_hvm    (1U<<_DOMCRF_hvm)
+ /* DOMCRF_hap: Create a domain with hardware-assisted paging. */
+#define _DOMCRF_hap   1
+#define DOMCRF_hap    (1U<<_DOMCRF_hap)
+ /* DOMCRF_dummy: Create a dummy domain (not scheduled; not on domain list) */
+#define _DOMCRF_dummy 2
+#define DOMCRF_dummy  (1U<<_DOMCRF_dummy)
 
 int construct_dom0(
     struct domain *d,