Skip to content

Commit ffc143d

Browse files
author
Matthew Wilcox (Oracle)
committed
filemap: Add fgf_t typedef
Similarly to gfp_t, define fgf_t as its own type to prevent various misuses and confusion. Leave the flags as FGP_* for now to reduce the size of this patch; they will be converted to FGF_* later. Move the documentation to the definition of the type insted of burying it in the __filemap_get_folio() documentation. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Kent Overstreet <[email protected]>
1 parent 7a8eb01 commit ffc143d

File tree

7 files changed

+46
-35
lines changed

7 files changed

+46
-35
lines changed

fs/btrfs/file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ static int prepare_uptodate_page(struct inode *inode,
876876
return 0;
877877
}
878878

879-
static unsigned int get_prepare_fgp_flags(bool nowait)
879+
static fgf_t get_prepare_fgp_flags(bool nowait)
880880
{
881-
unsigned int fgp_flags = FGP_LOCK | FGP_ACCESSED | FGP_CREAT;
881+
fgf_t fgp_flags = FGP_LOCK | FGP_ACCESSED | FGP_CREAT;
882882

883883
if (nowait)
884884
fgp_flags |= FGP_NOWAIT;
@@ -910,7 +910,7 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages,
910910
int i;
911911
unsigned long index = pos >> PAGE_SHIFT;
912912
gfp_t mask = get_prepare_gfp_flags(inode, nowait);
913-
unsigned int fgp_flags = get_prepare_fgp_flags(nowait);
913+
fgf_t fgp_flags = get_prepare_fgp_flags(nowait);
914914
int err = 0;
915915
int faili;
916916

fs/f2fs/compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
10451045
struct address_space *mapping = cc->inode->i_mapping;
10461046
struct page *page;
10471047
sector_t last_block_in_bio;
1048-
unsigned fgp_flag = FGP_LOCK | FGP_WRITE | FGP_CREAT;
1048+
fgf_t fgp_flag = FGP_LOCK | FGP_WRITE | FGP_CREAT;
10491049
pgoff_t start_idx = start_idx_of_cluster(cc);
10501050
int i, ret;
10511051

fs/f2fs/f2fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2736,7 +2736,7 @@ static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
27362736

27372737
static inline struct page *f2fs_pagecache_get_page(
27382738
struct address_space *mapping, pgoff_t index,
2739-
int fgp_flags, gfp_t gfp_mask)
2739+
fgf_t fgp_flags, gfp_t gfp_mask)
27402740
{
27412741
if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET))
27422742
return NULL;

fs/iomap/buffered-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate);
467467
*/
468468
struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos)
469469
{
470-
unsigned fgp = FGP_WRITEBEGIN | FGP_NOFS;
470+
fgf_t fgp = FGP_WRITEBEGIN | FGP_NOFS;
471471

472472
if (iter->flags & IOMAP_NOWAIT)
473473
fgp |= FGP_NOWAIT;

include/linux/pagemap.h

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,48 @@ pgoff_t page_cache_next_miss(struct address_space *mapping,
501501
pgoff_t page_cache_prev_miss(struct address_space *mapping,
502502
pgoff_t index, unsigned long max_scan);
503503

504-
#define FGP_ACCESSED 0x00000001
505-
#define FGP_LOCK 0x00000002
506-
#define FGP_CREAT 0x00000004
507-
#define FGP_WRITE 0x00000008
508-
#define FGP_NOFS 0x00000010
509-
#define FGP_NOWAIT 0x00000020
510-
#define FGP_FOR_MMAP 0x00000040
511-
#define FGP_STABLE 0x00000080
504+
/**
505+
* typedef fgf_t - Flags for getting folios from the page cache.
506+
*
507+
* Most users of the page cache will not need to use these flags;
508+
* there are convenience functions such as filemap_get_folio() and
509+
* filemap_lock_folio(). For users which need more control over exactly
510+
* what is done with the folios, these flags to __filemap_get_folio()
511+
* are available.
512+
*
513+
* * %FGP_ACCESSED - The folio will be marked accessed.
514+
* * %FGP_LOCK - The folio is returned locked.
515+
* * %FGP_CREAT - If no folio is present then a new folio is allocated,
516+
* added to the page cache and the VM's LRU list. The folio is
517+
* returned locked.
518+
* * %FGP_FOR_MMAP - The caller wants to do its own locking dance if the
519+
* folio is already in cache. If the folio was allocated, unlock it
520+
* before returning so the caller can do the same dance.
521+
* * %FGP_WRITE - The folio will be written to by the caller.
522+
* * %FGP_NOFS - __GFP_FS will get cleared in gfp.
523+
* * %FGP_NOWAIT - Don't block on the folio lock.
524+
* * %FGP_STABLE - Wait for the folio to be stable (finished writeback)
525+
* * %FGP_WRITEBEGIN - The flags to use in a filesystem write_begin()
526+
* implementation.
527+
*/
528+
typedef unsigned int __bitwise fgf_t;
529+
530+
#define FGP_ACCESSED ((__force fgf_t)0x00000001)
531+
#define FGP_LOCK ((__force fgf_t)0x00000002)
532+
#define FGP_CREAT ((__force fgf_t)0x00000004)
533+
#define FGP_WRITE ((__force fgf_t)0x00000008)
534+
#define FGP_NOFS ((__force fgf_t)0x00000010)
535+
#define FGP_NOWAIT ((__force fgf_t)0x00000020)
536+
#define FGP_FOR_MMAP ((__force fgf_t)0x00000040)
537+
#define FGP_STABLE ((__force fgf_t)0x00000080)
512538

513539
#define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE)
514540

515541
void *filemap_get_entry(struct address_space *mapping, pgoff_t index);
516542
struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
517-
int fgp_flags, gfp_t gfp);
543+
fgf_t fgp_flags, gfp_t gfp);
518544
struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
519-
int fgp_flags, gfp_t gfp);
545+
fgf_t fgp_flags, gfp_t gfp);
520546

521547
/**
522548
* filemap_get_folio - Find and get a folio.
@@ -590,7 +616,7 @@ static inline struct page *find_get_page(struct address_space *mapping,
590616
}
591617

592618
static inline struct page *find_get_page_flags(struct address_space *mapping,
593-
pgoff_t offset, int fgp_flags)
619+
pgoff_t offset, fgf_t fgp_flags)
594620
{
595621
return pagecache_get_page(mapping, offset, fgp_flags, 0);
596622
}

mm/filemap.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,30 +1855,15 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index)
18551855
*
18561856
* Looks up the page cache entry at @mapping & @index.
18571857
*
1858-
* @fgp_flags can be zero or more of these flags:
1859-
*
1860-
* * %FGP_ACCESSED - The folio will be marked accessed.
1861-
* * %FGP_LOCK - The folio is returned locked.
1862-
* * %FGP_CREAT - If no page is present then a new page is allocated using
1863-
* @gfp and added to the page cache and the VM's LRU list.
1864-
* The page is returned locked and with an increased refcount.
1865-
* * %FGP_FOR_MMAP - The caller wants to do its own locking dance if the
1866-
* page is already in cache. If the page was allocated, unlock it before
1867-
* returning so the caller can do the same dance.
1868-
* * %FGP_WRITE - The page will be written to by the caller.
1869-
* * %FGP_NOFS - __GFP_FS will get cleared in gfp.
1870-
* * %FGP_NOWAIT - Don't get blocked by page lock.
1871-
* * %FGP_STABLE - Wait for the folio to be stable (finished writeback)
1872-
*
18731858
* If %FGP_LOCK or %FGP_CREAT are specified then the function may sleep even
18741859
* if the %GFP flags specified for %FGP_CREAT are atomic.
18751860
*
1876-
* If there is a page cache page, it is returned with an increased refcount.
1861+
* If this function returns a folio, it is returned with an increased refcount.
18771862
*
18781863
* Return: The found folio or an ERR_PTR() otherwise.
18791864
*/
18801865
struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
1881-
int fgp_flags, gfp_t gfp)
1866+
fgf_t fgp_flags, gfp_t gfp)
18821867
{
18831868
struct folio *folio;
18841869

mm/folio-compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ EXPORT_SYMBOL(add_to_page_cache_lru);
9292

9393
noinline
9494
struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
95-
int fgp_flags, gfp_t gfp)
95+
fgf_t fgp_flags, gfp_t gfp)
9696
{
9797
struct folio *folio;
9898

0 commit comments

Comments
 (0)