ext4: Use scoped memory APIs in ext4_write_begin()

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: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 36d116e9
...@@ -3591,7 +3591,6 @@ extern int ext4_readpage_inline(struct inode *inode, struct page *page); ...@@ -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, extern int ext4_try_to_write_inline_data(struct address_space *mapping,
struct inode *inode, struct inode *inode,
loff_t pos, unsigned len, loff_t pos, unsigned len,
unsigned flags,
struct page **pagep); struct page **pagep);
extern int ext4_write_inline_data_end(struct inode *inode, extern int ext4_write_inline_data_end(struct inode *inode,
loff_t pos, unsigned len, loff_t pos, unsigned len,
......
...@@ -527,13 +527,13 @@ int ext4_readpage_inline(struct inode *inode, struct page *page) ...@@ -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, static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
struct inode *inode, struct inode *inode)
unsigned flags)
{ {
int ret, needed_blocks, no_expand; int ret, needed_blocks, no_expand;
handle_t *handle = NULL; handle_t *handle = NULL;
int retries = 0, sem_held = 0; int retries = 0, sem_held = 0;
struct page *page = NULL; struct page *page = NULL;
unsigned int flags;
unsigned from, to; unsigned from, to;
struct ext4_iloc iloc; struct ext4_iloc iloc;
...@@ -562,9 +562,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -562,9 +562,9 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
/* We cannot recurse into the filesystem as the transaction is already /* We cannot recurse into the filesystem as the transaction is already
* started */ * started */
flags |= AOP_FLAG_NOFS; flags = memalloc_nofs_save();
page = grab_cache_page_write_begin(mapping, 0, 0);
page = grab_cache_page_write_begin(mapping, 0, flags); memalloc_nofs_restore(flags);
if (!page) { if (!page) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -649,11 +649,11 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -649,11 +649,11 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
int ext4_try_to_write_inline_data(struct address_space *mapping, int ext4_try_to_write_inline_data(struct address_space *mapping,
struct inode *inode, struct inode *inode,
loff_t pos, unsigned len, loff_t pos, unsigned len,
unsigned flags,
struct page **pagep) struct page **pagep)
{ {
int ret; int ret;
handle_t *handle; handle_t *handle;
unsigned int flags;
struct page *page; struct page *page;
struct ext4_iloc iloc; struct ext4_iloc iloc;
...@@ -691,9 +691,9 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, ...@@ -691,9 +691,9 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
if (ret) if (ret)
goto out; goto out;
flags |= AOP_FLAG_NOFS; flags = memalloc_nofs_save();
page = grab_cache_page_write_begin(mapping, 0, 0);
page = grab_cache_page_write_begin(mapping, 0, flags); memalloc_nofs_restore(flags);
if (!page) { if (!page) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -727,8 +727,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, ...@@ -727,8 +727,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
brelse(iloc.bh); brelse(iloc.bh);
return ret; return ret;
convert: convert:
return ext4_convert_inline_data_to_extent(mapping, return ext4_convert_inline_data_to_extent(mapping, inode);
inode, flags);
} }
int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
......
...@@ -1156,7 +1156,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, ...@@ -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)) { if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
ret = ext4_try_to_write_inline_data(mapping, inode, pos, len, ret = ext4_try_to_write_inline_data(mapping, inode, pos, len,
flags, pagep); pagep);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 1) if (ret == 1)
......
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