blob: 99cee51734e55d0dd5425db56b05dfa26d507297 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
NeilBrownbff61972009-03-31 14:33:13 +110021#include <linux/blkdev.h>
NeilBrownbff61972009-03-31 14:33:13 +110022#include <linux/seq_file.h>
NeilBrown43b2e5d2009-03-31 14:33:13 +110023#include "md.h"
Christoph Hellwigef740c32009-03-31 14:27:03 +110024#include "raid0.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Jens Axboe165125e2007-07-24 09:28:11 +020026static void raid0_unplug(struct request_queue *q)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
28 mddev_t *mddev = q->queuedata;
29 raid0_conf_t *conf = mddev_to_conf(mddev);
30 mdk_rdev_t **devlist = conf->strip_zone[0].dev;
31 int i;
32
33 for (i=0; i<mddev->raid_disks; i++) {
Jens Axboe165125e2007-07-24 09:28:11 +020034 struct request_queue *r_queue = bdev_get_queue(devlist[i]->bdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Alan D. Brunelle2ad8b1e2007-11-07 14:26:56 -050036 blk_unplug(r_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 }
38}
39
NeilBrown26be34d2006-10-03 01:15:53 -070040static int raid0_congested(void *data, int bits)
41{
42 mddev_t *mddev = data;
43 raid0_conf_t *conf = mddev_to_conf(mddev);
44 mdk_rdev_t **devlist = conf->strip_zone[0].dev;
45 int i, ret = 0;
46
47 for (i = 0; i < mddev->raid_disks && !ret ; i++) {
Jens Axboe165125e2007-07-24 09:28:11 +020048 struct request_queue *q = bdev_get_queue(devlist[i]->bdev);
NeilBrown26be34d2006-10-03 01:15:53 -070049
50 ret |= bdi_congested(&q->backing_dev_info, bits);
51 }
52 return ret;
53}
54
Andre Nolled7b0032009-06-16 16:47:36 +100055static int create_strip_zones(mddev_t *mddev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Andre Nolled7b0032009-06-16 16:47:36 +100057 int i, c, j, err;
NeilBrownd27a43ab2009-06-16 16:46:46 +100058 sector_t curr_zone_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct strip_zone *zone;
61 int cnt;
62 char b[BDEVNAME_SIZE];
Andre Nolled7b0032009-06-16 16:47:36 +100063 raid0_conf_t *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
64
65 if (!conf)
66 return -ENOMEM;
Cheng Renquan159ec1f2009-01-09 08:31:08 +110067 list_for_each_entry(rdev1, &mddev->disks, same_set) {
Andre Noll0825b87a2009-01-09 08:31:07 +110068 printk(KERN_INFO "raid0: looking at %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 bdevname(rdev1->bdev,b));
70 c = 0;
Cheng Renquan159ec1f2009-01-09 08:31:08 +110071 list_for_each_entry(rdev2, &mddev->disks, same_set) {
Andre Noll0825b87a2009-01-09 08:31:07 +110072 printk(KERN_INFO "raid0: comparing %s(%llu)",
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 bdevname(rdev1->bdev,b),
Andre Nolldd8ac332009-03-31 14:33:13 +110074 (unsigned long long)rdev1->sectors);
Andre Noll0825b87a2009-01-09 08:31:07 +110075 printk(KERN_INFO " with %s(%llu)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 bdevname(rdev2->bdev,b),
Andre Nolldd8ac332009-03-31 14:33:13 +110077 (unsigned long long)rdev2->sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (rdev2 == rdev1) {
Andre Noll0825b87a2009-01-09 08:31:07 +110079 printk(KERN_INFO "raid0: END\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 break;
81 }
Andre Nolldd8ac332009-03-31 14:33:13 +110082 if (rdev2->sectors == rdev1->sectors) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 /*
84 * Not unique, don't count it as a new
85 * group
86 */
Andre Noll0825b87a2009-01-09 08:31:07 +110087 printk(KERN_INFO "raid0: EQUAL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 c = 1;
89 break;
90 }
Andre Noll0825b87a2009-01-09 08:31:07 +110091 printk(KERN_INFO "raid0: NOT EQUAL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
93 if (!c) {
Andre Noll0825b87a2009-01-09 08:31:07 +110094 printk(KERN_INFO "raid0: ==> UNIQUE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 conf->nr_strip_zones++;
Andre Noll0825b87a2009-01-09 08:31:07 +110096 printk(KERN_INFO "raid0: %d zones\n",
97 conf->nr_strip_zones);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 }
99 }
Andre Noll0825b87a2009-01-09 08:31:07 +1100100 printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones);
Andre Nolled7b0032009-06-16 16:47:36 +1000101 err = -ENOMEM;
NeilBrown9ffae0c2006-01-06 00:20:32 -0800102 conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 conf->nr_strip_zones, GFP_KERNEL);
104 if (!conf->strip_zone)
Andre Nolled7b0032009-06-16 16:47:36 +1000105 goto abort;
NeilBrown9ffae0c2006-01-06 00:20:32 -0800106 conf->devlist = kzalloc(sizeof(mdk_rdev_t*)*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 conf->nr_strip_zones*mddev->raid_disks,
108 GFP_KERNEL);
109 if (!conf->devlist)
Andre Nolled7b0032009-06-16 16:47:36 +1000110 goto abort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /* The first zone must contain all devices, so here we check that
113 * there is a proper alignment of slots to devices and find them all
114 */
115 zone = &conf->strip_zone[0];
116 cnt = 0;
117 smallest = NULL;
118 zone->dev = conf->devlist;
Andre Nolled7b0032009-06-16 16:47:36 +1000119 err = -EINVAL;
Cheng Renquan159ec1f2009-01-09 08:31:08 +1100120 list_for_each_entry(rdev1, &mddev->disks, same_set) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 int j = rdev1->raid_disk;
122
123 if (j < 0 || j >= mddev->raid_disks) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100124 printk(KERN_ERR "raid0: bad disk number %d - "
125 "aborting!\n", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 goto abort;
127 }
128 if (zone->dev[j]) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100129 printk(KERN_ERR "raid0: multiple devices for %d - "
130 "aborting!\n", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 goto abort;
132 }
133 zone->dev[j] = rdev1;
134
135 blk_queue_stack_limits(mddev->queue,
136 rdev1->bdev->bd_disk->queue);
137 /* as we don't honour merge_bvec_fn, we must never risk
138 * violating it, so limit ->max_sector to one PAGE, as
139 * a one page request is never in violation.
140 */
141
142 if (rdev1->bdev->bd_disk->queue->merge_bvec_fn &&
Martin K. Petersenae03bf62009-05-22 17:17:50 -0400143 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
145
Andre Nolldd8ac332009-03-31 14:33:13 +1100146 if (!smallest || (rdev1->sectors < smallest->sectors))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 smallest = rdev1;
148 cnt++;
149 }
150 if (cnt != mddev->raid_disks) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100151 printk(KERN_ERR "raid0: too few disks (%d of %d) - "
152 "aborting!\n", cnt, mddev->raid_disks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 goto abort;
154 }
155 zone->nb_dev = cnt;
Andre Nolldd8ac332009-03-31 14:33:13 +1100156 zone->sectors = smallest->sectors * cnt;
Andre Nolldc582662009-06-16 16:18:43 +1000157 zone->zone_end = zone->sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
NeilBrownd27a43ab2009-06-16 16:46:46 +1000159 curr_zone_end = zone->sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 /* now do the other zones */
162 for (i = 1; i < conf->nr_strip_zones; i++)
163 {
164 zone = conf->strip_zone + i;
165 zone->dev = conf->strip_zone[i-1].dev + mddev->raid_disks;
166
Andre Noll0825b87a2009-01-09 08:31:07 +1100167 printk(KERN_INFO "raid0: zone %d\n", i);
NeilBrownd27a43ab2009-06-16 16:46:46 +1000168 zone->dev_start = smallest->sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 smallest = NULL;
170 c = 0;
171
172 for (j=0; j<cnt; j++) {
173 char b[BDEVNAME_SIZE];
174 rdev = conf->strip_zone[0].dev[j];
Andre Noll0825b87a2009-01-09 08:31:07 +1100175 printk(KERN_INFO "raid0: checking %s ...",
176 bdevname(rdev->bdev, b));
NeilBrownd27a43ab2009-06-16 16:46:46 +1000177 if (rdev->sectors <= zone->dev_start) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100178 printk(KERN_INFO " nope.\n");
Andre Nolldd8ac332009-03-31 14:33:13 +1100179 continue;
180 }
181 printk(KERN_INFO " contained as device %d\n", c);
182 zone->dev[c] = rdev;
183 c++;
184 if (!smallest || rdev->sectors < smallest->sectors) {
185 smallest = rdev;
186 printk(KERN_INFO " (%llu) is smallest!.\n",
187 (unsigned long long)rdev->sectors);
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190
191 zone->nb_dev = c;
NeilBrownd27a43ab2009-06-16 16:46:46 +1000192 zone->sectors = (smallest->sectors - zone->dev_start) * c;
Andre Noll83838ed2009-01-09 08:31:07 +1100193 printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n",
194 zone->nb_dev, (unsigned long long)zone->sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
NeilBrownd27a43ab2009-06-16 16:46:46 +1000196 curr_zone_end += zone->sectors;
197 zone->zone_end = curr_zone_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Andre Noll6b8796c2009-01-09 08:31:07 +1100199 printk(KERN_INFO "raid0: current zone start: %llu\n",
NeilBrownd27a43ab2009-06-16 16:46:46 +1000200 (unsigned long long)smallest->sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 mddev->queue->unplug_fn = raid0_unplug;
NeilBrown26be34d2006-10-03 01:15:53 -0700203 mddev->queue->backing_dev_info.congested_fn = raid0_congested;
204 mddev->queue->backing_dev_info.congested_data = mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Andre Noll0825b87a2009-01-09 08:31:07 +1100206 printk(KERN_INFO "raid0: done.\n");
Andre Nolled7b0032009-06-16 16:47:36 +1000207 mddev->private = conf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return 0;
Andre Noll5568a602009-06-16 16:47:21 +1000209abort:
Andre Nolled7b0032009-06-16 16:47:36 +1000210 kfree(conf->strip_zone);
211 kfree(conf->devlist);
212 kfree(conf);
213 mddev->private = NULL;
214 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
217/**
218 * raid0_mergeable_bvec -- tell bio layer if a two requests can be merged
219 * @q: request queue
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200220 * @bvm: properties of new bio
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 * @biovec: the request that could be merged to it.
222 *
223 * Return amount of bytes we can accept at this offset
224 */
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200225static int raid0_mergeable_bvec(struct request_queue *q,
226 struct bvec_merge_data *bvm,
227 struct bio_vec *biovec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 mddev_t *mddev = q->queuedata;
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200230 sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 int max;
232 unsigned int chunk_sectors = mddev->chunk_size >> 9;
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200233 unsigned int bio_sectors = bvm->bi_size >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
236 if (max < 0) max = 0; /* bio_add cannot handle a negative return */
237 if (max <= biovec->bv_len && bio_sectors == 0)
238 return biovec->bv_len;
239 else
240 return max;
241}
242
Dan Williams80c3a6c2009-03-17 18:10:40 -0700243static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks)
244{
245 sector_t array_sectors = 0;
246 mdk_rdev_t *rdev;
247
248 WARN_ONCE(sectors || raid_disks,
249 "%s does not support generic reshape\n", __func__);
250
251 list_for_each_entry(rdev, &mddev->disks, same_set)
252 array_sectors += rdev->sectors;
253
254 return array_sectors;
255}
256
Andre Noll8f79cfc2009-06-16 16:47:10 +1000257static int raid0_run(mddev_t *mddev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Andre Noll5568a602009-06-16 16:47:21 +1000259 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
NeilBrown2604b702006-01-06 00:20:36 -0800261 if (mddev->chunk_size == 0) {
262 printk(KERN_ERR "md/raid0: non-zero chunk size required.\n");
263 return -EINVAL;
264 }
265 printk(KERN_INFO "%s: setting max_sectors to %d, segment boundary to %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 mdname(mddev),
267 mddev->chunk_size >> 9,
268 (mddev->chunk_size>>1)-1);
269 blk_queue_max_sectors(mddev->queue, mddev->chunk_size >> 9);
270 blk_queue_segment_boundary(mddev->queue, (mddev->chunk_size>>1) - 1);
Neil Browne7e72bf2008-05-14 16:05:54 -0700271 mddev->queue->queue_lock = &mddev->queue->__queue_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Andre Noll5568a602009-06-16 16:47:21 +1000273 ret = create_strip_zones(mddev);
274 if (ret < 0)
Andre Nolled7b0032009-06-16 16:47:36 +1000275 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 /* calculate array device size */
Dan Williams1f403622009-03-31 14:59:03 +1100278 md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Andre Nollccacc7d2009-01-09 08:31:08 +1100280 printk(KERN_INFO "raid0 : md_size is %llu sectors.\n",
281 (unsigned long long)mddev->array_sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* calculate the max read-ahead size.
283 * For read-ahead of large files to be effective, we need to
284 * readahead at least twice a whole stripe. i.e. number of devices
285 * multiplied by chunk size times 2.
286 * If an individual device has an ra_pages greater than the
287 * chunk size, then we will not drive that device as hard as it
288 * wants. We consider this a configuration error: a larger
289 * chunksize should be used in that case.
290 */
291 {
NeilBrown2d1f3b52006-01-06 00:20:31 -0800292 int stripe = mddev->raid_disks * mddev->chunk_size / PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
294 mddev->queue->backing_dev_info.ra_pages = 2* stripe;
295 }
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec);
298 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
301static int raid0_stop (mddev_t *mddev)
302{
303 raid0_conf_t *conf = mddev_to_conf(mddev);
304
305 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
Jesper Juhl990a8ba2005-06-21 17:17:30 -0700306 kfree(conf->strip_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 conf->strip_zone = NULL;
Jesper Juhl990a8ba2005-06-21 17:17:30 -0700308 kfree(conf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 mddev->private = NULL;
310
311 return 0;
312}
313
Andre Nolldc582662009-06-16 16:18:43 +1000314/* Find the zone which holds a particular offset */
315static struct strip_zone *find_zone(struct raid0_private_data *conf,
316 sector_t sector)
317{
318 int i;
319 struct strip_zone *z = conf->strip_zone;
320
321 for (i = 0; i < conf->nr_strip_zones; i++)
322 if (sector < z[i].zone_end)
323 return z + i;
324 BUG();
325}
326
Jens Axboe165125e2007-07-24 09:28:11 +0200327static int raid0_make_request (struct request_queue *q, struct bio *bio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
329 mddev_t *mddev = q->queuedata;
Andre Nolla4712002009-01-09 08:31:06 +1100330 unsigned int sect_in_chunk, chunksect_bits, chunk_sects;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 raid0_conf_t *conf = mddev_to_conf(mddev);
332 struct strip_zone *zone;
333 mdk_rdev_t *tmp_dev;
NeilBrown787f17f2007-05-23 13:58:09 -0700334 sector_t chunk;
Andre Nolle0f06862009-01-09 08:31:06 +1100335 sector_t sector, rsect;
Jens Axboea3623572005-11-01 09:26:16 +0100336 const int rw = bio_data_dir(bio);
Tejun Heoc9959052008-08-25 19:47:21 +0900337 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
NeilBrowne5dcdd82005-09-09 16:23:41 -0700339 if (unlikely(bio_barrier(bio))) {
NeilBrown6712ecf2007-09-27 12:47:43 +0200340 bio_endio(bio, -EOPNOTSUPP);
NeilBrowne5dcdd82005-09-09 16:23:41 -0700341 return 0;
342 }
343
Tejun Heo074a7ac2008-08-25 19:56:14 +0900344 cpu = part_stat_lock();
345 part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]);
346 part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw],
347 bio_sectors(bio));
348 part_stat_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 chunk_sects = mddev->chunk_size >> 9;
Andre Noll1b7fdf82009-01-09 08:31:06 +1100351 chunksect_bits = ffz(~chunk_sects);
Andre Nolle0f06862009-01-09 08:31:06 +1100352 sector = bio->bi_sector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (unlikely(chunk_sects < (bio->bi_sector & (chunk_sects - 1)) + (bio->bi_size >> 9))) {
355 struct bio_pair *bp;
356 /* Sanity check -- queue functions should prevent this happening */
357 if (bio->bi_vcnt != 1 ||
358 bio->bi_idx != 0)
359 goto bad_map;
360 /* This is a one page bio that upper layers
361 * refuse to split for us, so we need to split it.
362 */
Denis ChengRq6feef532008-10-09 08:57:05 +0200363 bp = bio_split(bio, chunk_sects - (bio->bi_sector & (chunk_sects - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (raid0_make_request(q, &bp->bio1))
365 generic_make_request(&bp->bio1);
366 if (raid0_make_request(q, &bp->bio2))
367 generic_make_request(&bp->bio2);
368
369 bio_pair_release(bp);
370 return 0;
371 }
Andre Nolldc582662009-06-16 16:18:43 +1000372 zone = find_zone(conf, sector);
Andre Nolla4712002009-01-09 08:31:06 +1100373 sect_in_chunk = bio->bi_sector & (chunk_sects - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 {
Andre Nolldc582662009-06-16 16:18:43 +1000375 sector_t x = (zone->sectors + sector - zone->zone_end)
376 >> chunksect_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 sector_div(x, zone->nb_dev);
379 chunk = x;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Andre Nolle0f06862009-01-09 08:31:06 +1100381 x = sector >> chunksect_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 tmp_dev = zone->dev[sector_div(x, zone->nb_dev)];
383 }
Andre Noll019c4e22009-01-09 08:31:06 +1100384 rsect = (chunk << chunksect_bits) + zone->dev_start + sect_in_chunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 bio->bi_bdev = tmp_dev->bdev;
387 bio->bi_sector = rsect + tmp_dev->data_offset;
388
389 /*
390 * Let the main block layer submit the IO and resolve recursion:
391 */
392 return 1;
393
394bad_map:
395 printk("raid0_make_request bug: can't convert block across chunks"
Andre Nolla4712002009-01-09 08:31:06 +1100396 " or bigger than %dk %llu %d\n", chunk_sects / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
398
NeilBrown6712ecf2007-09-27 12:47:43 +0200399 bio_io_error(bio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return 0;
401}
NeilBrown8299d7f2007-10-16 23:30:53 -0700402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403static void raid0_status (struct seq_file *seq, mddev_t *mddev)
404{
405#undef MD_DEBUG
406#ifdef MD_DEBUG
407 int j, k, h;
408 char b[BDEVNAME_SIZE];
409 raid0_conf_t *conf = mddev_to_conf(mddev);
NeilBrown8299d7f2007-10-16 23:30:53 -0700410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 h = 0;
412 for (j = 0; j < conf->nr_strip_zones; j++) {
413 seq_printf(seq, " z%d", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 seq_printf(seq, "=[");
415 for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
NeilBrown8299d7f2007-10-16 23:30:53 -0700416 seq_printf(seq, "%s/", bdevname(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 conf->strip_zone[j].dev[k]->bdev,b));
418
Andre Nolldc582662009-06-16 16:18:43 +1000419 seq_printf(seq, "] ze=%d ds=%d s=%d\n",
420 conf->strip_zone[j].zone_end,
Andre Noll019c4e22009-01-09 08:31:06 +1100421 conf->strip_zone[j].dev_start,
Andre Noll83838ed2009-01-09 08:31:07 +1100422 conf->strip_zone[j].sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424#endif
425 seq_printf(seq, " %dk chunks", mddev->chunk_size/1024);
426 return;
427}
428
NeilBrown2604b702006-01-06 00:20:36 -0800429static struct mdk_personality raid0_personality=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 .name = "raid0",
NeilBrown2604b702006-01-06 00:20:36 -0800432 .level = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 .owner = THIS_MODULE,
434 .make_request = raid0_make_request,
435 .run = raid0_run,
436 .stop = raid0_stop,
437 .status = raid0_status,
Dan Williams80c3a6c2009-03-17 18:10:40 -0700438 .size = raid0_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439};
440
441static int __init raid0_init (void)
442{
NeilBrown2604b702006-01-06 00:20:36 -0800443 return register_md_personality (&raid0_personality);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
446static void raid0_exit (void)
447{
NeilBrown2604b702006-01-06 00:20:36 -0800448 unregister_md_personality (&raid0_personality);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449}
450
451module_init(raid0_init);
452module_exit(raid0_exit);
453MODULE_LICENSE("GPL");
454MODULE_ALIAS("md-personality-2"); /* RAID0 */
NeilBrownd9d166c2006-01-06 00:20:51 -0800455MODULE_ALIAS("md-raid0");
NeilBrown2604b702006-01-06 00:20:36 -0800456MODULE_ALIAS("md-level-0");