public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfsd: Prevent truncation of an unlinked inode from blocking access to its directory
@ 2021-05-14  3:58 Nick Huang
  2021-05-14 15:09 ` J. Bruce Fields
  2021-05-14 15:46 ` Trond Myklebust
  0 siblings, 2 replies; 11+ messages in thread
From: Nick Huang @ 2021-05-14  3:58 UTC (permalink / raw)
  To: bfields, chuck.lever
  Cc: linux-nfs, Yu Hsiang Huang, Bing Jing Chang, Robbie Ko

From: Yu Hsiang Huang <nickhuang@synology.com>

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>
---
 fs/nfsd/vfs.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 15adf1f6ab21..39948f130712 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -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;
 
@@ -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;
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-05-18 21:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-14  3:58 [PATCH] nfsd: Prevent truncation of an unlinked inode from blocking access to its directory Nick Huang
2021-05-14 15:09 ` J. Bruce Fields
2021-05-14 15:46 ` Trond Myklebust
2021-05-15  7:02   ` Christoph Hellwig
2021-05-17 18:56     ` bfields
2021-05-18  7:33       ` Christoph Hellwig
2021-05-18 17:53     ` Trond Myklebust
2021-05-18 18:21       ` bfields
2021-05-18 18:36         ` Trond Myklebust
2021-05-18 18:39           ` bfields
2021-05-18 21:06   ` bfields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox