Add helpers to lookup the event channel for a domid.  This hides some
of the differences between dom0 and stubdom xenstored.  Each version
defines its own.

It highlights the different meanings between get_xenbus_evtchn() in a
stubdom, where it looks up dom0's event channel, and dom0, where it
looks up the local event channel.

get_domain_evtchn() replaces get_xenbus_evtchn(), and
get_xenbus_evtchn() is removed from minios.c as it is inlined in the new
function.

The default return 0 will be fine as any other auto-introduced domain
will needs the event channel populated in the grant.

Signed-off-by: Jason Andryuk <jason.andr...@amd.com>
Reviewed-by: Juergen Gross <jgr...@suse.com>
---
v6:
R-b: Juergen

v5:
Split get_domain_evtchn() in minios.c and posix.c versions
s/dom0/stubdom/
---
 tools/xenstored/core.h   |  2 +-
 tools/xenstored/domain.c | 10 +++++++---
 tools/xenstored/minios.c | 19 ++++++++++++++++---
 tools/xenstored/posix.c  | 16 +++++++++++++++-
 4 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h
index 5071f1dedd..cef3c71eb0 100644
--- a/tools/xenstored/core.h
+++ b/tools/xenstored/core.h
@@ -397,7 +397,7 @@ static inline bool domain_is_unprivileged(const struct 
connection *conn)
 extern xenevtchn_handle *xce_handle; /* in domain.c */
 
 /* Return the event channel used by xenbus. */
-evtchn_port_t get_xenbus_evtchn(void);
+evtchn_port_t get_domain_evtchn(unsigned int domid);
 void early_init(bool live_update, bool dofork, const char *pidfile);
 void late_init(bool live_update);
 
diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index 60d398682f..0866e04aa9 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -1330,7 +1330,7 @@ void dom0_init(void)
        evtchn_port_t port;
        struct domain *dom0;
 
-       port = get_xenbus_evtchn();
+       port = get_domain_evtchn(xenbus_master_domid());
        if (port == -1)
                barf_perror("Failed to initialize dom0 port");
 
@@ -1345,13 +1345,17 @@ void stubdom_init(bool live_update)
 {
 #ifdef __MINIOS__
        struct domain *stubdom;
+       evtchn_port_t port;
 
        if (stub_domid < 0)
                return;
 
        if (!live_update) {
-               stubdom = introduce_domain(NULL, stub_domid, xenbus_evtchn,
-                                          false);
+               port = get_domain_evtchn(stub_domid);
+               if (port == -1)
+                       barf_perror("Failed to initialize stubdom port");
+
+               stubdom = introduce_domain(NULL, stub_domid, port, false);
                if (!stubdom)
                        barf_perror("Failed to initialize stubdom");
 
diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c
index f04423fe09..60d921cf01 100644
--- a/tools/xenstored/minios.c
+++ b/tools/xenstored/minios.c
@@ -41,9 +41,22 @@ struct connection *add_socket_connection(int fd)
        barf("socket based connection without sockets");
 }
 
-evtchn_port_t get_xenbus_evtchn(void)
-{
-       return dom0_event;
+/*
+ * minios stubdom looks up dom0's event channel from the command line
+ * (--event).  The stubdom's own event channel is returned directly.
+ *
+ * Any other existing domains from dom0less/Hyperlaunch will have
+ * the event channel in the xenstore page, so lookup here isn't necessary.
+ * --event would not be set, so it would default to 0.
+ */
+evtchn_port_t get_domain_evtchn(unsigned int domid)
+{
+       if (domid == stub_domid)
+               return xenbus_evtchn;
+       else if (domid == priv_domid)
+               return dom0_event;
+
+       return 0;
 }
 
 void *xenbus_map(void)
diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
index 97561701ae..4a97f53dc0 100644
--- a/tools/xenstored/posix.c
+++ b/tools/xenstored/posix.c
@@ -139,7 +139,7 @@ void unmap_xenbus(void *interface)
        munmap(interface, getpagesize());
 }
 
-evtchn_port_t get_xenbus_evtchn(void)
+static evtchn_port_t get_xenbus_evtchn(void)
 {
        int fd;
        int rc;
@@ -166,6 +166,20 @@ evtchn_port_t get_xenbus_evtchn(void)
        return port;
 }
 
+/*
+ * dom0 xenstored uses get_xenbus_evtchn() to lookup with XENSTORED_PORT_DEV.
+ *
+ * Any other existing domains from dom0less/Hyperlaunch will have
+ * the event channel in the xenstore page, so lookup here isn't necessary.
+ */
+evtchn_port_t get_domain_evtchn(unsigned int domid)
+{
+       if (domid == xenbus_master_domid())
+               return get_xenbus_evtchn();
+
+       return 0;
+}
+
 void *xenbus_map(void)
 {
        int fd;
-- 
2.50.1


Reply via email to