From 8278e30c459e21db93c17d2182ad8352ec2dd4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:46 +0400 Subject: util: drop qemu_fork() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortunately, qemu_fork() is no longer used since commit a95570e3e4d6 ("io/command: use glib GSpawn, instead of open-coding fork/exec"). (GSpawn uses posix_spawn() whenever possible instead) Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé Message-Id: <20230221124802.4103554-2-marcandre.lureau@redhat.com> --- include/qemu/osdep.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 88c9fac..f68b5d8 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -665,20 +665,6 @@ void qemu_prealloc_mem(int fd, char *area, size_t sz, int max_threads, */ char *qemu_get_pid_name(pid_t pid); -/** - * qemu_fork: - * - * A version of fork that avoids signal handler race - * conditions that can lead to child process getting - * signals that are otherwise only expected by the - * parent. It also resets all signal handlers to the - * default settings. - * - * Returns 0 to child process, pid number to parent - * or -1 on failure. - */ -pid_t qemu_fork(Error **errp); - /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even * when intptr_t is 32-bit and we are aligning a long long. */ -- cgit v1.1 From 3ffef1a55ca3b55fa64d43cd35af5adb2c260463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:50 +0400 Subject: error: add global &error_warn destination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can help debugging issues or develop, when error handling is introduced. Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-6-marcandre.lureau@redhat.com> --- include/qapi/error.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/qapi/error.h b/include/qapi/error.h index d798fae..f21a231 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -520,6 +520,12 @@ static inline void error_propagator_cleanup(ErrorPropagator *prop) G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup); /* + * Special error destination to warn on error. + * See error_setg() and error_propagate() for details. + */ +extern Error *error_warn; + +/* * Special error destination to abort on error. * See error_setg() and error_propagate() for details. */ -- cgit v1.1 From f5fd677ae7cf7cfb07b12adbfd479c460ddc3ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:51 +0400 Subject: win32/socket: introduce qemu_socket_select() helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a wrapper for WSAEventSelect, with Error handling. By default, it will produce a warning, so callers don't have to be modified now, and yet we can spot potential mis-use. Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-7-marcandre.lureau@redhat.com> --- include/sysemu/os-win32.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 97d0243..9f842ae 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -29,6 +29,7 @@ #include #include #include +#include "qemu/typedefs.h" #ifdef HAVE_AFUNIX_H #include @@ -164,6 +165,10 @@ static inline void qemu_funlockfile(FILE *f) #endif } +/* Helper for WSAEventSelect, to report errors */ +bool qemu_socket_select(SOCKET s, WSAEVENT hEventObject, + long lNetworkEvents, Error **errp); + /* We wrap all the sockets functions so that we can * set errno based on WSAGetLastError() */ -- cgit v1.1 From a4aafea26152b58c61c8105ffc574661cdfeb17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:52 +0400 Subject: win32/socket: introduce qemu_socket_unselect() helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A more explicit version of qemu_socket_select() with no events. Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-8-marcandre.lureau@redhat.com> --- include/sysemu/os-win32.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 9f842ae..504a896 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -169,6 +169,8 @@ static inline void qemu_funlockfile(FILE *f) bool qemu_socket_select(SOCKET s, WSAEVENT hEventObject, long lNetworkEvents, Error **errp); +bool qemu_socket_unselect(SOCKET s, Error **errp); + /* We wrap all the sockets functions so that we can * set errno based on WSAGetLastError() */ -- cgit v1.1 From 6eeef4477a8588f44a15458ab560c68d373d1033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:53 +0400 Subject: aio: make aio_set_fd_poll() static to aio-posix.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-9-marcandre.lureau@redhat.com> --- include/block/aio.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'include') diff --git a/include/block/aio.h b/include/block/aio.h index 8fba6a3..543717f 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -482,14 +482,6 @@ void aio_set_fd_handler(AioContext *ctx, IOHandler *io_poll_ready, void *opaque); -/* Set polling begin/end callbacks for a file descriptor that has already been - * registered with aio_set_fd_handler. Do nothing if the file descriptor is - * not registered. - */ -void aio_set_fd_poll(AioContext *ctx, int fd, - IOHandler *io_poll_begin, - IOHandler *io_poll_end); - /* Register an event notifier and associated callbacks. Behaves very similarly * to event_notifier_set_handler. Unlike event_notifier_set_handler, these callbacks * will be invoked when using aio_poll(). -- cgit v1.1 From faa4ec16419c62d616fcc2dfc02d74d7fcc513d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:56 +0400 Subject: main-loop: remove qemu_fd_register(), win32/slirp/socket specific MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Open-code the socket registration where it's needed, to avoid artificially used or unclear generic interface. Furthermore, the following patches are going to make socket handling use FD-only inside QEMU, but we need to handle win32 SOCKET from libslirp. Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-12-marcandre.lureau@redhat.com> --- include/qemu/main-loop.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index c25f390..b3e54e0 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -387,8 +387,6 @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms); /* internal interfaces */ -void qemu_fd_register(int fd); - #define qemu_bh_new(cb, opaque) \ qemu_bh_new_full((cb), (opaque), (stringify(cb))) QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name); -- cgit v1.1 From abe34282b088499f4e86fff9bb6d6dafd57ae1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:47:59 +0400 Subject: win32: avoid mixing SOCKET and file descriptor space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now, a win32 SOCKET handle is often cast to an int file descriptor, as this is what other OS use for sockets. When necessary, QEMU eventually queries whether it's a socket with the help of fd_is_socket(). However, there is no guarantee of conflict between the fd and SOCKET space. Such conflict would have surprising consequences, we shouldn't mix them. Also, it is often forgotten that SOCKET must be closed with closesocket(), and not close(). Instead, let's make the win32 socket wrapper functions return and take a file descriptor, and let util/ wrappers do the fd/SOCKET conversion as necessary. A bit of adaptation is necessary in io/ as well. Unfortunately, we can't drop closesocket() usage, despite _open_osfhandle() documentation claiming transfer of ownership, testing shows bad behaviour if you forget to call closesocket(). Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-15-marcandre.lureau@redhat.com> --- include/sysemu/os-win32.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index 504a896..cb1dcce 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -166,10 +166,10 @@ static inline void qemu_funlockfile(FILE *f) } /* Helper for WSAEventSelect, to report errors */ -bool qemu_socket_select(SOCKET s, WSAEVENT hEventObject, +bool qemu_socket_select(int sockfd, WSAEVENT hEventObject, long lNetworkEvents, Error **errp); -bool qemu_socket_unselect(SOCKET s, Error **errp); +bool qemu_socket_unselect(int sockfd, Error **errp); /* We wrap all the sockets functions so that we can * set errno based on WSAGetLastError() -- cgit v1.1 From b7e5374637daffa49657be2c559a0566836a172f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:48:00 +0400 Subject: os-posix: remove useless ioctlsocket() define MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The API is specific to win32. Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé Message-Id: <20230221124802.4103554-16-marcandre.lureau@redhat.com> --- include/sysemu/os-posix.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h index 58de7c9..378213f 100644 --- a/include/sysemu/os-posix.h +++ b/include/sysemu/os-posix.h @@ -52,7 +52,6 @@ void os_setup_post(void); int os_mlock(void); #define closesocket(s) close(s) -#define ioctlsocket(s, r, v) ioctl(s, r, v) int os_set_daemonize(bool d); bool is_daemonized(void); -- cgit v1.1 From 25657fc6c1b693096e2ceadaa53cd10c1e81c8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 21 Feb 2023 16:48:01 +0400 Subject: win32: replace closesocket() with close() wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a close() wrapper instead, so that we don't need to worry about closesocket() vs close() anymore, let's hope. Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Message-Id: <20230221124802.4103554-17-marcandre.lureau@redhat.com> --- include/sysemu/os-posix.h | 2 -- include/sysemu/os-win32.h | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h index 378213f..1030d39 100644 --- a/include/sysemu/os-posix.h +++ b/include/sysemu/os-posix.h @@ -51,8 +51,6 @@ void os_daemonize(void); void os_setup_post(void); int os_mlock(void); -#define closesocket(s) close(s) - int os_set_daemonize(bool d); bool is_daemonized(void); diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index cb1dcce..e2849f8 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -175,6 +175,10 @@ bool qemu_socket_unselect(int sockfd, Error **errp); * set errno based on WSAGetLastError() */ +#undef close +#define close qemu_close_wrap +int qemu_close_wrap(int fd); + #undef connect #define connect qemu_connect_wrap int qemu_connect_wrap(int sockfd, const struct sockaddr *addr, @@ -206,10 +210,6 @@ int qemu_shutdown_wrap(int sockfd, int how); #define ioctlsocket qemu_ioctlsocket_wrap int qemu_ioctlsocket_wrap(int fd, int req, void *val); -#undef closesocket -#define closesocket qemu_closesocket_wrap -int qemu_closesocket_wrap(int fd); - #undef getsockopt #define getsockopt qemu_getsockopt_wrap int qemu_getsockopt_wrap(int sockfd, int level, int optname, -- cgit v1.1 From 0a237f4de45b8addbc35a316ee1c0bc7a4887da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 6 Mar 2023 16:27:44 +0400 Subject: osdep: implement qemu_socketpair() for win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Manually implement a socketpair() function, using UNIX sockets and simple peer credential checking. QEMU doesn't make much use of socketpair, beside vhost-user which is not available for win32 at this point. However, I intend to use it for writing some new portable tests. Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé Message-Id: <20230306122751.2355515-5-marcandre.lureau@redhat.com> --- include/qemu/sockets.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 2b0698a..d935fd8 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -15,7 +15,6 @@ int inet_aton(const char *cp, struct in_addr *ia); bool fd_is_socket(int fd); int qemu_socket(int domain, int type, int protocol); -#ifndef WIN32 /** * qemu_socketpair: * @domain: specifies a communication domain, such as PF_UNIX @@ -30,7 +29,6 @@ int qemu_socket(int domain, int type, int protocol); * Return 0 on success. */ int qemu_socketpair(int domain, int type, int protocol, int sv[2]); -#endif int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); /* -- cgit v1.1