[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] tools/xenstore: split off domain introduction from do_introduce()



commit d4c275d4716233c864c6c3100b658cd2ba623a66
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Wed Jan 13 14:00:19 2021 +0100
Commit:     Juergen Gross <jgross@xxxxxxxx>
CommitDate: Thu Jan 21 17:31:39 2021 +0100

    tools/xenstore: split off domain introduction from do_introduce()
    
    For live update the functionality to introduce a new domain similar to
    the XS_INTRODUCE command is needed, so split that functionality off
    into a dedicated function introduce_domain().
    
    Switch initial dom0 initialization to use this function, too.
    
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Reviewed-by: Julien Grall <jgrall@xxxxxxxxxx>
    Acked-by: Wei Liu <wl@xxxxxxx>
---
 tools/xenstore/xenstored_domain.c | 95 ++++++++++++++++++++++-----------------
 1 file changed, 55 insertions(+), 40 deletions(-)

diff --git a/tools/xenstore/xenstored_domain.c 
b/tools/xenstore/xenstored_domain.c
index 38d250fbed..71b078caf3 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -326,7 +326,7 @@ static struct domain *find_domain_struct(unsigned int domid)
        return NULL;
 }
 
-static struct domain *alloc_domain(void *context, unsigned int domid)
+static struct domain *alloc_domain(const void *context, unsigned int domid)
 {
        struct domain *domain;
 
@@ -347,6 +347,14 @@ static struct domain *alloc_domain(void *context, unsigned 
int domid)
        return domain;
 }
 
+static struct domain *find_or_alloc_domain(const void *ctx, unsigned int domid)
+{
+       struct domain *domain;
+
+       domain = find_domain_struct(domid);
+       return domain ? : alloc_domain(ctx, domid);
+}
+
 static int new_domain(struct domain *domain, int port)
 {
        int rc;
@@ -413,52 +421,41 @@ static void domain_conn_reset(struct domain *domain)
        domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
 }
 
-/* domid, gfn, evtchn, path */
-int do_introduce(struct connection *conn, struct buffered_data *in)
+static struct domain *introduce_domain(const void *ctx,
+                                      unsigned int domid,
+                                      evtchn_port_t port)
 {
        struct domain *domain;
-       char *vec[3];
-       unsigned int domid;
-       evtchn_port_t port;
        int rc;
        struct xenstore_domain_interface *interface;
+       bool is_master_domain = (domid == xenbus_master_domid());
 
-       if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
-               return EINVAL;
-
-       domid = atoi(vec[0]);
-       /* Ignore the gfn, we don't need it. */
-       port = atoi(vec[2]);
-
-       /* Sanity check args. */
-       if (port <= 0)
-               return EINVAL;
-
-       domain = find_domain_struct(domid);
-
-       if (domain == NULL) {
-               /* Hang domain off "in" until we're finished. */
-               domain = alloc_domain(in, domid);
-               if (domain == NULL)
-                       return ENOMEM;
-       }
+       domain = find_or_alloc_domain(ctx, domid);
+       if (!domain)
+               return NULL;
 
        if (!domain->introduced) {
-               interface = map_interface(domid);
+               interface = is_master_domain ? xenbus_map()
+                                            : map_interface(domid);
                if (!interface)
-                       return errno;
-               /* Hang domain off "in" until we're finished. */
+                       return NULL;
                if (new_domain(domain, port)) {
                        rc = errno;
-                       unmap_interface(interface);
-                       return rc;
+                       if (is_master_domain)
+                               unmap_xenbus(interface);
+                       else
+                               unmap_interface(interface);
+                       errno = rc;
+                       return NULL;
                }
                domain->interface = interface;
 
                /* Now domain belongs to its connection. */
                talloc_steal(domain->conn, domain);
 
-               fire_watches(NULL, in, "@introduceDomain", NULL, false, NULL);
+               if (!is_master_domain)
+                       fire_watches(NULL, ctx, "@introduceDomain", NULL,
+                                    false, NULL);
        } else {
                /* Use XS_INTRODUCE for recreating the xenbus event-channel. */
                if (domain->port)
@@ -467,6 +464,32 @@ int do_introduce(struct connection *conn, struct 
buffered_data *in)
                domain->port = (rc == -1) ? 0 : rc;
        }
 
+       return domain;
+}
+
+/* domid, gfn, evtchn, path */
+int do_introduce(struct connection *conn, struct buffered_data *in)
+{
+       struct domain *domain;
+       char *vec[3];
+       unsigned int domid;
+       evtchn_port_t port;
+
+       if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
+               return EINVAL;
+
+       domid = atoi(vec[0]);
+       /* Ignore the gfn, we don't need it. */
+       port = atoi(vec[2]);
+
+       /* Sanity check args. */
+       if (port <= 0)
+               return EINVAL;
+
+       domain = introduce_domain(in, domid, port);
+       if (!domain)
+               return errno;
+
        domain_conn_reset(domain);
 
        send_ack(conn, XS_INTRODUCE);
@@ -692,17 +715,9 @@ static int dom0_init(void)
        if (port == -1)
                return -1;
 
-       dom0 = alloc_domain(NULL, xenbus_master_domid());
+       dom0 = introduce_domain(NULL, xenbus_master_domid(), port);
        if (!dom0)
                return -1;
-       if (new_domain(dom0, port))
-               return -1;
-
-       dom0->interface = xenbus_map();
-       if (dom0->interface == NULL)
-               return -1;
-
-       talloc_steal(dom0->conn, dom0); 
 
        xenevtchn_notify(xce_handle, dom0->port);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.