summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-08-30 15:04:59 +0200
committerChristian Brauner <brauner@kernel.org>2024-09-12 11:58:45 +0200
commit5e9b50dea970ae6d3e1309d4254157099734a2af (patch)
tree89f9d1704d813436a4125ebc615a4dd0278578a6
parent1146e5a69efca76501378f748388fd7742ad09cf (diff)
fs: add f_pipe
Only regular files with FMODE_ATOMIC_POS and directories need f_pos_lock. Place a new f_pipe member in a union with f_pos_lock that they can use and make them stop abusing f_version in follow-up patches. Link: https://lore.kernel.org/r/20240830-vfs-file-f_version-v1-18-6d3e4816aa7b@kernel.org Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
-rw-r--r--fs/file_table.c7
-rw-r--r--include/linux/fs.h8
2 files changed, 14 insertions, 1 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index 3ef558f27a1c..7ce4d5dac080 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -156,6 +156,13 @@ static int init_file(struct file *f, int flags, const struct cred *cred)
}
spin_lock_init(&f->f_lock);
+ /*
+ * Note that f_pos_lock is only used for files raising
+ * FMODE_ATOMIC_POS and directories. Other files such as pipes
+ * don't need it and since f_pos_lock is in a union may reuse
+ * the space for other purposes. They are expected to initialize
+ * the respective member when opening the file.
+ */
mutex_init(&f->f_pos_lock);
f->f_flags = flags;
f->f_mode = OPEN_FMODE(flags);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3e6b3c1afb31..ca4925008244 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1001,6 +1001,7 @@ static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
* @f_cred: stashed credentials of creator/opener
* @f_path: path of the file
* @f_pos_lock: lock protecting file position
+ * @f_pipe: specific to pipes
* @f_pos: file position
* @f_version: file version
* @f_security: LSM security context of this file
@@ -1026,7 +1027,12 @@ struct file {
const struct cred *f_cred;
/* --- cacheline 1 boundary (64 bytes) --- */
struct path f_path;
- struct mutex f_pos_lock;
+ union {
+ /* regular files (with FMODE_ATOMIC_POS) and directories */
+ struct mutex f_pos_lock;
+ /* pipes */
+ u64 f_pipe;
+ };
loff_t f_pos;
u64 f_version;
/* --- cacheline 2 boundary (128 bytes) --- */