blob: e5648b660e751099076bb45231d4a30db0d8afab [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static int create_strip_zones (mddev_t *mddev)
56{
57 int i, c, j;
NeilBrownd27a43ab2009-06-16 16:46:46 +100058 sector_t curr_zone_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 raid0_conf_t *conf = mddev_to_conf(mddev);
60 mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct strip_zone *zone;
62 int cnt;
63 char b[BDEVNAME_SIZE];
64
65 /*
66 * The number of 'same size groups'
67 */
68 conf->nr_strip_zones = 0;
69
Cheng Renquan159ec1f2009-01-09 08:31:08 +110070 list_for_each_entry(rdev1, &mddev->disks, same_set) {
Andre Noll0825b87a2009-01-09 08:31:07 +110071 printk(KERN_INFO "raid0: looking at %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 bdevname(rdev1->bdev,b));
73 c = 0;
Cheng Renquan159ec1f2009-01-09 08:31:08 +110074 list_for_each_entry(rdev2, &mddev->disks, same_set) {
Andre Noll0825b87a2009-01-09 08:31:07 +110075 printk(KERN_INFO "raid0: comparing %s(%llu)",
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 bdevname(rdev1->bdev,b),
Andre Nolldd8ac332009-03-31 14:33:13 +110077 (unsigned long long)rdev1->sectors);
Andre Noll0825b87a2009-01-09 08:31:07 +110078 printk(KERN_INFO " with %s(%llu)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 bdevname(rdev2->bdev,b),
Andre Nolldd8ac332009-03-31 14:33:13 +110080 (unsigned long long)rdev2->sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 if (rdev2 == rdev1) {
Andre Noll0825b87a2009-01-09 08:31:07 +110082 printk(KERN_INFO "raid0: END\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 break;
84 }
Andre Nolldd8ac332009-03-31 14:33:13 +110085 if (rdev2->sectors == rdev1->sectors) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /*
87 * Not unique, don't count it as a new
88 * group
89 */
Andre Noll0825b87a2009-01-09 08:31:07 +110090 printk(KERN_INFO "raid0: EQUAL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 c = 1;
92 break;
93 }
Andre Noll0825b87a2009-01-09 08:31:07 +110094 printk(KERN_INFO "raid0: NOT EQUAL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96 if (!c) {
Andre Noll0825b87a2009-01-09 08:31:07 +110097 printk(KERN_INFO "raid0: ==> UNIQUE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 conf->nr_strip_zones++;
Andre Noll0825b87a2009-01-09 08:31:07 +110099 printk(KERN_INFO "raid0: %d zones\n",
100 conf->nr_strip_zones);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102 }
Andre Noll0825b87a2009-01-09 08:31:07 +1100103 printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
NeilBrown9ffae0c2006-01-06 00:20:32 -0800105 conf->strip_zone = kzalloc(sizeof(struct strip_zone)*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 conf->nr_strip_zones, GFP_KERNEL);
107 if (!conf->strip_zone)
Andre Noll5568a602009-06-16 16:47:21 +1000108 return -ENOMEM;
NeilBrown9ffae0c2006-01-06 00:20:32 -0800109 conf->devlist = kzalloc(sizeof(mdk_rdev_t*)*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 conf->nr_strip_zones*mddev->raid_disks,
111 GFP_KERNEL);
112 if (!conf->devlist)
Andre Noll5568a602009-06-16 16:47:21 +1000113 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 /* 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
117 */
118 zone = &conf->strip_zone[0];
119 cnt = 0;
120 smallest = NULL;
121 zone->dev = conf->devlist;
Cheng Renquan159ec1f2009-01-09 08:31:08 +1100122 list_for_each_entry(rdev1, &mddev->disks, same_set) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 int j = rdev1->raid_disk;
124
125 if (j < 0 || j >= mddev->raid_disks) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100126 printk(KERN_ERR "raid0: bad disk number %d - "
127 "aborting!\n", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 goto abort;
129 }
130 if (zone->dev[j]) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100131 printk(KERN_ERR "raid0: multiple devices for %d - "
132 "aborting!\n", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 goto abort;
134 }
135 zone->dev[j] = rdev1;
136
137 blk_queue_stack_limits(mddev->queue,
138 rdev1->bdev->bd_disk->queue);
139 /* as we don't honour merge_bvec_fn, we must never risk
140 * violating it, so limit ->max_sector to one PAGE, as
141 * a one page request is never in violation.
142 */
143
144 if (rdev1->bdev->bd_disk->queue->merge_bvec_fn &&
Martin K. Petersenae03bf62009-05-22 17:17:50 -0400145 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
147
Andre Nolldd8ac332009-03-31 14:33:13 +1100148 if (!smallest || (rdev1->sectors < smallest->sectors))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 smallest = rdev1;
150 cnt++;
151 }
152 if (cnt != mddev->raid_disks) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100153 printk(KERN_ERR "raid0: too few disks (%d of %d) - "
154 "aborting!\n", cnt, mddev->raid_disks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 goto abort;
156 }
157 zone->nb_dev = cnt;
Andre Nolldd8ac332009-03-31 14:33:13 +1100158 zone->sectors = smallest->sectors * cnt;
Andre Nolldc582662009-06-16 16:18:43 +1000159 zone->zone_end = zone->sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
NeilBrownd27a43ab2009-06-16 16:46:46 +1000161 curr_zone_end = zone->sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* now do the other zones */
164 for (i = 1; i < conf->nr_strip_zones; i++)
165 {
166 zone = conf->strip_zone + i;
167 zone->dev = conf->strip_zone[i-1].dev + mddev->raid_disks;
168
Andre Noll0825b87a2009-01-09 08:31:07 +1100169 printk(KERN_INFO "raid0: zone %d\n", i);
NeilBrownd27a43ab2009-06-16 16:46:46 +1000170 zone->dev_start = smallest->sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 smallest = NULL;
172 c = 0;
173
174 for (j=0; j<cnt; j++) {
175 char b[BDEVNAME_SIZE];
176 rdev = conf->strip_zone[0].dev[j];
Andre Noll0825b87a2009-01-09 08:31:07 +1100177 printk(KERN_INFO "raid0: checking %s ...",
178 bdevname(rdev->bdev, b));
NeilBrownd27a43ab2009-06-16 16:46:46 +1000179 if (rdev->sectors <= zone->dev_start) {
Andre Noll0825b87a2009-01-09 08:31:07 +1100180 printk(KERN_INFO " nope.\n");
Andre Nolldd8ac332009-03-31 14:33:13 +1100181 continue;
182 }
183 printk(KERN_INFO " contained as device %d\n", c);
184 zone->dev[c] = rdev;
185 c++;
186 if (!smallest || rdev->sectors < smallest->sectors) {
187 smallest = rdev;
188 printk(KERN_INFO " (%llu) is smallest!.\n",
189 (unsigned long long)rdev->sectors);
190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 }
192
193 zone->nb_dev = c;
NeilBrownd27a43ab2009-06-16 16:46:46 +1000194 zone->sectors = (smallest->sectors - zone->dev_start) * c;
Andre Noll83838ed2009-01-09 08:31:07 +1100195 printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n",
196 zone->nb_dev, (unsigned long long)zone->sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
NeilBrownd27a43ab2009-06-16 16:46:46 +1000198 curr_zone_end += zone->sectors;
199 zone->zone_end = curr_zone_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Andre Noll6b8796c2009-01-09 08:31:07 +1100201 printk(KERN_INFO "raid0: current zone start: %llu\n",
NeilBrownd27a43ab2009-06-16 16:46:46 +1000202 (unsigned long long)smallest->sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 mddev->queue->unplug_fn = raid0_unplug;
NeilBrown26be34d2006-10-03 01:15:53 -0700205 mddev->queue->backing_dev_info.congested_fn = raid0_congested;
206 mddev->queue->backing_dev_info.congested_data = mddev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Andre Noll0825b87a2009-01-09 08:31:07 +1100208 printk(KERN_INFO "raid0: done.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return 0;
Andre Noll5568a602009-06-16 16:47:21 +1000210abort:
211 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
214/**
215 * raid0_mergeable_bvec -- tell bio layer if a two requests can be merged
216 * @q: request queue
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200217 * @bvm: properties of new bio
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 * @biovec: the request that could be merged to it.
219 *
220 * Return amount of bytes we can accept at this offset
221 */
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200222static int raid0_mergeable_bvec(struct request_queue *q,
223 struct bvec_merge_data *bvm,
224 struct bio_vec *biovec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
226 mddev_t *mddev = q->queuedata;
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200227 sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 int max;
229 unsigned int chunk_sectors = mddev->chunk_size >> 9;
Alasdair G Kergoncc371e62008-07-03 09:53:43 +0200230 unsigned int bio_sectors = bvm->bi_size >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
233 if (max < 0) max = 0; /* bio_add cannot handle a negative return */
234 if (max <= biovec->bv_len && bio_sectors == 0)
235 return biovec->bv_len;
236 else
237 return max;
238}
239
Dan Williams80c3a6c2009-03-17 18:10:40 -0700240static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks)
241{
242 sector_t array_sectors = 0;
243 mdk_rdev_t *rdev;
244
245 WARN_ONCE(sectors || raid_disks,
246 "%s does not support generic reshape\n", __func__);
247
248 list_for_each_entry(rdev, &mddev->disks, same_set)
249 array_sectors += rdev->sectors;
250
251 return array_sectors;
252}
253
Andre Noll8f79cfc2009-06-16 16:47:10 +1000254static int raid0_run(mddev_t *mddev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 raid0_conf_t *conf;
Andre Noll5568a602009-06-16 16:47:21 +1000257 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
NeilBrown2604b702006-01-06 00:20:36 -0800259 if (mddev->chunk_size == 0) {
260 printk(KERN_ERR "md/raid0: non-zero chunk size required.\n");
261 return -EINVAL;
262 }
263 printk(KERN_INFO "%s: setting max_sectors to %d, segment boundary to %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 mdname(mddev),
265 mddev->chunk_size >> 9,
266 (mddev->chunk_size>>1)-1);
267 blk_queue_max_sectors(mddev->queue, mddev->chunk_size >> 9);
268 blk_queue_segment_boundary(mddev->queue, (mddev->chunk_size>>1) - 1);
Neil Browne7e72bf2008-05-14 16:05:54 -0700269 mddev->queue->queue_lock = &mddev->queue->__queue_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 conf = kmalloc(sizeof (raid0_conf_t), GFP_KERNEL);
272 if (!conf)
Andre Noll5568a602009-06-16 16:47:21 +1000273 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 mddev->private = (void *)conf;
275
276 conf->strip_zone = NULL;
277 conf->devlist = NULL;
Andre Noll5568a602009-06-16 16:47:21 +1000278 ret = create_strip_zones(mddev);
279 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 goto out_free_conf;
281
282 /* calculate array device size */
Dan Williams1f403622009-03-31 14:59:03 +1100283 md_set_array_sectors(mddev, raid0_size(mddev, 0, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Andre Nollccacc7d2009-01-09 08:31:08 +1100285 printk(KERN_INFO "raid0 : md_size is %llu sectors.\n",
286 (unsigned long long)mddev->array_sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 /* calculate the max read-ahead size.
288 * For read-ahead of large files to be effective, we need to
289 * readahead at least twice a whole stripe. i.e. number of devices
290 * multiplied by chunk size times 2.
291 * If an individual device has an ra_pages greater than the
292 * chunk size, then we will not drive that device as hard as it
293 * wants. We consider this a configuration error: a larger
294 * chunksize should be used in that case.
295 */
296 {
NeilBrown2d1f3b52006-01-06 00:20:31 -0800297 int stripe = mddev->raid_disks * mddev->chunk_size / PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (mddev->queue->backing_dev_info.ra_pages < 2* stripe)
299 mddev->queue->backing_dev_info.ra_pages = 2* stripe;
300 }
301
302
303 blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec);
304 return 0;
305
306out_free_conf:
Jesper Juhl990a8ba2005-06-21 17:17:30 -0700307 kfree(conf->strip_zone);
308 kfree(conf->devlist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 kfree(conf);
310 mddev->private = NULL;
Andre Noll5568a602009-06-16 16:47:21 +1000311 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
314static int raid0_stop (mddev_t *mddev)
315{
316 raid0_conf_t *conf = mddev_to_conf(mddev);
317
318 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
Jesper Juhl990a8ba2005-06-21 17:17:30 -0700319 kfree(conf->strip_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 conf->strip_zone = NULL;
Jesper Juhl990a8ba2005-06-21 17:17:30 -0700321 kfree(conf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 mddev->private = NULL;
323
324 return 0;
325}
326
Andre Nolldc582662009-06-16 16:18:43 +1000327/* Find the zone which holds a particular offset */
328static struct strip_zone *find_zone(struct raid0_private_data *conf,
329 sector_t sector)
330{
331 int i;
332 struct strip_zone *z = conf->strip_zone;
333
334 for (i = 0; i < conf->nr_strip_zones; i++)
335 if (sector < z[i].zone_end)
336 return z + i;
337 BUG();
338}
339
Jens Axboe165125e2007-07-24 09:28:11 +0200340static int raid0_make_request (struct request_queue *q, struct bio *bio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
342 mddev_t *mddev = q->queuedata;
Andre Nolla4712002009-01-09 08:31:06 +1100343 unsigned int sect_in_chunk, chunksect_bits, chunk_sects;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 raid0_conf_t *conf = mddev_to_conf(mddev);
345 struct strip_zone *zone;
346 mdk_rdev_t *tmp_dev;
NeilBrown787f17f2007-05-23 13:58:09 -0700347 sector_t chunk;
Andre Nolle0f06862009-01-09 08:31:06 +1100348 sector_t sector, rsect;
Jens Axboea3623572005-11-01 09:26:16 +0100349 const int rw = bio_data_dir(bio);
Tejun Heoc9959052008-08-25 19:47:21 +0900350 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
NeilBrowne5dcdd82005-09-09 16:23:41 -0700352 if (unlikely(bio_barrier(bio))) {
NeilBrown6712ecf2007-09-27 12:47:43 +0200353 bio_endio(bio, -EOPNOTSUPP);
NeilBrowne5dcdd82005-09-09 16:23:41 -0700354 return 0;
355 }
356
Tejun Heo074a7ac2008-08-25 19:56:14 +0900357 cpu = part_stat_lock();
358 part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]);
359 part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw],
360 bio_sectors(bio));
361 part_stat_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 chunk_sects = mddev->chunk_size >> 9;
Andre Noll1b7fdf82009-01-09 08:31:06 +1100364 chunksect_bits = ffz(~chunk_sects);
Andre Nolle0f06862009-01-09 08:31:06 +1100365 sector = bio->bi_sector;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 if (unlikely(chunk_sects < (bio->bi_sector & (chunk_sects - 1)) + (bio->bi_size >> 9))) {
368 struct bio_pair *bp;
369 /* Sanity check -- queue functions should prevent this happening */
370 if (bio->bi_vcnt != 1 ||
371 bio->bi_idx != 0)
372 goto bad_map;
373 /* This is a one page bio that upper layers
374 * refuse to split for us, so we need to split it.
375 */
Denis ChengRq6feef532008-10-09 08:57:05 +0200376 bp = bio_split(bio, chunk_sects - (bio->bi_sector & (chunk_sects - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (raid0_make_request(q, &bp->bio1))
378 generic_make_request(&bp->bio1);
379 if (raid0_make_request(q, &bp->bio2))
380 generic_make_request(&bp->bio2);
381
382 bio_pair_release(bp);
383 return 0;
384 }
Andre Nolldc582662009-06-16 16:18:43 +1000385 zone = find_zone(conf, sector);
Andre Nolla4712002009-01-09 08:31:06 +1100386 sect_in_chunk = bio->bi_sector & (chunk_sects - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 {
Andre Nolldc582662009-06-16 16:18:43 +1000388 sector_t x = (zone->sectors + sector - zone->zone_end)
389 >> chunksect_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 sector_div(x, zone->nb_dev);
392 chunk = x;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andre Nolle0f06862009-01-09 08:31:06 +1100394 x = sector >> chunksect_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 tmp_dev = zone->dev[sector_div(x, zone->nb_dev)];
396 }
Andre Noll019c4e22009-01-09 08:31:06 +1100397 rsect = (chunk << chunksect_bits) + zone->dev_start + sect_in_chunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 bio->bi_bdev = tmp_dev->bdev;
400 bio->bi_sector = rsect + tmp_dev->data_offset;
401
402 /*
403 * Let the main block layer submit the IO and resolve recursion:
404 */
405 return 1;
406
407bad_map:
408 printk("raid0_make_request bug: can't convert block across chunks"
Andre Nolla4712002009-01-09 08:31:06 +1100409 " or bigger than %dk %llu %d\n", chunk_sects / 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
411
NeilBrown6712ecf2007-09-27 12:47:43 +0200412 bio_io_error(bio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return 0;
414}
NeilBrown8299d7f2007-10-16 23:30:53 -0700415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416static void raid0_status (struct seq_file *seq, mddev_t *mddev)
417{
418#undef MD_DEBUG
419#ifdef MD_DEBUG
420 int j, k, h;
421 char b[BDEVNAME_SIZE];
422 raid0_conf_t *conf = mddev_to_conf(mddev);
NeilBrown8299d7f2007-10-16 23:30:53 -0700423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 h = 0;
425 for (j = 0; j < conf->nr_strip_zones; j++) {
426 seq_printf(seq, " z%d", j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 seq_printf(seq, "=[");
428 for (k = 0; k < conf->strip_zone[j].nb_dev; k++)
NeilBrown8299d7f2007-10-16 23:30:53 -0700429 seq_printf(seq, "%s/", bdevname(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 conf->strip_zone[j].dev[k]->bdev,b));
431
Andre Nolldc582662009-06-16 16:18:43 +1000432 seq_printf(seq, "] ze=%d ds=%d s=%d\n",
433 conf->strip_zone[j].zone_end,
Andre Noll019c4e22009-01-09 08:31:06 +1100434 conf->strip_zone[j].dev_start,
Andre Noll83838ed2009-01-09 08:31:07 +1100435 conf->strip_zone[j].sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437#endif
438 seq_printf(seq, " %dk chunks", mddev->chunk_size/1024);
439 return;
440}
441
NeilBrown2604b702006-01-06 00:20:36 -0800442static struct mdk_personality raid0_personality=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
444 .name = "raid0",
NeilBrown2604b702006-01-06 00:20:36 -0800445 .level = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .owner = THIS_MODULE,
447 .make_request = raid0_make_request,
448 .run = raid0_run,
449 .stop = raid0_stop,
450 .status = raid0_status,
Dan Williams80c3a6c2009-03-17 18:10:40 -0700451 .size = raid0_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452};
453
454static int __init raid0_init (void)
455{
NeilBrown2604b702006-01-06 00:20:36 -0800456 return register_md_personality (&raid0_personality);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
459static void raid0_exit (void)
460{
NeilBrown2604b702006-01-06 00:20:36 -0800461 unregister_md_personality (&raid0_personality);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
464module_init(raid0_init);
465module_exit(raid0_exit);
466MODULE_LICENSE("GPL");
467MODULE_ALIAS("md-personality-2"); /* RAID0 */
NeilBrownd9d166c2006-01-06 00:20:51 -0800468MODULE_ALIAS("md-raid0");
NeilBrown2604b702006-01-06 00:20:36 -0800469MODULE_ALIAS("md-level-0");