@@ -255,7 +255,7 @@ static void free_r1bio(struct r1bio *r1_bio)
255255 struct r1conf * conf = r1_bio -> mddev -> private ;
256256
257257 put_all_bios (conf , r1_bio );
258- mempool_free (r1_bio , & conf -> r1bio_pool );
258+ mempool_free (r1_bio , conf -> r1bio_pool );
259259}
260260
261261static void put_buf (struct r1bio * r1_bio )
@@ -1305,9 +1305,8 @@ alloc_r1bio(struct mddev *mddev, struct bio *bio)
13051305 struct r1conf * conf = mddev -> private ;
13061306 struct r1bio * r1_bio ;
13071307
1308- r1_bio = mempool_alloc (& conf -> r1bio_pool , GFP_NOIO );
1309- /* Ensure no bio records IO_BLOCKED */
1310- memset (r1_bio -> bios , 0 , conf -> raid_disks * sizeof (r1_bio -> bios [0 ]));
1308+ r1_bio = mempool_alloc (conf -> r1bio_pool , GFP_NOIO );
1309+ memset (r1_bio , 0 , offsetof(struct r1bio , bios [conf -> raid_disks * 2 ]));
13111310 init_r1bio (r1_bio , mddev , bio );
13121311 return r1_bio ;
13131312}
@@ -3085,6 +3084,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
30853084 int i ;
30863085 struct raid1_info * disk ;
30873086 struct md_rdev * rdev ;
3087+ size_t r1bio_size ;
30883088 int err = - ENOMEM ;
30893089
30903090 conf = kzalloc (sizeof (struct r1conf ), GFP_KERNEL );
@@ -3125,9 +3125,10 @@ static struct r1conf *setup_conf(struct mddev *mddev)
31253125 if (!conf -> poolinfo )
31263126 goto abort ;
31273127 conf -> poolinfo -> raid_disks = mddev -> raid_disks * 2 ;
3128- err = mempool_init (& conf -> r1bio_pool , NR_RAID_BIOS , r1bio_pool_alloc ,
3129- rbio_pool_free , conf -> poolinfo );
3130- if (err )
3128+
3129+ r1bio_size = offsetof(struct r1bio , bios [mddev -> raid_disks * 2 ]);
3130+ conf -> r1bio_pool = mempool_create_kmalloc_pool (NR_RAID_BIOS , r1bio_size );
3131+ if (!conf -> r1bio_pool )
31313132 goto abort ;
31323133
31333134 err = bioset_init (& conf -> bio_split , BIO_POOL_SIZE , 0 , 0 );
@@ -3198,7 +3199,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
31983199
31993200 abort :
32003201 if (conf ) {
3201- mempool_exit ( & conf -> r1bio_pool );
3202+ mempool_destroy ( conf -> r1bio_pool );
32023203 kfree (conf -> mirrors );
32033204 safe_put_page (conf -> tmppage );
32043205 kfree (conf -> poolinfo );
@@ -3311,7 +3312,7 @@ static void raid1_free(struct mddev *mddev, void *priv)
33113312{
33123313 struct r1conf * conf = priv ;
33133314
3314- mempool_exit ( & conf -> r1bio_pool );
3315+ mempool_destroy ( conf -> r1bio_pool );
33153316 kfree (conf -> mirrors );
33163317 safe_put_page (conf -> tmppage );
33173318 kfree (conf -> poolinfo );
@@ -3367,17 +3368,14 @@ static int raid1_reshape(struct mddev *mddev)
33673368 * At the same time, we "pack" the devices so that all the missing
33683369 * devices have the higher raid_disk numbers.
33693370 */
3370- mempool_t newpool , oldpool ;
3371+ mempool_t * newpool , * oldpool ;
33713372 struct pool_info * newpoolinfo ;
3373+ size_t new_r1bio_size ;
33723374 struct raid1_info * newmirrors ;
33733375 struct r1conf * conf = mddev -> private ;
33743376 int cnt , raid_disks ;
33753377 unsigned long flags ;
33763378 int d , d2 ;
3377- int ret ;
3378-
3379- memset (& newpool , 0 , sizeof (newpool ));
3380- memset (& oldpool , 0 , sizeof (oldpool ));
33813379
33823380 /* Cannot change chunk_size, layout, or level */
33833381 if (mddev -> chunk_sectors != mddev -> new_chunk_sectors ||
@@ -3409,18 +3407,18 @@ static int raid1_reshape(struct mddev *mddev)
34093407 newpoolinfo -> mddev = mddev ;
34103408 newpoolinfo -> raid_disks = raid_disks * 2 ;
34113409
3412- ret = mempool_init ( & newpool , NR_RAID_BIOS , r1bio_pool_alloc ,
3413- rbio_pool_free , newpoolinfo );
3414- if (ret ) {
3410+ new_r1bio_size = offsetof( struct r1bio , bios [ raid_disks * 2 ]);
3411+ newpool = mempool_create_kmalloc_pool ( NR_RAID_BIOS , new_r1bio_size );
3412+ if (! newpool ) {
34153413 kfree (newpoolinfo );
3416- return ret ;
3414+ return - ENOMEM ;
34173415 }
34183416 newmirrors = kzalloc (array3_size (sizeof (struct raid1_info ),
34193417 raid_disks , 2 ),
34203418 GFP_KERNEL );
34213419 if (!newmirrors ) {
34223420 kfree (newpoolinfo );
3423- mempool_exit ( & newpool );
3421+ mempool_destroy ( newpool );
34243422 return - ENOMEM ;
34253423 }
34263424
@@ -3429,7 +3427,6 @@ static int raid1_reshape(struct mddev *mddev)
34293427 /* ok, everything is stopped */
34303428 oldpool = conf -> r1bio_pool ;
34313429 conf -> r1bio_pool = newpool ;
3432- init_waitqueue_head (& conf -> r1bio_pool .wait );
34333430
34343431 for (d = d2 = 0 ; d < conf -> raid_disks ; d ++ ) {
34353432 struct md_rdev * rdev = conf -> mirrors [d ].rdev ;
@@ -3461,7 +3458,7 @@ static int raid1_reshape(struct mddev *mddev)
34613458 set_bit (MD_RECOVERY_NEEDED , & mddev -> recovery );
34623459 md_wakeup_thread (mddev -> thread );
34633460
3464- mempool_exit ( & oldpool );
3461+ mempool_destroy ( oldpool );
34653462 return 0 ;
34663463}
34673464
0 commit comments