qemu-img check: unallocated size
cover qemu-img check: unallocated size
Hi all!
These small series is about "Format unallocated size" section for qemu-img check. It is needed to know, how many holes we have in qcow2, when underlying raw file is on non-sparse file-system. In this case actual-size from qemu-img info will not take holes into account. Also, qemu-img check 'allocated' stat is not appropriate too, as it is about guest clusters, so metadata and snapshots are not accounted.
Qemu-img check is chosen instead of qemu-img info, to not slow down qemu-img info by loading all L2 tables (Kevin)
Vladimir Sementsov-Ogievskiy (7):
block: fix comment for bdrv_get_allocated_file_size()
block: add bdrv_get_format_allocated_size format interface
qcow2: add .bdrv_get_format_allocated_size
common: make get_human_readable_size public
qemu-img check: add format unallocated size
qemu-img check: add file-size
block: rename _get_allocated_file_size() to _get_fs_allocated_size()
block.c | 27 ++++++++++++++++----- block/file-posix.c | 14 ++++------- block/file-win32.c | 8 +++---- block/gluster.c | 8 +++---- block/nfs.c | 8 +++---- block/qapi.c | 4 ++-- block/qcow2-refcount.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 2 ++ block/qcow2.h | 2 ++ block/sheepdog.c | 8 +++---- block/vmdk.c | 8 +++---- include/block/block.h | 3 ++- include/block/block_int.h | 3 ++- include/qemu-common.h | 2 ++ qapi/block-core.json | 3 ++- qemu-img.c | 24 +++++++++++++++++++ 16 files changed, 144 insertions(+), 41 deletions(-)
Signature · 1 line
2.11.1
PATCH 1/7 block: fix comment for bdrv_get_allocated_file_size()
Current comment is not clear enough: which sparseness is meant, coming from sparse image format or from sparse file system?
For example, if we have qcow2 above raw file on non-sparse file system, this function will say nothing about unallocated (by qcow2 layer) clusters.
--- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block.c +2 -2
@@ -3388,8 +3388,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) }/** -* Length of a allocated file in bytes. Sparse files are counted by actual -* allocated space. Return < 0 if error or unknown. +* Size of allocated in underlying file system area. Sparseness is taken into +* account for sparse file systems. Return < 0 if error or unknown. */ int64_t bdrv_get_allocated_file_size (BlockDriverState *bs) {
Signature · 1 line
2.11.1
PATCH 2/7 block: add bdrv_get_format_allocated_size format interface
In reply to Vladimir Sementsov-OgievskiyThe function should return actually used by top-level format driver space (in it's .file). It differs from bdrv_get_allocated_file_size, which returns allocated on fs file size.
--- block.c | 15 +++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 1 + 3 files changed, 17 insertions(+)
block.c +15 -0
@@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) }/** +* Actually used by top-level format driver space (in it's .file) in bytes +*/ +int64_t bdrv_get_format_allocated_size (BlockDriverState *bs) +{ +BlockDriver *drv = bs->drv; +if (!drv) { +return -ENOMEDIUM ; + } +if (drv->bdrv_get_format_allocated_size) { +return drv->bdrv_get_format_allocated_size (bs); + } +return -ENOTSUP ; +} + +/** * Return number of sectors on success, -errno on error. */ int64_t bdrv_nb_sectors (BlockDriverState *bs)
include/block/block.h +1 -0
@@ -304,6 +304,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp);int64_t bdrv_nb_sectors (BlockDriverState *bs);int64_t bdrv_getlength (BlockDriverState *bs);int64_t bdrv_get_allocated_file_size (BlockDriverState *bs); +int64_t bdrv_get_format_allocated_size (BlockDriverState *bs);void bdrv_get_geometry (BlockDriverState *bs,uint64_t *nb_sectors_ptr);void bdrv_refresh_limits (BlockDriverState *bs,Error **errp);int bdrv_commit (BlockDriverState *bs);
include/block/block_int.h +1 -0
@@ -208,6 +208,7 @@ struct BlockDriver {int64_t (*bdrv_getlength)(BlockDriverState *bs);bool has_variable_length;int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); +int64_t (*bdrv_get_format_allocated_size)(BlockDriverState *bs); int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs,uint64_t offset,uint64_t bytes,QEMUIOVector *qiov);
Signature · 1 line
2.11.1
PATCH 3/7 qcow2: add .bdrv_get_format_allocated_size
In reply to Vladimir Sementsov-OgievskiyRealize .bdrv_get_format_allocated_size interface.
--- block/qcow2-refcount.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 2 ++ block/qcow2.h | 2 ++ 3 files changed, 65 insertions(+)
block/qcow2-refcount.c +61 -0
@@ -2931,3 +2931,64 @@ done:qemu_vfree (new_refblock);return ret; } + +typedef struct NbAllocatedClustersCo { +BlockDriverState *bs; +int64_t ret; +}NbAllocatedClustersCo ; + +static void coroutine_fn qcow2_get_format_allocated_size_co_entry(void *opaque) +{ +NbAllocatedClustersCo *nbco = opaque; +BlockDriverState *bs = nbco->bs; +BDRVQcow2State *s = bs->opaque; +int64_t size, nb_clusters, nb_allocated =0 , i; +int ret =0 ; + + size =bdrv_getlength (bs->file->bs); +if (size <0 ) { + nbco->ret = size; +return ; + } + + nb_clusters =size_to_clusters (s, size); + +qemu_co_mutex_lock (&s->lock); + +for (i =0 ; i < nb_clusters; ++i) { +uint64_t refcount; + ret =qcow2_get_refcount (bs, i, &refcount); +if (ret <0 ) { + nbco->ret = ret; +qemu_co_mutex_unlock (&s->lock); +return ; + } +if (refcount >0 ) { + nb_allocated++; + } + } + +qemu_co_mutex_unlock (&s->lock); + + nbco->ret = nb_allocated << s->cluster_bits; +} + +int64_t qcow2_get_format_allocated_size (BlockDriverState *bs) +{ +NbAllocatedClustersCo nbco = { + .bs = bs, + .ret = -EINPROGRESS + }; + +if (qemu_in_coroutine ()) { +qcow2_get_format_allocated_size_co_entry (&nbco); + }else { +Coroutine *co = +qemu_coroutine_create (qcow2_get_format_allocated_size_co_entry, + &nbco); +qemu_coroutine_enter (co); +BDRV_POLL_WHILE (bs, nbco.ret == -EINPROGRESS ); + } + +return nbco.ret; +}
block/qcow2.c +2 -0
@@ -3469,6 +3469,8 @@ BlockDriver bdrv_qcow2 = { .bdrv_detach_aio_context = qcow2_detach_aio_context, .bdrv_attach_aio_context = qcow2_attach_aio_context, + + .bdrv_get_format_allocated_size = qcow2_get_format_allocated_size, };static void bdrv_qcow2_init (void )
block/qcow2.h +2 -0
@@ -532,6 +532,8 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, BlockDriverAmendStatusCB *status_cb, void *cb_opaque, Error **errp); +int64_t qcow2_get_format_allocated_size (BlockDriverState *bs); +/* qcow2-cluster.c functions */ int qcow2_grow_l1_table (BlockDriverState *bs,uint64_t min_size,bool exact_size);
Signature · 1 line
2.11.1
PATCH 4/7 common: make get_human_readable_size public
In reply to Vladimir Sementsov-OgievskiyTo be reused from qemu-img check.
--- block/qapi.c | 2 +- include/qemu-common.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
block/qapi.c +1 -1
@@ -524,7 +524,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,#define NB_SUFFIXES 4 -static char *get_human_readable_size (char *buf,int buf_size,int64_t size) +char *get_human_readable_size (char *buf,int buf_size,int64_t size) {static const char suffixes[NB_SUFFIXES ] = {'K' ,'M' ,'G' ,'T' };int64_t base;
include/qemu-common.h +2 -0
@@ -152,4 +152,6 @@ void page_size_init(void);* returned. */ bool dump_in_progress (void ); +char *get_human_readable_size (char *buf,int buf_size,int64_t size); +#endif
Signature · 1 line
2.11.1
PATCH 5/7 qemu-img check: add format unallocated size
In reply to Vladimir Sementsov-OgievskiyShows format 'sparseness' of the image top level.
--- qapi/block-core.json | 3 ++- qemu-img.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)
qapi/block-core.json +2 -1
@@ -185,7 +185,8 @@ '*image-end-offset': 'int', '*corruptions': 'int', '*leaks': 'int', '*corruptions-fixed': 'int', '*leaks-fixed': 'int', '*total-clusters': 'int', '*allocated-clusters': 'int', - '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } } + '*fragmented-clusters': 'int', '*compressed-clusters': 'int', + '*format-unallocated-size': 'uint64'} } ## # @MapEntry:
qemu-img.c +19 -0
@@ -601,6 +601,13 @@ static void dump_human_image_check(ImageCheck *check, bool quiet)qprintf (quiet,"Image end offset: %" PRId64"\n" , check->image_end_offset); } + +if (check->has_format_unallocated_size) { +char u_buf[128 ]; +qprintf (quiet,"Format unallocated size: %s\n" , +get_human_readable_size (u_buf,sizeof (u_buf), + check->format_unallocated_size)); + } } static int collect_image_check(BlockDriverState *bs,
@@ -639,6 +646,18 @@ static int collect_image_check(BlockDriverState *bs, check->compressed_clusters = result.bfi.compressed_clusters; check->has_compressed_clusters = result.bfi.compressed_clusters !=0 ; +if (bs->file) { +int64_t file_size =bdrv_getlength (bs->file->bs); +if (file_size >=0 ) { +int64_t format_allocated_size =bdrv_get_format_allocated_size (bs); +if (format_allocated_size >=0 ) { + check->format_unallocated_size = + file_size - format_allocated_size; + check->has_format_unallocated_size = true; + } + } + } +return 0 ; }
Signature · 1 line
2.11.1
PATCH 6/7 qemu-img check: add file-size
In reply to Vladimir Sementsov-OgievskiyAdd bdrv_getlength() of underlying bs->file->bs, to improve 'Format unallocated size' section of qemu-img check output.
--- qapi/block-core.json | 2 +- qemu-img.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
qapi/block-core.json +1 -1
@@ -186,7 +186,7 @@ '*corruptions-fixed': 'int', '*leaks-fixed': 'int', '*total-clusters': 'int', '*allocated-clusters': 'int', '*fragmented-clusters': 'int', '*compressed-clusters': 'int', - '*format-unallocated-size': 'uint64'} } + '*format-unallocated-size': 'uint64', '*file-size': 'uint64'} } ## # @MapEntry:
qemu-img.c +8 -3
@@ -603,10 +603,13 @@ static void dump_human_image_check(ImageCheck *check, bool quiet) }if (check->has_format_unallocated_size) { -char u_buf[128 ]; -qprintf (quiet,"Format unallocated size: %s\n" , +char buf[128 ], u_buf[128 ]; +assert (check->has_file_size); +qprintf (quiet,"Format unallocated size: %s/%s = %0.2f%%\n" ,get_human_readable_size (u_buf,sizeof (u_buf), - check->format_unallocated_size)); + check->format_unallocated_size), +get_human_readable_size (buf,sizeof (buf), check->file_size), + check->format_unallocated_size *100.0 / check->file_size); } }
@@ -650,6 +653,8 @@ static int collect_image_check(BlockDriverState *bs,int64_t file_size =bdrv_getlength (bs->file->bs);if (file_size >=0 ) {int64_t format_allocated_size =bdrv_get_format_allocated_size (bs); + check->file_size = file_size; + check->has_file_size = true;if (format_allocated_size >=0 ) { check->format_unallocated_size = file_size - format_allocated_size;
Signature · 1 line
2.11.1
PATCH 7/7 block: rename _get_allocated_file_size() to _get_fs_allocated_size()
In reply to Vladimir Sementsov-OgievskiyTo be in contrast with _get_format_allocated_size()
--- block.c | 8 ++++---- block/file-posix.c | 14 +++++--------- block/file-win32.c | 8 +++----- block/gluster.c | 8 ++++---- block/nfs.c | 8 ++++---- block/qapi.c | 2 +- block/sheepdog.c | 8 ++++---- block/vmdk.c | 8 ++++---- include/block/block.h | 2 +- include/block/block_int.h | 2 +- 10 files changed, 31 insertions(+), 37 deletions(-)
block.c +4 -4
@@ -3391,17 +3391,17 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)* Size of allocated in underlying file system area. Sparseness is taken into * account for sparse file systems. Return < 0 if error or unknown. */ -int64_t bdrv_get_allocated_file_size (BlockDriverState *bs) +int64_t bdrv_get_fs_allocated_size (BlockDriverState *bs) {BlockDriver *drv = bs->drv;if (!drv) {return -ENOMEDIUM ; } -if (drv->bdrv_get_allocated_file_size) { -return drv->bdrv_get_allocated_file_size (bs); +if (drv->bdrv_get_fs_allocated_size) { +return drv->bdrv_get_fs_allocated_size (bs); }if (bs->file) { -return bdrv_get_allocated_file_size (bs->file->bs); +return bdrv_get_fs_allocated_size (bs->file->bs); }return -ENOTSUP ; }
block/file-posix.c +5 -9
@@ -1829,7 +1829,7 @@ static int64_t raw_getlength(BlockDriverState *bs) }#endif -static int64_t raw_get_allocated_file_size (BlockDriverState *bs) +static int64_t raw_get_fs_allocated_size (BlockDriverState *bs) {struct stat st;BDRVRawState *s = bs->opaque;
@@ -2218,8 +2218,7 @@ BlockDriver bdrv_file = { .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, .bdrv_get_info = raw_get_info, - .bdrv_get_allocated_file_size - = raw_get_allocated_file_size, + .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size, .bdrv_check_perm = raw_check_perm, .bdrv_set_perm = raw_set_perm, .bdrv_abort_perm_update = raw_abort_perm_update,
@@ -2679,8 +2678,7 @@ static BlockDriver bdrv_host_device = { .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, .bdrv_get_info = raw_get_info, - .bdrv_get_allocated_file_size - = raw_get_allocated_file_size, + .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size, .bdrv_check_perm = raw_check_perm, .bdrv_set_perm = raw_set_perm, .bdrv_abort_perm_update = raw_abort_perm_update,
@@ -2803,8 +2801,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, .has_variable_length = true, - .bdrv_get_allocated_file_size - = raw_get_allocated_file_size, + .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,/* removable device support */ .bdrv_is_inserted = cdrom_is_inserted,
@@ -2933,8 +2930,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, .has_variable_length = true, - .bdrv_get_allocated_file_size - = raw_get_allocated_file_size, + .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,/* removable device support */ .bdrv_is_inserted = cdrom_is_inserted,
block/file-win32.c +3 -5
@@ -524,7 +524,7 @@ static int64_t raw_getlength(BlockDriverState *bs)return l.QuadPart; } -static int64_t raw_get_allocated_file_size (BlockDriverState *bs) +static int64_t raw_get_fs_allocated_size (BlockDriverState *bs) { typedef DWORD (WINAPI * get_compressed_t)(const char *filename, DWORD * high);
@@ -604,8 +604,7 @@ BlockDriver bdrv_file = { .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, - .bdrv_get_allocated_file_size - = raw_get_allocated_file_size, + .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size, .create_opts = &raw_create_opts, };
@@ -773,8 +772,7 @@ static BlockDriver bdrv_host_device = { .bdrv_getlength = raw_getlength, .has_variable_length = true, - .bdrv_get_allocated_file_size - = raw_get_allocated_file_size, + .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size, };static void bdrv_file_init (void )
block/gluster.c +4 -4
@@ -1407,7 +1407,7 @@ static BlockDriver bdrv_gluster = { .bdrv_close = qemu_gluster_close, .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, - .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, + .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate, .bdrv_co_readv = qemu_gluster_co_readv, .bdrv_co_writev = qemu_gluster_co_writev,
@@ -1435,7 +1435,7 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_close = qemu_gluster_close, .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, - .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, + .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate, .bdrv_co_readv = qemu_gluster_co_readv, .bdrv_co_writev = qemu_gluster_co_writev,
@@ -1463,7 +1463,7 @@ static BlockDriver bdrv_gluster_unix = { .bdrv_close = qemu_gluster_close, .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, - .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, + .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate, .bdrv_co_readv = qemu_gluster_co_readv, .bdrv_co_writev = qemu_gluster_co_writev,
@@ -1497,7 +1497,7 @@ static BlockDriver bdrv_gluster_rdma = { .bdrv_close = qemu_gluster_close, .bdrv_create = qemu_gluster_create, .bdrv_getlength = qemu_gluster_getlength, - .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size, + .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size, .bdrv_truncate = qemu_gluster_truncate, .bdrv_co_readv = qemu_gluster_co_readv, .bdrv_co_writev = qemu_gluster_co_writev,
block/nfs.c +4 -4
@@ -719,7 +719,7 @@ static int nfs_has_zero_init(BlockDriverState *bs)/* Called (via nfs_service) with QemuMutex held. */ static void -nfs_get_allocated_file_size_cb (int ret,struct nfs_context *nfs,void *data, +nfs_get_fs_allocated_size_cb (int ret,struct nfs_context *nfs,void *data,void *private_data) {NFSRPC *task = private_data;
@@ -734,7 +734,7 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,bdrv_wakeup (task->bs); } -static int64_t nfs_get_allocated_file_size (BlockDriverState *bs) +static int64_t nfs_get_fs_allocated_size (BlockDriverState *bs) {NFSClient *client = bs->opaque;NFSRPC task = {0 };
@@ -747,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) task.bs = bs; task.st = &st; -if (nfs_fstat_async (client->context, client->fh, nfs_get_allocated_file_size_cb, +if (nfs_fstat_async (client->context, client->fh, nfs_get_fs_allocated_size_cb, &task) !=0 ) {return -ENOMEM ; }
@@ -880,7 +880,7 @@ static BlockDriver bdrv_nfs = { .create_opts = &nfs_create_opts, .bdrv_has_zero_init = nfs_has_zero_init, - .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, + .bdrv_get_fs_allocated_size = nfs_get_fs_allocated_size, .bdrv_truncate = nfs_file_truncate, .bdrv_file_open = nfs_file_open,
block/qapi.c +1 -1
@@ -246,7 +246,7 @@ void bdrv_query_image_info(BlockDriverState *bs, info->filename =g_strdup (bs->filename); info->format =g_strdup (bdrv_get_format_name (bs)); info->virtual_size = size; - info->actual_size =bdrv_get_allocated_file_size (bs); + info->actual_size =bdrv_get_fs_allocated_size (bs); info->has_actual_size = info->actual_size >=0 ;if (bdrv_is_encrypted (bs)) { info->encrypted = true;
block/sheepdog.c +4 -4
@@ -3003,7 +3003,7 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,return ret; } -static int64_t sd_get_allocated_file_size (BlockDriverState *bs) +static int64_t sd_get_fs_allocated_size (BlockDriverState *bs) {BDRVSheepdogState *s = bs->opaque;SheepdogInode *inode = &s->inode;
@@ -3066,7 +3066,7 @@ static BlockDriver bdrv_sheepdog = { .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, - .bdrv_get_allocated_file_size = sd_get_allocated_file_size, + .bdrv_get_fs_allocated_size = sd_get_fs_allocated_size, .bdrv_truncate = sd_truncate, .bdrv_co_readv = sd_co_readv,
@@ -3102,7 +3102,7 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, - .bdrv_get_allocated_file_size = sd_get_allocated_file_size, + .bdrv_get_fs_allocated_size = sd_get_fs_allocated_size, .bdrv_truncate = sd_truncate, .bdrv_co_readv = sd_co_readv,
@@ -3138,7 +3138,7 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_create = sd_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_getlength = sd_getlength, - .bdrv_get_allocated_file_size = sd_get_allocated_file_size, + .bdrv_get_fs_allocated_size = sd_get_fs_allocated_size, .bdrv_truncate = sd_truncate, .bdrv_co_readv = sd_co_readv,
block/vmdk.c +4 -4
@@ -2134,14 +2134,14 @@ static coroutine_fn int vmdk_co_flush(BlockDriverState *bs)return ret; } -static int64_t vmdk_get_allocated_file_size (BlockDriverState *bs) +static int64_t vmdk_get_fs_allocated_size (BlockDriverState *bs) {int i;int64_t ret =0 ;int64_t r;BDRVVmdkState *s = bs->opaque; - ret =bdrv_get_allocated_file_size (bs->file->bs); + ret =bdrv_get_fs_allocated_size (bs->file->bs);if (ret <0 ) {return ret; }
@@ -2149,7 +2149,7 @@ static int64_t vmdk_get_allocated_file_size(BlockDriverState *bs)if (s->extents[i].file == bs->file) {continue ; } - r =bdrv_get_allocated_file_size (s->extents[i].file->bs); + r =bdrv_get_fs_allocated_size (s->extents[i].file->bs);if (r <0 ) {return r; }
@@ -2363,7 +2363,7 @@ static BlockDriver bdrv_vmdk = { .bdrv_create = vmdk_create, .bdrv_co_flush_to_disk = vmdk_co_flush, .bdrv_co_get_block_status = vmdk_co_get_block_status, - .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, + .bdrv_get_fs_allocated_size = vmdk_get_fs_allocated_size, .bdrv_has_zero_init = vmdk_has_zero_init, .bdrv_get_specific_info = vmdk_get_specific_info, .bdrv_refresh_limits = vmdk_refresh_limits,
include/block/block.h +1 -1
@@ -303,7 +303,7 @@ void bdrv_refresh_filename(BlockDriverState *bs);int bdrv_truncate (BdrvChild *child,int64_t offset,Error **errp);int64_t bdrv_nb_sectors (BlockDriverState *bs);int64_t bdrv_getlength (BlockDriverState *bs); -int64_t bdrv_get_allocated_file_size (BlockDriverState *bs); +int64_t bdrv_get_fs_allocated_size (BlockDriverState *bs);int64_t bdrv_get_format_allocated_size (BlockDriverState *bs);void bdrv_get_geometry (BlockDriverState *bs,uint64_t *nb_sectors_ptr);void bdrv_refresh_limits (BlockDriverState *bs,Error **errp);
include/block/block_int.h +1 -1
@@ -207,7 +207,7 @@ struct BlockDriver {int64_t (*bdrv_getlength)(BlockDriverState *bs);bool has_variable_length; -int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); +int64_t (*bdrv_get_fs_allocated_size)(BlockDriverState *bs);int64_t (*bdrv_get_format_allocated_size)(BlockDriverState *bs); int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs,
Signature · 1 line
2.11.1
Re: [Qemu-devel] [PATCH 7/7] block: rename _get_allocated_file_size() to _get_fs_allocated_size()
Quoted 1 line · Vladimir Sementsov-Ogievskiy
To be in contrast with
_get_format_allocated_size()
Sorry for broken indents in this patch, I'll fix them in the next version. Waiting for other comments.
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
In reply to Vladimir Sementsov-OgievskiyQuoted 17 lines · Vladimir Sementsov-Ogievskiy
Current comment is not clear enough: which sparseness is meant, coming from sparse image format or from sparse file system?
For example, if we have qcow2 above raw file on non-sparse file system, this function will say nothing about unallocated (by qcow2 layer) clusters.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block.c +0
-0
block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3391
Quoted 4 lines
block.c +0
-1@@ -3388,8 +3388,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) }/** -* Length of a allocated file in bytes. Sparse files are counted by actual
Yay for getting rid of bad grammar (s/a /an /)
block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3391
Quoted 2 lines
block.c +1
-1-* allocated space. Return < 0 if error or unknown. +* Size of allocated in underlying file system area. Sparseness is taken into
Doesn't read well. Maybe: s/Size of allocated/Allocation size/ ?
block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3392
Quoted 1 line
block.c +1
-0+* account for sparse file systems. Return < 0 if error or unknown.
I still don't get what we are trying to present.
If we have the following 6 qcow2 file clusters backed by the underlying lseek(SEEK_DATA/HOLE) file system contents:
BDRV_BLOCK_UNALLOCATED N/A BDRV_BLOCK_ZERO_PLAIN N/A BDRV_BLOCK_ZERO_ALLOC hole BDRV_BLOCK_ZERO_ALLOC data BDRV_BLOCK_DATA hole BDRV_BLOCK_DATA data
Then is our answer the size of all qcow2 allocations regardless of underlying status (4, due to clusters 3-6), or the size of only the clusters that read from the backing file (2, due to clusters 5-6), or the size of only the clusters that currently occupy space in the file system (2, due to clusters 4 and 6), or the size of clusters that are not provably read-as-zero (1, due to cluster 6)?
Does the answer change if you can have underlying holes happen at a smaller granularity than clusters?
What happens for compressed clusters?
I think we still need to do a better job at writing a precise comment.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Quoted 9 lines · Eric Blake
If we have the following 6 qcow2 file clusters backed by the underlying
lseek(SEEK_DATA/HOLE)file system contents:BDRV_BLOCK_UNALLOCATED N/A BDRV_BLOCK_ZERO_PLAIN N/A BDRV_BLOCK_ZERO_ALLOC hole BDRV_BLOCK_ZERO_ALLOC data BDRV_BLOCK_DATA hole BDRV_BLOCK_DATA data
Sorry, these should all be s/BDRV_BLOCK/QCOW2_CLUSTER/ and s/DATA/NORMAL/ - as I was referring to the qcow2 cluster status given by qcow2_get_cluster_type() (as of commit fdfab37 or later).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
In reply to Eric BlakeQuoted 48 lines · Eric Blake
Quoted 17 lines · Vladimir Sementsov-Ogievskiy
Current comment is not clear enough: which sparseness is meant, coming from sparse image format or from sparse file system?
For example, if we have qcow2 above raw file on non-sparse file system, this function will say nothing about unallocated (by qcow2 layer) clusters.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block.c +0
-0block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3391
Quoted 4 lines
block.c +0
-1@@ -3388,8 +3388,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) }/** -* Length of a allocated file in bytes. Sparse files are counted by actual Yay for getting rid of bad grammar (s/a /an /)
block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3391
Quoted 2 lines
block.c +1
-1-* allocated space. Return < 0 if error or unknown. +* Size of allocated in underlying file system area. Sparseness is taken into Doesn't read well. Maybe: s/Size of allocated/Allocation size/ ?
block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3392
Quoted 1 line
block.c +1
-0+* account for sparse file systems. Return < 0 if error or unknown. I still don't get what we are trying to present.
If we have the following 6 qcow2 file clusters backed by the underlying
lseek(SEEK_DATA/HOLE)file system contents:BDRV_BLOCK_UNALLOCATED N/A BDRV_BLOCK_ZERO_PLAIN N/A BDRV_BLOCK_ZERO_ALLOC hole BDRV_BLOCK_ZERO_ALLOC data BDRV_BLOCK_DATA hole BDRV_BLOCK_DATA dataThen is our answer the size of all qcow2 allocations regardless of underlying status (4, due to clusters 3-6), or the size of only the clusters that read from the backing file (2, due to clusters 5-6), or the size of only the clusters that currently occupy space in the file system (2, due to clusters 4 and 6), or the size of clusters that are not provably read-as-zero (1, due to cluster 6)?
Quoted 7 lines
Does the answer change if you can have underlying holes happen at a smaller granularity than clusters?
What happens for compressed clusters?
I think we still need to do a better job at writing a precise comment.
bdrv_get_allocated_file_size is not related to qcow2, as qcow2 doesn't support it. So, it is finally just raw_get_allocated_file_size, which returns st.st_blocks * 512 after fstat(s->fd).
It will correspond to qcow2 sparseness if qcow2 discarded corresponding clusters in bs->file and if underlying fs is sparse.
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Quoted 22 lines · Vladimir Sementsov-Ogievskiy
Quoted 11 lines · Eric Blake
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Current comment is not clear enough: which sparseness is meant, coming from sparse image format or from sparse file system?
For example, if we have qcow2 above raw file on non-sparse file system, this function will say nothing about unallocated (by qcow2 layer) clusters.
+ * Size of allocated in underlying file system area. Sparseness is taken into
Quoted 9 lines
Doesn't read well. Maybe: s/Size of allocated/Allocation size/ ?
Quoted 1 line
+ * account for sparse file systems. Return < 0 if error or unknown.
I still don't get what we are trying to present.
I think we still need to do a better job at writing a precise comment.
Quoted 6 lines
bdrv_get_allocated_file_sizeis not related to qcow2, as qcow2 doesn't support it. So, it is finally justraw_get_allocated_file_size, which returns st.st_blocks * 512 afterfstat(s->fd).It will correspond to qcow2 sparseness if qcow2 discarded corresponding clusters in
bs->fileand if underlying fs is sparse.
Okay, that helps. How about this wording:
Allocation size of the underlying file system area. Sparseness is taken into account (holes do not contribute to this size). Return < 0 if error or unknown.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
In reply to Vladimir Sementsov-OgievskiyQuoted 1 line · Vladimir Sementsov-Ogievskiy
The function should return actually used by top-level format driver
s/actually/the allocation actually/
Quoted 1 line
space (in it's .file). It differs from
bdrv_get_allocated_file_size,
s/it's/its/ (remember, "it's" is only appropriate if "it is" can be used in its place)
Quoted 1 line
which returns allocated on fs file size.
s/allocated on fs file size/the disk usage of the underlying file/
So this is a measure of how many clusters a qcow2 image is currently using (including metadata clusters, and regardless of whether those clusters happen to point to a hole in the underlying protocol layer)?
Quoted 13 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block.c | 15 +++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 1 + 3 files changed, 17 insertions(+)block.c +0
-0
block.c int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) · line 3410
Quoted 4 lines
block.c +1
-0@@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) }/** +* Actually used by top-level format driver space (in it's .file) in bytes
s/it's/its/
I think we can do better. How about:
Return the amount of space allocated by the format driver (including metadata) in bytes, even if some of that space currently maps to holes in the underlying protocol file.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
In reply to Eric BlakeQuoted 23 lines · Eric Blake
Quoted 22 lines · Vladimir Sementsov-Ogievskiy
Quoted 8 lines · Eric Blake
Quoted 7 lines · Vladimir Sementsov-Ogievskiy
Current comment is not clear enough: which sparseness is meant, coming from sparse image format or from sparse file system?
For example, if we have qcow2 above raw file on non-sparse file system, this function will say nothing about unallocated (by qcow2 layer) clusters.
Quoted 9 lines
Quoted 2 lines
+ * Size of allocated in underlying file system area. Sparseness is taken into
Doesn't read well. Maybe: s/Size of allocated/Allocation size/ ?
Quoted 1 line
+ * account for sparse file systems. Return < 0 if error or unknown.
I still don't get what we are trying to present.
I think we still need to do a better job at writing a precise comment.
bdrv_get_allocated_file_sizeis not related to qcow2, as qcow2 doesn't support it. So, it is finally justraw_get_allocated_file_size, which returns st.st_blocks * 512 afterfstat(s->fd).
Quoted 8 lines
Quoted 2 lines
It will correspond to qcow2 sparseness if qcow2 discarded corresponding clusters in
bs->fileand if underlying fs is sparse.Okay, that helps. How about this wording:
Allocation size of the underlying file system area. Sparseness is taken into account (holes do not contribute to this size). Return < 0 if error or unknown.
OK for me, thank you. Will use your wording if no other comments on this.
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH 4/7] common: make get_human_readable_size public
In reply to Vladimir Sementsov-OgievskiyQuoted 7 lines · Vladimir Sementsov-Ogievskiy
To be reused from qemu-img check.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block/qapi.c | 2 +- include/qemu-common.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Would it be better to use size_to_str() added in commit 22951aa?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 5/7] qemu-img check: add format unallocated size
In reply to Vladimir Sementsov-OgievskiyQuoted 13 lines · Vladimir Sementsov-Ogievskiy
Shows format 'sparseness' of the image top level.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 3 ++- qemu-img.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)qapi/block-core.json +0
-0
qapi/block-core.json line 189
Quoted 6 lines
qapi/block-core.json +2
-1@@ -185,7 +185,8 @@ '*image-end-offset': 'int', '*corruptions': 'int', '*leaks': 'int', '*corruptions-fixed': 'int', '*leaks-fixed': 'int', '*total-clusters': 'int', '*allocated-clusters': 'int', - '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } } + '*fragmented-clusters': 'int', '*compressed-clusters': 'int', + '*format-unallocated-size': 'uint64'} }
Missing documentation (including a since 2.10 blurb).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 6/7] qemu-img check: add file-size
In reply to Vladimir Sementsov-OgievskiyQuoted 14 lines · Vladimir Sementsov-Ogievskiy
Add
bdrv_getlength()of underlyingbs->file->bs, to improve 'Format unallocated size' section of qemu-img check output.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- qapi/block-core.json | 2 +- qemu-img.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)qapi/block-core.json +0
-0
qapi/block-core.json line 189
Quoted 5 lines
qapi/block-core.json +1
-1@@ -186,7 +186,7 @@ '*corruptions-fixed': 'int', '*leaks-fixed': 'int', '*total-clusters': 'int', '*allocated-clusters': 'int', '*fragmented-clusters': 'int', '*compressed-clusters': 'int', - '*format-unallocated-size': 'uint64'} } + '*format-unallocated-size': 'uint64', '*file-size': 'uint64'} }
Missing documentation, including a since 2.10 blurb.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 7/7] block: rename _get_allocated_file_size() to _get_fs_allocated_size()
In reply to Vladimir Sementsov-OgievskiyQuoted 15 lines · Vladimir Sementsov-Ogievskiy
To be in contrast with
_get_format_allocated_size()Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block.c | 8 ++++---- block/file-posix.c | 14 +++++--------- block/file-win32.c | 8 +++----- block/gluster.c | 8 ++++---- block/nfs.c | 8 ++++---- block/qapi.c | 2 +- block/sheepdog.c | 8 ++++---- block/vmdk.c | 8 ++++---- include/block/block.h | 2 +- include/block/block_int.h | 2 +- 10 files changed, 31 insertions(+), 37 deletions(-)
Bikeshedding: is 'protocol' a better name than 'fs'? Unfortunately, it's longer.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
In reply to Eric BlakeQuoted 8 lines · Eric Blake
Quoted 1 line · Vladimir Sementsov-Ogievskiy
The function should return actually used by top-level format driver
s/actually/the allocation actually/
Quoted 1 line
space (in it's .file). It differs from
bdrv_get_allocated_file_size,s/it's/its/ (remember, "it's" is only appropriate if "it is" can be used in its place)
Quoted 6 lines
Quoted 1 line
which returns allocated on fs file size.
s/allocated on fs file size/the disk usage of the underlying file/
So this is a measure of how many clusters a qcow2 image is currently using (including metadata clusters, and regardless of whether those clusters happen to point to a hole in the underlying protocol layer)?
Hmm, interesting remark. Now it is realized exactly as you write.. But this leads to the situation, when qcow2 allocates data amount > bdrv_getlength(bs->file->bs) and we will have negative size of unallocated area =). Denis what do you think? (Actually, we needed this feature for non-sparce file system and this question was not considered).
Quoted 25 lines
Quoted 13 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- block.c | 15 +++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 1 + 3 files changed, 17 insertions(+)block.c +0
-0block.c int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) · line 3410
Quoted 4 lines
block.c +1
-0@@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) }/** +* Actually used by top-level format driver space (in it's .file) in bytes s/it's/its/
I think we can do better. How about:
Return the amount of space allocated by the format driver (including metadata) in bytes, even if some of that space currently maps to holes in the underlying protocol file.
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Quoted 9 lines · Vladimir Sementsov-Ogievskiy
Quoted 8 lines · Eric Blake
Quoted 1 line · Vladimir Sementsov-Ogievskiy
The function should return actually used by top-level format driver
s/actually/the allocation actually/
Quoted 1 line
space (in it's .file). It differs from
bdrv_get_allocated_file_size,s/it's/its/ (remember, "it's" is only appropriate if "it is" can be used in its place)
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
which returns allocated on fs file size.
s/allocated on fs file size/the disk usage of the underlying file/
So this is a measure of how many clusters a qcow2 image is currently using (including metadata clusters, and regardless of whether those clusters happen to point to a hole in the underlying protocol layer)?
Hmm, interesting remark. Now it is realized exactly as you write.. But this leads to the situation, when qcow2 allocates data amount >
bdrv_getlength(bs->file->bs)and we will have negative size of unallocated area =). Denis what do you think? (Actually, we needed this feature for non-sparce file system and this question was not considered).
No, it will not be negative, all OK. I've mistaken. length of bs->file->bs will be positive anyway.
Actually, current approach is the following:
a. clusters allocated in qcow2 and after the end of bs->file: unallocated b. clusters allocated in qcow2 and which are holes bs->file: allocated
(a) look inconsistent with b and with commit message and other things. But if I just account (a) clusters, it will lead to negative size of unallocated and will spoil the whole stat.. Something should be adjusted, at least at comment/commit-message level.
Quoted 29 lines
Quoted 25 lines
Quoted 13 lines
Signed-off-by Vladimir Sementsov-Ogievskiy<[email protected]>--- block.c | 15 +++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 1 + 3 files changed, 17 insertions(+)block.c +0
-0block.c int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) · line 3410
Quoted 4 lines
block.c +1
-0@@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) }/** +* Actually used by top-level format driver space (in it's .file) in bytes s/it's/its/
I think we can do better. How about:
Return the amount of space allocated by the format driver (including metadata) in bytes, even if some of that space currently maps to holes in the underlying protocol file.
Signature · 2 lines
Best regards, Vladimir
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Quoted 6 lines · Vladimir Sementsov-Ogievskiy
No, it will not be negative, all OK. I've mistaken. length of
bs->file->bswill be positive anyway.Actually, current approach is the following:
a. clusters allocated in qcow2 and after the end of
bs->file: unallocated
How often do we actually end up in this situation? I know there are a few cases where it makes sense (for example, if your image is large enough to have L1 occupy two clusters, but the guest hasn't written anything in the second half of the guest-visible area, then the second cluster of the L1 table can be all zeroes - and depending on allocation patterns, it is feasible that the L1 table can occupy the end of the image, where the second cluster of the L1 table thus points beyond end-of-file of the underlying image while still being a well-formed qcow2 image). It may also be a common transitory state in how we expand a qcow2 image; if the expansion is interrupted in the middle, we could easily have the refcount table saying a cluster has been allocated while we have not yet actually written to the host file.
Quoted 1 line
b. clusters allocated in qcow2 and which are holes
bs->file: allocated
This may be more common; a typical example is if we have a cluster marked QCOW2_CLUSTER_NORMAL but which maps to a hole (and therefore bdrv_get_block_status will report it as BDRV_BLOCK_DATA|BDRV_BLOCK_ZERO).
Quoted 5 lines
(a) look inconsistent with b and with commit message and other things. But if I just account (a) clusters, it will lead to negative size of unallocated and will spoil the whole stat.. Something should be adjusted, at least at comment/commit-message level.
Exposing the stat as a difference may not make as much sense as reporting actual numbers (this image requires an allocation of this many bytes to fully represent current guest- and meta-data, even if some of the allocation is currently pointing to holes or beyond the end of the underlying file).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org