ext4: Use scoped memory APIs in ext4_da_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 8f50c8b7
...@@ -3604,7 +3604,6 @@ ext4_journalled_write_inline_data(struct inode *inode, ...@@ -3604,7 +3604,6 @@ ext4_journalled_write_inline_data(struct inode *inode,
extern int ext4_da_write_inline_data_begin(struct address_space *mapping, extern int ext4_da_write_inline_data_begin(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,
void **fsdata); void **fsdata);
extern int ext4_try_add_inline_entry(handle_t *handle, extern int ext4_try_add_inline_entry(handle_t *handle,
......
...@@ -906,7 +906,6 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, ...@@ -906,7 +906,6 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
int ext4_da_write_inline_data_begin(struct address_space *mapping, int ext4_da_write_inline_data_begin(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,
void **fsdata) void **fsdata)
{ {
...@@ -915,6 +914,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, ...@@ -915,6 +914,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
struct page *page; struct page *page;
struct ext4_iloc iloc; struct ext4_iloc iloc;
int retries = 0; int retries = 0;
unsigned int flags;
ret = ext4_get_inode_loc(inode, &iloc); ret = ext4_get_inode_loc(inode, &iloc);
if (ret) if (ret)
...@@ -931,12 +931,6 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, ...@@ -931,12 +931,6 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
if (ret && ret != -ENOSPC) if (ret && ret != -ENOSPC)
goto out_journal; goto out_journal;
/*
* We cannot recurse into the filesystem as the transaction
* is already started.
*/
flags |= AOP_FLAG_NOFS;
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
ext4_journal_stop(handle); ext4_journal_stop(handle);
ret = ext4_da_convert_inline_data_to_extent(mapping, ret = ext4_da_convert_inline_data_to_extent(mapping,
...@@ -948,7 +942,13 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, ...@@ -948,7 +942,13 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
goto out; goto out;
} }
page = grab_cache_page_write_begin(mapping, 0, flags); /*
* We cannot recurse into the filesystem as the transaction
* is already started.
*/
flags = memalloc_nofs_save();
page = grab_cache_page_write_begin(mapping, 0, 0);
memalloc_nofs_restore(flags);
if (!page) { if (!page) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_journal; goto out_journal;
......
...@@ -2954,8 +2954,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, ...@@ -2954,8 +2954,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
trace_ext4_da_write_begin(inode, pos, len, flags); trace_ext4_da_write_begin(inode, pos, len, flags);
if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
ret = ext4_da_write_inline_data_begin(mapping, inode, ret = ext4_da_write_inline_data_begin(mapping, inode, pos, len,
pos, len, flags,
pagep, fsdata); pagep, fsdata);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
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