xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
PATCH v8 1/1 xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
Add support for FALLOC_FL_WRITE_ZEROES if the underlying device enable the unmap write zeroes operation.
---
v8 changes:
rebase to v6.19 add early check for not supported cases
fs/xfs/xfs_bmap_util.c | 10 ++++++++-- fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_file.c | 39 ++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 16 deletions(-)
fs/xfs/xfs_bmap_util.c +8 -2
@@ -642,11 +642,17 @@ xfs_free_eofblocks(return error; } +/* +* Callers can specify bmapi_flags, if XFS_BMAPI_ZERO is used there are no +* further checks whether the hard ware supports and it can fallback to +* software zeroing. +*/ int xfs_alloc_file_space (struct xfs_inode *ip,xfs_off_t offset, -xfs_off_t len) +xfs_off_t len, +uint32_t bmapi_flags) {xfs_mount_t *mp = ip->i_mount;xfs_off_t count;
@@ -748,7 +754,7 @@ xfs_alloc_file_space(* will eventually reach the requested range. */ error =xfs_bmapi_write (tp, ip, startoffset_fsb, - allocatesize_fsb,XFS_BMAPI_PREALLOC ,0 , imapp, + allocatesize_fsb, bmapi_flags,0 , imapp, &nimaps);if (error) {if (error != -ENOSR )
fs/xfs/xfs_bmap_util.h +1 -1
@@ -56,7 +56,7 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,/* preallocation and hole punch interface */ int xfs_alloc_file_space (struct xfs_inode *ip,xfs_off_t offset, -xfs_off_t len); +xfs_off_t len,uint32_t bmapi_flags);int xfs_free_file_space (struct xfs_inode *ip,xfs_off_t offset,xfs_off_t len,struct xfs_zone_alloc_ctx *ac); int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
fs/xfs/xfs_file.c +26 -13
@@ -1293,6 +1293,7 @@ xfs_falloc_zero_range(unsigned int blksize =i_blocksize (inode);loff_t new_size =0 ;int error; +uint32_t bmapi_flags;trace_xfs_zero_file_space (ip);
@@ -1300,18 +1301,27 @@ xfs_falloc_zero_range(if (error)return error; -if (xfs_falloc_force_zero (ip, ac)) { - error =xfs_zero_range (ip, offset, len, ac,NULL ); - }else { - error =xfs_free_file_space (ip, offset, len, ac); -if (error) -return error; - len =round_up (offset + len, blksize) - -round_down (offset, blksize); - offset =round_down (offset, blksize); - error =xfs_alloc_file_space (ip, offset, len); +if (mode &FALLOC_FL_WRITE_ZEROES ) { +if (xfs_is_always_cow_inode (ip) || + !bdev_write_zeroes_unmap_sectors ( +xfs_inode_buftarg (ip)->bt_bdev)) +return -EOPNOTSUPP ; + bmapi_flags =XFS_BMAPI_ZERO ; + }else { +if (xfs_falloc_force_zero (ip, ac)) { + error =xfs_zero_range (ip, offset, len, ac,NULL ); + goto set_filesize; + } + bmapi_flags =XFS_BMAPI_PREALLOC ; } + + len =round_up (offset + len, blksize) -round_down (offset, blksize); + offset =round_down (offset, blksize); + + error =xfs_alloc_file_space (ip, offset, len, bmapi_flags); + +set_filesize:if (error)return error;return xfs_falloc_setsize (file, new_size);
@@ -1336,7 +1346,8 @@ xfs_falloc_unshare_range(if (error)return error; - error =xfs_alloc_file_space (XFS_I (inode), offset, len); + error =xfs_alloc_file_space (XFS_I (inode), offset, len, +XFS_BMAPI_PREALLOC );if (error)return error;return xfs_falloc_setsize (file, new_size);
@@ -1364,7 +1375,8 @@ xfs_falloc_allocate_range(if (error)return error; - error =xfs_alloc_file_space (XFS_I (inode), offset, len); + error =xfs_alloc_file_space (XFS_I (inode), offset, len, +XFS_BMAPI_PREALLOC );if (error)return error;return xfs_falloc_setsize (file, new_size);
@@ -1374,7 +1386,7 @@ xfs_falloc_allocate_range( (FALLOC_FL_ALLOCATE_RANGE |FALLOC_FL_KEEP_SIZE | \FALLOC_FL_PUNCH_HOLE |FALLOC_FL_COLLAPSE_RANGE | \FALLOC_FL_ZERO_RANGE |FALLOC_FL_INSERT_RANGE | \ - FALLOC_FL_UNSHARE_RANGE) + FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_WRITE_ZEROES)STATIC long __xfs_file_fallocate(
@@ -1417,6 +1429,7 @@ __xfs_file_fallocate(case FALLOC_FL_INSERT_RANGE : error =xfs_falloc_insert_range (file, offset, len);break ; +case FALLOC_FL_WRITE_ZEROES :case FALLOC_FL_ZERO_RANGE : error =xfs_falloc_zero_range (file, mode, offset, len, ac);break ;
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
Signature · 1 line
2.53.0
Carlos Maiolino
maintainerQuoted 19 lines · Lukas Herbolt
Add support for
FALLOC_FL_WRITE_ZEROESif the underlying device enable the unmap write zeroes operation.Signed-off-by Lukas Herbolt <[email protected]>---
v8 changes:rebase to v6.19 add early check for not supported casesfs/xfs/xfs_bmap_util.c | 10 ++++++++-- fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_file.c | 39 ++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 16 deletions(-)fs/xfs/xfs_bmap_util.c +0
-0
fs/xfs/xfs_bmap_util.c xfs_free_eofblocks( · line 646
Quoted 5 lines
fs/xfs/xfs_bmap_util.c +2
-0@@ -642,11 +642,17 @@ xfs_free_eofblocks(return error; } +/* +* Callers can specify bmapi_flags, if XFS_BMAPI_ZERO is used there are no
"Callers can specify bmapi_flags" is unneeded here IMHO, the function definition already states that.
fs/xfs/xfs_bmap_util.c xfs_free_eofblocks( · line 648
Quoted 2 lines
fs/xfs/xfs_bmap_util.c +2
-0+* further checks whether the hard ware supports and it can fallback to +* software zeroing.
This sounds weird to me, but I'm not native English speaker. Also, I don't think this comment belongs here, xfs_alloc_file_space() ignores bmapi_flags, it just pass it along...
Quoted 51 lines
fs/xfs/xfs_bmap_util.c +4
-2+*/ int xfs_alloc_file_space (struct xfs_inode *ip,xfs_off_t offset, -xfs_off_t len) +xfs_off_t len, +uint32_t bmapi_flags) {xfs_mount_t *mp = ip->i_mount;xfs_off_t count;@@ -748,7 +754,7 @@ xfs_alloc_file_space(* will eventually reach the requested range. */ error =xfs_bmapi_write (tp, ip, startoffset_fsb, - allocatesize_fsb,XFS_BMAPI_PREALLOC ,0 , imapp, + allocatesize_fsb, bmapi_flags,0 , imapp, &nimaps);if (error) {if (error != -ENOSR )fs/xfs/xfs_bmap_util.h +1
-1@@ -56,7 +56,7 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,/* preallocation and hole punch interface */ int xfs_alloc_file_space (struct xfs_inode *ip,xfs_off_t offset, -xfs_off_t len); +xfs_off_t len,uint32_t bmapi_flags);int xfs_free_file_space (struct xfs_inode *ip,xfs_off_t offset,xfs_off_t len,struct xfs_zone_alloc_ctx *ac); int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,fs/xfs/xfs_file.c +1
-2@@ -1293,6 +1293,7 @@ xfs_falloc_zero_range(unsigned int blksize =i_blocksize (inode);loff_t new_size =0 ;int error; +uint32_t bmapi_flags;trace_xfs_zero_file_space (ip);@@ -1300,18 +1301,27 @@ xfs_falloc_zero_range(if (error)return error; -if (xfs_falloc_force_zero (ip, ac)) { - error =xfs_zero_range (ip, offset, len, ac,NULL );
fs/xfs/xfs_file.c xfs_falloc_zero_range( · line 1305
Quoted 10 lines
fs/xfs/xfs_file.c +1
-8- }else { - error =xfs_free_file_space (ip, offset, len, ac); -if (error) -return error; - len =round_up (offset + len, blksize) - -round_down (offset, blksize); - offset =round_down (offset, blksize); - error =xfs_alloc_file_space (ip, offset, len); +if (mode &FALLOC_FL_WRITE_ZEROES ) {
... The comment probably belongs here and it can be short like (based on the same comment from Ext4):
/*
* Do not allow writing zeroes if the hardware does not
* support it
*/
The rest of the patch looks fine to me, although Christoph likely will also need to take a look on it because xfs_falloc_force_zero() behavior.
Quoted 65 lines
fs/xfs/xfs_file.c +24
-3+if (xfs_is_always_cow_inode (ip) || + !bdev_write_zeroes_unmap_sectors ( +xfs_inode_buftarg (ip)->bt_bdev)) +return -EOPNOTSUPP ; + bmapi_flags =XFS_BMAPI_ZERO ; + }else { +if (xfs_falloc_force_zero (ip, ac)) { + error =xfs_zero_range (ip, offset, len, ac,NULL ); + goto set_filesize; + } + bmapi_flags =XFS_BMAPI_PREALLOC ; } + + len =round_up (offset + len, blksize) -round_down (offset, blksize); + offset =round_down (offset, blksize); + + error =xfs_alloc_file_space (ip, offset, len, bmapi_flags); + +set_filesize:if (error)return error;return xfs_falloc_setsize (file, new_size);@@ -1336,7 +1346,8 @@ xfs_falloc_unshare_range(if (error)return error; - error =xfs_alloc_file_space (XFS_I (inode), offset, len); + error =xfs_alloc_file_space (XFS_I (inode), offset, len, +XFS_BMAPI_PREALLOC );if (error)return error;return xfs_falloc_setsize (file, new_size);@@ -1364,7 +1375,8 @@ xfs_falloc_allocate_range(if (error)return error; - error =xfs_alloc_file_space (XFS_I (inode), offset, len); + error =xfs_alloc_file_space (XFS_I (inode), offset, len, +XFS_BMAPI_PREALLOC );if (error)return error;return xfs_falloc_setsize (file, new_size);@@ -1374,7 +1386,7 @@ xfs_falloc_allocate_range( (FALLOC_FL_ALLOCATE_RANGE |FALLOC_FL_KEEP_SIZE | \FALLOC_FL_PUNCH_HOLE |FALLOC_FL_COLLAPSE_RANGE | \FALLOC_FL_ZERO_RANGE |FALLOC_FL_INSERT_RANGE | \ - FALLOC_FL_UNSHARE_RANGE) + FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_WRITE_ZEROES)STATIC long __xfs_file_fallocate(@@ -1417,6 +1429,7 @@ __xfs_file_fallocate(case FALLOC_FL_INSERT_RANGE : error =xfs_falloc_insert_range (file, offset, len);break ; +case FALLOC_FL_WRITE_ZEROES :case FALLOC_FL_ZERO_RANGE : error =xfs_falloc_zero_range (file, mode, offset, len, ac);break ;base-commit:
05f7e89ab9731565d8a62e3b5d1ec206485eeb0bSignature · 1 line
2.53.0
Quoted 23 lines · Carlos Maiolino
Quoted 22 lines · Lukas Herbolt
Add support for
FALLOC_FL_WRITE_ZEROESif the underlying device enable the unmap write zeroes operation.Signed-off-by Lukas Herbolt <[email protected]>---
v8 changes:rebase to v6.19 add early check for not supported casesfs/xfs/xfs_bmap_util.c | 10 ++++++++-- fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_file.c | 39 ++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 16 deletions(-)fs/xfs/xfs_bmap_util.c +0
-0@@ -642,11 +642,17 @@ xfs_free_eofblocks(return error; }
Quoted 5 lines
fs/xfs/xfs_bmap_util.c xfs_free_eofblocks( · line 646
Quoted 2 lines
fs/xfs/xfs_bmap_util.c +2
-0+/* +* Callers can specify bmapi_flags, if XFS_BMAPI_ZERO is used there are no "Callers can specify
bmapi_flags" is unneeded here IMHO, the function definition already states that.
They in fact have to specify the value :)
Quoted 7 lines
fs/xfs/xfs_bmap_util.c xfs_free_eofblocks( · line 648
Quoted 3 lines
fs/xfs/xfs_bmap_util.c +2
-0+* further checks whether the hard ware supports and it can fallback to +* software zeroing. This sounds weird to me, but I'm not native English speaker. Also, I don't think this comment belongs here,
xfs_alloc_file_space()ignoresbmapi_flags, it just pass it along...
Yeah. I think we can just drop it.
Quoted 5 lines
fs/xfs/xfs_bmap_util.c xfs_free_eofblocks( · line 649
Quoted 1 line
fs/xfs/xfs_bmap_util.c +1
-0+if (mode &FALLOC_FL_WRITE_ZEROES ) {... The comment probably belongs here and it can be short like (based on the same comment from Ext4):
Quoted 7 lines
/*
* Do not allow writing zeroes if the hardware does not
* support it
*/The rest of the patch looks fine to me, although Christoph likely will also need to take a look on it because
xfs_falloc_force_zero()behavior.
I'll reply directly if I find anything.
Quoted 5 lines · Lukas Herbolt
+/*
+ * Callers can specifybmapi_flags, ifXFS_BMAPI_ZEROis used there are no
+ * further checks whether the hard ware supports and it can fallback to
+ * software zeroing.
+ */
As mentioned in the reply to Carlos, I'd just drop this comment.
Quoted 6 lines
fs/xfs/xfs_file.c +0
-5-if (xfs_falloc_force_zero (ip, ac)) { - error =xfs_zero_range (ip, offset, len, ac,NULL ); - }else { - error =xfs_free_file_space (ip, offset, len, ac); -if (error)
fs/xfs/xfs_file.c xfs_falloc_zero_range( · line 1308
Quoted 10 lines
fs/xfs/xfs_file.c +4
-5-return error; - len =round_up (offset + len, blksize) - -round_down (offset, blksize); - offset =round_down (offset, blksize); - error =xfs_alloc_file_space (ip, offset, len); +if (mode &FALLOC_FL_WRITE_ZEROES ) { +if (xfs_is_always_cow_inode (ip) || + !bdev_write_zeroes_unmap_sectors ( +xfs_inode_buftarg (ip)->bt_bdev))
This needs an extra tab, as the condition should not be aligned the same as the following branch.
Otherwise this still looks good.