Commit e20e830bbdc502986d6fd30c26b06c37a5ee0611

Authored by aliguori
1 parent 984b5181

block: make raw aio signaling non-blocking (Gerd Hoffman)

This patch switches the read handle of the signaling pipe into
non-blocking mode.  This avoids unwanted blocking reads and also
allows to read all bytes out of the signaling pipe in case we got
signaled more that once before the handler ran.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5716 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 10 additions and 7 deletions
block-raw-posix.c
... ... @@ -497,15 +497,17 @@ static void posix_aio_read(void *opaque)
497 497 int ret;
498 498 ssize_t len;
499 499  
500   - do {
501   - char byte;
  500 + /* read all bytes from signal pipe */
  501 + for (;;) {
  502 + char bytes[16];
502 503  
503   - len = read(s->rfd, &byte, 1);
  504 + len = read(s->rfd, bytes, sizeof(bytes));
504 505 if (len == -1 && errno == EINTR)
505   - continue;
506   - if (len == -1 && errno == EAGAIN)
507   - break;
508   - } while (len == -1);
  506 + continue; /* try again */
  507 + if (len == sizeof(bytes))
  508 + continue; /* more to read */
  509 + break;
  510 + }
509 511  
510 512 for(;;) {
511 513 pacb = &s->first_aio;
... ... @@ -591,6 +593,7 @@ static int posix_aio_init(void)
591 593 s->rfd = fds[0];
592 594 s->wfd = fds[1];
593 595  
  596 + fcntl(s->rfd, F_SETFL, O_NONBLOCK);
594 597 fcntl(s->wfd, F_SETFL, O_NONBLOCK);
595 598  
596 599 qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, s);
... ...