aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2016-06-22 18:54:56 -0400
committerDavid Sterba <dsterba@suse.com>2016-12-06 10:06:58 -0500
commitfb456252d3d9c05dfad09b603868e1ef9097a220 (patch)
treec245b8915a5353f67a4c54e10af0cd746fe658f6
parentc28f158e5ee78621ae693b8b18a9b89c7695af40 (diff)
btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/check-integrity.c2
-rw-r--r--fs/btrfs/disk-io.c4
-rw-r--r--fs/btrfs/extent-tree.c2
-rw-r--r--fs/btrfs/scrub.c86
-rw-r--r--fs/btrfs/volumes.c41
-rw-r--r--fs/btrfs/volumes.h3
6 files changed, 68 insertions, 70 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 270da67de53d..91f6bd9124d9 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -832,7 +832,7 @@ static int btrfsic_process_superblock_dev_mirror(
832 superblock_tmp->never_written = 0; 832 superblock_tmp->never_written = 0;
833 superblock_tmp->mirror_num = 1 + superblock_mirror_num; 833 superblock_tmp->mirror_num = 1 + superblock_mirror_num;
834 if (state->print_mask & BTRFSIC_PRINT_MASK_SUPERBLOCK_WRITE) 834 if (state->print_mask & BTRFSIC_PRINT_MASK_SUPERBLOCK_WRITE)
835 btrfs_info_in_rcu(device->dev_root->fs_info, 835 btrfs_info_in_rcu(device->fs_info,
836 "new initial S-block (bdev %p, %s) @%llu (%s/%llu/%d)", 836 "new initial S-block (bdev %p, %s) @%llu (%s/%llu/%d)",
837 superblock_bdev, 837 superblock_bdev,
838 rcu_str_deref(device->name), dev_bytenr, 838 rcu_str_deref(device->name), dev_bytenr,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 1db5f0304c6b..83848314e12f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3308,7 +3308,7 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
3308 struct btrfs_device *device = (struct btrfs_device *) 3308 struct btrfs_device *device = (struct btrfs_device *)
3309 bh->b_private; 3309 bh->b_private;
3310 3310
3311 btrfs_warn_rl_in_rcu(device->dev_root->fs_info, 3311 btrfs_warn_rl_in_rcu(device->fs_info,
3312 "lost page write due to IO error on %s", 3312 "lost page write due to IO error on %s",
3313 rcu_str_deref(device->name)); 3313 rcu_str_deref(device->name));
3314 /* note, we don't set_buffer_write_io_error because we have 3314 /* note, we don't set_buffer_write_io_error because we have
@@ -3453,7 +3453,7 @@ static int write_dev_supers(struct btrfs_device *device,
3453 bh = __getblk(device->bdev, bytenr / 4096, 3453 bh = __getblk(device->bdev, bytenr / 4096,
3454 BTRFS_SUPER_INFO_SIZE); 3454 BTRFS_SUPER_INFO_SIZE);
3455 if (!bh) { 3455 if (!bh) {
3456 btrfs_err(device->dev_root->fs_info, 3456 btrfs_err(device->fs_info,
3457 "couldn't get super buffer head for bytenr %llu", 3457 "couldn't get super buffer head for bytenr %llu",
3458 bytenr); 3458 bytenr);
3459 errors++; 3459 errors++;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e8b8e309e4ab..9e8342367056 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -10853,7 +10853,7 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
10853 ret = 0; 10853 ret = 0;
10854 10854
10855 while (1) { 10855 while (1) {
10856 struct btrfs_fs_info *fs_info = device->dev_root->fs_info; 10856 struct btrfs_fs_info *fs_info = device->fs_info;
10857 struct btrfs_transaction *trans; 10857 struct btrfs_transaction *trans;
10858 u64 bytes; 10858 u64 bytes;
10859 10859
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 589d79219c18..ed7024687ae0 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -171,7 +171,7 @@ struct scrub_wr_ctx {
171 171
172struct scrub_ctx { 172struct scrub_ctx {
173 struct scrub_bio *bios[SCRUB_BIOS_PER_SCTX]; 173 struct scrub_bio *bios[SCRUB_BIOS_PER_SCTX];
174 struct btrfs_root *dev_root; 174 struct btrfs_fs_info *fs_info;
175 int first_free; 175 int first_free;
176 int curr; 176 int curr;
177 atomic_t bios_in_flight; 177 atomic_t bios_in_flight;
@@ -356,7 +356,7 @@ static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info)
356 */ 356 */
357static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx) 357static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
358{ 358{
359 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 359 struct btrfs_fs_info *fs_info = sctx->fs_info;
360 360
361 atomic_inc(&sctx->refs); 361 atomic_inc(&sctx->refs);
362 /* 362 /*
@@ -388,7 +388,7 @@ static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
388/* used for workers that require transaction commits */ 388/* used for workers that require transaction commits */
389static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx) 389static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx)
390{ 390{
391 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 391 struct btrfs_fs_info *fs_info = sctx->fs_info;
392 392
393 /* 393 /*
394 * see scrub_pending_trans_workers_inc() why we're pretending 394 * see scrub_pending_trans_workers_inc() why we're pretending
@@ -458,7 +458,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
458{ 458{
459 struct scrub_ctx *sctx; 459 struct scrub_ctx *sctx;
460 int i; 460 int i;
461 struct btrfs_fs_info *fs_info = dev->dev_root->fs_info; 461 struct btrfs_fs_info *fs_info = dev->fs_info;
462 int ret; 462 int ret;
463 463
464 sctx = kzalloc(sizeof(*sctx), GFP_KERNEL); 464 sctx = kzalloc(sizeof(*sctx), GFP_KERNEL);
@@ -468,7 +468,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
468 sctx->is_dev_replace = is_dev_replace; 468 sctx->is_dev_replace = is_dev_replace;
469 sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO; 469 sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
470 sctx->curr = -1; 470 sctx->curr = -1;
471 sctx->dev_root = dev->dev_root; 471 sctx->fs_info = dev->fs_info;
472 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) { 472 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
473 struct scrub_bio *sbio; 473 struct scrub_bio *sbio;
474 474
@@ -489,8 +489,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
489 sctx->bios[i]->next_free = -1; 489 sctx->bios[i]->next_free = -1;
490 } 490 }
491 sctx->first_free = 0; 491 sctx->first_free = 0;
492 sctx->nodesize = dev->dev_root->nodesize; 492 sctx->nodesize = dev->fs_info->dev_root->nodesize;
493 sctx->sectorsize = dev->dev_root->sectorsize; 493 sctx->sectorsize = dev->fs_info->dev_root->sectorsize;
494 atomic_set(&sctx->bios_in_flight, 0); 494 atomic_set(&sctx->bios_in_flight, 0);
495 atomic_set(&sctx->workers_pending, 0); 495 atomic_set(&sctx->workers_pending, 0);
496 atomic_set(&sctx->cancel_req, 0); 496 atomic_set(&sctx->cancel_req, 0);
@@ -524,7 +524,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
524 struct extent_buffer *eb; 524 struct extent_buffer *eb;
525 struct btrfs_inode_item *inode_item; 525 struct btrfs_inode_item *inode_item;
526 struct scrub_warning *swarn = warn_ctx; 526 struct scrub_warning *swarn = warn_ctx;
527 struct btrfs_fs_info *fs_info = swarn->dev->dev_root->fs_info; 527 struct btrfs_fs_info *fs_info = swarn->dev->fs_info;
528 struct inode_fs_paths *ipath = NULL; 528 struct inode_fs_paths *ipath = NULL;
529 struct btrfs_root *local_root; 529 struct btrfs_root *local_root;
530 struct btrfs_key root_key; 530 struct btrfs_key root_key;
@@ -618,7 +618,7 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock)
618 618
619 WARN_ON(sblock->page_count < 1); 619 WARN_ON(sblock->page_count < 1);
620 dev = sblock->pagev[0]->dev; 620 dev = sblock->pagev[0]->dev;
621 fs_info = sblock->sctx->dev_root->fs_info; 621 fs_info = sblock->sctx->fs_info;
622 622
623 path = btrfs_alloc_path(); 623 path = btrfs_alloc_path();
624 if (!path) 624 if (!path)
@@ -843,10 +843,9 @@ out:
843 spin_lock(&sctx->stat_lock); 843 spin_lock(&sctx->stat_lock);
844 ++sctx->stat.uncorrectable_errors; 844 ++sctx->stat.uncorrectable_errors;
845 spin_unlock(&sctx->stat_lock); 845 spin_unlock(&sctx->stat_lock);
846 btrfs_dev_replace_stats_inc( 846 btrfs_dev_replace_stats_inc(&sctx->fs_info->dev_replace.
847 &sctx->dev_root->fs_info->dev_replace. 847 num_uncorrectable_read_errors);
848 num_uncorrectable_read_errors); 848 btrfs_err_rl_in_rcu(sctx->fs_info,
849 btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
850 "unable to fixup (nodatasum) error at logical %llu on dev %s", 849 "unable to fixup (nodatasum) error at logical %llu on dev %s",
851 fixup->logical, rcu_str_deref(fixup->dev->name)); 850 fixup->logical, rcu_str_deref(fixup->dev->name));
852 } 851 }
@@ -898,7 +897,7 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
898 DEFAULT_RATELIMIT_BURST); 897 DEFAULT_RATELIMIT_BURST);
899 898
900 BUG_ON(sblock_to_check->page_count < 1); 899 BUG_ON(sblock_to_check->page_count < 1);
901 fs_info = sctx->dev_root->fs_info; 900 fs_info = sctx->fs_info;
902 if (sblock_to_check->pagev[0]->flags & BTRFS_EXTENT_FLAG_SUPER) { 901 if (sblock_to_check->pagev[0]->flags & BTRFS_EXTENT_FLAG_SUPER) {
903 /* 902 /*
904 * if we find an error in a super block, we just report it. 903 * if we find an error in a super block, we just report it.
@@ -1177,8 +1176,7 @@ nodatasum_case:
1177 if (scrub_write_page_to_dev_replace(sblock_other, 1176 if (scrub_write_page_to_dev_replace(sblock_other,
1178 page_num) != 0) { 1177 page_num) != 0) {
1179 btrfs_dev_replace_stats_inc( 1178 btrfs_dev_replace_stats_inc(
1180 &sctx->dev_root-> 1179 &sctx->fs_info->dev_replace.
1181 fs_info->dev_replace.
1182 num_write_errors); 1180 num_write_errors);
1183 success = 0; 1181 success = 0;
1184 } 1182 }
@@ -1302,7 +1300,7 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock,
1302 struct scrub_block *sblocks_for_recheck) 1300 struct scrub_block *sblocks_for_recheck)
1303{ 1301{
1304 struct scrub_ctx *sctx = original_sblock->sctx; 1302 struct scrub_ctx *sctx = original_sblock->sctx;
1305 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 1303 struct btrfs_fs_info *fs_info = sctx->fs_info;
1306 u64 length = original_sblock->page_count * PAGE_SIZE; 1304 u64 length = original_sblock->page_count * PAGE_SIZE;
1307 u64 logical = original_sblock->pagev[0]->logical; 1305 u64 logical = original_sblock->pagev[0]->logical;
1308 u64 generation = original_sblock->pagev[0]->generation; 1306 u64 generation = original_sblock->pagev[0]->generation;
@@ -1574,7 +1572,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1574 int ret; 1572 int ret;
1575 1573
1576 if (!page_bad->dev->bdev) { 1574 if (!page_bad->dev->bdev) {
1577 btrfs_warn_rl(sblock_bad->sctx->dev_root->fs_info, 1575 btrfs_warn_rl(sblock_bad->sctx->fs_info,
1578 "scrub_repair_page_from_good_copy(bdev == NULL) is unexpected"); 1576 "scrub_repair_page_from_good_copy(bdev == NULL) is unexpected");
1579 return -EIO; 1577 return -EIO;
1580 } 1578 }
@@ -1596,7 +1594,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1596 btrfs_dev_stat_inc_and_print(page_bad->dev, 1594 btrfs_dev_stat_inc_and_print(page_bad->dev,
1597 BTRFS_DEV_STAT_WRITE_ERRS); 1595 BTRFS_DEV_STAT_WRITE_ERRS);
1598 btrfs_dev_replace_stats_inc( 1596 btrfs_dev_replace_stats_inc(
1599 &sblock_bad->sctx->dev_root->fs_info-> 1597 &sblock_bad->sctx->fs_info->
1600 dev_replace.num_write_errors); 1598 dev_replace.num_write_errors);
1601 bio_put(bio); 1599 bio_put(bio);
1602 return -EIO; 1600 return -EIO;
@@ -1624,7 +1622,7 @@ static void scrub_write_block_to_dev_replace(struct scrub_block *sblock)
1624 ret = scrub_write_page_to_dev_replace(sblock, page_num); 1622 ret = scrub_write_page_to_dev_replace(sblock, page_num);
1625 if (ret) 1623 if (ret)
1626 btrfs_dev_replace_stats_inc( 1624 btrfs_dev_replace_stats_inc(
1627 &sblock->sctx->dev_root->fs_info->dev_replace. 1625 &sblock->sctx->fs_info->dev_replace.
1628 num_write_errors); 1626 num_write_errors);
1629 } 1627 }
1630} 1628}
@@ -1740,7 +1738,7 @@ static void scrub_wr_submit(struct scrub_ctx *sctx)
1740static void scrub_wr_bio_end_io(struct bio *bio) 1738static void scrub_wr_bio_end_io(struct bio *bio)
1741{ 1739{
1742 struct scrub_bio *sbio = bio->bi_private; 1740 struct scrub_bio *sbio = bio->bi_private;
1743 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info; 1741 struct btrfs_fs_info *fs_info = sbio->dev->fs_info;
1744 1742
1745 sbio->err = bio->bi_error; 1743 sbio->err = bio->bi_error;
1746 sbio->bio = bio; 1744 sbio->bio = bio;
@@ -1759,7 +1757,7 @@ static void scrub_wr_bio_end_io_worker(struct btrfs_work *work)
1759 WARN_ON(sbio->page_count > SCRUB_PAGES_PER_WR_BIO); 1757 WARN_ON(sbio->page_count > SCRUB_PAGES_PER_WR_BIO);
1760 if (sbio->err) { 1758 if (sbio->err) {
1761 struct btrfs_dev_replace *dev_replace = 1759 struct btrfs_dev_replace *dev_replace =
1762 &sbio->sctx->dev_root->fs_info->dev_replace; 1760 &sbio->sctx->fs_info->dev_replace;
1763 1761
1764 for (i = 0; i < sbio->page_count; i++) { 1762 for (i = 0; i < sbio->page_count; i++) {
1765 struct scrub_page *spage = sbio->pagev[i]; 1763 struct scrub_page *spage = sbio->pagev[i];
@@ -1859,7 +1857,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
1859{ 1857{
1860 struct scrub_ctx *sctx = sblock->sctx; 1858 struct scrub_ctx *sctx = sblock->sctx;
1861 struct btrfs_header *h; 1859 struct btrfs_header *h;
1862 struct btrfs_root *root = sctx->dev_root; 1860 struct btrfs_root *root = sctx->fs_info->dev_root;
1863 struct btrfs_fs_info *fs_info = root->fs_info; 1861 struct btrfs_fs_info *fs_info = root->fs_info;
1864 u8 calculated_csum[BTRFS_CSUM_SIZE]; 1862 u8 calculated_csum[BTRFS_CSUM_SIZE];
1865 u8 on_disk_csum[BTRFS_CSUM_SIZE]; 1863 u8 on_disk_csum[BTRFS_CSUM_SIZE];
@@ -2126,7 +2124,7 @@ again:
2126static void scrub_missing_raid56_end_io(struct bio *bio) 2124static void scrub_missing_raid56_end_io(struct bio *bio)
2127{ 2125{
2128 struct scrub_block *sblock = bio->bi_private; 2126 struct scrub_block *sblock = bio->bi_private;
2129 struct btrfs_fs_info *fs_info = sblock->sctx->dev_root->fs_info; 2127 struct btrfs_fs_info *fs_info = sblock->sctx->fs_info;
2130 2128
2131 if (bio->bi_error) 2129 if (bio->bi_error)
2132 sblock->no_io_error_seen = 0; 2130 sblock->no_io_error_seen = 0;
@@ -2153,14 +2151,14 @@ static void scrub_missing_raid56_worker(struct btrfs_work *work)
2153 spin_lock(&sctx->stat_lock); 2151 spin_lock(&sctx->stat_lock);
2154 sctx->stat.read_errors++; 2152 sctx->stat.read_errors++;
2155 spin_unlock(&sctx->stat_lock); 2153 spin_unlock(&sctx->stat_lock);
2156 btrfs_err_rl_in_rcu(sctx->dev_root->fs_info, 2154 btrfs_err_rl_in_rcu(sctx->fs_info,
2157 "IO error rebuilding logical %llu for dev %s", 2155 "IO error rebuilding logical %llu for dev %s",
2158 logical, rcu_str_deref(dev->name)); 2156 logical, rcu_str_deref(dev->name));
2159 } else if (sblock->header_error || sblock->checksum_error) { 2157 } else if (sblock->header_error || sblock->checksum_error) {
2160 spin_lock(&sctx->stat_lock); 2158 spin_lock(&sctx->stat_lock);
2161 sctx->stat.uncorrectable_errors++; 2159 sctx->stat.uncorrectable_errors++;
2162 spin_unlock(&sctx->stat_lock); 2160 spin_unlock(&sctx->stat_lock);
2163 btrfs_err_rl_in_rcu(sctx->dev_root->fs_info, 2161 btrfs_err_rl_in_rcu(sctx->fs_info,
2164 "failed to rebuild valid logical %llu for dev %s", 2162 "failed to rebuild valid logical %llu for dev %s",
2165 logical, rcu_str_deref(dev->name)); 2163 logical, rcu_str_deref(dev->name));
2166 } else { 2164 } else {
@@ -2182,7 +2180,8 @@ static void scrub_missing_raid56_worker(struct btrfs_work *work)
2182static void scrub_missing_raid56_pages(struct scrub_block *sblock) 2180static void scrub_missing_raid56_pages(struct scrub_block *sblock)
2183{ 2181{
2184 struct scrub_ctx *sctx = sblock->sctx; 2182 struct scrub_ctx *sctx = sblock->sctx;
2185 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 2183 struct btrfs_fs_info *fs_info = sctx->fs_info;
2184 struct btrfs_root *dev_root = fs_info->dev_root;
2186 u64 length = sblock->page_count * PAGE_SIZE; 2185 u64 length = sblock->page_count * PAGE_SIZE;
2187 u64 logical = sblock->pagev[0]->logical; 2186 u64 logical = sblock->pagev[0]->logical;
2188 struct btrfs_bio *bbio = NULL; 2187 struct btrfs_bio *bbio = NULL;
@@ -2215,7 +2214,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock)
2215 bio->bi_private = sblock; 2214 bio->bi_private = sblock;
2216 bio->bi_end_io = scrub_missing_raid56_end_io; 2215 bio->bi_end_io = scrub_missing_raid56_end_io;
2217 2216
2218 rbio = raid56_alloc_missing_rbio(sctx->dev_root, bio, bbio, length); 2217 rbio = raid56_alloc_missing_rbio(dev_root, bio, bbio, length);
2219 if (!rbio) 2218 if (!rbio)
2220 goto rbio_out; 2219 goto rbio_out;
2221 2220
@@ -2334,7 +2333,7 @@ leave_nomem:
2334static void scrub_bio_end_io(struct bio *bio) 2333static void scrub_bio_end_io(struct bio *bio)
2335{ 2334{
2336 struct scrub_bio *sbio = bio->bi_private; 2335 struct scrub_bio *sbio = bio->bi_private;
2337 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info; 2336 struct btrfs_fs_info *fs_info = sbio->dev->fs_info;
2338 2337
2339 sbio->err = bio->bi_error; 2338 sbio->err = bio->bi_error;
2340 sbio->bio = bio; 2339 sbio->bio = bio;
@@ -2391,7 +2390,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
2391{ 2390{
2392 u32 offset; 2391 u32 offset;
2393 int nsectors; 2392 int nsectors;
2394 int sectorsize = sparity->sctx->dev_root->sectorsize; 2393 int sectorsize = sparity->sctx->fs_info->dev_root->sectorsize;
2395 2394
2396 if (len >= sparity->stripe_len) { 2395 if (len >= sparity->stripe_len) {
2397 bitmap_set(bitmap, 0, sparity->nsectors); 2396 bitmap_set(bitmap, 0, sparity->nsectors);
@@ -2759,13 +2758,14 @@ static void scrub_parity_bio_endio(struct bio *bio)
2759 2758
2760 btrfs_init_work(&sparity->work, btrfs_scrubparity_helper, 2759 btrfs_init_work(&sparity->work, btrfs_scrubparity_helper,
2761 scrub_parity_bio_endio_worker, NULL, NULL); 2760 scrub_parity_bio_endio_worker, NULL, NULL);
2762 btrfs_queue_work(sparity->sctx->dev_root->fs_info->scrub_parity_workers, 2761 btrfs_queue_work(sparity->sctx->fs_info->scrub_parity_workers,
2763 &sparity->work); 2762 &sparity->work);
2764} 2763}
2765 2764
2766static void scrub_parity_check_and_repair(struct scrub_parity *sparity) 2765static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
2767{ 2766{
2768 struct scrub_ctx *sctx = sparity->sctx; 2767 struct scrub_ctx *sctx = sparity->sctx;
2768 struct btrfs_root *dev_root = sctx->fs_info->dev_root;
2769 struct bio *bio; 2769 struct bio *bio;
2770 struct btrfs_raid_bio *rbio; 2770 struct btrfs_raid_bio *rbio;
2771 struct scrub_page *spage; 2771 struct scrub_page *spage;
@@ -2778,7 +2778,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
2778 goto out; 2778 goto out;
2779 2779
2780 length = sparity->logic_end - sparity->logic_start; 2780 length = sparity->logic_end - sparity->logic_start;
2781 ret = btrfs_map_sblock(sctx->dev_root->fs_info, BTRFS_MAP_WRITE, 2781 ret = btrfs_map_sblock(sctx->fs_info, BTRFS_MAP_WRITE,
2782 sparity->logic_start, 2782 sparity->logic_start,
2783 &length, &bbio, 0, 1); 2783 &length, &bbio, 0, 1);
2784 if (ret || !bbio || !bbio->raid_map) 2784 if (ret || !bbio || !bbio->raid_map)
@@ -2792,7 +2792,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
2792 bio->bi_private = sparity; 2792 bio->bi_private = sparity;
2793 bio->bi_end_io = scrub_parity_bio_endio; 2793 bio->bi_end_io = scrub_parity_bio_endio;
2794 2794
2795 rbio = raid56_parity_alloc_scrub_rbio(sctx->dev_root, bio, bbio, 2795 rbio = raid56_parity_alloc_scrub_rbio(dev_root, bio, bbio,
2796 length, sparity->scrub_dev, 2796 length, sparity->scrub_dev,
2797 sparity->dbitmap, 2797 sparity->dbitmap,
2798 sparity->nsectors); 2798 sparity->nsectors);
@@ -2844,7 +2844,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
2844 u64 logic_start, 2844 u64 logic_start,
2845 u64 logic_end) 2845 u64 logic_end)
2846{ 2846{
2847 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 2847 struct btrfs_fs_info *fs_info = sctx->fs_info;
2848 struct btrfs_root *root = fs_info->extent_root; 2848 struct btrfs_root *root = fs_info->extent_root;
2849 struct btrfs_root *csum_root = fs_info->csum_root; 2849 struct btrfs_root *csum_root = fs_info->csum_root;
2850 struct btrfs_extent_item *extent; 2850 struct btrfs_extent_item *extent;
@@ -3069,7 +3069,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
3069 int is_dev_replace) 3069 int is_dev_replace)
3070{ 3070{
3071 struct btrfs_path *path, *ppath; 3071 struct btrfs_path *path, *ppath;
3072 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 3072 struct btrfs_fs_info *fs_info = sctx->fs_info;
3073 struct btrfs_root *root = fs_info->extent_root; 3073 struct btrfs_root *root = fs_info->extent_root;
3074 struct btrfs_root *csum_root = fs_info->csum_root; 3074 struct btrfs_root *csum_root = fs_info->csum_root;
3075 struct btrfs_extent_item *extent; 3075 struct btrfs_extent_item *extent;
@@ -3443,8 +3443,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
3443 struct btrfs_block_group_cache *cache, 3443 struct btrfs_block_group_cache *cache,
3444 int is_dev_replace) 3444 int is_dev_replace)
3445{ 3445{
3446 struct btrfs_mapping_tree *map_tree = 3446 struct btrfs_fs_info *fs_info = sctx->fs_info;
3447 &sctx->dev_root->fs_info->mapping_tree; 3447 struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
3448 struct map_lookup *map; 3448 struct map_lookup *map;
3449 struct extent_map *em; 3449 struct extent_map *em;
3450 int i; 3450 int i;
@@ -3497,7 +3497,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
3497{ 3497{
3498 struct btrfs_dev_extent *dev_extent = NULL; 3498 struct btrfs_dev_extent *dev_extent = NULL;
3499 struct btrfs_path *path; 3499 struct btrfs_path *path;
3500 struct btrfs_root *root = sctx->dev_root; 3500 struct btrfs_root *root = sctx->fs_info->dev_root;
3501 struct btrfs_fs_info *fs_info = root->fs_info; 3501 struct btrfs_fs_info *fs_info = root->fs_info;
3502 u64 length; 3502 u64 length;
3503 u64 chunk_offset; 3503 u64 chunk_offset;
@@ -3747,7 +3747,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
3747 u64 bytenr; 3747 u64 bytenr;
3748 u64 gen; 3748 u64 gen;
3749 int ret; 3749 int ret;
3750 struct btrfs_root *root = sctx->dev_root; 3750 struct btrfs_root *root = sctx->fs_info->dev_root;
3751 3751
3752 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) 3752 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
3753 return -EIO; 3753 return -EIO;
@@ -4123,7 +4123,7 @@ static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
4123 int mirror_num, u64 physical_for_dev_replace) 4123 int mirror_num, u64 physical_for_dev_replace)
4124{ 4124{
4125 struct scrub_copy_nocow_ctx *nocow_ctx; 4125 struct scrub_copy_nocow_ctx *nocow_ctx;
4126 struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info; 4126 struct btrfs_fs_info *fs_info = sctx->fs_info;
4127 4127
4128 nocow_ctx = kzalloc(sizeof(*nocow_ctx), GFP_NOFS); 4128 nocow_ctx = kzalloc(sizeof(*nocow_ctx), GFP_NOFS);
4129 if (!nocow_ctx) { 4129 if (!nocow_ctx) {
@@ -4182,7 +4182,7 @@ static void copy_nocow_pages_worker(struct btrfs_work *work)
4182 struct btrfs_root *root; 4182 struct btrfs_root *root;
4183 int not_written = 0; 4183 int not_written = 0;
4184 4184
4185 fs_info = sctx->dev_root->fs_info; 4185 fs_info = sctx->fs_info;
4186 root = fs_info->extent_root; 4186 root = fs_info->extent_root;
4187 4187
4188 path = btrfs_alloc_path(); 4188 path = btrfs_alloc_path();
@@ -4297,7 +4297,7 @@ out_unlock:
4297static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, 4297static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
4298 struct scrub_copy_nocow_ctx *nocow_ctx) 4298 struct scrub_copy_nocow_ctx *nocow_ctx)
4299{ 4299{
4300 struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info; 4300 struct btrfs_fs_info *fs_info = nocow_ctx->sctx->fs_info;
4301 struct btrfs_key key; 4301 struct btrfs_key key;
4302 struct inode *inode; 4302 struct inode *inode;
4303 struct page *page; 4303 struct page *page;
@@ -4427,7 +4427,7 @@ static int write_page_nocow(struct scrub_ctx *sctx,
4427 if (!dev) 4427 if (!dev)
4428 return -EIO; 4428 return -EIO;
4429 if (!dev->bdev) { 4429 if (!dev->bdev) {
4430 btrfs_warn_rl(dev->dev_root->fs_info, 4430 btrfs_warn_rl(dev->fs_info,
4431 "scrub write_page_nocow(bdev == NULL) is unexpected"); 4431 "scrub write_page_nocow(bdev == NULL) is unexpected");
4432 return -EIO; 4432 return -EIO;
4433 } 4433 }
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1622dc7eab91..4a21d82e1fb6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -367,7 +367,7 @@ static noinline void run_scheduled_bios(struct btrfs_device *device)
367 blk_start_plug(&plug); 367 blk_start_plug(&plug);
368 368
369 bdi = blk_get_backing_dev_info(device->bdev); 369 bdi = blk_get_backing_dev_info(device->bdev);
370 fs_info = device->dev_root->fs_info; 370 fs_info = device->fs_info;
371 limit = btrfs_async_submit_limit(fs_info); 371 limit = btrfs_async_submit_limit(fs_info);
372 limit = limit * 2 / 3; 372 limit = limit * 2 / 3;
373 373
@@ -1179,7 +1179,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
1179 u64 end, u64 *length) 1179 u64 end, u64 *length)
1180{ 1180{
1181 struct btrfs_key key; 1181 struct btrfs_key key;
1182 struct btrfs_root *root = device->dev_root; 1182 struct btrfs_root *root = device->fs_info->dev_root;
1183 struct btrfs_dev_extent *dev_extent; 1183 struct btrfs_dev_extent *dev_extent;
1184 struct btrfs_path *path; 1184 struct btrfs_path *path;
1185 u64 extent_end; 1185 u64 extent_end;
@@ -1262,7 +1262,7 @@ static int contains_pending_extent(struct btrfs_transaction *transaction,
1262 struct btrfs_device *device, 1262 struct btrfs_device *device,
1263 u64 *start, u64 len) 1263 u64 *start, u64 len)
1264{ 1264{
1265 struct btrfs_fs_info *fs_info = device->dev_root->fs_info; 1265 struct btrfs_fs_info *fs_info = device->fs_info;
1266 struct extent_map *em; 1266 struct extent_map *em;
1267 struct list_head *search_list = &fs_info->pinned_chunks; 1267 struct list_head *search_list = &fs_info->pinned_chunks;
1268 int ret = 0; 1268 int ret = 0;
@@ -1338,8 +1338,8 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction,
1338 struct btrfs_device *device, u64 num_bytes, 1338 struct btrfs_device *device, u64 num_bytes,
1339 u64 search_start, u64 *start, u64 *len) 1339 u64 search_start, u64 *start, u64 *len)
1340{ 1340{
1341 struct btrfs_root *root = device->fs_info->dev_root;
1341 struct btrfs_key key; 1342 struct btrfs_key key;
1342 struct btrfs_root *root = device->dev_root;
1343 struct btrfs_dev_extent *dev_extent; 1343 struct btrfs_dev_extent *dev_extent;
1344 struct btrfs_path *path; 1344 struct btrfs_path *path;
1345 u64 hole_size; 1345 u64 hole_size;
@@ -1508,9 +1508,9 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
1508 struct btrfs_device *device, 1508 struct btrfs_device *device,
1509 u64 start, u64 *dev_extent_len) 1509 u64 start, u64 *dev_extent_len)
1510{ 1510{
1511 struct btrfs_root *root = device->fs_info->dev_root;
1511 int ret; 1512 int ret;
1512 struct btrfs_path *path; 1513 struct btrfs_path *path;
1513 struct btrfs_root *root = device->dev_root;
1514 struct btrfs_key key; 1514 struct btrfs_key key;
1515 struct btrfs_key found_key; 1515 struct btrfs_key found_key;
1516 struct extent_buffer *leaf = NULL; 1516 struct extent_buffer *leaf = NULL;
@@ -1569,7 +1569,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
1569{ 1569{
1570 int ret; 1570 int ret;
1571 struct btrfs_path *path; 1571 struct btrfs_path *path;
1572 struct btrfs_root *root = device->dev_root; 1572 struct btrfs_root *root = device->fs_info->dev_root;
1573 struct btrfs_dev_extent *extent; 1573 struct btrfs_dev_extent *extent;
1574 struct extent_buffer *leaf; 1574 struct extent_buffer *leaf;
1575 struct btrfs_key key; 1575 struct btrfs_key key;
@@ -2387,7 +2387,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
2387 device->total_bytes = i_size_read(bdev->bd_inode); 2387 device->total_bytes = i_size_read(bdev->bd_inode);
2388 device->disk_total_bytes = device->total_bytes; 2388 device->disk_total_bytes = device->total_bytes;
2389 device->commit_total_bytes = device->total_bytes; 2389 device->commit_total_bytes = device->total_bytes;
2390 device->dev_root = root->fs_info->dev_root; 2390 device->fs_info = fs_info;
2391 device->bdev = bdev; 2391 device->bdev = bdev;
2392 device->in_fs_metadata = 1; 2392 device->in_fs_metadata = 1;
2393 device->is_tgtdev_for_dev_replace = 0; 2393 device->is_tgtdev_for_dev_replace = 0;
@@ -2596,7 +2596,7 @@ int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
2596 ASSERT(list_empty(&srcdev->resized_list)); 2596 ASSERT(list_empty(&srcdev->resized_list));
2597 device->commit_total_bytes = srcdev->commit_total_bytes; 2597 device->commit_total_bytes = srcdev->commit_total_bytes;
2598 device->commit_bytes_used = device->bytes_used; 2598 device->commit_bytes_used = device->bytes_used;
2599 device->dev_root = fs_info->dev_root; 2599 device->fs_info = fs_info;
2600 device->bdev = bdev; 2600 device->bdev = bdev;
2601 device->in_fs_metadata = 1; 2601 device->in_fs_metadata = 1;
2602 device->is_tgtdev_for_dev_replace = 1; 2602 device->is_tgtdev_for_dev_replace = 1;
@@ -2624,7 +2624,7 @@ void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
2624 tgtdev->io_width = fs_info->dev_root->sectorsize; 2624 tgtdev->io_width = fs_info->dev_root->sectorsize;
2625 tgtdev->io_align = fs_info->dev_root->sectorsize; 2625 tgtdev->io_align = fs_info->dev_root->sectorsize;
2626 tgtdev->sector_size = fs_info->dev_root->sectorsize; 2626 tgtdev->sector_size = fs_info->dev_root->sectorsize;
2627 tgtdev->dev_root = fs_info->dev_root; 2627 tgtdev->fs_info = fs_info;
2628 tgtdev->in_fs_metadata = 1; 2628 tgtdev->in_fs_metadata = 1;
2629} 2629}
2630 2630
@@ -2638,7 +2638,7 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
2638 struct extent_buffer *leaf; 2638 struct extent_buffer *leaf;
2639 struct btrfs_key key; 2639 struct btrfs_key key;
2640 2640
2641 root = device->dev_root->fs_info->chunk_root; 2641 root = device->fs_info->chunk_root;
2642 2642
2643 path = btrfs_alloc_path(); 2643 path = btrfs_alloc_path();
2644 if (!path) 2644 if (!path)
@@ -2679,8 +2679,7 @@ out:
2679int btrfs_grow_device(struct btrfs_trans_handle *trans, 2679int btrfs_grow_device(struct btrfs_trans_handle *trans,
2680 struct btrfs_device *device, u64 new_size) 2680 struct btrfs_device *device, u64 new_size)
2681{ 2681{
2682 struct btrfs_super_block *super_copy = 2682 struct btrfs_super_block *super_copy = device->fs_info->super_copy;
2683 device->dev_root->fs_info->super_copy;
2684 struct btrfs_fs_devices *fs_devices; 2683 struct btrfs_fs_devices *fs_devices;
2685 u64 old_total; 2684 u64 old_total;
2686 u64 diff; 2685 u64 diff;
@@ -2688,28 +2687,28 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
2688 if (!device->writeable) 2687 if (!device->writeable)
2689 return -EACCES; 2688 return -EACCES;
2690 2689
2691 lock_chunks(device->dev_root); 2690 lock_chunks(device->fs_info->dev_root);
2692 old_total = btrfs_super_total_bytes(super_copy); 2691 old_total = btrfs_super_total_bytes(super_copy);
2693 diff = new_size - device->total_bytes; 2692 diff = new_size - device->total_bytes;
2694 2693
2695 if (new_size <= device->total_bytes || 2694 if (new_size <= device->total_bytes ||
2696 device->is_tgtdev_for_dev_replace) { 2695 device->is_tgtdev_for_dev_replace) {
2697 unlock_chunks(device->dev_root); 2696 unlock_chunks(device->fs_info->dev_root);
2698 return -EINVAL; 2697 return -EINVAL;
2699 } 2698 }
2700 2699
2701 fs_devices = device->dev_root->fs_info->fs_devices; 2700 fs_devices = device->fs_info->fs_devices;
2702 2701
2703 btrfs_set_super_total_bytes(super_copy, old_total + diff); 2702 btrfs_set_super_total_bytes(super_copy, old_total + diff);
2704 device->fs_devices->total_rw_bytes += diff; 2703 device->fs_devices->total_rw_bytes += diff;
2705 2704
2706 btrfs_device_set_total_bytes(device, new_size); 2705 btrfs_device_set_total_bytes(device, new_size);
2707 btrfs_device_set_disk_total_bytes(device, new_size); 2706 btrfs_device_set_disk_total_bytes(device, new_size);
2708 btrfs_clear_space_info_full(device->dev_root->fs_info); 2707 btrfs_clear_space_info_full(device->fs_info);
2709 if (list_empty(&device->resized_list)) 2708 if (list_empty(&device->resized_list))
2710 list_add_tail(&device->resized_list, 2709 list_add_tail(&device->resized_list,
2711 &fs_devices->resized_devices); 2710 &fs_devices->resized_devices);
2712 unlock_chunks(device->dev_root); 2711 unlock_chunks(device->fs_info->dev_root);
2713 2712
2714 return btrfs_update_device(trans, device); 2713 return btrfs_update_device(trans, device);
2715} 2714}
@@ -4356,7 +4355,7 @@ int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info)
4356int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) 4355int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
4357{ 4356{
4358 struct btrfs_trans_handle *trans; 4357 struct btrfs_trans_handle *trans;
4359 struct btrfs_root *root = device->dev_root; 4358 struct btrfs_root *root = device->fs_info->dev_root;
4360 struct btrfs_dev_extent *dev_extent = NULL; 4359 struct btrfs_dev_extent *dev_extent = NULL;
4361 struct btrfs_path *path; 4360 struct btrfs_path *path;
4362 u64 length; 4361 u64 length;
@@ -6884,7 +6883,7 @@ void btrfs_init_devices_late(struct btrfs_fs_info *fs_info)
6884 while (fs_devices) { 6883 while (fs_devices) {
6885 mutex_lock(&fs_devices->device_list_mutex); 6884 mutex_lock(&fs_devices->device_list_mutex);
6886 list_for_each_entry(device, &fs_devices->devices, dev_list) 6885 list_for_each_entry(device, &fs_devices->devices, dev_list)
6887 device->dev_root = fs_info->dev_root; 6886 device->fs_info = fs_info;
6888 mutex_unlock(&fs_devices->device_list_mutex); 6887 mutex_unlock(&fs_devices->device_list_mutex);
6889 6888
6890 fs_devices = fs_devices->seed; 6889 fs_devices = fs_devices->seed;
@@ -7060,7 +7059,7 @@ static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev)
7060{ 7059{
7061 if (!dev->dev_stats_valid) 7060 if (!dev->dev_stats_valid)
7062 return; 7061 return;
7063 btrfs_err_rl_in_rcu(dev->dev_root->fs_info, 7062 btrfs_err_rl_in_rcu(dev->fs_info,
7064 "bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u", 7063 "bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u",
7065 rcu_str_deref(dev->name), 7064 rcu_str_deref(dev->name),
7066 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS), 7065 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS),
@@ -7080,7 +7079,7 @@ static void btrfs_dev_stat_print_on_load(struct btrfs_device *dev)
7080 if (i == BTRFS_DEV_STAT_VALUES_MAX) 7079 if (i == BTRFS_DEV_STAT_VALUES_MAX)
7081 return; /* all values == 0, suppress message */ 7080 return; /* all values == 0, suppress message */
7082 7081
7083 btrfs_info_in_rcu(dev->dev_root->fs_info, 7082 btrfs_info_in_rcu(dev->fs_info,
7084 "bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u", 7083 "bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u",
7085 rcu_str_deref(dev->name), 7084 rcu_str_deref(dev->name),
7086 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS), 7085 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS),
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 0c8e77bfa8f6..859221769696 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -51,8 +51,7 @@ struct btrfs_device {
51 struct list_head dev_list; 51 struct list_head dev_list;
52 struct list_head dev_alloc_list; 52 struct list_head dev_alloc_list;
53 struct btrfs_fs_devices *fs_devices; 53 struct btrfs_fs_devices *fs_devices;
54 54 struct btrfs_fs_info *fs_info;
55 struct btrfs_root *dev_root;
56 55
57 struct rcu_string *name; 56 struct rcu_string *name;
58 57