diff mbox

[v2,6/9] blkdebug: Sanity check block layer guarantees

Message ID 1479413642-22463-7-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake Nov. 17, 2016, 8:13 p.m. UTC
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 <eblake@redhat.com>
---
 block/blkdebug.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Max Reitz Nov. 17, 2016, 10:36 p.m. UTC | #1
On 17.11.2016 21:13, Eric Blake wrote:
> 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 <eblake@redhat.com>
> ---
>  block/blkdebug.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

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 &&