Merge tag 'misc-pull-request' of gitlab.com:marcandre.lureau/qemu into staging

Misc cleanups

# -----BEGIN PGP SIGNATURE-----
#
# iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmJxKjQcHG1hcmNhbmRy
# ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5ZD5D/9f5CGbNsrl7kB1t6iS
# 1ABr5AeW0g9sidMCsQAe9xhWl6+R2SO/z0bBue+mv1ltG0RSZ1ZXS4FyJFBAhFfR
# fZ6J7bvdnawIKOxu5T9NY/UvthdRV0eC8CTo0q6GAJo9MHyIGvo1TOoM2Ld9QpfB
# 2uup+9fw3Clh0HSHwV9LSL7v2nucFef4A5P1CJ6d1KHnnej0hfug5o+Aiy+wDLA2
# 5RnTm44dqm9lzTgt/x4MqE6Us7WWQukjlLny8/gyurNTR+6fxLqjsHZG+6woQETu
# Gg6angsOoAFyciFZ564rjGv80qQuccMVMjtrKvBZz/cmwUUz+Lb4tU3tUPBqomGX
# wiofVtL4qcXs94OHWX654UX/iXgkRqC3r+aC0xT37cL4svC8N69BhilxI5+gIGxZ
# ZjaQhHx/0e+Ut3c+xrjYHbywQMd9L9AhRyYSMz5BNeLg9+yUiMR+hvGVR/SubLN1
# iiLS07CRgdOKdP6ts7CC7txAgDw4h3cPN5Hz+gqXMJTcnBKpXpnF1lL+Zd/J5++N
# 8qMVQH5O4REQRISsbKaOPW8PCiPESsUaHb/mWkre7iYLgkEdNMVQvRcnfx14ejbk
# /KKXolrG1huJXGQGnYvgJArHMBBL+ieIYiT6alKFNRNECLdioL46FuSOlirHVCGe
# StU22Vsl61M8ifDOPdolK55X5Q==
# =npwd
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 03 May 2022 06:12:20 AM PDT
# gpg:                using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5
# gpg:                issuer "marcandre.lureau@redhat.com"
# gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full]
# gpg:                 aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full]

* tag 'misc-pull-request' of gitlab.com:marcandre.lureau/qemu: (23 commits)
  util: rename qemu_*block() socket functions
  tests: replace qemu_set_nonblock()
  net: replace qemu_set_nonblock()
  ui: replace qemu_set_nonblock()
  hw: replace qemu_set_nonblock()
  qga: replace qemu_set_nonblock()
  io: replace qemu_set{_non}block()
  chardev: replace qemu_set_nonblock()
  io: make qio_channel_command_new_pid() static
  Replace fcntl(O_NONBLOCK) with g_unix_set_fd_nonblocking()
  io: replace pipe() with g_unix_open_pipe(CLOEXEC)
  virtiofsd: replace pipe() with g_unix_open_pipe(CLOEXEC)
  os-posix: replace pipe()+cloexec with g_unix_open_pipe(CLOEXEC)
  tests: replace pipe() with g_unix_open_pipe(CLOEXEC)
  qga: replace pipe() with g_unix_open_pipe(CLOEXEC)
  util: replace pipe()+cloexec with g_unix_open_pipe()
  Replace qemu_pipe() with g_unix_open_pipe()
  block: move fcntl_setfl()
  Use g_unix_set_fd_nonblocking()
  libqtest: split QMP part in libqmp
  ...

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson
2022-05-03 09:13:17 -07:00
192 changed files with 609 additions and 565 deletions
+15
View File
@@ -1022,6 +1022,21 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
return ret;
}
/* Sets a specific flag */
static int fcntl_setfl(int fd, int flag)
{
int flags;
flags = fcntl(fd, F_GETFL);
if (flags == -1) {
return -errno;
}
if (fcntl(fd, F_SETFL, flags | flag) == -1) {
return -errno;
}
return 0;
}
static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
int *open_flags, uint64_t perm, bool force_dup,
Error **errp)
+2 -2
View File
@@ -212,8 +212,8 @@ void qemu_chr_open_fd(Chardev *chr,
FDChardev *s = FD_CHARDEV(chr);
g_autofree char *name = NULL;
if (fd_out >= 0) {
qemu_set_nonblock(fd_out);
if (fd_out >= 0 && !g_unix_set_fd_nonblocking(fd_out, true, NULL)) {
assert(!"Failed to set FD nonblocking");
}
if (fd_out == fd_in && fd_in >= 0) {
+4 -1
View File
@@ -324,7 +324,10 @@ static void char_pty_open(Chardev *chr,
}
close(slave_fd);
qemu_set_nonblock(master_fd);
if (!g_unix_set_fd_nonblocking(master_fd, true, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return;
}
chr->filename = g_strdup_printf("pty:%s", pty_name);
qemu_printf("char device redirected to %s (label %s)\n",
+4 -1
View File
@@ -271,7 +271,10 @@ static void qmp_chardev_open_serial(Chardev *chr,
if (fd < 0) {
return;
}
qemu_set_nonblock(fd);
if (!g_unix_set_fd_nonblocking(fd, true, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return;
}
tty_serial_init(fd, 115200, 'N', 8, 1);
qemu_chr_open_fd(chr, fd, fd);
+1 -1
View File
@@ -311,7 +311,7 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)
}
/* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
qemu_set_block(fd);
qemu_socket_set_block(fd);
#ifndef MSG_CMSG_CLOEXEC
qemu_set_cloexec(fd);
+4 -1
View File
@@ -103,7 +103,10 @@ static void qemu_chr_open_stdio(Chardev *chr,
stdio_in_use = true;
old_fd0_flags = fcntl(0, F_GETFL);
tcgetattr(0, &oldtty);
qemu_set_nonblock(0);
if (!g_unix_set_fd_nonblocking(0, true, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return;
}
atexit(term_exit);
memset(&act, 0, sizeof(act));
+1 -1
View File
@@ -146,7 +146,7 @@ ivshmem_server_handle_new_conn(IvshmemServer *server)
return -1;
}
qemu_set_nonblock(newfd);
qemu_socket_set_nonblock(newfd);
IVSHMEM_SERVER_DEBUG(server, "accept()=%d\n", newfd);
/* allocate new structure for this peer */
+1 -1
View File
@@ -88,4 +88,4 @@ QTest Protocol
libqtest API reference
----------------------
.. kernel-doc:: tests/qtest/libqos/libqtest.h
.. kernel-doc:: tests/qtest/libqtest.h
+1 -1
View File
@@ -334,7 +334,7 @@ static void hv_syndbg_realize(DeviceState *dev, Error **errp)
return;
}
qemu_set_nonblock(syndbg->socket);
qemu_socket_set_nonblock(syndbg->socket);
syndbg->servaddr.sin_port = htons(syndbg->host_port);
syndbg->servaddr.sin_family = AF_INET;
+4 -1
View File
@@ -114,7 +114,10 @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp)
error_setg_file_open(errp, errno, vih->evdev);
return;
}
qemu_set_nonblock(vih->fd);
if (!g_unix_set_fd_nonblocking(vih->fd, true, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
goto err_close;
}
rc = ioctl(vih->fd, EVIOCGVERSION, &ver);
if (rc < 0) {
+1 -1
View File
@@ -537,7 +537,7 @@ static void process_msg_connect(IVShmemState *s, uint16_t posn, int fd,
IVSHMEM_DPRINTF("eventfds[%d][%d] = %d\n", posn, vector, fd);
event_notifier_init_fd(&peer->eventfds[vector], fd);
fcntl_setfl(fd, O_NONBLOCK); /* msix/irqfd poll non block */
g_unix_set_fd_nonblocking(fd, true, NULL); /* msix/irqfd poll non block */
if (posn == s->vm_id) {
setup_interrupt(s, vector, errp);
+1 -1
View File
@@ -1826,7 +1826,7 @@ static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp)
error_setg(errp, "%s: Failed to get ufd", __func__);
return -EIO;
}
qemu_set_nonblock(ufd);
qemu_socket_set_nonblock(ufd);
/* register ufd with userfault thread */
u->postcopy_fd.fd = ufd;
+7 -4
View File
@@ -149,9 +149,8 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
return;
}
ret = qemu_try_set_nonblock(vhostfd);
if (ret < 0) {
error_setg_errno(errp, -ret,
if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
error_setg_errno(errp, errno,
"vhost-vsock: unable to set non-blocking mode");
return;
}
@@ -163,7 +162,11 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
return;
}
qemu_set_nonblock(vhostfd);
if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
error_setg_errno(errp, errno,
"Failed to set FD nonblocking");
return;
}
}
vhost_vsock_common_realize(vdev, "vhost-vsock");
-25
View File
@@ -45,31 +45,6 @@ struct QIOChannelCommand {
};
/**
* qio_channel_command_new_pid:
* @writefd: the FD connected to the command's stdin
* @readfd: the FD connected to the command's stdout
* @pid: the PID of the running child command
* @errp: pointer to a NULL-initialized error object
*
* Create a channel for performing I/O with the
* previously spawned command identified by @pid.
* The two file descriptors provide the connection
* to command's stdio streams, either one or which
* may be -1 to indicate that stream is not open.
*
* The channel will take ownership of the process
* @pid and will kill it when closing the channel.
* Similarly it will take responsibility for
* closing the file descriptors @writefd and @readfd.
*
* Returns: the command channel object, or NULL on error
*/
QIOChannelCommand *
qio_channel_command_new_pid(int writefd,
int readfd,
pid_t pid);
/**
* qio_channel_command_new_spawn:
* @argv: the NULL terminated list of command arguments
+5 -3
View File
@@ -15,6 +15,8 @@
#ifndef QEMU_ATOMIC_H
#define QEMU_ATOMIC_H
#include "compiler.h"
/* Compiler barrier */
#define barrier() ({ asm volatile("" ::: "memory"); (void)0; })
@@ -81,7 +83,7 @@
* no processors except Alpha need a barrier here. Leave it in if
* using Thread Sanitizer to avoid warnings, otherwise optimize it away.
*/
#if defined(__SANITIZE_THREAD__)
#ifdef QEMU_SANITIZE_THREAD
#define smp_read_barrier_depends() ({ barrier(); __atomic_thread_fence(__ATOMIC_CONSUME); })
#elif defined(__alpha__)
#define smp_read_barrier_depends() asm volatile("mb":::"memory")
@@ -146,7 +148,7 @@
/* See above: most compilers currently treat consume and acquire the
* same, but this slows down qatomic_rcu_read unnecessarily.
*/
#ifdef __SANITIZE_THREAD__
#ifdef QEMU_SANITIZE_THREAD
#define qatomic_rcu_read__nocheck(ptr, valptr) \
__atomic_load(ptr, valptr, __ATOMIC_CONSUME);
#else
@@ -254,7 +256,7 @@
#define qatomic_mb_read(ptr) \
qatomic_load_acquire(ptr)
#if !defined(__SANITIZE_THREAD__) && \
#if !defined(QEMU_SANITIZE_THREAD) && \
(defined(__i386__) || defined(__x86_64__) || defined(__s390x__))
/* This is more efficient than a store plus a fence. */
# define qatomic_mb_set(ptr, i) ((void)qatomic_xchg(ptr, i))
-4
View File
@@ -547,10 +547,6 @@ static inline void qemu_timersub(const struct timeval *val1,
ssize_t qemu_write_full(int fd, const void *buf, size_t count)
G_GNUC_WARN_UNUSED_RESULT;
#ifndef _WIN32
int qemu_pipe(int pipefd[2]);
#endif
void qemu_set_cloexec(int fd);
/* Return a dynamically allocated directory path that is appropriate for storing
+3 -3
View File
@@ -17,9 +17,9 @@ int qemu_socket(int domain, int type, int protocol);
int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int socket_set_cork(int fd, int v);
int socket_set_nodelay(int fd);
void qemu_set_block(int fd);
int qemu_try_set_nonblock(int fd);
void qemu_set_nonblock(int fd);
void qemu_socket_set_block(int fd);
int qemu_socket_try_set_nonblock(int fd);
void qemu_socket_set_nonblock(int fd);
int socket_set_fast_reuse(int fd);
#ifdef WIN32
-2
View File
@@ -96,8 +96,6 @@ static inline void qemu_funlockfile(FILE *f)
funlockfile(f);
}
int fcntl_setfl(int fd, int flag);
#ifdef __cplusplus
}
#endif
+33 -13
View File
@@ -26,8 +26,28 @@
#include "qemu/sockets.h"
#include "trace.h"
QIOChannelCommand *
#ifndef WIN32
/**
* qio_channel_command_new_pid:
* @writefd: the FD connected to the command's stdin
* @readfd: the FD connected to the command's stdout
* @pid: the PID of the running child command
* @errp: pointer to a NULL-initialized error object
*
* Create a channel for performing I/O with the
* previously spawned command identified by @pid.
* The two file descriptors provide the connection
* to command's stdio streams, either one or which
* may be -1 to indicate that stream is not open.
*
* The channel will take ownership of the process
* @pid and will kill it when closing the channel.
* Similarly it will take responsibility for
* closing the file descriptors @writefd and @readfd.
*
* Returns: the command channel object, or NULL on error
*/
static QIOChannelCommand *
qio_channel_command_new_pid(int writefd,
int readfd,
pid_t pid)
@@ -44,8 +64,6 @@ qio_channel_command_new_pid(int writefd,
return ioc;
}
#ifndef WIN32
QIOChannelCommand *
qio_channel_command_new_spawn(const char *const argv[],
int flags,
@@ -76,8 +94,8 @@ qio_channel_command_new_spawn(const char *const argv[],
}
}
if ((!stdinnull && pipe(stdinfd) < 0) ||
(!stdoutnull && pipe(stdoutfd) < 0)) {
if ((!stdinnull && !g_unix_open_pipe(stdinfd, FD_CLOEXEC, NULL)) ||
(!stdoutnull && !g_unix_open_pipe(stdoutfd, FD_CLOEXEC, NULL))) {
error_setg_errno(errp, errno,
"Unable to open pipe");
goto error;
@@ -283,16 +301,18 @@ static int qio_channel_command_set_blocking(QIOChannel *ioc,
bool enabled,
Error **errp)
{
#ifdef WIN32
/* command spawn is not supported on win32 */
g_assert_not_reached();
#else
QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc);
if (enabled) {
qemu_set_block(cioc->writefd);
qemu_set_block(cioc->readfd);
} else {
qemu_set_nonblock(cioc->writefd);
qemu_set_nonblock(cioc->readfd);
if (!g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL) ||
!g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return -1;
}
#endif
return 0;
}
+9 -4
View File
@@ -139,14 +139,19 @@ static int qio_channel_file_set_blocking(QIOChannel *ioc,
bool enabled,
Error **errp)
{
#ifdef WIN32
/* not implemented */
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return -1;
#else
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
if (enabled) {
qemu_set_block(fioc->fd);
} else {
qemu_set_nonblock(fioc->fd);
if (!g_unix_set_fd_nonblocking(fioc->fd, !enabled, NULL)) {
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return -1;
}
return 0;
#endif
}

Some files were not shown because too many files have changed in this diff Show More