Commit ed9bfdf1a40952fd0f8094ec77f876b84ead69af

Authored by NeilBrown
1 parent f5efd45ae5

md: raid1/raid10: handle allocation errors during array setup.

Both raid1 and raid10 create a mempool during startup.
If the 'alloc' function for this mempool fails, unplug_slaves
is called.
If that happens when the pool is being initialised, unplug_slaves
will try to use the 'conf' structure that isn't filled in yet, and
badness will happen.

So ensure that unplug_slaves doesn't get called unless we know
that the conf structure if fully initialised.

Signed-off-by: NeilBrown <neilb@suse.de>

Showing 2 changed files with 5 additions and 4 deletions Side-by-side Diff

... ... @@ -64,7 +64,7 @@
64 64  
65 65 /* allocate a r1bio with room for raid_disks entries in the bios array */
66 66 r1_bio = kzalloc(size, gfp_flags);
67   - if (!r1_bio)
  67 + if (!r1_bio && pi->mddev)
68 68 unplug_slaves(pi->mddev);
69 69  
70 70 return r1_bio;
71 71  
... ... @@ -1979,13 +1979,14 @@
1979 1979 conf->poolinfo = kmalloc(sizeof(*conf->poolinfo), GFP_KERNEL);
1980 1980 if (!conf->poolinfo)
1981 1981 goto out_no_mem;
1982   - conf->poolinfo->mddev = mddev;
  1982 + conf->poolinfo->mddev = NULL;
1983 1983 conf->poolinfo->raid_disks = mddev->raid_disks;
1984 1984 conf->r1bio_pool = mempool_create(NR_RAID1_BIOS, r1bio_pool_alloc,
1985 1985 r1bio_pool_free,
1986 1986 conf->poolinfo);
1987 1987 if (!conf->r1bio_pool)
1988 1988 goto out_no_mem;
  1989 + conf->poolinfo->mddev = mddev;
1989 1990  
1990 1991 spin_lock_init(&conf->device_lock);
1991 1992 mddev->queue->queue_lock = &conf->device_lock;
... ... @@ -68,7 +68,7 @@
68 68  
69 69 /* allocate a r10bio with room for raid_disks entries in the bios array */
70 70 r10_bio = kzalloc(size, gfp_flags);
71   - if (!r10_bio)
  71 + if (!r10_bio && conf->mddev)
72 72 unplug_slaves(conf->mddev);
73 73  
74 74 return r10_bio;
... ... @@ -2096,7 +2096,6 @@
2096 2096 if (!conf->tmppage)
2097 2097 goto out_free_conf;
2098 2098  
2099   - conf->mddev = mddev;
2100 2099 conf->raid_disks = mddev->raid_disks;
2101 2100 conf->near_copies = nc;
2102 2101 conf->far_copies = fc;
... ... @@ -2133,6 +2132,7 @@
2133 2132 goto out_free_conf;
2134 2133 }
2135 2134  
  2135 + conf->mddev = mddev;
2136 2136 spin_lock_init(&conf->device_lock);
2137 2137 mddev->queue->queue_lock = &conf->device_lock;
2138 2138