From: "Denis V. Lunev" via <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, "Denis V. Lunev" <den@openvz.org>,
Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Subject: [PULL v2 12/22] parallels: collect bitmap of used clusters at open
Date: Thu, 21 Sep 2023 09:54:50 +0200 [thread overview]
Message-ID: <20230921075500.694585-13-den@openvz.org> (raw)
In-Reply-To: <20230921075500.694585-1-den@openvz.org>
If the operation is failed, we need to check image consistency if the
problem is not about memory allocation.
Bitmap adjustments in allocate_cluster are not performed yet.
They worth to be separate. This was proven useful during debug of this
series. Kept as is for future bissecting.
It should be specifically noted that used bitmap must be recalculated
if data_off has been fixed during image consistency check.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
block/parallels.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++
block/parallels.h | 3 ++
2 files changed, 76 insertions(+)
diff --git a/block/parallels.c b/block/parallels.c
index 2b5f2b54a0..a997880c34 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -193,6 +193,58 @@ static int mark_used(BlockDriverState *bs,
return 0;
}
+/*
+ * Collect used bitmap. The image can contain errors, we should fill the
+ * bitmap anyway, as much as we can. This information will be used for
+ * error resolution.
+ */
+static int parallels_fill_used_bitmap(BlockDriverState *bs)
+{
+ BDRVParallelsState *s = bs->opaque;
+ int64_t payload_bytes;
+ uint32_t i;
+ int err = 0;
+
+ payload_bytes = bdrv_getlength(bs->file->bs);
+ if (payload_bytes < 0) {
+ return payload_bytes;
+ }
+ payload_bytes -= s->data_start * BDRV_SECTOR_SIZE;
+ if (payload_bytes < 0) {
+ return -EINVAL;
+ }
+
+ s->used_bmap_size = DIV_ROUND_UP(payload_bytes, s->cluster_size);
+ if (s->used_bmap_size == 0) {
+ return 0;
+ }
+ s->used_bmap = bitmap_try_new(s->used_bmap_size);
+ if (s->used_bmap == NULL) {
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < s->bat_size; i++) {
+ int err2;
+ int64_t host_off = bat2sect(s, i) << BDRV_SECTOR_BITS;
+ if (host_off == 0) {
+ continue;
+ }
+
+ err2 = mark_used(bs, s->used_bmap, s->used_bmap_size, host_off);
+ if (err2 < 0 && err == 0) {
+ err = err2;
+ }
+ }
+ return err;
+}
+
+static void parallels_free_used_bitmap(BlockDriverState *bs)
+{
+ BDRVParallelsState *s = bs->opaque;
+ s->used_bmap_size = 0;
+ g_free(s->used_bmap);
+}
+
static int64_t coroutine_fn GRAPH_RDLOCK
allocate_clusters(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
@@ -530,8 +582,17 @@ parallels_check_data_off(BlockDriverState *bs, BdrvCheckResult *res,
res->corruptions++;
if (fix & BDRV_FIX_ERRORS) {
+ int err;
s->header->data_off = cpu_to_le32(data_off);
s->data_start = data_off;
+
+ parallels_free_used_bitmap(bs);
+ err = parallels_fill_used_bitmap(bs);
+ if (err == -ENOMEM) {
+ res->check_errors++;
+ return err;
+ }
+
res->corruptions_fixed++;
}
@@ -1222,6 +1283,14 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
}
need_check = need_check || s->data_end > file_nb_sectors;
+ if (!need_check) {
+ ret = parallels_fill_used_bitmap(bs);
+ if (ret == -ENOMEM) {
+ goto fail;
+ }
+ need_check = need_check || ret < 0; /* These are correctable errors */
+ }
+
/*
* We don't repair the image here if it's opened for checks. Also we don't
* want to change inactive images and can't change readonly images.
@@ -1251,6 +1320,8 @@ fail:
* "s" object was allocated by g_malloc0 so we can safely
* try to free its fields even they were not allocated.
*/
+ parallels_free_used_bitmap(bs);
+
error_free(s->migration_blocker);
g_free(s->bat_dirty_bmap);
qemu_vfree(s->header);
@@ -1271,6 +1342,8 @@ static void parallels_close(BlockDriverState *bs)
PREALLOC_MODE_OFF, 0, NULL);
}
+ parallels_free_used_bitmap(bs);
+
g_free(s->bat_dirty_bmap);
qemu_vfree(s->header);
diff --git a/block/parallels.h b/block/parallels.h
index 4e53e9572d..6b199443cf 100644
--- a/block/parallels.h
+++ b/block/parallels.h
@@ -72,6 +72,9 @@ typedef struct BDRVParallelsState {
unsigned long *bat_dirty_bmap;
unsigned int bat_dirty_block;
+ unsigned long *used_bmap;
+ unsigned long used_bmap_size;
+
uint32_t *bat_bitmap;
unsigned int bat_size;
--
2.34.1
next prev parent reply other threads:[~2023-09-21 7:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-21 7:54 [PULL v2 00/22] implement discard operation for Parallels images Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 01/22] parallels: fix formatting in bdrv_parallels initialization Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 02/22] parallels: mark driver as supporting CBT Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 03/22] parallels: fix memory leak in parallels_open() Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 04/22] parallels: invent parallels_opts_prealloc() helper to parse prealloc opts Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 05/22] parallels: return earler in fail_format branch in parallels_open() Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 06/22] parallels: return earlier from parallels_open() function on error Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 07/22] parallels: refactor path when we need to re-check image in parallels_open Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 08/22] parallels: create mark_used() helper which sets bit in used bitmap Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 09/22] tests: ensure that image validation will not cure the corruption Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 10/22] parallels: fix broken parallels_check_data_off() Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 11/22] parallels: add test which will validate data_off fixes through repair Denis V. Lunev via
2023-09-21 7:54 ` Denis V. Lunev via [this message]
2023-09-21 7:54 ` [PULL v2 13/22] tests: fix broken deduplication check in parallels format test Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 14/22] tests: test self-cure of parallels image with duplicated clusters Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 15/22] parallels: accept multiple clusters in mark_used() Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 16/22] parallels: update used bitmap in allocate_cluster Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 17/22] parallels: naive implementation of allocate_clusters with used bitmap Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 18/22] parallels: improve readability of allocate_clusters Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 19/22] parallels: naive implementation of parallels_co_pdiscard Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 20/22] tests: extend test 131 to cover availability of the discard operation Denis V. Lunev via
2023-09-21 7:54 ` [PULL v2 21/22] parallels: naive implementation of parallels_co_pwrite_zeroes Denis V. Lunev via
2023-09-21 7:55 ` [PULL v2 22/22] tests: extend test 131 to cover availability of the write-zeroes Denis V. Lunev via
2023-09-21 15:16 ` [PULL v2 00/22] implement discard operation for Parallels images Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230921075500.694585-13-den@openvz.org \
--to=qemu-devel@nongnu.org \
--cc=alexander.ivanov@virtuozzo.com \
--cc=den@openvz.org \
--cc=qemu-block@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).