]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
filemap: introduce filemap_invalidate_pages
authorPavel Begunkov <asml.silence@gmail.com>
Wed, 11 Sep 2024 16:34:39 +0000 (17:34 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 11 Sep 2024 16:44:10 +0000 (10:44 -0600)
kiocb_invalidate_pages() is useful for the write path, however not
everything is backed by kiocb and we want to reuse the function for bio
based discard implementation. Extract and and reuse a new helper called
filemap_invalidate_pages(), which takes a argument indicating whether it
should be non-blocking and might return -EAGAIN.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/f81374b52c92d0dce0f01a279d1eed42b54056aa.1726072086.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/pagemap.h
mm/filemap.c

index d9c7edb6422bdddcc35e211bee34546e46178071..e39c3a7ce33cc9a04b2b8d0fa7ed5e8fbaa1f63e 100644 (file)
@@ -32,6 +32,8 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
                pgoff_t start, pgoff_t end);
 int kiocb_invalidate_pages(struct kiocb *iocb, size_t count);
 void kiocb_invalidate_post_direct_write(struct kiocb *iocb, size_t count);
+int filemap_invalidate_pages(struct address_space *mapping,
+                            loff_t pos, loff_t end, bool nowait);
 
 int write_inode_now(struct inode *, int sync);
 int filemap_fdatawrite(struct address_space *);
index 0ca9c1377b686ff075777b2b922528c2aa228a90..497e802325c9e312d44d849cb6246097b3334efe 100644 (file)
@@ -2712,14 +2712,12 @@ int kiocb_write_and_wait(struct kiocb *iocb, size_t count)
 }
 EXPORT_SYMBOL_GPL(kiocb_write_and_wait);
 
-int kiocb_invalidate_pages(struct kiocb *iocb, size_t count)
+int filemap_invalidate_pages(struct address_space *mapping,
+                            loff_t pos, loff_t end, bool nowait)
 {
-       struct address_space *mapping = iocb->ki_filp->f_mapping;
-       loff_t pos = iocb->ki_pos;
-       loff_t end = pos + count - 1;
        int ret;
 
-       if (iocb->ki_flags & IOCB_NOWAIT) {
+       if (nowait) {
                /* we could block if there are any pages in the range */
                if (filemap_range_has_page(mapping, pos, end))
                        return -EAGAIN;
@@ -2738,6 +2736,15 @@ int kiocb_invalidate_pages(struct kiocb *iocb, size_t count)
        return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT,
                                             end >> PAGE_SHIFT);
 }
+
+int kiocb_invalidate_pages(struct kiocb *iocb, size_t count)
+{
+       struct address_space *mapping = iocb->ki_filp->f_mapping;
+
+       return filemap_invalidate_pages(mapping, iocb->ki_pos,
+                                       iocb->ki_pos + count - 1,
+                                       iocb->ki_flags & IOCB_NOWAIT);
+}
 EXPORT_SYMBOL_GPL(kiocb_invalidate_pages);
 
 /**