From a8c71d4d7eb67c9d50607a5c98c7d3ef2522c478 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Paolo Bonzini Date: Fri, 6 Sep 2013 18:12:37 +0200 Subject: [PATCH 17/25] block: introduce bdrv_get_block_status API For now, bdrv_get_block_status is just another name for bdrv_is_allocated. The next patches will add more flags. This also touches all block drivers with a mostly mechanical rename. The sole exception is cow; because it calls cow_co_is_allocated from the read code, we keep that function and make cow_co_get_block_status a wrapper. Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi (cherry picked from commit b6b8a33354a448ee421f57676c1a93a536a63269) Signed-off-by: Michal Novotny --- block.c | 46 ++++++++++++++++++++++++++-------------------- block.h | 2 ++ block/cow.c | 8 +++++++- block/qcow.c | 4 ++-- block/qcow2.c | 4 ++-- block/qed.c | 4 ++-- block/raw.c | 6 +++--- block/vdi.c | 4 ++-- block/vmdk.c | 4 ++-- block/vvfat.c | 4 ++-- block_int.h | 2 +- 11 files changed, 51 insertions(+), 37 deletions(-) diff --git a/block.c b/block.c index 22de930..367f622 100644 --- a/block.c +++ b/block.c @@ -2720,14 +2720,14 @@ int bdrv_has_zero_init(BlockDriverState *bs) return 1; } -typedef struct BdrvCoIsAllocatedData { +typedef struct BdrvCoGetBlockStatusData { BlockDriverState *bs; int64_t sector_num; int nb_sectors; int *pnum; - int ret; + int64_t ret; bool done; -} BdrvCoIsAllocatedData; +} BdrvCoGetBlockStatusData; /* * Returns true iff the specified sector is present in the disk image. Drivers @@ -2744,9 +2744,9 @@ typedef struct BdrvCoIsAllocatedData { * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes * beyond the end of the disk image it will be clamped. */ -static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum) +static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, int *pnum) { int64_t length; int64_t n; @@ -2766,35 +2766,35 @@ static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, nb_sectors = n; } - if (!bs->drv->bdrv_co_is_allocated) { + if (!bs->drv->bdrv_co_get_block_status) { *pnum = nb_sectors; return 1; } - return bs->drv->bdrv_co_is_allocated(bs, sector_num, nb_sectors, pnum); + return bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum); } -/* Coroutine wrapper for bdrv_is_allocated() */ -static void coroutine_fn bdrv_is_allocated_co_entry(void *opaque) +/* Coroutine wrapper for bdrv_get_block_status() */ +static void coroutine_fn bdrv_get_block_status_co_entry(void *opaque) { - BdrvCoIsAllocatedData *data = opaque; + BdrvCoGetBlockStatusData *data = opaque; BlockDriverState *bs = data->bs; - data->ret = bdrv_co_is_allocated(bs, data->sector_num, data->nb_sectors, - data->pnum); + data->ret = bdrv_co_get_block_status(bs, data->sector_num, data->nb_sectors, + data->pnum); data->done = true; } /* - * Synchronous wrapper around bdrv_co_is_allocated(). + * Synchronous wrapper around bdrv_co_get_block_status(). * - * See bdrv_co_is_allocated() for details. + * See bdrv_co_get_block_status() for details. */ -int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, - int *pnum) +int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum) { Coroutine *co; - BdrvCoIsAllocatedData data = { + BdrvCoGetBlockStatusData data = { .bs = bs, .sector_num = sector_num, .nb_sectors = nb_sectors, @@ -2804,9 +2804,9 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ - bdrv_is_allocated_co_entry(&data); + bdrv_get_block_status_co_entry(&data); } else { - co = qemu_coroutine_create(bdrv_is_allocated_co_entry); + co = qemu_coroutine_create(bdrv_get_block_status_co_entry); qemu_coroutine_enter(co, &data); while (!data.done) { qemu_aio_wait(); @@ -2815,6 +2815,12 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, return data.ret; } +int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum) +{ + return bdrv_get_block_status(bs, sector_num, nb_sectors, pnum); +} + /* * Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP] * diff --git a/block.h b/block.h index 741a54a..65c0024 100644 --- a/block.h +++ b/block.h @@ -282,6 +282,8 @@ void bdrv_drain_all(void); int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); int bdrv_has_zero_init(BlockDriverState *bs); +int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum); int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); diff --git a/block/cow.c b/block/cow.c index d5cac88..39032cb 100644 --- a/block/cow.c +++ b/block/cow.c @@ -188,6 +188,12 @@ static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs, return changed; } +static int64_t coroutine_fn cow_co_get_block_status(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *num_same) +{ + return cow_co_is_allocated(bs, sector_num, nb_sectors, num_same); +} + static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { @@ -376,7 +382,7 @@ static BlockDriver bdrv_cow = { .bdrv_close = cow_close, .bdrv_create = cow_create, .bdrv_co_flush = cow_co_flush, - .bdrv_co_is_allocated = cow_co_is_allocated, + .bdrv_co_get_block_status = cow_co_get_block_status, .create_options = cow_create_options, }; diff --git a/block/qcow.c b/block/qcow.c index 9b6b548..6df355c 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -386,7 +386,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, return cluster_offset; } -static int coroutine_fn qcow_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { BDRVQcowState *s = bs->opaque; @@ -946,7 +946,7 @@ static BlockDriver bdrv_qcow = { .bdrv_close = qcow_close, .bdrv_reopen_prepare = qcow_reopen_prepare, .bdrv_create = qcow_create, - .bdrv_co_is_allocated = qcow_co_is_allocated, + .bdrv_co_get_block_status = qcow_co_get_block_status, .bdrv_set_key = qcow_set_key, .bdrv_make_empty = qcow_make_empty, .bdrv_co_readv = qcow_co_readv, diff --git a/block/qcow2.c b/block/qcow2.c index d102440..8a185c5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -377,7 +377,7 @@ static int qcow2_reopen_prepare(BDRVReopenState *state, return 0; } -static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { BDRVQcowState *s = bs->opaque; @@ -1354,7 +1354,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_close = qcow2_close, .bdrv_reopen_prepare = qcow2_reopen_prepare, .bdrv_create = qcow2_create, - .bdrv_co_is_allocated = qcow2_co_is_allocated, + .bdrv_co_get_block_status = qcow2_co_get_block_status, .bdrv_set_key = qcow2_set_key, .bdrv_make_empty = qcow2_make_empty, diff --git a/block/qed.c b/block/qed.c index 5d96be9..2ca2bfe 100644 --- a/block/qed.c +++ b/block/qed.c @@ -670,7 +670,7 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l } } -static int coroutine_fn bdrv_qed_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { @@ -1578,7 +1578,7 @@ static BlockDriver bdrv_qed = { .bdrv_close = bdrv_qed_close, .bdrv_reopen_prepare = bdrv_qed_reopen_prepare, .bdrv_create = bdrv_qed_create, - .bdrv_co_is_allocated = bdrv_qed_co_is_allocated, + .bdrv_co_get_block_status = bdrv_qed_co_get_block_status, .bdrv_make_empty = bdrv_qed_make_empty, .bdrv_aio_readv = bdrv_qed_aio_readv, .bdrv_aio_writev = bdrv_qed_aio_writev, diff --git a/block/raw.c b/block/raw.c index def65e2..40279d0 100644 --- a/block/raw.c +++ b/block/raw.c @@ -38,11 +38,11 @@ static int coroutine_fn raw_co_flush(BlockDriverState *bs) return bdrv_co_flush(bs->file); } -static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { - return bdrv_is_allocated(bs->file, sector_num, nb_sectors, pnum); + return bdrv_get_block_status(bs->file, sector_num, nb_sectors, pnum); } static int64_t raw_getlength(BlockDriverState *bs) @@ -130,7 +130,7 @@ static BlockDriver bdrv_raw = { .bdrv_co_readv = raw_co_readv, .bdrv_co_writev = raw_co_writev, .bdrv_co_flush = raw_co_flush, - .bdrv_co_is_allocated = raw_co_is_allocated, + .bdrv_co_get_block_status = raw_co_get_block_status, .bdrv_co_discard = raw_co_discard, .bdrv_probe = raw_probe, diff --git a/block/vdi.c b/block/vdi.c index 9f07f7d..ada5baf 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -454,7 +454,7 @@ static int vdi_reopen_prepare(BDRVReopenState *state, return 0; } -static int coroutine_fn vdi_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { /* TODO: Check for too large sector_num (in bdrv_is_allocated or here). */ @@ -932,7 +932,7 @@ static BlockDriver bdrv_vdi = { .bdrv_reopen_prepare = vdi_reopen_prepare, .bdrv_create = vdi_create, .bdrv_co_flush = vdi_co_flush, - .bdrv_co_is_allocated = vdi_co_is_allocated, + .bdrv_co_get_block_status = vdi_co_get_block_status, .bdrv_make_empty = vdi_make_empty, .bdrv_aio_readv = vdi_aio_readv, diff --git a/block/vmdk.c b/block/vmdk.c index 92eaeb2..0f4b09e 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1033,7 +1033,7 @@ static VmdkExtent *find_extent(BDRVVmdkState *s, return NULL; } -static int coroutine_fn vmdk_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { BDRVVmdkState *s = bs->opaque; @@ -1809,7 +1809,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_close = vmdk_close, .bdrv_create = vmdk_create, .bdrv_co_flush = vmdk_co_flush, - .bdrv_co_is_allocated = vmdk_co_is_allocated, + .bdrv_co_get_block_status = vmdk_co_get_block_status, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, .create_options = vmdk_create_options, diff --git a/block/vvfat.c b/block/vvfat.c index f3abd1b..4e9fbfc 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2768,7 +2768,7 @@ static coroutine_fn int vvfat_co_write(BlockDriverState *bs, int64_t sector_num, return ret; } -static int coroutine_fn vvfat_co_is_allocated(BlockDriverState *bs, +static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int* n) { BDRVVVFATState* s = bs->opaque; @@ -2865,7 +2865,7 @@ static BlockDriver bdrv_vvfat = { .bdrv_read = vvfat_co_read, .bdrv_write = vvfat_co_write, .bdrv_close = vvfat_close, - .bdrv_co_is_allocated = vvfat_co_is_allocated, + .bdrv_co_get_block_status = vvfat_co_get_block_status, .protocol_name = "fat", }; diff --git a/block_int.h b/block_int.h index 610ea66..9fab23d 100644 --- a/block_int.h +++ b/block_int.h @@ -171,7 +171,7 @@ struct BlockDriver { int64_t sector_num, int nb_sectors); int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs, int64_t sector_num, int nb_sectors); - int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs, + int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs, -- 1.7.11.7