vfs: don't unnecessarily clone write access for writable fds
Subsystems (2)
PATCH v3 1/1 vfs: don't unnecessarily clone write access for writable fds
From: Eric Biggers <[email protected]>
There's no need for mnt_want_write_file() to increment mnt_writers when the file is already open for writing, provided that mnt_drop_write_file() is changed to conditionally decrement it.
We seem to have ended up in the current situation because mnt_want_write_file() used to be paired with mnt_drop_write(), due to mnt_drop_write_file() not having been added yet. So originally mnt_want_write_file() had to always increment mnt_writers.
But later mnt_drop_write_file() was added, and all callers of mnt_want_write_file() were paired with it. This makes the compatibility between mnt_want_write_file() and mnt_drop_write() no longer necessary.
Therefore, make __mnt_want_write_file() and __mnt_drop_write_file() skip incrementing mnt_writers on files already open for writing. This removes the only caller of mnt_clone_write(), so remove that too.
---
v3: added note to porting file.
v2: keep the check for emergency r/o remounts.
Documentation/filesystems/porting.rst | 7 ++++ fs/namespace.c | 53 ++++++++++----------------- include/linux/mount.h | 1 - 3 files changed, 27 insertions(+), 34 deletions(-)
Documentation/filesystems/porting.rst +7 -0
@@ -865,3 +865,10 @@ no matter what. Everything is handled by the caller. clone_private_mount() returns a longterm mount now, so the proper destructor of its result is kern_unmount() or kern_unmount_array(). + +--- + +**mandatory** + +mnt_want_write_file() can now only be paired with mnt_drop_write_file(), +whereas previously it could be paired with mnt_drop_write() as well.
fs/namespace.c +20 -33
78 lines not on this page · raw message
include/linux/mount.h +0 -1
@@ -78,7 +78,6 @@ struct path;extern int mnt_want_write (struct vfsmount *mnt);extern int mnt_want_write_file (struct file *file); -extern int mnt_clone_write (struct vfsmount *mnt);extern void mnt_drop_write (struct vfsmount *mnt);extern void mnt_drop_write_file (struct file *file);extern void mntput (struct vfsmount *mnt);
Signature · 1 line
2.28.0
Quoted 22 lines · Eric Biggers
From: Eric Biggers <[email protected]>
There's no need for
mnt_want_write_file()to incrementmnt_writerswhen the file is already open for writing, provided thatmnt_drop_write_file()is changed to conditionally decrement it.We seem to have ended up in the current situation because
mnt_want_write_file()used to be paired withmnt_drop_write(), due tomnt_drop_write_file()not having been added yet. So originallymnt_want_write_file()had to always incrementmnt_writers.But later
mnt_drop_write_file()was added, and all callers ofmnt_want_write_file()were paired with it. This makes the compatibility betweenmnt_want_write_file()andmnt_drop_write()no longer necessary.Therefore, make
__mnt_want_write_file()and__mnt_drop_write_file()skip incrementingmnt_writerson files already open for writing. This removes the only caller ofmnt_clone_write(), so remove that too.Signed-off-by Eric Biggers <[email protected]>---
Quoted 7 lines
v3: added note to porting file.
v2: keep the check for emergency r/o remounts.Documentation/filesystems/porting.rst | 7 ++++ fs/namespace.c | 53 ++++++++++----------------- include/linux/mount.h | 1 - 3 files changed, 27 insertions(+), 34 deletions(-)
Ping.
Quoted 26 lines · Eric Biggers
Quoted 25 lines · Eric Biggers
From: Eric Biggers <[email protected]>
There's no need for
mnt_want_write_file()to incrementmnt_writerswhen the file is already open for writing, provided thatmnt_drop_write_file()is changed to conditionally decrement it.We seem to have ended up in the current situation because
mnt_want_write_file()used to be paired withmnt_drop_write(), due tomnt_drop_write_file()not having been added yet. So originallymnt_want_write_file()had to always incrementmnt_writers.But later
mnt_drop_write_file()was added, and all callers ofmnt_want_write_file()were paired with it. This makes the compatibility betweenmnt_want_write_file()andmnt_drop_write()no longer necessary.Therefore, make
__mnt_want_write_file()and__mnt_drop_write_file()skip incrementingmnt_writerson files already open for writing. This removes the only caller ofmnt_clone_write(), so remove that too.Signed-off-by Eric Biggers <[email protected]>---
v3: added note to porting file.
v2: keep the check for emergency r/o remounts.
Quoted 6 lines
Quoted 4 lines
Documentation/filesystems/porting.rst | 7 ++++ fs/namespace.c | 53 ++++++++++----------------- include/linux/mount.h | 1 - 3 files changed, 27 insertions(+), 34 deletions(-)Ping.
Applied.