Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 21 | #include <linux/blkdev.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 22 | #include <linux/seq_file.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 23 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 24 | #include "raid0.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 26 | static void raid0_unplug(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
| 28 | mddev_t *mddev = q->queuedata; |
| 29 | raid0_conf_t *conf = mddev_to_conf(mddev); |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 30 | mdk_rdev_t **devlist = conf->devlist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | int i; |
| 32 | |
| 33 | for (i=0; i<mddev->raid_disks; i++) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 34 | struct request_queue *r_queue = bdev_get_queue(devlist[i]->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 36 | blk_unplug(r_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 40 | static int raid0_congested(void *data, int bits) |
| 41 | { |
| 42 | mddev_t *mddev = data; |
| 43 | raid0_conf_t *conf = mddev_to_conf(mddev); |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 44 | mdk_rdev_t **devlist = conf->devlist; |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 45 | int i, ret = 0; |
| 46 | |
| 47 | for (i = 0; i < mddev->raid_disks && !ret ; i++) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 48 | struct request_queue *q = bdev_get_queue(devlist[i]->bdev); |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 49 | |
| 50 | ret |= bdi_congested(&q->backing_dev_info, bits); |
| 51 | } |
| 52 | return ret; |
| 53 | } |
| 54 | |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 55 | static int create_strip_zones(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 57 | int i, c, j, err; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 58 | sector_t curr_zone_end, sectors; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 59 | mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev, **dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct strip_zone *zone; |
| 61 | int cnt; |
| 62 | char b[BDEVNAME_SIZE]; |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 63 | raid0_conf_t *conf = kzalloc(sizeof(*conf), GFP_KERNEL); |
| 64 | |
| 65 | if (!conf) |
| 66 | return -ENOMEM; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 67 | list_for_each_entry(rdev1, &mddev->disks, same_set) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 68 | printk(KERN_INFO "raid0: looking at %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | bdevname(rdev1->bdev,b)); |
| 70 | c = 0; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 71 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 72 | printk(KERN_INFO "raid0: comparing %s(%llu)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | bdevname(rdev1->bdev,b), |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 74 | (unsigned long long)rdev1->sectors); |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 75 | printk(KERN_INFO " with %s(%llu)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | bdevname(rdev2->bdev,b), |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 77 | (unsigned long long)rdev2->sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | if (rdev2 == rdev1) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 79 | printk(KERN_INFO "raid0: END\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | break; |
| 81 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 82 | if (rdev2->sectors == rdev1->sectors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Not unique, don't count it as a new |
| 85 | * group |
| 86 | */ |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 87 | printk(KERN_INFO "raid0: EQUAL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | c = 1; |
| 89 | break; |
| 90 | } |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 91 | printk(KERN_INFO "raid0: NOT EQUAL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | if (!c) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 94 | printk(KERN_INFO "raid0: ==> UNIQUE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | conf->nr_strip_zones++; |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 96 | printk(KERN_INFO "raid0: %d zones\n", |
| 97 | conf->nr_strip_zones); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 100 | printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones); |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 101 | err = -ENOMEM; |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 102 | conf->strip_zone = kzalloc(sizeof(struct strip_zone)* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | conf->nr_strip_zones, GFP_KERNEL); |
| 104 | if (!conf->strip_zone) |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 105 | goto abort; |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 106 | conf->devlist = kzalloc(sizeof(mdk_rdev_t*)* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | conf->nr_strip_zones*mddev->raid_disks, |
| 108 | GFP_KERNEL); |
| 109 | if (!conf->devlist) |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 110 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* 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; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 118 | dev = conf->devlist; |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 119 | err = -EINVAL; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 120 | list_for_each_entry(rdev1, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | int j = rdev1->raid_disk; |
| 122 | |
| 123 | if (j < 0 || j >= mddev->raid_disks) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 124 | printk(KERN_ERR "raid0: bad disk number %d - " |
| 125 | "aborting!\n", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | goto abort; |
| 127 | } |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 128 | if (dev[j]) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 129 | printk(KERN_ERR "raid0: multiple devices for %d - " |
| 130 | "aborting!\n", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | goto abort; |
| 132 | } |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 133 | dev[j] = rdev1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 143 | queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); |
| 145 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 146 | if (!smallest || (rdev1->sectors < smallest->sectors)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | smallest = rdev1; |
| 148 | cnt++; |
| 149 | } |
| 150 | if (cnt != mddev->raid_disks) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 151 | printk(KERN_ERR "raid0: too few disks (%d of %d) - " |
| 152 | "aborting!\n", cnt, mddev->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | goto abort; |
| 154 | } |
| 155 | zone->nb_dev = cnt; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 156 | zone->zone_end = smallest->sectors * cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 158 | curr_zone_end = zone->zone_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /* now do the other zones */ |
| 161 | for (i = 1; i < conf->nr_strip_zones; i++) |
| 162 | { |
| 163 | zone = conf->strip_zone + i; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 164 | dev = conf->devlist + i * mddev->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 166 | printk(KERN_INFO "raid0: zone %d\n", i); |
NeilBrown | d27a43a | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 167 | zone->dev_start = smallest->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | smallest = NULL; |
| 169 | c = 0; |
| 170 | |
| 171 | for (j=0; j<cnt; j++) { |
| 172 | char b[BDEVNAME_SIZE]; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 173 | rdev = conf->devlist[j]; |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 174 | printk(KERN_INFO "raid0: checking %s ...", |
| 175 | bdevname(rdev->bdev, b)); |
NeilBrown | d27a43a | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 176 | if (rdev->sectors <= zone->dev_start) { |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 177 | printk(KERN_INFO " nope.\n"); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 178 | continue; |
| 179 | } |
| 180 | printk(KERN_INFO " contained as device %d\n", c); |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 181 | dev[c] = rdev; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 182 | c++; |
| 183 | if (!smallest || rdev->sectors < smallest->sectors) { |
| 184 | smallest = rdev; |
| 185 | printk(KERN_INFO " (%llu) is smallest!.\n", |
| 186 | (unsigned long long)rdev->sectors); |
| 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | zone->nb_dev = c; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 191 | sectors = (smallest->sectors - zone->dev_start) * c; |
Andre Noll | 83838ed | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 192 | printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n", |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 193 | zone->nb_dev, (unsigned long long)sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 195 | curr_zone_end += sectors; |
NeilBrown | d27a43a | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 196 | zone->zone_end = curr_zone_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Andre Noll | 6b8796c | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 198 | printk(KERN_INFO "raid0: current zone start: %llu\n", |
NeilBrown | d27a43a | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 199 | (unsigned long long)smallest->sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | mddev->queue->unplug_fn = raid0_unplug; |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 202 | mddev->queue->backing_dev_info.congested_fn = raid0_congested; |
| 203 | mddev->queue->backing_dev_info.congested_data = mddev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Andre Noll | 0825b87 | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 205 | printk(KERN_INFO "raid0: done.\n"); |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 206 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | return 0; |
Andre Noll | 5568a60 | 2009-06-16 16:47:21 +1000 | [diff] [blame] | 208 | abort: |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 209 | kfree(conf->strip_zone); |
| 210 | kfree(conf->devlist); |
| 211 | kfree(conf); |
| 212 | mddev->private = NULL; |
| 213 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
| 217 | * raid0_mergeable_bvec -- tell bio layer if a two requests can be merged |
| 218 | * @q: request queue |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 219 | * @bvm: properties of new bio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | * @biovec: the request that could be merged to it. |
| 221 | * |
| 222 | * Return amount of bytes we can accept at this offset |
| 223 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 224 | static int raid0_mergeable_bvec(struct request_queue *q, |
| 225 | struct bvec_merge_data *bvm, |
| 226 | struct bio_vec *biovec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | mddev_t *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 229 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | int max; |
| 231 | unsigned int chunk_sectors = mddev->chunk_size >> 9; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 232 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 235 | if (max < 0) max = 0; /* bio_add cannot handle a negative return */ |
| 236 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 237 | return biovec->bv_len; |
| 238 | else |
| 239 | return max; |
| 240 | } |
| 241 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 242 | static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
| 243 | { |
| 244 | sector_t array_sectors = 0; |
| 245 | mdk_rdev_t *rdev; |
| 246 | |
| 247 | WARN_ONCE(sectors || raid_disks, |
| 248 | "%s does not support generic reshape\n", __func__); |
| 249 | |
| 250 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 251 | array_sectors += rdev->sectors; |
| 252 | |
| 253 | return array_sectors; |
| 254 | } |
| 255 | |
Andre Noll | 8f79cfc | 2009-06-16 16:47:10 +1000 | [diff] [blame] | 256 | static int raid0_run(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Andre Noll | 5568a60 | 2009-06-16 16:47:21 +1000 | [diff] [blame] | 258 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 260 | if (mddev->chunk_size == 0) { |
| 261 | printk(KERN_ERR "md/raid0: non-zero chunk size required.\n"); |
| 262 | return -EINVAL; |
| 263 | } |
| 264 | printk(KERN_INFO "%s: setting max_sectors to %d, segment boundary to %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | mdname(mddev), |
| 266 | mddev->chunk_size >> 9, |
| 267 | (mddev->chunk_size>>1)-1); |
| 268 | blk_queue_max_sectors(mddev->queue, mddev->chunk_size >> 9); |
| 269 | blk_queue_segment_boundary(mddev->queue, (mddev->chunk_size>>1) - 1); |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 270 | mddev->queue->queue_lock = &mddev->queue->__queue_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Andre Noll | 5568a60 | 2009-06-16 16:47:21 +1000 | [diff] [blame] | 272 | ret = create_strip_zones(mddev); |
| 273 | if (ret < 0) |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 274 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | /* calculate array device size */ |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 277 | md_set_array_sectors(mddev, raid0_size(mddev, 0, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Andre Noll | ccacc7d | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 279 | printk(KERN_INFO "raid0 : md_size is %llu sectors.\n", |
| 280 | (unsigned long long)mddev->array_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* calculate the max read-ahead size. |
| 282 | * For read-ahead of large files to be effective, we need to |
| 283 | * readahead at least twice a whole stripe. i.e. number of devices |
| 284 | * multiplied by chunk size times 2. |
| 285 | * If an individual device has an ra_pages greater than the |
| 286 | * chunk size, then we will not drive that device as hard as it |
| 287 | * wants. We consider this a configuration error: a larger |
| 288 | * chunksize should be used in that case. |
| 289 | */ |
| 290 | { |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 291 | int stripe = mddev->raid_disks * mddev->chunk_size / PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (mddev->queue->backing_dev_info.ra_pages < 2* stripe) |
| 293 | mddev->queue->backing_dev_info.ra_pages = 2* stripe; |
| 294 | } |
| 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec); |
| 297 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Andre Noll | fb5ab4b | 2009-06-16 16:48:19 +1000 | [diff] [blame] | 300 | static int raid0_stop(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
| 302 | raid0_conf_t *conf = mddev_to_conf(mddev); |
| 303 | |
| 304 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 305 | kfree(conf->strip_zone); |
Andre Noll | fb5ab4b | 2009-06-16 16:48:19 +1000 | [diff] [blame] | 306 | kfree(conf->devlist); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 307 | kfree(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | mddev->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 312 | /* Find the zone which holds a particular offset |
| 313 | * Update *sectorp to be an offset in that zone |
| 314 | */ |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 315 | static struct strip_zone *find_zone(struct raid0_private_data *conf, |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 316 | sector_t *sectorp) |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 317 | { |
| 318 | int i; |
| 319 | struct strip_zone *z = conf->strip_zone; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 320 | sector_t sector = *sectorp; |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 321 | |
| 322 | for (i = 0; i < conf->nr_strip_zones; i++) |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 323 | if (sector < z[i].zone_end) { |
| 324 | if (i) |
| 325 | *sectorp = sector - z[i-1].zone_end; |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 326 | return z + i; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 327 | } |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 328 | BUG(); |
| 329 | } |
| 330 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 331 | static int raid0_make_request (struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
| 333 | mddev_t *mddev = q->queuedata; |
Andre Noll | a471200 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 334 | unsigned int sect_in_chunk, chunksect_bits, chunk_sects; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | raid0_conf_t *conf = mddev_to_conf(mddev); |
| 336 | struct strip_zone *zone; |
| 337 | mdk_rdev_t *tmp_dev; |
NeilBrown | 787f17f | 2007-05-23 13:58:09 -0700 | [diff] [blame] | 338 | sector_t chunk; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 339 | sector_t sector, rsect, sector_offset; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 340 | const int rw = bio_data_dir(bio); |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 341 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 343 | if (unlikely(bio_barrier(bio))) { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 344 | bio_endio(bio, -EOPNOTSUPP); |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 348 | cpu = part_stat_lock(); |
| 349 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 350 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 351 | bio_sectors(bio)); |
| 352 | part_stat_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | chunk_sects = mddev->chunk_size >> 9; |
Andre Noll | 1b7fdf8 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 355 | chunksect_bits = ffz(~chunk_sects); |
Andre Noll | e0f0686 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 356 | sector = bio->bi_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
| 358 | if (unlikely(chunk_sects < (bio->bi_sector & (chunk_sects - 1)) + (bio->bi_size >> 9))) { |
| 359 | struct bio_pair *bp; |
| 360 | /* Sanity check -- queue functions should prevent this happening */ |
| 361 | if (bio->bi_vcnt != 1 || |
| 362 | bio->bi_idx != 0) |
| 363 | goto bad_map; |
| 364 | /* This is a one page bio that upper layers |
| 365 | * refuse to split for us, so we need to split it. |
| 366 | */ |
Denis ChengRq | 6feef53 | 2008-10-09 08:57:05 +0200 | [diff] [blame] | 367 | bp = bio_split(bio, chunk_sects - (bio->bi_sector & (chunk_sects - 1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | if (raid0_make_request(q, &bp->bio1)) |
| 369 | generic_make_request(&bp->bio1); |
| 370 | if (raid0_make_request(q, &bp->bio2)) |
| 371 | generic_make_request(&bp->bio2); |
| 372 | |
| 373 | bio_pair_release(bp); |
| 374 | return 0; |
| 375 | } |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 376 | sector_offset = sector; |
| 377 | zone = find_zone(conf, §or_offset); |
Andre Noll | a471200 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 378 | sect_in_chunk = bio->bi_sector & (chunk_sects - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 380 | sector_t x = sector_offset >> chunksect_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | sector_div(x, zone->nb_dev); |
| 383 | chunk = x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Andre Noll | e0f0686 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 385 | x = sector >> chunksect_bits; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame^] | 386 | tmp_dev = conf->devlist[(zone - conf->strip_zone)*mddev->raid_disks |
| 387 | + sector_div(x, zone->nb_dev)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
Andre Noll | 019c4e2 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 389 | rsect = (chunk << chunksect_bits) + zone->dev_start + sect_in_chunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | bio->bi_bdev = tmp_dev->bdev; |
| 392 | bio->bi_sector = rsect + tmp_dev->data_offset; |
| 393 | |
| 394 | /* |
| 395 | * Let the main block layer submit the IO and resolve recursion: |
| 396 | */ |
| 397 | return 1; |
| 398 | |
| 399 | bad_map: |
| 400 | printk("raid0_make_request bug: can't convert block across chunks" |
Andre Noll | a471200 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 401 | " or bigger than %dk %llu %d\n", chunk_sects / 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | (unsigned long long)bio->bi_sector, bio->bi_size >> 10); |
| 403 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 404 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | return 0; |
| 406 | } |
NeilBrown | 8299d7f | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | static void raid0_status (struct seq_file *seq, mddev_t *mddev) |
| 409 | { |
| 410 | #undef MD_DEBUG |
| 411 | #ifdef MD_DEBUG |
| 412 | int j, k, h; |
| 413 | char b[BDEVNAME_SIZE]; |
| 414 | raid0_conf_t *conf = mddev_to_conf(mddev); |
NeilBrown | 8299d7f | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | h = 0; |
| 417 | for (j = 0; j < conf->nr_strip_zones; j++) { |
| 418 | seq_printf(seq, " z%d", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | seq_printf(seq, "=["); |
| 420 | for (k = 0; k < conf->strip_zone[j].nb_dev; k++) |
NeilBrown | 8299d7f | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 421 | seq_printf(seq, "%s/", bdevname( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | conf->strip_zone[j].dev[k]->bdev,b)); |
| 423 | |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 424 | seq_printf(seq, "] ze=%d ds=%d s=%d\n", |
| 425 | conf->strip_zone[j].zone_end, |
Andre Noll | 019c4e2 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 426 | conf->strip_zone[j].dev_start, |
Andre Noll | 83838ed | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 427 | conf->strip_zone[j].sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | #endif |
| 430 | seq_printf(seq, " %dk chunks", mddev->chunk_size/1024); |
| 431 | return; |
| 432 | } |
| 433 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 434 | static struct mdk_personality raid0_personality= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
| 436 | .name = "raid0", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 437 | .level = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | .owner = THIS_MODULE, |
| 439 | .make_request = raid0_make_request, |
| 440 | .run = raid0_run, |
| 441 | .stop = raid0_stop, |
| 442 | .status = raid0_status, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 443 | .size = raid0_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | static int __init raid0_init (void) |
| 447 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 448 | return register_md_personality (&raid0_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static void raid0_exit (void) |
| 452 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 453 | unregister_md_personality (&raid0_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | module_init(raid0_init); |
| 457 | module_exit(raid0_exit); |
| 458 | MODULE_LICENSE("GPL"); |
| 459 | MODULE_ALIAS("md-personality-2"); /* RAID0 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 460 | MODULE_ALIAS("md-raid0"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 461 | MODULE_ALIAS("md-level-0"); |