include/linux/fs.h: add inode_lock_killable()
PATCH v2 1/4 include/linux/fs.h: add inode_lock_killable()
Prepare for making inode operations killable while they're waiting for the lock.
--- include/linux/fs.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/fs.h +10 -0
@@ -867,6 +867,11 @@ static inline void inode_lock(struct inode *inode)down_write (&inode->i_rwsem); } +static inline __must_check int inode_lock_killable (struct inode *inode) +{ +return down_write_killable (&inode->i_rwsem); +} +static inline void inode_unlock (struct inode *inode) {up_write (&inode->i_rwsem);
@@ -877,6 +882,11 @@ static inline void inode_lock_shared(struct inode *inode)down_read (&inode->i_rwsem); } +static inline __must_check int inode_lock_shared_killable (struct inode *inode) +{ +return down_read_killable (&inode->i_rwsem); +} +static inline void inode_unlock_shared (struct inode *inode) {up_read (&inode->i_rwsem);
Signature · 1 line
2.47.2
PATCH v2 2/4 fs/open: make chmod_common() and chown_common() killable
Allows killing processes that are waiting for the inode lock.
---
v2: split into separate patches
This part was reviewed by Christian Brauner here:
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/
--- fs/open.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/open.c +7 -2
@@ -635,7 +635,9 @@ int chmod_common(const struct path *path, umode_t mode)if (error)return error; retry_deleg: -inode_lock (inode); + error =inode_lock_killable (inode); +if (error) + goto out_mnt_unlock; error =security_path_chmod (path, mode);if (error) goto out_unlock;
@@ -650,6 +652,7 @@ int chmod_common(const struct path *path, umode_t mode)if (!error) goto retry_deleg; } +out_mnt_unlock:mnt_drop_write (path->mnt);return error; }
@@ -769,7 +772,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)return -EINVAL ;if ((group != (gid_t)-1 ) && !setattr_vfsgid (&newattrs, gid))return -EINVAL ; -inode_lock (inode); + error =inode_lock_killable (inode); +if (error) +return error;if (!S_ISDIR (inode->i_mode)) newattrs.ia_valid |=ATTR_KILL_SUID |ATTR_KILL_PRIV |setattr_should_drop_sgid (idmap, inode);
Signature · 1 line
2.47.2
Re: [PATCH v2 2/4] fs/open: make chmod_common() and chown_common() killable
Quoted 3 lines · Max Kellermann
Allows killing processes that are waiting for the inode lock.
Signed-off-by Max Kellermann <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 48 lines
---
v2: split into separate patchesThis part was reviewed by Christian Brauner here:
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/Signed-off-by Max Kellermann <[email protected]>--- fs/open.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)fs/open.c +7
-2@@ -635,7 +635,9 @@ int chmod_common(const struct path *path, umode_t mode)if (error)return error; retry_deleg: -inode_lock (inode); + error =inode_lock_killable (inode); +if (error) + goto out_mnt_unlock; error =security_path_chmod (path, mode);if (error) goto out_unlock;@@ -650,6 +652,7 @@ int chmod_common(const struct path *path, umode_t mode)if (!error) goto retry_deleg; } +out_mnt_unlock:mnt_drop_write (path->mnt);return error; }@@ -769,7 +772,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)return -EINVAL ;if ((group != (gid_t)-1 ) && !setattr_vfsgid (&newattrs, gid))return -EINVAL ; -inode_lock (inode); + error =inode_lock_killable (inode); +if (error) +return error;if (!S_ISDIR (inode->i_mode)) newattrs.ia_valid |=ATTR_KILL_SUID |ATTR_KILL_PRIV |setattr_should_drop_sgid (idmap, inode);Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v2 3/4 fs/open: make do_truncate() killable
In reply to Max KellermannAllows killing processes that are waiting for the inode lock.
---
v2: split into separate patches
Review here (though nothing about do_truncate()):
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/
--- fs/open.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/open.c +4 -1
@@ -60,7 +60,10 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,if (ret) newattrs.ia_valid |= ret |ATTR_FORCE ; -inode_lock (dentry->d_inode); + ret =inode_lock_killable (dentry->d_inode); +if (ret) +return ret; +/* Note any delegations or leases have already been broken: */ ret =notify_change (idmap, dentry, &newattrs,NULL );inode_unlock (dentry->d_inode);
Signature · 1 line
2.47.2
Re: [PATCH v2 3/4] fs/open: make do_truncate() killable
Quoted 3 lines · Max Kellermann
Allows killing processes that are waiting for the inode lock.
Signed-off-by Max Kellermann <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 30 lines
---
v2: split into separate patchesReview here (though nothing about
do_truncate()):
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/Signed-off-by Max Kellermann <[email protected]>--- fs/open.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/open.c +4
-1@@ -60,7 +60,10 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,if (ret) newattrs.ia_valid |= ret |ATTR_FORCE ; -inode_lock (dentry->d_inode); + ret =inode_lock_killable (dentry->d_inode); +if (ret) +return ret; +/* Note any delegations or leases have already been broken: */ ret =notify_change (idmap, dentry, &newattrs,NULL );inode_unlock (dentry->d_inode);Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v2 4/4 fs/read_write: make default_llseek() killable
In reply to Max KellermannAllows killing processes that are waiting for the inode lock.
---
v2: split into separate patches
TODO: review whether all callers can handle EINTR; see
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/
and
https://lore.kernel.org/linux-fsdevel/hzrj5b7x3rvtxt4qgjxdihhi5vjoc5gw3i35pbyopa7ccucizo@q5c42kjlkly3/
--- fs/read_write.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/read_write.c +3 -1
@@ -332,7 +332,9 @@ loff_t default_llseek(struct file *file, loff_t offset, int whence)struct inode *inode =file_inode (file);loff_t retval; -inode_lock (inode); + retval =inode_lock_killable (inode); +if (retval) +return retval;switch (whence) {case SEEK_END : offset +=i_size_read (inode);
Signature · 1 line
2.47.2
Re: [PATCH v2 4/4] fs/read_write: make default_llseek() killable
Quoted 3 lines · Max Kellermann
Allows killing processes that are waiting for the inode lock.
Signed-off-by Max Kellermann <[email protected]>
Looks good. Feel free to add:
Quoted 3 lines
v2: split into separate patches
TODO: review whether all callers can handle EINTR; see
I did a quick audit and everything seems OK AFAICT.
Honza
Quoted 27 lines
https://lore.kernel.org/linux-fsdevel/20250512-unrat-kapital-2122d3777c5d@brauner/
and
https://lore.kernel.org/linux-fsdevel/hzrj5b7x3rvtxt4qgjxdihhi5vjoc5gw3i35pbyopa7ccucizo@q5c42kjlkly3/Signed-off-by Max Kellermann <[email protected]>--- fs/read_write.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/read_write.c +3
-1@@ -332,7 +332,9 @@ loff_t default_llseek(struct file *file, loff_t offset, int whence)struct inode *inode =file_inode (file);loff_t retval; -inode_lock (inode); + retval =inode_lock_killable (inode); +if (retval) +return retval;switch (whence) {case SEEK_END : offset +=i_size_read (inode);Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 4 lines · Max Kellermann
Prepare for making inode operations killable while they're waiting for the lock.
Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree. Patches in the vfs-6.16.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.16.misc
[1/4] include/linux/fs.h: add inode_lock_killable()
https://git.kernel.org/vfs/vfs/c/d8c5507cd140 [2/4] fs/open: make chmod_common() and chown_common() killable https://git.kernel.org/vfs/vfs/c/28a3f6ab2fe0 [3/4] fs/open: make do_truncate() killable https://git.kernel.org/vfs/vfs/c/d68687564280 [4/4] fs/read_write: make default_llseek() killable https://git.kernel.org/vfs/vfs/c/2e1a8fbff51b
Quoted 4 lines · Max Kellermann
Prepare for making inode operations killable while they're waiting for the lock.
Signed-off-by Max Kellermann <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 35 lines
--- include/linux/fs.h | 10 ++++++++++ 1 file changed, 10 insertions(+)include/linux/fs.h +10
-0@@ -867,6 +867,11 @@ static inline void inode_lock(struct inode *inode)down_write (&inode->i_rwsem); } +static inline __must_check int inode_lock_killable (struct inode *inode) +{ +return down_write_killable (&inode->i_rwsem); +} +static inline void inode_unlock (struct inode *inode) {up_write (&inode->i_rwsem);@@ -877,6 +882,11 @@ static inline void inode_lock_shared(struct inode *inode)down_read (&inode->i_rwsem); } +static inline __must_check int inode_lock_shared_killable (struct inode *inode) +{ +return down_read_killable (&inode->i_rwsem); +} +static inline void inode_unlock_shared (struct inode *inode) {up_read (&inode->i_rwsem);Signature · 1 line
2.47.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR