diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index c8ea9ba6829e..d52adf81065a 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2713,6 +2713,37 @@ static int drop_one_stripe(struct r5conf *conf) static void shrink_stripes(struct r5conf *conf) { + struct list_head temp[NR_STRIPE_HASH_LOCKS]; + int i; + + /* + * grow_one_stripe() parks new stripes on released_stripes when + * mddev->thread is already set. Takeover leaves the previous + * personality's thread there, so raid5d never moves them to + * inactive_list. Drain them before the cache is destroyed. + * slab_cache is assigned only after device_lock and the hash + * lists exist; earlier abort paths have nothing to drain. + */ + if (conf->slab_cache) { + for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) + INIT_LIST_HEAD(&temp[i]); + + spin_lock_irq(&conf->device_lock); + release_stripe_list(conf, temp); + spin_unlock_irq(&conf->device_lock); + + for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) { + if (list_empty(&temp[i])) + continue; + spin_lock_irq(conf->hash_locks + i); + if (list_empty(conf->inactive_list + i)) + atomic_dec(&conf->empty_inactive_list_nr); + list_splice_tail_init(&temp[i], + conf->inactive_list + i); + spin_unlock_irq(conf->hash_locks + i); + } + } + while (conf->max_nr_stripes && drop_one_stripe(conf)) ;