mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
iomap: fix incorrect did_zero setting in iomap_zero_iter()
The did_zero output parameter was unconditionally set after the loop,
which is incorrect. It should only be set when the zeroing operation
actually completes, not when IOMAP_F_STALE is set or when
IOMAP_F_FOLIO_BATCH is set but !folio causes the loop to break early,
or when iomap_iter_advance() returns an error.
This causes did_zero to be incorrectly set when zeroing a clean
unwritten extent because the loop exits early without actually zeroing
any data.
Fix it by using a local variable to track whether any folio was actually
zeroed, and only set did_zero after the loop if zeroing happened.
Fixes: 98eb8d9502 ("iomap: set did_zero to true when zeroing successfully")
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://patch.msgid.link/20260714082325.325163-4-yi.zhang@huaweicloud.com
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
parent
562d192c43
commit
7a6fd6b21d
|
|
@ -1625,6 +1625,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
|
|||
const struct iomap_write_ops *write_ops)
|
||||
{
|
||||
u64 bytes = iomap_length(iter);
|
||||
bool zeroed = false;
|
||||
int status;
|
||||
|
||||
do {
|
||||
|
|
@ -1645,6 +1646,8 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
|
|||
/* a NULL folio means we're done with a folio batch */
|
||||
if (!folio) {
|
||||
status = iomap_iter_advance_full(iter);
|
||||
if (status)
|
||||
return status;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1655,6 +1658,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
|
|||
bytes);
|
||||
|
||||
folio_zero_range(folio, offset, bytes);
|
||||
zeroed = true;
|
||||
folio_mark_accessed(folio);
|
||||
|
||||
ret = iomap_write_end(iter, bytes, bytes, folio);
|
||||
|
|
@ -1664,10 +1668,10 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
|
|||
|
||||
status = iomap_iter_advance(iter, bytes);
|
||||
if (status)
|
||||
break;
|
||||
return status;
|
||||
} while ((bytes = iomap_length(iter)) > 0);
|
||||
|
||||
if (did_zero)
|
||||
if (did_zero && zeroed)
|
||||
*did_zero = true;
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user