Skip to content

Commit

Permalink
block: add BDRV_BLOCK_COMPRESSED flag for bdrv_block_status()
Browse files Browse the repository at this point in the history
Functions qcow2_get_host_offset(), get_cluster_offset(),
vmdk_co_block_status() explicitly report compressed cluster types when data
is compressed.  However, this information is never passed further.  Let's
make use of it by adding new BDRV_BLOCK_COMPRESSED flag for
bdrv_block_status(), so that caller may know that the data range is
compressed.  In particular, we're going to use this flag to tweak
"qemu-img map" output.

This new flag is only being utilized by qcow, qcow2 and vmdk formats, as only
those support compression.

Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Message-ID: <20230907210226.953821-2-andrey.drobyshev@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Andrey Drobyshev via authored and kevmw committed Sep 20, 2023
1 parent 9def608 commit 2848289
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion block/qcow.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,10 @@ qcow_co_block_status(BlockDriverState *bs, bool want_zero,
if (!cluster_offset) {
return 0;
}
if ((cluster_offset & QCOW_OFLAG_COMPRESSED) || s->crypto) {
if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
return BDRV_BLOCK_DATA | BDRV_BLOCK_COMPRESSED;
}
if (s->crypto) {
return BDRV_BLOCK_DATA;
}
*map = cluster_offset | index_in_cluster;
Expand Down
3 changes: 3 additions & 0 deletions block/qcow2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,9 @@ qcow2_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
{
status |= BDRV_BLOCK_RECURSE;
}
if (type == QCOW2_SUBCLUSTER_COMPRESSED) {
status |= BDRV_BLOCK_COMPRESSED;
}
return status;
}

Expand Down
2 changes: 2 additions & 0 deletions block/vmdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,8 @@ vmdk_co_block_status(BlockDriverState *bs, bool want_zero,
if (extent->flat) {
ret |= BDRV_BLOCK_RECURSE;
}
} else {
ret |= BDRV_BLOCK_COMPRESSED;
}
*file = extent->file->bs;
break;
Expand Down
3 changes: 3 additions & 0 deletions include/block/block-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ typedef enum {
* layer rather than any backing, set by block layer
* BDRV_BLOCK_EOF: the returned pnum covers through end of file for this
* layer, set by block layer
* BDRV_BLOCK_COMPRESSED: the underlying data is compressed; only valid for
* the formats supporting compression: qcow, qcow2
*
* Internal flags:
* BDRV_BLOCK_RAW: for use by passthrough drivers, such as raw, to request
Expand Down Expand Up @@ -326,6 +328,7 @@ typedef enum {
#define BDRV_BLOCK_ALLOCATED 0x10
#define BDRV_BLOCK_EOF 0x20
#define BDRV_BLOCK_RECURSE 0x40
#define BDRV_BLOCK_COMPRESSED 0x80

typedef QTAILQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;

Expand Down

0 comments on commit 2848289

Please sign in to comment.