Expose preparation steps for truncate_inode_pages_final() to allow preparation steps to be shared by filesystems that want to implement truncation differently.
This preparation function will be used by guest_memfd in a later patch. Signed-off-by: Ackerley Tng <[email protected]> --- include/linux/mm.h | 1 + mm/truncate.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f0d5be9dc7368..7f04f1eaab15a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3732,6 +3732,7 @@ extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info); void truncate_inode_pages(struct address_space *mapping, loff_t lstart); void truncate_inode_pages_range(struct address_space *mapping, loff_t lstart, uoff_t lend); +void truncate_inode_pages_final_prepare(struct address_space *mapping); void truncate_inode_pages_final(struct address_space *mapping); /* generic vm_area_ops exported for stackable file systems */ diff --git a/mm/truncate.c b/mm/truncate.c index 12467c1bd711e..0e85d5451adbe 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -487,7 +487,9 @@ void truncate_inode_pages(struct address_space *mapping, loff_t lstart) EXPORT_SYMBOL(truncate_inode_pages); /** - * truncate_inode_pages_final - truncate *all* pages before inode dies + * truncate_inode_pages_final_prepare - Prepare the mapping for final + * truncation but not actually truncate the inode pages. This could be + * used by filesystems which want to add custom truncation of folios. * @mapping: mapping to truncate * * Called under (and serialized by) inode->i_rwsem. @@ -495,7 +497,7 @@ EXPORT_SYMBOL(truncate_inode_pages); * Filesystems have to use this in the .evict_inode path to inform the * VM that this is the final truncate and the inode is going away. */ -void truncate_inode_pages_final(struct address_space *mapping) +void truncate_inode_pages_final_prepare(struct address_space *mapping) { /* * Page reclaim can not participate in regular inode lifetime @@ -516,6 +518,21 @@ void truncate_inode_pages_final(struct address_space *mapping) xa_lock_irq(&mapping->i_pages); xa_unlock_irq(&mapping->i_pages); } +} +EXPORT_SYMBOL(truncate_inode_pages_final_prepare); + +/** + * truncate_inode_pages_final - truncate *all* pages before inode dies + * @mapping: mapping to truncate + * + * Called under (and serialized by) inode->i_rwsem. + * + * Filesystems have to use this in the .evict_inode path to inform the + * VM that this is the final truncate and the inode is going away. + */ +void truncate_inode_pages_final(struct address_space *mapping) +{ + truncate_inode_pages_final_prepare(mapping); truncate_inode_pages(mapping, 0); } -- 2.53.0.345.g96ddfc5eaa-goog

