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" |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 25 | #include "raid5.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 27 | static void raid0_unplug(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 30 | raid0_conf_t *conf = mddev->private; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 31 | mdk_rdev_t **devlist = conf->devlist; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 32 | int raid_disks = conf->strip_zone[0].nb_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | int i; |
| 34 | |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 35 | for (i=0; i < raid_disks; i++) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 36 | struct request_queue *r_queue = bdev_get_queue(devlist[i]->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 38 | blk_unplug(r_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 42 | static int raid0_congested(void *data, int bits) |
| 43 | { |
| 44 | mddev_t *mddev = data; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 45 | raid0_conf_t *conf = mddev->private; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 46 | mdk_rdev_t **devlist = conf->devlist; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 47 | int raid_disks = conf->strip_zone[0].nb_dev; |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 48 | int i, ret = 0; |
| 49 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 50 | if (mddev_congested(mddev, bits)) |
| 51 | return 1; |
| 52 | |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 53 | for (i = 0; i < raid_disks && !ret ; i++) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 54 | struct request_queue *q = bdev_get_queue(devlist[i]->bdev); |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 55 | |
| 56 | ret |= bdi_congested(&q->backing_dev_info, bits); |
| 57 | } |
| 58 | return ret; |
| 59 | } |
| 60 | |
raz ben yehuda | 4699419 | 2009-06-16 17:00:54 +1000 | [diff] [blame] | 61 | /* |
| 62 | * inform the user of the raid configuration |
| 63 | */ |
| 64 | static void dump_zones(mddev_t *mddev) |
| 65 | { |
| 66 | int j, k, h; |
| 67 | sector_t zone_size = 0; |
| 68 | sector_t zone_start = 0; |
| 69 | char b[BDEVNAME_SIZE]; |
| 70 | raid0_conf_t *conf = mddev->private; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 71 | int raid_disks = conf->strip_zone[0].nb_dev; |
raz ben yehuda | 4699419 | 2009-06-16 17:00:54 +1000 | [diff] [blame] | 72 | printk(KERN_INFO "******* %s configuration *********\n", |
| 73 | mdname(mddev)); |
| 74 | h = 0; |
| 75 | for (j = 0; j < conf->nr_strip_zones; j++) { |
| 76 | printk(KERN_INFO "zone%d=[", j); |
| 77 | for (k = 0; k < conf->strip_zone[j].nb_dev; k++) |
| 78 | printk("%s/", |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 79 | bdevname(conf->devlist[j*raid_disks |
raz ben yehuda | 4699419 | 2009-06-16 17:00:54 +1000 | [diff] [blame] | 80 | + k]->bdev, b)); |
| 81 | printk("]\n"); |
| 82 | |
| 83 | zone_size = conf->strip_zone[j].zone_end - zone_start; |
| 84 | printk(KERN_INFO " zone offset=%llukb " |
| 85 | "device offset=%llukb size=%llukb\n", |
| 86 | (unsigned long long)zone_start>>1, |
| 87 | (unsigned long long)conf->strip_zone[j].dev_start>>1, |
| 88 | (unsigned long long)zone_size>>1); |
| 89 | zone_start = conf->strip_zone[j].zone_end; |
| 90 | } |
| 91 | printk(KERN_INFO "**********************************\n\n"); |
| 92 | } |
| 93 | |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 94 | static int create_strip_zones(mddev_t *mddev, raid0_conf_t **private_conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 96 | int i, c, err; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 97 | sector_t curr_zone_end, sectors; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 98 | mdk_rdev_t *smallest, *rdev1, *rdev2, *rdev, **dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | struct strip_zone *zone; |
| 100 | int cnt; |
| 101 | char b[BDEVNAME_SIZE]; |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 102 | raid0_conf_t *conf = kzalloc(sizeof(*conf), GFP_KERNEL); |
| 103 | |
| 104 | if (!conf) |
| 105 | return -ENOMEM; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 106 | list_for_each_entry(rdev1, &mddev->disks, same_set) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 107 | printk(KERN_INFO "raid0: looking at %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | bdevname(rdev1->bdev,b)); |
| 109 | c = 0; |
NeilBrown | 13f2682 | 2009-06-18 08:48:55 +1000 | [diff] [blame] | 110 | |
| 111 | /* round size to chunk_size */ |
| 112 | sectors = rdev1->sectors; |
| 113 | sector_div(sectors, mddev->chunk_sectors); |
| 114 | rdev1->sectors = sectors * mddev->chunk_sectors; |
| 115 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 116 | list_for_each_entry(rdev2, &mddev->disks, same_set) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 117 | printk(KERN_INFO "raid0: comparing %s(%llu)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | bdevname(rdev1->bdev,b), |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 119 | (unsigned long long)rdev1->sectors); |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 120 | printk(KERN_INFO " with %s(%llu)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | bdevname(rdev2->bdev,b), |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 122 | (unsigned long long)rdev2->sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | if (rdev2 == rdev1) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 124 | printk(KERN_INFO "raid0: END\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | break; |
| 126 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 127 | if (rdev2->sectors == rdev1->sectors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* |
| 129 | * Not unique, don't count it as a new |
| 130 | * group |
| 131 | */ |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 132 | printk(KERN_INFO "raid0: EQUAL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | c = 1; |
| 134 | break; |
| 135 | } |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 136 | printk(KERN_INFO "raid0: NOT EQUAL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | if (!c) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 139 | printk(KERN_INFO "raid0: ==> UNIQUE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | conf->nr_strip_zones++; |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 141 | printk(KERN_INFO "raid0: %d zones\n", |
| 142 | conf->nr_strip_zones); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 145 | printk(KERN_INFO "raid0: FINAL %d zones\n", conf->nr_strip_zones); |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 146 | err = -ENOMEM; |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 147 | conf->strip_zone = kzalloc(sizeof(struct strip_zone)* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | conf->nr_strip_zones, GFP_KERNEL); |
| 149 | if (!conf->strip_zone) |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 150 | goto abort; |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 151 | conf->devlist = kzalloc(sizeof(mdk_rdev_t*)* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | conf->nr_strip_zones*mddev->raid_disks, |
| 153 | GFP_KERNEL); |
| 154 | if (!conf->devlist) |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 155 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* The first zone must contain all devices, so here we check that |
| 158 | * there is a proper alignment of slots to devices and find them all |
| 159 | */ |
| 160 | zone = &conf->strip_zone[0]; |
| 161 | cnt = 0; |
| 162 | smallest = NULL; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 163 | dev = conf->devlist; |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 164 | err = -EINVAL; |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 165 | list_for_each_entry(rdev1, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | int j = rdev1->raid_disk; |
| 167 | |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 168 | if (mddev->level == 10) |
| 169 | /* taking over a raid10-n2 array */ |
| 170 | j /= 2; |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | if (j < 0 || j >= mddev->raid_disks) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 173 | printk(KERN_ERR "raid0: bad disk number %d - " |
| 174 | "aborting!\n", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | goto abort; |
| 176 | } |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 177 | if (dev[j]) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 178 | printk(KERN_ERR "raid0: multiple devices for %d - " |
| 179 | "aborting!\n", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | goto abort; |
| 181 | } |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 182 | dev[j] = rdev1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 184 | disk_stack_limits(mddev->gendisk, rdev1->bdev, |
| 185 | rdev1->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* as we don't honour merge_bvec_fn, we must never risk |
NeilBrown | 627a2d3 | 2010-03-08 16:44:38 +1100 | [diff] [blame] | 187 | * violating it, so limit ->max_segments to 1, lying within |
| 188 | * a single page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | */ |
| 190 | |
NeilBrown | 627a2d3 | 2010-03-08 16:44:38 +1100 | [diff] [blame] | 191 | if (rdev1->bdev->bd_disk->queue->merge_bvec_fn) { |
| 192 | blk_queue_max_segments(mddev->queue, 1); |
| 193 | blk_queue_segment_boundary(mddev->queue, |
| 194 | PAGE_CACHE_SIZE - 1); |
| 195 | } |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 196 | if (!smallest || (rdev1->sectors < smallest->sectors)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | smallest = rdev1; |
| 198 | cnt++; |
| 199 | } |
| 200 | if (cnt != mddev->raid_disks) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 201 | printk(KERN_ERR "raid0: too few disks (%d of %d) - " |
| 202 | "aborting!\n", cnt, mddev->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | goto abort; |
| 204 | } |
| 205 | zone->nb_dev = cnt; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 206 | zone->zone_end = smallest->sectors * cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 208 | curr_zone_end = zone->zone_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | /* now do the other zones */ |
| 211 | for (i = 1; i < conf->nr_strip_zones; i++) |
| 212 | { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 213 | int j; |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | zone = conf->strip_zone + i; |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 216 | dev = conf->devlist + i * mddev->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 218 | printk(KERN_INFO "raid0: zone %d\n", i); |
NeilBrown | d27a43ab | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 219 | zone->dev_start = smallest->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | smallest = NULL; |
| 221 | c = 0; |
| 222 | |
| 223 | for (j=0; j<cnt; j++) { |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 224 | rdev = conf->devlist[j]; |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 225 | printk(KERN_INFO "raid0: checking %s ...", |
| 226 | bdevname(rdev->bdev, b)); |
NeilBrown | d27a43ab | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 227 | if (rdev->sectors <= zone->dev_start) { |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 228 | printk(KERN_INFO " nope.\n"); |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 229 | continue; |
| 230 | } |
| 231 | printk(KERN_INFO " contained as device %d\n", c); |
NeilBrown | b414579 | 2009-06-16 16:50:52 +1000 | [diff] [blame] | 232 | dev[c] = rdev; |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 233 | c++; |
| 234 | if (!smallest || rdev->sectors < smallest->sectors) { |
| 235 | smallest = rdev; |
| 236 | printk(KERN_INFO " (%llu) is smallest!.\n", |
| 237 | (unsigned long long)rdev->sectors); |
| 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | zone->nb_dev = c; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 242 | sectors = (smallest->sectors - zone->dev_start) * c; |
Andre Noll | 83838ed | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 243 | printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n", |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 244 | zone->nb_dev, (unsigned long long)sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 246 | curr_zone_end += sectors; |
NeilBrown | d27a43ab | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 247 | zone->zone_end = curr_zone_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Andre Noll | 6b8796c | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 249 | printk(KERN_INFO "raid0: current zone start: %llu\n", |
NeilBrown | d27a43ab | 2009-06-16 16:46:46 +1000 | [diff] [blame] | 250 | (unsigned long long)smallest->sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | mddev->queue->unplug_fn = raid0_unplug; |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 253 | mddev->queue->backing_dev_info.congested_fn = raid0_congested; |
| 254 | mddev->queue->backing_dev_info.congested_data = mddev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
raz ben yehuda | 92e59b6 | 2009-06-16 17:00:57 +1000 | [diff] [blame] | 256 | /* |
| 257 | * now since we have the hard sector sizes, we can make sure |
| 258 | * chunk size is a multiple of that sector size |
| 259 | */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 260 | if ((mddev->chunk_sectors << 9) % queue_logical_block_size(mddev->queue)) { |
raz ben yehuda | 92e59b6 | 2009-06-16 17:00:57 +1000 | [diff] [blame] | 261 | printk(KERN_ERR "%s chunk_size of %d not valid\n", |
| 262 | mdname(mddev), |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 263 | mddev->chunk_sectors << 9); |
raz ben yehuda | 92e59b6 | 2009-06-16 17:00:57 +1000 | [diff] [blame] | 264 | goto abort; |
| 265 | } |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 266 | |
| 267 | blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9); |
| 268 | blk_queue_io_opt(mddev->queue, |
| 269 | (mddev->chunk_sectors << 9) * mddev->raid_disks); |
| 270 | |
Andre Noll | 0825b87a | 2009-01-09 08:31:07 +1100 | [diff] [blame] | 271 | printk(KERN_INFO "raid0: done.\n"); |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 272 | *private_conf = conf; |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return 0; |
Andre Noll | 5568a60 | 2009-06-16 16:47:21 +1000 | [diff] [blame] | 275 | abort: |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 276 | kfree(conf->strip_zone); |
| 277 | kfree(conf->devlist); |
| 278 | kfree(conf); |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 279 | *private_conf = NULL; |
Andre Noll | ed7b003 | 2009-06-16 16:47:36 +1000 | [diff] [blame] | 280 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /** |
| 284 | * raid0_mergeable_bvec -- tell bio layer if a two requests can be merged |
| 285 | * @q: request queue |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 286 | * @bvm: properties of new bio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | * @biovec: the request that could be merged to it. |
| 288 | * |
| 289 | * Return amount of bytes we can accept at this offset |
| 290 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 291 | static int raid0_mergeable_bvec(struct request_queue *q, |
| 292 | struct bvec_merge_data *bvm, |
| 293 | struct bio_vec *biovec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
| 295 | mddev_t *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 296 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 298 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 299 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
NeilBrown | d6e412e | 2009-06-18 08:47:00 +1000 | [diff] [blame] | 301 | if (is_power_of_2(chunk_sectors)) |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 302 | max = (chunk_sectors - ((sector & (chunk_sectors-1)) |
| 303 | + bio_sectors)) << 9; |
| 304 | else |
| 305 | max = (chunk_sectors - (sector_div(sector, chunk_sectors) |
| 306 | + bio_sectors)) << 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | if (max < 0) max = 0; /* bio_add cannot handle a negative return */ |
| 308 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 309 | return biovec->bv_len; |
| 310 | else |
| 311 | return max; |
| 312 | } |
| 313 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 314 | static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
| 315 | { |
| 316 | sector_t array_sectors = 0; |
| 317 | mdk_rdev_t *rdev; |
| 318 | |
| 319 | WARN_ONCE(sectors || raid_disks, |
| 320 | "%s does not support generic reshape\n", __func__); |
| 321 | |
| 322 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 323 | array_sectors += rdev->sectors; |
| 324 | |
| 325 | return array_sectors; |
| 326 | } |
| 327 | |
Andre Noll | 8f79cfc | 2009-06-16 16:47:10 +1000 | [diff] [blame] | 328 | static int raid0_run(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 330 | raid0_conf_t *conf; |
Andre Noll | 5568a60 | 2009-06-16 16:47:21 +1000 | [diff] [blame] | 331 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 333 | if (mddev->chunk_sectors == 0) { |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 334 | printk(KERN_ERR "md/raid0: chunk size must be set.\n"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 335 | return -EINVAL; |
| 336 | } |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 337 | if (md_check_no_bitmap(mddev)) |
| 338 | return -EINVAL; |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 339 | blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors); |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 340 | mddev->queue->queue_lock = &mddev->queue->__queue_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 342 | /* if private is not null, we are here after takeover */ |
| 343 | if (mddev->private == NULL) { |
| 344 | ret = create_strip_zones(mddev, &conf); |
| 345 | if (ret < 0) |
| 346 | return ret; |
| 347 | mddev->private = conf; |
| 348 | } |
| 349 | conf = mddev->private; |
| 350 | if (conf->scale_raid_disks) { |
| 351 | int i; |
| 352 | for (i=0; i < conf->strip_zone[0].nb_dev; i++) |
| 353 | conf->devlist[i]->raid_disk /= conf->scale_raid_disks; |
| 354 | /* FIXME update sysfs rd links */ |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* calculate array device size */ |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 358 | md_set_array_sectors(mddev, raid0_size(mddev, 0, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Andre Noll | ccacc7d | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 360 | printk(KERN_INFO "raid0 : md_size is %llu sectors.\n", |
| 361 | (unsigned long long)mddev->array_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | /* calculate the max read-ahead size. |
| 363 | * For read-ahead of large files to be effective, we need to |
| 364 | * readahead at least twice a whole stripe. i.e. number of devices |
| 365 | * multiplied by chunk size times 2. |
| 366 | * If an individual device has an ra_pages greater than the |
| 367 | * chunk size, then we will not drive that device as hard as it |
| 368 | * wants. We consider this a configuration error: a larger |
| 369 | * chunksize should be used in that case. |
| 370 | */ |
| 371 | { |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 372 | int stripe = mddev->raid_disks * |
| 373 | (mddev->chunk_sectors << 9) / PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | if (mddev->queue->backing_dev_info.ra_pages < 2* stripe) |
| 375 | mddev->queue->backing_dev_info.ra_pages = 2* stripe; |
| 376 | } |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec); |
raz ben yehuda | 4699419 | 2009-06-16 17:00:54 +1000 | [diff] [blame] | 379 | dump_zones(mddev); |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 380 | md_integrity_register(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Andre Noll | fb5ab4b | 2009-06-16 16:48:19 +1000 | [diff] [blame] | 384 | static int raid0_stop(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 386 | raid0_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 389 | kfree(conf->strip_zone); |
Andre Noll | fb5ab4b | 2009-06-16 16:48:19 +1000 | [diff] [blame] | 390 | kfree(conf->devlist); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 391 | kfree(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | mddev->private = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 396 | /* Find the zone which holds a particular offset |
| 397 | * Update *sectorp to be an offset in that zone |
| 398 | */ |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 399 | static struct strip_zone *find_zone(struct raid0_private_data *conf, |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 400 | sector_t *sectorp) |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 401 | { |
| 402 | int i; |
| 403 | struct strip_zone *z = conf->strip_zone; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 404 | sector_t sector = *sectorp; |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 405 | |
| 406 | for (i = 0; i < conf->nr_strip_zones; i++) |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 407 | if (sector < z[i].zone_end) { |
| 408 | if (i) |
| 409 | *sectorp = sector - z[i-1].zone_end; |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 410 | return z + i; |
NeilBrown | 49f357a2 | 2009-06-16 16:50:35 +1000 | [diff] [blame] | 411 | } |
Andre Noll | dc58266 | 2009-06-16 16:18:43 +1000 | [diff] [blame] | 412 | BUG(); |
| 413 | } |
| 414 | |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 415 | /* |
| 416 | * remaps the bio to the target device. we separate two flows. |
| 417 | * power 2 flow and a general flow for the sake of perfromance |
| 418 | */ |
| 419 | static mdk_rdev_t *map_sector(mddev_t *mddev, struct strip_zone *zone, |
| 420 | sector_t sector, sector_t *sector_offset) |
| 421 | { |
| 422 | unsigned int sect_in_chunk; |
| 423 | sector_t chunk; |
| 424 | raid0_conf_t *conf = mddev->private; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 425 | int raid_disks = conf->strip_zone[0].nb_dev; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 426 | unsigned int chunk_sects = mddev->chunk_sectors; |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 427 | |
NeilBrown | d6e412e | 2009-06-18 08:47:00 +1000 | [diff] [blame] | 428 | if (is_power_of_2(chunk_sects)) { |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 429 | int chunksect_bits = ffz(~chunk_sects); |
| 430 | /* find the sector offset inside the chunk */ |
| 431 | sect_in_chunk = sector & (chunk_sects - 1); |
| 432 | sector >>= chunksect_bits; |
| 433 | /* chunk in zone */ |
| 434 | chunk = *sector_offset; |
| 435 | /* quotient is the chunk in real device*/ |
| 436 | sector_div(chunk, zone->nb_dev << chunksect_bits); |
| 437 | } else{ |
| 438 | sect_in_chunk = sector_div(sector, chunk_sects); |
| 439 | chunk = *sector_offset; |
| 440 | sector_div(chunk, chunk_sects * zone->nb_dev); |
| 441 | } |
| 442 | /* |
| 443 | * position the bio over the real device |
| 444 | * real sector = chunk in device + starting of zone |
| 445 | * + the position in the chunk |
| 446 | */ |
| 447 | *sector_offset = (chunk * chunk_sects) + sect_in_chunk; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 448 | return conf->devlist[(zone - conf->strip_zone)*raid_disks |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 449 | + sector_div(sector, zone->nb_dev)]; |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * Is io distribute over 1 or more chunks ? |
| 454 | */ |
| 455 | static inline int is_io_in_chunk_boundary(mddev_t *mddev, |
| 456 | unsigned int chunk_sects, struct bio *bio) |
| 457 | { |
NeilBrown | d6e412e | 2009-06-18 08:47:00 +1000 | [diff] [blame] | 458 | if (likely(is_power_of_2(chunk_sects))) { |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 459 | return chunk_sects >= ((bio->bi_sector & (chunk_sects-1)) |
| 460 | + (bio->bi_size >> 9)); |
| 461 | } else{ |
| 462 | sector_t sector = bio->bi_sector; |
| 463 | return chunk_sects >= (sector_div(sector, chunk_sects) |
| 464 | + (bio->bi_size >> 9)); |
| 465 | } |
| 466 | } |
| 467 | |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame^] | 468 | static int raid0_make_request(mddev_t *mddev, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 470 | unsigned int chunk_sects; |
| 471 | sector_t sector_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | struct strip_zone *zone; |
| 473 | mdk_rdev_t *tmp_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Jens Axboe | 1f98a13 | 2009-09-11 14:32:04 +0200 | [diff] [blame] | 475 | if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 476 | md_barrier_request(mddev, bio); |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 477 | return 0; |
| 478 | } |
| 479 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 480 | chunk_sects = mddev->chunk_sectors; |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 481 | if (unlikely(!is_io_in_chunk_boundary(mddev, chunk_sects, bio))) { |
| 482 | sector_t sector = bio->bi_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | struct bio_pair *bp; |
| 484 | /* Sanity check -- queue functions should prevent this happening */ |
| 485 | if (bio->bi_vcnt != 1 || |
| 486 | bio->bi_idx != 0) |
| 487 | goto bad_map; |
| 488 | /* This is a one page bio that upper layers |
| 489 | * refuse to split for us, so we need to split it. |
| 490 | */ |
NeilBrown | d6e412e | 2009-06-18 08:47:00 +1000 | [diff] [blame] | 491 | if (likely(is_power_of_2(chunk_sects))) |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 492 | bp = bio_split(bio, chunk_sects - (sector & |
| 493 | (chunk_sects-1))); |
| 494 | else |
| 495 | bp = bio_split(bio, chunk_sects - |
| 496 | sector_div(sector, chunk_sects)); |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame^] | 497 | if (raid0_make_request(mddev, &bp->bio1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | generic_make_request(&bp->bio1); |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame^] | 499 | if (raid0_make_request(mddev, &bp->bio2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | generic_make_request(&bp->bio2); |
| 501 | |
| 502 | bio_pair_release(bp); |
| 503 | return 0; |
| 504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 506 | sector_offset = bio->bi_sector; |
| 507 | zone = find_zone(mddev->private, §or_offset); |
| 508 | tmp_dev = map_sector(mddev, zone, bio->bi_sector, |
| 509 | §or_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | bio->bi_bdev = tmp_dev->bdev; |
raz ben yehuda | fbb704e | 2009-06-16 17:02:05 +1000 | [diff] [blame] | 511 | bio->bi_sector = sector_offset + zone->dev_start + |
| 512 | tmp_dev->data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* |
| 514 | * Let the main block layer submit the IO and resolve recursion: |
| 515 | */ |
| 516 | return 1; |
| 517 | |
| 518 | bad_map: |
| 519 | printk("raid0_make_request bug: can't convert block across chunks" |
Andre Noll | a471200 | 2009-01-09 08:31:06 +1100 | [diff] [blame] | 520 | " or bigger than %dk %llu %d\n", chunk_sects / 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | (unsigned long long)bio->bi_sector, bio->bi_size >> 10); |
| 522 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 523 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | return 0; |
| 525 | } |
NeilBrown | 8299d7f | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 526 | |
raz ben yehuda | 1b96142 | 2009-06-16 16:57:40 +1000 | [diff] [blame] | 527 | static void raid0_status(struct seq_file *seq, mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | #undef MD_DEBUG |
| 530 | #ifdef MD_DEBUG |
| 531 | int j, k, h; |
| 532 | char b[BDEVNAME_SIZE]; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 533 | raid0_conf_t *conf = mddev->private; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 534 | int raid_disks = conf->strip_zone[0].nb_dev; |
NeilBrown | 8299d7f | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 535 | |
raz ben yehuda | 1b96142 | 2009-06-16 16:57:40 +1000 | [diff] [blame] | 536 | sector_t zone_size; |
| 537 | sector_t zone_start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | h = 0; |
raz ben yehuda | 1b96142 | 2009-06-16 16:57:40 +1000 | [diff] [blame] | 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | for (j = 0; j < conf->nr_strip_zones; j++) { |
| 541 | seq_printf(seq, " z%d", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | seq_printf(seq, "=["); |
| 543 | for (k = 0; k < conf->strip_zone[j].nb_dev; k++) |
NeilBrown | 8299d7f | 2007-10-16 23:30:53 -0700 | [diff] [blame] | 544 | seq_printf(seq, "%s/", bdevname( |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 545 | conf->devlist[j*raid_disks + k] |
raz ben yehuda | 1b96142 | 2009-06-16 16:57:40 +1000 | [diff] [blame] | 546 | ->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
raz ben yehuda | 1b96142 | 2009-06-16 16:57:40 +1000 | [diff] [blame] | 548 | zone_size = conf->strip_zone[j].zone_end - zone_start; |
| 549 | seq_printf(seq, "] ze=%lld ds=%lld s=%lld\n", |
| 550 | (unsigned long long)zone_start>>1, |
| 551 | (unsigned long long)conf->strip_zone[j].dev_start>>1, |
| 552 | (unsigned long long)zone_size>>1); |
| 553 | zone_start = conf->strip_zone[j].zone_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | #endif |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 556 | seq_printf(seq, " %dk chunks", mddev->chunk_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | return; |
| 558 | } |
| 559 | |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 560 | static void *raid0_takeover_raid5(mddev_t *mddev) |
| 561 | { |
| 562 | mdk_rdev_t *rdev; |
| 563 | raid0_conf_t *priv_conf; |
| 564 | |
| 565 | if (mddev->degraded != 1) { |
| 566 | printk(KERN_ERR "md: raid5 must be degraded! Degraded disks: %d\n", |
| 567 | mddev->degraded); |
| 568 | return ERR_PTR(-EINVAL); |
| 569 | } |
| 570 | |
| 571 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 572 | /* check slot number for a disk */ |
| 573 | if (rdev->raid_disk == mddev->raid_disks-1) { |
| 574 | printk(KERN_ERR "md: raid5 must have missing parity disk!\n"); |
| 575 | return ERR_PTR(-EINVAL); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /* Set new parameters */ |
| 580 | mddev->new_level = 0; |
| 581 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 582 | mddev->raid_disks--; |
| 583 | mddev->delta_disks = -1; |
| 584 | /* make sure it will be not marked as dirty */ |
| 585 | mddev->recovery_cp = MaxSector; |
| 586 | |
| 587 | create_strip_zones(mddev, &priv_conf); |
| 588 | return priv_conf; |
| 589 | } |
| 590 | |
| 591 | static void *raid0_takeover_raid10(mddev_t *mddev) |
| 592 | { |
| 593 | raid0_conf_t *priv_conf; |
| 594 | |
| 595 | /* Check layout: |
| 596 | * - far_copies must be 1 |
| 597 | * - near_copies must be 2 |
| 598 | * - disks number must be even |
| 599 | * - all mirrors must be already degraded |
| 600 | */ |
| 601 | if (mddev->layout != ((1 << 8) + 2)) { |
| 602 | printk(KERN_ERR "md: Raid0 cannot takover layout: %x\n", |
| 603 | mddev->layout); |
| 604 | return ERR_PTR(-EINVAL); |
| 605 | } |
| 606 | if (mddev->raid_disks & 1) { |
| 607 | printk(KERN_ERR "md: Raid0 cannot takover Raid10 with odd disk number.\n"); |
| 608 | return ERR_PTR(-EINVAL); |
| 609 | } |
| 610 | if (mddev->degraded != (mddev->raid_disks>>1)) { |
| 611 | printk(KERN_ERR "md: All mirrors must be already degraded!\n"); |
| 612 | return ERR_PTR(-EINVAL); |
| 613 | } |
| 614 | |
| 615 | /* Set new parameters */ |
| 616 | mddev->new_level = 0; |
| 617 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 618 | mddev->delta_disks = - mddev->raid_disks / 2; |
| 619 | mddev->raid_disks += mddev->delta_disks; |
| 620 | mddev->degraded = 0; |
| 621 | /* make sure it will be not marked as dirty */ |
| 622 | mddev->recovery_cp = MaxSector; |
| 623 | |
| 624 | create_strip_zones(mddev, &priv_conf); |
| 625 | priv_conf->scale_raid_disks = 2; |
| 626 | return priv_conf; |
| 627 | } |
| 628 | |
| 629 | static void *raid0_takeover(mddev_t *mddev) |
| 630 | { |
| 631 | /* raid0 can take over: |
| 632 | * raid5 - providing it is Raid4 layout and one disk is faulty |
| 633 | * raid10 - assuming we have all necessary active disks |
| 634 | */ |
| 635 | if (mddev->level == 5) { |
| 636 | if (mddev->layout == ALGORITHM_PARITY_N) |
| 637 | return raid0_takeover_raid5(mddev); |
| 638 | |
| 639 | printk(KERN_ERR "md: Raid can only takeover Raid5 with layout: %d\n", |
| 640 | ALGORITHM_PARITY_N); |
| 641 | } |
| 642 | |
| 643 | if (mddev->level == 10) |
| 644 | return raid0_takeover_raid10(mddev); |
| 645 | |
| 646 | return ERR_PTR(-EINVAL); |
| 647 | } |
| 648 | |
| 649 | static void raid0_quiesce(mddev_t *mddev, int state) |
| 650 | { |
| 651 | } |
| 652 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 653 | static struct mdk_personality raid0_personality= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | { |
| 655 | .name = "raid0", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 656 | .level = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | .owner = THIS_MODULE, |
| 658 | .make_request = raid0_make_request, |
| 659 | .run = raid0_run, |
| 660 | .stop = raid0_stop, |
| 661 | .status = raid0_status, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 662 | .size = raid0_size, |
Trela, Maciej | 9af204c | 2010-03-08 16:02:44 +1100 | [diff] [blame] | 663 | .takeover = raid0_takeover, |
| 664 | .quiesce = raid0_quiesce, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | static int __init raid0_init (void) |
| 668 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 669 | return register_md_personality (&raid0_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static void raid0_exit (void) |
| 673 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 674 | unregister_md_personality (&raid0_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | module_init(raid0_init); |
| 678 | module_exit(raid0_exit); |
| 679 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 680 | MODULE_DESCRIPTION("RAID0 (striping) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | MODULE_ALIAS("md-personality-2"); /* RAID0 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 682 | MODULE_ALIAS("md-raid0"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 683 | MODULE_ALIAS("md-level-0"); |