btrfs: fix string and comment grammatical issues and typos
[deliverable/linux.git] / fs / btrfs / volumes.c
index c32abbca9d77f65684b85d137fa41bec8bac005c..8fe7fff5ffb735538090f81fa7350be34a538fc1 100644 (file)
@@ -108,7 +108,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
        },
 };
 
-const u64 const btrfs_raid_group[BTRFS_NR_RAID_TYPES] = {
+const u64 btrfs_raid_group[BTRFS_NR_RAID_TYPES] = {
        [BTRFS_RAID_RAID10] = BTRFS_BLOCK_GROUP_RAID10,
        [BTRFS_RAID_RAID1]  = BTRFS_BLOCK_GROUP_RAID1,
        [BTRFS_RAID_DUP]    = BTRFS_BLOCK_GROUP_DUP,
@@ -138,7 +138,7 @@ static struct btrfs_fs_devices *__alloc_fs_devices(void)
 {
        struct btrfs_fs_devices *fs_devs;
 
-       fs_devs = kzalloc(sizeof(*fs_devs), GFP_NOFS);
+       fs_devs = kzalloc(sizeof(*fs_devs), GFP_KERNEL);
        if (!fs_devs)
                return ERR_PTR(-ENOMEM);
 
@@ -220,7 +220,7 @@ static struct btrfs_device *__alloc_device(void)
 {
        struct btrfs_device *dev;
 
-       dev = kzalloc(sizeof(*dev), GFP_NOFS);
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (!dev)
                return ERR_PTR(-ENOMEM);
 
@@ -233,6 +233,7 @@ static struct btrfs_device *__alloc_device(void)
        spin_lock_init(&dev->reada_lock);
        atomic_set(&dev->reada_in_flight, 0);
        atomic_set(&dev->dev_stats_ccnt, 0);
+       btrfs_device_data_ordered_init(dev);
        INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
        INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
 
@@ -732,7 +733,8 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
                 * uuid mutex so nothing we touch in here is going to disappear.
                 */
                if (orig_dev->name) {
-                       name = rcu_string_strdup(orig_dev->name->str, GFP_NOFS);
+                       name = rcu_string_strdup(orig_dev->name->str,
+                                       GFP_KERNEL);
                        if (!name) {
                                kfree(device);
                                goto error;
@@ -1023,16 +1025,16 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
        }
 
        /* make sure our super fits in the device */
-       if (bytenr + PAGE_CACHE_SIZE >= i_size_read(bdev->bd_inode))
+       if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode))
                goto error_bdev_put;
 
        /* make sure our super fits in the page */
-       if (sizeof(*disk_super) > PAGE_CACHE_SIZE)
+       if (sizeof(*disk_super) > PAGE_SIZE)
                goto error_bdev_put;
 
        /* make sure our super doesn't straddle pages on disk */
-       index = bytenr >> PAGE_CACHE_SHIFT;
-       if ((bytenr + sizeof(*disk_super) - 1) >> PAGE_CACHE_SHIFT != index)
+       index = bytenr >> PAGE_SHIFT;
+       if ((bytenr + sizeof(*disk_super) - 1) >> PAGE_SHIFT != index)
                goto error_bdev_put;
 
        /* pull in the page with our super */
@@ -1045,7 +1047,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
        p = kmap(page);
 
        /* align our pointer to the offset of the super block */
-       disk_super = p + (bytenr & ~PAGE_CACHE_MASK);
+       disk_super = p + (bytenr & ~PAGE_MASK);
 
        if (btrfs_super_bytenr(disk_super) != bytenr ||
            btrfs_super_magic(disk_super) != BTRFS_MAGIC)
@@ -1073,7 +1075,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
 
 error_unmap:
        kunmap(page);
-       page_cache_release(page);
+       put_page(page);
 
 error_bdev_put:
        blkdev_put(bdev, flags);
@@ -1183,7 +1185,7 @@ again:
                struct map_lookup *map;
                int i;
 
-               map = (struct map_lookup *)em->bdev;
+               map = em->map_lookup;
                for (i = 0; i < map->num_stripes; i++) {
                        u64 end;
 
@@ -1713,12 +1715,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
        } while (read_seqretry(&root->fs_info->profiles_lock, seq));
 
        num_devices = root->fs_info->fs_devices->num_devices;
-       btrfs_dev_replace_lock(&root->fs_info->dev_replace);
+       btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0);
        if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) {
                WARN_ON(num_devices < 1);
                num_devices--;
        }
-       btrfs_dev_replace_unlock(&root->fs_info->dev_replace);
+       btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0);
 
        if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
                ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
@@ -2163,7 +2165,7 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
 }
 
 /*
- * strore the expected generation for seed devices in device items.
+ * Store the expected generation for seed devices in device items.
  */
 static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
                               struct btrfs_root *root)
@@ -2286,7 +2288,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
                goto error;
        }
 
-       name = rcu_string_strdup(device_path, GFP_NOFS);
+       name = rcu_string_strdup(device_path, GFP_KERNEL);
        if (!name) {
                kfree(device);
                ret = -ENOMEM;
@@ -2747,7 +2749,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
            em->start + em->len < chunk_offset) {
                /*
                 * This is a logic error, but we don't want to just rely on the
-                * user having built with ASSERT enabled, so if ASSERT doens't
+                * user having built with ASSERT enabled, so if ASSERT doesn't
                 * do anything we still error out.
                 */
                ASSERT(0);
@@ -2755,7 +2757,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
                        free_extent_map(em);
                return -EINVAL;
        }
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        lock_chunks(root->fs_info->chunk_root);
        check_system_chunk(trans, extent_root, map->type);
        unlock_chunks(root->fs_info->chunk_root);
@@ -2965,7 +2967,7 @@ static int insert_balance_item(struct btrfs_root *root,
        }
 
        key.objectid = BTRFS_BALANCE_OBJECTID;
-       key.type = BTRFS_BALANCE_ITEM_KEY;
+       key.type = BTRFS_TEMPORARY_ITEM_KEY;
        key.offset = 0;
 
        ret = btrfs_insert_empty_item(trans, root, path, &key,
@@ -3014,7 +3016,7 @@ static int del_balance_item(struct btrfs_root *root)
        }
 
        key.objectid = BTRFS_BALANCE_OBJECTID;
-       key.type = BTRFS_BALANCE_ITEM_KEY;
+       key.type = BTRFS_TEMPORARY_ITEM_KEY;
        key.offset = 0;
 
        ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
@@ -3360,7 +3362,7 @@ static int should_balance_chunk(struct btrfs_root *root,
        } else if ((bargs->flags & BTRFS_BALANCE_ARGS_LIMIT_RANGE)) {
                /*
                 * Same logic as the 'limit' filter; the minimum cannot be
-                * determined here because we do not have the global informatoin
+                * determined here because we do not have the global information
                 * about the count of all chunks that satisfy the filters.
                 */
                if (bargs->limit_max == 0)
@@ -3685,12 +3687,12 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
        }
 
        num_devices = fs_info->fs_devices->num_devices;
-       btrfs_dev_replace_lock(&fs_info->dev_replace);
+       btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
        if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) {
                BUG_ON(num_devices < 1);
                num_devices--;
        }
-       btrfs_dev_replace_unlock(&fs_info->dev_replace);
+       btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
        allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
        if (num_devices == 1)
                allowed |= BTRFS_BLOCK_GROUP_DUP;
@@ -3751,7 +3753,7 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
        if (btrfs_get_num_tolerated_disk_barrier_failures(bctl->meta.target) <
                btrfs_get_num_tolerated_disk_barrier_failures(bctl->data.target)) {
                btrfs_warn(fs_info,
-       "metatdata profile 0x%llx has lower redundancy than data profile 0x%llx",
+       "metadata profile 0x%llx has lower redundancy than data profile 0x%llx",
                        bctl->meta.target, bctl->data.target);
        }
 
@@ -3866,7 +3868,7 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
                return -ENOMEM;
 
        key.objectid = BTRFS_BALANCE_OBJECTID;
-       key.type = BTRFS_BALANCE_ITEM_KEY;
+       key.type = BTRFS_TEMPORARY_ITEM_KEY;
        key.offset = 0;
 
        ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
@@ -4117,7 +4119,7 @@ out:
  * Callback for btrfs_uuid_tree_iterate().
  * returns:
  * 0   check succeeded, the entry is not outdated.
- * < 0 if an error occured.
+ * < 0 if an error occurred.
  * > 0 if the check failed, which means the caller shall remove the entry.
  */
 static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info,
@@ -4718,7 +4720,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
                goto error;
        }
        set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags);
-       em->bdev = (struct block_device *)map;
+       em->map_lookup = map;
        em->start = start;
        em->len = num_bytes;
        em->block_start = 0;
@@ -4813,7 +4815,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
                return -EINVAL;
        }
 
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        item_size = btrfs_chunk_item_size(map->num_stripes);
        stripe_size = em->orig_block_len;
 
@@ -4968,7 +4970,7 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset)
        if (!em)
                return 1;
 
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        for (i = 0; i < map->num_stripes; i++) {
                if (map->stripes[i].dev->missing) {
                        miss_ndevs++;
@@ -5048,7 +5050,7 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
                return 1;
        }
 
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1))
                ret = map->num_stripes;
        else if (map->type & BTRFS_BLOCK_GROUP_RAID10)
@@ -5061,10 +5063,10 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
                ret = 1;
        free_extent_map(em);
 
-       btrfs_dev_replace_lock(&fs_info->dev_replace);
+       btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
        if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))
                ret++;
-       btrfs_dev_replace_unlock(&fs_info->dev_replace);
+       btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
 
        return ret;
 }
@@ -5084,7 +5086,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
        BUG_ON(!em);
 
        BUG_ON(em->start > logical || em->start + em->len < logical);
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
                len = map->stripe_len * nr_data_stripes(map);
        free_extent_map(em);
@@ -5105,7 +5107,7 @@ int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
        BUG_ON(!em);
 
        BUG_ON(em->start > logical || em->start + em->len < logical);
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
                ret = 1;
        free_extent_map(em);
@@ -5264,7 +5266,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                return -EINVAL;
        }
 
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
        offset = logical - em->start;
 
        stripe_len = map->stripe_len;
@@ -5324,10 +5326,12 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
        if (!bbio_ret)
                goto out;
 
-       btrfs_dev_replace_lock(dev_replace);
+       btrfs_dev_replace_lock(dev_replace, 0);
        dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace);
        if (!dev_replace_is_ongoing)
-               btrfs_dev_replace_unlock(dev_replace);
+               btrfs_dev_replace_unlock(dev_replace, 0);
+       else
+               btrfs_dev_replace_set_lock_blocking(dev_replace);
 
        if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 &&
            !(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)) &&
@@ -5378,35 +5382,33 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                 * target drive.
                 */
                for (i = 0; i < tmp_num_stripes; i++) {
-                       if (tmp_bbio->stripes[i].dev->devid == srcdev_devid) {
-                               /*
-                                * In case of DUP, in order to keep it
-                                * simple, only add the mirror with the
-                                * lowest physical address
-                                */
-                               if (found &&
-                                   physical_of_found <=
-                                    tmp_bbio->stripes[i].physical)
-                                       continue;
-                               index_srcdev = i;
-                               found = 1;
-                               physical_of_found =
-                                       tmp_bbio->stripes[i].physical;
-                       }
+                       if (tmp_bbio->stripes[i].dev->devid != srcdev_devid)
+                               continue;
+
+                       /*
+                        * In case of DUP, in order to keep it simple, only add
+                        * the mirror with the lowest physical address
+                        */
+                       if (found &&
+                           physical_of_found <= tmp_bbio->stripes[i].physical)
+                               continue;
+
+                       index_srcdev = i;
+                       found = 1;
+                       physical_of_found = tmp_bbio->stripes[i].physical;
                }
 
-               if (found) {
-                       mirror_num = index_srcdev + 1;
-                       patch_the_first_stripe_for_dev_replace = 1;
-                       physical_to_patch_in_first_stripe = physical_of_found;
-               } else {
+               btrfs_put_bbio(tmp_bbio);
+
+               if (!found) {
                        WARN_ON(1);
                        ret = -EIO;
-                       btrfs_put_bbio(tmp_bbio);
                        goto out;
                }
 
-               btrfs_put_bbio(tmp_bbio);
+               mirror_num = index_srcdev + 1;
+               patch_the_first_stripe_for_dev_replace = 1;
+               physical_to_patch_in_first_stripe = physical_of_found;
        } else if (mirror_num > map->num_stripes) {
                mirror_num = 0;
        }
@@ -5752,8 +5754,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                bbio->mirror_num = map->num_stripes + 1;
        }
 out:
-       if (dev_replace_is_ongoing)
-               btrfs_dev_replace_unlock(dev_replace);
+       if (dev_replace_is_ongoing) {
+               btrfs_dev_replace_clear_lock_blocking(dev_replace);
+               btrfs_dev_replace_unlock(dev_replace, 0);
+       }
        free_extent_map(em);
        return ret;
 }
@@ -5806,7 +5810,7 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
                free_extent_map(em);
                return -EIO;
        }
-       map = (struct map_lookup *)em->bdev;
+       map = em->map_lookup;
 
        length = em->len;
        rmap_len = map->stripe_len;
@@ -6028,7 +6032,7 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
 {
        atomic_inc(&bbio->error);
        if (atomic_dec_and_test(&bbio->stripes_pending)) {
-               /* Shoud be the original bio. */
+               /* Should be the original bio. */
                WARN_ON(bio != bbio->orig_bio);
 
                btrfs_io_bio(bio)->mirror_num = bbio->mirror_num;
@@ -6069,7 +6073,8 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
        bbio->fs_info = root->fs_info;
        atomic_set(&bbio->stripes_pending, bbio->num_stripes);
 
-       if (bbio->raid_map) {
+       if ((bbio->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
+           ((rw & WRITE) || (mirror_num > 1))) {
                /* In this case, map_length has been set to the length of
                   a single stripe; not the whole write */
                if (rw & WRITE) {
@@ -6210,6 +6215,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
        struct extent_map *em;
        u64 logical;
        u64 length;
+       u64 stripe_len;
        u64 devid;
        u8 uuid[BTRFS_UUID_SIZE];
        int num_stripes;
@@ -6218,6 +6224,37 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
 
        logical = key->offset;
        length = btrfs_chunk_length(leaf, chunk);
+       stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
+       num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
+       /* Validation check */
+       if (!num_stripes) {
+               btrfs_err(root->fs_info, "invalid chunk num_stripes: %u",
+                         num_stripes);
+               return -EIO;
+       }
+       if (!IS_ALIGNED(logical, root->sectorsize)) {
+               btrfs_err(root->fs_info,
+                         "invalid chunk logical %llu", logical);
+               return -EIO;
+       }
+       if (!length || !IS_ALIGNED(length, root->sectorsize)) {
+               btrfs_err(root->fs_info,
+                       "invalid chunk length %llu", length);
+               return -EIO;
+       }
+       if (!is_power_of_2(stripe_len)) {
+               btrfs_err(root->fs_info, "invalid chunk stripe length: %llu",
+                         stripe_len);
+               return -EIO;
+       }
+       if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) &
+           btrfs_chunk_type(leaf, chunk)) {
+               btrfs_err(root->fs_info, "unrecognized chunk type: %llu",
+                         ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
+                           BTRFS_BLOCK_GROUP_PROFILE_MASK) &
+                         btrfs_chunk_type(leaf, chunk));
+               return -EIO;
+       }
 
        read_lock(&map_tree->map_tree.lock);
        em = lookup_extent_mapping(&map_tree->map_tree, logical, 1);
@@ -6234,7 +6271,6 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
        em = alloc_extent_map();
        if (!em)
                return -ENOMEM;
-       num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
        map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
        if (!map) {
                free_extent_map(em);
@@ -6242,7 +6278,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
        }
 
        set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags);
-       em->bdev = (struct block_device *)map;
+       em->map_lookup = map;
        em->start = logical;
        em->len = length;
        em->orig_start = 0;
@@ -6480,7 +6516,7 @@ int btrfs_read_sys_array(struct btrfs_root *root)
        set_extent_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.
+        * The sb extent buffer is artificial and just used to read the system array.
         * set_extent_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
@@ -6491,7 +6527,7 @@ int btrfs_read_sys_array(struct btrfs_root *root)
         * 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)
+       if (PAGE_SIZE > BTRFS_SUPER_INFO_SIZE)
                SetPageUptodate(sb->pages[0]);
 
        write_extent_buffer(sb, super_copy, 0, BTRFS_SUPER_INFO_SIZE);
@@ -6674,8 +6710,8 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
                int item_size;
                struct btrfs_dev_stats_item *ptr;
 
-               key.objectid = 0;
-               key.type = BTRFS_DEV_STATS_KEY;
+               key.objectid = BTRFS_DEV_STATS_OBJECTID;
+               key.type = BTRFS_PERSISTENT_ITEM_KEY;
                key.offset = device->devid;
                ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0);
                if (ret) {
@@ -6722,8 +6758,8 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
        int ret;
        int i;
 
-       key.objectid = 0;
-       key.type = BTRFS_DEV_STATS_KEY;
+       key.objectid = BTRFS_DEV_STATS_OBJECTID;
+       key.type = BTRFS_PERSISTENT_ITEM_KEY;
        key.offset = device->devid;
 
        path = btrfs_alloc_path();
@@ -6944,7 +6980,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_root *root,
        /* In order to kick the device replace finish process */
        lock_chunks(root);
        list_for_each_entry(em, &transaction->pending_chunks, list) {
-               map = (struct map_lookup *)em->bdev;
+               map = em->map_lookup;
 
                for (i = 0; i < map->num_stripes; i++) {
                        dev = map->stripes[i].dev;
This page took 0.034897 seconds and 5 git commands to generate.