[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/22] parallels: create mark_used() helper which sets bit in use
From: |
Denis V. Lunev |
Subject: |
[PATCH 08/22] parallels: create mark_used() helper which sets bit in used bitmap |
Date: |
Mon, 18 Sep 2023 20:00:46 +0200 |
This functionality is used twice already and next patch will add more
code with it.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
block/parallels.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/block/parallels.c b/block/parallels.c
index af3b4894d7..66c86d87e3 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -178,6 +178,21 @@ static void parallels_set_bat_entry(BDRVParallelsState *s,
bitmap_set(s->bat_dirty_bmap, bat_entry_off(index) / s->bat_dirty_block,
1);
}
+static int mark_used(BlockDriverState *bs,
+ unsigned long *bitmap, uint32_t bitmap_size, int64_t off)
+{
+ BDRVParallelsState *s = bs->opaque;
+ uint32_t cluster_index = host_cluster_index(s, off);
+ if (cluster_index >= bitmap_size) {
+ return -E2BIG;
+ }
+ if (test_bit(cluster_index, bitmap)) {
+ return -EBUSY;
+ }
+ bitmap_set(bitmap, cluster_index, 1);
+ return 0;
+}
+
static int64_t coroutine_fn GRAPH_RDLOCK
allocate_clusters(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
@@ -621,7 +636,7 @@ parallels_check_duplicate(BlockDriverState *bs,
BdrvCheckResult *res,
BDRVParallelsState *s = bs->opaque;
int64_t host_off, host_sector, guest_sector;
unsigned long *bitmap;
- uint32_t i, bitmap_size, cluster_index, bat_entry;
+ uint32_t i, bitmap_size, bat_entry;
int n, ret = 0;
uint64_t *buf = NULL;
bool fixed = false;
@@ -655,10 +670,9 @@ parallels_check_duplicate(BlockDriverState *bs,
BdrvCheckResult *res,
continue;
}
- cluster_index = host_cluster_index(s, host_off);
- assert(cluster_index < bitmap_size);
- if (!test_bit(cluster_index, bitmap)) {
- bitmap_set(bitmap, cluster_index, 1);
+ ret = mark_used(bs, bitmap, bitmap_size, host_off);
+ assert(ret != -E2BIG);
+ if (ret == 0) {
continue;
}
@@ -713,11 +727,13 @@ parallels_check_duplicate(BlockDriverState *bs,
BdrvCheckResult *res,
* consistent for the new allocated clusters too.
*
* Note, clusters allocated outside the current image are not
- * considered, and the bitmap size doesn't change.
+ * considered, and the bitmap size doesn't change. This specifically
+ * means that -E2BIG is OK.
*/
- cluster_index = host_cluster_index(s, host_off);
- if (cluster_index < bitmap_size) {
- bitmap_set(bitmap, cluster_index, 1);
+ ret = mark_used(bs, bitmap, bitmap_size, host_off);
+ if (ret == -EBUSY) {
+ res->check_errors++;
+ goto out_repair_bat;
}
fixed = true;
--
2.34.1
- [PATCH v2 00/22] implement discard operation for Parallels images, Denis V. Lunev, 2023/09/18
- [PATCH 03/22] parallels: fix memory leak in parallels_open(), Denis V. Lunev, 2023/09/18
- [PATCH 05/22] parallels: return earler in fail_format branch in parallels_open(), Denis V. Lunev, 2023/09/18
- [PATCH 07/22] parallels: refactor path when we need to re-check image in parallels_open, Denis V. Lunev, 2023/09/18
- [PATCH 02/22] parallels: mark driver as supporting CBT, Denis V. Lunev, 2023/09/18
- [PATCH 06/22] parallels: return earlier from parallels_open() function on error, Denis V. Lunev, 2023/09/18
- [PATCH 04/22] parallels: invent parallels_opts_prealloc() helper to parse prealloc opts, Denis V. Lunev, 2023/09/18
- [PATCH 08/22] parallels: create mark_used() helper which sets bit in used bitmap,
Denis V. Lunev <=
- [PATCH 3/3] tests: extend test 131 to cover availability of the write-zeroes, Denis V. Lunev, 2023/09/18
- [PATCH 01/22] parallels: fix formatting in bdrv_parallels initialization, Denis V. Lunev, 2023/09/18
- [PATCH 18/22] parallels: improve readability of allocate_clusters, Denis V. Lunev, 2023/09/18
- [PATCH 17/22] parallels: naive implementation of allocate_clusters with used bitmap, Denis V. Lunev, 2023/09/18
- [PATCH 15/22] parallels: accept multiple clusters in mark_used(), Denis V. Lunev, 2023/09/18
- [PATCH 21/22] parallels: naive implementation of parallels_co_pwrite_zeroes, Denis V. Lunev, 2023/09/18
- [PATCH 16/22] parallels: update used bitmap in allocate_cluster, Denis V. Lunev, 2023/09/18
- [PATCH 13/22] tests: fix broken deduplication check in parallels format test, Denis V. Lunev, 2023/09/18
- [PATCH 22/22] tests: extend test 131 to cover availability of the write-zeroes, Denis V. Lunev, 2023/09/18