Commit e999a5c5 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Theodore Ts'o

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: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/r/20230324180129.1220691-2-willy@infradead.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 361eb69f
...@@ -126,7 +126,6 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2, ...@@ -126,7 +126,6 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2,
{ {
struct address_space *mapping[2]; struct address_space *mapping[2];
unsigned int flags; unsigned int flags;
unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
BUG_ON(!inode1 || !inode2); BUG_ON(!inode1 || !inode2);
if (inode1 < inode2) { if (inode1 < inode2) {
...@@ -139,14 +138,14 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2, ...@@ -139,14 +138,14 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2,
} }
flags = memalloc_nofs_save(); 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])); mapping_gfp_mask(mapping[0]));
if (!folio[0]) { if (!folio[0]) {
memalloc_nofs_restore(flags); memalloc_nofs_restore(flags);
return -ENOMEM; return -ENOMEM;
} }
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])); mapping_gfp_mask(mapping[1]));
memalloc_nofs_restore(flags); memalloc_nofs_restore(flags);
if (!folio[1]) { if (!folio[1]) {
......
...@@ -467,7 +467,7 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); ...@@ -467,7 +467,7 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate);
*/ */
struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos) 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;
struct folio *folio; struct folio *folio;
if (iter->flags & IOMAP_NOWAIT) if (iter->flags & IOMAP_NOWAIT)
......
...@@ -341,14 +341,13 @@ int netfs_write_begin(struct netfs_inode *ctx, ...@@ -341,14 +341,13 @@ int netfs_write_begin(struct netfs_inode *ctx,
{ {
struct netfs_io_request *rreq; struct netfs_io_request *rreq;
struct folio *folio; struct folio *folio;
unsigned int fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
pgoff_t index = pos >> PAGE_SHIFT; pgoff_t index = pos >> PAGE_SHIFT;
int ret; int ret;
DEFINE_READAHEAD(ractl, file, NULL, mapping, index); DEFINE_READAHEAD(ractl, file, NULL, mapping, index);
retry: retry:
folio = __filemap_get_folio(mapping, index, fgp_flags, folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping)); mapping_gfp_mask(mapping));
if (!folio) if (!folio)
return -ENOMEM; return -ENOMEM;
......
...@@ -306,15 +306,6 @@ static bool nfs_want_read_modify_write(struct file *file, struct folio *folio, ...@@ -306,15 +306,6 @@ static bool nfs_want_read_modify_write(struct file *file, struct folio *folio,
return false; 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 * 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 * page to be sent back to the generic routine, which then copies the
...@@ -335,7 +326,8 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping, ...@@ -335,7 +326,8 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
file, mapping->host->i_ino, len, (long long) pos); file, mapping->host->i_ino, len, (long long) pos);
start: 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 (!folio) if (!folio)
return -ENOMEM; return -ENOMEM;
*pagep = &folio->page; *pagep = &folio->page;
......
...@@ -507,6 +507,8 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, ...@@ -507,6 +507,8 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
#define FGP_ENTRY 0x00000080 #define FGP_ENTRY 0x00000080
#define FGP_STABLE 0x00000100 #define FGP_STABLE 0x00000100
#define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE)
struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
int fgp_flags, gfp_t gfp); int fgp_flags, gfp_t gfp);
struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
......
...@@ -106,9 +106,7 @@ EXPORT_SYMBOL(pagecache_get_page); ...@@ -106,9 +106,7 @@ EXPORT_SYMBOL(pagecache_get_page);
struct page *grab_cache_page_write_begin(struct address_space *mapping, struct page *grab_cache_page_write_begin(struct address_space *mapping,
pgoff_t index) pgoff_t index)
{ {
unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE; return pagecache_get_page(mapping, index, FGP_WRITEBEGIN,
return pagecache_get_page(mapping, index, fgp_flags,
mapping_gfp_mask(mapping)); mapping_gfp_mask(mapping));
} }
EXPORT_SYMBOL(grab_cache_page_write_begin); EXPORT_SYMBOL(grab_cache_page_write_begin);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment