Btrfs: setup a nofs context for memory allocation at __btrfs_set_acl
[sfrench/cifs-2.6.git] / fs / btrfs / acl.c
index 3b66c957ea6f2a02f49e8581d032cf22745ea80c..5810463dc6d210b274d85e8a8819f7579fcf4dbc 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/posix_acl_xattr.h>
 #include <linux/posix_acl.h>
 #include <linux/sched.h>
+#include <linux/sched/mm.h>
 #include <linux/slab.h>
 
 #include "ctree.h"
@@ -72,8 +73,16 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
        }
 
        if (acl) {
+               unsigned int nofs_flag;
+
                size = posix_acl_xattr_size(acl->a_count);
+               /*
+                * We're holding a transaction handle, so use a NOFS memory
+                * allocation context to avoid deadlock if reclaim happens.
+                */
+               nofs_flag = memalloc_nofs_save();
                value = kmalloc(size, GFP_KERNEL);
+               memalloc_nofs_restore(nofs_flag);
                if (!value) {
                        ret = -ENOMEM;
                        goto out;