ext4: Use scoped memory APIs in ext4_write_begin()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 22 Feb 2022 15:36:28 +0000 (10:36 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sun, 8 May 2022 18:28:19 +0000 (14:28 -0400)
Instead of setting AOP_FLAG_NOFS, use memalloc_nofs_save() and
memalloc_nofs_restore() to prevent GFP_FS allocations recursing
into the filesystem with a journal already started.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/inline.c
fs/ext4/inode.c

index 90677e3..0c3308b 100644 (file)
@@ -3591,7 +3591,6 @@ extern int ext4_readpage_inline(struct inode *inode, struct page *page);
 extern int ext4_try_to_write_inline_data(struct address_space *mapping,
                                         struct inode *inode,
                                         loff_t pos, unsigned len,
-                                        unsigned flags,
                                         struct page **pagep);
 extern int ext4_write_inline_data_end(struct inode *inode,
                                      loff_t pos, unsigned len,
index d965ba0..b2ef5ba 100644 (file)
@@ -527,13 +527,13 @@ int ext4_readpage_inline(struct inode *inode, struct page *page)
 }
 
 static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
-                                             struct inode *inode,
-                                             unsigned flags)
+                                             struct inode *inode)
 {
        int ret, needed_blocks, no_expand;
        handle_t *handle = NULL;
        int retries = 0, sem_held = 0;
        struct page *page = NULL;
+       unsigned int flags;
        unsigned from, to;
        struct ext4_iloc iloc;
 
@@ -562,9 +562,9 @@ retry:
 
        /* We cannot recurse into the filesystem as the transaction is already
         * started */
-       flags |= AOP_FLAG_NOFS;
-
-       page = grab_cache_page_write_begin(mapping, 0, flags);
+       flags = memalloc_nofs_save();
+       page = grab_cache_page_write_begin(mapping, 0, 0);
+       memalloc_nofs_restore(flags);
        if (!page) {
                ret = -ENOMEM;
                goto out;
@@ -649,11 +649,11 @@ out:
 int ext4_try_to_write_inline_data(struct address_space *mapping,
                                  struct inode *inode,
                                  loff_t pos, unsigned len,
-                                 unsigned flags,
                                  struct page **pagep)
 {
        int ret;
        handle_t *handle;
+       unsigned int flags;
        struct page *page;
        struct ext4_iloc iloc;
 
@@ -691,9 +691,9 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
        if (ret)
                goto out;
 
-       flags |= AOP_FLAG_NOFS;
-
-       page = grab_cache_page_write_begin(mapping, 0, flags);
+       flags = memalloc_nofs_save();
+       page = grab_cache_page_write_begin(mapping, 0, 0);
+       memalloc_nofs_restore(flags);
        if (!page) {
                ret = -ENOMEM;
                goto out;
@@ -727,8 +727,7 @@ out:
        brelse(iloc.bh);
        return ret;
 convert:
-       return ext4_convert_inline_data_to_extent(mapping,
-                                                 inode, flags);
+       return ext4_convert_inline_data_to_extent(mapping, inode);
 }
 
 int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
index 21ebcb3..01a5564 100644 (file)
@@ -1156,7 +1156,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
 
        if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
                ret = ext4_try_to_write_inline_data(mapping, inode, pos, len,
-                                                   flags, pagep);
+                                                   pagep);
                if (ret < 0)
                        return ret;
                if (ret == 1)