Skip to content

Commit e8619bc

Browse files
ahjf-07aalexandrovich
authored andcommitted
fs/ntfs3: return folios from ntfs_lock_new_page()
ntfs_lock_new_page() currently returns a struct page * but it primarily operates on folios via __filemap_get_folio(). Convert it to return a struct folio * and use folio_alloc() + __folio_set_locked() for the temporary page used to avoid data corruption during decompression. When the cached folio is not uptodate, preserve the existing behavior by using folio_file_page() and converting the returned page back to a folio. Update ni_readpage_cmpr() and ni_decompress_file() to handle the new return type while keeping the existing struct page * array and the unlock_page()/put_page() cleanup paths unchanged. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202602072013.jwrURE2e-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202602071921.nGIiI1J5-lkp@intel.com/ Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com> [almaz.alexandrovich@paragon-software.com: removed ni_fiemap function, added reported-by and closes tags to commit] Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 3a2141b commit e8619bc

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

fs/ntfs3/frecord.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,27 +1852,31 @@ enum REPARSE_SIGN ni_parse_reparse(struct ntfs_inode *ni, struct ATTRIB *attr,
18521852
return REPARSE_LINK;
18531853
}
18541854

1855-
static struct page *ntfs_lock_new_page(struct address_space *mapping,
1856-
pgoff_t index, gfp_t gfp)
1855+
static struct folio *ntfs_lock_new_page(struct address_space *mapping,
1856+
pgoff_t index, gfp_t gfp)
18571857
{
1858-
struct folio *folio = __filemap_get_folio(
1859-
mapping, index, FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
1860-
struct page *page;
1858+
struct folio *folio = __filemap_get_folio(mapping, index,
1859+
FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
18611860

18621861
if (IS_ERR(folio))
1863-
return ERR_CAST(folio);
1862+
return folio;
18641863

1865-
if (!folio_test_uptodate(folio))
1866-
return folio_file_page(folio, index);
1864+
if (!folio_test_uptodate(folio)) {
1865+
struct page *page = folio_file_page(folio, index);
1866+
1867+
if (IS_ERR(page))
1868+
return ERR_CAST(page);
1869+
return page_folio(page);
1870+
}
18671871

18681872
/* Use a temporary page to avoid data corruption */
18691873
folio_unlock(folio);
18701874
folio_put(folio);
1871-
page = alloc_page(gfp);
1872-
if (!page)
1875+
folio = folio_alloc(gfp, 0);
1876+
if (!folio)
18731877
return ERR_PTR(-ENOMEM);
1874-
__SetPageLocked(page);
1875-
return page;
1878+
__folio_set_locked(folio);
1879+
return folio;
18761880
}
18771881

18781882
/*
@@ -1894,6 +1898,7 @@ int ni_read_folio_cmpr(struct ntfs_inode *ni, struct folio *folio)
18941898
u32 i, idx, frame_size, pages_per_frame;
18951899
gfp_t gfp_mask;
18961900
struct page *pg;
1901+
struct folio *f;
18971902

18981903
if (vbo >= i_size_read(&ni->vfs_inode)) {
18991904
folio_zero_range(folio, 0, folio_size(folio));
@@ -1929,12 +1934,12 @@ int ni_read_folio_cmpr(struct ntfs_inode *ni, struct folio *folio)
19291934
if (i == idx)
19301935
continue;
19311936

1932-
pg = ntfs_lock_new_page(mapping, index, gfp_mask);
1933-
if (IS_ERR(pg)) {
1934-
err = PTR_ERR(pg);
1937+
f = ntfs_lock_new_page(mapping, index, gfp_mask);
1938+
if (IS_ERR(f)) {
1939+
err = PTR_ERR(f);
19351940
goto out1;
19361941
}
1937-
pages[i] = pg;
1942+
pages[i] = &f->page;
19381943
}
19391944

19401945
ni_lock(ni);
@@ -2023,18 +2028,18 @@ int ni_decompress_file(struct ntfs_inode *ni)
20232028
}
20242029

20252030
for (i = 0; i < pages_per_frame; i++, index++) {
2026-
struct page *pg;
2031+
struct folio *f;
20272032

2028-
pg = ntfs_lock_new_page(mapping, index, gfp_mask);
2029-
if (IS_ERR(pg)) {
2033+
f = ntfs_lock_new_page(mapping, index, gfp_mask);
2034+
if (IS_ERR(f)) {
20302035
while (i--) {
20312036
unlock_page(pages[i]);
20322037
put_page(pages[i]);
20332038
}
2034-
err = PTR_ERR(pg);
2039+
err = PTR_ERR(f);
20352040
goto out;
20362041
}
2037-
pages[i] = pg;
2042+
pages[i] = &f->page;
20382043
}
20392044

20402045
err = ni_read_frame(ni, vbo, pages, pages_per_frame, 1);

0 commit comments

Comments
 (0)