[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 22/23] block: Fix early failure in multiwrite
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 22/23] block: Fix early failure in multiwrite |
Date: |
Fri, 2 Jul 2010 18:38:31 +0200 |
bdrv_aio_writev may call the callback immediately (and it will commonly do so
in error cases). Current code doesn't consider this. For details see the
comment added by this patch.
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 35 +++++++++++++++++++++++++++++------
1 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 9176dec..e65971c 100644
--- a/block.c
+++ b/block.c
@@ -2183,8 +2183,29 @@ int bdrv_aio_multiwrite(BlockDriverState *bs,
BlockRequest *reqs, int num_reqs)
// Check for mergable requests
num_reqs = multiwrite_merge(bs, reqs, num_reqs, mcb);
- // Run the aio requests
+ /*
+ * Run the aio requests. As soon as one request can't be submitted
+ * successfully, fail all requests that are not yet submitted (we must
+ * return failure for all requests anyway)
+ *
+ * num_requests cannot be set to the right value immediately: If
+ * bdrv_aio_writev fails for some request, num_requests would be too high
+ * and therefore multiwrite_cb() would never recognize the multiwrite
+ * request as completed. We also cannot use the loop variable i to set it
+ * when the first request fails because the callback may already have been
+ * called for previously submitted requests. Thus, num_requests must be
+ * incremented for each request that is submitted.
+ *
+ * The problem that callbacks may be called early also means that we need
+ * to take care that num_requests doesn't become 0 before all requests are
+ * submitted - multiwrite_cb() would consider the multiwrite request
+ * completed. A dummy request that is "completed" by a manual call to
+ * multiwrite_cb() takes care of this.
+ */
+ mcb->num_requests = 1;
+
for (i = 0; i < num_reqs; i++) {
+ mcb->num_requests++;
acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov,
reqs[i].nb_sectors, multiwrite_cb, mcb);
@@ -2192,22 +2213,24 @@ int bdrv_aio_multiwrite(BlockDriverState *bs,
BlockRequest *reqs, int num_reqs)
// We can only fail the whole thing if no request has been
// submitted yet. Otherwise we'll wait for the submitted AIOs to
// complete and report the error in the callback.
- if (mcb->num_requests == 0) {
- reqs[i].error = -EIO;
+ if (i == 0) {
goto fail;
} else {
- mcb->num_requests++;
multiwrite_cb(mcb, -EIO);
break;
}
- } else {
- mcb->num_requests++;
}
}
+ /* Complete the dummy request */
+ multiwrite_cb(mcb, 0);
+
return 0;
fail:
+ for (i = 0; i < mcb->num_callbacks; i++) {
+ reqs[i].error = -EIO;
+ }
qemu_free(mcb);
return -1;
}
--
1.6.6.1
- [Qemu-devel] [PULL 00/23] Block patches, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 01/23] qcow2: Fix error handling during metadata preallocation, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 02/23] block: allow filenames with colons again for host devices, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 03/23] scsi: scsi_bus_legacy_handle_cmdline() can fail, fix callers, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 06/23] Don't reset bs->is_temporary in bdrv_open_common, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 10/23] blockdev: drive_get_by_id() is no longer used, remove, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 11/23] block: Catch attempt to attach multiple devices to a blockdev, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 19/23] ide: Make PIIX and ISA IDE init functions return the qdev, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 20/23] pc: Fix CMOS info for drives defined with -device, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 22/23] block: Fix early failure in multiwrite,
Kevin Wolf <=
- [Qemu-devel] [PATCH 23/23] block: Handle multiwrite errors only when all requests have completed, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 21/23] qemu-img: avoid calling exit(1) to release resources properly, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 15/23] blkdebug: Initialize state as 1, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 09/23] qdev: Decouple qdev_prop_drive from DriveInfo, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 07/23] blockdev: New drive_get_by_blockdev(), Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 08/23] blockdev: Clean up automatic drive deletion, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 17/23] block: Clean up bdrv_snapshots(), Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 18/23] block: Fix virtual media change for if=none, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 16/23] savevm: Survive hot-unplug of snapshot device, Kevin Wolf, 2010/07/02
- [Qemu-devel] [PATCH 04/23] ide: Make it explicit that ide_create_drive() can't fail, Kevin Wolf, 2010/07/02