Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | raid0.c : Multiple Devices driver for Linux | |
3 | Copyright (C) 1994-96 Marc ZYNGIER | |
4 | <zyngier@ufr-info-p7.ibp.fr> or | |
5 | <maz@gloups.fdn.fr> | |
6 | Copyright (C) 1999, 2000 Ingo Molnar, Red Hat | |
7 | ||
8 | ||
9 | RAID-0 management functions. | |
10 | ||
11 | This program is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2, or (at your option) | |
14 | any later version. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | (for example /usr/src/linux/COPYING); if not, write to the Free | |
18 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | */ | |
20 | ||
bff61975 | 21 | #include <linux/blkdev.h> |
bff61975 | 22 | #include <linux/seq_file.h> |
43b2e5d8 | 23 | #include "md.h" |
ef740c37 | 24 | #include "raid0.h" |
1da177e4 | 25 | |
165125e1 | 26 | static void raid0_unplug(struct request_queue *q) |
1da177e4 LT |
27 | { |
28 | mddev_t *mddev = q->queuedata; | |
070ec55d | 29 | raid0_conf_t *conf = mddev->private; |
b414579f | 30 | mdk_rdev_t **devlist = conf->devlist; |
1da177e4 LT |
31 | int i; |
32 | ||
33 | for (i=0; i<mddev->raid_disks; i++) { | |
165125e1 | 34 | struct request_queue *r_queue = bdev_get_queue(devlist[i]->bdev); |
1da177e4 | 35 | |
2ad8b1ef | 36 | blk_unplug(r_queue); |
1da177e4 LT |
37 | } |
38 | } | |
39 | ||
26be34dc N |
40 | static int raid0_congested(void *data, int bits) |
41 | { | |
42 | mddev_t *mddev = data; | |
070ec55d | 43 | raid0_conf_t *conf = mddev->private; |
b414579f | 44 | mdk_rdev_t **devlist = conf->devlist; |
26be34dc N |
45 | int i, ret = 0; |
46 | ||
47 | for (i = 0; i < mddev->raid_disks && !ret ; i++) { | |
165125e1 | 48 | struct request_queue *q = bdev_get_queue(devlist[i]->bdev); |
26be34dc N |
49 | |
50 | ret |= bdi_congested(&q->backing_dev_info, bits); | |
51 | } | |
52 | return ret; | |
53 | } | |
54 | ||
46994191 | 55 | /* |
56 | * inform the user of the raid configuration | |
57 | */ | |
58 | static void dump_zones(mddev_t *mddev) | |
59 | { | |
60 | int j, k, h; | |
61 | sector_t zone_size = 0; | |
62 | sector_t zone_start = 0; | |
63 | char b[BDEVNAME_SIZE]; | |
64 | raid0_conf_t *conf = mddev->private; | |
65 | printk(KERN_INFO "******* %s configuration *********\n", | |
66 | mdname(mddev)); | |
67 | h = 0; | |
68 | for (j = 0; j < conf->nr_strip_zones; j++) { | |
69 | printk(KERN_INFO "zone%d=[", j); | |
70 | for (k = 0; k < conf->strip_zone[j].nb_dev; k++) | |
71 | printk("%s/", | |
72 | bdevname(conf->devlist[j*mddev->raid_disks | |
73 | + k]->bdev, b)); | |
74 | printk("]\n"); | |
75 | ||
76 | zone_size = conf->strip_zone[j].zone_end - zone_start; | |
77 | printk(KERN_INFO " zone offset=%llukb " | |
78 | "device offset=%llukb size=%llukb\n", | |
79 | (unsigned long long)zone_start>>1, | |
80 | (unsigned long long)conf->strip_zone[j].dev_start>>1, | |
81 | (unsigned long long)zone_size>>1); | |
82 | zone_start = conf->strip_zone[j].zone_end; | |
83 | } | |
84 | printk(KERN_INFO "**********************************\n\n"); | |
85 | } | |
86 | ||
ed7b0038 | 87 | static int create_strip_zones(mddev_t *mddev) |
1da177e4 | 88 | { |
ed7b0038 | 89 | int i, c, j, err; |
49f357a2 | 90 | sector_t curr_zone_end, sectors; |
b414579f | 91 | mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev, **dev; |
1da177e4 LT |
92 | struct strip_zone *zone; |
93 | int cnt; | |
94 | char b[BDEVNAME_SIZE]; | |
ed7b0038 AN |
95 | raid0_conf_t *conf = kzalloc(sizeof(*conf), GFP_KERNEL); |
96 | ||
97 | if (!conf) | |
98 | return -ENOMEM; | |
159ec1fc | 99 | list_for_each_entry(rdev1, &mddev->disks, same_set) { |
0825b87a | 100 | printk(KERN_INFO "raid0: looking at %s\n", |
1da177e4 LT |
101 | bdevname(rdev1->bdev,b)); |
102 | c = 0; | |
13f2682b N |
103 | |
104 | /* round size to chunk_size */ | |
105 | sectors = rdev1->sectors; | |
106 | sector_div(sectors, mddev->chunk_sectors); | |
107 | rdev1->sectors = sectors * mddev->chunk_sectors; | |
108 | ||
159ec1fc | 109 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
0825b87a | 110 | printk(KERN_INFO "raid0: comparing %s(%llu)", |
1da177e4 | 111 | bdevname(rdev1->bdev,b), |
dd8ac336 | 112 | (unsigned long long)rdev1->sectors); |
0825b87a | 113 | printk(KERN_INFO " with %s(%llu)\n", |
1da177e4 | 114 | bdevname(rdev2->bdev,b), |
dd8ac336 | 115 | (unsigned long long)rdev2->sectors); |
1da177e4 | 116 | if (rdev2 == rdev1) { |
0825b87a | 117 | printk(KERN_INFO "raid0: END\n"); |
1da177e4 LT |
118 | break; |
119 | } | |
dd8ac336 | 120 | if (rdev2->sectors == rdev1->sectors) { |
1da177e4 LT |
121 | /* |
122 | * Not unique, don't count it as a new | |
123 | * group | |
124 | */ | |
0825b87a | 125 | printk(KERN_INFO "raid0: EQUAL\n"); |
1da177e4 LT |
126 | c = 1; |
127 | break; | |
128 | } | |
0825b87a | 129 | printk(KERN_INFO "raid0: NOT EQUAL\n"); |
1da177e4 LT |
130 | } |
131 | if (!c) { | |
0825b87a | 132 | printk(KERN_INFO "raid0: ==> UNIQUE\n"); |
1da177e4 | 133 | conf->nr_strip_zones++; |
0825b87a AN |
134 | printk(KERN_INFO "raid0: %d zones\n", |
135 | conf->nr_strip_zones); | |
1da177e4 LT |
136 | } |
137 | } | |
0825b87a | 138 | printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones); |
ed7b0038 | 139 | err = -ENOMEM; |
9ffae0cf | 140 | conf->strip_zone = kzalloc(sizeof(struct strip_zone)* |
1da177e4 LT |
141 | conf->nr_strip_zones, GFP_KERNEL); |
142 | if (!conf->strip_zone) | |
ed7b0038 | 143 | goto abort; |
9ffae0cf | 144 | conf->devlist = kzalloc(sizeof(mdk_rdev_t*)* |
1da177e4 LT |
145 | conf->nr_strip_zones*mddev->raid_disks, |
146 | GFP_KERNEL); | |
147 | if (!conf->devlist) | |
ed7b0038 | 148 | goto abort; |
1da177e4 | 149 | |
1da177e4 LT |
150 | /* The first zone must contain all devices, so here we check that |
151 | * there is a proper alignment of slots to devices and find them all | |
152 | */ | |
153 | zone = &conf->strip_zone[0]; | |
154 | cnt = 0; | |
155 | smallest = NULL; | |
b414579f | 156 | dev = conf->devlist; |
ed7b0038 | 157 | err = -EINVAL; |
159ec1fc | 158 | list_for_each_entry(rdev1, &mddev->disks, same_set) { |
1da177e4 LT |
159 | int j = rdev1->raid_disk; |
160 | ||
161 | if (j < 0 || j >= mddev->raid_disks) { | |
0825b87a AN |
162 | printk(KERN_ERR "raid0: bad disk number %d - " |
163 | "aborting!\n", j); | |
1da177e4 LT |
164 | goto abort; |
165 | } | |
b414579f | 166 | if (dev[j]) { |
0825b87a AN |
167 | printk(KERN_ERR "raid0: multiple devices for %d - " |
168 | "aborting!\n", j); | |
1da177e4 LT |
169 | goto abort; |
170 | } | |
b414579f | 171 | dev[j] = rdev1; |
1da177e4 LT |
172 | |
173 | blk_queue_stack_limits(mddev->queue, | |
174 | rdev1->bdev->bd_disk->queue); | |
175 | /* as we don't honour merge_bvec_fn, we must never risk | |
176 | * violating it, so limit ->max_sector to one PAGE, as | |
177 | * a one page request is never in violation. | |
178 | */ | |
179 | ||
180 | if (rdev1->bdev->bd_disk->queue->merge_bvec_fn && | |
ae03bf63 | 181 | queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9)) |
1da177e4 LT |
182 | blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); |
183 | ||
dd8ac336 | 184 | if (!smallest || (rdev1->sectors < smallest->sectors)) |
1da177e4 LT |
185 | smallest = rdev1; |
186 | cnt++; | |
187 | } | |
188 | if (cnt != mddev->raid_disks) { | |
0825b87a AN |
189 | printk(KERN_ERR "raid0: too few disks (%d of %d) - " |
190 | "aborting!\n", cnt, mddev->raid_disks); | |
1da177e4 LT |
191 | goto abort; |
192 | } | |
193 | zone->nb_dev = cnt; | |
49f357a2 | 194 | zone->zone_end = smallest->sectors * cnt; |
1da177e4 | 195 | |
49f357a2 | 196 | curr_zone_end = zone->zone_end; |
1da177e4 LT |
197 | |
198 | /* now do the other zones */ | |
199 | for (i = 1; i < conf->nr_strip_zones; i++) | |
200 | { | |
201 | zone = conf->strip_zone + i; | |
b414579f | 202 | dev = conf->devlist + i * mddev->raid_disks; |
1da177e4 | 203 | |
0825b87a | 204 | printk(KERN_INFO "raid0: zone %d\n", i); |
d27a43ab | 205 | zone->dev_start = smallest->sectors; |
1da177e4 LT |
206 | smallest = NULL; |
207 | c = 0; | |
208 | ||
209 | for (j=0; j<cnt; j++) { | |
210 | char b[BDEVNAME_SIZE]; | |
b414579f | 211 | rdev = conf->devlist[j]; |
0825b87a AN |
212 | printk(KERN_INFO "raid0: checking %s ...", |
213 | bdevname(rdev->bdev, b)); | |
d27a43ab | 214 | if (rdev->sectors <= zone->dev_start) { |
0825b87a | 215 | printk(KERN_INFO " nope.\n"); |
dd8ac336 AN |
216 | continue; |
217 | } | |
218 | printk(KERN_INFO " contained as device %d\n", c); | |
b414579f | 219 | dev[c] = rdev; |
dd8ac336 AN |
220 | c++; |
221 | if (!smallest || rdev->sectors < smallest->sectors) { | |
222 | smallest = rdev; | |
223 | printk(KERN_INFO " (%llu) is smallest!.\n", | |
224 | (unsigned long long)rdev->sectors); | |
225 | } | |
1da177e4 LT |
226 | } |
227 | ||
228 | zone->nb_dev = c; | |
49f357a2 | 229 | sectors = (smallest->sectors - zone->dev_start) * c; |
83838ed8 | 230 | printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n", |
49f357a2 | 231 | zone->nb_dev, (unsigned long long)sectors); |
1da177e4 | 232 | |
49f357a2 | 233 | curr_zone_end += sectors; |
d27a43ab | 234 | zone->zone_end = curr_zone_end; |
1da177e4 | 235 | |
6b8796cc | 236 | printk(KERN_INFO "raid0: current zone start: %llu\n", |
d27a43ab | 237 | (unsigned long long)smallest->sectors); |
1da177e4 | 238 | } |
1da177e4 | 239 | mddev->queue->unplug_fn = raid0_unplug; |
26be34dc N |
240 | mddev->queue->backing_dev_info.congested_fn = raid0_congested; |
241 | mddev->queue->backing_dev_info.congested_data = mddev; | |
1da177e4 | 242 | |
92e59b6b | 243 | /* |
244 | * now since we have the hard sector sizes, we can make sure | |
245 | * chunk size is a multiple of that sector size | |
246 | */ | |
9d8f0363 | 247 | if ((mddev->chunk_sectors << 9) % queue_logical_block_size(mddev->queue)) { |
92e59b6b | 248 | printk(KERN_ERR "%s chunk_size of %d not valid\n", |
249 | mdname(mddev), | |
9d8f0363 | 250 | mddev->chunk_sectors << 9); |
92e59b6b | 251 | goto abort; |
252 | } | |
0825b87a | 253 | printk(KERN_INFO "raid0: done.\n"); |
ed7b0038 | 254 | mddev->private = conf; |
1da177e4 | 255 | return 0; |
5568a603 | 256 | abort: |
ed7b0038 AN |
257 | kfree(conf->strip_zone); |
258 | kfree(conf->devlist); | |
259 | kfree(conf); | |
260 | mddev->private = NULL; | |
261 | return err; | |
1da177e4 LT |
262 | } |
263 | ||
264 | /** | |
265 | * raid0_mergeable_bvec -- tell bio layer if a two requests can be merged | |
266 | * @q: request queue | |
cc371e66 | 267 | * @bvm: properties of new bio |
1da177e4 LT |
268 | * @biovec: the request that could be merged to it. |
269 | * | |
270 | * Return amount of bytes we can accept at this offset | |
271 | */ | |
cc371e66 AK |
272 | static int raid0_mergeable_bvec(struct request_queue *q, |
273 | struct bvec_merge_data *bvm, | |
274 | struct bio_vec *biovec) | |
1da177e4 LT |
275 | { |
276 | mddev_t *mddev = q->queuedata; | |
cc371e66 | 277 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
1da177e4 | 278 | int max; |
9d8f0363 | 279 | unsigned int chunk_sectors = mddev->chunk_sectors; |
cc371e66 | 280 | unsigned int bio_sectors = bvm->bi_size >> 9; |
1da177e4 | 281 | |
d6e412ea | 282 | if (is_power_of_2(chunk_sectors)) |
fbb704ef | 283 | max = (chunk_sectors - ((sector & (chunk_sectors-1)) |
284 | + bio_sectors)) << 9; | |
285 | else | |
286 | max = (chunk_sectors - (sector_div(sector, chunk_sectors) | |
287 | + bio_sectors)) << 9; | |
1da177e4 LT |
288 | if (max < 0) max = 0; /* bio_add cannot handle a negative return */ |
289 | if (max <= biovec->bv_len && bio_sectors == 0) | |
290 | return biovec->bv_len; | |
291 | else | |
292 | return max; | |
293 | } | |
294 | ||
80c3a6ce DW |
295 | static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
296 | { | |
297 | sector_t array_sectors = 0; | |
298 | mdk_rdev_t *rdev; | |
299 | ||
300 | WARN_ONCE(sectors || raid_disks, | |
301 | "%s does not support generic reshape\n", __func__); | |
302 | ||
303 | list_for_each_entry(rdev, &mddev->disks, same_set) | |
304 | array_sectors += rdev->sectors; | |
305 | ||
306 | return array_sectors; | |
307 | } | |
308 | ||
8f79cfcd | 309 | static int raid0_run(mddev_t *mddev) |
1da177e4 | 310 | { |
5568a603 | 311 | int ret; |
1da177e4 | 312 | |
9d8f0363 | 313 | if (mddev->chunk_sectors == 0) { |
fbb704ef | 314 | printk(KERN_ERR "md/raid0: chunk size must be set.\n"); |
2604b703 N |
315 | return -EINVAL; |
316 | } | |
9d8f0363 | 317 | blk_queue_max_sectors(mddev->queue, mddev->chunk_sectors); |
e7e72bf6 | 318 | mddev->queue->queue_lock = &mddev->queue->__queue_lock; |
1da177e4 | 319 | |
5568a603 AN |
320 | ret = create_strip_zones(mddev); |
321 | if (ret < 0) | |
ed7b0038 | 322 | return ret; |
1da177e4 LT |
323 | |
324 | /* calculate array device size */ | |
1f403624 | 325 | md_set_array_sectors(mddev, raid0_size(mddev, 0, 0)); |
1da177e4 | 326 | |
ccacc7d2 AN |
327 | printk(KERN_INFO "raid0 : md_size is %llu sectors.\n", |
328 | (unsigned long long)mddev->array_sectors); | |
1da177e4 LT |
329 | /* calculate the max read-ahead size. |
330 | * For read-ahead of large files to be effective, we need to | |
331 | * readahead at least twice a whole stripe. i.e. number of devices | |
332 | * multiplied by chunk size times 2. | |
333 | * If an individual device has an ra_pages greater than the | |
334 | * chunk size, then we will not drive that device as hard as it | |
335 | * wants. We consider this a configuration error: a larger | |
336 | * chunksize should be used in that case. | |
337 | */ | |
338 | { | |
9d8f0363 AN |
339 | int stripe = mddev->raid_disks * |
340 | (mddev->chunk_sectors << 9) / PAGE_SIZE; | |
1da177e4 LT |
341 | if (mddev->queue->backing_dev_info.ra_pages < 2* stripe) |
342 | mddev->queue->backing_dev_info.ra_pages = 2* stripe; | |
343 | } | |
344 | ||
1da177e4 | 345 | blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec); |
46994191 | 346 | dump_zones(mddev); |
1da177e4 | 347 | return 0; |
1da177e4 LT |
348 | } |
349 | ||
fb5ab4b5 | 350 | static int raid0_stop(mddev_t *mddev) |
1da177e4 | 351 | { |
070ec55d | 352 | raid0_conf_t *conf = mddev->private; |
1da177e4 LT |
353 | |
354 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ | |
990a8baf | 355 | kfree(conf->strip_zone); |
fb5ab4b5 | 356 | kfree(conf->devlist); |
990a8baf | 357 | kfree(conf); |
1da177e4 | 358 | mddev->private = NULL; |
1da177e4 LT |
359 | return 0; |
360 | } | |
361 | ||
49f357a2 N |
362 | /* Find the zone which holds a particular offset |
363 | * Update *sectorp to be an offset in that zone | |
364 | */ | |
dc582663 | 365 | static struct strip_zone *find_zone(struct raid0_private_data *conf, |
49f357a2 | 366 | sector_t *sectorp) |
dc582663 AN |
367 | { |
368 | int i; | |
369 | struct strip_zone *z = conf->strip_zone; | |
49f357a2 | 370 | sector_t sector = *sectorp; |
dc582663 AN |
371 | |
372 | for (i = 0; i < conf->nr_strip_zones; i++) | |
49f357a2 N |
373 | if (sector < z[i].zone_end) { |
374 | if (i) | |
375 | *sectorp = sector - z[i-1].zone_end; | |
dc582663 | 376 | return z + i; |
49f357a2 | 377 | } |
dc582663 AN |
378 | BUG(); |
379 | } | |
380 | ||
fbb704ef | 381 | /* |
382 | * remaps the bio to the target device. we separate two flows. | |
383 | * power 2 flow and a general flow for the sake of perfromance | |
384 | */ | |
385 | static mdk_rdev_t *map_sector(mddev_t *mddev, struct strip_zone *zone, | |
386 | sector_t sector, sector_t *sector_offset) | |
1da177e4 | 387 | { |
fbb704ef | 388 | unsigned int sect_in_chunk; |
389 | sector_t chunk; | |
070ec55d | 390 | raid0_conf_t *conf = mddev->private; |
9d8f0363 | 391 | unsigned int chunk_sects = mddev->chunk_sectors; |
fbb704ef | 392 | |
d6e412ea | 393 | if (is_power_of_2(chunk_sects)) { |
fbb704ef | 394 | int chunksect_bits = ffz(~chunk_sects); |
395 | /* find the sector offset inside the chunk */ | |
396 | sect_in_chunk = sector & (chunk_sects - 1); | |
397 | sector >>= chunksect_bits; | |
398 | /* chunk in zone */ | |
399 | chunk = *sector_offset; | |
400 | /* quotient is the chunk in real device*/ | |
401 | sector_div(chunk, zone->nb_dev << chunksect_bits); | |
402 | } else{ | |
403 | sect_in_chunk = sector_div(sector, chunk_sects); | |
404 | chunk = *sector_offset; | |
405 | sector_div(chunk, chunk_sects * zone->nb_dev); | |
406 | } | |
407 | /* | |
408 | * position the bio over the real device | |
409 | * real sector = chunk in device + starting of zone | |
410 | * + the position in the chunk | |
411 | */ | |
412 | *sector_offset = (chunk * chunk_sects) + sect_in_chunk; | |
413 | return conf->devlist[(zone - conf->strip_zone)*mddev->raid_disks | |
414 | + sector_div(sector, zone->nb_dev)]; | |
415 | } | |
416 | ||
417 | /* | |
418 | * Is io distribute over 1 or more chunks ? | |
419 | */ | |
420 | static inline int is_io_in_chunk_boundary(mddev_t *mddev, | |
421 | unsigned int chunk_sects, struct bio *bio) | |
422 | { | |
d6e412ea | 423 | if (likely(is_power_of_2(chunk_sects))) { |
fbb704ef | 424 | return chunk_sects >= ((bio->bi_sector & (chunk_sects-1)) |
425 | + (bio->bi_size >> 9)); | |
426 | } else{ | |
427 | sector_t sector = bio->bi_sector; | |
428 | return chunk_sects >= (sector_div(sector, chunk_sects) | |
429 | + (bio->bi_size >> 9)); | |
430 | } | |
431 | } | |
432 | ||
433 | static int raid0_make_request(struct request_queue *q, struct bio *bio) | |
434 | { | |
435 | mddev_t *mddev = q->queuedata; | |
436 | unsigned int chunk_sects; | |
437 | sector_t sector_offset; | |
1da177e4 LT |
438 | struct strip_zone *zone; |
439 | mdk_rdev_t *tmp_dev; | |
a362357b | 440 | const int rw = bio_data_dir(bio); |
c9959059 | 441 | int cpu; |
1da177e4 | 442 | |
e5dcdd80 | 443 | if (unlikely(bio_barrier(bio))) { |
6712ecf8 | 444 | bio_endio(bio, -EOPNOTSUPP); |
e5dcdd80 N |
445 | return 0; |
446 | } | |
447 | ||
074a7aca TH |
448 | cpu = part_stat_lock(); |
449 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); | |
450 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], | |
451 | bio_sectors(bio)); | |
452 | part_stat_unlock(); | |
1da177e4 | 453 | |
9d8f0363 | 454 | chunk_sects = mddev->chunk_sectors; |
fbb704ef | 455 | if (unlikely(!is_io_in_chunk_boundary(mddev, chunk_sects, bio))) { |
456 | sector_t sector = bio->bi_sector; | |
1da177e4 LT |
457 | struct bio_pair *bp; |
458 | /* Sanity check -- queue functions should prevent this happening */ | |
459 | if (bio->bi_vcnt != 1 || | |
460 | bio->bi_idx != 0) | |
461 | goto bad_map; | |
462 | /* This is a one page bio that upper layers | |
463 | * refuse to split for us, so we need to split it. | |
464 | */ | |
d6e412ea | 465 | if (likely(is_power_of_2(chunk_sects))) |
fbb704ef | 466 | bp = bio_split(bio, chunk_sects - (sector & |
467 | (chunk_sects-1))); | |
468 | else | |
469 | bp = bio_split(bio, chunk_sects - | |
470 | sector_div(sector, chunk_sects)); | |
1da177e4 LT |
471 | if (raid0_make_request(q, &bp->bio1)) |
472 | generic_make_request(&bp->bio1); | |
473 | if (raid0_make_request(q, &bp->bio2)) | |
474 | generic_make_request(&bp->bio2); | |
475 | ||
476 | bio_pair_release(bp); | |
477 | return 0; | |
478 | } | |
1da177e4 | 479 | |
fbb704ef | 480 | sector_offset = bio->bi_sector; |
481 | zone = find_zone(mddev->private, §or_offset); | |
482 | tmp_dev = map_sector(mddev, zone, bio->bi_sector, | |
483 | §or_offset); | |
1da177e4 | 484 | bio->bi_bdev = tmp_dev->bdev; |
fbb704ef | 485 | bio->bi_sector = sector_offset + zone->dev_start + |
486 | tmp_dev->data_offset; | |
1da177e4 LT |
487 | /* |
488 | * Let the main block layer submit the IO and resolve recursion: | |
489 | */ | |
490 | return 1; | |
491 | ||
492 | bad_map: | |
493 | printk("raid0_make_request bug: can't convert block across chunks" | |
a4712005 | 494 | " or bigger than %dk %llu %d\n", chunk_sects / 2, |
1da177e4 LT |
495 | (unsigned long long)bio->bi_sector, bio->bi_size >> 10); |
496 | ||
6712ecf8 | 497 | bio_io_error(bio); |
1da177e4 LT |
498 | return 0; |
499 | } | |
8299d7f7 | 500 | |
1b961429 | 501 | static void raid0_status(struct seq_file *seq, mddev_t *mddev) |
1da177e4 LT |
502 | { |
503 | #undef MD_DEBUG | |
504 | #ifdef MD_DEBUG | |
505 | int j, k, h; | |
506 | char b[BDEVNAME_SIZE]; | |
070ec55d | 507 | raid0_conf_t *conf = mddev->private; |
8299d7f7 | 508 | |
1b961429 | 509 | sector_t zone_size; |
510 | sector_t zone_start = 0; | |
1da177e4 | 511 | h = 0; |
1b961429 | 512 | |
1da177e4 LT |
513 | for (j = 0; j < conf->nr_strip_zones; j++) { |
514 | seq_printf(seq, " z%d", j); | |
1da177e4 LT |
515 | seq_printf(seq, "=["); |
516 | for (k = 0; k < conf->strip_zone[j].nb_dev; k++) | |
8299d7f7 | 517 | seq_printf(seq, "%s/", bdevname( |
1b961429 | 518 | conf->devlist[j*mddev->raid_disks + k] |
519 | ->bdev, b)); | |
520 | ||
521 | zone_size = conf->strip_zone[j].zone_end - zone_start; | |
522 | seq_printf(seq, "] ze=%lld ds=%lld s=%lld\n", | |
523 | (unsigned long long)zone_start>>1, | |
524 | (unsigned long long)conf->strip_zone[j].dev_start>>1, | |
525 | (unsigned long long)zone_size>>1); | |
526 | zone_start = conf->strip_zone[j].zone_end; | |
1da177e4 LT |
527 | } |
528 | #endif | |
9d8f0363 | 529 | seq_printf(seq, " %dk chunks", mddev->chunk_sectors / 2); |
1da177e4 LT |
530 | return; |
531 | } | |
532 | ||
2604b703 | 533 | static struct mdk_personality raid0_personality= |
1da177e4 LT |
534 | { |
535 | .name = "raid0", | |
2604b703 | 536 | .level = 0, |
1da177e4 LT |
537 | .owner = THIS_MODULE, |
538 | .make_request = raid0_make_request, | |
539 | .run = raid0_run, | |
540 | .stop = raid0_stop, | |
541 | .status = raid0_status, | |
80c3a6ce | 542 | .size = raid0_size, |
1da177e4 LT |
543 | }; |
544 | ||
545 | static int __init raid0_init (void) | |
546 | { | |
2604b703 | 547 | return register_md_personality (&raid0_personality); |
1da177e4 LT |
548 | } |
549 | ||
550 | static void raid0_exit (void) | |
551 | { | |
2604b703 | 552 | unregister_md_personality (&raid0_personality); |
1da177e4 LT |
553 | } |
554 | ||
555 | module_init(raid0_init); | |
556 | module_exit(raid0_exit); | |
557 | MODULE_LICENSE("GPL"); | |
558 | MODULE_ALIAS("md-personality-2"); /* RAID0 */ | |
d9d166c2 | 559 | MODULE_ALIAS("md-raid0"); |
2604b703 | 560 | MODULE_ALIAS("md-level-0"); |