Signed-off-by: Lin Ma <l...@suse.com> --- block/block-backend.c | 38 ++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 40 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c index 6936b25c83..6d08dd5e0d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1650,6 +1650,44 @@ int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes) return blk_prw(blk, offset, NULL, bytes, blk_pdiscard_entry, 0); } +static int coroutine_fn +blk_do_get_lba_status(BlockBackend *blk, int64_t offset, int bytes, + uint32_t *num_blocks, uint32_t *is_deallocated) +{ + int ret; + + blk_wait_while_drained(blk); + + ret = blk_check_byte_request(blk, offset, bytes); + if (ret < 0) { + return ret; + } + + return bdrv_co_get_lba_status(blk->root, offset, bytes, num_blocks, + is_deallocated); +} + +static void blk_aio_get_lba_status_entry(void *opaque) +{ + BlkAioEmAIOCB *acb = opaque; + BlkRwCo *rwco = &acb->rwco; + + void *data = acb->common.opaque; + uint32_t *num_blocks = (uint32_t *)data; + uint32_t *is_deallocated = (uint32_t *)(data + sizeof(uint32_t)); + + rwco->ret = blk_do_get_lba_status(rwco->blk, rwco->offset, acb->bytes, + num_blocks, is_deallocated); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_get_lba_status(BlockBackend *blk, int64_t offset, int bytes, + BlockCompletionFunc *cb, void *opaque) +{ + return blk_aio_prwv(blk, offset, bytes, NULL, blk_aio_get_lba_status_entry, + 0, cb, opaque); +} + /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_do_flush(BlockBackend *blk) { diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8203d7f6f9..cd527ec0c9 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -171,6 +171,8 @@ BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_get_lba_status(BlockBackend *blk, int64_t offset, int bytes, + BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel(BlockAIOCB *acb); void blk_aio_cancel_async(BlockAIOCB *acb); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); -- 2.26.0