WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Clean up domain_create() interface.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Clean up domain_create() interface.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 20 Jun 2008 09:40:18 -0700
Delivery-date: Fri, 20 Jun 2008 09:40:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1213971686 -3600
# Node ID 926a366ca82f43ff1f9fd90bac435f4835b4dbf9
# Parent  ad156e312aefd4deca7d968c13a6b9ed0ece45f8
Clean up domain_create() interface.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 xen/arch/ia64/xen/mm.c   |    6 -
 xen/arch/x86/mm.c        |    4 
 xen/common/domain.c      |  259 +++++++++++++++++++++++------------------------
 xen/include/xen/domain.h |    3 
 xen/include/xen/sched.h  |   12 +-
 5 files changed, 143 insertions(+), 141 deletions(-)

diff -r ad156e312aef -r 926a366ca82f xen/arch/ia64/xen/mm.c
--- a/xen/arch/ia64/xen/mm.c    Fri Jun 20 15:21:04 2008 +0100
+++ b/xen/arch/ia64/xen/mm.c    Fri Jun 20 15:21:26 2008 +0100
@@ -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;
 
diff -r ad156e312aef -r 926a366ca82f xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Fri Jun 20 15:21:04 2008 +0100
+++ b/xen/arch/x86/mm.c Fri Jun 20 15:21:26 2008 +0100
@@ -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. */
diff -r ad156e312aef -r 926a366ca82f xen/common/domain.c
--- a/xen/common/domain.c       Fri Jun 20 15:21:04 2008 +0100
+++ b/xen/common/domain.c       Fri Jun 20 15:21:26 2008 +0100
@@ -73,21 +73,133 @@ int current_domain_id(void)
     return current->domain->domain_id;
 }
 
-struct domain *alloc_domain(domid_t domid)
+static struct domain *alloc_domain_struct(void)
+{
+    return xmalloc(struct domain);
+}
+
+static void free_domain_struct(struct domain *d)
+{
+    xfree(d);
+}
+
+static void __domain_finalise_shutdown(struct domain *d)
+{
+    struct vcpu *v;
+
+    BUG_ON(!spin_is_locked(&d->shutdown_lock));
+
+    if ( d->is_shut_down )
+        return;
+
+    for_each_vcpu ( d, v )
+        if ( !v->paused_for_shutdown )
+            return;
+
+    d->is_shut_down = 1;
+    send_guest_global_virq(dom0, VIRQ_DOM_EXC);
+}
+
+static void vcpu_check_shutdown(struct vcpu *v)
+{
+    struct domain *d = v->domain;
+
+    spin_lock(&d->shutdown_lock);
+
+    if ( d->is_shutting_down )
+    {
+        if ( !v->paused_for_shutdown )
+            vcpu_pause_nosync(v);
+        v->paused_for_shutdown = 1;
+        v->defer_shutdown = 0;
+        __domain_finalise_shutdown(d);
+    }
+
+    spin_unlock(&d->shutdown_lock);
+}
+
+struct vcpu *alloc_vcpu(
+    struct domain *d, unsigned int vcpu_id, unsigned int cpu_id)
+{
+    struct vcpu *v;
+
+    BUG_ON(d->vcpu[vcpu_id] != NULL);
+
+    if ( (v = alloc_vcpu_struct()) == NULL )
+        return NULL;
+
+    v->domain = d;
+    v->vcpu_id = vcpu_id;
+
+    v->runstate.state = is_idle_vcpu(v) ? RUNSTATE_running : RUNSTATE_offline;
+    v->runstate.state_entry_time = NOW();
+
+    if ( !is_idle_domain(d) )
+    {
+        set_bit(_VPF_down, &v->pause_flags);
+        v->vcpu_info = (void *)&shared_info(d, vcpu_info[vcpu_id]);
+    }
+
+    if ( sched_init_vcpu(v, cpu_id) != 0 )
+    {
+        free_vcpu_struct(v);
+        return NULL;
+    }
+
+    if ( vcpu_initialise(v) != 0 )
+    {
+        sched_destroy_vcpu(v);
+        free_vcpu_struct(v);
+        return NULL;
+    }
+
+    d->vcpu[vcpu_id] = v;
+    if ( vcpu_id != 0 )
+        d->vcpu[v->vcpu_id-1]->next_in_list = v;
+
+    /* Must be called after making new vcpu visible to for_each_vcpu(). */
+    vcpu_check_shutdown(v);
+
+    return v;
+}
+
+struct vcpu *alloc_idle_vcpu(unsigned int cpu_id)
 {
     struct domain *d;
-
-    if ( (d = xmalloc(struct domain)) == NULL )
+    struct vcpu *v;
+    unsigned int vcpu_id = cpu_id % MAX_VIRT_CPUS;
+
+    if ( (v = idle_vcpu[cpu_id]) != NULL )
+        return v;
+
+    d = (vcpu_id == 0) ?
+        domain_create(IDLE_DOMAIN_ID, 0, 0) :
+        idle_vcpu[cpu_id - vcpu_id]->domain;
+    BUG_ON(d == NULL);
+
+    v = alloc_vcpu(d, vcpu_id, cpu_id);
+    idle_vcpu[cpu_id] = v;
+
+    return v;
+}
+
+struct domain *domain_create(
+    domid_t domid, unsigned int domcr_flags, ssidref_t ssidref)
+{
+    struct domain *d, **pd;
+    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_struct()) == NULL )
         return NULL;
 
     memset(d, 0, sizeof(*d));
     d->domain_id = domid;
 
     if ( xsm_alloc_security_domain(d) != 0 )
-    {
-        free_domain(d);
-        return NULL;
-    }
+        goto fail;
+    init_status |= INIT_xsm;
 
     atomic_set(&d->refcnt, 1);
     spin_lock_init(&d->domain_lock);
@@ -97,132 +209,17 @@ struct domain *alloc_domain(domid_t domi
     INIT_LIST_HEAD(&d->page_list);
     INIT_LIST_HEAD(&d->xenpage_list);
 
-    return d;
-}
-
-void free_domain(struct domain *d)
-{
-    xsm_free_security_domain(d);
-    xfree(d);
-}
-
-static void __domain_finalise_shutdown(struct domain *d)
-{
-    struct vcpu *v;
-
-    BUG_ON(!spin_is_locked(&d->shutdown_lock));
-
-    if ( d->is_shut_down )
-        return;
-
-    for_each_vcpu ( d, v )
-        if ( !v->paused_for_shutdown )
-            return;
-
-    d->is_shut_down = 1;
-    send_guest_global_virq(dom0, VIRQ_DOM_EXC);
-}
-
-static void vcpu_check_shutdown(struct vcpu *v)
-{
-    struct domain *d = v->domain;
-
-    spin_lock(&d->shutdown_lock);
-
-    if ( d->is_shutting_down )
-    {
-        if ( !v->paused_for_shutdown )
-            vcpu_pause_nosync(v);
-        v->paused_for_shutdown = 1;
-        v->defer_shutdown = 0;
-        __domain_finalise_shutdown(d);
-    }
-
-    spin_unlock(&d->shutdown_lock);
-}
-
-struct vcpu *alloc_vcpu(
-    struct domain *d, unsigned int vcpu_id, unsigned int cpu_id)
-{
-    struct vcpu *v;
-
-    BUG_ON(d->vcpu[vcpu_id] != NULL);
-
-    if ( (v = alloc_vcpu_struct()) == NULL )
-        return NULL;
-
-    v->domain = d;
-    v->vcpu_id = vcpu_id;
-
-    v->runstate.state = is_idle_vcpu(v) ? RUNSTATE_running : RUNSTATE_offline;
-    v->runstate.state_entry_time = NOW();
-
-    if ( !is_idle_domain(d) )
-    {
-        set_bit(_VPF_down, &v->pause_flags);
-        v->vcpu_info = (void *)&shared_info(d, vcpu_info[vcpu_id]);
-    }
-
-    if ( sched_init_vcpu(v, cpu_id) != 0 )
-    {
-        free_vcpu_struct(v);
-        return NULL;
-    }
-
-    if ( vcpu_initialise(v) != 0 )
-    {
-        sched_destroy_vcpu(v);
-        free_vcpu_struct(v);
-        return NULL;
-    }
-
-    d->vcpu[vcpu_id] = v;
-    if ( vcpu_id != 0 )
-        d->vcpu[v->vcpu_id-1]->next_in_list = v;
-
-    /* Must be called after making new vcpu visible to for_each_vcpu(). */
-    vcpu_check_shutdown(v);
-
-    return v;
-}
-
-struct vcpu *alloc_idle_vcpu(unsigned int cpu_id)
-{
-    struct domain *d;
-    struct vcpu *v;
-    unsigned int vcpu_id = cpu_id % MAX_VIRT_CPUS;
-
-    if ( (v = idle_vcpu[cpu_id]) != NULL )
-        return v;
-
-    d = (vcpu_id == 0) ?
-        domain_create(IDLE_DOMAIN_ID, 0, 0) :
-        idle_vcpu[cpu_id - vcpu_id]->domain;
-    BUG_ON(d == NULL);
-
-    v = alloc_vcpu(d, vcpu_id, cpu_id);
-    idle_vcpu[cpu_id] = v;
-
-    return v;
-}
-
-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 }; 
-    int init_status = 0;
-
-    if ( (d = alloc_domain(domid)) == NULL )
-        return NULL;
-
     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(stru
     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);
 }
diff -r ad156e312aef -r 926a366ca82f xen/include/xen/domain.h
--- a/xen/include/xen/domain.h  Fri Jun 20 15:21:04 2008 +0100
+++ b/xen/include/xen/domain.h  Fri Jun 20 15:21:26 2008 +0100
@@ -15,9 +15,6 @@ int boot_vcpu(
     struct domain *d, int vcpuid, vcpu_guest_context_u ctxt);
 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);
diff -r ad156e312aef -r 926a366ca82f xen/include/xen/sched.h
--- a/xen/include/xen/sched.h   Fri Jun 20 15:21:04 2008 +0100
+++ b/xen/include/xen/sched.h   Fri Jun 20 15:21:26 2008 +0100
@@ -315,10 +315,14 @@ struct domain *domain_create(
 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,

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Clean up domain_create() interface., Xen patchbot-unstable <=