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 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8 | * Base on code in raid1.c. See raid1.c for further copyright information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Stephen Rothwell | 2557072 | 2008-10-15 09:09:21 +1100 | [diff] [blame] | 22 | #include <linux/delay.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 23 | #include <linux/blkdev.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 25 | #include <linux/seq_file.h> |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 26 | #include <linux/ratelimit.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 27 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 28 | #include "raid10.h" |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 29 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 30 | #include "bitmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * RAID10 provides a combination of RAID0 and RAID1 functionality. |
| 34 | * The layout of data is defined by |
| 35 | * chunk_size |
| 36 | * raid_disks |
| 37 | * near_copies (stored in low byte of layout) |
| 38 | * far_copies (stored in second byte of layout) |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 39 | * far_offset (stored in bit 16 of layout ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * |
| 41 | * The data to be stored is divided into chunks using chunksize. |
| 42 | * Each device is divided into far_copies sections. |
| 43 | * In each section, chunks are laid out in a style similar to raid0, but |
| 44 | * near_copies copies of each chunk is stored (each on a different drive). |
| 45 | * The starting device for each section is offset near_copies from the starting |
| 46 | * device of the previous section. |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 47 | * 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] | 48 | * drive. |
| 49 | * near_copies and far_copies must be at least one, and their product is at most |
| 50 | * raid_disks. |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 51 | * |
| 52 | * If far_offset is true, then the far_copies are handled a bit differently. |
| 53 | * The copies are still in different stripes, but instead of be very far apart |
| 54 | * on disk, there are adjacent stripes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | */ |
| 56 | |
| 57 | /* |
| 58 | * Number of guaranteed r10bios in case of extreme VM load: |
| 59 | */ |
| 60 | #define NR_RAID10_BIOS 256 |
| 61 | |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 62 | /* When there are this many requests queue to be written by |
| 63 | * the raid10 thread, we become 'congested' to provide back-pressure |
| 64 | * for writeback. |
| 65 | */ |
| 66 | static int max_queued_requests = 1024; |
| 67 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 68 | static void allow_barrier(struct r10conf *conf); |
| 69 | static void lower_barrier(struct r10conf *conf); |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 70 | |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 71 | static void * r10bio_pool_alloc(gfp_t gfp_flags, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 73 | struct r10conf *conf = data; |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 74 | int size = offsetof(struct r10bio, devs[conf->copies]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 76 | /* allocate a r10bio with room for raid_disks entries in the |
| 77 | * bios array */ |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 78 | return kzalloc(size, gfp_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void r10bio_pool_free(void *r10_bio, void *data) |
| 82 | { |
| 83 | kfree(r10_bio); |
| 84 | } |
| 85 | |
NeilBrown | 0310fa2 | 2008-08-05 15:54:14 +1000 | [diff] [blame] | 86 | /* Maximum size of each resync request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #define RESYNC_BLOCK_SIZE (64*1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE) |
NeilBrown | 0310fa2 | 2008-08-05 15:54:14 +1000 | [diff] [blame] | 89 | /* amount of memory to reserve for resync requests */ |
| 90 | #define RESYNC_WINDOW (1024*1024) |
| 91 | /* maximum number of concurrent requests, memory permitting */ |
| 92 | #define RESYNC_DEPTH (32*1024*1024/RESYNC_BLOCK_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * When performing a resync, we need to read and compare, so |
| 96 | * we need as many pages are there are copies. |
| 97 | * When performing a recovery, we need 2 bios, one for read, |
| 98 | * one for write (we recover only one drive per r10buf) |
| 99 | * |
| 100 | */ |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 101 | static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 103 | struct r10conf *conf = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | struct page *page; |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 105 | struct r10bio *r10_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | struct bio *bio; |
| 107 | int i, j; |
| 108 | int nalloc; |
| 109 | |
| 110 | r10_bio = r10bio_pool_alloc(gfp_flags, conf); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 111 | if (!r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | if (test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery)) |
| 115 | nalloc = conf->copies; /* resync */ |
| 116 | else |
| 117 | nalloc = 2; /* recovery */ |
| 118 | |
| 119 | /* |
| 120 | * Allocate bios. |
| 121 | */ |
| 122 | for (j = nalloc ; j-- ; ) { |
NeilBrown | 6746557 | 2010-10-26 17:33:54 +1100 | [diff] [blame] | 123 | bio = bio_kmalloc(gfp_flags, RESYNC_PAGES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (!bio) |
| 125 | goto out_free_bio; |
| 126 | r10_bio->devs[j].bio = bio; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 127 | if (!conf->have_replacement) |
| 128 | continue; |
| 129 | bio = bio_kmalloc(gfp_flags, RESYNC_PAGES); |
| 130 | if (!bio) |
| 131 | goto out_free_bio; |
| 132 | r10_bio->devs[j].repl_bio = bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | /* |
| 135 | * Allocate RESYNC_PAGES data pages and attach them |
| 136 | * where needed. |
| 137 | */ |
| 138 | for (j = 0 ; j < nalloc; j++) { |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 139 | struct bio *rbio = r10_bio->devs[j].repl_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | bio = r10_bio->devs[j].bio; |
| 141 | for (i = 0; i < RESYNC_PAGES; i++) { |
Namhyung Kim | c65060a | 2011-07-18 17:38:49 +1000 | [diff] [blame] | 142 | if (j == 1 && !test_bit(MD_RECOVERY_SYNC, |
| 143 | &conf->mddev->recovery)) { |
| 144 | /* we can share bv_page's during recovery */ |
| 145 | struct bio *rbio = r10_bio->devs[0].bio; |
| 146 | page = rbio->bi_io_vec[i].bv_page; |
| 147 | get_page(page); |
| 148 | } else |
| 149 | page = alloc_page(gfp_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | if (unlikely(!page)) |
| 151 | goto out_free_pages; |
| 152 | |
| 153 | bio->bi_io_vec[i].bv_page = page; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 154 | if (rbio) |
| 155 | rbio->bi_io_vec[i].bv_page = page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
| 159 | return r10_bio; |
| 160 | |
| 161 | out_free_pages: |
| 162 | for ( ; i > 0 ; i--) |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 163 | safe_put_page(bio->bi_io_vec[i-1].bv_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | while (j--) |
| 165 | for (i = 0; i < RESYNC_PAGES ; i++) |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 166 | 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] | 167 | j = -1; |
| 168 | out_free_bio: |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 169 | while (++j < nalloc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | bio_put(r10_bio->devs[j].bio); |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 171 | if (r10_bio->devs[j].repl_bio) |
| 172 | bio_put(r10_bio->devs[j].repl_bio); |
| 173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | r10bio_pool_free(r10_bio, conf); |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | static void r10buf_pool_free(void *__r10_bio, void *data) |
| 179 | { |
| 180 | int i; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 181 | struct r10conf *conf = data; |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 182 | struct r10bio *r10bio = __r10_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | int j; |
| 184 | |
| 185 | for (j=0; j < conf->copies; j++) { |
| 186 | struct bio *bio = r10bio->devs[j].bio; |
| 187 | if (bio) { |
| 188 | for (i = 0; i < RESYNC_PAGES; i++) { |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 189 | safe_put_page(bio->bi_io_vec[i].bv_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | bio->bi_io_vec[i].bv_page = NULL; |
| 191 | } |
| 192 | bio_put(bio); |
| 193 | } |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 194 | bio = r10bio->devs[j].repl_bio; |
| 195 | if (bio) |
| 196 | bio_put(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | r10bio_pool_free(r10bio, conf); |
| 199 | } |
| 200 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 201 | static void put_all_bios(struct r10conf *conf, struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
| 203 | int i; |
| 204 | |
| 205 | for (i = 0; i < conf->copies; i++) { |
| 206 | struct bio **bio = & r10_bio->devs[i].bio; |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 207 | if (!BIO_SPECIAL(*bio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | bio_put(*bio); |
| 209 | *bio = NULL; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 210 | bio = &r10_bio->devs[i].repl_bio; |
| 211 | if (r10_bio->read_slot < 0 && !BIO_SPECIAL(*bio)) |
| 212 | bio_put(*bio); |
| 213 | *bio = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 217 | static void free_r10bio(struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 219 | struct r10conf *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | put_all_bios(conf, r10_bio); |
| 222 | mempool_free(r10_bio, conf->r10bio_pool); |
| 223 | } |
| 224 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 225 | static void put_buf(struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 227 | struct r10conf *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | mempool_free(r10_bio, conf->r10buf_pool); |
| 230 | |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 231 | lower_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 234 | static void reschedule_retry(struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
| 236 | unsigned long flags; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 237 | struct mddev *mddev = r10_bio->mddev; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 238 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | spin_lock_irqsave(&conf->device_lock, flags); |
| 241 | list_add(&r10_bio->retry_list, &conf->retry_list); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 242 | conf->nr_queued ++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 244 | |
Arthur Jones | 388667b | 2008-07-25 12:03:38 -0700 | [diff] [blame] | 245 | /* wake up frozen array... */ |
| 246 | wake_up(&conf->wait_barrier); |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | md_wakeup_thread(mddev->thread); |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * raid_end_bio_io() is called when we have finished servicing a mirrored |
| 253 | * operation and are ready to return a success/failure code to the buffer |
| 254 | * cache layer. |
| 255 | */ |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 256 | static void raid_end_bio_io(struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
| 258 | struct bio *bio = r10_bio->master_bio; |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 259 | int done; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 260 | struct r10conf *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 262 | if (bio->bi_phys_segments) { |
| 263 | unsigned long flags; |
| 264 | spin_lock_irqsave(&conf->device_lock, flags); |
| 265 | bio->bi_phys_segments--; |
| 266 | done = (bio->bi_phys_segments == 0); |
| 267 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 268 | } else |
| 269 | done = 1; |
| 270 | if (!test_bit(R10BIO_Uptodate, &r10_bio->state)) |
| 271 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
| 272 | if (done) { |
| 273 | bio_endio(bio, 0); |
| 274 | /* |
| 275 | * Wake up any possible resync thread that waits for the device |
| 276 | * to go idle. |
| 277 | */ |
| 278 | allow_barrier(conf); |
| 279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | free_r10bio(r10_bio); |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Update disk head position estimator based on IRQ completion info. |
| 285 | */ |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 286 | static inline void update_head_pos(int slot, struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 288 | struct r10conf *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | conf->mirrors[r10_bio->devs[slot].devnum].head_position = |
| 291 | r10_bio->devs[slot].addr + (r10_bio->sectors); |
| 292 | } |
| 293 | |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 294 | /* |
| 295 | * Find the disk number which triggered given bio |
| 296 | */ |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 297 | static int find_bio_disk(struct r10conf *conf, struct r10bio *r10_bio, |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 298 | struct bio *bio, int *slotp, int *replp) |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 299 | { |
| 300 | int slot; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 301 | int repl = 0; |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 302 | |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 303 | for (slot = 0; slot < conf->copies; slot++) { |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 304 | if (r10_bio->devs[slot].bio == bio) |
| 305 | break; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 306 | if (r10_bio->devs[slot].repl_bio == bio) { |
| 307 | repl = 1; |
| 308 | break; |
| 309 | } |
| 310 | } |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 311 | |
| 312 | BUG_ON(slot == conf->copies); |
| 313 | update_head_pos(slot, r10_bio); |
| 314 | |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 315 | if (slotp) |
| 316 | *slotp = slot; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 317 | if (replp) |
| 318 | *replp = repl; |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 319 | return r10_bio->devs[slot].devnum; |
| 320 | } |
| 321 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 322 | static void raid10_end_read_request(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
| 324 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 325 | struct r10bio *r10_bio = bio->bi_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | int slot, dev; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 327 | struct md_rdev *rdev; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 328 | struct r10conf *conf = r10_bio->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | slot = r10_bio->read_slot; |
| 332 | dev = r10_bio->devs[slot].devnum; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 333 | rdev = r10_bio->devs[slot].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* |
| 335 | * this branch is our 'one mirror IO has finished' event handler: |
| 336 | */ |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 337 | update_head_pos(slot, r10_bio); |
| 338 | |
| 339 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* |
| 341 | * Set R10BIO_Uptodate in our master bio, so that |
| 342 | * we will return a good error code to the higher |
| 343 | * levels even if IO on some other mirrored buffer fails. |
| 344 | * |
| 345 | * The 'master' represents the composite IO operation to |
| 346 | * user-side. So if something waits for IO, then it will |
| 347 | * wait for the 'master' bio. |
| 348 | */ |
| 349 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | raid_end_bio_io(r10_bio); |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 351 | rdev_dec_pending(rdev, conf->mddev); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 352 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | /* |
NeilBrown | 7c4e06f | 2011-05-11 14:53:17 +1000 | [diff] [blame] | 354 | * oops, read error - keep the refcount on the rdev |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | */ |
| 356 | char b[BDEVNAME_SIZE]; |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 357 | printk_ratelimited(KERN_ERR |
| 358 | "md/raid10:%s: %s: rescheduling sector %llu\n", |
| 359 | mdname(conf->mddev), |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 360 | bdevname(rdev->bdev, b), |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 361 | (unsigned long long)r10_bio->sector); |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 362 | set_bit(R10BIO_ReadError, &r10_bio->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | reschedule_retry(r10_bio); |
| 364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 367 | static void close_write(struct r10bio *r10_bio) |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 368 | { |
| 369 | /* clear the bitmap if all writes complete successfully */ |
| 370 | bitmap_endwrite(r10_bio->mddev->bitmap, r10_bio->sector, |
| 371 | r10_bio->sectors, |
| 372 | !test_bit(R10BIO_Degraded, &r10_bio->state), |
| 373 | 0); |
| 374 | md_write_end(r10_bio->mddev); |
| 375 | } |
| 376 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 377 | static void one_write_done(struct r10bio *r10_bio) |
NeilBrown | 19d5f83 | 2011-09-10 17:21:17 +1000 | [diff] [blame] | 378 | { |
| 379 | if (atomic_dec_and_test(&r10_bio->remaining)) { |
| 380 | if (test_bit(R10BIO_WriteError, &r10_bio->state)) |
| 381 | reschedule_retry(r10_bio); |
| 382 | else { |
| 383 | close_write(r10_bio); |
| 384 | if (test_bit(R10BIO_MadeGood, &r10_bio->state)) |
| 385 | reschedule_retry(r10_bio); |
| 386 | else |
| 387 | raid_end_bio_io(r10_bio); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 392 | static void raid10_end_write_request(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
| 394 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 395 | struct r10bio *r10_bio = bio->bi_private; |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 396 | int dev; |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 397 | int dec_rdev = 1; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 398 | struct r10conf *conf = r10_bio->mddev->private; |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 399 | int slot, repl; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 400 | struct md_rdev *rdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 402 | dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 404 | if (repl) |
| 405 | rdev = conf->mirrors[dev].replacement; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 406 | if (!rdev) { |
| 407 | smp_rmb(); |
| 408 | repl = 0; |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 409 | rdev = conf->mirrors[dev].rdev; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* |
| 412 | * this branch is our 'one mirror IO has finished' event handler: |
| 413 | */ |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 414 | if (!uptodate) { |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 415 | if (repl) |
| 416 | /* Never record new bad blocks to replacement, |
| 417 | * just fail it. |
| 418 | */ |
| 419 | md_error(rdev->mddev, rdev); |
| 420 | else { |
| 421 | set_bit(WriteErrorSeen, &rdev->flags); |
| 422 | set_bit(R10BIO_WriteError, &r10_bio->state); |
| 423 | dec_rdev = 0; |
| 424 | } |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 425 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* |
| 427 | * Set R10BIO_Uptodate in our master bio, so that |
| 428 | * we will return a good error code for to the higher |
| 429 | * levels even if IO on some other mirrored buffer fails. |
| 430 | * |
| 431 | * The 'master' represents the composite IO operation to |
| 432 | * user-side. So if something waits for IO, then it will |
| 433 | * wait for the 'master' bio. |
| 434 | */ |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 435 | sector_t first_bad; |
| 436 | int bad_sectors; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
| 439 | |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 440 | /* Maybe we can clear some bad blocks. */ |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 441 | if (is_badblock(rdev, |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 442 | r10_bio->devs[slot].addr, |
| 443 | r10_bio->sectors, |
| 444 | &first_bad, &bad_sectors)) { |
| 445 | bio_put(bio); |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 446 | if (repl) |
| 447 | r10_bio->devs[slot].repl_bio = IO_MADE_GOOD; |
| 448 | else |
| 449 | r10_bio->devs[slot].bio = IO_MADE_GOOD; |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 450 | dec_rdev = 0; |
| 451 | set_bit(R10BIO_MadeGood, &r10_bio->state); |
| 452 | } |
| 453 | } |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | /* |
| 456 | * |
| 457 | * Let's see if all mirrored write operations have finished |
| 458 | * already. |
| 459 | */ |
NeilBrown | 19d5f83 | 2011-09-10 17:21:17 +1000 | [diff] [blame] | 460 | one_write_done(r10_bio); |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 461 | if (dec_rdev) |
| 462 | rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | /* |
| 466 | * RAID10 layout manager |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 467 | * As well as the chunksize and raid_disks count, there are two |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | * parameters: near_copies and far_copies. |
| 469 | * near_copies * far_copies must be <= raid_disks. |
| 470 | * Normally one of these will be 1. |
| 471 | * If both are 1, we get raid0. |
| 472 | * If near_copies == raid_disks, we get raid1. |
| 473 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 474 | * Chunks are laid out in raid0 style with near_copies copies of the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | * first chunk, followed by near_copies copies of the next chunk and |
| 476 | * so on. |
| 477 | * If far_copies > 1, then after 1/far_copies of the array has been assigned |
| 478 | * as described above, we start again with a device offset of near_copies. |
| 479 | * So we effectively have another copy of the whole array further down all |
| 480 | * the drives, but with blocks on different drives. |
| 481 | * With this layout, and block is never stored twice on the one device. |
| 482 | * |
| 483 | * raid10_find_phys finds the sector offset of a given virtual sector |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 484 | * on each device that it is on. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | * |
| 486 | * raid10_find_virt does the reverse mapping, from a device and a |
| 487 | * sector offset to a virtual address |
| 488 | */ |
| 489 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 490 | static void raid10_find_phys(struct r10conf *conf, struct r10bio *r10bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
| 492 | int n,f; |
| 493 | sector_t sector; |
| 494 | sector_t chunk; |
| 495 | sector_t stripe; |
| 496 | int dev; |
| 497 | |
| 498 | int slot = 0; |
| 499 | |
| 500 | /* now calculate first sector/dev */ |
| 501 | chunk = r10bio->sector >> conf->chunk_shift; |
| 502 | sector = r10bio->sector & conf->chunk_mask; |
| 503 | |
| 504 | chunk *= conf->near_copies; |
| 505 | stripe = chunk; |
| 506 | dev = sector_div(stripe, conf->raid_disks); |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 507 | if (conf->far_offset) |
| 508 | stripe *= conf->far_copies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | sector += stripe << conf->chunk_shift; |
| 511 | |
| 512 | /* and calculate all the others */ |
| 513 | for (n=0; n < conf->near_copies; n++) { |
| 514 | int d = dev; |
| 515 | sector_t s = sector; |
| 516 | r10bio->devs[slot].addr = sector; |
| 517 | r10bio->devs[slot].devnum = d; |
| 518 | slot++; |
| 519 | |
| 520 | for (f = 1; f < conf->far_copies; f++) { |
| 521 | d += conf->near_copies; |
| 522 | if (d >= conf->raid_disks) |
| 523 | d -= conf->raid_disks; |
| 524 | s += conf->stride; |
| 525 | r10bio->devs[slot].devnum = d; |
| 526 | r10bio->devs[slot].addr = s; |
| 527 | slot++; |
| 528 | } |
| 529 | dev++; |
| 530 | if (dev >= conf->raid_disks) { |
| 531 | dev = 0; |
| 532 | sector += (conf->chunk_mask + 1); |
| 533 | } |
| 534 | } |
| 535 | BUG_ON(slot != conf->copies); |
| 536 | } |
| 537 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 538 | static sector_t raid10_find_virt(struct r10conf *conf, sector_t sector, int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
| 540 | sector_t offset, chunk, vchunk; |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | offset = sector & conf->chunk_mask; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 543 | if (conf->far_offset) { |
| 544 | int fc; |
| 545 | chunk = sector >> conf->chunk_shift; |
| 546 | fc = sector_div(chunk, conf->far_copies); |
| 547 | dev -= fc * conf->near_copies; |
| 548 | if (dev < 0) |
| 549 | dev += conf->raid_disks; |
| 550 | } else { |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 551 | while (sector >= conf->stride) { |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 552 | sector -= conf->stride; |
| 553 | if (dev < conf->near_copies) |
| 554 | dev += conf->raid_disks - conf->near_copies; |
| 555 | else |
| 556 | dev -= conf->near_copies; |
| 557 | } |
| 558 | chunk = sector >> conf->chunk_shift; |
| 559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | vchunk = chunk * conf->raid_disks + dev; |
| 561 | sector_div(vchunk, conf->near_copies); |
| 562 | return (vchunk << conf->chunk_shift) + offset; |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * raid10_mergeable_bvec -- tell bio layer if a two requests can be merged |
| 567 | * @q: request queue |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 568 | * @bvm: properties of new bio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | * @biovec: the request that could be merged to it. |
| 570 | * |
| 571 | * Return amount of bytes we can accept at this offset |
| 572 | * If near_copies == raid_disk, there are no striping issues, |
| 573 | * but in that case, the function isn't called at all. |
| 574 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 575 | static int raid10_mergeable_bvec(struct request_queue *q, |
| 576 | struct bvec_merge_data *bvm, |
| 577 | struct bio_vec *biovec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 579 | struct mddev *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 580 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 582 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 583 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
| 585 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 586 | 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] | 587 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 588 | return biovec->bv_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | else |
| 590 | return max; |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * This routine returns the disk from which the requested read should |
| 595 | * be done. There is a per-array 'next expected sequential IO' sector |
| 596 | * number - if this matches on the next IO then we use the last disk. |
| 597 | * There is also a per-disk 'last know head position' sector that is |
| 598 | * maintained from IRQ contexts, both the normal and the resync IO |
| 599 | * completion handlers update this position correctly. If there is no |
| 600 | * perfect sequential match then we pick the disk whose head is closest. |
| 601 | * |
| 602 | * If there are 2 mirrors in the same 2 devices, performance degrades |
| 603 | * because position is mirror, not device based. |
| 604 | * |
| 605 | * The rdev for the device selected will have nr_pending incremented. |
| 606 | */ |
| 607 | |
| 608 | /* |
| 609 | * FIXME: possibly should rethink readbalancing and do it differently |
| 610 | * depending on near_copies / far_copies geometry. |
| 611 | */ |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 612 | static struct md_rdev *read_balance(struct r10conf *conf, |
| 613 | struct r10bio *r10_bio, |
| 614 | int *max_sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
NeilBrown | af3a2cd | 2010-05-08 08:20:17 +1000 | [diff] [blame] | 616 | const sector_t this_sector = r10_bio->sector; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 617 | int disk, slot; |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 618 | int sectors = r10_bio->sectors; |
| 619 | int best_good_sectors; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 620 | sector_t new_distance, best_dist; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 621 | struct md_rdev *rdev, *best_rdev; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 622 | int do_balance; |
| 623 | int best_slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | raid10_find_phys(conf, r10_bio); |
| 626 | rcu_read_lock(); |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 627 | retry: |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 628 | sectors = r10_bio->sectors; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 629 | best_slot = -1; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 630 | best_rdev = NULL; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 631 | best_dist = MaxSector; |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 632 | best_good_sectors = 0; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 633 | do_balance = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | /* |
| 635 | * Check if we can balance. We can balance on the whole |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 636 | * device if no resync is going on (recovery is ok), or below |
| 637 | * the resync window. We take the first readable disk when |
| 638 | * above the resync window. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | */ |
| 640 | if (conf->mddev->recovery_cp < MaxSector |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 641 | && (this_sector + sectors >= conf->next_resync)) |
| 642 | do_balance = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 644 | for (slot = 0; slot < conf->copies ; slot++) { |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 645 | sector_t first_bad; |
| 646 | int bad_sectors; |
| 647 | sector_t dev_sector; |
| 648 | |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 649 | if (r10_bio->devs[slot].bio == IO_BLOCKED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | continue; |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 651 | disk = r10_bio->devs[slot].devnum; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 652 | rdev = rcu_dereference(conf->mirrors[disk].replacement); |
| 653 | if (rdev == NULL || test_bit(Faulty, &rdev->flags) || |
| 654 | r10_bio->devs[slot].addr + sectors > rdev->recovery_offset) |
| 655 | rdev = rcu_dereference(conf->mirrors[disk].rdev); |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 656 | if (rdev == NULL) |
| 657 | continue; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 658 | if (test_bit(Faulty, &rdev->flags)) |
| 659 | continue; |
| 660 | if (!test_bit(In_sync, &rdev->flags) && |
| 661 | r10_bio->devs[slot].addr + sectors > rdev->recovery_offset) |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 662 | continue; |
| 663 | |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 664 | dev_sector = r10_bio->devs[slot].addr; |
| 665 | if (is_badblock(rdev, dev_sector, sectors, |
| 666 | &first_bad, &bad_sectors)) { |
| 667 | if (best_dist < MaxSector) |
| 668 | /* Already have a better slot */ |
| 669 | continue; |
| 670 | if (first_bad <= dev_sector) { |
| 671 | /* Cannot read here. If this is the |
| 672 | * 'primary' device, then we must not read |
| 673 | * beyond 'bad_sectors' from another device. |
| 674 | */ |
| 675 | bad_sectors -= (dev_sector - first_bad); |
| 676 | if (!do_balance && sectors > bad_sectors) |
| 677 | sectors = bad_sectors; |
| 678 | if (best_good_sectors > sectors) |
| 679 | best_good_sectors = sectors; |
| 680 | } else { |
| 681 | sector_t good_sectors = |
| 682 | first_bad - dev_sector; |
| 683 | if (good_sectors > best_good_sectors) { |
| 684 | best_good_sectors = good_sectors; |
| 685 | best_slot = slot; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 686 | best_rdev = rdev; |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 687 | } |
| 688 | if (!do_balance) |
| 689 | /* Must read from here */ |
| 690 | break; |
| 691 | } |
| 692 | continue; |
| 693 | } else |
| 694 | best_good_sectors = sectors; |
| 695 | |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 696 | if (!do_balance) |
| 697 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
NeilBrown | 22dfdf5 | 2005-11-28 13:44:09 -0800 | [diff] [blame] | 699 | /* This optimisation is debatable, and completely destroys |
| 700 | * sequential read speed for 'far copies' arrays. So only |
| 701 | * keep it for 'near' arrays, and review those later. |
| 702 | */ |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 703 | if (conf->near_copies > 1 && !atomic_read(&rdev->nr_pending)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | break; |
Keld Simonsen | 8ed3a19 | 2008-03-04 14:29:34 -0800 | [diff] [blame] | 705 | |
| 706 | /* for far > 1 always use the lowest address */ |
| 707 | if (conf->far_copies > 1) |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 708 | new_distance = r10_bio->devs[slot].addr; |
Keld Simonsen | 8ed3a19 | 2008-03-04 14:29:34 -0800 | [diff] [blame] | 709 | else |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 710 | new_distance = abs(r10_bio->devs[slot].addr - |
| 711 | conf->mirrors[disk].head_position); |
| 712 | if (new_distance < best_dist) { |
| 713 | best_dist = new_distance; |
| 714 | best_slot = slot; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 715 | best_rdev = rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 718 | if (slot >= conf->copies) { |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 719 | slot = best_slot; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 720 | rdev = best_rdev; |
| 721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 723 | if (slot >= 0) { |
NeilBrown | 56d9912 | 2011-05-11 14:27:03 +1000 | [diff] [blame] | 724 | atomic_inc(&rdev->nr_pending); |
| 725 | if (test_bit(Faulty, &rdev->flags)) { |
| 726 | /* Cannot risk returning a device that failed |
| 727 | * before we inc'ed nr_pending |
| 728 | */ |
| 729 | rdev_dec_pending(rdev, conf->mddev); |
| 730 | goto retry; |
| 731 | } |
| 732 | r10_bio->read_slot = slot; |
| 733 | } else |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 734 | rdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | rcu_read_unlock(); |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 736 | *max_sectors = best_good_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 738 | return rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 741 | static int raid10_congested(void *data, int bits) |
| 742 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 743 | struct mddev *mddev = data; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 744 | struct r10conf *conf = mddev->private; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 745 | int i, ret = 0; |
| 746 | |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 747 | if ((bits & (1 << BDI_async_congested)) && |
| 748 | conf->pending_count >= max_queued_requests) |
| 749 | return 1; |
| 750 | |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 751 | if (mddev_congested(mddev, bits)) |
| 752 | return 1; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 753 | rcu_read_lock(); |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 754 | for (i = 0; i < conf->raid_disks && ret == 0; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 755 | struct md_rdev *rdev = rcu_dereference(conf->mirrors[i].rdev); |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 756 | if (rdev && !test_bit(Faulty, &rdev->flags)) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 757 | struct request_queue *q = bdev_get_queue(rdev->bdev); |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 758 | |
| 759 | ret |= bdi_congested(&q->backing_dev_info, bits); |
| 760 | } |
| 761 | } |
| 762 | rcu_read_unlock(); |
| 763 | return ret; |
| 764 | } |
| 765 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 766 | static void flush_pending_writes(struct r10conf *conf) |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 767 | { |
| 768 | /* Any writes that have been queued but are awaiting |
| 769 | * bitmap updates get flushed here. |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 770 | */ |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 771 | spin_lock_irq(&conf->device_lock); |
| 772 | |
| 773 | if (conf->pending_bio_list.head) { |
| 774 | struct bio *bio; |
| 775 | bio = bio_list_get(&conf->pending_bio_list); |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 776 | conf->pending_count = 0; |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 777 | spin_unlock_irq(&conf->device_lock); |
| 778 | /* flush any pending bitmap writes to disk |
| 779 | * before proceeding w/ I/O */ |
| 780 | bitmap_unplug(conf->mddev->bitmap); |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 781 | wake_up(&conf->wait_barrier); |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 782 | |
| 783 | while (bio) { /* submit pending writes */ |
| 784 | struct bio *next = bio->bi_next; |
| 785 | bio->bi_next = NULL; |
| 786 | generic_make_request(bio); |
| 787 | bio = next; |
| 788 | } |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 789 | } else |
| 790 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 791 | } |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 792 | |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 793 | /* Barriers.... |
| 794 | * Sometimes we need to suspend IO while we do something else, |
| 795 | * either some resync/recovery, or reconfigure the array. |
| 796 | * To do this we raise a 'barrier'. |
| 797 | * The 'barrier' is a counter that can be raised multiple times |
| 798 | * to count how many activities are happening which preclude |
| 799 | * normal IO. |
| 800 | * We can only raise the barrier if there is no pending IO. |
| 801 | * i.e. if nr_pending == 0. |
| 802 | * We choose only to raise the barrier if no-one is waiting for the |
| 803 | * barrier to go down. This means that as soon as an IO request |
| 804 | * is ready, no other operations which require a barrier will start |
| 805 | * until the IO request has had a chance. |
| 806 | * |
| 807 | * So: regular IO calls 'wait_barrier'. When that returns there |
| 808 | * is no backgroup IO happening, It must arrange to call |
| 809 | * allow_barrier when it has finished its IO. |
| 810 | * backgroup IO calls must call raise_barrier. Once that returns |
| 811 | * there is no normal IO happeing. It must arrange to call |
| 812 | * lower_barrier when the particular background IO completes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 815 | static void raise_barrier(struct r10conf *conf, int force) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | { |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 817 | BUG_ON(force && !conf->barrier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | spin_lock_irq(&conf->resync_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 820 | /* Wait until no block IO is waiting (unless 'force') */ |
| 821 | wait_event_lock_irq(conf->wait_barrier, force || !conf->nr_waiting, |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 822 | conf->resync_lock, ); |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 823 | |
| 824 | /* block any new IO from starting */ |
| 825 | conf->barrier++; |
| 826 | |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 827 | /* Now wait for all pending IO to complete */ |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 828 | wait_event_lock_irq(conf->wait_barrier, |
| 829 | !conf->nr_pending && conf->barrier < RESYNC_DEPTH, |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 830 | conf->resync_lock, ); |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | spin_unlock_irq(&conf->resync_lock); |
| 833 | } |
| 834 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 835 | static void lower_barrier(struct r10conf *conf) |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 836 | { |
| 837 | unsigned long flags; |
| 838 | spin_lock_irqsave(&conf->resync_lock, flags); |
| 839 | conf->barrier--; |
| 840 | spin_unlock_irqrestore(&conf->resync_lock, flags); |
| 841 | wake_up(&conf->wait_barrier); |
| 842 | } |
| 843 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 844 | static void wait_barrier(struct r10conf *conf) |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 845 | { |
| 846 | spin_lock_irq(&conf->resync_lock); |
| 847 | if (conf->barrier) { |
| 848 | conf->nr_waiting++; |
| 849 | wait_event_lock_irq(conf->wait_barrier, !conf->barrier, |
| 850 | conf->resync_lock, |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 851 | ); |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 852 | conf->nr_waiting--; |
| 853 | } |
| 854 | conf->nr_pending++; |
| 855 | spin_unlock_irq(&conf->resync_lock); |
| 856 | } |
| 857 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 858 | static void allow_barrier(struct r10conf *conf) |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 859 | { |
| 860 | unsigned long flags; |
| 861 | spin_lock_irqsave(&conf->resync_lock, flags); |
| 862 | conf->nr_pending--; |
| 863 | spin_unlock_irqrestore(&conf->resync_lock, flags); |
| 864 | wake_up(&conf->wait_barrier); |
| 865 | } |
| 866 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 867 | static void freeze_array(struct r10conf *conf) |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 868 | { |
| 869 | /* stop syncio and normal IO and wait for everything to |
NeilBrown | f188593 | 2006-01-06 00:20:42 -0800 | [diff] [blame] | 870 | * go quiet. |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 871 | * We increment barrier and nr_waiting, and then |
NeilBrown | 1c83053 | 2008-03-04 14:29:35 -0800 | [diff] [blame] | 872 | * wait until nr_pending match nr_queued+1 |
| 873 | * This is called in the context of one normal IO request |
| 874 | * that has failed. Thus any sync request that might be pending |
| 875 | * will be blocked by nr_pending, and we need to wait for |
| 876 | * pending IO requests to complete or be queued for re-try. |
| 877 | * Thus the number queued (nr_queued) plus this request (1) |
| 878 | * must match the number of pending IOs (nr_pending) before |
| 879 | * we continue. |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 880 | */ |
| 881 | spin_lock_irq(&conf->resync_lock); |
| 882 | conf->barrier++; |
| 883 | conf->nr_waiting++; |
| 884 | wait_event_lock_irq(conf->wait_barrier, |
NeilBrown | 1c83053 | 2008-03-04 14:29:35 -0800 | [diff] [blame] | 885 | conf->nr_pending == conf->nr_queued+1, |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 886 | conf->resync_lock, |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 887 | flush_pending_writes(conf)); |
| 888 | |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 889 | spin_unlock_irq(&conf->resync_lock); |
| 890 | } |
| 891 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 892 | static void unfreeze_array(struct r10conf *conf) |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 893 | { |
| 894 | /* reverse the effect of the freeze */ |
| 895 | spin_lock_irq(&conf->resync_lock); |
| 896 | conf->barrier--; |
| 897 | conf->nr_waiting--; |
| 898 | wake_up(&conf->wait_barrier); |
| 899 | spin_unlock_irq(&conf->resync_lock); |
| 900 | } |
| 901 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame] | 902 | static void make_request(struct mddev *mddev, struct bio * bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 904 | struct r10conf *conf = mddev->private; |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 905 | struct r10bio *r10_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | struct bio *read_bio; |
| 907 | int i; |
| 908 | int chunk_sects = conf->chunk_mask + 1; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 909 | const int rw = bio_data_dir(bio); |
NeilBrown | 2c7d46e | 2010-08-18 16:16:05 +1000 | [diff] [blame] | 910 | const unsigned long do_sync = (bio->bi_rw & REQ_SYNC); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 911 | const unsigned long do_fua = (bio->bi_rw & REQ_FUA); |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 912 | unsigned long flags; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 913 | struct md_rdev *blocked_rdev; |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 914 | int plugged; |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 915 | int sectors_handled; |
| 916 | int max_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 918 | if (unlikely(bio->bi_rw & REQ_FLUSH)) { |
| 919 | md_flush_request(mddev, bio); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 920 | return; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | /* If this request crosses a chunk boundary, we need to |
| 924 | * split it. This will only happen for 1 PAGE (or less) requests. |
| 925 | */ |
| 926 | if (unlikely( (bio->bi_sector & conf->chunk_mask) + (bio->bi_size >> 9) |
| 927 | > chunk_sects && |
| 928 | conf->near_copies < conf->raid_disks)) { |
| 929 | struct bio_pair *bp; |
| 930 | /* Sanity check -- queue functions should prevent this happening */ |
| 931 | if (bio->bi_vcnt != 1 || |
| 932 | bio->bi_idx != 0) |
| 933 | goto bad_map; |
| 934 | /* This is a one page bio that upper layers |
| 935 | * refuse to split for us, so we need to split it. |
| 936 | */ |
Denis ChengRq | 6feef53 | 2008-10-09 08:57:05 +0200 | [diff] [blame] | 937 | bp = bio_split(bio, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | chunk_sects - (bio->bi_sector & (chunk_sects - 1)) ); |
NeilBrown | 51e9ac7 | 2010-08-07 21:17:00 +1000 | [diff] [blame] | 939 | |
| 940 | /* Each of these 'make_request' calls will call 'wait_barrier'. |
| 941 | * If the first succeeds but the second blocks due to the resync |
| 942 | * thread raising the barrier, we will deadlock because the |
| 943 | * IO to the underlying device will be queued in generic_make_request |
| 944 | * and will never complete, so will never reduce nr_pending. |
| 945 | * So increment nr_waiting here so no new raise_barriers will |
| 946 | * succeed, and so the second wait_barrier cannot block. |
| 947 | */ |
| 948 | spin_lock_irq(&conf->resync_lock); |
| 949 | conf->nr_waiting++; |
| 950 | spin_unlock_irq(&conf->resync_lock); |
| 951 | |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 952 | make_request(mddev, &bp->bio1); |
| 953 | make_request(mddev, &bp->bio2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
NeilBrown | 51e9ac7 | 2010-08-07 21:17:00 +1000 | [diff] [blame] | 955 | spin_lock_irq(&conf->resync_lock); |
| 956 | conf->nr_waiting--; |
| 957 | wake_up(&conf->wait_barrier); |
| 958 | spin_unlock_irq(&conf->resync_lock); |
| 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | bio_pair_release(bp); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 961 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | bad_map: |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 963 | printk("md/raid10:%s: make_request bug: can't convert block across chunks" |
| 964 | " or bigger than %dk %llu %d\n", mdname(mddev), chunk_sects/2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | (unsigned long long)bio->bi_sector, bio->bi_size >> 10); |
| 966 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 967 | bio_io_error(bio); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 968 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } |
| 970 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 971 | md_write_start(mddev, bio); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | /* |
| 974 | * Register the new request and wait if the reconstruction |
| 975 | * thread has put up a bar for new requests. |
| 976 | * Continue immediately if no resync is active currently. |
| 977 | */ |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 978 | wait_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO); |
| 981 | |
| 982 | r10_bio->master_bio = bio; |
| 983 | r10_bio->sectors = bio->bi_size >> 9; |
| 984 | |
| 985 | r10_bio->mddev = mddev; |
| 986 | r10_bio->sector = bio->bi_sector; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 987 | r10_bio->state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 989 | /* We might need to issue multiple reads to different |
| 990 | * devices if there are bad blocks around, so we keep |
| 991 | * track of the number of reads in bio->bi_phys_segments. |
| 992 | * If this is 0, there is only one r10_bio and no locking |
| 993 | * will be needed when the request completes. If it is |
| 994 | * non-zero, then it is the number of not-completed requests. |
| 995 | */ |
| 996 | bio->bi_phys_segments = 0; |
| 997 | clear_bit(BIO_SEG_VALID, &bio->bi_flags); |
| 998 | |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 999 | if (rw == READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | /* |
| 1001 | * read balancing logic: |
| 1002 | */ |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1003 | struct md_rdev *rdev; |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1004 | int slot; |
| 1005 | |
| 1006 | read_again: |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1007 | rdev = read_balance(conf, r10_bio, &max_sectors); |
| 1008 | if (!rdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | raid_end_bio_io(r10_bio); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 1010 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1012 | slot = r10_bio->read_slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 1014 | read_bio = bio_clone_mddev(bio, GFP_NOIO, mddev); |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1015 | md_trim_bio(read_bio, r10_bio->sector - bio->bi_sector, |
| 1016 | max_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
| 1018 | r10_bio->devs[slot].bio = read_bio; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1019 | r10_bio->devs[slot].rdev = rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
| 1021 | read_bio->bi_sector = r10_bio->devs[slot].addr + |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1022 | rdev->data_offset; |
| 1023 | read_bio->bi_bdev = rdev->bdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | read_bio->bi_end_io = raid10_end_read_request; |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 1025 | read_bio->bi_rw = READ | do_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | read_bio->bi_private = r10_bio; |
| 1027 | |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1028 | if (max_sectors < r10_bio->sectors) { |
| 1029 | /* Could not read all from this device, so we will |
| 1030 | * need another r10_bio. |
| 1031 | */ |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1032 | sectors_handled = (r10_bio->sectors + max_sectors |
| 1033 | - bio->bi_sector); |
| 1034 | r10_bio->sectors = max_sectors; |
| 1035 | spin_lock_irq(&conf->device_lock); |
| 1036 | if (bio->bi_phys_segments == 0) |
| 1037 | bio->bi_phys_segments = 2; |
| 1038 | else |
| 1039 | bio->bi_phys_segments++; |
| 1040 | spin_unlock(&conf->device_lock); |
| 1041 | /* Cannot call generic_make_request directly |
| 1042 | * as that will be queued in __generic_make_request |
| 1043 | * and subsequent mempool_alloc might block |
| 1044 | * waiting for it. so hand bio over to raid10d. |
| 1045 | */ |
| 1046 | reschedule_retry(r10_bio); |
| 1047 | |
| 1048 | r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO); |
| 1049 | |
| 1050 | r10_bio->master_bio = bio; |
| 1051 | r10_bio->sectors = ((bio->bi_size >> 9) |
| 1052 | - sectors_handled); |
| 1053 | r10_bio->state = 0; |
| 1054 | r10_bio->mddev = mddev; |
| 1055 | r10_bio->sector = bio->bi_sector + sectors_handled; |
| 1056 | goto read_again; |
| 1057 | } else |
| 1058 | generic_make_request(read_bio); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 1059 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | /* |
| 1063 | * WRITE: |
| 1064 | */ |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 1065 | if (conf->pending_count >= max_queued_requests) { |
| 1066 | md_wakeup_thread(mddev->thread); |
| 1067 | wait_event(conf->wait_barrier, |
| 1068 | conf->pending_count < max_queued_requests); |
| 1069 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1070 | /* first select target devices under rcu_lock and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | * inc refcount on their rdev. Record them by setting |
| 1072 | * bios[x] to bio |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1073 | * If there are known/acknowledged bad blocks on any device |
| 1074 | * on which we have seen a write error, we want to avoid |
| 1075 | * writing to those blocks. This potentially requires several |
| 1076 | * writes to write around the bad blocks. Each set of writes |
| 1077 | * gets its own r10_bio with a set of bios attached. The number |
| 1078 | * of r10_bios is recored in bio->bi_phys_segments just as with |
| 1079 | * the read case. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | */ |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 1081 | plugged = mddev_check_plugged(mddev); |
| 1082 | |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1083 | r10_bio->read_slot = -1; /* make sure repl_bio gets freed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | raid10_find_phys(conf, r10_bio); |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1085 | retry_write: |
Harvey Harrison | cb6969e | 2008-05-06 20:42:32 -0700 | [diff] [blame] | 1086 | blocked_rdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | rcu_read_lock(); |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1088 | max_sectors = r10_bio->sectors; |
| 1089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | for (i = 0; i < conf->copies; i++) { |
| 1091 | int d = r10_bio->devs[i].devnum; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 1092 | struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev); |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1093 | struct md_rdev *rrdev = rcu_dereference( |
| 1094 | conf->mirrors[d].replacement); |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1095 | if (rdev == rrdev) |
| 1096 | rrdev = NULL; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1097 | if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
| 1098 | atomic_inc(&rdev->nr_pending); |
| 1099 | blocked_rdev = rdev; |
| 1100 | break; |
| 1101 | } |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1102 | if (rrdev && unlikely(test_bit(Blocked, &rrdev->flags))) { |
| 1103 | atomic_inc(&rrdev->nr_pending); |
| 1104 | blocked_rdev = rrdev; |
| 1105 | break; |
| 1106 | } |
| 1107 | if (rrdev && test_bit(Faulty, &rrdev->flags)) |
| 1108 | rrdev = NULL; |
| 1109 | |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1110 | r10_bio->devs[i].bio = NULL; |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1111 | r10_bio->devs[i].repl_bio = NULL; |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1112 | if (!rdev || test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1113 | set_bit(R10BIO_Degraded, &r10_bio->state); |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1114 | continue; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1115 | } |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1116 | if (test_bit(WriteErrorSeen, &rdev->flags)) { |
| 1117 | sector_t first_bad; |
| 1118 | sector_t dev_sector = r10_bio->devs[i].addr; |
| 1119 | int bad_sectors; |
| 1120 | int is_bad; |
| 1121 | |
| 1122 | is_bad = is_badblock(rdev, dev_sector, |
| 1123 | max_sectors, |
| 1124 | &first_bad, &bad_sectors); |
| 1125 | if (is_bad < 0) { |
| 1126 | /* Mustn't write here until the bad block |
| 1127 | * is acknowledged |
| 1128 | */ |
| 1129 | atomic_inc(&rdev->nr_pending); |
| 1130 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 1131 | blocked_rdev = rdev; |
| 1132 | break; |
| 1133 | } |
| 1134 | if (is_bad && first_bad <= dev_sector) { |
| 1135 | /* Cannot write here at all */ |
| 1136 | bad_sectors -= (dev_sector - first_bad); |
| 1137 | if (bad_sectors < max_sectors) |
| 1138 | /* Mustn't write more than bad_sectors |
| 1139 | * to other devices yet |
| 1140 | */ |
| 1141 | max_sectors = bad_sectors; |
| 1142 | /* We don't set R10BIO_Degraded as that |
| 1143 | * only applies if the disk is missing, |
| 1144 | * so it might be re-added, and we want to |
| 1145 | * know to recover this chunk. |
| 1146 | * In this case the device is here, and the |
| 1147 | * fact that this chunk is not in-sync is |
| 1148 | * recorded in the bad block log. |
| 1149 | */ |
| 1150 | continue; |
| 1151 | } |
| 1152 | if (is_bad) { |
| 1153 | int good_sectors = first_bad - dev_sector; |
| 1154 | if (good_sectors < max_sectors) |
| 1155 | max_sectors = good_sectors; |
| 1156 | } |
| 1157 | } |
| 1158 | r10_bio->devs[i].bio = bio; |
| 1159 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1160 | if (rrdev) { |
| 1161 | r10_bio->devs[i].repl_bio = bio; |
| 1162 | atomic_inc(&rrdev->nr_pending); |
| 1163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | } |
| 1165 | rcu_read_unlock(); |
| 1166 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1167 | if (unlikely(blocked_rdev)) { |
| 1168 | /* Have to wait for this device to get unblocked, then retry */ |
| 1169 | int j; |
| 1170 | int d; |
| 1171 | |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1172 | for (j = 0; j < i; j++) { |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1173 | if (r10_bio->devs[j].bio) { |
| 1174 | d = r10_bio->devs[j].devnum; |
| 1175 | rdev_dec_pending(conf->mirrors[d].rdev, mddev); |
| 1176 | } |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1177 | if (r10_bio->devs[j].repl_bio) { |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1178 | struct md_rdev *rdev; |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1179 | d = r10_bio->devs[j].devnum; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1180 | rdev = conf->mirrors[d].replacement; |
| 1181 | if (!rdev) { |
| 1182 | /* Race with remove_disk */ |
| 1183 | smp_mb(); |
| 1184 | rdev = conf->mirrors[d].rdev; |
| 1185 | } |
| 1186 | rdev_dec_pending(rdev, mddev); |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1187 | } |
| 1188 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 1189 | allow_barrier(conf); |
| 1190 | md_wait_for_blocked_rdev(blocked_rdev, mddev); |
| 1191 | wait_barrier(conf); |
| 1192 | goto retry_write; |
| 1193 | } |
| 1194 | |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1195 | if (max_sectors < r10_bio->sectors) { |
| 1196 | /* We are splitting this into multiple parts, so |
| 1197 | * we need to prepare for allocating another r10_bio. |
| 1198 | */ |
| 1199 | r10_bio->sectors = max_sectors; |
| 1200 | spin_lock_irq(&conf->device_lock); |
| 1201 | if (bio->bi_phys_segments == 0) |
| 1202 | bio->bi_phys_segments = 2; |
| 1203 | else |
| 1204 | bio->bi_phys_segments++; |
| 1205 | spin_unlock_irq(&conf->device_lock); |
| 1206 | } |
| 1207 | sectors_handled = r10_bio->sector + max_sectors - bio->bi_sector; |
| 1208 | |
NeilBrown | 4e78064 | 2010-10-19 12:54:01 +1100 | [diff] [blame] | 1209 | atomic_set(&r10_bio->remaining, 1); |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1210 | bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 1211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | for (i = 0; i < conf->copies; i++) { |
| 1213 | struct bio *mbio; |
| 1214 | int d = r10_bio->devs[i].devnum; |
| 1215 | if (!r10_bio->devs[i].bio) |
| 1216 | continue; |
| 1217 | |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 1218 | mbio = bio_clone_mddev(bio, GFP_NOIO, mddev); |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1219 | md_trim_bio(mbio, r10_bio->sector - bio->bi_sector, |
| 1220 | max_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | r10_bio->devs[i].bio = mbio; |
| 1222 | |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1223 | mbio->bi_sector = (r10_bio->devs[i].addr+ |
| 1224 | conf->mirrors[d].rdev->data_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | mbio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 1226 | mbio->bi_end_io = raid10_end_write_request; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1227 | mbio->bi_rw = WRITE | do_sync | do_fua; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | mbio->bi_private = r10_bio; |
| 1229 | |
| 1230 | atomic_inc(&r10_bio->remaining); |
NeilBrown | 4e78064 | 2010-10-19 12:54:01 +1100 | [diff] [blame] | 1231 | spin_lock_irqsave(&conf->device_lock, flags); |
| 1232 | bio_list_add(&conf->pending_bio_list, mbio); |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 1233 | conf->pending_count++; |
NeilBrown | 4e78064 | 2010-10-19 12:54:01 +1100 | [diff] [blame] | 1234 | spin_unlock_irqrestore(&conf->device_lock, flags); |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1235 | |
| 1236 | if (!r10_bio->devs[i].repl_bio) |
| 1237 | continue; |
| 1238 | |
| 1239 | mbio = bio_clone_mddev(bio, GFP_NOIO, mddev); |
| 1240 | md_trim_bio(mbio, r10_bio->sector - bio->bi_sector, |
| 1241 | max_sectors); |
| 1242 | r10_bio->devs[i].repl_bio = mbio; |
| 1243 | |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1244 | /* We are actively writing to the original device |
| 1245 | * so it cannot disappear, so the replacement cannot |
| 1246 | * become NULL here |
| 1247 | */ |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1248 | mbio->bi_sector = (r10_bio->devs[i].addr+ |
| 1249 | conf->mirrors[d].replacement->data_offset); |
| 1250 | mbio->bi_bdev = conf->mirrors[d].replacement->bdev; |
| 1251 | mbio->bi_end_io = raid10_end_write_request; |
| 1252 | mbio->bi_rw = WRITE | do_sync | do_fua; |
| 1253 | mbio->bi_private = r10_bio; |
| 1254 | |
| 1255 | atomic_inc(&r10_bio->remaining); |
| 1256 | spin_lock_irqsave(&conf->device_lock, flags); |
| 1257 | bio_list_add(&conf->pending_bio_list, mbio); |
| 1258 | conf->pending_count++; |
| 1259 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
NeilBrown | 079fa16 | 2011-09-10 17:21:23 +1000 | [diff] [blame] | 1262 | /* Don't remove the bias on 'remaining' (one_write_done) until |
| 1263 | * after checking if we need to go around again. |
| 1264 | */ |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 1265 | |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1266 | if (sectors_handled < (bio->bi_size >> 9)) { |
NeilBrown | 079fa16 | 2011-09-10 17:21:23 +1000 | [diff] [blame] | 1267 | one_write_done(r10_bio); |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1268 | /* We need another r10_bio. It has already been counted |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1269 | * in bio->bi_phys_segments. |
| 1270 | */ |
| 1271 | r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO); |
| 1272 | |
| 1273 | r10_bio->master_bio = bio; |
| 1274 | r10_bio->sectors = (bio->bi_size >> 9) - sectors_handled; |
| 1275 | |
| 1276 | r10_bio->mddev = mddev; |
| 1277 | r10_bio->sector = bio->bi_sector + sectors_handled; |
| 1278 | r10_bio->state = 0; |
| 1279 | goto retry_write; |
| 1280 | } |
NeilBrown | 079fa16 | 2011-09-10 17:21:23 +1000 | [diff] [blame] | 1281 | one_write_done(r10_bio); |
| 1282 | |
| 1283 | /* In case raid10d snuck in to freeze_array */ |
| 1284 | wake_up(&conf->wait_barrier); |
NeilBrown | d4432c2 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1285 | |
NeilBrown | c3b328a | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 1286 | if (do_sync || !mddev->bitmap || !plugged) |
Lars Ellenberg | e3881a6 | 2007-01-10 23:15:37 -0800 | [diff] [blame] | 1287 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1290 | static void status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1292 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | int i; |
| 1294 | |
| 1295 | if (conf->near_copies < conf->raid_disks) |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 1296 | seq_printf(seq, " %dK chunks", mddev->chunk_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | if (conf->near_copies > 1) |
| 1298 | seq_printf(seq, " %d near-copies", conf->near_copies); |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 1299 | if (conf->far_copies > 1) { |
| 1300 | if (conf->far_offset) |
| 1301 | seq_printf(seq, " %d offset-copies", conf->far_copies); |
| 1302 | else |
| 1303 | seq_printf(seq, " %d far-copies", conf->far_copies); |
| 1304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | seq_printf(seq, " [%d/%d] [", conf->raid_disks, |
NeilBrown | 76186dd | 2006-10-03 01:15:48 -0700 | [diff] [blame] | 1306 | conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | for (i = 0; i < conf->raid_disks; i++) |
| 1308 | seq_printf(seq, "%s", |
| 1309 | conf->mirrors[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1310 | test_bit(In_sync, &conf->mirrors[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | seq_printf(seq, "]"); |
| 1312 | } |
| 1313 | |
NeilBrown | 700c721 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1314 | /* check if there are enough drives for |
| 1315 | * every block to appear on atleast one. |
| 1316 | * Don't consider the device numbered 'ignore' |
| 1317 | * as we might be about to remove it. |
| 1318 | */ |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1319 | static int enough(struct r10conf *conf, int ignore) |
NeilBrown | 700c721 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1320 | { |
| 1321 | int first = 0; |
| 1322 | |
| 1323 | do { |
| 1324 | int n = conf->copies; |
| 1325 | int cnt = 0; |
| 1326 | while (n--) { |
| 1327 | if (conf->mirrors[first].rdev && |
| 1328 | first != ignore) |
| 1329 | cnt++; |
| 1330 | first = (first+1) % conf->raid_disks; |
| 1331 | } |
| 1332 | if (cnt == 0) |
| 1333 | return 0; |
| 1334 | } while (first != 0); |
| 1335 | return 1; |
| 1336 | } |
| 1337 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1338 | static void error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | { |
| 1340 | char b[BDEVNAME_SIZE]; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1341 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* |
| 1344 | * If it is not operational, then we have already marked it as dead |
| 1345 | * else if it is the last working disks, ignore the error, let the |
| 1346 | * next level up know. |
| 1347 | * else mark the drive as failed |
| 1348 | */ |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1349 | if (test_bit(In_sync, &rdev->flags) |
NeilBrown | 700c721 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1350 | && !enough(conf, rdev->raid_disk)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | /* |
| 1352 | * Don't fail the drive, just return an IO error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | */ |
| 1354 | return; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1355 | if (test_and_clear_bit(In_sync, &rdev->flags)) { |
| 1356 | unsigned long flags; |
| 1357 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | mddev->degraded++; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1359 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | /* |
| 1361 | * if recovery is running, make sure it aborts. |
| 1362 | */ |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1363 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 1365 | set_bit(Blocked, &rdev->flags); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1366 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1367 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
Joe Perches | 067032b | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 1368 | printk(KERN_ALERT |
| 1369 | "md/raid10:%s: Disk failure on %s, disabling device.\n" |
| 1370 | "md/raid10:%s: Operation continuing on %d devices.\n", |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 1371 | mdname(mddev), bdevname(rdev->bdev, b), |
| 1372 | mdname(mddev), conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1375 | static void print_conf(struct r10conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | { |
| 1377 | int i; |
NeilBrown | 0f6d02d | 2011-10-11 16:48:46 +1100 | [diff] [blame] | 1378 | struct mirror_info *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 1380 | printk(KERN_DEBUG "RAID10 conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | if (!conf) { |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 1382 | printk(KERN_DEBUG "(!conf)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | return; |
| 1384 | } |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 1385 | printk(KERN_DEBUG " --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | conf->raid_disks); |
| 1387 | |
| 1388 | for (i = 0; i < conf->raid_disks; i++) { |
| 1389 | char b[BDEVNAME_SIZE]; |
| 1390 | tmp = conf->mirrors + i; |
| 1391 | if (tmp->rdev) |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 1392 | printk(KERN_DEBUG " disk %d, wo:%d, o:%d, dev:%s\n", |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1393 | i, !test_bit(In_sync, &tmp->rdev->flags), |
| 1394 | !test_bit(Faulty, &tmp->rdev->flags), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | bdevname(tmp->rdev->bdev,b)); |
| 1396 | } |
| 1397 | } |
| 1398 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1399 | static void close_sync(struct r10conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | { |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 1401 | wait_barrier(conf); |
| 1402 | allow_barrier(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
| 1404 | mempool_destroy(conf->r10buf_pool); |
| 1405 | conf->r10buf_pool = NULL; |
| 1406 | } |
| 1407 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1408 | static int raid10_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | { |
| 1410 | int i; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1411 | struct r10conf *conf = mddev->private; |
NeilBrown | 0f6d02d | 2011-10-11 16:48:46 +1100 | [diff] [blame] | 1412 | struct mirror_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 1413 | int count = 0; |
| 1414 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
| 1416 | /* |
| 1417 | * Find all non-in_sync disks within the RAID10 configuration |
| 1418 | * and mark them in_sync |
| 1419 | */ |
| 1420 | for (i = 0; i < conf->raid_disks; i++) { |
| 1421 | tmp = conf->mirrors + i; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1422 | if (tmp->replacement |
| 1423 | && tmp->replacement->recovery_offset == MaxSector |
| 1424 | && !test_bit(Faulty, &tmp->replacement->flags) |
| 1425 | && !test_and_set_bit(In_sync, &tmp->replacement->flags)) { |
| 1426 | /* Replacement has just become active */ |
| 1427 | if (!tmp->rdev |
| 1428 | || !test_and_clear_bit(In_sync, &tmp->rdev->flags)) |
| 1429 | count++; |
| 1430 | if (tmp->rdev) { |
| 1431 | /* Replaced device not technically faulty, |
| 1432 | * but we need to be sure it gets removed |
| 1433 | * and never re-added. |
| 1434 | */ |
| 1435 | set_bit(Faulty, &tmp->rdev->flags); |
| 1436 | sysfs_notify_dirent_safe( |
| 1437 | tmp->rdev->sysfs_state); |
| 1438 | } |
| 1439 | sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); |
| 1440 | } else if (tmp->rdev |
| 1441 | && !test_bit(Faulty, &tmp->rdev->flags) |
| 1442 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 1443 | count++; |
Adrian Drzewiecki | e6ffbcb | 2010-08-18 11:49:02 +1000 | [diff] [blame] | 1444 | sysfs_notify_dirent(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | } |
| 1446 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 1447 | spin_lock_irqsave(&conf->device_lock, flags); |
| 1448 | mddev->degraded -= count; |
| 1449 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
| 1451 | print_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 1452 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1456 | static int raid10_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1458 | struct r10conf *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1459 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | int mirror; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1461 | int first = 0; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 1462 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
| 1464 | if (mddev->recovery_cp < MaxSector) |
| 1465 | /* only hot-add to in-sync arrays, as recovery is |
| 1466 | * very different from resync |
| 1467 | */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1468 | return -EBUSY; |
NeilBrown | 700c721 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1469 | if (!enough(conf, -1)) |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1470 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | |
NeilBrown | a53a6c8 | 2008-11-06 17:28:20 +1100 | [diff] [blame] | 1472 | if (rdev->raid_disk >= 0) |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1473 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
Namhyung Kim | 2c4193d | 2011-07-18 17:38:43 +1000 | [diff] [blame] | 1475 | if (rdev->saved_raid_disk >= first && |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 1476 | conf->mirrors[rdev->saved_raid_disk].rdev == NULL) |
| 1477 | mirror = rdev->saved_raid_disk; |
| 1478 | else |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 1479 | mirror = first; |
NeilBrown | 2bb7773 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1480 | for ( ; mirror <= last ; mirror++) { |
NeilBrown | 0f6d02d | 2011-10-11 16:48:46 +1100 | [diff] [blame] | 1481 | struct mirror_info *p = &conf->mirrors[mirror]; |
NeilBrown | 2bb7773 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1482 | if (p->recovery_disabled == mddev->recovery_disabled) |
| 1483 | continue; |
NeilBrown | 7fcc7c8 | 2011-10-31 12:59:44 +1100 | [diff] [blame] | 1484 | if (p->rdev) |
NeilBrown | 2bb7773 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1485 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | |
NeilBrown | 2bb7773 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1487 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 1488 | rdev->data_offset << 9); |
| 1489 | /* as we don't honour merge_bvec_fn, we must |
| 1490 | * never risk violating it, so limit |
| 1491 | * ->max_segments to one lying with a single |
| 1492 | * page, as a one page request is never in |
| 1493 | * violation. |
| 1494 | */ |
| 1495 | if (rdev->bdev->bd_disk->queue->merge_bvec_fn) { |
| 1496 | blk_queue_max_segments(mddev->queue, 1); |
| 1497 | blk_queue_segment_boundary(mddev->queue, |
| 1498 | PAGE_CACHE_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
NeilBrown | 2bb7773 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1501 | p->head_position = 0; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 1502 | p->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 2bb7773 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1503 | rdev->raid_disk = mirror; |
| 1504 | err = 0; |
| 1505 | if (rdev->saved_raid_disk != mirror) |
| 1506 | conf->fullsync = 1; |
| 1507 | rcu_assign_pointer(p->rdev, rdev); |
| 1508 | break; |
| 1509 | } |
| 1510 | |
Andre Noll | ac5e711 | 2009-08-03 10:59:47 +1000 | [diff] [blame] | 1511 | md_integrity_add_rdev(rdev, mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | print_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 1513 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 1516 | static int raid10_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1518 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 1520 | int number = rdev->raid_disk; |
NeilBrown | c8ab903 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1521 | struct md_rdev **rdevp; |
| 1522 | struct mirror_info *p = conf->mirrors + number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
| 1524 | print_conf(conf); |
NeilBrown | c8ab903 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1525 | if (rdev == p->rdev) |
| 1526 | rdevp = &p->rdev; |
| 1527 | else if (rdev == p->replacement) |
| 1528 | rdevp = &p->replacement; |
| 1529 | else |
| 1530 | return 0; |
| 1531 | |
| 1532 | if (test_bit(In_sync, &rdev->flags) || |
| 1533 | atomic_read(&rdev->nr_pending)) { |
| 1534 | err = -EBUSY; |
| 1535 | goto abort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } |
NeilBrown | c8ab903 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1537 | /* Only remove faulty devices if recovery |
| 1538 | * is not possible. |
| 1539 | */ |
| 1540 | if (!test_bit(Faulty, &rdev->flags) && |
| 1541 | mddev->recovery_disabled != p->recovery_disabled && |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1542 | (!p->replacement || p->replacement == rdev) && |
NeilBrown | c8ab903 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1543 | enough(conf, -1)) { |
| 1544 | err = -EBUSY; |
| 1545 | goto abort; |
| 1546 | } |
| 1547 | *rdevp = NULL; |
| 1548 | synchronize_rcu(); |
| 1549 | if (atomic_read(&rdev->nr_pending)) { |
| 1550 | /* lost the race, try later */ |
| 1551 | err = -EBUSY; |
| 1552 | *rdevp = rdev; |
| 1553 | goto abort; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1554 | } else if (p->replacement) { |
| 1555 | /* We must have just cleared 'rdev' */ |
| 1556 | p->rdev = p->replacement; |
| 1557 | clear_bit(Replacement, &p->replacement->flags); |
| 1558 | smp_mb(); /* Make sure other CPUs may see both as identical |
| 1559 | * but will never see neither -- if they are careful. |
| 1560 | */ |
| 1561 | p->replacement = NULL; |
| 1562 | clear_bit(WantReplacement, &rdev->flags); |
| 1563 | } else |
| 1564 | /* We might have just remove the Replacement as faulty |
| 1565 | * Clear the flag just in case |
| 1566 | */ |
| 1567 | clear_bit(WantReplacement, &rdev->flags); |
| 1568 | |
NeilBrown | c8ab903 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1569 | err = md_integrity_register(mddev); |
| 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | abort: |
| 1572 | |
| 1573 | print_conf(conf); |
| 1574 | return err; |
| 1575 | } |
| 1576 | |
| 1577 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1578 | static void end_sync_read(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | { |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1580 | struct r10bio *r10_bio = bio->bi_private; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1581 | struct r10conf *conf = r10_bio->mddev->private; |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 1582 | int d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1584 | d = find_bio_disk(conf, r10_bio, bio, NULL, NULL); |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1585 | |
| 1586 | if (test_bit(BIO_UPTODATE, &bio->bi_flags)) |
| 1587 | set_bit(R10BIO_Uptodate, &r10_bio->state); |
NeilBrown | e684e41 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1588 | else |
| 1589 | /* The write handler will notice the lack of |
| 1590 | * R10BIO_Uptodate and record any errors etc |
| 1591 | */ |
NeilBrown | 4dbcdc7 | 2006-01-06 00:20:52 -0800 | [diff] [blame] | 1592 | atomic_add(r10_bio->sectors, |
| 1593 | &conf->mirrors[d].rdev->corrected_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | |
| 1595 | /* for reconstruct, we always reschedule after a read. |
| 1596 | * for resync, only after all reads |
| 1597 | */ |
NeilBrown | 73d5c38 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 1598 | rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | if (test_bit(R10BIO_IsRecover, &r10_bio->state) || |
| 1600 | atomic_dec_and_test(&r10_bio->remaining)) { |
| 1601 | /* we have read all the blocks, |
| 1602 | * do the comparison in process context in raid10d |
| 1603 | */ |
| 1604 | reschedule_retry(r10_bio); |
| 1605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1608 | static void end_sync_request(struct r10bio *r10_bio) |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1609 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1610 | struct mddev *mddev = r10_bio->mddev; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1611 | |
| 1612 | while (atomic_dec_and_test(&r10_bio->remaining)) { |
| 1613 | if (r10_bio->master_bio == NULL) { |
| 1614 | /* the primary of several recovery bios */ |
| 1615 | sector_t s = r10_bio->sectors; |
| 1616 | if (test_bit(R10BIO_MadeGood, &r10_bio->state) || |
| 1617 | test_bit(R10BIO_WriteError, &r10_bio->state)) |
| 1618 | reschedule_retry(r10_bio); |
| 1619 | else |
| 1620 | put_buf(r10_bio); |
| 1621 | md_done_sync(mddev, s, 1); |
| 1622 | break; |
| 1623 | } else { |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1624 | struct r10bio *r10_bio2 = (struct r10bio *)r10_bio->master_bio; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1625 | if (test_bit(R10BIO_MadeGood, &r10_bio->state) || |
| 1626 | test_bit(R10BIO_WriteError, &r10_bio->state)) |
| 1627 | reschedule_retry(r10_bio); |
| 1628 | else |
| 1629 | put_buf(r10_bio); |
| 1630 | r10_bio = r10_bio2; |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1635 | static void end_sync_write(struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | { |
| 1637 | int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1638 | struct r10bio *r10_bio = bio->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1639 | struct mddev *mddev = r10_bio->mddev; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1640 | struct r10conf *conf = mddev->private; |
Namhyung Kim | 778ca01 | 2011-07-18 17:38:47 +1000 | [diff] [blame] | 1641 | int d; |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1642 | sector_t first_bad; |
| 1643 | int bad_sectors; |
| 1644 | int slot; |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1645 | int repl; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1646 | struct md_rdev *rdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1648 | d = find_bio_disk(conf, r10_bio, bio, &slot, &repl); |
| 1649 | if (repl) |
| 1650 | rdev = conf->mirrors[d].replacement; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1651 | if (!rdev) { |
| 1652 | smp_mb(); |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1653 | rdev = conf->mirrors[d].rdev; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1654 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
NeilBrown | 1a0b7cd | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1656 | if (!uptodate) { |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1657 | if (repl) |
| 1658 | md_error(mddev, rdev); |
| 1659 | else { |
| 1660 | set_bit(WriteErrorSeen, &rdev->flags); |
| 1661 | set_bit(R10BIO_WriteError, &r10_bio->state); |
| 1662 | } |
| 1663 | } else if (is_badblock(rdev, |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 1664 | r10_bio->devs[slot].addr, |
| 1665 | r10_bio->sectors, |
| 1666 | &first_bad, &bad_sectors)) |
| 1667 | set_bit(R10BIO_MadeGood, &r10_bio->state); |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1668 | |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1669 | rdev_dec_pending(rdev, mddev); |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1670 | |
| 1671 | end_sync_request(r10_bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | /* |
| 1675 | * Note: sync and recover and handled very differently for raid10 |
| 1676 | * This code is for resync. |
| 1677 | * For resync, we read through virtual addresses and read all blocks. |
| 1678 | * If there is any error, we schedule a write. The lowest numbered |
| 1679 | * drive is authoritative. |
| 1680 | * However requests come for physical address, so we need to map. |
| 1681 | * For every physical address there are raid_disks/copies virtual addresses, |
| 1682 | * which is always are least one, but is not necessarly an integer. |
| 1683 | * This means that a physical address can span multiple chunks, so we may |
| 1684 | * have to submit multiple io requests for a single sync request. |
| 1685 | */ |
| 1686 | /* |
| 1687 | * We check if all blocks are in-sync and only write to blocks that |
| 1688 | * aren't in sync |
| 1689 | */ |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1690 | static void sync_request_write(struct mddev *mddev, struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1692 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | int i, first; |
| 1694 | struct bio *tbio, *fbio; |
| 1695 | |
| 1696 | atomic_set(&r10_bio->remaining, 1); |
| 1697 | |
| 1698 | /* find the first device with a block */ |
| 1699 | for (i=0; i<conf->copies; i++) |
| 1700 | if (test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags)) |
| 1701 | break; |
| 1702 | |
| 1703 | if (i == conf->copies) |
| 1704 | goto done; |
| 1705 | |
| 1706 | first = i; |
| 1707 | fbio = r10_bio->devs[i].bio; |
| 1708 | |
| 1709 | /* now find blocks with errors */ |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1710 | for (i=0 ; i < conf->copies ; i++) { |
| 1711 | int j, d; |
| 1712 | int vcnt = r10_bio->sectors >> (PAGE_SHIFT-9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | tbio = r10_bio->devs[i].bio; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1715 | |
| 1716 | if (tbio->bi_end_io != end_sync_read) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | continue; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1718 | if (i == first) |
| 1719 | continue; |
| 1720 | if (test_bit(BIO_UPTODATE, &r10_bio->devs[i].bio->bi_flags)) { |
| 1721 | /* We know that the bi_io_vec layout is the same for |
| 1722 | * both 'first' and 'i', so we just compare them. |
| 1723 | * All vec entries are PAGE_SIZE; |
| 1724 | */ |
| 1725 | for (j = 0; j < vcnt; j++) |
| 1726 | if (memcmp(page_address(fbio->bi_io_vec[j].bv_page), |
| 1727 | page_address(tbio->bi_io_vec[j].bv_page), |
| 1728 | PAGE_SIZE)) |
| 1729 | break; |
| 1730 | if (j == vcnt) |
| 1731 | continue; |
| 1732 | mddev->resync_mismatches += r10_bio->sectors; |
NeilBrown | f84ee36 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1733 | if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 1734 | /* Don't fix anything. */ |
| 1735 | continue; |
NeilBrown | 0eb3ff1 | 2006-01-06 00:20:29 -0800 | [diff] [blame] | 1736 | } |
NeilBrown | f84ee36 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1737 | /* Ok, we need to write this bio, either to correct an |
| 1738 | * inconsistency or to correct an unreadable block. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | * First we need to fixup bv_offset, bv_len and |
| 1740 | * bi_vecs, as the read request might have corrupted these |
| 1741 | */ |
| 1742 | tbio->bi_vcnt = vcnt; |
| 1743 | tbio->bi_size = r10_bio->sectors << 9; |
| 1744 | tbio->bi_idx = 0; |
| 1745 | tbio->bi_phys_segments = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | tbio->bi_flags &= ~(BIO_POOL_MASK - 1); |
| 1747 | tbio->bi_flags |= 1 << BIO_UPTODATE; |
| 1748 | tbio->bi_next = NULL; |
| 1749 | tbio->bi_rw = WRITE; |
| 1750 | tbio->bi_private = r10_bio; |
| 1751 | tbio->bi_sector = r10_bio->devs[i].addr; |
| 1752 | |
| 1753 | for (j=0; j < vcnt ; j++) { |
| 1754 | tbio->bi_io_vec[j].bv_offset = 0; |
| 1755 | tbio->bi_io_vec[j].bv_len = PAGE_SIZE; |
| 1756 | |
| 1757 | memcpy(page_address(tbio->bi_io_vec[j].bv_page), |
| 1758 | page_address(fbio->bi_io_vec[j].bv_page), |
| 1759 | PAGE_SIZE); |
| 1760 | } |
| 1761 | tbio->bi_end_io = end_sync_write; |
| 1762 | |
| 1763 | d = r10_bio->devs[i].devnum; |
| 1764 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 1765 | atomic_inc(&r10_bio->remaining); |
| 1766 | md_sync_acct(conf->mirrors[d].rdev->bdev, tbio->bi_size >> 9); |
| 1767 | |
| 1768 | tbio->bi_sector += conf->mirrors[d].rdev->data_offset; |
| 1769 | tbio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 1770 | generic_make_request(tbio); |
| 1771 | } |
| 1772 | |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1773 | /* Now write out to any replacement devices |
| 1774 | * that are active |
| 1775 | */ |
| 1776 | for (i = 0; i < conf->copies; i++) { |
| 1777 | int j, d; |
| 1778 | int vcnt = r10_bio->sectors >> (PAGE_SHIFT-9); |
| 1779 | |
| 1780 | tbio = r10_bio->devs[i].repl_bio; |
| 1781 | if (!tbio || !tbio->bi_end_io) |
| 1782 | continue; |
| 1783 | if (r10_bio->devs[i].bio->bi_end_io != end_sync_write |
| 1784 | && r10_bio->devs[i].bio != fbio) |
| 1785 | for (j = 0; j < vcnt; j++) |
| 1786 | memcpy(page_address(tbio->bi_io_vec[j].bv_page), |
| 1787 | page_address(fbio->bi_io_vec[j].bv_page), |
| 1788 | PAGE_SIZE); |
| 1789 | d = r10_bio->devs[i].devnum; |
| 1790 | atomic_inc(&r10_bio->remaining); |
| 1791 | md_sync_acct(conf->mirrors[d].replacement->bdev, |
| 1792 | tbio->bi_size >> 9); |
| 1793 | generic_make_request(tbio); |
| 1794 | } |
| 1795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | done: |
| 1797 | if (atomic_dec_and_test(&r10_bio->remaining)) { |
| 1798 | md_done_sync(mddev, r10_bio->sectors, 1); |
| 1799 | put_buf(r10_bio); |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | /* |
| 1804 | * Now for the recovery code. |
| 1805 | * Recovery happens across physical sectors. |
| 1806 | * We recover all non-is_sync drives by finding the virtual address of |
| 1807 | * each, and then choose a working drive that also has that virt address. |
| 1808 | * There is a separate r10_bio for each non-in_sync drive. |
| 1809 | * Only the first two slots are in use. The first for reading, |
| 1810 | * The second for writing. |
| 1811 | * |
| 1812 | */ |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1813 | static void fix_recovery_read_error(struct r10bio *r10_bio) |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1814 | { |
| 1815 | /* We got a read error during recovery. |
| 1816 | * We repeat the read in smaller page-sized sections. |
| 1817 | * If a read succeeds, write it to the new device or record |
| 1818 | * a bad block if we cannot. |
| 1819 | * If a read fails, record a bad block on both old and |
| 1820 | * new devices. |
| 1821 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1822 | struct mddev *mddev = r10_bio->mddev; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1823 | struct r10conf *conf = mddev->private; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1824 | struct bio *bio = r10_bio->devs[0].bio; |
| 1825 | sector_t sect = 0; |
| 1826 | int sectors = r10_bio->sectors; |
| 1827 | int idx = 0; |
| 1828 | int dr = r10_bio->devs[0].devnum; |
| 1829 | int dw = r10_bio->devs[1].devnum; |
| 1830 | |
| 1831 | while (sectors) { |
| 1832 | int s = sectors; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 1833 | struct md_rdev *rdev; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1834 | sector_t addr; |
| 1835 | int ok; |
| 1836 | |
| 1837 | if (s > (PAGE_SIZE>>9)) |
| 1838 | s = PAGE_SIZE >> 9; |
| 1839 | |
| 1840 | rdev = conf->mirrors[dr].rdev; |
| 1841 | addr = r10_bio->devs[0].addr + sect, |
| 1842 | ok = sync_page_io(rdev, |
| 1843 | addr, |
| 1844 | s << 9, |
| 1845 | bio->bi_io_vec[idx].bv_page, |
| 1846 | READ, false); |
| 1847 | if (ok) { |
| 1848 | rdev = conf->mirrors[dw].rdev; |
| 1849 | addr = r10_bio->devs[1].addr + sect; |
| 1850 | ok = sync_page_io(rdev, |
| 1851 | addr, |
| 1852 | s << 9, |
| 1853 | bio->bi_io_vec[idx].bv_page, |
| 1854 | WRITE, false); |
| 1855 | if (!ok) |
| 1856 | set_bit(WriteErrorSeen, &rdev->flags); |
| 1857 | } |
| 1858 | if (!ok) { |
| 1859 | /* We don't worry if we cannot set a bad block - |
| 1860 | * it really is bad so there is no loss in not |
| 1861 | * recording it yet |
| 1862 | */ |
| 1863 | rdev_set_badblocks(rdev, addr, s, 0); |
| 1864 | |
| 1865 | if (rdev != conf->mirrors[dw].rdev) { |
| 1866 | /* need bad block on destination too */ |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 1867 | struct md_rdev *rdev2 = conf->mirrors[dw].rdev; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1868 | addr = r10_bio->devs[1].addr + sect; |
| 1869 | ok = rdev_set_badblocks(rdev2, addr, s, 0); |
| 1870 | if (!ok) { |
| 1871 | /* just abort the recovery */ |
| 1872 | printk(KERN_NOTICE |
| 1873 | "md/raid10:%s: recovery aborted" |
| 1874 | " due to read error\n", |
| 1875 | mdname(mddev)); |
| 1876 | |
| 1877 | conf->mirrors[dw].recovery_disabled |
| 1878 | = mddev->recovery_disabled; |
| 1879 | set_bit(MD_RECOVERY_INTR, |
| 1880 | &mddev->recovery); |
| 1881 | break; |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | sectors -= s; |
| 1887 | sect += s; |
| 1888 | idx++; |
| 1889 | } |
| 1890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 1892 | static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1894 | struct r10conf *conf = mddev->private; |
Namhyung Kim | c65060a | 2011-07-18 17:38:49 +1000 | [diff] [blame] | 1895 | int d; |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1896 | struct bio *wbio, *wbio2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1898 | if (!test_bit(R10BIO_Uptodate, &r10_bio->state)) { |
| 1899 | fix_recovery_read_error(r10_bio); |
| 1900 | end_sync_request(r10_bio); |
| 1901 | return; |
| 1902 | } |
| 1903 | |
Namhyung Kim | c65060a | 2011-07-18 17:38:49 +1000 | [diff] [blame] | 1904 | /* |
| 1905 | * share the pages with the first bio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | * and submit the write request |
| 1907 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | d = r10_bio->devs[1].devnum; |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 1909 | wbio = r10_bio->devs[1].bio; |
| 1910 | wbio2 = r10_bio->devs[1].repl_bio; |
| 1911 | if (wbio->bi_end_io) { |
| 1912 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 1913 | md_sync_acct(conf->mirrors[d].rdev->bdev, wbio->bi_size >> 9); |
| 1914 | generic_make_request(wbio); |
| 1915 | } |
| 1916 | if (wbio2 && wbio2->bi_end_io) { |
| 1917 | atomic_inc(&conf->mirrors[d].replacement->nr_pending); |
| 1918 | md_sync_acct(conf->mirrors[d].replacement->bdev, |
| 1919 | wbio2->bi_size >> 9); |
| 1920 | generic_make_request(wbio2); |
| 1921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | /* |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1926 | * Used by fix_read_error() to decay the per rdev read_errors. |
| 1927 | * We halve the read error count for every hour that has elapsed |
| 1928 | * since the last recorded read error. |
| 1929 | * |
| 1930 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1931 | static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev) |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1932 | { |
| 1933 | struct timespec cur_time_mon; |
| 1934 | unsigned long hours_since_last; |
| 1935 | unsigned int read_errors = atomic_read(&rdev->read_errors); |
| 1936 | |
| 1937 | ktime_get_ts(&cur_time_mon); |
| 1938 | |
| 1939 | if (rdev->last_read_error.tv_sec == 0 && |
| 1940 | rdev->last_read_error.tv_nsec == 0) { |
| 1941 | /* first time we've seen a read error */ |
| 1942 | rdev->last_read_error = cur_time_mon; |
| 1943 | return; |
| 1944 | } |
| 1945 | |
| 1946 | hours_since_last = (cur_time_mon.tv_sec - |
| 1947 | rdev->last_read_error.tv_sec) / 3600; |
| 1948 | |
| 1949 | rdev->last_read_error = cur_time_mon; |
| 1950 | |
| 1951 | /* |
| 1952 | * if hours_since_last is > the number of bits in read_errors |
| 1953 | * just set read errors to 0. We do this to avoid |
| 1954 | * overflowing the shift of read_errors by hours_since_last. |
| 1955 | */ |
| 1956 | if (hours_since_last >= 8 * sizeof(read_errors)) |
| 1957 | atomic_set(&rdev->read_errors, 0); |
| 1958 | else |
| 1959 | atomic_set(&rdev->read_errors, read_errors >> hours_since_last); |
| 1960 | } |
| 1961 | |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 1962 | static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector, |
NeilBrown | 58c54fc | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 1963 | int sectors, struct page *page, int rw) |
| 1964 | { |
| 1965 | sector_t first_bad; |
| 1966 | int bad_sectors; |
| 1967 | |
| 1968 | if (is_badblock(rdev, sector, sectors, &first_bad, &bad_sectors) |
| 1969 | && (rw == READ || test_bit(WriteErrorSeen, &rdev->flags))) |
| 1970 | return -1; |
| 1971 | if (sync_page_io(rdev, sector, sectors << 9, page, rw, false)) |
| 1972 | /* success */ |
| 1973 | return 1; |
| 1974 | if (rw == WRITE) |
| 1975 | set_bit(WriteErrorSeen, &rdev->flags); |
| 1976 | /* need to record an error - either for the block or the device */ |
| 1977 | if (!rdev_set_badblocks(rdev, sector, sectors, 0)) |
| 1978 | md_error(rdev->mddev, rdev); |
| 1979 | return 0; |
| 1980 | } |
| 1981 | |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1982 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | * This is a kernel thread which: |
| 1984 | * |
| 1985 | * 1. Retries failed read operations on working mirrors. |
| 1986 | * 2. Updates the raid superblock when problems encounter. |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1987 | * 3. Performs writes following reads for array synchronising. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | */ |
| 1989 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 1990 | static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10bio *r10_bio) |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 1991 | { |
| 1992 | int sect = 0; /* Offset from r10_bio->sector */ |
| 1993 | int sectors = r10_bio->sectors; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 1994 | struct md_rdev*rdev; |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1995 | int max_read_errors = atomic_read(&mddev->max_corr_read_errors); |
Prasanna S. Panchamukhi | 0544a21 | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 1996 | int d = r10_bio->devs[r10_bio->read_slot].devnum; |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 1997 | |
NeilBrown | 7c4e06f | 2011-05-11 14:53:17 +1000 | [diff] [blame] | 1998 | /* still own a reference to this rdev, so it cannot |
| 1999 | * have been cleared recently. |
| 2000 | */ |
| 2001 | rdev = conf->mirrors[d].rdev; |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 2002 | |
NeilBrown | 7c4e06f | 2011-05-11 14:53:17 +1000 | [diff] [blame] | 2003 | if (test_bit(Faulty, &rdev->flags)) |
| 2004 | /* drive has already been failed, just ignore any |
| 2005 | more fix_read_error() attempts */ |
| 2006 | return; |
| 2007 | |
| 2008 | check_decay_read_errors(mddev, rdev); |
| 2009 | atomic_inc(&rdev->read_errors); |
| 2010 | if (atomic_read(&rdev->read_errors) > max_read_errors) { |
| 2011 | char b[BDEVNAME_SIZE]; |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 2012 | bdevname(rdev->bdev, b); |
| 2013 | |
NeilBrown | 7c4e06f | 2011-05-11 14:53:17 +1000 | [diff] [blame] | 2014 | printk(KERN_NOTICE |
| 2015 | "md/raid10:%s: %s: Raid device exceeded " |
| 2016 | "read_error threshold [cur %d:max %d]\n", |
| 2017 | mdname(mddev), b, |
| 2018 | atomic_read(&rdev->read_errors), max_read_errors); |
| 2019 | printk(KERN_NOTICE |
| 2020 | "md/raid10:%s: %s: Failing raid device\n", |
| 2021 | mdname(mddev), b); |
| 2022 | md_error(mddev, conf->mirrors[d].rdev); |
| 2023 | return; |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 2024 | } |
Robert Becker | 1e50915 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 2025 | |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2026 | while(sectors) { |
| 2027 | int s = sectors; |
| 2028 | int sl = r10_bio->read_slot; |
| 2029 | int success = 0; |
| 2030 | int start; |
| 2031 | |
| 2032 | if (s > (PAGE_SIZE>>9)) |
| 2033 | s = PAGE_SIZE >> 9; |
| 2034 | |
| 2035 | rcu_read_lock(); |
| 2036 | do { |
NeilBrown | 8dbed5c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2037 | sector_t first_bad; |
| 2038 | int bad_sectors; |
| 2039 | |
Prasanna S. Panchamukhi | 0544a21 | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 2040 | d = r10_bio->devs[sl].devnum; |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2041 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
| 2042 | if (rdev && |
NeilBrown | 8dbed5c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2043 | test_bit(In_sync, &rdev->flags) && |
| 2044 | is_badblock(rdev, r10_bio->devs[sl].addr + sect, s, |
| 2045 | &first_bad, &bad_sectors) == 0) { |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2046 | atomic_inc(&rdev->nr_pending); |
| 2047 | rcu_read_unlock(); |
NeilBrown | 2b19336 | 2010-10-27 15:16:40 +1100 | [diff] [blame] | 2048 | success = sync_page_io(rdev, |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2049 | r10_bio->devs[sl].addr + |
Jonathan Brassow | ccebd4c | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 2050 | sect, |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2051 | s<<9, |
Jonathan Brassow | ccebd4c | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 2052 | conf->tmppage, READ, false); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2053 | rdev_dec_pending(rdev, mddev); |
| 2054 | rcu_read_lock(); |
| 2055 | if (success) |
| 2056 | break; |
| 2057 | } |
| 2058 | sl++; |
| 2059 | if (sl == conf->copies) |
| 2060 | sl = 0; |
| 2061 | } while (!success && sl != r10_bio->read_slot); |
| 2062 | rcu_read_unlock(); |
| 2063 | |
| 2064 | if (!success) { |
NeilBrown | 58c54fc | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2065 | /* Cannot read from anywhere, just mark the block |
| 2066 | * as bad on the first device to discourage future |
| 2067 | * reads. |
| 2068 | */ |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2069 | int dn = r10_bio->devs[r10_bio->read_slot].devnum; |
NeilBrown | 58c54fc | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2070 | rdev = conf->mirrors[dn].rdev; |
| 2071 | |
| 2072 | if (!rdev_set_badblocks( |
| 2073 | rdev, |
| 2074 | r10_bio->devs[r10_bio->read_slot].addr |
| 2075 | + sect, |
| 2076 | s, 0)) |
| 2077 | md_error(mddev, rdev); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2078 | break; |
| 2079 | } |
| 2080 | |
| 2081 | start = sl; |
| 2082 | /* write it back and re-read */ |
| 2083 | rcu_read_lock(); |
| 2084 | while (sl != r10_bio->read_slot) { |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 2085 | char b[BDEVNAME_SIZE]; |
Prasanna S. Panchamukhi | 0544a21 | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 2086 | |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2087 | if (sl==0) |
| 2088 | sl = conf->copies; |
| 2089 | sl--; |
| 2090 | d = r10_bio->devs[sl].devnum; |
| 2091 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2092 | if (!rdev || |
| 2093 | !test_bit(In_sync, &rdev->flags)) |
| 2094 | continue; |
| 2095 | |
| 2096 | atomic_inc(&rdev->nr_pending); |
| 2097 | rcu_read_unlock(); |
NeilBrown | 58c54fc | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2098 | if (r10_sync_page_io(rdev, |
| 2099 | r10_bio->devs[sl].addr + |
| 2100 | sect, |
| 2101 | s<<9, conf->tmppage, WRITE) |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2102 | == 0) { |
| 2103 | /* Well, this device is dead */ |
| 2104 | printk(KERN_NOTICE |
| 2105 | "md/raid10:%s: read correction " |
| 2106 | "write failed" |
| 2107 | " (%d sectors at %llu on %s)\n", |
| 2108 | mdname(mddev), s, |
| 2109 | (unsigned long long)( |
| 2110 | sect + rdev->data_offset), |
| 2111 | bdevname(rdev->bdev, b)); |
| 2112 | printk(KERN_NOTICE "md/raid10:%s: %s: failing " |
| 2113 | "drive\n", |
| 2114 | mdname(mddev), |
| 2115 | bdevname(rdev->bdev, b)); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2116 | } |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2117 | rdev_dec_pending(rdev, mddev); |
| 2118 | rcu_read_lock(); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2119 | } |
| 2120 | sl = start; |
| 2121 | while (sl != r10_bio->read_slot) { |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2122 | char b[BDEVNAME_SIZE]; |
Prasanna S. Panchamukhi | 0544a21 | 2010-06-24 13:31:03 +1000 | [diff] [blame] | 2123 | |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2124 | if (sl==0) |
| 2125 | sl = conf->copies; |
| 2126 | sl--; |
| 2127 | d = r10_bio->devs[sl].devnum; |
| 2128 | rdev = rcu_dereference(conf->mirrors[d].rdev); |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2129 | if (!rdev || |
| 2130 | !test_bit(In_sync, &rdev->flags)) |
| 2131 | continue; |
Robert Becker | 67b8dc4 | 2009-12-14 12:49:57 +1100 | [diff] [blame] | 2132 | |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2133 | atomic_inc(&rdev->nr_pending); |
| 2134 | rcu_read_unlock(); |
NeilBrown | 58c54fc | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2135 | switch (r10_sync_page_io(rdev, |
| 2136 | r10_bio->devs[sl].addr + |
| 2137 | sect, |
| 2138 | s<<9, conf->tmppage, |
| 2139 | READ)) { |
| 2140 | case 0: |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2141 | /* Well, this device is dead */ |
| 2142 | printk(KERN_NOTICE |
| 2143 | "md/raid10:%s: unable to read back " |
| 2144 | "corrected sectors" |
| 2145 | " (%d sectors at %llu on %s)\n", |
| 2146 | mdname(mddev), s, |
| 2147 | (unsigned long long)( |
| 2148 | sect + rdev->data_offset), |
| 2149 | bdevname(rdev->bdev, b)); |
| 2150 | printk(KERN_NOTICE "md/raid10:%s: %s: failing " |
| 2151 | "drive\n", |
| 2152 | mdname(mddev), |
| 2153 | bdevname(rdev->bdev, b)); |
NeilBrown | 58c54fc | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2154 | break; |
| 2155 | case 1: |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2156 | printk(KERN_INFO |
| 2157 | "md/raid10:%s: read error corrected" |
| 2158 | " (%d sectors at %llu on %s)\n", |
| 2159 | mdname(mddev), s, |
| 2160 | (unsigned long long)( |
| 2161 | sect + rdev->data_offset), |
| 2162 | bdevname(rdev->bdev, b)); |
| 2163 | atomic_add(s, &rdev->corrected_errors); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2164 | } |
NeilBrown | 1294b9c | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2165 | |
| 2166 | rdev_dec_pending(rdev, mddev); |
| 2167 | rcu_read_lock(); |
NeilBrown | 6814d53 | 2006-10-03 01:15:45 -0700 | [diff] [blame] | 2168 | } |
| 2169 | rcu_read_unlock(); |
| 2170 | |
| 2171 | sectors -= s; |
| 2172 | sect += s; |
| 2173 | } |
| 2174 | } |
| 2175 | |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2176 | static void bi_complete(struct bio *bio, int error) |
| 2177 | { |
| 2178 | complete((struct completion *)bio->bi_private); |
| 2179 | } |
| 2180 | |
| 2181 | static int submit_bio_wait(int rw, struct bio *bio) |
| 2182 | { |
| 2183 | struct completion event; |
| 2184 | rw |= REQ_SYNC; |
| 2185 | |
| 2186 | init_completion(&event); |
| 2187 | bio->bi_private = &event; |
| 2188 | bio->bi_end_io = bi_complete; |
| 2189 | submit_bio(rw, bio); |
| 2190 | wait_for_completion(&event); |
| 2191 | |
| 2192 | return test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 2193 | } |
| 2194 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2195 | static int narrow_write_error(struct r10bio *r10_bio, int i) |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2196 | { |
| 2197 | struct bio *bio = r10_bio->master_bio; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 2198 | struct mddev *mddev = r10_bio->mddev; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 2199 | struct r10conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2200 | struct md_rdev *rdev = conf->mirrors[r10_bio->devs[i].devnum].rdev; |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2201 | /* bio has the data to be written to slot 'i' where |
| 2202 | * we just recently had a write error. |
| 2203 | * We repeatedly clone the bio and trim down to one block, |
| 2204 | * then try the write. Where the write fails we record |
| 2205 | * a bad block. |
| 2206 | * It is conceivable that the bio doesn't exactly align with |
| 2207 | * blocks. We must handle this. |
| 2208 | * |
| 2209 | * We currently own a reference to the rdev. |
| 2210 | */ |
| 2211 | |
| 2212 | int block_sectors; |
| 2213 | sector_t sector; |
| 2214 | int sectors; |
| 2215 | int sect_to_write = r10_bio->sectors; |
| 2216 | int ok = 1; |
| 2217 | |
| 2218 | if (rdev->badblocks.shift < 0) |
| 2219 | return 0; |
| 2220 | |
| 2221 | block_sectors = 1 << rdev->badblocks.shift; |
| 2222 | sector = r10_bio->sector; |
| 2223 | sectors = ((r10_bio->sector + block_sectors) |
| 2224 | & ~(sector_t)(block_sectors - 1)) |
| 2225 | - sector; |
| 2226 | |
| 2227 | while (sect_to_write) { |
| 2228 | struct bio *wbio; |
| 2229 | if (sectors > sect_to_write) |
| 2230 | sectors = sect_to_write; |
| 2231 | /* Write at 'sector' for 'sectors' */ |
| 2232 | wbio = bio_clone_mddev(bio, GFP_NOIO, mddev); |
| 2233 | md_trim_bio(wbio, sector - bio->bi_sector, sectors); |
| 2234 | wbio->bi_sector = (r10_bio->devs[i].addr+ |
| 2235 | rdev->data_offset+ |
| 2236 | (sector - r10_bio->sector)); |
| 2237 | wbio->bi_bdev = rdev->bdev; |
| 2238 | if (submit_bio_wait(WRITE, wbio) == 0) |
| 2239 | /* Failure! */ |
| 2240 | ok = rdev_set_badblocks(rdev, sector, |
| 2241 | sectors, 0) |
| 2242 | && ok; |
| 2243 | |
| 2244 | bio_put(wbio); |
| 2245 | sect_to_write -= sectors; |
| 2246 | sector += sectors; |
| 2247 | sectors = block_sectors; |
| 2248 | } |
| 2249 | return ok; |
| 2250 | } |
| 2251 | |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2252 | static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio) |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2253 | { |
| 2254 | int slot = r10_bio->read_slot; |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2255 | struct bio *bio; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 2256 | struct r10conf *conf = mddev->private; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2257 | struct md_rdev *rdev = r10_bio->devs[slot].rdev; |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2258 | char b[BDEVNAME_SIZE]; |
| 2259 | unsigned long do_sync; |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2260 | int max_sectors; |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2261 | |
| 2262 | /* we got a read error. Maybe the drive is bad. Maybe just |
| 2263 | * the block and we can fix it. |
| 2264 | * We freeze all other IO, and try reading the block from |
| 2265 | * other devices. When we find one, we re-write |
| 2266 | * and check it that fixes the read error. |
| 2267 | * This is all done synchronously while the array is |
| 2268 | * frozen. |
| 2269 | */ |
| 2270 | if (mddev->ro == 0) { |
| 2271 | freeze_array(conf); |
| 2272 | fix_read_error(conf, mddev, r10_bio); |
| 2273 | unfreeze_array(conf); |
| 2274 | } |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2275 | rdev_dec_pending(rdev, mddev); |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2276 | |
| 2277 | bio = r10_bio->devs[slot].bio; |
NeilBrown | 7399c31 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2278 | bdevname(bio->bi_bdev, b); |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2279 | r10_bio->devs[slot].bio = |
| 2280 | mddev->ro ? IO_BLOCKED : NULL; |
NeilBrown | 7399c31 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2281 | read_more: |
NeilBrown | 96c3fd1 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2282 | rdev = read_balance(conf, r10_bio, &max_sectors); |
| 2283 | if (rdev == NULL) { |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2284 | printk(KERN_ALERT "md/raid10:%s: %s: unrecoverable I/O" |
| 2285 | " read error for block %llu\n", |
NeilBrown | 7399c31 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2286 | mdname(mddev), b, |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2287 | (unsigned long long)r10_bio->sector); |
| 2288 | raid_end_bio_io(r10_bio); |
| 2289 | bio_put(bio); |
| 2290 | return; |
| 2291 | } |
| 2292 | |
| 2293 | do_sync = (r10_bio->master_bio->bi_rw & REQ_SYNC); |
NeilBrown | 7399c31 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2294 | if (bio) |
| 2295 | bio_put(bio); |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2296 | slot = r10_bio->read_slot; |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2297 | printk_ratelimited( |
| 2298 | KERN_ERR |
| 2299 | "md/raid10:%s: %s: redirecting" |
| 2300 | "sector %llu to another mirror\n", |
| 2301 | mdname(mddev), |
| 2302 | bdevname(rdev->bdev, b), |
| 2303 | (unsigned long long)r10_bio->sector); |
| 2304 | bio = bio_clone_mddev(r10_bio->master_bio, |
| 2305 | GFP_NOIO, mddev); |
NeilBrown | 7399c31 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2306 | md_trim_bio(bio, |
| 2307 | r10_bio->sector - bio->bi_sector, |
| 2308 | max_sectors); |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2309 | r10_bio->devs[slot].bio = bio; |
NeilBrown | abbf098 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2310 | r10_bio->devs[slot].rdev = rdev; |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2311 | bio->bi_sector = r10_bio->devs[slot].addr |
| 2312 | + rdev->data_offset; |
| 2313 | bio->bi_bdev = rdev->bdev; |
| 2314 | bio->bi_rw = READ | do_sync; |
| 2315 | bio->bi_private = r10_bio; |
| 2316 | bio->bi_end_io = raid10_end_read_request; |
NeilBrown | 7399c31 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2317 | if (max_sectors < r10_bio->sectors) { |
| 2318 | /* Drat - have to split this up more */ |
| 2319 | struct bio *mbio = r10_bio->master_bio; |
| 2320 | int sectors_handled = |
| 2321 | r10_bio->sector + max_sectors |
| 2322 | - mbio->bi_sector; |
| 2323 | r10_bio->sectors = max_sectors; |
| 2324 | spin_lock_irq(&conf->device_lock); |
| 2325 | if (mbio->bi_phys_segments == 0) |
| 2326 | mbio->bi_phys_segments = 2; |
| 2327 | else |
| 2328 | mbio->bi_phys_segments++; |
| 2329 | spin_unlock_irq(&conf->device_lock); |
| 2330 | generic_make_request(bio); |
| 2331 | bio = NULL; |
| 2332 | |
| 2333 | r10_bio = mempool_alloc(conf->r10bio_pool, |
| 2334 | GFP_NOIO); |
| 2335 | r10_bio->master_bio = mbio; |
| 2336 | r10_bio->sectors = (mbio->bi_size >> 9) |
| 2337 | - sectors_handled; |
| 2338 | r10_bio->state = 0; |
| 2339 | set_bit(R10BIO_ReadError, |
| 2340 | &r10_bio->state); |
| 2341 | r10_bio->mddev = mddev; |
| 2342 | r10_bio->sector = mbio->bi_sector |
| 2343 | + sectors_handled; |
| 2344 | |
| 2345 | goto read_more; |
| 2346 | } else |
| 2347 | generic_make_request(bio); |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2348 | } |
| 2349 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 2350 | static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio) |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2351 | { |
| 2352 | /* Some sort of write request has finished and it |
| 2353 | * succeeded in writing where we thought there was a |
| 2354 | * bad block. So forget the bad block. |
NeilBrown | 1a0b7cd | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2355 | * Or possibly if failed and we need to record |
| 2356 | * a bad block. |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2357 | */ |
| 2358 | int m; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2359 | struct md_rdev *rdev; |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2360 | |
| 2361 | if (test_bit(R10BIO_IsSync, &r10_bio->state) || |
| 2362 | test_bit(R10BIO_IsRecover, &r10_bio->state)) { |
NeilBrown | 1a0b7cd | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2363 | for (m = 0; m < conf->copies; m++) { |
| 2364 | int dev = r10_bio->devs[m].devnum; |
| 2365 | rdev = conf->mirrors[dev].rdev; |
| 2366 | if (r10_bio->devs[m].bio == NULL) |
| 2367 | continue; |
| 2368 | if (test_bit(BIO_UPTODATE, |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2369 | &r10_bio->devs[m].bio->bi_flags)) { |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2370 | rdev_clear_badblocks( |
| 2371 | rdev, |
| 2372 | r10_bio->devs[m].addr, |
| 2373 | r10_bio->sectors); |
NeilBrown | 1a0b7cd | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2374 | } else { |
| 2375 | if (!rdev_set_badblocks( |
| 2376 | rdev, |
| 2377 | r10_bio->devs[m].addr, |
| 2378 | r10_bio->sectors, 0)) |
| 2379 | md_error(conf->mddev, rdev); |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2380 | } |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2381 | rdev = conf->mirrors[dev].replacement; |
| 2382 | if (r10_bio->devs[m].repl_bio == NULL) |
| 2383 | continue; |
| 2384 | if (test_bit(BIO_UPTODATE, |
| 2385 | &r10_bio->devs[m].repl_bio->bi_flags)) { |
| 2386 | rdev_clear_badblocks( |
| 2387 | rdev, |
| 2388 | r10_bio->devs[m].addr, |
| 2389 | r10_bio->sectors); |
| 2390 | } else { |
| 2391 | if (!rdev_set_badblocks( |
| 2392 | rdev, |
| 2393 | r10_bio->devs[m].addr, |
| 2394 | r10_bio->sectors, 0)) |
| 2395 | md_error(conf->mddev, rdev); |
| 2396 | } |
NeilBrown | 1a0b7cd | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2397 | } |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2398 | put_buf(r10_bio); |
| 2399 | } else { |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2400 | for (m = 0; m < conf->copies; m++) { |
| 2401 | int dev = r10_bio->devs[m].devnum; |
| 2402 | struct bio *bio = r10_bio->devs[m].bio; |
| 2403 | rdev = conf->mirrors[dev].rdev; |
| 2404 | if (bio == IO_MADE_GOOD) { |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2405 | rdev_clear_badblocks( |
| 2406 | rdev, |
| 2407 | r10_bio->devs[m].addr, |
| 2408 | r10_bio->sectors); |
| 2409 | rdev_dec_pending(rdev, conf->mddev); |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2410 | } else if (bio != NULL && |
| 2411 | !test_bit(BIO_UPTODATE, &bio->bi_flags)) { |
| 2412 | if (!narrow_write_error(r10_bio, m)) { |
| 2413 | md_error(conf->mddev, rdev); |
| 2414 | set_bit(R10BIO_Degraded, |
| 2415 | &r10_bio->state); |
| 2416 | } |
| 2417 | rdev_dec_pending(rdev, conf->mddev); |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2418 | } |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2419 | bio = r10_bio->devs[m].repl_bio; |
| 2420 | rdev = conf->mirrors[dev].replacement; |
NeilBrown | 4ca40c2 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2421 | if (rdev && bio == IO_MADE_GOOD) { |
NeilBrown | 475b032 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2422 | rdev_clear_badblocks( |
| 2423 | rdev, |
| 2424 | r10_bio->devs[m].addr, |
| 2425 | r10_bio->sectors); |
| 2426 | rdev_dec_pending(rdev, conf->mddev); |
| 2427 | } |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2428 | } |
| 2429 | if (test_bit(R10BIO_WriteError, |
| 2430 | &r10_bio->state)) |
| 2431 | close_write(r10_bio); |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2432 | raid_end_bio_io(r10_bio); |
| 2433 | } |
| 2434 | } |
| 2435 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 2436 | static void raid10d(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | { |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2438 | struct r10bio *r10_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | unsigned long flags; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 2440 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | struct list_head *head = &conf->retry_list; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 2442 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | |
| 2444 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 2446 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | for (;;) { |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 2448 | |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 2449 | flush_pending_writes(conf); |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 2450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 2452 | if (list_empty(head)) { |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2453 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | break; |
NeilBrown | a35e63e | 2008-03-04 14:29:29 -0800 | [diff] [blame] | 2455 | } |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2456 | r10_bio = list_entry(head->prev, struct r10bio, retry_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | list_del(head->prev); |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 2458 | conf->nr_queued--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 2460 | |
| 2461 | mddev = r10_bio->mddev; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 2462 | conf = mddev->private; |
NeilBrown | bd870a1 | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2463 | if (test_bit(R10BIO_MadeGood, &r10_bio->state) || |
| 2464 | test_bit(R10BIO_WriteError, &r10_bio->state)) |
NeilBrown | 749c55e | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2465 | handle_write_completed(conf, r10_bio); |
| 2466 | else if (test_bit(R10BIO_IsSync, &r10_bio->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | sync_request_write(mddev, r10_bio); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 2468 | else if (test_bit(R10BIO_IsRecover, &r10_bio->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | recovery_request_write(mddev, r10_bio); |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2470 | else if (test_bit(R10BIO_ReadError, &r10_bio->state)) |
NeilBrown | 560f8e5 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2471 | handle_read_error(mddev, r10_bio); |
NeilBrown | 856e08e | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2472 | else { |
| 2473 | /* just a partial read to be scheduled from a |
| 2474 | * separate context |
| 2475 | */ |
| 2476 | int slot = r10_bio->read_slot; |
| 2477 | generic_make_request(r10_bio->devs[slot].bio); |
| 2478 | } |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 2479 | |
NeilBrown | 1d9d524 | 2009-10-16 15:55:32 +1100 | [diff] [blame] | 2480 | cond_resched(); |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 2481 | if (mddev->flags & ~(1<<MD_CHANGE_PENDING)) |
| 2482 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | } |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 2484 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 2488 | static int init_resync(struct r10conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | { |
| 2490 | int buffs; |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2491 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
| 2493 | buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE; |
Eric Sesterhenn | b638548 | 2006-04-02 13:34:29 +0200 | [diff] [blame] | 2494 | BUG_ON(conf->r10buf_pool); |
NeilBrown | 69335ef | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2495 | conf->have_replacement = 0; |
| 2496 | for (i = 0; i < conf->raid_disks; i++) |
| 2497 | if (conf->mirrors[i].replacement) |
| 2498 | conf->have_replacement = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | conf->r10buf_pool = mempool_create(buffs, r10buf_pool_alloc, r10buf_pool_free, conf); |
| 2500 | if (!conf->r10buf_pool) |
| 2501 | return -ENOMEM; |
| 2502 | conf->next_resync = 0; |
| 2503 | return 0; |
| 2504 | } |
| 2505 | |
| 2506 | /* |
| 2507 | * perform a "sync" on one "block" |
| 2508 | * |
| 2509 | * We need to make sure that no normal I/O request - particularly write |
| 2510 | * requests - conflict with active sync requests. |
| 2511 | * |
| 2512 | * This is achieved by tracking pending requests and a 'barrier' concept |
| 2513 | * that can be installed to exclude normal IO requests. |
| 2514 | * |
| 2515 | * Resync and recovery are handled very differently. |
| 2516 | * We differentiate by looking at MD_RECOVERY_SYNC in mddev->recovery. |
| 2517 | * |
| 2518 | * For resync, we iterate over virtual addresses, read all copies, |
| 2519 | * and update if there are differences. If only one copy is live, |
| 2520 | * skip it. |
| 2521 | * For recovery, we iterate over physical addresses, read a good |
| 2522 | * value for each non-in_sync drive, and over-write. |
| 2523 | * |
| 2524 | * So, for recovery we may have several outstanding complex requests for a |
| 2525 | * given address, one for each out-of-sync device. We model this by allocating |
| 2526 | * a number of r10_bio structures, one for each out-of-sync device. |
| 2527 | * As we setup these structures, we collect all bio's together into a list |
| 2528 | * which we then process collectively to add pages, and then process again |
| 2529 | * to pass to generic_make_request. |
| 2530 | * |
| 2531 | * The r10_bio structures are linked using a borrowed master_bio pointer. |
| 2532 | * This link is counted in ->remaining. When the r10_bio that points to NULL |
| 2533 | * has its remaining count decremented to 0, the whole complex operation |
| 2534 | * is complete. |
| 2535 | * |
| 2536 | */ |
| 2537 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 2538 | static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2539 | int *skipped, int go_faster) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 2541 | struct r10conf *conf = mddev->private; |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2542 | struct r10bio *r10_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | struct bio *biolist = NULL, *bio; |
| 2544 | sector_t max_sector, nr_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | int i; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2546 | int max_sync; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 2547 | sector_t sync_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | sector_t sectors_skipped = 0; |
| 2549 | int chunks_skipped = 0; |
| 2550 | |
| 2551 | if (!conf->r10buf_pool) |
| 2552 | if (init_resync(conf)) |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 2553 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | |
| 2555 | skipped: |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 2556 | max_sector = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 2558 | max_sector = mddev->resync_max_sectors; |
| 2559 | if (sector_nr >= max_sector) { |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2560 | /* If we aborted, we need to abort the |
| 2561 | * sync on the 'current' bitmap chucks (there can |
| 2562 | * be several when recovering multiple devices). |
| 2563 | * as we may have started syncing it but not finished. |
| 2564 | * We can find the current address in |
| 2565 | * mddev->curr_resync, but for recovery, |
| 2566 | * we need to convert that to several |
| 2567 | * virtual addresses. |
| 2568 | */ |
| 2569 | if (mddev->curr_resync < max_sector) { /* aborted */ |
| 2570 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) |
| 2571 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 2572 | &sync_blocks, 1); |
| 2573 | else for (i=0; i<conf->raid_disks; i++) { |
| 2574 | sector_t sect = |
| 2575 | raid10_find_virt(conf, mddev->curr_resync, i); |
| 2576 | bitmap_end_sync(mddev->bitmap, sect, |
| 2577 | &sync_blocks, 1); |
| 2578 | } |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2579 | } else { |
| 2580 | /* completed sync */ |
| 2581 | if ((!mddev->bitmap || conf->fullsync) |
| 2582 | && conf->have_replacement |
| 2583 | && test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 2584 | /* Completed a full sync so the replacements |
| 2585 | * are now fully recovered. |
| 2586 | */ |
| 2587 | for (i = 0; i < conf->raid_disks; i++) |
| 2588 | if (conf->mirrors[i].replacement) |
| 2589 | conf->mirrors[i].replacement |
| 2590 | ->recovery_offset |
| 2591 | = MaxSector; |
| 2592 | } |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2593 | conf->fullsync = 0; |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2594 | } |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2595 | bitmap_close_sync(mddev->bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | close_sync(conf); |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 2597 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | return sectors_skipped; |
| 2599 | } |
| 2600 | if (chunks_skipped >= conf->raid_disks) { |
| 2601 | /* if there has been nothing to do on any drive, |
| 2602 | * then there is nothing to do at all.. |
| 2603 | */ |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 2604 | *skipped = 1; |
| 2605 | return (max_sector - sector_nr) + sectors_skipped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 2608 | if (max_sector > mddev->resync_max) |
| 2609 | max_sector = mddev->resync_max; /* Don't do IO beyond here */ |
| 2610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | /* make sure whole request will fit in a chunk - if chunks |
| 2612 | * are meaningful |
| 2613 | */ |
| 2614 | if (conf->near_copies < conf->raid_disks && |
| 2615 | max_sector > (sector_nr | conf->chunk_mask)) |
| 2616 | max_sector = (sector_nr | conf->chunk_mask) + 1; |
| 2617 | /* |
| 2618 | * If there is non-resync activity waiting for us then |
| 2619 | * put in a delay to throttle resync. |
| 2620 | */ |
NeilBrown | 0a27ec9 | 2006-01-06 00:20:13 -0800 | [diff] [blame] | 2621 | if (!go_faster && conf->nr_waiting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | msleep_interruptible(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | |
| 2624 | /* Again, very different code for resync and recovery. |
| 2625 | * Both must result in an r10bio with a list of bios that |
| 2626 | * have bi_end_io, bi_sector, bi_bdev set, |
| 2627 | * and bi_private set to the r10bio. |
| 2628 | * For recovery, we may actually create several r10bios |
| 2629 | * with 2 bios in each, that correspond to the bios in the main one. |
| 2630 | * In this case, the subordinate r10bios link back through a |
| 2631 | * borrowed master_bio pointer, and the counter in the master |
| 2632 | * includes a ref from each subordinate. |
| 2633 | */ |
| 2634 | /* First, we decide what to do and set ->bi_end_io |
| 2635 | * To end_sync_read if we want to read, and |
| 2636 | * end_sync_write if we will want to write. |
| 2637 | */ |
| 2638 | |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2639 | max_sync = RESYNC_PAGES << (PAGE_SHIFT-9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 2641 | /* recovery... the complicated one */ |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2642 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | r10_bio = NULL; |
| 2644 | |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2645 | for (i=0 ; i<conf->raid_disks; i++) { |
| 2646 | int still_degraded; |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2647 | struct r10bio *rb2; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2648 | sector_t sect; |
| 2649 | int must_sync; |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2650 | int any_working; |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2651 | struct mirror_info *mirror = &conf->mirrors[i]; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2652 | |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2653 | if ((mirror->rdev == NULL || |
| 2654 | test_bit(In_sync, &mirror->rdev->flags)) |
| 2655 | && |
| 2656 | (mirror->replacement == NULL || |
| 2657 | test_bit(Faulty, |
| 2658 | &mirror->replacement->flags))) |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2659 | continue; |
| 2660 | |
| 2661 | still_degraded = 0; |
| 2662 | /* want to reconstruct this device */ |
| 2663 | rb2 = r10_bio; |
| 2664 | sect = raid10_find_virt(conf, sector_nr, i); |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2665 | /* Unless we are doing a full sync, or a replacement |
| 2666 | * we only need to recover the block if it is set in |
| 2667 | * the bitmap |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2668 | */ |
| 2669 | must_sync = bitmap_start_sync(mddev->bitmap, sect, |
| 2670 | &sync_blocks, 1); |
| 2671 | if (sync_blocks < max_sync) |
| 2672 | max_sync = sync_blocks; |
| 2673 | if (!must_sync && |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2674 | mirror->replacement == NULL && |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2675 | !conf->fullsync) { |
| 2676 | /* yep, skip the sync_blocks here, but don't assume |
| 2677 | * that there will never be anything to do here |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2678 | */ |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2679 | chunks_skipped = -1; |
| 2680 | continue; |
| 2681 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2683 | r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO); |
| 2684 | raise_barrier(conf, rb2 != NULL); |
| 2685 | atomic_set(&r10_bio->remaining, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2687 | r10_bio->master_bio = (struct bio*)rb2; |
| 2688 | if (rb2) |
| 2689 | atomic_inc(&rb2->remaining); |
| 2690 | r10_bio->mddev = mddev; |
| 2691 | set_bit(R10BIO_IsRecover, &r10_bio->state); |
| 2692 | r10_bio->sector = sect; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2693 | |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2694 | raid10_find_phys(conf, r10_bio); |
NeilBrown | 1805556 | 2009-05-07 12:48:10 +1000 | [diff] [blame] | 2695 | |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2696 | /* Need to check if the array will still be |
| 2697 | * degraded |
| 2698 | */ |
| 2699 | for (j=0; j<conf->raid_disks; j++) |
| 2700 | if (conf->mirrors[j].rdev == NULL || |
| 2701 | test_bit(Faulty, &conf->mirrors[j].rdev->flags)) { |
| 2702 | still_degraded = 1; |
NeilBrown | 87fc767 | 2005-09-09 16:24:04 -0700 | [diff] [blame] | 2703 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | } |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2705 | |
| 2706 | must_sync = bitmap_start_sync(mddev->bitmap, sect, |
| 2707 | &sync_blocks, still_degraded); |
| 2708 | |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2709 | any_working = 0; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2710 | for (j=0; j<conf->copies;j++) { |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2711 | int k; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2712 | int d = r10_bio->devs[j].devnum; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2713 | sector_t from_addr, to_addr; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2714 | struct md_rdev *rdev; |
NeilBrown | 40c356c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2715 | sector_t sector, first_bad; |
| 2716 | int bad_sectors; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2717 | if (!conf->mirrors[d].rdev || |
| 2718 | !test_bit(In_sync, &conf->mirrors[d].rdev->flags)) |
| 2719 | continue; |
| 2720 | /* This is where we read from */ |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2721 | any_working = 1; |
NeilBrown | 40c356c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2722 | rdev = conf->mirrors[d].rdev; |
| 2723 | sector = r10_bio->devs[j].addr; |
| 2724 | |
| 2725 | if (is_badblock(rdev, sector, max_sync, |
| 2726 | &first_bad, &bad_sectors)) { |
| 2727 | if (first_bad > sector) |
| 2728 | max_sync = first_bad - sector; |
| 2729 | else { |
| 2730 | bad_sectors -= (sector |
| 2731 | - first_bad); |
| 2732 | if (max_sync > bad_sectors) |
| 2733 | max_sync = bad_sectors; |
| 2734 | continue; |
| 2735 | } |
| 2736 | } |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2737 | bio = r10_bio->devs[0].bio; |
| 2738 | bio->bi_next = biolist; |
| 2739 | biolist = bio; |
| 2740 | bio->bi_private = r10_bio; |
| 2741 | bio->bi_end_io = end_sync_read; |
| 2742 | bio->bi_rw = READ; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2743 | from_addr = r10_bio->devs[j].addr; |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2744 | bio->bi_sector = from_addr + rdev->data_offset; |
| 2745 | bio->bi_bdev = rdev->bdev; |
| 2746 | atomic_inc(&rdev->nr_pending); |
| 2747 | /* and we write to 'i' (if not in_sync) */ |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2748 | |
| 2749 | for (k=0; k<conf->copies; k++) |
| 2750 | if (r10_bio->devs[k].devnum == i) |
| 2751 | break; |
| 2752 | BUG_ON(k == conf->copies); |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2753 | to_addr = r10_bio->devs[k].addr; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2754 | r10_bio->devs[0].devnum = d; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2755 | r10_bio->devs[0].addr = from_addr; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2756 | r10_bio->devs[1].devnum = i; |
NeilBrown | 5e57028 | 2011-07-28 11:39:25 +1000 | [diff] [blame] | 2757 | r10_bio->devs[1].addr = to_addr; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2758 | |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2759 | rdev = mirror->rdev; |
| 2760 | if (!test_bit(In_sync, &rdev->flags)) { |
| 2761 | bio = r10_bio->devs[1].bio; |
| 2762 | bio->bi_next = biolist; |
| 2763 | biolist = bio; |
| 2764 | bio->bi_private = r10_bio; |
| 2765 | bio->bi_end_io = end_sync_write; |
| 2766 | bio->bi_rw = WRITE; |
| 2767 | bio->bi_sector = to_addr |
| 2768 | + rdev->data_offset; |
| 2769 | bio->bi_bdev = rdev->bdev; |
| 2770 | atomic_inc(&r10_bio->remaining); |
| 2771 | } else |
| 2772 | r10_bio->devs[1].bio->bi_end_io = NULL; |
| 2773 | |
| 2774 | /* and maybe write to replacement */ |
| 2775 | bio = r10_bio->devs[1].repl_bio; |
| 2776 | if (bio) |
| 2777 | bio->bi_end_io = NULL; |
| 2778 | rdev = mirror->replacement; |
| 2779 | /* Note: if rdev != NULL, then bio |
| 2780 | * cannot be NULL as r10buf_pool_alloc will |
| 2781 | * have allocated it. |
| 2782 | * So the second test here is pointless. |
| 2783 | * But it keeps semantic-checkers happy, and |
| 2784 | * this comment keeps human reviewers |
| 2785 | * happy. |
| 2786 | */ |
| 2787 | if (rdev == NULL || bio == NULL || |
| 2788 | test_bit(Faulty, &rdev->flags)) |
| 2789 | break; |
| 2790 | bio->bi_next = biolist; |
| 2791 | biolist = bio; |
| 2792 | bio->bi_private = r10_bio; |
| 2793 | bio->bi_end_io = end_sync_write; |
| 2794 | bio->bi_rw = WRITE; |
| 2795 | bio->bi_sector = to_addr + rdev->data_offset; |
| 2796 | bio->bi_bdev = rdev->bdev; |
| 2797 | atomic_inc(&r10_bio->remaining); |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2798 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | } |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2800 | if (j == conf->copies) { |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2801 | /* Cannot recover, so abort the recovery or |
| 2802 | * record a bad block */ |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2803 | put_buf(r10_bio); |
| 2804 | if (rb2) |
| 2805 | atomic_dec(&rb2->remaining); |
| 2806 | r10_bio = rb2; |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2807 | if (any_working) { |
| 2808 | /* problem is that there are bad blocks |
| 2809 | * on other device(s) |
| 2810 | */ |
| 2811 | int k; |
| 2812 | for (k = 0; k < conf->copies; k++) |
| 2813 | if (r10_bio->devs[k].devnum == i) |
| 2814 | break; |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2815 | if (!test_bit(In_sync, |
| 2816 | &mirror->rdev->flags) |
| 2817 | && !rdev_set_badblocks( |
| 2818 | mirror->rdev, |
| 2819 | r10_bio->devs[k].addr, |
| 2820 | max_sync, 0)) |
| 2821 | any_working = 0; |
| 2822 | if (mirror->replacement && |
| 2823 | !rdev_set_badblocks( |
| 2824 | mirror->replacement, |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2825 | r10_bio->devs[k].addr, |
| 2826 | max_sync, 0)) |
| 2827 | any_working = 0; |
| 2828 | } |
| 2829 | if (!any_working) { |
| 2830 | if (!test_and_set_bit(MD_RECOVERY_INTR, |
| 2831 | &mddev->recovery)) |
| 2832 | printk(KERN_INFO "md/raid10:%s: insufficient " |
| 2833 | "working devices for recovery.\n", |
| 2834 | mdname(mddev)); |
NeilBrown | 24afd80 | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2835 | mirror->recovery_disabled |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2836 | = mddev->recovery_disabled; |
| 2837 | } |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2838 | break; |
| 2839 | } |
| 2840 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | if (biolist == NULL) { |
| 2842 | while (r10_bio) { |
NeilBrown | 9f2c9d1 | 2011-10-11 16:48:43 +1100 | [diff] [blame] | 2843 | struct r10bio *rb2 = r10_bio; |
| 2844 | r10_bio = (struct r10bio*) rb2->master_bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | rb2->master_bio = NULL; |
| 2846 | put_buf(rb2); |
| 2847 | } |
| 2848 | goto giveup; |
| 2849 | } |
| 2850 | } else { |
| 2851 | /* resync. Schedule a read for every block at this virt offset */ |
| 2852 | int count = 0; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2853 | |
NeilBrown | 78200d4 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 2854 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 2855 | |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2856 | if (!bitmap_start_sync(mddev->bitmap, sector_nr, |
| 2857 | &sync_blocks, mddev->degraded) && |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2858 | !conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, |
| 2859 | &mddev->recovery)) { |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2860 | /* We can skip this block */ |
| 2861 | *skipped = 1; |
| 2862 | return sync_blocks + sectors_skipped; |
| 2863 | } |
| 2864 | if (sync_blocks < max_sync) |
| 2865 | max_sync = sync_blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | r10_bio = mempool_alloc(conf->r10buf_pool, GFP_NOIO); |
| 2867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | r10_bio->mddev = mddev; |
| 2869 | atomic_set(&r10_bio->remaining, 0); |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2870 | raise_barrier(conf, 0); |
| 2871 | conf->next_resync = sector_nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | |
| 2873 | r10_bio->master_bio = NULL; |
| 2874 | r10_bio->sector = sector_nr; |
| 2875 | set_bit(R10BIO_IsSync, &r10_bio->state); |
| 2876 | raid10_find_phys(conf, r10_bio); |
| 2877 | r10_bio->sectors = (sector_nr | conf->chunk_mask) - sector_nr +1; |
| 2878 | |
| 2879 | for (i=0; i<conf->copies; i++) { |
| 2880 | int d = r10_bio->devs[i].devnum; |
NeilBrown | 40c356c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2881 | sector_t first_bad, sector; |
| 2882 | int bad_sectors; |
| 2883 | |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2884 | if (r10_bio->devs[i].repl_bio) |
| 2885 | r10_bio->devs[i].repl_bio->bi_end_io = NULL; |
| 2886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | bio = r10_bio->devs[i].bio; |
| 2888 | bio->bi_end_io = NULL; |
NeilBrown | af03b8e | 2007-06-16 10:16:06 -0700 | [diff] [blame] | 2889 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | if (conf->mirrors[d].rdev == NULL || |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2891 | test_bit(Faulty, &conf->mirrors[d].rdev->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | continue; |
NeilBrown | 40c356c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2893 | sector = r10_bio->devs[i].addr; |
| 2894 | if (is_badblock(conf->mirrors[d].rdev, |
| 2895 | sector, max_sync, |
| 2896 | &first_bad, &bad_sectors)) { |
| 2897 | if (first_bad > sector) |
| 2898 | max_sync = first_bad - sector; |
| 2899 | else { |
| 2900 | bad_sectors -= (sector - first_bad); |
| 2901 | if (max_sync > bad_sectors) |
| 2902 | max_sync = max_sync; |
| 2903 | continue; |
| 2904 | } |
| 2905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 2907 | atomic_inc(&r10_bio->remaining); |
| 2908 | bio->bi_next = biolist; |
| 2909 | biolist = bio; |
| 2910 | bio->bi_private = r10_bio; |
| 2911 | bio->bi_end_io = end_sync_read; |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 2912 | bio->bi_rw = READ; |
NeilBrown | 40c356c | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 2913 | bio->bi_sector = sector + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | conf->mirrors[d].rdev->data_offset; |
| 2915 | bio->bi_bdev = conf->mirrors[d].rdev->bdev; |
| 2916 | count++; |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2917 | |
| 2918 | if (conf->mirrors[d].replacement == NULL || |
| 2919 | test_bit(Faulty, |
| 2920 | &conf->mirrors[d].replacement->flags)) |
| 2921 | continue; |
| 2922 | |
| 2923 | /* Need to set up for writing to the replacement */ |
| 2924 | bio = r10_bio->devs[i].repl_bio; |
| 2925 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
| 2926 | |
| 2927 | sector = r10_bio->devs[i].addr; |
| 2928 | atomic_inc(&conf->mirrors[d].rdev->nr_pending); |
| 2929 | bio->bi_next = biolist; |
| 2930 | biolist = bio; |
| 2931 | bio->bi_private = r10_bio; |
| 2932 | bio->bi_end_io = end_sync_write; |
| 2933 | bio->bi_rw = WRITE; |
| 2934 | bio->bi_sector = sector + |
| 2935 | conf->mirrors[d].replacement->data_offset; |
| 2936 | bio->bi_bdev = conf->mirrors[d].replacement->bdev; |
| 2937 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | if (count < 2) { |
| 2941 | for (i=0; i<conf->copies; i++) { |
| 2942 | int d = r10_bio->devs[i].devnum; |
| 2943 | if (r10_bio->devs[i].bio->bi_end_io) |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2944 | rdev_dec_pending(conf->mirrors[d].rdev, |
| 2945 | mddev); |
NeilBrown | 9ad1aef | 2011-12-23 10:17:55 +1100 | [diff] [blame] | 2946 | if (r10_bio->devs[i].repl_bio && |
| 2947 | r10_bio->devs[i].repl_bio->bi_end_io) |
| 2948 | rdev_dec_pending( |
| 2949 | conf->mirrors[d].replacement, |
| 2950 | mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | } |
| 2952 | put_buf(r10_bio); |
| 2953 | biolist = NULL; |
| 2954 | goto giveup; |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | for (bio = biolist; bio ; bio=bio->bi_next) { |
| 2959 | |
| 2960 | bio->bi_flags &= ~(BIO_POOL_MASK - 1); |
| 2961 | if (bio->bi_end_io) |
| 2962 | bio->bi_flags |= 1 << BIO_UPTODATE; |
| 2963 | bio->bi_vcnt = 0; |
| 2964 | bio->bi_idx = 0; |
| 2965 | bio->bi_phys_segments = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | bio->bi_size = 0; |
| 2967 | } |
| 2968 | |
| 2969 | nr_sectors = 0; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 2970 | if (sector_nr + max_sync < max_sector) |
| 2971 | max_sector = sector_nr + max_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | do { |
| 2973 | struct page *page; |
| 2974 | int len = PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | if (sector_nr + (len>>9) > max_sector) |
| 2976 | len = (max_sector - sector_nr) << 9; |
| 2977 | if (len == 0) |
| 2978 | break; |
| 2979 | for (bio= biolist ; bio ; bio=bio->bi_next) { |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2980 | struct bio *bio2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | page = bio->bi_io_vec[bio->bi_vcnt].bv_page; |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2982 | if (bio_add_page(bio, page, len, 0)) |
| 2983 | continue; |
| 2984 | |
| 2985 | /* stop here */ |
| 2986 | bio->bi_io_vec[bio->bi_vcnt].bv_page = page; |
| 2987 | for (bio2 = biolist; |
| 2988 | bio2 && bio2 != bio; |
| 2989 | bio2 = bio2->bi_next) { |
| 2990 | /* remove last page from this bio */ |
| 2991 | bio2->bi_vcnt--; |
| 2992 | bio2->bi_size -= len; |
| 2993 | bio2->bi_flags &= ~(1<< BIO_SEG_VALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | } |
NeilBrown | ab9d47e | 2011-05-11 14:54:41 +1000 | [diff] [blame] | 2995 | goto bio_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | } |
| 2997 | nr_sectors += len>>9; |
| 2998 | sector_nr += len>>9; |
| 2999 | } while (biolist->bi_vcnt < RESYNC_PAGES); |
| 3000 | bio_full: |
| 3001 | r10_bio->sectors = nr_sectors; |
| 3002 | |
| 3003 | while (biolist) { |
| 3004 | bio = biolist; |
| 3005 | biolist = biolist->bi_next; |
| 3006 | |
| 3007 | bio->bi_next = NULL; |
| 3008 | r10_bio = bio->bi_private; |
| 3009 | r10_bio->sectors = nr_sectors; |
| 3010 | |
| 3011 | if (bio->bi_end_io == end_sync_read) { |
| 3012 | md_sync_acct(bio->bi_bdev, nr_sectors); |
| 3013 | generic_make_request(bio); |
| 3014 | } |
| 3015 | } |
| 3016 | |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 3017 | if (sectors_skipped) |
| 3018 | /* pretend they weren't skipped, it makes |
| 3019 | * no important difference in this case |
| 3020 | */ |
| 3021 | md_done_sync(mddev, sectors_skipped, 1); |
| 3022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | return sectors_skipped + nr_sectors; |
| 3024 | giveup: |
| 3025 | /* There is nowhere to write, so all non-sync |
NeilBrown | e875ece | 2011-07-28 11:39:24 +1000 | [diff] [blame] | 3026 | * drives must be failed or in resync, all drives |
| 3027 | * have a bad block, so try the next chunk... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | */ |
NeilBrown | 09b4068 | 2009-02-25 13:18:47 +1100 | [diff] [blame] | 3029 | if (sector_nr + max_sync < max_sector) |
| 3030 | max_sector = sector_nr + max_sync; |
| 3031 | |
| 3032 | sectors_skipped += (max_sector - sector_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | chunks_skipped ++; |
| 3034 | sector_nr = max_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | goto skipped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 3038 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3039 | raid10_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 3040 | { |
| 3041 | sector_t size; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3042 | struct r10conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 3043 | |
| 3044 | if (!raid_disks) |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 3045 | raid_disks = conf->raid_disks; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 3046 | if (!sectors) |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3047 | sectors = conf->dev_sectors; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 3048 | |
| 3049 | size = sectors >> conf->chunk_shift; |
| 3050 | sector_div(size, conf->far_copies); |
| 3051 | size = size * raid_disks; |
| 3052 | sector_div(size, conf->near_copies); |
| 3053 | |
| 3054 | return size << conf->chunk_shift; |
| 3055 | } |
| 3056 | |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3057 | |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3058 | static struct r10conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3060 | struct r10conf *conf = NULL; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 3061 | int nc, fc, fo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | sector_t stride, size; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3063 | int err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
Maciej Trela | f73ea87 | 2010-06-16 11:46:29 +0100 | [diff] [blame] | 3065 | if (mddev->new_chunk_sectors < (PAGE_SIZE >> 9) || |
| 3066 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3067 | printk(KERN_ERR "md/raid10:%s: chunk size must be " |
| 3068 | "at least PAGE_SIZE(%ld) and be a power of 2.\n", |
| 3069 | mdname(mddev), PAGE_SIZE); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3070 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | } |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3072 | |
Maciej Trela | f73ea87 | 2010-06-16 11:46:29 +0100 | [diff] [blame] | 3073 | nc = mddev->new_layout & 255; |
| 3074 | fc = (mddev->new_layout >> 8) & 255; |
| 3075 | fo = mddev->new_layout & (1<<16); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | if ((nc*fc) <2 || (nc*fc) > mddev->raid_disks || |
Maciej Trela | f73ea87 | 2010-06-16 11:46:29 +0100 | [diff] [blame] | 3078 | (mddev->new_layout >> 17)) { |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3079 | printk(KERN_ERR "md/raid10:%s: unsupported raid10 layout: 0x%8x\n", |
Maciej Trela | f73ea87 | 2010-06-16 11:46:29 +0100 | [diff] [blame] | 3080 | mdname(mddev), mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | goto out; |
| 3082 | } |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3083 | |
| 3084 | err = -ENOMEM; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3085 | conf = kzalloc(sizeof(struct r10conf), GFP_KERNEL); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3086 | if (!conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | goto out; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3088 | |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 3089 | conf->mirrors = kzalloc(sizeof(struct mirror_info)*mddev->raid_disks, |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3090 | GFP_KERNEL); |
| 3091 | if (!conf->mirrors) |
| 3092 | goto out; |
NeilBrown | 4443ae1 | 2006-01-06 00:20:28 -0800 | [diff] [blame] | 3093 | |
| 3094 | conf->tmppage = alloc_page(GFP_KERNEL); |
| 3095 | if (!conf->tmppage) |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3096 | goto out; |
| 3097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 3099 | conf->raid_disks = mddev->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | conf->near_copies = nc; |
| 3101 | conf->far_copies = fc; |
| 3102 | conf->copies = nc*fc; |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 3103 | conf->far_offset = fo; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3104 | conf->chunk_mask = mddev->new_chunk_sectors - 1; |
| 3105 | conf->chunk_shift = ffz(~mddev->new_chunk_sectors); |
| 3106 | |
| 3107 | conf->r10bio_pool = mempool_create(NR_RAID10_BIOS, r10bio_pool_alloc, |
| 3108 | r10bio_pool_free, conf); |
| 3109 | if (!conf->r10bio_pool) |
| 3110 | goto out; |
| 3111 | |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3112 | size = mddev->dev_sectors >> conf->chunk_shift; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 3113 | sector_div(size, fc); |
| 3114 | size = size * conf->raid_disks; |
| 3115 | sector_div(size, nc); |
| 3116 | /* 'size' is now the number of chunks in the array */ |
| 3117 | /* calculate "used chunks per device" in 'stride' */ |
| 3118 | stride = size * conf->copies; |
NeilBrown | af03b8e | 2007-06-16 10:16:06 -0700 | [diff] [blame] | 3119 | |
| 3120 | /* We need to round up when dividing by raid_disks to |
| 3121 | * get the stride size. |
| 3122 | */ |
| 3123 | stride += conf->raid_disks - 1; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 3124 | sector_div(stride, conf->raid_disks); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3125 | |
| 3126 | conf->dev_sectors = stride << conf->chunk_shift; |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 3127 | |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 3128 | if (fo) |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 3129 | stride = 1; |
| 3130 | else |
NeilBrown | c93983b | 2006-06-26 00:27:41 -0700 | [diff] [blame] | 3131 | sector_div(stride, fc); |
NeilBrown | 64a742b | 2007-02-28 20:11:18 -0800 | [diff] [blame] | 3132 | conf->stride = stride << conf->chunk_shift; |
| 3133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | |
Neil Brown | e7e72bf | 2008-05-14 16:05:54 -0700 | [diff] [blame] | 3135 | spin_lock_init(&conf->device_lock); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3136 | INIT_LIST_HEAD(&conf->retry_list); |
| 3137 | |
| 3138 | spin_lock_init(&conf->resync_lock); |
| 3139 | init_waitqueue_head(&conf->wait_barrier); |
| 3140 | |
| 3141 | conf->thread = md_register_thread(raid10d, mddev, NULL); |
| 3142 | if (!conf->thread) |
| 3143 | goto out; |
| 3144 | |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3145 | conf->mddev = mddev; |
| 3146 | return conf; |
| 3147 | |
| 3148 | out: |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3149 | printk(KERN_ERR "md/raid10:%s: couldn't allocate memory.\n", |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3150 | mdname(mddev)); |
| 3151 | if (conf) { |
| 3152 | if (conf->r10bio_pool) |
| 3153 | mempool_destroy(conf->r10bio_pool); |
| 3154 | kfree(conf->mirrors); |
| 3155 | safe_put_page(conf->tmppage); |
| 3156 | kfree(conf); |
| 3157 | } |
| 3158 | return ERR_PTR(err); |
| 3159 | } |
| 3160 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3161 | static int run(struct mddev *mddev) |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3162 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3163 | struct r10conf *conf; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3164 | int i, disk_idx, chunk_size; |
NeilBrown | 0f6d02d | 2011-10-11 16:48:46 +1100 | [diff] [blame] | 3165 | struct mirror_info *disk; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3166 | struct md_rdev *rdev; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3167 | sector_t size; |
| 3168 | |
| 3169 | /* |
| 3170 | * copy the already verified devices into our private RAID10 |
| 3171 | * bookkeeping area. [whatever we allocate in run(), |
| 3172 | * should be freed in stop()] |
| 3173 | */ |
| 3174 | |
| 3175 | if (mddev->private == NULL) { |
| 3176 | conf = setup_conf(mddev); |
| 3177 | if (IS_ERR(conf)) |
| 3178 | return PTR_ERR(conf); |
| 3179 | mddev->private = conf; |
| 3180 | } |
| 3181 | conf = mddev->private; |
| 3182 | if (!conf) |
| 3183 | goto out; |
| 3184 | |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3185 | mddev->thread = conf->thread; |
| 3186 | conf->thread = NULL; |
| 3187 | |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 3188 | chunk_size = mddev->chunk_sectors << 9; |
| 3189 | blk_queue_io_min(mddev->queue, chunk_size); |
| 3190 | if (conf->raid_disks % conf->near_copies) |
| 3191 | blk_queue_io_opt(mddev->queue, chunk_size * conf->raid_disks); |
| 3192 | else |
| 3193 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 3194 | (conf->raid_disks / conf->near_copies)); |
| 3195 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 3196 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
NeilBrown | 34b343c | 2011-07-28 11:31:47 +1000 | [diff] [blame] | 3197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | disk_idx = rdev->raid_disk; |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 3199 | if (disk_idx >= conf->raid_disks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | || disk_idx < 0) |
| 3201 | continue; |
| 3202 | disk = conf->mirrors + disk_idx; |
| 3203 | |
NeilBrown | 56a2559 | 2011-12-23 10:17:55 +1100 | [diff] [blame^] | 3204 | if (test_bit(Replacement, &rdev->flags)) { |
| 3205 | if (disk->replacement) |
| 3206 | goto out_free_conf; |
| 3207 | disk->replacement = rdev; |
| 3208 | } else { |
| 3209 | if (disk->rdev) |
| 3210 | goto out_free_conf; |
| 3211 | disk->rdev = rdev; |
| 3212 | } |
| 3213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | disk->rdev = rdev; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 3215 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 3216 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | /* as we don't honour merge_bvec_fn, we must never risk |
NeilBrown | 627a2d3 | 2010-03-08 16:44:38 +1100 | [diff] [blame] | 3218 | * violating it, so limit max_segments to 1 lying |
| 3219 | * within a single page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | */ |
NeilBrown | 627a2d3 | 2010-03-08 16:44:38 +1100 | [diff] [blame] | 3221 | if (rdev->bdev->bd_disk->queue->merge_bvec_fn) { |
| 3222 | blk_queue_max_segments(mddev->queue, 1); |
| 3223 | blk_queue_segment_boundary(mddev->queue, |
| 3224 | PAGE_CACHE_SIZE - 1); |
| 3225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | |
| 3227 | disk->head_position = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | } |
NeilBrown | 6d50824 | 2005-09-09 16:24:03 -0700 | [diff] [blame] | 3229 | /* need to check that every block has at least one working mirror */ |
NeilBrown | 700c721 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3230 | if (!enough(conf, -1)) { |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3231 | printk(KERN_ERR "md/raid10:%s: not enough operational mirrors.\n", |
NeilBrown | 6d50824 | 2005-09-09 16:24:03 -0700 | [diff] [blame] | 3232 | mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | goto out_free_conf; |
| 3234 | } |
| 3235 | |
| 3236 | mddev->degraded = 0; |
| 3237 | for (i = 0; i < conf->raid_disks; i++) { |
| 3238 | |
| 3239 | disk = conf->mirrors + i; |
| 3240 | |
NeilBrown | 56a2559 | 2011-12-23 10:17:55 +1100 | [diff] [blame^] | 3241 | if (!disk->rdev && disk->replacement) { |
| 3242 | /* The replacement is all we have - use it */ |
| 3243 | disk->rdev = disk->replacement; |
| 3244 | disk->replacement = NULL; |
| 3245 | clear_bit(Replacement, &disk->rdev->flags); |
| 3246 | } |
| 3247 | |
NeilBrown | 5fd6c1d | 2006-06-26 00:27:40 -0700 | [diff] [blame] | 3248 | if (!disk->rdev || |
NeilBrown | 2e333e8 | 2006-10-21 10:24:07 -0700 | [diff] [blame] | 3249 | !test_bit(In_sync, &disk->rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | disk->head_position = 0; |
| 3251 | mddev->degraded++; |
Neil Brown | 8c2e870 | 2008-06-28 08:30:52 +1000 | [diff] [blame] | 3252 | if (disk->rdev) |
| 3253 | conf->fullsync = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | } |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 3255 | disk->recovery_disabled = mddev->recovery_disabled - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | } |
| 3257 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 3258 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3259 | printk(KERN_NOTICE "md/raid10:%s: not clean" |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 3260 | " -- starting background reconstruction\n", |
| 3261 | mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | printk(KERN_INFO |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3263 | "md/raid10:%s: active with %d out of %d devices\n", |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 3264 | mdname(mddev), conf->raid_disks - mddev->degraded, |
| 3265 | conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | /* |
| 3267 | * Ok, everything is just fine now |
| 3268 | */ |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3269 | mddev->dev_sectors = conf->dev_sectors; |
| 3270 | size = raid10_size(mddev, 0, 0); |
| 3271 | md_set_array_sectors(mddev, size); |
| 3272 | mddev->resync_max_sectors = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 3274 | mddev->queue->backing_dev_info.congested_fn = raid10_congested; |
| 3275 | mddev->queue->backing_dev_info.congested_data = mddev; |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 3276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | /* Calculate max read-ahead size. |
| 3278 | * We need to readahead at least twice a whole stripe.... |
| 3279 | * maybe... |
| 3280 | */ |
| 3281 | { |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3282 | int stripe = conf->raid_disks * |
| 3283 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | stripe /= conf->near_copies; |
| 3285 | if (mddev->queue->backing_dev_info.ra_pages < 2* stripe) |
| 3286 | mddev->queue->backing_dev_info.ra_pages = 2* stripe; |
| 3287 | } |
| 3288 | |
NeilBrown | 84707f3 | 2010-03-16 17:23:35 +1100 | [diff] [blame] | 3289 | if (conf->near_copies < conf->raid_disks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec); |
Martin K. Petersen | a91a278 | 2011-03-17 11:11:05 +0100 | [diff] [blame] | 3291 | |
| 3292 | if (md_integrity_register(mddev)) |
| 3293 | goto out_free_conf; |
| 3294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | return 0; |
| 3296 | |
| 3297 | out_free_conf: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 3298 | md_unregister_thread(&mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | if (conf->r10bio_pool) |
| 3300 | mempool_destroy(conf->r10bio_pool); |
NeilBrown | 1345b1d | 2006-01-06 00:20:40 -0800 | [diff] [blame] | 3301 | safe_put_page(conf->tmppage); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 3302 | kfree(conf->mirrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | kfree(conf); |
| 3304 | mddev->private = NULL; |
| 3305 | out: |
| 3306 | return -EIO; |
| 3307 | } |
| 3308 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3309 | static int stop(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3311 | struct r10conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | |
NeilBrown | 409c57f | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 3313 | raise_barrier(conf, 0); |
| 3314 | lower_barrier(conf); |
| 3315 | |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 3316 | md_unregister_thread(&mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
| 3318 | if (conf->r10bio_pool) |
| 3319 | mempool_destroy(conf->r10bio_pool); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 3320 | kfree(conf->mirrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | kfree(conf); |
| 3322 | mddev->private = NULL; |
| 3323 | return 0; |
| 3324 | } |
| 3325 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3326 | static void raid10_quiesce(struct mddev *mddev, int state) |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3327 | { |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3328 | struct r10conf *conf = mddev->private; |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3329 | |
| 3330 | switch(state) { |
| 3331 | case 1: |
| 3332 | raise_barrier(conf, 0); |
| 3333 | break; |
| 3334 | case 0: |
| 3335 | lower_barrier(conf); |
| 3336 | break; |
| 3337 | } |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3340 | static void *raid10_takeover_raid0(struct mddev *mddev) |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3341 | { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3342 | struct md_rdev *rdev; |
NeilBrown | e879a87 | 2011-10-11 16:49:02 +1100 | [diff] [blame] | 3343 | struct r10conf *conf; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3344 | |
| 3345 | if (mddev->degraded > 0) { |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3346 | printk(KERN_ERR "md/raid10:%s: Error: degraded raid0!\n", |
| 3347 | mdname(mddev)); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3348 | return ERR_PTR(-EINVAL); |
| 3349 | } |
| 3350 | |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3351 | /* Set new parameters */ |
| 3352 | mddev->new_level = 10; |
| 3353 | /* new layout: far_copies = 1, near_copies = 2 */ |
| 3354 | mddev->new_layout = (1<<8) + 2; |
| 3355 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 3356 | mddev->delta_disks = mddev->raid_disks; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3357 | mddev->raid_disks *= 2; |
| 3358 | /* make sure it will be not marked as dirty */ |
| 3359 | mddev->recovery_cp = MaxSector; |
| 3360 | |
| 3361 | conf = setup_conf(mddev); |
Krzysztof Wojcik | 02214dc | 2011-02-04 14:18:26 +0100 | [diff] [blame] | 3362 | if (!IS_ERR(conf)) { |
NeilBrown | e93f68a | 2010-06-15 09:36:03 +0100 | [diff] [blame] | 3363 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 3364 | if (rdev->raid_disk >= 0) |
| 3365 | rdev->new_raid_disk = rdev->raid_disk * 2; |
Krzysztof Wojcik | 02214dc | 2011-02-04 14:18:26 +0100 | [diff] [blame] | 3366 | conf->barrier = 1; |
| 3367 | } |
| 3368 | |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3369 | return conf; |
| 3370 | } |
| 3371 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3372 | static void *raid10_takeover(struct mddev *mddev) |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3373 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 3374 | struct r0conf *raid0_conf; |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3375 | |
| 3376 | /* raid10 can take over: |
| 3377 | * raid0 - providing it has only two drives |
| 3378 | */ |
| 3379 | if (mddev->level == 0) { |
| 3380 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 3381 | raid0_conf = mddev->private; |
| 3382 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | 128595e | 2010-05-03 14:47:14 +1000 | [diff] [blame] | 3383 | printk(KERN_ERR "md/raid10:%s: cannot takeover raid 0" |
| 3384 | " with more than one zone.\n", |
| 3385 | mdname(mddev)); |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3386 | return ERR_PTR(-EINVAL); |
| 3387 | } |
| 3388 | return raid10_takeover_raid0(mddev); |
| 3389 | } |
| 3390 | return ERR_PTR(-EINVAL); |
| 3391 | } |
| 3392 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 3393 | static struct md_personality raid10_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | { |
| 3395 | .name = "raid10", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3396 | .level = 10, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | .owner = THIS_MODULE, |
| 3398 | .make_request = make_request, |
| 3399 | .run = run, |
| 3400 | .stop = stop, |
| 3401 | .status = status, |
| 3402 | .error_handler = error, |
| 3403 | .hot_add_disk = raid10_add_disk, |
| 3404 | .hot_remove_disk= raid10_remove_disk, |
| 3405 | .spare_active = raid10_spare_active, |
| 3406 | .sync_request = sync_request, |
NeilBrown | 6cce3b2 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 3407 | .quiesce = raid10_quiesce, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 3408 | .size = raid10_size, |
Trela, Maciej | dab8b29 | 2010-03-08 16:02:45 +1100 | [diff] [blame] | 3409 | .takeover = raid10_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | }; |
| 3411 | |
| 3412 | static int __init raid_init(void) |
| 3413 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3414 | return register_md_personality(&raid10_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | static void raid_exit(void) |
| 3418 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3419 | unregister_md_personality(&raid10_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | module_init(raid_init); |
| 3423 | module_exit(raid_exit); |
| 3424 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 3425 | MODULE_DESCRIPTION("RAID10 (striped mirror) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | MODULE_ALIAS("md-personality-9"); /* RAID10 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 3427 | MODULE_ALIAS("md-raid10"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 3428 | MODULE_ALIAS("md-level-10"); |
NeilBrown | 34db0cd | 2011-10-11 16:50:01 +1100 | [diff] [blame] | 3429 | |
| 3430 | module_param(max_queued_requests, int, S_IRUGO|S_IWUSR); |