aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 366b335946fa..e2b54d546b7c 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -138,7 +138,7 @@ static struct btrfs_fs_devices *__alloc_fs_devices(void)
138{ 138{
139 struct btrfs_fs_devices *fs_devs; 139 struct btrfs_fs_devices *fs_devs;
140 140
141 fs_devs = kzalloc(sizeof(*fs_devs), GFP_NOFS); 141 fs_devs = kzalloc(sizeof(*fs_devs), GFP_KERNEL);
142 if (!fs_devs) 142 if (!fs_devs)
143 return ERR_PTR(-ENOMEM); 143 return ERR_PTR(-ENOMEM);
144 144
@@ -220,7 +220,7 @@ static struct btrfs_device *__alloc_device(void)
220{ 220{
221 struct btrfs_device *dev; 221 struct btrfs_device *dev;
222 222
223 dev = kzalloc(sizeof(*dev), GFP_NOFS); 223 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
224 if (!dev) 224 if (!dev)
225 return ERR_PTR(-ENOMEM); 225 return ERR_PTR(-ENOMEM);
226 226
@@ -733,7 +733,8 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
733 * uuid mutex so nothing we touch in here is going to disappear. 733 * uuid mutex so nothing we touch in here is going to disappear.
734 */ 734 */
735 if (orig_dev->name) { 735 if (orig_dev->name) {
736 name = rcu_string_strdup(orig_dev->name->str, GFP_NOFS); 736 name = rcu_string_strdup(orig_dev->name->str,
737 GFP_KERNEL);
737 if (!name) { 738 if (!name) {
738 kfree(device); 739 kfree(device);
739 goto error; 740 goto error;
@@ -1714,12 +1715,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1714 } while (read_seqretry(&root->fs_info->profiles_lock, seq)); 1715 } while (read_seqretry(&root->fs_info->profiles_lock, seq));
1715 1716
1716 num_devices = root->fs_info->fs_devices->num_devices; 1717 num_devices = root->fs_info->fs_devices->num_devices;
1717 btrfs_dev_replace_lock(&root->fs_info->dev_replace); 1718 btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0);
1718 if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) { 1719 if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) {
1719 WARN_ON(num_devices < 1); 1720 WARN_ON(num_devices < 1);
1720 num_devices--; 1721 num_devices--;
1721 } 1722 }
1722 btrfs_dev_replace_unlock(&root->fs_info->dev_replace); 1723 btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0);
1723 1724
1724 if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) { 1725 if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
1725 ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; 1726 ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
@@ -2287,7 +2288,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
2287 goto error; 2288 goto error;
2288 } 2289 }
2289 2290
2290 name = rcu_string_strdup(device_path, GFP_NOFS); 2291 name = rcu_string_strdup(device_path, GFP_KERNEL);
2291 if (!name) { 2292 if (!name) {
2292 kfree(device); 2293 kfree(device);
2293 ret = -ENOMEM; 2294 ret = -ENOMEM;
@@ -2748,7 +2749,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
2748 em->start + em->len < chunk_offset) { 2749 em->start + em->len < chunk_offset) {
2749 /* 2750 /*
2750 * This is a logic error, but we don't want to just rely on the 2751 * This is a logic error, but we don't want to just rely on the
2751 * user having built with ASSERT enabled, so if ASSERT doens't 2752 * user having built with ASSERT enabled, so if ASSERT doesn't
2752 * do anything we still error out. 2753 * do anything we still error out.
2753 */ 2754 */
2754 ASSERT(0); 2755 ASSERT(0);
@@ -2966,7 +2967,7 @@ static int insert_balance_item(struct btrfs_root *root,
2966 } 2967 }
2967 2968
2968 key.objectid = BTRFS_BALANCE_OBJECTID; 2969 key.objectid = BTRFS_BALANCE_OBJECTID;
2969 key.type = BTRFS_BALANCE_ITEM_KEY; 2970 key.type = BTRFS_TEMPORARY_ITEM_KEY;
2970 key.offset = 0; 2971 key.offset = 0;
2971 2972
2972 ret = btrfs_insert_empty_item(trans, root, path, &key, 2973 ret = btrfs_insert_empty_item(trans, root, path, &key,
@@ -3015,7 +3016,7 @@ static int del_balance_item(struct btrfs_root *root)
3015 } 3016 }
3016 3017
3017 key.objectid = BTRFS_BALANCE_OBJECTID; 3018 key.objectid = BTRFS_BALANCE_OBJECTID;
3018 key.type = BTRFS_BALANCE_ITEM_KEY; 3019 key.type = BTRFS_TEMPORARY_ITEM_KEY;
3019 key.offset = 0; 3020 key.offset = 0;
3020 3021
3021 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 3022 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
@@ -3686,12 +3687,12 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
3686 } 3687 }
3687 3688
3688 num_devices = fs_info->fs_devices->num_devices; 3689 num_devices = fs_info->fs_devices->num_devices;
3689 btrfs_dev_replace_lock(&fs_info->dev_replace); 3690 btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
3690 if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) { 3691 if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) {
3691 BUG_ON(num_devices < 1); 3692 BUG_ON(num_devices < 1);
3692 num_devices--; 3693 num_devices--;
3693 } 3694 }
3694 btrfs_dev_replace_unlock(&fs_info->dev_replace); 3695 btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
3695 allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE; 3696 allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
3696 if (num_devices == 1) 3697 if (num_devices == 1)
3697 allowed |= BTRFS_BLOCK_GROUP_DUP; 3698 allowed |= BTRFS_BLOCK_GROUP_DUP;
@@ -3867,7 +3868,7 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
3867 return -ENOMEM; 3868 return -ENOMEM;
3868 3869
3869 key.objectid = BTRFS_BALANCE_OBJECTID; 3870 key.objectid = BTRFS_BALANCE_OBJECTID;
3870 key.type = BTRFS_BALANCE_ITEM_KEY; 3871 key.type = BTRFS_TEMPORARY_ITEM_KEY;
3871 key.offset = 0; 3872 key.offset = 0;
3872 3873
3873 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); 3874 ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
@@ -4118,7 +4119,7 @@ out:
4118 * Callback for btrfs_uuid_tree_iterate(). 4119 * Callback for btrfs_uuid_tree_iterate().
4119 * returns: 4120 * returns:
4120 * 0 check succeeded, the entry is not outdated. 4121 * 0 check succeeded, the entry is not outdated.
4121 * < 0 if an error occured. 4122 * < 0 if an error occurred.
4122 * > 0 if the check failed, which means the caller shall remove the entry. 4123 * > 0 if the check failed, which means the caller shall remove the entry.
4123 */ 4124 */
4124static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info, 4125static int btrfs_check_uuid_tree_entry(struct btrfs_fs_info *fs_info,
@@ -5062,10 +5063,10 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
5062 ret = 1; 5063 ret = 1;
5063 free_extent_map(em); 5064 free_extent_map(em);
5064 5065
5065 btrfs_dev_replace_lock(&fs_info->dev_replace); 5066 btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
5066 if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) 5067 if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))
5067 ret++; 5068 ret++;
5068 btrfs_dev_replace_unlock(&fs_info->dev_replace); 5069 btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
5069 5070
5070 return ret; 5071 return ret;
5071} 5072}
@@ -5325,10 +5326,12 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5325 if (!bbio_ret) 5326 if (!bbio_ret)
5326 goto out; 5327 goto out;
5327 5328
5328 btrfs_dev_replace_lock(dev_replace); 5329 btrfs_dev_replace_lock(dev_replace, 0);
5329 dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace); 5330 dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace);
5330 if (!dev_replace_is_ongoing) 5331 if (!dev_replace_is_ongoing)
5331 btrfs_dev_replace_unlock(dev_replace); 5332 btrfs_dev_replace_unlock(dev_replace, 0);
5333 else
5334 btrfs_dev_replace_set_lock_blocking(dev_replace);
5332 5335
5333 if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 && 5336 if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 &&
5334 !(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)) && 5337 !(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)) &&
@@ -5751,8 +5754,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
5751 bbio->mirror_num = map->num_stripes + 1; 5754 bbio->mirror_num = map->num_stripes + 1;
5752 } 5755 }
5753out: 5756out:
5754 if (dev_replace_is_ongoing) 5757 if (dev_replace_is_ongoing) {
5755 btrfs_dev_replace_unlock(dev_replace); 5758 btrfs_dev_replace_clear_lock_blocking(dev_replace);
5759 btrfs_dev_replace_unlock(dev_replace, 0);
5760 }
5756 free_extent_map(em); 5761 free_extent_map(em);
5757 return ret; 5762 return ret;
5758} 5763}
@@ -6705,8 +6710,8 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
6705 int item_size; 6710 int item_size;
6706 struct btrfs_dev_stats_item *ptr; 6711 struct btrfs_dev_stats_item *ptr;
6707 6712
6708 key.objectid = 0; 6713 key.objectid = BTRFS_DEV_STATS_OBJECTID;
6709 key.type = BTRFS_DEV_STATS_KEY; 6714 key.type = BTRFS_PERSISTENT_ITEM_KEY;
6710 key.offset = device->devid; 6715 key.offset = device->devid;
6711 ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0); 6716 ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0);
6712 if (ret) { 6717 if (ret) {
@@ -6753,8 +6758,8 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
6753 int ret; 6758 int ret;
6754 int i; 6759 int i;
6755 6760
6756 key.objectid = 0; 6761 key.objectid = BTRFS_DEV_STATS_OBJECTID;
6757 key.type = BTRFS_DEV_STATS_KEY; 6762 key.type = BTRFS_PERSISTENT_ITEM_KEY;
6758 key.offset = device->devid; 6763 key.offset = device->devid;
6759 6764
6760 path = btrfs_alloc_path(); 6765 path = btrfs_alloc_path();