diff options
author | Linus Torvalds | 2016-12-16 19:53:01 +0100 |
---|---|---|
committer | Linus Torvalds | 2016-12-16 19:53:01 +0100 |
commit | 087a76d390cbb8c0d21ea0cb3672ab4a7bb76362 (patch) | |
tree | 7c86752ba8d430c37618851ee2806b5b921299bd /fs/btrfs/volumes.c | |
parent | Merge tag 'nfsd-4.10' of git://linux-nfs.org/~bfields/linux (diff) | |
parent | btrfs: limit async_work allocation and worker func duration (diff) | |
download | kernel-qcow2-linux-087a76d390cbb8c0d21ea0cb3672ab4a7bb76362.tar.gz kernel-qcow2-linux-087a76d390cbb8c0d21ea0cb3672ab4a7bb76362.tar.xz kernel-qcow2-linux-087a76d390cbb8c0d21ea0cb3672ab4a7bb76362.zip |
Merge branch 'for-linus-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs updates from Chris Mason:
"Jeff Mahoney and Dave Sterba have a really nice set of cleanups in
here, and Christoph pitched in corrections/improvements to make btrfs
use proper helpers for bio walking instead of doing it by hand.
There are some key fixes as well, including some long standing bugs
that took forever to track down in btrfs_drop_extents and during
balance"
* 'for-linus-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (77 commits)
btrfs: limit async_work allocation and worker func duration
Revert "Btrfs: adjust len of writes if following a preallocated extent"
Btrfs: don't WARN() in btrfs_transaction_abort() for IO errors
btrfs: opencode chunk locking, remove helpers
btrfs: remove root parameter from transaction commit/end routines
btrfs: split btrfs_wait_marked_extents into normal and tree log functions
btrfs: take an fs_info directly when the root is not used otherwise
btrfs: simplify btrfs_wait_cache_io prototype
btrfs: convert extent-tree tracepoints to use fs_info
btrfs: root->fs_info cleanup, access fs_info->delayed_root directly
btrfs: root->fs_info cleanup, add fs_info convenience variables
btrfs: root->fs_info cleanup, update_block_group{,flags}
btrfs: root->fs_info cleanup, lock/unlock_chunks
btrfs: root->fs_info cleanup, btrfs_calc_{trans,trunc}_metadata_size
btrfs: pull node/sector/stripe sizes out of root and into fs_info
btrfs: root->fs_info cleanup, io_ctl_init
btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
btrfs: struct reada_control.root -> reada_control.fs_info
btrfs: struct btrfsic_state->root should be an fs_info
btrfs: alloc_reserved_file_extent trace point should use extent_root
...
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r-- | fs/btrfs/volumes.c | 845 |
1 files changed, 413 insertions, 432 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0d7d635d8bfb..3c3c69c0eee4 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -134,9 +134,9 @@ const int btrfs_raid_mindev_error[BTRFS_NR_RAID_TYPES] = { }; static int init_first_rw_device(struct btrfs_trans_handle *trans, - struct btrfs_root *root, + struct btrfs_fs_info *fs_info, struct btrfs_device *device); -static int btrfs_relocate_sys_chunks(struct btrfs_root *root); +static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info); static void __btrfs_reset_dev_stats(struct btrfs_device *dev); static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev); static void btrfs_dev_stat_print_on_load(struct btrfs_device *device); @@ -343,9 +343,9 @@ static void requeue_list(struct btrfs_pending_bios *pending_bios, */ static noinline void run_scheduled_bios(struct btrfs_device *device) { + struct btrfs_fs_info *fs_info = device->fs_info; struct bio *pending; struct backing_dev_info *bdi; - struct btrfs_fs_info *fs_info; struct btrfs_pending_bios *pending_bios; struct bio *tail; struct bio *cur; @@ -367,7 +367,6 @@ static noinline void run_scheduled_bios(struct btrfs_device *device) blk_start_plug(&plug); bdi = blk_get_backing_dev_info(device->bdev); - fs_info = device->dev_root->fs_info; limit = btrfs_async_submit_limit(fs_info); limit = limit * 2 / 3; @@ -1179,7 +1178,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, u64 end, u64 *length) { struct btrfs_key key; - struct btrfs_root *root = device->dev_root; + struct btrfs_root *root = device->fs_info->dev_root; struct btrfs_dev_extent *dev_extent; struct btrfs_path *path; u64 extent_end; @@ -1262,7 +1261,7 @@ static int contains_pending_extent(struct btrfs_transaction *transaction, struct btrfs_device *device, u64 *start, u64 len) { - struct btrfs_fs_info *fs_info = device->dev_root->fs_info; + struct btrfs_fs_info *fs_info = device->fs_info; struct extent_map *em; struct list_head *search_list = &fs_info->pinned_chunks; int ret = 0; @@ -1338,8 +1337,9 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction, struct btrfs_device *device, u64 num_bytes, u64 search_start, u64 *start, u64 *len) { + struct btrfs_fs_info *fs_info = device->fs_info; + struct btrfs_root *root = fs_info->dev_root; struct btrfs_key key; - struct btrfs_root *root = device->dev_root; struct btrfs_dev_extent *dev_extent; struct btrfs_path *path; u64 hole_size; @@ -1357,7 +1357,7 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction, * used by the boot loader (grub for example), so we make sure to start * at an offset of at least 1MB. */ - min_search_start = max(root->fs_info->alloc_start, 1024ull * 1024); + min_search_start = max(fs_info->alloc_start, 1024ull * 1024); search_start = max(search_start, min_search_start); path = btrfs_alloc_path(); @@ -1508,9 +1508,10 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 start, u64 *dev_extent_len) { + struct btrfs_fs_info *fs_info = device->fs_info; + struct btrfs_root *root = fs_info->dev_root; int ret; struct btrfs_path *path; - struct btrfs_root *root = device->dev_root; struct btrfs_key key; struct btrfs_key found_key; struct extent_buffer *leaf = NULL; @@ -1544,7 +1545,7 @@ again: extent = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_extent); } else { - btrfs_handle_fs_error(root->fs_info, ret, "Slot search failed"); + btrfs_handle_fs_error(fs_info, ret, "Slot search failed"); goto out; } @@ -1552,8 +1553,8 @@ again: ret = btrfs_del_item(trans, root, path); if (ret) { - btrfs_handle_fs_error(root->fs_info, ret, - "Failed to remove dev extent item"); + btrfs_handle_fs_error(fs_info, ret, + "Failed to remove dev extent item"); } else { set_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags); } @@ -1569,7 +1570,8 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, { int ret; struct btrfs_path *path; - struct btrfs_root *root = device->dev_root; + struct btrfs_fs_info *fs_info = device->fs_info; + struct btrfs_root *root = fs_info->dev_root; struct btrfs_dev_extent *extent; struct extent_buffer *leaf; struct btrfs_key key; @@ -1595,8 +1597,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, btrfs_set_dev_extent_chunk_objectid(leaf, extent, chunk_objectid); btrfs_set_dev_extent_chunk_offset(leaf, extent, chunk_offset); - write_extent_buffer(leaf, root->fs_info->chunk_tree_uuid, - btrfs_dev_extent_chunk_tree_uuid(extent), BTRFS_UUID_SIZE); + write_extent_buffer_chunk_tree_uuid(leaf, fs_info->chunk_tree_uuid); btrfs_set_dev_extent_length(leaf, extent, num_bytes); btrfs_mark_buffer_dirty(leaf); @@ -1667,9 +1668,10 @@ error: * the btrfs_device struct should be fully filled in */ static int btrfs_add_device(struct btrfs_trans_handle *trans, - struct btrfs_root *root, + struct btrfs_fs_info *fs_info, struct btrfs_device *device) { + struct btrfs_root *root = fs_info->chunk_root; int ret; struct btrfs_path *path; struct btrfs_dev_item *dev_item; @@ -1677,8 +1679,6 @@ static int btrfs_add_device(struct btrfs_trans_handle *trans, struct btrfs_key key; unsigned long ptr; - root = root->fs_info->chunk_root; - path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -1713,7 +1713,7 @@ static int btrfs_add_device(struct btrfs_trans_handle *trans, ptr = btrfs_device_uuid(dev_item); write_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE); ptr = btrfs_device_fsid(dev_item); - write_extent_buffer(leaf, root->fs_info->fsid, ptr, BTRFS_UUID_SIZE); + write_extent_buffer(leaf, fs_info->fsid, ptr, BTRFS_UUID_SIZE); btrfs_mark_buffer_dirty(leaf); ret = 0; @@ -1737,16 +1737,15 @@ static void update_dev_time(char *path_name) filp_close(filp, NULL); } -static int btrfs_rm_dev_item(struct btrfs_root *root, +static int btrfs_rm_dev_item(struct btrfs_fs_info *fs_info, struct btrfs_device *device) { + struct btrfs_root *root = fs_info->chunk_root; int ret; struct btrfs_path *path; struct btrfs_key key; struct btrfs_trans_handle *trans; - root = root->fs_info->chunk_root; - path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -1774,7 +1773,7 @@ static int btrfs_rm_dev_item(struct btrfs_root *root, goto out; out: btrfs_free_path(path); - btrfs_commit_transaction(trans, root); + btrfs_commit_transaction(trans); return ret; } @@ -1853,7 +1852,7 @@ void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info, fs_info->fs_devices->latest_bdev = next_device->bdev; } -int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) +int btrfs_rm_device(struct btrfs_fs_info *fs_info, char *device_path, u64 devid) { struct btrfs_device *device; struct btrfs_fs_devices *cur_devices; @@ -1863,20 +1862,20 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) mutex_lock(&uuid_mutex); - num_devices = root->fs_info->fs_devices->num_devices; - btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0); - if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) { + num_devices = fs_info->fs_devices->num_devices; + btrfs_dev_replace_lock(&fs_info->dev_replace, 0); + if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) { WARN_ON(num_devices < 1); num_devices--; } - btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0); + btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); - ret = btrfs_check_raid_min_devices(root->fs_info, num_devices - 1); + ret = btrfs_check_raid_min_devices(fs_info, num_devices - 1); if (ret) goto out; - ret = btrfs_find_device_by_devspec(root, devid, device_path, - &device); + ret = btrfs_find_device_by_devspec(fs_info, devid, device_path, + &device); if (ret) goto out; @@ -1885,16 +1884,16 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) goto out; } - if (device->writeable && root->fs_info->fs_devices->rw_devices == 1) { + if (device->writeable && fs_info->fs_devices->rw_devices == 1) { ret = BTRFS_ERROR_DEV_ONLY_WRITABLE; goto out; } if (device->writeable) { - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); list_del_init(&device->dev_alloc_list); device->fs_devices->rw_devices--; - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); clear_super = true; } @@ -1909,12 +1908,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) * counter although write_all_supers() is not locked out. This * could give a filesystem state which requires a degraded mount. */ - ret = btrfs_rm_dev_item(root->fs_info->chunk_root, device); + ret = btrfs_rm_dev_item(fs_info, device); if (ret) goto error_undo; device->in_fs_metadata = 0; - btrfs_scrub_cancel_dev(root->fs_info, device); + btrfs_scrub_cancel_dev(fs_info, device); /* * the device list mutex makes sure that we don't change @@ -1927,7 +1926,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) */ cur_devices = device->fs_devices; - mutex_lock(&root->fs_info->fs_devices->device_list_mutex); + mutex_lock(&fs_info->fs_devices->device_list_mutex); list_del_rcu(&device->dev_list); device->fs_devices->num_devices--; @@ -1936,17 +1935,17 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) if (device->missing) device->fs_devices->missing_devices--; - btrfs_assign_next_active_device(root->fs_info, device, NULL); + btrfs_assign_next_active_device(fs_info, device, NULL); if (device->bdev) { device->fs_devices->open_devices--; /* remove sysfs entry */ - btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device); + btrfs_sysfs_rm_device_link(fs_info->fs_devices, device); } - num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1; - btrfs_set_super_num_devices(root->fs_info->super_copy, num_devices); - mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); + num_devices = btrfs_super_num_devices(fs_info->super_copy) - 1; + btrfs_set_super_num_devices(fs_info->super_copy, num_devices); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); /* * at this point, the device is zero sized and detached from @@ -1961,7 +1960,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) if (cur_devices->open_devices == 0) { struct btrfs_fs_devices *fs_devices; - fs_devices = root->fs_info->fs_devices; + fs_devices = fs_info->fs_devices; while (fs_devices) { if (fs_devices->seed == cur_devices) { fs_devices->seed = cur_devices->seed; @@ -1974,8 +1973,8 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid) free_fs_devices(cur_devices); } - root->fs_info->num_tolerated_disk_barrier_failures = - btrfs_calc_num_tolerated_disk_barrier_failures(root->fs_info); + fs_info->num_tolerated_disk_barrier_failures = + btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); out: mutex_unlock(&uuid_mutex); @@ -1983,11 +1982,11 @@ out: error_undo: if (device->writeable) { - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); list_add(&device->dev_alloc_list, - &root->fs_info->fs_devices->alloc_list); + &fs_info->fs_devices->alloc_list); device->fs_devices->rw_devices++; - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); } goto out; } @@ -2092,7 +2091,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, call_rcu(&tgtdev->rcu, free_device); } -static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path, +static int btrfs_find_device_by_path(struct btrfs_fs_info *fs_info, + char *device_path, struct btrfs_device **device) { int ret = 0; @@ -2104,14 +2104,13 @@ static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path, *device = NULL; ret = btrfs_get_bdev_and_sb(device_path, FMODE_READ, - root->fs_info->bdev_holder, 0, &bdev, &bh); + fs_info->bdev_holder, 0, &bdev, &bh); if (ret) return ret; disk_super = (struct btrfs_super_block *)bh->b_data; devid = btrfs_stack_device_id(&disk_super->dev_item); dev_uuid = disk_super->dev_item.uuid; - *device = btrfs_find_device(root->fs_info, devid, dev_uuid, - disk_super->fsid); + *device = btrfs_find_device(fs_info, devid, dev_uuid, disk_super->fsid); brelse(bh); if (!*device) ret = -ENOENT; @@ -2119,7 +2118,7 @@ static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path, return ret; } -int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, +int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info, char *device_path, struct btrfs_device **device) { @@ -2128,7 +2127,7 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, struct list_head *devices; struct btrfs_device *tmp; - devices = &root->fs_info->fs_devices->devices; + devices = &fs_info->fs_devices->devices; /* * It is safe to read the devices since the volume_mutex * is held by the caller. @@ -2145,30 +2144,28 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_root *root, return 0; } else { - return btrfs_find_device_by_path(root, device_path, device); + return btrfs_find_device_by_path(fs_info, device_path, device); } } /* * Lookup a device given by device id, or the path if the id is 0. */ -int btrfs_find_device_by_devspec(struct btrfs_root *root, u64 devid, - char *devpath, - struct btrfs_device **device) +int btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info, u64 devid, + char *devpath, struct btrfs_device **device) { int ret; if (devid) { ret = 0; - *device = btrfs_find_device(root->fs_info, devid, NULL, - NULL); + *device = btrfs_find_device(fs_info, devid, NULL, NULL); if (!*device) ret = -ENOENT; } else { if (!devpath || !devpath[0]) return -EINVAL; - ret = btrfs_find_device_missing_or_by_path(root, devpath, + ret = btrfs_find_device_missing_or_by_path(fs_info, devpath, device); } return ret; @@ -2177,12 +2174,12 @@ int btrfs_find_device_by_devspec(struct btrfs_root *root, u64 devid, /* * does all the dirty work required for changing file system's UUID. */ -static int btrfs_prepare_sprout(struct btrfs_root *root) +static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info) { - struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; struct btrfs_fs_devices *old_devices; struct btrfs_fs_devices *seed_devices; - struct btrfs_super_block *disk_super = root->fs_info->super_copy; + struct btrfs_super_block *disk_super = fs_info->super_copy; struct btrfs_device *device; u64 super_flags; @@ -2208,15 +2205,15 @@ static int btrfs_prepare_sprout(struct btrfs_root *root) INIT_LIST_HEAD(&seed_devices->alloc_list); mutex_init(&seed_devices->device_list_mutex); - mutex_lock(&root->fs_info->fs_devices->device_list_mutex); + mutex_lock(&fs_info->fs_devices->device_list_mutex); list_splice_init_rcu(&fs_devices->devices, &seed_devices->devices, synchronize_rcu); list_for_each_entry(device, &seed_devices->devices, dev_list) device->fs_devices = seed_devices; - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); list_splice_init(&fs_devices->alloc_list, &seed_devices->alloc_list); - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); fs_devices->seeding = 0; fs_devices->num_devices = 0; @@ -2226,9 +2223,9 @@ static int btrfs_prepare_sprout(struct btrfs_root *root) fs_devices->seed = seed_devices; generate_random_uuid(fs_devices->fsid); - memcpy(root->fs_info->fsid, fs_devices->fsid, BTRFS_FSID_SIZE); + memcpy(fs_info->fsid, fs_devices->fsid, BTRFS_FSID_SIZE); memcpy(disk_super->fsid, fs_devices->fsid, BTRFS_FSID_SIZE); - mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); super_flags = btrfs_super_flags(disk_super) & ~BTRFS_SUPER_FLAG_SEEDING; @@ -2241,8 +2238,9 @@ static int btrfs_prepare_sprout(struct btrfs_root *root) * Store the expected generation for seed devices in device items. */ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans, - struct btrfs_root *root) + struct btrfs_fs_info *fs_info) { + struct btrfs_root *root = fs_info->chunk_root; struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_dev_item *dev_item; @@ -2257,7 +2255,6 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans, if (!path) return -ENOMEM; - root = root->fs_info->chunk_root; key.objectid = BTRFS_DEV_ITEMS_OBJECTID; key.offset = 0; key.type = BTRFS_DEV_ITEM_KEY; @@ -2293,8 +2290,7 @@ next_slot: BTRFS_UUID_SIZE); read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item), BTRFS_UUID_SIZE); - device = btrfs_find_device(root->fs_info, devid, dev_uuid, - fs_uuid); + device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid); BUG_ON(!device); /* Logic error */ if (device->fs_devices->seeding) { @@ -2312,28 +2308,29 @@ error: return ret; } -int btrfs_init_new_device(struct btrfs_root *root, char *device_path) +int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path) { + struct btrfs_root *root = fs_info->dev_root; struct request_queue *q; struct btrfs_trans_handle *trans; struct btrfs_device *device; struct block_device *bdev; struct list_head *devices; - struct super_block *sb = root->fs_info->sb; + struct super_block *sb = fs_info->sb; struct rcu_string *name; u64 tmp; int seeding_dev = 0; int ret = 0; - if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding) + if ((sb->s_flags & MS_RDONLY) && !fs_info->fs_devices->seeding) return -EROFS; bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL, - root->fs_info->bdev_holder); + fs_info->bdev_holder); if (IS_ERR(bdev)) return PTR_ERR(bdev); - if (root->fs_info->fs_devices->seeding) { + if (fs_info->fs_devices->seeding) { seeding_dev = 1; down_write(&sb->s_umount); mutex_lock(&uuid_mutex); @@ -2341,20 +2338,20 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) filemap_write_and_wait(bdev->bd_inode->i_mapping); - devices = &root->fs_info->fs_devices->devices; + devices = &fs_info->fs_devices->devices; - mutex_lock(&root->fs_info->fs_devices->device_list_mutex); + mutex_lock(&fs_info->fs_devices->device_list_mutex); list_for_each_entry(device, devices, dev_list) { if (device->bdev == bdev) { ret = -EEXIST; mutex_unlock( - &root->fs_info->fs_devices->device_list_mutex); + &fs_info->fs_devices->device_list_mutex); goto error; } } - mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); - device = btrfs_alloc_device(root->fs_info, NULL, NULL); + device = btrfs_alloc_device(fs_info, NULL, NULL); if (IS_ERR(device)) { /* we can safely leave the fs_devices entry around */ ret = PTR_ERR(device); @@ -2382,13 +2379,13 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) device->can_discard = 1; device->writeable = 1; device->generation = trans->transid; - device->io_width = root->sectorsize; - device->io_align = root->sectorsize; - device->sector_size = root->sectorsize; + device->io_width = fs_info->sectorsize; + device->io_align = fs_info->sectorsize; + device->sector_size = fs_info->sectorsize; device->total_bytes = i_size_read(bdev->bd_inode); device->disk_total_bytes = device->total_bytes; device->commit_total_bytes = device->total_bytes; - device->dev_root = root->fs_info->dev_root; + device->fs_info = fs_info; device->bdev = bdev; device->in_fs_metadata = 1; device->is_tgtdev_for_dev_replace = 0; @@ -2398,61 +2395,60 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) if (seeding_dev) { sb->s_flags &= ~MS_RDONLY; - ret = btrfs_prepare_sprout(root); + ret = btrfs_prepare_sprout(fs_info); BUG_ON(ret); /* -ENOMEM */ } - device->fs_devices = root->fs_info->fs_devices; + device->fs_devices = fs_info->fs_devices; - mutex_lock(&root->fs_info->fs_devices->device_list_mutex); - lock_chunks(root); - list_add_rcu(&device->dev_list, &root->fs_info->fs_devices->devices); + mutex_lock(&fs_info->fs_devices->device_list_mutex); + mutex_lock(&fs_info->chunk_mutex); + list_add_rcu(&device->dev_list, &fs_info->fs_devices->devices); list_add(&device->dev_alloc_list, - &root->fs_info->fs_devices->alloc_list); - root->fs_info->fs_devices->num_devices++; - root->fs_info->fs_devices->open_devices++; - root->fs_info->fs_devices->rw_devices++; - root->fs_info->fs_devices->total_devices++; - root->fs_info->fs_devices->total_rw_bytes += device->total_bytes; + &fs_info->fs_devices->alloc_list); + fs_info->fs_devices->num_devices++; + fs_info->fs_devices->open_devices++; + fs_info->fs_devices->rw_devices++; + fs_info->fs_devices->total_devices++; + fs_info->fs_devices->total_rw_bytes += device->total_bytes; - spin_lock(&root->fs_info->free_chunk_lock); - root->fs_info->free_chunk_space += device->total_bytes; - spin_unlock(&root->fs_info->free_chunk_lock); + spin_lock(&fs_info->free_chunk_lock); + fs_info->free_chunk_space += device->total_bytes; + spin_unlock(&fs_info->free_chunk_lock); if (!blk_queue_nonrot(bdev_get_queue(bdev))) - root->fs_info->fs_devices->rotating = 1; + fs_info->fs_devices->rotating = 1; - tmp = btrfs_super_total_bytes(root->fs_info->super_copy); - btrfs_set_super_total_bytes(root->fs_info->super_copy, + tmp = btrfs_super_total_bytes(fs_info->super_copy); + btrfs_set_super_total_bytes(fs_info->super_copy, tmp + device->total_bytes); - tmp = btrfs_super_num_devices(root->fs_info->super_copy); - btrfs_set_super_num_devices(root->fs_info->super_copy, - tmp + 1); + tmp = btrfs_super_num_devices(fs_info->super_copy); + btrfs_set_super_num_devices(fs_info->super_copy, tmp + 1); /* add sysfs device entry */ - btrfs_sysfs_add_device_link(root->fs_info->fs_devices, device); + btrfs_sysfs_add_device_link(fs_info->fs_devices, device); /* * we've got more storage, clear any full flags on the space * infos */ - btrfs_clear_space_info_full(root->fs_info); + btrfs_clear_space_info_full(fs_info); - unlock_chunks(root); - mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); + mutex_unlock(&fs_info->chunk_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); if (seeding_dev) { - lock_chunks(root); - ret = init_first_rw_device(trans, root, device); - unlock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); + ret = init_first_rw_device(trans, fs_info, device); + mutex_unlock(&fs_info->chunk_mutex); if (ret) { btrfs_abort_transaction(trans, ret); goto error_trans; } } - ret = btrfs_add_device(trans, root, device); + ret = btrfs_add_device(trans, fs_info, device); if (ret) { btrfs_abort_transaction(trans, ret); goto error_trans; @@ -2461,7 +2457,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) if (seeding_dev) { char fsid_buf[BTRFS_UUID_UNPARSED_SIZE]; - ret = btrfs_finish_sprout(trans, root); + ret = btrfs_finish_sprout(trans, fs_info); if (ret) { btrfs_abort_transaction(trans, ret); goto error_trans; @@ -2471,16 +2467,15 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) * so rename the fsid on the sysfs */ snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU", - root->fs_info->fsid); - if (kobject_rename(&root->fs_info->fs_devices->fsid_kobj, - fsid_buf)) - btrfs_warn(root->fs_info, - "sysfs: failed to create fsid for sprout"); + fs_info->fsid); + if (kobject_rename(&fs_info->fs_devices->fsid_kobj, fsid_buf)) + btrfs_warn(fs_info, + "sysfs: failed to create fsid for sprout"); } - root->fs_info->num_tolerated_disk_barrier_failures = - btrfs_calc_num_tolerated_disk_barrier_failures(root->fs_info); - ret = btrfs_commit_transaction(trans, root); + fs_info->num_tolerated_disk_barrier_failures = + btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); + ret = btrfs_commit_transaction(trans); if (seeding_dev) { mutex_unlock(&uuid_mutex); @@ -2489,9 +2484,9 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) if (ret) /* transaction commit */ return ret; - ret = btrfs_relocate_sys_chunks(root); + ret = btrfs_relocate_sys_chunks(fs_info); if (ret < 0) - btrfs_handle_fs_error(root->fs_info, ret, + btrfs_handle_fs_error(fs_info, ret, "Failed to relocate sys chunks after device initialization. This can be fixed using the \"btrfs balance\" command."); trans = btrfs_attach_transaction(root); if (IS_ERR(trans)) { @@ -2499,7 +2494,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) return 0; return PTR_ERR(trans); } - ret = btrfs_commit_transaction(trans, root); + ret = btrfs_commit_transaction(trans); } /* Update ctime/mtime for libblkid */ @@ -2507,9 +2502,9 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) return ret; error_trans: - btrfs_end_transaction(trans, root); + btrfs_end_transaction(trans); rcu_string_free(device->name); - btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device); + btrfs_sysfs_rm_device_link(fs_info->fs_devices, device); kfree(device); error: blkdev_put(bdev, FMODE_EXCL); @@ -2520,14 +2515,14 @@ error: return ret; } -int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path, +int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, + char *device_path, struct btrfs_device *srcdev, struct btrfs_device **device_out) { struct request_queue *q; struct btrfs_device *device; struct block_device *bdev; - struct btrfs_fs_info *fs_info = root->fs_info; struct list_head *devices; struct rcu_string *name; u64 devid = BTRFS_DEV_REPLACE_DEVID; @@ -2585,19 +2580,19 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path, q = bdev_get_queue(bdev); if (blk_queue_discard(q)) device->can_discard = 1; - mutex_lock(&root->fs_info->fs_devices->device_list_mutex); + mutex_lock(&fs_info->fs_devices->device_list_mutex); device->writeable = 1; device->generation = 0; - device->io_width = root->sectorsize; - device->io_align = root->sectorsize; - device->sector_size = root->sectorsize; + device->io_width = fs_info->sectorsize; + device->io_align = fs_info->sectorsize; + device->sector_size = fs_info->sectorsize; device->total_bytes = btrfs_device_get_total_bytes(srcdev); device->disk_total_bytes = btrfs_device_get_disk_total_bytes(srcdev); device->bytes_used = btrfs_device_get_bytes_used(srcdev); ASSERT(list_empty(&srcdev->resized_list)); device->commit_total_bytes = srcdev->commit_total_bytes; device->commit_bytes_used = device->bytes_used; - device->dev_root = fs_info->dev_root; + device->fs_info = fs_info; device->bdev = bdev; device->in_fs_metadata = 1; device->is_tgtdev_for_dev_replace = 1; @@ -2608,7 +2603,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path, list_add(&device->dev_list, &fs_info->fs_devices->devices); fs_info->fs_devices->num_devices++; fs_info->fs_devices->open_devices++; - mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); *device_out = device; return ret; @@ -2621,11 +2616,13 @@ error: void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info, struct btrfs_device *tgtdev) { + u32 sectorsize = fs_info->sectorsize; + WARN_ON(fs_info->fs_devices->rw_devices == 0); - tgtdev->io_width = fs_info->dev_root->sectorsize; - tgtdev->io_align = fs_info->dev_root->sectorsize; - tgtdev->sector_size = fs_info->dev_root->sectorsize; - tgtdev->dev_root = fs_info->dev_root; + tgtdev->io_width = sectorsize; + tgtdev->io_align = sectorsize; + tgtdev->sector_size = sectorsize; + tgtdev->fs_info = fs_info; tgtdev->in_fs_metadata = 1; } @@ -2634,13 +2631,11 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans, { int ret; struct btrfs_path *path; - struct btrfs_root *root; + struct btrfs_root *root = device->fs_info->chunk_root; struct btrfs_dev_item *dev_item; struct extent_buffer *leaf; struct btrfs_key key; - root = device->dev_root->fs_info->chunk_root; - path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -2680,8 +2675,8 @@ out: int btrfs_grow_device(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 new_size) { - struct btrfs_super_block *super_copy = - device->dev_root->fs_info->super_copy; + struct btrfs_fs_info *fs_info = device->fs_info; + struct btrfs_super_block *super_copy = fs_info->super_copy; struct btrfs_fs_devices *fs_devices; u64 old_total; u64 diff; @@ -2689,41 +2684,41 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans, if (!device->writeable) return -EACCES; - lock_chunks(device->dev_root); + mutex_lock(&fs_info->chunk_mutex); old_total = btrfs_super_total_bytes(super_copy); diff = new_size - device->total_bytes; if (new_size <= device->total_bytes || device->is_tgtdev_for_dev_replace) { - unlock_chunks(device->dev_root); + mutex_unlock(&fs_info->chunk_mutex); return -EINVAL; } - fs_devices = device->dev_root->fs_info->fs_devices; + fs_devices = fs_info->fs_devices; btrfs_set_super_total_bytes(super_copy, old_total + diff); device->fs_devices->total_rw_bytes += diff; btrfs_device_set_total_bytes(device, new_size); btrfs_device_set_disk_total_bytes(device, new_size); - btrfs_clear_space_info_full(device->dev_root->fs_info); + btrfs_clear_space_info_full(device->fs_info); if (list_empty(&device->resized_list)) list_add_tail(&device->resized_list, &fs_devices->resized_devices); - unlock_chunks(device->dev_root); + mutex_unlock(&fs_info->chunk_mutex); return btrfs_update_device(trans, device); } static int btrfs_free_chunk(struct btrfs_trans_handle *trans, - struct btrfs_root *root, u64 chunk_objectid, + struct btrfs_fs_info *fs_info, u64 chunk_objectid, u64 chunk_offset) { + struct btrfs_root *root = fs_info->chunk_root; int ret; struct btrfs_path *path; struct btrfs_key key; - root = root->fs_info->chunk_root; path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -2736,25 +2731,25 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, if (ret < 0) goto out; else if (ret > 0) { /* Logic error or corruption */ - btrfs_handle_fs_error(root->fs_info, -ENOENT, - "Failed lookup while freeing chunk."); + btrfs_handle_fs_error(fs_info, -ENOENT, + "Failed lookup while freeing chunk."); ret = -ENOENT; goto out; } ret = btrfs_del_item(trans, root, path); if (ret < 0) - btrfs_handle_fs_error(root->fs_info, ret, - "Failed to delete chunk item."); + btrfs_handle_fs_error(fs_info, ret, + "Failed to delete chunk item."); out: btrfs_free_path(path); return ret; } -static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64 - chunk_offset) +static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info, + u64 chunk_objectid, u64 chunk_offset) { - struct btrfs_super_block *super_copy = root->fs_info->super_copy; + struct btrfs_super_block *super_copy = fs_info->super_copy; struct btrfs_disk_key *disk_key; struct btrfs_chunk *chunk; u8 *ptr; @@ -2765,7 +2760,7 @@ static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64 u32 cur; struct btrfs_key key; - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); array_size = btrfs_super_sys_array_size(super_copy); ptr = super_copy->sys_chunk_array; @@ -2795,25 +2790,22 @@ static int btrfs_del_sys_chunk(struct btrfs_root *root, u64 chunk_objectid, u64 cur += len; } } - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); return ret; } int btrfs_remove_chunk(struct btrfs_trans_handle *trans, - struct btrfs_root *root, u64 chunk_offset) + struct btrfs_fs_info *fs_info, u64 chunk_offset) { struct extent_map_tree *em_tree; struct extent_map *em; - struct btrfs_root *extent_root = root->fs_info->extent_root; struct map_lookup *map; u64 dev_extent_len = 0; u64 chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; int i, ret = 0; - struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; - /* Just in case */ - root = root->fs_info->chunk_root; - em_tree = &root->fs_info->mapping_tree.map_tree; + em_tree = &fs_info->mapping_tree.map_tree; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, chunk_offset, 1); @@ -2832,9 +2824,9 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, return -EINVAL; } 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); + mutex_lock(&fs_info->chunk_mutex); + check_system_chunk(trans, fs_info, map->type); + mutex_unlock(&fs_info->chunk_mutex); /* * Take the device list mutex to prevent races with the final phase of @@ -2854,14 +2846,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, } if (device->bytes_used > 0) { - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); btrfs_device_set_bytes_used(device, device->bytes_used - dev_extent_len); - spin_lock(&root->fs_info->free_chunk_lock); - root->fs_info->free_chunk_space += dev_extent_len; - spin_unlock(&root->fs_info->free_chunk_lock); - btrfs_clear_space_info_full(root->fs_info); - unlock_chunks(root); + spin_lock(&fs_info->free_chunk_lock); + fs_info->free_chunk_space += dev_extent_len; + spin_unlock(&fs_info->free_chunk_lock); + btrfs_clear_space_info_full(fs_info); + mutex_unlock(&fs_info->chunk_mutex); } if (map->stripes[i].dev) { @@ -2875,23 +2867,24 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, } mutex_unlock(&fs_devices->device_list_mutex); - ret = btrfs_free_chunk(trans, root, chunk_objectid, chunk_offset); + ret = btrfs_free_chunk(trans, fs_info, chunk_objectid, chunk_offset); if (ret) { btrfs_abort_transaction(trans, ret); goto out; } - trace_btrfs_chunk_free(root, map, chunk_offset, em->len); + trace_btrfs_chunk_free(fs_info, map, chunk_offset, em->len); if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) { - ret = btrfs_del_sys_chunk(root, chunk_objectid, chunk_offset); + ret = btrfs_del_sys_chunk(fs_info, chunk_objectid, + chunk_offset); if (ret) { btrfs_abort_transaction(trans, ret); goto out; } } - ret = btrfs_remove_block_group(trans, extent_root, chunk_offset, em); + ret = btrfs_remove_block_group(trans, fs_info, chunk_offset, em); if (ret) { btrfs_abort_transaction(trans, ret); goto out; @@ -2903,15 +2896,12 @@ out: return ret; } -static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) +static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset) { - struct btrfs_root *extent_root; + struct btrfs_root *root = fs_info->chunk_root; struct btrfs_trans_handle *trans; int ret; - root = root->fs_info->chunk_root; - extent_root = root->fs_info->extent_root; - /* * Prevent races with automatic removal of unused block groups. * After we relocate and before we remove the chunk with offset @@ -2924,16 +2914,16 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) * we release the path used to search the chunk/dev tree and before * the current task acquires this mutex and calls us. */ - ASSERT(mutex_is_locked(&root->fs_info->delete_unused_bgs_mutex)); + ASSERT(mutex_is_locked(&fs_info->delete_unused_bgs_mutex)); - ret = btrfs_can_relocate(extent_root, chunk_offset); + ret = btrfs_can_relocate(fs_info, chunk_offset); if (ret) return -ENOSPC; /* step one, relocate all the extents inside this chunk */ - btrfs_scrub_pause(root); - ret = btrfs_relocate_block_group(extent_root, chunk_offset); - btrfs_scrub_continue(root); + btrfs_scrub_pause(fs_info); + ret = btrfs_relocate_block_group(fs_info, chunk_offset); + btrfs_scrub_continue(fs_info); if (ret) return ret; @@ -2949,14 +2939,14 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) * step two, delete the device extents and the * chunk tree entries */ - ret = btrfs_remove_chunk(trans, root, chunk_offset); - btrfs_end_transaction(trans, extent_root); + ret = btrfs_remove_chunk(trans, fs_info, chunk_offset); + btrfs_end_transaction(trans); return ret; } -static int btrfs_relocate_sys_chunks(struct btrfs_root *root) +static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info) { - struct btrfs_root *chunk_root = root->fs_info->chunk_root; + struct btrfs_root *chunk_root = fs_info->chunk_root; struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_chunk *chunk; @@ -2977,10 +2967,10 @@ again: key.type = BTRFS_CHUNK_ITEM_KEY; while (1) { - mutex_lock(&root->fs_info->delete_unused_bgs_mutex); + mutex_lock(&fs_info->delete_unused_bgs_mutex); ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0); if (ret < 0) { - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); goto error; } BUG_ON(ret == 0); /* Corruption */ @@ -2988,7 +2978,7 @@ again: ret = btrfs_previous_item(chunk_root, path, key.objectid, key.type); if (ret) - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); if (ret < 0) goto error; if (ret > 0) @@ -3003,14 +2993,13 @@ again: btrfs_release_path(path); if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) { - ret = btrfs_relocate_chunk(chunk_root, - found_key.offset); + ret = btrfs_relocate_chunk(fs_info, found_key.offset); if (ret == -ENOSPC) failed++; else BUG_ON(ret); } - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); if (found_key.offset == 0) break; @@ -3029,9 +3018,10 @@ error: return ret; } -static int insert_balance_item(struct btrfs_root *root, +static int insert_balance_item(struct btrfs_fs_info *fs_info, struct btrfs_balance_control *bctl) { + struct btrfs_root *root = fs_info->tree_root; struct btrfs_trans_handle *trans; struct btrfs_balance_item *item; struct btrfs_disk_balance_args disk_bargs; @@ -3062,7 +3052,7 @@ static int insert_balance_item(struct btrfs_root *root, leaf = path->nodes[0]; item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item); - memset_extent_buffer(leaf, 0, (unsigned long)item, sizeof(*item)); + memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item)); btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data); btrfs_set_balance_data(leaf, item, &disk_bargs); @@ -3076,14 +3066,15 @@ static int insert_balance_item(struct btrfs_root *root, btrfs_mark_buffer_dirty(leaf); out: btrfs_free_path(path); - err = btrfs_commit_transaction(trans, root); + err = btrfs_commit_transaction(trans); if (err && !ret) ret = err; return ret; } -static int del_balance_item(struct btrfs_root *root) +static int del_balance_item(struct btrfs_fs_info *fs_info) { + struct btrfs_root *root = fs_info->tree_root; struct btrfs_trans_handle *trans; struct btrfs_path *path; struct btrfs_key key; @@ -3114,7 +3105,7 @@ static int del_balance_item(struct btrfs_root *root) ret = btrfs_del_item(trans, root, path); out: btrfs_free_path(path); - err = btrfs_commit_transaction(trans, root); + err = btrfs_commit_transaction(trans); if (err && !ret) ret = err; return ret; @@ -3369,11 +3360,11 @@ static int chunk_soft_convert_filter(u64 chunk_type, return 0; } -static int should_balance_chunk(struct btrfs_root *root, +static int should_balance_chunk(struct btrfs_fs_info *fs_info, struct extent_buffer *leaf, struct btrfs_chunk *chunk, u64 chunk_offset) { - struct btrfs_balance_control *bctl = root->fs_info->balance_ctl; + struct btrfs_balance_control *bctl = fs_info->balance_ctl; struct btrfs_balance_args *bargs = NULL; u64 chunk_type = btrfs_chunk_type(leaf, chunk); @@ -3398,10 +3389,10 @@ static int should_balance_chunk(struct btrfs_root *root, /* usage filter */ if ((bargs->flags & BTRFS_BALANCE_ARGS_USAGE) && - chunk_usage_filter(bctl->fs_info, chunk_offset, bargs)) { + chunk_usage_filter(fs_info, chunk_offset, bargs)) { return 0; } else if ((bargs->flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) && - chunk_usage_range_filter(bctl->fs_info, chunk_offset, bargs)) { + chunk_usage_range_filter(fs_info, chunk_offset, bargs)) { return 0; } @@ -3521,7 +3512,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ret = btrfs_grow_device(trans, device, old_size); if (ret) { - btrfs_end_transaction(trans, dev_root); + btrfs_end_transaction(trans); /* btrfs_grow_device never returns ret > 0 */ WARN_ON(ret > 0); btrfs_info_in_rcu(fs_info, @@ -3531,7 +3522,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) goto error; } - btrfs_end_transaction(trans, dev_root); + btrfs_end_transaction(trans); } /* step two, relocate all the chunks */ @@ -3606,7 +3597,7 @@ again: spin_unlock(&fs_info->balance_lock); } - ret = should_balance_chunk(chunk_root, leaf, chunk, + ret = should_balance_chunk(fs_info, leaf, chunk, found_key.offset); btrfs_release_path(path); @@ -3659,9 +3650,9 @@ again: goto error; } - ret = btrfs_force_chunk_alloc(trans, chunk_root, + ret = btrfs_force_chunk_alloc(trans, fs_info, BTRFS_BLOCK_GROUP_DATA); - btrfs_end_transaction(trans, chunk_root); + btrfs_end_transaction(trans); if (ret < 0) { mutex_unlock(&fs_info->delete_unused_bgs_mutex); goto error; @@ -3669,8 +3660,7 @@ again: chunk_reserved = 1; } - ret = btrfs_relocate_chunk(chunk_root, - found_key.offset); + ret = btrfs_relocate_chunk(fs_info, found_key.offset); mutex_unlock(&fs_info->delete_unused_bgs_mutex); if (ret && ret != -ENOSPC) goto error; @@ -3741,7 +3731,7 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info) int ret; unset_balance_control(fs_info); - ret = del_balance_item(fs_info->tree_root); + ret = del_balance_item(fs_info); if (ret) btrfs_handle_fs_error(fs_info, ret, NULL); @@ -3874,7 +3864,7 @@ int btrfs_balance(struct btrfs_balance_control *bctl, bctl->sys.target)); } - ret = insert_balance_item(fs_info->tree_root, bctl); + ret = insert_balance_item(fs_info, bctl); if (ret && ret != -EEXIST) goto out; @@ -4166,7 +4156,7 @@ static int btrfs_uuid_scan_kthread(void *data) } update_tree: if (!btrfs_is_empty_uuid(root_item.uuid)) { - ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, + ret = btrfs_uuid_tree_add(trans, fs_info, root_item.uuid, BTRFS_UUID_KEY_SUBVOL, key.objectid); @@ -4178,7 +4168,7 @@ update_tree: } if (!btrfs_is_empty_uuid(root_item.received_uuid)) { - ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, + ret = btrfs_uuid_tree_add(trans, fs_info, root_item.received_uuid, BTRFS_UUID_KEY_RECEIVED_SUBVOL, key.objectid); @@ -4191,7 +4181,7 @@ update_tree: skip: if (trans) { - ret = btrfs_end_transaction(trans, fs_info->uuid_root); + ret = btrfs_end_transaction(trans); trans = NULL; if (ret) break; @@ -4216,7 +4206,7 @@ skip: out: btrfs_free_path(path); if (trans && !IS_ERR(trans)) - btrfs_end_transaction(trans, fs_info->uuid_root); + btrfs_end_transaction(trans); if (ret) btrfs_warn(fs_info, "btrfs_uuid_scan_kthread failed %d", ret); else @@ -4310,13 +4300,13 @@ int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info) if (IS_ERR(uuid_root)) { ret = PTR_ERR(uuid_root); btrfs_abort_transaction(trans, ret); - btrfs_end_transaction(trans, tree_root); + btrfs_end_transaction(trans); return ret; } fs_info->uuid_root = uuid_root; - ret = btrfs_commit_transaction(trans, tree_root); + ret = btrfs_commit_transaction(trans); if (ret) return ret; @@ -4355,8 +4345,9 @@ int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) */ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) { + struct btrfs_fs_info *fs_info = device->fs_info; + struct btrfs_root *root = fs_info->dev_root; struct btrfs_trans_handle *trans; - struct btrfs_root *root = device->dev_root; struct btrfs_dev_extent *dev_extent = NULL; struct btrfs_path *path; u64 length; @@ -4368,7 +4359,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) bool checked_pending_chunks = false; struct extent_buffer *l; struct btrfs_key key; - struct btrfs_super_block *super_copy = root->fs_info->super_copy; + struct btrfs_super_block *super_copy = fs_info->super_copy; u64 old_total = btrfs_super_total_bytes(super_copy); u64 old_size = btrfs_device_get_total_bytes(device); u64 diff = old_size - new_size; @@ -4382,16 +4373,16 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) path->reada = READA_FORWARD; - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); btrfs_device_set_total_bytes(device, new_size); if (device->writeable) { device->fs_devices->total_rw_bytes -= diff; - spin_lock(&root->fs_info->free_chunk_lock); - root->fs_info->free_chunk_space -= diff; - spin_unlock(&root->fs_info->free_chunk_lock); + spin_lock(&fs_info->free_chunk_lock); + fs_info->free_chunk_space -= diff; + spin_unlock(&fs_info->free_chunk_lock); } - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); again: key.objectid = device->devid; @@ -4399,16 +4390,16 @@ again: key.type = BTRFS_DEV_EXTENT_KEY; do { - mutex_lock(&root->fs_info->delete_unused_bgs_mutex); + mutex_lock(&fs_info->delete_unused_bgs_mutex); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) { - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); goto done; } ret = btrfs_previous_item(root, path, 0, key.type); if (ret) - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); if (ret < 0) goto done; if (ret) { @@ -4422,7 +4413,7 @@ again: btrfs_item_key_to_cpu(l, &key, path->slots[0]); if (key.objectid != device->devid) { - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); btrfs_release_path(path); break; } @@ -4431,7 +4422,7 @@ again: length = btrfs_dev_extent_length(l, dev_extent); if (key.offset + length <= new_size) { - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); btrfs_release_path(path); break; } @@ -4439,8 +4430,8 @@ again: chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); btrfs_release_path(path); - ret = btrfs_relocate_chunk(root, chunk_offset); - mutex_unlock(&root->fs_info->delete_unused_bgs_mutex); + ret = btrfs_relocate_chunk(fs_info, chunk_offset); + mutex_unlock(&fs_info->delete_unused_bgs_mutex); if (ret && ret != -ENOSPC) goto done; if (ret == -ENOSPC) @@ -4463,7 +4454,7 @@ again: goto done; } - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); /* * We checked in the above loop all device extents that were already in @@ -4483,11 +4474,11 @@ again: if (contains_pending_extent(trans->transaction, device, &start, len)) { - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); checked_pending_chunks = true; failed = 0; retried = false; - ret = btrfs_commit_transaction(trans, root); + ret = btrfs_commit_transaction(trans); if (ret) goto done; goto again; @@ -4497,44 +4488,44 @@ again: btrfs_device_set_disk_total_bytes(device, new_size); if (list_empty(&device->resized_list)) list_add_tail(&device->resized_list, - &root->fs_info->fs_devices->resized_devices); + &fs_info->fs_devices->resized_devices); WARN_ON(diff > old_total); btrfs_set_super_total_bytes(super_copy, old_total - diff); - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); /* Now btrfs_update_device() will change the on-disk size. */ ret = btrfs_update_device(trans, device); - btrfs_end_transaction(trans, root); + btrfs_end_transaction(trans); done: btrfs_free_path(path); if (ret) { - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); btrfs_device_set_total_bytes(device, old_size); if (device->writeable) device->fs_devices->total_rw_bytes += diff; - spin_lock(&root->fs_info->free_chunk_lock); - root->fs_info->free_chunk_space += diff; - spin_unlock(&root->fs_info->free_chunk_lock); - unlock_chunks(root); + spin_lock(&fs_info->free_chunk_lock); + fs_info->free_chunk_space += diff; + spin_unlock(&fs_info->free_chunk_lock); + mutex_unlock(&fs_info->chunk_mutex); } return ret; } -static int btrfs_add_system_chunk(struct btrfs_root *root, +static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, struct btrfs_chunk *chunk, int item_size) { - struct btrfs_super_block *super_copy = root->fs_info->super_copy; + struct btrfs_super_block *super_copy = fs_info->super_copy; struct btrfs_disk_key disk_key; u32 array_size; u8 *ptr; - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); array_size = btrfs_super_sys_array_size(super_copy); if (array_size + item_size + sizeof(disk_key) > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) { - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); return -EFBIG; } @@ -4545,7 +4536,7 @@ static int btrfs_add_system_chunk(struct btrfs_root *root, memcpy(ptr, chunk, item_size); item_size += sizeof(disk_key); btrfs_set_super_sys_array_size(super_copy, array_size + item_size); - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); return 0; } @@ -4583,7 +4574,7 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type) btrfs_set_fs_incompat(info, RAID56); } -#define BTRFS_MAX_DEVS(r) ((BTRFS_MAX_ITEM_SIZE(r) \ +#define BTRFS_MAX_DEVS(r) ((BTRFS_MAX_ITEM_SIZE(r->fs_info) \ - sizeof(struct btrfs_chunk)) \ / sizeof(struct btrfs_stripe) + 1) @@ -4593,10 +4584,10 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type) / sizeof(struct btrfs_stripe) + 1) static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, - struct btrfs_root *extent_root, u64 start, + struct btrfs_fs_info *fs_info, u64 start, u64 type) { - struct btrfs_fs_info *info = extent_root->fs_info; + struct btrfs_fs_info *info = trans->fs_info; struct btrfs_fs_devices *fs_devices = info->fs_devices; struct list_head *cur; struct map_lookup *map = NULL; @@ -4762,12 +4753,12 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (type & BTRFS_BLOCK_GROUP_RAID5) { raid_stripe_len = find_raid56_stripe_len(ndevs - 1, - extent_root->stripesize); + info->stripesize); data_stripes = num_stripes - 1; } if (type & BTRFS_BLOCK_GROUP_RAID6) { raid_stripe_len = find_raid56_stripe_len(ndevs - 2, - extent_root->stripesize); + info->stripesize); data_stripes = num_stripes - 2; } @@ -4812,7 +4803,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, j * stripe_size; } } - map->sector_size = extent_root->sectorsize; + map->sector_size = info->sectorsize; map->stripe_len = raid_stripe_len; map->io_align = raid_stripe_len; map->io_width = raid_stripe_len; @@ -4821,7 +4812,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, num_bytes = stripe_size * data_stripes; - trace_btrfs_chunk_alloc(info->chunk_root, map, start, num_bytes); + trace_btrfs_chunk_alloc(info, map, start, num_bytes); em = alloc_extent_map(); if (!em) { @@ -4837,7 +4828,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, em->block_len = em->len; em->orig_block_len = stripe_size; - em_tree = &extent_root->fs_info->mapping_tree.map_tree; + em_tree = &info->mapping_tree.map_tree; write_lock(&em_tree->lock); ret = add_extent_mapping(em_tree, em, 0); if (!ret) { @@ -4850,7 +4841,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, goto error; } - ret = btrfs_make_block_group(trans, extent_root, 0, type, + ret = btrfs_make_block_group(trans, info, 0, type, BTRFS_FIRST_CHUNK_TREE_OBJECTID, start, num_bytes); if (ret) @@ -4861,13 +4852,12 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, btrfs_device_set_bytes_used(map->stripes[i].dev, num_bytes); } - spin_lock(&extent_root->fs_info->free_chunk_lock); - extent_root->fs_info->free_chunk_space -= (stripe_size * - map->num_stripes); - spin_unlock(&extent_root->fs_info->free_chunk_lock); + spin_lock(&info->free_chunk_lock); + info->free_chunk_space -= (stripe_size * map->num_stripes); + spin_unlock(&info->free_chunk_lock); free_extent_map(em); - check_raid56_incompat_flag(extent_root->fs_info, type); + check_raid56_incompat_flag(info, type); kfree(devices_info); return 0; @@ -4889,11 +4879,12 @@ error: } int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, - struct btrfs_root *extent_root, + struct btrfs_fs_info *fs_info, u64 chunk_offset, u64 chunk_size) { + struct btrfs_root *extent_root = fs_info->extent_root; + struct btrfs_root *chunk_root = fs_info->chunk_root; struct btrfs_key key; - struct btrfs_root *chunk_root = extent_root->fs_info->chunk_root; struct btrfs_device *device; struct btrfs_chunk *chunk; struct btrfs_stripe *stripe; @@ -4906,20 +4897,19 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, int i = 0; int ret = 0; - em_tree = &extent_root->fs_info->mapping_tree.map_tree; + em_tree = &fs_info->mapping_tree.map_tree; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, chunk_offset, chunk_size); read_unlock(&em_tree->lock); if (!em) { - btrfs_crit(extent_root->fs_info, - "unable to find logical %Lu len %Lu", + btrfs_crit(fs_info, "unable to find logical %Lu len %Lu", chunk_offset, chunk_size); return -EINVAL; } if (em->start != chunk_offset || em->len != chunk_size) { - btrfs_crit(extent_root->fs_info, + btrfs_crit(fs_info, "found a bad mapping, wanted %Lu-%Lu, found %Lu-%Lu", chunk_offset, chunk_size, em->start, em->len); free_extent_map(em); @@ -4943,7 +4933,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, * at any time during that final phase of the device replace operation * (dev-replace.c:btrfs_dev_replace_finishing()). */ - mutex_lock(&chunk_root->fs_info->fs_devices->device_list_mutex); + mutex_lock(&fs_info->fs_devices->device_list_mutex); for (i = 0; i < map->num_stripes; i++) { device = map->stripes[i].dev; dev_offset = map->stripes[i].physical; @@ -4960,7 +4950,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, break; } if (ret) { - mutex_unlock(&chunk_root->fs_info->fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); goto out; } @@ -4974,7 +4964,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, memcpy(stripe->dev_uuid, device->uuid, BTRFS_UUID_SIZE); stripe++; } - mutex_unlock(&chunk_root->fs_info->fs_devices->device_list_mutex); + mutex_unlock(&fs_info->fs_devices->device_list_mutex); btrfs_set_stack_chunk_length(chunk, chunk_size); btrfs_set_stack_chunk_owner(chunk, extent_root->root_key.objectid); @@ -4983,7 +4973,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, btrfs_set_stack_chunk_num_stripes(chunk, map->num_stripes); btrfs_set_stack_chunk_io_align(chunk, map->stripe_len); btrfs_set_stack_chunk_io_width(chunk, map->stripe_len); - btrfs_set_stack_chunk_sector_size(chunk, extent_root->sectorsize); + btrfs_set_stack_chunk_sector_size(chunk, fs_info->sectorsize); btrfs_set_stack_chunk_sub_stripes(chunk, map->sub_stripes); key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; @@ -4996,8 +4986,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, * TODO: Cleanup of inserted chunk root in case of * failure. */ - ret = btrfs_add_system_chunk(chunk_root, &key, chunk, - item_size); + ret = btrfs_add_system_chunk(fs_info, &key, chunk, item_size); } out: @@ -5014,36 +5003,34 @@ out: * bootstrap process of adding storage to a seed btrfs. */ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, - struct btrfs_root *extent_root, u64 type) + struct btrfs_fs_info *fs_info, u64 type) { u64 chunk_offset; - ASSERT(mutex_is_locked(&extent_root->fs_info->chunk_mutex)); - chunk_offset = find_next_chunk(extent_root->fs_info); - return __btrfs_alloc_chunk(trans, extent_root, chunk_offset, type); + ASSERT(mutex_is_locked(&fs_info->chunk_mutex)); + chunk_offset = find_next_chunk(fs_info); + return __btrfs_alloc_chunk(trans, fs_info, chunk_offset, type); } static noinline int init_first_rw_device(struct btrfs_trans_handle *trans, - struct btrfs_root *root, + struct btrfs_fs_info *fs_info, struct btrfs_device *device) { + struct btrfs_root *extent_root = fs_info->extent_root; u64 chunk_offset; u64 sys_chunk_offset; u64 alloc_profile; - struct btrfs_fs_info *fs_info = root->fs_info; - struct btrfs_root *extent_root = fs_info->extent_root; int ret; chunk_offset = find_next_chunk(fs_info); alloc_profile = btrfs_get_alloc_profile(extent_root, 0); - ret = __btrfs_alloc_chunk(trans, extent_root, chunk_offset, - alloc_profile); + ret = __btrfs_alloc_chunk(trans, fs_info, chunk_offset, alloc_profile); if (ret) return ret; - sys_chunk_offset = find_next_chunk(root->fs_info); + sys_chunk_offset = find_next_chunk(fs_info); alloc_profile = btrfs_get_alloc_profile(fs_info->chunk_root, 0); - ret = __btrfs_alloc_chunk(trans, extent_root, sys_chunk_offset, + ret = __btrfs_alloc_chunk(trans, fs_info, sys_chunk_offset, alloc_profile); return ret; } @@ -5066,11 +5053,11 @@ static inline int btrfs_chunk_max_errors(struct map_lookup *map) return max_errors; } -int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset) +int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset) { struct extent_map *em; struct map_lookup *map; - struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; + struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; int readonly = 0; int miss_ndevs = 0; int i; @@ -5182,14 +5169,14 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len) return ret; } -unsigned long btrfs_full_stripe_len(struct btrfs_root *root, +unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info, struct btrfs_mapping_tree *map_tree, u64 logical) { struct extent_map *em; struct map_lookup *map; struct extent_map_tree *em_tree = &map_tree->map_tree; - unsigned long len = root->sectorsize; + unsigned long len = fs_info->sectorsize; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, logical, len); @@ -5329,7 +5316,8 @@ void btrfs_put_bbio(struct btrfs_bio *bbio) kfree(bbio); } -static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, +static int __btrfs_map_block(struct btrfs_fs_info *fs_info, + enum btrfs_map_op op, u64 logical, u64 *length, struct btrfs_bio **bbio_ret, int mirror_num, int need_raid_map) @@ -5414,7 +5402,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, raid56_full_stripe_start *= full_stripe_len; } - if (op == REQ_OP_DISCARD) { + if (op == BTRFS_MAP_DISCARD) { /* we don't discard raid56 yet */ if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { ret = -EOPNOTSUPP; @@ -5427,7 +5415,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, For other RAID types and for RAID[56] reads, just allow a single stripe (on a single disk). */ if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && - (op == REQ_OP_WRITE)) { + (op == BTRFS_MAP_WRITE)) { max_len = stripe_len * nr_data_stripes(map) - (offset - raid56_full_stripe_start); } else { @@ -5452,8 +5440,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, btrfs_dev_replace_set_lock_blocking(dev_replace); if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 && - op != REQ_OP_WRITE && op != REQ_OP_DISCARD && - op != REQ_GET_READ_MIRRORS && dev_replace->tgtdev != NULL) { + op != BTRFS_MAP_WRITE && op != BTRFS_MAP_DISCARD && + op != BTRFS_MAP_GET_READ_MIRRORS && dev_replace->tgtdev != NULL) { /* * in dev-replace case, for repair case (that's the only * case where the mirror is selected explicitly when @@ -5474,7 +5462,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, int found = 0; u64 physical_of_found = 0; - ret = __btrfs_map_block(fs_info, REQ_GET_READ_MIRRORS, + ret = __btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS, logical, &tmp_length, &tmp_bbio, 0, 0); if (ret) { WARN_ON(tmp_bbio != NULL); @@ -5484,7 +5472,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, tmp_num_stripes = tmp_bbio->num_stripes; if (mirror_num > tmp_num_stripes) { /* - * REQ_GET_READ_MIRRORS does not contain this + * BTRFS_MAP_GET_READ_MIRRORS does not contain this * mirror, that means that the requested area * is not left of the left cursor */ @@ -5540,17 +5528,17 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, (offset + *length); if (map->type & BTRFS_BLOCK_GROUP_RAID0) { - if (op == REQ_OP_DISCARD) + if (op == BTRFS_MAP_DISCARD) num_stripes = min_t(u64, map->num_stripes, stripe_nr_end - stripe_nr_orig); stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, &stripe_index); - if (op != REQ_OP_WRITE && op != REQ_OP_DISCARD && - op != REQ_GET_READ_MIRRORS) + if (op != BTRFS_MAP_WRITE && op != BTRFS_MAP_DISCARD && + op != BTRFS_MAP_GET_READ_MIRRORS) mirror_num = 1; } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { - if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD || - op == REQ_GET_READ_MIRRORS) + if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD || + op == BTRFS_MAP_GET_READ_MIRRORS) num_stripes = map->num_stripes; else if (mirror_num) stripe_index = mirror_num - 1; @@ -5563,8 +5551,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, } } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { - if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD || - op == REQ_GET_READ_MIRRORS) { + if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD || + op == BTRFS_MAP_GET_READ_MIRRORS) { num_stripes = map->num_stripes; } else if (mirror_num) { stripe_index = mirror_num - 1; @@ -5578,9 +5566,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index); stripe_index *= map->sub_stripes; - if (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) + if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) num_stripes = map->sub_stripes; - else if (op == REQ_OP_DISCARD) + else if (op == BTRFS_MAP_DISCARD) num_stripes = min_t(u64, map->sub_stripes * (stripe_nr_end - stripe_nr_orig), map->num_stripes); @@ -5598,7 +5586,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { if (need_raid_map && - (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS || + (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS || mirror_num > 1)) { /* push stripe_nr back to the start of the full stripe */ stripe_nr = div_u64(raid56_full_stripe_start, @@ -5626,8 +5614,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, /* We distribute the parity blocks across stripes */ div_u64_rem(stripe_nr + stripe_index, map->num_stripes, &stripe_index); - if ((op != REQ_OP_WRITE && op != REQ_OP_DISCARD && - op != REQ_GET_READ_MIRRORS) && mirror_num <= 1) + if ((op != BTRFS_MAP_WRITE && op != BTRFS_MAP_DISCARD && + op != BTRFS_MAP_GET_READ_MIRRORS) && mirror_num <= 1) mirror_num = 1; } } else { @@ -5650,9 +5638,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, num_alloc_stripes = num_stripes; if (dev_replace_is_ongoing) { - if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD) + if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD) num_alloc_stripes <<= 1; - if (op == REQ_GET_READ_MIRRORS) + if (op == BTRFS_MAP_GET_READ_MIRRORS) num_alloc_stripes++; tgtdev_indexes = num_stripes; } @@ -5668,7 +5656,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, /* build raid_map */ if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK && need_raid_map && - ((op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) || + ((op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) || mirror_num > 1)) { u64 tmp; unsigned rot; @@ -5693,7 +5681,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, RAID6_Q_STRIPE; } - if (op == REQ_OP_DISCARD) { + if (op == BTRFS_MAP_DISCARD) { u32 factor = 0; u32 sub_stripes = 0; u64 stripes_per_dev = 0; @@ -5773,7 +5761,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, } } - if (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) + if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) max_errors = btrfs_chunk_max_errors(map); if (bbio->raid_map) @@ -5781,7 +5769,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, tgtdev_indexes = 0; if (dev_replace_is_ongoing && - (op == REQ_OP_WRITE || op == REQ_OP_DISCARD) && + (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD) && dev_replace->tgtdev != NULL) { int index_where_to_add; u64 srcdev_devid = dev_replace->srcdev->devid; @@ -5816,7 +5804,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, } } num_stripes = index_where_to_add; - } else if (dev_replace_is_ongoing && (op == REQ_GET_READ_MIRRORS) && + } else if (dev_replace_is_ongoing && + op == BTRFS_MAP_GET_READ_MIRRORS && dev_replace->tgtdev != NULL) { u64 srcdev_devid = dev_replace->srcdev->devid; int index_srcdev = 0; @@ -5888,7 +5877,7 @@ out: return ret; } -int btrfs_map_block(struct btrfs_fs_info *fs_info, int op, +int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, u64 logical, u64 *length, struct btrfs_bio **bbio_ret, int mirror_num) { @@ -5897,7 +5886,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, int op, } /* For Scrub/replace */ -int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int op, +int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, u64 logical, u64 *length, struct btrfs_bio **bbio_ret, int mirror_num, int need_raid_map) @@ -6069,10 +6058,10 @@ static void btrfs_end_bio(struct bio *bio) * This will add one bio to the pending list for a device and make sure * the work struct is scheduled. */ -static noinline void btrfs_schedule_bio(struct btrfs_root *root, - struct btrfs_device *device, +static noinline void btrfs_schedule_bio(struct btrfs_device *device, struct bio *bio) { + struct btrfs_fs_info *fs_info = device->fs_info; int should_queue = 1; struct btrfs_pending_bios *pending_bios; @@ -6095,7 +6084,7 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root, * made progress against dirty pages when we've really just put it * on a queue for later */ - atomic_inc(&root->fs_info->nr_async_bios); + atomic_inc(&fs_info->nr_async_bios); WARN_ON(bio->bi_next); bio->bi_next = NULL; @@ -6117,15 +6106,14 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root, spin_unlock(&device->io_lock); if (should_queue) - btrfs_queue_work(root->fs_info->submit_workers, - &device->work); + btrfs_queue_work(fs_info->submit_workers, &device->work); } -static void submit_stripe_bio(struct btrfs_root *root, struct btrfs_bio *bbio, - struct bio *bio, u64 physical, int dev_nr, - int async) +static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio, + u64 physical, int dev_nr, int async) { struct btrfs_device *dev = bbio->stripes[dev_nr].dev; + struct btrfs_fs_info *fs_info = bbio->fs_info; bio->bi_private = bbio; btrfs_io_bio(bio)->stripe_index = dev_nr; @@ -6148,10 +6136,10 @@ static void submit_stripe_bio(struct btrfs_root *root, struct btrfs_bio *bbio, #endif bio->bi_bdev = dev->bdev; - btrfs_bio_counter_inc_noblocked(root->fs_info); + btrfs_bio_counter_inc_noblocked(fs_info); if (async) - btrfs_schedule_bio(root, dev, bio); + btrfs_schedule_bio(dev, bio); else btrfsic_submit_bio(bio); } @@ -6170,7 +6158,7 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical) } } -int btrfs_map_bio(struct btrfs_root *root, struct bio *bio, +int btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, int mirror_num, int async_submit) { struct btrfs_device *dev; @@ -6186,11 +6174,11 @@ int btrfs_map_bio(struct btrfs_root *root, struct bio *bio, length = bio->bi_iter.bi_size; map_length = length; - btrfs_bio_counter_inc_blocked(root->fs_info); - ret = __btrfs_map_block(root->fs_info, bio_op(bio), logical, + btrfs_bio_counter_inc_blocked(fs_info); + ret = __btrfs_map_block(fs_info, bio_op(bio), logical, &map_length, &bbio, mirror_num, 1); if (ret) { - btrfs_bio_counter_dec(root->fs_info); + btrfs_bio_counter_dec(fs_info); return ret; } @@ -6198,7 +6186,7 @@ int btrfs_map_bio(struct btrfs_root *root, struct bio *bio, bbio->orig_bio = first_bio; bbio->private = first_bio->bi_private; bbio->end_io = first_bio->bi_end_io; - bbio->fs_info = root->fs_info; + bbio->fs_info = fs_info; atomic_set(&bbio->stripes_pending, bbio->num_stripes); if ((bbio->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) && @@ -6206,18 +6194,19 @@ int btrfs_map_bio(struct btrfs_root *root, struct bio *bio, /* In this case, map_length has been set to the length of a single stripe; not the whole write */ if (bio_op(bio) == REQ_OP_WRITE) { - ret = raid56_parity_write(root, bio, bbio, map_length); + ret = raid56_parity_write(fs_info, bio, bbio, + map_length); } else { - ret = raid56_parity_recover(root, bio, bbio, map_length, - mirror_num, 1); + ret = raid56_parity_recover(fs_info, bio, bbio, + map_length, mirror_num, 1); } - btrfs_bio_counter_dec(root->fs_info); + btrfs_bio_counter_dec(fs_info); return ret; } if (map_length < length) { - btrfs_crit(root->fs_info, + btrfs_crit(fs_info, "mapping failed logical %llu bio len %llu len %llu", logical, length, map_length); BUG(); @@ -6237,11 +6226,10 @@ int btrfs_map_bio(struct btrfs_root *root, struct bio *bio, } else bio = first_bio; - submit_stripe_bio(root, bbio, bio, - bbio->stripes[dev_nr].physical, dev_nr, - async_submit); + submit_stripe_bio(bbio, bio, bbio->stripes[dev_nr].physical, + dev_nr, async_submit); } - btrfs_bio_counter_dec(root->fs_info); + btrfs_bio_counter_dec(fs_info); return 0; } @@ -6265,8 +6253,7 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, return NULL; } -static struct btrfs_device *add_missing_dev(struct btrfs_root *root, - struct btrfs_fs_devices *fs_devices, +static struct btrfs_device *add_missing_dev(struct btrfs_fs_devices *fs_devices, u64 devid, u8 *dev_uuid) { struct btrfs_device *device; @@ -6337,7 +6324,7 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, } /* Return -EIO if any error, otherwise return 0. */ -static int btrfs_check_chunk_valid(struct btrfs_root *root, +static int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, struct extent_buffer *leaf, struct btrfs_chunk *chunk, u64 logical) { @@ -6354,33 +6341,31 @@ static int btrfs_check_chunk_valid(struct btrfs_root *root, type = btrfs_chunk_type(leaf, chunk); if (!num_stripes) { - btrfs_err(root->fs_info, "invalid chunk num_stripes: %u", + btrfs_err(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); + if (!IS_ALIGNED(logical, fs_info->sectorsize)) { + btrfs_err(fs_info, "invalid chunk logical %llu", logical); return -EIO; } - if (btrfs_chunk_sector_size(leaf, chunk) != root->sectorsize) { - btrfs_err(root->fs_info, "invalid chunk sectorsize %u", + if (btrfs_chunk_sector_size(leaf, chunk) != fs_info->sectorsize) { + btrfs_err(fs_info, "invalid chunk sectorsize %u", btrfs_chunk_sector_size(leaf, chunk)); return -EIO; } - if (!length || !IS_ALIGNED(length, root->sectorsize)) { - btrfs_err(root->fs_info, - "invalid chunk length %llu", length); + if (!length || !IS_ALIGNED(length, fs_info->sectorsize)) { + btrfs_err(fs_info, "invalid chunk length %llu", length); return -EIO; } if (!is_power_of_2(stripe_len) || stripe_len != BTRFS_STRIPE_LEN) { - btrfs_err(root->fs_info, "invalid chunk stripe length: %llu", + btrfs_err(fs_info, "invalid chunk stripe length: %llu", stripe_len); return -EIO; } if (~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) & type) { - btrfs_err(root->fs_info, "unrecognized chunk type: %llu", + btrfs_err(fs_info, "unrecognized chunk type: %llu", ~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_PROFILE_MASK) & btrfs_chunk_type(leaf, chunk)); @@ -6393,7 +6378,7 @@ static int btrfs_check_chunk_valid(struct btrfs_root *root, (type & BTRFS_BLOCK_GROUP_DUP && num_stripes > 2) || ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 && num_stripes != 1)) { - btrfs_err(root->fs_info, + btrfs_err(fs_info, "invalid num_stripes:sub_stripes %u:%u for profile %llu", num_stripes, sub_stripes, type & BTRFS_BLOCK_GROUP_PROFILE_MASK); @@ -6403,11 +6388,11 @@ static int btrfs_check_chunk_valid(struct btrfs_root *root, return 0; } -static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, +static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, struct extent_buffer *leaf, struct btrfs_chunk *chunk) { - struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; + struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; struct map_lookup *map; struct extent_map *em; u64 logical; @@ -6424,7 +6409,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, stripe_len = btrfs_chunk_stripe_len(leaf, chunk); num_stripes = btrfs_chunk_num_stripes(leaf, chunk); - ret = btrfs_check_chunk_valid(root, leaf, chunk, logical); + ret = btrfs_check_chunk_valid(fs_info, leaf, chunk, logical); if (ret) return ret; @@ -6471,23 +6456,22 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, read_extent_buffer(leaf, uuid, (unsigned long) btrfs_stripe_dev_uuid_nr(chunk, i), BTRFS_UUID_SIZE); - map->stripes[i].dev = btrfs_find_device(root->fs_info, devid, + map->stripes[i].dev = btrfs_find_device(fs_info, devid, uuid, NULL); if (!map->stripes[i].dev && - !btrfs_test_opt(root->fs_info, DEGRADED)) { + !btrfs_test_opt(fs_info, DEGRADED)) { free_extent_map(em); return -EIO; } if (!map->stripes[i].dev) { map->stripes[i].dev = - add_missing_dev(root, root->fs_info->fs_devices, - devid, uuid); + add_missing_dev(fs_info->fs_devices, devid, + uuid); if (!map->stripes[i].dev) { free_extent_map(em); return -EIO; } - btrfs_warn(root->fs_info, - "devid %llu uuid %pU is missing", + btrfs_warn(fs_info, "devid %llu uuid %pU is missing", devid, uuid); } map->stripes[i].dev->in_fs_metadata = 1; @@ -6525,7 +6509,7 @@ static void fill_device_from_item(struct extent_buffer *leaf, read_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE); } -static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root, +static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info, u8 *fsid) { struct btrfs_fs_devices *fs_devices; @@ -6533,7 +6517,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root, BUG_ON(!mutex_is_locked(&uuid_mutex)); - fs_devices = root->fs_info->fs_devices->seed; + fs_devices = fs_info->fs_devices->seed; while (fs_devices) { if (!memcmp(fs_devices->fsid, fsid, BTRFS_UUID_SIZE)) return fs_devices; @@ -6543,7 +6527,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root, fs_devices = find_fsid(fsid); if (!fs_devices) { - if (!btrfs_test_opt(root->fs_info, DEGRADED)) + if (!btrfs_test_opt(fs_info, DEGRADED)) return ERR_PTR(-ENOENT); fs_devices = alloc_fs_devices(fsid); @@ -6560,7 +6544,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root, return fs_devices; ret = __btrfs_open_devices(fs_devices, FMODE_READ, - root->fs_info->bdev_holder); + fs_info->bdev_holder); if (ret) { free_fs_devices(fs_devices); fs_devices = ERR_PTR(ret); @@ -6574,17 +6558,17 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_root *root, goto out; } - fs_devices->seed = root->fs_info->fs_devices->seed; - root->fs_info->fs_devices->seed = fs_devices; + fs_devices->seed = fs_info->fs_devices->seed; + fs_info->fs_devices->seed = fs_devices; out: return fs_devices; } -static int read_one_dev(struct btrfs_root *root, +static int read_one_dev(struct btrfs_fs_info *fs_info, struct extent_buffer *leaf, struct btrfs_dev_item *dev_item) { - struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; struct btrfs_device *device; u64 devid; int ret; @@ -6597,24 +6581,24 @@ static int read_one_dev(struct btrfs_root *root, read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item), BTRFS_UUID_SIZE); - if (memcmp(fs_uuid, root->fs_info->fsid, BTRFS_UUID_SIZE)) { - fs_devices = open_seed_devices(root, fs_uuid); + if (memcmp(fs_uuid, fs_info->fsid, BTRFS_UUID_SIZE)) { + fs_devices = open_seed_devices(fs_info, fs_uuid); if (IS_ERR(fs_devices)) return PTR_ERR(fs_devices); } - device = btrfs_find_device(root->fs_info, devid, dev_uuid, fs_uuid); + device = btrfs_find_device(fs_info, devid, dev_uuid, fs_uuid); if (!device) { - if (!btrfs_test_opt(root->fs_info, DEGRADED)) + if (!btrfs_test_opt(fs_info, DEGRADED)) return -EIO; - device = add_missing_dev(root, fs_devices, devid, dev_uuid); + device = add_missing_dev(fs_devices, devid, dev_uuid); if (!device) return -ENOMEM; - btrfs_warn(root->fs_info, "devid %llu uuid %pU missing", + btrfs_warn(fs_info, "devid %llu uuid %pU missing", devid, dev_uuid); } else { - if (!device->bdev && !btrfs_test_opt(root->fs_info, DEGRADED)) + if (!device->bdev && !btrfs_test_opt(fs_info, DEGRADED)) return -EIO; if(!device->bdev && !device->missing) { @@ -6643,7 +6627,7 @@ static int read_one_dev(struct btrfs_root *root, } } - if (device->fs_devices != root->fs_info->fs_devices) { + if (device->fs_devices != fs_info->fs_devices) { BUG_ON(device->writeable); if (device->generation != btrfs_device_generation(leaf, dev_item)) @@ -6654,18 +6638,18 @@ static int read_one_dev(struct btrfs_root *root, device->in_fs_metadata = 1; if (device->writeable && !device->is_tgtdev_for_dev_replace) { device->fs_devices->total_rw_bytes += device->total_bytes; - spin_lock(&root->fs_info->free_chunk_lock); - root->fs_info->free_chunk_space += device->total_bytes - + spin_lock(&fs_info->free_chunk_lock); + fs_info->free_chunk_space += device->total_bytes - device->bytes_used; - spin_unlock(&root->fs_info->free_chunk_lock); + spin_unlock(&fs_info->free_chunk_lock); } ret = 0; return ret; } -int btrfs_read_sys_array(struct btrfs_root *root) +int btrfs_read_sys_array(struct btrfs_fs_info *fs_info) { - struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_root *root = fs_info->tree_root; struct btrfs_super_block *super_copy = fs_info->super_copy; struct extent_buffer *sb; struct btrfs_disk_key *disk_key; @@ -6680,13 +6664,13 @@ int btrfs_read_sys_array(struct btrfs_root *root) u64 type; struct btrfs_key key; - ASSERT(BTRFS_SUPER_INFO_SIZE <= root->nodesize); + ASSERT(BTRFS_SUPER_INFO_SIZE <= fs_info->nodesize); /* * This will create extent buffer of nodesize, superblock size is * fixed to BTRFS_SUPER_INFO_SIZE. If nodesize > sb size, this will * overallocate but we can keep it as-is, only the first page is used. */ - sb = btrfs_find_create_tree_block(root, BTRFS_SUPER_INFO_OFFSET); + sb = btrfs_find_create_tree_block(fs_info, BTRFS_SUPER_INFO_OFFSET); if (IS_ERR(sb)) return PTR_ERR(sb); set_extent_buffer_uptodate(sb); @@ -6757,7 +6741,7 @@ int btrfs_read_sys_array(struct btrfs_root *root) if (cur_offset + len > array_size) goto out_short_read; - ret = read_one_chunk(root, &key, sb, chunk); + ret = read_one_chunk(fs_info, &key, sb, chunk); if (ret) break; } else { @@ -6783,8 +6767,9 @@ out_short_read: return -EIO; } -int btrfs_read_chunk_tree(struct btrfs_root *root) +int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info) { + struct btrfs_root *root = fs_info->chunk_root; struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_key key; @@ -6793,14 +6778,12 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) int slot; u64 total_dev = 0; - root = root->fs_info->chunk_root; - path = btrfs_alloc_path(); if (!path) return -ENOMEM; mutex_lock(&uuid_mutex); - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); /* * Read all device items, and then all the chunk items. All @@ -6830,14 +6813,14 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) struct btrfs_dev_item *dev_item; dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_dev_item); - ret = read_one_dev(root, leaf, dev_item); + ret = read_one_dev(fs_info, leaf, dev_item); if (ret) goto error; total_dev++; } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { struct btrfs_chunk *chunk; chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); - ret = read_one_chunk(root, &found_key, leaf, chunk); + ret = read_one_chunk(fs_info, &found_key, leaf, chunk); if (ret) goto error; } @@ -6848,26 +6831,26 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) * After loading chunk tree, we've got all device information, * do another round of validation checks. */ - if (total_dev != root->fs_info->fs_devices->total_devices) { - btrfs_err(root->fs_info, + if (total_dev != fs_info->fs_devices->total_devices) { + btrfs_err(fs_info, "super_num_devices %llu mismatch with num_devices %llu found here", - btrfs_super_num_devices(root->fs_info->super_copy), + btrfs_super_num_devices(fs_info->super_copy), total_dev); ret = -EINVAL; goto error; } - if (btrfs_super_total_bytes(root->fs_info->super_copy) < - root->fs_info->fs_devices->total_rw_bytes) { - btrfs_err(root->fs_info, + if (btrfs_super_total_bytes(fs_info->super_copy) < + fs_info->fs_devices->total_rw_bytes) { + btrfs_err(fs_info, "super_total_bytes %llu mismatch with fs_devices total_rw_bytes %llu", - btrfs_super_total_bytes(root->fs_info->super_copy), - root->fs_info->fs_devices->total_rw_bytes); + btrfs_super_total_bytes(fs_info->super_copy), + fs_info->fs_devices->total_rw_bytes); ret = -EINVAL; goto error; } ret = 0; error: - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&uuid_mutex); btrfs_free_path(path); @@ -6882,7 +6865,7 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info) while (fs_devices) { mutex_lock(&fs_devices->device_list_mutex); list_for_each_entry(device, &fs_devices->devices, dev_list) - device->dev_root = fs_info->dev_root; + device->fs_info = fs_info; mutex_unlock(&fs_devices->device_list_mutex); fs_devices = fs_devices->seed; @@ -6959,9 +6942,10 @@ out: } static int update_dev_stat_item(struct btrfs_trans_handle *trans, - struct btrfs_root *dev_root, + struct btrfs_fs_info *fs_info, struct btrfs_device *device) { + struct btrfs_root *dev_root = fs_info->dev_root; struct btrfs_path *path; struct btrfs_key key; struct extent_buffer *eb; @@ -6977,7 +6961,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans, BUG_ON(!path); ret = btrfs_search_slot(trans, dev_root, &key, path, -1, 1); if (ret < 0) { - btrfs_warn_in_rcu(dev_root->fs_info, + btrfs_warn_in_rcu(fs_info, "error %d while searching for dev_stats item for device %s", ret, rcu_str_deref(device->name)); goto out; @@ -6988,7 +6972,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans, /* need to delete old one and insert a new one */ ret = btrfs_del_item(trans, dev_root, path); if (ret != 0) { - btrfs_warn_in_rcu(dev_root->fs_info, + btrfs_warn_in_rcu(fs_info, "delete too small dev_stats item for device %s failed %d", rcu_str_deref(device->name), ret); goto out; @@ -7002,7 +6986,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans, ret = btrfs_insert_empty_item(trans, dev_root, path, &key, sizeof(*ptr)); if (ret < 0) { - btrfs_warn_in_rcu(dev_root->fs_info, + btrfs_warn_in_rcu(fs_info, "insert dev_stats item for device %s failed %d", rcu_str_deref(device->name), ret); goto out; @@ -7027,7 +7011,6 @@ out: int btrfs_run_dev_stats(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info) { - struct btrfs_root *dev_root = fs_info->dev_root; struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; struct btrfs_device *device; int stats_cnt; @@ -7039,7 +7022,7 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans, continue; stats_cnt = atomic_read(&device->dev_stats_ccnt); - ret = update_dev_stat_item(trans, dev_root, device); + ret = update_dev_stat_item(trans, fs_info, device); if (!ret) atomic_sub(stats_cnt, &device->dev_stats_ccnt); } @@ -7058,7 +7041,7 @@ static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev) { if (!dev->dev_stats_valid) return; - btrfs_err_rl_in_rcu(dev->dev_root->fs_info, + btrfs_err_rl_in_rcu(dev->fs_info, "bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u", rcu_str_deref(dev->name), btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS), @@ -7078,7 +7061,7 @@ static void btrfs_dev_stat_print_on_load(struct btrfs_device *dev) if (i == BTRFS_DEV_STAT_VALUES_MAX) return; /* all values == 0, suppress message */ - btrfs_info_in_rcu(dev->dev_root->fs_info, + btrfs_info_in_rcu(dev->fs_info, "bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u", rcu_str_deref(dev->name), btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS), @@ -7088,24 +7071,22 @@ static void btrfs_dev_stat_print_on_load(struct btrfs_device *dev) btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_GENERATION_ERRS)); } -int btrfs_get_dev_stats(struct btrfs_root *root, +int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info, struct btrfs_ioctl_get_dev_stats *stats) { struct btrfs_device *dev; - struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; int i; mutex_lock(&fs_devices->device_list_mutex); - dev = btrfs_find_device(root->fs_info, stats->devid, NULL, NULL); + dev = btrfs_find_device(fs_info, stats->devid, NULL, NULL); mutex_unlock(&fs_devices->device_list_mutex); if (!dev) { - btrfs_warn(root->fs_info, - "get dev_stats failed, device not found"); + btrfs_warn(fs_info, "get dev_stats failed, device not found"); return -ENODEV; } else if (!dev->dev_stats_valid) { - btrfs_warn(root->fs_info, - "get dev_stats failed, not yet valid"); + btrfs_warn(fs_info, "get dev_stats failed, not yet valid"); return -ENODEV; } else if (stats->flags & BTRFS_DEV_STATS_RESET) { for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) { @@ -7168,18 +7149,18 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info) return; mutex_lock(&fs_devices->device_list_mutex); - lock_chunks(fs_info->dev_root); + mutex_lock(&fs_info->chunk_mutex); list_for_each_entry_safe(curr, next, &fs_devices->resized_devices, resized_list) { list_del_init(&curr->resized_list); curr->commit_total_bytes = curr->disk_total_bytes; } - unlock_chunks(fs_info->dev_root); + mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&fs_devices->device_list_mutex); } /* Must be invoked during the transaction commit */ -void btrfs_update_commit_device_bytes_used(struct btrfs_root *root, +void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info, struct btrfs_transaction *transaction) { struct extent_map *em; @@ -7191,7 +7172,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_root *root, return; /* In order to kick the device replace finish process */ - lock_chunks(root); + mutex_lock(&fs_info->chunk_mutex); list_for_each_entry(em, &transaction->pending_chunks, list) { map = em->map_lookup; @@ -7200,7 +7181,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_root *root, dev->commit_bytes_used = dev->bytes_used; } } - unlock_chunks(root); + mutex_unlock(&fs_info->chunk_mutex); } void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info) |