Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | linear.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 | |
| 7 | Linear mode management functions. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2, or (at your option) |
| 12 | any later version. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | (for example /usr/src/linux/COPYING); if not, write to the Free |
| 16 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | */ |
| 18 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 19 | #include <linux/blkdev.h> |
| 20 | #include <linux/raid/md_u.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 21 | #include <linux/seq_file.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 22 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 23 | #include "linear.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* |
| 26 | * find which device holds a particular offset |
| 27 | */ |
| 28 | static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector) |
| 29 | { |
Sandeep K Sinha | aece3d1 | 2009-06-16 16:57:08 +1000 | [diff] [blame] | 30 | int lo, mid, hi; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 31 | linear_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Sandeep K Sinha | aece3d1 | 2009-06-16 16:57:08 +1000 | [diff] [blame] | 33 | lo = 0; |
| 34 | hi = mddev->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Sandeep K Sinha | aece3d1 | 2009-06-16 16:57:08 +1000 | [diff] [blame] | 36 | /* |
| 37 | * Binary Search |
| 38 | */ |
| 39 | |
| 40 | while (hi > lo) { |
| 41 | |
| 42 | mid = (hi + lo) / 2; |
| 43 | if (sector < conf->disks[mid].end_sector) |
| 44 | hi = mid; |
| 45 | else |
| 46 | lo = mid + 1; |
| 47 | } |
| 48 | |
| 49 | return conf->disks + lo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
NeilBrown | 15945fe | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 53 | * linear_mergeable_bvec -- tell bio layer if two requests can be merged |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * @q: request queue |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 55 | * @bvm: properties of new bio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * @biovec: the request that could be merged to it. |
| 57 | * |
| 58 | * Return amount of bytes we can take at this offset |
| 59 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 60 | static int linear_mergeable_bvec(struct request_queue *q, |
| 61 | struct bvec_merge_data *bvm, |
| 62 | struct bio_vec *biovec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
| 64 | mddev_t *mddev = q->queuedata; |
| 65 | dev_info_t *dev0; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 66 | unsigned long maxsectors, bio_sectors = bvm->bi_size >> 9; |
| 67 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | dev0 = which_dev(mddev, sector); |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 70 | maxsectors = dev0->end_sector - sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | if (maxsectors < bio_sectors) |
| 73 | maxsectors = 0; |
| 74 | else |
| 75 | maxsectors -= bio_sectors; |
| 76 | |
| 77 | if (maxsectors <= (PAGE_SIZE >> 9 ) && bio_sectors == 0) |
| 78 | return biovec->bv_len; |
| 79 | /* The bytes available at this offset could be really big, |
| 80 | * so we cap at 2^31 to avoid overflow */ |
| 81 | if (maxsectors > (1 << (31-9))) |
| 82 | return 1<<31; |
| 83 | return maxsectors << 9; |
| 84 | } |
| 85 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 86 | static void linear_unplug(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 89 | linear_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | int i; |
| 91 | |
| 92 | for (i=0; i < mddev->raid_disks; i++) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 93 | struct request_queue *r_queue = bdev_get_queue(conf->disks[i].rdev->bdev); |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 94 | blk_unplug(r_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 98 | static int linear_congested(void *data, int bits) |
| 99 | { |
| 100 | mddev_t *mddev = data; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 101 | linear_conf_t *conf = mddev->private; |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 102 | int i, ret = 0; |
| 103 | |
| 104 | for (i = 0; i < mddev->raid_disks && !ret ; i++) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 105 | struct request_queue *q = bdev_get_queue(conf->disks[i].rdev->bdev); |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 106 | ret |= bdi_congested(&q->backing_dev_info, bits); |
| 107 | } |
| 108 | return ret; |
| 109 | } |
| 110 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 111 | static sector_t linear_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
| 112 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 113 | linear_conf_t *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 114 | |
| 115 | WARN_ONCE(sectors || raid_disks, |
| 116 | "%s does not support generic reshape\n", __func__); |
| 117 | |
| 118 | return conf->array_sectors; |
| 119 | } |
| 120 | |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 121 | static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | linear_conf_t *conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | mdk_rdev_t *rdev; |
Sandeep K Sinha | 45d4582 | 2009-06-16 16:55:26 +1000 | [diff] [blame] | 125 | int i, cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 127 | conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | GFP_KERNEL); |
| 129 | if (!conf) |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 130 | return NULL; |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | cnt = 0; |
Andre Noll | d6e2215 | 2008-07-21 17:05:25 +1000 | [diff] [blame] | 133 | conf->array_sectors = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 135 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | int j = rdev->raid_disk; |
| 137 | dev_info_t *disk = conf->disks + j; |
NeilBrown | 13f2682 | 2009-06-18 08:48:55 +1000 | [diff] [blame] | 138 | sector_t sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Nikanth Karthikesan | 1386451 | 2008-06-28 08:31:19 +1000 | [diff] [blame] | 140 | if (j < 0 || j >= raid_disks || disk->rdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | printk("linear: disk numbering problem. Aborting!\n"); |
| 142 | goto out; |
| 143 | } |
| 144 | |
| 145 | disk->rdev = rdev; |
NeilBrown | 13f2682 | 2009-06-18 08:48:55 +1000 | [diff] [blame] | 146 | if (mddev->chunk_sectors) { |
| 147 | sectors = rdev->sectors; |
| 148 | sector_div(sectors, mddev->chunk_sectors); |
| 149 | rdev->sectors = sectors * mddev->chunk_sectors; |
| 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | blk_queue_stack_limits(mddev->queue, |
| 153 | rdev->bdev->bd_disk->queue); |
| 154 | /* as we don't honour merge_bvec_fn, we must never risk |
| 155 | * violating it, so limit ->max_sector to one PAGE, as |
| 156 | * a one page request is never in violation. |
| 157 | */ |
| 158 | if (rdev->bdev->bd_disk->queue->merge_bvec_fn && |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 159 | queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); |
| 161 | |
Andre Noll | dd8ac33 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 162 | conf->array_sectors += rdev->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | cnt++; |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 166 | if (cnt != raid_disks) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | printk("linear: not enough drives present. Aborting!\n"); |
| 168 | goto out; |
| 169 | } |
| 170 | |
| 171 | /* |
Sandeep K Sinha | 45d4582 | 2009-06-16 16:55:26 +1000 | [diff] [blame] | 172 | * Here we calculate the device offsets. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | */ |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 174 | conf->disks[0].end_sector = conf->disks[0].rdev->sectors; |
| 175 | |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 176 | for (i = 1; i < raid_disks; i++) |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 177 | conf->disks[i].end_sector = |
| 178 | conf->disks[i-1].end_sector + |
| 179 | conf->disks[i].rdev->sectors; |
NeilBrown | 15945fe | 2005-09-09 16:23:47 -0700 | [diff] [blame] | 180 | |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 181 | return conf; |
| 182 | |
| 183 | out: |
| 184 | kfree(conf); |
| 185 | return NULL; |
| 186 | } |
| 187 | |
| 188 | static int linear_run (mddev_t *mddev) |
| 189 | { |
| 190 | linear_conf_t *conf; |
| 191 | |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame^] | 192 | if (md_check_no_bitmap(mddev)) |
| 193 | return -EINVAL; |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 194 | mddev->queue->queue_lock = &mddev->queue->__queue_lock; |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 195 | conf = linear_conf(mddev, mddev->raid_disks); |
| 196 | |
| 197 | if (!conf) |
| 198 | return 1; |
| 199 | mddev->private = conf; |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 200 | md_set_array_sectors(mddev, linear_size(mddev, 0, 0)); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec); |
| 203 | mddev->queue->unplug_fn = linear_unplug; |
NeilBrown | 26be34d | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 204 | mddev->queue->backing_dev_info.congested_fn = linear_congested; |
| 205 | mddev->queue->backing_dev_info.congested_data = mddev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return 0; |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 209 | static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev) |
| 210 | { |
| 211 | /* Adding a drive to a linear array allows the array to grow. |
| 212 | * It is permitted if the new drive has a matching superblock |
| 213 | * already on it, with raid_disk equal to raid_disks. |
| 214 | * It is achieved by creating a new linear_private_data structure |
| 215 | * and swapping it in in-place of the current one. |
| 216 | * The current one is never freed until the array is stopped. |
| 217 | * This avoids races. |
| 218 | */ |
| 219 | linear_conf_t *newconf; |
| 220 | |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 221 | if (rdev->saved_raid_disk != mddev->raid_disks) |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 222 | return -EINVAL; |
| 223 | |
NeilBrown | a778b73 | 2007-05-23 13:58:10 -0700 | [diff] [blame] | 224 | rdev->raid_disk = rdev->saved_raid_disk; |
| 225 | |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 226 | newconf = linear_conf(mddev,mddev->raid_disks+1); |
| 227 | |
| 228 | if (!newconf) |
| 229 | return -ENOMEM; |
| 230 | |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 231 | newconf->prev = mddev->private; |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 232 | mddev->private = newconf; |
| 233 | mddev->raid_disks++; |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 234 | md_set_array_sectors(mddev, linear_size(mddev, 0, 0)); |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 235 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 236 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int linear_stop (mddev_t *mddev) |
| 240 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 241 | linear_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 244 | do { |
| 245 | linear_conf_t *t = conf->prev; |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 246 | kfree(conf); |
| 247 | conf = t; |
| 248 | } while (conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 253 | static int linear_make_request (struct request_queue *q, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 255 | const int rw = bio_data_dir(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | mddev_t *mddev = q->queuedata; |
| 257 | dev_info_t *tmp_dev; |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 258 | sector_t start_sector; |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 259 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 261 | if (unlikely(bio_barrier(bio))) { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 262 | bio_endio(bio, -EOPNOTSUPP); |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 266 | cpu = part_stat_lock(); |
| 267 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 268 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 269 | bio_sectors(bio)); |
| 270 | part_stat_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | tmp_dev = which_dev(mddev, bio->bi_sector); |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 273 | start_sector = tmp_dev->end_sector - tmp_dev->rdev->sectors; |
| 274 | |
| 275 | if (unlikely(bio->bi_sector >= (tmp_dev->end_sector) |
| 276 | || (bio->bi_sector < start_sector))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | char b[BDEVNAME_SIZE]; |
| 278 | |
Andre Noll | 6283815 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 279 | printk("linear_make_request: Sector %llu out of bounds on " |
| 280 | "dev %s: %llu sectors, offset %llu\n", |
| 281 | (unsigned long long)bio->bi_sector, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | bdevname(tmp_dev->rdev->bdev, b), |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 283 | (unsigned long long)tmp_dev->rdev->sectors, |
| 284 | (unsigned long long)start_sector); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 285 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | if (unlikely(bio->bi_sector + (bio->bi_size >> 9) > |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 289 | tmp_dev->end_sector)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* This bio crosses a device boundary, so we have to |
| 291 | * split it. |
| 292 | */ |
| 293 | struct bio_pair *bp; |
Andre Noll | 6283815 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 294 | |
Denis ChengRq | 6feef53 | 2008-10-09 08:57:05 +0200 | [diff] [blame] | 295 | bp = bio_split(bio, |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 296 | tmp_dev->end_sector - bio->bi_sector); |
Andre Noll | 6283815 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | if (linear_make_request(q, &bp->bio1)) |
| 299 | generic_make_request(&bp->bio1); |
| 300 | if (linear_make_request(q, &bp->bio2)) |
| 301 | generic_make_request(&bp->bio2); |
| 302 | bio_pair_release(bp); |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | bio->bi_bdev = tmp_dev->rdev->bdev; |
Sandeep K Sinha | 4db7cdc | 2009-06-16 16:56:13 +1000 | [diff] [blame] | 307 | bio->bi_sector = bio->bi_sector - start_sector |
Andre Noll | 6283815 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 308 | + tmp_dev->rdev->data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | return 1; |
| 311 | } |
| 312 | |
| 313 | static void linear_status (struct seq_file *seq, mddev_t *mddev) |
| 314 | { |
| 315 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 316 | seq_printf(seq, " %dk rounding", mddev->chunk_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 320 | static struct mdk_personality linear_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
| 322 | .name = "linear", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 323 | .level = LEVEL_LINEAR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | .owner = THIS_MODULE, |
| 325 | .make_request = linear_make_request, |
| 326 | .run = linear_run, |
| 327 | .stop = linear_stop, |
| 328 | .status = linear_status, |
NeilBrown | 7c7546c | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 329 | .hot_add_disk = linear_add, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 330 | .size = linear_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | static int __init linear_init (void) |
| 334 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 335 | return register_md_personality (&linear_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void linear_exit (void) |
| 339 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 340 | unregister_md_personality (&linear_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | |
| 344 | module_init(linear_init); |
| 345 | module_exit(linear_exit); |
| 346 | MODULE_LICENSE("GPL"); |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 347 | MODULE_ALIAS("md-personality-1"); /* LINEAR - deprecated*/ |
| 348 | MODULE_ALIAS("md-linear"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 349 | MODULE_ALIAS("md-level--1"); |