[PATCH -next 2/2] squashfs: convert squashfs_read_folio to use folio APIs

From: Li Zetao
Date: Sat Aug 17 2024 - 06:04:47 EST


In order to remote page APIs and index field in structure page [1],
this patch convert squashfs_read_folio to use folio APIs, switch from
kmap_atomic to kmap_local and use folio_end_read() to set uptodate
and unlock folio.

[1]: https://lore.kernel.org/all/Zp8fgUSIBGQ1TN0D@xxxxxxxxxxxxxxxxxxxx/

Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Signed-off-by: Li Zetao <lizetao1@xxxxxxxxxx>
---
fs/squashfs/file.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index 893043ecf973..8c80d77a6115 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -446,10 +446,9 @@ static int squashfs_readpage_sparse(struct page *page, int expected)

static int squashfs_read_folio(struct file *file, struct folio *folio)
{
- struct page *page = &folio->page;
- struct inode *inode = page->mapping->host;
+ struct inode *inode = folio_inode(folio);
struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
- int index = page->index >> (msblk->block_log - PAGE_SHIFT);
+ int index = folio->index >> (msblk->block_log - PAGE_SHIFT);
int file_end = i_size_read(inode) >> msblk->block_log;
int expected = index == file_end ?
(i_size_read(inode) & (msblk->block_size - 1)) :
@@ -457,10 +456,10 @@ static int squashfs_read_folio(struct file *file, struct folio *folio)
int res = 0;
void *pageaddr;

- TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
- page->index, squashfs_i(inode)->start);
+ TRACE("Entered squashfs_readpage, folio index %lx, start block %llx\n",
+ folio->index, squashfs_i(inode)->start);

- if (page->index >= ((i_size_read(inode) + PAGE_SIZE - 1) >>
+ if (folio->index >= ((i_size_read(inode) + PAGE_SIZE - 1) >>
PAGE_SHIFT))
goto out;

@@ -473,23 +472,21 @@ static int squashfs_read_folio(struct file *file, struct folio *folio)
goto out;

if (res == 0)
- res = squashfs_readpage_sparse(page, expected);
+ res = squashfs_readpage_sparse(&folio->page, expected);
else
- res = squashfs_readpage_block(page, block, res, expected);
+ res = squashfs_readpage_block(&folio->page, block, res, expected);
} else
- res = squashfs_readpage_fragment(page, expected);
+ res = squashfs_readpage_fragment(&folio->page, expected);

if (!res)
return 0;

out:
- pageaddr = kmap_atomic(page);
+ pageaddr = kmap_local_folio(folio, 0);
memset(pageaddr, 0, PAGE_SIZE);
- kunmap_atomic(pageaddr);
- flush_dcache_page(page);
- if (res == 0)
- SetPageUptodate(page);
- unlock_page(page);
+ kunmap_local(pageaddr);
+ flush_dcache_folio(folio);
+ folio_end_read(folio, res == 0);

return res;
}
--
2.34.1