Commit 2c41a5f9e355412bdab3d92329ae5637bbdb08f1
1 parent
da3d9c5b
Make sure to read siginfo from signalfd
Otherwise, we'll idle at 100% cpu. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5195 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
27 additions
and
0 deletions
block-raw-posix.c
... | ... | @@ -449,6 +449,30 @@ static void qemu_aio_poll(void *opaque) |
449 | 449 | { |
450 | 450 | RawAIOCB *acb, **pacb; |
451 | 451 | int ret; |
452 | + size_t offset; | |
453 | + union { | |
454 | + struct qemu_signalfd_siginfo siginfo; | |
455 | + char buf[128]; | |
456 | + } sig; | |
457 | + | |
458 | + /* try to read from signalfd, don't freak out if we can't read anything */ | |
459 | + offset = 0; | |
460 | + while (offset < 128) { | |
461 | + ssize_t len; | |
462 | + | |
463 | + len = read(aio_sig_fd, sig.buf + offset, 128 - offset); | |
464 | + if (len == -1 && errno == EINTR) | |
465 | + continue; | |
466 | + if (len == -1 && errno == EAGAIN) { | |
467 | + /* there is no natural reason for this to happen, | |
468 | + * so we'll spin hard until we get everything just | |
469 | + * to be on the safe side. */ | |
470 | + if (offset > 0) | |
471 | + continue; | |
472 | + } | |
473 | + | |
474 | + offset += len; | |
475 | + } | |
452 | 476 | |
453 | 477 | for(;;) { |
454 | 478 | pacb = &first_aio; |
... | ... | @@ -498,6 +522,9 @@ void qemu_aio_init(void) |
498 | 522 | sigprocmask(SIG_BLOCK, &mask, NULL); |
499 | 523 | |
500 | 524 | aio_sig_fd = qemu_signalfd(&mask); |
525 | + | |
526 | + fcntl(aio_sig_fd, F_SETFL, O_NONBLOCK); | |
527 | + | |
501 | 528 | #if !defined(QEMU_IMG) && !defined(QEMU_NBD) |
502 | 529 | qemu_set_fd_handler2(aio_sig_fd, NULL, qemu_aio_poll, NULL, NULL); |
503 | 530 | #endif | ... | ... |