Re: [PATCH v6 3/3] xfs: add support for FALLOC_FL_WRITE_ZEROES
From: Zhang Yi <hidden>
Date: 2026-06-25 11:16:53
Also in:
linux-fsdevel, linux-xfs
On 6/18/2026 11:22 AM, Zhang Yi wrote:
On 6/17/2026 5:44 PM, Pankaj Raghav (Samsung) wrote:quoted
On Tue, Jun 16, 2026 at 06:31:40AM -0700, Christoph Hellwig wrote:quoted
[API questions for Zhang and -fsdevel/ -api below)quoted
+ unsigned int blksize = i_blocksize(inode); + loff_t offset_aligned = round_down(offset, blksize);I think this actually needs to found up instead of rounding down.quoted
+ /* + * Zero the tail of the old EOF block and any space up to the new + * offset. + * In the usual truncate path, xfs_falloc_setsize takes care of + * zeroing those blocks. + */ + if (offset_aligned > old_size) { + trace_xfs_zero_eof(ip, old_size, offset_aligned - old_size); + error = xfs_zero_range(ip, old_size, offset_aligned - old_size, + NULL, &did_zero); + if (error) + return error; + }... then this will properly zero from the old i_size to the first block boundary after the old size.Hmm, right now we do this: |----------|----------|----------| ^ ^ ^ ^ | | | | old_size | offset | | | off_rd off_ru At the moment, we zero out old_size to off_rd and pass offset to xfs_alloc_file_space. xfs_alloc_file_space rounds down the offset to off_rd. What you are proposing is to zero out old_size to off_ru, and pass off_ru to xfs_alloc_file_space. I don't exactly understand the difference.IMO, FALLOC_FL_WRITE_ZEROES should handle the unaligned cases, if the 'offset' and 'end' are not block-size aligned, then: 1) if the two blocks straddling the boundaries have not yet been allocated, or allocated as unwritten, we should round outward the allocation range and zero out all allocated blocks, including those two boundary blocks. 2) if the blocks at the boundaries are already in the written state — which can occur when we call FALLOC_FL_WRITE_ZEROES within the file size. We should be careful here: we should only zero the ranges [offset, offset_ru) and [end_rd, end) for the boundary blocks, leaving the already-written portions of the boundary blocks intact.
I've thought about this more and feel that we need to add one more scenario here: 3) If the blocks at the boundaries are in dirty unwritten or in delay allocated state, it should be handled the same way as scenario 2. Additionally, before returning, we need to flush these two boundary blocks that have been partially zeroed, to ensure that after FALLOC_FL_WRITE_ZEROES, all ranges are in the written state. What do you think? Best Regards, Yi.