Skip to content

Commit

Permalink
Squashfs: Update squashfs_readahead() to not use page->index
Browse files Browse the repository at this point in the history
This commit removes references to page->index in the pages returned
from __readahead_batch(), and instead uses the 'start' variable.

This does reveal a bug in the previous code in that 'start' was
not updated every time around the loop.  This is fixed in this
commit.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Link: https://lore.kernel.org/r/20240818235847.170468-3-phillip@squashfs.org.uk
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Phillip Lougher authored and Christian Brauner committed Aug 19, 2024
1 parent 2258e22 commit 6f09ffb
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions fs/squashfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ static void squashfs_readahead(struct readahead_control *ractl)
return;

for (;;) {
pgoff_t index;
int res, bsize;
u64 block = 0;
unsigned int expected;
Expand All @@ -570,21 +569,16 @@ static void squashfs_readahead(struct readahead_control *ractl)
if (readahead_pos(ractl) >= i_size_read(inode))
goto skip_pages;

index = pages[0]->index >> shift;

if ((pages[nr_pages - 1]->index >> shift) != index)
goto skip_pages;

if (index == file_end && squashfs_i(inode)->fragment_block !=
SQUASHFS_INVALID_BLK) {
if (start >> msblk->block_log == file_end &&
squashfs_i(inode)->fragment_block != SQUASHFS_INVALID_BLK) {
res = squashfs_readahead_fragment(pages, nr_pages,
expected);
if (res)
goto skip_pages;
continue;
}

bsize = read_blocklist(inode, index, &block);
bsize = read_blocklist(inode, start >> msblk->block_log, &block);
if (bsize == 0)
goto skip_pages;

Expand All @@ -602,7 +596,7 @@ static void squashfs_readahead(struct readahead_control *ractl)

/* Last page (if present) may have trailing bytes not filled */
bytes = res % PAGE_SIZE;
if (index == file_end && bytes && last_page)
if (start >> msblk->block_log == file_end && bytes && last_page)
memzero_page(last_page, bytes,
PAGE_SIZE - bytes);

Expand All @@ -616,6 +610,8 @@ static void squashfs_readahead(struct readahead_control *ractl)
unlock_page(pages[i]);
put_page(pages[i]);
}

start += readahead_batch_length(ractl);
}

kfree(pages);
Expand Down

0 comments on commit 6f09ffb

Please sign in to comment.