Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fsck breaks preallocated files #145

Open
antmat opened this issue May 18, 2023 · 2 comments
Open

fsck breaks preallocated files #145

antmat opened this issue May 18, 2023 · 2 comments

Comments

@antmat
Copy link

antmat commented May 18, 2023

Hi!
First of all I'm in doubt if this is a ext4 driver issue or fsck issue, but as far as without fsck all works just fine I thought you may be interested in it.
In situation when we have a file with rather small size, which was preallocated via fallocate with FALLOC_FL_KEEP_SIZE flag to rather big value fsck treats its extents as invalid and lost data.

Some details:

I created a minimal reproducible example with minimal comments, you can see it here:
https://gist.github.com/antmat/569408754a007f7519a0ce5122e4ffac

Thanks in advance!

@antmat antmat changed the title fsck breaks preallocaterd files fsck breaks preallocated files May 18, 2023
@antmat
Copy link
Author

antmat commented May 22, 2023

It looks like the problem is here

handle->path[0].end_blk =

We assume, that end_blk is located at the size bound of file, but that is not true, as we preallocated more than size blocks.
The check does not fail on extent tree of deth 2, as on the second level there are leaf nodes that are in UNINIT state, but starting from depth 3 we have index nodes, which doesn't have that flag

@antmat
Copy link
Author

antmat commented May 22, 2023

https://gist.github.com/antmat/9c3ce004a080c50d341e8c3afb22416a
I've created a simple patch, that fixes the problem, but it has a problem itself: if we have a file with holes and preallocated space end_blk should be calculated smarter. Perhaps we could traverse child nodes to determine real bounds or we can leave end_blk zeroed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant