diff options
author | Eric Blake <eblake@redhat.com> | 2016-07-15 17:22:51 -0600 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2016-07-20 14:11:55 +0100 |
commit | 0c51a893b643bc9393c685b47b9cea1e6831565f (patch) | |
tree | 9636a6178fd16b1efadc97009c5b600a5d589303 /block/io.c | |
parent | 9f1963b3f72521f75a549f8afd61b19e7da63c6f (diff) |
block: Convert bdrv_discard() to byte-based
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 <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1468624988-423-3-git-send-email-eblake@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/io.c')
-rw-r--r-- | block/io.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/block/io.c b/block/io.c index 14d448d50c..8d413058be 100644 --- a/block/io.c +++ b/block/io.c @@ -2391,16 +2391,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, @@ -2495,23 +2494,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, &rwco); + co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco); qemu_coroutine_enter(co); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); |