Skip to content

Commit

Permalink
ext4: Use scoped memory APIs in ext4_da_write_begin()
Browse files Browse the repository at this point in the history
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) <[email protected]>
Acked-by: Theodore Ts'o <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) committed May 8, 2022
1 parent 8f50c8b commit 36d116e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -3604,7 +3604,6 @@ ext4_journalled_write_inline_data(struct inode *inode,
extern int ext4_da_write_inline_data_begin(struct address_space *mapping,
struct inode *inode,
loff_t pos, unsigned len,
unsigned flags,
struct page **pagep,
void **fsdata);
extern int ext4_try_add_inline_entry(handle_t *handle,
Expand Down
16 changes: 8 additions & 8 deletions fs/ext4/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
struct inode *inode,
loff_t pos, unsigned len,
unsigned flags,
struct page **pagep,
void **fsdata)
{
Expand All @@ -915,6 +914,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
struct page *page;
struct ext4_iloc iloc;
int retries = 0;
unsigned int flags;

ret = ext4_get_inode_loc(inode, &iloc);
if (ret)
Expand All @@ -931,12 +931,6 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
if (ret && ret != -ENOSPC)
goto out_journal;

/*
* We cannot recurse into the filesystem as the transaction
* is already started.
*/
flags |= AOP_FLAG_NOFS;

if (ret == -ENOSPC) {
ext4_journal_stop(handle);
ret = ext4_da_convert_inline_data_to_extent(mapping,
Expand All @@ -948,7 +942,13 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
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) {
ret = -ENOMEM;
goto out_journal;
Expand Down
3 changes: 1 addition & 2 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
ret = ext4_da_write_inline_data_begin(mapping, inode,
pos, len, flags,
ret = ext4_da_write_inline_data_begin(mapping, inode, pos, len,
pagep, fsdata);
if (ret < 0)
return ret;
Expand Down

0 comments on commit 36d116e

Please sign in to comment.