Skip to content

Commit c29440f

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: share more code in xfs_buffered_write_iomap_begin
Introduce a local iomap_flags variable so that the code allocating new delalloc blocks in the data fork can fall through to the found_imap label and reuse the code to unlock and fill the iomap. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 8fe3b21 commit c29440f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

fs/xfs/xfs_iomap.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ xfs_buffered_write_iomap_begin(
975975
int allocfork = XFS_DATA_FORK;
976976
int error = 0;
977977
unsigned int lockmode = XFS_ILOCK_EXCL;
978+
unsigned int iomap_flags = 0;
978979
u64 seq;
979980

980981
if (xfs_is_shutdown(mp))
@@ -1145,6 +1146,11 @@ xfs_buffered_write_iomap_begin(
11451146
}
11461147
}
11471148

1149+
/*
1150+
* Flag newly allocated delalloc blocks with IOMAP_F_NEW so we punch
1151+
* them out if the write happens to fail.
1152+
*/
1153+
iomap_flags |= IOMAP_F_NEW;
11481154
if (allocfork == XFS_COW_FORK) {
11491155
error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb,
11501156
end_fsb - offset_fsb, prealloc_blocks, &cmap,
@@ -1162,19 +1168,11 @@ xfs_buffered_write_iomap_begin(
11621168
if (error)
11631169
goto out_unlock;
11641170

1165-
/*
1166-
* Flag newly allocated delalloc blocks with IOMAP_F_NEW so we punch
1167-
* them out if the write happens to fail.
1168-
*/
1169-
seq = xfs_iomap_inode_sequence(ip, IOMAP_F_NEW);
1170-
xfs_iunlock(ip, lockmode);
11711171
trace_xfs_iomap_alloc(ip, offset, count, allocfork, &imap);
1172-
return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, IOMAP_F_NEW, seq);
1173-
11741172
found_imap:
1175-
seq = xfs_iomap_inode_sequence(ip, 0);
1173+
seq = xfs_iomap_inode_sequence(ip, iomap_flags);
11761174
xfs_iunlock(ip, lockmode);
1177-
return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, 0, seq);
1175+
return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
11781176

11791177
convert_delay:
11801178
xfs_iunlock(ip, lockmode);

0 commit comments

Comments
 (0)