Skip to content

Commit 9006ad1

Browse files
josefbacikgregkh
authored andcommitted
btrfs: protect space cache inode alloc with GFP_NOFS
commit 84de76a upstream. If we're allocating a new space cache inode it's likely going to be under a transaction handle, so we need to use memalloc_nofs_save() in order to avoid deadlocks, and more importantly lockdep messages that make xfstests fail. CC: [email protected] # 4.4+ Reviewed-by: Omar Sandoval <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0de8cf3 commit 9006ad1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/btrfs/free-space-cache.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/math64.h>
1111
#include <linux/ratelimit.h>
1212
#include <linux/error-injection.h>
13+
#include <linux/sched/mm.h>
1314
#include "ctree.h"
1415
#include "free-space-cache.h"
1516
#include "transaction.h"
@@ -47,6 +48,7 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
4748
struct btrfs_free_space_header *header;
4849
struct extent_buffer *leaf;
4950
struct inode *inode = NULL;
51+
unsigned nofs_flag;
5052
int ret;
5153

5254
key.objectid = BTRFS_FREE_SPACE_OBJECTID;
@@ -68,7 +70,13 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
6870
btrfs_disk_key_to_cpu(&location, &disk_key);
6971
btrfs_release_path(path);
7072

73+
/*
74+
* We are often under a trans handle at this point, so we need to make
75+
* sure NOFS is set to keep us from deadlocking.
76+
*/
77+
nofs_flag = memalloc_nofs_save();
7178
inode = btrfs_iget(fs_info->sb, &location, root, NULL);
79+
memalloc_nofs_restore(nofs_flag);
7280
if (IS_ERR(inode))
7381
return inode;
7482

0 commit comments

Comments
 (0)