]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/6.1.83/nfsd-allow-reaping-files-still-under-writeback.patch
Linux 6.1.83
[thirdparty/kernel/stable-queue.git] / releases / 6.1.83 / nfsd-allow-reaping-files-still-under-writeback.patch
1 From ac9a9f41a15c31910d32eee697d7fab55053c493 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 15 Feb 2023 06:53:54 -0500
4 Subject: nfsd: allow reaping files still under writeback
5
6 From: Jeff Layton <jlayton@kernel.org>
7
8 [ Upstream commit dcb779fcd4ed5984ad15991d574943d12a8693d1 ]
9
10 On most filesystems, there is no reason to delay reaping an nfsd_file
11 just because its underlying inode is still under writeback. nfsd just
12 relies on client activity or the local flusher threads to do writeback.
13
14 The main exception is NFS, which flushes all of its dirty data on last
15 close. Add a new EXPORT_OP_FLUSH_ON_CLOSE flag to allow filesystems to
16 signal that they do this, and only skip closing files under writeback on
17 such filesystems.
18
19 Also, remove a redundant NULL file pointer check in
20 nfsd_file_check_writeback, and clean up nfs's export op flag
21 definitions.
22
23 Signed-off-by: Jeff Layton <jlayton@kernel.org>
24 Acked-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
25 [ cel: adjusted to apply to v6.1.y ]
26 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
27 Signed-off-by: Sasha Levin <sashal@kernel.org>
28 ---
29 fs/nfs/export.c | 9 ++++++---
30 fs/nfsd/filecache.c | 12 +++++++++++-
31 include/linux/exportfs.h | 1 +
32 3 files changed, 18 insertions(+), 4 deletions(-)
33
34 diff --git a/fs/nfs/export.c b/fs/nfs/export.c
35 index 01596f2d0a1ed..9fe9586a51b71 100644
36 --- a/fs/nfs/export.c
37 +++ b/fs/nfs/export.c
38 @@ -156,7 +156,10 @@ const struct export_operations nfs_export_ops = {
39 .fh_to_dentry = nfs_fh_to_dentry,
40 .get_parent = nfs_get_parent,
41 .fetch_iversion = nfs_fetch_iversion,
42 - .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK|
43 - EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS|
44 - EXPORT_OP_NOATOMIC_ATTR,
45 + .flags = EXPORT_OP_NOWCC |
46 + EXPORT_OP_NOSUBTREECHK |
47 + EXPORT_OP_CLOSE_BEFORE_UNLINK |
48 + EXPORT_OP_REMOTE_FS |
49 + EXPORT_OP_NOATOMIC_ATTR |
50 + EXPORT_OP_FLUSH_ON_CLOSE,
51 };
52 diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
53 index 9b7082fdd2115..a6fa6e9802772 100644
54 --- a/fs/nfsd/filecache.c
55 +++ b/fs/nfsd/filecache.c
56 @@ -402,13 +402,23 @@ nfsd_file_check_writeback(struct nfsd_file *nf)
57 struct file *file = nf->nf_file;
58 struct address_space *mapping;
59
60 - if (!file || !(file->f_mode & FMODE_WRITE))
61 + /* File not open for write? */
62 + if (!(file->f_mode & FMODE_WRITE))
63 return false;
64 +
65 + /*
66 + * Some filesystems (e.g. NFS) flush all dirty data on close.
67 + * On others, there is no need to wait for writeback.
68 + */
69 + if (!(file_inode(file)->i_sb->s_export_op->flags & EXPORT_OP_FLUSH_ON_CLOSE))
70 + return false;
71 +
72 mapping = file->f_mapping;
73 return mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) ||
74 mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK);
75 }
76
77 +
78 static bool nfsd_file_lru_add(struct nfsd_file *nf)
79 {
80 set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);
81 diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h
82 index fe848901fcc3a..218fc5c54e901 100644
83 --- a/include/linux/exportfs.h
84 +++ b/include/linux/exportfs.h
85 @@ -221,6 +221,7 @@ struct export_operations {
86 #define EXPORT_OP_NOATOMIC_ATTR (0x10) /* Filesystem cannot supply
87 atomic attribute updates
88 */
89 +#define EXPORT_OP_FLUSH_ON_CLOSE (0x20) /* fs flushes file data on close */
90 unsigned long flags;
91 };
92
93 --
94 2.43.0
95