From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com, Anthony Liguori <anthony@codemonkey.ws>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 2/2] qemu-kvm: drop posix-aio-compat.cs signalfd usage
Date: Mon, 06 Sep 2010 17:20:17 -0300 [thread overview]
Message-ID: <20100906202301.361862359@amt.cnet> (raw)
In-Reply-To: 20100906202015.433641568@amt.cnet
[-- Attachment #1: posix-aio-compat-use-signal --]
[-- Type: text/plain, Size: 3996 bytes --]
Block SIGUSR2, which makes the signal be handled through qemu-kvm.c's
signalfd.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/posix-aio-compat.c
===================================================================
--- qemu-kvm.orig/posix-aio-compat.c
+++ qemu-kvm/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
static void posix_aio_read(void *opaque)
{
PosixAioState *s = opaque;
- union {
- struct qemu_signalfd_siginfo siginfo;
- char buf[128];
- } sig;
- size_t offset;
-
- /* try to read from signalfd, don't freak out if we can't read anything */
- offset = 0;
- while (offset < 128) {
- ssize_t len;
+ ssize_t len;
- len = read(s->fd, sig.buf + offset, 128 - offset);
- 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;
- }
+ /* read all bytes from signal pipe */
+ for (;;) {
+ char bytes[16];
- offset += len;
+ len = read(s->rfd, bytes, sizeof(bytes));
+ if (len == -1 && errno == EINTR)
+ 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(BlockDriver
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);
Index: qemu-kvm/qemu-kvm.c
===================================================================
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -1680,6 +1680,7 @@ int kvm_main_loop(void)
sigemptyset(&mask);
sigaddset(&mask, SIGIO);
sigaddset(&mask, SIGALRM);
+ sigaddset(&mask, SIGUSR2);
sigaddset(&mask, SIGBUS);
sigprocmask(SIG_BLOCK, &mask, NULL);
prev parent reply other threads:[~2010-09-06 20:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-06 20:20 [patch 0/2] qemu-kvm cleanups Marcelo Tosatti
2010-09-06 20:20 ` [patch 1/2] qemu-kvm: use usptream eventfd code Marcelo Tosatti
2010-09-07 8:21 ` Avi Kivity
2010-09-07 17:25 ` Marcelo Tosatti
2010-09-08 8:25 ` Avi Kivity
2010-09-06 20:20 ` Marcelo Tosatti [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100906202301.361862359@amt.cnet \
--to=mtosatti@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.