This is a note to let you know that I've just added the patch titled nfsd: Prevent truncation of an unlinked inode from blocking access to its directory to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: nfsd-prevent-truncation-of-an-unlinked-inode-from-bl.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 4b4b2f629e1ade8fd1e7c7aef5ef0b62981520a5 Author: Yu Hsiang Huang <nickhuang@xxxxxxxxxxxx> Date: Fri May 14 11:58:29 2021 +0800 nfsd: Prevent truncation of an unlinked inode from blocking access to its directory [ Upstream commit e5d74a2d0ee67ae00edad43c3d7811016e4d2e21 ] Truncation of an unlinked inode may take a long time for I/O waiting, and it doesn't have to prevent access to the directory. Thus, let truncation occur outside the directory's mutex, just like do_unlinkat() does. Signed-off-by: Yu Hsiang Huang <nickhuang@xxxxxxxxxxxx> Signed-off-by: Bing Jing Chang <bingjingc@xxxxxxxxxxxx> Signed-off-by: Robbie Ko <robbieko@xxxxxxxxxxxx> Signed-off-by: J. Bruce Fields <bfields@xxxxxxxxxx> Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 520e55c35e742..2eb3bfbc8a35f 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1870,6 +1870,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, { struct dentry *dentry, *rdentry; struct inode *dirp; + struct inode *rinode; __be32 err; int host_err; @@ -1898,6 +1899,8 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, host_err = -ENOENT; goto out_drop_write; } + rinode = d_inode(rdentry); + ihold(rinode); if (!type) type = d_inode(rdentry)->i_mode & S_IFMT; @@ -1913,6 +1916,8 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, if (!host_err) host_err = commit_metadata(fhp); dput(rdentry); + fh_unlock(fhp); + iput(rinode); /* truncate the inode here */ out_drop_write: fh_drop_write(fhp);