Skip to content

Commit

Permalink
btrfs: root->fs_info cleanup, use fs_info->dev_root everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Mahoney <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
jeffmahoney authored and kdave committed Dec 6, 2016
1 parent c28f158 commit fb45625
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 70 deletions.
2 changes: 1 addition & 1 deletion fs/btrfs/check-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ static int btrfsic_process_superblock_dev_mirror(
superblock_tmp->never_written = 0;
superblock_tmp->mirror_num = 1 + superblock_mirror_num;
if (state->print_mask & BTRFSIC_PRINT_MASK_SUPERBLOCK_WRITE)
btrfs_info_in_rcu(device->dev_root->fs_info,
btrfs_info_in_rcu(device->fs_info,
"new initial S-block (bdev %p, %s) @%llu (%s/%llu/%d)",
superblock_bdev,
rcu_str_deref(device->name), dev_bytenr,
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3308,7 +3308,7 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
struct btrfs_device *device = (struct btrfs_device *)
bh->b_private;

btrfs_warn_rl_in_rcu(device->dev_root->fs_info,
btrfs_warn_rl_in_rcu(device->fs_info,
"lost page write due to IO error on %s",
rcu_str_deref(device->name));
/* note, we don't set_buffer_write_io_error because we have
Expand Down Expand Up @@ -3453,7 +3453,7 @@ static int write_dev_supers(struct btrfs_device *device,
bh = __getblk(device->bdev, bytenr / 4096,
BTRFS_SUPER_INFO_SIZE);
if (!bh) {
btrfs_err(device->dev_root->fs_info,
btrfs_err(device->fs_info,
"couldn't get super buffer head for bytenr %llu",
bytenr);
errors++;
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -10853,7 +10853,7 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
ret = 0;

while (1) {
struct btrfs_fs_info *fs_info = device->dev_root->fs_info;
struct btrfs_fs_info *fs_info = device->fs_info;
struct btrfs_transaction *trans;
u64 bytes;

Expand Down
86 changes: 43 additions & 43 deletions fs/btrfs/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct scrub_wr_ctx {

struct scrub_ctx {
struct scrub_bio *bios[SCRUB_BIOS_PER_SCTX];
struct btrfs_root *dev_root;
struct btrfs_fs_info *fs_info;
int first_free;
int curr;
atomic_t bios_in_flight;
Expand Down Expand Up @@ -356,7 +356,7 @@ static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info)
*/
static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
{
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;

atomic_inc(&sctx->refs);
/*
Expand Down Expand Up @@ -388,7 +388,7 @@ static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx)
/* used for workers that require transaction commits */
static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx)
{
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;

/*
* see scrub_pending_trans_workers_inc() why we're pretending
Expand Down Expand Up @@ -458,7 +458,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
{
struct scrub_ctx *sctx;
int i;
struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;
struct btrfs_fs_info *fs_info = dev->fs_info;
int ret;

sctx = kzalloc(sizeof(*sctx), GFP_KERNEL);
Expand All @@ -468,7 +468,7 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
sctx->is_dev_replace = is_dev_replace;
sctx->pages_per_rd_bio = SCRUB_PAGES_PER_RD_BIO;
sctx->curr = -1;
sctx->dev_root = dev->dev_root;
sctx->fs_info = dev->fs_info;
for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {
struct scrub_bio *sbio;

Expand All @@ -489,8 +489,8 @@ struct scrub_ctx *scrub_setup_ctx(struct btrfs_device *dev, int is_dev_replace)
sctx->bios[i]->next_free = -1;
}
sctx->first_free = 0;
sctx->nodesize = dev->dev_root->nodesize;
sctx->sectorsize = dev->dev_root->sectorsize;
sctx->nodesize = dev->fs_info->dev_root->nodesize;
sctx->sectorsize = dev->fs_info->dev_root->sectorsize;
atomic_set(&sctx->bios_in_flight, 0);
atomic_set(&sctx->workers_pending, 0);
atomic_set(&sctx->cancel_req, 0);
Expand Down Expand Up @@ -524,7 +524,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root,
struct extent_buffer *eb;
struct btrfs_inode_item *inode_item;
struct scrub_warning *swarn = warn_ctx;
struct btrfs_fs_info *fs_info = swarn->dev->dev_root->fs_info;
struct btrfs_fs_info *fs_info = swarn->dev->fs_info;
struct inode_fs_paths *ipath = NULL;
struct btrfs_root *local_root;
struct btrfs_key root_key;
Expand Down Expand Up @@ -618,7 +618,7 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock)

WARN_ON(sblock->page_count < 1);
dev = sblock->pagev[0]->dev;
fs_info = sblock->sctx->dev_root->fs_info;
fs_info = sblock->sctx->fs_info;

path = btrfs_alloc_path();
if (!path)
Expand Down Expand Up @@ -843,10 +843,9 @@ static void scrub_fixup_nodatasum(struct btrfs_work *work)
spin_lock(&sctx->stat_lock);
++sctx->stat.uncorrectable_errors;
spin_unlock(&sctx->stat_lock);
btrfs_dev_replace_stats_inc(
&sctx->dev_root->fs_info->dev_replace.
num_uncorrectable_read_errors);
btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
btrfs_dev_replace_stats_inc(&sctx->fs_info->dev_replace.
num_uncorrectable_read_errors);
btrfs_err_rl_in_rcu(sctx->fs_info,
"unable to fixup (nodatasum) error at logical %llu on dev %s",
fixup->logical, rcu_str_deref(fixup->dev->name));
}
Expand Down Expand Up @@ -898,7 +897,7 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
DEFAULT_RATELIMIT_BURST);

BUG_ON(sblock_to_check->page_count < 1);
fs_info = sctx->dev_root->fs_info;
fs_info = sctx->fs_info;
if (sblock_to_check->pagev[0]->flags & BTRFS_EXTENT_FLAG_SUPER) {
/*
* if we find an error in a super block, we just report it.
Expand Down Expand Up @@ -1177,8 +1176,7 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
if (scrub_write_page_to_dev_replace(sblock_other,
page_num) != 0) {
btrfs_dev_replace_stats_inc(
&sctx->dev_root->
fs_info->dev_replace.
&sctx->fs_info->dev_replace.
num_write_errors);
success = 0;
}
Expand Down Expand Up @@ -1302,7 +1300,7 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock,
struct scrub_block *sblocks_for_recheck)
{
struct scrub_ctx *sctx = original_sblock->sctx;
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;
u64 length = original_sblock->page_count * PAGE_SIZE;
u64 logical = original_sblock->pagev[0]->logical;
u64 generation = original_sblock->pagev[0]->generation;
Expand Down Expand Up @@ -1574,7 +1572,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
int ret;

if (!page_bad->dev->bdev) {
btrfs_warn_rl(sblock_bad->sctx->dev_root->fs_info,
btrfs_warn_rl(sblock_bad->sctx->fs_info,
"scrub_repair_page_from_good_copy(bdev == NULL) is unexpected");
return -EIO;
}
Expand All @@ -1596,7 +1594,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
btrfs_dev_stat_inc_and_print(page_bad->dev,
BTRFS_DEV_STAT_WRITE_ERRS);
btrfs_dev_replace_stats_inc(
&sblock_bad->sctx->dev_root->fs_info->
&sblock_bad->sctx->fs_info->
dev_replace.num_write_errors);
bio_put(bio);
return -EIO;
Expand Down Expand Up @@ -1624,7 +1622,7 @@ static void scrub_write_block_to_dev_replace(struct scrub_block *sblock)
ret = scrub_write_page_to_dev_replace(sblock, page_num);
if (ret)
btrfs_dev_replace_stats_inc(
&sblock->sctx->dev_root->fs_info->dev_replace.
&sblock->sctx->fs_info->dev_replace.
num_write_errors);
}
}
Expand Down Expand Up @@ -1740,7 +1738,7 @@ static void scrub_wr_submit(struct scrub_ctx *sctx)
static void scrub_wr_bio_end_io(struct bio *bio)
{
struct scrub_bio *sbio = bio->bi_private;
struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sbio->dev->fs_info;

sbio->err = bio->bi_error;
sbio->bio = bio;
Expand All @@ -1759,7 +1757,7 @@ static void scrub_wr_bio_end_io_worker(struct btrfs_work *work)
WARN_ON(sbio->page_count > SCRUB_PAGES_PER_WR_BIO);
if (sbio->err) {
struct btrfs_dev_replace *dev_replace =
&sbio->sctx->dev_root->fs_info->dev_replace;
&sbio->sctx->fs_info->dev_replace;

for (i = 0; i < sbio->page_count; i++) {
struct scrub_page *spage = sbio->pagev[i];
Expand Down Expand Up @@ -1859,7 +1857,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
{
struct scrub_ctx *sctx = sblock->sctx;
struct btrfs_header *h;
struct btrfs_root *root = sctx->dev_root;
struct btrfs_root *root = sctx->fs_info->dev_root;
struct btrfs_fs_info *fs_info = root->fs_info;
u8 calculated_csum[BTRFS_CSUM_SIZE];
u8 on_disk_csum[BTRFS_CSUM_SIZE];
Expand Down Expand Up @@ -2126,7 +2124,7 @@ static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx,
static void scrub_missing_raid56_end_io(struct bio *bio)
{
struct scrub_block *sblock = bio->bi_private;
struct btrfs_fs_info *fs_info = sblock->sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sblock->sctx->fs_info;

if (bio->bi_error)
sblock->no_io_error_seen = 0;
Expand All @@ -2153,14 +2151,14 @@ static void scrub_missing_raid56_worker(struct btrfs_work *work)
spin_lock(&sctx->stat_lock);
sctx->stat.read_errors++;
spin_unlock(&sctx->stat_lock);
btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
btrfs_err_rl_in_rcu(sctx->fs_info,
"IO error rebuilding logical %llu for dev %s",
logical, rcu_str_deref(dev->name));
} else if (sblock->header_error || sblock->checksum_error) {
spin_lock(&sctx->stat_lock);
sctx->stat.uncorrectable_errors++;
spin_unlock(&sctx->stat_lock);
btrfs_err_rl_in_rcu(sctx->dev_root->fs_info,
btrfs_err_rl_in_rcu(sctx->fs_info,
"failed to rebuild valid logical %llu for dev %s",
logical, rcu_str_deref(dev->name));
} else {
Expand All @@ -2182,7 +2180,8 @@ static void scrub_missing_raid56_worker(struct btrfs_work *work)
static void scrub_missing_raid56_pages(struct scrub_block *sblock)
{
struct scrub_ctx *sctx = sblock->sctx;
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;
struct btrfs_root *dev_root = fs_info->dev_root;
u64 length = sblock->page_count * PAGE_SIZE;
u64 logical = sblock->pagev[0]->logical;
struct btrfs_bio *bbio = NULL;
Expand Down Expand Up @@ -2215,7 +2214,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock)
bio->bi_private = sblock;
bio->bi_end_io = scrub_missing_raid56_end_io;

rbio = raid56_alloc_missing_rbio(sctx->dev_root, bio, bbio, length);
rbio = raid56_alloc_missing_rbio(dev_root, bio, bbio, length);
if (!rbio)
goto rbio_out;

Expand Down Expand Up @@ -2334,7 +2333,7 @@ static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
static void scrub_bio_end_io(struct bio *bio)
{
struct scrub_bio *sbio = bio->bi_private;
struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sbio->dev->fs_info;

sbio->err = bio->bi_error;
sbio->bio = bio;
Expand Down Expand Up @@ -2391,7 +2390,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
{
u32 offset;
int nsectors;
int sectorsize = sparity->sctx->dev_root->sectorsize;
int sectorsize = sparity->sctx->fs_info->dev_root->sectorsize;

if (len >= sparity->stripe_len) {
bitmap_set(bitmap, 0, sparity->nsectors);
Expand Down Expand Up @@ -2759,13 +2758,14 @@ static void scrub_parity_bio_endio(struct bio *bio)

btrfs_init_work(&sparity->work, btrfs_scrubparity_helper,
scrub_parity_bio_endio_worker, NULL, NULL);
btrfs_queue_work(sparity->sctx->dev_root->fs_info->scrub_parity_workers,
btrfs_queue_work(sparity->sctx->fs_info->scrub_parity_workers,
&sparity->work);
}

static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
{
struct scrub_ctx *sctx = sparity->sctx;
struct btrfs_root *dev_root = sctx->fs_info->dev_root;
struct bio *bio;
struct btrfs_raid_bio *rbio;
struct scrub_page *spage;
Expand All @@ -2778,7 +2778,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
goto out;

length = sparity->logic_end - sparity->logic_start;
ret = btrfs_map_sblock(sctx->dev_root->fs_info, BTRFS_MAP_WRITE,
ret = btrfs_map_sblock(sctx->fs_info, BTRFS_MAP_WRITE,
sparity->logic_start,
&length, &bbio, 0, 1);
if (ret || !bbio || !bbio->raid_map)
Expand All @@ -2792,7 +2792,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
bio->bi_private = sparity;
bio->bi_end_io = scrub_parity_bio_endio;

rbio = raid56_parity_alloc_scrub_rbio(sctx->dev_root, bio, bbio,
rbio = raid56_parity_alloc_scrub_rbio(dev_root, bio, bbio,
length, sparity->scrub_dev,
sparity->dbitmap,
sparity->nsectors);
Expand Down Expand Up @@ -2844,7 +2844,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
u64 logic_start,
u64 logic_end)
{
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;
struct btrfs_root *root = fs_info->extent_root;
struct btrfs_root *csum_root = fs_info->csum_root;
struct btrfs_extent_item *extent;
Expand Down Expand Up @@ -3069,7 +3069,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
int is_dev_replace)
{
struct btrfs_path *path, *ppath;
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;
struct btrfs_root *root = fs_info->extent_root;
struct btrfs_root *csum_root = fs_info->csum_root;
struct btrfs_extent_item *extent;
Expand Down Expand Up @@ -3443,8 +3443,8 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
struct btrfs_block_group_cache *cache,
int is_dev_replace)
{
struct btrfs_mapping_tree *map_tree =
&sctx->dev_root->fs_info->mapping_tree;
struct btrfs_fs_info *fs_info = sctx->fs_info;
struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
struct map_lookup *map;
struct extent_map *em;
int i;
Expand Down Expand Up @@ -3497,7 +3497,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
{
struct btrfs_dev_extent *dev_extent = NULL;
struct btrfs_path *path;
struct btrfs_root *root = sctx->dev_root;
struct btrfs_root *root = sctx->fs_info->dev_root;
struct btrfs_fs_info *fs_info = root->fs_info;
u64 length;
u64 chunk_offset;
Expand Down Expand Up @@ -3747,7 +3747,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
u64 bytenr;
u64 gen;
int ret;
struct btrfs_root *root = sctx->dev_root;
struct btrfs_root *root = sctx->fs_info->dev_root;

if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
return -EIO;
Expand Down Expand Up @@ -4123,7 +4123,7 @@ static int copy_nocow_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
int mirror_num, u64 physical_for_dev_replace)
{
struct scrub_copy_nocow_ctx *nocow_ctx;
struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = sctx->fs_info;

nocow_ctx = kzalloc(sizeof(*nocow_ctx), GFP_NOFS);
if (!nocow_ctx) {
Expand Down Expand Up @@ -4182,7 +4182,7 @@ static void copy_nocow_pages_worker(struct btrfs_work *work)
struct btrfs_root *root;
int not_written = 0;

fs_info = sctx->dev_root->fs_info;
fs_info = sctx->fs_info;
root = fs_info->extent_root;

path = btrfs_alloc_path();
Expand Down Expand Up @@ -4297,7 +4297,7 @@ static int check_extent_to_block(struct inode *inode, u64 start, u64 len,
static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root,
struct scrub_copy_nocow_ctx *nocow_ctx)
{
struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info;
struct btrfs_fs_info *fs_info = nocow_ctx->sctx->fs_info;
struct btrfs_key key;
struct inode *inode;
struct page *page;
Expand Down Expand Up @@ -4427,7 +4427,7 @@ static int write_page_nocow(struct scrub_ctx *sctx,
if (!dev)
return -EIO;
if (!dev->bdev) {
btrfs_warn_rl(dev->dev_root->fs_info,
btrfs_warn_rl(dev->fs_info,
"scrub write_page_nocow(bdev == NULL) is unexpected");
return -EIO;
}
Expand Down
Loading

0 comments on commit fb45625

Please sign in to comment.