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