[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 04/11] qcow2: introduce qcow2_parse_compressed_cluster_descrip
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v7 04/11] qcow2: introduce qcow2_parse_compressed_cluster_descriptor() |
Date: |
Sat, 4 Sep 2021 19:24:21 +0300 |
This functionality will be reused later. Let's make a separate function
now.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/qcow2.h | 4 ++++
block/qcow2.c | 21 ++++++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.h b/block/qcow2.h
index 0fe5f74ed3..4859ca3d0d 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -914,6 +914,10 @@ int qcow2_alloc_compressed_cluster_offset(BlockDriverState
*bs,
uint64_t offset,
int compressed_size,
uint64_t *host_offset);
+void qcow2_parse_compressed_cluster_descriptor(BDRVQcow2State *s,
+ uint64_t cluster_descriptor,
+ uint64_t *coffset,
+ int *csize);
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);
diff --git a/block/qcow2.c b/block/qcow2.c
index 9f1b6461c8..2095188b6f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -4691,6 +4691,19 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,
return ret;
}
+void qcow2_parse_compressed_cluster_descriptor(BDRVQcow2State *s,
+ uint64_t cluster_descriptor,
+ uint64_t *coffset,
+ int *csize)
+{
+ int nb_csectors;
+
+ *coffset = cluster_descriptor & s->cluster_offset_mask;
+ nb_csectors = ((cluster_descriptor >> s->csize_shift) & s->csize_mask) + 1;
+ *csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE -
+ (*coffset & ~QCOW2_COMPRESSED_SECTOR_MASK);
+}
+
static int coroutine_fn
qcow2_co_preadv_compressed(BlockDriverState *bs,
uint64_t cluster_descriptor,
@@ -4700,15 +4713,13 @@ qcow2_co_preadv_compressed(BlockDriverState *bs,
size_t qiov_offset)
{
BDRVQcow2State *s = bs->opaque;
- int ret = 0, csize, nb_csectors;
+ int ret = 0, csize;
uint64_t coffset;
uint8_t *buf, *out_buf;
int offset_in_cluster = offset_into_cluster(s, offset);
- coffset = cluster_descriptor & s->cluster_offset_mask;
- nb_csectors = ((cluster_descriptor >> s->csize_shift) & s->csize_mask) + 1;
- csize = nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE -
- (coffset & ~QCOW2_COMPRESSED_SECTOR_MASK);
+ qcow2_parse_compressed_cluster_descriptor(s, cluster_descriptor, &coffset,
+ &csize);
buf = g_try_malloc(csize);
if (!buf) {
--
2.29.2
- [PATCH v7 00/11] qcow2: fix parallel rewrite and discard (reqlist), Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 02/11] block/reqlist: add reqlist_new_req() and reqlist_free_req(), Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 01/11] block/reqlist: drop extra assertion, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 03/11] iotests: add qcow2-discard-during-rewrite, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 04/11] qcow2: introduce qcow2_parse_compressed_cluster_descriptor(),
Vladimir Sementsov-Ogievskiy <=
- [PATCH v7 05/11] qcow2: refactor qcow2_co_preadv_task() to have one return, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 06/11] qcow2: prepare for tracking guest io requests in data_file, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 08/11] qcow2: introduce is_cluster_free() helper, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 07/11] qcow2: track guest io requests in data_file, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 10/11] block/reqlist: implement reqlist_mark_req_invalid(), Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 09/11] qcow2: don't reallocate host clusters under guest operation, Vladimir Sementsov-Ogievskiy, 2021/09/04
- [PATCH v7 11/11] qcow2: use reqlist_mark_req_invalid(), Vladimir Sementsov-Ogievskiy, 2021/09/04
- Re: [PATCH v7 00/11] qcow2: fix parallel rewrite and discard (reqlist), Vladimir Sementsov-Ogievskiy, 2021/09/22