summaryrefslogtreecommitdiff
path: root/posix-aio-compat.c
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2010-09-06 17:20:17 -0300
committerMarcelo Tosatti <mtosatti@redhat.com>2010-09-07 18:36:38 -0300
commitcb375ad1a62ba9de0207d144d0ad8ca1bee09d33 (patch)
tree1e6bdde467f4b7f332a06282afd7db038b766ecb /posix-aio-compat.c
parent2a0620db650cc12b5a3c932152e43461ad55c5f1 (diff)
qemu-kvm: drop posix-aio-compat.cs signalfd usage
Block SIGUSR2, which makes the signal be handled through qemu-kvm.c's signalfd. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'posix-aio-compat.c')
-rw-r--r--posix-aio-compat.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index c05c77b55..a67ffe311 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -26,7 +26,6 @@
#include "osdep.h"
#include "qemu-common.h"
#include "block_int.h"
-#include "compatfd.h"
#include "block/raw-posix-aio.h"
@@ -54,7 +53,7 @@ struct qemu_paiocb {
};
typedef struct PosixAioState {
- int fd;
+ int rfd, wfd;
struct qemu_paiocb *first_aio;
} PosixAioState;
@@ -473,29 +472,18 @@ static int posix_aio_process_queue(void *opaque)
static void posix_aio_read(void *opaque)
{
PosixAioState *s = opaque;
- union {
- struct qemu_signalfd_siginfo siginfo;
- char buf[128];
- } sig;
- size_t offset;
+ ssize_t len;
- /* try to read from signalfd, don't freak out if we can't read anything */
- offset = 0;
- while (offset < 128) {
- ssize_t len;
+ /* read all bytes from signal pipe */
+ for (;;) {
+ char bytes[16];
- len = read(s->fd, sig.buf + offset, 128 - offset);
+ len = read(s->rfd, bytes, sizeof(bytes));
if (len == -1 && errno == EINTR)
- continue;
- if (len == -1 && errno == EAGAIN) {
- /* there is no natural reason for this to happen,
- * so we'll spin hard until we get everything just
- * to be on the safe side. */
- if (offset > 0)
- continue;
- }
-
- offset += len;
+ continue; /* try again */
+ if (len == sizeof(bytes))
+ continue; /* more to read */
+ break;
}
posix_aio_process_queue(s);
@@ -509,6 +497,20 @@ static int posix_aio_flush(void *opaque)
static PosixAioState *posix_aio_state;
+static void aio_signal_handler(int signum)
+{
+ if (posix_aio_state) {
+ char byte = 0;
+ ssize_t ret;
+
+ ret = write(posix_aio_state->wfd, &byte, sizeof(byte));
+ if (ret < 0 && errno != EAGAIN)
+ die("write()");
+ }
+
+ qemu_service_io();
+}
+
static void paio_remove(struct qemu_paiocb *acb)
{
struct qemu_paiocb **pacb;
@@ -610,8 +612,9 @@ BlockDriverAIOCB *paio_ioctl(BlockDriverState *bs, int fd,
int paio_init(void)
{
- sigset_t mask;
+ struct sigaction act;
PosixAioState *s;
+ int fds[2];
int ret;
if (posix_aio_state)
@@ -619,21 +622,24 @@ int paio_init(void)
s = qemu_malloc(sizeof(PosixAioState));
- /* Make sure to block AIO signal */
- sigemptyset(&mask);
- sigaddset(&mask, SIGUSR2);
- sigprocmask(SIG_BLOCK, &mask, NULL);
+ sigfillset(&act.sa_mask);
+ act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
+ act.sa_handler = aio_signal_handler;
+ sigaction(SIGUSR2, &act, NULL);
s->first_aio = NULL;
- s->fd = qemu_signalfd(&mask);
- if (s->fd == -1) {
- fprintf(stderr, "failed to create signalfd\n");
+ if (qemu_pipe(fds) == -1) {
+ fprintf(stderr, "failed to create pipe\n");
return -1;
}
- fcntl(s->fd, F_SETFL, O_NONBLOCK);
+ s->rfd = fds[0];
+ s->wfd = fds[1];
+
+ fcntl(s->rfd, F_SETFL, O_NONBLOCK);
+ fcntl(s->wfd, F_SETFL, O_NONBLOCK);
- qemu_aio_set_fd_handler(s->fd, posix_aio_read, NULL, posix_aio_flush,
+ qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush,
posix_aio_process_queue, s);
ret = pthread_attr_init(&attr);