Commit 6a258d72 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: remove btrfs_raid_bio::fs_info member

We can grab fs_info reliably from btrfs_raid_bio::bioc, as the bioc is
always passed into alloc_rbio(), and only get released when the raid bio
is released.

Remove btrfs_raid_bio::fs_info member, and cleanup all the @fs_info
parameters for alloc_rbio() callers.
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 731ccf15
...@@ -60,7 +60,6 @@ enum btrfs_rbio_ops { ...@@ -60,7 +60,6 @@ enum btrfs_rbio_ops {
}; };
struct btrfs_raid_bio { struct btrfs_raid_bio {
struct btrfs_fs_info *fs_info;
struct btrfs_io_context *bioc; struct btrfs_io_context *bioc;
/* while we're doing rmw on a stripe /* while we're doing rmw on a stripe
...@@ -192,7 +191,7 @@ static void scrub_parity_work(struct btrfs_work *work); ...@@ -192,7 +191,7 @@ static void scrub_parity_work(struct btrfs_work *work);
static void start_async_work(struct btrfs_raid_bio *rbio, btrfs_func_t work_func) static void start_async_work(struct btrfs_raid_bio *rbio, btrfs_func_t work_func)
{ {
btrfs_init_work(&rbio->work, work_func, NULL, NULL); btrfs_init_work(&rbio->work, work_func, NULL, NULL);
btrfs_queue_work(rbio->fs_info->rmw_workers, &rbio->work); btrfs_queue_work(rbio->bioc->fs_info->rmw_workers, &rbio->work);
} }
/* /*
...@@ -345,7 +344,7 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio) ...@@ -345,7 +344,7 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
if (!test_bit(RBIO_CACHE_BIT, &rbio->flags)) if (!test_bit(RBIO_CACHE_BIT, &rbio->flags))
return; return;
table = rbio->fs_info->stripe_hash_table; table = rbio->bioc->fs_info->stripe_hash_table;
h = table->table + bucket; h = table->table + bucket;
/* hold the lock for the bucket because we may be /* hold the lock for the bucket because we may be
...@@ -400,7 +399,7 @@ static void remove_rbio_from_cache(struct btrfs_raid_bio *rbio) ...@@ -400,7 +399,7 @@ static void remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
if (!test_bit(RBIO_CACHE_BIT, &rbio->flags)) if (!test_bit(RBIO_CACHE_BIT, &rbio->flags))
return; return;
table = rbio->fs_info->stripe_hash_table; table = rbio->bioc->fs_info->stripe_hash_table;
spin_lock_irqsave(&table->cache_lock, flags); spin_lock_irqsave(&table->cache_lock, flags);
__remove_rbio_from_cache(rbio); __remove_rbio_from_cache(rbio);
...@@ -460,7 +459,7 @@ static void cache_rbio(struct btrfs_raid_bio *rbio) ...@@ -460,7 +459,7 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
if (!test_bit(RBIO_CACHE_READY_BIT, &rbio->flags)) if (!test_bit(RBIO_CACHE_READY_BIT, &rbio->flags))
return; return;
table = rbio->fs_info->stripe_hash_table; table = rbio->bioc->fs_info->stripe_hash_table;
spin_lock_irqsave(&table->cache_lock, flags); spin_lock_irqsave(&table->cache_lock, flags);
spin_lock(&rbio->bio_list_lock); spin_lock(&rbio->bio_list_lock);
...@@ -668,7 +667,7 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio) ...@@ -668,7 +667,7 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
struct btrfs_raid_bio *cache_drop = NULL; struct btrfs_raid_bio *cache_drop = NULL;
int ret = 0; int ret = 0;
h = rbio->fs_info->stripe_hash_table->table + rbio_bucket(rbio); h = rbio->bioc->fs_info->stripe_hash_table->table + rbio_bucket(rbio);
spin_lock_irqsave(&h->lock, flags); spin_lock_irqsave(&h->lock, flags);
list_for_each_entry(cur, &h->hash_list, hash_list) { list_for_each_entry(cur, &h->hash_list, hash_list) {
...@@ -750,7 +749,7 @@ static noinline void unlock_stripe(struct btrfs_raid_bio *rbio) ...@@ -750,7 +749,7 @@ static noinline void unlock_stripe(struct btrfs_raid_bio *rbio)
int keep_cache = 0; int keep_cache = 0;
bucket = rbio_bucket(rbio); bucket = rbio_bucket(rbio);
h = rbio->fs_info->stripe_hash_table->table + bucket; h = rbio->bioc->fs_info->stripe_hash_table->table + bucket;
if (list_empty(&rbio->plug_list)) if (list_empty(&rbio->plug_list))
cache_rbio(rbio); cache_rbio(rbio);
...@@ -864,7 +863,7 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t err) ...@@ -864,7 +863,7 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t err)
struct bio *extra; struct bio *extra;
if (rbio->generic_bio_cnt) if (rbio->generic_bio_cnt)
btrfs_bio_counter_sub(rbio->fs_info, rbio->generic_bio_cnt); btrfs_bio_counter_sub(rbio->bioc->fs_info, rbio->generic_bio_cnt);
/* /*
* At this moment, rbio->bio_list is empty, however since rbio does not * At this moment, rbio->bio_list is empty, however since rbio does not
...@@ -987,7 +986,6 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info, ...@@ -987,7 +986,6 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
INIT_LIST_HEAD(&rbio->stripe_cache); INIT_LIST_HEAD(&rbio->stripe_cache);
INIT_LIST_HEAD(&rbio->hash_list); INIT_LIST_HEAD(&rbio->hash_list);
rbio->bioc = bioc; rbio->bioc = bioc;
rbio->fs_info = fs_info;
rbio->stripe_len = stripe_len; rbio->stripe_len = stripe_len;
rbio->nr_pages = num_pages; rbio->nr_pages = num_pages;
rbio->real_stripes = real_stripes; rbio->real_stripes = real_stripes;
...@@ -1546,7 +1544,7 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio) ...@@ -1546,7 +1544,7 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
bio->bi_end_io = raid_rmw_end_io; bio->bi_end_io = raid_rmw_end_io;
bio->bi_opf = REQ_OP_READ; bio->bi_opf = REQ_OP_READ;
btrfs_bio_wq_end_io(rbio->fs_info, bio, BTRFS_WQ_ENDIO_RAID56); btrfs_bio_wq_end_io(rbio->bioc->fs_info, bio, BTRFS_WQ_ENDIO_RAID56);
submit_bio(bio); submit_bio(bio);
} }
...@@ -1718,9 +1716,10 @@ static void btrfs_raid_unplug(struct blk_plug_cb *cb, bool from_schedule) ...@@ -1718,9 +1716,10 @@ static void btrfs_raid_unplug(struct blk_plug_cb *cb, bool from_schedule)
/* /*
* our main entry point for writes from the rest of the FS. * our main entry point for writes from the rest of the FS.
*/ */
int raid56_parity_write(struct btrfs_fs_info *fs_info, struct bio *bio, int raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc,
struct btrfs_io_context *bioc, u64 stripe_len) u64 stripe_len)
{ {
struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio; struct btrfs_raid_bio *rbio;
struct btrfs_plug_cb *plug = NULL; struct btrfs_plug_cb *plug = NULL;
struct blk_plug_cb *cb; struct blk_plug_cb *cb;
...@@ -2091,7 +2090,7 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio) ...@@ -2091,7 +2090,7 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)
bio->bi_end_io = raid_recover_end_io; bio->bi_end_io = raid_recover_end_io;
bio->bi_opf = REQ_OP_READ; bio->bi_opf = REQ_OP_READ;
btrfs_bio_wq_end_io(rbio->fs_info, bio, BTRFS_WQ_ENDIO_RAID56); btrfs_bio_wq_end_io(rbio->bioc->fs_info, bio, BTRFS_WQ_ENDIO_RAID56);
submit_bio(bio); submit_bio(bio);
} }
...@@ -2115,10 +2114,10 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio) ...@@ -2115,10 +2114,10 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)
* so we assume the bio they send down corresponds to a failed part * so we assume the bio they send down corresponds to a failed part
* of the drive. * of the drive.
*/ */
int raid56_parity_recover(struct btrfs_fs_info *fs_info, struct bio *bio, int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
struct btrfs_io_context *bioc, u64 stripe_len, u64 stripe_len, int mirror_num, int generic_io)
int mirror_num, int generic_io)
{ {
struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio; struct btrfs_raid_bio *rbio;
int ret; int ret;
...@@ -2220,12 +2219,12 @@ static void read_rebuild_work(struct btrfs_work *work) ...@@ -2220,12 +2219,12 @@ static void read_rebuild_work(struct btrfs_work *work)
* is those pages just hold metadata or file data with checksum. * is those pages just hold metadata or file data with checksum.
*/ */
struct btrfs_raid_bio * struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
raid56_parity_alloc_scrub_rbio(struct btrfs_fs_info *fs_info, struct bio *bio, struct btrfs_io_context *bioc,
struct btrfs_io_context *bioc, u64 stripe_len, u64 stripe_len, struct btrfs_device *scrub_dev,
struct btrfs_device *scrub_dev, unsigned long *dbitmap, int stripe_nsectors)
unsigned long *dbitmap, int stripe_nsectors)
{ {
struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio; struct btrfs_raid_bio *rbio;
int i; int i;
...@@ -2633,7 +2632,7 @@ static void raid56_parity_scrub_stripe(struct btrfs_raid_bio *rbio) ...@@ -2633,7 +2632,7 @@ static void raid56_parity_scrub_stripe(struct btrfs_raid_bio *rbio)
bio->bi_end_io = raid56_parity_scrub_end_io; bio->bi_end_io = raid56_parity_scrub_end_io;
bio->bi_opf = REQ_OP_READ; bio->bi_opf = REQ_OP_READ;
btrfs_bio_wq_end_io(rbio->fs_info, bio, BTRFS_WQ_ENDIO_RAID56); btrfs_bio_wq_end_io(rbio->bioc->fs_info, bio, BTRFS_WQ_ENDIO_RAID56);
submit_bio(bio); submit_bio(bio);
} }
...@@ -2669,9 +2668,10 @@ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio) ...@@ -2669,9 +2668,10 @@ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio)
/* The following code is used for dev replace of a missing RAID 5/6 device. */ /* The following code is used for dev replace of a missing RAID 5/6 device. */
struct btrfs_raid_bio * struct btrfs_raid_bio *
raid56_alloc_missing_rbio(struct btrfs_fs_info *fs_info, struct bio *bio, raid56_alloc_missing_rbio(struct bio *bio, struct btrfs_io_context *bioc,
struct btrfs_io_context *bioc, u64 length) u64 length)
{ {
struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio; struct btrfs_raid_bio *rbio;
rbio = alloc_rbio(fs_info, bioc, length); rbio = alloc_rbio(fs_info, bioc, length);
......
...@@ -30,25 +30,23 @@ static inline int nr_data_stripes(const struct map_lookup *map) ...@@ -30,25 +30,23 @@ static inline int nr_data_stripes(const struct map_lookup *map)
struct btrfs_raid_bio; struct btrfs_raid_bio;
struct btrfs_device; struct btrfs_device;
int raid56_parity_recover(struct btrfs_fs_info *fs_info, struct bio *bio, int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
struct btrfs_io_context *bioc, u64 stripe_len, u64 stripe_len, int mirror_num, int generic_io);
int mirror_num, int generic_io); int raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc,
int raid56_parity_write(struct btrfs_fs_info *fs_info, struct bio *bio, u64 stripe_len);
struct btrfs_io_context *bioc, u64 stripe_len);
void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page, void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page,
u64 logical); u64 logical);
struct btrfs_raid_bio * struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
raid56_parity_alloc_scrub_rbio(struct btrfs_fs_info *fs_info, struct bio *bio, struct btrfs_io_context *bioc, u64 stripe_len,
struct btrfs_io_context *bioc, u64 stripe_len, struct btrfs_device *scrub_dev,
struct btrfs_device *scrub_dev, unsigned long *dbitmap, int stripe_nsectors);
unsigned long *dbitmap, int stripe_nsectors);
void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio); void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio);
struct btrfs_raid_bio * struct btrfs_raid_bio *
raid56_alloc_missing_rbio(struct btrfs_fs_info *fs_info, struct bio *bio, raid56_alloc_missing_rbio(struct bio *bio, struct btrfs_io_context *bioc,
struct btrfs_io_context *bioc, u64 length); u64 length);
void raid56_submit_missing_rbio(struct btrfs_raid_bio *rbio); void raid56_submit_missing_rbio(struct btrfs_raid_bio *rbio);
int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info); int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
......
...@@ -1400,7 +1400,7 @@ static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info, ...@@ -1400,7 +1400,7 @@ static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info,
bio->bi_end_io = scrub_bio_wait_endio; bio->bi_end_io = scrub_bio_wait_endio;
mirror_num = spage->sblock->pagev[0]->mirror_num; mirror_num = spage->sblock->pagev[0]->mirror_num;
ret = raid56_parity_recover(fs_info, bio, spage->recover->bioc, ret = raid56_parity_recover(bio, spage->recover->bioc,
spage->recover->map_length, spage->recover->map_length,
mirror_num, 0); mirror_num, 0);
if (ret) if (ret)
...@@ -2230,7 +2230,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock) ...@@ -2230,7 +2230,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock)
bio->bi_private = sblock; bio->bi_private = sblock;
bio->bi_end_io = scrub_missing_raid56_end_io; bio->bi_end_io = scrub_missing_raid56_end_io;
rbio = raid56_alloc_missing_rbio(fs_info, bio, bioc, length); rbio = raid56_alloc_missing_rbio(bio, bioc, length);
if (!rbio) if (!rbio)
goto rbio_out; goto rbio_out;
...@@ -2846,8 +2846,8 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity) ...@@ -2846,8 +2846,8 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
bio->bi_private = sparity; bio->bi_private = sparity;
bio->bi_end_io = scrub_parity_bio_endio; bio->bi_end_io = scrub_parity_bio_endio;
rbio = raid56_parity_alloc_scrub_rbio(fs_info, bio, bioc, rbio = raid56_parity_alloc_scrub_rbio(bio, bioc, length,
length, sparity->scrub_dev, sparity->scrub_dev,
sparity->dbitmap, sparity->dbitmap,
sparity->nsectors); sparity->nsectors);
if (!rbio) if (!rbio)
......
...@@ -6708,11 +6708,10 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, ...@@ -6708,11 +6708,10 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
/* In this case, map_length has been set to the length of /* In this case, map_length has been set to the length of
a single stripe; not the whole write */ a single stripe; not the whole write */
if (btrfs_op(bio) == BTRFS_MAP_WRITE) { if (btrfs_op(bio) == BTRFS_MAP_WRITE) {
ret = raid56_parity_write(fs_info, bio, bioc, ret = raid56_parity_write(bio, bioc, map_length);
map_length);
} else { } else {
ret = raid56_parity_recover(fs_info, bio, bioc, ret = raid56_parity_recover(bio, bioc, map_length,
map_length, mirror_num, 1); mirror_num, 1);
} }
btrfs_bio_counter_dec(fs_info); btrfs_bio_counter_dec(fs_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment