Skip to content

Commit 8c90ae8

Browse files
ljskernelbrauner
authored andcommitted
fs/ext4: transition from deprecated .mmap hook to .mmap_prepare
Since commit c84bf6d ("mm: introduce new .mmap_prepare() file callback"), the f_op->mmap() hook has been deprecated in favour of f_op->mmap_prepare(). This callback is invoked in the mmap() logic far earlier, so error handling can be performed more safely without complicated and bug-prone state unwinding required should an error arise. This hook also avoids passing a pointer to a not-yet-correctly-established VMA avoiding any issues with referencing this data structure. It rather provides a pointer to the new struct vm_area_desc descriptor type which contains all required state and allows easy setting of required parameters without any consideration needing to be paid to locking or reference counts. Note that nested filesystems like overlayfs are compatible with an .mmap_prepare() callback since commit bb666b7 ("mm: add mmap_prepare() compatibility layer for nested file systems"). Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Link: https://lore.kernel.org/5abfe526032a6698fd1bcd074a74165cda7ea57c.1750099179.git.lorenzo.stoakes@oracle.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 0335f6a commit 8c90ae8

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

fs/ext4/file.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,10 @@ static const struct vm_operations_struct ext4_file_vm_ops = {
804804
.page_mkwrite = ext4_page_mkwrite,
805805
};
806806

807-
static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
807+
static int ext4_file_mmap_prepare(struct vm_area_desc *desc)
808808
{
809809
int ret;
810+
struct file *file = desc->file;
810811
struct inode *inode = file->f_mapping->host;
811812
struct dax_device *dax_dev = EXT4_SB(inode->i_sb)->s_daxdev;
812813

@@ -821,15 +822,15 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
821822
* We don't support synchronous mappings for non-DAX files and
822823
* for DAX files if underneath dax_device is not synchronous.
823824
*/
824-
if (!daxdev_mapping_supported(vma->vm_flags, file_inode(vma->vm_file), dax_dev))
825+
if (!daxdev_mapping_supported(desc->vm_flags, file_inode(file), dax_dev))
825826
return -EOPNOTSUPP;
826827

827828
file_accessed(file);
828829
if (IS_DAX(file_inode(file))) {
829-
vma->vm_ops = &ext4_dax_vm_ops;
830-
vm_flags_set(vma, VM_HUGEPAGE);
830+
desc->vm_ops = &ext4_dax_vm_ops;
831+
desc->vm_flags |= VM_HUGEPAGE;
831832
} else {
832-
vma->vm_ops = &ext4_file_vm_ops;
833+
desc->vm_ops = &ext4_file_vm_ops;
833834
}
834835
return 0;
835836
}
@@ -968,7 +969,7 @@ const struct file_operations ext4_file_operations = {
968969
#ifdef CONFIG_COMPAT
969970
.compat_ioctl = ext4_compat_ioctl,
970971
#endif
971-
.mmap = ext4_file_mmap,
972+
.mmap_prepare = ext4_file_mmap_prepare,
972973
.open = ext4_file_open,
973974
.release = ext4_release_file,
974975
.fsync = ext4_sync_file,

0 commit comments

Comments
 (0)