xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
PATCH v12 2/2 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.
---
v12 changes:
split from xfs_falloc_zero_range() into separate function
fs/xfs/xfs_file.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
fs/xfs/xfs_file.c +48 -1
@@ -1318,6 +1318,49 @@ xfs_falloc_zero_range(return xfs_falloc_setsize (file, new_size); } +static int +xfs_falloc_write_zero_range ( +struct file *file, +int mode, +loff_t offset, +loff_t len, +struct xfs_zone_alloc_ctx *ac) +{ +struct inode *inode =file_inode (file); +struct xfs_inode *ip =XFS_I (inode); +unsigned int blksize =i_blocksize (inode); +loff_t new_size =0 ; +int error; + +if (xfs_is_always_cow_inode (ip) || + !bdev_write_zeroes_unmap_sectors ( +xfs_inode_buftarg (ip)->bt_bdev)) +return -EOPNOTSUPP ; + +trace_xfs_zero_file_space (ip); + + error =xfs_falloc_newsize (file, mode, offset, len, &new_size); +if (error) +return error; + + 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,XFS_BMAPI_PREALLOC ); +if (error) +return error; + + error =xfs_falloc_setsize (file, new_size); +if (error) +return error; + +return xfs_alloc_file_space (ip, offset, len, +XFS_BMAPI_CONVERT |XFS_BMAPI_ZERO ); +} + static int xfs_falloc_unshare_range( struct file *file,
@@ -1377,7 +1420,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(
@@ -1423,6 +1466,10 @@ __xfs_file_fallocate(case FALLOC_FL_ZERO_RANGE : error =xfs_falloc_zero_range (file, mode, offset, len, ac);break ; +case FALLOC_FL_WRITE_ZEROES : + error =xfs_falloc_write_zero_range (file, mode, offset, + len, ac); +break ;case FALLOC_FL_UNSHARE_RANGE : error =xfs_falloc_unshare_range (file, mode, offset, len);break ;
Signature · 1 line
2.53.0
Quoted 30 lines · Lukas Herbolt
Add support for
FALLOC_FL_WRITE_ZEROESif the underlying device enable the unmap write zeroes operation.Co-developed-by Pankaj Raghav <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>Signed-off-by Lukas Herbolt <[email protected]>---
v12 changes:
split fromxfs_falloc_zero_range()into separate functionfs/xfs/xfs_file.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)fs/xfs/xfs_file.c +10
-0@@ -1318,6 +1318,49 @@ xfs_falloc_zero_range(return xfs_falloc_setsize (file, new_size); } +static int +xfs_falloc_write_zero_range ( +struct file *file, +int mode, +loff_t offset, +loff_t len, +struct xfs_zone_alloc_ctx *ac) +{ +struct inode *inode =file_inode (file); +struct xfs_inode *ip =XFS_I (inode);
fs/xfs/xfs_file.c xfs_falloc_zero_range( · line 1340
Quoted 10 lines
fs/xfs/xfs_file.c +10
-0+unsigned int blksize =i_blocksize (inode); +loff_t new_size =0 ; +int error; + +if (xfs_is_always_cow_inode (ip) || + !bdev_write_zeroes_unmap_sectors ( +xfs_inode_buftarg (ip)->bt_bdev)) +return -EOPNOTSUPP ; + +trace_xfs_zero_file_space (ip);
I think we want to have a separate tracepoint for write-zeroes, but TBH the fallocate tracepoints all kinda suck in that we don't record the range or any of the flags so... there's a minor cleanup to be done separately.
In the meantime this looks ok provided it doesn't break fsx/fsstress?
--D
Quoted 50 lines
fs/xfs/xfs_file.c +28
-1+ + error =xfs_falloc_newsize (file, mode, offset, len, &new_size); +if (error) +return error; + + 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,XFS_BMAPI_PREALLOC ); +if (error) +return error; + + error =xfs_falloc_setsize (file, new_size); +if (error) +return error; + +return xfs_alloc_file_space (ip, offset, len, +XFS_BMAPI_CONVERT |XFS_BMAPI_ZERO ); +} + static int xfs_falloc_unshare_range( struct file *file,@@ -1377,7 +1420,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(@@ -1423,6 +1466,10 @@ __xfs_file_fallocate(case FALLOC_FL_ZERO_RANGE : error =xfs_falloc_zero_range (file, mode, offset, len, ac);break ; +case FALLOC_FL_WRITE_ZEROES : + error =xfs_falloc_write_zero_range (file, mode, offset, + len, ac); +break ;case FALLOC_FL_UNSHARE_RANGE : error =xfs_falloc_unshare_range (file, mode, offset, len);break ;Signature · 1 line
2.53.0
Quoted 11 lines · Lukas Herbolt
Add support for
FALLOC_FL_WRITE_ZEROESif the underlying device enable the unmap write zeroes operation.Co-developed-by Pankaj Raghav <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>Signed-off-by Lukas Herbolt <[email protected]>---
v12 changes:
split fromxfs_falloc_zero_range()into separate functionfs/xfs/xfs_file.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
Ugh, I just reviewed v11 and pointed out how unnecessarily complex this new "three phase" method is. Please given people a chance to review the code by waiting a couple of days before posting a new version....
My comments against v11 are still relevant; working around low level truncate issues when calling truncate to transactionally update the file size is not necessary is less than ideal.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]