Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux-2.6-microblaze.git] / fs / btrfs / volumes.c
index 214856c..117b433 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/sched.h>
+#include <linux/sched/mm.h>
 #include <linux/bio.h>
 #include <linux/slab.h>
 #include <linux/blkdev.h>
@@ -6484,8 +6485,17 @@ static struct btrfs_device *add_missing_dev(struct btrfs_fs_devices *fs_devices,
                                            u64 devid, u8 *dev_uuid)
 {
        struct btrfs_device *device;
+       unsigned int nofs_flag;
 
+       /*
+        * We call this under the chunk_mutex, so we want to use NOFS for this
+        * allocation, however we don't want to change btrfs_alloc_device() to
+        * always do NOFS because we use it in a lot of other GFP_KERNEL safe
+        * places.
+        */
+       nofs_flag = memalloc_nofs_save();
        device = btrfs_alloc_device(NULL, &devid, dev_uuid);
+       memalloc_nofs_restore(nofs_flag);
        if (IS_ERR(device))
                return device;