Btrfs: check return value of lookup_extent_mapping() correctly
[firefly-linux-kernel-4.4.55.git] / fs / btrfs / volumes.c
index e0b7bb92a170c3ad529fca30ed9f6539646dbbe5..cd040bf3fd87134bd36c76e40b29d7d0eab46b1d 100644 (file)
@@ -33,6 +33,7 @@
 #include "print-tree.h"
 #include "volumes.h"
 #include "async-thread.h"
+#include "check-integrity.h"
 
 static int init_first_rw_device(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
@@ -247,7 +248,7 @@ loop_lock:
                        sync_pending = 0;
                }
 
-               submit_bio(cur->bi_rw, cur);
+               btrfsic_submit_bio(cur->bi_rw, cur);
                num_run++;
                batch_run++;
                if (need_resched())
@@ -1953,7 +1954,7 @@ static int btrfs_relocate_chunk(struct btrfs_root *root,
        em = lookup_extent_mapping(em_tree, chunk_offset, 1);
        read_unlock(&em_tree->lock);
 
-       BUG_ON(em->start > chunk_offset ||
+       BUG_ON(!em || em->start > chunk_offset ||
               em->start + em->len < chunk_offset);
        map = (struct map_lookup *)em->bdev;
 
@@ -3165,7 +3166,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
                        max_stripe_size = 256 * 1024 * 1024;
                max_chunk_size = max_stripe_size;
        } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
-               max_stripe_size = 8 * 1024 * 1024;
+               max_stripe_size = 32 * 1024 * 1024;
                max_chunk_size = 2 * max_stripe_size;
        } else {
                printk(KERN_ERR "btrfs: invalid chunk type 0x%llx requested\n",
@@ -3962,7 +3963,7 @@ static noinline int schedule_bio(struct btrfs_root *root,
        /* don't bother with additional async steps for reads, right now */
        if (!(rw & REQ_WRITE)) {
                bio_get(bio);
-               submit_bio(rw, bio);
+               btrfsic_submit_bio(rw, bio);
                bio_put(bio);
                return 0;
        }
@@ -4057,7 +4058,7 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
                        if (async_submit)
                                schedule_bio(root, dev, rw, bio);
                        else
-                               submit_bio(rw, bio);
+                               btrfsic_submit_bio(rw, bio);
                } else {
                        bio->bi_bdev = root->fs_info->fs_devices->latest_bdev;
                        bio->bi_sector = logical >> 9;
@@ -4356,6 +4357,20 @@ int btrfs_read_sys_array(struct btrfs_root *root)
                return -ENOMEM;
        btrfs_set_buffer_uptodate(sb);
        btrfs_set_buffer_lockdep_class(root->root_key.objectid, sb, 0);
+       /*
+        * The sb extent buffer is artifical and just used to read the system array.
+        * btrfs_set_buffer_uptodate() call does not properly mark all it's
+        * pages up-to-date when the page is larger: extent does not cover the
+        * whole page and consequently check_page_uptodate does not find all
+        * the page's extents up-to-date (the hole beyond sb),
+        * write_extent_buffer then triggers a WARN_ON.
+        *
+        * Regular short extents go through mark_extent_buffer_dirty/writeback cycle,
+        * but sb spans only this function. Add an explicit SetPageUptodate call
+        * to silence the warning eg. on PowerPC 64.
+        */
+       if (PAGE_CACHE_SIZE > BTRFS_SUPER_INFO_SIZE)
+               SetPageUptodate(sb->first_page);
 
        write_extent_buffer(sb, super_copy, 0, BTRFS_SUPER_INFO_SIZE);
        array_size = btrfs_super_sys_array_size(super_copy);