[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 31/41] block: add request tracking
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 31/41] block: add request tracking |
Date: |
Mon, 5 Dec 2011 15:21:08 +0100 |
From: Stefan Hajnoczi <address@hidden>
The block layer does not know about pending requests. This information
is necessary for copy-on-read since overlapping requests must be
serialized to prevent races that corrupt the image.
The BlockDriverState gets a new tracked_request list field which
contains all pending requests. Each request is a BdrvTrackedRequest
record with sector_num, nb_sectors, and is_write fields.
Note that request tracking is always enabled but hopefully this extra
work is so small that it doesn't justify adding an enable/disable flag.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
block_int.h | 4 ++++
2 files changed, 51 insertions(+), 1 deletions(-)
diff --git a/block.c b/block.c
index d82854a..1643667 100644
--- a/block.c
+++ b/block.c
@@ -1071,6 +1071,42 @@ void bdrv_commit_all(void)
}
}
+struct BdrvTrackedRequest {
+ BlockDriverState *bs;
+ int64_t sector_num;
+ int nb_sectors;
+ bool is_write;
+ QLIST_ENTRY(BdrvTrackedRequest) list;
+};
+
+/**
+ * Remove an active request from the tracked requests list
+ *
+ * This function should be called when a tracked request is completing.
+ */
+static void tracked_request_end(BdrvTrackedRequest *req)
+{
+ QLIST_REMOVE(req, list);
+}
+
+/**
+ * Add an active request to the tracked requests list
+ */
+static void tracked_request_begin(BdrvTrackedRequest *req,
+ BlockDriverState *bs,
+ int64_t sector_num,
+ int nb_sectors, bool is_write)
+{
+ *req = (BdrvTrackedRequest){
+ .bs = bs,
+ .sector_num = sector_num,
+ .nb_sectors = nb_sectors,
+ .is_write = is_write,
+ };
+
+ QLIST_INSERT_HEAD(&bs->tracked_requests, req, list);
+}
+
/*
* Return values:
* 0 - success
@@ -1350,6 +1386,8 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState
*bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
{
BlockDriver *drv = bs->drv;
+ BdrvTrackedRequest req;
+ int ret;
if (!drv) {
return -ENOMEDIUM;
@@ -1363,7 +1401,10 @@ static int coroutine_fn
bdrv_co_do_readv(BlockDriverState *bs,
bdrv_io_limits_intercept(bs, false, nb_sectors);
}
- return drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+ tracked_request_begin(&req, bs, sector_num, nb_sectors, false);
+ ret = drv->bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+ tracked_request_end(&req);
+ return ret;
}
int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
@@ -1381,6 +1422,7 @@ static int coroutine_fn
bdrv_co_do_writev(BlockDriverState *bs,
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
{
BlockDriver *drv = bs->drv;
+ BdrvTrackedRequest req;
int ret;
if (!bs->drv) {
@@ -1398,6 +1440,8 @@ static int coroutine_fn
bdrv_co_do_writev(BlockDriverState *bs,
bdrv_io_limits_intercept(bs, true, nb_sectors);
}
+ tracked_request_begin(&req, bs, sector_num, nb_sectors, true);
+
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
if (bs->dirty_bitmap) {
@@ -1408,6 +1452,8 @@ static int coroutine_fn
bdrv_co_do_writev(BlockDriverState *bs,
bs->wr_highest_sector = sector_num + nb_sectors - 1;
}
+ tracked_request_end(&req);
+
return ret;
}
diff --git a/block_int.h b/block_int.h
index a0b46d7..ea818e4 100644
--- a/block_int.h
+++ b/block_int.h
@@ -51,6 +51,8 @@
#define BLOCK_OPT_PREALLOC "preallocation"
#define BLOCK_OPT_SUBFMT "subformat"
+typedef struct BdrvTrackedRequest BdrvTrackedRequest;
+
typedef struct AIOPool {
void (*cancel)(BlockDriverAIOCB *acb);
int aiocb_size;
@@ -255,6 +257,8 @@ struct BlockDriverState {
int in_use; /* users other than guest access, eg. block migration */
QTAILQ_ENTRY(BlockDriverState) list;
void *private;
+
+ QLIST_HEAD(, BdrvTrackedRequest) tracked_requests;
};
struct BlockDriverAIOCB {
--
1.7.6.4
- [Qemu-devel] [PATCH 17/41] qcow2: Fix order of refcount updates in qcow2_snapshot_goto, (continued)
- [Qemu-devel] [PATCH 17/41] qcow2: Fix order of refcount updates in qcow2_snapshot_goto, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 22/41] qed: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 26/41] cow: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 27/41] block: drop .bdrv_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 24/41] vvfat: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 20/41] block: use public bdrv_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 23/41] block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 21/41] block: add .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 25/41] vdi: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 29/41] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 31/41] block: add request tracking,
Kevin Wolf <=
- [Qemu-devel] [PATCH 30/41] coroutine: add qemu_co_queue_restart_all(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 28/41] block: add bdrv_co_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 32/41] block: add interface to toggle copy-on-read, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 39/41] block: implement bdrv_co_is_allocated() boundary cases, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 37/41] cow: use bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 35/41] block: core copy-on-read logic, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 36/41] block: add -drive copy-on-read=on|off, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 34/41] block: request overlap detection, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 40/41] block: wait_for_overlapping_requests() deadlock detection, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 41/41] block: convert qemu_aio_flush() calls to bdrv_drain_all(), Kevin Wolf, 2011/12/05