From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7T4d-00072X-AZ for qemu-devel@nongnu.org; Thu, 17 Nov 2016 15:14:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7T4c-0003nY-7A for qemu-devel@nongnu.org; Thu, 17 Nov 2016 15:14:19 -0500 From: Eric Blake Date: Thu, 17 Nov 2016 14:13:59 -0600 Message-Id: <1479413642-22463-7-git-send-email-eblake@redhat.com> In-Reply-To: <1479413642-22463-1-git-send-email-eblake@redhat.com> References: <1479413642-22463-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v2 6/9] blkdebug: Sanity check block layer guarantees List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com, Max Reitz 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 --- 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