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.andryuk@amd.com>
---
v5:
Split get_domain_evtchn() in minios.c and posix.c versions
s/dom0/stubdom/
---
tools/xenstored/core.h | 2 +-
tools/xenstored/domain.c | 9 +++++++--
tools/xenstored/minios.c | 17 +++++++++++++++--
tools/xenstored/posix.c | 16 +++++++++++++++-
4 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h
index 1ba9592d16..877b1e1103 100644
--- a/tools/xenstored/core.h
+++ b/tools/xenstored/core.h
@@ -394,7 +394,7 @@ static inline bool domain_is_unprivileged(const struct connection *conn)
}
/* 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 1241f8c73e..71ab7aaad3 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -1256,7 +1256,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");
@@ -1271,11 +1271,16 @@ void stubdom_init(void)
{
#ifdef __MINIOS__
struct domain *stubdom;
+ evtchn_port_t port;
if (stub_domid < 0)
return;
- 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 a229954cf4..a86edbd5c8 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)
+/*
+ * 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)
{
- return dom0_event;
+ 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 6037d739d0..d850dc0da9 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