mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-15 06:01:58 -06:00
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----- 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:
commit
2e3408b3cc
192 changed files with 609 additions and 565 deletions
|
@ -1022,6 +1022,21 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
|
||||||
return ret;
|
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,
|
static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
|
||||||
int *open_flags, uint64_t perm, bool force_dup,
|
int *open_flags, uint64_t perm, bool force_dup,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
|
|
|
@ -212,8 +212,8 @@ void qemu_chr_open_fd(Chardev *chr,
|
||||||
FDChardev *s = FD_CHARDEV(chr);
|
FDChardev *s = FD_CHARDEV(chr);
|
||||||
g_autofree char *name = NULL;
|
g_autofree char *name = NULL;
|
||||||
|
|
||||||
if (fd_out >= 0) {
|
if (fd_out >= 0 && !g_unix_set_fd_nonblocking(fd_out, true, NULL)) {
|
||||||
qemu_set_nonblock(fd_out);
|
assert(!"Failed to set FD nonblocking");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd_out == fd_in && fd_in >= 0) {
|
if (fd_out == fd_in && fd_in >= 0) {
|
||||||
|
|
|
@ -324,7 +324,10 @@ static void char_pty_open(Chardev *chr,
|
||||||
}
|
}
|
||||||
|
|
||||||
close(slave_fd);
|
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);
|
chr->filename = g_strdup_printf("pty:%s", pty_name);
|
||||||
qemu_printf("char device redirected to %s (label %s)\n",
|
qemu_printf("char device redirected to %s (label %s)\n",
|
||||||
|
|
|
@ -271,7 +271,10 @@ static void qmp_chardev_open_serial(Chardev *chr,
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return;
|
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);
|
tty_serial_init(fd, 115200, 'N', 8, 1);
|
||||||
|
|
||||||
qemu_chr_open_fd(chr, fd, fd);
|
qemu_chr_open_fd(chr, fd, fd);
|
||||||
|
|
|
@ -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 */
|
/* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
|
||||||
qemu_set_block(fd);
|
qemu_socket_set_block(fd);
|
||||||
|
|
||||||
#ifndef MSG_CMSG_CLOEXEC
|
#ifndef MSG_CMSG_CLOEXEC
|
||||||
qemu_set_cloexec(fd);
|
qemu_set_cloexec(fd);
|
||||||
|
|
|
@ -103,7 +103,10 @@ static void qemu_chr_open_stdio(Chardev *chr,
|
||||||
stdio_in_use = true;
|
stdio_in_use = true;
|
||||||
old_fd0_flags = fcntl(0, F_GETFL);
|
old_fd0_flags = fcntl(0, F_GETFL);
|
||||||
tcgetattr(0, &oldtty);
|
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);
|
atexit(term_exit);
|
||||||
|
|
||||||
memset(&act, 0, sizeof(act));
|
memset(&act, 0, sizeof(act));
|
||||||
|
|
|
@ -146,7 +146,7 @@ ivshmem_server_handle_new_conn(IvshmemServer *server)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_set_nonblock(newfd);
|
qemu_socket_set_nonblock(newfd);
|
||||||
IVSHMEM_SERVER_DEBUG(server, "accept()=%d\n", newfd);
|
IVSHMEM_SERVER_DEBUG(server, "accept()=%d\n", newfd);
|
||||||
|
|
||||||
/* allocate new structure for this peer */
|
/* allocate new structure for this peer */
|
||||||
|
|
|
@ -88,4 +88,4 @@ QTest Protocol
|
||||||
libqtest API reference
|
libqtest API reference
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
.. kernel-doc:: tests/qtest/libqos/libqtest.h
|
.. kernel-doc:: tests/qtest/libqtest.h
|
||||||
|
|
|
@ -334,7 +334,7 @@ static void hv_syndbg_realize(DeviceState *dev, Error **errp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_set_nonblock(syndbg->socket);
|
qemu_socket_set_nonblock(syndbg->socket);
|
||||||
|
|
||||||
syndbg->servaddr.sin_port = htons(syndbg->host_port);
|
syndbg->servaddr.sin_port = htons(syndbg->host_port);
|
||||||
syndbg->servaddr.sin_family = AF_INET;
|
syndbg->servaddr.sin_family = AF_INET;
|
||||||
|
|
|
@ -114,7 +114,10 @@ static void virtio_input_host_realize(DeviceState *dev, Error **errp)
|
||||||
error_setg_file_open(errp, errno, vih->evdev);
|
error_setg_file_open(errp, errno, vih->evdev);
|
||||||
return;
|
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);
|
rc = ioctl(vih->fd, EVIOCGVERSION, &ver);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|
|
@ -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);
|
IVSHMEM_DPRINTF("eventfds[%d][%d] = %d\n", posn, vector, fd);
|
||||||
event_notifier_init_fd(&peer->eventfds[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) {
|
if (posn == s->vm_id) {
|
||||||
setup_interrupt(s, vector, errp);
|
setup_interrupt(s, vector, errp);
|
||||||
|
|
|
@ -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__);
|
error_setg(errp, "%s: Failed to get ufd", __func__);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
qemu_set_nonblock(ufd);
|
qemu_socket_set_nonblock(ufd);
|
||||||
|
|
||||||
/* register ufd with userfault thread */
|
/* register ufd with userfault thread */
|
||||||
u->postcopy_fd.fd = ufd;
|
u->postcopy_fd.fd = ufd;
|
||||||
|
|
|
@ -149,9 +149,8 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemu_try_set_nonblock(vhostfd);
|
if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
|
||||||
if (ret < 0) {
|
error_setg_errno(errp, errno,
|
||||||
error_setg_errno(errp, -ret,
|
|
||||||
"vhost-vsock: unable to set non-blocking mode");
|
"vhost-vsock: unable to set non-blocking mode");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +162,11 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
|
||||||
return;
|
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");
|
vhost_vsock_common_realize(vdev, "vhost-vsock");
|
||||||
|
|
|
@ -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:
|
* qio_channel_command_new_spawn:
|
||||||
* @argv: the NULL terminated list of command arguments
|
* @argv: the NULL terminated list of command arguments
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#ifndef QEMU_ATOMIC_H
|
#ifndef QEMU_ATOMIC_H
|
||||||
#define QEMU_ATOMIC_H
|
#define QEMU_ATOMIC_H
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
|
||||||
/* Compiler barrier */
|
/* Compiler barrier */
|
||||||
#define barrier() ({ asm volatile("" ::: "memory"); (void)0; })
|
#define barrier() ({ asm volatile("" ::: "memory"); (void)0; })
|
||||||
|
|
||||||
|
@ -81,7 +83,7 @@
|
||||||
* no processors except Alpha need a barrier here. Leave it in if
|
* no processors except Alpha need a barrier here. Leave it in if
|
||||||
* using Thread Sanitizer to avoid warnings, otherwise optimize it away.
|
* 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); })
|
#define smp_read_barrier_depends() ({ barrier(); __atomic_thread_fence(__ATOMIC_CONSUME); })
|
||||||
#elif defined(__alpha__)
|
#elif defined(__alpha__)
|
||||||
#define smp_read_barrier_depends() asm volatile("mb":::"memory")
|
#define smp_read_barrier_depends() asm volatile("mb":::"memory")
|
||||||
|
@ -146,7 +148,7 @@
|
||||||
/* See above: most compilers currently treat consume and acquire the
|
/* See above: most compilers currently treat consume and acquire the
|
||||||
* same, but this slows down qatomic_rcu_read unnecessarily.
|
* same, but this slows down qatomic_rcu_read unnecessarily.
|
||||||
*/
|
*/
|
||||||
#ifdef __SANITIZE_THREAD__
|
#ifdef QEMU_SANITIZE_THREAD
|
||||||
#define qatomic_rcu_read__nocheck(ptr, valptr) \
|
#define qatomic_rcu_read__nocheck(ptr, valptr) \
|
||||||
__atomic_load(ptr, valptr, __ATOMIC_CONSUME);
|
__atomic_load(ptr, valptr, __ATOMIC_CONSUME);
|
||||||
#else
|
#else
|
||||||
|
@ -254,7 +256,7 @@
|
||||||
#define qatomic_mb_read(ptr) \
|
#define qatomic_mb_read(ptr) \
|
||||||
qatomic_load_acquire(ptr)
|
qatomic_load_acquire(ptr)
|
||||||
|
|
||||||
#if !defined(__SANITIZE_THREAD__) && \
|
#if !defined(QEMU_SANITIZE_THREAD) && \
|
||||||
(defined(__i386__) || defined(__x86_64__) || defined(__s390x__))
|
(defined(__i386__) || defined(__x86_64__) || defined(__s390x__))
|
||||||
/* This is more efficient than a store plus a fence. */
|
/* This is more efficient than a store plus a fence. */
|
||||||
# define qatomic_mb_set(ptr, i) ((void)qatomic_xchg(ptr, i))
|
# define qatomic_mb_set(ptr, i) ((void)qatomic_xchg(ptr, i))
|
||||||
|
|
|
@ -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)
|
ssize_t qemu_write_full(int fd, const void *buf, size_t count)
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
int qemu_pipe(int pipefd[2]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void qemu_set_cloexec(int fd);
|
void qemu_set_cloexec(int fd);
|
||||||
|
|
||||||
/* Return a dynamically allocated directory path that is appropriate for storing
|
/* Return a dynamically allocated directory path that is appropriate for storing
|
||||||
|
|
|
@ -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 qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
||||||
int socket_set_cork(int fd, int v);
|
int socket_set_cork(int fd, int v);
|
||||||
int socket_set_nodelay(int fd);
|
int socket_set_nodelay(int fd);
|
||||||
void qemu_set_block(int fd);
|
void qemu_socket_set_block(int fd);
|
||||||
int qemu_try_set_nonblock(int fd);
|
int qemu_socket_try_set_nonblock(int fd);
|
||||||
void qemu_set_nonblock(int fd);
|
void qemu_socket_set_nonblock(int fd);
|
||||||
int socket_set_fast_reuse(int fd);
|
int socket_set_fast_reuse(int fd);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
@ -96,8 +96,6 @@ static inline void qemu_funlockfile(FILE *f)
|
||||||
funlockfile(f);
|
funlockfile(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fcntl_setfl(int fd, int flag);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,8 +26,28 @@
|
||||||
#include "qemu/sockets.h"
|
#include "qemu/sockets.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
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
|
||||||
|
*/
|
||||||
|
static QIOChannelCommand *
|
||||||
qio_channel_command_new_pid(int writefd,
|
qio_channel_command_new_pid(int writefd,
|
||||||
int readfd,
|
int readfd,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
|
@ -44,8 +64,6 @@ qio_channel_command_new_pid(int writefd,
|
||||||
return ioc;
|
return ioc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
QIOChannelCommand *
|
QIOChannelCommand *
|
||||||
qio_channel_command_new_spawn(const char *const argv[],
|
qio_channel_command_new_spawn(const char *const argv[],
|
||||||
int flags,
|
int flags,
|
||||||
|
@ -76,8 +94,8 @@ qio_channel_command_new_spawn(const char *const argv[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!stdinnull && pipe(stdinfd) < 0) ||
|
if ((!stdinnull && !g_unix_open_pipe(stdinfd, FD_CLOEXEC, NULL)) ||
|
||||||
(!stdoutnull && pipe(stdoutfd) < 0)) {
|
(!stdoutnull && !g_unix_open_pipe(stdoutfd, FD_CLOEXEC, NULL))) {
|
||||||
error_setg_errno(errp, errno,
|
error_setg_errno(errp, errno,
|
||||||
"Unable to open pipe");
|
"Unable to open pipe");
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -283,16 +301,18 @@ static int qio_channel_command_set_blocking(QIOChannel *ioc,
|
||||||
bool enabled,
|
bool enabled,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
/* command spawn is not supported on win32 */
|
||||||
|
g_assert_not_reached();
|
||||||
|
#else
|
||||||
QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc);
|
QIOChannelCommand *cioc = QIO_CHANNEL_COMMAND(ioc);
|
||||||
|
|
||||||
if (enabled) {
|
if (!g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL) ||
|
||||||
qemu_set_block(cioc->writefd);
|
!g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL)) {
|
||||||
qemu_set_block(cioc->readfd);
|
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
|
||||||
} else {
|
return -1;
|
||||||
qemu_set_nonblock(cioc->writefd);
|
|
||||||
qemu_set_nonblock(cioc->readfd);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,14 +139,19 @@ static int qio_channel_file_set_blocking(QIOChannel *ioc,
|
||||||
bool enabled,
|
bool enabled,
|
||||||
Error **errp)
|
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);
|
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
|
||||||
|
|
||||||
if (enabled) {
|
if (!g_unix_set_fd_nonblocking(fioc->fd, !enabled, NULL)) {
|
||||||
qemu_set_block(fioc->fd);
|
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
|
||||||
} else {
|
return -1;
|
||||||
qemu_set_nonblock(fioc->fd);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -460,7 +460,7 @@ static void qio_channel_socket_copy_fds(struct msghdr *msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
|
/* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
|
||||||
qemu_set_block(fd);
|
qemu_socket_set_block(fd);
|
||||||
|
|
||||||
#ifndef MSG_CMSG_CLOEXEC
|
#ifndef MSG_CMSG_CLOEXEC
|
||||||
qemu_set_cloexec(fd);
|
qemu_set_cloexec(fd);
|
||||||
|
@ -665,9 +665,9 @@ qio_channel_socket_set_blocking(QIOChannel *ioc,
|
||||||
QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
|
QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
qemu_set_block(sioc->fd);
|
qemu_socket_set_block(sioc->fd);
|
||||||
} else {
|
} else {
|
||||||
qemu_set_nonblock(sioc->fd);
|
qemu_socket_set_nonblock(sioc->fd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -716,7 +716,7 @@ int net_init_l2tpv3(const Netdev *netdev,
|
||||||
s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT);
|
s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT);
|
||||||
s->header_buf = g_malloc(s->header_size);
|
s->header_buf = g_malloc(s->header_size);
|
||||||
|
|
||||||
qemu_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
|
|
||||||
s->fd = fd;
|
s->fd = fd;
|
||||||
s->counter = 0;
|
s->counter = 0;
|
||||||
|
|
10
net/socket.c
10
net/socket.c
|
@ -297,7 +297,7 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
return fd;
|
return fd;
|
||||||
fail:
|
fail:
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
|
@ -522,7 +522,7 @@ static int net_socket_listen_init(NetClientState *peer,
|
||||||
error_setg_errno(errp, errno, "can't create stream socket");
|
error_setg_errno(errp, errno, "can't create stream socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
|
|
||||||
socket_set_fast_reuse(fd);
|
socket_set_fast_reuse(fd);
|
||||||
|
|
||||||
|
@ -570,7 +570,7 @@ static int net_socket_connect_init(NetClientState *peer,
|
||||||
error_setg_errno(errp, errno, "can't create stream socket");
|
error_setg_errno(errp, errno, "can't create stream socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
|
|
||||||
connected = 0;
|
connected = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
@ -688,7 +688,7 @@ static int net_socket_udp_init(NetClientState *peer,
|
||||||
closesocket(fd);
|
closesocket(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
qemu_set_nonblock(fd);
|
qemu_socket_set_nonblock(fd);
|
||||||
|
|
||||||
s = net_socket_fd_init(peer, model, name, fd, 0, NULL, errp);
|
s = net_socket_fd_init(peer, model, name, fd, 0, NULL, errp);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
|
@ -730,7 +730,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = qemu_try_set_nonblock(fd);
|
ret = qemu_socket_try_set_nonblock(fd);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
||||||
name, fd);
|
name, fd);
|
||||||
|
|
|
@ -98,7 +98,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
g_unix_set_fd_nonblocking(fd, true, NULL);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
g_unix_set_fd_nonblocking(fd, true, NULL);
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
|
@ -113,7 +113,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pstrcpy(ifname, ifname_size, ifr.ifr_name);
|
pstrcpy(ifname, ifname_size, ifr.ifr_name);
|
||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
g_unix_set_fd_nonblocking(fd, true, NULL);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
g_unix_set_fd_nonblocking(fd, true, NULL);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
33
net/tap.c
33
net/tap.c
|
@ -619,7 +619,10 @@ int net_init_bridge(const Netdev *netdev, const char *name,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_set_nonblock(fd);
|
if (!g_unix_set_fd_nonblocking(fd, true, NULL)) {
|
||||||
|
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
vnet_hdr = tap_probe_vnet_hdr(fd, errp);
|
vnet_hdr = tap_probe_vnet_hdr(fd, errp);
|
||||||
if (vnet_hdr < 0) {
|
if (vnet_hdr < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -716,8 +719,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vhostfdname) {
|
if (vhostfdname) {
|
||||||
int ret;
|
|
||||||
|
|
||||||
vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, &err);
|
vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, &err);
|
||||||
if (vhostfd == -1) {
|
if (vhostfd == -1) {
|
||||||
if (tap->has_vhostforce && tap->vhostforce) {
|
if (tap->has_vhostforce && tap->vhostforce) {
|
||||||
|
@ -727,9 +728,8 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ret = qemu_try_set_nonblock(vhostfd);
|
if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
|
||||||
if (ret < 0) {
|
error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
|
||||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
|
||||||
name, fd);
|
name, fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -745,7 +745,10 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
||||||
}
|
}
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
options.opaque = (void *)(uintptr_t)vhostfd;
|
options.opaque = (void *)(uintptr_t)vhostfd;
|
||||||
options.nvqs = 2;
|
options.nvqs = 2;
|
||||||
|
@ -832,9 +835,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemu_try_set_nonblock(fd);
|
if (!g_unix_set_fd_nonblocking(fd, true, NULL)) {
|
||||||
if (ret < 0) {
|
error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
|
||||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
|
||||||
name, fd);
|
name, fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -889,9 +891,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
|
||||||
goto free_fail;
|
goto free_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = qemu_try_set_nonblock(fd);
|
ret = g_unix_set_fd_nonblocking(fd, true, NULL);
|
||||||
if (ret < 0) {
|
if (!ret) {
|
||||||
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
|
error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
|
||||||
name, fd);
|
name, fd);
|
||||||
goto free_fail;
|
goto free_fail;
|
||||||
}
|
}
|
||||||
|
@ -946,7 +948,10 @@ free_fail:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_set_nonblock(fd);
|
if (!g_unix_set_fd_nonblocking(fd, true, NULL)) {
|
||||||
|
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
vnet_hdr = tap_probe_vnet_hdr(fd, errp);
|
vnet_hdr = tap_probe_vnet_hdr(fd, errp);
|
||||||
if (vnet_hdr < 0) {
|
if (vnet_hdr < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -215,7 +215,7 @@ void os_daemonize(void)
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
|
|
||||||
if (pipe(fds) == -1) {
|
if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +240,6 @@ void os_daemonize(void)
|
||||||
|
|
||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
daemon_pipe = fds[1];
|
daemon_pipe = fds[1];
|
||||||
qemu_set_cloexec(daemon_pipe);
|
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
|
|
|
@ -909,13 +909,14 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if ((device && !verbose) || fork_process) {
|
if ((device && !verbose) || fork_process) {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
g_autoptr(GError) err = NULL;
|
||||||
int stderr_fd[2];
|
int stderr_fd[2];
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (qemu_pipe(stderr_fd) < 0) {
|
if (!g_unix_open_pipe(stderr_fd, FD_CLOEXEC, &err)) {
|
||||||
error_report("Error setting up communication pipe: %s",
|
error_report("Error setting up communication pipe: %s",
|
||||||
strerror(errno));
|
err->message);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ static gboolean ga_channel_listen_accept(GIOChannel *channel,
|
||||||
g_warning("error converting fd to gsocket: %s", strerror(errno));
|
g_warning("error converting fd to gsocket: %s", strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
qemu_set_nonblock(client_fd);
|
qemu_socket_set_nonblock(client_fd);
|
||||||
ret = ga_channel_client_add(c, client_fd);
|
ret = ga_channel_client_add(c, client_fd);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
g_warning("error setting up connection");
|
g_warning("error setting up connection");
|
||||||
|
|
|
@ -404,7 +404,11 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode,
|
||||||
/* set fd non-blocking to avoid common use cases (like reading from a
|
/* set fd non-blocking to avoid common use cases (like reading from a
|
||||||
* named pipe) from hanging the agent
|
* named pipe) from hanging the agent
|
||||||
*/
|
*/
|
||||||
qemu_set_nonblock(fileno(fh));
|
if (!g_unix_set_fd_nonblocking(fileno(fh), true, NULL)) {
|
||||||
|
fclose(fh);
|
||||||
|
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
handle = guest_file_handle_add(fh, errp);
|
handle = guest_file_handle_add(fh, errp);
|
||||||
if (handle < 0) {
|
if (handle < 0) {
|
||||||
|
@ -2529,7 +2533,7 @@ void qmp_guest_set_user_password(const char *username,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pipe(datafd) < 0) {
|
if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) {
|
||||||
error_setg(errp, "cannot create pipe FDs");
|
error_setg(errp, "cannot create pipe FDs");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ def c_header(owner):
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
""".format(date=date.today().year, owner=owner)
|
""".format(date=date.today().year, owner=owner)
|
||||||
|
|
||||||
|
|
1
subprojects/libvhost-user/include/compiler.h
Symbolic link
1
subprojects/libvhost-user/include/compiler.h
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../../include/qemu/compiler.h
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "libqos/qgraph.h"
|
#include "libqos/qgraph.h"
|
||||||
#include "libqos/pci.h"
|
#include "libqos/pci.h"
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#ifndef TEST_ACPI_UTILS_H
|
#ifndef TEST_ACPI_UTILS_H
|
||||||
#define TEST_ACPI_UTILS_H
|
#define TEST_ACPI_UTILS_H
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/* DSDT and SSDTs format */
|
/* DSDT and SSDTs format */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "libqos/libqos-pc.h"
|
#include "libqos/libqos-pc.h"
|
||||||
#include "libqos/ahci.h"
|
#include "libqos/ahci.h"
|
||||||
#include "libqos/pci-pc.h"
|
#include "libqos/pci-pc.h"
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
|
|
||||||
static void test_cmdfifo_underflow_ok(void)
|
static void test_cmdfifo_underflow_ok(void)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*/
|
*/
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "qemu/bitops.h"
|
#include "qemu/bitops.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "qapi/qmp/qjson.h"
|
#include "qapi/qmp/qjson.h"
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/bitops.h"
|
#include "qemu/bitops.h"
|
||||||
|
|
||||||
#define HACE_CMD 0x10
|
#define HACE_CMD 0x10
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/fw_cfg.h"
|
#include "libqos/fw_cfg.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "standard-headers/linux/qemu_fw_cfg.h"
|
#include "standard-headers/linux/qemu_fw_cfg.h"
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "boot-sector.h"
|
#include "boot-sector.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
#define LOW(x) ((x) & 0xff)
|
#define LOW(x) ((x) & 0xff)
|
||||||
#define HIGH(x) ((x) >> 8)
|
#define HIGH(x) ((x) >> 8)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#ifndef TEST_BOOT_SECTOR_H
|
#ifndef TEST_BOOT_SECTOR_H
|
||||||
#define TEST_BOOT_SECTOR_H
|
#define TEST_BOOT_SECTOR_H
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/* Create boot disk file. fname must be a suitable string for mkstemp() */
|
/* Create boot disk file. fname must be a suitable string for mkstemp() */
|
||||||
int boot_sector_init(char *fname);
|
int boot_sector_init(char *fname);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "libqos/libqos-spapr.h"
|
#include "libqos/libqos-spapr.h"
|
||||||
|
|
||||||
static const uint8_t bios_avr[] = {
|
static const uint8_t bios_avr[] = {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "boot-sector.h"
|
#include "boot-sector.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "qemu/dbus.h"
|
#include "qemu/dbus.h"
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <gio/gunixfdlist.h>
|
#include <gio/gunixfdlist.h>
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "dbus-display1.h"
|
#include "dbus-display1.h"
|
||||||
|
|
||||||
static GDBusConnection*
|
static GDBusConnection*
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "dbus-vmstate1.h"
|
#include "dbus-vmstate1.h"
|
||||||
#include "migration-helpers.h"
|
#include "migration-helpers.h"
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "qapi/qmp/qstring.h"
|
#include "qapi/qmp/qstring.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "qapi/qmp/qlist.h"
|
#include "qapi/qmp/qlist.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
const char common_args[] = "-nodefaults -machine none";
|
const char common_args[] = "-nodefaults -machine none";
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "qapi/qmp/qstring.h"
|
#include "qapi/qmp/qstring.h"
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "libqos/virtio.h"
|
#include "libqos/virtio.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "qapi/qmp/qlist.h"
|
#include "qapi/qmp/qlist.h"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "libqos/i2c.h"
|
#include "libqos/i2c.h"
|
||||||
|
|
||||||
#define DS1338_ADDR 0x68
|
#define DS1338_ADDR 0x68
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "libqos/qgraph.h"
|
#include "libqos/qgraph.h"
|
||||||
#include "libqos/pci.h"
|
#include "libqos/pci.h"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "libqos/qgraph.h"
|
#include "libqos/qgraph.h"
|
||||||
#include "libqos/pci.h"
|
#include "libqos/pci.h"
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/bswap.h"
|
#include "qemu/bswap.h"
|
||||||
|
|
||||||
typedef struct TestCase TestCase;
|
typedef struct TestCase TestCase;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include "libqos/libqos-pc.h"
|
#include "libqos/libqos-pc.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
#include "hw/pci/pci.h"
|
#include "hw/pci/pci.h"
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "libqos/qgraph.h"
|
#include "libqos/qgraph.h"
|
||||||
#include "libqos/pci.h"
|
#include "libqos/pci.h"
|
||||||
|
|
|
@ -550,7 +550,7 @@ static void fuzz_registers(void)
|
||||||
|
|
||||||
static bool qtest_check_clang_sanitizer(void)
|
static bool qtest_check_clang_sanitizer(void)
|
||||||
{
|
{
|
||||||
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
|
#ifdef QEMU_SANITIZE_ADDRESS
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
g_test_skip("QEMU not configured using --enable-sanitizers");
|
g_test_skip("QEMU not configured using --enable-sanitizers");
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* https://bugs.launchpad.net/qemu/+bug/1879531
|
* https://bugs.launchpad.net/qemu/+bug/1879531
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This used to trigger the assert in lsi_do_dma()
|
* This used to trigger the assert in lsi_do_dma()
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This used to trigger the assert in scsi_dma_complete
|
* This used to trigger the assert in scsi_dma_complete
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This used to trigger the assert in audio_calloc
|
* This used to trigger the assert in audio_calloc
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* https://gitlab.com/qemu-project/qemu/-/issues/450
|
* https://gitlab.com/qemu-project/qemu/-/issues/450
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here a MemoryRegionCache pointed to an MMIO region but had a
|
* Here a MemoryRegionCache pointed to an MMIO region but had a
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This used to trigger the out-of-bounds read in xlnx_dp_read
|
* This used to trigger the out-of-bounds read in xlnx_dp_read
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "sysemu/runstate.h"
|
#include "sysemu/runstate.h"
|
||||||
#include "qemu/main-loop.h"
|
#include "qemu/main-loop.h"
|
||||||
#include "qemu/rcu.h"
|
#include "qemu/rcu.h"
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/qgraph.h"
|
#include "tests/qtest/libqos/qgraph.h"
|
||||||
#include "fuzz.h"
|
#include "fuzz.h"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "qemu/units.h"
|
#include "qemu/units.h"
|
||||||
#include "qapi/error.h"
|
#include "qapi/error.h"
|
||||||
|
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A libfuzzer fuzzing target
|
* A libfuzzer fuzzing target
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
|
||||||
#include "hw/core/cpu.h"
|
#include "hw/core/cpu.h"
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/pci-pc.h"
|
#include "tests/qtest/libqos/pci-pc.h"
|
||||||
#include "fuzz.h"
|
#include "fuzz.h"
|
||||||
#include "fork_fuzz.h"
|
#include "fork_fuzz.h"
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "qemu/main-loop.h"
|
#include "qemu/main-loop.h"
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/pci.h"
|
#include "tests/qtest/libqos/pci.h"
|
||||||
#include "tests/qtest/libqos/pci-pc.h"
|
#include "tests/qtest/libqos/pci-pc.h"
|
||||||
#include "fuzz.h"
|
#include "fuzz.h"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "exec/memory.h"
|
#include "exec/memory.h"
|
||||||
#include "qemu/main-loop.h"
|
#include "qemu/main-loop.h"
|
||||||
|
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/malloc.h"
|
#include "tests/qtest/libqos/malloc.h"
|
||||||
#include "tests/qtest/libqos/qgraph.h"
|
#include "tests/qtest/libqos/qgraph.h"
|
||||||
#include "tests/qtest/libqos/qgraph_internal.h"
|
#include "tests/qtest/libqos/qgraph_internal.h"
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/virtio-blk.h"
|
#include "tests/qtest/libqos/virtio-blk.h"
|
||||||
#include "tests/qtest/libqos/virtio.h"
|
#include "tests/qtest/libqos/virtio.h"
|
||||||
#include "tests/qtest/libqos/virtio-pci.h"
|
#include "tests/qtest/libqos/virtio-pci.h"
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "standard-headers/linux/virtio_config.h"
|
#include "standard-headers/linux/virtio_config.h"
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/virtio-net.h"
|
#include "tests/qtest/libqos/virtio-net.h"
|
||||||
#include "fuzz.h"
|
#include "fuzz.h"
|
||||||
#include "fork_fuzz.h"
|
#include "fork_fuzz.h"
|
||||||
|
@ -151,7 +151,7 @@ static void *virtio_net_test_setup_socket(GString *cmd_line, void *arg)
|
||||||
{
|
{
|
||||||
int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sockfds);
|
int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sockfds);
|
||||||
g_assert_cmpint(ret, !=, -1);
|
g_assert_cmpint(ret, !=, -1);
|
||||||
fcntl(sockfds[0], F_SETFL, O_NONBLOCK);
|
g_unix_set_fd_nonblocking(sockfds[0], true, NULL);
|
||||||
sockfds_initialized = true;
|
sockfds_initialized = true;
|
||||||
g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ",
|
g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ",
|
||||||
sockfds[1]);
|
sockfds[1]);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "tests/qtest/libqos/libqtest.h"
|
#include "tests/qtest/libqtest.h"
|
||||||
#include "tests/qtest/libqos/virtio-scsi.h"
|
#include "tests/qtest/libqos/virtio-scsi.h"
|
||||||
#include "tests/qtest/libqos/virtio.h"
|
#include "tests/qtest/libqos/virtio.h"
|
||||||
#include "tests/qtest/libqos/virtio-pci.h"
|
#include "tests/qtest/libqos/virtio-pci.h"
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "standard-headers/linux/qemu_fw_cfg.h"
|
#include "standard-headers/linux/qemu_fw_cfg.h"
|
||||||
#include "libqos/fw_cfg.h"
|
#include "libqos/fw_cfg.h"
|
||||||
#include "qemu/bswap.h"
|
#include "qemu/bswap.h"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "qemu/bswap.h"
|
#include "qemu/bswap.h"
|
||||||
#include "qapi/qmp/qlist.h"
|
#include "qapi/qmp/qlist.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "libqos/fw_cfg.h"
|
#include "libqos/fw_cfg.h"
|
||||||
#include "libqos/libqos.h"
|
#include "libqos/libqos.h"
|
||||||
#include "standard-headers/linux/qemu_fw_cfg.h"
|
#include "standard-headers/linux/qemu_fw_cfg.h"
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
/* Load 'test.hex' and verify that the in-memory contents are as expected.
|
/* Load 'test.hex' and verify that the in-memory contents are as expected.
|
||||||
* 'test.hex' is a memory test pattern stored in Hexadecimal Object
|
* 'test.hex' is a memory test pattern stored in Hexadecimal Object
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
|
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "libqos/libqos.h"
|
#include "libqos/libqos.h"
|
||||||
#include "libqos/pci-pc.h"
|
#include "libqos/pci-pc.h"
|
||||||
#include "libqos/malloc-pc.h"
|
#include "libqos/malloc-pc.h"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "libqos/qgraph.h"
|
#include "libqos/qgraph.h"
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "contrib/ivshmem-server/ivshmem-server.h"
|
#include "contrib/ivshmem-server/ivshmem-server.h"
|
||||||
#include "libqos/libqos-pc.h"
|
#include "libqos/libqos-pc.h"
|
||||||
#include "libqos/libqos-spapr.h"
|
#include "libqos/libqos-spapr.h"
|
||||||
#include "libqos/libqtest.h"
|
#include "libqtest.h"
|
||||||
|
|
||||||
#define TMPSHMSIZE (1 << 20)
|
#define TMPSHMSIZE (1 << 20)
|
||||||
static char *tmpshm;
|
static char *tmpshm;
|
||||||
|
@ -304,6 +304,7 @@ static void setup_vm_with_server(IVState *s, int nvectors)
|
||||||
|
|
||||||
static void test_ivshmem_server(void)
|
static void test_ivshmem_server(void)
|
||||||
{
|
{
|
||||||
|
g_autoptr(GError) err = NULL;
|
||||||
IVState state1, state2, *s1, *s2;
|
IVState state1, state2, *s1, *s2;
|
||||||
ServerThread thread;
|
ServerThread thread;
|
||||||
IvshmemServer server;
|
IvshmemServer server;
|
||||||
|
@ -320,8 +321,8 @@ static void test_ivshmem_server(void)
|
||||||
g_assert_cmpint(ret, ==, 0);
|
g_assert_cmpint(ret, ==, 0);
|
||||||
|
|
||||||
thread.server = &server;
|
thread.server = &server;
|
||||||
ret = pipe(thread.pipe);
|
g_unix_open_pipe(thread.pipe, FD_CLOEXEC, &err);
|
||||||
g_assert_cmpint(ret, ==, 0);
|
g_assert_no_error(err);
|
||||||
thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
|
thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
|
||||||
g_assert(thread.thread != NULL);
|
g_assert(thread.thread != NULL);
|
||||||
|
|
||||||
|
|
233
tests/qtest/libqmp.c
Normal file
233
tests/qtest/libqmp.c
Normal file
|
@ -0,0 +1,233 @@
|
||||||
|
/*
|
||||||
|
* QTest
|
||||||
|
*
|
||||||
|
* Copyright IBM, Corp. 2012
|
||||||
|
* Copyright Red Hat, Inc. 2012
|
||||||
|
* Copyright SUSE LINUX Products GmbH 2013
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anthony Liguori <aliguori@us.ibm.com>
|
||||||
|
* Paolo Bonzini <pbonzini@redhat.com>
|
||||||
|
* Andreas Färber <afaerber@suse.de>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
|
#include "libqmp.h"
|
||||||
|
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "qapi/qmp/json-parser.h"
|
||||||
|
#include "qapi/qmp/qjson.h"
|
||||||
|
|
||||||
|
#define SOCKET_MAX_FDS 16
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
JSONMessageParser parser;
|
||||||
|
QDict *response;
|
||||||
|
} QMPResponseParser;
|
||||||
|
|
||||||
|
static void socket_send(int fd, const char *buf, size_t size)
|
||||||
|
{
|
||||||
|
size_t res = qemu_write_full(fd, buf, size);
|
||||||
|
|
||||||
|
assert(res == size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void qmp_response(void *opaque, QObject *obj, Error *err)
|
||||||
|
{
|
||||||
|
QMPResponseParser *qmp = opaque;
|
||||||
|
|
||||||
|
assert(!obj != !err);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
error_prepend(&err, "QMP JSON response parsing failed: ");
|
||||||
|
error_report_err(err);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert(!qmp->response);
|
||||||
|
qmp->response = qobject_to(QDict, obj);
|
||||||
|
g_assert(qmp->response);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDict *qmp_fd_receive(int fd)
|
||||||
|
{
|
||||||
|
QMPResponseParser qmp;
|
||||||
|
bool log = getenv("QTEST_LOG") != NULL;
|
||||||
|
|
||||||
|
qmp.response = NULL;
|
||||||
|
json_message_parser_init(&qmp.parser, qmp_response, &qmp, NULL);
|
||||||
|
while (!qmp.response) {
|
||||||
|
ssize_t len;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
len = read(fd, &c, 1);
|
||||||
|
if (len == -1 && errno == EINTR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len == -1 || len == 0) {
|
||||||
|
fprintf(stderr, "Broken pipe\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log) {
|
||||||
|
g_assert(write(2, &c, 1) == 1);
|
||||||
|
}
|
||||||
|
json_message_parser_feed(&qmp.parser, &c, 1);
|
||||||
|
}
|
||||||
|
if (log) {
|
||||||
|
g_assert(write(2, "\n", 1) == 1);
|
||||||
|
}
|
||||||
|
json_message_parser_destroy(&qmp.parser);
|
||||||
|
|
||||||
|
return qmp.response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sends a message and file descriptors to the socket.
|
||||||
|
* It's needed for qmp-commands like getfd/add-fd */
|
||||||
|
static void socket_send_fds(int socket_fd, int *fds, size_t fds_num,
|
||||||
|
const char *buf, size_t buf_size)
|
||||||
|
{
|
||||||
|
ssize_t ret;
|
||||||
|
struct msghdr msg = { 0 };
|
||||||
|
char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };
|
||||||
|
size_t fdsize = sizeof(int) * fds_num;
|
||||||
|
struct cmsghdr *cmsg;
|
||||||
|
struct iovec iov = { .iov_base = (char *)buf, .iov_len = buf_size };
|
||||||
|
|
||||||
|
msg.msg_iov = &iov;
|
||||||
|
msg.msg_iovlen = 1;
|
||||||
|
|
||||||
|
if (fds && fds_num > 0) {
|
||||||
|
g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS);
|
||||||
|
|
||||||
|
msg.msg_control = control;
|
||||||
|
msg.msg_controllen = CMSG_SPACE(fdsize);
|
||||||
|
|
||||||
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
|
cmsg->cmsg_len = CMSG_LEN(fdsize);
|
||||||
|
cmsg->cmsg_level = SOL_SOCKET;
|
||||||
|
cmsg->cmsg_type = SCM_RIGHTS;
|
||||||
|
memcpy(CMSG_DATA(cmsg), fds, fdsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
ret = sendmsg(socket_fd, &msg, 0);
|
||||||
|
} while (ret < 0 && errno == EINTR);
|
||||||
|
g_assert_cmpint(ret, >, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow users to send a message without waiting for the reply,
|
||||||
|
* in the case that they choose to discard all replies up until
|
||||||
|
* a particular EVENT is received.
|
||||||
|
*/
|
||||||
|
void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
|
||||||
|
const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
QObject *qobj;
|
||||||
|
|
||||||
|
/* Going through qobject ensures we escape strings properly */
|
||||||
|
qobj = qobject_from_vjsonf_nofail(fmt, ap);
|
||||||
|
|
||||||
|
/* No need to send anything for an empty QObject. */
|
||||||
|
if (qobj) {
|
||||||
|
int log = getenv("QTEST_LOG") != NULL;
|
||||||
|
GString *str = qobject_to_json(qobj);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BUG: QMP doesn't react to input until it sees a newline, an
|
||||||
|
* object, or an array. Work-around: give it a newline.
|
||||||
|
*/
|
||||||
|
g_string_append_c(str, '\n');
|
||||||
|
|
||||||
|
if (log) {
|
||||||
|
fprintf(stderr, "%s", str->str);
|
||||||
|
}
|
||||||
|
/* Send QMP request */
|
||||||
|
if (fds && fds_num > 0) {
|
||||||
|
socket_send_fds(fd, fds, fds_num, str->str, str->len);
|
||||||
|
} else {
|
||||||
|
socket_send(fd, str->str, str->len);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_string_free(str, true);
|
||||||
|
qobject_unref(qobj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDict *qmp_fdv(int fd, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
|
||||||
|
|
||||||
|
return qmp_fd_receive(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDict *qmp_fd(int fd, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
QDict *response;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
response = qmp_fdv(fd, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qmp_fd_send(int fd, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
qmp_fd_vsend(fd, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
bool log = getenv("QTEST_LOG") != NULL;
|
||||||
|
char *str = g_strdup_vprintf(fmt, ap);
|
||||||
|
|
||||||
|
if (log) {
|
||||||
|
fprintf(stderr, "%s", str);
|
||||||
|
}
|
||||||
|
socket_send(fd, str, strlen(str));
|
||||||
|
g_free(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void qmp_fd_send_raw(int fd, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
qmp_fd_vsend_raw(fd, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool qmp_rsp_is_err(QDict *rsp)
|
||||||
|
{
|
||||||
|
QDict *error = qdict_get_qdict(rsp, "error");
|
||||||
|
qobject_unref(rsp);
|
||||||
|
return !!error;
|
||||||
|
}
|
||||||
|
|
||||||
|
void qmp_expect_error_and_unref(QDict *rsp, const char *class)
|
||||||
|
{
|
||||||
|
QDict *error = qdict_get_qdict(rsp, "error");
|
||||||
|
|
||||||
|
g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class);
|
||||||
|
g_assert_nonnull(qdict_get_try_str(error, "desc"));
|
||||||
|
g_assert(!qdict_haskey(rsp, "return"));
|
||||||
|
|
||||||
|
qobject_unref(rsp);
|
||||||
|
}
|
50
tests/qtest/libqmp.h
Normal file
50
tests/qtest/libqmp.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* libqmp test unit
|
||||||
|
*
|
||||||
|
* Copyright IBM, Corp. 2012
|
||||||
|
* Copyright Red Hat, Inc. 2012
|
||||||
|
* Copyright SUSE LINUX Products GmbH 2013
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anthony Liguori <aliguori@us.ibm.com>
|
||||||
|
* Paolo Bonzini <pbonzini@redhat.com>
|
||||||
|
* Andreas Färber <afaerber@suse.de>
|
||||||
|
*
|
||||||
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||||
|
* See the COPYING file in the top-level directory.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef LIBQMP_H_
|
||||||
|
#define LIBQMP_H_
|
||||||
|
|
||||||
|
#include "qapi/qmp/qdict.h"
|
||||||
|
|
||||||
|
QDict *qmp_fd_receive(int fd);
|
||||||
|
void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
|
||||||
|
const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0);
|
||||||
|
void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||||
|
void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||||
|
void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||||
|
void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||||
|
QDict *qmp_fdv(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||||
|
QDict *qmp_fd(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qmp_rsp_is_err:
|
||||||
|
* @rsp: QMP response to check for error
|
||||||
|
*
|
||||||
|
* Test @rsp for error and discard @rsp.
|
||||||
|
* Returns 'true' if there is error in @rsp and 'false' otherwise.
|
||||||
|
*/
|
||||||
|
bool qmp_rsp_is_err(QDict *rsp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qmp_expect_error_and_unref:
|
||||||
|
* @rsp: QMP response to check for error
|
||||||
|
* @class: an error class
|
||||||
|
*
|
||||||
|
* Assert the response has the given error class and discard @rsp.
|
||||||
|
*/
|
||||||
|
void qmp_expect_error_and_unref(QDict *rsp, const char *class);
|
||||||
|
|
||||||
|
#endif /* LIBQMP_H_ */
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "ahci.h"
|
#include "ahci.h"
|
||||||
#include "pci-pc.h"
|
#include "pci-pc.h"
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "pci-pc.h"
|
#include "pci-pc.h"
|
||||||
#include "qemu/sockets.h"
|
#include "qemu/sockets.h"
|
||||||
#include "qemu/iov.h"
|
#include "qemu/iov.h"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "fw_cfg.h"
|
#include "fw_cfg.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qemu/bswap.h"
|
#include "qemu/bswap.h"
|
||||||
#include "hw/nvram/fw_cfg.h"
|
#include "hw/nvram/fw_cfg.h"
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#ifndef LIBQOS_FW_CFG_H
|
#ifndef LIBQOS_FW_CFG_H
|
||||||
#define LIBQOS_FW_CFG_H
|
#define LIBQOS_FW_CFG_H
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
|
|
||||||
typedef struct QFWCFG QFWCFG;
|
typedef struct QFWCFG QFWCFG;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
|
|
||||||
#include "hw/i2c/imx_i2c.h"
|
#include "hw/i2c/imx_i2c.h"
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "qemu/bswap.h"
|
#include "qemu/bswap.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
|
|
||||||
enum OMAPI2CRegisters {
|
enum OMAPI2CRegisters {
|
||||||
OMAP_I2C_REV = 0x00,
|
OMAP_I2C_REV = 0x00,
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
|
|
||||||
void qi2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len)
|
void qi2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef LIBQOS_I2C_H
|
#ifndef LIBQOS_I2C_H
|
||||||
#define LIBQOS_I2C_H
|
#define LIBQOS_I2C_H
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "qgraph.h"
|
#include "qgraph.h"
|
||||||
|
|
||||||
typedef struct I2CAdapter I2CAdapter;
|
typedef struct I2CAdapter I2CAdapter;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "libqos.h"
|
#include "libqos.h"
|
||||||
#include "pci.h"
|
#include "pci.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef LIBQOS_H
|
#ifndef LIBQOS_H
|
||||||
#define LIBQOS_H
|
#define LIBQOS_H
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "pci.h"
|
#include "pci.h"
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#define LIBQOS_MALLOC_H
|
#define LIBQOS_MALLOC_H
|
||||||
|
|
||||||
#include "qemu/queue.h"
|
#include "qemu/queue.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ALLOC_NO_FLAGS = 0x00,
|
ALLOC_NO_FLAGS = 0x00,
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
libqos_srcs = files('../libqtest.c',
|
libqos_srcs = files(
|
||||||
|
'../libqtest.c',
|
||||||
|
'../libqmp.c',
|
||||||
|
|
||||||
'qgraph.c',
|
'qgraph.c',
|
||||||
'qos_external.c',
|
'qos_external.c',
|
||||||
'pci.c',
|
'pci.c',
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "libqtest.h"
|
#include "../libqtest.h"
|
||||||
#include "pci-pc.h"
|
#include "pci-pc.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
#include "hw/pci/pci_regs.h"
|
#include "hw/pci/pci_regs.h"
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue