Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * raid5.c : Multiple Devices driver for Linux |
| 3 | * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman |
| 4 | * Copyright (C) 1999, 2000 Ingo Molnar |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5 | * Copyright (C) 2002, 2003 H. Peter Anvin |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7 | * RAID-4/5/6 management functions. |
| 8 | * Thanks to Penguin Computing for making the RAID-6 development possible |
| 9 | * by donating a test server! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 21 | /* |
| 22 | * BITMAP UNPLUGGING: |
| 23 | * |
| 24 | * The sequencing for updating the bitmap reliably is a little |
| 25 | * subtle (and I got it wrong the first time) so it deserves some |
| 26 | * explanation. |
| 27 | * |
| 28 | * We group bitmap updates into batches. Each batch has a number. |
| 29 | * We may write out several batches at once, but that isn't very important. |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 30 | * conf->seq_write is the number of the last batch successfully written. |
| 31 | * conf->seq_flush is the number of the last batch that was closed to |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 32 | * new additions. |
| 33 | * When we discover that we will need to write to any block in a stripe |
| 34 | * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 35 | * the number of the batch it will be in. This is seq_flush+1. |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 36 | * When we are ready to do a write, if that batch hasn't been written yet, |
| 37 | * we plug the array and queue the stripe for later. |
| 38 | * When an unplug happens, we increment bm_flush, thus closing the current |
| 39 | * batch. |
| 40 | * When we notice that bm_flush > bm_write, we write out all pending updates |
| 41 | * to the bitmap, and advance bm_write to where bm_flush was. |
| 42 | * This may occasionally write a bit out twice, but is sure never to |
| 43 | * miss any bits. |
| 44 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 46 | #include <linux/blkdev.h> |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 47 | #include <linux/kthread.h> |
Dan Williams | f701d58 | 2009-03-31 15:09:39 +1100 | [diff] [blame] | 48 | #include <linux/raid/pq.h> |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 49 | #include <linux/async_tx.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Dan Williams | 07a3b41 | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 51 | #include <linux/async.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 52 | #include <linux/seq_file.h> |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 53 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 54 | #include <linux/slab.h> |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 55 | #include <linux/ratelimit.h> |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 56 | #include <trace/events/block.h> |
| 57 | |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 58 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 59 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 60 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 61 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Stripe cache |
| 65 | */ |
| 66 | |
| 67 | #define NR_STRIPES 256 |
| 68 | #define STRIPE_SIZE PAGE_SIZE |
| 69 | #define STRIPE_SHIFT (PAGE_SHIFT - 9) |
| 70 | #define STRIPE_SECTORS (STRIPE_SIZE>>9) |
| 71 | #define IO_THRESHOLD 1 |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 72 | #define BYPASS_THRESHOLD 1 |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 73 | #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define HASH_MASK (NR_HASH - 1) |
| 75 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 76 | static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 77 | { |
| 78 | int hash = (sect >> STRIPE_SHIFT) & HASH_MASK; |
| 79 | return &conf->stripe_hashtbl[hash]; |
| 80 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | /* bio's attached to a stripe+device for I/O are linked together in bi_sector |
| 83 | * order without overlap. There may be several bio's per stripe+device, and |
| 84 | * a bio could span several devices. |
| 85 | * When walking this list for a particular stripe+device, we must never proceed |
| 86 | * beyond a bio that extends past this device, as the next bio might no longer |
| 87 | * be valid. |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 88 | * This function is used to determine the 'next' bio in the list, given the sector |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | * of the current stripe+device |
| 90 | */ |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 91 | static inline struct bio *r5_next_bio(struct bio *bio, sector_t sector) |
| 92 | { |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 93 | int sectors = bio_sectors(bio); |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 94 | if (bio->bi_sector + sectors < sector + STRIPE_SECTORS) |
| 95 | return bio->bi_next; |
| 96 | else |
| 97 | return NULL; |
| 98 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 100 | /* |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 101 | * We maintain a biased count of active stripes in the bottom 16 bits of |
| 102 | * bi_phys_segments, and a count of processed stripes in the upper 16 bits |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 103 | */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 104 | static inline int raid5_bi_processed_stripes(struct bio *bio) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 105 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 106 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 107 | return (atomic_read(segments) >> 16) & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 110 | static inline int raid5_dec_bi_active_stripes(struct bio *bio) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 111 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 112 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 113 | return atomic_sub_return(1, segments) & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 114 | } |
| 115 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 116 | static inline void raid5_inc_bi_active_stripes(struct bio *bio) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 117 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 118 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 119 | atomic_inc(segments); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 122 | static inline void raid5_set_bi_processed_stripes(struct bio *bio, |
| 123 | unsigned int cnt) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 124 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 125 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 126 | int old, new; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 127 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 128 | do { |
| 129 | old = atomic_read(segments); |
| 130 | new = (old & 0xffff) | (cnt << 16); |
| 131 | } while (atomic_cmpxchg(segments, old, new) != old); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 134 | static inline void raid5_set_bi_stripes(struct bio *bio, unsigned int cnt) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 135 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 136 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 137 | atomic_set(segments, cnt); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 138 | } |
| 139 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 140 | /* Find first data disk in a raid6 stripe */ |
| 141 | static inline int raid6_d0(struct stripe_head *sh) |
| 142 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 143 | if (sh->ddf_layout) |
| 144 | /* ddf always start from first device */ |
| 145 | return 0; |
| 146 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 147 | if (sh->qd_idx == sh->disks - 1) |
| 148 | return 0; |
| 149 | else |
| 150 | return sh->qd_idx + 1; |
| 151 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 152 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 153 | { |
| 154 | disk++; |
| 155 | return (disk < raid_disks) ? disk : 0; |
| 156 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 157 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 158 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 159 | * We need to map each disk to a 'slot', where the data disks are slot |
| 160 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 161 | * is raid_disks-1. This help does that mapping. |
| 162 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 163 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 164 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 165 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 166 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 167 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 168 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 169 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 170 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 171 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 172 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 173 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 174 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 175 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 176 | return slot; |
| 177 | } |
| 178 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 179 | static void return_io(struct bio *return_bi) |
| 180 | { |
| 181 | struct bio *bi = return_bi; |
| 182 | while (bi) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 183 | |
| 184 | return_bi = bi->bi_next; |
| 185 | bi->bi_next = NULL; |
| 186 | bi->bi_size = 0; |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 187 | trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), |
| 188 | bi, 0); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 189 | bio_endio(bi, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 190 | bi = return_bi; |
| 191 | } |
| 192 | } |
| 193 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 194 | static void print_raid5_conf (struct r5conf *conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 196 | static int stripe_operations_active(struct stripe_head *sh) |
| 197 | { |
| 198 | return sh->check_state || sh->reconstruct_state || |
| 199 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 200 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 201 | } |
| 202 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 203 | static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 205 | BUG_ON(!list_empty(&sh->lru)); |
| 206 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
| 207 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
| 208 | if (test_bit(STRIPE_DELAYED, &sh->state) && |
| 209 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 210 | list_add_tail(&sh->lru, &conf->delayed_list); |
| 211 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
| 212 | sh->bm_seq - conf->seq_write > 0) |
| 213 | list_add_tail(&sh->lru, &conf->bitmap_list); |
| 214 | else { |
| 215 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 216 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
| 217 | list_add_tail(&sh->lru, &conf->handle_list); |
| 218 | } |
| 219 | md_wakeup_thread(conf->mddev->thread); |
| 220 | } else { |
| 221 | BUG_ON(stripe_operations_active(sh)); |
| 222 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 223 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 224 | < IO_THRESHOLD) |
| 225 | md_wakeup_thread(conf->mddev->thread); |
| 226 | atomic_dec(&conf->active_stripes); |
| 227 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 228 | list_add_tail(&sh->lru, &conf->inactive_list); |
| 229 | wake_up(&conf->wait_for_stripe); |
| 230 | if (conf->retry_read_aligned) |
| 231 | md_wakeup_thread(conf->mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 235 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 236 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh) |
| 237 | { |
| 238 | if (atomic_dec_and_test(&sh->count)) |
| 239 | do_release_stripe(conf, sh); |
| 240 | } |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | static void release_stripe(struct stripe_head *sh) |
| 243 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 244 | struct r5conf *conf = sh->raid_conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | unsigned long flags; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 246 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 247 | local_irq_save(flags); |
| 248 | if (atomic_dec_and_lock(&sh->count, &conf->device_lock)) { |
| 249 | do_release_stripe(conf, sh); |
| 250 | spin_unlock(&conf->device_lock); |
| 251 | } |
| 252 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 255 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 257 | pr_debug("remove_hash(), stripe %llu\n", |
| 258 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 260 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 263 | static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 265 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 267 | pr_debug("insert_hash(), stripe %llu\n", |
| 268 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 270 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
| 274 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 275 | static struct stripe_head *get_free_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | struct stripe_head *sh = NULL; |
| 278 | struct list_head *first; |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (list_empty(&conf->inactive_list)) |
| 281 | goto out; |
| 282 | first = conf->inactive_list.next; |
| 283 | sh = list_entry(first, struct stripe_head, lru); |
| 284 | list_del_init(first); |
| 285 | remove_hash(sh); |
| 286 | atomic_inc(&conf->active_stripes); |
| 287 | out: |
| 288 | return sh; |
| 289 | } |
| 290 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 291 | static void shrink_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
| 293 | struct page *p; |
| 294 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 295 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 297 | for (i = 0; i < num ; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | p = sh->dev[i].page; |
| 299 | if (!p) |
| 300 | continue; |
| 301 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 302 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 306 | static int grow_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 309 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 311 | for (i = 0; i < num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct page *page; |
| 313 | |
| 314 | if (!(page = alloc_page(GFP_KERNEL))) { |
| 315 | return 1; |
| 316 | } |
| 317 | sh->dev[i].page = page; |
| 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 322 | static void raid5_build_block(struct stripe_head *sh, int i, int previous); |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 323 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 324 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 326 | static void init_stripe(struct stripe_head *sh, sector_t sector, int previous) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 328 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 329 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 331 | BUG_ON(atomic_read(&sh->count) != 0); |
| 332 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 333 | BUG_ON(stripe_operations_active(sh)); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 334 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 335 | pr_debug("init_stripe called, stripe %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | (unsigned long long)sh->sector); |
| 337 | |
| 338 | remove_hash(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 339 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 340 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 341 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 343 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | sh->state = 0; |
| 345 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 346 | |
| 347 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | struct r5dev *dev = &sh->dev[i]; |
| 349 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 350 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | test_bit(R5_LOCKED, &dev->flags)) { |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 352 | printk(KERN_ERR "sector=%llx i=%d %p %p %p %p %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 354 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | test_bit(R5_LOCKED, &dev->flags)); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 356 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 359 | raid5_build_block(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | insert_hash(conf, sh); |
| 362 | } |
| 363 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 364 | static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 365 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
| 367 | struct stripe_head *sh; |
| 368 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 369 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 370 | hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 371 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 373 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | return NULL; |
| 375 | } |
| 376 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 377 | /* |
| 378 | * Need to check if array has failed when deciding whether to: |
| 379 | * - start an array |
| 380 | * - remove non-faulty devices |
| 381 | * - add a spare |
| 382 | * - allow a reshape |
| 383 | * This determination is simple when no reshape is happening. |
| 384 | * However if there is a reshape, we need to carefully check |
| 385 | * both the before and after sections. |
| 386 | * This is because some failed devices may only affect one |
| 387 | * of the two sections, and some non-in_sync devices may |
| 388 | * be insync in the section most affected by failed devices. |
| 389 | */ |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 390 | static int calc_degraded(struct r5conf *conf) |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 391 | { |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 392 | int degraded, degraded2; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 393 | int i; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 394 | |
| 395 | rcu_read_lock(); |
| 396 | degraded = 0; |
| 397 | for (i = 0; i < conf->previous_raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 398 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 399 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 400 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 401 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 402 | degraded++; |
| 403 | else if (test_bit(In_sync, &rdev->flags)) |
| 404 | ; |
| 405 | else |
| 406 | /* not in-sync or faulty. |
| 407 | * If the reshape increases the number of devices, |
| 408 | * this is being recovered by the reshape, so |
| 409 | * this 'previous' section is not in_sync. |
| 410 | * If the number of devices is being reduced however, |
| 411 | * the device can only be part of the array if |
| 412 | * we are reverting a reshape, so this section will |
| 413 | * be in-sync. |
| 414 | */ |
| 415 | if (conf->raid_disks >= conf->previous_raid_disks) |
| 416 | degraded++; |
| 417 | } |
| 418 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 419 | if (conf->raid_disks == conf->previous_raid_disks) |
| 420 | return degraded; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 421 | rcu_read_lock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 422 | degraded2 = 0; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 423 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 424 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 425 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 426 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 427 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 428 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 429 | else if (test_bit(In_sync, &rdev->flags)) |
| 430 | ; |
| 431 | else |
| 432 | /* not in-sync or faulty. |
| 433 | * If reshape increases the number of devices, this |
| 434 | * section has already been recovered, else it |
| 435 | * almost certainly hasn't. |
| 436 | */ |
| 437 | if (conf->raid_disks <= conf->previous_raid_disks) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 438 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 439 | } |
| 440 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 441 | if (degraded2 > degraded) |
| 442 | return degraded2; |
| 443 | return degraded; |
| 444 | } |
| 445 | |
| 446 | static int has_failed(struct r5conf *conf) |
| 447 | { |
| 448 | int degraded; |
| 449 | |
| 450 | if (conf->mddev->reshape_position == MaxSector) |
| 451 | return conf->mddev->degraded > conf->max_degraded; |
| 452 | |
| 453 | degraded = calc_degraded(conf); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 454 | if (degraded > conf->max_degraded) |
| 455 | return 1; |
| 456 | return 0; |
| 457 | } |
| 458 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 459 | static struct stripe_head * |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 460 | get_active_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 461 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
| 463 | struct stripe_head *sh; |
| 464 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 465 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | spin_lock_irq(&conf->device_lock); |
| 468 | |
| 469 | do { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 470 | wait_event_lock_irq(conf->wait_for_stripe, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 471 | conf->quiesce == 0 || noquiesce, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 472 | conf->device_lock); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 473 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | if (!sh) { |
| 475 | if (!conf->inactive_blocked) |
| 476 | sh = get_free_stripe(conf); |
| 477 | if (noblock && sh == NULL) |
| 478 | break; |
| 479 | if (!sh) { |
| 480 | conf->inactive_blocked = 1; |
| 481 | wait_event_lock_irq(conf->wait_for_stripe, |
| 482 | !list_empty(&conf->inactive_list) && |
NeilBrown | 5036805 | 2005-12-12 02:39:17 -0800 | [diff] [blame] | 483 | (atomic_read(&conf->active_stripes) |
| 484 | < (conf->max_nr_stripes *3/4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | || !conf->inactive_blocked), |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 486 | conf->device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | conf->inactive_blocked = 0; |
| 488 | } else |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 489 | init_stripe(sh, sector, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } else { |
| 491 | if (atomic_read(&sh->count)) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 492 | BUG_ON(!list_empty(&sh->lru) |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 493 | && !test_bit(STRIPE_EXPANDING, &sh->state) |
| 494 | && !test_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } else { |
| 496 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 497 | atomic_inc(&conf->active_stripes); |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 498 | if (list_empty(&sh->lru) && |
| 499 | !test_bit(STRIPE_EXPANDING, &sh->state)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 500 | BUG(); |
| 501 | list_del_init(&sh->lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | } while (sh == NULL); |
| 505 | |
| 506 | if (sh) |
| 507 | atomic_inc(&sh->count); |
| 508 | |
| 509 | spin_unlock_irq(&conf->device_lock); |
| 510 | return sh; |
| 511 | } |
| 512 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 513 | /* Determine if 'data_offset' or 'new_data_offset' should be used |
| 514 | * in this stripe_head. |
| 515 | */ |
| 516 | static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) |
| 517 | { |
| 518 | sector_t progress = conf->reshape_progress; |
| 519 | /* Need a memory barrier to make sure we see the value |
| 520 | * of conf->generation, or ->data_offset that was set before |
| 521 | * reshape_progress was updated. |
| 522 | */ |
| 523 | smp_rmb(); |
| 524 | if (progress == MaxSector) |
| 525 | return 0; |
| 526 | if (sh->generation == conf->generation - 1) |
| 527 | return 0; |
| 528 | /* We are in a reshape, and this is a new-generation stripe, |
| 529 | * so use new_data_offset. |
| 530 | */ |
| 531 | return 1; |
| 532 | } |
| 533 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 534 | static void |
| 535 | raid5_end_read_request(struct bio *bi, int error); |
| 536 | static void |
| 537 | raid5_end_write_request(struct bio *bi, int error); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 538 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 539 | static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 540 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 541 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 542 | int i, disks = sh->disks; |
| 543 | |
| 544 | might_sleep(); |
| 545 | |
| 546 | for (i = disks; i--; ) { |
| 547 | int rw; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 548 | int replace_only = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 549 | struct bio *bi, *rbi; |
| 550 | struct md_rdev *rdev, *rrdev = NULL; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 551 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { |
| 552 | if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) |
| 553 | rw = WRITE_FUA; |
| 554 | else |
| 555 | rw = WRITE; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 556 | if (test_bit(R5_Discard, &sh->dev[i].flags)) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 557 | rw |= REQ_DISCARD; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 558 | } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 559 | rw = READ; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 560 | else if (test_and_clear_bit(R5_WantReplace, |
| 561 | &sh->dev[i].flags)) { |
| 562 | rw = WRITE; |
| 563 | replace_only = 1; |
| 564 | } else |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 565 | continue; |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 566 | if (test_and_clear_bit(R5_SyncIO, &sh->dev[i].flags)) |
| 567 | rw |= REQ_SYNC; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 568 | |
| 569 | bi = &sh->dev[i].req; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 570 | rbi = &sh->dev[i].rreq; /* For writing to replacement */ |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 571 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 572 | rcu_read_lock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 573 | rrdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 574 | smp_mb(); /* Ensure that if rrdev is NULL, rdev won't be */ |
| 575 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 576 | if (!rdev) { |
| 577 | rdev = rrdev; |
| 578 | rrdev = NULL; |
| 579 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 580 | if (rw & WRITE) { |
| 581 | if (replace_only) |
| 582 | rdev = NULL; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 583 | if (rdev == rrdev) |
| 584 | /* We raced and saw duplicates */ |
| 585 | rrdev = NULL; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 586 | } else { |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 587 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags) && rrdev) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 588 | rdev = rrdev; |
| 589 | rrdev = NULL; |
| 590 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 591 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 592 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 593 | rdev = NULL; |
| 594 | if (rdev) |
| 595 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 596 | if (rrdev && test_bit(Faulty, &rrdev->flags)) |
| 597 | rrdev = NULL; |
| 598 | if (rrdev) |
| 599 | atomic_inc(&rrdev->nr_pending); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 600 | rcu_read_unlock(); |
| 601 | |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 602 | /* We have already checked bad blocks for reads. Now |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 603 | * need to check for writes. We never accept write errors |
| 604 | * on the replacement, so we don't to check rrdev. |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 605 | */ |
| 606 | while ((rw & WRITE) && rdev && |
| 607 | test_bit(WriteErrorSeen, &rdev->flags)) { |
| 608 | sector_t first_bad; |
| 609 | int bad_sectors; |
| 610 | int bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 611 | &first_bad, &bad_sectors); |
| 612 | if (!bad) |
| 613 | break; |
| 614 | |
| 615 | if (bad < 0) { |
| 616 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 617 | if (!conf->mddev->external && |
| 618 | conf->mddev->flags) { |
| 619 | /* It is very unlikely, but we might |
| 620 | * still need to write out the |
| 621 | * bad block log - better give it |
| 622 | * a chance*/ |
| 623 | md_check_recovery(conf->mddev); |
| 624 | } |
majianpeng | 1850753 | 2012-07-03 12:11:54 +1000 | [diff] [blame] | 625 | /* |
| 626 | * Because md_wait_for_blocked_rdev |
| 627 | * will dec nr_pending, we must |
| 628 | * increment it first. |
| 629 | */ |
| 630 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 631 | md_wait_for_blocked_rdev(rdev, conf->mddev); |
| 632 | } else { |
| 633 | /* Acknowledged bad block - skip the write */ |
| 634 | rdev_dec_pending(rdev, conf->mddev); |
| 635 | rdev = NULL; |
| 636 | } |
| 637 | } |
| 638 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 639 | if (rdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 640 | if (s->syncing || s->expanding || s->expanded |
| 641 | || s->replacing) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 642 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 643 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 644 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 645 | |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 646 | bio_reset(bi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 647 | bi->bi_bdev = rdev->bdev; |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 648 | bi->bi_rw = rw; |
| 649 | bi->bi_end_io = (rw & WRITE) |
| 650 | ? raid5_end_write_request |
| 651 | : raid5_end_read_request; |
| 652 | bi->bi_private = sh; |
| 653 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 654 | pr_debug("%s: for %llu schedule op %ld on disc %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 655 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 656 | bi->bi_rw, i); |
| 657 | atomic_inc(&sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 658 | if (use_new_offset(conf, sh)) |
| 659 | bi->bi_sector = (sh->sector |
| 660 | + rdev->new_data_offset); |
| 661 | else |
| 662 | bi->bi_sector = (sh->sector |
| 663 | + rdev->data_offset); |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 664 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 665 | bi->bi_rw |= REQ_FLUSH; |
| 666 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 667 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 668 | bi->bi_io_vec[0].bv_offset = 0; |
| 669 | bi->bi_size = STRIPE_SIZE; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 670 | if (rrdev) |
| 671 | set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 672 | |
| 673 | if (conf->mddev->gendisk) |
| 674 | trace_block_bio_remap(bdev_get_queue(bi->bi_bdev), |
| 675 | bi, disk_devt(conf->mddev->gendisk), |
| 676 | sh->dev[i].sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 677 | generic_make_request(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 678 | } |
| 679 | if (rrdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 680 | if (s->syncing || s->expanding || s->expanded |
| 681 | || s->replacing) |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 682 | md_sync_acct(rrdev->bdev, STRIPE_SECTORS); |
| 683 | |
| 684 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 685 | |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 686 | bio_reset(rbi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 687 | rbi->bi_bdev = rrdev->bdev; |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 688 | rbi->bi_rw = rw; |
| 689 | BUG_ON(!(rw & WRITE)); |
| 690 | rbi->bi_end_io = raid5_end_write_request; |
| 691 | rbi->bi_private = sh; |
| 692 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 693 | pr_debug("%s: for %llu schedule op %ld on " |
| 694 | "replacement disc %d\n", |
| 695 | __func__, (unsigned long long)sh->sector, |
| 696 | rbi->bi_rw, i); |
| 697 | atomic_inc(&sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 698 | if (use_new_offset(conf, sh)) |
| 699 | rbi->bi_sector = (sh->sector |
| 700 | + rrdev->new_data_offset); |
| 701 | else |
| 702 | rbi->bi_sector = (sh->sector |
| 703 | + rrdev->data_offset); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 704 | rbi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 705 | rbi->bi_io_vec[0].bv_offset = 0; |
| 706 | rbi->bi_size = STRIPE_SIZE; |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 707 | if (conf->mddev->gendisk) |
| 708 | trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev), |
| 709 | rbi, disk_devt(conf->mddev->gendisk), |
| 710 | sh->dev[i].sector); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 711 | generic_make_request(rbi); |
| 712 | } |
| 713 | if (!rdev && !rrdev) { |
Namhyung Kim | b062962 | 2011-06-14 14:20:19 +1000 | [diff] [blame] | 714 | if (rw & WRITE) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 715 | set_bit(STRIPE_DEGRADED, &sh->state); |
| 716 | pr_debug("skip op %ld on disc %d for sector %llu\n", |
| 717 | bi->bi_rw, i, (unsigned long long)sh->sector); |
| 718 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 719 | set_bit(STRIPE_HANDLE, &sh->state); |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | static struct dma_async_tx_descriptor * |
| 725 | async_copy_data(int frombio, struct bio *bio, struct page *page, |
| 726 | sector_t sector, struct dma_async_tx_descriptor *tx) |
| 727 | { |
| 728 | struct bio_vec *bvl; |
| 729 | struct page *bio_page; |
| 730 | int i; |
| 731 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 732 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 733 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 734 | |
| 735 | if (bio->bi_sector >= sector) |
| 736 | page_offset = (signed)(bio->bi_sector - sector) * 512; |
| 737 | else |
| 738 | page_offset = (signed)(sector - bio->bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 739 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 740 | if (frombio) |
| 741 | flags |= ASYNC_TX_FENCE; |
| 742 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 743 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 744 | bio_for_each_segment(bvl, bio, i) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 745 | int len = bvl->bv_len; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 746 | int clen; |
| 747 | int b_offset = 0; |
| 748 | |
| 749 | if (page_offset < 0) { |
| 750 | b_offset = -page_offset; |
| 751 | page_offset += b_offset; |
| 752 | len -= b_offset; |
| 753 | } |
| 754 | |
| 755 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 756 | clen = STRIPE_SIZE - page_offset; |
| 757 | else |
| 758 | clen = len; |
| 759 | |
| 760 | if (clen > 0) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 761 | b_offset += bvl->bv_offset; |
| 762 | bio_page = bvl->bv_page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 763 | if (frombio) |
| 764 | tx = async_memcpy(page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 765 | b_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 766 | else |
| 767 | tx = async_memcpy(bio_page, page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 768 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 769 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 770 | /* chain the operations */ |
| 771 | submit.depend_tx = tx; |
| 772 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 773 | if (clen < len) /* hit end of page */ |
| 774 | break; |
| 775 | page_offset += len; |
| 776 | } |
| 777 | |
| 778 | return tx; |
| 779 | } |
| 780 | |
| 781 | static void ops_complete_biofill(void *stripe_head_ref) |
| 782 | { |
| 783 | struct stripe_head *sh = stripe_head_ref; |
| 784 | struct bio *return_bi = NULL; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 785 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 786 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 787 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 788 | (unsigned long long)sh->sector); |
| 789 | |
| 790 | /* clear completed biofills */ |
| 791 | for (i = sh->disks; i--; ) { |
| 792 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 793 | |
| 794 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 795 | /* and check if we need to reply to a read request, |
| 796 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 797 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 798 | */ |
| 799 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 800 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 801 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 802 | BUG_ON(!dev->read); |
| 803 | rbi = dev->read; |
| 804 | dev->read = NULL; |
| 805 | while (rbi && rbi->bi_sector < |
| 806 | dev->sector + STRIPE_SECTORS) { |
| 807 | rbi2 = r5_next_bio(rbi, dev->sector); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 808 | if (!raid5_dec_bi_active_stripes(rbi)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 809 | rbi->bi_next = return_bi; |
| 810 | return_bi = rbi; |
| 811 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 812 | rbi = rbi2; |
| 813 | } |
| 814 | } |
| 815 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 816 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 817 | |
| 818 | return_io(return_bi); |
| 819 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 820 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 821 | release_stripe(sh); |
| 822 | } |
| 823 | |
| 824 | static void ops_run_biofill(struct stripe_head *sh) |
| 825 | { |
| 826 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 827 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 828 | int i; |
| 829 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 830 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 831 | (unsigned long long)sh->sector); |
| 832 | |
| 833 | for (i = sh->disks; i--; ) { |
| 834 | struct r5dev *dev = &sh->dev[i]; |
| 835 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 836 | struct bio *rbi; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 837 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 838 | dev->read = rbi = dev->toread; |
| 839 | dev->toread = NULL; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 840 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 841 | while (rbi && rbi->bi_sector < |
| 842 | dev->sector + STRIPE_SECTORS) { |
| 843 | tx = async_copy_data(0, rbi, dev->page, |
| 844 | dev->sector, tx); |
| 845 | rbi = r5_next_bio(rbi, dev->sector); |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 851 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 852 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 855 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 856 | { |
| 857 | struct r5dev *tgt; |
| 858 | |
| 859 | if (target < 0) |
| 860 | return; |
| 861 | |
| 862 | tgt = &sh->dev[target]; |
| 863 | set_bit(R5_UPTODATE, &tgt->flags); |
| 864 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 865 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 866 | } |
| 867 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 868 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 869 | { |
| 870 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 871 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 872 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 873 | (unsigned long long)sh->sector); |
| 874 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 875 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 876 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 877 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 878 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 879 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 880 | if (sh->check_state == check_state_compute_run) |
| 881 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 882 | set_bit(STRIPE_HANDLE, &sh->state); |
| 883 | release_stripe(sh); |
| 884 | } |
| 885 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 886 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 887 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 888 | struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 889 | { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 890 | return percpu->scribble + sizeof(struct page *) * (sh->disks + 2); |
| 891 | } |
| 892 | |
| 893 | static struct dma_async_tx_descriptor * |
| 894 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 895 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 896 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 897 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 898 | int target = sh->ops.target; |
| 899 | struct r5dev *tgt = &sh->dev[target]; |
| 900 | struct page *xor_dest = tgt->page; |
| 901 | int count = 0; |
| 902 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 903 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 904 | int i; |
| 905 | |
| 906 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 907 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 908 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 909 | |
| 910 | for (i = disks; i--; ) |
| 911 | if (i != target) |
| 912 | xor_srcs[count++] = sh->dev[i].page; |
| 913 | |
| 914 | atomic_inc(&sh->count); |
| 915 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 916 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, NULL, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 917 | ops_complete_compute, sh, to_addr_conv(sh, percpu)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 918 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 919 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 920 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 921 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 922 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 923 | return tx; |
| 924 | } |
| 925 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 926 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 927 | * @srcs - (struct page *) array of size sh->disks |
| 928 | * @sh - stripe_head to parse |
| 929 | * |
| 930 | * Populates srcs in proper layout order for the stripe and returns the |
| 931 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 932 | * destination buffer is recorded in srcs[count] and the Q destination |
| 933 | * is recorded in srcs[count+1]]. |
| 934 | */ |
| 935 | static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh) |
| 936 | { |
| 937 | int disks = sh->disks; |
| 938 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 939 | int d0_idx = raid6_d0(sh); |
| 940 | int count; |
| 941 | int i; |
| 942 | |
| 943 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 944 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 945 | |
| 946 | count = 0; |
| 947 | i = d0_idx; |
| 948 | do { |
| 949 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 950 | |
| 951 | srcs[slot] = sh->dev[i].page; |
| 952 | i = raid6_next_disk(i, disks); |
| 953 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 954 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 955 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | static struct dma_async_tx_descriptor * |
| 959 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 960 | { |
| 961 | int disks = sh->disks; |
| 962 | struct page **blocks = percpu->scribble; |
| 963 | int target; |
| 964 | int qd_idx = sh->qd_idx; |
| 965 | struct dma_async_tx_descriptor *tx; |
| 966 | struct async_submit_ctl submit; |
| 967 | struct r5dev *tgt; |
| 968 | struct page *dest; |
| 969 | int i; |
| 970 | int count; |
| 971 | |
| 972 | if (sh->ops.target < 0) |
| 973 | target = sh->ops.target2; |
| 974 | else if (sh->ops.target2 < 0) |
| 975 | target = sh->ops.target; |
| 976 | else |
| 977 | /* we should only have one valid target */ |
| 978 | BUG(); |
| 979 | BUG_ON(target < 0); |
| 980 | pr_debug("%s: stripe %llu block: %d\n", |
| 981 | __func__, (unsigned long long)sh->sector, target); |
| 982 | |
| 983 | tgt = &sh->dev[target]; |
| 984 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 985 | dest = tgt->page; |
| 986 | |
| 987 | atomic_inc(&sh->count); |
| 988 | |
| 989 | if (target == qd_idx) { |
| 990 | count = set_syndrome_sources(blocks, sh); |
| 991 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 992 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 993 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 994 | ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 995 | to_addr_conv(sh, percpu)); |
| 996 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 997 | } else { |
| 998 | /* Compute any data- or p-drive using XOR */ |
| 999 | count = 0; |
| 1000 | for (i = disks; i-- ; ) { |
| 1001 | if (i == target || i == qd_idx) |
| 1002 | continue; |
| 1003 | blocks[count++] = sh->dev[i].page; |
| 1004 | } |
| 1005 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1006 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1007 | NULL, ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1008 | to_addr_conv(sh, percpu)); |
| 1009 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 1010 | } |
| 1011 | |
| 1012 | return tx; |
| 1013 | } |
| 1014 | |
| 1015 | static struct dma_async_tx_descriptor * |
| 1016 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1017 | { |
| 1018 | int i, count, disks = sh->disks; |
| 1019 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 1020 | int d0_idx = raid6_d0(sh); |
| 1021 | int faila = -1, failb = -1; |
| 1022 | int target = sh->ops.target; |
| 1023 | int target2 = sh->ops.target2; |
| 1024 | struct r5dev *tgt = &sh->dev[target]; |
| 1025 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 1026 | struct dma_async_tx_descriptor *tx; |
| 1027 | struct page **blocks = percpu->scribble; |
| 1028 | struct async_submit_ctl submit; |
| 1029 | |
| 1030 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 1031 | __func__, (unsigned long long)sh->sector, target, target2); |
| 1032 | BUG_ON(target < 0 || target2 < 0); |
| 1033 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1034 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 1035 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1036 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1037 | * slot number conversion for 'faila' and 'failb' |
| 1038 | */ |
| 1039 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1040 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1041 | count = 0; |
| 1042 | i = d0_idx; |
| 1043 | do { |
| 1044 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 1045 | |
| 1046 | blocks[slot] = sh->dev[i].page; |
| 1047 | |
| 1048 | if (i == target) |
| 1049 | faila = slot; |
| 1050 | if (i == target2) |
| 1051 | failb = slot; |
| 1052 | i = raid6_next_disk(i, disks); |
| 1053 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1054 | |
| 1055 | BUG_ON(faila == failb); |
| 1056 | if (failb < faila) |
| 1057 | swap(faila, failb); |
| 1058 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 1059 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 1060 | |
| 1061 | atomic_inc(&sh->count); |
| 1062 | |
| 1063 | if (failb == syndrome_disks+1) { |
| 1064 | /* Q disk is one of the missing disks */ |
| 1065 | if (faila == syndrome_disks) { |
| 1066 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1067 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1068 | ops_complete_compute, sh, |
| 1069 | to_addr_conv(sh, percpu)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1070 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1071 | STRIPE_SIZE, &submit); |
| 1072 | } else { |
| 1073 | struct page *dest; |
| 1074 | int data_target; |
| 1075 | int qd_idx = sh->qd_idx; |
| 1076 | |
| 1077 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 1078 | if (target == qd_idx) |
| 1079 | data_target = target2; |
| 1080 | else |
| 1081 | data_target = target; |
| 1082 | |
| 1083 | count = 0; |
| 1084 | for (i = disks; i-- ; ) { |
| 1085 | if (i == data_target || i == qd_idx) |
| 1086 | continue; |
| 1087 | blocks[count++] = sh->dev[i].page; |
| 1088 | } |
| 1089 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1090 | init_async_submit(&submit, |
| 1091 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1092 | NULL, NULL, NULL, |
| 1093 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1094 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 1095 | &submit); |
| 1096 | |
| 1097 | count = set_syndrome_sources(blocks, sh); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1098 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 1099 | ops_complete_compute, sh, |
| 1100 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1101 | return async_gen_syndrome(blocks, 0, count+2, |
| 1102 | STRIPE_SIZE, &submit); |
| 1103 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1104 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1105 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1106 | ops_complete_compute, sh, |
| 1107 | to_addr_conv(sh, percpu)); |
| 1108 | if (failb == syndrome_disks) { |
| 1109 | /* We're missing D+P. */ |
| 1110 | return async_raid6_datap_recov(syndrome_disks+2, |
| 1111 | STRIPE_SIZE, faila, |
| 1112 | blocks, &submit); |
| 1113 | } else { |
| 1114 | /* We're missing D+D. */ |
| 1115 | return async_raid6_2data_recov(syndrome_disks+2, |
| 1116 | STRIPE_SIZE, faila, failb, |
| 1117 | blocks, &submit); |
| 1118 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1123 | static void ops_complete_prexor(void *stripe_head_ref) |
| 1124 | { |
| 1125 | struct stripe_head *sh = stripe_head_ref; |
| 1126 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1127 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1128 | (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static struct dma_async_tx_descriptor * |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1132 | ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1133 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1134 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1135 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1136 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1137 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1138 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1139 | |
| 1140 | /* existing parity data subtracted */ |
| 1141 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1142 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1143 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1144 | (unsigned long long)sh->sector); |
| 1145 | |
| 1146 | for (i = disks; i--; ) { |
| 1147 | struct r5dev *dev = &sh->dev[i]; |
| 1148 | /* Only process blocks that are known to be uptodate */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1149 | if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1150 | xor_srcs[count++] = dev->page; |
| 1151 | } |
| 1152 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1153 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_DROP_DST, tx, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1154 | ops_complete_prexor, sh, to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1155 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1156 | |
| 1157 | return tx; |
| 1158 | } |
| 1159 | |
| 1160 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1161 | ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1162 | { |
| 1163 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1164 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1165 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1166 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1167 | (unsigned long long)sh->sector); |
| 1168 | |
| 1169 | for (i = disks; i--; ) { |
| 1170 | struct r5dev *dev = &sh->dev[i]; |
| 1171 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1172 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1173 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1174 | struct bio *wbi; |
| 1175 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1176 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1177 | chosen = dev->towrite; |
| 1178 | dev->towrite = NULL; |
| 1179 | BUG_ON(dev->written); |
| 1180 | wbi = dev->written = chosen; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1181 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1182 | |
| 1183 | while (wbi && wbi->bi_sector < |
| 1184 | dev->sector + STRIPE_SECTORS) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1185 | if (wbi->bi_rw & REQ_FUA) |
| 1186 | set_bit(R5_WantFUA, &dev->flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1187 | if (wbi->bi_rw & REQ_SYNC) |
| 1188 | set_bit(R5_SyncIO, &dev->flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1189 | if (wbi->bi_rw & REQ_DISCARD) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1190 | set_bit(R5_Discard, &dev->flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1191 | else |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1192 | tx = async_copy_data(1, wbi, dev->page, |
| 1193 | dev->sector, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1194 | wbi = r5_next_bio(wbi, dev->sector); |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | return tx; |
| 1200 | } |
| 1201 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1202 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1203 | { |
| 1204 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1205 | int disks = sh->disks; |
| 1206 | int pd_idx = sh->pd_idx; |
| 1207 | int qd_idx = sh->qd_idx; |
| 1208 | int i; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1209 | bool fua = false, sync = false, discard = false; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1210 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1211 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1212 | (unsigned long long)sh->sector); |
| 1213 | |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1214 | for (i = disks; i--; ) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1215 | fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1216 | sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1217 | discard |= test_bit(R5_Discard, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1218 | } |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1219 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1220 | for (i = disks; i--; ) { |
| 1221 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1222 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1223 | if (dev->written || i == pd_idx || i == qd_idx) { |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1224 | if (!discard) |
| 1225 | set_bit(R5_UPTODATE, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1226 | if (fua) |
| 1227 | set_bit(R5_WantFUA, &dev->flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1228 | if (sync) |
| 1229 | set_bit(R5_SyncIO, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1230 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1233 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 1234 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 1235 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 1236 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 1237 | else { |
| 1238 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 1239 | sh->reconstruct_state = reconstruct_state_result; |
| 1240 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1241 | |
| 1242 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1243 | release_stripe(sh); |
| 1244 | } |
| 1245 | |
| 1246 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1247 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1248 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1249 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1250 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1251 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1252 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1253 | int count = 0, pd_idx = sh->pd_idx, i; |
| 1254 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1255 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1256 | unsigned long flags; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1257 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1258 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1259 | (unsigned long long)sh->sector); |
| 1260 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1261 | for (i = 0; i < sh->disks; i++) { |
| 1262 | if (pd_idx == i) |
| 1263 | continue; |
| 1264 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1265 | break; |
| 1266 | } |
| 1267 | if (i >= sh->disks) { |
| 1268 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1269 | set_bit(R5_Discard, &sh->dev[pd_idx].flags); |
| 1270 | ops_complete_reconstruct(sh); |
| 1271 | return; |
| 1272 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1273 | /* check if prexor is active which means only process blocks |
| 1274 | * that are part of a read-modify-write (written) |
| 1275 | */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1276 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1277 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1278 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1279 | for (i = disks; i--; ) { |
| 1280 | struct r5dev *dev = &sh->dev[i]; |
| 1281 | if (dev->written) |
| 1282 | xor_srcs[count++] = dev->page; |
| 1283 | } |
| 1284 | } else { |
| 1285 | xor_dest = sh->dev[pd_idx].page; |
| 1286 | for (i = disks; i--; ) { |
| 1287 | struct r5dev *dev = &sh->dev[i]; |
| 1288 | if (i != pd_idx) |
| 1289 | xor_srcs[count++] = dev->page; |
| 1290 | } |
| 1291 | } |
| 1292 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1293 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1294 | * 2/ if we did not prexor then we are redoing the parity |
| 1295 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1296 | * for the synchronous xor case |
| 1297 | */ |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 1298 | flags = ASYNC_TX_ACK | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1299 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
| 1300 | |
| 1301 | atomic_inc(&sh->count); |
| 1302 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1303 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, sh, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1304 | to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1305 | if (unlikely(count == 1)) |
| 1306 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1307 | else |
| 1308 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1311 | static void |
| 1312 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1313 | struct dma_async_tx_descriptor *tx) |
| 1314 | { |
| 1315 | struct async_submit_ctl submit; |
| 1316 | struct page **blocks = percpu->scribble; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1317 | int count, i; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1318 | |
| 1319 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1320 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1321 | for (i = 0; i < sh->disks; i++) { |
| 1322 | if (sh->pd_idx == i || sh->qd_idx == i) |
| 1323 | continue; |
| 1324 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1325 | break; |
| 1326 | } |
| 1327 | if (i >= sh->disks) { |
| 1328 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1329 | set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 1330 | set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 1331 | ops_complete_reconstruct(sh); |
| 1332 | return; |
| 1333 | } |
| 1334 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1335 | count = set_syndrome_sources(blocks, sh); |
| 1336 | |
| 1337 | atomic_inc(&sh->count); |
| 1338 | |
| 1339 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct, |
| 1340 | sh, to_addr_conv(sh, percpu)); |
| 1341 | async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static void ops_complete_check(void *stripe_head_ref) |
| 1345 | { |
| 1346 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1347 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1348 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1349 | (unsigned long long)sh->sector); |
| 1350 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1351 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1352 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1353 | release_stripe(sh); |
| 1354 | } |
| 1355 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1356 | static void ops_run_check_p(struct stripe_head *sh, struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1357 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1358 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1359 | int pd_idx = sh->pd_idx; |
| 1360 | int qd_idx = sh->qd_idx; |
| 1361 | struct page *xor_dest; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1362 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1363 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1364 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1365 | int count; |
| 1366 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1367 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1368 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1369 | (unsigned long long)sh->sector); |
| 1370 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1371 | count = 0; |
| 1372 | xor_dest = sh->dev[pd_idx].page; |
| 1373 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1374 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1375 | if (i == pd_idx || i == qd_idx) |
| 1376 | continue; |
| 1377 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1380 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
| 1381 | to_addr_conv(sh, percpu)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1382 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1383 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1384 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1385 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1386 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 1387 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1390 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 1391 | { |
| 1392 | struct page **srcs = percpu->scribble; |
| 1393 | struct async_submit_ctl submit; |
| 1394 | int count; |
| 1395 | |
| 1396 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 1397 | (unsigned long long)sh->sector, checkp); |
| 1398 | |
| 1399 | count = set_syndrome_sources(srcs, sh); |
| 1400 | if (!checkp) |
| 1401 | srcs[count] = NULL; |
| 1402 | |
| 1403 | atomic_inc(&sh->count); |
| 1404 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
| 1405 | sh, to_addr_conv(sh, percpu)); |
| 1406 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 1407 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 1408 | } |
| 1409 | |
NeilBrown | 51acbce | 2013-02-28 09:08:34 +1100 | [diff] [blame] | 1410 | static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1411 | { |
| 1412 | int overlap_clear = 0, i, disks = sh->disks; |
| 1413 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1414 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1415 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1416 | struct raid5_percpu *percpu; |
| 1417 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1418 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1419 | cpu = get_cpu(); |
| 1420 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1421 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1422 | ops_run_biofill(sh); |
| 1423 | overlap_clear++; |
| 1424 | } |
| 1425 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1426 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1427 | if (level < 6) |
| 1428 | tx = ops_run_compute5(sh, percpu); |
| 1429 | else { |
| 1430 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 1431 | tx = ops_run_compute6_1(sh, percpu); |
| 1432 | else |
| 1433 | tx = ops_run_compute6_2(sh, percpu); |
| 1434 | } |
| 1435 | /* terminate the chain if reconstruct is not set to be run */ |
| 1436 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1437 | async_tx_ack(tx); |
| 1438 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1439 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1440 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1441 | tx = ops_run_prexor(sh, percpu, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1442 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1443 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1444 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1445 | overlap_clear++; |
| 1446 | } |
| 1447 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1448 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 1449 | if (level < 6) |
| 1450 | ops_run_reconstruct5(sh, percpu, tx); |
| 1451 | else |
| 1452 | ops_run_reconstruct6(sh, percpu, tx); |
| 1453 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1454 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1455 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 1456 | if (sh->check_state == check_state_run) |
| 1457 | ops_run_check_p(sh, percpu); |
| 1458 | else if (sh->check_state == check_state_run_q) |
| 1459 | ops_run_check_pq(sh, percpu, 0); |
| 1460 | else if (sh->check_state == check_state_run_pq) |
| 1461 | ops_run_check_pq(sh, percpu, 1); |
| 1462 | else |
| 1463 | BUG(); |
| 1464 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1465 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1466 | if (overlap_clear) |
| 1467 | for (i = disks; i--; ) { |
| 1468 | struct r5dev *dev = &sh->dev[i]; |
| 1469 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 1470 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 1471 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1472 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1475 | static int grow_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | { |
| 1477 | struct stripe_head *sh; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1478 | sh = kmem_cache_zalloc(conf->slab_cache, GFP_KERNEL); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1479 | if (!sh) |
| 1480 | return 0; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1481 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1482 | sh->raid_conf = conf; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1483 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1484 | spin_lock_init(&sh->stripe_lock); |
| 1485 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1486 | if (grow_buffers(sh)) { |
| 1487 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1488 | kmem_cache_free(conf->slab_cache, sh); |
| 1489 | return 0; |
| 1490 | } |
| 1491 | /* we just created an active stripe so... */ |
| 1492 | atomic_set(&sh->count, 1); |
| 1493 | atomic_inc(&conf->active_stripes); |
| 1494 | INIT_LIST_HEAD(&sh->lru); |
| 1495 | release_stripe(sh); |
| 1496 | return 1; |
| 1497 | } |
| 1498 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1499 | static int grow_stripes(struct r5conf *conf, int num) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1500 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1501 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1502 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 1504 | if (conf->mddev->gendisk) |
| 1505 | sprintf(conf->cache_name[0], |
| 1506 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 1507 | else |
| 1508 | sprintf(conf->cache_name[0], |
| 1509 | "raid%d-%p", conf->level, conf->mddev); |
| 1510 | sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]); |
| 1511 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1512 | conf->active_name = 0; |
| 1513 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1515 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | if (!sc) |
| 1517 | return 1; |
| 1518 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1519 | conf->pool_size = devs; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1520 | while (num--) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1521 | if (!grow_one_stripe(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | return 0; |
| 1524 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 1525 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1526 | /** |
| 1527 | * scribble_len - return the required size of the scribble region |
| 1528 | * @num - total number of disks in the array |
| 1529 | * |
| 1530 | * The size must be enough to contain: |
| 1531 | * 1/ a struct page pointer for each device in the array +2 |
| 1532 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 1533 | * (dma_map_page()) or page (page_address()) address. |
| 1534 | * |
| 1535 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 1536 | * calculate over all devices (not just the data blocks), using zeros in place |
| 1537 | * of the P and Q blocks. |
| 1538 | */ |
| 1539 | static size_t scribble_len(int num) |
| 1540 | { |
| 1541 | size_t len; |
| 1542 | |
| 1543 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
| 1544 | |
| 1545 | return len; |
| 1546 | } |
| 1547 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1548 | static int resize_stripes(struct r5conf *conf, int newsize) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1549 | { |
| 1550 | /* Make all the stripes able to hold 'newsize' devices. |
| 1551 | * New slots in each stripe get 'page' set to a new page. |
| 1552 | * |
| 1553 | * This happens in stages: |
| 1554 | * 1/ create a new kmem_cache and allocate the required number of |
| 1555 | * stripe_heads. |
Masanari Iida | 83f0d77 | 2012-10-30 00:18:08 +0900 | [diff] [blame] | 1556 | * 2/ gather all the old stripe_heads and transfer the pages across |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1557 | * to the new stripe_heads. This will have the side effect of |
| 1558 | * freezing the array as once all stripe_heads have been collected, |
| 1559 | * no IO will be possible. Old stripe heads are freed once their |
| 1560 | * pages have been transferred over, and the old kmem_cache is |
| 1561 | * freed when all stripes are done. |
| 1562 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 1563 | * we simple return a failre status - no need to clean anything up. |
| 1564 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 1565 | * If this fails, we don't bother trying the shrink the |
| 1566 | * stripe_heads down again, we just leave them as they are. |
| 1567 | * As each stripe_head is processed the new one is released into |
| 1568 | * active service. |
| 1569 | * |
| 1570 | * Once step2 is started, we cannot afford to wait for a write, |
| 1571 | * so we use GFP_NOIO allocations. |
| 1572 | */ |
| 1573 | struct stripe_head *osh, *nsh; |
| 1574 | LIST_HEAD(newstripes); |
| 1575 | struct disk_info *ndisks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1576 | unsigned long cpu; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1577 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1578 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1579 | int i; |
| 1580 | |
| 1581 | if (newsize <= conf->pool_size) |
| 1582 | return 0; /* never bother to shrink */ |
| 1583 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1584 | err = md_allow_write(conf->mddev); |
| 1585 | if (err) |
| 1586 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 1587 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1588 | /* Step 1 */ |
| 1589 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 1590 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1591 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1592 | if (!sc) |
| 1593 | return -ENOMEM; |
| 1594 | |
| 1595 | for (i = conf->max_nr_stripes; i; i--) { |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1596 | nsh = kmem_cache_zalloc(sc, GFP_KERNEL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1597 | if (!nsh) |
| 1598 | break; |
| 1599 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1600 | nsh->raid_conf = conf; |
NeilBrown | cb13ff6 | 2012-09-24 16:27:20 +1000 | [diff] [blame] | 1601 | spin_lock_init(&nsh->stripe_lock); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1602 | |
| 1603 | list_add(&nsh->lru, &newstripes); |
| 1604 | } |
| 1605 | if (i) { |
| 1606 | /* didn't get enough, give up */ |
| 1607 | while (!list_empty(&newstripes)) { |
| 1608 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1609 | list_del(&nsh->lru); |
| 1610 | kmem_cache_free(sc, nsh); |
| 1611 | } |
| 1612 | kmem_cache_destroy(sc); |
| 1613 | return -ENOMEM; |
| 1614 | } |
| 1615 | /* Step 2 - Must use GFP_NOIO now. |
| 1616 | * OK, we have enough stripes, start collecting inactive |
| 1617 | * stripes and copying them over |
| 1618 | */ |
| 1619 | list_for_each_entry(nsh, &newstripes, lru) { |
| 1620 | spin_lock_irq(&conf->device_lock); |
| 1621 | wait_event_lock_irq(conf->wait_for_stripe, |
| 1622 | !list_empty(&conf->inactive_list), |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 1623 | conf->device_lock); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1624 | osh = get_free_stripe(conf); |
| 1625 | spin_unlock_irq(&conf->device_lock); |
| 1626 | atomic_set(&nsh->count, 1); |
| 1627 | for(i=0; i<conf->pool_size; i++) |
| 1628 | nsh->dev[i].page = osh->dev[i].page; |
| 1629 | for( ; i<newsize; i++) |
| 1630 | nsh->dev[i].page = NULL; |
| 1631 | kmem_cache_free(conf->slab_cache, osh); |
| 1632 | } |
| 1633 | kmem_cache_destroy(conf->slab_cache); |
| 1634 | |
| 1635 | /* Step 3. |
| 1636 | * At this point, we are holding all the stripes so the array |
| 1637 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1638 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1639 | */ |
| 1640 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 1641 | if (ndisks) { |
| 1642 | for (i=0; i<conf->raid_disks; i++) |
| 1643 | ndisks[i] = conf->disks[i]; |
| 1644 | kfree(conf->disks); |
| 1645 | conf->disks = ndisks; |
| 1646 | } else |
| 1647 | err = -ENOMEM; |
| 1648 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1649 | get_online_cpus(); |
| 1650 | conf->scribble_len = scribble_len(newsize); |
| 1651 | for_each_present_cpu(cpu) { |
| 1652 | struct raid5_percpu *percpu; |
| 1653 | void *scribble; |
| 1654 | |
| 1655 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 1656 | scribble = kmalloc(conf->scribble_len, GFP_NOIO); |
| 1657 | |
| 1658 | if (scribble) { |
| 1659 | kfree(percpu->scribble); |
| 1660 | percpu->scribble = scribble; |
| 1661 | } else { |
| 1662 | err = -ENOMEM; |
| 1663 | break; |
| 1664 | } |
| 1665 | } |
| 1666 | put_online_cpus(); |
| 1667 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1668 | /* Step 4, return new stripes to service */ |
| 1669 | while(!list_empty(&newstripes)) { |
| 1670 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1671 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1672 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1673 | for (i=conf->raid_disks; i < newsize; i++) |
| 1674 | if (nsh->dev[i].page == NULL) { |
| 1675 | struct page *p = alloc_page(GFP_NOIO); |
| 1676 | nsh->dev[i].page = p; |
| 1677 | if (!p) |
| 1678 | err = -ENOMEM; |
| 1679 | } |
| 1680 | release_stripe(nsh); |
| 1681 | } |
| 1682 | /* critical section pass, GFP_NOIO no longer needed */ |
| 1683 | |
| 1684 | conf->slab_cache = sc; |
| 1685 | conf->active_name = 1-conf->active_name; |
| 1686 | conf->pool_size = newsize; |
| 1687 | return err; |
| 1688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1690 | static int drop_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | { |
| 1692 | struct stripe_head *sh; |
| 1693 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1694 | spin_lock_irq(&conf->device_lock); |
| 1695 | sh = get_free_stripe(conf); |
| 1696 | spin_unlock_irq(&conf->device_lock); |
| 1697 | if (!sh) |
| 1698 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 1699 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1700 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1701 | kmem_cache_free(conf->slab_cache, sh); |
| 1702 | atomic_dec(&conf->active_stripes); |
| 1703 | return 1; |
| 1704 | } |
| 1705 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1706 | static void shrink_stripes(struct r5conf *conf) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1707 | { |
| 1708 | while (drop_one_stripe(conf)) |
| 1709 | ; |
| 1710 | |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1711 | if (conf->slab_cache) |
| 1712 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | conf->slab_cache = NULL; |
| 1714 | } |
| 1715 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1716 | static void raid5_end_read_request(struct bio * bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1718 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1719 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1720 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1722 | char b[BDEVNAME_SIZE]; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1723 | struct md_rdev *rdev = NULL; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1724 | sector_t s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
| 1726 | for (i=0 ; i<disks; i++) |
| 1727 | if (bi == &sh->dev[i].req) |
| 1728 | break; |
| 1729 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1730 | pr_debug("end_read_request %llu/%d, count: %d, uptodate %d.\n", |
| 1731 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | uptodate); |
| 1733 | if (i == disks) { |
| 1734 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1735 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1737 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1738 | /* If replacement finished while this request was outstanding, |
| 1739 | * 'replacement' might be NULL already. |
| 1740 | * In that case it moved down to 'rdev'. |
| 1741 | * rdev is not removed until all requests are finished. |
| 1742 | */ |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1743 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1744 | if (!rdev) |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1745 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1747 | if (use_new_offset(conf, sh)) |
| 1748 | s = sh->sector + rdev->new_data_offset; |
| 1749 | else |
| 1750 | s = sh->sector + rdev->data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1753 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1754 | /* Note that this cannot happen on a |
| 1755 | * replacement device. We just fail those on |
| 1756 | * any error |
| 1757 | */ |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1758 | printk_ratelimited( |
| 1759 | KERN_INFO |
| 1760 | "md/raid:%s: read error corrected" |
| 1761 | " (%lu sectors at %llu on %s)\n", |
| 1762 | mdname(conf->mddev), STRIPE_SECTORS, |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1763 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1764 | bdevname(rdev->bdev, b)); |
Namhyung Kim | ddd5115 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1765 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1766 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1767 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 1768 | } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 1769 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 1770 | |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1771 | if (atomic_read(&rdev->read_errors)) |
| 1772 | atomic_set(&rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | } else { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1774 | const char *bdn = bdevname(rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1775 | int retry = 0; |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1776 | int set_bad = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1779 | atomic_inc(&rdev->read_errors); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1780 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
| 1781 | printk_ratelimited( |
| 1782 | KERN_WARNING |
| 1783 | "md/raid:%s: read error on replacement device " |
| 1784 | "(sector %llu on %s).\n", |
| 1785 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1786 | (unsigned long long)s, |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1787 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1788 | else if (conf->mddev->degraded >= conf->max_degraded) { |
| 1789 | set_bad = 1; |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1790 | printk_ratelimited( |
| 1791 | KERN_WARNING |
| 1792 | "md/raid:%s: read error not correctable " |
| 1793 | "(sector %llu on %s).\n", |
| 1794 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1795 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1796 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1797 | } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1798 | /* Oh, no!!! */ |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1799 | set_bad = 1; |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1800 | printk_ratelimited( |
| 1801 | KERN_WARNING |
| 1802 | "md/raid:%s: read error NOT corrected!! " |
| 1803 | "(sector %llu on %s).\n", |
| 1804 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1805 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1806 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1807 | } else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1808 | > conf->max_nr_stripes) |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1809 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1810 | "md/raid:%s: Too many read errors, failing device %s.\n", |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1811 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1812 | else |
| 1813 | retry = 1; |
| 1814 | if (retry) |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 1815 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { |
| 1816 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 1817 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 1818 | } else |
| 1819 | set_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1820 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1821 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1822 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1823 | if (!(set_bad |
| 1824 | && test_bit(In_sync, &rdev->flags) |
| 1825 | && rdev_set_badblocks( |
| 1826 | rdev, sh->sector, STRIPE_SECTORS, 0))) |
| 1827 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1828 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1830 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1832 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1833 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1836 | static void raid5_end_write_request(struct bio *bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1838 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1839 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1840 | int disks = sh->disks, i; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1841 | struct md_rdev *uninitialized_var(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1843 | sector_t first_bad; |
| 1844 | int bad_sectors; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1845 | int replacement = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1847 | for (i = 0 ; i < disks; i++) { |
| 1848 | if (bi == &sh->dev[i].req) { |
| 1849 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | break; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1851 | } |
| 1852 | if (bi == &sh->dev[i].rreq) { |
| 1853 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1854 | if (rdev) |
| 1855 | replacement = 1; |
| 1856 | else |
| 1857 | /* rdev was removed and 'replacement' |
| 1858 | * replaced it. rdev is not removed |
| 1859 | * until all requests are finished. |
| 1860 | */ |
| 1861 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1862 | break; |
| 1863 | } |
| 1864 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1865 | pr_debug("end_write_request %llu/%d, count %d, uptodate: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
| 1867 | uptodate); |
| 1868 | if (i == disks) { |
| 1869 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1870 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1873 | if (replacement) { |
| 1874 | if (!uptodate) |
| 1875 | md_error(conf->mddev, rdev); |
| 1876 | else if (is_badblock(rdev, sh->sector, |
| 1877 | STRIPE_SECTORS, |
| 1878 | &first_bad, &bad_sectors)) |
| 1879 | set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); |
| 1880 | } else { |
| 1881 | if (!uptodate) { |
| 1882 | set_bit(WriteErrorSeen, &rdev->flags); |
| 1883 | set_bit(R5_WriteError, &sh->dev[i].flags); |
NeilBrown | 3a6de29 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1884 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) |
| 1885 | set_bit(MD_RECOVERY_NEEDED, |
| 1886 | &rdev->mddev->recovery); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1887 | } else if (is_badblock(rdev, sh->sector, |
| 1888 | STRIPE_SECTORS, |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 1889 | &first_bad, &bad_sectors)) { |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1890 | set_bit(R5_MadeGood, &sh->dev[i].flags); |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 1891 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) |
| 1892 | /* That was a successful write so make |
| 1893 | * sure it looks like we already did |
| 1894 | * a re-write. |
| 1895 | */ |
| 1896 | set_bit(R5_ReWrite, &sh->dev[i].flags); |
| 1897 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1898 | } |
| 1899 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1901 | if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) |
| 1902 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1904 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1907 | static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1909 | static void raid5_build_block(struct stripe_head *sh, int i, int previous) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | { |
| 1911 | struct r5dev *dev = &sh->dev[i]; |
| 1912 | |
| 1913 | bio_init(&dev->req); |
| 1914 | dev->req.bi_io_vec = &dev->vec; |
| 1915 | dev->req.bi_vcnt++; |
| 1916 | dev->req.bi_max_vecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | dev->req.bi_private = sh; |
NeilBrown | 995c427 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1918 | dev->vec.bv_page = dev->page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1920 | bio_init(&dev->rreq); |
| 1921 | dev->rreq.bi_io_vec = &dev->rvec; |
| 1922 | dev->rreq.bi_vcnt++; |
| 1923 | dev->rreq.bi_max_vecs++; |
| 1924 | dev->rreq.bi_private = sh; |
| 1925 | dev->rvec.bv_page = dev->page; |
| 1926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1928 | dev->sector = compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1931 | static void error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | { |
| 1933 | char b[BDEVNAME_SIZE]; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1934 | struct r5conf *conf = mddev->private; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 1935 | unsigned long flags; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1936 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 1938 | spin_lock_irqsave(&conf->device_lock, flags); |
| 1939 | clear_bit(In_sync, &rdev->flags); |
| 1940 | mddev->degraded = calc_degraded(conf); |
| 1941 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 1942 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 1943 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 1944 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 1945 | set_bit(Faulty, &rdev->flags); |
| 1946 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 1947 | printk(KERN_ALERT |
| 1948 | "md/raid:%s: Disk failure on %s, disabling device.\n" |
| 1949 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 1950 | mdname(mddev), |
| 1951 | bdevname(rdev->bdev, b), |
| 1952 | mdname(mddev), |
| 1953 | conf->raid_disks - mddev->degraded); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | |
| 1956 | /* |
| 1957 | * Input: a 'big' sector number, |
| 1958 | * Output: index of the data and parity disk, and the sector # in them. |
| 1959 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1960 | static sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1961 | int previous, int *dd_idx, |
| 1962 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | { |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1964 | sector_t stripe, stripe2; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1965 | sector_t chunk_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1967 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1968 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1970 | int algorithm = previous ? conf->prev_algo |
| 1971 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1972 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1973 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1974 | int raid_disks = previous ? conf->previous_raid_disks |
| 1975 | : conf->raid_disks; |
| 1976 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
| 1978 | /* First compute the information on this sector */ |
| 1979 | |
| 1980 | /* |
| 1981 | * Compute the chunk number and the sector offset inside the chunk |
| 1982 | */ |
| 1983 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 1984 | chunk_number = r_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | |
| 1986 | /* |
| 1987 | * Compute the stripe number |
| 1988 | */ |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1989 | stripe = chunk_number; |
| 1990 | *dd_idx = sector_div(stripe, data_disks); |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1991 | stripe2 = stripe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | /* |
| 1993 | * Select the parity disk based on the user selected algorithm. |
| 1994 | */ |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1995 | pd_idx = qd_idx = -1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1996 | switch(conf->level) { |
| 1997 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1998 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1999 | break; |
| 2000 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2001 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2003 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2004 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | (*dd_idx)++; |
| 2006 | break; |
| 2007 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2008 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2009 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | (*dd_idx)++; |
| 2011 | break; |
| 2012 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2013 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2014 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | break; |
| 2016 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2017 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2018 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2020 | case ALGORITHM_PARITY_0: |
| 2021 | pd_idx = 0; |
| 2022 | (*dd_idx)++; |
| 2023 | break; |
| 2024 | case ALGORITHM_PARITY_N: |
| 2025 | pd_idx = data_disks; |
| 2026 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2028 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2029 | } |
| 2030 | break; |
| 2031 | case 6: |
| 2032 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2033 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2034 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2035 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2036 | qd_idx = pd_idx + 1; |
| 2037 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2038 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2039 | qd_idx = 0; |
| 2040 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2041 | (*dd_idx) += 2; /* D D P Q D */ |
| 2042 | break; |
| 2043 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2044 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2045 | qd_idx = pd_idx + 1; |
| 2046 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2047 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2048 | qd_idx = 0; |
| 2049 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2050 | (*dd_idx) += 2; /* D D P Q D */ |
| 2051 | break; |
| 2052 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2053 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2054 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2055 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2056 | break; |
| 2057 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2058 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2059 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2060 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2061 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2062 | |
| 2063 | case ALGORITHM_PARITY_0: |
| 2064 | pd_idx = 0; |
| 2065 | qd_idx = 1; |
| 2066 | (*dd_idx) += 2; |
| 2067 | break; |
| 2068 | case ALGORITHM_PARITY_N: |
| 2069 | pd_idx = data_disks; |
| 2070 | qd_idx = data_disks + 1; |
| 2071 | break; |
| 2072 | |
| 2073 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2074 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 2075 | * of blocks for computing Q is different. |
| 2076 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2077 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2078 | qd_idx = pd_idx + 1; |
| 2079 | if (pd_idx == raid_disks-1) { |
| 2080 | (*dd_idx)++; /* Q D D D P */ |
| 2081 | qd_idx = 0; |
| 2082 | } else if (*dd_idx >= pd_idx) |
| 2083 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2084 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2085 | break; |
| 2086 | |
| 2087 | case ALGORITHM_ROTATING_N_RESTART: |
| 2088 | /* Same a left_asymmetric, by first stripe is |
| 2089 | * D D D P Q rather than |
| 2090 | * Q D D D P |
| 2091 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2092 | stripe2 += 1; |
| 2093 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2094 | qd_idx = pd_idx + 1; |
| 2095 | if (pd_idx == raid_disks-1) { |
| 2096 | (*dd_idx)++; /* Q D D D P */ |
| 2097 | qd_idx = 0; |
| 2098 | } else if (*dd_idx >= pd_idx) |
| 2099 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2100 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2101 | break; |
| 2102 | |
| 2103 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 2104 | /* Same as left_symmetric but Q is before P */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2105 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2106 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 2107 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2108 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2109 | break; |
| 2110 | |
| 2111 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2112 | /* RAID5 left_asymmetric, with Q on last device */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2113 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2114 | if (*dd_idx >= pd_idx) |
| 2115 | (*dd_idx)++; |
| 2116 | qd_idx = raid_disks - 1; |
| 2117 | break; |
| 2118 | |
| 2119 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2120 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2121 | if (*dd_idx >= pd_idx) |
| 2122 | (*dd_idx)++; |
| 2123 | qd_idx = raid_disks - 1; |
| 2124 | break; |
| 2125 | |
| 2126 | case ALGORITHM_LEFT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2127 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2128 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2129 | qd_idx = raid_disks - 1; |
| 2130 | break; |
| 2131 | |
| 2132 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2133 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2134 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2135 | qd_idx = raid_disks - 1; |
| 2136 | break; |
| 2137 | |
| 2138 | case ALGORITHM_PARITY_0_6: |
| 2139 | pd_idx = 0; |
| 2140 | (*dd_idx)++; |
| 2141 | qd_idx = raid_disks - 1; |
| 2142 | break; |
| 2143 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2144 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2145 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2146 | } |
| 2147 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2150 | if (sh) { |
| 2151 | sh->pd_idx = pd_idx; |
| 2152 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2153 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | /* |
| 2156 | * Finally, compute the new sector number |
| 2157 | */ |
| 2158 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 2159 | return new_sector; |
| 2160 | } |
| 2161 | |
| 2162 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2163 | static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2165 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2166 | int raid_disks = sh->disks; |
| 2167 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2169 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2170 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2171 | int algorithm = previous ? conf->prev_algo |
| 2172 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | sector_t stripe; |
| 2174 | int chunk_offset; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2175 | sector_t chunk_number; |
| 2176 | int dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2178 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 2182 | stripe = new_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2184 | if (i == sh->pd_idx) |
| 2185 | return 0; |
| 2186 | switch(conf->level) { |
| 2187 | case 4: break; |
| 2188 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2189 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2191 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 2192 | if (i > sh->pd_idx) |
| 2193 | i--; |
| 2194 | break; |
| 2195 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2196 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2197 | if (i < sh->pd_idx) |
| 2198 | i += raid_disks; |
| 2199 | i -= (sh->pd_idx + 1); |
| 2200 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2201 | case ALGORITHM_PARITY_0: |
| 2202 | i -= 1; |
| 2203 | break; |
| 2204 | case ALGORITHM_PARITY_N: |
| 2205 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2207 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2208 | } |
| 2209 | break; |
| 2210 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2211 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2212 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2213 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2214 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2215 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2216 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2217 | case ALGORITHM_ROTATING_N_RESTART: |
| 2218 | if (sh->pd_idx == raid_disks-1) |
| 2219 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2220 | else if (i > sh->pd_idx) |
| 2221 | i -= 2; /* D D P Q D */ |
| 2222 | break; |
| 2223 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2224 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2225 | if (sh->pd_idx == raid_disks-1) |
| 2226 | i--; /* Q D D D P */ |
| 2227 | else { |
| 2228 | /* D D P Q D */ |
| 2229 | if (i < sh->pd_idx) |
| 2230 | i += raid_disks; |
| 2231 | i -= (sh->pd_idx + 2); |
| 2232 | } |
| 2233 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2234 | case ALGORITHM_PARITY_0: |
| 2235 | i -= 2; |
| 2236 | break; |
| 2237 | case ALGORITHM_PARITY_N: |
| 2238 | break; |
| 2239 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2240 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2241 | if (sh->pd_idx == 0) |
| 2242 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2243 | else { |
| 2244 | /* D D Q P D */ |
| 2245 | if (i < sh->pd_idx) |
| 2246 | i += raid_disks; |
| 2247 | i -= (sh->pd_idx + 1); |
| 2248 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2249 | break; |
| 2250 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2251 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 2252 | if (i > sh->pd_idx) |
| 2253 | i--; |
| 2254 | break; |
| 2255 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 2256 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 2257 | if (i < sh->pd_idx) |
| 2258 | i += data_disks + 1; |
| 2259 | i -= (sh->pd_idx + 1); |
| 2260 | break; |
| 2261 | case ALGORITHM_PARITY_0_6: |
| 2262 | i -= 1; |
| 2263 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2264 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2265 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2266 | } |
| 2267 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | chunk_number = stripe * data_disks + i; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2271 | r_sector = chunk_number * sectors_per_chunk + chunk_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2273 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2274 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2275 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 2276 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2277 | printk(KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n", |
| 2278 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | return 0; |
| 2280 | } |
| 2281 | return r_sector; |
| 2282 | } |
| 2283 | |
| 2284 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2285 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2286 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2287 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2288 | { |
| 2289 | int i, pd_idx = sh->pd_idx, disks = sh->disks; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2290 | struct r5conf *conf = sh->raid_conf; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2291 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2292 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2293 | if (rcw) { |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2294 | |
| 2295 | for (i = disks; i--; ) { |
| 2296 | struct r5dev *dev = &sh->dev[i]; |
| 2297 | |
| 2298 | if (dev->towrite) { |
| 2299 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2300 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2301 | if (!expand) |
| 2302 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2303 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2304 | } |
| 2305 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 2306 | /* if we are not expanding this is a proper write request, and |
| 2307 | * there will be bios with new data to be drained into the |
| 2308 | * stripe cache |
| 2309 | */ |
| 2310 | if (!expand) { |
| 2311 | if (!s->locked) |
| 2312 | /* False alarm, nothing to do */ |
| 2313 | return; |
| 2314 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 2315 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2316 | } else |
| 2317 | sh->reconstruct_state = reconstruct_state_run; |
| 2318 | |
| 2319 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
| 2320 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2321 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2322 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2323 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2324 | } else { |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2325 | BUG_ON(level == 6); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2326 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 2327 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
| 2328 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2329 | for (i = disks; i--; ) { |
| 2330 | struct r5dev *dev = &sh->dev[i]; |
| 2331 | if (i == pd_idx) |
| 2332 | continue; |
| 2333 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2334 | if (dev->towrite && |
| 2335 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2336 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2337 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2338 | set_bit(R5_LOCKED, &dev->flags); |
| 2339 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2340 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2341 | } |
| 2342 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 2343 | if (!s->locked) |
| 2344 | /* False alarm - nothing to do */ |
| 2345 | return; |
| 2346 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
| 2347 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 2348 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2349 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2352 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2353 | * are in flight |
| 2354 | */ |
| 2355 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 2356 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2357 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2358 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2359 | if (level == 6) { |
| 2360 | int qd_idx = sh->qd_idx; |
| 2361 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 2362 | |
| 2363 | set_bit(R5_LOCKED, &dev->flags); |
| 2364 | clear_bit(R5_UPTODATE, &dev->flags); |
| 2365 | s->locked++; |
| 2366 | } |
| 2367 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2368 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2369 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2370 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2371 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | /* |
| 2374 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2375 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | * The bi_next chain must be in order. |
| 2377 | */ |
| 2378 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) |
| 2379 | { |
| 2380 | struct bio **bip; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2381 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2382 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2384 | pr_debug("adding bi b#%llu to stripe s#%llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | (unsigned long long)bi->bi_sector, |
| 2386 | (unsigned long long)sh->sector); |
| 2387 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2388 | /* |
| 2389 | * If several bio share a stripe. The bio bi_phys_segments acts as a |
| 2390 | * reference count to avoid race. The reference count should already be |
| 2391 | * increased before this function is called (for example, in |
| 2392 | * make_request()), so other bio sharing this stripe will not free the |
| 2393 | * stripe. If a stripe is owned by one stripe, the stripe lock will |
| 2394 | * protect it. |
| 2395 | */ |
| 2396 | spin_lock_irq(&sh->stripe_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2397 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | bip = &sh->dev[dd_idx].towrite; |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2399 | if (*bip == NULL) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2400 | firstwrite = 1; |
| 2401 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | bip = &sh->dev[dd_idx].toread; |
| 2403 | while (*bip && (*bip)->bi_sector < bi->bi_sector) { |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 2404 | if (bio_end_sector(*bip) > bi->bi_sector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | goto overlap; |
| 2406 | bip = & (*bip)->bi_next; |
| 2407 | } |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 2408 | if (*bip && (*bip)->bi_sector < bio_end_sector(bi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | goto overlap; |
| 2410 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2411 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | if (*bip) |
| 2413 | bi->bi_next = *bip; |
| 2414 | *bip = bi; |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2415 | raid5_inc_bi_active_stripes(bi); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | if (forwrite) { |
| 2418 | /* check if page is covered */ |
| 2419 | sector_t sector = sh->dev[dd_idx].sector; |
| 2420 | for (bi=sh->dev[dd_idx].towrite; |
| 2421 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
| 2422 | bi && bi->bi_sector <= sector; |
| 2423 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 2424 | if (bio_end_sector(bi) >= sector) |
| 2425 | sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | } |
| 2427 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
| 2428 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
| 2429 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2430 | |
| 2431 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
| 2432 | (unsigned long long)(*bip)->bi_sector, |
| 2433 | (unsigned long long)sh->sector, dd_idx); |
NeilBrown | b97390a | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2434 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2435 | |
| 2436 | if (conf->mddev->bitmap && firstwrite) { |
| 2437 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 2438 | STRIPE_SECTORS, 0); |
| 2439 | sh->bm_seq = conf->seq_flush+1; |
| 2440 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 2441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | return 1; |
| 2443 | |
| 2444 | overlap: |
| 2445 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2446 | spin_unlock_irq(&sh->stripe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | return 0; |
| 2448 | } |
| 2449 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2450 | static void end_reshape(struct r5conf *conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2451 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2452 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2453 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2454 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2455 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2456 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2457 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2458 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2459 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2460 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2461 | raid5_compute_sector(conf, |
| 2462 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2463 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2464 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2465 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2466 | } |
| 2467 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2468 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2469 | handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2470 | struct stripe_head_state *s, int disks, |
| 2471 | struct bio **return_bi) |
| 2472 | { |
| 2473 | int i; |
| 2474 | for (i = disks; i--; ) { |
| 2475 | struct bio *bi; |
| 2476 | int bitmap_end = 0; |
| 2477 | |
| 2478 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2479 | struct md_rdev *rdev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2480 | rcu_read_lock(); |
| 2481 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 2482 | if (rdev && test_bit(In_sync, &rdev->flags)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2483 | atomic_inc(&rdev->nr_pending); |
| 2484 | else |
| 2485 | rdev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2486 | rcu_read_unlock(); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2487 | if (rdev) { |
| 2488 | if (!rdev_set_badblocks( |
| 2489 | rdev, |
| 2490 | sh->sector, |
| 2491 | STRIPE_SECTORS, 0)) |
| 2492 | md_error(conf->mddev, rdev); |
| 2493 | rdev_dec_pending(rdev, conf->mddev); |
| 2494 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2495 | } |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2496 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2497 | /* fail all writes first */ |
| 2498 | bi = sh->dev[i].towrite; |
| 2499 | sh->dev[i].towrite = NULL; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2500 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | 1ed850f | 2012-10-11 13:50:13 +1100 | [diff] [blame] | 2501 | if (bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2502 | bitmap_end = 1; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2503 | |
| 2504 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2505 | wake_up(&conf->wait_for_overlap); |
| 2506 | |
| 2507 | while (bi && bi->bi_sector < |
| 2508 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2509 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
| 2510 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2511 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2512 | md_write_end(conf->mddev); |
| 2513 | bi->bi_next = *return_bi; |
| 2514 | *return_bi = bi; |
| 2515 | } |
| 2516 | bi = nextbi; |
| 2517 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2518 | if (bitmap_end) |
| 2519 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2520 | STRIPE_SECTORS, 0, 0); |
| 2521 | bitmap_end = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2522 | /* and fail all 'written' */ |
| 2523 | bi = sh->dev[i].written; |
| 2524 | sh->dev[i].written = NULL; |
| 2525 | if (bi) bitmap_end = 1; |
| 2526 | while (bi && bi->bi_sector < |
| 2527 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2528 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
| 2529 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2530 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2531 | md_write_end(conf->mddev); |
| 2532 | bi->bi_next = *return_bi; |
| 2533 | *return_bi = bi; |
| 2534 | } |
| 2535 | bi = bi2; |
| 2536 | } |
| 2537 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2538 | /* fail any reads if this device is non-operational and |
| 2539 | * the data has not reached the cache yet. |
| 2540 | */ |
| 2541 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
| 2542 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 2543 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2544 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2545 | bi = sh->dev[i].toread; |
| 2546 | sh->dev[i].toread = NULL; |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2547 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2548 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2549 | wake_up(&conf->wait_for_overlap); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2550 | while (bi && bi->bi_sector < |
| 2551 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2552 | struct bio *nextbi = |
| 2553 | r5_next_bio(bi, sh->dev[i].sector); |
| 2554 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2555 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2556 | bi->bi_next = *return_bi; |
| 2557 | *return_bi = bi; |
| 2558 | } |
| 2559 | bi = nextbi; |
| 2560 | } |
| 2561 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2562 | if (bitmap_end) |
| 2563 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2564 | STRIPE_SECTORS, 0, 0); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2565 | /* If we were in the middle of a write the parity block might |
| 2566 | * still be locked - so just clear all R5_LOCKED flags |
| 2567 | */ |
| 2568 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2571 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2572 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2573 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2576 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2577 | handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2578 | struct stripe_head_state *s) |
| 2579 | { |
| 2580 | int abort = 0; |
| 2581 | int i; |
| 2582 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2583 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 2584 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 2585 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2586 | s->syncing = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2587 | s->replacing = 0; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2588 | /* There is nothing more to do for sync/check/repair. |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 2589 | * Don't even need to abort as that is handled elsewhere |
| 2590 | * if needed, and not always wanted e.g. if there is a known |
| 2591 | * bad block here. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2592 | * For recover/replace we need to record a bad block on all |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2593 | * non-sync devices, or abort the recovery |
| 2594 | */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 2595 | if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { |
| 2596 | /* During recovery devices cannot be removed, so |
| 2597 | * locking and refcounting of rdevs is not needed |
| 2598 | */ |
| 2599 | for (i = 0; i < conf->raid_disks; i++) { |
| 2600 | struct md_rdev *rdev = conf->disks[i].rdev; |
| 2601 | if (rdev |
| 2602 | && !test_bit(Faulty, &rdev->flags) |
| 2603 | && !test_bit(In_sync, &rdev->flags) |
| 2604 | && !rdev_set_badblocks(rdev, sh->sector, |
| 2605 | STRIPE_SECTORS, 0)) |
| 2606 | abort = 1; |
| 2607 | rdev = conf->disks[i].replacement; |
| 2608 | if (rdev |
| 2609 | && !test_bit(Faulty, &rdev->flags) |
| 2610 | && !test_bit(In_sync, &rdev->flags) |
| 2611 | && !rdev_set_badblocks(rdev, sh->sector, |
| 2612 | STRIPE_SECTORS, 0)) |
| 2613 | abort = 1; |
| 2614 | } |
| 2615 | if (abort) |
| 2616 | conf->recovery_disabled = |
| 2617 | conf->mddev->recovery_disabled; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2618 | } |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 2619 | md_done_sync(conf->mddev, STRIPE_SECTORS, !abort); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2620 | } |
| 2621 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2622 | static int want_replace(struct stripe_head *sh, int disk_idx) |
| 2623 | { |
| 2624 | struct md_rdev *rdev; |
| 2625 | int rv = 0; |
| 2626 | /* Doing recovery so rcu locking not required */ |
| 2627 | rdev = sh->raid_conf->disks[disk_idx].replacement; |
| 2628 | if (rdev |
| 2629 | && !test_bit(Faulty, &rdev->flags) |
| 2630 | && !test_bit(In_sync, &rdev->flags) |
| 2631 | && (rdev->recovery_offset <= sh->sector |
| 2632 | || rdev->mddev->recovery_cp <= sh->sector)) |
| 2633 | rv = 1; |
| 2634 | |
| 2635 | return rv; |
| 2636 | } |
| 2637 | |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2638 | /* fetch_block - checks the given member device to see if its data needs |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2639 | * to be read or computed to satisfy a request. |
| 2640 | * |
| 2641 | * Returns 1 when no more member devices need to be checked, otherwise returns |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2642 | * 0 to tell the loop in handle_stripe_fill to continue |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2643 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2644 | static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 2645 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2646 | { |
| 2647 | struct r5dev *dev = &sh->dev[disk_idx]; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2648 | struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], |
| 2649 | &sh->dev[s->failed_num[1]] }; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2650 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2651 | /* is the data in this block needed, and can we get it? */ |
| 2652 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2653 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2654 | (dev->toread || |
| 2655 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2656 | s->syncing || s->expanding || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2657 | (s->replacing && want_replace(sh, disk_idx)) || |
NeilBrown | 5d35e09 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2658 | (s->failed >= 1 && fdev[0]->toread) || |
| 2659 | (s->failed >= 2 && fdev[1]->toread) || |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2660 | (sh->raid_conf->level <= 5 && s->failed && fdev[0]->towrite && |
| 2661 | !test_bit(R5_OVERWRITE, &fdev[0]->flags)) || |
| 2662 | (sh->raid_conf->level == 6 && s->failed && s->to_write))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2663 | /* we would like to get this block, possibly by computing it, |
| 2664 | * otherwise read it if the backing disk is insync |
| 2665 | */ |
| 2666 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 2667 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
| 2668 | if ((s->uptodate == disks - 1) && |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2669 | (s->failed && (disk_idx == s->failed_num[0] || |
| 2670 | disk_idx == s->failed_num[1]))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2671 | /* have disk failed, and we're requested to fetch it; |
| 2672 | * do compute it |
| 2673 | */ |
| 2674 | pr_debug("Computing stripe %llu block %d\n", |
| 2675 | (unsigned long long)sh->sector, disk_idx); |
| 2676 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2677 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2678 | set_bit(R5_Wantcompute, &dev->flags); |
| 2679 | sh->ops.target = disk_idx; |
| 2680 | sh->ops.target2 = -1; /* no 2nd target */ |
| 2681 | s->req_compute = 1; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2682 | /* Careful: from this point on 'uptodate' is in the eye |
| 2683 | * of raid_run_ops which services 'compute' operations |
| 2684 | * before writes. R5_Wantcompute flags a block that will |
| 2685 | * be R5_UPTODATE by the time it is needed for a |
| 2686 | * subsequent operation. |
| 2687 | */ |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2688 | s->uptodate++; |
| 2689 | return 1; |
| 2690 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 2691 | /* Computing 2-failure is *very* expensive; only |
| 2692 | * do it if failed >= 2 |
| 2693 | */ |
| 2694 | int other; |
| 2695 | for (other = disks; other--; ) { |
| 2696 | if (other == disk_idx) |
| 2697 | continue; |
| 2698 | if (!test_bit(R5_UPTODATE, |
| 2699 | &sh->dev[other].flags)) |
| 2700 | break; |
| 2701 | } |
| 2702 | BUG_ON(other < 0); |
| 2703 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 2704 | (unsigned long long)sh->sector, |
| 2705 | disk_idx, other); |
| 2706 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2707 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2708 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 2709 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 2710 | sh->ops.target = disk_idx; |
| 2711 | sh->ops.target2 = other; |
| 2712 | s->uptodate += 2; |
| 2713 | s->req_compute = 1; |
| 2714 | return 1; |
| 2715 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 2716 | set_bit(R5_LOCKED, &dev->flags); |
| 2717 | set_bit(R5_Wantread, &dev->flags); |
| 2718 | s->locked++; |
| 2719 | pr_debug("Reading block %d (sync=%d)\n", |
| 2720 | disk_idx, s->syncing); |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | return 0; |
| 2725 | } |
| 2726 | |
| 2727 | /** |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2728 | * handle_stripe_fill - read or compute data to satisfy pending requests. |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2729 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2730 | static void handle_stripe_fill(struct stripe_head *sh, |
| 2731 | struct stripe_head_state *s, |
| 2732 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2733 | { |
| 2734 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2735 | |
| 2736 | /* look for blocks to read/compute, skip this if a compute |
| 2737 | * is already in flight, or if the stripe contents are in the |
| 2738 | * midst of changing due to a write |
| 2739 | */ |
| 2740 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
| 2741 | !sh->reconstruct_state) |
| 2742 | for (i = disks; i--; ) |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2743 | if (fetch_block(sh, s, i, disks)) |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2744 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2745 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2746 | } |
| 2747 | |
| 2748 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2749 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2750 | * any written block on an uptodate or failed drive can be returned. |
| 2751 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 2752 | * never LOCKED, so we don't need to test 'failed' directly. |
| 2753 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2754 | static void handle_stripe_clean_event(struct r5conf *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2755 | struct stripe_head *sh, int disks, struct bio **return_bi) |
| 2756 | { |
| 2757 | int i; |
| 2758 | struct r5dev *dev; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 2759 | int discard_pending = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2760 | |
| 2761 | for (i = disks; i--; ) |
| 2762 | if (sh->dev[i].written) { |
| 2763 | dev = &sh->dev[i]; |
| 2764 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 2765 | (test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | ca64cae | 2012-11-21 16:33:40 +1100 | [diff] [blame] | 2766 | test_bit(R5_Discard, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2767 | /* We can return any write requests */ |
| 2768 | struct bio *wbi, *wbi2; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2769 | pr_debug("Return write for disc %d\n", i); |
NeilBrown | ca64cae | 2012-11-21 16:33:40 +1100 | [diff] [blame] | 2770 | if (test_and_clear_bit(R5_Discard, &dev->flags)) |
| 2771 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2772 | wbi = dev->written; |
| 2773 | dev->written = NULL; |
| 2774 | while (wbi && wbi->bi_sector < |
| 2775 | dev->sector + STRIPE_SECTORS) { |
| 2776 | wbi2 = r5_next_bio(wbi, dev->sector); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2777 | if (!raid5_dec_bi_active_stripes(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2778 | md_write_end(conf->mddev); |
| 2779 | wbi->bi_next = *return_bi; |
| 2780 | *return_bi = wbi; |
| 2781 | } |
| 2782 | wbi = wbi2; |
| 2783 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2784 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2785 | STRIPE_SECTORS, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2786 | !test_bit(STRIPE_DEGRADED, &sh->state), |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2787 | 0); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 2788 | } else if (test_bit(R5_Discard, &dev->flags)) |
| 2789 | discard_pending = 1; |
| 2790 | } |
| 2791 | if (!discard_pending && |
| 2792 | test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { |
| 2793 | clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 2794 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
| 2795 | if (sh->qd_idx >= 0) { |
| 2796 | clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 2797 | clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); |
| 2798 | } |
| 2799 | /* now that discard is done we can proceed with any sync */ |
| 2800 | clear_bit(STRIPE_DISCARD, &sh->state); |
| 2801 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) |
| 2802 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2803 | |
| 2804 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2805 | |
| 2806 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2807 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2808 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2811 | static void handle_stripe_dirtying(struct r5conf *conf, |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2812 | struct stripe_head *sh, |
| 2813 | struct stripe_head_state *s, |
| 2814 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2815 | { |
| 2816 | int rmw = 0, rcw = 0, i; |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2817 | sector_t recovery_cp = conf->mddev->recovery_cp; |
| 2818 | |
| 2819 | /* RAID6 requires 'rcw' in current implementation. |
| 2820 | * Otherwise, check whether resync is now happening or should start. |
| 2821 | * If yes, then the array is dirty (after unclean shutdown or |
| 2822 | * initial creation), so parity in some stripes might be inconsistent. |
| 2823 | * In this case, we need to always do reconstruct-write, to ensure |
| 2824 | * that in case of drive failure or read-error correction, we |
| 2825 | * generate correct data from the parity. |
| 2826 | */ |
| 2827 | if (conf->max_degraded == 2 || |
| 2828 | (recovery_cp < MaxSector && sh->sector >= recovery_cp)) { |
| 2829 | /* Calculate the real rcw later - for now make it |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2830 | * look like rcw is cheaper |
| 2831 | */ |
| 2832 | rcw = 1; rmw = 2; |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2833 | pr_debug("force RCW max_degraded=%u, recovery_cp=%llu sh->sector=%llu\n", |
| 2834 | conf->max_degraded, (unsigned long long)recovery_cp, |
| 2835 | (unsigned long long)sh->sector); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2836 | } else for (i = disks; i--; ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2837 | /* would I have to read this buffer for read_modify_write */ |
| 2838 | struct r5dev *dev = &sh->dev[i]; |
| 2839 | if ((dev->towrite || i == sh->pd_idx) && |
| 2840 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2841 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2842 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2843 | if (test_bit(R5_Insync, &dev->flags)) |
| 2844 | rmw++; |
| 2845 | else |
| 2846 | rmw += 2*disks; /* cannot read it */ |
| 2847 | } |
| 2848 | /* Would I have to read this buffer for reconstruct_write */ |
| 2849 | if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && |
| 2850 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2851 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2852 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2853 | if (test_bit(R5_Insync, &dev->flags)) rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2854 | else |
| 2855 | rcw += 2*disks; |
| 2856 | } |
| 2857 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2858 | pr_debug("for sector %llu, rmw=%d rcw=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2859 | (unsigned long long)sh->sector, rmw, rcw); |
| 2860 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2861 | if (rmw < rcw && rmw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2862 | /* prefer read-modify-write, but need to get some data */ |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 2863 | if (conf->mddev->queue) |
| 2864 | blk_add_trace_msg(conf->mddev->queue, |
| 2865 | "raid5 rmw %llu %d", |
| 2866 | (unsigned long long)sh->sector, rmw); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2867 | for (i = disks; i--; ) { |
| 2868 | struct r5dev *dev = &sh->dev[i]; |
| 2869 | if ((dev->towrite || i == sh->pd_idx) && |
| 2870 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2871 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2872 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2873 | test_bit(R5_Insync, &dev->flags)) { |
| 2874 | if ( |
| 2875 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2876 | pr_debug("Read_old block " |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2877 | "%d for r-m-w\n", i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2878 | set_bit(R5_LOCKED, &dev->flags); |
| 2879 | set_bit(R5_Wantread, &dev->flags); |
| 2880 | s->locked++; |
| 2881 | } else { |
| 2882 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2883 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2884 | } |
| 2885 | } |
| 2886 | } |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2887 | } |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2888 | if (rcw <= rmw && rcw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2889 | /* want reconstruct write, but need to get some data */ |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2890 | int qread =0; |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2891 | rcw = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2892 | for (i = disks; i--; ) { |
| 2893 | struct r5dev *dev = &sh->dev[i]; |
| 2894 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2895 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2896 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2897 | !(test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2898 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2899 | rcw++; |
| 2900 | if (!test_bit(R5_Insync, &dev->flags)) |
| 2901 | continue; /* it's a failed drive */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2902 | if ( |
| 2903 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2904 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2905 | "%d for Reconstruct\n", i); |
| 2906 | set_bit(R5_LOCKED, &dev->flags); |
| 2907 | set_bit(R5_Wantread, &dev->flags); |
| 2908 | s->locked++; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2909 | qread++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2910 | } else { |
| 2911 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2912 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2913 | } |
| 2914 | } |
| 2915 | } |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 2916 | if (rcw && conf->mddev->queue) |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2917 | blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", |
| 2918 | (unsigned long long)sh->sector, |
| 2919 | rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2920 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2921 | /* now if nothing is locked, and if we have enough data, |
| 2922 | * we can start a write request |
| 2923 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2924 | /* since handle_stripe can be called at any time we need to handle the |
| 2925 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2926 | * subsequent call wants to start a write request. raid_run_ops only |
| 2927 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2928 | * simultaneously. If this is not the case then new writes need to be |
| 2929 | * held off until the compute completes. |
| 2930 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2931 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2932 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
| 2933 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2934 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2937 | static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2938 | struct stripe_head_state *s, int disks) |
| 2939 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2940 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2941 | |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2942 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2943 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2944 | switch (sh->check_state) { |
| 2945 | case check_state_idle: |
| 2946 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2947 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2948 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2949 | sh->check_state = check_state_run; |
| 2950 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2951 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2952 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2953 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2954 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2955 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2956 | /* fall through */ |
| 2957 | case check_state_compute_result: |
| 2958 | sh->check_state = check_state_idle; |
| 2959 | if (!dev) |
| 2960 | dev = &sh->dev[sh->pd_idx]; |
| 2961 | |
| 2962 | /* check that a write has not made the stripe insync */ |
| 2963 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2964 | break; |
| 2965 | |
| 2966 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2967 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 2968 | BUG_ON(s->uptodate != disks); |
| 2969 | |
| 2970 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2971 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2972 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2973 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2974 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2975 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2976 | break; |
| 2977 | case check_state_run: |
| 2978 | break; /* we will be called again upon completion */ |
| 2979 | case check_state_check_result: |
| 2980 | sh->check_state = check_state_idle; |
| 2981 | |
| 2982 | /* if a failure occurred during the check operation, leave |
| 2983 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 2984 | */ |
| 2985 | if (s->failed) |
| 2986 | break; |
| 2987 | |
| 2988 | /* handle a successful check operation, if parity is correct |
| 2989 | * we are done. Otherwise update the mismatch count and repair |
| 2990 | * parity if !MD_RECOVERY_CHECK |
| 2991 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 2992 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2993 | /* parity is correct (on disc, |
| 2994 | * not in buffer any more) |
| 2995 | */ |
| 2996 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2997 | else { |
Jianpeng Ma | 7f7583d | 2012-10-11 14:17:59 +1100 | [diff] [blame] | 2998 | atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2999 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 3000 | /* don't try to repair!! */ |
| 3001 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3002 | else { |
| 3003 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3004 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3005 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3006 | set_bit(R5_Wantcompute, |
| 3007 | &sh->dev[sh->pd_idx].flags); |
| 3008 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 3009 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3010 | s->uptodate++; |
| 3011 | } |
| 3012 | } |
| 3013 | break; |
| 3014 | case check_state_compute_run: |
| 3015 | break; |
| 3016 | default: |
| 3017 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 3018 | __func__, sh->check_state, |
| 3019 | (unsigned long long) sh->sector); |
| 3020 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3025 | static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3026 | struct stripe_head_state *s, |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3027 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3028 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3029 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3030 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3031 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3032 | |
| 3033 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3034 | |
| 3035 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3036 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3037 | /* Want to check and possibly repair P and Q. |
| 3038 | * However there could be one 'failed' device, in which |
| 3039 | * case we can only check one of them, possibly using the |
| 3040 | * other to generate missing data |
| 3041 | */ |
| 3042 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3043 | switch (sh->check_state) { |
| 3044 | case check_state_idle: |
| 3045 | /* start a new check operation if there are < 2 failures */ |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3046 | if (s->failed == s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3047 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3048 | * makes sense to check P (If anything else were failed, |
| 3049 | * we would have used P to recreate it). |
| 3050 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3051 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3052 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3053 | if (!s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3054 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3055 | * anything, so it makes sense to check it |
| 3056 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3057 | if (sh->check_state == check_state_run) |
| 3058 | sh->check_state = check_state_run_pq; |
| 3059 | else |
| 3060 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3061 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3062 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3063 | /* discard potentially stale zero_sum_result */ |
| 3064 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3065 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3066 | if (sh->check_state == check_state_run) { |
| 3067 | /* async_xor_zero_sum destroys the contents of P */ |
| 3068 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 3069 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3070 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3071 | if (sh->check_state >= check_state_run && |
| 3072 | sh->check_state <= check_state_run_pq) { |
| 3073 | /* async_syndrome_zero_sum preserves P and Q, so |
| 3074 | * no need to mark them !uptodate here |
| 3075 | */ |
| 3076 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 3077 | break; |
| 3078 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3079 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3080 | /* we have 2-disk failure */ |
| 3081 | BUG_ON(s->failed != 2); |
| 3082 | /* fall through */ |
| 3083 | case check_state_compute_result: |
| 3084 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3085 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3086 | /* check that a write has not made the stripe insync */ |
| 3087 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 3088 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3089 | |
| 3090 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3091 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3092 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3093 | BUG_ON(s->uptodate < disks - 1); /* We don't need Q to recover */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3094 | if (s->failed == 2) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3095 | dev = &sh->dev[s->failed_num[1]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3096 | s->locked++; |
| 3097 | set_bit(R5_LOCKED, &dev->flags); |
| 3098 | set_bit(R5_Wantwrite, &dev->flags); |
| 3099 | } |
| 3100 | if (s->failed >= 1) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3101 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3102 | s->locked++; |
| 3103 | set_bit(R5_LOCKED, &dev->flags); |
| 3104 | set_bit(R5_Wantwrite, &dev->flags); |
| 3105 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3106 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3107 | dev = &sh->dev[pd_idx]; |
| 3108 | s->locked++; |
| 3109 | set_bit(R5_LOCKED, &dev->flags); |
| 3110 | set_bit(R5_Wantwrite, &dev->flags); |
| 3111 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3112 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3113 | dev = &sh->dev[qd_idx]; |
| 3114 | s->locked++; |
| 3115 | set_bit(R5_LOCKED, &dev->flags); |
| 3116 | set_bit(R5_Wantwrite, &dev->flags); |
| 3117 | } |
| 3118 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 3119 | |
| 3120 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3121 | break; |
| 3122 | case check_state_run: |
| 3123 | case check_state_run_q: |
| 3124 | case check_state_run_pq: |
| 3125 | break; /* we will be called again upon completion */ |
| 3126 | case check_state_check_result: |
| 3127 | sh->check_state = check_state_idle; |
| 3128 | |
| 3129 | /* handle a successful check operation, if parity is correct |
| 3130 | * we are done. Otherwise update the mismatch count and repair |
| 3131 | * parity if !MD_RECOVERY_CHECK |
| 3132 | */ |
| 3133 | if (sh->ops.zero_sum_result == 0) { |
| 3134 | /* both parities are correct */ |
| 3135 | if (!s->failed) |
| 3136 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3137 | else { |
| 3138 | /* in contrast to the raid5 case we can validate |
| 3139 | * parity, but still have a failure to write |
| 3140 | * back |
| 3141 | */ |
| 3142 | sh->check_state = check_state_compute_result; |
| 3143 | /* Returning at this point means that we may go |
| 3144 | * off and bring p and/or q uptodate again so |
| 3145 | * we make sure to check zero_sum_result again |
| 3146 | * to verify if p or q need writeback |
| 3147 | */ |
| 3148 | } |
| 3149 | } else { |
Jianpeng Ma | 7f7583d | 2012-10-11 14:17:59 +1100 | [diff] [blame] | 3150 | atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3151 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 3152 | /* don't try to repair!! */ |
| 3153 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3154 | else { |
| 3155 | int *target = &sh->ops.target; |
| 3156 | |
| 3157 | sh->ops.target = -1; |
| 3158 | sh->ops.target2 = -1; |
| 3159 | sh->check_state = check_state_compute_run; |
| 3160 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3161 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3162 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 3163 | set_bit(R5_Wantcompute, |
| 3164 | &sh->dev[pd_idx].flags); |
| 3165 | *target = pd_idx; |
| 3166 | target = &sh->ops.target2; |
| 3167 | s->uptodate++; |
| 3168 | } |
| 3169 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 3170 | set_bit(R5_Wantcompute, |
| 3171 | &sh->dev[qd_idx].flags); |
| 3172 | *target = qd_idx; |
| 3173 | s->uptodate++; |
| 3174 | } |
| 3175 | } |
| 3176 | } |
| 3177 | break; |
| 3178 | case check_state_compute_run: |
| 3179 | break; |
| 3180 | default: |
| 3181 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 3182 | __func__, sh->check_state, |
| 3183 | (unsigned long long) sh->sector); |
| 3184 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3185 | } |
| 3186 | } |
| 3187 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3188 | static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3189 | { |
| 3190 | int i; |
| 3191 | |
| 3192 | /* We have read all the blocks in this stripe and now we need to |
| 3193 | * copy some of them into a target stripe for expand. |
| 3194 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3195 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3196 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3197 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3198 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3199 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3200 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3201 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3202 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3203 | sector_t bn = compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3204 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 3205 | &dd_idx, NULL); |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3206 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3207 | if (sh2 == NULL) |
| 3208 | /* so far only the early blocks of this stripe |
| 3209 | * have been requested. When later blocks |
| 3210 | * get requested, we will try again |
| 3211 | */ |
| 3212 | continue; |
| 3213 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 3214 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 3215 | /* must have already done this block */ |
| 3216 | release_stripe(sh2); |
| 3217 | continue; |
| 3218 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3219 | |
| 3220 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3221 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3222 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 3223 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3224 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3225 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3226 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 3227 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 3228 | for (j = 0; j < conf->raid_disks; j++) |
| 3229 | if (j != sh2->pd_idx && |
NeilBrown | 86c374b | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3230 | j != sh2->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3231 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 3232 | break; |
| 3233 | if (j == conf->raid_disks) { |
| 3234 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 3235 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 3236 | } |
| 3237 | release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3238 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3239 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 3240 | /* done submitting copies, wait for them to complete */ |
NeilBrown | 749586b | 2012-11-20 14:11:15 +1100 | [diff] [blame] | 3241 | async_tx_quiesce(&tx); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
| 3244 | /* |
| 3245 | * handle_stripe - do things to a stripe. |
| 3246 | * |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3247 | * We lock the stripe by setting STRIPE_ACTIVE and then examine the |
| 3248 | * state of various bits to see what needs to be done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | * Possible results: |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3250 | * return some read requests which now have data |
| 3251 | * return some write requests which are safely on storage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | * schedule a read on some buffers |
| 3253 | * schedule a write of some buffers |
| 3254 | * return confirmation of parity correctness |
| 3255 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3257 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3258 | static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3259 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3260 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3261 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3262 | struct r5dev *dev; |
| 3263 | int i; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3264 | int do_recovery = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3265 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3266 | memset(s, 0, sizeof(*s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3267 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3268 | s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3269 | s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3270 | s->failed_num[0] = -1; |
| 3271 | s->failed_num[1] = -1; |
| 3272 | |
| 3273 | /* Now to look around and see what can be done */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3274 | rcu_read_lock(); |
| 3275 | for (i=disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3276 | struct md_rdev *rdev; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3277 | sector_t first_bad; |
| 3278 | int bad_sectors; |
| 3279 | int is_bad = 0; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3280 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3281 | dev = &sh->dev[i]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3282 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3283 | pr_debug("check %d: state 0x%lx read %p write %p written %p\n", |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3284 | i, dev->flags, |
| 3285 | dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3286 | /* maybe we can reply to a read |
| 3287 | * |
| 3288 | * new wantfill requests are only permitted while |
| 3289 | * ops_complete_biofill is guaranteed to be inactive |
| 3290 | */ |
| 3291 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 3292 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 3293 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3294 | |
| 3295 | /* now count some things */ |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3296 | if (test_bit(R5_LOCKED, &dev->flags)) |
| 3297 | s->locked++; |
| 3298 | if (test_bit(R5_UPTODATE, &dev->flags)) |
| 3299 | s->uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3300 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3301 | s->compute++; |
| 3302 | BUG_ON(s->compute > 2); |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3303 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3304 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3305 | if (test_bit(R5_Wantfill, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3306 | s->to_fill++; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3307 | else if (dev->toread) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3308 | s->to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3309 | if (dev->towrite) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3310 | s->to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3311 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3312 | s->non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3313 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3314 | if (dev->written) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3315 | s->written++; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3316 | /* Prefer to use the replacement for reads, but only |
| 3317 | * if it is recovered enough and has no bad blocks. |
| 3318 | */ |
| 3319 | rdev = rcu_dereference(conf->disks[i].replacement); |
| 3320 | if (rdev && !test_bit(Faulty, &rdev->flags) && |
| 3321 | rdev->recovery_offset >= sh->sector + STRIPE_SECTORS && |
| 3322 | !is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3323 | &first_bad, &bad_sectors)) |
| 3324 | set_bit(R5_ReadRepl, &dev->flags); |
| 3325 | else { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3326 | if (rdev) |
| 3327 | set_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3328 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 3329 | clear_bit(R5_ReadRepl, &dev->flags); |
| 3330 | } |
NeilBrown | 9283d8c | 2011-12-08 16:27:57 +1100 | [diff] [blame] | 3331 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 3332 | rdev = NULL; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3333 | if (rdev) { |
| 3334 | is_bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3335 | &first_bad, &bad_sectors); |
| 3336 | if (s->blocked_rdev == NULL |
| 3337 | && (test_bit(Blocked, &rdev->flags) |
| 3338 | || is_bad < 0)) { |
| 3339 | if (is_bad < 0) |
| 3340 | set_bit(BlockedBadBlocks, |
| 3341 | &rdev->flags); |
| 3342 | s->blocked_rdev = rdev; |
| 3343 | atomic_inc(&rdev->nr_pending); |
| 3344 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3345 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3346 | clear_bit(R5_Insync, &dev->flags); |
| 3347 | if (!rdev) |
| 3348 | /* Not in-sync */; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3349 | else if (is_bad) { |
| 3350 | /* also not in-sync */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3351 | if (!test_bit(WriteErrorSeen, &rdev->flags) && |
| 3352 | test_bit(R5_UPTODATE, &dev->flags)) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3353 | /* treat as in-sync, but with a read error |
| 3354 | * which we can now try to correct |
| 3355 | */ |
| 3356 | set_bit(R5_Insync, &dev->flags); |
| 3357 | set_bit(R5_ReadError, &dev->flags); |
| 3358 | } |
| 3359 | } else if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3360 | set_bit(R5_Insync, &dev->flags); |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 3361 | else if (sh->sector + STRIPE_SECTORS <= rdev->recovery_offset) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3362 | /* in sync if before recovery_offset */ |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 3363 | set_bit(R5_Insync, &dev->flags); |
| 3364 | else if (test_bit(R5_UPTODATE, &dev->flags) && |
| 3365 | test_bit(R5_Expanded, &dev->flags)) |
| 3366 | /* If we've reshaped into here, we assume it is Insync. |
| 3367 | * We will shortly update recovery_offset to make |
| 3368 | * it official. |
| 3369 | */ |
| 3370 | set_bit(R5_Insync, &dev->flags); |
| 3371 | |
Adam Kwolek | 5d8c71f | 2011-12-09 14:26:11 +1100 | [diff] [blame] | 3372 | if (rdev && test_bit(R5_WriteError, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3373 | /* This flag does not apply to '.replacement' |
| 3374 | * only to .rdev, so make sure to check that*/ |
| 3375 | struct md_rdev *rdev2 = rcu_dereference( |
| 3376 | conf->disks[i].rdev); |
| 3377 | if (rdev2 == rdev) |
| 3378 | clear_bit(R5_Insync, &dev->flags); |
| 3379 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3380 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3381 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3382 | } else |
| 3383 | clear_bit(R5_WriteError, &dev->flags); |
| 3384 | } |
Adam Kwolek | 5d8c71f | 2011-12-09 14:26:11 +1100 | [diff] [blame] | 3385 | if (rdev && test_bit(R5_MadeGood, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3386 | /* This flag does not apply to '.replacement' |
| 3387 | * only to .rdev, so make sure to check that*/ |
| 3388 | struct md_rdev *rdev2 = rcu_dereference( |
| 3389 | conf->disks[i].rdev); |
| 3390 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3391 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3392 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3393 | } else |
| 3394 | clear_bit(R5_MadeGood, &dev->flags); |
| 3395 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3396 | if (test_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 3397 | struct md_rdev *rdev2 = rcu_dereference( |
| 3398 | conf->disks[i].replacement); |
| 3399 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
| 3400 | s->handle_bad_blocks = 1; |
| 3401 | atomic_inc(&rdev2->nr_pending); |
| 3402 | } else |
| 3403 | clear_bit(R5_MadeGoodRepl, &dev->flags); |
| 3404 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3405 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3406 | /* The ReadError flag will just be confusing now */ |
| 3407 | clear_bit(R5_ReadError, &dev->flags); |
| 3408 | clear_bit(R5_ReWrite, &dev->flags); |
| 3409 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3410 | if (test_bit(R5_ReadError, &dev->flags)) |
| 3411 | clear_bit(R5_Insync, &dev->flags); |
| 3412 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3413 | if (s->failed < 2) |
| 3414 | s->failed_num[s->failed] = i; |
| 3415 | s->failed++; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3416 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
| 3417 | do_recovery = 1; |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3418 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3419 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3420 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 3421 | /* If there is a failed device being replaced, |
| 3422 | * we must be recovering. |
| 3423 | * else if we are after recovery_cp, we must be syncing |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 3424 | * else if MD_RECOVERY_REQUESTED is set, we also are syncing. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3425 | * else we can only be replacing |
| 3426 | * sync and recovery both need to read all devices, and so |
| 3427 | * use the same flag. |
| 3428 | */ |
| 3429 | if (do_recovery || |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 3430 | sh->sector >= conf->mddev->recovery_cp || |
| 3431 | test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3432 | s->syncing = 1; |
| 3433 | else |
| 3434 | s->replacing = 1; |
| 3435 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3436 | rcu_read_unlock(); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3437 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3438 | |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3439 | static void handle_stripe(struct stripe_head *sh) |
| 3440 | { |
| 3441 | struct stripe_head_state s; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3442 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3443 | int i; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3444 | int prexor; |
| 3445 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3446 | struct r5dev *pdev, *qdev; |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3447 | |
| 3448 | clear_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 3449 | if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3450 | /* already being handled, ensure it gets handled |
| 3451 | * again when current action finishes */ |
| 3452 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3453 | return; |
| 3454 | } |
| 3455 | |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3456 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 3457 | spin_lock(&sh->stripe_lock); |
| 3458 | /* Cannot process 'sync' concurrently with 'discard' */ |
| 3459 | if (!test_bit(STRIPE_DISCARD, &sh->state) && |
| 3460 | test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 3461 | set_bit(STRIPE_SYNCING, &sh->state); |
| 3462 | clear_bit(STRIPE_INSYNC, &sh->state); |
| 3463 | } |
| 3464 | spin_unlock(&sh->stripe_lock); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3465 | } |
| 3466 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3467 | |
| 3468 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
| 3469 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
| 3470 | (unsigned long long)sh->sector, sh->state, |
| 3471 | atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, |
| 3472 | sh->check_state, sh->reconstruct_state); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3473 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3474 | analyse_stripe(sh, &s); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3475 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3476 | if (s.handle_bad_blocks) { |
| 3477 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3478 | goto finish; |
| 3479 | } |
| 3480 | |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3481 | if (unlikely(s.blocked_rdev)) { |
| 3482 | if (s.syncing || s.expanding || s.expanded || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3483 | s.replacing || s.to_write || s.written) { |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3484 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3485 | goto finish; |
| 3486 | } |
| 3487 | /* There is nothing for the blocked_rdev to block */ |
| 3488 | rdev_dec_pending(s.blocked_rdev, conf->mddev); |
| 3489 | s.blocked_rdev = NULL; |
| 3490 | } |
| 3491 | |
| 3492 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3493 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3494 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3495 | } |
| 3496 | |
| 3497 | pr_debug("locked=%d uptodate=%d to_read=%d" |
| 3498 | " to_write=%d failed=%d failed_num=%d,%d\n", |
| 3499 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 3500 | s.failed_num[0], s.failed_num[1]); |
| 3501 | /* check if the array has lost more than max_degraded devices and, |
| 3502 | * if so, some requests might need to be failed. |
| 3503 | */ |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 3504 | if (s.failed > conf->max_degraded) { |
| 3505 | sh->check_state = 0; |
| 3506 | sh->reconstruct_state = 0; |
| 3507 | if (s.to_read+s.to_write+s.written) |
| 3508 | handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3509 | if (s.syncing + s.replacing) |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 3510 | handle_failed_sync(conf, sh, &s); |
| 3511 | } |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3512 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3513 | /* Now we check to see if any write operations have recently |
| 3514 | * completed |
| 3515 | */ |
| 3516 | prexor = 0; |
| 3517 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
| 3518 | prexor = 1; |
| 3519 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 3520 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
| 3521 | sh->reconstruct_state = reconstruct_state_idle; |
| 3522 | |
| 3523 | /* All the 'written' buffers and the parity block are ready to |
| 3524 | * be written back to disk |
| 3525 | */ |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 3526 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && |
| 3527 | !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3528 | BUG_ON(sh->qd_idx >= 0 && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 3529 | !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && |
| 3530 | !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3531 | for (i = disks; i--; ) { |
| 3532 | struct r5dev *dev = &sh->dev[i]; |
| 3533 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3534 | (i == sh->pd_idx || i == sh->qd_idx || |
| 3535 | dev->written)) { |
| 3536 | pr_debug("Writing block %d\n", i); |
| 3537 | set_bit(R5_Wantwrite, &dev->flags); |
| 3538 | if (prexor) |
| 3539 | continue; |
| 3540 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3541 | ((i == sh->pd_idx || i == sh->qd_idx) && |
| 3542 | s.failed == 0)) |
| 3543 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3544 | } |
| 3545 | } |
| 3546 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3547 | s.dec_preread_active = 1; |
| 3548 | } |
| 3549 | |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 3550 | /* |
| 3551 | * might be able to return some write requests if the parity blocks |
| 3552 | * are safe, or on a failed drive |
| 3553 | */ |
| 3554 | pdev = &sh->dev[sh->pd_idx]; |
| 3555 | s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) |
| 3556 | || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); |
| 3557 | qdev = &sh->dev[sh->qd_idx]; |
| 3558 | s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) |
| 3559 | || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) |
| 3560 | || conf->level < 6; |
| 3561 | |
| 3562 | if (s.written && |
| 3563 | (s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
| 3564 | && !test_bit(R5_LOCKED, &pdev->flags) |
| 3565 | && (test_bit(R5_UPTODATE, &pdev->flags) || |
| 3566 | test_bit(R5_Discard, &pdev->flags))))) && |
| 3567 | (s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
| 3568 | && !test_bit(R5_LOCKED, &qdev->flags) |
| 3569 | && (test_bit(R5_UPTODATE, &qdev->flags) || |
| 3570 | test_bit(R5_Discard, &qdev->flags)))))) |
| 3571 | handle_stripe_clean_event(conf, sh, disks, &s.return_bi); |
| 3572 | |
| 3573 | /* Now we might consider reading some blocks, either to check/generate |
| 3574 | * parity, or to satisfy requests |
| 3575 | * or to load a block that is being partially written. |
| 3576 | */ |
| 3577 | if (s.to_read || s.non_overwrite |
| 3578 | || (conf->level == 6 && s.to_write && s.failed) |
| 3579 | || (s.syncing && (s.uptodate + s.compute < disks)) |
| 3580 | || s.replacing |
| 3581 | || s.expanding) |
| 3582 | handle_stripe_fill(sh, &s, disks); |
| 3583 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3584 | /* Now to consider new write requests and what else, if anything |
| 3585 | * should be read. We do not handle new writes when: |
| 3586 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 3587 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3588 | * block. |
| 3589 | */ |
| 3590 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
| 3591 | handle_stripe_dirtying(conf, sh, &s, disks); |
| 3592 | |
| 3593 | /* maybe we need to check and possibly fix the parity for this stripe |
| 3594 | * Any reads will already have been scheduled, so we just see if enough |
| 3595 | * data is available. The parity check is held off while parity |
| 3596 | * dependent operations are in flight. |
| 3597 | */ |
| 3598 | if (sh->check_state || |
| 3599 | (s.syncing && s.locked == 0 && |
| 3600 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 3601 | !test_bit(STRIPE_INSYNC, &sh->state))) { |
| 3602 | if (conf->level == 6) |
| 3603 | handle_parity_checks6(conf, sh, &s, disks); |
| 3604 | else |
| 3605 | handle_parity_checks5(conf, sh, &s, disks); |
| 3606 | } |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3607 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3608 | if (s.replacing && s.locked == 0 |
| 3609 | && !test_bit(STRIPE_INSYNC, &sh->state)) { |
| 3610 | /* Write out to replacement devices where possible */ |
| 3611 | for (i = 0; i < conf->raid_disks; i++) |
| 3612 | if (test_bit(R5_UPTODATE, &sh->dev[i].flags) && |
| 3613 | test_bit(R5_NeedReplace, &sh->dev[i].flags)) { |
| 3614 | set_bit(R5_WantReplace, &sh->dev[i].flags); |
| 3615 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3616 | s.locked++; |
| 3617 | } |
| 3618 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3619 | } |
| 3620 | if ((s.syncing || s.replacing) && s.locked == 0 && |
| 3621 | test_bit(STRIPE_INSYNC, &sh->state)) { |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3622 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3623 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3624 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 3625 | wake_up(&conf->wait_for_overlap); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | /* If the failed drives are just a ReadError, then we might need |
| 3629 | * to progress the repair/check process |
| 3630 | */ |
| 3631 | if (s.failed <= conf->max_degraded && !conf->mddev->ro) |
| 3632 | for (i = 0; i < s.failed; i++) { |
| 3633 | struct r5dev *dev = &sh->dev[s.failed_num[i]]; |
| 3634 | if (test_bit(R5_ReadError, &dev->flags) |
| 3635 | && !test_bit(R5_LOCKED, &dev->flags) |
| 3636 | && test_bit(R5_UPTODATE, &dev->flags) |
| 3637 | ) { |
| 3638 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3639 | set_bit(R5_Wantwrite, &dev->flags); |
| 3640 | set_bit(R5_ReWrite, &dev->flags); |
| 3641 | set_bit(R5_LOCKED, &dev->flags); |
| 3642 | s.locked++; |
| 3643 | } else { |
| 3644 | /* let's read it back */ |
| 3645 | set_bit(R5_Wantread, &dev->flags); |
| 3646 | set_bit(R5_LOCKED, &dev->flags); |
| 3647 | s.locked++; |
| 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3653 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3654 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 3655 | struct stripe_head *sh_src |
| 3656 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
| 3657 | if (sh_src && test_bit(STRIPE_EXPAND_SOURCE, &sh_src->state)) { |
| 3658 | /* sh cannot be written until sh_src has been read. |
| 3659 | * so arrange for sh to be delayed a little |
| 3660 | */ |
| 3661 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3662 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3663 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3664 | &sh_src->state)) |
| 3665 | atomic_inc(&conf->preread_active_stripes); |
| 3666 | release_stripe(sh_src); |
| 3667 | goto finish; |
| 3668 | } |
| 3669 | if (sh_src) |
| 3670 | release_stripe(sh_src); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3671 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3672 | sh->reconstruct_state = reconstruct_state_idle; |
| 3673 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 3674 | for (i = conf->raid_disks; i--; ) { |
| 3675 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 3676 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3677 | s.locked++; |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 3682 | !sh->reconstruct_state) { |
| 3683 | /* Need to write out all blocks after computing parity */ |
| 3684 | sh->disks = conf->raid_disks; |
| 3685 | stripe_set_idx(sh->sector, conf, 0, sh); |
| 3686 | schedule_reconstruction(sh, &s, 1, 1); |
| 3687 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
| 3688 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3689 | atomic_dec(&conf->reshape_stripes); |
| 3690 | wake_up(&conf->wait_for_overlap); |
| 3691 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3692 | } |
| 3693 | |
| 3694 | if (s.expanding && s.locked == 0 && |
| 3695 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
| 3696 | handle_stripe_expansion(conf, sh); |
| 3697 | |
| 3698 | finish: |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3699 | /* wait for this device to become unblocked */ |
NeilBrown | 5f066c6 | 2012-07-03 12:13:29 +1000 | [diff] [blame] | 3700 | if (unlikely(s.blocked_rdev)) { |
| 3701 | if (conf->mddev->external) |
| 3702 | md_wait_for_blocked_rdev(s.blocked_rdev, |
| 3703 | conf->mddev); |
| 3704 | else |
| 3705 | /* Internal metadata will immediately |
| 3706 | * be written by raid5d, so we don't |
| 3707 | * need to wait here. |
| 3708 | */ |
| 3709 | rdev_dec_pending(s.blocked_rdev, |
| 3710 | conf->mddev); |
| 3711 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3712 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3713 | if (s.handle_bad_blocks) |
| 3714 | for (i = disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3715 | struct md_rdev *rdev; |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3716 | struct r5dev *dev = &sh->dev[i]; |
| 3717 | if (test_and_clear_bit(R5_WriteError, &dev->flags)) { |
| 3718 | /* We own a safe reference to the rdev */ |
| 3719 | rdev = conf->disks[i].rdev; |
| 3720 | if (!rdev_set_badblocks(rdev, sh->sector, |
| 3721 | STRIPE_SECTORS, 0)) |
| 3722 | md_error(conf->mddev, rdev); |
| 3723 | rdev_dec_pending(rdev, conf->mddev); |
| 3724 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3725 | if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { |
| 3726 | rdev = conf->disks[i].rdev; |
| 3727 | rdev_clear_badblocks(rdev, sh->sector, |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 3728 | STRIPE_SECTORS, 0); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3729 | rdev_dec_pending(rdev, conf->mddev); |
| 3730 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3731 | if (test_and_clear_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 3732 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3733 | if (!rdev) |
| 3734 | /* rdev have been moved down */ |
| 3735 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3736 | rdev_clear_badblocks(rdev, sh->sector, |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 3737 | STRIPE_SECTORS, 0); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3738 | rdev_dec_pending(rdev, conf->mddev); |
| 3739 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3740 | } |
| 3741 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3742 | if (s.ops_request) |
| 3743 | raid_run_ops(sh, s.ops_request); |
| 3744 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 3745 | ops_run_io(sh, &s); |
| 3746 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3747 | if (s.dec_preread_active) { |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3748 | /* We delay this until after ops_run_io so that if make_request |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 3749 | * is waiting on a flush, it won't continue until the writes |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3750 | * have actually been submitted. |
| 3751 | */ |
| 3752 | atomic_dec(&conf->preread_active_stripes); |
| 3753 | if (atomic_read(&conf->preread_active_stripes) < |
| 3754 | IO_THRESHOLD) |
| 3755 | md_wakeup_thread(conf->mddev->thread); |
| 3756 | } |
| 3757 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3758 | return_io(s.return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3759 | |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 3760 | clear_bit_unlock(STRIPE_ACTIVE, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3763 | static void raid5_activate_delayed(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | { |
| 3765 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 3766 | while (!list_empty(&conf->delayed_list)) { |
| 3767 | struct list_head *l = conf->delayed_list.next; |
| 3768 | struct stripe_head *sh; |
| 3769 | sh = list_entry(l, struct stripe_head, lru); |
| 3770 | list_del_init(l); |
| 3771 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3772 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3773 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3774 | list_add_tail(&sh->lru, &conf->hold_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | } |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 3776 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3779 | static void activate_bit_delay(struct r5conf *conf) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3780 | { |
| 3781 | /* device_lock is held */ |
| 3782 | struct list_head head; |
| 3783 | list_add(&head, &conf->bitmap_list); |
| 3784 | list_del_init(&conf->bitmap_list); |
| 3785 | while (!list_empty(&head)) { |
| 3786 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
| 3787 | list_del_init(&sh->lru); |
| 3788 | atomic_inc(&sh->count); |
| 3789 | __release_stripe(conf, sh); |
| 3790 | } |
| 3791 | } |
| 3792 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3793 | int md_raid5_congested(struct mddev *mddev, int bits) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3794 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3795 | struct r5conf *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3796 | |
| 3797 | /* No difference between reads and writes. Just check |
| 3798 | * how busy the stripe_cache is |
| 3799 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 3800 | |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3801 | if (conf->inactive_blocked) |
| 3802 | return 1; |
| 3803 | if (conf->quiesce) |
| 3804 | return 1; |
| 3805 | if (list_empty_careful(&conf->inactive_list)) |
| 3806 | return 1; |
| 3807 | |
| 3808 | return 0; |
| 3809 | } |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3810 | EXPORT_SYMBOL_GPL(md_raid5_congested); |
| 3811 | |
| 3812 | static int raid5_congested(void *data, int bits) |
| 3813 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3814 | struct mddev *mddev = data; |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3815 | |
| 3816 | return mddev_congested(mddev, bits) || |
| 3817 | md_raid5_congested(mddev, bits); |
| 3818 | } |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3819 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3820 | /* We want read requests to align with chunks where possible, |
| 3821 | * but write requests don't need to. |
| 3822 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3823 | static int raid5_mergeable_bvec(struct request_queue *q, |
| 3824 | struct bvec_merge_data *bvm, |
| 3825 | struct bio_vec *biovec) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3826 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3827 | struct mddev *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3828 | sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3829 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3830 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3831 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3832 | |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3833 | if ((bvm->bi_rw & 1) == WRITE) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3834 | return biovec->bv_len; /* always allow writes to be mergeable */ |
| 3835 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3836 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3837 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3838 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 3839 | if (max < 0) max = 0; |
| 3840 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 3841 | return biovec->bv_len; |
| 3842 | else |
| 3843 | return max; |
| 3844 | } |
| 3845 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3846 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3847 | static int in_chunk_boundary(struct mddev *mddev, struct bio *bio) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3848 | { |
| 3849 | sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3850 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 3851 | unsigned int bio_sectors = bio_sectors(bio); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3852 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3853 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3854 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3855 | return chunk_sectors >= |
| 3856 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 3857 | } |
| 3858 | |
| 3859 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3860 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 3861 | * later sampled by raid5d. |
| 3862 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3863 | static void add_bio_to_retry(struct bio *bi,struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3864 | { |
| 3865 | unsigned long flags; |
| 3866 | |
| 3867 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3868 | |
| 3869 | bi->bi_next = conf->retry_read_aligned_list; |
| 3870 | conf->retry_read_aligned_list = bi; |
| 3871 | |
| 3872 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3873 | md_wakeup_thread(conf->mddev->thread); |
| 3874 | } |
| 3875 | |
| 3876 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3877 | static struct bio *remove_bio_from_retry(struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3878 | { |
| 3879 | struct bio *bi; |
| 3880 | |
| 3881 | bi = conf->retry_read_aligned; |
| 3882 | if (bi) { |
| 3883 | conf->retry_read_aligned = NULL; |
| 3884 | return bi; |
| 3885 | } |
| 3886 | bi = conf->retry_read_aligned_list; |
| 3887 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3888 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3889 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 3890 | /* |
| 3891 | * this sets the active strip count to 1 and the processed |
| 3892 | * strip count to zero (upper 8 bits) |
| 3893 | */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3894 | raid5_set_bi_stripes(bi, 1); /* biased count of active stripes */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | return bi; |
| 3898 | } |
| 3899 | |
| 3900 | |
| 3901 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3902 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 3903 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 3904 | * first). |
| 3905 | * If the read failed.. |
| 3906 | */ |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3907 | static void raid5_align_endio(struct bio *bi, int error) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3908 | { |
| 3909 | struct bio* raid_bi = bi->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3910 | struct mddev *mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3911 | struct r5conf *conf; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3912 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3913 | struct md_rdev *rdev; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3914 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3915 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3916 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3917 | rdev = (void*)raid_bi->bi_next; |
| 3918 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 3919 | mddev = rdev->mddev; |
| 3920 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3921 | |
| 3922 | rdev_dec_pending(rdev, conf->mddev); |
| 3923 | |
| 3924 | if (!error && uptodate) { |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 3925 | trace_block_bio_complete(bdev_get_queue(raid_bi->bi_bdev), |
| 3926 | raid_bi, 0); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3927 | bio_endio(raid_bi, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3928 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 3929 | wake_up(&conf->wait_for_stripe); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3930 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3934 | pr_debug("raid5_align_endio : io error...handing IO for a retry\n"); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3935 | |
| 3936 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3937 | } |
| 3938 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3939 | static int bio_fits_rdev(struct bio *bi) |
| 3940 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3941 | struct request_queue *q = bdev_get_queue(bi->bi_bdev); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3942 | |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 3943 | if (bio_sectors(bi) > queue_max_sectors(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3944 | return 0; |
| 3945 | blk_recount_segments(q, bi); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 3946 | if (bi->bi_phys_segments > queue_max_segments(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3947 | return 0; |
| 3948 | |
| 3949 | if (q->merge_bvec_fn) |
| 3950 | /* it's too hard to apply the merge_bvec_fn at this stage, |
| 3951 | * just just give up |
| 3952 | */ |
| 3953 | return 0; |
| 3954 | |
| 3955 | return 1; |
| 3956 | } |
| 3957 | |
| 3958 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3959 | static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3960 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3961 | struct r5conf *conf = mddev->private; |
NeilBrown | 8553fe7ec | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 3962 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3963 | struct bio* align_bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3964 | struct md_rdev *rdev; |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3965 | sector_t end_sector; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3966 | |
| 3967 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3968 | pr_debug("chunk_aligned_read : non aligned\n"); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3969 | return 0; |
| 3970 | } |
| 3971 | /* |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 3972 | * use bio_clone_mddev to make a copy of the bio |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3973 | */ |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 3974 | align_bi = bio_clone_mddev(raid_bio, GFP_NOIO, mddev); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3975 | if (!align_bi) |
| 3976 | return 0; |
| 3977 | /* |
| 3978 | * set bi_end_io to a new function, and set bi_private to the |
| 3979 | * original bio. |
| 3980 | */ |
| 3981 | align_bi->bi_end_io = raid5_align_endio; |
| 3982 | align_bi->bi_private = raid_bio; |
| 3983 | /* |
| 3984 | * compute position |
| 3985 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3986 | align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, |
| 3987 | 0, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3988 | &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3989 | |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 3990 | end_sector = bio_end_sector(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3991 | rcu_read_lock(); |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3992 | rdev = rcu_dereference(conf->disks[dd_idx].replacement); |
| 3993 | if (!rdev || test_bit(Faulty, &rdev->flags) || |
| 3994 | rdev->recovery_offset < end_sector) { |
| 3995 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 3996 | if (rdev && |
| 3997 | (test_bit(Faulty, &rdev->flags) || |
| 3998 | !(test_bit(In_sync, &rdev->flags) || |
| 3999 | rdev->recovery_offset >= end_sector))) |
| 4000 | rdev = NULL; |
| 4001 | } |
| 4002 | if (rdev) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4003 | sector_t first_bad; |
| 4004 | int bad_sectors; |
| 4005 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4006 | atomic_inc(&rdev->nr_pending); |
| 4007 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4008 | raid_bio->bi_next = (void*)rdev; |
| 4009 | align_bi->bi_bdev = rdev->bdev; |
| 4010 | align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4011 | |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4012 | if (!bio_fits_rdev(align_bi) || |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 4013 | is_badblock(rdev, align_bi->bi_sector, bio_sectors(align_bi), |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4014 | &first_bad, &bad_sectors)) { |
| 4015 | /* too big in some way, or has a known bad block */ |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4016 | bio_put(align_bi); |
| 4017 | rdev_dec_pending(rdev, mddev); |
| 4018 | return 0; |
| 4019 | } |
| 4020 | |
majianpeng | 6c0544e | 2012-06-12 08:31:10 +0800 | [diff] [blame] | 4021 | /* No reshape active, so we can trust rdev->data_offset */ |
| 4022 | align_bi->bi_sector += rdev->data_offset; |
| 4023 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4024 | spin_lock_irq(&conf->device_lock); |
| 4025 | wait_event_lock_irq(conf->wait_for_stripe, |
| 4026 | conf->quiesce == 0, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 4027 | conf->device_lock); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4028 | atomic_inc(&conf->active_aligned_reads); |
| 4029 | spin_unlock_irq(&conf->device_lock); |
| 4030 | |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 4031 | if (mddev->gendisk) |
| 4032 | trace_block_bio_remap(bdev_get_queue(align_bi->bi_bdev), |
| 4033 | align_bi, disk_devt(mddev->gendisk), |
| 4034 | raid_bio->bi_sector); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4035 | generic_make_request(align_bi); |
| 4036 | return 1; |
| 4037 | } else { |
| 4038 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4039 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4040 | return 0; |
| 4041 | } |
| 4042 | } |
| 4043 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4044 | /* __get_priority_stripe - get the next stripe to process |
| 4045 | * |
| 4046 | * Full stripe writes are allowed to pass preread active stripes up until |
| 4047 | * the bypass_threshold is exceeded. In general the bypass_count |
| 4048 | * increments when the handle_list is handled before the hold_list; however, it |
| 4049 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 4050 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 4051 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 4052 | * handle_list. |
| 4053 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4054 | static struct stripe_head *__get_priority_stripe(struct r5conf *conf) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4055 | { |
| 4056 | struct stripe_head *sh; |
| 4057 | |
| 4058 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 4059 | __func__, |
| 4060 | list_empty(&conf->handle_list) ? "empty" : "busy", |
| 4061 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 4062 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 4063 | |
| 4064 | if (!list_empty(&conf->handle_list)) { |
| 4065 | sh = list_entry(conf->handle_list.next, typeof(*sh), lru); |
| 4066 | |
| 4067 | if (list_empty(&conf->hold_list)) |
| 4068 | conf->bypass_count = 0; |
| 4069 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 4070 | if (conf->hold_list.next == conf->last_hold) |
| 4071 | conf->bypass_count++; |
| 4072 | else { |
| 4073 | conf->last_hold = conf->hold_list.next; |
| 4074 | conf->bypass_count -= conf->bypass_threshold; |
| 4075 | if (conf->bypass_count < 0) |
| 4076 | conf->bypass_count = 0; |
| 4077 | } |
| 4078 | } |
| 4079 | } else if (!list_empty(&conf->hold_list) && |
| 4080 | ((conf->bypass_threshold && |
| 4081 | conf->bypass_count > conf->bypass_threshold) || |
| 4082 | atomic_read(&conf->pending_full_writes) == 0)) { |
| 4083 | sh = list_entry(conf->hold_list.next, |
| 4084 | typeof(*sh), lru); |
| 4085 | conf->bypass_count -= conf->bypass_threshold; |
| 4086 | if (conf->bypass_count < 0) |
| 4087 | conf->bypass_count = 0; |
| 4088 | } else |
| 4089 | return NULL; |
| 4090 | |
| 4091 | list_del_init(&sh->lru); |
| 4092 | atomic_inc(&sh->count); |
| 4093 | BUG_ON(atomic_read(&sh->count) != 1); |
| 4094 | return sh; |
| 4095 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4096 | |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4097 | struct raid5_plug_cb { |
| 4098 | struct blk_plug_cb cb; |
| 4099 | struct list_head list; |
| 4100 | }; |
| 4101 | |
| 4102 | static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule) |
| 4103 | { |
| 4104 | struct raid5_plug_cb *cb = container_of( |
| 4105 | blk_cb, struct raid5_plug_cb, cb); |
| 4106 | struct stripe_head *sh; |
| 4107 | struct mddev *mddev = cb->cb.data; |
| 4108 | struct r5conf *conf = mddev->private; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4109 | int cnt = 0; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4110 | |
| 4111 | if (cb->list.next && !list_empty(&cb->list)) { |
| 4112 | spin_lock_irq(&conf->device_lock); |
| 4113 | while (!list_empty(&cb->list)) { |
| 4114 | sh = list_first_entry(&cb->list, struct stripe_head, lru); |
| 4115 | list_del_init(&sh->lru); |
| 4116 | /* |
| 4117 | * avoid race release_stripe_plug() sees |
| 4118 | * STRIPE_ON_UNPLUG_LIST clear but the stripe |
| 4119 | * is still in our list |
| 4120 | */ |
| 4121 | smp_mb__before_clear_bit(); |
| 4122 | clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); |
| 4123 | __release_stripe(conf, sh); |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4124 | cnt++; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4125 | } |
| 4126 | spin_unlock_irq(&conf->device_lock); |
| 4127 | } |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 4128 | if (mddev->queue) |
| 4129 | trace_block_unplug(mddev->queue, cnt, !from_schedule); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4130 | kfree(cb); |
| 4131 | } |
| 4132 | |
| 4133 | static void release_stripe_plug(struct mddev *mddev, |
| 4134 | struct stripe_head *sh) |
| 4135 | { |
| 4136 | struct blk_plug_cb *blk_cb = blk_check_plugged( |
| 4137 | raid5_unplug, mddev, |
| 4138 | sizeof(struct raid5_plug_cb)); |
| 4139 | struct raid5_plug_cb *cb; |
| 4140 | |
| 4141 | if (!blk_cb) { |
| 4142 | release_stripe(sh); |
| 4143 | return; |
| 4144 | } |
| 4145 | |
| 4146 | cb = container_of(blk_cb, struct raid5_plug_cb, cb); |
| 4147 | |
| 4148 | if (cb->list.next == NULL) |
| 4149 | INIT_LIST_HEAD(&cb->list); |
| 4150 | |
| 4151 | if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) |
| 4152 | list_add_tail(&sh->lru, &cb->list); |
| 4153 | else |
| 4154 | release_stripe(sh); |
| 4155 | } |
| 4156 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4157 | static void make_discard_request(struct mddev *mddev, struct bio *bi) |
| 4158 | { |
| 4159 | struct r5conf *conf = mddev->private; |
| 4160 | sector_t logical_sector, last_sector; |
| 4161 | struct stripe_head *sh; |
| 4162 | int remaining; |
| 4163 | int stripe_sectors; |
| 4164 | |
| 4165 | if (mddev->reshape_position != MaxSector) |
| 4166 | /* Skip discard while reshape is happening */ |
| 4167 | return; |
| 4168 | |
| 4169 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 4170 | last_sector = bi->bi_sector + (bi->bi_size>>9); |
| 4171 | |
| 4172 | bi->bi_next = NULL; |
| 4173 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
| 4174 | |
| 4175 | stripe_sectors = conf->chunk_sectors * |
| 4176 | (conf->raid_disks - conf->max_degraded); |
| 4177 | logical_sector = DIV_ROUND_UP_SECTOR_T(logical_sector, |
| 4178 | stripe_sectors); |
| 4179 | sector_div(last_sector, stripe_sectors); |
| 4180 | |
| 4181 | logical_sector *= conf->chunk_sectors; |
| 4182 | last_sector *= conf->chunk_sectors; |
| 4183 | |
| 4184 | for (; logical_sector < last_sector; |
| 4185 | logical_sector += STRIPE_SECTORS) { |
| 4186 | DEFINE_WAIT(w); |
| 4187 | int d; |
| 4188 | again: |
| 4189 | sh = get_active_stripe(conf, logical_sector, 0, 0, 0); |
| 4190 | prepare_to_wait(&conf->wait_for_overlap, &w, |
| 4191 | TASK_UNINTERRUPTIBLE); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4192 | set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
| 4193 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 4194 | release_stripe(sh); |
| 4195 | schedule(); |
| 4196 | goto again; |
| 4197 | } |
| 4198 | clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4199 | spin_lock_irq(&sh->stripe_lock); |
| 4200 | for (d = 0; d < conf->raid_disks; d++) { |
| 4201 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 4202 | continue; |
| 4203 | if (sh->dev[d].towrite || sh->dev[d].toread) { |
| 4204 | set_bit(R5_Overlap, &sh->dev[d].flags); |
| 4205 | spin_unlock_irq(&sh->stripe_lock); |
| 4206 | release_stripe(sh); |
| 4207 | schedule(); |
| 4208 | goto again; |
| 4209 | } |
| 4210 | } |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4211 | set_bit(STRIPE_DISCARD, &sh->state); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4212 | finish_wait(&conf->wait_for_overlap, &w); |
| 4213 | for (d = 0; d < conf->raid_disks; d++) { |
| 4214 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 4215 | continue; |
| 4216 | sh->dev[d].towrite = bi; |
| 4217 | set_bit(R5_OVERWRITE, &sh->dev[d].flags); |
| 4218 | raid5_inc_bi_active_stripes(bi); |
| 4219 | } |
| 4220 | spin_unlock_irq(&sh->stripe_lock); |
| 4221 | if (conf->mddev->bitmap) { |
| 4222 | for (d = 0; |
| 4223 | d < conf->raid_disks - conf->max_degraded; |
| 4224 | d++) |
| 4225 | bitmap_startwrite(mddev->bitmap, |
| 4226 | sh->sector, |
| 4227 | STRIPE_SECTORS, |
| 4228 | 0); |
| 4229 | sh->bm_seq = conf->seq_flush + 1; |
| 4230 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 4231 | } |
| 4232 | |
| 4233 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4234 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 4235 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4236 | atomic_inc(&conf->preread_active_stripes); |
| 4237 | release_stripe_plug(mddev, sh); |
| 4238 | } |
| 4239 | |
| 4240 | remaining = raid5_dec_bi_active_stripes(bi); |
| 4241 | if (remaining == 0) { |
| 4242 | md_write_end(mddev); |
| 4243 | bio_endio(bi, 0); |
| 4244 | } |
| 4245 | } |
| 4246 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame] | 4247 | static void make_request(struct mddev *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4249 | struct r5conf *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4250 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | sector_t new_sector; |
| 4252 | sector_t logical_sector, last_sector; |
| 4253 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 4254 | const int rw = bio_data_dir(bi); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 4255 | int remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 4257 | if (unlikely(bi->bi_rw & REQ_FLUSH)) { |
| 4258 | md_flush_request(mddev, bi); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 4259 | return; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 4262 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 4263 | |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 4264 | if (rw == READ && |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 4265 | mddev->reshape_position == MaxSector && |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 4266 | chunk_aligned_read(mddev,bi)) |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 4267 | return; |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 4268 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4269 | if (unlikely(bi->bi_rw & REQ_DISCARD)) { |
| 4270 | make_discard_request(mddev, bi); |
| 4271 | return; |
| 4272 | } |
| 4273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 4275 | last_sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | bi->bi_next = NULL; |
| 4277 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 4278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
| 4280 | DEFINE_WAIT(w); |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4281 | int previous; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 4282 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4283 | retry: |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4284 | previous = 0; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 4285 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4286 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4287 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 4288 | * 64bit on a 32bit platform, and so it might be |
| 4289 | * possible to see a half-updated value |
Jesper Juhl | aeb878b | 2011-04-10 18:06:17 +0200 | [diff] [blame] | 4290 | * Of course reshape_progress could change after |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 4291 | * the lock is dropped, so once we get a reference |
| 4292 | * to the stripe that we think it is, we will have |
| 4293 | * to check again. |
| 4294 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4295 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4296 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4297 | ? logical_sector < conf->reshape_progress |
| 4298 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4299 | previous = 1; |
| 4300 | } else { |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4301 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4302 | ? logical_sector < conf->reshape_safe |
| 4303 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 4304 | spin_unlock_irq(&conf->device_lock); |
| 4305 | schedule(); |
| 4306 | goto retry; |
| 4307 | } |
| 4308 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4309 | spin_unlock_irq(&conf->device_lock); |
| 4310 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4311 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4312 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 4313 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4314 | &dd_idx, NULL); |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4315 | pr_debug("raid456: make_request, sector %llu logical %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | (unsigned long long)new_sector, |
| 4317 | (unsigned long long)logical_sector); |
| 4318 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4319 | sh = get_active_stripe(conf, new_sector, previous, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4320 | (bi->bi_rw&RWA_MASK), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4322 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4323 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 4324 | * stripe, so we must do the range check again. |
| 4325 | * Expansion could still move past after this |
| 4326 | * test, but as we are holding a reference to |
| 4327 | * 'sh', we know that if that happens, |
| 4328 | * STRIPE_EXPANDING will get set and the expansion |
| 4329 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4330 | */ |
| 4331 | int must_retry = 0; |
| 4332 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4333 | if (mddev->reshape_backwards |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4334 | ? logical_sector >= conf->reshape_progress |
| 4335 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4336 | /* mismatch, need to try again */ |
| 4337 | must_retry = 1; |
| 4338 | spin_unlock_irq(&conf->device_lock); |
| 4339 | if (must_retry) { |
| 4340 | release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 4341 | schedule(); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4342 | goto retry; |
| 4343 | } |
| 4344 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4345 | |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 4346 | if (rw == WRITE && |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4347 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4348 | logical_sector < mddev->suspend_hi) { |
| 4349 | release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4350 | /* As the suspend_* range is controlled by |
| 4351 | * userspace, we want an interruptible |
| 4352 | * wait. |
| 4353 | */ |
| 4354 | flush_signals(current); |
| 4355 | prepare_to_wait(&conf->wait_for_overlap, |
| 4356 | &w, TASK_INTERRUPTIBLE); |
| 4357 | if (logical_sector >= mddev->suspend_lo && |
| 4358 | logical_sector < mddev->suspend_hi) |
| 4359 | schedule(); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4360 | goto retry; |
| 4361 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4362 | |
| 4363 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 4364 | !add_stripe_bio(sh, bi, dd_idx, rw)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4365 | /* Stripe is busy expanding or |
| 4366 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | * and wait a while |
| 4368 | */ |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 4369 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | release_stripe(sh); |
| 4371 | schedule(); |
| 4372 | goto retry; |
| 4373 | } |
| 4374 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4375 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4376 | clear_bit(STRIPE_DELAYED, &sh->state); |
NeilBrown | a852d7b | 2012-09-19 12:48:30 +1000 | [diff] [blame] | 4377 | if ((bi->bi_rw & REQ_SYNC) && |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4378 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4379 | atomic_inc(&conf->preread_active_stripes); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4380 | release_stripe_plug(mddev, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | } else { |
| 4382 | /* cannot get stripe for read-ahead, just give-up */ |
| 4383 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
| 4384 | finish_wait(&conf->wait_for_overlap, &w); |
| 4385 | break; |
| 4386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | } |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4388 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4389 | remaining = raid5_dec_bi_active_stripes(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 4390 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4392 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4394 | |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4395 | trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), |
| 4396 | bi, 0); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4397 | bio_endio(bi, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4401 | static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4402 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4403 | static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *skipped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4405 | /* reshaping is quite different to recovery/resync so it is |
| 4406 | * handled quite separately ... here. |
| 4407 | * |
| 4408 | * On each call to sync_request, we gather one chunk worth of |
| 4409 | * destination stripes and flag them as expanding. |
| 4410 | * Then we find all the source stripes and request reads. |
| 4411 | * As the reads complete, handle_stripe will copy the data |
| 4412 | * into the destination stripe and release that stripe. |
| 4413 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4414 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4416 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4417 | int raid_disks = conf->previous_raid_disks; |
| 4418 | int data_disks = raid_disks - conf->max_degraded; |
| 4419 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4420 | int i; |
| 4421 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4422 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4423 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4424 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4425 | struct list_head stripes; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4426 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4427 | if (sector_nr == 0) { |
| 4428 | /* If restarting in the middle, skip the initial sectors */ |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4429 | if (mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4430 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 4431 | sector_nr = raid5_size(mddev, 0, 0) |
| 4432 | - conf->reshape_progress; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4433 | } else if (!mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4434 | conf->reshape_progress > 0) |
| 4435 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4436 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4437 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 4438 | mddev->curr_resync_completed = sector_nr; |
| 4439 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4440 | *skipped = 1; |
| 4441 | return sector_nr; |
| 4442 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4443 | } |
| 4444 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4445 | /* We need to process a full chunk at a time. |
| 4446 | * If old and new chunk sizes differ, we need to process the |
| 4447 | * largest of these |
| 4448 | */ |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4449 | if (mddev->new_chunk_sectors > mddev->chunk_sectors) |
| 4450 | reshape_sectors = mddev->new_chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4451 | else |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4452 | reshape_sectors = mddev->chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4453 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4454 | /* We update the metadata at least every 10 seconds, or when |
| 4455 | * the data about to be copied would over-write the source of |
| 4456 | * the data at the front of the range. i.e. one new_stripe |
| 4457 | * along from reshape_progress new_maps to after where |
| 4458 | * reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4459 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4460 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4461 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4462 | readpos = conf->reshape_progress; |
| 4463 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4464 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4465 | sector_div(safepos, data_disks); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4466 | if (mddev->reshape_backwards) { |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4467 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4468 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4469 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4470 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4471 | writepos += reshape_sectors; |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4472 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 4473 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4474 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4475 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4476 | /* Having calculated the 'writepos' possibly use it |
| 4477 | * to set 'stripe_addr' which is where we will write to. |
| 4478 | */ |
| 4479 | if (mddev->reshape_backwards) { |
| 4480 | BUG_ON(conf->reshape_progress == 0); |
| 4481 | stripe_addr = writepos; |
| 4482 | BUG_ON((mddev->dev_sectors & |
| 4483 | ~((sector_t)reshape_sectors - 1)) |
| 4484 | - reshape_sectors - stripe_addr |
| 4485 | != sector_nr); |
| 4486 | } else { |
| 4487 | BUG_ON(writepos != sector_nr + reshape_sectors); |
| 4488 | stripe_addr = sector_nr; |
| 4489 | } |
| 4490 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4491 | /* 'writepos' is the most advanced device address we might write. |
| 4492 | * 'readpos' is the least advanced device address we might read. |
| 4493 | * 'safepos' is the least address recorded in the metadata as having |
| 4494 | * been reshaped. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4495 | * If there is a min_offset_diff, these are adjusted either by |
| 4496 | * increasing the safepos/readpos if diff is negative, or |
| 4497 | * increasing writepos if diff is positive. |
| 4498 | * If 'readpos' is then behind 'writepos', there is no way that we can |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4499 | * ensure safety in the face of a crash - that must be done by userspace |
| 4500 | * making a backup of the data. So in that case there is no particular |
| 4501 | * rush to update metadata. |
| 4502 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 4503 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 4504 | * we can be safe in the event of a crash. |
| 4505 | * So we insist on updating metadata if safepos is behind writepos and |
| 4506 | * readpos is beyond writepos. |
| 4507 | * In any case, update the metadata every 10 seconds. |
| 4508 | * Maybe that number should be configurable, but I'm not sure it is |
| 4509 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 4510 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4511 | if (conf->min_offset_diff < 0) { |
| 4512 | safepos += -conf->min_offset_diff; |
| 4513 | readpos += -conf->min_offset_diff; |
| 4514 | } else |
| 4515 | writepos += conf->min_offset_diff; |
| 4516 | |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4517 | if ((mddev->reshape_backwards |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4518 | ? (safepos > writepos && readpos < writepos) |
| 4519 | : (safepos < writepos && readpos > writepos)) || |
| 4520 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4521 | /* Cannot proceed until we've updated the superblock... */ |
| 4522 | wait_event(conf->wait_for_overlap, |
| 4523 | atomic_read(&conf->reshape_stripes)==0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4524 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4525 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4526 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4527 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4528 | md_wakeup_thread(mddev->thread); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4529 | wait_event(mddev->sb_wait, mddev->flags == 0 || |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4530 | kthread_should_stop()); |
| 4531 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4532 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4533 | spin_unlock_irq(&conf->device_lock); |
| 4534 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4535 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4536 | } |
| 4537 | |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4538 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4539 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4540 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4541 | int skipped_disk = 0; |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4542 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4543 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 4544 | atomic_inc(&conf->reshape_stripes); |
| 4545 | /* If any of this stripe is beyond the end of the old |
| 4546 | * array, then we need to zero those blocks |
| 4547 | */ |
| 4548 | for (j=sh->disks; j--;) { |
| 4549 | sector_t s; |
| 4550 | if (j == sh->pd_idx) |
| 4551 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4552 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4553 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4554 | continue; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 4555 | s = compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4556 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4557 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4558 | continue; |
| 4559 | } |
| 4560 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 4561 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 4562 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 4563 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4564 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4565 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4566 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4567 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4568 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4569 | } |
| 4570 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4571 | if (mddev->reshape_backwards) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4572 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4573 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4574 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4575 | spin_unlock_irq(&conf->device_lock); |
| 4576 | /* Ok, those stripe are ready. We can start scheduling |
| 4577 | * reads on the source stripes. |
| 4578 | * The source stripes are determined by mapping the first and last |
| 4579 | * block on the destination stripes. |
| 4580 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4581 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4582 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4583 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4584 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 4585 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4586 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4587 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4588 | if (last_sector >= mddev->dev_sectors) |
| 4589 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4590 | while (first_sector <= last_sector) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4591 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4592 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4593 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4594 | release_stripe(sh); |
| 4595 | first_sector += STRIPE_SECTORS; |
| 4596 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4597 | /* Now that the sources are clearly marked, we can release |
| 4598 | * the destination stripes |
| 4599 | */ |
| 4600 | while (!list_empty(&stripes)) { |
| 4601 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 4602 | list_del_init(&sh->lru); |
| 4603 | release_stripe(sh); |
| 4604 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4605 | /* If this takes us to the resync_max point where we have to pause, |
| 4606 | * then we need to write out the superblock. |
| 4607 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4608 | sector_nr += reshape_sectors; |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 4609 | if ((sector_nr - mddev->curr_resync_completed) * 2 |
| 4610 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4611 | /* Cannot proceed until we've updated the superblock... */ |
| 4612 | wait_event(conf->wait_for_overlap, |
| 4613 | atomic_read(&conf->reshape_stripes) == 0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4614 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4615 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4616 | conf->reshape_checkpoint = jiffies; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4617 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 4618 | md_wakeup_thread(mddev->thread); |
| 4619 | wait_event(mddev->sb_wait, |
| 4620 | !test_bit(MD_CHANGE_DEVS, &mddev->flags) |
| 4621 | || kthread_should_stop()); |
| 4622 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4623 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4624 | spin_unlock_irq(&conf->device_lock); |
| 4625 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4626 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4627 | } |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4628 | return reshape_sectors; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | /* FIXME go_faster isn't used */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4632 | static inline sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipped, int go_faster) |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4633 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4634 | struct r5conf *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4635 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4636 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 4637 | sector_t sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4638 | int still_degraded = 0; |
| 4639 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4641 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | /* just being told to finish up .. nothing much to do */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 4643 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 4644 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 4645 | end_reshape(conf); |
| 4646 | return 0; |
| 4647 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4648 | |
| 4649 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 4650 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 4651 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4652 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4653 | conf->fullsync = 0; |
| 4654 | bitmap_close_sync(mddev->bitmap); |
| 4655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | return 0; |
| 4657 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4658 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4659 | /* Allow raid5_quiesce to complete */ |
| 4660 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 4661 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4662 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 4663 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4664 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4665 | /* No need to check resync_max as we never do more than one |
| 4666 | * stripe, and as resync_max will always be on a chunk boundary, |
| 4667 | * if the check in md_do_sync didn't fire, there is no chance |
| 4668 | * of overstepping resync_max here |
| 4669 | */ |
| 4670 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4671 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | * to resync, then assert that we are finished, because there is |
| 4673 | * nothing we can do. |
| 4674 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 4675 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4676 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4677 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 4678 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | return rv; |
| 4680 | } |
majianpeng | 6f60804 | 2013-04-24 11:42:41 +1000 | [diff] [blame] | 4681 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
| 4682 | !conf->fullsync && |
| 4683 | !bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
| 4684 | sync_blocks >= STRIPE_SECTORS) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4685 | /* we can skip this block, and probably more */ |
| 4686 | sync_blocks /= STRIPE_SECTORS; |
| 4687 | *skipped = 1; |
| 4688 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 4689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 4691 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 4692 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4693 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | if (sh == NULL) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4695 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4697 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 4699 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4701 | /* Need to check if array will still be degraded after recovery/resync |
| 4702 | * We don't need to check the 'failed' flag as when that gets set, |
| 4703 | * recovery aborts. |
| 4704 | */ |
NeilBrown | f001a70 | 2009-06-09 14:30:31 +1000 | [diff] [blame] | 4705 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4706 | if (conf->disks[i].rdev == NULL) |
| 4707 | still_degraded = 1; |
| 4708 | |
| 4709 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 4710 | |
NeilBrown | 83206d6 | 2011-07-26 11:19:49 +1000 | [diff] [blame] | 4711 | set_bit(STRIPE_SYNC_REQUESTED, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 4713 | handle_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | release_stripe(sh); |
| 4715 | |
| 4716 | return STRIPE_SECTORS; |
| 4717 | } |
| 4718 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4719 | static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4720 | { |
| 4721 | /* We may not be able to submit a whole bio at once as there |
| 4722 | * may not be enough stripe_heads available. |
| 4723 | * We cannot pre-allocate enough stripe_heads as we may need |
| 4724 | * more than exist in the cache (if we allow ever large chunks). |
| 4725 | * So we do one stripe head at a time and record in |
| 4726 | * ->bi_hw_segments how many have been done. |
| 4727 | * |
| 4728 | * We *know* that this entire raid_bio is in one chunk, so |
| 4729 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 4730 | */ |
| 4731 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4732 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4733 | sector_t sector, logical_sector, last_sector; |
| 4734 | int scnt = 0; |
| 4735 | int remaining; |
| 4736 | int handled = 0; |
| 4737 | |
| 4738 | logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4739 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4740 | 0, &dd_idx, NULL); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 4741 | last_sector = bio_end_sector(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4742 | |
| 4743 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4744 | logical_sector += STRIPE_SECTORS, |
| 4745 | sector += STRIPE_SECTORS, |
| 4746 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4747 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4748 | if (scnt < raid5_bi_processed_stripes(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4749 | /* already done this stripe */ |
| 4750 | continue; |
| 4751 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4752 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4753 | |
| 4754 | if (!sh) { |
| 4755 | /* failed to get a stripe - must wait */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4756 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4757 | conf->retry_read_aligned = raid_bio; |
| 4758 | return handled; |
| 4759 | } |
| 4760 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4761 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
| 4762 | release_stripe(sh); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4763 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4764 | conf->retry_read_aligned = raid_bio; |
| 4765 | return handled; |
| 4766 | } |
| 4767 | |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 4768 | set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4769 | handle_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4770 | release_stripe(sh); |
| 4771 | handled++; |
| 4772 | } |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4773 | remaining = raid5_dec_bi_active_stripes(raid_bio); |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4774 | if (remaining == 0) { |
| 4775 | trace_block_bio_complete(bdev_get_queue(raid_bio->bi_bdev), |
| 4776 | raid_bio, 0); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4777 | bio_endio(raid_bio, 0); |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4778 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4779 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4780 | wake_up(&conf->wait_for_stripe); |
| 4781 | return handled; |
| 4782 | } |
| 4783 | |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4784 | #define MAX_STRIPE_BATCH 8 |
| 4785 | static int handle_active_stripes(struct r5conf *conf) |
| 4786 | { |
| 4787 | struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; |
| 4788 | int i, batch_size = 0; |
| 4789 | |
| 4790 | while (batch_size < MAX_STRIPE_BATCH && |
| 4791 | (sh = __get_priority_stripe(conf)) != NULL) |
| 4792 | batch[batch_size++] = sh; |
| 4793 | |
| 4794 | if (batch_size == 0) |
| 4795 | return batch_size; |
| 4796 | spin_unlock_irq(&conf->device_lock); |
| 4797 | |
| 4798 | for (i = 0; i < batch_size; i++) |
| 4799 | handle_stripe(batch[i]); |
| 4800 | |
| 4801 | cond_resched(); |
| 4802 | |
| 4803 | spin_lock_irq(&conf->device_lock); |
| 4804 | for (i = 0; i < batch_size; i++) |
| 4805 | __release_stripe(conf, batch[i]); |
| 4806 | return batch_size; |
| 4807 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | /* |
| 4810 | * This is our raid5 kernel thread. |
| 4811 | * |
| 4812 | * We scan the hash table for stripes which can be handled now. |
| 4813 | * During the scan, completed stripes are saved for us by the interrupt |
| 4814 | * handler, so that they will not have to wait for our next wakeup. |
| 4815 | */ |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 4816 | static void raid5d(struct md_thread *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | { |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 4818 | struct mddev *mddev = thread->mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4819 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | int handled; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4821 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4823 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | |
| 4825 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4827 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | handled = 0; |
| 4829 | spin_lock_irq(&conf->device_lock); |
| 4830 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4831 | struct bio *bio; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4832 | int batch_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 4834 | if ( |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4835 | !list_empty(&conf->bitmap_list)) { |
| 4836 | /* Now is a good time to flush some bitmap updates */ |
| 4837 | conf->seq_flush++; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4838 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4839 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4840 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4841 | conf->seq_write = conf->seq_flush; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4842 | activate_bit_delay(conf); |
| 4843 | } |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 4844 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4845 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4846 | while ((bio = remove_bio_from_retry(conf))) { |
| 4847 | int ok; |
| 4848 | spin_unlock_irq(&conf->device_lock); |
| 4849 | ok = retry_aligned_read(conf, bio); |
| 4850 | spin_lock_irq(&conf->device_lock); |
| 4851 | if (!ok) |
| 4852 | break; |
| 4853 | handled++; |
| 4854 | } |
| 4855 | |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4856 | batch_size = handle_active_stripes(conf); |
| 4857 | if (!batch_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | break; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4859 | handled += batch_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4861 | if (mddev->flags & ~(1<<MD_CHANGE_PENDING)) { |
| 4862 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 4863 | md_check_recovery(mddev); |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4864 | spin_lock_irq(&conf->device_lock); |
| 4865 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4867 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | |
| 4869 | spin_unlock_irq(&conf->device_lock); |
| 4870 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4871 | async_tx_issue_pending_all(); |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4872 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4874 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4877 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4878 | raid5_show_stripe_cache_size(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4879 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4880 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4881 | if (conf) |
| 4882 | return sprintf(page, "%d\n", conf->max_nr_stripes); |
| 4883 | else |
| 4884 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4885 | } |
| 4886 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4887 | int |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4888 | raid5_set_cache_size(struct mddev *mddev, int size) |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4889 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4890 | struct r5conf *conf = mddev->private; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4891 | int err; |
| 4892 | |
| 4893 | if (size <= 16 || size > 32768) |
| 4894 | return -EINVAL; |
| 4895 | while (size < conf->max_nr_stripes) { |
| 4896 | if (drop_one_stripe(conf)) |
| 4897 | conf->max_nr_stripes--; |
| 4898 | else |
| 4899 | break; |
| 4900 | } |
| 4901 | err = md_allow_write(mddev); |
| 4902 | if (err) |
| 4903 | return err; |
| 4904 | while (size > conf->max_nr_stripes) { |
| 4905 | if (grow_one_stripe(conf)) |
| 4906 | conf->max_nr_stripes++; |
| 4907 | else break; |
| 4908 | } |
| 4909 | return 0; |
| 4910 | } |
| 4911 | EXPORT_SYMBOL(raid5_set_cache_size); |
| 4912 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4913 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4914 | raid5_store_stripe_cache_size(struct mddev *mddev, const char *page, size_t len) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4915 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4916 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4917 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4918 | int err; |
| 4919 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4920 | if (len >= PAGE_SIZE) |
| 4921 | return -EINVAL; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4922 | if (!conf) |
| 4923 | return -ENODEV; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4924 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4925 | if (strict_strtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4926 | return -EINVAL; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4927 | err = raid5_set_cache_size(mddev, new); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4928 | if (err) |
| 4929 | return err; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4930 | return len; |
| 4931 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4932 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4933 | static struct md_sysfs_entry |
| 4934 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 4935 | raid5_show_stripe_cache_size, |
| 4936 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4937 | |
| 4938 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4939 | raid5_show_preread_threshold(struct mddev *mddev, char *page) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4940 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4941 | struct r5conf *conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4942 | if (conf) |
| 4943 | return sprintf(page, "%d\n", conf->bypass_threshold); |
| 4944 | else |
| 4945 | return 0; |
| 4946 | } |
| 4947 | |
| 4948 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4949 | raid5_store_preread_threshold(struct mddev *mddev, const char *page, size_t len) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4950 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4951 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4952 | unsigned long new; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4953 | if (len >= PAGE_SIZE) |
| 4954 | return -EINVAL; |
| 4955 | if (!conf) |
| 4956 | return -ENODEV; |
| 4957 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4958 | if (strict_strtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4959 | return -EINVAL; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4960 | if (new > conf->max_nr_stripes) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4961 | return -EINVAL; |
| 4962 | conf->bypass_threshold = new; |
| 4963 | return len; |
| 4964 | } |
| 4965 | |
| 4966 | static struct md_sysfs_entry |
| 4967 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 4968 | S_IRUGO | S_IWUSR, |
| 4969 | raid5_show_preread_threshold, |
| 4970 | raid5_store_preread_threshold); |
| 4971 | |
| 4972 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4973 | stripe_cache_active_show(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4974 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4975 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4976 | if (conf) |
| 4977 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 4978 | else |
| 4979 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4980 | } |
| 4981 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4982 | static struct md_sysfs_entry |
| 4983 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4984 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4985 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4986 | &raid5_stripecache_size.attr, |
| 4987 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4988 | &raid5_preread_bypass_threshold.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4989 | NULL, |
| 4990 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4991 | static struct attribute_group raid5_attrs_group = { |
| 4992 | .name = NULL, |
| 4993 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4994 | }; |
| 4995 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4996 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4997 | raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4998 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4999 | struct r5conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5000 | |
| 5001 | if (!sectors) |
| 5002 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5003 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 5004 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5005 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5006 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5007 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5008 | sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5009 | return sectors * (raid_disks - conf->max_degraded); |
| 5010 | } |
| 5011 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5012 | static void raid5_free_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5013 | { |
| 5014 | struct raid5_percpu *percpu; |
| 5015 | unsigned long cpu; |
| 5016 | |
| 5017 | if (!conf->percpu) |
| 5018 | return; |
| 5019 | |
| 5020 | get_online_cpus(); |
| 5021 | for_each_possible_cpu(cpu) { |
| 5022 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 5023 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5024 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5025 | } |
| 5026 | #ifdef CONFIG_HOTPLUG_CPU |
| 5027 | unregister_cpu_notifier(&conf->cpu_notify); |
| 5028 | #endif |
| 5029 | put_online_cpus(); |
| 5030 | |
| 5031 | free_percpu(conf->percpu); |
| 5032 | } |
| 5033 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5034 | static void free_conf(struct r5conf *conf) |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5035 | { |
| 5036 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5037 | raid5_free_percpu(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5038 | kfree(conf->disks); |
| 5039 | kfree(conf->stripe_hashtbl); |
| 5040 | kfree(conf); |
| 5041 | } |
| 5042 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5043 | #ifdef CONFIG_HOTPLUG_CPU |
| 5044 | static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, |
| 5045 | void *hcpu) |
| 5046 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5047 | struct r5conf *conf = container_of(nfb, struct r5conf, cpu_notify); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5048 | long cpu = (long)hcpu; |
| 5049 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 5050 | |
| 5051 | switch (action) { |
| 5052 | case CPU_UP_PREPARE: |
| 5053 | case CPU_UP_PREPARE_FROZEN: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5054 | if (conf->level == 6 && !percpu->spare_page) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5055 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5056 | if (!percpu->scribble) |
| 5057 | percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
| 5058 | |
| 5059 | if (!percpu->scribble || |
| 5060 | (conf->level == 6 && !percpu->spare_page)) { |
| 5061 | safe_put_page(percpu->spare_page); |
| 5062 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5063 | pr_err("%s: failed memory allocation for cpu%ld\n", |
| 5064 | __func__, cpu); |
Akinobu Mita | 55af6bb | 2010-05-26 14:43:35 -0700 | [diff] [blame] | 5065 | return notifier_from_errno(-ENOMEM); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5066 | } |
| 5067 | break; |
| 5068 | case CPU_DEAD: |
| 5069 | case CPU_DEAD_FROZEN: |
| 5070 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5071 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5072 | percpu->spare_page = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5073 | percpu->scribble = NULL; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5074 | break; |
| 5075 | default: |
| 5076 | break; |
| 5077 | } |
| 5078 | return NOTIFY_OK; |
| 5079 | } |
| 5080 | #endif |
| 5081 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5082 | static int raid5_alloc_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5083 | { |
| 5084 | unsigned long cpu; |
| 5085 | struct page *spare_page; |
Tejun Heo | a29d8b8 | 2010-02-02 14:39:15 +0900 | [diff] [blame] | 5086 | struct raid5_percpu __percpu *allcpus; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5087 | void *scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5088 | int err; |
| 5089 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5090 | allcpus = alloc_percpu(struct raid5_percpu); |
| 5091 | if (!allcpus) |
| 5092 | return -ENOMEM; |
| 5093 | conf->percpu = allcpus; |
| 5094 | |
| 5095 | get_online_cpus(); |
| 5096 | err = 0; |
| 5097 | for_each_present_cpu(cpu) { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5098 | if (conf->level == 6) { |
| 5099 | spare_page = alloc_page(GFP_KERNEL); |
| 5100 | if (!spare_page) { |
| 5101 | err = -ENOMEM; |
| 5102 | break; |
| 5103 | } |
| 5104 | per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page; |
| 5105 | } |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5106 | scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5107 | if (!scribble) { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5108 | err = -ENOMEM; |
| 5109 | break; |
| 5110 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5111 | per_cpu_ptr(conf->percpu, cpu)->scribble = scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5112 | } |
| 5113 | #ifdef CONFIG_HOTPLUG_CPU |
| 5114 | conf->cpu_notify.notifier_call = raid456_cpu_notify; |
| 5115 | conf->cpu_notify.priority = 0; |
| 5116 | if (err == 0) |
| 5117 | err = register_cpu_notifier(&conf->cpu_notify); |
| 5118 | #endif |
| 5119 | put_online_cpus(); |
| 5120 | |
| 5121 | return err; |
| 5122 | } |
| 5123 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5124 | static struct r5conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5126 | struct r5conf *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5127 | int raid_disk, memory, max_disks; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5128 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | struct disk_info *disk; |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 5130 | char pers_name[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5132 | if (mddev->new_level != 5 |
| 5133 | && mddev->new_level != 4 |
| 5134 | && mddev->new_level != 6) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5135 | printk(KERN_ERR "md/raid:%s: raid level not set to 4/5/6 (%d)\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5136 | mdname(mddev), mddev->new_level); |
| 5137 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5139 | if ((mddev->new_level == 5 |
| 5140 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 5141 | (mddev->new_level == 6 |
| 5142 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5143 | printk(KERN_ERR "md/raid:%s: layout %d not supported\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5144 | mdname(mddev), mddev->new_layout); |
| 5145 | return ERR_PTR(-EIO); |
| 5146 | } |
| 5147 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5148 | printk(KERN_ERR "md/raid:%s: not enough configured devices (%d, minimum 4)\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5149 | mdname(mddev), mddev->raid_disks); |
| 5150 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5153 | if (!mddev->new_chunk_sectors || |
| 5154 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 5155 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5156 | printk(KERN_ERR "md/raid:%s: invalid chunk size %d\n", |
| 5157 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5158 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5159 | } |
| 5160 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5161 | conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5162 | if (conf == NULL) |
| 5163 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 5164 | spin_lock_init(&conf->device_lock); |
| 5165 | init_waitqueue_head(&conf->wait_for_stripe); |
| 5166 | init_waitqueue_head(&conf->wait_for_overlap); |
| 5167 | INIT_LIST_HEAD(&conf->handle_list); |
| 5168 | INIT_LIST_HEAD(&conf->hold_list); |
| 5169 | INIT_LIST_HEAD(&conf->delayed_list); |
| 5170 | INIT_LIST_HEAD(&conf->bitmap_list); |
| 5171 | INIT_LIST_HEAD(&conf->inactive_list); |
| 5172 | atomic_set(&conf->active_stripes, 0); |
| 5173 | atomic_set(&conf->preread_active_stripes, 0); |
| 5174 | atomic_set(&conf->active_aligned_reads, 0); |
| 5175 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 5176 | conf->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5177 | |
| 5178 | conf->raid_disks = mddev->raid_disks; |
| 5179 | if (mddev->reshape_position == MaxSector) |
| 5180 | conf->previous_raid_disks = mddev->raid_disks; |
| 5181 | else |
| 5182 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5183 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
| 5184 | conf->scribble_len = scribble_len(max_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5185 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5186 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5187 | GFP_KERNEL); |
| 5188 | if (!conf->disks) |
| 5189 | goto abort; |
| 5190 | |
| 5191 | conf->mddev = mddev; |
| 5192 | |
| 5193 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 5194 | goto abort; |
| 5195 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5196 | conf->level = mddev->new_level; |
| 5197 | if (raid5_alloc_percpu(conf) != 0) |
| 5198 | goto abort; |
| 5199 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5200 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5201 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 5202 | rdev_for_each(rdev, mddev) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5203 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5204 | if (raid_disk >= max_disks |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5205 | || raid_disk < 0) |
| 5206 | continue; |
| 5207 | disk = conf->disks + raid_disk; |
| 5208 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5209 | if (test_bit(Replacement, &rdev->flags)) { |
| 5210 | if (disk->replacement) |
| 5211 | goto abort; |
| 5212 | disk->replacement = rdev; |
| 5213 | } else { |
| 5214 | if (disk->rdev) |
| 5215 | goto abort; |
| 5216 | disk->rdev = rdev; |
| 5217 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5218 | |
| 5219 | if (test_bit(In_sync, &rdev->flags)) { |
| 5220 | char b[BDEVNAME_SIZE]; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5221 | printk(KERN_INFO "md/raid:%s: device %s operational as raid" |
| 5222 | " disk %d\n", |
| 5223 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
Jonathan Brassow | d6b212f | 2011-06-08 18:00:28 -0500 | [diff] [blame] | 5224 | } else if (rdev->saved_raid_disk != raid_disk) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5225 | /* Cannot rely on bitmap to complete recovery */ |
| 5226 | conf->fullsync = 1; |
| 5227 | } |
| 5228 | |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5229 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5230 | conf->level = mddev->new_level; |
| 5231 | if (conf->level == 6) |
| 5232 | conf->max_degraded = 2; |
| 5233 | else |
| 5234 | conf->max_degraded = 1; |
| 5235 | conf->algorithm = mddev->new_layout; |
| 5236 | conf->max_nr_stripes = NR_STRIPES; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5237 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5238 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5239 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5240 | conf->prev_algo = mddev->layout; |
| 5241 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5242 | |
| 5243 | memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5244 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5245 | if (grow_stripes(conf, conf->max_nr_stripes)) { |
| 5246 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5247 | "md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 5248 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5249 | goto abort; |
| 5250 | } else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5251 | printk(KERN_INFO "md/raid:%s: allocated %dkB\n", |
| 5252 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5253 | |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 5254 | sprintf(pers_name, "raid%d", mddev->new_level); |
| 5255 | conf->thread = md_register_thread(raid5d, mddev, pers_name); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5256 | if (!conf->thread) { |
| 5257 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5258 | "md/raid:%s: couldn't allocate thread.\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5259 | mdname(mddev)); |
| 5260 | goto abort; |
| 5261 | } |
| 5262 | |
| 5263 | return conf; |
| 5264 | |
| 5265 | abort: |
| 5266 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5267 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5268 | return ERR_PTR(-EIO); |
| 5269 | } else |
| 5270 | return ERR_PTR(-ENOMEM); |
| 5271 | } |
| 5272 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5273 | |
| 5274 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 5275 | { |
| 5276 | switch (algo) { |
| 5277 | case ALGORITHM_PARITY_0: |
| 5278 | if (raid_disk < max_degraded) |
| 5279 | return 1; |
| 5280 | break; |
| 5281 | case ALGORITHM_PARITY_N: |
| 5282 | if (raid_disk >= raid_disks - max_degraded) |
| 5283 | return 1; |
| 5284 | break; |
| 5285 | case ALGORITHM_PARITY_0_6: |
| 5286 | if (raid_disk == 0 || |
| 5287 | raid_disk == raid_disks - 1) |
| 5288 | return 1; |
| 5289 | break; |
| 5290 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 5291 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 5292 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 5293 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 5294 | if (raid_disk == raid_disks - 1) |
| 5295 | return 1; |
| 5296 | } |
| 5297 | return 0; |
| 5298 | } |
| 5299 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5300 | static int run(struct mddev *mddev) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5301 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5302 | struct r5conf *conf; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5303 | int working_disks = 0; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5304 | int dirty_parity_disks = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5305 | struct md_rdev *rdev; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5306 | sector_t reshape_offset = 0; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5307 | int i; |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5308 | long long min_offset_diff = 0; |
| 5309 | int first = 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5310 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 5311 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5312 | printk(KERN_NOTICE "md/raid:%s: not clean" |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 5313 | " -- starting background reconstruction\n", |
| 5314 | mdname(mddev)); |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5315 | |
| 5316 | rdev_for_each(rdev, mddev) { |
| 5317 | long long diff; |
| 5318 | if (rdev->raid_disk < 0) |
| 5319 | continue; |
| 5320 | diff = (rdev->new_data_offset - rdev->data_offset); |
| 5321 | if (first) { |
| 5322 | min_offset_diff = diff; |
| 5323 | first = 0; |
| 5324 | } else if (mddev->reshape_backwards && |
| 5325 | diff < min_offset_diff) |
| 5326 | min_offset_diff = diff; |
| 5327 | else if (!mddev->reshape_backwards && |
| 5328 | diff > min_offset_diff) |
| 5329 | min_offset_diff = diff; |
| 5330 | } |
| 5331 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5332 | if (mddev->reshape_position != MaxSector) { |
| 5333 | /* Check that we can continue the reshape. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5334 | * Difficulties arise if the stripe we would write to |
| 5335 | * next is at or after the stripe we would read from next. |
| 5336 | * For a reshape that changes the number of devices, this |
| 5337 | * is only possible for a very short time, and mdadm makes |
| 5338 | * sure that time appears to have past before assembling |
| 5339 | * the array. So we fail if that time hasn't passed. |
| 5340 | * For a reshape that keeps the number of devices the same |
| 5341 | * mdadm must be monitoring the reshape can keeping the |
| 5342 | * critical areas read-only and backed up. It will start |
| 5343 | * the array in read-only mode, so we check for that. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5344 | */ |
| 5345 | sector_t here_new, here_old; |
| 5346 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 5347 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5348 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5349 | if (mddev->new_level != mddev->level) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5350 | printk(KERN_ERR "md/raid:%s: unsupported reshape " |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5351 | "required - aborting.\n", |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5352 | mdname(mddev)); |
| 5353 | return -EINVAL; |
| 5354 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5355 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 5356 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5357 | * further up in new geometry must map after here in old |
| 5358 | * geometry. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5359 | */ |
| 5360 | here_new = mddev->reshape_position; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5361 | if (sector_div(here_new, mddev->new_chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5362 | (mddev->raid_disks - max_degraded))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5363 | printk(KERN_ERR "md/raid:%s: reshape_position not " |
| 5364 | "on a stripe boundary\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5365 | return -EINVAL; |
| 5366 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5367 | reshape_offset = here_new * mddev->new_chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5368 | /* here_new is the stripe we will write to */ |
| 5369 | here_old = mddev->reshape_position; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5370 | sector_div(here_old, mddev->chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5371 | (old_disks-max_degraded)); |
| 5372 | /* here_old is the first stripe that we might need to read |
| 5373 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5374 | if (mddev->delta_disks == 0) { |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5375 | if ((here_new * mddev->new_chunk_sectors != |
| 5376 | here_old * mddev->chunk_sectors)) { |
| 5377 | printk(KERN_ERR "md/raid:%s: reshape position is" |
| 5378 | " confused - aborting\n", mdname(mddev)); |
| 5379 | return -EINVAL; |
| 5380 | } |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5381 | /* We cannot be sure it is safe to start an in-place |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5382 | * reshape. It is only safe if user-space is monitoring |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5383 | * and taking constant backups. |
| 5384 | * mdadm always starts a situation like this in |
| 5385 | * readonly mode so it can take control before |
| 5386 | * allowing any writes. So just check for that. |
| 5387 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5388 | if (abs(min_offset_diff) >= mddev->chunk_sectors && |
| 5389 | abs(min_offset_diff) >= mddev->new_chunk_sectors) |
| 5390 | /* not really in-place - so OK */; |
| 5391 | else if (mddev->ro == 0) { |
| 5392 | printk(KERN_ERR "md/raid:%s: in-place reshape " |
| 5393 | "must be started in read-only mode " |
| 5394 | "- aborting\n", |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5395 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5396 | return -EINVAL; |
| 5397 | } |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5398 | } else if (mddev->reshape_backwards |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5399 | ? (here_new * mddev->new_chunk_sectors + min_offset_diff <= |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5400 | here_old * mddev->chunk_sectors) |
| 5401 | : (here_new * mddev->new_chunk_sectors >= |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5402 | here_old * mddev->chunk_sectors + (-min_offset_diff))) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5403 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5404 | printk(KERN_ERR "md/raid:%s: reshape_position too early for " |
| 5405 | "auto-recovery - aborting.\n", |
| 5406 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5407 | return -EINVAL; |
| 5408 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5409 | printk(KERN_INFO "md/raid:%s: reshape will continue\n", |
| 5410 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5411 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5412 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5413 | BUG_ON(mddev->level != mddev->new_level); |
| 5414 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5415 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5416 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5417 | } |
| 5418 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5419 | if (mddev->private == NULL) |
| 5420 | conf = setup_conf(mddev); |
| 5421 | else |
| 5422 | conf = mddev->private; |
| 5423 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5424 | if (IS_ERR(conf)) |
| 5425 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 5426 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5427 | conf->min_offset_diff = min_offset_diff; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5428 | mddev->thread = conf->thread; |
| 5429 | conf->thread = NULL; |
| 5430 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5431 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5432 | for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; |
| 5433 | i++) { |
| 5434 | rdev = conf->disks[i].rdev; |
| 5435 | if (!rdev && conf->disks[i].replacement) { |
| 5436 | /* The replacement is all we have yet */ |
| 5437 | rdev = conf->disks[i].replacement; |
| 5438 | conf->disks[i].replacement = NULL; |
| 5439 | clear_bit(Replacement, &rdev->flags); |
| 5440 | conf->disks[i].rdev = rdev; |
| 5441 | } |
| 5442 | if (!rdev) |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5443 | continue; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5444 | if (conf->disks[i].replacement && |
| 5445 | conf->reshape_progress != MaxSector) { |
| 5446 | /* replacements and reshape simply do not mix. */ |
| 5447 | printk(KERN_ERR "md: cannot handle concurrent " |
| 5448 | "replacement and reshape.\n"); |
| 5449 | goto abort; |
| 5450 | } |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 5451 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5452 | working_disks++; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 5453 | continue; |
| 5454 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5455 | /* This disc is not fully in-sync. However if it |
| 5456 | * just stored parity (beyond the recovery_offset), |
| 5457 | * when we don't need to be concerned about the |
| 5458 | * array being dirty. |
| 5459 | * When reshape goes 'backwards', we never have |
| 5460 | * partially completed devices, so we only need |
| 5461 | * to worry about reshape going forwards. |
| 5462 | */ |
| 5463 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 5464 | if (mddev->major_version == 0 && |
| 5465 | mddev->minor_version > 90) |
| 5466 | rdev->recovery_offset = reshape_offset; |
| 5467 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5468 | if (rdev->recovery_offset < reshape_offset) { |
| 5469 | /* We need to check old and new layout */ |
| 5470 | if (!only_parity(rdev->raid_disk, |
| 5471 | conf->algorithm, |
| 5472 | conf->raid_disks, |
| 5473 | conf->max_degraded)) |
| 5474 | continue; |
| 5475 | } |
| 5476 | if (!only_parity(rdev->raid_disk, |
| 5477 | conf->prev_algo, |
| 5478 | conf->previous_raid_disks, |
| 5479 | conf->max_degraded)) |
| 5480 | continue; |
| 5481 | dirty_parity_disks++; |
| 5482 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5483 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5484 | /* |
| 5485 | * 0 for a fully functional array, 1 or 2 for a degraded array. |
| 5486 | */ |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5487 | mddev->degraded = calc_degraded(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5489 | if (has_failed(conf)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5490 | printk(KERN_ERR "md/raid:%s: not enough operational devices" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | " (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5492 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | goto abort; |
| 5494 | } |
| 5495 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5496 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5497 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5498 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 5499 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5500 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5502 | if (mddev->ok_start_degraded) |
| 5503 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5504 | "md/raid:%s: starting dirty degraded array" |
| 5505 | " - data corruption possible.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5506 | mdname(mddev)); |
| 5507 | else { |
| 5508 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5509 | "md/raid:%s: cannot start dirty degraded array.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5510 | mdname(mddev)); |
| 5511 | goto abort; |
| 5512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | } |
| 5514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | if (mddev->degraded == 0) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5516 | printk(KERN_INFO "md/raid:%s: raid level %d active with %d out of %d" |
| 5517 | " devices, algorithm %d\n", mdname(mddev), conf->level, |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5518 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 5519 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5521 | printk(KERN_ALERT "md/raid:%s: raid level %d active with %d" |
| 5522 | " out of %d devices, algorithm %d\n", |
| 5523 | mdname(mddev), conf->level, |
| 5524 | mddev->raid_disks - mddev->degraded, |
| 5525 | mddev->raid_disks, mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | |
| 5527 | print_raid5_conf(conf); |
| 5528 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5529 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5530 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5531 | atomic_set(&conf->reshape_stripes, 0); |
| 5532 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5533 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5534 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5535 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5536 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5537 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5538 | } |
| 5539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | |
| 5541 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5542 | if (mddev->to_remove == &raid5_attrs_group) |
| 5543 | mddev->to_remove = NULL; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5544 | else if (mddev->kobj.sd && |
| 5545 | sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5546 | printk(KERN_WARNING |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5547 | "raid5: failed to create sysfs attributes for %s\n", |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5548 | mdname(mddev)); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5549 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5550 | |
| 5551 | if (mddev->queue) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5552 | int chunk_size; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5553 | bool discard_supported = true; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5554 | /* read-ahead size must cover two whole stripes, which |
| 5555 | * is 2 * (datadisks) * chunksize where 'n' is the |
| 5556 | * number of raid devices |
| 5557 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 5559 | int stripe = data_disks * |
| 5560 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
| 5561 | if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5562 | mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5563 | |
| 5564 | blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 5565 | |
| 5566 | mddev->queue->backing_dev_info.congested_data = mddev; |
| 5567 | mddev->queue->backing_dev_info.congested_fn = raid5_congested; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5568 | |
| 5569 | chunk_size = mddev->chunk_sectors << 9; |
| 5570 | blk_queue_io_min(mddev->queue, chunk_size); |
| 5571 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 5572 | (conf->raid_disks - conf->max_degraded)); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5573 | /* |
| 5574 | * We can only discard a whole stripe. It doesn't make sense to |
| 5575 | * discard data disk but write parity disk |
| 5576 | */ |
| 5577 | stripe = stripe * PAGE_SIZE; |
NeilBrown | 4ac6875 | 2012-11-19 13:11:26 +1100 | [diff] [blame] | 5578 | /* Round up to power of 2, as discard handling |
| 5579 | * currently assumes that */ |
| 5580 | while ((stripe-1) & stripe) |
| 5581 | stripe = (stripe | (stripe-1)) + 1; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5582 | mddev->queue->limits.discard_alignment = stripe; |
| 5583 | mddev->queue->limits.discard_granularity = stripe; |
| 5584 | /* |
| 5585 | * unaligned part of discard request will be ignored, so can't |
| 5586 | * guarantee discard_zerors_data |
| 5587 | */ |
| 5588 | mddev->queue->limits.discard_zeroes_data = 0; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5589 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5590 | rdev_for_each(rdev, mddev) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5591 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5592 | rdev->data_offset << 9); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5593 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5594 | rdev->new_data_offset << 9); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5595 | /* |
| 5596 | * discard_zeroes_data is required, otherwise data |
| 5597 | * could be lost. Consider a scenario: discard a stripe |
| 5598 | * (the stripe could be inconsistent if |
| 5599 | * discard_zeroes_data is 0); write one disk of the |
| 5600 | * stripe (the stripe could be inconsistent again |
| 5601 | * depending on which disks are used to calculate |
| 5602 | * parity); the disk is broken; The stripe data of this |
| 5603 | * disk is lost. |
| 5604 | */ |
| 5605 | if (!blk_queue_discard(bdev_get_queue(rdev->bdev)) || |
| 5606 | !bdev_get_queue(rdev->bdev)-> |
| 5607 | limits.discard_zeroes_data) |
| 5608 | discard_supported = false; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5609 | } |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5610 | |
| 5611 | if (discard_supported && |
| 5612 | mddev->queue->limits.max_discard_sectors >= stripe && |
| 5613 | mddev->queue->limits.discard_granularity >= stripe) |
| 5614 | queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, |
| 5615 | mddev->queue); |
| 5616 | else |
| 5617 | queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, |
| 5618 | mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5621 | return 0; |
| 5622 | abort: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 5623 | md_unregister_thread(&mddev->thread); |
NeilBrown | e4f869d | 2011-10-07 14:22:49 +1100 | [diff] [blame] | 5624 | print_raid5_conf(conf); |
| 5625 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | mddev->private = NULL; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5627 | printk(KERN_ALERT "md/raid:%s: failed to run raid set.\n", mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | return -EIO; |
| 5629 | } |
| 5630 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5631 | static int stop(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5633 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 5635 | md_unregister_thread(&mddev->thread); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 5636 | if (mddev->queue) |
| 5637 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5638 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5639 | mddev->private = NULL; |
| 5640 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | return 0; |
| 5642 | } |
| 5643 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5644 | static void status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5646 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | int i; |
| 5648 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5649 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
| 5650 | mddev->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5651 | seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | for (i = 0; i < conf->raid_disks; i++) |
| 5653 | seq_printf (seq, "%s", |
| 5654 | conf->disks[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5655 | test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | seq_printf (seq, "]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5657 | } |
| 5658 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5659 | static void print_raid5_conf (struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5660 | { |
| 5661 | int i; |
| 5662 | struct disk_info *tmp; |
| 5663 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5664 | printk(KERN_DEBUG "RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | if (!conf) { |
| 5666 | printk("(conf==NULL)\n"); |
| 5667 | return; |
| 5668 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5669 | printk(KERN_DEBUG " --- level:%d rd:%d wd:%d\n", conf->level, |
| 5670 | conf->raid_disks, |
| 5671 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | |
| 5673 | for (i = 0; i < conf->raid_disks; i++) { |
| 5674 | char b[BDEVNAME_SIZE]; |
| 5675 | tmp = conf->disks + i; |
| 5676 | if (tmp->rdev) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5677 | printk(KERN_DEBUG " disk %d, o:%d, dev:%s\n", |
| 5678 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 5679 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5680 | } |
| 5681 | } |
| 5682 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5683 | static int raid5_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | { |
| 5685 | int i; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5686 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | struct disk_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5688 | int count = 0; |
| 5689 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | |
| 5691 | for (i = 0; i < conf->raid_disks; i++) { |
| 5692 | tmp = conf->disks + i; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5693 | if (tmp->replacement |
| 5694 | && tmp->replacement->recovery_offset == MaxSector |
| 5695 | && !test_bit(Faulty, &tmp->replacement->flags) |
| 5696 | && !test_and_set_bit(In_sync, &tmp->replacement->flags)) { |
| 5697 | /* Replacement has just become active. */ |
| 5698 | if (!tmp->rdev |
| 5699 | || !test_and_clear_bit(In_sync, &tmp->rdev->flags)) |
| 5700 | count++; |
| 5701 | if (tmp->rdev) { |
| 5702 | /* Replaced device not technically faulty, |
| 5703 | * but we need to be sure it gets removed |
| 5704 | * and never re-added. |
| 5705 | */ |
| 5706 | set_bit(Faulty, &tmp->rdev->flags); |
| 5707 | sysfs_notify_dirent_safe( |
| 5708 | tmp->rdev->sysfs_state); |
| 5709 | } |
| 5710 | sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); |
| 5711 | } else if (tmp->rdev |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 5712 | && tmp->rdev->recovery_offset == MaxSector |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5713 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5714 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5715 | count++; |
Jonathan Brassow | 43c73ca | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 5716 | sysfs_notify_dirent_safe(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | } |
| 5718 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5719 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5720 | mddev->degraded = calc_degraded(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5721 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | print_raid5_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5723 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | } |
| 5725 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 5726 | static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5728 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5729 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 5730 | int number = rdev->raid_disk; |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5731 | struct md_rdev **rdevp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | struct disk_info *p = conf->disks + number; |
| 5733 | |
| 5734 | print_raid5_conf(conf); |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5735 | if (rdev == p->rdev) |
| 5736 | rdevp = &p->rdev; |
| 5737 | else if (rdev == p->replacement) |
| 5738 | rdevp = &p->replacement; |
| 5739 | else |
| 5740 | return 0; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5741 | |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5742 | if (number >= conf->raid_disks && |
| 5743 | conf->reshape_progress == MaxSector) |
| 5744 | clear_bit(In_sync, &rdev->flags); |
| 5745 | |
| 5746 | if (test_bit(In_sync, &rdev->flags) || |
| 5747 | atomic_read(&rdev->nr_pending)) { |
| 5748 | err = -EBUSY; |
| 5749 | goto abort; |
| 5750 | } |
| 5751 | /* Only remove non-faulty devices if recovery |
| 5752 | * isn't possible. |
| 5753 | */ |
| 5754 | if (!test_bit(Faulty, &rdev->flags) && |
| 5755 | mddev->recovery_disabled != conf->recovery_disabled && |
| 5756 | !has_failed(conf) && |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5757 | (!p->replacement || p->replacement == rdev) && |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5758 | number < conf->raid_disks) { |
| 5759 | err = -EBUSY; |
| 5760 | goto abort; |
| 5761 | } |
| 5762 | *rdevp = NULL; |
| 5763 | synchronize_rcu(); |
| 5764 | if (atomic_read(&rdev->nr_pending)) { |
| 5765 | /* lost the race, try later */ |
| 5766 | err = -EBUSY; |
| 5767 | *rdevp = rdev; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5768 | } else if (p->replacement) { |
| 5769 | /* We must have just cleared 'rdev' */ |
| 5770 | p->rdev = p->replacement; |
| 5771 | clear_bit(Replacement, &p->replacement->flags); |
| 5772 | smp_mb(); /* Make sure other CPUs may see both as identical |
| 5773 | * but will never see neither - if they are careful |
| 5774 | */ |
| 5775 | p->replacement = NULL; |
| 5776 | clear_bit(WantReplacement, &rdev->flags); |
| 5777 | } else |
| 5778 | /* We might have just removed the Replacement as faulty- |
| 5779 | * clear the bit just in case |
| 5780 | */ |
| 5781 | clear_bit(WantReplacement, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | abort: |
| 5783 | |
| 5784 | print_raid5_conf(conf); |
| 5785 | return err; |
| 5786 | } |
| 5787 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5788 | static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5790 | struct r5conf *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5791 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | int disk; |
| 5793 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5794 | int first = 0; |
| 5795 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5797 | if (mddev->recovery_disabled == conf->recovery_disabled) |
| 5798 | return -EBUSY; |
| 5799 | |
NeilBrown | dc10c64 | 2012-03-19 12:46:37 +1100 | [diff] [blame] | 5800 | if (rdev->saved_raid_disk < 0 && has_failed(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5802 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5804 | if (rdev->raid_disk >= 0) |
| 5805 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | |
| 5807 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5808 | * find the disk ... but prefer rdev->saved_raid_disk |
| 5809 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5811 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5812 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5813 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 5814 | first = rdev->saved_raid_disk; |
| 5815 | |
| 5816 | for (disk = first; disk <= last; disk++) { |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5817 | p = conf->disks + disk; |
| 5818 | if (p->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5819 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5821 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5822 | if (rdev->saved_raid_disk != disk) |
| 5823 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 5824 | rcu_assign_pointer(p->rdev, rdev); |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 5825 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 5827 | } |
| 5828 | for (disk = first; disk <= last; disk++) { |
| 5829 | p = conf->disks + disk; |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5830 | if (test_bit(WantReplacement, &p->rdev->flags) && |
| 5831 | p->replacement == NULL) { |
| 5832 | clear_bit(In_sync, &rdev->flags); |
| 5833 | set_bit(Replacement, &rdev->flags); |
| 5834 | rdev->raid_disk = disk; |
| 5835 | err = 0; |
| 5836 | conf->fullsync = 1; |
| 5837 | rcu_assign_pointer(p->replacement, rdev); |
| 5838 | break; |
| 5839 | } |
| 5840 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 5841 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5843 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5846 | static int raid5_resize(struct mddev *mddev, sector_t sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | { |
| 5848 | /* no resync is happening, and there is enough space |
| 5849 | * on all devices, so we can resize. |
| 5850 | * We need to make sure resync covers any new space. |
| 5851 | * If the array is shrinking we should possibly wait until |
| 5852 | * any io in the removed space completes, but it hardly seems |
| 5853 | * worth it. |
| 5854 | */ |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 5855 | sector_t newsize; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5856 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 5857 | newsize = raid5_size(mddev, sectors, mddev->raid_disks); |
| 5858 | if (mddev->external_size && |
| 5859 | mddev->array_sectors > newsize) |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5860 | return -EINVAL; |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 5861 | if (mddev->bitmap) { |
| 5862 | int ret = bitmap_resize(mddev->bitmap, sectors, 0, 0); |
| 5863 | if (ret) |
| 5864 | return ret; |
| 5865 | } |
| 5866 | md_set_array_sectors(mddev, newsize); |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 5867 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5868 | revalidate_disk(mddev->gendisk); |
NeilBrown | b098636 | 2011-05-11 15:52:21 +1000 | [diff] [blame] | 5869 | if (sectors > mddev->dev_sectors && |
| 5870 | mddev->recovery_cp > mddev->dev_sectors) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5871 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5872 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5873 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5874 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 5875 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | return 0; |
| 5877 | } |
| 5878 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5879 | static int check_stripe_cache(struct mddev *mddev) |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5880 | { |
| 5881 | /* Can only proceed if there are plenty of stripe_heads. |
| 5882 | * We need a minimum of one full stripe,, and for sensible progress |
| 5883 | * it is best to have about 4 times that. |
| 5884 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 5885 | * allow for chunk sizes up to 256K, which is probably OK. |
| 5886 | * If the chunk size is greater, user-space should request more |
| 5887 | * stripe_heads first. |
| 5888 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5889 | struct r5conf *conf = mddev->private; |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5890 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5891 | > conf->max_nr_stripes || |
| 5892 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5893 | > conf->max_nr_stripes) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5894 | printk(KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 5895 | mdname(mddev), |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5896 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 5897 | / STRIPE_SIZE)*4); |
| 5898 | return 0; |
| 5899 | } |
| 5900 | return 1; |
| 5901 | } |
| 5902 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5903 | static int check_reshape(struct mddev *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5904 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5905 | struct r5conf *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5906 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5907 | if (mddev->delta_disks == 0 && |
| 5908 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5909 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5910 | return 0; /* nothing to do */ |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5911 | if (has_failed(conf)) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5912 | return -EINVAL; |
| 5913 | if (mddev->delta_disks < 0) { |
| 5914 | /* We might be able to shrink, but the devices must |
| 5915 | * be made bigger first. |
| 5916 | * For raid6, 4 is the minimum size. |
| 5917 | * Otherwise 2 is the minimum |
| 5918 | */ |
| 5919 | int min = 2; |
| 5920 | if (mddev->level == 6) |
| 5921 | min = 4; |
| 5922 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 5923 | return -EINVAL; |
| 5924 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5925 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5926 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5927 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5928 | |
NeilBrown | e56108d6 | 2012-10-11 14:24:13 +1100 | [diff] [blame] | 5929 | return resize_stripes(conf, (conf->previous_raid_disks |
| 5930 | + mddev->delta_disks)); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5931 | } |
| 5932 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5933 | static int raid5_start_reshape(struct mddev *mddev) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5934 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5935 | struct r5conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5936 | struct md_rdev *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5937 | int spares = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5938 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5939 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5940 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5941 | return -EBUSY; |
| 5942 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5943 | if (!check_stripe_cache(mddev)) |
| 5944 | return -ENOSPC; |
| 5945 | |
NeilBrown | 30b6764 | 2012-05-22 13:55:28 +1000 | [diff] [blame] | 5946 | if (has_failed(conf)) |
| 5947 | return -EINVAL; |
| 5948 | |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5949 | rdev_for_each(rdev, mddev) { |
NeilBrown | 469518a | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5950 | if (!test_bit(In_sync, &rdev->flags) |
| 5951 | && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5952 | spares++; |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5953 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5954 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5955 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5956 | /* Not enough devices even to make a degraded array |
| 5957 | * of that size |
| 5958 | */ |
| 5959 | return -EINVAL; |
| 5960 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5961 | /* Refuse to reduce size of the array. Any reductions in |
| 5962 | * array size must be through explicit setting of array_size |
| 5963 | * attribute. |
| 5964 | */ |
| 5965 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 5966 | < mddev->array_sectors) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5967 | printk(KERN_ERR "md/raid:%s: array size must be reduced " |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5968 | "before number of disks\n", mdname(mddev)); |
| 5969 | return -EINVAL; |
| 5970 | } |
| 5971 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5972 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5973 | spin_lock_irq(&conf->device_lock); |
| 5974 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5975 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5976 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 5977 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5978 | conf->prev_algo = conf->algorithm; |
| 5979 | conf->algorithm = mddev->new_layout; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5980 | conf->generation++; |
| 5981 | /* Code that selects data_offset needs to see the generation update |
| 5982 | * if reshape_progress has been set - so a memory barrier needed. |
| 5983 | */ |
| 5984 | smp_mb(); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5985 | if (mddev->reshape_backwards) |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5986 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 5987 | else |
| 5988 | conf->reshape_progress = 0; |
| 5989 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5990 | spin_unlock_irq(&conf->device_lock); |
| 5991 | |
| 5992 | /* Add some new drives, as many as will fit. |
| 5993 | * We know there are enough to make the newly sized array work. |
NeilBrown | 3424bf6 | 2010-06-17 17:48:26 +1000 | [diff] [blame] | 5994 | * Don't add devices if we are reducing the number of |
| 5995 | * devices in the array. This is because it is not possible |
| 5996 | * to correctly record the "partially reconstructed" state of |
| 5997 | * such devices during the reshape and confusion could result. |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5998 | */ |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5999 | if (mddev->delta_disks >= 0) { |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 6000 | rdev_for_each(rdev, mddev) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6001 | if (rdev->raid_disk < 0 && |
| 6002 | !test_bit(Faulty, &rdev->flags)) { |
| 6003 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6004 | if (rdev->raid_disk |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 6005 | >= conf->previous_raid_disks) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6006 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 6007 | else |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6008 | rdev->recovery_offset = 0; |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 6009 | |
| 6010 | if (sysfs_link_rdev(mddev, rdev)) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6011 | /* Failure here is OK */; |
NeilBrown | 50da084 | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6012 | } |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6013 | } else if (rdev->raid_disk >= conf->previous_raid_disks |
| 6014 | && !test_bit(Faulty, &rdev->flags)) { |
| 6015 | /* This is a spare that was manually added */ |
| 6016 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6017 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6018 | |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6019 | /* When a reshape changes the number of devices, |
| 6020 | * ->degraded is measured against the larger of the |
| 6021 | * pre and post number of devices. |
| 6022 | */ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6023 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 6024 | mddev->degraded = calc_degraded(conf); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6025 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 6026 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6027 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 6028 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6029 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6030 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6031 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 6032 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 6033 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 6034 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 6035 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 6036 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6037 | if (!mddev->sync_thread) { |
| 6038 | mddev->recovery = 0; |
| 6039 | spin_lock_irq(&conf->device_lock); |
| 6040 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6041 | rdev_for_each(rdev, mddev) |
| 6042 | rdev->new_data_offset = rdev->data_offset; |
| 6043 | smp_wmb(); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6044 | conf->reshape_progress = MaxSector; |
NeilBrown | 1e3fa9b | 2012-03-13 11:21:18 +1100 | [diff] [blame] | 6045 | mddev->reshape_position = MaxSector; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6046 | spin_unlock_irq(&conf->device_lock); |
| 6047 | return -EAGAIN; |
| 6048 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 6049 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6050 | md_wakeup_thread(mddev->sync_thread); |
| 6051 | md_new_event(mddev); |
| 6052 | return 0; |
| 6053 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6054 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6055 | /* This is called from the reshape thread and should make any |
| 6056 | * changes needed in 'conf' |
| 6057 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6058 | static void end_reshape(struct r5conf *conf) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6059 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6060 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6061 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6062 | struct md_rdev *rdev; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6063 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6064 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6065 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6066 | rdev_for_each(rdev, conf->mddev) |
| 6067 | rdev->data_offset = rdev->new_data_offset; |
| 6068 | smp_wmb(); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6069 | conf->reshape_progress = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6070 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 6071 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6072 | |
| 6073 | /* read-ahead size must cover two whole stripes, which is |
| 6074 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 6075 | */ |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 6076 | if (conf->mddev->queue) { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6077 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 6078 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6079 | / PAGE_SIZE); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6080 | if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 6081 | conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 6082 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6083 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6084 | } |
| 6085 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6086 | /* This is called from the raid5d thread with mddev_lock held. |
| 6087 | * It makes config changes to the device. |
| 6088 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6089 | static void raid5_finish_reshape(struct mddev *mddev) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6090 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6091 | struct r5conf *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6092 | |
| 6093 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6094 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6095 | if (mddev->delta_disks > 0) { |
| 6096 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 6097 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6098 | revalidate_disk(mddev->gendisk); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6099 | } else { |
| 6100 | int d; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 6101 | spin_lock_irq(&conf->device_lock); |
| 6102 | mddev->degraded = calc_degraded(conf); |
| 6103 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6104 | for (d = conf->raid_disks ; |
| 6105 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 6106 | d++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 6107 | struct md_rdev *rdev = conf->disks[d].rdev; |
NeilBrown | da7613b | 2012-05-22 13:55:33 +1000 | [diff] [blame] | 6108 | if (rdev) |
| 6109 | clear_bit(In_sync, &rdev->flags); |
| 6110 | rdev = conf->disks[d].replacement; |
| 6111 | if (rdev) |
| 6112 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 6113 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6114 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6115 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 6116 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6117 | mddev->reshape_position = MaxSector; |
| 6118 | mddev->delta_disks = 0; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6119 | mddev->reshape_backwards = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6120 | } |
| 6121 | } |
| 6122 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6123 | static void raid5_quiesce(struct mddev *mddev, int state) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6124 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6125 | struct r5conf *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6126 | |
| 6127 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 6128 | case 2: /* resume for a suspend */ |
| 6129 | wake_up(&conf->wait_for_overlap); |
| 6130 | break; |
| 6131 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6132 | case 1: /* stop all writes */ |
| 6133 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6134 | /* '2' tells resync/reshape to pause so that all |
| 6135 | * active stripes can drain |
| 6136 | */ |
| 6137 | conf->quiesce = 2; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6138 | wait_event_lock_irq(conf->wait_for_stripe, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6139 | atomic_read(&conf->active_stripes) == 0 && |
| 6140 | atomic_read(&conf->active_aligned_reads) == 0, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 6141 | conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6142 | conf->quiesce = 1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6143 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6144 | /* allow reshape to continue */ |
| 6145 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6146 | break; |
| 6147 | |
| 6148 | case 0: /* re-enable writes */ |
| 6149 | spin_lock_irq(&conf->device_lock); |
| 6150 | conf->quiesce = 0; |
| 6151 | wake_up(&conf->wait_for_stripe); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 6152 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6153 | spin_unlock_irq(&conf->device_lock); |
| 6154 | break; |
| 6155 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6156 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 6157 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6158 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6159 | static void *raid45_takeover_raid0(struct mddev *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 6160 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 6161 | struct r0conf *raid0_conf = mddev->private; |
Randy Dunlap | d76c842 | 2011-04-21 09:07:26 -0700 | [diff] [blame] | 6162 | sector_t sectors; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 6163 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6164 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 6165 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 6166 | printk(KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 6167 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6168 | return ERR_PTR(-EINVAL); |
| 6169 | } |
| 6170 | |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 6171 | sectors = raid0_conf->strip_zone[0].zone_end; |
| 6172 | sector_div(sectors, raid0_conf->strip_zone[0].nb_dev); |
NeilBrown | 3b71bd9 | 2011-04-20 15:38:18 +1000 | [diff] [blame] | 6173 | mddev->dev_sectors = sectors; |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6174 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 6175 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 6176 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 6177 | mddev->raid_disks += 1; |
| 6178 | mddev->delta_disks = 1; |
| 6179 | /* make sure it will be not marked as dirty */ |
| 6180 | mddev->recovery_cp = MaxSector; |
| 6181 | |
| 6182 | return setup_conf(mddev); |
| 6183 | } |
| 6184 | |
| 6185 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6186 | static void *raid5_takeover_raid1(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6187 | { |
| 6188 | int chunksect; |
| 6189 | |
| 6190 | if (mddev->raid_disks != 2 || |
| 6191 | mddev->degraded > 1) |
| 6192 | return ERR_PTR(-EINVAL); |
| 6193 | |
| 6194 | /* Should check if there are write-behind devices? */ |
| 6195 | |
| 6196 | chunksect = 64*2; /* 64K by default */ |
| 6197 | |
| 6198 | /* The array must be an exact multiple of chunksize */ |
| 6199 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 6200 | chunksect >>= 1; |
| 6201 | |
| 6202 | if ((chunksect<<9) < STRIPE_SIZE) |
| 6203 | /* array size does not allow a suitable chunk size */ |
| 6204 | return ERR_PTR(-EINVAL); |
| 6205 | |
| 6206 | mddev->new_level = 5; |
| 6207 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 6208 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6209 | |
| 6210 | return setup_conf(mddev); |
| 6211 | } |
| 6212 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6213 | static void *raid5_takeover_raid6(struct mddev *mddev) |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 6214 | { |
| 6215 | int new_layout; |
| 6216 | |
| 6217 | switch (mddev->layout) { |
| 6218 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 6219 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 6220 | break; |
| 6221 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 6222 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 6223 | break; |
| 6224 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 6225 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 6226 | break; |
| 6227 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 6228 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 6229 | break; |
| 6230 | case ALGORITHM_PARITY_0_6: |
| 6231 | new_layout = ALGORITHM_PARITY_0; |
| 6232 | break; |
| 6233 | case ALGORITHM_PARITY_N: |
| 6234 | new_layout = ALGORITHM_PARITY_N; |
| 6235 | break; |
| 6236 | default: |
| 6237 | return ERR_PTR(-EINVAL); |
| 6238 | } |
| 6239 | mddev->new_level = 5; |
| 6240 | mddev->new_layout = new_layout; |
| 6241 | mddev->delta_disks = -1; |
| 6242 | mddev->raid_disks -= 1; |
| 6243 | return setup_conf(mddev); |
| 6244 | } |
| 6245 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6246 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6247 | static int raid5_check_reshape(struct mddev *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6248 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6249 | /* For a 2-drive array, the layout and chunk size can be changed |
| 6250 | * immediately as not restriping is needed. |
| 6251 | * For larger arrays we record the new value - after validation |
| 6252 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6253 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6254 | struct r5conf *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6255 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6256 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6257 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6258 | return -EINVAL; |
| 6259 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 6260 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6261 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6262 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6263 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6264 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6265 | /* not factor of array size */ |
| 6266 | return -EINVAL; |
| 6267 | } |
| 6268 | |
| 6269 | /* They look valid */ |
| 6270 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6271 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6272 | /* can make the change immediately */ |
| 6273 | if (mddev->new_layout >= 0) { |
| 6274 | conf->algorithm = mddev->new_layout; |
| 6275 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6276 | } |
| 6277 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6278 | conf->chunk_sectors = new_chunk ; |
| 6279 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6280 | } |
| 6281 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 6282 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6283 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6284 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6285 | } |
| 6286 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6287 | static int raid6_check_reshape(struct mddev *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6288 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6289 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6290 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6291 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6292 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6293 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 6294 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6295 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6296 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6297 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6298 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6299 | /* not factor of array size */ |
| 6300 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6301 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6302 | |
| 6303 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6304 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6305 | } |
| 6306 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6307 | static void *raid5_takeover(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6308 | { |
| 6309 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6310 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6311 | * raid1 - if there are two drives. We need to know the chunk size |
| 6312 | * raid4 - trivial - just use a raid4 layout. |
| 6313 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6314 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6315 | if (mddev->level == 0) |
| 6316 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6317 | if (mddev->level == 1) |
| 6318 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 6319 | if (mddev->level == 4) { |
| 6320 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 6321 | mddev->new_level = 5; |
| 6322 | return setup_conf(mddev); |
| 6323 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 6324 | if (mddev->level == 6) |
| 6325 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6326 | |
| 6327 | return ERR_PTR(-EINVAL); |
| 6328 | } |
| 6329 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6330 | static void *raid4_takeover(struct mddev *mddev) |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6331 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6332 | /* raid4 can take over: |
| 6333 | * raid0 - if there is only one strip zone |
| 6334 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6335 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6336 | if (mddev->level == 0) |
| 6337 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6338 | if (mddev->level == 5 && |
| 6339 | mddev->layout == ALGORITHM_PARITY_N) { |
| 6340 | mddev->new_layout = 0; |
| 6341 | mddev->new_level = 4; |
| 6342 | return setup_conf(mddev); |
| 6343 | } |
| 6344 | return ERR_PTR(-EINVAL); |
| 6345 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6346 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6347 | static struct md_personality raid5_personality; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6348 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6349 | static void *raid6_takeover(struct mddev *mddev) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6350 | { |
| 6351 | /* Currently can only take over a raid5. We map the |
| 6352 | * personality to an equivalent raid6 personality |
| 6353 | * with the Q block at the end. |
| 6354 | */ |
| 6355 | int new_layout; |
| 6356 | |
| 6357 | if (mddev->pers != &raid5_personality) |
| 6358 | return ERR_PTR(-EINVAL); |
| 6359 | if (mddev->degraded > 1) |
| 6360 | return ERR_PTR(-EINVAL); |
| 6361 | if (mddev->raid_disks > 253) |
| 6362 | return ERR_PTR(-EINVAL); |
| 6363 | if (mddev->raid_disks < 3) |
| 6364 | return ERR_PTR(-EINVAL); |
| 6365 | |
| 6366 | switch (mddev->layout) { |
| 6367 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 6368 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 6369 | break; |
| 6370 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 6371 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 6372 | break; |
| 6373 | case ALGORITHM_LEFT_SYMMETRIC: |
| 6374 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 6375 | break; |
| 6376 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 6377 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 6378 | break; |
| 6379 | case ALGORITHM_PARITY_0: |
| 6380 | new_layout = ALGORITHM_PARITY_0_6; |
| 6381 | break; |
| 6382 | case ALGORITHM_PARITY_N: |
| 6383 | new_layout = ALGORITHM_PARITY_N; |
| 6384 | break; |
| 6385 | default: |
| 6386 | return ERR_PTR(-EINVAL); |
| 6387 | } |
| 6388 | mddev->new_level = 6; |
| 6389 | mddev->new_layout = new_layout; |
| 6390 | mddev->delta_disks = 1; |
| 6391 | mddev->raid_disks += 1; |
| 6392 | return setup_conf(mddev); |
| 6393 | } |
| 6394 | |
| 6395 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6396 | static struct md_personality raid6_personality = |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6397 | { |
| 6398 | .name = "raid6", |
| 6399 | .level = 6, |
| 6400 | .owner = THIS_MODULE, |
| 6401 | .make_request = make_request, |
| 6402 | .run = run, |
| 6403 | .stop = stop, |
| 6404 | .status = status, |
| 6405 | .error_handler = error, |
| 6406 | .hot_add_disk = raid5_add_disk, |
| 6407 | .hot_remove_disk= raid5_remove_disk, |
| 6408 | .spare_active = raid5_spare_active, |
| 6409 | .sync_request = sync_request, |
| 6410 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6411 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6412 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 6413 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6414 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6415 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6416 | .takeover = raid6_takeover, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6417 | }; |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6418 | static struct md_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6419 | { |
| 6420 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6421 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6422 | .owner = THIS_MODULE, |
| 6423 | .make_request = make_request, |
| 6424 | .run = run, |
| 6425 | .stop = stop, |
| 6426 | .status = status, |
| 6427 | .error_handler = error, |
| 6428 | .hot_add_disk = raid5_add_disk, |
| 6429 | .hot_remove_disk= raid5_remove_disk, |
| 6430 | .spare_active = raid5_spare_active, |
| 6431 | .sync_request = sync_request, |
| 6432 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6433 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6434 | .check_reshape = raid5_check_reshape, |
| 6435 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6436 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6437 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6438 | .takeover = raid5_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6439 | }; |
| 6440 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6441 | static struct md_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6442 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6443 | .name = "raid4", |
| 6444 | .level = 4, |
| 6445 | .owner = THIS_MODULE, |
| 6446 | .make_request = make_request, |
| 6447 | .run = run, |
| 6448 | .stop = stop, |
| 6449 | .status = status, |
| 6450 | .error_handler = error, |
| 6451 | .hot_add_disk = raid5_add_disk, |
| 6452 | .hot_remove_disk= raid5_remove_disk, |
| 6453 | .spare_active = raid5_spare_active, |
| 6454 | .sync_request = sync_request, |
| 6455 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6456 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 6457 | .check_reshape = raid5_check_reshape, |
| 6458 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6459 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6460 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6461 | .takeover = raid4_takeover, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6462 | }; |
| 6463 | |
| 6464 | static int __init raid5_init(void) |
| 6465 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6466 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6467 | register_md_personality(&raid5_personality); |
| 6468 | register_md_personality(&raid4_personality); |
| 6469 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6472 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6473 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6474 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6475 | unregister_md_personality(&raid5_personality); |
| 6476 | unregister_md_personality(&raid4_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | module_init(raid5_init); |
| 6480 | module_exit(raid5_exit); |
| 6481 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 6482 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6483 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 6484 | MODULE_ALIAS("md-raid5"); |
| 6485 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6486 | MODULE_ALIAS("md-level-5"); |
| 6487 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6488 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 6489 | MODULE_ALIAS("md-raid6"); |
| 6490 | MODULE_ALIAS("md-level-6"); |
| 6491 | |
| 6492 | /* This used to be two separate modules, they were: */ |
| 6493 | MODULE_ALIAS("raid5"); |
| 6494 | MODULE_ALIAS("raid6"); |