* [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled
@ 2025-05-13 13:26 Jean-Louis Dupond
2025-05-13 13:26 ` [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard Jean-Louis Dupond
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jean-Louis Dupond @ 2025-05-13 13:26 UTC (permalink / raw)
To: qemu-devel
Cc: Hanna Reitz, Kevin Wolf, Alexander Ivanov, Andrey Drobyshev,
qemu-block, Jean-Louis Dupond
Partially based on the proposal of Andrey in
https://patchew.org/QEMU/20240913163942.423050-1-andrey.drobyshev@virtuozzo.com/
Split up this from the rest might get it merged a bit quicker hopefully :)
Since the implementation of discard-no-unref, we did not queue the discards correctly
when discard-no-unref was enabled.
Jean-Louis Dupond (2):
qcow2: rename update_refcount_discard to queue_discard
qcow2: put discards in discard queue when discard-no-unref is enabled
block/qcow2-cluster.c | 16 ++++++----------
block/qcow2-refcount.c | 25 +++++++++++++++++++++----
block/qcow2.h | 4 ++++
3 files changed, 31 insertions(+), 14 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard
2025-05-13 13:26 [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
@ 2025-05-13 13:26 ` Jean-Louis Dupond
2025-05-15 19:42 ` Eric Blake
2025-05-13 13:26 ` [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled Jean-Louis Dupond
2025-08-29 9:43 ` [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
2 siblings, 1 reply; 6+ messages in thread
From: Jean-Louis Dupond @ 2025-05-13 13:26 UTC (permalink / raw)
To: qemu-devel
Cc: Hanna Reitz, Kevin Wolf, Alexander Ivanov, Andrey Drobyshev,
qemu-block, Jean-Louis Dupond
The function just queues discards, and doesn't do any refcount change.
So let's change the function name to align with its function.
Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
---
block/qcow2-refcount.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 0266542cee..8fb210501c 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -754,8 +754,8 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
}
}
-static void update_refcount_discard(BlockDriverState *bs,
- uint64_t offset, uint64_t length)
+static void queue_discard(BlockDriverState *bs,
+ uint64_t offset, uint64_t length)
{
BDRVQcow2State *s = bs->opaque;
Qcow2DiscardRegion *d, *p, *next;
@@ -902,7 +902,7 @@ update_refcount(BlockDriverState *bs, int64_t offset, int64_t length,
}
if (s->discard_passthrough[type]) {
- update_refcount_discard(bs, cluster_offset, s->cluster_size);
+ queue_discard(bs, cluster_offset, s->cluster_size);
}
}
}
@@ -3619,7 +3619,7 @@ qcow2_discard_refcount_block(BlockDriverState *bs, uint64_t discard_block_offs)
/* discard refblock from the cache if refblock is cached */
qcow2_cache_discard(s->refcount_block_cache, refblock);
}
- update_refcount_discard(bs, discard_block_offs, s->cluster_size);
+ queue_discard(bs, discard_block_offs, s->cluster_size);
return 0;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled
2025-05-13 13:26 [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
2025-05-13 13:26 ` [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard Jean-Louis Dupond
@ 2025-05-13 13:26 ` Jean-Louis Dupond
2025-05-15 19:47 ` Eric Blake
2025-08-29 9:43 ` [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
2 siblings, 1 reply; 6+ messages in thread
From: Jean-Louis Dupond @ 2025-05-13 13:26 UTC (permalink / raw)
To: qemu-devel
Cc: Hanna Reitz, Kevin Wolf, Alexander Ivanov, Andrey Drobyshev,
qemu-block, Jean-Louis Dupond
When discard-no-unref is enabled, discards are not queued like it
should.
This was broken since discard-no-unref was added.
Add some helper function qcow2_discard_cluster which handles some common
checks and calls the queue_discards function if needed to add the
discard request to the queue.
Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
---
block/qcow2-cluster.c | 16 ++++++----------
block/qcow2-refcount.c | 17 +++++++++++++++++
block/qcow2.h | 4 ++++
3 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index ce8c0076b3..c655bf6df4 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1978,12 +1978,10 @@ discard_in_l2_slice(BlockDriverState *bs, uint64_t offset, uint64_t nb_clusters,
if (!keep_reference) {
/* Then decrease the refcount */
qcow2_free_any_cluster(bs, old_l2_entry, type);
- } else if (s->discard_passthrough[type] &&
- (cluster_type == QCOW2_CLUSTER_NORMAL ||
- cluster_type == QCOW2_CLUSTER_ZERO_ALLOC)) {
+ } else {
/* If we keep the reference, pass on the discard still */
- bdrv_pdiscard(s->data_file, old_l2_entry & L2E_OFFSET_MASK,
- s->cluster_size);
+ qcow2_discard_cluster(bs, old_l2_entry & L2E_OFFSET_MASK,
+ s->cluster_size, cluster_type, type);
}
}
@@ -2092,12 +2090,10 @@ zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
if (!keep_reference) {
/* Then decrease the refcount */
qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_REQUEST);
- } else if (s->discard_passthrough[QCOW2_DISCARD_REQUEST] &&
- (type == QCOW2_CLUSTER_NORMAL ||
- type == QCOW2_CLUSTER_ZERO_ALLOC)) {
+ } else {
/* If we keep the reference, pass on the discard still */
- bdrv_pdiscard(s->data_file, old_l2_entry & L2E_OFFSET_MASK,
- s->cluster_size);
+ qcow2_discard_cluster(bs, old_l2_entry & L2E_OFFSET_MASK,
+ s->cluster_size, type, QCOW2_DISCARD_REQUEST);
}
}
}
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 8fb210501c..6512cda407 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1205,6 +1205,23 @@ void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry,
}
}
+void qcow2_discard_cluster(BlockDriverState *bs, uint64_t offset,
+ uint64_t length, QCow2ClusterType ctype,
+ enum qcow2_discard_type dtype)
+{
+ BDRVQcow2State *s = bs->opaque;
+
+ if (s->discard_passthrough[dtype] &&
+ (ctype == QCOW2_CLUSTER_NORMAL ||
+ ctype == QCOW2_CLUSTER_ZERO_ALLOC)) {
+ if (has_data_file(bs)) {
+ bdrv_pdiscard(s->data_file, offset, length);
+ } else {
+ queue_discard(bs, offset, length);
+ }
+ }
+}
+
int qcow2_write_caches(BlockDriverState *bs)
{
BDRVQcow2State *s = bs->opaque;
diff --git a/block/qcow2.h b/block/qcow2.h
index a9e3481c6e..547bb2b814 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -880,6 +880,10 @@ void GRAPH_RDLOCK qcow2_free_clusters(BlockDriverState *bs,
void GRAPH_RDLOCK
qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry,
enum qcow2_discard_type type);
+void GRAPH_RDLOCK
+qcow2_discard_cluster(BlockDriverState *bs, uint64_t offset,
+ uint64_t length, QCow2ClusterType ctype,
+ enum qcow2_discard_type dtype);
int GRAPH_RDLOCK
qcow2_update_snapshot_refcount(BlockDriverState *bs, int64_t l1_table_offset,
--
2.49.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard
2025-05-13 13:26 ` [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard Jean-Louis Dupond
@ 2025-05-15 19:42 ` Eric Blake
0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2025-05-15 19:42 UTC (permalink / raw)
To: Jean-Louis Dupond
Cc: qemu-devel, Hanna Reitz, Kevin Wolf, Alexander Ivanov,
Andrey Drobyshev, qemu-block
On Tue, May 13, 2025 at 03:26:27PM +0200, Jean-Louis Dupond wrote:
> The function just queues discards, and doesn't do any refcount change.
> So let's change the function name to align with its function.
>
> Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
> ---
Reviewed-by: Eric Blake <eblake@redhat.com>
> block/qcow2-refcount.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 0266542cee..8fb210501c 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -754,8 +754,8 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
> }
> }
>
> -static void update_refcount_discard(BlockDriverState *bs,
> - uint64_t offset, uint64_t length)
> +static void queue_discard(BlockDriverState *bs,
> + uint64_t offset, uint64_t length)
> {
> BDRVQcow2State *s = bs->opaque;
> Qcow2DiscardRegion *d, *p, *next;
> @@ -902,7 +902,7 @@ update_refcount(BlockDriverState *bs, int64_t offset, int64_t length,
> }
>
> if (s->discard_passthrough[type]) {
> - update_refcount_discard(bs, cluster_offset, s->cluster_size);
> + queue_discard(bs, cluster_offset, s->cluster_size);
> }
> }
> }
> @@ -3619,7 +3619,7 @@ qcow2_discard_refcount_block(BlockDriverState *bs, uint64_t discard_block_offs)
> /* discard refblock from the cache if refblock is cached */
> qcow2_cache_discard(s->refcount_block_cache, refblock);
> }
> - update_refcount_discard(bs, discard_block_offs, s->cluster_size);
> + queue_discard(bs, discard_block_offs, s->cluster_size);
>
> return 0;
> }
> --
> 2.49.0
>
>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled
2025-05-13 13:26 ` [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled Jean-Louis Dupond
@ 2025-05-15 19:47 ` Eric Blake
0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2025-05-15 19:47 UTC (permalink / raw)
To: Jean-Louis Dupond
Cc: qemu-devel, Hanna Reitz, Kevin Wolf, Alexander Ivanov,
Andrey Drobyshev, qemu-block
On Tue, May 13, 2025 at 03:26:28PM +0200, Jean-Louis Dupond wrote:
> When discard-no-unref is enabled, discards are not queued like it
> should.
> This was broken since discard-no-unref was added.
>
> Add some helper function qcow2_discard_cluster which handles some common
s/Add some/Add a/
(presumably the maintainer will fix the typo when queueing the patch,
no need to respin if the only change is a trivial commit message typo)
> checks and calls the queue_discards function if needed to add the
> discard request to the queue.
>
> Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
> ---
> block/qcow2-cluster.c | 16 ++++++----------
> block/qcow2-refcount.c | 17 +++++++++++++++++
> block/qcow2.h | 4 ++++
> 3 files changed, 27 insertions(+), 10 deletions(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled
2025-05-13 13:26 [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
2025-05-13 13:26 ` [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard Jean-Louis Dupond
2025-05-13 13:26 ` [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled Jean-Louis Dupond
@ 2025-08-29 9:43 ` Jean-Louis Dupond
2 siblings, 0 replies; 6+ messages in thread
From: Jean-Louis Dupond @ 2025-08-29 9:43 UTC (permalink / raw)
To: qemu-devel
Cc: Hanna Reitz, Kevin Wolf, Alexander Ivanov, Andrey Drobyshev,
qemu-block
On 13/05/2025 15:26, Jean-Louis Dupond wrote:
> Partially based on the proposal of Andrey in
> https://patchew.org/QEMU/20240913163942.423050-1-andrey.drobyshev@virtuozzo.com/
> Split up this from the rest might get it merged a bit quicker hopefully :)
>
> Since the implementation of discard-no-unref, we did not queue the discards correctly
> when discard-no-unref was enabled.
>
> Jean-Louis Dupond (2):
> qcow2: rename update_refcount_discard to queue_discard
> qcow2: put discards in discard queue when discard-no-unref is enabled
>
> block/qcow2-cluster.c | 16 ++++++----------
> block/qcow2-refcount.c | 25 +++++++++++++++++++++----
> block/qcow2.h | 4 ++++
> 3 files changed, 31 insertions(+), 14 deletions(-)
>
This was already reviewed.
Reviewed-by: Eric Blake <eblake@redhat.com>
Any chance on getting this merged?
Thanks
Jean-Louis
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-30 15:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-13 13:26 [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
2025-05-13 13:26 ` [PATCH v2 1/2] qcow2: rename update_refcount_discard to queue_discard Jean-Louis Dupond
2025-05-15 19:42 ` Eric Blake
2025-05-13 13:26 ` [PATCH v2 2/2] qcow2: put discards in discard queue when discard-no-unref is enabled Jean-Louis Dupond
2025-05-15 19:47 ` Eric Blake
2025-08-29 9:43 ` [PATCH v2 0/2] qcow2: queue discards when discard-no-unref enabled Jean-Louis Dupond
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).