[bugfix] do not reuse an out-of-range last allocated block hint - #11
Open
WaberZhuang wants to merge 1 commit into
Open
[bugfix] do not reuse an out-of-range last allocated block hint#11WaberZhuang wants to merge 1 commit into
WaberZhuang wants to merge 1 commit into
Conversation
Signed-off-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>
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.
The allocation hint cached in
fs->reserved[3]is the block right after thelast allocated range, so it equals
blocks_countas soon as an allocation endsat the last block of the file system.
ext2fs_new_range()used it as the searchstart unconditionally (the
s_first_data_blockfallback was commented out), soext2fs_find_first_zero_block_bitmap2()rejected the range withEXT2_ET_INVALID_ARGUMENT:From then on every allocation without a goal of its own failed, although the
file system still had free blocks. A zero hint is equally unusable when
s_first_data_blockis 1 (1KB block size), because block 0 is outside of theblock bitmap - there the very first allocation already fails.
ext2fs_fallocate()had the same problem and additionally overwrote the goalgiven by its caller, which made the upstream
~0ULLsentinel (and with itext2fs_find_inode_goal()) unreachable, sincereserved[]is 32 bit.Changes:
ext2fs_new_range(): fall back tos_first_data_blockwhen the hint is 0 oroutside the file system.
ext2fs_new_range()/ext2fs_new_block3(): only cache a hint that is insidethe file system and fits in the 32 bit
reserved[]slot, otherwise store 0, soa truncated block number can never be used as a goal (this also removes the
not 64-bit safecase for filesystems beyond 2^32 blocks).ext2fs_fallocate(): only follow the hint while it points inside the filesystem, and