aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid0.c
diff options
context:
space:
mode:
authorAndre Noll <maan@systemlinux.org>2009-06-16 02:47:36 -0400
committerNeilBrown <neilb@suse.de>2009-06-16 02:47:36 -0400
commited7b00380d957ec770b5e90380d012c6062c13cc (patch)
tree8eced97cefca4be9f8eefce22ecb64a49ef6771b /drivers/md/raid0.c
parent5568a6035d9fca2cd8f1ef7005e215eae4e65fab (diff)
md: raid0: Allocate all buffers for the raid0 configuration in one function.
Currently the raid0 configuration is allocated in raid0_run() while the buffers for the strip_zone and the dev_list arrays are allocated in create_strip_zones(). On errors, all three buffers are freed in raid0_run(). It's easier and more readable to do the allocation and cleanup within a single function. So move that code into create_strip_zones(). Signed-off-by: Andre Noll <maan@systemlinux.org> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md/raid0.c')
-rw-r--r--drivers/md/raid0.c47
1 files changed, 17 insertions, 30 deletions
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index e5648b660e75..99cee51734e5 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -52,21 +52,18 @@ static int raid0_congested(void *data, int bits)
52 return ret; 52 return ret;
53} 53}
54 54
55static int create_strip_zones (mddev_t *mddev) 55static int create_strip_zones(mddev_t *mddev)
56{ 56{
57 int i, c, j; 57 int i, c, j, err;
58 sector_t curr_zone_end; 58 sector_t curr_zone_end;
59 raid0_conf_t *conf = mddev_to_conf(mddev);
60 mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev; 59 mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev;
61 struct strip_zone *zone; 60 struct strip_zone *zone;
62 int cnt; 61 int cnt;
63 char b[BDEVNAME_SIZE]; 62 char b[BDEVNAME_SIZE];
64 63 raid0_conf_t *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
65 /* 64
66 * The number of 'same size groups' 65 if (!conf)
67 */ 66 return -ENOMEM;
68 conf->nr_strip_zones = 0;
69
70 list_for_each_entry(rdev1, &mddev->disks, same_set) { 67 list_for_each_entry(rdev1, &mddev->disks, same_set) {
71 printk(KERN_INFO "raid0: looking at %s\n", 68 printk(KERN_INFO "raid0: looking at %s\n",
72 bdevname(rdev1->bdev,b)); 69 bdevname(rdev1->bdev,b));
@@ -101,16 +98,16 @@ static int create_strip_zones (mddev_t *mddev)
101 } 98 }
102 } 99 }
103 printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones); 100 printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones);
104 101 err = -ENOMEM;
105 conf->strip_zone = kzalloc(sizeof(struct strip_zone)* 102 conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
106 conf->nr_strip_zones, GFP_KERNEL); 103 conf->nr_strip_zones, GFP_KERNEL);
107 if (!conf->strip_zone) 104 if (!conf->strip_zone)
108 return -ENOMEM; 105 goto abort;
109 conf->devlist = kzalloc(sizeof(mdk_rdev_t*)* 106 conf->devlist = kzalloc(sizeof(mdk_rdev_t*)*
110 conf->nr_strip_zones*mddev->raid_disks, 107 conf->nr_strip_zones*mddev->raid_disks,
111 GFP_KERNEL); 108 GFP_KERNEL);
112 if (!conf->devlist) 109 if (!conf->devlist)
113 return -ENOMEM; 110 goto abort;
114 111
115 /* The first zone must contain all devices, so here we check that 112 /* The first zone must contain all devices, so here we check that
116 * there is a proper alignment of slots to devices and find them all 113 * there is a proper alignment of slots to devices and find them all
@@ -119,6 +116,7 @@ static int create_strip_zones (mddev_t *mddev)
119 cnt = 0; 116 cnt = 0;
120 smallest = NULL; 117 smallest = NULL;
121 zone->dev = conf->devlist; 118 zone->dev = conf->devlist;
119 err = -EINVAL;
122 list_for_each_entry(rdev1, &mddev->disks, same_set) { 120 list_for_each_entry(rdev1, &mddev->disks, same_set) {
123 int j = rdev1->raid_disk; 121 int j = rdev1->raid_disk;
124 122
@@ -206,9 +204,14 @@ static int create_strip_zones (mddev_t *mddev)
206 mddev->queue->backing_dev_info.congested_data = mddev; 204 mddev->queue->backing_dev_info.congested_data = mddev;
207 205
208 printk(KERN_INFO "raid0: done.\n"); 206 printk(KERN_INFO "raid0: done.\n");
207 mddev->private = conf;
209 return 0; 208 return 0;
210abort: 209abort:
211 return -EINVAL; 210 kfree(conf->strip_zone);
211 kfree(conf->devlist);
212 kfree(conf);
213 mddev->private = NULL;
214 return err;
212} 215}
213 216
214/** 217/**
@@ -253,7 +256,6 @@ static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks)
253 256
254static int raid0_run(mddev_t *mddev) 257static int raid0_run(mddev_t *mddev)
255{ 258{
256 raid0_conf_t *conf;
257 int ret; 259 int ret;
258 260
259 if (mddev->chunk_size == 0) { 261 if (mddev->chunk_size == 0) {
@@ -268,16 +270,9 @@ static int raid0_run(mddev_t *mddev)
268 blk_queue_segment_boundary(mddev->queue, (mddev->chunk_size>>1) - 1); 270 blk_queue_segment_boundary(mddev->queue, (mddev->chunk_size>>1) - 1);
269 mddev->queue->queue_lock = &mddev->queue->__queue_lock; 271 mddev->queue->queue_lock = &mddev->queue->__queue_lock;
270 272
271 conf = kmalloc(sizeof (raid0_conf_t), GFP_KERNEL);
272 if (!conf)
273 return -ENOMEM;
274 mddev->private = (void *)conf;
275
276 conf->strip_zone = NULL;
277 conf->devlist = NULL;
278 ret = create_strip_zones(mddev); 273 ret = create_strip_zones(mddev);
279 if (ret < 0) 274 if (ret < 0)
280 goto out_free_conf; 275 return ret;
281 276
282 /* calculate array device size */ 277 /* calculate array device size */
283 md_set_array_sectors(mddev, raid0_size(mddev, 0, 0)); 278 md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
@@ -299,16 +294,8 @@ static int raid0_run(mddev_t *mddev)
299 mddev->queue->backing_dev_info.ra_pages = 2* stripe; 294 mddev->queue->backing_dev_info.ra_pages = 2* stripe;
300 } 295 }
301 296
302
303 blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec); 297 blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec);
304 return 0; 298 return 0;
305
306out_free_conf:
307 kfree(conf->strip_zone);
308 kfree(conf->devlist);
309 kfree(conf);
310 mddev->private = NULL;
311 return ret;
312} 299}
313 300
314static int raid0_stop (mddev_t *mddev) 301static int raid0_stop (mddev_t *mddev)