From: Vincent Vanlaer <libvirt-e6954efa@volkihar.be>
To: qemu-devel@nongnu.org
Cc: John Snow <jsnow@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
Vincent Vanlaer <libvirt-e6954efa@volkihar.be>
Subject: [PATCH v2 3/4] block: allow commit to unmap zero blocks
Date: Sat, 13 Jul 2024 23:56:43 +0200 [thread overview]
Message-ID: <20240713215644.742244-4-libvirt-e6954efa@volkihar.be> (raw)
In-Reply-To: <20240713215644.742244-1-libvirt-e6954efa@volkihar.be>
Non-active block commits do not discard blocks only containing zeros,
causing images to lose sparseness after the commit. This commit fixes
that by writing zero blocks using blk_co_pwrite_zeroes rather than
writing them out as any other arbitrary data.
Signed-off-by: Vincent Vanlaer <libvirt-e6954efa@volkihar.be>
---
block/commit.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/block/commit.c b/block/commit.c
index fb54fc9560..6ce30927ac 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -130,6 +130,7 @@ static void commit_clean(Job *job)
typedef enum CommitMethod {
COMMIT_METHOD_COPY,
+ COMMIT_METHOD_ZERO,
COMMIT_METHOD_IGNORE,
} CommitMethod;
@@ -185,6 +186,18 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
if (ret >= 0) {
if (!(ret & BDRV_BLOCK_ALLOCATED)) {
commit_method = COMMIT_METHOD_IGNORE;
+ } else if (ret & BDRV_BLOCK_ZERO) {
+ int64_t target_offset;
+ int64_t target_bytes;
+ WITH_GRAPH_RDLOCK_GUARD() {
+ bdrv_round_to_subclusters(s->base_bs, offset, n,
+ &target_offset, &target_bytes);
+ }
+
+ if (target_offset == offset &&
+ target_bytes == n) {
+ commit_method = COMMIT_METHOD_ZERO;
+ }
}
switch (commit_method) {
@@ -198,6 +211,11 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
}
}
break;
+ case COMMIT_METHOD_ZERO:
+ ret = blk_co_pwrite_zeroes(s->base, offset, n,
+ BDRV_REQ_MAY_UNMAP);
+ error_in_source = false;
+ break;
case COMMIT_METHOD_IGNORE:
break;
default:
@@ -216,6 +234,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
continue;
}
}
+
/* Publish progress */
job_progress_update(&s->common.job, n);
--
2.44.1
next prev parent reply other threads:[~2024-07-13 22:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-13 21:56 [PATCH v2 0/4] block: allow commit to unmap zero blocks Vincent Vanlaer
2024-07-13 21:56 ` [PATCH v2 1/4] block: get type of block allocation in commit_run Vincent Vanlaer
2024-08-02 10:09 ` Vladimir Sementsov-Ogievskiy
2024-07-13 21:56 ` [PATCH v2 2/4] block: refactor commit_run for multiple write types Vincent Vanlaer
2024-08-02 10:22 ` Vladimir Sementsov-Ogievskiy
2024-07-13 21:56 ` Vincent Vanlaer [this message]
2024-08-02 10:58 ` [PATCH v2 3/4] block: allow commit to unmap zero blocks Vladimir Sementsov-Ogievskiy
2024-09-01 10:25 ` Vincent Vanlaer
2024-07-13 21:56 ` [PATCH v2 4/4] block: add test non-active commit with zeroed data Vincent Vanlaer
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=20240713215644.742244-4-libvirt-e6954efa@volkihar.be \
--to=libvirt-e6954efa@volkihar.be \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/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).