Unverified Commit d937c813 authored by Christian Brauner's avatar Christian Brauner
Browse files

Merge patch series "Squashfs: Update code to not use page->index"

Phillip Lougher <phillip@squashfs.org.uk> says:

In the near future page->index will be removed [1].  Any code which
still uses page->index needs to be updated.

This patch-set contains 4 patches which updates most of the code in
Squashfs.  The exceptions are functions which have been fixed in
recent patches [2] & [3].

[1]: https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@casper.infradead.org/
[2]: https://lore.kernel.org/all/20240817101146.2347378-1-lizetao1@huawei.com/
[3]: https://lore.kernel.org/all/20240817101146.2347378-2-lizetao1@huawei.com/

* patchesf from https://lore.kernel.org/r/20240818235847.170468-1-phillip@squashfs.org.uk:
  Squashfs: Rewrite and update squashfs_readahead_fragment() to not use page->index
  Squashfs: Update squashfs_readpage_block() to not use page->index
  Squashfs: Update squashfs_readahead() to not use page->index
  Squashfs: Update page_actor to not use page->index

Link: https://lore.kernel.org/r/20240818235847.170468-1-phillip@squashfs.org.uk


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parents 424f8cb7 fd54fa6e
Loading
Loading
Loading
Loading
+57 −27
Original line number Diff line number Diff line
@@ -494,39 +494,73 @@ static int squashfs_read_folio(struct file *file, struct folio *folio)
}

static int squashfs_readahead_fragment(struct page **page,
	unsigned int pages, unsigned int expected)
	unsigned int pages, unsigned int expected, loff_t start)
{
	struct inode *inode = page[0]->mapping->host;
	struct squashfs_cache_entry *buffer = squashfs_get_fragment(inode->i_sb,
		squashfs_i(inode)->fragment_block,
		squashfs_i(inode)->fragment_size);
	struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
	unsigned int n, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
	int error = buffer->error;
	int i, bytes, copied;
	struct squashfs_page_actor *actor;
	unsigned int offset;
	void *addr;
	struct page *last_page;

	if (error)
	if (buffer->error)
		goto out;

	expected += squashfs_i(inode)->fragment_offset;
	actor = squashfs_page_actor_init_special(msblk, page, pages,
							expected, start);
	if (!actor)
		goto out;

	for (n = 0; n < pages; n++) {
		unsigned int base = (page[n]->index & mask) << PAGE_SHIFT;
		unsigned int offset = base + squashfs_i(inode)->fragment_offset;
	squashfs_actor_nobuff(actor);
	addr = squashfs_first_page(actor);

		if (expected > offset) {
			unsigned int avail = min_t(unsigned int, expected -
				offset, PAGE_SIZE);
	for (copied = offset = 0; offset < expected; offset += PAGE_SIZE) {
		int avail = min_t(int, expected - offset, PAGE_SIZE);

			squashfs_fill_page(page[n], buffer, offset, avail);
		if (!IS_ERR(addr)) {
			bytes = squashfs_copy_data(addr, buffer, offset +
					squashfs_i(inode)->fragment_offset, avail);

			if (bytes != avail)
				goto failed;
		}

		unlock_page(page[n]);
		put_page(page[n]);
		copied += avail;
		addr = squashfs_next_page(actor);
	}

	last_page = squashfs_page_actor_free(actor);

	if (copied == expected) {
		/* Last page (if present) may have trailing bytes not filled */
		bytes = copied % PAGE_SIZE;
		if (bytes && last_page)
			memzero_page(last_page, bytes, PAGE_SIZE - bytes);

		for (i = 0; i < pages; i++) {
			flush_dcache_page(page[i]);
			SetPageUptodate(page[i]);
		}
	}

	for (i = 0; i < pages; i++) {
		unlock_page(page[i]);
		put_page(page[i]);
	}

	squashfs_cache_put(buffer);
	return 0;

failed:
	squashfs_page_actor_free(actor);

out:
	squashfs_cache_put(buffer);
	return error;
	return 1;
}

static void squashfs_readahead(struct readahead_control *ractl)
@@ -551,7 +585,6 @@ static void squashfs_readahead(struct readahead_control *ractl)
		return;

	for (;;) {
		pgoff_t index;
		int res, bsize;
		u64 block = 0;
		unsigned int expected;
@@ -570,26 +603,21 @@ 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);
							  expected, start);
			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;

		actor = squashfs_page_actor_init_special(msblk, pages, nr_pages,
							 expected);
							expected, start);
		if (!actor)
			goto skip_pages;

@@ -602,7 +630,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);

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

		start += readahead_batch_length(ractl);
	}

	kfree(pages);
+9 −8
Original line number Diff line number Diff line
@@ -23,15 +23,15 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
	int expected)

{
	struct folio *folio = page_folio(target_page);
	struct inode *inode = target_page->mapping->host;
	struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;

	loff_t file_end = (i_size_read(inode) - 1) >> PAGE_SHIFT;
	int mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
	loff_t start_index = target_page->index & ~mask;
	loff_t start_index = folio->index & ~mask;
	loff_t end_index = start_index | mask;
	int i, n, pages, bytes, res = -ENOMEM;
	struct page **page;
	struct page **page, *last_page;
	struct squashfs_page_actor *actor;
	void *pageaddr;

@@ -46,7 +46,7 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,

	/* Try to grab all the pages covered by the Squashfs block */
	for (i = 0, n = start_index; n <= end_index; n++) {
		page[i] = (n == target_page->index) ? target_page :
		page[i] = (n == folio->index) ? target_page :
			grab_cache_page_nowait(target_page->mapping, n);

		if (page[i] == NULL)
@@ -67,14 +67,15 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
	 * Create a "page actor" which will kmap and kunmap the
	 * page cache pages appropriately within the decompressor
	 */
	actor = squashfs_page_actor_init_special(msblk, page, pages, expected);
	actor = squashfs_page_actor_init_special(msblk, page, pages, expected,
						start_index << PAGE_SHIFT);
	if (actor == NULL)
		goto out;

	/* Decompress directly into the page cache buffers */
	res = squashfs_read_data(inode->i_sb, block, bsize, NULL, actor);

	squashfs_page_actor_free(actor);
	last_page = squashfs_page_actor_free(actor);

	if (res < 0)
		goto mark_errored;
@@ -86,8 +87,8 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,

	/* Last page (if present) may have trailing bytes not filled */
	bytes = res % PAGE_SIZE;
	if (page[pages - 1]->index == end_index && bytes) {
		pageaddr = kmap_local_page(page[pages - 1]);
	if (end_index == file_end && last_page && bytes) {
		pageaddr = kmap_local_page(last_page);
		memset(pageaddr + bytes, 0, PAGE_SIZE - bytes);
		kunmap_local(pageaddr);
	}
+8 −3
Original line number Diff line number Diff line
@@ -60,6 +60,11 @@ struct squashfs_page_actor *squashfs_page_actor_init(void **buffer,
}

/* Implementation of page_actor for decompressing directly into page cache. */
static loff_t page_next_index(struct squashfs_page_actor *actor)
{
	return page_folio(actor->page[actor->next_page])->index;
}

static void *handle_next_page(struct squashfs_page_actor *actor)
{
	int max_pages = (actor->length + PAGE_SIZE - 1) >> PAGE_SHIFT;
@@ -68,7 +73,7 @@ static void *handle_next_page(struct squashfs_page_actor *actor)
		return NULL;

	if ((actor->next_page == actor->pages) ||
			(actor->next_index != actor->page[actor->next_page]->index)) {
			(actor->next_index != page_next_index(actor))) {
		actor->next_index++;
		actor->returned_pages++;
		actor->last_page = NULL;
@@ -103,7 +108,7 @@ static void direct_finish_page(struct squashfs_page_actor *actor)
}

struct squashfs_page_actor *squashfs_page_actor_init_special(struct squashfs_sb_info *msblk,
	struct page **page, int pages, int length)
	struct page **page, int pages, int length, loff_t start_index)
{
	struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);

@@ -125,7 +130,7 @@ struct squashfs_page_actor *squashfs_page_actor_init_special(struct squashfs_sb_
	actor->pages = pages;
	actor->next_page = 0;
	actor->returned_pages = 0;
	actor->next_index = page[0]->index & ~((1 << (msblk->block_log - PAGE_SHIFT)) - 1);
	actor->next_index = start_index >> PAGE_SHIFT;
	actor->pageaddr = NULL;
	actor->last_page = NULL;
	actor->alloc_buffer = msblk->decompressor->alloc_buffer;
+2 −1
Original line number Diff line number Diff line
@@ -29,7 +29,8 @@ extern struct squashfs_page_actor *squashfs_page_actor_init(void **buffer,
				int pages, int length);
extern struct squashfs_page_actor *squashfs_page_actor_init_special(
				struct squashfs_sb_info *msblk,
				struct page **page, int pages, int length);
				struct page **page, int pages, int length,
				loff_t start_index);
static inline struct page *squashfs_page_actor_free(struct squashfs_page_actor *actor)
{
	struct page *last_page = actor->last_page;