From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFkRA-0002K8-RU for qemu-devel@nongnu.org; Wed, 22 Jun 2016 11:51:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFkR5-00029p-K7 for qemu-devel@nongnu.org; Wed, 22 Jun 2016 11:51:32 -0400 From: Eric Blake Date: Wed, 22 Jun 2016 09:50:59 -0600 Message-Id: <1466610674-23157-3-git-send-email-eblake@redhat.com> In-Reply-To: <1466610674-23157-1-git-send-email-eblake@redhat.com> References: <1466610674-23157-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH 02/17] block: Convert bdrv_discard() to byte-based 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, Max Reitz , Stefan Hajnoczi , Fam Zheng Another step towards byte-based interfaces everywhere. Replace the sector-based bdrv_discard() with a new byte-based bdrv_pdiscard(), which silently ignores any unaligned head or tail. Signed-off-by: Eric Blake --- include/block/block.h | 2 +- block/block-backend.c | 3 ++- block/io.c | 19 +++++++++---------- block/qcow2-refcount.c | 4 +--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index b8df2fb..a93bf11 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -344,7 +344,7 @@ void bdrv_drain(BlockDriverState *bs); void coroutine_fn bdrv_co_drain(BlockDriverState *bs); void bdrv_drain_all(void); -int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); +int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count); int bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, int count); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); diff --git a/block/block-backend.c b/block/block-backend.c index f44e7e6..f56c573 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1506,7 +1506,8 @@ int blk_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors) return ret; } - return bdrv_discard(blk_bs(blk), sector_num, nb_sectors); + return bdrv_pdiscard(blk_bs(blk), sector_num << BDRV_SECTOR_BITS, + nb_sectors << BDRV_SECTOR_BITS); } int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, diff --git a/block/io.c b/block/io.c index 22869b8..305e5c5 100644 --- a/block/io.c +++ b/block/io.c @@ -2360,16 +2360,15 @@ int bdrv_flush(BlockDriverState *bs) typedef struct DiscardCo { BlockDriverState *bs; - int64_t sector_num; - int nb_sectors; + int64_t offset; + int count; int ret; } DiscardCo; -static void coroutine_fn bdrv_discard_co_entry(void *opaque) +static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) { DiscardCo *rwco = opaque; - rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->sector_num << BDRV_SECTOR_BITS, - rwco->nb_sectors << BDRV_SECTOR_BITS); + rwco->ret = bdrv_co_pdiscard(rwco->bs, rwco->offset, rwco->count); } int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, @@ -2463,23 +2462,23 @@ out: return ret; } -int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) +int bdrv_pdiscard(BlockDriverState *bs, int64_t offset, int count) { Coroutine *co; DiscardCo rwco = { .bs = bs, - .sector_num = sector_num, - .nb_sectors = nb_sectors, + .offset = offset, + .count = count, .ret = NOT_DONE, }; if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ - bdrv_discard_co_entry(&rwco); + bdrv_pdiscard_co_entry(&rwco); } else { AioContext *aio_context = bdrv_get_aio_context(bs); - co = qemu_coroutine_create(bdrv_discard_co_entry); + co = qemu_coroutine_create(bdrv_pdiscard_co_entry); qemu_coroutine_enter(co, &rwco); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3bef410..b35f2f4 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -615,9 +615,7 @@ void qcow2_process_discards(BlockDriverState *bs, int ret) /* Discard is optional, ignore the return value */ if (ret >= 0) { - bdrv_discard(bs->file->bs, - d->offset >> BDRV_SECTOR_BITS, - d->bytes >> BDRV_SECTOR_BITS); + bdrv_pdiscard(bs->file->bs, d->offset, d->bytes); } g_free(d); -- 2.5.5