Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

squashfs; convert squashfs_copy_cache() to take a folio

Remove accesses to page->index and page->mapping. Also use folio
APIs where available. This code still assumes order 0 folios.

[dan.carpenter@linaro.org: fix a NULL vs IS_ERR() bug]
Link: https://lkml.kernel.org/r/7b7f44d6-9153-4d7c-b65b-2d78febe6c7a@stanley.mountain
Link: https://lkml.kernel.org/r/20241220224634.723899-4-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Phillip Lougher <phillip@squashfs.org.uk>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
5641371f 2a7aea59

+28 -24
+25 -21
fs/squashfs/file.c
··· 378 378 } 379 379 380 380 /* Copy data into page cache */ 381 - void squashfs_copy_cache(struct page *page, struct squashfs_cache_entry *buffer, 382 - int bytes, int offset) 381 + void squashfs_copy_cache(struct folio *folio, 382 + struct squashfs_cache_entry *buffer, size_t bytes, 383 + size_t offset) 383 384 { 384 - struct inode *inode = page->mapping->host; 385 + struct address_space *mapping = folio->mapping; 386 + struct inode *inode = mapping->host; 385 387 struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info; 386 388 int i, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1; 387 - int start_index = page->index & ~mask, end_index = start_index | mask; 389 + int start_index = folio->index & ~mask, end_index = start_index | mask; 388 390 389 391 /* 390 392 * Loop copying datablock into pages. As the datablock likely covers ··· 396 394 */ 397 395 for (i = start_index; i <= end_index && bytes > 0; i++, 398 396 bytes -= PAGE_SIZE, offset += PAGE_SIZE) { 399 - struct page *push_page; 400 - int avail = buffer ? min_t(int, bytes, PAGE_SIZE) : 0; 397 + struct folio *push_folio; 398 + size_t avail = buffer ? min(bytes, PAGE_SIZE) : 0; 401 399 402 - TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail); 400 + TRACE("bytes %zu, i %d, available_bytes %zu\n", bytes, i, avail); 403 401 404 - push_page = (i == page->index) ? page : 405 - grab_cache_page_nowait(page->mapping, i); 402 + push_folio = (i == folio->index) ? folio : 403 + __filemap_get_folio(mapping, i, 404 + FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT, 405 + mapping_gfp_mask(mapping)); 406 406 407 - if (!push_page) 407 + if (IS_ERR(push_folio)) 408 408 continue; 409 409 410 - if (PageUptodate(push_page)) 411 - goto skip_page; 410 + if (folio_test_uptodate(push_folio)) 411 + goto skip_folio; 412 412 413 - squashfs_fill_page(push_page, buffer, offset, avail); 414 - skip_page: 415 - unlock_page(push_page); 416 - if (i != page->index) 417 - put_page(push_page); 413 + squashfs_fill_page(&push_folio->page, buffer, offset, avail); 414 + skip_folio: 415 + folio_unlock(push_folio); 416 + if (i != folio->index) 417 + folio_put(push_folio); 418 418 } 419 419 } 420 420 ··· 434 430 squashfs_i(inode)->fragment_block, 435 431 squashfs_i(inode)->fragment_size); 436 432 else 437 - squashfs_copy_cache(&folio->page, buffer, expected, 433 + squashfs_copy_cache(folio, buffer, expected, 438 434 squashfs_i(inode)->fragment_offset); 439 435 440 436 squashfs_cache_put(buffer); 441 437 return res; 442 438 } 443 439 444 - static int squashfs_readpage_sparse(struct page *page, int expected) 440 + static int squashfs_readpage_sparse(struct folio *folio, int expected) 445 441 { 446 - squashfs_copy_cache(page, NULL, expected, 0); 442 + squashfs_copy_cache(folio, NULL, expected, 0); 447 443 return 0; 448 444 } 449 445 ··· 474 470 goto out; 475 471 476 472 if (res == 0) 477 - res = squashfs_readpage_sparse(&folio->page, expected); 473 + res = squashfs_readpage_sparse(folio, expected); 478 474 else 479 475 res = squashfs_readpage_block(folio, block, res, expected); 480 476 } else
+1 -1
fs/squashfs/file_cache.c
··· 29 29 ERROR("Unable to read page, block %llx, size %x\n", block, 30 30 bsize); 31 31 else 32 - squashfs_copy_cache(&folio->page, buffer, expected, 0); 32 + squashfs_copy_cache(folio, buffer, expected, 0); 33 33 34 34 squashfs_cache_put(buffer); 35 35 return res;
+2 -2
fs/squashfs/squashfs.h
··· 74 74 75 75 /* file.c */ 76 76 void squashfs_fill_page(struct page *, struct squashfs_cache_entry *, int, int); 77 - void squashfs_copy_cache(struct page *, struct squashfs_cache_entry *, int, 78 - int); 77 + void squashfs_copy_cache(struct folio *, struct squashfs_cache_entry *, 78 + size_t bytes, size_t offset); 79 79 80 80 /* file_xxx.c */ 81 81 int squashfs_readpage_block(struct folio *, u64 block, int bsize, int expected);