[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 6/9] blkdebug: Sanity check block layer guarantee
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v2 6/9] blkdebug: Sanity check block layer guarantees |
Date: |
Thu, 17 Nov 2016 14:13:59 -0600 |
Commits 04ed95f4 and 1a62d0ac updated the block layer to auto-fragment
any I/O to fit within device boundaries. Additionally, when using a
minimum alignment of 4k, we want to ensure the block layer does proper
read-modify-write rather than requesting I/O on a slice of a sector.
Let's enforce that the contract is obeyed when using blkdebug. For
now, blkdebug only allows alignment overrides, and just inherits other
limits from whatever device it is wrapping, but a future patch will
further enhance things.
Signed-off-by: Eric Blake <address@hidden>
---
block/blkdebug.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 4127571..0a47977 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -445,6 +445,15 @@ static BlockAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
BDRVBlkdebugState *s = bs->opaque;
BlkdebugRule *rule = NULL;
+ /* Sanity check block layer guarantees */
+ assert(QEMU_IS_ALIGNED(sector_num * BDRV_SECTOR_SIZE,
+ bs->bl.request_alignment));
+ assert(QEMU_IS_ALIGNED(nb_sectors * BDRV_SECTOR_SIZE,
+ bs->bl.request_alignment));
+ if (bs->bl.max_transfer) {
+ assert(nb_sectors * BDRV_SECTOR_SIZE <= bs->bl.max_transfer);
+ }
+
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
if (rule->options.inject.sector == -1 ||
(rule->options.inject.sector >= sector_num &&
@@ -468,6 +477,15 @@ static BlockAIOCB *blkdebug_aio_writev(BlockDriverState
*bs,
BDRVBlkdebugState *s = bs->opaque;
BlkdebugRule *rule = NULL;
+ /* Sanity check block layer guarantees */
+ assert(QEMU_IS_ALIGNED(sector_num * BDRV_SECTOR_SIZE,
+ bs->bl.request_alignment));
+ assert(QEMU_IS_ALIGNED(nb_sectors * BDRV_SECTOR_SIZE,
+ bs->bl.request_alignment));
+ if (bs->bl.max_transfer) {
+ assert(nb_sectors * BDRV_SECTOR_SIZE <= bs->bl.max_transfer);
+ }
+
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
if (rule->options.inject.sector == -1 ||
(rule->options.inject.sector >= sector_num &&
--
2.7.4