aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-05-03 09:13:17 -0700
committerRichard Henderson <richard.henderson@linaro.org>2022-05-03 09:13:17 -0700
commit2e3408b3cc7de4e87a9adafc8c19bfce3abec947 (patch)
tree28882508d4c1581c825fa026feca33c2a9119995
parent5f14cfe187e2fc3c71f4536b2021b8118d224239 (diff)
parentff5927baa7ffb9c97873a071f6a8d85a3584182b (diff)
downloadqemu-2e3408b3cc7de4e87a9adafc8c19bfce3abec947.zip
qemu-2e3408b3cc7de4e87a9adafc8c19bfce3abec947.tar.gz
qemu-2e3408b3cc7de4e87a9adafc8c19bfce3abec947.tar.bz2
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>
-rw-r--r--block/file-posix.c15
-rw-r--r--chardev/char-fd.c4
-rw-r--r--chardev/char-pty.c5
-rw-r--r--chardev/char-serial.c5
-rw-r--r--chardev/char-socket.c2
-rw-r--r--chardev/char-stdio.c5
-rw-r--r--contrib/ivshmem-server/ivshmem-server.c2
-rw-r--r--docs/devel/qtest.rst2
-rw-r--r--hw/hyperv/syndbg.c2
-rw-r--r--hw/input/virtio-input-host.c5
-rw-r--r--hw/misc/ivshmem.c2
-rw-r--r--hw/virtio/vhost-user.c2
-rw-r--r--hw/virtio/vhost-vsock.c11
-rw-r--r--include/io/channel-command.h25
-rw-r--r--include/qemu/atomic.h8
-rw-r--r--include/qemu/osdep.h4
-rw-r--r--include/qemu/sockets.h6
-rw-r--r--include/sysemu/os-posix.h2
-rw-r--r--io/channel-command.c46
-rw-r--r--io/channel-file.c13
-rw-r--r--io/channel-socket.c6
-rw-r--r--net/l2tpv3.c2
-rw-r--r--net/socket.c10
-rw-r--r--net/tap-bsd.c4
-rw-r--r--net/tap-linux.c2
-rw-r--r--net/tap-solaris.c2
-rw-r--r--net/tap.c33
-rw-r--r--os-posix.c3
-rw-r--r--qemu-nbd.c5
-rw-r--r--qga/channel-posix.c2
-rw-r--r--qga/commands-posix.c8
-rwxr-xr-xscripts/oss-fuzz/output_reproducer.py2
l---------subprojects/libvhost-user/include/compiler.h1
-rw-r--r--tests/qtest/ac97-test.c2
-rw-r--r--tests/qtest/acpi-utils.h2
-rw-r--r--tests/qtest/ahci-test.c2
-rw-r--r--tests/qtest/am53c974-test.c2
-rw-r--r--tests/qtest/arm-cpu-features.c2
-rw-r--r--tests/qtest/aspeed_hace-test.c2
-rw-r--r--tests/qtest/boot-order-test.c2
-rw-r--r--tests/qtest/boot-sector.c2
-rw-r--r--tests/qtest/boot-sector.h2
-rw-r--r--tests/qtest/boot-serial-test.c2
-rw-r--r--tests/qtest/cdrom-test.c2
-rw-r--r--tests/qtest/dbus-display-test.c2
-rw-r--r--tests/qtest/dbus-vmstate-test.c2
-rw-r--r--tests/qtest/device-introspect-test.c2
-rw-r--r--tests/qtest/device-plug-test.c2
-rw-r--r--tests/qtest/drive_del-test.c2
-rw-r--r--tests/qtest/ds1338-test.c2
-rw-r--r--tests/qtest/e1000-test.c2
-rw-r--r--tests/qtest/eepro100-test.c2
-rw-r--r--tests/qtest/endianness-test.c2
-rw-r--r--tests/qtest/erst-test.c2
-rw-r--r--tests/qtest/es1370-test.c2
-rw-r--r--tests/qtest/fdc-test.c2
-rw-r--r--tests/qtest/fuzz-e1000e-test.c2
-rw-r--r--tests/qtest/fuzz-lsi53c895a-test.c2
-rw-r--r--tests/qtest/fuzz-megasas-test.c2
-rw-r--r--tests/qtest/fuzz-sb16-test.c2
-rw-r--r--tests/qtest/fuzz-sdcard-test.c2
-rw-r--r--tests/qtest/fuzz-virtio-scsi-test.c2
-rw-r--r--tests/qtest/fuzz-xlnx-dp-test.c2
-rw-r--r--tests/qtest/fuzz/fuzz.c2
-rw-r--r--tests/qtest/fuzz/fuzz.h2
-rw-r--r--tests/qtest/fuzz/generic_fuzz.c2
-rw-r--r--tests/qtest/fuzz/i440fx_fuzz.c2
-rw-r--r--tests/qtest/fuzz/qos_fuzz.c2
-rw-r--r--tests/qtest/fuzz/virtio_blk_fuzz.c2
-rw-r--r--tests/qtest/fuzz/virtio_net_fuzz.c4
-rw-r--r--tests/qtest/fuzz/virtio_scsi_fuzz.c2
-rw-r--r--tests/qtest/fw_cfg-test.c2
-rw-r--r--tests/qtest/hd-geo-test.c2
-rw-r--r--tests/qtest/hexloader-test.c2
-rw-r--r--tests/qtest/ide-test.c2
-rw-r--r--tests/qtest/ipoctal232-test.c2
-rw-r--r--tests/qtest/ivshmem-test.c7
-rw-r--r--tests/qtest/libqmp.c233
-rw-r--r--tests/qtest/libqmp.h50
-rw-r--r--tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c2
-rw-r--r--tests/qtest/libqos/ahci.c2
-rw-r--r--tests/qtest/libqos/arm-imx25-pdk-machine.c2
-rw-r--r--tests/qtest/libqos/arm-n800-machine.c2
-rw-r--r--tests/qtest/libqos/arm-raspi2-machine.c2
-rw-r--r--tests/qtest/libqos/arm-sabrelite-machine.c2
-rw-r--r--tests/qtest/libqos/arm-smdkc210-machine.c2
-rw-r--r--tests/qtest/libqos/arm-virt-machine.c2
-rw-r--r--tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c2
-rw-r--r--tests/qtest/libqos/e1000e.c2
-rw-r--r--tests/qtest/libqos/fw_cfg.c2
-rw-r--r--tests/qtest/libqos/fw_cfg.h2
-rw-r--r--tests/qtest/libqos/i2c-imx.c2
-rw-r--r--tests/qtest/libqos/i2c-omap.c2
-rw-r--r--tests/qtest/libqos/i2c.c2
-rw-r--r--tests/qtest/libqos/i2c.h2
-rw-r--r--tests/qtest/libqos/libqos.c2
-rw-r--r--tests/qtest/libqos/libqos.h2
-rw-r--r--tests/qtest/libqos/malloc.h2
-rw-r--r--tests/qtest/libqos/meson.build5
-rw-r--r--tests/qtest/libqos/pci-pc.c2
-rw-r--r--tests/qtest/libqos/pci-spapr.c2
-rw-r--r--tests/qtest/libqos/pci.h2
-rw-r--r--tests/qtest/libqos/ppc64_pseries-machine.c2
-rw-r--r--tests/qtest/libqos/qgraph.c2
-rw-r--r--tests/qtest/libqos/qos_external.c2
-rw-r--r--tests/qtest/libqos/rtas.c2
-rw-r--r--tests/qtest/libqos/sdhci-cmd.c2
-rw-r--r--tests/qtest/libqos/sdhci-cmd.h2
-rw-r--r--tests/qtest/libqos/sdhci.c2
-rw-r--r--tests/qtest/libqos/tpci200.c2
-rw-r--r--tests/qtest/libqos/usb.c2
-rw-r--r--tests/qtest/libqos/vhost-user-blk.c2
-rw-r--r--tests/qtest/libqos/virtio-9p.c2
-rw-r--r--tests/qtest/libqos/virtio-balloon.c2
-rw-r--r--tests/qtest/libqos/virtio-blk.c2
-rw-r--r--tests/qtest/libqos/virtio-iommu.c2
-rw-r--r--tests/qtest/libqos/virtio-mmio.c2
-rw-r--r--tests/qtest/libqos/virtio-net.c2
-rw-r--r--tests/qtest/libqos/virtio-pci.c2
-rw-r--r--tests/qtest/libqos/virtio-rng.c2
-rw-r--r--tests/qtest/libqos/virtio-scsi.c2
-rw-r--r--tests/qtest/libqos/virtio-serial.c2
-rw-r--r--tests/qtest/libqos/virtio.c2
-rw-r--r--tests/qtest/libqos/x86_64_pc-machine.c2
-rw-r--r--tests/qtest/libqtest-single.h2
-rw-r--r--tests/qtest/libqtest.c207
-rw-r--r--tests/qtest/libqtest.h (renamed from tests/qtest/libqos/libqtest.h)29
-rw-r--r--tests/qtest/lpc-ich9-test.c2
-rw-r--r--tests/qtest/m48t59-test.c2
-rw-r--r--tests/qtest/machine-none-test.c2
-rw-r--r--tests/qtest/megasas-test.c2
-rw-r--r--tests/qtest/microbit-test.c2
-rw-r--r--tests/qtest/migration-helpers.h2
-rw-r--r--tests/qtest/migration-test.c2
-rw-r--r--tests/qtest/modules-test.c2
-rw-r--r--tests/qtest/ne2000-test.c2
-rw-r--r--tests/qtest/npcm7xx_adc-test.c2
-rw-r--r--tests/qtest/npcm7xx_pwm-test.c2
-rw-r--r--tests/qtest/npcm7xx_sdhci-test.c2
-rw-r--r--tests/qtest/npcm7xx_smbus-test.c2
-rw-r--r--tests/qtest/npcm7xx_watchdog_timer-test.c2
-rw-r--r--tests/qtest/numa-test.c2
-rw-r--r--tests/qtest/nvme-test.c2
-rw-r--r--tests/qtest/pca9552-test.c2
-rw-r--r--tests/qtest/pci-test.c2
-rw-r--r--tests/qtest/pcnet-test.c2
-rw-r--r--tests/qtest/pflash-cfi02-test.c2
-rw-r--r--tests/qtest/pnv-xscom-test.c2
-rw-r--r--tests/qtest/prom-env-test.c2
-rw-r--r--tests/qtest/pvpanic-pci-test.c2
-rw-r--r--tests/qtest/pvpanic-test.c2
-rw-r--r--tests/qtest/pxe-test.c2
-rw-r--r--tests/qtest/q35-test.c2
-rw-r--r--tests/qtest/qmp-cmd-test.c2
-rw-r--r--tests/qtest/qmp-test.c2
-rw-r--r--tests/qtest/qom-test.c2
-rw-r--r--tests/qtest/rtas-test.c2
-rw-r--r--tests/qtest/sdhci-test.c2
-rw-r--r--tests/qtest/spapr-phb-test.c2
-rw-r--r--tests/qtest/tco-test.c2
-rw-r--r--tests/qtest/test-filter-mirror.c2
-rw-r--r--tests/qtest/test-filter-redirector.c2
-rw-r--r--tests/qtest/test-hmp.c2
-rw-r--r--tests/qtest/tpm-crb-swtpm-test.c2
-rw-r--r--tests/qtest/tpm-emu.h2
-rw-r--r--tests/qtest/tpm-tis-device-swtpm-test.c2
-rw-r--r--tests/qtest/tpm-tis-swtpm-test.c2
-rw-r--r--tests/qtest/tpm-util.c2
-rw-r--r--tests/qtest/tulip-test.c2
-rw-r--r--tests/qtest/vhost-user-test.c4
-rw-r--r--tests/qtest/virtio-net-failover.c2
-rw-r--r--tests/qtest/virtio-rng-test.c2
-rw-r--r--tests/qtest/virtio-test.c2
-rw-r--r--tests/qtest/vmgenid-test.c2
-rw-r--r--tests/qtest/vmxnet3-test.c2
-rw-r--r--tests/qtest/wdt_ib700-test.c2
-rw-r--r--tests/qtest/xlnx-can-test.c2
-rw-r--r--tests/unit/meson.build2
-rw-r--r--tests/unit/socket-helpers.c2
-rw-r--r--tests/unit/test-crypto-tlssession.c8
-rw-r--r--tests/unit/test-io-channel-file.c2
-rw-r--r--tests/unit/test-iov.c4
-rw-r--r--tests/unit/test-qga.c2
-rw-r--r--tools/virtiofsd/helper.c2
-rw-r--r--ui/input-linux.c5
-rw-r--r--util/compatfd.c5
-rw-r--r--util/coroutine-ucontext.c2
-rw-r--r--util/event_notifier-posix.c8
-rw-r--r--util/main-loop.c2
-rw-r--r--util/oslib-posix.c61
-rw-r--r--util/oslib-win32.c8
-rw-r--r--util/vhost-user-server.c4
192 files changed, 609 insertions, 565 deletions
diff --git a/block/file-posix.c b/block/file-posix.c
index bfd9b21..48cd096 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -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)
diff --git a/chardev/char-fd.c b/chardev/char-fd.c
index 6ec9682..cf78454 100644
--- a/chardev/char-fd.c
+++ b/chardev/char-fd.c
@@ -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) {
diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 1e2863f..53f25c6 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -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",
diff --git a/chardev/char-serial.c b/chardev/char-serial.c
index 7c3d84a..4b0b83d 100644
--- a/chardev/char-serial.c
+++ b/chardev/char-serial.c
@@ -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);
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index fab2d79..dc4e218 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -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);
diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index 403da30..3c64867 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -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));
diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
index 39a6ffd..2f3c732 100644
--- a/contrib/ivshmem-server/ivshmem-server.c
+++ b/contrib/ivshmem-server/ivshmem-server.c
@@ -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 */
diff --git a/docs/devel/qtest.rst b/docs/devel/qtest.rst
index add293d..0455aa0 100644
--- a/docs/devel/qtest.rst
+++ b/docs/devel/qtest.rst
@@ -88,4 +88,4 @@ QTest Protocol
libqtest API reference
----------------------
-.. kernel-doc:: tests/qtest/libqos/libqtest.h
+.. kernel-doc:: tests/qtest/libqtest.h
diff --git a/hw/hyperv/syndbg.c b/hw/hyperv/syndbg.c
index ebb8a29..16d04cf 100644
--- a/hw/hyperv/syndbg.c
+++ b/hw/hyperv/syndbg.c
@@ -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;
diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
index 137efba..fea7139 100644
--- a/hw/input/virtio-input-host.c
+++ b/hw/input/virtio-input-host.c
@@ -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) {
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index e7c0099..8270db5 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -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);
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 9c4f84f..a80315e 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -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;
diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
index 433d42d..7140462 100644
--- a/hw/virtio/vhost-vsock.c
+++ b/hw/virtio/vhost-vsock.c
@@ -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");
diff --git a/include/io/channel-command.h b/include/io/channel-command.h
index 27e42bd..305ac1d 100644
--- a/include/io/channel-command.h
+++ b/include/io/channel-command.h
@@ -46,31 +46,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
* @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR
diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
index 112a299..7e8fc8e 100644
--- a/include/qemu/atomic.h
+++ b/include/qemu/atomic.h
@@ -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))
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 52d81c0..1c1e7ec 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -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
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 0c34bf2..038faa1 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -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
diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index adbe19d..58de7c9 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -96,8 +96,6 @@ static inline void qemu_funlockfile(FILE *f)
funlockfile(f);
}
-int fcntl_setfl(int fd, int flag);
-
#ifdef __cplusplus
}
#endif
diff --git a/io/channel-command.c b/io/channel-command.c
index 338da73..4a1f969 100644
--- a/io/channel-command.c
+++ b/io/channel-command.c
@@ -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;
}
diff --git a/io/channel-file.c b/io/channel-file.c
index d7cf6d2..d146ace 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -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
}
diff --git a/io/channel-socket.c b/io/channel-socket.c
index 9f5ddf6..e531d7b 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -460,7 +460,7 @@ static void qio_channel_socket_copy_fds(struct msghdr *msg,
}
/* 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);
@@ -665,9 +665,9 @@ qio_channel_socket_set_blocking(QIOChannel *ioc,
QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
if (enabled) {
- qemu_set_block(sioc->fd);
+ qemu_socket_set_block(sioc->fd);
} else {
- qemu_set_nonblock(sioc->fd);
+ qemu_socket_set_nonblock(sioc->fd);
}
return 0;
}
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
index b8faa87..af373e5 100644
--- a/net/l2tpv3.c
+++ b/net/l2tpv3.c
@@ -716,7 +716,7 @@ int net_init_l2tpv3(const Netdev *netdev,
s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT);
s->header_buf = g_malloc(s->header_size);
- qemu_set_nonblock(fd);
+ qemu_socket_set_nonblock(fd);
s->fd = fd;
s->counter = 0;
diff --git a/net/socket.c b/net/socket.c
index ea5220a..bfd8596 100644
--- a/net/socket.c
+++ b/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;
fail:
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");
return -1;
}
- qemu_set_nonblock(fd);
+ qemu_socket_set_nonblock(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");
return -1;
}
- qemu_set_nonblock(fd);
+ qemu_socket_set_nonblock(fd);
connected = 0;
for(;;) {
@@ -688,7 +688,7 @@ static int net_socket_udp_init(NetClientState *peer,
closesocket(fd);
return -1;
}
- qemu_set_nonblock(fd);
+ qemu_socket_set_nonblock(fd);
s = net_socket_fd_init(peer, model, name, fd, 0, NULL, errp);
if (!s) {
@@ -730,7 +730,7 @@ int net_init_socket(const Netdev *netdev, const char *name,
if (fd == -1) {
return -1;
}
- ret = qemu_try_set_nonblock(fd);
+ ret = qemu_socket_try_set_nonblock(fd);
if (ret < 0) {
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
name, fd);
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 7e65bd3..005ce05 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -98,7 +98,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
return -1;
}
}
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(fd, true, NULL);
return fd;
}
@@ -189,7 +189,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
goto error;
}
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(fd, true, NULL);
return fd;
error:
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 3e24d23..304ff45 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -113,7 +113,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
return -1;
}
pstrcpy(ifname, ifname_size, ifr.ifr_name);
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(fd, true, NULL);
return fd;
}
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 7991978..a44f880 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -198,7 +198,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
return -1;
}
}
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(fd, true, NULL);
return fd;
}
diff --git a/net/tap.c b/net/tap.c
index 6190fa6..b3ddfd4 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -619,7 +619,10 @@ int net_init_bridge(const Netdev *netdev, const char *name,
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);
if (vnet_hdr < 0) {
close(fd);
@@ -716,8 +719,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
}
if (vhostfdname) {
- int ret;
-
vhostfd = monitor_fd_param(monitor_cur(), vhostfdname, &err);
if (vhostfd == -1) {
if (tap->has_vhostforce && tap->vhostforce) {
@@ -727,9 +728,8 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
}
return;
}
- ret = qemu_try_set_nonblock(vhostfd);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
+ if (!g_unix_set_fd_nonblocking(vhostfd, true, NULL)) {
+ error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
name, fd);
return;
}
@@ -745,7 +745,10 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
}
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.nvqs = 2;
@@ -832,9 +835,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
- ret = qemu_try_set_nonblock(fd);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
+ if (!g_unix_set_fd_nonblocking(fd, true, NULL)) {
+ error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
name, fd);
close(fd);
return -1;
@@ -889,9 +891,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
goto free_fail;
}
- ret = qemu_try_set_nonblock(fd);
- if (ret < 0) {
- error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
+ ret = g_unix_set_fd_nonblocking(fd, true, NULL);
+ if (!ret) {
+ error_setg_errno(errp, errno, "%s: Can't use file descriptor %d",
name, fd);
goto free_fail;
}
@@ -946,7 +948,10 @@ free_fail:
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);
if (vnet_hdr < 0) {
close(fd);
diff --git a/os-posix.c b/os-posix.c
index 1b746db..321fc4b 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -215,7 +215,7 @@ void os_daemonize(void)
pid_t pid;
int fds[2];
- if (pipe(fds) == -1) {
+ if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) {
exit(1);
}
@@ -240,7 +240,6 @@ void os_daemonize(void)
close(fds[0]);
daemon_pipe = fds[1];
- qemu_set_cloexec(daemon_pipe);
setsid();
diff --git a/qemu-nbd.c b/qemu-nbd.c
index db63980..2382b50 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -909,13 +909,14 @@ int main(int argc, char **argv)
if ((device && !verbose) || fork_process) {
#ifndef WIN32
+ g_autoptr(GError) err = NULL;
int stderr_fd[2];
pid_t pid;
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",
- strerror(errno));
+ err->message);
exit(EXIT_FAILURE);
}
diff --git a/qga/channel-posix.c b/qga/channel-posix.c
index 0373975..a996858 100644
--- a/qga/channel-posix.c
+++ b/qga/channel-posix.c
@@ -34,7 +34,7 @@ static gboolean ga_channel_listen_accept(GIOChannel *channel,
g_warning("error converting fd to gsocket: %s", strerror(errno));
goto out;
}
- qemu_set_nonblock(client_fd);
+ qemu_socket_set_nonblock(client_fd);
ret = ga_channel_client_add(c, client_fd);
if (ret) {
g_warning("error setting up connection");
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 77f4672..78f2f21 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -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
* 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);
if (handle < 0) {
@@ -2529,7 +2533,7 @@ void qmp_guest_set_user_password(const char *username,
goto out;
}
- if (pipe(datafd) < 0) {
+ if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) {
error_setg(errp, "cannot create pipe FDs");
goto out;
}
diff --git a/scripts/oss-fuzz/output_reproducer.py b/scripts/oss-fuzz/output_reproducer.py
index 3608b06..e8ef76b 100755
--- a/scripts/oss-fuzz/output_reproducer.py
+++ b/scripts/oss-fuzz/output_reproducer.py
@@ -36,7 +36,7 @@ def c_header(owner):
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
""".format(date=date.today().year, owner=owner)
diff --git a/subprojects/libvhost-user/include/compiler.h b/subprojects/libvhost-user/include/compiler.h
new file mode 120000
index 0000000..de7b706
--- /dev/null
+++ b/subprojects/libvhost-user/include/compiler.h
@@ -0,0 +1 @@
+../../../include/qemu/compiler.h \ No newline at end of file
diff --git a/tests/qtest/ac97-test.c b/tests/qtest/ac97-test.c
index e09f249..b084e31 100644
--- a/tests/qtest/ac97-test.c
+++ b/tests/qtest/ac97-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/acpi-utils.h b/tests/qtest/acpi-utils.h
index 261784d..0c86780 100644
--- a/tests/qtest/acpi-utils.h
+++ b/tests/qtest/acpi-utils.h
@@ -13,7 +13,7 @@
#ifndef TEST_ACPI_UTILS_H
#define TEST_ACPI_UTILS_H
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/* DSDT and SSDTs format */
typedef struct {
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index aff5f3f..f1e510b 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -25,7 +25,7 @@
#include "qemu/osdep.h"
#include <getopt.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/libqos-pc.h"
#include "libqos/ahci.h"
#include "libqos/pci-pc.h"
diff --git a/tests/qtest/am53c974-test.c b/tests/qtest/am53c974-test.c
index d214a91..ed3ac7d 100644
--- a/tests/qtest/am53c974-test.c
+++ b/tests/qtest/am53c974-test.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
static void test_cmdfifo_underflow_ok(void)
diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c
index f766521..5a14527 100644
--- a/tests/qtest/arm-cpu-features.c
+++ b/tests/qtest/arm-cpu-features.c
@@ -10,7 +10,7 @@
*/
#include "qemu/osdep.h"
#include "qemu/bitops.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
diff --git a/tests/qtest/aspeed_hace-test.c b/tests/qtest/aspeed_hace-test.c
index 935a276..ce86a44 100644
--- a/tests/qtest/aspeed_hace-test.c
+++ b/tests/qtest/aspeed_hace-test.c
@@ -7,7 +7,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/bitops.h"
#define HACE_CMD 0x10
diff --git a/tests/qtest/boot-order-test.c b/tests/qtest/boot-order-test.c
index f1f59b1..0680d79 100644
--- a/tests/qtest/boot-order-test.c
+++ b/tests/qtest/boot-order-test.c
@@ -12,7 +12,7 @@
#include "qemu/osdep.h"
#include "libqos/fw_cfg.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "standard-headers/linux/qemu_fw_cfg.h"
diff --git a/tests/qtest/boot-sector.c b/tests/qtest/boot-sector.c
index 9d9825b..44a109a 100644
--- a/tests/qtest/boot-sector.c
+++ b/tests/qtest/boot-sector.c
@@ -12,7 +12,7 @@
*/
#include "qemu/osdep.h"
#include "boot-sector.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#define LOW(x) ((x) & 0xff)
#define HIGH(x) ((x) >> 8)
diff --git a/tests/qtest/boot-sector.h b/tests/qtest/boot-sector.h
index b339fde..6ee6bb4 100644
--- a/tests/qtest/boot-sector.h
+++ b/tests/qtest/boot-sector.h
@@ -14,7 +14,7 @@
#ifndef 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() */
int boot_sector_init(char *fname);
diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index d72a82d..2f99d71 100644
--- a/tests/qtest/boot-serial-test.c
+++ b/tests/qtest/boot-serial-test.c
@@ -14,7 +14,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/libqos-spapr.h"
static const uint8_t bios_avr[] = {
diff --git a/tests/qtest/cdrom-test.c b/tests/qtest/cdrom-test.c
index fdd889a..a7766a9 100644
--- a/tests/qtest/cdrom-test.c
+++ b/tests/qtest/cdrom-test.c
@@ -11,7 +11,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "boot-sector.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/dbus-display-test.c b/tests/qtest/dbus-display-test.c
index 8104316..8be5974 100644
--- a/tests/qtest/dbus-display-test.c
+++ b/tests/qtest/dbus-display-test.c
@@ -2,7 +2,7 @@
#include "qemu/dbus.h"
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "dbus-display1.h"
static GDBusConnection*
diff --git a/tests/qtest/dbus-vmstate-test.c b/tests/qtest/dbus-vmstate-test.c
index a8acab7..74ede65 100644
--- a/tests/qtest/dbus-vmstate-test.c
+++ b/tests/qtest/dbus-vmstate-test.c
@@ -1,7 +1,7 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
#include <gio/gio.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "dbus-vmstate1.h"
#include "migration-helpers.h"
diff --git a/tests/qtest/device-introspect-test.c b/tests/qtest/device-introspect-test.c
index adf39b2..5b0ffe4 100644
--- a/tests/qtest/device-introspect-test.c
+++ b/tests/qtest/device-introspect-test.c
@@ -21,7 +21,7 @@
#include "qapi/qmp/qstring.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
const char common_args[] = "-nodefaults -machine none";
diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c
index 404a92e..2e31378 100644
--- a/tests/qtest/device-plug-test.c
+++ b/tests/qtest/device-plug-test.c
@@ -11,7 +11,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"
diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c
index 0cc18df..5e6d58b 100644
--- a/tests/qtest/drive_del-test.c
+++ b/tests/qtest/drive_del-test.c
@@ -11,7 +11,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/virtio.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c
index c5d46bc..f6ade9a 100644
--- a/tests/qtest/ds1338-test.c
+++ b/tests/qtest/ds1338-test.c
@@ -18,7 +18,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/i2c.h"
#define DS1338_ADDR 0x68
diff --git a/tests/qtest/e1000-test.c b/tests/qtest/e1000-test.c
index ea286d1..c387984 100644
--- a/tests/qtest/e1000-test.c
+++ b/tests/qtest/e1000-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/eepro100-test.c b/tests/qtest/eepro100-test.c
index d72ad09..8dbffff 100644
--- a/tests/qtest/eepro100-test.c
+++ b/tests/qtest/eepro100-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/endianness-test.c b/tests/qtest/endianness-test.c
index 2f5a88b..222d116 100644
--- a/tests/qtest/endianness-test.c
+++ b/tests/qtest/endianness-test.c
@@ -13,7 +13,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/bswap.h"
typedef struct TestCase TestCase;
diff --git a/tests/qtest/erst-test.c b/tests/qtest/erst-test.c
index a0adc35..4e768a1 100644
--- a/tests/qtest/erst-test.c
+++ b/tests/qtest/erst-test.c
@@ -10,7 +10,7 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
#include "libqos/libqos-pc.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "hw/pci/pci.h"
diff --git a/tests/qtest/es1370-test.c b/tests/qtest/es1370-test.c
index 2fd7fd2..adccdac 100644
--- a/tests/qtest/es1370-test.c
+++ b/tests/qtest/es1370-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c
index 4aa72f3..0b3c2c0 100644
--- a/tests/qtest/fdc-test.c
+++ b/tests/qtest/fdc-test.c
@@ -550,7 +550,7 @@ static void fuzz_registers(void)
static bool qtest_check_clang_sanitizer(void)
{
-#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
+#ifdef QEMU_SANITIZE_ADDRESS
return true;
#else
g_test_skip("QEMU not configured using --enable-sanitizers");
diff --git a/tests/qtest/fuzz-e1000e-test.c b/tests/qtest/fuzz-e1000e-test.c
index 66229e6..5052883 100644
--- a/tests/qtest/fuzz-e1000e-test.c
+++ b/tests/qtest/fuzz-e1000e-test.c
@@ -8,7 +8,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* https://bugs.launchpad.net/qemu/+bug/1879531
diff --git a/tests/qtest/fuzz-lsi53c895a-test.c b/tests/qtest/fuzz-lsi53c895a-test.c
index 031d9de..2e8e678 100644
--- a/tests/qtest/fuzz-lsi53c895a-test.c
+++ b/tests/qtest/fuzz-lsi53c895a-test.c
@@ -6,7 +6,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* This used to trigger the assert in lsi_do_dma()
diff --git a/tests/qtest/fuzz-megasas-test.c b/tests/qtest/fuzz-megasas-test.c
index 129b182..287fe19 100644
--- a/tests/qtest/fuzz-megasas-test.c
+++ b/tests/qtest/fuzz-megasas-test.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* This used to trigger the assert in scsi_dma_complete
diff --git a/tests/qtest/fuzz-sb16-test.c b/tests/qtest/fuzz-sb16-test.c
index 91fdcd1..a65826b 100644
--- a/tests/qtest/fuzz-sb16-test.c
+++ b/tests/qtest/fuzz-sb16-test.c
@@ -7,7 +7,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* This used to trigger the assert in audio_calloc
diff --git a/tests/qtest/fuzz-sdcard-test.c b/tests/qtest/fuzz-sdcard-test.c
index d0f4e0e..e7fd818 100644
--- a/tests/qtest/fuzz-sdcard-test.c
+++ b/tests/qtest/fuzz-sdcard-test.c
@@ -7,7 +7,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* https://gitlab.com/qemu-project/qemu/-/issues/450
diff --git a/tests/qtest/fuzz-virtio-scsi-test.c b/tests/qtest/fuzz-virtio-scsi-test.c
index c9b6fe2..71c91b0 100644
--- a/tests/qtest/fuzz-virtio-scsi-test.c
+++ b/tests/qtest/fuzz-virtio-scsi-test.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* Here a MemoryRegionCache pointed to an MMIO region but had a
diff --git a/tests/qtest/fuzz-xlnx-dp-test.c b/tests/qtest/fuzz-xlnx-dp-test.c
index 69eb6c0..51e9a37 100644
--- a/tests/qtest/fuzz-xlnx-dp-test.c
+++ b/tests/qtest/fuzz-xlnx-dp-test.c
@@ -7,7 +7,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* This used to trigger the out-of-bounds read in xlnx_dp_read
diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c
index 5f77c84..a7a5e14 100644
--- a/tests/qtest/fuzz/fuzz.c
+++ b/tests/qtest/fuzz/fuzz.c
@@ -21,7 +21,7 @@
#include "sysemu/runstate.h"
#include "qemu/main-loop.h"
#include "qemu/rcu.h"
-#include "tests/qtest/libqos/libqtest.h"
+#include "tests/qtest/libqtest.h"
#include "tests/qtest/libqos/qgraph.h"
#include "fuzz.h"
diff --git a/tests/qtest/fuzz/fuzz.h b/tests/qtest/fuzz/fuzz.h
index 3a8570e..c5f0b72 100644
--- a/tests/qtest/fuzz/fuzz.h
+++ b/tests/qtest/fuzz/fuzz.h
@@ -17,7 +17,7 @@
#include "qemu/units.h"
#include "qapi/error.h"
-#include "tests/qtest/libqos/libqtest.h"
+#include "tests/qtest/libqtest.h"
/**
* A libfuzzer fuzzing target
diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c
index bce8360..25df19f 100644
--- a/tests/qtest/fuzz/generic_fuzz.c
+++ b/tests/qtest/fuzz/generic_fuzz.c
@@ -15,7 +15,7 @@
#include <wordexp.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 "fuzz.h"
#include "fork_fuzz.h"
diff --git a/tests/qtest/fuzz/i440fx_fuzz.c b/tests/qtest/fuzz/i440fx_fuzz.c
index 86796bf..b17fc72 100644
--- a/tests/qtest/fuzz/i440fx_fuzz.c
+++ b/tests/qtest/fuzz/i440fx_fuzz.c
@@ -13,7 +13,7 @@
#include "qemu/osdep.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-pc.h"
#include "fuzz.h"
diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
index dc891d8..c856d3d 100644
--- a/tests/qtest/fuzz/qos_fuzz.c
+++ b/tests/qtest/fuzz/qos_fuzz.c
@@ -22,7 +22,7 @@
#include "exec/memory.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/qgraph.h"
#include "tests/qtest/libqos/qgraph_internal.h"
diff --git a/tests/qtest/fuzz/virtio_blk_fuzz.c b/tests/qtest/fuzz/virtio_blk_fuzz.c
index 623a756..236d078 100644
--- a/tests/qtest/fuzz/virtio_blk_fuzz.c
+++ b/tests/qtest/fuzz/virtio_blk_fuzz.c
@@ -11,7 +11,7 @@
#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.h"
#include "tests/qtest/libqos/virtio-pci.h"
diff --git a/tests/qtest/fuzz/virtio_net_fuzz.c b/tests/qtest/fuzz/virtio_net_fuzz.c
index 0e873ab..c2c15f0 100644
--- a/tests/qtest/fuzz/virtio_net_fuzz.c
+++ b/tests/qtest/fuzz/virtio_net_fuzz.c
@@ -13,7 +13,7 @@
#include "qemu/osdep.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 "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);
g_assert_cmpint(ret, !=, -1);
- fcntl(sockfds[0], F_SETFL, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(sockfds[0], true, NULL);
sockfds_initialized = true;
g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ",
sockfds[1]);
diff --git a/tests/qtest/fuzz/virtio_scsi_fuzz.c b/tests/qtest/fuzz/virtio_scsi_fuzz.c
index 6ff6fab..b3220ef 100644
--- a/tests/qtest/fuzz/virtio_scsi_fuzz.c
+++ b/tests/qtest/fuzz/virtio_scsi_fuzz.c
@@ -12,7 +12,7 @@
#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.h"
#include "tests/qtest/libqos/virtio-pci.h"
diff --git a/tests/qtest/fw_cfg-test.c b/tests/qtest/fw_cfg-test.c
index 95b3907..5dc807b 100644
--- a/tests/qtest/fw_cfg-test.c
+++ b/tests/qtest/fw_cfg-test.c
@@ -12,7 +12,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "standard-headers/linux/qemu_fw_cfg.h"
#include "libqos/fw_cfg.h"
#include "qemu/bswap.h"
diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index da9c4c2..413cf96 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -18,7 +18,7 @@
#include "qemu/osdep.h"
#include "qemu/bswap.h"
#include "qapi/qmp/qlist.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/fw_cfg.h"
#include "libqos/libqos.h"
#include "standard-headers/linux/qemu_fw_cfg.h"
diff --git a/tests/qtest/hexloader-test.c b/tests/qtest/hexloader-test.c
index 5615020..8b7aa2d 100644
--- a/tests/qtest/hexloader-test.c
+++ b/tests/qtest/hexloader-test.c
@@ -10,7 +10,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/* Load 'test.hex' and verify that the in-memory contents are as expected.
* 'test.hex' is a memory test pattern stored in Hexadecimal Object
diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index b7243a1..5bcb75a 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -25,7 +25,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/libqos.h"
#include "libqos/pci-pc.h"
#include "libqos/malloc-pc.h"
diff --git a/tests/qtest/ipoctal232-test.c b/tests/qtest/ipoctal232-test.c
index 65ce10b..53a8c9b 100644
--- a/tests/qtest/ipoctal232-test.c
+++ b/tests/qtest/ipoctal232-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c
index 95628a4..e23a97f 100644
--- a/tests/qtest/ivshmem-test.c
+++ b/tests/qtest/ivshmem-test.c
@@ -13,7 +13,7 @@
#include "contrib/ivshmem-server/ivshmem-server.h"
#include "libqos/libqos-pc.h"
#include "libqos/libqos-spapr.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#define TMPSHMSIZE (1 << 20)
static char *tmpshm;
@@ -304,6 +304,7 @@ static void setup_vm_with_server(IVState *s, int nvectors)
static void test_ivshmem_server(void)
{
+ g_autoptr(GError) err = NULL;
IVState state1, state2, *s1, *s2;
ServerThread thread;
IvshmemServer server;
@@ -320,8 +321,8 @@ static void test_ivshmem_server(void)
g_assert_cmpint(ret, ==, 0);
thread.server = &server;
- ret = pipe(thread.pipe);
- g_assert_cmpint(ret, ==, 0);
+ g_unix_open_pipe(thread.pipe, FD_CLOEXEC, &err);
+ g_assert_no_error(err);
thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
g_assert(thread.thread != NULL);
diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
new file mode 100644
index 0000000..0358b83
--- /dev/null
+++ b/tests/qtest/libqmp.c
@@ -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);
+}
diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h
new file mode 100644
index 0000000..94aa973
--- /dev/null
+++ b/tests/qtest/libqmp.h
@@ -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_ */
diff --git a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
index 79631cc..c8a3ea1 100644
--- a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
+++ b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "malloc.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c
index 41c4be5..f53f12a 100644
--- a/tests/qtest/libqos/ahci.c
+++ b/tests/qtest/libqos/ahci.c
@@ -24,7 +24,7 @@
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "ahci.h"
#include "pci-pc.h"
diff --git a/tests/qtest/libqos/arm-imx25-pdk-machine.c b/tests/qtest/libqos/arm-imx25-pdk-machine.c
index 6692adf..54d0c95 100644
--- a/tests/qtest/libqos/arm-imx25-pdk-machine.c
+++ b/tests/qtest/libqos/arm-imx25-pdk-machine.c
@@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "malloc.h"
#include "qgraph.h"
#include "i2c.h"
diff --git a/tests/qtest/libqos/arm-n800-machine.c b/tests/qtest/libqos/arm-n800-machine.c
index ff2049c..ecd46b1 100644
--- a/tests/qtest/libqos/arm-n800-machine.c
+++ b/tests/qtest/libqos/arm-n800-machine.c
@@ -19,7 +19,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "malloc.h"
#include "qgraph.h"
#include "i2c.h"
diff --git a/tests/qtest/libqos/arm-raspi2-machine.c b/tests/qtest/libqos/arm-raspi2-machine.c
index 09ca863..0a29434 100644
--- a/tests/qtest/libqos/arm-raspi2-machine.c
+++ b/tests/qtest/libqos/arm-raspi2-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "malloc.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/arm-sabrelite-machine.c b/tests/qtest/libqos/arm-sabrelite-machine.c
index 72425f0..ec19a01 100644
--- a/tests/qtest/libqos/arm-sabrelite-machine.c
+++ b/tests/qtest/libqos/arm-sabrelite-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "malloc.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/arm-smdkc210-machine.c b/tests/qtest/libqos/arm-smdkc210-machine.c
index 321b882..4bff249 100644
--- a/tests/qtest/libqos/arm-smdkc210-machine.c
+++ b/tests/qtest/libqos/arm-smdkc210-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "malloc.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/arm-virt-machine.c b/tests/qtest/libqos/arm-virt-machine.c
index e0f5932..2e0beae 100644
--- a/tests/qtest/libqos/arm-virt-machine.c
+++ b/tests/qtest/libqos/arm-virt-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "malloc.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
index 56e53c7..3be8002 100644
--- a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
+++ b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "malloc.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/e1000e.c b/tests/qtest/libqos/e1000e.c
index a451f61..f87e0e8 100644
--- a/tests/qtest/libqos/e1000e.c
+++ b/tests/qtest/libqos/e1000e.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "pci-pc.h"
#include "qemu/sockets.h"
#include "qemu/iov.h"
diff --git a/tests/qtest/libqos/fw_cfg.c b/tests/qtest/libqos/fw_cfg.c
index 6b8e1ba..89f053c 100644
--- a/tests/qtest/libqos/fw_cfg.c
+++ b/tests/qtest/libqos/fw_cfg.c
@@ -14,7 +14,7 @@
#include "qemu/osdep.h"
#include "fw_cfg.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/bswap.h"
#include "hw/nvram/fw_cfg.h"
diff --git a/tests/qtest/libqos/fw_cfg.h b/tests/qtest/libqos/fw_cfg.h
index c6a7cf8..b0456a1 100644
--- a/tests/qtest/libqos/fw_cfg.h
+++ b/tests/qtest/libqos/fw_cfg.h
@@ -13,7 +13,7 @@
#ifndef LIBQOS_FW_CFG_H
#define LIBQOS_FW_CFG_H
-#include "libqtest.h"
+#include "../libqtest.h"
typedef struct QFWCFG QFWCFG;
diff --git a/tests/qtest/libqos/i2c-imx.c b/tests/qtest/libqos/i2c-imx.c
index 8f9a7e3..710cb92 100644
--- a/tests/qtest/libqos/i2c-imx.c
+++ b/tests/qtest/libqos/i2c-imx.c
@@ -21,7 +21,7 @@
#include "i2c.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "hw/i2c/imx_i2c.h"
diff --git a/tests/qtest/libqos/i2c-omap.c b/tests/qtest/libqos/i2c-omap.c
index eb4e453..6f98f54 100644
--- a/tests/qtest/libqos/i2c-omap.c
+++ b/tests/qtest/libqos/i2c-omap.c
@@ -11,7 +11,7 @@
#include "qemu/bswap.h"
-#include "libqtest.h"
+#include "../libqtest.h"
enum OMAPI2CRegisters {
OMAP_I2C_REV = 0x00,
diff --git a/tests/qtest/libqos/i2c.c b/tests/qtest/libqos/i2c.c
index ade1bdb..1a54c00 100644
--- a/tests/qtest/libqos/i2c.c
+++ b/tests/qtest/libqos/i2c.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
#include "i2c.h"
-#include "libqtest.h"
+#include "../libqtest.h"
void qi2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len)
{
diff --git a/tests/qtest/libqos/i2c.h b/tests/qtest/libqos/i2c.h
index 1341bac..d032240 100644
--- a/tests/qtest/libqos/i2c.h
+++ b/tests/qtest/libqos/i2c.h
@@ -9,7 +9,7 @@
#ifndef LIBQOS_I2C_H
#define LIBQOS_I2C_H
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qgraph.h"
typedef struct I2CAdapter I2CAdapter;
diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c
index 2251e86..85c7641 100644
--- a/tests/qtest/libqos/libqos.c
+++ b/tests/qtest/libqos/libqos.c
@@ -1,7 +1,7 @@
#include "qemu/osdep.h"
#include <sys/wait.h>
-#include "libqtest.h"
+#include "../libqtest.h"
#include "libqos.h"
#include "pci.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/libqos/libqos.h b/tests/qtest/libqos/libqos.h
index e0b2bfe..ba7df44 100644
--- a/tests/qtest/libqos/libqos.h
+++ b/tests/qtest/libqos/libqos.h
@@ -1,7 +1,7 @@
#ifndef LIBQOS_H
#define LIBQOS_H
-#include "libqtest.h"
+#include "../libqtest.h"
#include "pci.h"
#include "malloc.h"
diff --git a/tests/qtest/libqos/malloc.h b/tests/qtest/libqos/malloc.h
index 4d1a2e2..bbb8c74 100644
--- a/tests/qtest/libqos/malloc.h
+++ b/tests/qtest/libqos/malloc.h
@@ -14,7 +14,7 @@
#define LIBQOS_MALLOC_H
#include "qemu/queue.h"
-#include "libqtest.h"
+#include "../libqtest.h"
typedef enum {
ALLOC_NO_FLAGS = 0x00,
diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
index e988d15..9f29233 100644
--- a/tests/qtest/libqos/meson.build
+++ b/tests/qtest/libqos/meson.build
@@ -1,4 +1,7 @@
-libqos_srcs = files('../libqtest.c',
+libqos_srcs = files(
+ '../libqtest.c',
+ '../libqmp.c',
+
'qgraph.c',
'qos_external.c',
'pci.c',
diff --git a/tests/qtest/libqos/pci-pc.c b/tests/qtest/libqos/pci-pc.c
index f978442..e9dd5a5 100644
--- a/tests/qtest/libqos/pci-pc.c
+++ b/tests/qtest/libqos/pci-pc.c
@@ -11,7 +11,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "pci-pc.h"
#include "qapi/qmp/qdict.h"
#include "hw/pci/pci_regs.h"
diff --git a/tests/qtest/libqos/pci-spapr.c b/tests/qtest/libqos/pci-spapr.c
index 2622269..76bf9a8 100644
--- a/tests/qtest/libqos/pci-spapr.c
+++ b/tests/qtest/libqos/pci-spapr.c
@@ -6,7 +6,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "pci-spapr.h"
#include "rtas.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/pci.h b/tests/qtest/libqos/pci.h
index becb800..e705e06 100644
--- a/tests/qtest/libqos/pci.h
+++ b/tests/qtest/libqos/pci.h
@@ -13,7 +13,7 @@
#ifndef LIBQOS_PCI_H
#define LIBQOS_PCI_H
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qgraph.h"
#define QPCI_PIO_LIMIT 0x10000
diff --git a/tests/qtest/libqos/ppc64_pseries-machine.c b/tests/qtest/libqos/ppc64_pseries-machine.c
index 24ca179..364e9c6 100644
--- a/tests/qtest/libqos/ppc64_pseries-machine.c
+++ b/tests/qtest/libqos/ppc64_pseries-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qgraph.h"
#include "pci-spapr.h"
#include "qemu/module.h"
diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c
index 109ff04..0a2dddf 100644
--- a/tests/qtest/libqos/qgraph.c
+++ b/tests/qtest/libqos/qgraph.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/queue.h"
#include "qgraph_internal.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/qos_external.c b/tests/qtest/libqos/qos_external.c
index 10ee0f7..b7a0b87 100644
--- a/tests/qtest/libqos/qos_external.c
+++ b/tests/qtest/libqos/qos_external.c
@@ -18,7 +18,7 @@
#include "qemu/osdep.h"
#include <getopt.h>
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qbool.h"
#include "qapi/qmp/qstring.h"
diff --git a/tests/qtest/libqos/rtas.c b/tests/qtest/libqos/rtas.c
index db29d55..dedbfb4 100644
--- a/tests/qtest/libqos/rtas.c
+++ b/tests/qtest/libqos/rtas.c
@@ -4,7 +4,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "rtas.h"
static void qrtas_copy_args(QTestState *qts, uint64_t target_args,
diff --git a/tests/qtest/libqos/sdhci-cmd.c b/tests/qtest/libqos/sdhci-cmd.c
index 2d9e518..a6f073a 100644
--- a/tests/qtest/libqos/sdhci-cmd.c
+++ b/tests/qtest/libqos/sdhci-cmd.c
@@ -16,7 +16,7 @@
#include "qemu/osdep.h"
#include "sdhci-cmd.h"
-#include "libqtest.h"
+#include "../libqtest.h"
static ssize_t read_fifo(QTestState *qts, uint64_t reg, char *msg, size_t count)
{
diff --git a/tests/qtest/libqos/sdhci-cmd.h b/tests/qtest/libqos/sdhci-cmd.h
index 64763c5..9e61dd4 100644
--- a/tests/qtest/libqos/sdhci-cmd.h
+++ b/tests/qtest/libqos/sdhci-cmd.h
@@ -14,7 +14,7 @@
* for more details.
*/
-#include "libqtest.h"
+#include "../libqtest.h"
/* more details at hw/sd/sdhci-internal.h */
#define SDHC_BLKSIZE 0x04
diff --git a/tests/qtest/libqos/sdhci.c b/tests/qtest/libqos/sdhci.c
index 65f0d07..7169698 100644
--- a/tests/qtest/libqos/sdhci.c
+++ b/tests/qtest/libqos/sdhci.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qgraph.h"
#include "pci.h"
#include "qemu/module.h"
diff --git a/tests/qtest/libqos/tpci200.c b/tests/qtest/libqos/tpci200.c
index 1787b1f..8b00603 100644
--- a/tests/qtest/libqos/tpci200.c
+++ b/tests/qtest/libqos/tpci200.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "qgraph.h"
#include "pci.h"
diff --git a/tests/qtest/libqos/usb.c b/tests/qtest/libqos/usb.c
index 8b45b02..446fdb5 100644
--- a/tests/qtest/libqos/usb.c
+++ b/tests/qtest/libqos/usb.c
@@ -12,7 +12,7 @@
* See the COPYING file in the top-level directory.
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "hw/usb/uhci-regs.h"
#include "usb.h"
diff --git a/tests/qtest/libqos/vhost-user-blk.c b/tests/qtest/libqos/vhost-user-blk.c
index 568c342..2f3c9cb 100644
--- a/tests/qtest/libqos/vhost-user-blk.c
+++ b/tests/qtest/libqos/vhost-user-blk.c
@@ -21,7 +21,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "standard-headers/linux/virtio_blk.h"
#include "vhost-user-blk.h"
diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index f51f063..70aea8b 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -22,7 +22,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "standard-headers/linux/virtio_ids.h"
#include "virtio-9p.h"
diff --git a/tests/qtest/libqos/virtio-balloon.c b/tests/qtest/libqos/virtio-balloon.c
index a3da5c2..29b5d17 100644
--- a/tests/qtest/libqos/virtio-balloon.c
+++ b/tests/qtest/libqos/virtio-balloon.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "qgraph.h"
#include "virtio-balloon.h"
diff --git a/tests/qtest/libqos/virtio-blk.c b/tests/qtest/libqos/virtio-blk.c
index 5da0259..ee4943f 100644
--- a/tests/qtest/libqos/virtio-blk.c
+++ b/tests/qtest/libqos/virtio-blk.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "standard-headers/linux/virtio_blk.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/virtio-iommu.c b/tests/qtest/libqos/virtio-iommu.c
index 18cba4c..afc7d14 100644
--- a/tests/qtest/libqos/virtio-iommu.c
+++ b/tests/qtest/libqos/virtio-iommu.c
@@ -12,7 +12,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "qgraph.h"
#include "virtio-iommu.h"
diff --git a/tests/qtest/libqos/virtio-mmio.c b/tests/qtest/libqos/virtio-mmio.c
index 75efda3..a6cca86 100644
--- a/tests/qtest/libqos/virtio-mmio.c
+++ b/tests/qtest/libqos/virtio-mmio.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "virtio.h"
#include "virtio-mmio.h"
diff --git a/tests/qtest/libqos/virtio-net.c b/tests/qtest/libqos/virtio-net.c
index 1cae07f..2ac73ac 100644
--- a/tests/qtest/libqos/virtio-net.c
+++ b/tests/qtest/libqos/virtio-net.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "qgraph.h"
#include "virtio-net.h"
diff --git a/tests/qtest/libqos/virtio-pci.c b/tests/qtest/libqos/virtio-pci.c
index cd3c0f5..67c2498 100644
--- a/tests/qtest/libqos/virtio-pci.c
+++ b/tests/qtest/libqos/virtio-pci.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "virtio.h"
#include "virtio-pci.h"
#include "pci.h"
diff --git a/tests/qtest/libqos/virtio-rng.c b/tests/qtest/libqos/virtio-rng.c
index 2e09dd7..078e3ab 100644
--- a/tests/qtest/libqos/virtio-rng.c
+++ b/tests/qtest/libqos/virtio-rng.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "qgraph.h"
#include "virtio-rng.h"
diff --git a/tests/qtest/libqos/virtio-scsi.c b/tests/qtest/libqos/virtio-scsi.c
index 5644e32..c4d0461 100644
--- a/tests/qtest/libqos/virtio-scsi.c
+++ b/tests/qtest/libqos/virtio-scsi.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "standard-headers/linux/virtio_ids.h"
#include "qgraph.h"
diff --git a/tests/qtest/libqos/virtio-serial.c b/tests/qtest/libqos/virtio-serial.c
index ee34afd..1d689c3 100644
--- a/tests/qtest/libqos/virtio-serial.c
+++ b/tests/qtest/libqos/virtio-serial.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qemu/module.h"
#include "qgraph.h"
#include "virtio-serial.h"
diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c
index fba9186..09ec09b 100644
--- a/tests/qtest/libqos/virtio.c
+++ b/tests/qtest/libqos/virtio.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
#include "qemu/bswap.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "virtio.h"
#include "standard-headers/linux/virtio_config.h"
#include "standard-headers/linux/virtio_ring.h"
diff --git a/tests/qtest/libqos/x86_64_pc-machine.c b/tests/qtest/libqos/x86_64_pc-machine.c
index ad96742..dce0c94 100644
--- a/tests/qtest/libqos/x86_64_pc-machine.c
+++ b/tests/qtest/libqos/x86_64_pc-machine.c
@@ -17,7 +17,7 @@
*/
#include "qemu/osdep.h"
-#include "libqtest.h"
+#include "../libqtest.h"
#include "qgraph.h"
#include "pci-pc.h"
#include "qemu/module.h"
diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h
index b0838b9..4e7d0ae 100644
--- a/tests/qtest/libqtest-single.h
+++ b/tests/qtest/libqtest-single.h
@@ -11,7 +11,7 @@
#ifndef LIBQTEST_SINGLE_H
#define LIBQTEST_SINGLE_H
-#include "libqos/libqtest.h"
+#include "libqtest.h"
QTestState *global_qtest __attribute__((common, weak));
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 5098d71..228357f 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -20,11 +20,10 @@
#include <sys/wait.h>
#include <sys/un.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
+#include "libqmp.h"
#include "qemu/ctype.h"
#include "qemu/cutils.h"
-#include "qapi/error.h"
-#include "qapi/qmp/json-parser.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
#include "qapi/qmp/qlist.h"
@@ -32,8 +31,6 @@
#define MAX_IRQ 256
#define SOCKET_TIMEOUT 50
-#define SOCKET_MAX_FDS 16
-
typedef void (*QTestSendFn)(QTestState *s, const char *buf);
typedef void (*ExternalSendFn)(void *s, const char *buf);
@@ -440,40 +437,6 @@ static void G_GNUC_PRINTF(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
g_free(str);
}
-/* 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);
-}
-
static GString *qtest_client_socket_recv_line(QTestState *s)
{
GString *line;
@@ -568,62 +531,6 @@ static int qtest_query_target_endianness(QTestState *s)
return big_endian;
}
-typedef struct {
- JSONMessageParser parser;
- QDict *response;
-} QMPResponseParser;
-
-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;
-}
-
QDict *qtest_qmp_receive(QTestState *s)
{
while (true) {
@@ -664,50 +571,6 @@ int qtest_socket_server(const char *socket_path)
return sock;
}
-/**
- * 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);
-}
-
void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
const char *fmt, va_list ap)
{
@@ -719,13 +582,6 @@ void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
qmp_fd_vsend_fds(s->qmp_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 *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
const char *fmt, va_list ap)
{
@@ -743,26 +599,6 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
return qtest_qmp_receive(s);
}
-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);
-}
-
QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
const char *fmt, ...)
{
@@ -795,27 +631,6 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...)
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);
-}
-
void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
{
va_list ap;
@@ -1539,24 +1354,6 @@ void qtest_qmp_device_del(QTestState *qts, const char *id)
qtest_qmp_eventwait(qts, "DEVICE_DELETED");
}
-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);
-}
-
static void qtest_client_set_tx_handler(QTestState *s,
QTestSendFn send)
{
diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqtest.h
index 552667f..4ab0cad 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -19,6 +19,7 @@
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qdict.h"
+#include "libqmp.h"
typedef struct QTestState QTestState;
@@ -690,16 +691,6 @@ void qtest_remove_abrt_handler(void *data);
void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
G_GNUC_PRINTF(2, 3);
-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);
-
/**
* qtest_cb_for_every_machine:
* @cb: Pointer to the callback function
@@ -772,24 +763,6 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
void qtest_qmp_device_del(QTestState *qts, const char *id);
/**
- * 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);
-
-/**
* qtest_probe_child:
* @s: QTestState instance to operate on.
*
diff --git a/tests/qtest/lpc-ich9-test.c b/tests/qtest/lpc-ich9-test.c
index fe0bef9..8ac95b8 100644
--- a/tests/qtest/lpc-ich9-test.c
+++ b/tests/qtest/lpc-ich9-test.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
static void test_lp1878642_pci_bus_get_irq_level_assert(void)
{
diff --git a/tests/qtest/m48t59-test.c b/tests/qtest/m48t59-test.c
index 6db3234..b94a123 100644
--- a/tests/qtest/m48t59-test.c
+++ b/tests/qtest/m48t59-test.c
@@ -14,7 +14,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#define RTC_SECONDS 0x9
#define RTC_MINUTES 0xa
diff --git a/tests/qtest/machine-none-test.c b/tests/qtest/machine-none-test.c
index 8ca1807..d0f8cd9 100644
--- a/tests/qtest/machine-none-test.c
+++ b/tests/qtest/machine-none-test.c
@@ -13,7 +13,7 @@
#include "qemu/osdep.h"
#include "qemu/cutils.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/megasas-test.c b/tests/qtest/megasas-test.c
index eae70ff..d6796b9 100644
--- a/tests/qtest/megasas-test.c
+++ b/tests/qtest/megasas-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/bswap.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
diff --git a/tests/qtest/microbit-test.c b/tests/qtest/microbit-test.c
index 2b25557..04e199e 100644
--- a/tests/qtest/microbit-test.c
+++ b/tests/qtest/microbit-test.c
@@ -16,7 +16,7 @@
#include "qemu/osdep.h"
#include "exec/hwaddr.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "hw/arm/nrf51.h"
#include "hw/char/nrf51_uart.h"
diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 555adaf..c7872e8 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -12,7 +12,7 @@
#ifndef MIGRATION_HELPERS_H_
#define MIGRATION_HELPERS_H_
-#include "libqos/libqtest.h"
+#include "libqtest.h"
extern bool got_stop;
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 2af36c1..cba6023 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -12,7 +12,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "qemu/module.h"
diff --git a/tests/qtest/modules-test.c b/tests/qtest/modules-test.c
index c238b3f..8821768 100644
--- a/tests/qtest/modules-test.c
+++ b/tests/qtest/modules-test.c
@@ -1,5 +1,5 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
const char common_args[] = "-nodefaults -machine none";
diff --git a/tests/qtest/ne2000-test.c b/tests/qtest/ne2000-test.c
index 43cfc45..3fc0e55 100644
--- a/tests/qtest/ne2000-test.c
+++ b/tests/qtest/ne2000-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c
index 5ce8ce1..3fa6d9e 100644
--- a/tests/qtest/npcm7xx_adc-test.c
+++ b/tests/qtest/npcm7xx_adc-test.c
@@ -17,7 +17,7 @@
#include "qemu/osdep.h"
#include "qemu/bitops.h"
#include "qemu/timer.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#define REF_HZ (25000000)
diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c
index a54fd70..c4a5fdc 100644
--- a/tests/qtest/npcm7xx_pwm-test.c
+++ b/tests/qtest/npcm7xx_pwm-test.c
@@ -16,7 +16,7 @@
#include "qemu/osdep.h"
#include "qemu/bitops.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qnum.h"
diff --git a/tests/qtest/npcm7xx_sdhci-test.c b/tests/qtest/npcm7xx_sdhci-test.c
index c1f496f..aa35a77 100644
--- a/tests/qtest/npcm7xx_sdhci-test.c
+++ b/tests/qtest/npcm7xx_sdhci-test.c
@@ -17,7 +17,7 @@
#include "qemu/osdep.h"
#include "hw/sd/npcm7xx_sdhci.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqtest-single.h"
#include "libqos/sdhci-cmd.h"
diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c
index 6b3038a..a878cdc 100644
--- a/tests/qtest/npcm7xx_smbus-test.c
+++ b/tests/qtest/npcm7xx_smbus-test.c
@@ -17,7 +17,7 @@
#include "qemu/osdep.h"
#include "qemu/bitops.h"
#include "libqos/i2c.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "hw/sensor/tmp105_regs.h"
#define NR_SMBUS_DEVICES 16
diff --git a/tests/qtest/npcm7xx_watchdog_timer-test.c b/tests/qtest/npcm7xx_watchdog_timer-test.c
index 3aae5a0..4773a67 100644
--- a/tests/qtest/npcm7xx_watchdog_timer-test.c
+++ b/tests/qtest/npcm7xx_watchdog_timer-test.c
@@ -17,7 +17,7 @@
#include "qemu/osdep.h"
#include "qemu/timer.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#define WTCR_OFFSET 0x1c
diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c
index 90bf68a..749429d 100644
--- a/tests/qtest/numa-test.c
+++ b/tests/qtest/numa-test.c
@@ -10,7 +10,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
diff --git a/tests/qtest/nvme-test.c b/tests/qtest/nvme-test.c
index f8bafb5..008d189 100644
--- a/tests/qtest/nvme-test.c
+++ b/tests/qtest/nvme-test.c
@@ -10,7 +10,7 @@
#include "qemu/osdep.h"
#include "qemu/module.h"
#include "qemu/units.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
#include "include/block/nvme.h"
diff --git a/tests/qtest/pca9552-test.c b/tests/qtest/pca9552-test.c
index 42a1312..d80ed93 100644
--- a/tests/qtest/pca9552-test.c
+++ b/tests/qtest/pca9552-test.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/qgraph.h"
#include "libqos/i2c.h"
#include "hw/misc/pca9552_regs.h"
diff --git a/tests/qtest/pci-test.c b/tests/qtest/pci-test.c
index e15d4d9..4b2092b 100644
--- a/tests/qtest/pci-test.c
+++ b/tests/qtest/pci-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/pcnet-test.c b/tests/qtest/pcnet-test.c
index 7583aeb..900944f 100644
--- a/tests/qtest/pcnet-test.c
+++ b/tests/qtest/pcnet-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 6168edc..7fce614 100644
--- a/tests/qtest/pflash-cfi02-test.c
+++ b/tests/qtest/pflash-cfi02-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/*
* To test the pflash_cfi02 device, we run QEMU with the musicpal machine with
diff --git a/tests/qtest/pnv-xscom-test.c b/tests/qtest/pnv-xscom-test.c
index c8d4043..2c46d5c 100644
--- a/tests/qtest/pnv-xscom-test.c
+++ b/tests/qtest/pnv-xscom-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
typedef enum PnvChipType {
PNV_CHIP_POWER8E, /* AKA Murano (default) */
diff --git a/tests/qtest/prom-env-test.c b/tests/qtest/prom-env-test.c
index bdbb01d..c2b0448 100644
--- a/tests/qtest/prom-env-test.c
+++ b/tests/qtest/prom-env-test.c
@@ -20,7 +20,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/libqos-spapr.h"
#define MAGIC 0xcafec0de
diff --git a/tests/qtest/pvpanic-pci-test.c b/tests/qtest/pvpanic-pci-test.c
index 2358852..c82c365 100644
--- a/tests/qtest/pvpanic-pci-test.c
+++ b/tests/qtest/pvpanic-pci-test.c
@@ -12,7 +12,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "libqos/pci.h"
#include "libqos/pci-pc.h"
diff --git a/tests/qtest/pvpanic-test.c b/tests/qtest/pvpanic-test.c
index 6dcad2d..bc7b7df 100644
--- a/tests/qtest/pvpanic-test.c
+++ b/tests/qtest/pvpanic-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
static void test_panic_nopause(void)
diff --git a/tests/qtest/pxe-test.c b/tests/qtest/pxe-test.c
index 3cb47d2..52f0b5c 100644
--- a/tests/qtest/pxe-test.c
+++ b/tests/qtest/pxe-test.c
@@ -14,7 +14,7 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "boot-sector.h"
#include "libqos/libqos-spapr.h"
diff --git a/tests/qtest/q35-test.c b/tests/qtest/q35-test.c
index b7cf144..c922d81 100644
--- a/tests/qtest/q35-test.c
+++ b/tests/qtest/q35-test.c
@@ -10,7 +10,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/pci.h"
#include "libqos/pci-pc.h"
#include "hw/pci-host/q35.h"
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c
index 7f103ea..056b40e 100644
--- a/tests/qtest/qmp-cmd-test.c
+++ b/tests/qtest/qmp-cmd-test.c
@@ -11,7 +11,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-introspect.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index cd27fae..9a42480 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -11,7 +11,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-control.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c
index 6b162e1..7b871b2 100644
--- a/tests/qtest/qom-test.c
+++ b/tests/qtest/qom-test.c
@@ -12,7 +12,7 @@
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
#include "qemu/cutils.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
static void test_properties(QTestState *qts, const char *path, bool recurse)
{
diff --git a/tests/qtest/rtas-test.c b/tests/qtest/rtas-test.c
index 5f1194a..50df60e 100644
--- a/tests/qtest/rtas-test.c
+++ b/tests/qtest/rtas-test.c
@@ -1,6 +1,6 @@
#include "qemu/osdep.h"
#include "qemu/cutils.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/libqos-spapr.h"
#include "libqos/rtas.h"
diff --git a/tests/qtest/sdhci-test.c b/tests/qtest/sdhci-test.c
index a110cfe..6275e76 100644
--- a/tests/qtest/sdhci-test.c
+++ b/tests/qtest/sdhci-test.c
@@ -10,7 +10,7 @@
#include "qemu/osdep.h"
#include "hw/registerfields.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/pci-pc.h"
#include "hw/pci/pci.h"
diff --git a/tests/qtest/spapr-phb-test.c b/tests/qtest/spapr-phb-test.c
index ea8d596..093dc22 100644
--- a/tests/qtest/spapr-phb-test.c
+++ b/tests/qtest/spapr-phb-test.c
@@ -9,7 +9,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
diff --git a/tests/qtest/tco-test.c b/tests/qtest/tco-test.c
index 47bc7ad..254f735 100644
--- a/tests/qtest/tco-test.c
+++ b/tests/qtest/tco-test.c
@@ -9,7 +9,7 @@
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/pci.h"
#include "libqos/pci-pc.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
index fdf66ce..c8b0a92 100644
--- a/tests/qtest/test-filter-mirror.c
+++ b/tests/qtest/test-filter-mirror.c
@@ -9,7 +9,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qemu/iov.h"
#include "qemu/sockets.h"
diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
index 339d3c0..24ca928 100644
--- a/tests/qtest/test-filter-redirector.c
+++ b/tests/qtest/test-filter-redirector.c
@@ -51,7 +51,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qemu/iov.h"
#include "qemu/sockets.h"
diff --git a/tests/qtest/test-hmp.c b/tests/qtest/test-hmp.c
index 413eb95..f8b22ab 100644
--- a/tests/qtest/test-hmp.c
+++ b/tests/qtest/test-hmp.c
@@ -15,7 +15,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
static int verbose;
diff --git a/tests/qtest/tpm-crb-swtpm-test.c b/tests/qtest/tpm-crb-swtpm-test.c
index 1d82a48..55fdb56 100644
--- a/tests/qtest/tpm-crb-swtpm-test.c
+++ b/tests/qtest/tpm-crb-swtpm-test.c
@@ -15,7 +15,7 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "tpm-tests.h"
#include "hw/acpi/tpm.h"
diff --git a/tests/qtest/tpm-emu.h b/tests/qtest/tpm-emu.h
index c33d99a..712cee9 100644
--- a/tests/qtest/tpm-emu.h
+++ b/tests/qtest/tpm-emu.h
@@ -22,7 +22,7 @@
#include "qemu/sockets.h"
#include "io/channel.h"
#include "sysemu/tpm.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
struct tpm_hdr {
uint16_t tag;
diff --git a/tests/qtest/tpm-tis-device-swtpm-test.c b/tests/qtest/tpm-tis-device-swtpm-test.c
index f7126ef..7b20035 100644
--- a/tests/qtest/tpm-tis-device-swtpm-test.c
+++ b/tests/qtest/tpm-tis-device-swtpm-test.c
@@ -16,7 +16,7 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "tpm-tests.h"
#include "hw/acpi/tpm.h"
diff --git a/tests/qtest/tpm-tis-swtpm-test.c b/tests/qtest/tpm-tis-swtpm-test.c
index fa590e6..90131cb 100644
--- a/tests/qtest/tpm-tis-swtpm-test.c
+++ b/tests/qtest/tpm-tis-swtpm-test.c
@@ -15,7 +15,7 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "tpm-tests.h"
#include "hw/acpi/tpm.h"
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index 3a40ff3..e0dc5da 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -15,7 +15,7 @@
#include "qemu/osdep.h"
#include "hw/acpi/tpm.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "tpm-util.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/tulip-test.c b/tests/qtest/tulip-test.c
index da16cbf..2fb6c4d 100644
--- a/tests/qtest/tulip-test.c
+++ b/tests/qtest/tulip-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index ee30f54..a2cec87 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -302,6 +302,7 @@ static int chr_can_read(void *opaque)
static void chr_read(void *opaque, const uint8_t *buf, int size)
{
+ g_autoptr(GError) err = NULL;
TestServer *s = opaque;
CharBackend *chr = &s->chr;
VhostUserMsg msg;
@@ -394,7 +395,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)
* The receive function forces it to be blocking,
* so revert it back to non-blocking.
*/
- qemu_set_nonblock(fd);
+ g_unix_set_fd_nonblocking(fd, true, &err);
+ g_assert_no_error(err);
break;
case VHOST_USER_SET_LOG_BASE:
diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index 78811f1..443ee56 100644
--- a/tests/qtest/virtio-net-failover.c
+++ b/tests/qtest/virtio-net-failover.c
@@ -8,7 +8,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "libqos/pci.h"
#include "libqos/pci-pc.h"
#include "qapi/qmp/qdict.h"
diff --git a/tests/qtest/virtio-rng-test.c b/tests/qtest/virtio-rng-test.c
index e6b8cd8..092ba13 100644
--- a/tests/qtest/virtio-rng-test.c
+++ b/tests/qtest/virtio-rng-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/virtio-rng.h"
diff --git a/tests/qtest/virtio-test.c b/tests/qtest/virtio-test.c
index 6313417..f7c6afd 100644
--- a/tests/qtest/virtio-test.c
+++ b/tests/qtest/virtio-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/vmgenid-test.c b/tests/qtest/vmgenid-test.c
index 6781a51..efba76e 100644
--- a/tests/qtest/vmgenid-test.c
+++ b/tests/qtest/vmgenid-test.c
@@ -14,7 +14,7 @@
#include "hw/acpi/acpi-defs.h"
#include "boot-sector.h"
#include "acpi-utils.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#define VGID_GUID "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
diff --git a/tests/qtest/vmxnet3-test.c b/tests/qtest/vmxnet3-test.c
index 97c23fd..a810252 100644
--- a/tests/qtest/vmxnet3-test.c
+++ b/tests/qtest/vmxnet3-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qemu/module.h"
#include "libqos/qgraph.h"
#include "libqos/pci.h"
diff --git a/tests/qtest/wdt_ib700-test.c b/tests/qtest/wdt_ib700-test.c
index 6c36e43..797288d 100644
--- a/tests/qtest/wdt_ib700-test.c
+++ b/tests/qtest/wdt_ib700-test.c
@@ -8,7 +8,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qemu/timer.h"
diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c
index 54de71a..89610fc 100644
--- a/tests/qtest/xlnx-can-test.c
+++ b/tests/qtest/xlnx-can-test.c
@@ -25,7 +25,7 @@
*/
#include "qemu/osdep.h"
-#include "libqos/libqtest.h"
+#include "libqtest.h"
/* Base address. */
#define CAN0_BASE_ADDR 0xFF060000
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index ab01e00..264f2bc 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -154,7 +154,7 @@ if have_system
endif
if have_ga and targetos == 'linux'
- tests += {'test-qga': ['../qtest/libqtest.c']}
+ tests += {'test-qga': ['../qtest/libqmp.c']}
test_deps += {'test-qga': qga}
endif
diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c
index 0a9e090..5af4de5 100644
--- a/tests/unit/socket-helpers.c
+++ b/tests/unit/socket-helpers.c
@@ -88,7 +88,7 @@ static int socket_can_bind_connect(const char *hostname, int family)
goto cleanup;
}
- qemu_set_nonblock(cfd);
+ qemu_socket_set_nonblock(cfd);
if (connect(cfd, (struct sockaddr *)&ss, sslen) < 0) {
if (errno == EINPROGRESS) {
check_soerr = true;
diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-tlssession.c
index 5f0da91..a266dc3 100644
--- a/tests/unit/test-crypto-tlssession.c
+++ b/tests/unit/test-crypto-tlssession.c
@@ -90,8 +90,8 @@ static void test_crypto_tls_session_psk(void)
* thread, so we need these non-blocking to avoid deadlock
* of ourselves
*/
- qemu_set_nonblock(channel[0]);
- qemu_set_nonblock(channel[1]);
+ qemu_socket_set_nonblock(channel[0]);
+ qemu_socket_set_nonblock(channel[1]);
clientCreds = test_tls_creds_psk_create(
QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT,
@@ -244,8 +244,8 @@ static void test_crypto_tls_session_x509(const void *opaque)
* thread, so we need these non-blocking to avoid deadlock
* of ourselves
*/
- qemu_set_nonblock(channel[0]);
- qemu_set_nonblock(channel[1]);
+ qemu_socket_set_nonblock(channel[0]);
+ qemu_socket_set_nonblock(channel[1]);
#define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/"
#define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/"
diff --git a/tests/unit/test-io-channel-file.c b/tests/unit/test-io-channel-file.c
index 29038e6..1977006 100644
--- a/tests/unit/test-io-channel-file.c
+++ b/tests/unit/test-io-channel-file.c
@@ -109,7 +109,7 @@ static void test_io_channel_pipe(bool async)
QIOChannelTest *test;
int fd[2];
- if (pipe(fd) < 0) {
+ if (!g_unix_open_pipe(fd, FD_CLOEXEC, NULL)) {
perror("pipe");
abort();
}
diff --git a/tests/unit/test-iov.c b/tests/unit/test-iov.c
index 0d2ba9b..93bda00 100644
--- a/tests/unit/test-iov.c
+++ b/tests/unit/test-iov.c
@@ -186,7 +186,7 @@ static void test_io(void)
close(sv[0]);
FD_SET(sv[1], &fds);
- fcntl(sv[1], F_SETFL, O_RDWR|O_NONBLOCK);
+ g_unix_set_fd_nonblocking(sv[1], true, NULL);
r = g_test_rand_int_range(sz / 2, sz);
setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &r, sizeof(r));
@@ -220,7 +220,7 @@ static void test_io(void)
close(sv[1]);
FD_SET(sv[0], &fds);
- fcntl(sv[0], F_SETFL, O_RDWR|O_NONBLOCK);
+ g_unix_set_fd_nonblocking(sv[0], true, NULL);
r = g_test_rand_int_range(sz / 2, sz);
setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &r, sizeof(r));
usleep(500000);
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index e17a288..d6df1ee 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -4,7 +4,7 @@
#include <sys/socket.h>
#include <sys/un.h>
-#include "../qtest/libqos/libqtest.h"
+#include "../qtest/libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c
index f8981e5..f5f66f2 100644
--- a/tools/virtiofsd/helper.c
+++ b/tools/virtiofsd/helper.c
@@ -275,7 +275,7 @@ int fuse_daemonize(int foreground)
int waiter[2];
char completed;
- if (pipe(waiter)) {
+ if (!g_unix_open_pipe(waiter, FD_CLOEXEC, NULL)) {
fuse_log(FUSE_LOG_ERR, "fuse_daemonize: pipe: %s\n",
strerror(errno));
return -1;
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 05c0c98..e572a2e 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -316,7 +316,10 @@ static void input_linux_complete(UserCreatable *uc, Error **errp)
error_setg_file_open(errp, errno, il->evdev);
return;
}
- qemu_set_nonblock(il->fd);
+ if (!g_unix_set_fd_nonblocking(il->fd, true, NULL)) {
+ error_setg_errno(errp, errno, "Failed to set FD nonblocking");
+ return;
+ }
rc = ioctl(il->fd, EVIOCGVERSION, &ver);
if (rc < 0) {
diff --git a/util/compatfd.c b/util/compatfd.c
index 55b6e0b..147e39e 100644
--- a/util/compatfd.c
+++ b/util/compatfd.c
@@ -60,14 +60,11 @@ static int qemu_signalfd_compat(const sigset_t *mask)
info = g_malloc(sizeof(*info));
- if (pipe(fds) == -1) {
+ if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) {
g_free(info);
return -1;
}
- qemu_set_cloexec(fds[0]);
- qemu_set_cloexec(fds[1]);
-
memcpy(&info->mask, mask, sizeof(*mask));
info->fd = fds[1];
diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c
index 904b375..ed368e1 100644
--- a/util/coroutine-ucontext.c
+++ b/util/coroutine-ucontext.c
@@ -30,7 +30,7 @@
#include <valgrind/valgrind.h>
#endif
-#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
+#ifdef QEMU_SANITIZE_ADDRESS
#ifdef CONFIG_ASAN_IFACE_FIBER
#define CONFIG_ASAN 1
#include <sanitizer/asan_interface.h>
diff --git a/util/event_notifier-posix.c b/util/event_notifier-posix.c
index 8dc30c5..76420c5 100644
--- a/util/event_notifier-posix.c
+++ b/util/event_notifier-posix.c
@@ -49,16 +49,14 @@ int event_notifier_init(EventNotifier *e, int active)
if (errno != ENOSYS) {
return -errno;
}
- if (qemu_pipe(fds) < 0) {
+ if (!g_unix_open_pipe(fds, FD_CLOEXEC, NULL)) {
return -errno;
}
- ret = fcntl_setfl(fds[0], O_NONBLOCK);
- if (ret < 0) {
+ if (!g_unix_set_fd_nonblocking(fds[0], true, NULL)) {
ret = -errno;
goto fail;
}
- ret = fcntl_setfl(fds[1], O_NONBLOCK);
- if (ret < 0) {
+ if (!g_unix_set_fd_nonblocking(fds[1], true, NULL)) {
ret = -errno;
goto fail;
}
diff --git a/util/main-loop.c b/util/main-loop.c
index b7b0ce4..9afac10 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -114,7 +114,7 @@ static int qemu_signal_init(Error **errp)
return -errno;
}
- fcntl_setfl(sigfd, O_NONBLOCK);
+ g_unix_set_fd_nonblocking(sigfd, true, NULL);
qemu_set_fd_handler(sigfd, sigfd_handler, NULL, (void *)(intptr_t)sigfd);
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index b8bf7d4..477990f 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -224,32 +224,20 @@ void qemu_anon_ram_free(void *ptr, size_t size)
qemu_ram_munmap(-1, ptr, size);
}
-void qemu_set_block(int fd)
+void qemu_socket_set_block(int fd)
{
- int f;
- f = fcntl(fd, F_GETFL);
- assert(f != -1);
- f = fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
- assert(f != -1);
+ g_unix_set_fd_nonblocking(fd, false, NULL);
}
-int qemu_try_set_nonblock(int fd)
+int qemu_socket_try_set_nonblock(int fd)
{
- int f;
- f = fcntl(fd, F_GETFL);
- if (f == -1) {
- return -errno;
- }
- if (fcntl(fd, F_SETFL, f | O_NONBLOCK) == -1) {
- return -errno;
- }
- return 0;
+ return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -errno;
}
-void qemu_set_nonblock(int fd)
+void qemu_socket_set_nonblock(int fd)
{
int f;
- f = qemu_try_set_nonblock(fd);
+ f = qemu_socket_try_set_nonblock(fd);
assert(f == 0);
}
@@ -274,28 +262,6 @@ void qemu_set_cloexec(int fd)
assert(f != -1);
}
-/*
- * Creates a pipe with FD_CLOEXEC set on both file descriptors
- */
-int qemu_pipe(int pipefd[2])
-{
- int ret;
-
-#ifdef CONFIG_PIPE2
- ret = pipe2(pipefd, O_CLOEXEC);
- if (ret != -1 || errno != ENOSYS) {
- return ret;
- }
-#endif
- ret = pipe(pipefd);
- if (ret == 0) {
- qemu_set_cloexec(pipefd[0]);
- qemu_set_cloexec(pipefd[1]);
- }
-
- return ret;
-}
-
char *
qemu_get_local_state_dir(void)
{
@@ -897,21 +863,6 @@ size_t qemu_get_host_physmem(void)
return 0;
}
-/* Sets a specific flag */
-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;
-}
-
int qemu_msync(void *addr, size_t length, int fd)
{
size_t align_mask = ~(qemu_real_host_page_size() - 1);
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 9c1e812..dafef4f 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -184,14 +184,14 @@ static int socket_error(void)
}
}
-void qemu_set_block(int fd)
+void qemu_socket_set_block(int fd)
{
unsigned long opt = 0;
WSAEventSelect(fd, NULL, 0);
ioctlsocket(fd, FIONBIO, &opt);
}
-int qemu_try_set_nonblock(int fd)
+int qemu_socket_try_set_nonblock(int fd)
{
unsigned long opt = 1;
if (ioctlsocket(fd, FIONBIO, &opt) != NO_ERROR) {
@@ -200,9 +200,9 @@ int qemu_try_set_nonblock(int fd)
return 0;
}
-void qemu_set_nonblock(int fd)
+void qemu_socket_set_nonblock(int fd)
{
- (void)qemu_try_set_nonblock(fd);
+ (void)qemu_socket_try_set_nonblock(fd);
}
int socket_set_fast_reuse(int fd)
diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c
index f66fbba..232984a 100644
--- a/util/vhost-user-server.c
+++ b/util/vhost-user-server.c
@@ -65,7 +65,7 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg)
{
int i;
for (i = 0; i < vmsg->fd_num; i++) {
- qemu_set_nonblock(vmsg->fds[i]);
+ qemu_socket_set_nonblock(vmsg->fds[i]);
}
}
@@ -270,7 +270,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt,
vu_fd_watch->fd = fd;
vu_fd_watch->cb = cb;
- qemu_set_nonblock(fd);
+ qemu_socket_set_nonblock(fd);
aio_set_fd_handler(server->ioc->ctx, fd, true, kick_handler,
NULL, NULL, NULL, vu_fd_watch);
vu_fd_watch->vu_dev = vu_dev;