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