Skip to content

Commit 5e9b50d

Browse files
committed
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/[email protected] Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 1146e5a commit 5e9b50d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

fs/file_table.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ static int init_file(struct file *f, int flags, const struct cred *cred)
156156
}
157157

158158
spin_lock_init(&f->f_lock);
159+
/*
160+
* Note that f_pos_lock is only used for files raising
161+
* FMODE_ATOMIC_POS and directories. Other files such as pipes
162+
* don't need it and since f_pos_lock is in a union may reuse
163+
* the space for other purposes. They are expected to initialize
164+
* the respective member when opening the file.
165+
*/
159166
mutex_init(&f->f_pos_lock);
160167
f->f_flags = flags;
161168
f->f_mode = OPEN_FMODE(flags);

include/linux/fs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
10011001
* @f_cred: stashed credentials of creator/opener
10021002
* @f_path: path of the file
10031003
* @f_pos_lock: lock protecting file position
1004+
* @f_pipe: specific to pipes
10041005
* @f_pos: file position
10051006
* @f_version: file version
10061007
* @f_security: LSM security context of this file
@@ -1026,7 +1027,12 @@ struct file {
10261027
const struct cred *f_cred;
10271028
/* --- cacheline 1 boundary (64 bytes) --- */
10281029
struct path f_path;
1029-
struct mutex f_pos_lock;
1030+
union {
1031+
/* regular files (with FMODE_ATOMIC_POS) and directories */
1032+
struct mutex f_pos_lock;
1033+
/* pipes */
1034+
u64 f_pipe;
1035+
};
10301036
loff_t f_pos;
10311037
u64 f_version;
10321038
/* --- cacheline 2 boundary (128 bytes) --- */

0 commit comments

Comments
 (0)