[PATCH v2 4/9] xenstored: don't use xenevtchn_fdopen() in stubdom

Juergen Gross posted 9 patches 3 months ago
There is a newer version of this series
[PATCH v2 4/9] xenstored: don't use xenevtchn_fdopen() in stubdom
Posted by Juergen Gross 3 months ago
When running in a stubdom environment xenevtchn_fdopen() won't work,
as any file descriptor state is lost across kexec().

Use a wrapper to replace the call of xenevtchn_fdopen() with the
really needed xenevtchn_open() when running on top of Mini-OS.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
---
 tools/xenstored/core.h   | 3 +++
 tools/xenstored/domain.c | 2 +-
 tools/xenstored/minios.c | 5 +++++
 tools/xenstored/posix.c  | 5 +++++
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h
index 1ba9592d16..bef24a688c 100644
--- a/tools/xenstored/core.h
+++ b/tools/xenstored/core.h
@@ -29,6 +29,7 @@
 #include <stdint.h>
 #include <time.h>
 #include <errno.h>
+#include <xenevtchn.h>
 
 #include "xenstore_lib.h"
 #include "xenstore_state.h"
@@ -405,6 +406,8 @@ void handle_special_fds(void);
 int get_socket_fd(void);
 void set_socket_fd(int fd);
 
+xenevtchn_handle *evtchn_fdopen(int fd);
+
 #ifdef __MINIOS__
 void mount_9pfs(void);
 #endif
diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index 2362216a7a..6767d29a19 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -1396,7 +1396,7 @@ void domain_init(int evtfd)
 	if (evtfd < 0)
 		xce_handle = xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC);
 	else
-		xce_handle = xenevtchn_fdopen(NULL, evtfd, 0);
+		xce_handle = evtchn_fdopen(evtfd);
 
 	if (xce_handle == NULL)
 		barf_perror("Failed to open evtchn device");
diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c
index a229954cf4..aa1f03fd6b 100644
--- a/tools/xenstored/minios.c
+++ b/tools/xenstored/minios.c
@@ -85,6 +85,11 @@ void set_socket_fd(int fd)
 {
 }
 
+xenevtchn_handle *evtchn_fdopen(int fd)
+{
+	return xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC);
+}
+
 static void mount_thread(void *p)
 {
 	xenbus_event_queue events = NULL;
diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
index 6037d739d0..ebdec82215 100644
--- a/tools/xenstored/posix.c
+++ b/tools/xenstored/posix.c
@@ -408,6 +408,11 @@ void set_socket_fd(int fd)
 	sock = fd;
 }
 
+xenevtchn_handle *evtchn_fdopen(int fd)
+{
+	return xenevtchn_fdopen(NULL, fd, 0);
+}
+
 const char *xenstore_rundir(void)
 {
 	return xenstore_daemon_rundir();
-- 
2.43.0