Skip to content

Commit f1ba5fa

Browse files
iridesdjbw
authored andcommitted
xfs: add xfs_zero_range and xfs_truncate_page helpers
Add helpers to prepare for using different DAX operations. Signed-off-by: Shiyang Ruan <[email protected]> [hch: split from a larger patch + slight cleanups] Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 60696eb commit f1ba5fa

File tree

6 files changed

+37
-12
lines changed

6 files changed

+37
-12
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,23 +1001,22 @@ xfs_free_file_space(
10011001

10021002
/*
10031003
* Now that we've unmap all full blocks we'll have to zero out any
1004-
* partial block at the beginning and/or end. iomap_zero_range is smart
1004+
* partial block at the beginning and/or end. xfs_zero_range is smart
10051005
* enough to skip any holes, including those we just created, but we
10061006
* must take care not to zero beyond EOF and enlarge i_size.
10071007
*/
10081008
if (offset >= XFS_ISIZE(ip))
10091009
return 0;
10101010
if (offset + len > XFS_ISIZE(ip))
10111011
len = XFS_ISIZE(ip) - offset;
1012-
error = iomap_zero_range(VFS_I(ip), offset, len, NULL,
1013-
&xfs_buffered_write_iomap_ops);
1012+
error = xfs_zero_range(ip, offset, len, NULL);
10141013
if (error)
10151014
return error;
10161015

10171016
/*
10181017
* If we zeroed right up to EOF and EOF straddles a page boundary we
10191018
* must make sure that the post-EOF area is also zeroed because the
1020-
* page could be mmap'd and iomap_zero_range doesn't do that for us.
1019+
* page could be mmap'd and xfs_zero_range doesn't do that for us.
10211020
* Writeback of the eof page will do this, albeit clumsily.
10221021
*/
10231022
if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) {

fs/xfs/xfs_file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ xfs_file_write_checks(
437437
}
438438

439439
trace_xfs_zero_eof(ip, isize, iocb->ki_pos - isize);
440-
error = iomap_zero_range(inode, isize, iocb->ki_pos - isize,
441-
NULL, &xfs_buffered_write_iomap_ops);
440+
error = xfs_zero_range(ip, isize, iocb->ki_pos - isize, NULL);
442441
if (error)
443442
return error;
444443
} else

fs/xfs/xfs_iomap.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,3 +1311,28 @@ xfs_xattr_iomap_begin(
13111311
const struct iomap_ops xfs_xattr_iomap_ops = {
13121312
.iomap_begin = xfs_xattr_iomap_begin,
13131313
};
1314+
1315+
int
1316+
xfs_zero_range(
1317+
struct xfs_inode *ip,
1318+
loff_t pos,
1319+
loff_t len,
1320+
bool *did_zero)
1321+
{
1322+
struct inode *inode = VFS_I(ip);
1323+
1324+
return iomap_zero_range(inode, pos, len, did_zero,
1325+
&xfs_buffered_write_iomap_ops);
1326+
}
1327+
1328+
int
1329+
xfs_truncate_page(
1330+
struct xfs_inode *ip,
1331+
loff_t pos,
1332+
bool *did_zero)
1333+
{
1334+
struct inode *inode = VFS_I(ip);
1335+
1336+
return iomap_truncate_page(inode, pos, did_zero,
1337+
&xfs_buffered_write_iomap_ops);
1338+
}

fs/xfs/xfs_iomap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,
2020
int xfs_bmbt_to_iomap(struct xfs_inode *, struct iomap *,
2121
struct xfs_bmbt_irec *, u16);
2222

23+
int xfs_zero_range(struct xfs_inode *ip, loff_t pos, loff_t len,
24+
bool *did_zero);
25+
int xfs_truncate_page(struct xfs_inode *ip, loff_t pos, bool *did_zero);
26+
2327
static inline xfs_filblks_t
2428
xfs_aligned_fsb_count(
2529
xfs_fileoff_t offset_fsb,

fs/xfs/xfs_iops.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,8 @@ xfs_setattr_size(
911911
*/
912912
if (newsize > oldsize) {
913913
trace_xfs_zero_eof(ip, oldsize, newsize - oldsize);
914-
error = iomap_zero_range(inode, oldsize, newsize - oldsize,
915-
&did_zeroing, &xfs_buffered_write_iomap_ops);
914+
error = xfs_zero_range(ip, oldsize, newsize - oldsize,
915+
&did_zeroing);
916916
} else {
917917
/*
918918
* iomap won't detect a dirty page over an unwritten block (or a
@@ -924,8 +924,7 @@ xfs_setattr_size(
924924
newsize);
925925
if (error)
926926
return error;
927-
error = iomap_truncate_page(inode, newsize, &did_zeroing,
928-
&xfs_buffered_write_iomap_ops);
927+
error = xfs_truncate_page(ip, newsize, &did_zeroing);
929928
}
930929

931930
if (error)

fs/xfs/xfs_reflink.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,8 +1269,7 @@ xfs_reflink_zero_posteof(
12691269
return 0;
12701270

12711271
trace_xfs_zero_eof(ip, isize, pos - isize);
1272-
return iomap_zero_range(VFS_I(ip), isize, pos - isize, NULL,
1273-
&xfs_buffered_write_iomap_ops);
1272+
return xfs_zero_range(ip, isize, pos - isize, NULL);
12741273
}
12751274

12761275
/*

0 commit comments

Comments
 (0)