fs: Add FGP_WRITEBEGIN

Conflicts:
	fs/iomap/buffered-io.c - We already have
		66dabbb65d67 ("mm: return an ERR_PTR from __filemap_get_folio")
		so don't add declaration for folio
	include/linux/pagemap.h - We already have
		263e721e3ba1 ("mm: make mapping_get_entry available outside of filemap.c")
		so keep declaration of filemap_get_entry
	fs/nfs/file.c - We already have
		66dabbb65d67 (" mm: return an ERR_PTR from __filemap_get_folio")
		so keep IS_ERR/PTR_ERR

JIRA: https://issues.redhat.com/browse/RHEL-27741

commit e999a5c5a19cf3b679f3d93c49ad5f5c04e4806c
Author: Matthew Wilcox <willy@infradead.org>
Date:   Fri Mar 24 18:01:01 2023 +0000

    fs: Add FGP_WRITEBEGIN

    This particular combination of flags is used by most filesystems
    in their ->write_begin method, although it does find use in a
    few other places.  Before folios, it warranted its own function
    (grab_cache_page_write_begin()), but I think that just having specialised
    flags is enough.  It certainly helps the few places that have been
    converted from grab_cache_page_write_begin() to __filemap_get_folio().

    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Link: https://lore.kernel.org/r/20230324180129.1220691-2-willy@infradead.org
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
This commit is contained in:
Chris von Recklinghausen 2024-04-12 15:16:37 -04:00
parent 75a57ff9f2
commit c0aa51a6e5
6 changed files with 9 additions and 19 deletions

View File

@ -126,7 +126,6 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2,
{
struct address_space *mapping[2];
unsigned int flags;
unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
BUG_ON(!inode1 || !inode2);
if (inode1 < inode2) {
@ -139,14 +138,14 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2,
}
flags = memalloc_nofs_save();
folio[0] = __filemap_get_folio(mapping[0], index1, fgp_flags,
folio[0] = __filemap_get_folio(mapping[0], index1, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping[0]));
if (IS_ERR(folio[0])) {
memalloc_nofs_restore(flags);
return PTR_ERR(folio[0]);
}
folio[1] = __filemap_get_folio(mapping[1], index2, fgp_flags,
folio[1] = __filemap_get_folio(mapping[1], index2, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping[1]));
memalloc_nofs_restore(flags);
if (IS_ERR(folio[1])) {

View File

@ -471,7 +471,7 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate);
*/
struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos)
{
unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS;
unsigned fgp = FGP_WRITEBEGIN | FGP_NOFS;
if (iter->flags & IOMAP_NOWAIT)
fgp |= FGP_NOWAIT;

View File

@ -345,14 +345,13 @@ int netfs_write_begin(struct netfs_inode *ctx,
{
struct netfs_io_request *rreq;
struct folio *folio;
unsigned int fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
pgoff_t index = pos >> PAGE_SHIFT;
int ret;
DEFINE_READAHEAD(ractl, file, NULL, mapping, index);
retry:
folio = __filemap_get_folio(mapping, index, fgp_flags,
folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));
if (IS_ERR(folio))
return PTR_ERR(folio);

View File

@ -305,15 +305,6 @@ static bool nfs_want_read_modify_write(struct file *file, struct folio *folio,
return false;
}
static struct folio *
nfs_folio_grab_cache_write_begin(struct address_space *mapping, pgoff_t index)
{
unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
return __filemap_get_folio(mapping, index, fgp_flags,
mapping_gfp_mask(mapping));
}
/*
* This does the "real" work of the write. We must allocate and lock the
* page to be sent back to the generic routine, which then copies the
@ -334,7 +325,8 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
file, mapping->host->i_ino, len, (long long) pos);
start:
folio = nfs_folio_grab_cache_write_begin(mapping, pos >> PAGE_SHIFT);
folio = __filemap_get_folio(mapping, pos >> PAGE_SHIFT, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));
if (IS_ERR(folio))
return PTR_ERR(folio);
*pagep = &folio->page;

View File

@ -544,6 +544,8 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
#define FGP_STABLE 0x00000080
void *filemap_get_entry(struct address_space *mapping, pgoff_t index);
#define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE)
struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
int fgp_flags, gfp_t gfp);
struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,

View File

@ -106,9 +106,7 @@ EXPORT_SYMBOL(pagecache_get_page);
struct page *grab_cache_page_write_begin(struct address_space *mapping,
pgoff_t index)
{
unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
return pagecache_get_page(mapping, index, fgp_flags,
return pagecache_get_page(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));
}
EXPORT_SYMBOL(grab_cache_page_write_begin);