Skip to content

Commit

Permalink
nfsd: Prevent truncation of an unlinked inode from blocking access to…
Browse files Browse the repository at this point in the history
… its directory

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@synology.com>
Signed-off-by: Bing Jing Chang <bingjingc@synology.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Yu Hsiang Huang authored and J. Bruce Fields committed May 25, 2021
1 parent d6cbe98 commit e5d74a2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,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;

Expand Down Expand Up @@ -1887,6 +1888,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;
Expand All @@ -1902,6 +1905,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);
Expand Down

0 comments on commit e5d74a2

Please sign in to comment.