[PATCH v4 05/10] ceph: convert get_writepages_data_length() to folios

From: Tal Zussman

Date: Mon Aug 17 2026 - 15:20:13 EST


Introduce ceph_fscrypt_pagecache_folio() and ceph_fscrypt_folio_offset(),
folio equivalents of ceph_fscrypt_pagecache_page() and
ceph_fscrypt_page_offset(), and use them to convert
get_writepages_data_length() to folios.

This removes the last caller of page_snap_context(), so remove it as
well. This also removes a use of page->private and a call to
fscrypt_is_bounce_page().

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/ceph/addr.c | 25 +++++++++----------------
fs/ceph/crypto.h | 15 +++++++++++++++
2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 5efc8c7c91df..a34849374f65 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -29,9 +29,9 @@
*
* There are a few funny things going on here.
*
- * The page->private field is used to reference a struct
- * ceph_snap_context for _every_ dirty page. This indicates which
- * snapshot the page was logically dirtied in, and thus which snap
+ * The folio->private field is used to reference a struct
+ * ceph_snap_context for _every_ dirty folio. This indicates which
+ * snapshot the folio was logically dirtied in, and thus which snap
* context needs to be associated with the osd write during writeback.
*
* Similarly, struct ceph_inode_info maintains a set of counters to
@@ -68,13 +68,6 @@
static int ceph_netfs_check_write_begin(struct file *file, loff_t pos, unsigned int len,
struct folio **foliop, void **_fsdata);

-static inline struct ceph_snap_context *page_snap_context(struct page *page)
-{
- if (PagePrivate(page))
- return (void *)page->private;
- return NULL;
-}
-
static inline
struct ceph_snap_context *ceph_folio_snap_context(const struct folio *folio)
{
@@ -701,7 +694,7 @@ get_oldest_context(struct inode *inode, struct ceph_writeback_ctl *ctl,
}

static u64 get_writepages_data_length(struct inode *inode,
- struct page *page, u64 start)
+ struct folio *folio, u64 start)
{
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_snap_context *snapc;
@@ -709,7 +702,7 @@ static u64 get_writepages_data_length(struct inode *inode,
u64 end = i_size_read(inode);
u64 ret;

- snapc = page_snap_context(ceph_fscrypt_pagecache_page(page));
+ snapc = ceph_folio_snap_context(ceph_fscrypt_pagecache_folio(folio));
if (snapc != ci->i_head_snapc) {
bool found = false;
spin_lock(&ci->i_ceph_lock);
@@ -724,10 +717,10 @@ static u64 get_writepages_data_length(struct inode *inode,
spin_unlock(&ci->i_ceph_lock);
WARN_ON(!found);
}
- if (end > ceph_fscrypt_page_offset(page) + thp_size(page))
- end = ceph_fscrypt_page_offset(page) + thp_size(page);
+ if (end > ceph_fscrypt_folio_offset(folio) + folio_size(folio))
+ end = ceph_fscrypt_folio_offset(folio) + folio_size(folio);
ret = end > start ? end - start : 0;
- if (ret && fscrypt_is_bounce_page(page))
+ if (ret && fscrypt_is_bounce_folio(folio))
ret = round_up(ret, CEPH_FSCRYPT_BLOCK_SIZE);
return ret;
}
@@ -1589,7 +1582,7 @@ int ceph_submit_write(struct address_space *mapping,
* data length covers all locked pages */
u64 min_len = len + 1 - thp_size(page);
len = get_writepages_data_length(inode,
- ceph_wbc->pages[i - 1],
+ page_folio(ceph_wbc->pages[i - 1]),
offset);
len = max(len, min_len);
}
diff --git a/fs/ceph/crypto.h b/fs/ceph/crypto.h
index 79cb563fd887..948c8b5dca06 100644
--- a/fs/ceph/crypto.h
+++ b/fs/ceph/crypto.h
@@ -162,6 +162,11 @@ static inline struct page *ceph_fscrypt_pagecache_page(struct page *page)
return fscrypt_is_bounce_page(page) ? fscrypt_pagecache_page(page) : page;
}

+static inline struct folio *ceph_fscrypt_pagecache_folio(struct folio *folio)
+{
+ return fscrypt_is_bounce_folio(folio) ? fscrypt_pagecache_folio(folio) : folio;
+}
+
#else /* CONFIG_FS_ENCRYPTION */

static inline void ceph_fscrypt_set_ops(struct super_block *sb)
@@ -262,6 +267,11 @@ static inline struct page *ceph_fscrypt_pagecache_page(struct page *page)
{
return page;
}
+
+static inline struct folio *ceph_fscrypt_pagecache_folio(struct folio *folio)
+{
+ return folio;
+}
#endif /* CONFIG_FS_ENCRYPTION */

static inline loff_t ceph_fscrypt_page_offset(struct page *page)
@@ -269,4 +279,9 @@ static inline loff_t ceph_fscrypt_page_offset(struct page *page)
return page_offset(ceph_fscrypt_pagecache_page(page));
}

+static inline loff_t ceph_fscrypt_folio_offset(struct folio *folio)
+{
+ return folio_pos(ceph_fscrypt_pagecache_folio(folio));
+}
+
#endif /* _CEPH_CRYPTO_H */

--
2.39.5