From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bOCS3-0003eN-Kk for qemu-devel@nongnu.org; Fri, 15 Jul 2016 19:23:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bOCS2-0004HQ-0g for qemu-devel@nongnu.org; Fri, 15 Jul 2016 19:23:23 -0400 From: Eric Blake Date: Fri, 15 Jul 2016 17:22:58 -0600 Message-Id: <1468624988-423-10-git-send-email-eblake@redhat.com> In-Reply-To: <1468624988-423-1-git-send-email-eblake@redhat.com> References: <1468624988-423-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v2 09/19] block: Add .bdrv_co_pdiscard() driver callback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, pbonzini@redhat.com, kwolf@redhat.com, stefanha@redhat.com, Fam Zheng , Max Reitz There's enough drivers with a sector-based callback that it will be easier to switch one at a time. This patch adds a byte-based callback, and then after all drivers are swapped, we'll drop the sector-based callback. [checkpatch doesn't like the space after coroutine_fn in block_int.h, but it's consistent with the rest of the file] Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 2 ++ block/io.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 0cbe250..b4d4cd2 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -167,6 +167,8 @@ struct BlockDriver { int64_t offset, int count, BdrvRequestFlags flags); int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); + int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, + int64_t offset, int count); int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file); diff --git a/block/io.c b/block/io.c index 40d8444..ee87fbf 100644 --- a/block/io.c +++ b/block/io.c @@ -2403,7 +2403,8 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, return 0; } - if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_pdiscard) { + if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_co_pdiscard && + !bs->drv->bdrv_aio_pdiscard) { return 0; } @@ -2435,7 +2436,9 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int ret; int num = MIN(count, max_pdiscard); - if (bs->drv->bdrv_co_discard) { + if (bs->drv->bdrv_co_pdiscard) { + ret = bs->drv->bdrv_co_pdiscard(bs, offset, num); + } else if (bs->drv->bdrv_co_discard) { ret = bs->drv->bdrv_co_discard(bs, offset >> BDRV_SECTOR_BITS, num >> BDRV_SECTOR_BITS); } else { -- 2.5.5