Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * raid10.c : Multiple Devices driver for Linux |
| 3 | * |
| 4 | * Copyright (C) 2000-2004 Neil Brown |
| 5 | * |
| 6 | * RAID-10 support for md. |
| 7 | * |
| 8 | * Base on code in raid1.c. See raid1.c for futher copyright information. |
| 9 | * |
| 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 | |
Stephen Rothwell | 2557072 | 2008-10-15 09:09:21 +1100 | [diff] [blame] | 21 | #include <linux/delay.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 24 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 25 | #include "raid10.h" |
| 26 | #include "bitmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * RAID10 provides a combination of RAID0 and RAID1 functionality. |
| 30 | * The layout of data is defined by |
| 31 | * chunk_size |
| 32 | * raid_disks |
| 33 | * near_copies (stored in low byte of layout) |
| 34 | * far_copies (stored in second byte of layout) |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 35 | * far_offset (stored in bit 16 of layout ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * |
| 37 | * The data to be stored is divided into chunks using chunksize. |
| 38 | * Each device is divided into far_copies sections. |
| 39 | * In each section, chunks are laid out in a style similar to raid0, but |
| 40 | * near_copies copies of each chunk is stored (each on a different drive). |
| 41 | * The starting device for each section is offset near_copies from the starting |
| 42 | * device of the previous section. |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 43 | * Thus they are (near_copies*far_copies) of each chunk, and each is on a different |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * drive. |
| 45 | * near_copies and far_copies must be at least one, and their product is at most |
| 46 | * raid_disks. |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 47 | * |
| 48 | * If far_offset is true, then the far_copies are handled a bit differently. |
| 49 | * The copies are still in different stripes, but instead of be very far apart |
| 50 | * on disk, there are adjacent stripes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | */ |
| 52 | |
| 53 | /* |
| 54 | * Number of guaranteed r10bios in case of extreme VM load: |
| 55 | */ |
| 56 | #define NR_RAID10_BIOS 256 |
| 57 | |
| 58 | static void unplug_slaves(mddev_t *mddev); |
| 59 | |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 60 | static void allow_barrier(conf_t *conf); |
| 61 | static void lower_barrier(conf_t *conf); |
| 62 | |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 63 | static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | conf_t *conf = data; |
| 66 | r10bio_t *r10_bio; |
| 67 | int size = offsetof(struct r10bio_s, devs[conf->copies]); |
| 68 | |
| 69 | /* allocate a r10bio with room for raid_disks entries in the bios array */ |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 70 | r10_bio = kzalloc(size, gfp_flags); |
NeilBrown | ed9bfdf | 2009-10-16 15:55:44 +1100 | [diff] [blame] | 71 | if (!r10_bio && conf->mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | unplug_slaves(conf->mddev); |
| 73 | |
| 74 | return r10_bio; |
| 75 | } |
| 76 | |
| 77 | static void r10bio_pool_free(void *r10_bio, void *data) |
| 78 | { |
| 79 | kfree(r10_bio); |
| 80 | } |
| 81 | |
NeilBrown | 0310fa2 | 2008-08-05 15:54:14 +1000 | [diff] [blame] | 82 | /* Maximum size of each resync request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #define RESYNC_BLOCK_SIZE (64*1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE) |
NeilBrown | 0310fa2 | 2008-08-05 15:54:14 +1000 | [diff] [blame] | 85 | /* amount of memory to reserve for resync requests */ |
| 86 | #define RESYNC_WINDOW (1024*1024) |
| 87 | /* maximum number of concurrent requests, memory permitting */ |
| 88 | #define RESYNC_DEPTH (32*1024*1024/RESYNC_BLOCK_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * When performing a resync, we need to read and compare, so |
| 92 | * we need as many pages are there are copies. |
| 93 | * When performing a recovery, we need 2 bios, one for read, |
| 94 | * one for write (we recover only one drive per r10buf) |
| 95 | * |
| 96 | */ |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 97 | static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | conf_t *conf = data; |
| 100 | struct page *page; |
| 101 | r10bio_t *r10_bio; |
| 102 | struct bio *bio; |
| 103 | int i, j; |
| 104 | int nalloc; |
| 105 | |
| 106 | r10_bio = r10bio_pool_alloc(gfp_flags, conf); |
| 107 | if (!r10_bio) { |
| 108 | unplug_slaves(conf->mddev); |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery)) |
| 113 | nalloc = conf->copies; /* resync */ |
| 114 | else |
| 115 | nalloc = 2; /* recovery */ |
| 116 | |
| 117 | /* |
| 118 | * Allocate bios. |
| 119 | */ |
| 120 | for (j = nalloc ; j-- ; ) { |
| 121 | bio = bio_alloc(gfp_flags, RESYNC_PAGES); |
| 122 | if (!bio) |
| 123 | goto out_free_bio; |
| 124 | r10_bio->devs[j].bio = bio; |
| 125 | } |
| 126 | /* |
| 127 | * Allocate RESYNC_PAGES data pages and attach them |
| 128 | * where needed. |
| 129 | */ |
| 130 | for (j = 0 ; j < nalloc; j++) { |
| 131 | bio = r10_bio->devs[j].bio; |
| 132 | for (i = 0; i < RESYNC_PAGES; i++) { |
| 133 | page = alloc_page(gfp_flags); |
| 134 | if (unlikely(!page)) |
| 135 | goto out_free_pages; |
| 136 | |
| 137 | bio->bi_io_vec[i].bv_page = page; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return r10_bio; |
| 142 | |
| 143 | out_free_pages: |
| 144 | for ( ; i > 0 ; i--) |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 145 | safe_put_page(bio->bi_io_vec[i-1].bv_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | while (j--) |
| 147 | for (i = 0; i < RESYNC_PAGES ; i++) |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 148 | safe_put_page(r10_bio->devs[j].bio->bi_io_vec[i].bv_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | j = -1; |
| 150 | out_free_bio: |
| 151 | while ( ++j < nalloc ) |
| 152 | bio_put(r10_bio->devs[j].bio); |
| 153 | r10bio_pool_free(r10_bio, conf); |
| 154 | return NULL; |
| 155 | } |
| 156 | |
| 157 | static void r10buf_pool_free(void *__r10_bio, void *data) |
| 158 | { |
| 159 | int i; |
| 160 | conf_t *conf = data; |
| 161 | r10bio_t *r10bio = __r10_bio; |
| 162 | int j; |
| 163 | |
| 164 | for (j=0; j < conf->copies; j++) { |
| 165 | struct bio *bio = r10bio->devs[j].bio; |
| 166 | if (bio) { |
| 167 | for (i = 0; i < RESYNC_PAGES; i++) { |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 168 | safe_put_page(bio->bi_io_vec[i].bv_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | bio->bi_io_vec[i].bv_page = NULL; |
| 170 | } |
| 171 | bio_put(bio); |
| 172 | } |
| 173 | } |
| 174 | r10bio_pool_free(r10bio, conf); |
| 175 | } |
| 176 | |
| 177 | static void put_all_bios(conf_t *conf, r10bio_t *r10_bio) |
| 178 | { |
| 179 | int i; |
| 180 | |
| 181 | for (i = 0; i < conf->copies; i++) { |
| 182 | struct bio **bio = & r10_bio->devs[i].bio; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 183 | if (*bio && *bio != IO_BLOCKED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | bio_put(*bio); |
| 185 | *bio = NULL; |
| 186 | } |
| 187 | } |
| 188 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 189 | static void free_r10bio(r10bio_t *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 191 | conf_t *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * Wake up any possible resync thread that waits for the device |
| 195 | * to go idle. |
| 196 | */ |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 197 | allow_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | put_all_bios(conf, r10_bio); |
| 200 | mempool_free(r10_bio, conf->r10bio_pool); |
| 201 | } |
| 202 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 203 | static void put_buf(r10bio_t *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 205 | conf_t *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | mempool_free(r10_bio, conf->r10buf_pool); |
| 208 | |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 209 | lower_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static void reschedule_retry(r10bio_t *r10_bio) |
| 213 | { |
| 214 | unsigned long flags; |
| 215 | mddev_t *mddev = r10_bio->mddev; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 216 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | spin_lock_irqsave(&conf->device_lock, flags); |
| 219 | list_add(&r10_bio->retry_list, &conf->retry_list); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 220 | conf->nr_queued ++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 222 | |
Arthur Jones | 388667b | 2008-07-25 12:03:38 -0700 | [diff] [blame] | 223 | /* wake up frozen array... */ |
| 224 | wake_up(&conf->wait_barrier); |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | md_wakeup_thread(mddev->thread); |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * raid_end_bio_io() is called when we have finished servicing a mirrored |
| 231 | * operation and are ready to return a success/failure code to the buffer |
| 232 | * cache layer. |
| 233 | */ |
| 234 | static void raid_end_bio_io(r10bio_t *r10_bio) |
| 235 | { |
| 236 | struct bio *bio = r10_bio->master_bio; |
| 237 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 238 | bio_endio(bio, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | test_bit(R10BIO_Uptodate, &r10_bio->state) ? 0 : -EIO); |
| 240 | free_r10bio(r10_bio); |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Update disk head position estimator based on IRQ completion info. |
| 245 | */ |
| 246 | static inline void update_head_pos(int slot, r10bio_t *r10_bio) |
| 247 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 248 | conf_t *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | conf->mirrors[r10_bio->devs[slot].devnum].head_position = |
| 251 | r10_bio->devs[slot].addr + (r10_bio->sectors); |
| 252 | } |
| 253 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 254 | static void raid10_end_read_request(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 257 | r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); |
| 258 | int slot, dev; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 259 | conf_t *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | slot = r10_bio->read_slot; |
| 263 | dev = r10_bio->devs[slot].devnum; |
| 264 | /* |
| 265 | * this branch is our 'one mirror IO has finished' event handler: |
| 266 | */ |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 267 | update_head_pos(slot, r10_bio); |
| 268 | |
| 269 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* |
| 271 | * Set R10BIO_Uptodate in our master bio, so that |
| 272 | * we will return a good error code to the higher |
| 273 | * levels even if IO on some other mirrored buffer fails. |
| 274 | * |
| 275 | * The 'master' represents the composite IO operation to |
| 276 | * user-side. So if something waits for IO, then it will |
| 277 | * wait for the 'master' bio. |
| 278 | */ |
| 279 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | raid_end_bio_io(r10_bio); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 281 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | /* |
| 283 | * oops, read error: |
| 284 | */ |
| 285 | char b[BDEVNAME_SIZE]; |
| 286 | if (printk_ratelimit()) |
| 287 | printk(KERN_ERR "raid10: %s: rescheduling sector %llu\n", |
| 288 | bdevname(conf->mirrors[dev].rdev->bdev,b), (unsigned long long)r10_bio->sector); |
| 289 | reschedule_retry(r10_bio); |
| 290 | } |
| 291 | |
| 292 | rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 295 | static void raid10_end_write_request(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 298 | r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); |
| 299 | int slot, dev; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 300 | conf_t *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | for (slot = 0; slot < conf->copies; slot++) |
| 303 | if (r10_bio->devs[slot].bio == bio) |
| 304 | break; |
| 305 | dev = r10_bio->devs[slot].devnum; |
| 306 | |
| 307 | /* |
| 308 | * this branch is our 'one mirror IO has finished' event handler: |
| 309 | */ |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 310 | if (!uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | md_error(r10_bio->mddev, conf->mirrors[dev].rdev); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 312 | /* an I/O failed, we can't clear the bitmap */ |
| 313 | set_bit(R10BIO_Degraded, &r10_bio->state); |
| 314 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* |
| 316 | * Set R10BIO_Uptodate in our master bio, so that |
| 317 | * we will return a good error code for to the higher |
| 318 | * levels even if IO on some other mirrored buffer fails. |
| 319 | * |
| 320 | * The 'master' represents the composite IO operation to |
| 321 | * user-side. So if something waits for IO, then it will |
| 322 | * wait for the 'master' bio. |
| 323 | */ |
| 324 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
| 325 | |
| 326 | update_head_pos(slot, r10_bio); |
| 327 | |
| 328 | /* |
| 329 | * |
| 330 | * Let's see if all mirrored write operations have finished |
| 331 | * already. |
| 332 | */ |
| 333 | if (atomic_dec_and_test(&r10_bio->remaining)) { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 334 | /* clear the bitmap if all writes complete successfully */ |
| 335 | bitmap_endwrite(r10_bio->mddev->bitmap, r10_bio->sector, |
| 336 | r10_bio->sectors, |
| 337 | !test_bit(R10BIO_Degraded, &r10_bio->state), |
| 338 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | md_write_end(r10_bio->mddev); |
| 340 | raid_end_bio_io(r10_bio); |
| 341 | } |
| 342 | |
| 343 | rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | |
| 347 | /* |
| 348 | * RAID10 layout manager |
| 349 | * Aswell as the chunksize and raid_disks count, there are two |
| 350 | * parameters: near_copies and far_copies. |
| 351 | * near_copies * far_copies must be <= raid_disks. |
| 352 | * Normally one of these will be 1. |
| 353 | * If both are 1, we get raid0. |
| 354 | * If near_copies == raid_disks, we get raid1. |
| 355 | * |
| 356 | * Chunks are layed out in raid0 style with near_copies copies of the |
| 357 | * first chunk, followed by near_copies copies of the next chunk and |
| 358 | * so on. |
| 359 | * If far_copies > 1, then after 1/far_copies of the array has been assigned |
| 360 | * as described above, we start again with a device offset of near_copies. |
| 361 | * So we effectively have another copy of the whole array further down all |
| 362 | * the drives, but with blocks on different drives. |
| 363 | * With this layout, and block is never stored twice on the one device. |
| 364 | * |
| 365 | * raid10_find_phys finds the sector offset of a given virtual sector |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 366 | * on each device that it is on. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * |
| 368 | * raid10_find_virt does the reverse mapping, from a device and a |
| 369 | * sector offset to a virtual address |
| 370 | */ |
| 371 | |
| 372 | static void raid10_find_phys(conf_t *conf, r10bio_t *r10bio) |
| 373 | { |
| 374 | int n,f; |
| 375 | sector_t sector; |
| 376 | sector_t chunk; |
| 377 | sector_t stripe; |
| 378 | int dev; |
| 379 | |
| 380 | int slot = 0; |
| 381 | |
| 382 | /* now calculate first sector/dev */ |
| 383 | chunk = r10bio->sector >> conf->chunk_shift; |
| 384 | sector = r10bio->sector & conf->chunk_mask; |
| 385 | |
| 386 | chunk *= conf->near_copies; |
| 387 | stripe = chunk; |
| 388 | dev = sector_div(stripe, conf->raid_disks); |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 389 | if (conf->far_offset) |
| 390 | stripe *= conf->far_copies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | sector += stripe << conf->chunk_shift; |
| 393 | |
| 394 | /* and calculate all the others */ |
| 395 | for (n=0; n < conf->near_copies; n++) { |
| 396 | int d = dev; |
| 397 | sector_t s = sector; |
| 398 | r10bio->devs[slot].addr = sector; |
| 399 | r10bio->devs[slot].devnum = d; |
| 400 | slot++; |
| 401 | |
| 402 | for (f = 1; f < conf->far_copies; f++) { |
| 403 | d += conf->near_copies; |
| 404 | if (d >= conf->raid_disks) |
| 405 | d -= conf->raid_disks; |
| 406 | s += conf->stride; |
| 407 | r10bio->devs[slot].devnum = d; |
| 408 | r10bio->devs[slot].addr = s; |
| 409 | slot++; |
| 410 | } |
| 411 | dev++; |
| 412 | if (dev >= conf->raid_disks) { |
| 413 | dev = 0; |
| 414 | sector += (conf->chunk_mask + 1); |
| 415 | } |
| 416 | } |
| 417 | BUG_ON(slot != conf->copies); |
| 418 | } |
| 419 | |
| 420 | static sector_t raid10_find_virt(conf_t *conf, sector_t sector, int dev) |
| 421 | { |
| 422 | sector_t offset, chunk, vchunk; |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | offset = sector & conf->chunk_mask; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 425 | if (conf->far_offset) { |
| 426 | int fc; |
| 427 | chunk = sector >> conf->chunk_shift; |
| 428 | fc = sector_div(chunk, conf->far_copies); |
| 429 | dev -= fc * conf->near_copies; |
| 430 | if (dev < 0) |
| 431 | dev += conf->raid_disks; |
| 432 | } else { |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 433 | while (sector >= conf->stride) { |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 434 | sector -= conf->stride; |
| 435 | if (dev < conf->near_copies) |
| 436 | dev += conf->raid_disks - conf->near_copies; |
| 437 | else |
| 438 | dev -= conf->near_copies; |
| 439 | } |
| 440 | chunk = sector >> conf->chunk_shift; |
| 441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | vchunk = chunk * conf->raid_disks + dev; |
| 443 | sector_div(vchunk, conf->near_copies); |
| 444 | return (vchunk << conf->chunk_shift) + offset; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * raid10_mergeable_bvec -- tell bio layer if a two requests can be merged |
| 449 | * @q: request queue |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 450 | * @bvm: properties of new bio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | * @biovec: the request that could be merged to it. |
| 452 | * |
| 453 | * Return amount of bytes we can accept at this offset |
| 454 | * If near_copies == raid_disk, there are no striping issues, |
| 455 | * but in that case, the function isn't called at all. |
| 456 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 457 | static int raid10_mergeable_bvec(struct request_queue *q, |
| 458 | struct bvec_merge_data *bvm, |
| 459 | struct bio_vec *biovec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
| 461 | mddev_t *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 462 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 464 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 465 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 468 | if (max < 0) max = 0; /* bio_add cannot handle a negative return */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 469 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 470 | return biovec->bv_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | else |
| 472 | return max; |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * This routine returns the disk from which the requested read should |
| 477 | * be done. There is a per-array 'next expected sequential IO' sector |
| 478 | * number - if this matches on the next IO then we use the last disk. |
| 479 | * There is also a per-disk 'last know head position' sector that is |
| 480 | * maintained from IRQ contexts, both the normal and the resync IO |
| 481 | * completion handlers update this position correctly. If there is no |
| 482 | * perfect sequential match then we pick the disk whose head is closest. |
| 483 | * |
| 484 | * If there are 2 mirrors in the same 2 devices, performance degrades |
| 485 | * because position is mirror, not device based. |
| 486 | * |
| 487 | * The rdev for the device selected will have nr_pending incremented. |
| 488 | */ |
| 489 | |
| 490 | /* |
| 491 | * FIXME: possibly should rethink readbalancing and do it differently |
| 492 | * depending on near_copies / far_copies geometry. |
| 493 | */ |
| 494 | static int read_balance(conf_t *conf, r10bio_t *r10_bio) |
| 495 | { |
| 496 | const unsigned long this_sector = r10_bio->sector; |
| 497 | int disk, slot, nslot; |
| 498 | const int sectors = r10_bio->sectors; |
| 499 | sector_t new_distance, current_distance; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 500 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | raid10_find_phys(conf, r10_bio); |
| 503 | rcu_read_lock(); |
| 504 | /* |
| 505 | * Check if we can balance. We can balance on the whole |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 506 | * device if no resync is going on (recovery is ok), or below |
| 507 | * the resync window. We take the first readable disk when |
| 508 | * above the resync window. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | */ |
| 510 | if (conf->mddev->recovery_cp < MaxSector |
| 511 | && (this_sector + sectors >= conf->next_resync)) { |
| 512 | /* make sure that disk is operational */ |
| 513 | slot = 0; |
| 514 | disk = r10_bio->devs[slot].devnum; |
| 515 | |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 516 | while ((rdev = rcu_dereference(conf->mirrors[disk].rdev)) == NULL || |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 517 | r10_bio->devs[slot].bio == IO_BLOCKED || |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 518 | !test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | slot++; |
| 520 | if (slot == conf->copies) { |
| 521 | slot = 0; |
| 522 | disk = -1; |
| 523 | break; |
| 524 | } |
| 525 | disk = r10_bio->devs[slot].devnum; |
| 526 | } |
| 527 | goto rb_out; |
| 528 | } |
| 529 | |
| 530 | |
| 531 | /* make sure the disk is operational */ |
| 532 | slot = 0; |
| 533 | disk = r10_bio->devs[slot].devnum; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 534 | while ((rdev=rcu_dereference(conf->mirrors[disk].rdev)) == NULL || |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 535 | r10_bio->devs[slot].bio == IO_BLOCKED || |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 536 | !test_bit(In_sync, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | slot ++; |
| 538 | if (slot == conf->copies) { |
| 539 | disk = -1; |
| 540 | goto rb_out; |
| 541 | } |
| 542 | disk = r10_bio->devs[slot].devnum; |
| 543 | } |
| 544 | |
| 545 | |
NeilBrown | 3ec67ac | 2005-09-09 16:23:40 -0700 | [diff] [blame] | 546 | current_distance = abs(r10_bio->devs[slot].addr - |
| 547 | conf->mirrors[disk].head_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Keld Simonsen | 8ed3a19 | 2008-03-04 14:29:34 -0800 | [diff] [blame] | 549 | /* Find the disk whose head is closest, |
| 550 | * or - for far > 1 - find the closest to partition beginning */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | for (nslot = slot; nslot < conf->copies; nslot++) { |
| 553 | int ndisk = r10_bio->devs[nslot].devnum; |
| 554 | |
| 555 | |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 556 | if ((rdev=rcu_dereference(conf->mirrors[ndisk].rdev)) == NULL || |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 557 | r10_bio->devs[nslot].bio == IO_BLOCKED || |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 558 | !test_bit(In_sync, &rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | continue; |
| 560 | |
NeilBrown | 22dfdf5 | 2005-11-28 13:44:09 -0800 | [diff] [blame] | 561 | /* This optimisation is debatable, and completely destroys |
| 562 | * sequential read speed for 'far copies' arrays. So only |
| 563 | * keep it for 'near' arrays, and review those later. |
| 564 | */ |
| 565 | if (conf->near_copies > 1 && !atomic_read(&rdev->nr_pending)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | disk = ndisk; |
| 567 | slot = nslot; |
| 568 | break; |
| 569 | } |
Keld Simonsen | 8ed3a19 | 2008-03-04 14:29:34 -0800 | [diff] [blame] | 570 | |
| 571 | /* for far > 1 always use the lowest address */ |
| 572 | if (conf->far_copies > 1) |
| 573 | new_distance = r10_bio->devs[nslot].addr; |
| 574 | else |
| 575 | new_distance = abs(r10_bio->devs[nslot].addr - |
| 576 | conf->mirrors[ndisk].head_position); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | if (new_distance < current_distance) { |
| 578 | current_distance = new_distance; |
| 579 | disk = ndisk; |
| 580 | slot = nslot; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | rb_out: |
| 585 | r10_bio->read_slot = slot; |
| 586 | /* conf->next_seq_sect = this_sector + sectors;*/ |
| 587 | |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 588 | if (disk >= 0 && (rdev=rcu_dereference(conf->mirrors[disk].rdev))!= NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | atomic_inc(&conf->mirrors[disk].rdev->nr_pending); |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 590 | else |
| 591 | disk = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | rcu_read_unlock(); |
| 593 | |
| 594 | return disk; |
| 595 | } |
| 596 | |
| 597 | static void unplug_slaves(mddev_t *mddev) |
| 598 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 599 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | int i; |
| 601 | |
| 602 | rcu_read_lock(); |
| 603 | for (i=0; i<mddev->raid_disks; i++) { |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 604 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 605 | if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 606 | struct request_queue *r_queue = bdev_get_queue(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | atomic_inc(&rdev->nr_pending); |
| 609 | rcu_read_unlock(); |
| 610 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 611 | blk_unplug(r_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | rdev_dec_pending(rdev, mddev); |
| 614 | rcu_read_lock(); |
| 615 | } |
| 616 | } |
| 617 | rcu_read_unlock(); |
| 618 | } |
| 619 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 620 | static void raid10_unplug(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 622 | mddev_t *mddev = q->queuedata; |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | unplug_slaves(q->queuedata); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 625 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 628 | static int raid10_congested(void *data, int bits) |
| 629 | { |
| 630 | mddev_t *mddev = data; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 631 | conf_t *conf = mddev->private; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 632 | int i, ret = 0; |
| 633 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 634 | if (mddev_congested(mddev, bits)) |
| 635 | return 1; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 636 | rcu_read_lock(); |
| 637 | for (i = 0; i < mddev->raid_disks && ret == 0; i++) { |
| 638 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev); |
| 639 | if (rdev && !test_bit(Faulty, &rdev->flags)) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 640 | struct request_queue *q = bdev_get_queue(rdev->bdev); |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 641 | |
| 642 | ret |= bdi_congested(&q->backing_dev_info, bits); |
| 643 | } |
| 644 | } |
| 645 | rcu_read_unlock(); |
| 646 | return ret; |
| 647 | } |
| 648 | |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 649 | static int flush_pending_writes(conf_t *conf) |
| 650 | { |
| 651 | /* Any writes that have been queued but are awaiting |
| 652 | * bitmap updates get flushed here. |
| 653 | * We return 1 if any requests were actually submitted. |
| 654 | */ |
| 655 | int rv = 0; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 656 | |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 657 | spin_lock_irq(&conf->device_lock); |
| 658 | |
| 659 | if (conf->pending_bio_list.head) { |
| 660 | struct bio *bio; |
| 661 | bio = bio_list_get(&conf->pending_bio_list); |
| 662 | blk_remove_plug(conf->mddev->queue); |
| 663 | spin_unlock_irq(&conf->device_lock); |
| 664 | /* flush any pending bitmap writes to disk |
| 665 | * before proceeding w/ I/O */ |
| 666 | bitmap_unplug(conf->mddev->bitmap); |
| 667 | |
| 668 | while (bio) { /* submit pending writes */ |
| 669 | struct bio *next = bio->bi_next; |
| 670 | bio->bi_next = NULL; |
| 671 | generic_make_request(bio); |
| 672 | bio = next; |
| 673 | } |
| 674 | rv = 1; |
| 675 | } else |
| 676 | spin_unlock_irq(&conf->device_lock); |
| 677 | return rv; |
| 678 | } |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 679 | /* Barriers.... |
| 680 | * Sometimes we need to suspend IO while we do something else, |
| 681 | * either some resync/recovery, or reconfigure the array. |
| 682 | * To do this we raise a 'barrier'. |
| 683 | * The 'barrier' is a counter that can be raised multiple times |
| 684 | * to count how many activities are happening which preclude |
| 685 | * normal IO. |
| 686 | * We can only raise the barrier if there is no pending IO. |
| 687 | * i.e. if nr_pending == 0. |
| 688 | * We choose only to raise the barrier if no-one is waiting for the |
| 689 | * barrier to go down. This means that as soon as an IO request |
| 690 | * is ready, no other operations which require a barrier will start |
| 691 | * until the IO request has had a chance. |
| 692 | * |
| 693 | * So: regular IO calls 'wait_barrier'. When that returns there |
| 694 | * is no backgroup IO happening, It must arrange to call |
| 695 | * allow_barrier when it has finished its IO. |
| 696 | * backgroup IO calls must call raise_barrier. Once that returns |
| 697 | * there is no normal IO happeing. It must arrange to call |
| 698 | * lower_barrier when the particular background IO completes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 701 | static void raise_barrier(conf_t *conf, int force) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 703 | BUG_ON(force && !conf->barrier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | spin_lock_irq(&conf->resync_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 706 | /* Wait until no block IO is waiting (unless 'force') */ |
| 707 | wait_event_lock_irq(conf->wait_barrier, force || !conf->nr_waiting, |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 708 | conf->resync_lock, |
| 709 | raid10_unplug(conf->mddev->queue)); |
| 710 | |
| 711 | /* block any new IO from starting */ |
| 712 | conf->barrier++; |
| 713 | |
| 714 | /* No wait for all pending IO to complete */ |
| 715 | wait_event_lock_irq(conf->wait_barrier, |
| 716 | !conf->nr_pending && conf->barrier < RESYNC_DEPTH, |
| 717 | conf->resync_lock, |
| 718 | raid10_unplug(conf->mddev->queue)); |
| 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | spin_unlock_irq(&conf->resync_lock); |
| 721 | } |
| 722 | |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 723 | static void lower_barrier(conf_t *conf) |
| 724 | { |
| 725 | unsigned long flags; |
| 726 | spin_lock_irqsave(&conf->resync_lock, flags); |
| 727 | conf->barrier--; |
| 728 | spin_unlock_irqrestore(&conf->resync_lock, flags); |
| 729 | wake_up(&conf->wait_barrier); |
| 730 | } |
| 731 | |
| 732 | static void wait_barrier(conf_t *conf) |
| 733 | { |
| 734 | spin_lock_irq(&conf->resync_lock); |
| 735 | if (conf->barrier) { |
| 736 | conf->nr_waiting++; |
| 737 | wait_event_lock_irq(conf->wait_barrier, !conf->barrier, |
| 738 | conf->resync_lock, |
| 739 | raid10_unplug(conf->mddev->queue)); |
| 740 | conf->nr_waiting--; |
| 741 | } |
| 742 | conf->nr_pending++; |
| 743 | spin_unlock_irq(&conf->resync_lock); |
| 744 | } |
| 745 | |
| 746 | static void allow_barrier(conf_t *conf) |
| 747 | { |
| 748 | unsigned long flags; |
| 749 | spin_lock_irqsave(&conf->resync_lock, flags); |
| 750 | conf->nr_pending--; |
| 751 | spin_unlock_irqrestore(&conf->resync_lock, flags); |
| 752 | wake_up(&conf->wait_barrier); |
| 753 | } |
| 754 | |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 755 | static void freeze_array(conf_t *conf) |
| 756 | { |
| 757 | /* stop syncio and normal IO and wait for everything to |
NeilBrown | f188593 | 2006-01-06 00:20:42 -0800 | [diff] [blame] | 758 | * go quiet. |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 759 | * We increment barrier and nr_waiting, and then |
NeilBrown | 1c83053 | 2008-03-04 14:29:35 -0800 | [diff] [blame] | 760 | * wait until nr_pending match nr_queued+1 |
| 761 | * This is called in the context of one normal IO request |
| 762 | * that has failed. Thus any sync request that might be pending |
| 763 | * will be blocked by nr_pending, and we need to wait for |
| 764 | * pending IO requests to complete or be queued for re-try. |
| 765 | * Thus the number queued (nr_queued) plus this request (1) |
| 766 | * must match the number of pending IOs (nr_pending) before |
| 767 | * we continue. |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 768 | */ |
| 769 | spin_lock_irq(&conf->resync_lock); |
| 770 | conf->barrier++; |
| 771 | conf->nr_waiting++; |
| 772 | wait_event_lock_irq(conf->wait_barrier, |
NeilBrown | 1c83053 | 2008-03-04 14:29:35 -0800 | [diff] [blame] | 773 | conf->nr_pending == conf->nr_queued+1, |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 774 | conf->resync_lock, |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 775 | ({ flush_pending_writes(conf); |
| 776 | raid10_unplug(conf->mddev->queue); })); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 777 | spin_unlock_irq(&conf->resync_lock); |
| 778 | } |
| 779 | |
| 780 | static void unfreeze_array(conf_t *conf) |
| 781 | { |
| 782 | /* reverse the effect of the freeze */ |
| 783 | spin_lock_irq(&conf->resync_lock); |
| 784 | conf->barrier--; |
| 785 | conf->nr_waiting--; |
| 786 | wake_up(&conf->wait_barrier); |
| 787 | spin_unlock_irq(&conf->resync_lock); |
| 788 | } |
| 789 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 790 | static int make_request(struct request_queue *q, struct bio * bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | { |
| 792 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 793 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | mirror_info_t *mirror; |
| 795 | r10bio_t *r10_bio; |
| 796 | struct bio *read_bio; |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 797 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | int i; |
| 799 | int chunk_sects = conf->chunk_mask + 1; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 800 | const int rw = bio_data_dir(bio); |
Jens Axboe | 1f98a13 | 2009-09-11 14:32:04 +0200 | [diff] [blame] | 801 | const bool do_sync = bio_rw_flagged(bio, BIO_RW_SYNCIO); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 802 | struct bio_list bl; |
| 803 | unsigned long flags; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 804 | mdk_rdev_t *blocked_rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Jens Axboe | 1f98a13 | 2009-09-11 14:32:04 +0200 | [diff] [blame] | 806 | if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 807 | md_barrier_request(mddev, bio); |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 808 | return 0; |
| 809 | } |
| 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | /* If this request crosses a chunk boundary, we need to |
| 812 | * split it. This will only happen for 1 PAGE (or less) requests. |
| 813 | */ |
| 814 | if (unlikely( (bio->bi_sector & conf->chunk_mask) + (bio->bi_size >> 9) |
| 815 | > chunk_sects && |
| 816 | conf->near_copies < conf->raid_disks)) { |
| 817 | struct bio_pair *bp; |
| 818 | /* Sanity check -- queue functions should prevent this happening */ |
| 819 | if (bio->bi_vcnt != 1 || |
| 820 | bio->bi_idx != 0) |
| 821 | goto bad_map; |
| 822 | /* This is a one page bio that upper layers |
| 823 | * refuse to split for us, so we need to split it. |
| 824 | */ |
Denis ChengRq | 6feef53 | 2008-10-09 08:57:05 +0200 | [diff] [blame] | 825 | bp = bio_split(bio, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | chunk_sects - (bio->bi_sector & (chunk_sects - 1)) ); |
| 827 | if (make_request(q, &bp->bio1)) |
| 828 | generic_make_request(&bp->bio1); |
| 829 | if (make_request(q, &bp->bio2)) |
| 830 | generic_make_request(&bp->bio2); |
| 831 | |
| 832 | bio_pair_release(bp); |
| 833 | return 0; |
| 834 | bad_map: |
| 835 | printk("raid10_make_request bug: can't convert block across chunks" |
| 836 | " or bigger than %dk %llu %d\n", chunk_sects/2, |
| 837 | (unsigned long long)bio->bi_sector, bio->bi_size >> 10); |
| 838 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 839 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 843 | md_write_start(mddev, bio); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | /* |
| 846 | * Register the new request and wait if the reconstruction |
| 847 | * thread has put up a bar for new requests. |
| 848 | * Continue immediately if no resync is active currently. |
| 849 | */ |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 850 | wait_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 852 | cpu = part_stat_lock(); |
| 853 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 854 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 855 | bio_sectors(bio)); |
| 856 | part_stat_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
| 858 | r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO); |
| 859 | |
| 860 | r10_bio->master_bio = bio; |
| 861 | r10_bio->sectors = bio->bi_size >> 9; |
| 862 | |
| 863 | r10_bio->mddev = mddev; |
| 864 | r10_bio->sector = bio->bi_sector; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 865 | r10_bio->state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 867 | if (rw == READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* |
| 869 | * read balancing logic: |
| 870 | */ |
| 871 | int disk = read_balance(conf, r10_bio); |
| 872 | int slot = r10_bio->read_slot; |
| 873 | if (disk < 0) { |
| 874 | raid_end_bio_io(r10_bio); |
| 875 | return 0; |
| 876 | } |
| 877 | mirror = conf->mirrors + disk; |
| 878 | |
| 879 | read_bio = bio_clone(bio, GFP_NOIO); |
| 880 | |
| 881 | r10_bio->devs[slot].bio = read_bio; |
| 882 | |
| 883 | read_bio->bi_sector = r10_bio->devs[slot].addr + |
| 884 | mirror->rdev->data_offset; |
| 885 | read_bio->bi_bdev = mirror->rdev->bdev; |
| 886 | read_bio->bi_end_io = raid10_end_read_request; |
Dmitry Monakhov | 1ef04fe | 2009-09-20 05:52:25 +0400 | [diff] [blame] | 887 | read_bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | read_bio->bi_private = r10_bio; |
| 889 | |
| 890 | generic_make_request(read_bio); |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * WRITE: |
| 896 | */ |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 897 | /* first select target devices under rcu_lock and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | * inc refcount on their rdev. Record them by setting |
| 899 | * bios[x] to bio |
| 900 | */ |
| 901 | raid10_find_phys(conf, r10_bio); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 902 | retry_write: |
Harvey Harrison | cb6969e | 2008-05-06 20:42:32 -0700 | [diff] [blame] | 903 | blocked_rdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | rcu_read_lock(); |
| 905 | for (i = 0; i < conf->copies; i++) { |
| 906 | int d = r10_bio->devs[i].devnum; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 907 | mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[d].rdev); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 908 | if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
| 909 | atomic_inc(&rdev->nr_pending); |
| 910 | blocked_rdev = rdev; |
| 911 | break; |
| 912 | } |
| 913 | if (rdev && !test_bit(Faulty, &rdev->flags)) { |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 914 | atomic_inc(&rdev->nr_pending); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | r10_bio->devs[i].bio = bio; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 916 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | r10_bio->devs[i].bio = NULL; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 918 | set_bit(R10BIO_Degraded, &r10_bio->state); |
| 919 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | rcu_read_unlock(); |
| 922 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 923 | if (unlikely(blocked_rdev)) { |
| 924 | /* Have to wait for this device to get unblocked, then retry */ |
| 925 | int j; |
| 926 | int d; |
| 927 | |
| 928 | for (j = 0; j < i; j++) |
| 929 | if (r10_bio->devs[j].bio) { |
| 930 | d = r10_bio->devs[j].devnum; |
| 931 | rdev_dec_pending(conf->mirrors[d].rdev, mddev); |
| 932 | } |
| 933 | allow_barrier(conf); |
| 934 | md_wait_for_blocked_rdev(blocked_rdev, mddev); |
| 935 | wait_barrier(conf); |
| 936 | goto retry_write; |
| 937 | } |
| 938 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 939 | atomic_set(&r10_bio->remaining, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 940 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 941 | bio_list_init(&bl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | for (i = 0; i < conf->copies; i++) { |
| 943 | struct bio *mbio; |
| 944 | int d = r10_bio->devs[i].devnum; |
| 945 | if (!r10_bio->devs[i].bio) |
| 946 | continue; |
| 947 | |
| 948 | mbio = bio_clone(bio, GFP_NOIO); |
| 949 | r10_bio->devs[i].bio = mbio; |
| 950 | |
| 951 | mbio->bi_sector = r10_bio->devs[i].addr+ |
| 952 | conf->mirrors[d].rdev->data_offset; |
| 953 | mbio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 954 | mbio->bi_end_io = raid10_end_write_request; |
Dmitry Monakhov | 1ef04fe | 2009-09-20 05:52:25 +0400 | [diff] [blame] | 955 | mbio->bi_rw = WRITE | (do_sync << BIO_RW_SYNCIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | mbio->bi_private = r10_bio; |
| 957 | |
| 958 | atomic_inc(&r10_bio->remaining); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 959 | bio_list_add(&bl, mbio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Arne Redlich | f6f953a | 2007-07-31 00:37:57 -0700 | [diff] [blame] | 962 | if (unlikely(!atomic_read(&r10_bio->remaining))) { |
| 963 | /* the array is dead */ |
| 964 | md_write_end(mddev); |
| 965 | raid_end_bio_io(r10_bio); |
| 966 | return 0; |
| 967 | } |
| 968 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 969 | bitmap_startwrite(mddev->bitmap, bio->bi_sector, r10_bio->sectors, 0); |
| 970 | spin_lock_irqsave(&conf->device_lock, flags); |
| 971 | bio_list_merge(&conf->pending_bio_list, &bl); |
| 972 | blk_plug_device(mddev->queue); |
| 973 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 975 | /* In case raid10d snuck in to freeze_array */ |
| 976 | wake_up(&conf->wait_barrier); |
| 977 | |
Lars Ellenberg | e3881a6 | 2007-01-10 23:15:37 -0800 | [diff] [blame] | 978 | if (do_sync) |
| 979 | md_wakeup_thread(mddev->thread); |
| 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | return 0; |
| 982 | } |
| 983 | |
| 984 | static void status(struct seq_file *seq, mddev_t *mddev) |
| 985 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 986 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | int i; |
| 988 | |
| 989 | if (conf->near_copies < conf->raid_disks) |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 990 | seq_printf(seq, " %dK chunks", mddev->chunk_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | if (conf->near_copies > 1) |
| 992 | seq_printf(seq, " %d near-copies", conf->near_copies); |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 993 | if (conf->far_copies > 1) { |
| 994 | if (conf->far_offset) |
| 995 | seq_printf(seq, " %d offset-copies", conf->far_copies); |
| 996 | else |
| 997 | seq_printf(seq, " %d far-copies", conf->far_copies); |
| 998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | seq_printf(seq, " [%d/%d] [", conf->raid_disks, |
NeilBrown | 76186dd | 2006-10-03 01:15:48 -0700 | [diff] [blame] | 1000 | conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | for (i = 0; i < conf->raid_disks; i++) |
| 1002 | seq_printf(seq, "%s", |
| 1003 | conf->mirrors[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1004 | test_bit(In_sync, &conf->mirrors[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | seq_printf(seq, "]"); |
| 1006 | } |
| 1007 | |
| 1008 | static void error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1009 | { |
| 1010 | char b[BDEVNAME_SIZE]; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1011 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
| 1013 | /* |
| 1014 | * If it is not operational, then we have already marked it as dead |
| 1015 | * else if it is the last working disks, ignore the error, let the |
| 1016 | * next level up know. |
| 1017 | * else mark the drive as failed |
| 1018 | */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1019 | if (test_bit(In_sync, &rdev->flags) |
NeilBrown | 76186dd | 2006-10-03 01:15:48 -0700 | [diff] [blame] | 1020 | && conf->raid_disks-mddev->degraded == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | /* |
| 1022 | * Don't fail the drive, just return an IO error. |
| 1023 | * The test should really be more sophisticated than |
| 1024 | * "working_disks == 1", but it isn't critical, and |
| 1025 | * can wait until we do more sophisticated "is the drive |
| 1026 | * really dead" tests... |
| 1027 | */ |
| 1028 | return; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1029 | if (test_and_clear_bit(In_sync, &rdev->flags)) { |
| 1030 | unsigned long flags; |
| 1031 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | mddev->degraded++; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1033 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | /* |
| 1035 | * if recovery is running, make sure it aborts. |
| 1036 | */ |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1037 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1039 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1040 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Nick Andrew | d7a420c | 2008-04-28 02:15:55 -0700 | [diff] [blame] | 1041 | printk(KERN_ALERT "raid10: Disk failure on %s, disabling device.\n" |
| 1042 | "raid10: Operation continuing on %d devices.\n", |
NeilBrown | 76186dd | 2006-10-03 01:15:48 -0700 | [diff] [blame] | 1043 | bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | static void print_conf(conf_t *conf) |
| 1047 | { |
| 1048 | int i; |
| 1049 | mirror_info_t *tmp; |
| 1050 | |
| 1051 | printk("RAID10 conf printout:\n"); |
| 1052 | if (!conf) { |
| 1053 | printk("(!conf)\n"); |
| 1054 | return; |
| 1055 | } |
NeilBrown | 76186dd | 2006-10-03 01:15:48 -0700 | [diff] [blame] | 1056 | printk(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | conf->raid_disks); |
| 1058 | |
| 1059 | for (i = 0; i < conf->raid_disks; i++) { |
| 1060 | char b[BDEVNAME_SIZE]; |
| 1061 | tmp = conf->mirrors + i; |
| 1062 | if (tmp->rdev) |
| 1063 | printk(" disk %d, wo:%d, o:%d, dev:%s\n", |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1064 | i, !test_bit(In_sync, &tmp->rdev->flags), |
| 1065 | !test_bit(Faulty, &tmp->rdev->flags), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | bdevname(tmp->rdev->bdev,b)); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | static void close_sync(conf_t *conf) |
| 1071 | { |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 1072 | wait_barrier(conf); |
| 1073 | allow_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
| 1075 | mempool_destroy(conf->r10buf_pool); |
| 1076 | conf->r10buf_pool = NULL; |
| 1077 | } |
| 1078 | |
NeilBrown | 6d50824 | 2005-09-09 16:24:03 -0700 | [diff] [blame] | 1079 | /* check if there are enough drives for |
| 1080 | * every block to appear on atleast one |
| 1081 | */ |
| 1082 | static int enough(conf_t *conf) |
| 1083 | { |
| 1084 | int first = 0; |
| 1085 | |
| 1086 | do { |
| 1087 | int n = conf->copies; |
| 1088 | int cnt = 0; |
| 1089 | while (n--) { |
| 1090 | if (conf->mirrors[first].rdev) |
| 1091 | cnt++; |
| 1092 | first = (first+1) % conf->raid_disks; |
| 1093 | } |
| 1094 | if (cnt == 0) |
| 1095 | return 0; |
| 1096 | } while (first != 0); |
| 1097 | return 1; |
| 1098 | } |
| 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | static int raid10_spare_active(mddev_t *mddev) |
| 1101 | { |
| 1102 | int i; |
| 1103 | conf_t *conf = mddev->private; |
| 1104 | mirror_info_t *tmp; |
| 1105 | |
| 1106 | /* |
| 1107 | * Find all non-in_sync disks within the RAID10 configuration |
| 1108 | * and mark them in_sync |
| 1109 | */ |
| 1110 | for (i = 0; i < conf->raid_disks; i++) { |
| 1111 | tmp = conf->mirrors + i; |
| 1112 | if (tmp->rdev |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1113 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1114 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
| 1115 | unsigned long flags; |
| 1116 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | mddev->degraded--; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1118 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | print_conf(conf); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | |
| 1127 | static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1128 | { |
| 1129 | conf_t *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1130 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | int mirror; |
| 1132 | mirror_info_t *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1133 | int first = 0; |
| 1134 | int last = mddev->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
| 1136 | if (mddev->recovery_cp < MaxSector) |
| 1137 | /* only hot-add to in-sync arrays, as recovery is |
| 1138 | * very different from resync |
| 1139 | */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1140 | return -EBUSY; |
NeilBrown | 6d50824 | 2005-09-09 16:24:03 -0700 | [diff] [blame] | 1141 | if (!enough(conf)) |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1142 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
NeilBrown | a53a6c8 | 2008-11-06 17:28:20 +1100 | [diff] [blame] | 1144 | if (rdev->raid_disk >= 0) |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1145 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1147 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1148 | rdev->saved_raid_disk >= first && |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1149 | conf->mirrors[rdev->saved_raid_disk].rdev == NULL) |
| 1150 | mirror = rdev->saved_raid_disk; |
| 1151 | else |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1152 | mirror = first; |
| 1153 | for ( ; mirror <= last ; mirror++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | if ( !(p=conf->mirrors+mirror)->rdev) { |
| 1155 | |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 1156 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 1157 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | /* as we don't honour merge_bvec_fn, we must never risk |
| 1159 | * violating it, so limit ->max_sector to one PAGE, as |
| 1160 | * a one page request is never in violation. |
| 1161 | */ |
| 1162 | if (rdev->bdev->bd_disk->queue->merge_bvec_fn && |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 1163 | queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9)) |
| 1164 | blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
| 1166 | p->head_position = 0; |
| 1167 | rdev->raid_disk = mirror; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1168 | err = 0; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1169 | if (rdev->saved_raid_disk != mirror) |
| 1170 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 1171 | rcu_assign_pointer(p->rdev, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | break; |
| 1173 | } |
| 1174 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1175 | md_integrity_add_rdev(rdev, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | print_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1177 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | static int raid10_remove_disk(mddev_t *mddev, int number) |
| 1181 | { |
| 1182 | conf_t *conf = mddev->private; |
| 1183 | int err = 0; |
| 1184 | mdk_rdev_t *rdev; |
| 1185 | mirror_info_t *p = conf->mirrors+ number; |
| 1186 | |
| 1187 | print_conf(conf); |
| 1188 | rdev = p->rdev; |
| 1189 | if (rdev) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1190 | if (test_bit(In_sync, &rdev->flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | atomic_read(&rdev->nr_pending)) { |
| 1192 | err = -EBUSY; |
| 1193 | goto abort; |
| 1194 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1195 | /* Only remove faulty devices in recovery |
| 1196 | * is not possible. |
| 1197 | */ |
| 1198 | if (!test_bit(Faulty, &rdev->flags) && |
| 1199 | enough(conf)) { |
| 1200 | err = -EBUSY; |
| 1201 | goto abort; |
| 1202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | p->rdev = NULL; |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 1204 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | if (atomic_read(&rdev->nr_pending)) { |
| 1206 | /* lost the race, try later */ |
| 1207 | err = -EBUSY; |
| 1208 | p->rdev = rdev; |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1209 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1211 | md_integrity_register(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | } |
| 1213 | abort: |
| 1214 | |
| 1215 | print_conf(conf); |
| 1216 | return err; |
| 1217 | } |
| 1218 | |
| 1219 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1220 | static void end_sync_read(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1223 | conf_t *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | int i,d; |
| 1225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | for (i=0; i<conf->copies; i++) |
| 1227 | if (r10_bio->devs[i].bio == bio) |
| 1228 | break; |
Eric Sesterhenn | b638548 | 2006-04-02 13:34:29 +0200 | [diff] [blame] | 1229 | BUG_ON(i == conf->copies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | update_head_pos(i, r10_bio); |
| 1231 | d = r10_bio->devs[i].devnum; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1232 | |
| 1233 | if (test_bit(BIO_UPTODATE, &bio->bi_flags)) |
| 1234 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1235 | else { |
| 1236 | atomic_add(r10_bio->sectors, |
| 1237 | &conf->mirrors[d].rdev->corrected_errors); |
| 1238 | if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery)) |
| 1239 | md_error(r10_bio->mddev, |
| 1240 | conf->mirrors[d].rdev); |
| 1241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | /* for reconstruct, we always reschedule after a read. |
| 1244 | * for resync, only after all reads |
| 1245 | */ |
NeilBrown | 73d5c38 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 1246 | rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | if (test_bit(R10BIO_IsRecover, &r10_bio->state) || |
| 1248 | atomic_dec_and_test(&r10_bio->remaining)) { |
| 1249 | /* we have read all the blocks, |
| 1250 | * do the comparison in process context in raid10d |
| 1251 | */ |
| 1252 | reschedule_retry(r10_bio); |
| 1253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1256 | static void end_sync_write(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { |
| 1258 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 1259 | r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); |
| 1260 | mddev_t *mddev = r10_bio->mddev; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1261 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | int i,d; |
| 1263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | for (i = 0; i < conf->copies; i++) |
| 1265 | if (r10_bio->devs[i].bio == bio) |
| 1266 | break; |
| 1267 | d = r10_bio->devs[i].devnum; |
| 1268 | |
| 1269 | if (!uptodate) |
| 1270 | md_error(mddev, conf->mirrors[d].rdev); |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | update_head_pos(i, r10_bio); |
| 1273 | |
NeilBrown | 73d5c38 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 1274 | rdev_dec_pending(conf->mirrors[d].rdev, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | while (atomic_dec_and_test(&r10_bio->remaining)) { |
| 1276 | if (r10_bio->master_bio == NULL) { |
| 1277 | /* the primary of several recovery bios */ |
NeilBrown | 73d5c38 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 1278 | sector_t s = r10_bio->sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | put_buf(r10_bio); |
NeilBrown | 73d5c38 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 1280 | md_done_sync(mddev, s, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | break; |
| 1282 | } else { |
| 1283 | r10bio_t *r10_bio2 = (r10bio_t *)r10_bio->master_bio; |
| 1284 | put_buf(r10_bio); |
| 1285 | r10_bio = r10_bio2; |
| 1286 | } |
| 1287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /* |
| 1291 | * Note: sync and recover and handled very differently for raid10 |
| 1292 | * This code is for resync. |
| 1293 | * For resync, we read through virtual addresses and read all blocks. |
| 1294 | * If there is any error, we schedule a write. The lowest numbered |
| 1295 | * drive is authoritative. |
| 1296 | * However requests come for physical address, so we need to map. |
| 1297 | * For every physical address there are raid_disks/copies virtual addresses, |
| 1298 | * which is always are least one, but is not necessarly an integer. |
| 1299 | * This means that a physical address can span multiple chunks, so we may |
| 1300 | * have to submit multiple io requests for a single sync request. |
| 1301 | */ |
| 1302 | /* |
| 1303 | * We check if all blocks are in-sync and only write to blocks that |
| 1304 | * aren't in sync |
| 1305 | */ |
| 1306 | static void sync_request_write(mddev_t *mddev, r10bio_t *r10_bio) |
| 1307 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1308 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | int i, first; |
| 1310 | struct bio *tbio, *fbio; |
| 1311 | |
| 1312 | atomic_set(&r10_bio->remaining, 1); |
| 1313 | |
| 1314 | /* find the first device with a block */ |
| 1315 | for (i=0; i<conf->copies; i++) |
| 1316 | if (test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags)) |
| 1317 | break; |
| 1318 | |
| 1319 | if (i == conf->copies) |
| 1320 | goto done; |
| 1321 | |
| 1322 | first = i; |
| 1323 | fbio = r10_bio->devs[i].bio; |
| 1324 | |
| 1325 | /* now find blocks with errors */ |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1326 | for (i=0 ; i < conf->copies ; i++) { |
| 1327 | int j, d; |
| 1328 | int vcnt = r10_bio->sectors >> (PAGE_SHIFT-9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | tbio = r10_bio->devs[i].bio; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1331 | |
| 1332 | if (tbio->bi_end_io != end_sync_read) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | continue; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1334 | if (i == first) |
| 1335 | continue; |
| 1336 | if (test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags)) { |
| 1337 | /* We know that the bi_io_vec layout is the same for |
| 1338 | * both 'first' and 'i', so we just compare them. |
| 1339 | * All vec entries are PAGE_SIZE; |
| 1340 | */ |
| 1341 | for (j = 0; j < vcnt; j++) |
| 1342 | if (memcmp(page_address(fbio->bi_io_vec[j].bv_page), |
| 1343 | page_address(tbio->bi_io_vec[j].bv_page), |
| 1344 | PAGE_SIZE)) |
| 1345 | break; |
| 1346 | if (j == vcnt) |
| 1347 | continue; |
| 1348 | mddev->resync_mismatches += r10_bio->sectors; |
| 1349 | } |
NeilBrown | 18f0881 | 2006-01-06 00:20:25 -0800 | [diff] [blame] | 1350 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 1351 | /* Don't fix anything. */ |
| 1352 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | /* Ok, we need to write this bio |
| 1354 | * First we need to fixup bv_offset, bv_len and |
| 1355 | * bi_vecs, as the read request might have corrupted these |
| 1356 | */ |
| 1357 | tbio->bi_vcnt = vcnt; |
| 1358 | tbio->bi_size = r10_bio->sectors << 9; |
| 1359 | tbio->bi_idx = 0; |
| 1360 | tbio->bi_phys_segments = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | tbio->bi_flags &= ~(BIO_POOL_MASK - 1); |
| 1362 | tbio->bi_flags |= 1 << BIO_UPTODATE; |
| 1363 | tbio->bi_next = NULL; |
| 1364 | tbio->bi_rw = WRITE; |
| 1365 | tbio->bi_private = r10_bio; |
| 1366 | tbio->bi_sector = r10_bio->devs[i].addr; |
| 1367 | |
| 1368 | for (j=0; j < vcnt ; j++) { |
| 1369 | tbio->bi_io_vec[j].bv_offset = 0; |
| 1370 | tbio->bi_io_vec[j].bv_len = PAGE_SIZE; |
| 1371 | |
| 1372 | memcpy(page_address(tbio->bi_io_vec[j].bv_page), |
| 1373 | page_address(fbio->bi_io_vec[j].bv_page), |
| 1374 | PAGE_SIZE); |
| 1375 | } |
| 1376 | tbio->bi_end_io = end_sync_write; |
| 1377 | |
| 1378 | d = r10_bio->devs[i].devnum; |
| 1379 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 1380 | atomic_inc(&r10_bio->remaining); |
| 1381 | md_sync_acct(conf->mirrors[d].rdev->bdev, tbio->bi_size >> 9); |
| 1382 | |
| 1383 | tbio->bi_sector += conf->mirrors[d].rdev->data_offset; |
| 1384 | tbio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 1385 | generic_make_request(tbio); |
| 1386 | } |
| 1387 | |
| 1388 | done: |
| 1389 | if (atomic_dec_and_test(&r10_bio->remaining)) { |
| 1390 | md_done_sync(mddev, r10_bio->sectors, 1); |
| 1391 | put_buf(r10_bio); |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Now for the recovery code. |
| 1397 | * Recovery happens across physical sectors. |
| 1398 | * We recover all non-is_sync drives by finding the virtual address of |
| 1399 | * each, and then choose a working drive that also has that virt address. |
| 1400 | * There is a separate r10_bio for each non-in_sync drive. |
| 1401 | * Only the first two slots are in use. The first for reading, |
| 1402 | * The second for writing. |
| 1403 | * |
| 1404 | */ |
| 1405 | |
| 1406 | static void recovery_request_write(mddev_t *mddev, r10bio_t *r10_bio) |
| 1407 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1408 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | int i, d; |
| 1410 | struct bio *bio, *wbio; |
| 1411 | |
| 1412 | |
| 1413 | /* move the pages across to the second bio |
| 1414 | * and submit the write request |
| 1415 | */ |
| 1416 | bio = r10_bio->devs[0].bio; |
| 1417 | wbio = r10_bio->devs[1].bio; |
| 1418 | for (i=0; i < wbio->bi_vcnt; i++) { |
| 1419 | struct page *p = bio->bi_io_vec[i].bv_page; |
| 1420 | bio->bi_io_vec[i].bv_page = wbio->bi_io_vec[i].bv_page; |
| 1421 | wbio->bi_io_vec[i].bv_page = p; |
| 1422 | } |
| 1423 | d = r10_bio->devs[1].devnum; |
| 1424 | |
| 1425 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 1426 | md_sync_acct(conf->mirrors[d].rdev->bdev, wbio->bi_size >> 9); |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1427 | if (test_bit(R10BIO_Uptodate, &r10_bio->state)) |
| 1428 | generic_make_request(wbio); |
| 1429 | else |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1430 | bio_endio(wbio, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | /* |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1435 | * Used by fix_read_error() to decay the per rdev read_errors. |
| 1436 | * We halve the read error count for every hour that has elapsed |
| 1437 | * since the last recorded read error. |
| 1438 | * |
| 1439 | */ |
| 1440 | static void check_decay_read_errors(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1441 | { |
| 1442 | struct timespec cur_time_mon; |
| 1443 | unsigned long hours_since_last; |
| 1444 | unsigned int read_errors = atomic_read(&rdev->read_errors); |
| 1445 | |
| 1446 | ktime_get_ts(&cur_time_mon); |
| 1447 | |
| 1448 | if (rdev->last_read_error.tv_sec == 0 && |
| 1449 | rdev->last_read_error.tv_nsec == 0) { |
| 1450 | /* first time we've seen a read error */ |
| 1451 | rdev->last_read_error = cur_time_mon; |
| 1452 | return; |
| 1453 | } |
| 1454 | |
| 1455 | hours_since_last = (cur_time_mon.tv_sec - |
| 1456 | rdev->last_read_error.tv_sec) / 3600; |
| 1457 | |
| 1458 | rdev->last_read_error = cur_time_mon; |
| 1459 | |
| 1460 | /* |
| 1461 | * if hours_since_last is > the number of bits in read_errors |
| 1462 | * just set read errors to 0. We do this to avoid |
| 1463 | * overflowing the shift of read_errors by hours_since_last. |
| 1464 | */ |
| 1465 | if (hours_since_last >= 8 * sizeof(read_errors)) |
| 1466 | atomic_set(&rdev->read_errors, 0); |
| 1467 | else |
| 1468 | atomic_set(&rdev->read_errors, read_errors >> hours_since_last); |
| 1469 | } |
| 1470 | |
| 1471 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | * This is a kernel thread which: |
| 1473 | * |
| 1474 | * 1. Retries failed read operations on working mirrors. |
| 1475 | * 2. Updates the raid superblock when problems encounter. |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1476 | * 3. Performs writes following reads for array synchronising. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | */ |
| 1478 | |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1479 | static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio) |
| 1480 | { |
| 1481 | int sect = 0; /* Offset from r10_bio->sector */ |
| 1482 | int sectors = r10_bio->sectors; |
| 1483 | mdk_rdev_t*rdev; |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1484 | int max_read_errors = atomic_read(&mddev->max_corr_read_errors); |
| 1485 | |
| 1486 | rcu_read_lock(); |
| 1487 | { |
| 1488 | int d = r10_bio->devs[r10_bio->read_slot].devnum; |
| 1489 | char b[BDEVNAME_SIZE]; |
| 1490 | int cur_read_error_count = 0; |
| 1491 | |
| 1492 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
| 1493 | bdevname(rdev->bdev, b); |
| 1494 | |
| 1495 | if (test_bit(Faulty, &rdev->flags)) { |
| 1496 | rcu_read_unlock(); |
| 1497 | /* drive has already been failed, just ignore any |
| 1498 | more fix_read_error() attempts */ |
| 1499 | return; |
| 1500 | } |
| 1501 | |
| 1502 | check_decay_read_errors(mddev, rdev); |
| 1503 | atomic_inc(&rdev->read_errors); |
| 1504 | cur_read_error_count = atomic_read(&rdev->read_errors); |
| 1505 | if (cur_read_error_count > max_read_errors) { |
| 1506 | rcu_read_unlock(); |
| 1507 | printk(KERN_NOTICE |
| 1508 | "raid10: %s: Raid device exceeded " |
| 1509 | "read_error threshold " |
| 1510 | "[cur %d:max %d]\n", |
| 1511 | b, cur_read_error_count, max_read_errors); |
| 1512 | printk(KERN_NOTICE |
| 1513 | "raid10: %s: Failing raid " |
| 1514 | "device\n", b); |
| 1515 | md_error(mddev, conf->mirrors[d].rdev); |
| 1516 | return; |
| 1517 | } |
| 1518 | } |
| 1519 | rcu_read_unlock(); |
| 1520 | |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1521 | while(sectors) { |
| 1522 | int s = sectors; |
| 1523 | int sl = r10_bio->read_slot; |
| 1524 | int success = 0; |
| 1525 | int start; |
| 1526 | |
| 1527 | if (s > (PAGE_SIZE>>9)) |
| 1528 | s = PAGE_SIZE >> 9; |
| 1529 | |
| 1530 | rcu_read_lock(); |
| 1531 | do { |
| 1532 | int d = r10_bio->devs[sl].devnum; |
| 1533 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
| 1534 | if (rdev && |
| 1535 | test_bit(In_sync, &rdev->flags)) { |
| 1536 | atomic_inc(&rdev->nr_pending); |
| 1537 | rcu_read_unlock(); |
| 1538 | success = sync_page_io(rdev->bdev, |
| 1539 | r10_bio->devs[sl].addr + |
| 1540 | sect + rdev->data_offset, |
| 1541 | s<<9, |
| 1542 | conf->tmppage, READ); |
| 1543 | rdev_dec_pending(rdev, mddev); |
| 1544 | rcu_read_lock(); |
| 1545 | if (success) |
| 1546 | break; |
| 1547 | } |
| 1548 | sl++; |
| 1549 | if (sl == conf->copies) |
| 1550 | sl = 0; |
| 1551 | } while (!success && sl != r10_bio->read_slot); |
| 1552 | rcu_read_unlock(); |
| 1553 | |
| 1554 | if (!success) { |
| 1555 | /* Cannot read from anywhere -- bye bye array */ |
| 1556 | int dn = r10_bio->devs[r10_bio->read_slot].devnum; |
| 1557 | md_error(mddev, conf->mirrors[dn].rdev); |
| 1558 | break; |
| 1559 | } |
| 1560 | |
| 1561 | start = sl; |
| 1562 | /* write it back and re-read */ |
| 1563 | rcu_read_lock(); |
| 1564 | while (sl != r10_bio->read_slot) { |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1565 | char b[BDEVNAME_SIZE]; |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1566 | int d; |
| 1567 | if (sl==0) |
| 1568 | sl = conf->copies; |
| 1569 | sl--; |
| 1570 | d = r10_bio->devs[sl].devnum; |
| 1571 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
| 1572 | if (rdev && |
| 1573 | test_bit(In_sync, &rdev->flags)) { |
| 1574 | atomic_inc(&rdev->nr_pending); |
| 1575 | rcu_read_unlock(); |
| 1576 | atomic_add(s, &rdev->corrected_errors); |
| 1577 | if (sync_page_io(rdev->bdev, |
| 1578 | r10_bio->devs[sl].addr + |
| 1579 | sect + rdev->data_offset, |
| 1580 | s<<9, conf->tmppage, WRITE) |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1581 | == 0) { |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1582 | /* Well, this device is dead */ |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1583 | printk(KERN_NOTICE |
| 1584 | "raid10:%s: read correction " |
| 1585 | "write failed" |
| 1586 | " (%d sectors at %llu on %s)\n", |
| 1587 | mdname(mddev), s, |
| 1588 | (unsigned long long)(sect+ |
| 1589 | rdev->data_offset), |
| 1590 | bdevname(rdev->bdev, b)); |
| 1591 | printk(KERN_NOTICE "raid10:%s: failing " |
| 1592 | "drive\n", |
| 1593 | bdevname(rdev->bdev, b)); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1594 | md_error(mddev, rdev); |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1595 | } |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1596 | rdev_dec_pending(rdev, mddev); |
| 1597 | rcu_read_lock(); |
| 1598 | } |
| 1599 | } |
| 1600 | sl = start; |
| 1601 | while (sl != r10_bio->read_slot) { |
| 1602 | int d; |
| 1603 | if (sl==0) |
| 1604 | sl = conf->copies; |
| 1605 | sl--; |
| 1606 | d = r10_bio->devs[sl].devnum; |
| 1607 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
| 1608 | if (rdev && |
| 1609 | test_bit(In_sync, &rdev->flags)) { |
| 1610 | char b[BDEVNAME_SIZE]; |
| 1611 | atomic_inc(&rdev->nr_pending); |
| 1612 | rcu_read_unlock(); |
| 1613 | if (sync_page_io(rdev->bdev, |
| 1614 | r10_bio->devs[sl].addr + |
| 1615 | sect + rdev->data_offset, |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1616 | s<<9, conf->tmppage, |
| 1617 | READ) == 0) { |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1618 | /* Well, this device is dead */ |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1619 | printk(KERN_NOTICE |
| 1620 | "raid10:%s: unable to read back " |
| 1621 | "corrected sectors" |
| 1622 | " (%d sectors at %llu on %s)\n", |
| 1623 | mdname(mddev), s, |
| 1624 | (unsigned long long)(sect+ |
| 1625 | rdev->data_offset), |
| 1626 | bdevname(rdev->bdev, b)); |
| 1627 | printk(KERN_NOTICE "raid10:%s: failing drive\n", |
| 1628 | bdevname(rdev->bdev, b)); |
| 1629 | |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1630 | md_error(mddev, rdev); |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1631 | } else { |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1632 | printk(KERN_INFO |
| 1633 | "raid10:%s: read error corrected" |
| 1634 | " (%d sectors at %llu on %s)\n", |
| 1635 | mdname(mddev), s, |
Randy Dunlap | 969b755 | 2006-10-28 10:38:32 -0700 | [diff] [blame] | 1636 | (unsigned long long)(sect+ |
| 1637 | rdev->data_offset), |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1638 | bdevname(rdev->bdev, b)); |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 1639 | } |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1640 | |
| 1641 | rdev_dec_pending(rdev, mddev); |
| 1642 | rcu_read_lock(); |
| 1643 | } |
| 1644 | } |
| 1645 | rcu_read_unlock(); |
| 1646 | |
| 1647 | sectors -= s; |
| 1648 | sect += s; |
| 1649 | } |
| 1650 | } |
| 1651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | static void raid10d(mddev_t *mddev) |
| 1653 | { |
| 1654 | r10bio_t *r10_bio; |
| 1655 | struct bio *bio; |
| 1656 | unsigned long flags; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1657 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | struct list_head *head = &conf->retry_list; |
| 1659 | int unplug=0; |
| 1660 | mdk_rdev_t *rdev; |
| 1661 | |
| 1662 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
| 1664 | for (;;) { |
| 1665 | char b[BDEVNAME_SIZE]; |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 1666 | |
| 1667 | unplug += flush_pending_writes(conf); |
| 1668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 1670 | if (list_empty(head)) { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1671 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | break; |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 1673 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | r10_bio = list_entry(head->prev, r10bio_t, retry_list); |
| 1675 | list_del(head->prev); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 1676 | conf->nr_queued--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 1678 | |
| 1679 | mddev = r10_bio->mddev; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1680 | conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | if (test_bit(R10BIO_IsSync, &r10_bio->state)) { |
| 1682 | sync_request_write(mddev, r10_bio); |
| 1683 | unplug = 1; |
| 1684 | } else if (test_bit(R10BIO_IsRecover, &r10_bio->state)) { |
| 1685 | recovery_request_write(mddev, r10_bio); |
| 1686 | unplug = 1; |
| 1687 | } else { |
| 1688 | int mirror; |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 1689 | /* we got a read error. Maybe the drive is bad. Maybe just |
| 1690 | * the block and we can fix it. |
| 1691 | * We freeze all other IO, and try reading the block from |
| 1692 | * other devices. When we find one, we re-write |
| 1693 | * and check it that fixes the read error. |
| 1694 | * This is all done synchronously while the array is |
| 1695 | * frozen. |
| 1696 | */ |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1697 | if (mddev->ro == 0) { |
| 1698 | freeze_array(conf); |
| 1699 | fix_read_error(conf, mddev, r10_bio); |
| 1700 | unfreeze_array(conf); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | bio = r10_bio->devs[r10_bio->read_slot].bio; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1704 | r10_bio->devs[r10_bio->read_slot].bio = |
| 1705 | mddev->ro ? IO_BLOCKED : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | mirror = read_balance(conf, r10_bio); |
| 1707 | if (mirror == -1) { |
| 1708 | printk(KERN_ALERT "raid10: %s: unrecoverable I/O" |
| 1709 | " read error for block %llu\n", |
| 1710 | bdevname(bio->bi_bdev,b), |
| 1711 | (unsigned long long)r10_bio->sector); |
| 1712 | raid_end_bio_io(r10_bio); |
Maik Hampel | 14e7134 | 2007-07-31 00:37:57 -0700 | [diff] [blame] | 1713 | bio_put(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | } else { |
Jens Axboe | 1f98a13 | 2009-09-11 14:32:04 +0200 | [diff] [blame] | 1715 | const bool do_sync = bio_rw_flagged(r10_bio->master_bio, BIO_RW_SYNCIO); |
Maik Hampel | 14e7134 | 2007-07-31 00:37:57 -0700 | [diff] [blame] | 1716 | bio_put(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | rdev = conf->mirrors[mirror].rdev; |
| 1718 | if (printk_ratelimit()) |
| 1719 | printk(KERN_ERR "raid10: %s: redirecting sector %llu to" |
| 1720 | " another mirror\n", |
| 1721 | bdevname(rdev->bdev,b), |
| 1722 | (unsigned long long)r10_bio->sector); |
| 1723 | bio = bio_clone(r10_bio->master_bio, GFP_NOIO); |
| 1724 | r10_bio->devs[r10_bio->read_slot].bio = bio; |
| 1725 | bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr |
| 1726 | + rdev->data_offset; |
| 1727 | bio->bi_bdev = rdev->bdev; |
Dmitry Monakhov | 1ef04fe | 2009-09-20 05:52:25 +0400 | [diff] [blame] | 1728 | bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | bio->bi_private = r10_bio; |
| 1730 | bio->bi_end_io = raid10_end_read_request; |
| 1731 | unplug = 1; |
| 1732 | generic_make_request(bio); |
| 1733 | } |
| 1734 | } |
NeilBrown | 1d9d524 | 2009-10-16 15:55:32 +1100 | [diff] [blame] | 1735 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | if (unplug) |
| 1738 | unplug_slaves(mddev); |
| 1739 | } |
| 1740 | |
| 1741 | |
| 1742 | static int init_resync(conf_t *conf) |
| 1743 | { |
| 1744 | int buffs; |
| 1745 | |
| 1746 | buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE; |
Eric Sesterhenn | b638548 | 2006-04-02 13:34:29 +0200 | [diff] [blame] | 1747 | BUG_ON(conf->r10buf_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | conf->r10buf_pool = mempool_create(buffs, r10buf_pool_alloc, r10buf_pool_free, conf); |
| 1749 | if (!conf->r10buf_pool) |
| 1750 | return -ENOMEM; |
| 1751 | conf->next_resync = 0; |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | * perform a "sync" on one "block" |
| 1757 | * |
| 1758 | * We need to make sure that no normal I/O request - particularly write |
| 1759 | * requests - conflict with active sync requests. |
| 1760 | * |
| 1761 | * This is achieved by tracking pending requests and a 'barrier' concept |
| 1762 | * that can be installed to exclude normal IO requests. |
| 1763 | * |
| 1764 | * Resync and recovery are handled very differently. |
| 1765 | * We differentiate by looking at MD_RECOVERY_SYNC in mddev->recovery. |
| 1766 | * |
| 1767 | * For resync, we iterate over virtual addresses, read all copies, |
| 1768 | * and update if there are differences. If only one copy is live, |
| 1769 | * skip it. |
| 1770 | * For recovery, we iterate over physical addresses, read a good |
| 1771 | * value for each non-in_sync drive, and over-write. |
| 1772 | * |
| 1773 | * So, for recovery we may have several outstanding complex requests for a |
| 1774 | * given address, one for each out-of-sync device. We model this by allocating |
| 1775 | * a number of r10_bio structures, one for each out-of-sync device. |
| 1776 | * As we setup these structures, we collect all bio's together into a list |
| 1777 | * which we then process collectively to add pages, and then process again |
| 1778 | * to pass to generic_make_request. |
| 1779 | * |
| 1780 | * The r10_bio structures are linked using a borrowed master_bio pointer. |
| 1781 | * This link is counted in ->remaining. When the r10_bio that points to NULL |
| 1782 | * has its remaining count decremented to 0, the whole complex operation |
| 1783 | * is complete. |
| 1784 | * |
| 1785 | */ |
| 1786 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 1787 | static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 1789 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | r10bio_t *r10_bio; |
| 1791 | struct bio *biolist = NULL, *bio; |
| 1792 | sector_t max_sector, nr_sectors; |
| 1793 | int disk; |
| 1794 | int i; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1795 | int max_sync; |
| 1796 | int sync_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
| 1798 | sector_t sectors_skipped = 0; |
| 1799 | int chunks_skipped = 0; |
| 1800 | |
| 1801 | if (!conf->r10buf_pool) |
| 1802 | if (init_resync(conf)) |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 1803 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
| 1805 | skipped: |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 1806 | max_sector = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 1808 | max_sector = mddev->resync_max_sectors; |
| 1809 | if (sector_nr >= max_sector) { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1810 | /* If we aborted, we need to abort the |
| 1811 | * sync on the 'current' bitmap chucks (there can |
| 1812 | * be several when recovering multiple devices). |
| 1813 | * as we may have started syncing it but not finished. |
| 1814 | * We can find the current address in |
| 1815 | * mddev->curr_resync, but for recovery, |
| 1816 | * we need to convert that to several |
| 1817 | * virtual addresses. |
| 1818 | */ |
| 1819 | if (mddev->curr_resync < max_sector) { /* aborted */ |
| 1820 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 1821 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 1822 | &sync_blocks, 1); |
| 1823 | else for (i=0; i<conf->raid_disks; i++) { |
| 1824 | sector_t sect = |
| 1825 | raid10_find_virt(conf, mddev->curr_resync, i); |
| 1826 | bitmap_end_sync(mddev->bitmap, sect, |
| 1827 | &sync_blocks, 1); |
| 1828 | } |
| 1829 | } else /* completed sync */ |
| 1830 | conf->fullsync = 0; |
| 1831 | |
| 1832 | bitmap_close_sync(mddev->bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | close_sync(conf); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 1834 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | return sectors_skipped; |
| 1836 | } |
| 1837 | if (chunks_skipped >= conf->raid_disks) { |
| 1838 | /* if there has been nothing to do on any drive, |
| 1839 | * then there is nothing to do at all.. |
| 1840 | */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 1841 | *skipped = 1; |
| 1842 | return (max_sector - sector_nr) + sectors_skipped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 1845 | if (max_sector > mddev->resync_max) |
| 1846 | max_sector = mddev->resync_max; /* Don't do IO beyond here */ |
| 1847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | /* make sure whole request will fit in a chunk - if chunks |
| 1849 | * are meaningful |
| 1850 | */ |
| 1851 | if (conf->near_copies < conf->raid_disks && |
| 1852 | max_sector > (sector_nr | conf->chunk_mask)) |
| 1853 | max_sector = (sector_nr | conf->chunk_mask) + 1; |
| 1854 | /* |
| 1855 | * If there is non-resync activity waiting for us then |
| 1856 | * put in a delay to throttle resync. |
| 1857 | */ |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 1858 | if (!go_faster && conf->nr_waiting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | msleep_interruptible(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | |
| 1861 | /* Again, very different code for resync and recovery. |
| 1862 | * Both must result in an r10bio with a list of bios that |
| 1863 | * have bi_end_io, bi_sector, bi_bdev set, |
| 1864 | * and bi_private set to the r10bio. |
| 1865 | * For recovery, we may actually create several r10bios |
| 1866 | * with 2 bios in each, that correspond to the bios in the main one. |
| 1867 | * In this case, the subordinate r10bios link back through a |
| 1868 | * borrowed master_bio pointer, and the counter in the master |
| 1869 | * includes a ref from each subordinate. |
| 1870 | */ |
| 1871 | /* First, we decide what to do and set ->bi_end_io |
| 1872 | * To end_sync_read if we want to read, and |
| 1873 | * end_sync_write if we will want to write. |
| 1874 | */ |
| 1875 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1876 | max_sync = RESYNC_PAGES << (PAGE_SHIFT-9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 1878 | /* recovery... the complicated one */ |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 1879 | int j, k; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | r10_bio = NULL; |
| 1881 | |
| 1882 | for (i=0 ; i<conf->raid_disks; i++) |
| 1883 | if (conf->mirrors[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1884 | !test_bit(In_sync, &conf->mirrors[i].rdev->flags)) { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1885 | int still_degraded = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | /* want to reconstruct this device */ |
| 1887 | r10bio_t *rb2 = r10_bio; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1888 | sector_t sect = raid10_find_virt(conf, sector_nr, i); |
| 1889 | int must_sync; |
| 1890 | /* Unless we are doing a full sync, we only need |
| 1891 | * to recover the block if it is set in the bitmap |
| 1892 | */ |
| 1893 | must_sync = bitmap_start_sync(mddev->bitmap, sect, |
| 1894 | &sync_blocks, 1); |
| 1895 | if (sync_blocks < max_sync) |
| 1896 | max_sync = sync_blocks; |
| 1897 | if (!must_sync && |
| 1898 | !conf->fullsync) { |
| 1899 | /* yep, skip the sync_blocks here, but don't assume |
| 1900 | * that there will never be anything to do here |
| 1901 | */ |
| 1902 | chunks_skipped = -1; |
| 1903 | continue; |
| 1904 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
| 1906 | r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1907 | raise_barrier(conf, rb2 != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | atomic_set(&r10_bio->remaining, 0); |
| 1909 | |
| 1910 | r10_bio->master_bio = (struct bio*)rb2; |
| 1911 | if (rb2) |
| 1912 | atomic_inc(&rb2->remaining); |
| 1913 | r10_bio->mddev = mddev; |
| 1914 | set_bit(R10BIO_IsRecover, &r10_bio->state); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1915 | r10_bio->sector = sect; |
| 1916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | raid10_find_phys(conf, r10_bio); |
NeilBrown | 1805556 | 2009-05-07 12:48:10 +1000 | [diff] [blame] | 1918 | |
| 1919 | /* Need to check if the array will still be |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1920 | * degraded |
| 1921 | */ |
NeilBrown | 1805556 | 2009-05-07 12:48:10 +1000 | [diff] [blame] | 1922 | for (j=0; j<conf->raid_disks; j++) |
| 1923 | if (conf->mirrors[j].rdev == NULL || |
| 1924 | test_bit(Faulty, &conf->mirrors[j].rdev->flags)) { |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1925 | still_degraded = 1; |
NeilBrown | a24a8dd | 2006-01-06 00:20:35 -0800 | [diff] [blame] | 1926 | break; |
| 1927 | } |
NeilBrown | 1805556 | 2009-05-07 12:48:10 +1000 | [diff] [blame] | 1928 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1929 | must_sync = bitmap_start_sync(mddev->bitmap, sect, |
| 1930 | &sync_blocks, still_degraded); |
| 1931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | for (j=0; j<conf->copies;j++) { |
| 1933 | int d = r10_bio->devs[j].devnum; |
| 1934 | if (conf->mirrors[d].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1935 | test_bit(In_sync, &conf->mirrors[d].rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | /* This is where we read from */ |
| 1937 | bio = r10_bio->devs[0].bio; |
| 1938 | bio->bi_next = biolist; |
| 1939 | biolist = bio; |
| 1940 | bio->bi_private = r10_bio; |
| 1941 | bio->bi_end_io = end_sync_read; |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 1942 | bio->bi_rw = READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | bio->bi_sector = r10_bio->devs[j].addr + |
| 1944 | conf->mirrors[d].rdev->data_offset; |
| 1945 | bio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 1946 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 1947 | atomic_inc(&r10_bio->remaining); |
| 1948 | /* and we write to 'i' */ |
| 1949 | |
| 1950 | for (k=0; k<conf->copies; k++) |
| 1951 | if (r10_bio->devs[k].devnum == i) |
| 1952 | break; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 1953 | BUG_ON(k == conf->copies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | bio = r10_bio->devs[1].bio; |
| 1955 | bio->bi_next = biolist; |
| 1956 | biolist = bio; |
| 1957 | bio->bi_private = r10_bio; |
| 1958 | bio->bi_end_io = end_sync_write; |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 1959 | bio->bi_rw = WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | bio->bi_sector = r10_bio->devs[k].addr + |
| 1961 | conf->mirrors[i].rdev->data_offset; |
| 1962 | bio->bi_bdev = conf->mirrors[i].rdev->bdev; |
| 1963 | |
| 1964 | r10_bio->devs[0].devnum = d; |
| 1965 | r10_bio->devs[1].devnum = i; |
| 1966 | |
| 1967 | break; |
| 1968 | } |
| 1969 | } |
| 1970 | if (j == conf->copies) { |
NeilBrown | 87fc767 | 2005-09-09 16:24:04 -0700 | [diff] [blame] | 1971 | /* Cannot recover, so abort the recovery */ |
| 1972 | put_buf(r10_bio); |
K.Tanaka | a07e6ab | 2008-03-04 14:29:37 -0800 | [diff] [blame] | 1973 | if (rb2) |
| 1974 | atomic_dec(&rb2->remaining); |
NeilBrown | 87fc767 | 2005-09-09 16:24:04 -0700 | [diff] [blame] | 1975 | r10_bio = rb2; |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1976 | if (!test_and_set_bit(MD_RECOVERY_INTR, |
| 1977 | &mddev->recovery)) |
NeilBrown | 87fc767 | 2005-09-09 16:24:04 -0700 | [diff] [blame] | 1978 | printk(KERN_INFO "raid10: %s: insufficient working devices for recovery.\n", |
| 1979 | mdname(mddev)); |
| 1980 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | } |
| 1982 | } |
| 1983 | if (biolist == NULL) { |
| 1984 | while (r10_bio) { |
| 1985 | r10bio_t *rb2 = r10_bio; |
| 1986 | r10_bio = (r10bio_t*) rb2->master_bio; |
| 1987 | rb2->master_bio = NULL; |
| 1988 | put_buf(rb2); |
| 1989 | } |
| 1990 | goto giveup; |
| 1991 | } |
| 1992 | } else { |
| 1993 | /* resync. Schedule a read for every block at this virt offset */ |
| 1994 | int count = 0; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1995 | |
NeilBrown | 78200d4 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 1996 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 1997 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1998 | if (!bitmap_start_sync(mddev->bitmap, sector_nr, |
| 1999 | &sync_blocks, mddev->degraded) && |
| 2000 | !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) { |
| 2001 | /* We can skip this block */ |
| 2002 | *skipped = 1; |
| 2003 | return sync_blocks + sectors_skipped; |
| 2004 | } |
| 2005 | if (sync_blocks < max_sync) |
| 2006 | max_sync = sync_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO); |
| 2008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | r10_bio->mddev = mddev; |
| 2010 | atomic_set(&r10_bio->remaining, 0); |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2011 | raise_barrier(conf, 0); |
| 2012 | conf->next_resync = sector_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
| 2014 | r10_bio->master_bio = NULL; |
| 2015 | r10_bio->sector = sector_nr; |
| 2016 | set_bit(R10BIO_IsSync, &r10_bio->state); |
| 2017 | raid10_find_phys(conf, r10_bio); |
| 2018 | r10_bio->sectors = (sector_nr | conf->chunk_mask) - sector_nr +1; |
| 2019 | |
| 2020 | for (i=0; i<conf->copies; i++) { |
| 2021 | int d = r10_bio->devs[i].devnum; |
| 2022 | bio = r10_bio->devs[i].bio; |
| 2023 | bio->bi_end_io = NULL; |
NeilBrown | af03b8e | 2007-06-16 10:16:06 -0700 | [diff] [blame] | 2024 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | if (conf->mirrors[d].rdev == NULL || |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2026 | test_bit(Faulty, &conf->mirrors[d].rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | continue; |
| 2028 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 2029 | atomic_inc(&r10_bio->remaining); |
| 2030 | bio->bi_next = biolist; |
| 2031 | biolist = bio; |
| 2032 | bio->bi_private = r10_bio; |
| 2033 | bio->bi_end_io = end_sync_read; |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 2034 | bio->bi_rw = READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | bio->bi_sector = r10_bio->devs[i].addr + |
| 2036 | conf->mirrors[d].rdev->data_offset; |
| 2037 | bio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 2038 | count++; |
| 2039 | } |
| 2040 | |
| 2041 | if (count < 2) { |
| 2042 | for (i=0; i<conf->copies; i++) { |
| 2043 | int d = r10_bio->devs[i].devnum; |
| 2044 | if (r10_bio->devs[i].bio->bi_end_io) |
| 2045 | rdev_dec_pending(conf->mirrors[d].rdev, mddev); |
| 2046 | } |
| 2047 | put_buf(r10_bio); |
| 2048 | biolist = NULL; |
| 2049 | goto giveup; |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | for (bio = biolist; bio ; bio=bio->bi_next) { |
| 2054 | |
| 2055 | bio->bi_flags &= ~(BIO_POOL_MASK - 1); |
| 2056 | if (bio->bi_end_io) |
| 2057 | bio->bi_flags |= 1 << BIO_UPTODATE; |
| 2058 | bio->bi_vcnt = 0; |
| 2059 | bio->bi_idx = 0; |
| 2060 | bio->bi_phys_segments = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | bio->bi_size = 0; |
| 2062 | } |
| 2063 | |
| 2064 | nr_sectors = 0; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2065 | if (sector_nr + max_sync < max_sector) |
| 2066 | max_sector = sector_nr + max_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | do { |
| 2068 | struct page *page; |
| 2069 | int len = PAGE_SIZE; |
| 2070 | disk = 0; |
| 2071 | if (sector_nr + (len>>9) > max_sector) |
| 2072 | len = (max_sector - sector_nr) << 9; |
| 2073 | if (len == 0) |
| 2074 | break; |
| 2075 | for (bio= biolist ; bio ; bio=bio->bi_next) { |
| 2076 | page = bio->bi_io_vec[bio->bi_vcnt].bv_page; |
| 2077 | if (bio_add_page(bio, page, len, 0) == 0) { |
| 2078 | /* stop here */ |
| 2079 | struct bio *bio2; |
| 2080 | bio->bi_io_vec[bio->bi_vcnt].bv_page = page; |
| 2081 | for (bio2 = biolist; bio2 && bio2 != bio; bio2 = bio2->bi_next) { |
| 2082 | /* remove last page from this bio */ |
| 2083 | bio2->bi_vcnt--; |
| 2084 | bio2->bi_size -= len; |
| 2085 | bio2->bi_flags &= ~(1<< BIO_SEG_VALID); |
| 2086 | } |
| 2087 | goto bio_full; |
| 2088 | } |
| 2089 | disk = i; |
| 2090 | } |
| 2091 | nr_sectors += len>>9; |
| 2092 | sector_nr += len>>9; |
| 2093 | } while (biolist->bi_vcnt < RESYNC_PAGES); |
| 2094 | bio_full: |
| 2095 | r10_bio->sectors = nr_sectors; |
| 2096 | |
| 2097 | while (biolist) { |
| 2098 | bio = biolist; |
| 2099 | biolist = biolist->bi_next; |
| 2100 | |
| 2101 | bio->bi_next = NULL; |
| 2102 | r10_bio = bio->bi_private; |
| 2103 | r10_bio->sectors = nr_sectors; |
| 2104 | |
| 2105 | if (bio->bi_end_io == end_sync_read) { |
| 2106 | md_sync_acct(bio->bi_bdev, nr_sectors); |
| 2107 | generic_make_request(bio); |
| 2108 | } |
| 2109 | } |
| 2110 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 2111 | if (sectors_skipped) |
| 2112 | /* pretend they weren't skipped, it makes |
| 2113 | * no important difference in this case |
| 2114 | */ |
| 2115 | md_done_sync(mddev, sectors_skipped, 1); |
| 2116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | return sectors_skipped + nr_sectors; |
| 2118 | giveup: |
| 2119 | /* There is nowhere to write, so all non-sync |
| 2120 | * drives must be failed, so try the next chunk... |
| 2121 | */ |
NeilBrown | 09b4068 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 2122 | if (sector_nr + max_sync < max_sector) |
| 2123 | max_sector = sector_nr + max_sync; |
| 2124 | |
| 2125 | sectors_skipped += (max_sector - sector_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | chunks_skipped ++; |
| 2127 | sector_nr = max_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | goto skipped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 2131 | static sector_t |
| 2132 | raid10_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
| 2133 | { |
| 2134 | sector_t size; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 2135 | conf_t *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 2136 | |
| 2137 | if (!raid_disks) |
| 2138 | raid_disks = mddev->raid_disks; |
| 2139 | if (!sectors) |
| 2140 | sectors = mddev->dev_sectors; |
| 2141 | |
| 2142 | size = sectors >> conf->chunk_shift; |
| 2143 | sector_div(size, conf->far_copies); |
| 2144 | size = size * raid_disks; |
| 2145 | sector_div(size, conf->near_copies); |
| 2146 | |
| 2147 | return size << conf->chunk_shift; |
| 2148 | } |
| 2149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | static int run(mddev_t *mddev) |
| 2151 | { |
| 2152 | conf_t *conf; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 2153 | int i, disk_idx, chunk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | mirror_info_t *disk; |
| 2155 | mdk_rdev_t *rdev; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 2156 | int nc, fc, fo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | sector_t stride, size; |
| 2158 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 2159 | if (mddev->chunk_sectors < (PAGE_SIZE >> 9) || |
| 2160 | !is_power_of_2(mddev->chunk_sectors)) { |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 2161 | printk(KERN_ERR "md/raid10: chunk size must be " |
raz ben yehuda | 964e791 | 2009-06-16 17:01:22 +1000 | [diff] [blame] | 2162 | "at least PAGE_SIZE(%ld) and be a power of 2.\n", PAGE_SIZE); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2163 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | nc = mddev->layout & 255; |
| 2167 | fc = (mddev->layout >> 8) & 255; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 2168 | fo = mddev->layout & (1<<16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | if ((nc*fc) <2 || (nc*fc) > mddev->raid_disks || |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 2170 | (mddev->layout >> 17)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | printk(KERN_ERR "raid10: %s: unsupported raid10 layout: 0x%8x\n", |
| 2172 | mdname(mddev), mddev->layout); |
| 2173 | goto out; |
| 2174 | } |
| 2175 | /* |
| 2176 | * copy the already verified devices into our private RAID10 |
| 2177 | * bookkeeping area. [whatever we allocate in run(), |
| 2178 | * should be freed in stop()] |
| 2179 | */ |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 2180 | conf = kzalloc(sizeof(conf_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | mddev->private = conf; |
| 2182 | if (!conf) { |
| 2183 | printk(KERN_ERR "raid10: couldn't allocate memory for %s\n", |
| 2184 | mdname(mddev)); |
| 2185 | goto out; |
| 2186 | } |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 2187 | conf->mirrors = kzalloc(sizeof(struct mirror_info)*mddev->raid_disks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | GFP_KERNEL); |
| 2189 | if (!conf->mirrors) { |
| 2190 | printk(KERN_ERR "raid10: couldn't allocate memory for %s\n", |
| 2191 | mdname(mddev)); |
| 2192 | goto out_free_conf; |
| 2193 | } |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 2194 | |
| 2195 | conf->tmppage = alloc_page(GFP_KERNEL); |
| 2196 | if (!conf->tmppage) |
| 2197 | goto out_free_conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 2199 | conf->raid_disks = mddev->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | conf->near_copies = nc; |
| 2201 | conf->far_copies = fc; |
| 2202 | conf->copies = nc*fc; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 2203 | conf->far_offset = fo; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 2204 | conf->chunk_mask = mddev->chunk_sectors - 1; |
| 2205 | conf->chunk_shift = ffz(~mddev->chunk_sectors); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2206 | size = mddev->dev_sectors >> conf->chunk_shift; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 2207 | sector_div(size, fc); |
| 2208 | size = size * conf->raid_disks; |
| 2209 | sector_div(size, nc); |
| 2210 | /* 'size' is now the number of chunks in the array */ |
| 2211 | /* calculate "used chunks per device" in 'stride' */ |
| 2212 | stride = size * conf->copies; |
NeilBrown | af03b8e | 2007-06-16 10:16:06 -0700 | [diff] [blame] | 2213 | |
| 2214 | /* We need to round up when dividing by raid_disks to |
| 2215 | * get the stride size. |
| 2216 | */ |
| 2217 | stride += conf->raid_disks - 1; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 2218 | sector_div(stride, conf->raid_disks); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2219 | mddev->dev_sectors = stride << conf->chunk_shift; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 2220 | |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 2221 | if (fo) |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 2222 | stride = 1; |
| 2223 | else |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 2224 | sector_div(stride, fc); |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 2225 | conf->stride = stride << conf->chunk_shift; |
| 2226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc, |
| 2228 | r10bio_pool_free, conf); |
| 2229 | if (!conf->r10bio_pool) { |
| 2230 | printk(KERN_ERR "raid10: couldn't allocate memory for %s\n", |
| 2231 | mdname(mddev)); |
| 2232 | goto out_free_conf; |
| 2233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | |
NeilBrown | ed9bfdf | 2009-10-16 15:55:44 +1100 | [diff] [blame] | 2235 | conf->mddev = mddev; |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 2236 | spin_lock_init(&conf->device_lock); |
| 2237 | mddev->queue->queue_lock = &conf->device_lock; |
| 2238 | |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 2239 | chunk_size = mddev->chunk_sectors << 9; |
| 2240 | blk_queue_io_min(mddev->queue, chunk_size); |
| 2241 | if (conf->raid_disks % conf->near_copies) |
| 2242 | blk_queue_io_opt(mddev->queue, chunk_size * conf->raid_disks); |
| 2243 | else |
| 2244 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 2245 | (conf->raid_disks / conf->near_copies)); |
| 2246 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 2247 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | disk_idx = rdev->raid_disk; |
| 2249 | if (disk_idx >= mddev->raid_disks |
| 2250 | || disk_idx < 0) |
| 2251 | continue; |
| 2252 | disk = conf->mirrors + disk_idx; |
| 2253 | |
| 2254 | disk->rdev = rdev; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 2255 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 2256 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | /* as we don't honour merge_bvec_fn, we must never risk |
| 2258 | * violating it, so limit ->max_sector to one PAGE, as |
| 2259 | * a one page request is never in violation. |
| 2260 | */ |
| 2261 | if (rdev->bdev->bd_disk->queue->merge_bvec_fn && |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 2262 | queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9)) |
| 2263 | blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | |
| 2265 | disk->head_position = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | INIT_LIST_HEAD(&conf->retry_list); |
| 2268 | |
| 2269 | spin_lock_init(&conf->resync_lock); |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 2270 | init_waitqueue_head(&conf->wait_barrier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
NeilBrown | 6d50824 | 2005-09-09 16:24:03 -0700 | [diff] [blame] | 2272 | /* need to check that every block has at least one working mirror */ |
| 2273 | if (!enough(conf)) { |
| 2274 | printk(KERN_ERR "raid10: not enough operational mirrors for %s\n", |
| 2275 | mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | goto out_free_conf; |
| 2277 | } |
| 2278 | |
| 2279 | mddev->degraded = 0; |
| 2280 | for (i = 0; i < conf->raid_disks; i++) { |
| 2281 | |
| 2282 | disk = conf->mirrors + i; |
| 2283 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 2284 | if (!disk->rdev || |
NeilBrown | 2e333e8 | 2006-10-21 10:24:07 -0700 | [diff] [blame] | 2285 | !test_bit(In_sync, &disk->rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | disk->head_position = 0; |
| 2287 | mddev->degraded++; |
Neil Brown | 8c2e870 | 2008-06-28 08:30:52 +1000 | [diff] [blame] | 2288 | if (disk->rdev) |
| 2289 | conf->fullsync = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 2294 | mddev->thread = md_register_thread(raid10d, mddev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | if (!mddev->thread) { |
| 2296 | printk(KERN_ERR |
| 2297 | "raid10: couldn't allocate thread for %s\n", |
| 2298 | mdname(mddev)); |
| 2299 | goto out_free_conf; |
| 2300 | } |
| 2301 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 2302 | if (mddev->recovery_cp != MaxSector) |
| 2303 | printk(KERN_NOTICE "raid10: %s is not clean" |
| 2304 | " -- starting background reconstruction\n", |
| 2305 | mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | printk(KERN_INFO |
| 2307 | "raid10: raid set %s active with %d out of %d devices\n", |
| 2308 | mdname(mddev), mddev->raid_disks - mddev->degraded, |
| 2309 | mddev->raid_disks); |
| 2310 | /* |
| 2311 | * Ok, everything is just fine now |
| 2312 | */ |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 2313 | md_set_array_sectors(mddev, raid10_size(mddev, 0, 0)); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 2314 | mddev->resync_max_sectors = raid10_size(mddev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 2316 | mddev->queue->unplug_fn = raid10_unplug; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 2317 | mddev->queue->backing_dev_info.congested_fn = raid10_congested; |
| 2318 | mddev->queue->backing_dev_info.congested_data = mddev; |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 2319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | /* Calculate max read-ahead size. |
| 2321 | * We need to readahead at least twice a whole stripe.... |
| 2322 | * maybe... |
| 2323 | */ |
| 2324 | { |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 2325 | int stripe = conf->raid_disks * |
| 2326 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | stripe /= conf->near_copies; |
| 2328 | if (mddev->queue->backing_dev_info.ra_pages < 2* stripe) |
| 2329 | mddev->queue->backing_dev_info.ra_pages = 2* stripe; |
| 2330 | } |
| 2331 | |
| 2332 | if (conf->near_copies < mddev->raid_disks) |
| 2333 | blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec); |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 2334 | md_integrity_register(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | return 0; |
| 2336 | |
| 2337 | out_free_conf: |
| 2338 | if (conf->r10bio_pool) |
| 2339 | mempool_destroy(conf->r10bio_pool); |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 2340 | safe_put_page(conf->tmppage); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 2341 | kfree(conf->mirrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | kfree(conf); |
| 2343 | mddev->private = NULL; |
| 2344 | out: |
| 2345 | return -EIO; |
| 2346 | } |
| 2347 | |
| 2348 | static int stop(mddev_t *mddev) |
| 2349 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 2350 | conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 2352 | raise_barrier(conf, 0); |
| 2353 | lower_barrier(conf); |
| 2354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | md_unregister_thread(mddev->thread); |
| 2356 | mddev->thread = NULL; |
| 2357 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
| 2358 | if (conf->r10bio_pool) |
| 2359 | mempool_destroy(conf->r10bio_pool); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 2360 | kfree(conf->mirrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | kfree(conf); |
| 2362 | mddev->private = NULL; |
| 2363 | return 0; |
| 2364 | } |
| 2365 | |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2366 | static void raid10_quiesce(mddev_t *mddev, int state) |
| 2367 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 2368 | conf_t *conf = mddev->private; |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2369 | |
| 2370 | switch(state) { |
| 2371 | case 1: |
| 2372 | raise_barrier(conf, 0); |
| 2373 | break; |
| 2374 | case 0: |
| 2375 | lower_barrier(conf); |
| 2376 | break; |
| 2377 | } |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2380 | static struct mdk_personality raid10_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | { |
| 2382 | .name = "raid10", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2383 | .level = 10, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | .owner = THIS_MODULE, |
| 2385 | .make_request = make_request, |
| 2386 | .run = run, |
| 2387 | .stop = stop, |
| 2388 | .status = status, |
| 2389 | .error_handler = error, |
| 2390 | .hot_add_disk = raid10_add_disk, |
| 2391 | .hot_remove_disk= raid10_remove_disk, |
| 2392 | .spare_active = raid10_spare_active, |
| 2393 | .sync_request = sync_request, |
NeilBrown | 6cce3b23 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2394 | .quiesce = raid10_quiesce, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 2395 | .size = raid10_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | }; |
| 2397 | |
| 2398 | static int __init raid_init(void) |
| 2399 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2400 | return register_md_personality(&raid10_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | static void raid_exit(void) |
| 2404 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2405 | unregister_md_personality(&raid10_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | module_init(raid_init); |
| 2409 | module_exit(raid_exit); |
| 2410 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 2411 | MODULE_DESCRIPTION("RAID10 (striped mirror) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | MODULE_ALIAS("md-personality-9"); /* RAID10 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 2413 | MODULE_ALIAS("md-raid10"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 2414 | MODULE_ALIAS("md-level-10"); |