Skip to content

Commit

Permalink
md: convert to bioset_init()/mempool_init()
Browse files Browse the repository at this point in the history
Convert md to embedded bio sets.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Kent Overstreet authored and Jens Axboe committed May 30, 2018
1 parent d19936a commit afeee51
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 181 deletions.
2 changes: 1 addition & 1 deletion drivers/md/md-faulty.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static bool faulty_make_request(struct mddev *mddev, struct bio *bio)
}
}
if (failit) {
struct bio *b = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
struct bio *b = bio_clone_fast(bio, GFP_NOIO, &mddev->bio_set);

bio_set_dev(b, conf->rdev->bdev);
b->bi_private = bio;
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/md-linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static bool linear_make_request(struct mddev *mddev, struct bio *bio)
if (unlikely(bio_end_sector(bio) > end_sector)) {
/* This bio crosses a device boundary, so we have to split it */
struct bio *split = bio_split(bio, end_sector - bio_sector,
GFP_NOIO, mddev->bio_set);
GFP_NOIO, &mddev->bio_set);
bio_chain(split, bio);
generic_make_request(bio);
bio = split;
Expand Down
17 changes: 9 additions & 8 deletions drivers/md/md-multipath.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void multipath_end_bh_io(struct multipath_bh *mp_bh, blk_status_t status)

bio->bi_status = status;
bio_endio(bio);
mempool_free(mp_bh, conf->pool);
mempool_free(mp_bh, &conf->pool);
}

static void multipath_end_request(struct bio *bio)
Expand Down Expand Up @@ -117,15 +117,15 @@ static bool multipath_make_request(struct mddev *mddev, struct bio * bio)
return true;
}

mp_bh = mempool_alloc(conf->pool, GFP_NOIO);
mp_bh = mempool_alloc(&conf->pool, GFP_NOIO);

mp_bh->master_bio = bio;
mp_bh->mddev = mddev;

mp_bh->path = multipath_map(conf);
if (mp_bh->path < 0) {
bio_io_error(bio);
mempool_free(mp_bh, conf->pool);
mempool_free(mp_bh, &conf->pool);
return true;
}
multipath = conf->multipaths + mp_bh->path;
Expand Down Expand Up @@ -378,6 +378,7 @@ static int multipath_run (struct mddev *mddev)
struct multipath_info *disk;
struct md_rdev *rdev;
int working_disks;
int ret;

if (md_check_no_bitmap(mddev))
return -EINVAL;
Expand Down Expand Up @@ -431,9 +432,9 @@ static int multipath_run (struct mddev *mddev)
}
mddev->degraded = conf->raid_disks - working_disks;

conf->pool = mempool_create_kmalloc_pool(NR_RESERVED_BUFS,
sizeof(struct multipath_bh));
if (conf->pool == NULL)
ret = mempool_init_kmalloc_pool(&conf->pool, NR_RESERVED_BUFS,
sizeof(struct multipath_bh));
if (ret)
goto out_free_conf;

mddev->thread = md_register_thread(multipathd, mddev,
Expand All @@ -455,7 +456,7 @@ static int multipath_run (struct mddev *mddev)
return 0;

out_free_conf:
mempool_destroy(conf->pool);
mempool_exit(&conf->pool);
kfree(conf->multipaths);
kfree(conf);
mddev->private = NULL;
Expand All @@ -467,7 +468,7 @@ static void multipath_free(struct mddev *mddev, void *priv)
{
struct mpconf *conf = priv;

mempool_destroy(conf->pool);
mempool_exit(&conf->pool);
kfree(conf->multipaths);
kfree(conf);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/md/md-multipath.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct mpconf {
spinlock_t device_lock;
struct list_head retry_list;

mempool_t *pool;
mempool_t pool;
};

/*
Expand Down
61 changes: 24 additions & 37 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs,
{
struct bio *b;

if (!mddev || !mddev->bio_set)
if (!mddev || !bioset_initialized(&mddev->bio_set))
return bio_alloc(gfp_mask, nr_iovecs);

b = bio_alloc_bioset(gfp_mask, nr_iovecs, mddev->bio_set);
b = bio_alloc_bioset(gfp_mask, nr_iovecs, &mddev->bio_set);
if (!b)
return NULL;
return b;
Expand All @@ -205,10 +205,10 @@ EXPORT_SYMBOL_GPL(bio_alloc_mddev);

static struct bio *md_bio_alloc_sync(struct mddev *mddev)
{
if (!mddev || !mddev->sync_set)
if (!mddev || !bioset_initialized(&mddev->sync_set))
return bio_alloc(GFP_NOIO, 1);

return bio_alloc_bioset(GFP_NOIO, 1, mddev->sync_set);
return bio_alloc_bioset(GFP_NOIO, 1, &mddev->sync_set);
}

/*
Expand Down Expand Up @@ -510,7 +510,10 @@ static void mddev_delayed_delete(struct work_struct *ws);

static void mddev_put(struct mddev *mddev)
{
struct bio_set *bs = NULL, *sync_bs = NULL;
struct bio_set bs, sync_bs;

memset(&bs, 0, sizeof(bs));
memset(&sync_bs, 0, sizeof(sync_bs));

if (!atomic_dec_and_lock(&mddev->active, &all_mddevs_lock))
return;
Expand All @@ -521,8 +524,8 @@ static void mddev_put(struct mddev *mddev)
list_del_init(&mddev->all_mddevs);
bs = mddev->bio_set;
sync_bs = mddev->sync_set;
mddev->bio_set = NULL;
mddev->sync_set = NULL;
memset(&mddev->bio_set, 0, sizeof(mddev->bio_set));
memset(&mddev->sync_set, 0, sizeof(mddev->sync_set));
if (mddev->gendisk) {
/* We did a probe so need to clean up. Call
* queue_work inside the spinlock so that
Expand All @@ -535,10 +538,8 @@ static void mddev_put(struct mddev *mddev)
kfree(mddev);
}
spin_unlock(&all_mddevs_lock);
if (bs)
bioset_free(bs);
if (sync_bs)
bioset_free(sync_bs);
bioset_exit(&bs);
bioset_exit(&sync_bs);
}

static void md_safemode_timeout(struct timer_list *t);
Expand Down Expand Up @@ -2123,7 +2124,7 @@ int md_integrity_register(struct mddev *mddev)
bdev_get_integrity(reference->bdev));

pr_debug("md: data integrity enabled on %s\n", mdname(mddev));
if (bioset_integrity_create(mddev->bio_set, BIO_POOL_SIZE)) {
if (bioset_integrity_create(&mddev->bio_set, BIO_POOL_SIZE)) {
pr_err("md: failed to create integrity pool for %s\n",
mdname(mddev));
return -EINVAL;
Expand Down Expand Up @@ -5497,17 +5498,15 @@ int md_run(struct mddev *mddev)
sysfs_notify_dirent_safe(rdev->sysfs_state);
}

if (mddev->bio_set == NULL) {
mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!mddev->bio_set)
return -ENOMEM;
if (!bioset_initialized(&mddev->bio_set)) {
err = bioset_init(&mddev->bio_set, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (err)
return err;
}
if (mddev->sync_set == NULL) {
mddev->sync_set = bioset_create(BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (!mddev->sync_set) {
err = -ENOMEM;
if (!bioset_initialized(&mddev->sync_set)) {
err = bioset_init(&mddev->sync_set, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
if (err)
goto abort;
}
}

spin_lock(&pers_lock);
Expand Down Expand Up @@ -5668,14 +5667,8 @@ int md_run(struct mddev *mddev)
return 0;

abort:
if (mddev->bio_set) {
bioset_free(mddev->bio_set);
mddev->bio_set = NULL;
}
if (mddev->sync_set) {
bioset_free(mddev->sync_set);
mddev->sync_set = NULL;
}
bioset_exit(&mddev->bio_set);
bioset_exit(&mddev->sync_set);

return err;
}
Expand Down Expand Up @@ -5888,14 +5881,8 @@ void md_stop(struct mddev *mddev)
* This is called from dm-raid
*/
__md_stop(mddev);
if (mddev->bio_set) {
bioset_free(mddev->bio_set);
mddev->bio_set = NULL;
}
if (mddev->sync_set) {
bioset_free(mddev->sync_set);
mddev->sync_set = NULL;
}
bioset_exit(&mddev->bio_set);
bioset_exit(&mddev->sync_set);
}

EXPORT_SYMBOL_GPL(md_stop);
Expand Down
4 changes: 2 additions & 2 deletions drivers/md/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ struct mddev {

struct attribute_group *to_remove;

struct bio_set *bio_set;
struct bio_set *sync_set; /* for sync operations like
struct bio_set bio_set;
struct bio_set sync_set; /* for sync operations like
* metadata and bitmap writes
*/

Expand Down
5 changes: 3 additions & 2 deletions drivers/md/raid0.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
if (bio_end_sector(bio) > zone->zone_end) {
struct bio *split = bio_split(bio,
zone->zone_end - bio->bi_iter.bi_sector, GFP_NOIO,
mddev->bio_set);
&mddev->bio_set);
bio_chain(split, bio);
generic_make_request(bio);
bio = split;
Expand Down Expand Up @@ -582,7 +582,8 @@ static bool raid0_make_request(struct mddev *mddev, struct bio *bio)
sector = bio_sector;

if (sectors < bio_sectors(bio)) {
struct bio *split = bio_split(bio, sectors, GFP_NOIO, mddev->bio_set);
struct bio *split = bio_split(bio, sectors, GFP_NOIO,
&mddev->bio_set);
bio_chain(split, bio);
generic_make_request(bio);
bio = split;
Expand Down
Loading

0 comments on commit afeee51

Please sign in to comment.