daxfs: Fix truncate not updating VFS i_size in setattr#9
Merged
Conversation
daxfs_setattr() relied on setattr_copy() to update i_size when handling ATTR_SIZE (e.g. O_TRUNC). However, setattr_copy() does not handle ATTR_SIZE — the filesystem must update i_size itself. This caused a bug where overwriting an existing file via shell redirect (echo "..." > file) would produce empty reads: 1. O_TRUNC triggers setattr(ATTR_SIZE=0) which creates an overlay inode entry with size=0, but VFS i_size stays at the original base image size (e.g. 23 bytes) 2. The subsequent write (21 bytes) sees pos(21) <= i_size(23), so the "update size if extending" check is skipped — the overlay inode size is never updated from 0 3. On read, daxfs_refresh_isize() reads overlay size=0 and clobbers VFS i_size to 0, causing the read to return empty Fix by calling truncate_setsize() before setattr_copy() when ATTR_SIZE is set. This is the standard pattern used by other Linux filesystems (ramfs, tmpfs, etc.).
Contributor
|
For long term, we may need to restructure daxfs_setattr(). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
daxfs_setattr() relied on setattr_copy() to update i_size when handling ATTR_SIZE (e.g. O_TRUNC). However, setattr_copy() does not handle ATTR_SIZE — the filesystem must update i_size itself.
This caused a bug where overwriting an existing file via shell redirect (echo "..." > file) would produce empty reads:
Fix by calling truncate_setsize() before setattr_copy() when ATTR_SIZE is set. This is the standard pattern used by other Linux filesystems (ramfs, tmpfs, etc.).
Fixes: #8