Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge patch series "include/linux/fs.h: add inode_lock_killable()"

Try and make a few filesystem operations killable on the VFS
inode->i_mutex level.

* patches from https://lore.kernel.org/20250513150327.1373061-1-max.kellermann@ionos.com:
fs/read_write: make default_llseek() killable
fs/open: make do_truncate() killable
fs/open: make chmod_common() and chown_common() killable
include/linux/fs.h: add inode_lock_killable()

Link: https://lore.kernel.org/20250513150327.1373061-1-max.kellermann@ionos.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

+24 -4
+11 -3
fs/open.c
··· 60 60 if (ret) 61 61 newattrs.ia_valid |= ret | ATTR_FORCE; 62 62 63 - inode_lock(dentry->d_inode); 63 + ret = inode_lock_killable(dentry->d_inode); 64 + if (ret) 65 + return ret; 66 + 64 67 /* Note any delegations or leases have already been broken: */ 65 68 ret = notify_change(idmap, dentry, &newattrs, NULL); 66 69 inode_unlock(dentry->d_inode); ··· 638 635 if (error) 639 636 return error; 640 637 retry_deleg: 641 - inode_lock(inode); 638 + error = inode_lock_killable(inode); 639 + if (error) 640 + goto out_mnt_unlock; 642 641 error = security_path_chmod(path, mode); 643 642 if (error) 644 643 goto out_unlock; ··· 655 650 if (!error) 656 651 goto retry_deleg; 657 652 } 653 + out_mnt_unlock: 658 654 mnt_drop_write(path->mnt); 659 655 return error; 660 656 } ··· 775 769 return -EINVAL; 776 770 if ((group != (gid_t)-1) && !setattr_vfsgid(&newattrs, gid)) 777 771 return -EINVAL; 778 - inode_lock(inode); 772 + error = inode_lock_killable(inode); 773 + if (error) 774 + return error; 779 775 if (!S_ISDIR(inode->i_mode)) 780 776 newattrs.ia_valid |= ATTR_KILL_SUID | ATTR_KILL_PRIV | 781 777 setattr_should_drop_sgid(idmap, inode);
+3 -1
fs/read_write.c
··· 332 332 struct inode *inode = file_inode(file); 333 333 loff_t retval; 334 334 335 - inode_lock(inode); 335 + retval = inode_lock_killable(inode); 336 + if (retval) 337 + return retval; 336 338 switch (whence) { 337 339 case SEEK_END: 338 340 offset += i_size_read(inode);
+10
include/linux/fs.h
··· 867 867 down_write(&inode->i_rwsem); 868 868 } 869 869 870 + static inline __must_check int inode_lock_killable(struct inode *inode) 871 + { 872 + return down_write_killable(&inode->i_rwsem); 873 + } 874 + 870 875 static inline void inode_unlock(struct inode *inode) 871 876 { 872 877 up_write(&inode->i_rwsem); ··· 880 875 static inline void inode_lock_shared(struct inode *inode) 881 876 { 882 877 down_read(&inode->i_rwsem); 878 + } 879 + 880 + static inline __must_check int inode_lock_shared_killable(struct inode *inode) 881 + { 882 + return down_read_killable(&inode->i_rwsem); 883 883 } 884 884 885 885 static inline void inode_unlock_shared(struct inode *inode)