Skip to content

Commit dcb779f

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: allow reaping files still under writeback
On most filesystems, there is no reason to delay reaping an nfsd_file just because its underlying inode is still under writeback. nfsd just relies on client activity or the local flusher threads to do writeback. The main exception is NFS, which flushes all of its dirty data on last close. Add a new EXPORT_OP_FLUSH_ON_CLOSE flag to allow filesystems to signal that they do this, and only skip closing files under writeback on such filesystems. Also, remove a redundant NULL file pointer check in nfsd_file_check_writeback, and clean up nfs's export op flag definitions. Signed-off-by: Jeff Layton <jlayton@kernel.org> Acked-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 972cc0e commit dcb779f

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

fs/nfs/export.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ const struct export_operations nfs_export_ops = {
149149
.encode_fh = nfs_encode_fh,
150150
.fh_to_dentry = nfs_fh_to_dentry,
151151
.get_parent = nfs_get_parent,
152-
.flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK|
153-
EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS|
154-
EXPORT_OP_NOATOMIC_ATTR,
152+
.flags = EXPORT_OP_NOWCC |
153+
EXPORT_OP_NOSUBTREECHK |
154+
EXPORT_OP_CLOSE_BEFORE_UNLINK |
155+
EXPORT_OP_REMOTE_FS |
156+
EXPORT_OP_NOATOMIC_ATTR |
157+
EXPORT_OP_FLUSH_ON_CLOSE,
155158
};

fs/nfsd/filecache.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,23 @@ nfsd_file_check_writeback(struct nfsd_file *nf)
402402
struct file *file = nf->nf_file;
403403
struct address_space *mapping;
404404

405-
if (!file || !(file->f_mode & FMODE_WRITE))
405+
/* File not open for write? */
406+
if (!(file->f_mode & FMODE_WRITE))
406407
return false;
408+
409+
/*
410+
* Some filesystems (e.g. NFS) flush all dirty data on close.
411+
* On others, there is no need to wait for writeback.
412+
*/
413+
if (!(file_inode(file)->i_sb->s_export_op->flags & EXPORT_OP_FLUSH_ON_CLOSE))
414+
return false;
415+
407416
mapping = file->f_mapping;
408417
return mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) ||
409418
mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK);
410419
}
411420

421+
412422
static bool nfsd_file_lru_add(struct nfsd_file *nf)
413423
{
414424
set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags);

include/linux/exportfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct export_operations {
220220
#define EXPORT_OP_NOATOMIC_ATTR (0x10) /* Filesystem cannot supply
221221
atomic attribute updates
222222
*/
223+
#define EXPORT_OP_FLUSH_ON_CLOSE (0x20) /* fs flushes file data on close */
223224
unsigned long flags;
224225
};
225226

0 commit comments

Comments
 (0)