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