Skip to content

Commit 425c8bb

Browse files
lorenzo-stoakesbrauner
authored andcommitted
doc: update porting, vfs documentation to describe mmap_prepare()
Now that we have established .mmap_prepare() as the preferred means by which filesystems establish state upon memory mapping of a file, update the VFS and porting documentation to reflect this. As part of this change, additionally update the VFS documentation to contain the current state of the file_operations struct. Signed-off-by: Lorenzo Stoakes <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 738a6cf commit 425c8bb

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Documentation/filesystems/porting.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,3 +1249,15 @@ Using try_lookup_noperm() will require linux/namei.h to be included.
12491249

12501250
Calling conventions for ->d_automount() have changed; we should *not* grab
12511251
an extra reference to new mount - it should be returned with refcount 1.
1252+
1253+
---
1254+
1255+
**highly recommended**
1256+
1257+
The file operations mmap() callback is deprecated in favour of
1258+
mmap_prepare(). This passes a pointer to a vm_area_desc to the callback
1259+
rather than a VMA, as the VMA at this stage is not yet valid.
1260+
1261+
The vm_area_desc provides the minimum required information for a filesystem
1262+
to initialise state upon memory mapping of a file-backed region, and output
1263+
parameters for the file system to set this state.

Documentation/filesystems/vfs.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,14 @@ This describes how the VFS can manipulate an open file. As of kernel
10711071
10721072
struct file_operations {
10731073
struct module *owner;
1074+
fop_flags_t fop_flags;
10741075
loff_t (*llseek) (struct file *, loff_t, int);
10751076
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
10761077
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
10771078
ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
10781079
ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
1079-
int (*iopoll)(struct kiocb *kiocb, bool spin);
1080+
int (*iopoll)(struct kiocb *kiocb, struct io_comp_batch *,
1081+
unsigned int flags);
10801082
int (*iterate_shared) (struct file *, struct dir_context *);
10811083
__poll_t (*poll) (struct file *, struct poll_table_struct *);
10821084
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
@@ -1093,18 +1095,24 @@ This describes how the VFS can manipulate an open file. As of kernel
10931095
int (*flock) (struct file *, int, struct file_lock *);
10941096
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
10951097
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1096-
int (*setlease)(struct file *, long, struct file_lock **, void **);
1098+
void (*splice_eof)(struct file *file);
1099+
int (*setlease)(struct file *, int, struct file_lease **, void **);
10971100
long (*fallocate)(struct file *file, int mode, loff_t offset,
10981101
loff_t len);
10991102
void (*show_fdinfo)(struct seq_file *m, struct file *f);
11001103
#ifndef CONFIG_MMU
11011104
unsigned (*mmap_capabilities)(struct file *);
11021105
#endif
1103-
ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int);
1106+
ssize_t (*copy_file_range)(struct file *, loff_t, struct file *,
1107+
loff_t, size_t, unsigned int);
11041108
loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in,
11051109
struct file *file_out, loff_t pos_out,
11061110
loff_t len, unsigned int remap_flags);
11071111
int (*fadvise)(struct file *, loff_t, loff_t, int);
1112+
int (*uring_cmd)(struct io_uring_cmd *ioucmd, unsigned int issue_flags);
1113+
int (*uring_cmd_iopoll)(struct io_uring_cmd *, struct io_comp_batch *,
1114+
unsigned int poll_flags);
1115+
int (*mmap_prepare)(struct vm_area_desc *);
11081116
};
11091117
11101118
Again, all methods are called without any locks being held, unless
@@ -1144,7 +1152,8 @@ otherwise noted.
11441152
used on 64 bit kernels.
11451153

11461154
``mmap``
1147-
called by the mmap(2) system call
1155+
called by the mmap(2) system call. Deprecated in favour of
1156+
``mmap_prepare``.
11481157

11491158
``open``
11501159
called by the VFS when an inode should be opened. When the VFS
@@ -1221,6 +1230,11 @@ otherwise noted.
12211230
``fadvise``
12221231
possibly called by the fadvise64() system call.
12231232

1233+
``mmap_prepare``
1234+
Called by the mmap(2) system call. Allows a VFS to set up a
1235+
file-backed memory mapping, most notably establishing relevant
1236+
private state and VMA callbacks.
1237+
12241238
Note that the file operations are implemented by the specific
12251239
filesystem in which the inode resides. When opening a device node
12261240
(character or block special) most filesystems will call special

0 commit comments

Comments
 (0)