summaryrefslogtreecommitdiff
path: root/mm/shmem.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2024-02-19 09:27:13 +0300
committerChandan Babu R <chandanbabu@kernel.org>2024-02-21 09:06:51 +0300
commitd7468609ee0f90ceb24143a32edc47d433d1dbba (patch)
treee501d1c8f415211bced7a5d6525963e141c00881 /mm/shmem.c
parent1cd81faaf61b42307e81f2dd173934005c220a64 (diff)
downloadlinux-d7468609ee0f90ceb24143a32edc47d433d1dbba.tar.xz
shmem: export shmem_get_folio
Export shmem_get_folio as a slightly lower-level variant of shmem_read_folio_gfp. This will be useful for XFS xfile use cases that want to pass SGP_NOALLOC or get a locked page, which the thin shmem_read_folio_gfp wrapper can't provide. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Matthew Wilcox (Oracle)" <willy@infradead.org> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Diffstat (limited to 'mm/shmem.c')
-rw-r--r--mm/shmem.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index ad533b2f0721..aeb1fd19ea3f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2137,12 +2137,32 @@ unlock:
return error;
}
+/**
+ * shmem_get_folio - find, and lock a shmem folio.
+ * @inode: inode to search
+ * @index: the page index.
+ * @foliop: pointer to the folio if found
+ * @sgp: SGP_* flags to control behavior
+ *
+ * Looks up the page cache entry at @inode & @index. If a folio is
+ * present, it is returned locked with an increased refcount.
+ *
+ * When no folio is found, the behavior depends on @sgp:
+ * - for SGP_READ, *foliop is %NULL and 0 is returned
+ * - for SGP_NOALLOC, *foliop is %NULL and -ENOENT is returned
+ * - for all other flags a new folio is allocated, inserted into the
+ * page cache and returned locked in @foliop.
+ *
+ * Context: May sleep.
+ * Return: 0 if successful, else a negative error code.
+ */
int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop,
enum sgp_type sgp)
{
return shmem_get_folio_gfp(inode, index, foliop, sgp,
mapping_gfp_mask(inode->i_mapping), NULL, NULL);
}
+EXPORT_SYMBOL_GPL(shmem_get_folio);
/*
* This is like autoremove_wake_function, but it removes the wait queue