Commit 22bf14582af9e25e31b926fab23c9be2d4a0298f

Authored by aliguori
1 parent c1c0438c

fix raw_aio_read\write error handling (Stefano Stabellini)

Currently when qemu_paio_read or qemu_paio_write return an error we call
qemu_aio_release without removing the request from the list.
I know that in the current implementation qemu_paio_write\read don't return
any error, but still the behavior is wrong, especially considering
that the implementation of these two functions is likely to change in is
the future.
This patch fixes the problem adding a raw_aio_remove function that
removes the callback from the queue and also calls qemu_aio_release.
raw_aio_remove is called by raw_aio_read, raw_aio_write and
raw_aio_cancel.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6470 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 21 additions and 15 deletions
block-raw-posix.c
... ... @@ -598,6 +598,24 @@ static void raw_aio_em_cb(void* opaque)
598 598 qemu_aio_release(acb);
599 599 }
600 600  
  601 +static void raw_aio_remove(RawAIOCB *acb)
  602 +{
  603 + RawAIOCB **pacb;
  604 +
  605 + /* remove the callback from the queue */
  606 + pacb = &posix_aio_state->first_aio;
  607 + for(;;) {
  608 + if (*pacb == NULL) {
  609 + break;
  610 + } else if (*pacb == acb) {
  611 + *pacb = acb->next;
  612 + qemu_aio_release(acb);
  613 + break;
  614 + }
  615 + pacb = &acb->next;
  616 + }
  617 +}
  618 +
601 619 static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs,
602 620 int64_t sector_num, uint8_t *buf, int nb_sectors,
603 621 BlockDriverCompletionFunc *cb, void *opaque)
... ... @@ -623,7 +641,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs,
623 641 if (!acb)
624 642 return NULL;
625 643 if (qemu_paio_read(&acb->aiocb) < 0) {
626   - qemu_aio_release(acb);
  644 + raw_aio_remove(acb);
627 645 return NULL;
628 646 }
629 647 return &acb->common;
... ... @@ -654,7 +672,7 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs,
654 672 if (!acb)
655 673 return NULL;
656 674 if (qemu_paio_write(&acb->aiocb) < 0) {
657   - qemu_aio_release(acb);
  675 + raw_aio_remove(acb);
658 676 return NULL;
659 677 }
660 678 return &acb->common;
... ... @@ -664,7 +682,6 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
664 682 {
665 683 int ret;
666 684 RawAIOCB *acb = (RawAIOCB *)blockacb;
667   - RawAIOCB **pacb;
668 685  
669 686 ret = qemu_paio_cancel(acb->aiocb.aio_fildes, &acb->aiocb);
670 687 if (ret == QEMU_PAIO_NOTCANCELED) {
... ... @@ -673,18 +690,7 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb)
673 690 while (qemu_paio_error(&acb->aiocb) == EINPROGRESS);
674 691 }
675 692  
676   - /* remove the callback from the queue */
677   - pacb = &posix_aio_state->first_aio;
678   - for(;;) {
679   - if (*pacb == NULL) {
680   - break;
681   - } else if (*pacb == acb) {
682   - *pacb = acb->next;
683   - qemu_aio_release(acb);
684   - break;
685   - }
686   - pacb = &acb->next;
687   - }
  693 + raw_aio_remove(acb);
688 694 }
689 695 #else /* CONFIG_AIO */
690 696 static int posix_aio_init(void)
... ...