Skip to content

Commit 902893e

Browse files
Trond MyklebustAnna Schumaker
authored andcommitted
NFS: Enable use of the RWF_DONTCACHE flag on the NFS client
The NFS client needs to defer dropbehind until after any writes to the folio have been persisted on the server. Since this may be a 2 step process, use folio_end_writeback_no_dropbehind() to allow release of the writeback flag, and then call folio_end_dropbehind() once the COMMIT is done. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
1 parent 010054a commit 902893e

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

fs/nfs/file.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ static bool nfs_want_read_modify_write(struct file *file, struct folio *folio,
363363

364364
if (pnfs_ld_read_whole_page(file_inode(file)))
365365
return true;
366+
if (folio_test_dropbehind(folio))
367+
return false;
366368
/* Open for reading too? */
367369
if (file->f_mode & FMODE_READ)
368370
return true;
@@ -382,7 +384,6 @@ static int nfs_write_begin(const struct kiocb *iocb,
382384
loff_t pos, unsigned len, struct folio **foliop,
383385
void **fsdata)
384386
{
385-
fgf_t fgp = FGP_WRITEBEGIN;
386387
struct folio *folio;
387388
struct file *file = iocb->ki_filp;
388389
int once_thru = 0;
@@ -394,10 +395,8 @@ static int nfs_write_begin(const struct kiocb *iocb,
394395
file, mapping->host->i_ino, len, (long long) pos);
395396
nfs_truncate_last_folio(mapping, i_size_read(mapping->host), pos);
396397

397-
fgp |= fgf_set_order(len);
398398
start:
399-
folio = __filemap_get_folio(mapping, pos >> PAGE_SHIFT, fgp,
400-
mapping_gfp_mask(mapping));
399+
folio = write_begin_get_folio(iocb, mapping, pos >> PAGE_SHIFT, len);
401400
if (IS_ERR(folio)) {
402401
ret = PTR_ERR(folio);
403402
goto out;
@@ -411,6 +410,7 @@ static int nfs_write_begin(const struct kiocb *iocb,
411410
} else if (!once_thru &&
412411
nfs_want_read_modify_write(file, folio, pos, len)) {
413412
once_thru = 1;
413+
folio_clear_dropbehind(folio);
414414
ret = nfs_read_folio(file, folio);
415415
folio_put(folio);
416416
if (!ret)
@@ -963,5 +963,6 @@ const struct file_operations nfs_file_operations = {
963963
.splice_write = iter_file_splice_write,
964964
.check_flags = nfs_check_flags,
965965
.setlease = simple_nosetlease,
966+
.fop_flags = FOP_DONTCACHE,
966967
};
967968
EXPORT_SYMBOL_GPL(nfs_file_operations);

fs/nfs/nfs4file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,5 @@ const struct file_operations nfs4_file_operations = {
456456
#else
457457
.llseek = nfs_file_llseek,
458458
#endif
459+
.fop_flags = FOP_DONTCACHE,
459460
};

fs/nfs/write.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static void nfs_folio_end_writeback(struct folio *folio)
296296
{
297297
struct nfs_server *nfss = NFS_SERVER(folio->mapping->host);
298298

299-
folio_end_writeback(folio);
299+
folio_end_writeback_no_dropbehind(folio);
300300
if (atomic_long_dec_return(&nfss->writeback) <
301301
NFS_CONGESTION_OFF_THRESH) {
302302
nfss->write_congested = 0;
@@ -748,6 +748,8 @@ static void nfs_inode_remove_request(struct nfs_page *req)
748748
clear_bit(PG_MAPPED, &req->wb_head->wb_flags);
749749
}
750750
spin_unlock(&mapping->i_private_lock);
751+
752+
folio_end_dropbehind(folio);
751753
}
752754
nfs_page_group_unlock(req);
753755

0 commit comments

Comments
 (0)