Skip to content

Commit 8e31320

Browse files
Darrick J. Wonggregkh
authored andcommitted
xfs: fix delalloc write failures in software-provided atomic writes
commit 8d54eacd82a0623a963e0c150ad3b02970638b0d upstream. With the 20 Oct 2025 release of fstests, generic/521 fails for me on regular (aka non-block-atomic-writes) storage: QA output created by 521 dowrite: write: Input/output error LOG DUMP (8553 total operations): 1( 1 mod 256): SKIPPED (no operation) 2( 2 mod 256): WRITE 0x7e000 thru 0x8dfff (0x10000 bytes) HOLE 3( 3 mod 256): READ 0x69000 thru 0x79fff (0x11000 bytes) 4( 4 mod 256): FALLOC 0x53c38 thru 0x5e853 (0xac1b bytes) INTERIOR 5( 5 mod 256): COPY 0x55000 thru 0x59fff (0x5000 bytes) to 0x25000 thru 0x29fff 6( 6 mod 256): WRITE 0x74000 thru 0x88fff (0x15000 bytes) 7( 7 mod 256): ZERO 0xedb1 thru 0x11693 (0x28e3 bytes) with a warning in dmesg from iomap about XFS trying to give it a delalloc mapping for a directio write. Fix the software atomic write iomap_begin code to convert the reservation into a written mapping. This doesn't fix the data corruption problems reported by generic/760, but it's a start. Cc: [email protected] # v6.16 Fixes: bd1d2c2 ("xfs: add xfs_atomic_write_cow_iomap_begin()") Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: John Garry <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c4ad899 commit 8e31320

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

fs/xfs/xfs_iomap.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ xfs_atomic_write_cow_iomap_begin(
11211121
return -EAGAIN;
11221122

11231123
trace_xfs_iomap_atomic_write_cow(ip, offset, length);
1124-
1124+
retry:
11251125
xfs_ilock(ip, XFS_ILOCK_EXCL);
11261126

11271127
if (!ip->i_cowfp) {
@@ -1132,6 +1132,8 @@ xfs_atomic_write_cow_iomap_begin(
11321132
if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &cmap))
11331133
cmap.br_startoff = end_fsb;
11341134
if (cmap.br_startoff <= offset_fsb) {
1135+
if (isnullstartblock(cmap.br_startblock))
1136+
goto convert_delay;
11351137
xfs_trim_extent(&cmap, offset_fsb, count_fsb);
11361138
goto found;
11371139
}
@@ -1160,8 +1162,10 @@ xfs_atomic_write_cow_iomap_begin(
11601162
if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &cmap))
11611163
cmap.br_startoff = end_fsb;
11621164
if (cmap.br_startoff <= offset_fsb) {
1163-
xfs_trim_extent(&cmap, offset_fsb, count_fsb);
11641165
xfs_trans_cancel(tp);
1166+
if (isnullstartblock(cmap.br_startblock))
1167+
goto convert_delay;
1168+
xfs_trim_extent(&cmap, offset_fsb, count_fsb);
11651169
goto found;
11661170
}
11671171

@@ -1201,6 +1205,19 @@ xfs_atomic_write_cow_iomap_begin(
12011205
xfs_iunlock(ip, XFS_ILOCK_EXCL);
12021206
return xfs_bmbt_to_iomap(ip, iomap, &cmap, flags, IOMAP_F_SHARED, seq);
12031207

1208+
convert_delay:
1209+
xfs_iunlock(ip, XFS_ILOCK_EXCL);
1210+
error = xfs_bmapi_convert_delalloc(ip, XFS_COW_FORK, offset, iomap,
1211+
NULL);
1212+
if (error)
1213+
return error;
1214+
1215+
/*
1216+
* Try the lookup again, because the delalloc conversion might have
1217+
* turned the COW mapping into unwritten, but we need it to be in
1218+
* written state.
1219+
*/
1220+
goto retry;
12041221
out_unlock:
12051222
xfs_iunlock(ip, XFS_ILOCK_EXCL);
12061223
return error;

0 commit comments

Comments
 (0)