[PATCH 03/10] ext4: Use memalloc_nofs_* scope API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>
---
 fs/ext4/inline.c      | 21 +++++++++++++--------
 fs/ext4/move_extent.c | 12 ++++++++----
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 70cf4c7b268a..e59f8a8e40e7 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -7,6 +7,7 @@
 #include <linux/iomap.h>
 #include <linux/fiemap.h>
 #include <linux/iversion.h>
+#include <linux/sched/mm.h>
 
 #include "ext4_jbd2.h"
 #include "ext4.h"
@@ -525,6 +526,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
 	struct page *page = NULL;
 	unsigned from, to;
 	struct ext4_iloc iloc;
+	int nofs_flags;
 
 	if (!ext4_has_inline_data(inode)) {
 		/*
@@ -551,9 +553,12 @@ 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;
+	nofs_flags = memalloc_nofs_save();
 
 	page = grab_cache_page_write_begin(mapping, 0, flags);
+
+	memalloc_nofs_restore(nofs_flags);
+
 	if (!page) {
 		ret = -ENOMEM;
 		goto out;
@@ -645,6 +650,8 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
 	handle_t *handle;
 	struct page *page;
 	struct ext4_iloc iloc;
+	unsigned nofs_flags;
+
 
 	if (pos + len > ext4_get_max_inline_size(inode))
 		goto convert;
@@ -675,9 +682,11 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
 		goto convert;
 	}
 
-	flags |= AOP_FLAG_NOFS;
+	nofs_flags = memalloc_nofs_save();
 
 	page = grab_cache_page_write_begin(mapping, 0, flags);
+
+	memalloc_nofs_restore(nofs_flags);
 	if (!page) {
 		ret = -ENOMEM;
 		goto out;
@@ -873,17 +882,13 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
 			goto out_journal;
 	}
 
-	/*
-	 * We cannot recurse into the filesystem as the transaction
-	 * is already started.
-	 */
-	flags |= AOP_FLAG_NOFS;
-
 	if (ret == -ENOSPC) {
+		int nofs_flags = memalloc_nofs_save();
 		ret = ext4_da_convert_inline_data_to_extent(mapping,
 							    inode,
 							    flags,
 							    fsdata);
+		memalloc_nofs_restore(nofs_flags);
 		ext4_journal_stop(handle);
 		if (ret == -ENOSPC &&
 		    ext4_should_retry_alloc(inode->i_sb, &retries))
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index b96e4bd3b3ec..9e35e72dcd29 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -8,6 +8,7 @@
 #include <linux/fs.h>
 #include <linux/quotaops.h>
 #include <linux/slab.h>
+#include <linux/sched/mm.h>
 #include "ext4_jbd2.h"
 #include "ext4.h"
 #include "ext4_extents.h"
@@ -127,7 +128,7 @@ mext_page_double_lock(struct inode *inode1, struct inode *inode2,
 		      pgoff_t index1, pgoff_t index2, struct page *page[2])
 {
 	struct address_space *mapping[2];
-	unsigned fl = AOP_FLAG_NOFS;
+	unsigned nofs_fl = memalloc_nofs_save();
 
 	BUG_ON(!inode1 || !inode2);
 	if (inode1 < inode2) {
@@ -141,11 +142,14 @@ mext_page_double_lock(struct inode *inode1, struct inode *inode2,
 		mapping[1] = inode1->i_mapping;
 	}
 
-	page[0] = grab_cache_page_write_begin(mapping[0], index1, fl);
-	if (!page[0])
+	page[0] = grab_cache_page_write_begin(mapping[0], index1, 0);
+	if (!page[0]) {
+		memalloc_nofs_restore(nofs_fl);
 		return -ENOMEM;
+	}
 
-	page[1] = grab_cache_page_write_begin(mapping[1], index2, fl);
+	page[1] = grab_cache_page_write_begin(mapping[1], index2, 0);
+	memalloc_nofs_restore(nofs_fl);
 	if (!page[1]) {
 		unlock_page(page[0]);
 		put_page(page[0]);
-- 
2.16.1




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux