ocfs2: convert ocfs2_duplicate_clusters_by_page() to use a folio

Retrieve folios from the page cache, not pages, and use a folio throughout
this function.  Removes seven calls to compound_head().

Link: https://lkml.kernel.org/r/20241205171653.3179945-18-willy@infradead.org
Signed-off-by: Mark Tinguely <mark.tinguely@oracle.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Mark Fasheh <mark@fasheh.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Mark Tinguely 2024-12-05 17:16:45 +00:00 committed by Andrew Morton
parent 9a5e08652d
commit 395ea2ab46

View File

@ -2902,7 +2902,6 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
int ret = 0, partial;
struct super_block *sb = inode->i_sb;
u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
struct page *page;
pgoff_t page_index;
unsigned int from, to;
loff_t offset, end, map_end;
@ -2921,6 +2920,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
end = i_size_read(inode);
while (offset < end) {
struct folio *folio;
page_index = offset >> PAGE_SHIFT;
map_end = ((loff_t)page_index + 1) << PAGE_SHIFT;
if (map_end > end)
@ -2933,9 +2933,10 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
to = map_end & (PAGE_SIZE - 1);
retry:
page = find_or_create_page(mapping, page_index, GFP_NOFS);
if (!page) {
ret = -ENOMEM;
folio = __filemap_get_folio(mapping, page_index,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT, GFP_NOFS);
if (IS_ERR(folio)) {
ret = PTR_ERR(folio);
mlog_errno(ret);
break;
}
@ -2945,9 +2946,9 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
* page, so write it back.
*/
if (PAGE_SIZE <= OCFS2_SB(sb)->s_clustersize) {
if (PageDirty(page)) {
unlock_page(page);
put_page(page);
if (folio_test_dirty(folio)) {
folio_unlock(folio);
folio_put(folio);
ret = filemap_write_and_wait_range(mapping,
offset, map_end - 1);
@ -2955,9 +2956,7 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
}
}
if (!PageUptodate(page)) {
struct folio *folio = page_folio(page);
if (!folio_test_uptodate(folio)) {
ret = block_read_full_folio(folio, ocfs2_get_block);
if (ret) {
mlog_errno(ret);
@ -2966,8 +2965,8 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
folio_lock(folio);
}
if (page_has_buffers(page)) {
ret = walk_page_buffers(handle, page_buffers(page),
if (folio_buffers(folio)) {
ret = walk_page_buffers(handle, folio_buffers(folio),
from, to, &partial,
ocfs2_clear_cow_buffer);
if (ret) {
@ -2978,12 +2977,11 @@ int ocfs2_duplicate_clusters_by_page(handle_t *handle,
ocfs2_map_and_dirty_page(inode,
handle, from, to,
page, 0, &new_block);
mark_page_accessed(page);
&folio->page, 0, &new_block);
folio_mark_accessed(folio);
unlock:
unlock_page(page);
put_page(page);
page = NULL;
folio_unlock(folio);
folio_put(folio);
offset = map_end;
if (ret)
break;