Commit 832ee62d authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle)
Browse files

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
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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,
+10 −11
Original line number Diff line number Diff line
@@ -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 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,

	/* 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 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
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 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
	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,
+1 −1
Original line number Diff line number Diff line
@@ -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)