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> |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 56 | #include <linux/nodemask.h> |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 57 | #include <trace/events/block.h> |
| 58 | |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 59 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 60 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 61 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 62 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 63 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 64 | #define cpu_to_group(cpu) cpu_to_node(cpu) |
| 65 | #define ANY_GROUP NUMA_NO_NODE |
| 66 | |
| 67 | static struct workqueue_struct *raid5_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Stripe cache |
| 70 | */ |
| 71 | |
| 72 | #define NR_STRIPES 256 |
| 73 | #define STRIPE_SIZE PAGE_SIZE |
| 74 | #define STRIPE_SHIFT (PAGE_SHIFT - 9) |
| 75 | #define STRIPE_SECTORS (STRIPE_SIZE>>9) |
| 76 | #define IO_THRESHOLD 1 |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 77 | #define BYPASS_THRESHOLD 1 |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 78 | #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define HASH_MASK (NR_HASH - 1) |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 80 | #define MAX_STRIPE_BATCH 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 82 | static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 83 | { |
| 84 | int hash = (sect >> STRIPE_SHIFT) & HASH_MASK; |
| 85 | return &conf->stripe_hashtbl[hash]; |
| 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | /* bio's attached to a stripe+device for I/O are linked together in bi_sector |
| 89 | * order without overlap. There may be several bio's per stripe+device, and |
| 90 | * a bio could span several devices. |
| 91 | * When walking this list for a particular stripe+device, we must never proceed |
| 92 | * beyond a bio that extends past this device, as the next bio might no longer |
| 93 | * be valid. |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 94 | * 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] | 95 | * of the current stripe+device |
| 96 | */ |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 97 | static inline struct bio *r5_next_bio(struct bio *bio, sector_t sector) |
| 98 | { |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 99 | int sectors = bio_sectors(bio); |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 100 | if (bio->bi_sector + sectors < sector + STRIPE_SECTORS) |
| 101 | return bio->bi_next; |
| 102 | else |
| 103 | return NULL; |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 106 | /* |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 107 | * We maintain a biased count of active stripes in the bottom 16 bits of |
| 108 | * 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] | 109 | */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 110 | static inline int raid5_bi_processed_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_read(segments) >> 16) & 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 int raid5_dec_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 | return atomic_sub_return(1, segments) & 0xffff; |
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_inc_bi_active_stripes(struct bio *bio) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 123 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 124 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 125 | atomic_inc(segments); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 128 | static inline void raid5_set_bi_processed_stripes(struct bio *bio, |
| 129 | unsigned int cnt) |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 130 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 131 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 132 | int old, new; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 133 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 134 | do { |
| 135 | old = atomic_read(segments); |
| 136 | new = (old & 0xffff) | (cnt << 16); |
| 137 | } while (atomic_cmpxchg(segments, old, new) != old); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 140 | 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] | 141 | { |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 142 | atomic_t *segments = (atomic_t *)&bio->bi_phys_segments; |
| 143 | atomic_set(segments, cnt); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 144 | } |
| 145 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 146 | /* Find first data disk in a raid6 stripe */ |
| 147 | static inline int raid6_d0(struct stripe_head *sh) |
| 148 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 149 | if (sh->ddf_layout) |
| 150 | /* ddf always start from first device */ |
| 151 | return 0; |
| 152 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 153 | if (sh->qd_idx == sh->disks - 1) |
| 154 | return 0; |
| 155 | else |
| 156 | return sh->qd_idx + 1; |
| 157 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 158 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 159 | { |
| 160 | disk++; |
| 161 | return (disk < raid_disks) ? disk : 0; |
| 162 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 163 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 164 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 165 | * We need to map each disk to a 'slot', where the data disks are slot |
| 166 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 167 | * is raid_disks-1. This help does that mapping. |
| 168 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 169 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 170 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 171 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 172 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 173 | |
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 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 177 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 178 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 179 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 180 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 181 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 182 | return slot; |
| 183 | } |
| 184 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 185 | static void return_io(struct bio *return_bi) |
| 186 | { |
| 187 | struct bio *bi = return_bi; |
| 188 | while (bi) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 189 | |
| 190 | return_bi = bi->bi_next; |
| 191 | bi->bi_next = NULL; |
| 192 | bi->bi_size = 0; |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 193 | trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), |
| 194 | bi, 0); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 195 | bio_endio(bi, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 196 | bi = return_bi; |
| 197 | } |
| 198 | } |
| 199 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 200 | static void print_raid5_conf (struct r5conf *conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 202 | static int stripe_operations_active(struct stripe_head *sh) |
| 203 | { |
| 204 | return sh->check_state || sh->reconstruct_state || |
| 205 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 206 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 207 | } |
| 208 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 209 | static void raid5_wakeup_stripe_thread(struct stripe_head *sh) |
| 210 | { |
| 211 | struct r5conf *conf = sh->raid_conf; |
| 212 | struct r5worker_group *group; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 213 | int thread_cnt; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 214 | int i, cpu = sh->cpu; |
| 215 | |
| 216 | if (!cpu_online(cpu)) { |
| 217 | cpu = cpumask_any(cpu_online_mask); |
| 218 | sh->cpu = cpu; |
| 219 | } |
| 220 | |
| 221 | if (list_empty(&sh->lru)) { |
| 222 | struct r5worker_group *group; |
| 223 | group = conf->worker_groups + cpu_to_group(cpu); |
| 224 | list_add_tail(&sh->lru, &group->handle_list); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 225 | group->stripes_cnt++; |
| 226 | sh->group = group; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | if (conf->worker_cnt_per_group == 0) { |
| 230 | md_wakeup_thread(conf->mddev->thread); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | group = conf->worker_groups + cpu_to_group(sh->cpu); |
| 235 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 236 | group->workers[0].working = true; |
| 237 | /* at least one worker should run to avoid race */ |
| 238 | queue_work_on(sh->cpu, raid5_wq, &group->workers[0].work); |
| 239 | |
| 240 | thread_cnt = group->stripes_cnt / MAX_STRIPE_BATCH - 1; |
| 241 | /* wakeup more workers */ |
| 242 | for (i = 1; i < conf->worker_cnt_per_group && thread_cnt > 0; i++) { |
| 243 | if (group->workers[i].working == false) { |
| 244 | group->workers[i].working = true; |
| 245 | queue_work_on(sh->cpu, raid5_wq, |
| 246 | &group->workers[i].work); |
| 247 | thread_cnt--; |
| 248 | } |
| 249 | } |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 250 | } |
| 251 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 252 | static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 254 | BUG_ON(!list_empty(&sh->lru)); |
| 255 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
| 256 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
| 257 | if (test_bit(STRIPE_DELAYED, &sh->state) && |
| 258 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 259 | list_add_tail(&sh->lru, &conf->delayed_list); |
| 260 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
| 261 | sh->bm_seq - conf->seq_write > 0) |
| 262 | list_add_tail(&sh->lru, &conf->bitmap_list); |
| 263 | else { |
| 264 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 265 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 266 | if (conf->worker_cnt_per_group == 0) { |
| 267 | list_add_tail(&sh->lru, &conf->handle_list); |
| 268 | } else { |
| 269 | raid5_wakeup_stripe_thread(sh); |
| 270 | return; |
| 271 | } |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 272 | } |
| 273 | md_wakeup_thread(conf->mddev->thread); |
| 274 | } else { |
| 275 | BUG_ON(stripe_operations_active(sh)); |
| 276 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 277 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 278 | < IO_THRESHOLD) |
| 279 | md_wakeup_thread(conf->mddev->thread); |
| 280 | atomic_dec(&conf->active_stripes); |
| 281 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 282 | list_add_tail(&sh->lru, &conf->inactive_list); |
| 283 | wake_up(&conf->wait_for_stripe); |
| 284 | if (conf->retry_read_aligned) |
| 285 | md_wakeup_thread(conf->mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 289 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 290 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh) |
| 291 | { |
| 292 | if (atomic_dec_and_test(&sh->count)) |
| 293 | do_release_stripe(conf, sh); |
| 294 | } |
| 295 | |
Shaohua Li | d265d9d | 2013-08-28 14:29:05 +0800 | [diff] [blame] | 296 | static struct llist_node *llist_reverse_order(struct llist_node *head) |
| 297 | { |
| 298 | struct llist_node *new_head = NULL; |
| 299 | |
| 300 | while (head) { |
| 301 | struct llist_node *tmp = head; |
| 302 | head = head->next; |
| 303 | tmp->next = new_head; |
| 304 | new_head = tmp; |
| 305 | } |
| 306 | |
| 307 | return new_head; |
| 308 | } |
| 309 | |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 310 | /* should hold conf->device_lock already */ |
| 311 | static int release_stripe_list(struct r5conf *conf) |
| 312 | { |
| 313 | struct stripe_head *sh; |
| 314 | int count = 0; |
| 315 | struct llist_node *head; |
| 316 | |
| 317 | head = llist_del_all(&conf->released_stripes); |
Shaohua Li | d265d9d | 2013-08-28 14:29:05 +0800 | [diff] [blame] | 318 | head = llist_reverse_order(head); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 319 | while (head) { |
| 320 | sh = llist_entry(head, struct stripe_head, release_list); |
| 321 | head = llist_next(head); |
| 322 | /* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ |
| 323 | smp_mb(); |
| 324 | clear_bit(STRIPE_ON_RELEASE_LIST, &sh->state); |
| 325 | /* |
| 326 | * Don't worry the bit is set here, because if the bit is set |
| 327 | * again, the count is always > 1. This is true for |
| 328 | * STRIPE_ON_UNPLUG_LIST bit too. |
| 329 | */ |
| 330 | __release_stripe(conf, sh); |
| 331 | count++; |
| 332 | } |
| 333 | |
| 334 | return count; |
| 335 | } |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | static void release_stripe(struct stripe_head *sh) |
| 338 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 339 | struct r5conf *conf = sh->raid_conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | unsigned long flags; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 341 | bool wakeup; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 342 | |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 343 | if (test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state)) |
| 344 | goto slow_path; |
| 345 | wakeup = llist_add(&sh->release_list, &conf->released_stripes); |
| 346 | if (wakeup) |
| 347 | md_wakeup_thread(conf->mddev->thread); |
| 348 | return; |
| 349 | slow_path: |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 350 | local_irq_save(flags); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 351 | /* we are ok here if STRIPE_ON_RELEASE_LIST is set or not */ |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 352 | if (atomic_dec_and_lock(&sh->count, &conf->device_lock)) { |
| 353 | do_release_stripe(conf, sh); |
| 354 | spin_unlock(&conf->device_lock); |
| 355 | } |
| 356 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 359 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 361 | pr_debug("remove_hash(), stripe %llu\n", |
| 362 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 364 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 367 | static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 369 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 371 | pr_debug("insert_hash(), stripe %llu\n", |
| 372 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 374 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | |
| 378 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 379 | static struct stripe_head *get_free_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
| 381 | struct stripe_head *sh = NULL; |
| 382 | struct list_head *first; |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (list_empty(&conf->inactive_list)) |
| 385 | goto out; |
| 386 | first = conf->inactive_list.next; |
| 387 | sh = list_entry(first, struct stripe_head, lru); |
| 388 | list_del_init(first); |
| 389 | remove_hash(sh); |
| 390 | atomic_inc(&conf->active_stripes); |
| 391 | out: |
| 392 | return sh; |
| 393 | } |
| 394 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 395 | static void shrink_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
| 397 | struct page *p; |
| 398 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 399 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 401 | for (i = 0; i < num ; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | p = sh->dev[i].page; |
| 403 | if (!p) |
| 404 | continue; |
| 405 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 406 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 410 | static int grow_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
| 412 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 413 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 415 | for (i = 0; i < num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | struct page *page; |
| 417 | |
| 418 | if (!(page = alloc_page(GFP_KERNEL))) { |
| 419 | return 1; |
| 420 | } |
| 421 | sh->dev[i].page = page; |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 426 | static void raid5_build_block(struct stripe_head *sh, int i, int previous); |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 427 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 428 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 430 | 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] | 431 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 432 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 433 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 435 | BUG_ON(atomic_read(&sh->count) != 0); |
| 436 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 437 | BUG_ON(stripe_operations_active(sh)); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 438 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 439 | pr_debug("init_stripe called, stripe %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | (unsigned long long)sh->sector); |
| 441 | |
| 442 | remove_hash(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 443 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 444 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 445 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 447 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | sh->state = 0; |
| 449 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 450 | |
| 451 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | struct r5dev *dev = &sh->dev[i]; |
| 453 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 454 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | test_bit(R5_LOCKED, &dev->flags)) { |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 456 | 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] | 457 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 458 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | test_bit(R5_LOCKED, &dev->flags)); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 460 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 463 | raid5_build_block(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | insert_hash(conf, sh); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 466 | sh->cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 469 | static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 470 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
| 472 | struct stripe_head *sh; |
| 473 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 474 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 475 | hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 476 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 478 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | return NULL; |
| 480 | } |
| 481 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 482 | /* |
| 483 | * Need to check if array has failed when deciding whether to: |
| 484 | * - start an array |
| 485 | * - remove non-faulty devices |
| 486 | * - add a spare |
| 487 | * - allow a reshape |
| 488 | * This determination is simple when no reshape is happening. |
| 489 | * However if there is a reshape, we need to carefully check |
| 490 | * both the before and after sections. |
| 491 | * This is because some failed devices may only affect one |
| 492 | * of the two sections, and some non-in_sync devices may |
| 493 | * be insync in the section most affected by failed devices. |
| 494 | */ |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 495 | static int calc_degraded(struct r5conf *conf) |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 496 | { |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 497 | int degraded, degraded2; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 498 | int i; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 499 | |
| 500 | rcu_read_lock(); |
| 501 | degraded = 0; |
| 502 | for (i = 0; i < conf->previous_raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 503 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 504 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 505 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 506 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 507 | degraded++; |
| 508 | else if (test_bit(In_sync, &rdev->flags)) |
| 509 | ; |
| 510 | else |
| 511 | /* not in-sync or faulty. |
| 512 | * If the reshape increases the number of devices, |
| 513 | * this is being recovered by the reshape, so |
| 514 | * this 'previous' section is not in_sync. |
| 515 | * If the number of devices is being reduced however, |
| 516 | * the device can only be part of the array if |
| 517 | * we are reverting a reshape, so this section will |
| 518 | * be in-sync. |
| 519 | */ |
| 520 | if (conf->raid_disks >= conf->previous_raid_disks) |
| 521 | degraded++; |
| 522 | } |
| 523 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 524 | if (conf->raid_disks == conf->previous_raid_disks) |
| 525 | return degraded; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 526 | rcu_read_lock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 527 | degraded2 = 0; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 528 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 529 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 530 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 531 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 532 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 533 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 534 | else if (test_bit(In_sync, &rdev->flags)) |
| 535 | ; |
| 536 | else |
| 537 | /* not in-sync or faulty. |
| 538 | * If reshape increases the number of devices, this |
| 539 | * section has already been recovered, else it |
| 540 | * almost certainly hasn't. |
| 541 | */ |
| 542 | if (conf->raid_disks <= conf->previous_raid_disks) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 543 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 544 | } |
| 545 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 546 | if (degraded2 > degraded) |
| 547 | return degraded2; |
| 548 | return degraded; |
| 549 | } |
| 550 | |
| 551 | static int has_failed(struct r5conf *conf) |
| 552 | { |
| 553 | int degraded; |
| 554 | |
| 555 | if (conf->mddev->reshape_position == MaxSector) |
| 556 | return conf->mddev->degraded > conf->max_degraded; |
| 557 | |
| 558 | degraded = calc_degraded(conf); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 559 | if (degraded > conf->max_degraded) |
| 560 | return 1; |
| 561 | return 0; |
| 562 | } |
| 563 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 564 | static struct stripe_head * |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 565 | get_active_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 566 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
| 568 | struct stripe_head *sh; |
| 569 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 570 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | spin_lock_irq(&conf->device_lock); |
| 573 | |
| 574 | do { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 575 | wait_event_lock_irq(conf->wait_for_stripe, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 576 | conf->quiesce == 0 || noquiesce, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 577 | conf->device_lock); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 578 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | if (!sh) { |
| 580 | if (!conf->inactive_blocked) |
| 581 | sh = get_free_stripe(conf); |
| 582 | if (noblock && sh == NULL) |
| 583 | break; |
| 584 | if (!sh) { |
| 585 | conf->inactive_blocked = 1; |
| 586 | wait_event_lock_irq(conf->wait_for_stripe, |
| 587 | !list_empty(&conf->inactive_list) && |
NeilBrown | 5036805 | 2005-12-12 02:39:17 -0800 | [diff] [blame] | 588 | (atomic_read(&conf->active_stripes) |
| 589 | < (conf->max_nr_stripes *3/4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | || !conf->inactive_blocked), |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 591 | conf->device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | conf->inactive_blocked = 0; |
| 593 | } else |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 594 | init_stripe(sh, sector, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } else { |
| 596 | if (atomic_read(&sh->count)) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 597 | BUG_ON(!list_empty(&sh->lru) |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 598 | && !test_bit(STRIPE_EXPANDING, &sh->state) |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 599 | && !test_bit(STRIPE_ON_UNPLUG_LIST, &sh->state) |
| 600 | && !test_bit(STRIPE_ON_RELEASE_LIST, &sh->state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } else { |
| 602 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 603 | atomic_inc(&conf->active_stripes); |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 604 | if (list_empty(&sh->lru) && |
| 605 | !test_bit(STRIPE_EXPANDING, &sh->state)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 606 | BUG(); |
| 607 | list_del_init(&sh->lru); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 608 | if (sh->group) { |
| 609 | sh->group->stripes_cnt--; |
| 610 | sh->group = NULL; |
| 611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | } while (sh == NULL); |
| 615 | |
| 616 | if (sh) |
| 617 | atomic_inc(&sh->count); |
| 618 | |
| 619 | spin_unlock_irq(&conf->device_lock); |
| 620 | return sh; |
| 621 | } |
| 622 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 623 | /* Determine if 'data_offset' or 'new_data_offset' should be used |
| 624 | * in this stripe_head. |
| 625 | */ |
| 626 | static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) |
| 627 | { |
| 628 | sector_t progress = conf->reshape_progress; |
| 629 | /* Need a memory barrier to make sure we see the value |
| 630 | * of conf->generation, or ->data_offset that was set before |
| 631 | * reshape_progress was updated. |
| 632 | */ |
| 633 | smp_rmb(); |
| 634 | if (progress == MaxSector) |
| 635 | return 0; |
| 636 | if (sh->generation == conf->generation - 1) |
| 637 | return 0; |
| 638 | /* We are in a reshape, and this is a new-generation stripe, |
| 639 | * so use new_data_offset. |
| 640 | */ |
| 641 | return 1; |
| 642 | } |
| 643 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 644 | static void |
| 645 | raid5_end_read_request(struct bio *bi, int error); |
| 646 | static void |
| 647 | raid5_end_write_request(struct bio *bi, int error); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 648 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 649 | 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] | 650 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 651 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 652 | int i, disks = sh->disks; |
| 653 | |
| 654 | might_sleep(); |
| 655 | |
| 656 | for (i = disks; i--; ) { |
| 657 | int rw; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 658 | int replace_only = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 659 | struct bio *bi, *rbi; |
| 660 | struct md_rdev *rdev, *rrdev = NULL; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 661 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { |
| 662 | if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) |
| 663 | rw = WRITE_FUA; |
| 664 | else |
| 665 | rw = WRITE; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 666 | if (test_bit(R5_Discard, &sh->dev[i].flags)) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 667 | rw |= REQ_DISCARD; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 668 | } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 669 | rw = READ; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 670 | else if (test_and_clear_bit(R5_WantReplace, |
| 671 | &sh->dev[i].flags)) { |
| 672 | rw = WRITE; |
| 673 | replace_only = 1; |
| 674 | } else |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 675 | continue; |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 676 | if (test_and_clear_bit(R5_SyncIO, &sh->dev[i].flags)) |
| 677 | rw |= REQ_SYNC; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 678 | |
| 679 | bi = &sh->dev[i].req; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 680 | rbi = &sh->dev[i].rreq; /* For writing to replacement */ |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 681 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 682 | rcu_read_lock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 683 | rrdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 684 | smp_mb(); /* Ensure that if rrdev is NULL, rdev won't be */ |
| 685 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 686 | if (!rdev) { |
| 687 | rdev = rrdev; |
| 688 | rrdev = NULL; |
| 689 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 690 | if (rw & WRITE) { |
| 691 | if (replace_only) |
| 692 | rdev = NULL; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 693 | if (rdev == rrdev) |
| 694 | /* We raced and saw duplicates */ |
| 695 | rrdev = NULL; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 696 | } else { |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 697 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags) && rrdev) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 698 | rdev = rrdev; |
| 699 | rrdev = NULL; |
| 700 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 701 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 702 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 703 | rdev = NULL; |
| 704 | if (rdev) |
| 705 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 706 | if (rrdev && test_bit(Faulty, &rrdev->flags)) |
| 707 | rrdev = NULL; |
| 708 | if (rrdev) |
| 709 | atomic_inc(&rrdev->nr_pending); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 710 | rcu_read_unlock(); |
| 711 | |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 712 | /* We have already checked bad blocks for reads. Now |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 713 | * need to check for writes. We never accept write errors |
| 714 | * on the replacement, so we don't to check rrdev. |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 715 | */ |
| 716 | while ((rw & WRITE) && rdev && |
| 717 | test_bit(WriteErrorSeen, &rdev->flags)) { |
| 718 | sector_t first_bad; |
| 719 | int bad_sectors; |
| 720 | int bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 721 | &first_bad, &bad_sectors); |
| 722 | if (!bad) |
| 723 | break; |
| 724 | |
| 725 | if (bad < 0) { |
| 726 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 727 | if (!conf->mddev->external && |
| 728 | conf->mddev->flags) { |
| 729 | /* It is very unlikely, but we might |
| 730 | * still need to write out the |
| 731 | * bad block log - better give it |
| 732 | * a chance*/ |
| 733 | md_check_recovery(conf->mddev); |
| 734 | } |
majianpeng | 1850753 | 2012-07-03 12:11:54 +1000 | [diff] [blame] | 735 | /* |
| 736 | * Because md_wait_for_blocked_rdev |
| 737 | * will dec nr_pending, we must |
| 738 | * increment it first. |
| 739 | */ |
| 740 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 741 | md_wait_for_blocked_rdev(rdev, conf->mddev); |
| 742 | } else { |
| 743 | /* Acknowledged bad block - skip the write */ |
| 744 | rdev_dec_pending(rdev, conf->mddev); |
| 745 | rdev = NULL; |
| 746 | } |
| 747 | } |
| 748 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 749 | if (rdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 750 | if (s->syncing || s->expanding || s->expanded |
| 751 | || s->replacing) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 752 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 753 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 754 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 755 | |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 756 | bio_reset(bi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 757 | bi->bi_bdev = rdev->bdev; |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 758 | bi->bi_rw = rw; |
| 759 | bi->bi_end_io = (rw & WRITE) |
| 760 | ? raid5_end_write_request |
| 761 | : raid5_end_read_request; |
| 762 | bi->bi_private = sh; |
| 763 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 764 | pr_debug("%s: for %llu schedule op %ld on disc %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 765 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 766 | bi->bi_rw, i); |
| 767 | atomic_inc(&sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 768 | if (use_new_offset(conf, sh)) |
| 769 | bi->bi_sector = (sh->sector |
| 770 | + rdev->new_data_offset); |
| 771 | else |
| 772 | bi->bi_sector = (sh->sector |
| 773 | + rdev->data_offset); |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 774 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 775 | bi->bi_rw |= REQ_FLUSH; |
| 776 | |
Kent Overstreet | 4997b72 | 2013-05-30 08:44:39 +0200 | [diff] [blame] | 777 | bi->bi_vcnt = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 778 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 779 | bi->bi_io_vec[0].bv_offset = 0; |
| 780 | bi->bi_size = STRIPE_SIZE; |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame^] | 781 | /* |
| 782 | * If this is discard request, set bi_vcnt 0. We don't |
| 783 | * want to confuse SCSI because SCSI will replace payload |
| 784 | */ |
| 785 | if (rw & REQ_DISCARD) |
| 786 | bi->bi_vcnt = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 787 | if (rrdev) |
| 788 | set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 789 | |
| 790 | if (conf->mddev->gendisk) |
| 791 | trace_block_bio_remap(bdev_get_queue(bi->bi_bdev), |
| 792 | bi, disk_devt(conf->mddev->gendisk), |
| 793 | sh->dev[i].sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 794 | generic_make_request(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 795 | } |
| 796 | if (rrdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 797 | if (s->syncing || s->expanding || s->expanded |
| 798 | || s->replacing) |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 799 | md_sync_acct(rrdev->bdev, STRIPE_SECTORS); |
| 800 | |
| 801 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 802 | |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 803 | bio_reset(rbi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 804 | rbi->bi_bdev = rrdev->bdev; |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 805 | rbi->bi_rw = rw; |
| 806 | BUG_ON(!(rw & WRITE)); |
| 807 | rbi->bi_end_io = raid5_end_write_request; |
| 808 | rbi->bi_private = sh; |
| 809 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 810 | pr_debug("%s: for %llu schedule op %ld on " |
| 811 | "replacement disc %d\n", |
| 812 | __func__, (unsigned long long)sh->sector, |
| 813 | rbi->bi_rw, i); |
| 814 | atomic_inc(&sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 815 | if (use_new_offset(conf, sh)) |
| 816 | rbi->bi_sector = (sh->sector |
| 817 | + rrdev->new_data_offset); |
| 818 | else |
| 819 | rbi->bi_sector = (sh->sector |
| 820 | + rrdev->data_offset); |
Kent Overstreet | 4997b72 | 2013-05-30 08:44:39 +0200 | [diff] [blame] | 821 | rbi->bi_vcnt = 1; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 822 | rbi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 823 | rbi->bi_io_vec[0].bv_offset = 0; |
| 824 | rbi->bi_size = STRIPE_SIZE; |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame^] | 825 | /* |
| 826 | * If this is discard request, set bi_vcnt 0. We don't |
| 827 | * want to confuse SCSI because SCSI will replace payload |
| 828 | */ |
| 829 | if (rw & REQ_DISCARD) |
| 830 | rbi->bi_vcnt = 0; |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 831 | if (conf->mddev->gendisk) |
| 832 | trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev), |
| 833 | rbi, disk_devt(conf->mddev->gendisk), |
| 834 | sh->dev[i].sector); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 835 | generic_make_request(rbi); |
| 836 | } |
| 837 | if (!rdev && !rrdev) { |
Namhyung Kim | b062962 | 2011-06-14 14:20:19 +1000 | [diff] [blame] | 838 | if (rw & WRITE) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 839 | set_bit(STRIPE_DEGRADED, &sh->state); |
| 840 | pr_debug("skip op %ld on disc %d for sector %llu\n", |
| 841 | bi->bi_rw, i, (unsigned long long)sh->sector); |
| 842 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 843 | set_bit(STRIPE_HANDLE, &sh->state); |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | static struct dma_async_tx_descriptor * |
| 849 | async_copy_data(int frombio, struct bio *bio, struct page *page, |
| 850 | sector_t sector, struct dma_async_tx_descriptor *tx) |
| 851 | { |
| 852 | struct bio_vec *bvl; |
| 853 | struct page *bio_page; |
| 854 | int i; |
| 855 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 856 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 857 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 858 | |
| 859 | if (bio->bi_sector >= sector) |
| 860 | page_offset = (signed)(bio->bi_sector - sector) * 512; |
| 861 | else |
| 862 | page_offset = (signed)(sector - bio->bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 863 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 864 | if (frombio) |
| 865 | flags |= ASYNC_TX_FENCE; |
| 866 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 867 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 868 | bio_for_each_segment(bvl, bio, i) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 869 | int len = bvl->bv_len; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 870 | int clen; |
| 871 | int b_offset = 0; |
| 872 | |
| 873 | if (page_offset < 0) { |
| 874 | b_offset = -page_offset; |
| 875 | page_offset += b_offset; |
| 876 | len -= b_offset; |
| 877 | } |
| 878 | |
| 879 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 880 | clen = STRIPE_SIZE - page_offset; |
| 881 | else |
| 882 | clen = len; |
| 883 | |
| 884 | if (clen > 0) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 885 | b_offset += bvl->bv_offset; |
| 886 | bio_page = bvl->bv_page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 887 | if (frombio) |
| 888 | tx = async_memcpy(page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 889 | b_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 890 | else |
| 891 | tx = async_memcpy(bio_page, page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 892 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 893 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 894 | /* chain the operations */ |
| 895 | submit.depend_tx = tx; |
| 896 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 897 | if (clen < len) /* hit end of page */ |
| 898 | break; |
| 899 | page_offset += len; |
| 900 | } |
| 901 | |
| 902 | return tx; |
| 903 | } |
| 904 | |
| 905 | static void ops_complete_biofill(void *stripe_head_ref) |
| 906 | { |
| 907 | struct stripe_head *sh = stripe_head_ref; |
| 908 | struct bio *return_bi = NULL; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 909 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 910 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 911 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 912 | (unsigned long long)sh->sector); |
| 913 | |
| 914 | /* clear completed biofills */ |
| 915 | for (i = sh->disks; i--; ) { |
| 916 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 917 | |
| 918 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 919 | /* and check if we need to reply to a read request, |
| 920 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 921 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 922 | */ |
| 923 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 924 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 925 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 926 | BUG_ON(!dev->read); |
| 927 | rbi = dev->read; |
| 928 | dev->read = NULL; |
| 929 | while (rbi && rbi->bi_sector < |
| 930 | dev->sector + STRIPE_SECTORS) { |
| 931 | rbi2 = r5_next_bio(rbi, dev->sector); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 932 | if (!raid5_dec_bi_active_stripes(rbi)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 933 | rbi->bi_next = return_bi; |
| 934 | return_bi = rbi; |
| 935 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 936 | rbi = rbi2; |
| 937 | } |
| 938 | } |
| 939 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 940 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 941 | |
| 942 | return_io(return_bi); |
| 943 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 944 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 945 | release_stripe(sh); |
| 946 | } |
| 947 | |
| 948 | static void ops_run_biofill(struct stripe_head *sh) |
| 949 | { |
| 950 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 951 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 952 | int i; |
| 953 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 954 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 955 | (unsigned long long)sh->sector); |
| 956 | |
| 957 | for (i = sh->disks; i--; ) { |
| 958 | struct r5dev *dev = &sh->dev[i]; |
| 959 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 960 | struct bio *rbi; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 961 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 962 | dev->read = rbi = dev->toread; |
| 963 | dev->toread = NULL; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 964 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 965 | while (rbi && rbi->bi_sector < |
| 966 | dev->sector + STRIPE_SECTORS) { |
| 967 | tx = async_copy_data(0, rbi, dev->page, |
| 968 | dev->sector, tx); |
| 969 | rbi = r5_next_bio(rbi, dev->sector); |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 975 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 976 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 979 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 980 | { |
| 981 | struct r5dev *tgt; |
| 982 | |
| 983 | if (target < 0) |
| 984 | return; |
| 985 | |
| 986 | tgt = &sh->dev[target]; |
| 987 | set_bit(R5_UPTODATE, &tgt->flags); |
| 988 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 989 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 990 | } |
| 991 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 992 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 993 | { |
| 994 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 995 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 996 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 997 | (unsigned long long)sh->sector); |
| 998 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 999 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1000 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1001 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1002 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1003 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 1004 | if (sh->check_state == check_state_compute_run) |
| 1005 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1006 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1007 | release_stripe(sh); |
| 1008 | } |
| 1009 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1010 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 1011 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 1012 | struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1013 | { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1014 | return percpu->scribble + sizeof(struct page *) * (sh->disks + 2); |
| 1015 | } |
| 1016 | |
| 1017 | static struct dma_async_tx_descriptor * |
| 1018 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1019 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1020 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1021 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1022 | int target = sh->ops.target; |
| 1023 | struct r5dev *tgt = &sh->dev[target]; |
| 1024 | struct page *xor_dest = tgt->page; |
| 1025 | int count = 0; |
| 1026 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1027 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1028 | int i; |
| 1029 | |
| 1030 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1031 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1032 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1033 | |
| 1034 | for (i = disks; i--; ) |
| 1035 | if (i != target) |
| 1036 | xor_srcs[count++] = sh->dev[i].page; |
| 1037 | |
| 1038 | atomic_inc(&sh->count); |
| 1039 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1040 | 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] | 1041 | ops_complete_compute, sh, to_addr_conv(sh, percpu)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1042 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1043 | 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] | 1044 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1045 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1046 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1047 | return tx; |
| 1048 | } |
| 1049 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1050 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 1051 | * @srcs - (struct page *) array of size sh->disks |
| 1052 | * @sh - stripe_head to parse |
| 1053 | * |
| 1054 | * Populates srcs in proper layout order for the stripe and returns the |
| 1055 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 1056 | * destination buffer is recorded in srcs[count] and the Q destination |
| 1057 | * is recorded in srcs[count+1]]. |
| 1058 | */ |
| 1059 | static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh) |
| 1060 | { |
| 1061 | int disks = sh->disks; |
| 1062 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 1063 | int d0_idx = raid6_d0(sh); |
| 1064 | int count; |
| 1065 | int i; |
| 1066 | |
| 1067 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1068 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1069 | |
| 1070 | count = 0; |
| 1071 | i = d0_idx; |
| 1072 | do { |
| 1073 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 1074 | |
| 1075 | srcs[slot] = sh->dev[i].page; |
| 1076 | i = raid6_next_disk(i, disks); |
| 1077 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1078 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1079 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | static struct dma_async_tx_descriptor * |
| 1083 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1084 | { |
| 1085 | int disks = sh->disks; |
| 1086 | struct page **blocks = percpu->scribble; |
| 1087 | int target; |
| 1088 | int qd_idx = sh->qd_idx; |
| 1089 | struct dma_async_tx_descriptor *tx; |
| 1090 | struct async_submit_ctl submit; |
| 1091 | struct r5dev *tgt; |
| 1092 | struct page *dest; |
| 1093 | int i; |
| 1094 | int count; |
| 1095 | |
| 1096 | if (sh->ops.target < 0) |
| 1097 | target = sh->ops.target2; |
| 1098 | else if (sh->ops.target2 < 0) |
| 1099 | target = sh->ops.target; |
| 1100 | else |
| 1101 | /* we should only have one valid target */ |
| 1102 | BUG(); |
| 1103 | BUG_ON(target < 0); |
| 1104 | pr_debug("%s: stripe %llu block: %d\n", |
| 1105 | __func__, (unsigned long long)sh->sector, target); |
| 1106 | |
| 1107 | tgt = &sh->dev[target]; |
| 1108 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1109 | dest = tgt->page; |
| 1110 | |
| 1111 | atomic_inc(&sh->count); |
| 1112 | |
| 1113 | if (target == qd_idx) { |
| 1114 | count = set_syndrome_sources(blocks, sh); |
| 1115 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 1116 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1117 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1118 | ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1119 | to_addr_conv(sh, percpu)); |
| 1120 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 1121 | } else { |
| 1122 | /* Compute any data- or p-drive using XOR */ |
| 1123 | count = 0; |
| 1124 | for (i = disks; i-- ; ) { |
| 1125 | if (i == target || i == qd_idx) |
| 1126 | continue; |
| 1127 | blocks[count++] = sh->dev[i].page; |
| 1128 | } |
| 1129 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1130 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1131 | NULL, ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1132 | to_addr_conv(sh, percpu)); |
| 1133 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 1134 | } |
| 1135 | |
| 1136 | return tx; |
| 1137 | } |
| 1138 | |
| 1139 | static struct dma_async_tx_descriptor * |
| 1140 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1141 | { |
| 1142 | int i, count, disks = sh->disks; |
| 1143 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 1144 | int d0_idx = raid6_d0(sh); |
| 1145 | int faila = -1, failb = -1; |
| 1146 | int target = sh->ops.target; |
| 1147 | int target2 = sh->ops.target2; |
| 1148 | struct r5dev *tgt = &sh->dev[target]; |
| 1149 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 1150 | struct dma_async_tx_descriptor *tx; |
| 1151 | struct page **blocks = percpu->scribble; |
| 1152 | struct async_submit_ctl submit; |
| 1153 | |
| 1154 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 1155 | __func__, (unsigned long long)sh->sector, target, target2); |
| 1156 | BUG_ON(target < 0 || target2 < 0); |
| 1157 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1158 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 1159 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1160 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1161 | * slot number conversion for 'faila' and 'failb' |
| 1162 | */ |
| 1163 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1164 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1165 | count = 0; |
| 1166 | i = d0_idx; |
| 1167 | do { |
| 1168 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 1169 | |
| 1170 | blocks[slot] = sh->dev[i].page; |
| 1171 | |
| 1172 | if (i == target) |
| 1173 | faila = slot; |
| 1174 | if (i == target2) |
| 1175 | failb = slot; |
| 1176 | i = raid6_next_disk(i, disks); |
| 1177 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1178 | |
| 1179 | BUG_ON(faila == failb); |
| 1180 | if (failb < faila) |
| 1181 | swap(faila, failb); |
| 1182 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 1183 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 1184 | |
| 1185 | atomic_inc(&sh->count); |
| 1186 | |
| 1187 | if (failb == syndrome_disks+1) { |
| 1188 | /* Q disk is one of the missing disks */ |
| 1189 | if (faila == syndrome_disks) { |
| 1190 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1191 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1192 | ops_complete_compute, sh, |
| 1193 | to_addr_conv(sh, percpu)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1194 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1195 | STRIPE_SIZE, &submit); |
| 1196 | } else { |
| 1197 | struct page *dest; |
| 1198 | int data_target; |
| 1199 | int qd_idx = sh->qd_idx; |
| 1200 | |
| 1201 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 1202 | if (target == qd_idx) |
| 1203 | data_target = target2; |
| 1204 | else |
| 1205 | data_target = target; |
| 1206 | |
| 1207 | count = 0; |
| 1208 | for (i = disks; i-- ; ) { |
| 1209 | if (i == data_target || i == qd_idx) |
| 1210 | continue; |
| 1211 | blocks[count++] = sh->dev[i].page; |
| 1212 | } |
| 1213 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1214 | init_async_submit(&submit, |
| 1215 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1216 | NULL, NULL, NULL, |
| 1217 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1218 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 1219 | &submit); |
| 1220 | |
| 1221 | count = set_syndrome_sources(blocks, sh); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1222 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 1223 | ops_complete_compute, sh, |
| 1224 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1225 | return async_gen_syndrome(blocks, 0, count+2, |
| 1226 | STRIPE_SIZE, &submit); |
| 1227 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1228 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1229 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1230 | ops_complete_compute, sh, |
| 1231 | to_addr_conv(sh, percpu)); |
| 1232 | if (failb == syndrome_disks) { |
| 1233 | /* We're missing D+P. */ |
| 1234 | return async_raid6_datap_recov(syndrome_disks+2, |
| 1235 | STRIPE_SIZE, faila, |
| 1236 | blocks, &submit); |
| 1237 | } else { |
| 1238 | /* We're missing D+D. */ |
| 1239 | return async_raid6_2data_recov(syndrome_disks+2, |
| 1240 | STRIPE_SIZE, faila, failb, |
| 1241 | blocks, &submit); |
| 1242 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1247 | static void ops_complete_prexor(void *stripe_head_ref) |
| 1248 | { |
| 1249 | struct stripe_head *sh = stripe_head_ref; |
| 1250 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1251 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1252 | (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | static struct dma_async_tx_descriptor * |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1256 | ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1257 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1258 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1259 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1260 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1261 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1262 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1263 | |
| 1264 | /* existing parity data subtracted */ |
| 1265 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1266 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1267 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1268 | (unsigned long long)sh->sector); |
| 1269 | |
| 1270 | for (i = disks; i--; ) { |
| 1271 | struct r5dev *dev = &sh->dev[i]; |
| 1272 | /* Only process blocks that are known to be uptodate */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1273 | if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1274 | xor_srcs[count++] = dev->page; |
| 1275 | } |
| 1276 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1277 | 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] | 1278 | ops_complete_prexor, sh, to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1279 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1280 | |
| 1281 | return tx; |
| 1282 | } |
| 1283 | |
| 1284 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1285 | 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] | 1286 | { |
| 1287 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1288 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1289 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1290 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1291 | (unsigned long long)sh->sector); |
| 1292 | |
| 1293 | for (i = disks; i--; ) { |
| 1294 | struct r5dev *dev = &sh->dev[i]; |
| 1295 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1296 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1297 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1298 | struct bio *wbi; |
| 1299 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1300 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1301 | chosen = dev->towrite; |
| 1302 | dev->towrite = NULL; |
| 1303 | BUG_ON(dev->written); |
| 1304 | wbi = dev->written = chosen; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1305 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1306 | |
| 1307 | while (wbi && wbi->bi_sector < |
| 1308 | dev->sector + STRIPE_SECTORS) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1309 | if (wbi->bi_rw & REQ_FUA) |
| 1310 | set_bit(R5_WantFUA, &dev->flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1311 | if (wbi->bi_rw & REQ_SYNC) |
| 1312 | set_bit(R5_SyncIO, &dev->flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1313 | if (wbi->bi_rw & REQ_DISCARD) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1314 | set_bit(R5_Discard, &dev->flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1315 | else |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1316 | tx = async_copy_data(1, wbi, dev->page, |
| 1317 | dev->sector, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1318 | wbi = r5_next_bio(wbi, dev->sector); |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | return tx; |
| 1324 | } |
| 1325 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1326 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1327 | { |
| 1328 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1329 | int disks = sh->disks; |
| 1330 | int pd_idx = sh->pd_idx; |
| 1331 | int qd_idx = sh->qd_idx; |
| 1332 | int i; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1333 | bool fua = false, sync = false, discard = false; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1334 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1335 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1336 | (unsigned long long)sh->sector); |
| 1337 | |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1338 | for (i = disks; i--; ) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1339 | fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1340 | sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1341 | discard |= test_bit(R5_Discard, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1342 | } |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1343 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1344 | for (i = disks; i--; ) { |
| 1345 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1346 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1347 | if (dev->written || i == pd_idx || i == qd_idx) { |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1348 | if (!discard) |
| 1349 | set_bit(R5_UPTODATE, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1350 | if (fua) |
| 1351 | set_bit(R5_WantFUA, &dev->flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1352 | if (sync) |
| 1353 | set_bit(R5_SyncIO, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1354 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1357 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 1358 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 1359 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 1360 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 1361 | else { |
| 1362 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 1363 | sh->reconstruct_state = reconstruct_state_result; |
| 1364 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1365 | |
| 1366 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1367 | release_stripe(sh); |
| 1368 | } |
| 1369 | |
| 1370 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1371 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1372 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1373 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1374 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1375 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1376 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1377 | int count = 0, pd_idx = sh->pd_idx, i; |
| 1378 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1379 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1380 | unsigned long flags; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1381 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1382 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1383 | (unsigned long long)sh->sector); |
| 1384 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1385 | for (i = 0; i < sh->disks; i++) { |
| 1386 | if (pd_idx == i) |
| 1387 | continue; |
| 1388 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1389 | break; |
| 1390 | } |
| 1391 | if (i >= sh->disks) { |
| 1392 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1393 | set_bit(R5_Discard, &sh->dev[pd_idx].flags); |
| 1394 | ops_complete_reconstruct(sh); |
| 1395 | return; |
| 1396 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1397 | /* check if prexor is active which means only process blocks |
| 1398 | * that are part of a read-modify-write (written) |
| 1399 | */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1400 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1401 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1402 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1403 | for (i = disks; i--; ) { |
| 1404 | struct r5dev *dev = &sh->dev[i]; |
| 1405 | if (dev->written) |
| 1406 | xor_srcs[count++] = dev->page; |
| 1407 | } |
| 1408 | } else { |
| 1409 | xor_dest = sh->dev[pd_idx].page; |
| 1410 | for (i = disks; i--; ) { |
| 1411 | struct r5dev *dev = &sh->dev[i]; |
| 1412 | if (i != pd_idx) |
| 1413 | xor_srcs[count++] = dev->page; |
| 1414 | } |
| 1415 | } |
| 1416 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1417 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1418 | * 2/ if we did not prexor then we are redoing the parity |
| 1419 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1420 | * for the synchronous xor case |
| 1421 | */ |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 1422 | flags = ASYNC_TX_ACK | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1423 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
| 1424 | |
| 1425 | atomic_inc(&sh->count); |
| 1426 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1427 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, sh, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1428 | to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1429 | if (unlikely(count == 1)) |
| 1430 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1431 | else |
| 1432 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1435 | static void |
| 1436 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1437 | struct dma_async_tx_descriptor *tx) |
| 1438 | { |
| 1439 | struct async_submit_ctl submit; |
| 1440 | struct page **blocks = percpu->scribble; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1441 | int count, i; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1442 | |
| 1443 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1444 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1445 | for (i = 0; i < sh->disks; i++) { |
| 1446 | if (sh->pd_idx == i || sh->qd_idx == i) |
| 1447 | continue; |
| 1448 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1449 | break; |
| 1450 | } |
| 1451 | if (i >= sh->disks) { |
| 1452 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1453 | set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 1454 | set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 1455 | ops_complete_reconstruct(sh); |
| 1456 | return; |
| 1457 | } |
| 1458 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1459 | count = set_syndrome_sources(blocks, sh); |
| 1460 | |
| 1461 | atomic_inc(&sh->count); |
| 1462 | |
| 1463 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct, |
| 1464 | sh, to_addr_conv(sh, percpu)); |
| 1465 | async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | static void ops_complete_check(void *stripe_head_ref) |
| 1469 | { |
| 1470 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1471 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1472 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1473 | (unsigned long long)sh->sector); |
| 1474 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1475 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1476 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1477 | release_stripe(sh); |
| 1478 | } |
| 1479 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1480 | 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] | 1481 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1482 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1483 | int pd_idx = sh->pd_idx; |
| 1484 | int qd_idx = sh->qd_idx; |
| 1485 | struct page *xor_dest; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1486 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1487 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1488 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1489 | int count; |
| 1490 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1491 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1492 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1493 | (unsigned long long)sh->sector); |
| 1494 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1495 | count = 0; |
| 1496 | xor_dest = sh->dev[pd_idx].page; |
| 1497 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1498 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1499 | if (i == pd_idx || i == qd_idx) |
| 1500 | continue; |
| 1501 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1504 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
| 1505 | to_addr_conv(sh, percpu)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1506 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1507 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1508 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1509 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1510 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 1511 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1514 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 1515 | { |
| 1516 | struct page **srcs = percpu->scribble; |
| 1517 | struct async_submit_ctl submit; |
| 1518 | int count; |
| 1519 | |
| 1520 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 1521 | (unsigned long long)sh->sector, checkp); |
| 1522 | |
| 1523 | count = set_syndrome_sources(srcs, sh); |
| 1524 | if (!checkp) |
| 1525 | srcs[count] = NULL; |
| 1526 | |
| 1527 | atomic_inc(&sh->count); |
| 1528 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
| 1529 | sh, to_addr_conv(sh, percpu)); |
| 1530 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 1531 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 1532 | } |
| 1533 | |
NeilBrown | 51acbce | 2013-02-28 09:08:34 +1100 | [diff] [blame] | 1534 | 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] | 1535 | { |
| 1536 | int overlap_clear = 0, i, disks = sh->disks; |
| 1537 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1538 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1539 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1540 | struct raid5_percpu *percpu; |
| 1541 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1542 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1543 | cpu = get_cpu(); |
| 1544 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1545 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1546 | ops_run_biofill(sh); |
| 1547 | overlap_clear++; |
| 1548 | } |
| 1549 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1550 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1551 | if (level < 6) |
| 1552 | tx = ops_run_compute5(sh, percpu); |
| 1553 | else { |
| 1554 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 1555 | tx = ops_run_compute6_1(sh, percpu); |
| 1556 | else |
| 1557 | tx = ops_run_compute6_2(sh, percpu); |
| 1558 | } |
| 1559 | /* terminate the chain if reconstruct is not set to be run */ |
| 1560 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1561 | async_tx_ack(tx); |
| 1562 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1563 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1564 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1565 | tx = ops_run_prexor(sh, percpu, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1566 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1567 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1568 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1569 | overlap_clear++; |
| 1570 | } |
| 1571 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1572 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 1573 | if (level < 6) |
| 1574 | ops_run_reconstruct5(sh, percpu, tx); |
| 1575 | else |
| 1576 | ops_run_reconstruct6(sh, percpu, tx); |
| 1577 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1578 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1579 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 1580 | if (sh->check_state == check_state_run) |
| 1581 | ops_run_check_p(sh, percpu); |
| 1582 | else if (sh->check_state == check_state_run_q) |
| 1583 | ops_run_check_pq(sh, percpu, 0); |
| 1584 | else if (sh->check_state == check_state_run_pq) |
| 1585 | ops_run_check_pq(sh, percpu, 1); |
| 1586 | else |
| 1587 | BUG(); |
| 1588 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1589 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1590 | if (overlap_clear) |
| 1591 | for (i = disks; i--; ) { |
| 1592 | struct r5dev *dev = &sh->dev[i]; |
| 1593 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 1594 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 1595 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1596 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1599 | static int grow_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | { |
| 1601 | struct stripe_head *sh; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1602 | sh = kmem_cache_zalloc(conf->slab_cache, GFP_KERNEL); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1603 | if (!sh) |
| 1604 | return 0; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1605 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1606 | sh->raid_conf = conf; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1607 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1608 | spin_lock_init(&sh->stripe_lock); |
| 1609 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1610 | if (grow_buffers(sh)) { |
| 1611 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1612 | kmem_cache_free(conf->slab_cache, sh); |
| 1613 | return 0; |
| 1614 | } |
| 1615 | /* we just created an active stripe so... */ |
| 1616 | atomic_set(&sh->count, 1); |
| 1617 | atomic_inc(&conf->active_stripes); |
| 1618 | INIT_LIST_HEAD(&sh->lru); |
| 1619 | release_stripe(sh); |
| 1620 | return 1; |
| 1621 | } |
| 1622 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1623 | static int grow_stripes(struct r5conf *conf, int num) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1624 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1625 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1626 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 1628 | if (conf->mddev->gendisk) |
| 1629 | sprintf(conf->cache_name[0], |
| 1630 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 1631 | else |
| 1632 | sprintf(conf->cache_name[0], |
| 1633 | "raid%d-%p", conf->level, conf->mddev); |
| 1634 | sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]); |
| 1635 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1636 | conf->active_name = 0; |
| 1637 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1639 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | if (!sc) |
| 1641 | return 1; |
| 1642 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1643 | conf->pool_size = devs; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1644 | while (num--) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1645 | if (!grow_one_stripe(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | return 0; |
| 1648 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 1649 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1650 | /** |
| 1651 | * scribble_len - return the required size of the scribble region |
| 1652 | * @num - total number of disks in the array |
| 1653 | * |
| 1654 | * The size must be enough to contain: |
| 1655 | * 1/ a struct page pointer for each device in the array +2 |
| 1656 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 1657 | * (dma_map_page()) or page (page_address()) address. |
| 1658 | * |
| 1659 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 1660 | * calculate over all devices (not just the data blocks), using zeros in place |
| 1661 | * of the P and Q blocks. |
| 1662 | */ |
| 1663 | static size_t scribble_len(int num) |
| 1664 | { |
| 1665 | size_t len; |
| 1666 | |
| 1667 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
| 1668 | |
| 1669 | return len; |
| 1670 | } |
| 1671 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1672 | static int resize_stripes(struct r5conf *conf, int newsize) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1673 | { |
| 1674 | /* Make all the stripes able to hold 'newsize' devices. |
| 1675 | * New slots in each stripe get 'page' set to a new page. |
| 1676 | * |
| 1677 | * This happens in stages: |
| 1678 | * 1/ create a new kmem_cache and allocate the required number of |
| 1679 | * stripe_heads. |
Masanari Iida | 83f0d77 | 2012-10-30 00:18:08 +0900 | [diff] [blame] | 1680 | * 2/ gather all the old stripe_heads and transfer the pages across |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1681 | * to the new stripe_heads. This will have the side effect of |
| 1682 | * freezing the array as once all stripe_heads have been collected, |
| 1683 | * no IO will be possible. Old stripe heads are freed once their |
| 1684 | * pages have been transferred over, and the old kmem_cache is |
| 1685 | * freed when all stripes are done. |
| 1686 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 1687 | * we simple return a failre status - no need to clean anything up. |
| 1688 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 1689 | * If this fails, we don't bother trying the shrink the |
| 1690 | * stripe_heads down again, we just leave them as they are. |
| 1691 | * As each stripe_head is processed the new one is released into |
| 1692 | * active service. |
| 1693 | * |
| 1694 | * Once step2 is started, we cannot afford to wait for a write, |
| 1695 | * so we use GFP_NOIO allocations. |
| 1696 | */ |
| 1697 | struct stripe_head *osh, *nsh; |
| 1698 | LIST_HEAD(newstripes); |
| 1699 | struct disk_info *ndisks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1700 | unsigned long cpu; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1701 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1702 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1703 | int i; |
| 1704 | |
| 1705 | if (newsize <= conf->pool_size) |
| 1706 | return 0; /* never bother to shrink */ |
| 1707 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1708 | err = md_allow_write(conf->mddev); |
| 1709 | if (err) |
| 1710 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 1711 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1712 | /* Step 1 */ |
| 1713 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 1714 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1715 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1716 | if (!sc) |
| 1717 | return -ENOMEM; |
| 1718 | |
| 1719 | for (i = conf->max_nr_stripes; i; i--) { |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1720 | nsh = kmem_cache_zalloc(sc, GFP_KERNEL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1721 | if (!nsh) |
| 1722 | break; |
| 1723 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1724 | nsh->raid_conf = conf; |
NeilBrown | cb13ff6 | 2012-09-24 16:27:20 +1000 | [diff] [blame] | 1725 | spin_lock_init(&nsh->stripe_lock); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1726 | |
| 1727 | list_add(&nsh->lru, &newstripes); |
| 1728 | } |
| 1729 | if (i) { |
| 1730 | /* didn't get enough, give up */ |
| 1731 | while (!list_empty(&newstripes)) { |
| 1732 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1733 | list_del(&nsh->lru); |
| 1734 | kmem_cache_free(sc, nsh); |
| 1735 | } |
| 1736 | kmem_cache_destroy(sc); |
| 1737 | return -ENOMEM; |
| 1738 | } |
| 1739 | /* Step 2 - Must use GFP_NOIO now. |
| 1740 | * OK, we have enough stripes, start collecting inactive |
| 1741 | * stripes and copying them over |
| 1742 | */ |
| 1743 | list_for_each_entry(nsh, &newstripes, lru) { |
| 1744 | spin_lock_irq(&conf->device_lock); |
| 1745 | wait_event_lock_irq(conf->wait_for_stripe, |
| 1746 | !list_empty(&conf->inactive_list), |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 1747 | conf->device_lock); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1748 | osh = get_free_stripe(conf); |
| 1749 | spin_unlock_irq(&conf->device_lock); |
| 1750 | atomic_set(&nsh->count, 1); |
| 1751 | for(i=0; i<conf->pool_size; i++) |
| 1752 | nsh->dev[i].page = osh->dev[i].page; |
| 1753 | for( ; i<newsize; i++) |
| 1754 | nsh->dev[i].page = NULL; |
| 1755 | kmem_cache_free(conf->slab_cache, osh); |
| 1756 | } |
| 1757 | kmem_cache_destroy(conf->slab_cache); |
| 1758 | |
| 1759 | /* Step 3. |
| 1760 | * At this point, we are holding all the stripes so the array |
| 1761 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1762 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1763 | */ |
| 1764 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 1765 | if (ndisks) { |
| 1766 | for (i=0; i<conf->raid_disks; i++) |
| 1767 | ndisks[i] = conf->disks[i]; |
| 1768 | kfree(conf->disks); |
| 1769 | conf->disks = ndisks; |
| 1770 | } else |
| 1771 | err = -ENOMEM; |
| 1772 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1773 | get_online_cpus(); |
| 1774 | conf->scribble_len = scribble_len(newsize); |
| 1775 | for_each_present_cpu(cpu) { |
| 1776 | struct raid5_percpu *percpu; |
| 1777 | void *scribble; |
| 1778 | |
| 1779 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 1780 | scribble = kmalloc(conf->scribble_len, GFP_NOIO); |
| 1781 | |
| 1782 | if (scribble) { |
| 1783 | kfree(percpu->scribble); |
| 1784 | percpu->scribble = scribble; |
| 1785 | } else { |
| 1786 | err = -ENOMEM; |
| 1787 | break; |
| 1788 | } |
| 1789 | } |
| 1790 | put_online_cpus(); |
| 1791 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1792 | /* Step 4, return new stripes to service */ |
| 1793 | while(!list_empty(&newstripes)) { |
| 1794 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1795 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1796 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1797 | for (i=conf->raid_disks; i < newsize; i++) |
| 1798 | if (nsh->dev[i].page == NULL) { |
| 1799 | struct page *p = alloc_page(GFP_NOIO); |
| 1800 | nsh->dev[i].page = p; |
| 1801 | if (!p) |
| 1802 | err = -ENOMEM; |
| 1803 | } |
| 1804 | release_stripe(nsh); |
| 1805 | } |
| 1806 | /* critical section pass, GFP_NOIO no longer needed */ |
| 1807 | |
| 1808 | conf->slab_cache = sc; |
| 1809 | conf->active_name = 1-conf->active_name; |
| 1810 | conf->pool_size = newsize; |
| 1811 | return err; |
| 1812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1814 | static int drop_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | { |
| 1816 | struct stripe_head *sh; |
| 1817 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1818 | spin_lock_irq(&conf->device_lock); |
| 1819 | sh = get_free_stripe(conf); |
| 1820 | spin_unlock_irq(&conf->device_lock); |
| 1821 | if (!sh) |
| 1822 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 1823 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1824 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1825 | kmem_cache_free(conf->slab_cache, sh); |
| 1826 | atomic_dec(&conf->active_stripes); |
| 1827 | return 1; |
| 1828 | } |
| 1829 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1830 | static void shrink_stripes(struct r5conf *conf) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1831 | { |
| 1832 | while (drop_one_stripe(conf)) |
| 1833 | ; |
| 1834 | |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1835 | if (conf->slab_cache) |
| 1836 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | conf->slab_cache = NULL; |
| 1838 | } |
| 1839 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1840 | static void raid5_end_read_request(struct bio * bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1842 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1843 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1844 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1846 | char b[BDEVNAME_SIZE]; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1847 | struct md_rdev *rdev = NULL; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1848 | sector_t s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
| 1850 | for (i=0 ; i<disks; i++) |
| 1851 | if (bi == &sh->dev[i].req) |
| 1852 | break; |
| 1853 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1854 | pr_debug("end_read_request %llu/%d, count: %d, uptodate %d.\n", |
| 1855 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | uptodate); |
| 1857 | if (i == disks) { |
| 1858 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1859 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1861 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1862 | /* If replacement finished while this request was outstanding, |
| 1863 | * 'replacement' might be NULL already. |
| 1864 | * In that case it moved down to 'rdev'. |
| 1865 | * rdev is not removed until all requests are finished. |
| 1866 | */ |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1867 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1868 | if (!rdev) |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1869 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1871 | if (use_new_offset(conf, sh)) |
| 1872 | s = sh->sector + rdev->new_data_offset; |
| 1873 | else |
| 1874 | s = sh->sector + rdev->data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1877 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1878 | /* Note that this cannot happen on a |
| 1879 | * replacement device. We just fail those on |
| 1880 | * any error |
| 1881 | */ |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1882 | printk_ratelimited( |
| 1883 | KERN_INFO |
| 1884 | "md/raid:%s: read error corrected" |
| 1885 | " (%lu sectors at %llu on %s)\n", |
| 1886 | mdname(conf->mddev), STRIPE_SECTORS, |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1887 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1888 | bdevname(rdev->bdev, b)); |
Namhyung Kim | ddd5115 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1889 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1890 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1891 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 1892 | } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 1893 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 1894 | |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1895 | if (atomic_read(&rdev->read_errors)) |
| 1896 | atomic_set(&rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | } else { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1898 | const char *bdn = bdevname(rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1899 | int retry = 0; |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1900 | int set_bad = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1903 | atomic_inc(&rdev->read_errors); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1904 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
| 1905 | printk_ratelimited( |
| 1906 | KERN_WARNING |
| 1907 | "md/raid:%s: read error on replacement device " |
| 1908 | "(sector %llu on %s).\n", |
| 1909 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1910 | (unsigned long long)s, |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1911 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1912 | else if (conf->mddev->degraded >= conf->max_degraded) { |
| 1913 | set_bad = 1; |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1914 | printk_ratelimited( |
| 1915 | KERN_WARNING |
| 1916 | "md/raid:%s: read error not correctable " |
| 1917 | "(sector %llu on %s).\n", |
| 1918 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1919 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1920 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1921 | } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1922 | /* Oh, no!!! */ |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1923 | set_bad = 1; |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1924 | printk_ratelimited( |
| 1925 | KERN_WARNING |
| 1926 | "md/raid:%s: read error NOT corrected!! " |
| 1927 | "(sector %llu on %s).\n", |
| 1928 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1929 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1930 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1931 | } else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1932 | > conf->max_nr_stripes) |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1933 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1934 | "md/raid:%s: Too many read errors, failing device %s.\n", |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1935 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1936 | else |
| 1937 | retry = 1; |
| 1938 | if (retry) |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 1939 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { |
| 1940 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 1941 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 1942 | } else |
| 1943 | set_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1944 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1945 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1946 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 1947 | if (!(set_bad |
| 1948 | && test_bit(In_sync, &rdev->flags) |
| 1949 | && rdev_set_badblocks( |
| 1950 | rdev, sh->sector, STRIPE_SECTORS, 0))) |
| 1951 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1952 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1954 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1956 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1957 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1960 | static void raid5_end_write_request(struct bio *bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1962 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1963 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1964 | int disks = sh->disks, i; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1965 | struct md_rdev *uninitialized_var(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1967 | sector_t first_bad; |
| 1968 | int bad_sectors; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1969 | int replacement = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1971 | for (i = 0 ; i < disks; i++) { |
| 1972 | if (bi == &sh->dev[i].req) { |
| 1973 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | break; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1975 | } |
| 1976 | if (bi == &sh->dev[i].rreq) { |
| 1977 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1978 | if (rdev) |
| 1979 | replacement = 1; |
| 1980 | else |
| 1981 | /* rdev was removed and 'replacement' |
| 1982 | * replaced it. rdev is not removed |
| 1983 | * until all requests are finished. |
| 1984 | */ |
| 1985 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1986 | break; |
| 1987 | } |
| 1988 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1989 | pr_debug("end_write_request %llu/%d, count %d, uptodate: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
| 1991 | uptodate); |
| 1992 | if (i == disks) { |
| 1993 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1994 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1997 | if (replacement) { |
| 1998 | if (!uptodate) |
| 1999 | md_error(conf->mddev, rdev); |
| 2000 | else if (is_badblock(rdev, sh->sector, |
| 2001 | STRIPE_SECTORS, |
| 2002 | &first_bad, &bad_sectors)) |
| 2003 | set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); |
| 2004 | } else { |
| 2005 | if (!uptodate) { |
| 2006 | set_bit(WriteErrorSeen, &rdev->flags); |
| 2007 | set_bit(R5_WriteError, &sh->dev[i].flags); |
NeilBrown | 3a6de29 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2008 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) |
| 2009 | set_bit(MD_RECOVERY_NEEDED, |
| 2010 | &rdev->mddev->recovery); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2011 | } else if (is_badblock(rdev, sh->sector, |
| 2012 | STRIPE_SECTORS, |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 2013 | &first_bad, &bad_sectors)) { |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2014 | set_bit(R5_MadeGood, &sh->dev[i].flags); |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 2015 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) |
| 2016 | /* That was a successful write so make |
| 2017 | * sure it looks like we already did |
| 2018 | * a re-write. |
| 2019 | */ |
| 2020 | set_bit(R5_ReWrite, &sh->dev[i].flags); |
| 2021 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2022 | } |
| 2023 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2025 | if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) |
| 2026 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 2028 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2031 | 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] | 2032 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2033 | 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] | 2034 | { |
| 2035 | struct r5dev *dev = &sh->dev[i]; |
| 2036 | |
| 2037 | bio_init(&dev->req); |
| 2038 | dev->req.bi_io_vec = &dev->vec; |
| 2039 | dev->req.bi_vcnt++; |
| 2040 | dev->req.bi_max_vecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | dev->req.bi_private = sh; |
NeilBrown | 995c427 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2042 | dev->vec.bv_page = dev->page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2044 | bio_init(&dev->rreq); |
| 2045 | dev->rreq.bi_io_vec = &dev->rvec; |
| 2046 | dev->rreq.bi_vcnt++; |
| 2047 | dev->rreq.bi_max_vecs++; |
| 2048 | dev->rreq.bi_private = sh; |
| 2049 | dev->rvec.bv_page = dev->page; |
| 2050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2052 | dev->sector = compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 2055 | static void error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | { |
| 2057 | char b[BDEVNAME_SIZE]; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2058 | struct r5conf *conf = mddev->private; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2059 | unsigned long flags; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2060 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2062 | spin_lock_irqsave(&conf->device_lock, flags); |
| 2063 | clear_bit(In_sync, &rdev->flags); |
| 2064 | mddev->degraded = calc_degraded(conf); |
| 2065 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 2066 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 2067 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 2068 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 2069 | set_bit(Faulty, &rdev->flags); |
| 2070 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 2071 | printk(KERN_ALERT |
| 2072 | "md/raid:%s: Disk failure on %s, disabling device.\n" |
| 2073 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 2074 | mdname(mddev), |
| 2075 | bdevname(rdev->bdev, b), |
| 2076 | mdname(mddev), |
| 2077 | conf->raid_disks - mddev->degraded); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2078 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | |
| 2080 | /* |
| 2081 | * Input: a 'big' sector number, |
| 2082 | * Output: index of the data and parity disk, and the sector # in them. |
| 2083 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2084 | static sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2085 | int previous, int *dd_idx, |
| 2086 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | { |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2088 | sector_t stripe, stripe2; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2089 | sector_t chunk_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2091 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2092 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2094 | int algorithm = previous ? conf->prev_algo |
| 2095 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2096 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2097 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2098 | int raid_disks = previous ? conf->previous_raid_disks |
| 2099 | : conf->raid_disks; |
| 2100 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | |
| 2102 | /* First compute the information on this sector */ |
| 2103 | |
| 2104 | /* |
| 2105 | * Compute the chunk number and the sector offset inside the chunk |
| 2106 | */ |
| 2107 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 2108 | chunk_number = r_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | |
| 2110 | /* |
| 2111 | * Compute the stripe number |
| 2112 | */ |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2113 | stripe = chunk_number; |
| 2114 | *dd_idx = sector_div(stripe, data_disks); |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2115 | stripe2 = stripe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | /* |
| 2117 | * Select the parity disk based on the user selected algorithm. |
| 2118 | */ |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2119 | pd_idx = qd_idx = -1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2120 | switch(conf->level) { |
| 2121 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2122 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2123 | break; |
| 2124 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2125 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2127 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2128 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | (*dd_idx)++; |
| 2130 | break; |
| 2131 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2132 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2133 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | (*dd_idx)++; |
| 2135 | break; |
| 2136 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2137 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2138 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | break; |
| 2140 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2141 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2142 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2144 | case ALGORITHM_PARITY_0: |
| 2145 | pd_idx = 0; |
| 2146 | (*dd_idx)++; |
| 2147 | break; |
| 2148 | case ALGORITHM_PARITY_N: |
| 2149 | pd_idx = data_disks; |
| 2150 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2152 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2153 | } |
| 2154 | break; |
| 2155 | case 6: |
| 2156 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2157 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2158 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2159 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2160 | qd_idx = pd_idx + 1; |
| 2161 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2162 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2163 | qd_idx = 0; |
| 2164 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2165 | (*dd_idx) += 2; /* D D P Q D */ |
| 2166 | break; |
| 2167 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2168 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2169 | qd_idx = pd_idx + 1; |
| 2170 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2171 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2172 | qd_idx = 0; |
| 2173 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2174 | (*dd_idx) += 2; /* D D P Q D */ |
| 2175 | break; |
| 2176 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2177 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2178 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2179 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2180 | break; |
| 2181 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2182 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2183 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2184 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2185 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2186 | |
| 2187 | case ALGORITHM_PARITY_0: |
| 2188 | pd_idx = 0; |
| 2189 | qd_idx = 1; |
| 2190 | (*dd_idx) += 2; |
| 2191 | break; |
| 2192 | case ALGORITHM_PARITY_N: |
| 2193 | pd_idx = data_disks; |
| 2194 | qd_idx = data_disks + 1; |
| 2195 | break; |
| 2196 | |
| 2197 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2198 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 2199 | * of blocks for computing Q is different. |
| 2200 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2201 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2202 | qd_idx = pd_idx + 1; |
| 2203 | if (pd_idx == raid_disks-1) { |
| 2204 | (*dd_idx)++; /* Q D D D P */ |
| 2205 | qd_idx = 0; |
| 2206 | } else if (*dd_idx >= pd_idx) |
| 2207 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2208 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2209 | break; |
| 2210 | |
| 2211 | case ALGORITHM_ROTATING_N_RESTART: |
| 2212 | /* Same a left_asymmetric, by first stripe is |
| 2213 | * D D D P Q rather than |
| 2214 | * Q D D D P |
| 2215 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2216 | stripe2 += 1; |
| 2217 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2218 | qd_idx = pd_idx + 1; |
| 2219 | if (pd_idx == raid_disks-1) { |
| 2220 | (*dd_idx)++; /* Q D D D P */ |
| 2221 | qd_idx = 0; |
| 2222 | } else if (*dd_idx >= pd_idx) |
| 2223 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2224 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2225 | break; |
| 2226 | |
| 2227 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 2228 | /* Same as left_symmetric but Q is before P */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2229 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2230 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 2231 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2232 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2233 | break; |
| 2234 | |
| 2235 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2236 | /* RAID5 left_asymmetric, with Q on last device */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2237 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2238 | if (*dd_idx >= pd_idx) |
| 2239 | (*dd_idx)++; |
| 2240 | qd_idx = raid_disks - 1; |
| 2241 | break; |
| 2242 | |
| 2243 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2244 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2245 | if (*dd_idx >= pd_idx) |
| 2246 | (*dd_idx)++; |
| 2247 | qd_idx = raid_disks - 1; |
| 2248 | break; |
| 2249 | |
| 2250 | case ALGORITHM_LEFT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2251 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2252 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2253 | qd_idx = raid_disks - 1; |
| 2254 | break; |
| 2255 | |
| 2256 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2257 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2258 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2259 | qd_idx = raid_disks - 1; |
| 2260 | break; |
| 2261 | |
| 2262 | case ALGORITHM_PARITY_0_6: |
| 2263 | pd_idx = 0; |
| 2264 | (*dd_idx)++; |
| 2265 | qd_idx = raid_disks - 1; |
| 2266 | break; |
| 2267 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2268 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2269 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2270 | } |
| 2271 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2274 | if (sh) { |
| 2275 | sh->pd_idx = pd_idx; |
| 2276 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2277 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | /* |
| 2280 | * Finally, compute the new sector number |
| 2281 | */ |
| 2282 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 2283 | return new_sector; |
| 2284 | } |
| 2285 | |
| 2286 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2287 | 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] | 2288 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2289 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2290 | int raid_disks = sh->disks; |
| 2291 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2293 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2294 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2295 | int algorithm = previous ? conf->prev_algo |
| 2296 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | sector_t stripe; |
| 2298 | int chunk_offset; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2299 | sector_t chunk_number; |
| 2300 | int dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2302 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 2306 | stripe = new_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2308 | if (i == sh->pd_idx) |
| 2309 | return 0; |
| 2310 | switch(conf->level) { |
| 2311 | case 4: break; |
| 2312 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2313 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2315 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 2316 | if (i > sh->pd_idx) |
| 2317 | i--; |
| 2318 | break; |
| 2319 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2320 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2321 | if (i < sh->pd_idx) |
| 2322 | i += raid_disks; |
| 2323 | i -= (sh->pd_idx + 1); |
| 2324 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2325 | case ALGORITHM_PARITY_0: |
| 2326 | i -= 1; |
| 2327 | break; |
| 2328 | case ALGORITHM_PARITY_N: |
| 2329 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2331 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2332 | } |
| 2333 | break; |
| 2334 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2335 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2336 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2337 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2338 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2339 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2340 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2341 | case ALGORITHM_ROTATING_N_RESTART: |
| 2342 | if (sh->pd_idx == raid_disks-1) |
| 2343 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2344 | else if (i > sh->pd_idx) |
| 2345 | i -= 2; /* D D P Q D */ |
| 2346 | break; |
| 2347 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2348 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2349 | if (sh->pd_idx == raid_disks-1) |
| 2350 | i--; /* Q D D D P */ |
| 2351 | else { |
| 2352 | /* D D P Q D */ |
| 2353 | if (i < sh->pd_idx) |
| 2354 | i += raid_disks; |
| 2355 | i -= (sh->pd_idx + 2); |
| 2356 | } |
| 2357 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2358 | case ALGORITHM_PARITY_0: |
| 2359 | i -= 2; |
| 2360 | break; |
| 2361 | case ALGORITHM_PARITY_N: |
| 2362 | break; |
| 2363 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2364 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2365 | if (sh->pd_idx == 0) |
| 2366 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2367 | else { |
| 2368 | /* D D Q P D */ |
| 2369 | if (i < sh->pd_idx) |
| 2370 | i += raid_disks; |
| 2371 | i -= (sh->pd_idx + 1); |
| 2372 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2373 | break; |
| 2374 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2375 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 2376 | if (i > sh->pd_idx) |
| 2377 | i--; |
| 2378 | break; |
| 2379 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 2380 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 2381 | if (i < sh->pd_idx) |
| 2382 | i += data_disks + 1; |
| 2383 | i -= (sh->pd_idx + 1); |
| 2384 | break; |
| 2385 | case ALGORITHM_PARITY_0_6: |
| 2386 | i -= 1; |
| 2387 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2388 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2389 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2390 | } |
| 2391 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | chunk_number = stripe * data_disks + i; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2395 | r_sector = chunk_number * sectors_per_chunk + chunk_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2397 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2398 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2399 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 2400 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2401 | printk(KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n", |
| 2402 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | return 0; |
| 2404 | } |
| 2405 | return r_sector; |
| 2406 | } |
| 2407 | |
| 2408 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2409 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2410 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2411 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2412 | { |
| 2413 | int i, pd_idx = sh->pd_idx, disks = sh->disks; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2414 | struct r5conf *conf = sh->raid_conf; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2415 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2416 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2417 | if (rcw) { |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2418 | |
| 2419 | for (i = disks; i--; ) { |
| 2420 | struct r5dev *dev = &sh->dev[i]; |
| 2421 | |
| 2422 | if (dev->towrite) { |
| 2423 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2424 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2425 | if (!expand) |
| 2426 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2427 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2428 | } |
| 2429 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 2430 | /* if we are not expanding this is a proper write request, and |
| 2431 | * there will be bios with new data to be drained into the |
| 2432 | * stripe cache |
| 2433 | */ |
| 2434 | if (!expand) { |
| 2435 | if (!s->locked) |
| 2436 | /* False alarm, nothing to do */ |
| 2437 | return; |
| 2438 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 2439 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2440 | } else |
| 2441 | sh->reconstruct_state = reconstruct_state_run; |
| 2442 | |
| 2443 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
| 2444 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2445 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2446 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2447 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2448 | } else { |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2449 | BUG_ON(level == 6); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2450 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 2451 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
| 2452 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2453 | for (i = disks; i--; ) { |
| 2454 | struct r5dev *dev = &sh->dev[i]; |
| 2455 | if (i == pd_idx) |
| 2456 | continue; |
| 2457 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2458 | if (dev->towrite && |
| 2459 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2460 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2461 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2462 | set_bit(R5_LOCKED, &dev->flags); |
| 2463 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2464 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2465 | } |
| 2466 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 2467 | if (!s->locked) |
| 2468 | /* False alarm - nothing to do */ |
| 2469 | return; |
| 2470 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
| 2471 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 2472 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2473 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2476 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2477 | * are in flight |
| 2478 | */ |
| 2479 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 2480 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2481 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2482 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2483 | if (level == 6) { |
| 2484 | int qd_idx = sh->qd_idx; |
| 2485 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 2486 | |
| 2487 | set_bit(R5_LOCKED, &dev->flags); |
| 2488 | clear_bit(R5_UPTODATE, &dev->flags); |
| 2489 | s->locked++; |
| 2490 | } |
| 2491 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2492 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2493 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2494 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2495 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | /* |
| 2498 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2499 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | * The bi_next chain must be in order. |
| 2501 | */ |
| 2502 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) |
| 2503 | { |
| 2504 | struct bio **bip; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2505 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2506 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2508 | pr_debug("adding bi b#%llu to stripe s#%llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | (unsigned long long)bi->bi_sector, |
| 2510 | (unsigned long long)sh->sector); |
| 2511 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2512 | /* |
| 2513 | * If several bio share a stripe. The bio bi_phys_segments acts as a |
| 2514 | * reference count to avoid race. The reference count should already be |
| 2515 | * increased before this function is called (for example, in |
| 2516 | * make_request()), so other bio sharing this stripe will not free the |
| 2517 | * stripe. If a stripe is owned by one stripe, the stripe lock will |
| 2518 | * protect it. |
| 2519 | */ |
| 2520 | spin_lock_irq(&sh->stripe_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2521 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | bip = &sh->dev[dd_idx].towrite; |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2523 | if (*bip == NULL) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2524 | firstwrite = 1; |
| 2525 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | bip = &sh->dev[dd_idx].toread; |
| 2527 | while (*bip && (*bip)->bi_sector < bi->bi_sector) { |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 2528 | if (bio_end_sector(*bip) > bi->bi_sector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | goto overlap; |
| 2530 | bip = & (*bip)->bi_next; |
| 2531 | } |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 2532 | if (*bip && (*bip)->bi_sector < bio_end_sector(bi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | goto overlap; |
| 2534 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2535 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | if (*bip) |
| 2537 | bi->bi_next = *bip; |
| 2538 | *bip = bi; |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2539 | raid5_inc_bi_active_stripes(bi); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | if (forwrite) { |
| 2542 | /* check if page is covered */ |
| 2543 | sector_t sector = sh->dev[dd_idx].sector; |
| 2544 | for (bi=sh->dev[dd_idx].towrite; |
| 2545 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
| 2546 | bi && bi->bi_sector <= sector; |
| 2547 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 2548 | if (bio_end_sector(bi) >= sector) |
| 2549 | sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | } |
| 2551 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
| 2552 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
| 2553 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2554 | |
| 2555 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
| 2556 | (unsigned long long)(*bip)->bi_sector, |
| 2557 | (unsigned long long)sh->sector, dd_idx); |
NeilBrown | b97390a | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2558 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2559 | |
| 2560 | if (conf->mddev->bitmap && firstwrite) { |
| 2561 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 2562 | STRIPE_SECTORS, 0); |
| 2563 | sh->bm_seq = conf->seq_flush+1; |
| 2564 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 2565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | return 1; |
| 2567 | |
| 2568 | overlap: |
| 2569 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2570 | spin_unlock_irq(&sh->stripe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | return 0; |
| 2572 | } |
| 2573 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2574 | static void end_reshape(struct r5conf *conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2575 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2576 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2577 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2578 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2579 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2580 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2581 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2582 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2583 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2584 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2585 | raid5_compute_sector(conf, |
| 2586 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2587 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2588 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2589 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2590 | } |
| 2591 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2592 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2593 | handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2594 | struct stripe_head_state *s, int disks, |
| 2595 | struct bio **return_bi) |
| 2596 | { |
| 2597 | int i; |
| 2598 | for (i = disks; i--; ) { |
| 2599 | struct bio *bi; |
| 2600 | int bitmap_end = 0; |
| 2601 | |
| 2602 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2603 | struct md_rdev *rdev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2604 | rcu_read_lock(); |
| 2605 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 2606 | if (rdev && test_bit(In_sync, &rdev->flags)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2607 | atomic_inc(&rdev->nr_pending); |
| 2608 | else |
| 2609 | rdev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2610 | rcu_read_unlock(); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2611 | if (rdev) { |
| 2612 | if (!rdev_set_badblocks( |
| 2613 | rdev, |
| 2614 | sh->sector, |
| 2615 | STRIPE_SECTORS, 0)) |
| 2616 | md_error(conf->mddev, rdev); |
| 2617 | rdev_dec_pending(rdev, conf->mddev); |
| 2618 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2619 | } |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2620 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2621 | /* fail all writes first */ |
| 2622 | bi = sh->dev[i].towrite; |
| 2623 | sh->dev[i].towrite = NULL; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2624 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | 1ed850f | 2012-10-11 13:50:13 +1100 | [diff] [blame] | 2625 | if (bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2626 | bitmap_end = 1; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2627 | |
| 2628 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2629 | wake_up(&conf->wait_for_overlap); |
| 2630 | |
| 2631 | while (bi && bi->bi_sector < |
| 2632 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2633 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
| 2634 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2635 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2636 | md_write_end(conf->mddev); |
| 2637 | bi->bi_next = *return_bi; |
| 2638 | *return_bi = bi; |
| 2639 | } |
| 2640 | bi = nextbi; |
| 2641 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2642 | if (bitmap_end) |
| 2643 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2644 | STRIPE_SECTORS, 0, 0); |
| 2645 | bitmap_end = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2646 | /* and fail all 'written' */ |
| 2647 | bi = sh->dev[i].written; |
| 2648 | sh->dev[i].written = NULL; |
| 2649 | if (bi) bitmap_end = 1; |
| 2650 | while (bi && bi->bi_sector < |
| 2651 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2652 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
| 2653 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2654 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2655 | md_write_end(conf->mddev); |
| 2656 | bi->bi_next = *return_bi; |
| 2657 | *return_bi = bi; |
| 2658 | } |
| 2659 | bi = bi2; |
| 2660 | } |
| 2661 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2662 | /* fail any reads if this device is non-operational and |
| 2663 | * the data has not reached the cache yet. |
| 2664 | */ |
| 2665 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
| 2666 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 2667 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2668 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2669 | bi = sh->dev[i].toread; |
| 2670 | sh->dev[i].toread = NULL; |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2671 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2672 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2673 | wake_up(&conf->wait_for_overlap); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2674 | while (bi && bi->bi_sector < |
| 2675 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2676 | struct bio *nextbi = |
| 2677 | r5_next_bio(bi, sh->dev[i].sector); |
| 2678 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2679 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2680 | bi->bi_next = *return_bi; |
| 2681 | *return_bi = bi; |
| 2682 | } |
| 2683 | bi = nextbi; |
| 2684 | } |
| 2685 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2686 | if (bitmap_end) |
| 2687 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2688 | STRIPE_SECTORS, 0, 0); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2689 | /* If we were in the middle of a write the parity block might |
| 2690 | * still be locked - so just clear all R5_LOCKED flags |
| 2691 | */ |
| 2692 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2695 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2696 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2697 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2700 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2701 | handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2702 | struct stripe_head_state *s) |
| 2703 | { |
| 2704 | int abort = 0; |
| 2705 | int i; |
| 2706 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2707 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 2708 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 2709 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2710 | s->syncing = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2711 | s->replacing = 0; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2712 | /* There is nothing more to do for sync/check/repair. |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 2713 | * Don't even need to abort as that is handled elsewhere |
| 2714 | * if needed, and not always wanted e.g. if there is a known |
| 2715 | * bad block here. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2716 | * For recover/replace we need to record a bad block on all |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2717 | * non-sync devices, or abort the recovery |
| 2718 | */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 2719 | if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { |
| 2720 | /* During recovery devices cannot be removed, so |
| 2721 | * locking and refcounting of rdevs is not needed |
| 2722 | */ |
| 2723 | for (i = 0; i < conf->raid_disks; i++) { |
| 2724 | struct md_rdev *rdev = conf->disks[i].rdev; |
| 2725 | if (rdev |
| 2726 | && !test_bit(Faulty, &rdev->flags) |
| 2727 | && !test_bit(In_sync, &rdev->flags) |
| 2728 | && !rdev_set_badblocks(rdev, sh->sector, |
| 2729 | STRIPE_SECTORS, 0)) |
| 2730 | abort = 1; |
| 2731 | rdev = conf->disks[i].replacement; |
| 2732 | if (rdev |
| 2733 | && !test_bit(Faulty, &rdev->flags) |
| 2734 | && !test_bit(In_sync, &rdev->flags) |
| 2735 | && !rdev_set_badblocks(rdev, sh->sector, |
| 2736 | STRIPE_SECTORS, 0)) |
| 2737 | abort = 1; |
| 2738 | } |
| 2739 | if (abort) |
| 2740 | conf->recovery_disabled = |
| 2741 | conf->mddev->recovery_disabled; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2742 | } |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 2743 | md_done_sync(conf->mddev, STRIPE_SECTORS, !abort); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2744 | } |
| 2745 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2746 | static int want_replace(struct stripe_head *sh, int disk_idx) |
| 2747 | { |
| 2748 | struct md_rdev *rdev; |
| 2749 | int rv = 0; |
| 2750 | /* Doing recovery so rcu locking not required */ |
| 2751 | rdev = sh->raid_conf->disks[disk_idx].replacement; |
| 2752 | if (rdev |
| 2753 | && !test_bit(Faulty, &rdev->flags) |
| 2754 | && !test_bit(In_sync, &rdev->flags) |
| 2755 | && (rdev->recovery_offset <= sh->sector |
| 2756 | || rdev->mddev->recovery_cp <= sh->sector)) |
| 2757 | rv = 1; |
| 2758 | |
| 2759 | return rv; |
| 2760 | } |
| 2761 | |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2762 | /* 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] | 2763 | * to be read or computed to satisfy a request. |
| 2764 | * |
| 2765 | * Returns 1 when no more member devices need to be checked, otherwise returns |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2766 | * 0 to tell the loop in handle_stripe_fill to continue |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2767 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2768 | static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 2769 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2770 | { |
| 2771 | struct r5dev *dev = &sh->dev[disk_idx]; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2772 | struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], |
| 2773 | &sh->dev[s->failed_num[1]] }; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2774 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2775 | /* is the data in this block needed, and can we get it? */ |
| 2776 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2777 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2778 | (dev->toread || |
| 2779 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2780 | s->syncing || s->expanding || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2781 | (s->replacing && want_replace(sh, disk_idx)) || |
NeilBrown | 5d35e09 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2782 | (s->failed >= 1 && fdev[0]->toread) || |
| 2783 | (s->failed >= 2 && fdev[1]->toread) || |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2784 | (sh->raid_conf->level <= 5 && s->failed && fdev[0]->towrite && |
| 2785 | !test_bit(R5_OVERWRITE, &fdev[0]->flags)) || |
| 2786 | (sh->raid_conf->level == 6 && s->failed && s->to_write))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2787 | /* we would like to get this block, possibly by computing it, |
| 2788 | * otherwise read it if the backing disk is insync |
| 2789 | */ |
| 2790 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 2791 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
| 2792 | if ((s->uptodate == disks - 1) && |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2793 | (s->failed && (disk_idx == s->failed_num[0] || |
| 2794 | disk_idx == s->failed_num[1]))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2795 | /* have disk failed, and we're requested to fetch it; |
| 2796 | * do compute it |
| 2797 | */ |
| 2798 | pr_debug("Computing stripe %llu block %d\n", |
| 2799 | (unsigned long long)sh->sector, disk_idx); |
| 2800 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2801 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2802 | set_bit(R5_Wantcompute, &dev->flags); |
| 2803 | sh->ops.target = disk_idx; |
| 2804 | sh->ops.target2 = -1; /* no 2nd target */ |
| 2805 | s->req_compute = 1; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2806 | /* Careful: from this point on 'uptodate' is in the eye |
| 2807 | * of raid_run_ops which services 'compute' operations |
| 2808 | * before writes. R5_Wantcompute flags a block that will |
| 2809 | * be R5_UPTODATE by the time it is needed for a |
| 2810 | * subsequent operation. |
| 2811 | */ |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2812 | s->uptodate++; |
| 2813 | return 1; |
| 2814 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 2815 | /* Computing 2-failure is *very* expensive; only |
| 2816 | * do it if failed >= 2 |
| 2817 | */ |
| 2818 | int other; |
| 2819 | for (other = disks; other--; ) { |
| 2820 | if (other == disk_idx) |
| 2821 | continue; |
| 2822 | if (!test_bit(R5_UPTODATE, |
| 2823 | &sh->dev[other].flags)) |
| 2824 | break; |
| 2825 | } |
| 2826 | BUG_ON(other < 0); |
| 2827 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 2828 | (unsigned long long)sh->sector, |
| 2829 | disk_idx, other); |
| 2830 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2831 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2832 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 2833 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 2834 | sh->ops.target = disk_idx; |
| 2835 | sh->ops.target2 = other; |
| 2836 | s->uptodate += 2; |
| 2837 | s->req_compute = 1; |
| 2838 | return 1; |
| 2839 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 2840 | set_bit(R5_LOCKED, &dev->flags); |
| 2841 | set_bit(R5_Wantread, &dev->flags); |
| 2842 | s->locked++; |
| 2843 | pr_debug("Reading block %d (sync=%d)\n", |
| 2844 | disk_idx, s->syncing); |
| 2845 | } |
| 2846 | } |
| 2847 | |
| 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | /** |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2852 | * handle_stripe_fill - read or compute data to satisfy pending requests. |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2853 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2854 | static void handle_stripe_fill(struct stripe_head *sh, |
| 2855 | struct stripe_head_state *s, |
| 2856 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2857 | { |
| 2858 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2859 | |
| 2860 | /* look for blocks to read/compute, skip this if a compute |
| 2861 | * is already in flight, or if the stripe contents are in the |
| 2862 | * midst of changing due to a write |
| 2863 | */ |
| 2864 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
| 2865 | !sh->reconstruct_state) |
| 2866 | for (i = disks; i--; ) |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2867 | if (fetch_block(sh, s, i, disks)) |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2868 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2869 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2870 | } |
| 2871 | |
| 2872 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2873 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2874 | * any written block on an uptodate or failed drive can be returned. |
| 2875 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 2876 | * never LOCKED, so we don't need to test 'failed' directly. |
| 2877 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2878 | static void handle_stripe_clean_event(struct r5conf *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2879 | struct stripe_head *sh, int disks, struct bio **return_bi) |
| 2880 | { |
| 2881 | int i; |
| 2882 | struct r5dev *dev; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 2883 | int discard_pending = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2884 | |
| 2885 | for (i = disks; i--; ) |
| 2886 | if (sh->dev[i].written) { |
| 2887 | dev = &sh->dev[i]; |
| 2888 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 2889 | (test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | ca64cae | 2012-11-21 16:33:40 +1100 | [diff] [blame] | 2890 | test_bit(R5_Discard, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2891 | /* We can return any write requests */ |
| 2892 | struct bio *wbi, *wbi2; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2893 | pr_debug("Return write for disc %d\n", i); |
NeilBrown | ca64cae | 2012-11-21 16:33:40 +1100 | [diff] [blame] | 2894 | if (test_and_clear_bit(R5_Discard, &dev->flags)) |
| 2895 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2896 | wbi = dev->written; |
| 2897 | dev->written = NULL; |
| 2898 | while (wbi && wbi->bi_sector < |
| 2899 | dev->sector + STRIPE_SECTORS) { |
| 2900 | wbi2 = r5_next_bio(wbi, dev->sector); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2901 | if (!raid5_dec_bi_active_stripes(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2902 | md_write_end(conf->mddev); |
| 2903 | wbi->bi_next = *return_bi; |
| 2904 | *return_bi = wbi; |
| 2905 | } |
| 2906 | wbi = wbi2; |
| 2907 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2908 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2909 | STRIPE_SECTORS, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2910 | !test_bit(STRIPE_DEGRADED, &sh->state), |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 2911 | 0); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 2912 | } else if (test_bit(R5_Discard, &dev->flags)) |
| 2913 | discard_pending = 1; |
| 2914 | } |
| 2915 | if (!discard_pending && |
| 2916 | test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { |
| 2917 | clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 2918 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
| 2919 | if (sh->qd_idx >= 0) { |
| 2920 | clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 2921 | clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); |
| 2922 | } |
| 2923 | /* now that discard is done we can proceed with any sync */ |
| 2924 | clear_bit(STRIPE_DISCARD, &sh->state); |
| 2925 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) |
| 2926 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2927 | |
| 2928 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2929 | |
| 2930 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2931 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2932 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2935 | static void handle_stripe_dirtying(struct r5conf *conf, |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2936 | struct stripe_head *sh, |
| 2937 | struct stripe_head_state *s, |
| 2938 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2939 | { |
| 2940 | int rmw = 0, rcw = 0, i; |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2941 | sector_t recovery_cp = conf->mddev->recovery_cp; |
| 2942 | |
| 2943 | /* RAID6 requires 'rcw' in current implementation. |
| 2944 | * Otherwise, check whether resync is now happening or should start. |
| 2945 | * If yes, then the array is dirty (after unclean shutdown or |
| 2946 | * initial creation), so parity in some stripes might be inconsistent. |
| 2947 | * In this case, we need to always do reconstruct-write, to ensure |
| 2948 | * that in case of drive failure or read-error correction, we |
| 2949 | * generate correct data from the parity. |
| 2950 | */ |
| 2951 | if (conf->max_degraded == 2 || |
| 2952 | (recovery_cp < MaxSector && sh->sector >= recovery_cp)) { |
| 2953 | /* Calculate the real rcw later - for now make it |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2954 | * look like rcw is cheaper |
| 2955 | */ |
| 2956 | rcw = 1; rmw = 2; |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 2957 | pr_debug("force RCW max_degraded=%u, recovery_cp=%llu sh->sector=%llu\n", |
| 2958 | conf->max_degraded, (unsigned long long)recovery_cp, |
| 2959 | (unsigned long long)sh->sector); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2960 | } else for (i = disks; i--; ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2961 | /* would I have to read this buffer for read_modify_write */ |
| 2962 | struct r5dev *dev = &sh->dev[i]; |
| 2963 | if ((dev->towrite || i == sh->pd_idx) && |
| 2964 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2965 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2966 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2967 | if (test_bit(R5_Insync, &dev->flags)) |
| 2968 | rmw++; |
| 2969 | else |
| 2970 | rmw += 2*disks; /* cannot read it */ |
| 2971 | } |
| 2972 | /* Would I have to read this buffer for reconstruct_write */ |
| 2973 | if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && |
| 2974 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2975 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2976 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2977 | if (test_bit(R5_Insync, &dev->flags)) rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2978 | else |
| 2979 | rcw += 2*disks; |
| 2980 | } |
| 2981 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2982 | pr_debug("for sector %llu, rmw=%d rcw=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2983 | (unsigned long long)sh->sector, rmw, rcw); |
| 2984 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 2985 | if (rmw < rcw && rmw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2986 | /* prefer read-modify-write, but need to get some data */ |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 2987 | if (conf->mddev->queue) |
| 2988 | blk_add_trace_msg(conf->mddev->queue, |
| 2989 | "raid5 rmw %llu %d", |
| 2990 | (unsigned long long)sh->sector, rmw); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2991 | for (i = disks; i--; ) { |
| 2992 | struct r5dev *dev = &sh->dev[i]; |
| 2993 | if ((dev->towrite || i == sh->pd_idx) && |
| 2994 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2995 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2996 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2997 | test_bit(R5_Insync, &dev->flags)) { |
| 2998 | if ( |
| 2999 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3000 | pr_debug("Read_old block " |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3001 | "%d for r-m-w\n", i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3002 | set_bit(R5_LOCKED, &dev->flags); |
| 3003 | set_bit(R5_Wantread, &dev->flags); |
| 3004 | s->locked++; |
| 3005 | } else { |
| 3006 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3007 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3008 | } |
| 3009 | } |
| 3010 | } |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3011 | } |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3012 | if (rcw <= rmw && rcw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3013 | /* want reconstruct write, but need to get some data */ |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3014 | int qread =0; |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3015 | rcw = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3016 | for (i = disks; i--; ) { |
| 3017 | struct r5dev *dev = &sh->dev[i]; |
| 3018 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3019 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3020 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3021 | !(test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3022 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 3023 | rcw++; |
| 3024 | if (!test_bit(R5_Insync, &dev->flags)) |
| 3025 | continue; /* it's a failed drive */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3026 | if ( |
| 3027 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3028 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3029 | "%d for Reconstruct\n", i); |
| 3030 | set_bit(R5_LOCKED, &dev->flags); |
| 3031 | set_bit(R5_Wantread, &dev->flags); |
| 3032 | s->locked++; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3033 | qread++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3034 | } else { |
| 3035 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3036 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3037 | } |
| 3038 | } |
| 3039 | } |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 3040 | if (rcw && conf->mddev->queue) |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3041 | blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", |
| 3042 | (unsigned long long)sh->sector, |
| 3043 | rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3044 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3045 | /* now if nothing is locked, and if we have enough data, |
| 3046 | * we can start a write request |
| 3047 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3048 | /* since handle_stripe can be called at any time we need to handle the |
| 3049 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 3050 | * subsequent call wants to start a write request. raid_run_ops only |
| 3051 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3052 | * simultaneously. If this is not the case then new writes need to be |
| 3053 | * held off until the compute completes. |
| 3054 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3055 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 3056 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
| 3057 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3058 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3061 | static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3062 | struct stripe_head_state *s, int disks) |
| 3063 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3064 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3065 | |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 3066 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3067 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3068 | switch (sh->check_state) { |
| 3069 | case check_state_idle: |
| 3070 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 3071 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 3072 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3073 | sh->check_state = check_state_run; |
| 3074 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 3075 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 3076 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3077 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 3078 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3079 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3080 | /* fall through */ |
| 3081 | case check_state_compute_result: |
| 3082 | sh->check_state = check_state_idle; |
| 3083 | if (!dev) |
| 3084 | dev = &sh->dev[sh->pd_idx]; |
| 3085 | |
| 3086 | /* check that a write has not made the stripe insync */ |
| 3087 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 3088 | break; |
| 3089 | |
| 3090 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3091 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 3092 | BUG_ON(s->uptodate != disks); |
| 3093 | |
| 3094 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3095 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3096 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3097 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3098 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3099 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3100 | break; |
| 3101 | case check_state_run: |
| 3102 | break; /* we will be called again upon completion */ |
| 3103 | case check_state_check_result: |
| 3104 | sh->check_state = check_state_idle; |
| 3105 | |
| 3106 | /* if a failure occurred during the check operation, leave |
| 3107 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 3108 | */ |
| 3109 | if (s->failed) |
| 3110 | break; |
| 3111 | |
| 3112 | /* handle a successful check operation, if parity is correct |
| 3113 | * we are done. Otherwise update the mismatch count and repair |
| 3114 | * parity if !MD_RECOVERY_CHECK |
| 3115 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 3116 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3117 | /* parity is correct (on disc, |
| 3118 | * not in buffer any more) |
| 3119 | */ |
| 3120 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3121 | else { |
Jianpeng Ma | 7f7583d | 2012-10-11 14:17:59 +1100 | [diff] [blame] | 3122 | atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3123 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 3124 | /* don't try to repair!! */ |
| 3125 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3126 | else { |
| 3127 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3128 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3129 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3130 | set_bit(R5_Wantcompute, |
| 3131 | &sh->dev[sh->pd_idx].flags); |
| 3132 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 3133 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3134 | s->uptodate++; |
| 3135 | } |
| 3136 | } |
| 3137 | break; |
| 3138 | case check_state_compute_run: |
| 3139 | break; |
| 3140 | default: |
| 3141 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 3142 | __func__, sh->check_state, |
| 3143 | (unsigned long long) sh->sector); |
| 3144 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3149 | static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3150 | struct stripe_head_state *s, |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3151 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3152 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3153 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3154 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3155 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3156 | |
| 3157 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3158 | |
| 3159 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3160 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3161 | /* Want to check and possibly repair P and Q. |
| 3162 | * However there could be one 'failed' device, in which |
| 3163 | * case we can only check one of them, possibly using the |
| 3164 | * other to generate missing data |
| 3165 | */ |
| 3166 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3167 | switch (sh->check_state) { |
| 3168 | case check_state_idle: |
| 3169 | /* start a new check operation if there are < 2 failures */ |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3170 | if (s->failed == s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3171 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3172 | * makes sense to check P (If anything else were failed, |
| 3173 | * we would have used P to recreate it). |
| 3174 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3175 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3176 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3177 | if (!s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3178 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3179 | * anything, so it makes sense to check it |
| 3180 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3181 | if (sh->check_state == check_state_run) |
| 3182 | sh->check_state = check_state_run_pq; |
| 3183 | else |
| 3184 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3185 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3186 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3187 | /* discard potentially stale zero_sum_result */ |
| 3188 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3189 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3190 | if (sh->check_state == check_state_run) { |
| 3191 | /* async_xor_zero_sum destroys the contents of P */ |
| 3192 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 3193 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3194 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3195 | if (sh->check_state >= check_state_run && |
| 3196 | sh->check_state <= check_state_run_pq) { |
| 3197 | /* async_syndrome_zero_sum preserves P and Q, so |
| 3198 | * no need to mark them !uptodate here |
| 3199 | */ |
| 3200 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 3201 | break; |
| 3202 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3203 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3204 | /* we have 2-disk failure */ |
| 3205 | BUG_ON(s->failed != 2); |
| 3206 | /* fall through */ |
| 3207 | case check_state_compute_result: |
| 3208 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3209 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3210 | /* check that a write has not made the stripe insync */ |
| 3211 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 3212 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3213 | |
| 3214 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3215 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3216 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3217 | 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] | 3218 | if (s->failed == 2) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3219 | dev = &sh->dev[s->failed_num[1]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3220 | s->locked++; |
| 3221 | set_bit(R5_LOCKED, &dev->flags); |
| 3222 | set_bit(R5_Wantwrite, &dev->flags); |
| 3223 | } |
| 3224 | if (s->failed >= 1) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3225 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3226 | s->locked++; |
| 3227 | set_bit(R5_LOCKED, &dev->flags); |
| 3228 | set_bit(R5_Wantwrite, &dev->flags); |
| 3229 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3230 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3231 | dev = &sh->dev[pd_idx]; |
| 3232 | s->locked++; |
| 3233 | set_bit(R5_LOCKED, &dev->flags); |
| 3234 | set_bit(R5_Wantwrite, &dev->flags); |
| 3235 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3236 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3237 | dev = &sh->dev[qd_idx]; |
| 3238 | s->locked++; |
| 3239 | set_bit(R5_LOCKED, &dev->flags); |
| 3240 | set_bit(R5_Wantwrite, &dev->flags); |
| 3241 | } |
| 3242 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 3243 | |
| 3244 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3245 | break; |
| 3246 | case check_state_run: |
| 3247 | case check_state_run_q: |
| 3248 | case check_state_run_pq: |
| 3249 | break; /* we will be called again upon completion */ |
| 3250 | case check_state_check_result: |
| 3251 | sh->check_state = check_state_idle; |
| 3252 | |
| 3253 | /* handle a successful check operation, if parity is correct |
| 3254 | * we are done. Otherwise update the mismatch count and repair |
| 3255 | * parity if !MD_RECOVERY_CHECK |
| 3256 | */ |
| 3257 | if (sh->ops.zero_sum_result == 0) { |
| 3258 | /* both parities are correct */ |
| 3259 | if (!s->failed) |
| 3260 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3261 | else { |
| 3262 | /* in contrast to the raid5 case we can validate |
| 3263 | * parity, but still have a failure to write |
| 3264 | * back |
| 3265 | */ |
| 3266 | sh->check_state = check_state_compute_result; |
| 3267 | /* Returning at this point means that we may go |
| 3268 | * off and bring p and/or q uptodate again so |
| 3269 | * we make sure to check zero_sum_result again |
| 3270 | * to verify if p or q need writeback |
| 3271 | */ |
| 3272 | } |
| 3273 | } else { |
Jianpeng Ma | 7f7583d | 2012-10-11 14:17:59 +1100 | [diff] [blame] | 3274 | atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 3275 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 3276 | /* don't try to repair!! */ |
| 3277 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3278 | else { |
| 3279 | int *target = &sh->ops.target; |
| 3280 | |
| 3281 | sh->ops.target = -1; |
| 3282 | sh->ops.target2 = -1; |
| 3283 | sh->check_state = check_state_compute_run; |
| 3284 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3285 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3286 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 3287 | set_bit(R5_Wantcompute, |
| 3288 | &sh->dev[pd_idx].flags); |
| 3289 | *target = pd_idx; |
| 3290 | target = &sh->ops.target2; |
| 3291 | s->uptodate++; |
| 3292 | } |
| 3293 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 3294 | set_bit(R5_Wantcompute, |
| 3295 | &sh->dev[qd_idx].flags); |
| 3296 | *target = qd_idx; |
| 3297 | s->uptodate++; |
| 3298 | } |
| 3299 | } |
| 3300 | } |
| 3301 | break; |
| 3302 | case check_state_compute_run: |
| 3303 | break; |
| 3304 | default: |
| 3305 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 3306 | __func__, sh->check_state, |
| 3307 | (unsigned long long) sh->sector); |
| 3308 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3309 | } |
| 3310 | } |
| 3311 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3312 | static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3313 | { |
| 3314 | int i; |
| 3315 | |
| 3316 | /* We have read all the blocks in this stripe and now we need to |
| 3317 | * copy some of them into a target stripe for expand. |
| 3318 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3319 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3320 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3321 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3322 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3323 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3324 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3325 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3326 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3327 | sector_t bn = compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3328 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 3329 | &dd_idx, NULL); |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3330 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3331 | if (sh2 == NULL) |
| 3332 | /* so far only the early blocks of this stripe |
| 3333 | * have been requested. When later blocks |
| 3334 | * get requested, we will try again |
| 3335 | */ |
| 3336 | continue; |
| 3337 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 3338 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 3339 | /* must have already done this block */ |
| 3340 | release_stripe(sh2); |
| 3341 | continue; |
| 3342 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3343 | |
| 3344 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3345 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3346 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 3347 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3348 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3349 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3350 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 3351 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 3352 | for (j = 0; j < conf->raid_disks; j++) |
| 3353 | if (j != sh2->pd_idx && |
NeilBrown | 86c374b | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3354 | j != sh2->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3355 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 3356 | break; |
| 3357 | if (j == conf->raid_disks) { |
| 3358 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 3359 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 3360 | } |
| 3361 | release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3362 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3363 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 3364 | /* done submitting copies, wait for them to complete */ |
NeilBrown | 749586b | 2012-11-20 14:11:15 +1100 | [diff] [blame] | 3365 | async_tx_quiesce(&tx); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | |
| 3368 | /* |
| 3369 | * handle_stripe - do things to a stripe. |
| 3370 | * |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3371 | * We lock the stripe by setting STRIPE_ACTIVE and then examine the |
| 3372 | * state of various bits to see what needs to be done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | * Possible results: |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3374 | * return some read requests which now have data |
| 3375 | * return some write requests which are safely on storage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | * schedule a read on some buffers |
| 3377 | * schedule a write of some buffers |
| 3378 | * return confirmation of parity correctness |
| 3379 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3381 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3382 | static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3383 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3384 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3385 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3386 | struct r5dev *dev; |
| 3387 | int i; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3388 | int do_recovery = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3389 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3390 | memset(s, 0, sizeof(*s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3391 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3392 | s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3393 | s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3394 | s->failed_num[0] = -1; |
| 3395 | s->failed_num[1] = -1; |
| 3396 | |
| 3397 | /* Now to look around and see what can be done */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3398 | rcu_read_lock(); |
| 3399 | for (i=disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3400 | struct md_rdev *rdev; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3401 | sector_t first_bad; |
| 3402 | int bad_sectors; |
| 3403 | int is_bad = 0; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3404 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3405 | dev = &sh->dev[i]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3406 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3407 | 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] | 3408 | i, dev->flags, |
| 3409 | dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3410 | /* maybe we can reply to a read |
| 3411 | * |
| 3412 | * new wantfill requests are only permitted while |
| 3413 | * ops_complete_biofill is guaranteed to be inactive |
| 3414 | */ |
| 3415 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 3416 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 3417 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3418 | |
| 3419 | /* now count some things */ |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3420 | if (test_bit(R5_LOCKED, &dev->flags)) |
| 3421 | s->locked++; |
| 3422 | if (test_bit(R5_UPTODATE, &dev->flags)) |
| 3423 | s->uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3424 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3425 | s->compute++; |
| 3426 | BUG_ON(s->compute > 2); |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3427 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3428 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3429 | if (test_bit(R5_Wantfill, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3430 | s->to_fill++; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3431 | else if (dev->toread) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3432 | s->to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3433 | if (dev->towrite) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3434 | s->to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3435 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3436 | s->non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3437 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3438 | if (dev->written) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3439 | s->written++; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3440 | /* Prefer to use the replacement for reads, but only |
| 3441 | * if it is recovered enough and has no bad blocks. |
| 3442 | */ |
| 3443 | rdev = rcu_dereference(conf->disks[i].replacement); |
| 3444 | if (rdev && !test_bit(Faulty, &rdev->flags) && |
| 3445 | rdev->recovery_offset >= sh->sector + STRIPE_SECTORS && |
| 3446 | !is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3447 | &first_bad, &bad_sectors)) |
| 3448 | set_bit(R5_ReadRepl, &dev->flags); |
| 3449 | else { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3450 | if (rdev) |
| 3451 | set_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3452 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 3453 | clear_bit(R5_ReadRepl, &dev->flags); |
| 3454 | } |
NeilBrown | 9283d8c | 2011-12-08 16:27:57 +1100 | [diff] [blame] | 3455 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 3456 | rdev = NULL; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3457 | if (rdev) { |
| 3458 | is_bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3459 | &first_bad, &bad_sectors); |
| 3460 | if (s->blocked_rdev == NULL |
| 3461 | && (test_bit(Blocked, &rdev->flags) |
| 3462 | || is_bad < 0)) { |
| 3463 | if (is_bad < 0) |
| 3464 | set_bit(BlockedBadBlocks, |
| 3465 | &rdev->flags); |
| 3466 | s->blocked_rdev = rdev; |
| 3467 | atomic_inc(&rdev->nr_pending); |
| 3468 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3469 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3470 | clear_bit(R5_Insync, &dev->flags); |
| 3471 | if (!rdev) |
| 3472 | /* Not in-sync */; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3473 | else if (is_bad) { |
| 3474 | /* also not in-sync */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3475 | if (!test_bit(WriteErrorSeen, &rdev->flags) && |
| 3476 | test_bit(R5_UPTODATE, &dev->flags)) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3477 | /* treat as in-sync, but with a read error |
| 3478 | * which we can now try to correct |
| 3479 | */ |
| 3480 | set_bit(R5_Insync, &dev->flags); |
| 3481 | set_bit(R5_ReadError, &dev->flags); |
| 3482 | } |
| 3483 | } else if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3484 | set_bit(R5_Insync, &dev->flags); |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 3485 | else if (sh->sector + STRIPE_SECTORS <= rdev->recovery_offset) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3486 | /* in sync if before recovery_offset */ |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 3487 | set_bit(R5_Insync, &dev->flags); |
| 3488 | else if (test_bit(R5_UPTODATE, &dev->flags) && |
| 3489 | test_bit(R5_Expanded, &dev->flags)) |
| 3490 | /* If we've reshaped into here, we assume it is Insync. |
| 3491 | * We will shortly update recovery_offset to make |
| 3492 | * it official. |
| 3493 | */ |
| 3494 | set_bit(R5_Insync, &dev->flags); |
| 3495 | |
Adam Kwolek | 5d8c71f | 2011-12-09 14:26:11 +1100 | [diff] [blame] | 3496 | if (rdev && test_bit(R5_WriteError, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3497 | /* This flag does not apply to '.replacement' |
| 3498 | * only to .rdev, so make sure to check that*/ |
| 3499 | struct md_rdev *rdev2 = rcu_dereference( |
| 3500 | conf->disks[i].rdev); |
| 3501 | if (rdev2 == rdev) |
| 3502 | clear_bit(R5_Insync, &dev->flags); |
| 3503 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3504 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3505 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3506 | } else |
| 3507 | clear_bit(R5_WriteError, &dev->flags); |
| 3508 | } |
Adam Kwolek | 5d8c71f | 2011-12-09 14:26:11 +1100 | [diff] [blame] | 3509 | if (rdev && test_bit(R5_MadeGood, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3510 | /* This flag does not apply to '.replacement' |
| 3511 | * only to .rdev, so make sure to check that*/ |
| 3512 | struct md_rdev *rdev2 = rcu_dereference( |
| 3513 | conf->disks[i].rdev); |
| 3514 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3515 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3516 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3517 | } else |
| 3518 | clear_bit(R5_MadeGood, &dev->flags); |
| 3519 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3520 | if (test_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 3521 | struct md_rdev *rdev2 = rcu_dereference( |
| 3522 | conf->disks[i].replacement); |
| 3523 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
| 3524 | s->handle_bad_blocks = 1; |
| 3525 | atomic_inc(&rdev2->nr_pending); |
| 3526 | } else |
| 3527 | clear_bit(R5_MadeGoodRepl, &dev->flags); |
| 3528 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3529 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3530 | /* The ReadError flag will just be confusing now */ |
| 3531 | clear_bit(R5_ReadError, &dev->flags); |
| 3532 | clear_bit(R5_ReWrite, &dev->flags); |
| 3533 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3534 | if (test_bit(R5_ReadError, &dev->flags)) |
| 3535 | clear_bit(R5_Insync, &dev->flags); |
| 3536 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3537 | if (s->failed < 2) |
| 3538 | s->failed_num[s->failed] = i; |
| 3539 | s->failed++; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3540 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
| 3541 | do_recovery = 1; |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3542 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3543 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3544 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 3545 | /* If there is a failed device being replaced, |
| 3546 | * we must be recovering. |
| 3547 | * else if we are after recovery_cp, we must be syncing |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 3548 | * else if MD_RECOVERY_REQUESTED is set, we also are syncing. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3549 | * else we can only be replacing |
| 3550 | * sync and recovery both need to read all devices, and so |
| 3551 | * use the same flag. |
| 3552 | */ |
| 3553 | if (do_recovery || |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 3554 | sh->sector >= conf->mddev->recovery_cp || |
| 3555 | test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3556 | s->syncing = 1; |
| 3557 | else |
| 3558 | s->replacing = 1; |
| 3559 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3560 | rcu_read_unlock(); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3561 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3562 | |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3563 | static void handle_stripe(struct stripe_head *sh) |
| 3564 | { |
| 3565 | struct stripe_head_state s; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3566 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3567 | int i; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3568 | int prexor; |
| 3569 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3570 | struct r5dev *pdev, *qdev; |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3571 | |
| 3572 | clear_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 3573 | if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3574 | /* already being handled, ensure it gets handled |
| 3575 | * again when current action finishes */ |
| 3576 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3577 | return; |
| 3578 | } |
| 3579 | |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3580 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 3581 | spin_lock(&sh->stripe_lock); |
| 3582 | /* Cannot process 'sync' concurrently with 'discard' */ |
| 3583 | if (!test_bit(STRIPE_DISCARD, &sh->state) && |
| 3584 | test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 3585 | set_bit(STRIPE_SYNCING, &sh->state); |
| 3586 | clear_bit(STRIPE_INSYNC, &sh->state); |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 3587 | clear_bit(STRIPE_REPLACED, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3588 | } |
| 3589 | spin_unlock(&sh->stripe_lock); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3590 | } |
| 3591 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3592 | |
| 3593 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
| 3594 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
| 3595 | (unsigned long long)sh->sector, sh->state, |
| 3596 | atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, |
| 3597 | sh->check_state, sh->reconstruct_state); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3598 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3599 | analyse_stripe(sh, &s); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3600 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3601 | if (s.handle_bad_blocks) { |
| 3602 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3603 | goto finish; |
| 3604 | } |
| 3605 | |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3606 | if (unlikely(s.blocked_rdev)) { |
| 3607 | if (s.syncing || s.expanding || s.expanded || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3608 | s.replacing || s.to_write || s.written) { |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3609 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3610 | goto finish; |
| 3611 | } |
| 3612 | /* There is nothing for the blocked_rdev to block */ |
| 3613 | rdev_dec_pending(s.blocked_rdev, conf->mddev); |
| 3614 | s.blocked_rdev = NULL; |
| 3615 | } |
| 3616 | |
| 3617 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3618 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3619 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3620 | } |
| 3621 | |
| 3622 | pr_debug("locked=%d uptodate=%d to_read=%d" |
| 3623 | " to_write=%d failed=%d failed_num=%d,%d\n", |
| 3624 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 3625 | s.failed_num[0], s.failed_num[1]); |
| 3626 | /* check if the array has lost more than max_degraded devices and, |
| 3627 | * if so, some requests might need to be failed. |
| 3628 | */ |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 3629 | if (s.failed > conf->max_degraded) { |
| 3630 | sh->check_state = 0; |
| 3631 | sh->reconstruct_state = 0; |
| 3632 | if (s.to_read+s.to_write+s.written) |
| 3633 | handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3634 | if (s.syncing + s.replacing) |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 3635 | handle_failed_sync(conf, sh, &s); |
| 3636 | } |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3637 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3638 | /* Now we check to see if any write operations have recently |
| 3639 | * completed |
| 3640 | */ |
| 3641 | prexor = 0; |
| 3642 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
| 3643 | prexor = 1; |
| 3644 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 3645 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
| 3646 | sh->reconstruct_state = reconstruct_state_idle; |
| 3647 | |
| 3648 | /* All the 'written' buffers and the parity block are ready to |
| 3649 | * be written back to disk |
| 3650 | */ |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 3651 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && |
| 3652 | !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3653 | BUG_ON(sh->qd_idx >= 0 && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 3654 | !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && |
| 3655 | !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3656 | for (i = disks; i--; ) { |
| 3657 | struct r5dev *dev = &sh->dev[i]; |
| 3658 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3659 | (i == sh->pd_idx || i == sh->qd_idx || |
| 3660 | dev->written)) { |
| 3661 | pr_debug("Writing block %d\n", i); |
| 3662 | set_bit(R5_Wantwrite, &dev->flags); |
| 3663 | if (prexor) |
| 3664 | continue; |
| 3665 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3666 | ((i == sh->pd_idx || i == sh->qd_idx) && |
| 3667 | s.failed == 0)) |
| 3668 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3669 | } |
| 3670 | } |
| 3671 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3672 | s.dec_preread_active = 1; |
| 3673 | } |
| 3674 | |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 3675 | /* |
| 3676 | * might be able to return some write requests if the parity blocks |
| 3677 | * are safe, or on a failed drive |
| 3678 | */ |
| 3679 | pdev = &sh->dev[sh->pd_idx]; |
| 3680 | s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) |
| 3681 | || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); |
| 3682 | qdev = &sh->dev[sh->qd_idx]; |
| 3683 | s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) |
| 3684 | || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) |
| 3685 | || conf->level < 6; |
| 3686 | |
| 3687 | if (s.written && |
| 3688 | (s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
| 3689 | && !test_bit(R5_LOCKED, &pdev->flags) |
| 3690 | && (test_bit(R5_UPTODATE, &pdev->flags) || |
| 3691 | test_bit(R5_Discard, &pdev->flags))))) && |
| 3692 | (s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
| 3693 | && !test_bit(R5_LOCKED, &qdev->flags) |
| 3694 | && (test_bit(R5_UPTODATE, &qdev->flags) || |
| 3695 | test_bit(R5_Discard, &qdev->flags)))))) |
| 3696 | handle_stripe_clean_event(conf, sh, disks, &s.return_bi); |
| 3697 | |
| 3698 | /* Now we might consider reading some blocks, either to check/generate |
| 3699 | * parity, or to satisfy requests |
| 3700 | * or to load a block that is being partially written. |
| 3701 | */ |
| 3702 | if (s.to_read || s.non_overwrite |
| 3703 | || (conf->level == 6 && s.to_write && s.failed) |
| 3704 | || (s.syncing && (s.uptodate + s.compute < disks)) |
| 3705 | || s.replacing |
| 3706 | || s.expanding) |
| 3707 | handle_stripe_fill(sh, &s, disks); |
| 3708 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3709 | /* Now to consider new write requests and what else, if anything |
| 3710 | * should be read. We do not handle new writes when: |
| 3711 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 3712 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3713 | * block. |
| 3714 | */ |
| 3715 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
| 3716 | handle_stripe_dirtying(conf, sh, &s, disks); |
| 3717 | |
| 3718 | /* maybe we need to check and possibly fix the parity for this stripe |
| 3719 | * Any reads will already have been scheduled, so we just see if enough |
| 3720 | * data is available. The parity check is held off while parity |
| 3721 | * dependent operations are in flight. |
| 3722 | */ |
| 3723 | if (sh->check_state || |
| 3724 | (s.syncing && s.locked == 0 && |
| 3725 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 3726 | !test_bit(STRIPE_INSYNC, &sh->state))) { |
| 3727 | if (conf->level == 6) |
| 3728 | handle_parity_checks6(conf, sh, &s, disks); |
| 3729 | else |
| 3730 | handle_parity_checks5(conf, sh, &s, disks); |
| 3731 | } |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3732 | |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 3733 | if ((s.replacing || s.syncing) && s.locked == 0 |
| 3734 | && !test_bit(STRIPE_COMPUTE_RUN, &sh->state) |
| 3735 | && !test_bit(STRIPE_REPLACED, &sh->state)) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3736 | /* Write out to replacement devices where possible */ |
| 3737 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 3738 | if (test_bit(R5_NeedReplace, &sh->dev[i].flags)) { |
| 3739 | WARN_ON(!test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3740 | set_bit(R5_WantReplace, &sh->dev[i].flags); |
| 3741 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3742 | s.locked++; |
| 3743 | } |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 3744 | if (s.replacing) |
| 3745 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3746 | set_bit(STRIPE_REPLACED, &sh->state); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3747 | } |
| 3748 | if ((s.syncing || s.replacing) && s.locked == 0 && |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 3749 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3750 | test_bit(STRIPE_INSYNC, &sh->state)) { |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3751 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3752 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3753 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 3754 | wake_up(&conf->wait_for_overlap); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | /* If the failed drives are just a ReadError, then we might need |
| 3758 | * to progress the repair/check process |
| 3759 | */ |
| 3760 | if (s.failed <= conf->max_degraded && !conf->mddev->ro) |
| 3761 | for (i = 0; i < s.failed; i++) { |
| 3762 | struct r5dev *dev = &sh->dev[s.failed_num[i]]; |
| 3763 | if (test_bit(R5_ReadError, &dev->flags) |
| 3764 | && !test_bit(R5_LOCKED, &dev->flags) |
| 3765 | && test_bit(R5_UPTODATE, &dev->flags) |
| 3766 | ) { |
| 3767 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3768 | set_bit(R5_Wantwrite, &dev->flags); |
| 3769 | set_bit(R5_ReWrite, &dev->flags); |
| 3770 | set_bit(R5_LOCKED, &dev->flags); |
| 3771 | s.locked++; |
| 3772 | } else { |
| 3773 | /* let's read it back */ |
| 3774 | set_bit(R5_Wantread, &dev->flags); |
| 3775 | set_bit(R5_LOCKED, &dev->flags); |
| 3776 | s.locked++; |
| 3777 | } |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3782 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3783 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 3784 | struct stripe_head *sh_src |
| 3785 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
| 3786 | if (sh_src && test_bit(STRIPE_EXPAND_SOURCE, &sh_src->state)) { |
| 3787 | /* sh cannot be written until sh_src has been read. |
| 3788 | * so arrange for sh to be delayed a little |
| 3789 | */ |
| 3790 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3791 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3792 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3793 | &sh_src->state)) |
| 3794 | atomic_inc(&conf->preread_active_stripes); |
| 3795 | release_stripe(sh_src); |
| 3796 | goto finish; |
| 3797 | } |
| 3798 | if (sh_src) |
| 3799 | release_stripe(sh_src); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3800 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3801 | sh->reconstruct_state = reconstruct_state_idle; |
| 3802 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 3803 | for (i = conf->raid_disks; i--; ) { |
| 3804 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 3805 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3806 | s.locked++; |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 3811 | !sh->reconstruct_state) { |
| 3812 | /* Need to write out all blocks after computing parity */ |
| 3813 | sh->disks = conf->raid_disks; |
| 3814 | stripe_set_idx(sh->sector, conf, 0, sh); |
| 3815 | schedule_reconstruction(sh, &s, 1, 1); |
| 3816 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
| 3817 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3818 | atomic_dec(&conf->reshape_stripes); |
| 3819 | wake_up(&conf->wait_for_overlap); |
| 3820 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3821 | } |
| 3822 | |
| 3823 | if (s.expanding && s.locked == 0 && |
| 3824 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
| 3825 | handle_stripe_expansion(conf, sh); |
| 3826 | |
| 3827 | finish: |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3828 | /* wait for this device to become unblocked */ |
NeilBrown | 5f066c6 | 2012-07-03 12:13:29 +1000 | [diff] [blame] | 3829 | if (unlikely(s.blocked_rdev)) { |
| 3830 | if (conf->mddev->external) |
| 3831 | md_wait_for_blocked_rdev(s.blocked_rdev, |
| 3832 | conf->mddev); |
| 3833 | else |
| 3834 | /* Internal metadata will immediately |
| 3835 | * be written by raid5d, so we don't |
| 3836 | * need to wait here. |
| 3837 | */ |
| 3838 | rdev_dec_pending(s.blocked_rdev, |
| 3839 | conf->mddev); |
| 3840 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3841 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3842 | if (s.handle_bad_blocks) |
| 3843 | for (i = disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3844 | struct md_rdev *rdev; |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3845 | struct r5dev *dev = &sh->dev[i]; |
| 3846 | if (test_and_clear_bit(R5_WriteError, &dev->flags)) { |
| 3847 | /* We own a safe reference to the rdev */ |
| 3848 | rdev = conf->disks[i].rdev; |
| 3849 | if (!rdev_set_badblocks(rdev, sh->sector, |
| 3850 | STRIPE_SECTORS, 0)) |
| 3851 | md_error(conf->mddev, rdev); |
| 3852 | rdev_dec_pending(rdev, conf->mddev); |
| 3853 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3854 | if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { |
| 3855 | rdev = conf->disks[i].rdev; |
| 3856 | rdev_clear_badblocks(rdev, sh->sector, |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 3857 | STRIPE_SECTORS, 0); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3858 | rdev_dec_pending(rdev, conf->mddev); |
| 3859 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3860 | if (test_and_clear_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 3861 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3862 | if (!rdev) |
| 3863 | /* rdev have been moved down */ |
| 3864 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3865 | rdev_clear_badblocks(rdev, sh->sector, |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 3866 | STRIPE_SECTORS, 0); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3867 | rdev_dec_pending(rdev, conf->mddev); |
| 3868 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3869 | } |
| 3870 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3871 | if (s.ops_request) |
| 3872 | raid_run_ops(sh, s.ops_request); |
| 3873 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 3874 | ops_run_io(sh, &s); |
| 3875 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3876 | if (s.dec_preread_active) { |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3877 | /* 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] | 3878 | * is waiting on a flush, it won't continue until the writes |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3879 | * have actually been submitted. |
| 3880 | */ |
| 3881 | atomic_dec(&conf->preread_active_stripes); |
| 3882 | if (atomic_read(&conf->preread_active_stripes) < |
| 3883 | IO_THRESHOLD) |
| 3884 | md_wakeup_thread(conf->mddev->thread); |
| 3885 | } |
| 3886 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3887 | return_io(s.return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3888 | |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 3889 | clear_bit_unlock(STRIPE_ACTIVE, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3892 | static void raid5_activate_delayed(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | { |
| 3894 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 3895 | while (!list_empty(&conf->delayed_list)) { |
| 3896 | struct list_head *l = conf->delayed_list.next; |
| 3897 | struct stripe_head *sh; |
| 3898 | sh = list_entry(l, struct stripe_head, lru); |
| 3899 | list_del_init(l); |
| 3900 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3901 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3902 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3903 | list_add_tail(&sh->lru, &conf->hold_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 3904 | raid5_wakeup_stripe_thread(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | } |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 3906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3909 | static void activate_bit_delay(struct r5conf *conf) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3910 | { |
| 3911 | /* device_lock is held */ |
| 3912 | struct list_head head; |
| 3913 | list_add(&head, &conf->bitmap_list); |
| 3914 | list_del_init(&conf->bitmap_list); |
| 3915 | while (!list_empty(&head)) { |
| 3916 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
| 3917 | list_del_init(&sh->lru); |
| 3918 | atomic_inc(&sh->count); |
| 3919 | __release_stripe(conf, sh); |
| 3920 | } |
| 3921 | } |
| 3922 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3923 | int md_raid5_congested(struct mddev *mddev, int bits) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3924 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3925 | struct r5conf *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3926 | |
| 3927 | /* No difference between reads and writes. Just check |
| 3928 | * how busy the stripe_cache is |
| 3929 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 3930 | |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3931 | if (conf->inactive_blocked) |
| 3932 | return 1; |
| 3933 | if (conf->quiesce) |
| 3934 | return 1; |
| 3935 | if (list_empty_careful(&conf->inactive_list)) |
| 3936 | return 1; |
| 3937 | |
| 3938 | return 0; |
| 3939 | } |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3940 | EXPORT_SYMBOL_GPL(md_raid5_congested); |
| 3941 | |
| 3942 | static int raid5_congested(void *data, int bits) |
| 3943 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3944 | struct mddev *mddev = data; |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3945 | |
| 3946 | return mddev_congested(mddev, bits) || |
| 3947 | md_raid5_congested(mddev, bits); |
| 3948 | } |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3949 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3950 | /* We want read requests to align with chunks where possible, |
| 3951 | * but write requests don't need to. |
| 3952 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3953 | static int raid5_mergeable_bvec(struct request_queue *q, |
| 3954 | struct bvec_merge_data *bvm, |
| 3955 | struct bio_vec *biovec) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3956 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3957 | struct mddev *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3958 | 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] | 3959 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3960 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3961 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3962 | |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3963 | if ((bvm->bi_rw & 1) == WRITE) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3964 | return biovec->bv_len; /* always allow writes to be mergeable */ |
| 3965 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3966 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3967 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3968 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 3969 | if (max < 0) max = 0; |
| 3970 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 3971 | return biovec->bv_len; |
| 3972 | else |
| 3973 | return max; |
| 3974 | } |
| 3975 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3976 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3977 | 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] | 3978 | { |
| 3979 | sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3980 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 3981 | unsigned int bio_sectors = bio_sectors(bio); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3982 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3983 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3984 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3985 | return chunk_sectors >= |
| 3986 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 3987 | } |
| 3988 | |
| 3989 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3990 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 3991 | * later sampled by raid5d. |
| 3992 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3993 | 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] | 3994 | { |
| 3995 | unsigned long flags; |
| 3996 | |
| 3997 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3998 | |
| 3999 | bi->bi_next = conf->retry_read_aligned_list; |
| 4000 | conf->retry_read_aligned_list = bi; |
| 4001 | |
| 4002 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 4003 | md_wakeup_thread(conf->mddev->thread); |
| 4004 | } |
| 4005 | |
| 4006 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4007 | static struct bio *remove_bio_from_retry(struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4008 | { |
| 4009 | struct bio *bi; |
| 4010 | |
| 4011 | bi = conf->retry_read_aligned; |
| 4012 | if (bi) { |
| 4013 | conf->retry_read_aligned = NULL; |
| 4014 | return bi; |
| 4015 | } |
| 4016 | bi = conf->retry_read_aligned_list; |
| 4017 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4018 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4019 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4020 | /* |
| 4021 | * this sets the active strip count to 1 and the processed |
| 4022 | * strip count to zero (upper 8 bits) |
| 4023 | */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4024 | 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] | 4025 | } |
| 4026 | |
| 4027 | return bi; |
| 4028 | } |
| 4029 | |
| 4030 | |
| 4031 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4032 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 4033 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 4034 | * first). |
| 4035 | * If the read failed.. |
| 4036 | */ |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4037 | static void raid5_align_endio(struct bio *bi, int error) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4038 | { |
| 4039 | struct bio* raid_bi = bi->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4040 | struct mddev *mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4041 | struct r5conf *conf; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4042 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4043 | struct md_rdev *rdev; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4044 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4045 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4046 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4047 | rdev = (void*)raid_bi->bi_next; |
| 4048 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 4049 | mddev = rdev->mddev; |
| 4050 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4051 | |
| 4052 | rdev_dec_pending(rdev, conf->mddev); |
| 4053 | |
| 4054 | if (!error && uptodate) { |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4055 | trace_block_bio_complete(bdev_get_queue(raid_bi->bi_bdev), |
| 4056 | raid_bi, 0); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4057 | bio_endio(raid_bi, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4058 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4059 | wake_up(&conf->wait_for_stripe); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4060 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4064 | 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] | 4065 | |
| 4066 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4067 | } |
| 4068 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4069 | static int bio_fits_rdev(struct bio *bi) |
| 4070 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 4071 | struct request_queue *q = bdev_get_queue(bi->bi_bdev); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4072 | |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 4073 | if (bio_sectors(bi) > queue_max_sectors(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4074 | return 0; |
| 4075 | blk_recount_segments(q, bi); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 4076 | if (bi->bi_phys_segments > queue_max_segments(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4077 | return 0; |
| 4078 | |
| 4079 | if (q->merge_bvec_fn) |
| 4080 | /* it's too hard to apply the merge_bvec_fn at this stage, |
| 4081 | * just just give up |
| 4082 | */ |
| 4083 | return 0; |
| 4084 | |
| 4085 | return 1; |
| 4086 | } |
| 4087 | |
| 4088 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4089 | 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] | 4090 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4091 | struct r5conf *conf = mddev->private; |
NeilBrown | 8553fe7 | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 4092 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4093 | struct bio* align_bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4094 | struct md_rdev *rdev; |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4095 | sector_t end_sector; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4096 | |
| 4097 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4098 | pr_debug("chunk_aligned_read : non aligned\n"); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4099 | return 0; |
| 4100 | } |
| 4101 | /* |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 4102 | * 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] | 4103 | */ |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 4104 | align_bi = bio_clone_mddev(raid_bio, GFP_NOIO, mddev); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4105 | if (!align_bi) |
| 4106 | return 0; |
| 4107 | /* |
| 4108 | * set bi_end_io to a new function, and set bi_private to the |
| 4109 | * original bio. |
| 4110 | */ |
| 4111 | align_bi->bi_end_io = raid5_align_endio; |
| 4112 | align_bi->bi_private = raid_bio; |
| 4113 | /* |
| 4114 | * compute position |
| 4115 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4116 | align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, |
| 4117 | 0, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4118 | &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4119 | |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 4120 | end_sector = bio_end_sector(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4121 | rcu_read_lock(); |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4122 | rdev = rcu_dereference(conf->disks[dd_idx].replacement); |
| 4123 | if (!rdev || test_bit(Faulty, &rdev->flags) || |
| 4124 | rdev->recovery_offset < end_sector) { |
| 4125 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 4126 | if (rdev && |
| 4127 | (test_bit(Faulty, &rdev->flags) || |
| 4128 | !(test_bit(In_sync, &rdev->flags) || |
| 4129 | rdev->recovery_offset >= end_sector))) |
| 4130 | rdev = NULL; |
| 4131 | } |
| 4132 | if (rdev) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4133 | sector_t first_bad; |
| 4134 | int bad_sectors; |
| 4135 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4136 | atomic_inc(&rdev->nr_pending); |
| 4137 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4138 | raid_bio->bi_next = (void*)rdev; |
| 4139 | align_bi->bi_bdev = rdev->bdev; |
| 4140 | align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4141 | |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4142 | if (!bio_fits_rdev(align_bi) || |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 4143 | is_badblock(rdev, align_bi->bi_sector, bio_sectors(align_bi), |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4144 | &first_bad, &bad_sectors)) { |
| 4145 | /* too big in some way, or has a known bad block */ |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4146 | bio_put(align_bi); |
| 4147 | rdev_dec_pending(rdev, mddev); |
| 4148 | return 0; |
| 4149 | } |
| 4150 | |
majianpeng | 6c0544e | 2012-06-12 08:31:10 +0800 | [diff] [blame] | 4151 | /* No reshape active, so we can trust rdev->data_offset */ |
| 4152 | align_bi->bi_sector += rdev->data_offset; |
| 4153 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4154 | spin_lock_irq(&conf->device_lock); |
| 4155 | wait_event_lock_irq(conf->wait_for_stripe, |
| 4156 | conf->quiesce == 0, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 4157 | conf->device_lock); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4158 | atomic_inc(&conf->active_aligned_reads); |
| 4159 | spin_unlock_irq(&conf->device_lock); |
| 4160 | |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 4161 | if (mddev->gendisk) |
| 4162 | trace_block_bio_remap(bdev_get_queue(align_bi->bi_bdev), |
| 4163 | align_bi, disk_devt(mddev->gendisk), |
| 4164 | raid_bio->bi_sector); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4165 | generic_make_request(align_bi); |
| 4166 | return 1; |
| 4167 | } else { |
| 4168 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4169 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4170 | return 0; |
| 4171 | } |
| 4172 | } |
| 4173 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4174 | /* __get_priority_stripe - get the next stripe to process |
| 4175 | * |
| 4176 | * Full stripe writes are allowed to pass preread active stripes up until |
| 4177 | * the bypass_threshold is exceeded. In general the bypass_count |
| 4178 | * increments when the handle_list is handled before the hold_list; however, it |
| 4179 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 4180 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 4181 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 4182 | * handle_list. |
| 4183 | */ |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4184 | static struct stripe_head *__get_priority_stripe(struct r5conf *conf, int group) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4185 | { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4186 | struct stripe_head *sh = NULL, *tmp; |
| 4187 | struct list_head *handle_list = NULL; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 4188 | struct r5worker_group *wg = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4189 | |
| 4190 | if (conf->worker_cnt_per_group == 0) { |
| 4191 | handle_list = &conf->handle_list; |
| 4192 | } else if (group != ANY_GROUP) { |
| 4193 | handle_list = &conf->worker_groups[group].handle_list; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 4194 | wg = &conf->worker_groups[group]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4195 | } else { |
| 4196 | int i; |
| 4197 | for (i = 0; i < conf->group_cnt; i++) { |
| 4198 | handle_list = &conf->worker_groups[i].handle_list; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 4199 | wg = &conf->worker_groups[i]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4200 | if (!list_empty(handle_list)) |
| 4201 | break; |
| 4202 | } |
| 4203 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4204 | |
| 4205 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 4206 | __func__, |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4207 | list_empty(handle_list) ? "empty" : "busy", |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4208 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 4209 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 4210 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4211 | if (!list_empty(handle_list)) { |
| 4212 | sh = list_entry(handle_list->next, typeof(*sh), lru); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4213 | |
| 4214 | if (list_empty(&conf->hold_list)) |
| 4215 | conf->bypass_count = 0; |
| 4216 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 4217 | if (conf->hold_list.next == conf->last_hold) |
| 4218 | conf->bypass_count++; |
| 4219 | else { |
| 4220 | conf->last_hold = conf->hold_list.next; |
| 4221 | conf->bypass_count -= conf->bypass_threshold; |
| 4222 | if (conf->bypass_count < 0) |
| 4223 | conf->bypass_count = 0; |
| 4224 | } |
| 4225 | } |
| 4226 | } else if (!list_empty(&conf->hold_list) && |
| 4227 | ((conf->bypass_threshold && |
| 4228 | conf->bypass_count > conf->bypass_threshold) || |
| 4229 | atomic_read(&conf->pending_full_writes) == 0)) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4230 | |
| 4231 | list_for_each_entry(tmp, &conf->hold_list, lru) { |
| 4232 | if (conf->worker_cnt_per_group == 0 || |
| 4233 | group == ANY_GROUP || |
| 4234 | !cpu_online(tmp->cpu) || |
| 4235 | cpu_to_group(tmp->cpu) == group) { |
| 4236 | sh = tmp; |
| 4237 | break; |
| 4238 | } |
| 4239 | } |
| 4240 | |
| 4241 | if (sh) { |
| 4242 | conf->bypass_count -= conf->bypass_threshold; |
| 4243 | if (conf->bypass_count < 0) |
| 4244 | conf->bypass_count = 0; |
| 4245 | } |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 4246 | wg = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | if (!sh) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4250 | return NULL; |
| 4251 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 4252 | if (wg) { |
| 4253 | wg->stripes_cnt--; |
| 4254 | sh->group = NULL; |
| 4255 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4256 | list_del_init(&sh->lru); |
| 4257 | atomic_inc(&sh->count); |
| 4258 | BUG_ON(atomic_read(&sh->count) != 1); |
| 4259 | return sh; |
| 4260 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 4261 | |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4262 | struct raid5_plug_cb { |
| 4263 | struct blk_plug_cb cb; |
| 4264 | struct list_head list; |
| 4265 | }; |
| 4266 | |
| 4267 | static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule) |
| 4268 | { |
| 4269 | struct raid5_plug_cb *cb = container_of( |
| 4270 | blk_cb, struct raid5_plug_cb, cb); |
| 4271 | struct stripe_head *sh; |
| 4272 | struct mddev *mddev = cb->cb.data; |
| 4273 | struct r5conf *conf = mddev->private; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4274 | int cnt = 0; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4275 | |
| 4276 | if (cb->list.next && !list_empty(&cb->list)) { |
| 4277 | spin_lock_irq(&conf->device_lock); |
| 4278 | while (!list_empty(&cb->list)) { |
| 4279 | sh = list_first_entry(&cb->list, struct stripe_head, lru); |
| 4280 | list_del_init(&sh->lru); |
| 4281 | /* |
| 4282 | * avoid race release_stripe_plug() sees |
| 4283 | * STRIPE_ON_UNPLUG_LIST clear but the stripe |
| 4284 | * is still in our list |
| 4285 | */ |
| 4286 | smp_mb__before_clear_bit(); |
| 4287 | clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 4288 | /* |
| 4289 | * STRIPE_ON_RELEASE_LIST could be set here. In that |
| 4290 | * case, the count is always > 1 here |
| 4291 | */ |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4292 | __release_stripe(conf, sh); |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4293 | cnt++; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4294 | } |
| 4295 | spin_unlock_irq(&conf->device_lock); |
| 4296 | } |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 4297 | if (mddev->queue) |
| 4298 | trace_block_unplug(mddev->queue, cnt, !from_schedule); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4299 | kfree(cb); |
| 4300 | } |
| 4301 | |
| 4302 | static void release_stripe_plug(struct mddev *mddev, |
| 4303 | struct stripe_head *sh) |
| 4304 | { |
| 4305 | struct blk_plug_cb *blk_cb = blk_check_plugged( |
| 4306 | raid5_unplug, mddev, |
| 4307 | sizeof(struct raid5_plug_cb)); |
| 4308 | struct raid5_plug_cb *cb; |
| 4309 | |
| 4310 | if (!blk_cb) { |
| 4311 | release_stripe(sh); |
| 4312 | return; |
| 4313 | } |
| 4314 | |
| 4315 | cb = container_of(blk_cb, struct raid5_plug_cb, cb); |
| 4316 | |
| 4317 | if (cb->list.next == NULL) |
| 4318 | INIT_LIST_HEAD(&cb->list); |
| 4319 | |
| 4320 | if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) |
| 4321 | list_add_tail(&sh->lru, &cb->list); |
| 4322 | else |
| 4323 | release_stripe(sh); |
| 4324 | } |
| 4325 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4326 | static void make_discard_request(struct mddev *mddev, struct bio *bi) |
| 4327 | { |
| 4328 | struct r5conf *conf = mddev->private; |
| 4329 | sector_t logical_sector, last_sector; |
| 4330 | struct stripe_head *sh; |
| 4331 | int remaining; |
| 4332 | int stripe_sectors; |
| 4333 | |
| 4334 | if (mddev->reshape_position != MaxSector) |
| 4335 | /* Skip discard while reshape is happening */ |
| 4336 | return; |
| 4337 | |
| 4338 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 4339 | last_sector = bi->bi_sector + (bi->bi_size>>9); |
| 4340 | |
| 4341 | bi->bi_next = NULL; |
| 4342 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
| 4343 | |
| 4344 | stripe_sectors = conf->chunk_sectors * |
| 4345 | (conf->raid_disks - conf->max_degraded); |
| 4346 | logical_sector = DIV_ROUND_UP_SECTOR_T(logical_sector, |
| 4347 | stripe_sectors); |
| 4348 | sector_div(last_sector, stripe_sectors); |
| 4349 | |
| 4350 | logical_sector *= conf->chunk_sectors; |
| 4351 | last_sector *= conf->chunk_sectors; |
| 4352 | |
| 4353 | for (; logical_sector < last_sector; |
| 4354 | logical_sector += STRIPE_SECTORS) { |
| 4355 | DEFINE_WAIT(w); |
| 4356 | int d; |
| 4357 | again: |
| 4358 | sh = get_active_stripe(conf, logical_sector, 0, 0, 0); |
| 4359 | prepare_to_wait(&conf->wait_for_overlap, &w, |
| 4360 | TASK_UNINTERRUPTIBLE); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4361 | set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
| 4362 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 4363 | release_stripe(sh); |
| 4364 | schedule(); |
| 4365 | goto again; |
| 4366 | } |
| 4367 | clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4368 | spin_lock_irq(&sh->stripe_lock); |
| 4369 | for (d = 0; d < conf->raid_disks; d++) { |
| 4370 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 4371 | continue; |
| 4372 | if (sh->dev[d].towrite || sh->dev[d].toread) { |
| 4373 | set_bit(R5_Overlap, &sh->dev[d].flags); |
| 4374 | spin_unlock_irq(&sh->stripe_lock); |
| 4375 | release_stripe(sh); |
| 4376 | schedule(); |
| 4377 | goto again; |
| 4378 | } |
| 4379 | } |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4380 | set_bit(STRIPE_DISCARD, &sh->state); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4381 | finish_wait(&conf->wait_for_overlap, &w); |
| 4382 | for (d = 0; d < conf->raid_disks; d++) { |
| 4383 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 4384 | continue; |
| 4385 | sh->dev[d].towrite = bi; |
| 4386 | set_bit(R5_OVERWRITE, &sh->dev[d].flags); |
| 4387 | raid5_inc_bi_active_stripes(bi); |
| 4388 | } |
| 4389 | spin_unlock_irq(&sh->stripe_lock); |
| 4390 | if (conf->mddev->bitmap) { |
| 4391 | for (d = 0; |
| 4392 | d < conf->raid_disks - conf->max_degraded; |
| 4393 | d++) |
| 4394 | bitmap_startwrite(mddev->bitmap, |
| 4395 | sh->sector, |
| 4396 | STRIPE_SECTORS, |
| 4397 | 0); |
| 4398 | sh->bm_seq = conf->seq_flush + 1; |
| 4399 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 4400 | } |
| 4401 | |
| 4402 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4403 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 4404 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4405 | atomic_inc(&conf->preread_active_stripes); |
| 4406 | release_stripe_plug(mddev, sh); |
| 4407 | } |
| 4408 | |
| 4409 | remaining = raid5_dec_bi_active_stripes(bi); |
| 4410 | if (remaining == 0) { |
| 4411 | md_write_end(mddev); |
| 4412 | bio_endio(bi, 0); |
| 4413 | } |
| 4414 | } |
| 4415 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame] | 4416 | static void make_request(struct mddev *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4418 | struct r5conf *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4419 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | sector_t new_sector; |
| 4421 | sector_t logical_sector, last_sector; |
| 4422 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 4423 | const int rw = bio_data_dir(bi); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 4424 | int remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 4426 | if (unlikely(bi->bi_rw & REQ_FLUSH)) { |
| 4427 | md_flush_request(mddev, bi); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 4428 | return; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 4431 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 4432 | |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 4433 | if (rw == READ && |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 4434 | mddev->reshape_position == MaxSector && |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 4435 | chunk_aligned_read(mddev,bi)) |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 4436 | return; |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 4437 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 4438 | if (unlikely(bi->bi_rw & REQ_DISCARD)) { |
| 4439 | make_discard_request(mddev, bi); |
| 4440 | return; |
| 4441 | } |
| 4442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 4444 | last_sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | bi->bi_next = NULL; |
| 4446 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 4447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
| 4449 | DEFINE_WAIT(w); |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4450 | int previous; |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 4451 | int seq; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 4452 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4453 | retry: |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 4454 | seq = read_seqcount_begin(&conf->gen_lock); |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4455 | previous = 0; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 4456 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4457 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4458 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 4459 | * 64bit on a 32bit platform, and so it might be |
| 4460 | * possible to see a half-updated value |
Jesper Juhl | aeb878b | 2011-04-10 18:06:17 +0200 | [diff] [blame] | 4461 | * Of course reshape_progress could change after |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 4462 | * the lock is dropped, so once we get a reference |
| 4463 | * to the stripe that we think it is, we will have |
| 4464 | * to check again. |
| 4465 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4466 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4467 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4468 | ? logical_sector < conf->reshape_progress |
| 4469 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4470 | previous = 1; |
| 4471 | } else { |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4472 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4473 | ? logical_sector < conf->reshape_safe |
| 4474 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 4475 | spin_unlock_irq(&conf->device_lock); |
| 4476 | schedule(); |
| 4477 | goto retry; |
| 4478 | } |
| 4479 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4480 | spin_unlock_irq(&conf->device_lock); |
| 4481 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4482 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4483 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 4484 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4485 | &dd_idx, NULL); |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4486 | pr_debug("raid456: make_request, sector %llu logical %llu\n", |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 4487 | (unsigned long long)new_sector, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | (unsigned long long)logical_sector); |
| 4489 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4490 | sh = get_active_stripe(conf, new_sector, previous, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4491 | (bi->bi_rw&RWA_MASK), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4493 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4494 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 4495 | * stripe, so we must do the range check again. |
| 4496 | * Expansion could still move past after this |
| 4497 | * test, but as we are holding a reference to |
| 4498 | * 'sh', we know that if that happens, |
| 4499 | * STRIPE_EXPANDING will get set and the expansion |
| 4500 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4501 | */ |
| 4502 | int must_retry = 0; |
| 4503 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4504 | if (mddev->reshape_backwards |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4505 | ? logical_sector >= conf->reshape_progress |
| 4506 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4507 | /* mismatch, need to try again */ |
| 4508 | must_retry = 1; |
| 4509 | spin_unlock_irq(&conf->device_lock); |
| 4510 | if (must_retry) { |
| 4511 | release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 4512 | schedule(); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4513 | goto retry; |
| 4514 | } |
| 4515 | } |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 4516 | if (read_seqcount_retry(&conf->gen_lock, seq)) { |
| 4517 | /* Might have got the wrong stripe_head |
| 4518 | * by accident |
| 4519 | */ |
| 4520 | release_stripe(sh); |
| 4521 | goto retry; |
| 4522 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4523 | |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 4524 | if (rw == WRITE && |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4525 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4526 | logical_sector < mddev->suspend_hi) { |
| 4527 | release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4528 | /* As the suspend_* range is controlled by |
| 4529 | * userspace, we want an interruptible |
| 4530 | * wait. |
| 4531 | */ |
| 4532 | flush_signals(current); |
| 4533 | prepare_to_wait(&conf->wait_for_overlap, |
| 4534 | &w, TASK_INTERRUPTIBLE); |
| 4535 | if (logical_sector >= mddev->suspend_lo && |
| 4536 | logical_sector < mddev->suspend_hi) |
| 4537 | schedule(); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4538 | goto retry; |
| 4539 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4540 | |
| 4541 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 4542 | !add_stripe_bio(sh, bi, dd_idx, rw)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4543 | /* Stripe is busy expanding or |
| 4544 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | * and wait a while |
| 4546 | */ |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 4547 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | release_stripe(sh); |
| 4549 | schedule(); |
| 4550 | goto retry; |
| 4551 | } |
| 4552 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4553 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4554 | clear_bit(STRIPE_DELAYED, &sh->state); |
NeilBrown | a852d7b | 2012-09-19 12:48:30 +1000 | [diff] [blame] | 4555 | if ((bi->bi_rw & REQ_SYNC) && |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4556 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4557 | atomic_inc(&conf->preread_active_stripes); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 4558 | release_stripe_plug(mddev, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | } else { |
| 4560 | /* cannot get stripe for read-ahead, just give-up */ |
| 4561 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
| 4562 | finish_wait(&conf->wait_for_overlap, &w); |
| 4563 | break; |
| 4564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | } |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4566 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4567 | remaining = raid5_dec_bi_active_stripes(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 4568 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4570 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4572 | |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4573 | trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), |
| 4574 | bi, 0); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4575 | bio_endio(bi, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4579 | 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] | 4580 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4581 | 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] | 4582 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4583 | /* reshaping is quite different to recovery/resync so it is |
| 4584 | * handled quite separately ... here. |
| 4585 | * |
| 4586 | * On each call to sync_request, we gather one chunk worth of |
| 4587 | * destination stripes and flag them as expanding. |
| 4588 | * Then we find all the source stripes and request reads. |
| 4589 | * As the reads complete, handle_stripe will copy the data |
| 4590 | * into the destination stripe and release that stripe. |
| 4591 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4592 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4594 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4595 | int raid_disks = conf->previous_raid_disks; |
| 4596 | int data_disks = raid_disks - conf->max_degraded; |
| 4597 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4598 | int i; |
| 4599 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4600 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4601 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4602 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4603 | struct list_head stripes; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4604 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4605 | if (sector_nr == 0) { |
| 4606 | /* If restarting in the middle, skip the initial sectors */ |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4607 | if (mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4608 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 4609 | sector_nr = raid5_size(mddev, 0, 0) |
| 4610 | - conf->reshape_progress; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4611 | } else if (!mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4612 | conf->reshape_progress > 0) |
| 4613 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4614 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4615 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 4616 | mddev->curr_resync_completed = sector_nr; |
| 4617 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4618 | *skipped = 1; |
| 4619 | return sector_nr; |
| 4620 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4621 | } |
| 4622 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4623 | /* We need to process a full chunk at a time. |
| 4624 | * If old and new chunk sizes differ, we need to process the |
| 4625 | * largest of these |
| 4626 | */ |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4627 | if (mddev->new_chunk_sectors > mddev->chunk_sectors) |
| 4628 | reshape_sectors = mddev->new_chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4629 | else |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4630 | reshape_sectors = mddev->chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4631 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4632 | /* We update the metadata at least every 10 seconds, or when |
| 4633 | * the data about to be copied would over-write the source of |
| 4634 | * the data at the front of the range. i.e. one new_stripe |
| 4635 | * along from reshape_progress new_maps to after where |
| 4636 | * reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4637 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4638 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4639 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4640 | readpos = conf->reshape_progress; |
| 4641 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4642 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4643 | sector_div(safepos, data_disks); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4644 | if (mddev->reshape_backwards) { |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4645 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4646 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4647 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4648 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4649 | writepos += reshape_sectors; |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4650 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 4651 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4652 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4653 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4654 | /* Having calculated the 'writepos' possibly use it |
| 4655 | * to set 'stripe_addr' which is where we will write to. |
| 4656 | */ |
| 4657 | if (mddev->reshape_backwards) { |
| 4658 | BUG_ON(conf->reshape_progress == 0); |
| 4659 | stripe_addr = writepos; |
| 4660 | BUG_ON((mddev->dev_sectors & |
| 4661 | ~((sector_t)reshape_sectors - 1)) |
| 4662 | - reshape_sectors - stripe_addr |
| 4663 | != sector_nr); |
| 4664 | } else { |
| 4665 | BUG_ON(writepos != sector_nr + reshape_sectors); |
| 4666 | stripe_addr = sector_nr; |
| 4667 | } |
| 4668 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4669 | /* 'writepos' is the most advanced device address we might write. |
| 4670 | * 'readpos' is the least advanced device address we might read. |
| 4671 | * 'safepos' is the least address recorded in the metadata as having |
| 4672 | * been reshaped. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4673 | * If there is a min_offset_diff, these are adjusted either by |
| 4674 | * increasing the safepos/readpos if diff is negative, or |
| 4675 | * increasing writepos if diff is positive. |
| 4676 | * If 'readpos' is then behind 'writepos', there is no way that we can |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4677 | * ensure safety in the face of a crash - that must be done by userspace |
| 4678 | * making a backup of the data. So in that case there is no particular |
| 4679 | * rush to update metadata. |
| 4680 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 4681 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 4682 | * we can be safe in the event of a crash. |
| 4683 | * So we insist on updating metadata if safepos is behind writepos and |
| 4684 | * readpos is beyond writepos. |
| 4685 | * In any case, update the metadata every 10 seconds. |
| 4686 | * Maybe that number should be configurable, but I'm not sure it is |
| 4687 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 4688 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 4689 | if (conf->min_offset_diff < 0) { |
| 4690 | safepos += -conf->min_offset_diff; |
| 4691 | readpos += -conf->min_offset_diff; |
| 4692 | } else |
| 4693 | writepos += conf->min_offset_diff; |
| 4694 | |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4695 | if ((mddev->reshape_backwards |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4696 | ? (safepos > writepos && readpos < writepos) |
| 4697 | : (safepos < writepos && readpos > writepos)) || |
| 4698 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4699 | /* Cannot proceed until we've updated the superblock... */ |
| 4700 | wait_event(conf->wait_for_overlap, |
| 4701 | atomic_read(&conf->reshape_stripes)==0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4702 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4703 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4704 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4705 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4706 | md_wakeup_thread(mddev->thread); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4707 | wait_event(mddev->sb_wait, mddev->flags == 0 || |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4708 | kthread_should_stop()); |
| 4709 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4710 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4711 | spin_unlock_irq(&conf->device_lock); |
| 4712 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4713 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4714 | } |
| 4715 | |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4716 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4717 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4718 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4719 | int skipped_disk = 0; |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4720 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4721 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 4722 | atomic_inc(&conf->reshape_stripes); |
| 4723 | /* If any of this stripe is beyond the end of the old |
| 4724 | * array, then we need to zero those blocks |
| 4725 | */ |
| 4726 | for (j=sh->disks; j--;) { |
| 4727 | sector_t s; |
| 4728 | if (j == sh->pd_idx) |
| 4729 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4730 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4731 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4732 | continue; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 4733 | s = compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4734 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4735 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4736 | continue; |
| 4737 | } |
| 4738 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 4739 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 4740 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 4741 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4742 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4743 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4744 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4745 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4746 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4747 | } |
| 4748 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4749 | if (mddev->reshape_backwards) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4750 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4751 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4752 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4753 | spin_unlock_irq(&conf->device_lock); |
| 4754 | /* Ok, those stripe are ready. We can start scheduling |
| 4755 | * reads on the source stripes. |
| 4756 | * The source stripes are determined by mapping the first and last |
| 4757 | * block on the destination stripes. |
| 4758 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4759 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4760 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4761 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4762 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 4763 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4764 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4765 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4766 | if (last_sector >= mddev->dev_sectors) |
| 4767 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4768 | while (first_sector <= last_sector) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4769 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4770 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4771 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4772 | release_stripe(sh); |
| 4773 | first_sector += STRIPE_SECTORS; |
| 4774 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4775 | /* Now that the sources are clearly marked, we can release |
| 4776 | * the destination stripes |
| 4777 | */ |
| 4778 | while (!list_empty(&stripes)) { |
| 4779 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 4780 | list_del_init(&sh->lru); |
| 4781 | release_stripe(sh); |
| 4782 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4783 | /* If this takes us to the resync_max point where we have to pause, |
| 4784 | * then we need to write out the superblock. |
| 4785 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4786 | sector_nr += reshape_sectors; |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 4787 | if ((sector_nr - mddev->curr_resync_completed) * 2 |
| 4788 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4789 | /* Cannot proceed until we've updated the superblock... */ |
| 4790 | wait_event(conf->wait_for_overlap, |
| 4791 | atomic_read(&conf->reshape_stripes) == 0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4792 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4793 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4794 | conf->reshape_checkpoint = jiffies; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4795 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 4796 | md_wakeup_thread(mddev->thread); |
| 4797 | wait_event(mddev->sb_wait, |
| 4798 | !test_bit(MD_CHANGE_DEVS, &mddev->flags) |
| 4799 | || kthread_should_stop()); |
| 4800 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4801 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4802 | spin_unlock_irq(&conf->device_lock); |
| 4803 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4804 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4805 | } |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4806 | return reshape_sectors; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | /* FIXME go_faster isn't used */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4810 | 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] | 4811 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4812 | struct r5conf *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4813 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4814 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 4815 | sector_t sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4816 | int still_degraded = 0; |
| 4817 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4819 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | /* just being told to finish up .. nothing much to do */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 4821 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 4822 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 4823 | end_reshape(conf); |
| 4824 | return 0; |
| 4825 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4826 | |
| 4827 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 4828 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 4829 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4830 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4831 | conf->fullsync = 0; |
| 4832 | bitmap_close_sync(mddev->bitmap); |
| 4833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | return 0; |
| 4835 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4836 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4837 | /* Allow raid5_quiesce to complete */ |
| 4838 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 4839 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4840 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 4841 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4842 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4843 | /* No need to check resync_max as we never do more than one |
| 4844 | * stripe, and as resync_max will always be on a chunk boundary, |
| 4845 | * if the check in md_do_sync didn't fire, there is no chance |
| 4846 | * of overstepping resync_max here |
| 4847 | */ |
| 4848 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4849 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | * to resync, then assert that we are finished, because there is |
| 4851 | * nothing we can do. |
| 4852 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 4853 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4854 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4855 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 4856 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | return rv; |
| 4858 | } |
majianpeng | 6f60804 | 2013-04-24 11:42:41 +1000 | [diff] [blame] | 4859 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
| 4860 | !conf->fullsync && |
| 4861 | !bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
| 4862 | sync_blocks >= STRIPE_SECTORS) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4863 | /* we can skip this block, and probably more */ |
| 4864 | sync_blocks /= STRIPE_SECTORS; |
| 4865 | *skipped = 1; |
| 4866 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 4867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 4869 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 4870 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4871 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | if (sh == NULL) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4873 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4875 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 4877 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4879 | /* Need to check if array will still be degraded after recovery/resync |
| 4880 | * We don't need to check the 'failed' flag as when that gets set, |
| 4881 | * recovery aborts. |
| 4882 | */ |
NeilBrown | f001a70 | 2009-06-09 14:30:31 +1000 | [diff] [blame] | 4883 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4884 | if (conf->disks[i].rdev == NULL) |
| 4885 | still_degraded = 1; |
| 4886 | |
| 4887 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 4888 | |
NeilBrown | 83206d6 | 2011-07-26 11:19:49 +1000 | [diff] [blame] | 4889 | set_bit(STRIPE_SYNC_REQUESTED, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 4891 | handle_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | release_stripe(sh); |
| 4893 | |
| 4894 | return STRIPE_SECTORS; |
| 4895 | } |
| 4896 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4897 | 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] | 4898 | { |
| 4899 | /* We may not be able to submit a whole bio at once as there |
| 4900 | * may not be enough stripe_heads available. |
| 4901 | * We cannot pre-allocate enough stripe_heads as we may need |
| 4902 | * more than exist in the cache (if we allow ever large chunks). |
| 4903 | * So we do one stripe head at a time and record in |
| 4904 | * ->bi_hw_segments how many have been done. |
| 4905 | * |
| 4906 | * We *know* that this entire raid_bio is in one chunk, so |
| 4907 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 4908 | */ |
| 4909 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4910 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4911 | sector_t sector, logical_sector, last_sector; |
| 4912 | int scnt = 0; |
| 4913 | int remaining; |
| 4914 | int handled = 0; |
| 4915 | |
| 4916 | logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4917 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4918 | 0, &dd_idx, NULL); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 4919 | last_sector = bio_end_sector(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4920 | |
| 4921 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4922 | logical_sector += STRIPE_SECTORS, |
| 4923 | sector += STRIPE_SECTORS, |
| 4924 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4925 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4926 | if (scnt < raid5_bi_processed_stripes(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4927 | /* already done this stripe */ |
| 4928 | continue; |
| 4929 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4930 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4931 | |
| 4932 | if (!sh) { |
| 4933 | /* failed to get a stripe - must wait */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4934 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4935 | conf->retry_read_aligned = raid_bio; |
| 4936 | return handled; |
| 4937 | } |
| 4938 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4939 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
| 4940 | release_stripe(sh); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4941 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4942 | conf->retry_read_aligned = raid_bio; |
| 4943 | return handled; |
| 4944 | } |
| 4945 | |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 4946 | set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4947 | handle_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4948 | release_stripe(sh); |
| 4949 | handled++; |
| 4950 | } |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 4951 | remaining = raid5_dec_bi_active_stripes(raid_bio); |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4952 | if (remaining == 0) { |
| 4953 | trace_block_bio_complete(bdev_get_queue(raid_bio->bi_bdev), |
| 4954 | raid_bio, 0); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4955 | bio_endio(raid_bio, 0); |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 4956 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4957 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4958 | wake_up(&conf->wait_for_stripe); |
| 4959 | return handled; |
| 4960 | } |
| 4961 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 4962 | static int handle_active_stripes(struct r5conf *conf, int group, |
| 4963 | struct r5worker *worker) |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4964 | { |
| 4965 | struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; |
| 4966 | int i, batch_size = 0; |
| 4967 | |
| 4968 | while (batch_size < MAX_STRIPE_BATCH && |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4969 | (sh = __get_priority_stripe(conf, group)) != NULL) |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 4970 | batch[batch_size++] = sh; |
| 4971 | |
| 4972 | if (batch_size == 0) |
| 4973 | return batch_size; |
| 4974 | spin_unlock_irq(&conf->device_lock); |
| 4975 | |
| 4976 | for (i = 0; i < batch_size; i++) |
| 4977 | handle_stripe(batch[i]); |
| 4978 | |
| 4979 | cond_resched(); |
| 4980 | |
| 4981 | spin_lock_irq(&conf->device_lock); |
| 4982 | for (i = 0; i < batch_size; i++) |
| 4983 | __release_stripe(conf, batch[i]); |
| 4984 | return batch_size; |
| 4985 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4986 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 4987 | static void raid5_do_work(struct work_struct *work) |
| 4988 | { |
| 4989 | struct r5worker *worker = container_of(work, struct r5worker, work); |
| 4990 | struct r5worker_group *group = worker->group; |
| 4991 | struct r5conf *conf = group->conf; |
| 4992 | int group_id = group - conf->worker_groups; |
| 4993 | int handled; |
| 4994 | struct blk_plug plug; |
| 4995 | |
| 4996 | pr_debug("+++ raid5worker active\n"); |
| 4997 | |
| 4998 | blk_start_plug(&plug); |
| 4999 | handled = 0; |
| 5000 | spin_lock_irq(&conf->device_lock); |
| 5001 | while (1) { |
| 5002 | int batch_size, released; |
| 5003 | |
| 5004 | released = release_stripe_list(conf); |
| 5005 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5006 | batch_size = handle_active_stripes(conf, group_id, worker); |
| 5007 | worker->working = false; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5008 | if (!batch_size && !released) |
| 5009 | break; |
| 5010 | handled += batch_size; |
| 5011 | } |
| 5012 | pr_debug("%d stripes handled\n", handled); |
| 5013 | |
| 5014 | spin_unlock_irq(&conf->device_lock); |
| 5015 | blk_finish_plug(&plug); |
| 5016 | |
| 5017 | pr_debug("--- raid5worker inactive\n"); |
| 5018 | } |
| 5019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | /* |
| 5021 | * This is our raid5 kernel thread. |
| 5022 | * |
| 5023 | * We scan the hash table for stripes which can be handled now. |
| 5024 | * During the scan, completed stripes are saved for us by the interrupt |
| 5025 | * handler, so that they will not have to wait for our next wakeup. |
| 5026 | */ |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 5027 | static void raid5d(struct md_thread *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 | { |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 5029 | struct mddev *mddev = thread->mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5030 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | int handled; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 5032 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5034 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | |
| 5036 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 5038 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | handled = 0; |
| 5040 | spin_lock_irq(&conf->device_lock); |
| 5041 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5042 | struct bio *bio; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 5043 | int batch_size, released; |
| 5044 | |
| 5045 | released = release_stripe_list(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 5047 | if ( |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 5048 | !list_empty(&conf->bitmap_list)) { |
| 5049 | /* Now is a good time to flush some bitmap updates */ |
| 5050 | conf->seq_flush++; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 5051 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5052 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 5053 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 5054 | conf->seq_write = conf->seq_flush; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5055 | activate_bit_delay(conf); |
| 5056 | } |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 5057 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5058 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5059 | while ((bio = remove_bio_from_retry(conf))) { |
| 5060 | int ok; |
| 5061 | spin_unlock_irq(&conf->device_lock); |
| 5062 | ok = retry_aligned_read(conf, bio); |
| 5063 | spin_lock_irq(&conf->device_lock); |
| 5064 | if (!ok) |
| 5065 | break; |
| 5066 | handled++; |
| 5067 | } |
| 5068 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5069 | batch_size = handle_active_stripes(conf, ANY_GROUP, NULL); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 5070 | if (!batch_size && !released) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | break; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 5072 | handled += batch_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 5074 | if (mddev->flags & ~(1<<MD_CHANGE_PENDING)) { |
| 5075 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 5076 | md_check_recovery(mddev); |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 5077 | spin_lock_irq(&conf->device_lock); |
| 5078 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5080 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | |
| 5082 | spin_unlock_irq(&conf->device_lock); |
| 5083 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 5084 | async_tx_issue_pending_all(); |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 5085 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5087 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5090 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5091 | raid5_show_stripe_cache_size(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5092 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5093 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 5094 | if (conf) |
| 5095 | return sprintf(page, "%d\n", conf->max_nr_stripes); |
| 5096 | else |
| 5097 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5098 | } |
| 5099 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 5100 | int |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5101 | raid5_set_cache_size(struct mddev *mddev, int size) |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 5102 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5103 | struct r5conf *conf = mddev->private; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 5104 | int err; |
| 5105 | |
| 5106 | if (size <= 16 || size > 32768) |
| 5107 | return -EINVAL; |
| 5108 | while (size < conf->max_nr_stripes) { |
| 5109 | if (drop_one_stripe(conf)) |
| 5110 | conf->max_nr_stripes--; |
| 5111 | else |
| 5112 | break; |
| 5113 | } |
| 5114 | err = md_allow_write(mddev); |
| 5115 | if (err) |
| 5116 | return err; |
| 5117 | while (size > conf->max_nr_stripes) { |
| 5118 | if (grow_one_stripe(conf)) |
| 5119 | conf->max_nr_stripes++; |
| 5120 | else break; |
| 5121 | } |
| 5122 | return 0; |
| 5123 | } |
| 5124 | EXPORT_SYMBOL(raid5_set_cache_size); |
| 5125 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5126 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5127 | 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] | 5128 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5129 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 5130 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5131 | int err; |
| 5132 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5133 | if (len >= PAGE_SIZE) |
| 5134 | return -EINVAL; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 5135 | if (!conf) |
| 5136 | return -ENODEV; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5137 | |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 5138 | if (kstrtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5139 | return -EINVAL; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 5140 | err = raid5_set_cache_size(mddev, new); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 5141 | if (err) |
| 5142 | return err; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5143 | return len; |
| 5144 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 5145 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 5146 | static struct md_sysfs_entry |
| 5147 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 5148 | raid5_show_stripe_cache_size, |
| 5149 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5150 | |
| 5151 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5152 | raid5_show_preread_threshold(struct mddev *mddev, char *page) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5153 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5154 | struct r5conf *conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5155 | if (conf) |
| 5156 | return sprintf(page, "%d\n", conf->bypass_threshold); |
| 5157 | else |
| 5158 | return 0; |
| 5159 | } |
| 5160 | |
| 5161 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5162 | 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] | 5163 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5164 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 5165 | unsigned long new; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5166 | if (len >= PAGE_SIZE) |
| 5167 | return -EINVAL; |
| 5168 | if (!conf) |
| 5169 | return -ENODEV; |
| 5170 | |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 5171 | if (kstrtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5172 | return -EINVAL; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 5173 | if (new > conf->max_nr_stripes) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5174 | return -EINVAL; |
| 5175 | conf->bypass_threshold = new; |
| 5176 | return len; |
| 5177 | } |
| 5178 | |
| 5179 | static struct md_sysfs_entry |
| 5180 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 5181 | S_IRUGO | S_IWUSR, |
| 5182 | raid5_show_preread_threshold, |
| 5183 | raid5_store_preread_threshold); |
| 5184 | |
| 5185 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5186 | stripe_cache_active_show(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5187 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5188 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 5189 | if (conf) |
| 5190 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 5191 | else |
| 5192 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5193 | } |
| 5194 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 5195 | static struct md_sysfs_entry |
| 5196 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5197 | |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 5198 | static ssize_t |
| 5199 | raid5_show_group_thread_cnt(struct mddev *mddev, char *page) |
| 5200 | { |
| 5201 | struct r5conf *conf = mddev->private; |
| 5202 | if (conf) |
| 5203 | return sprintf(page, "%d\n", conf->worker_cnt_per_group); |
| 5204 | else |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
| 5208 | static int alloc_thread_groups(struct r5conf *conf, int cnt); |
| 5209 | static ssize_t |
| 5210 | raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) |
| 5211 | { |
| 5212 | struct r5conf *conf = mddev->private; |
| 5213 | unsigned long new; |
| 5214 | int err; |
| 5215 | struct r5worker_group *old_groups; |
| 5216 | int old_group_cnt; |
| 5217 | |
| 5218 | if (len >= PAGE_SIZE) |
| 5219 | return -EINVAL; |
| 5220 | if (!conf) |
| 5221 | return -ENODEV; |
| 5222 | |
| 5223 | if (kstrtoul(page, 10, &new)) |
| 5224 | return -EINVAL; |
| 5225 | |
| 5226 | if (new == conf->worker_cnt_per_group) |
| 5227 | return len; |
| 5228 | |
| 5229 | mddev_suspend(mddev); |
| 5230 | |
| 5231 | old_groups = conf->worker_groups; |
| 5232 | old_group_cnt = conf->worker_cnt_per_group; |
| 5233 | |
| 5234 | conf->worker_groups = NULL; |
| 5235 | err = alloc_thread_groups(conf, new); |
| 5236 | if (err) { |
| 5237 | conf->worker_groups = old_groups; |
| 5238 | conf->worker_cnt_per_group = old_group_cnt; |
| 5239 | } else { |
| 5240 | if (old_groups) |
| 5241 | kfree(old_groups[0].workers); |
| 5242 | kfree(old_groups); |
| 5243 | } |
| 5244 | |
| 5245 | mddev_resume(mddev); |
| 5246 | |
| 5247 | if (err) |
| 5248 | return err; |
| 5249 | return len; |
| 5250 | } |
| 5251 | |
| 5252 | static struct md_sysfs_entry |
| 5253 | raid5_group_thread_cnt = __ATTR(group_thread_cnt, S_IRUGO | S_IWUSR, |
| 5254 | raid5_show_group_thread_cnt, |
| 5255 | raid5_store_group_thread_cnt); |
| 5256 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 5257 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5258 | &raid5_stripecache_size.attr, |
| 5259 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5260 | &raid5_preread_bypass_threshold.attr, |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 5261 | &raid5_group_thread_cnt.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5262 | NULL, |
| 5263 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 5264 | static struct attribute_group raid5_attrs_group = { |
| 5265 | .name = NULL, |
| 5266 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5267 | }; |
| 5268 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5269 | static int alloc_thread_groups(struct r5conf *conf, int cnt) |
| 5270 | { |
| 5271 | int i, j; |
| 5272 | ssize_t size; |
| 5273 | struct r5worker *workers; |
| 5274 | |
| 5275 | conf->worker_cnt_per_group = cnt; |
| 5276 | if (cnt == 0) { |
| 5277 | conf->worker_groups = NULL; |
| 5278 | return 0; |
| 5279 | } |
| 5280 | conf->group_cnt = num_possible_nodes(); |
| 5281 | size = sizeof(struct r5worker) * cnt; |
| 5282 | workers = kzalloc(size * conf->group_cnt, GFP_NOIO); |
| 5283 | conf->worker_groups = kzalloc(sizeof(struct r5worker_group) * |
| 5284 | conf->group_cnt, GFP_NOIO); |
| 5285 | if (!conf->worker_groups || !workers) { |
| 5286 | kfree(workers); |
| 5287 | kfree(conf->worker_groups); |
| 5288 | conf->worker_groups = NULL; |
| 5289 | return -ENOMEM; |
| 5290 | } |
| 5291 | |
| 5292 | for (i = 0; i < conf->group_cnt; i++) { |
| 5293 | struct r5worker_group *group; |
| 5294 | |
| 5295 | group = &conf->worker_groups[i]; |
| 5296 | INIT_LIST_HEAD(&group->handle_list); |
| 5297 | group->conf = conf; |
| 5298 | group->workers = workers + i * cnt; |
| 5299 | |
| 5300 | for (j = 0; j < cnt; j++) { |
| 5301 | group->workers[j].group = group; |
| 5302 | INIT_WORK(&group->workers[j].work, raid5_do_work); |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | return 0; |
| 5307 | } |
| 5308 | |
| 5309 | static void free_thread_groups(struct r5conf *conf) |
| 5310 | { |
| 5311 | if (conf->worker_groups) |
| 5312 | kfree(conf->worker_groups[0].workers); |
| 5313 | kfree(conf->worker_groups); |
| 5314 | conf->worker_groups = NULL; |
| 5315 | } |
| 5316 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5317 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5318 | raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5319 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5320 | struct r5conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5321 | |
| 5322 | if (!sectors) |
| 5323 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5324 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 5325 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5326 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5327 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5328 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5329 | sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5330 | return sectors * (raid_disks - conf->max_degraded); |
| 5331 | } |
| 5332 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5333 | static void raid5_free_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5334 | { |
| 5335 | struct raid5_percpu *percpu; |
| 5336 | unsigned long cpu; |
| 5337 | |
| 5338 | if (!conf->percpu) |
| 5339 | return; |
| 5340 | |
| 5341 | get_online_cpus(); |
| 5342 | for_each_possible_cpu(cpu) { |
| 5343 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 5344 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5345 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5346 | } |
| 5347 | #ifdef CONFIG_HOTPLUG_CPU |
| 5348 | unregister_cpu_notifier(&conf->cpu_notify); |
| 5349 | #endif |
| 5350 | put_online_cpus(); |
| 5351 | |
| 5352 | free_percpu(conf->percpu); |
| 5353 | } |
| 5354 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5355 | static void free_conf(struct r5conf *conf) |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5356 | { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5357 | free_thread_groups(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5358 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5359 | raid5_free_percpu(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5360 | kfree(conf->disks); |
| 5361 | kfree(conf->stripe_hashtbl); |
| 5362 | kfree(conf); |
| 5363 | } |
| 5364 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5365 | #ifdef CONFIG_HOTPLUG_CPU |
| 5366 | static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, |
| 5367 | void *hcpu) |
| 5368 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5369 | struct r5conf *conf = container_of(nfb, struct r5conf, cpu_notify); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5370 | long cpu = (long)hcpu; |
| 5371 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 5372 | |
| 5373 | switch (action) { |
| 5374 | case CPU_UP_PREPARE: |
| 5375 | case CPU_UP_PREPARE_FROZEN: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5376 | if (conf->level == 6 && !percpu->spare_page) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5377 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5378 | if (!percpu->scribble) |
| 5379 | percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
| 5380 | |
| 5381 | if (!percpu->scribble || |
| 5382 | (conf->level == 6 && !percpu->spare_page)) { |
| 5383 | safe_put_page(percpu->spare_page); |
| 5384 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5385 | pr_err("%s: failed memory allocation for cpu%ld\n", |
| 5386 | __func__, cpu); |
Akinobu Mita | 55af6bb | 2010-05-26 14:43:35 -0700 | [diff] [blame] | 5387 | return notifier_from_errno(-ENOMEM); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5388 | } |
| 5389 | break; |
| 5390 | case CPU_DEAD: |
| 5391 | case CPU_DEAD_FROZEN: |
| 5392 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5393 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5394 | percpu->spare_page = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5395 | percpu->scribble = NULL; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5396 | break; |
| 5397 | default: |
| 5398 | break; |
| 5399 | } |
| 5400 | return NOTIFY_OK; |
| 5401 | } |
| 5402 | #endif |
| 5403 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5404 | static int raid5_alloc_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5405 | { |
| 5406 | unsigned long cpu; |
| 5407 | struct page *spare_page; |
Tejun Heo | a29d8b8 | 2010-02-02 14:39:15 +0900 | [diff] [blame] | 5408 | struct raid5_percpu __percpu *allcpus; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5409 | void *scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5410 | int err; |
| 5411 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5412 | allcpus = alloc_percpu(struct raid5_percpu); |
| 5413 | if (!allcpus) |
| 5414 | return -ENOMEM; |
| 5415 | conf->percpu = allcpus; |
| 5416 | |
| 5417 | get_online_cpus(); |
| 5418 | err = 0; |
| 5419 | for_each_present_cpu(cpu) { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5420 | if (conf->level == 6) { |
| 5421 | spare_page = alloc_page(GFP_KERNEL); |
| 5422 | if (!spare_page) { |
| 5423 | err = -ENOMEM; |
| 5424 | break; |
| 5425 | } |
| 5426 | per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page; |
| 5427 | } |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5428 | scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5429 | if (!scribble) { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5430 | err = -ENOMEM; |
| 5431 | break; |
| 5432 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 5433 | per_cpu_ptr(conf->percpu, cpu)->scribble = scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5434 | } |
| 5435 | #ifdef CONFIG_HOTPLUG_CPU |
| 5436 | conf->cpu_notify.notifier_call = raid456_cpu_notify; |
| 5437 | conf->cpu_notify.priority = 0; |
| 5438 | if (err == 0) |
| 5439 | err = register_cpu_notifier(&conf->cpu_notify); |
| 5440 | #endif |
| 5441 | put_online_cpus(); |
| 5442 | |
| 5443 | return err; |
| 5444 | } |
| 5445 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5446 | static struct r5conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5448 | struct r5conf *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5449 | int raid_disk, memory, max_disks; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5450 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5451 | struct disk_info *disk; |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 5452 | char pers_name[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5454 | if (mddev->new_level != 5 |
| 5455 | && mddev->new_level != 4 |
| 5456 | && mddev->new_level != 6) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5457 | 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] | 5458 | mdname(mddev), mddev->new_level); |
| 5459 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5461 | if ((mddev->new_level == 5 |
| 5462 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 5463 | (mddev->new_level == 6 |
| 5464 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5465 | printk(KERN_ERR "md/raid:%s: layout %d not supported\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5466 | mdname(mddev), mddev->new_layout); |
| 5467 | return ERR_PTR(-EIO); |
| 5468 | } |
| 5469 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5470 | 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] | 5471 | mdname(mddev), mddev->raid_disks); |
| 5472 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5475 | if (!mddev->new_chunk_sectors || |
| 5476 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 5477 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5478 | printk(KERN_ERR "md/raid:%s: invalid chunk size %d\n", |
| 5479 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5480 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5481 | } |
| 5482 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5483 | conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5484 | if (conf == NULL) |
| 5485 | goto abort; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5486 | /* Don't enable multi-threading by default*/ |
| 5487 | if (alloc_thread_groups(conf, 0)) |
| 5488 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 5489 | spin_lock_init(&conf->device_lock); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5490 | seqcount_init(&conf->gen_lock); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 5491 | init_waitqueue_head(&conf->wait_for_stripe); |
| 5492 | init_waitqueue_head(&conf->wait_for_overlap); |
| 5493 | INIT_LIST_HEAD(&conf->handle_list); |
| 5494 | INIT_LIST_HEAD(&conf->hold_list); |
| 5495 | INIT_LIST_HEAD(&conf->delayed_list); |
| 5496 | INIT_LIST_HEAD(&conf->bitmap_list); |
| 5497 | INIT_LIST_HEAD(&conf->inactive_list); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 5498 | init_llist_head(&conf->released_stripes); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 5499 | atomic_set(&conf->active_stripes, 0); |
| 5500 | atomic_set(&conf->preread_active_stripes, 0); |
| 5501 | atomic_set(&conf->active_aligned_reads, 0); |
| 5502 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 5503 | conf->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5504 | |
| 5505 | conf->raid_disks = mddev->raid_disks; |
| 5506 | if (mddev->reshape_position == MaxSector) |
| 5507 | conf->previous_raid_disks = mddev->raid_disks; |
| 5508 | else |
| 5509 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5510 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
| 5511 | conf->scribble_len = scribble_len(max_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5512 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5513 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5514 | GFP_KERNEL); |
| 5515 | if (!conf->disks) |
| 5516 | goto abort; |
| 5517 | |
| 5518 | conf->mddev = mddev; |
| 5519 | |
| 5520 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 5521 | goto abort; |
| 5522 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 5523 | conf->level = mddev->new_level; |
| 5524 | if (raid5_alloc_percpu(conf) != 0) |
| 5525 | goto abort; |
| 5526 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5527 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5528 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 5529 | rdev_for_each(rdev, mddev) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5530 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5531 | if (raid_disk >= max_disks |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5532 | || raid_disk < 0) |
| 5533 | continue; |
| 5534 | disk = conf->disks + raid_disk; |
| 5535 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5536 | if (test_bit(Replacement, &rdev->flags)) { |
| 5537 | if (disk->replacement) |
| 5538 | goto abort; |
| 5539 | disk->replacement = rdev; |
| 5540 | } else { |
| 5541 | if (disk->rdev) |
| 5542 | goto abort; |
| 5543 | disk->rdev = rdev; |
| 5544 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5545 | |
| 5546 | if (test_bit(In_sync, &rdev->flags)) { |
| 5547 | char b[BDEVNAME_SIZE]; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5548 | printk(KERN_INFO "md/raid:%s: device %s operational as raid" |
| 5549 | " disk %d\n", |
| 5550 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
Jonathan Brassow | d6b212f | 2011-06-08 18:00:28 -0500 | [diff] [blame] | 5551 | } else if (rdev->saved_raid_disk != raid_disk) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5552 | /* Cannot rely on bitmap to complete recovery */ |
| 5553 | conf->fullsync = 1; |
| 5554 | } |
| 5555 | |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5556 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5557 | conf->level = mddev->new_level; |
| 5558 | if (conf->level == 6) |
| 5559 | conf->max_degraded = 2; |
| 5560 | else |
| 5561 | conf->max_degraded = 1; |
| 5562 | conf->algorithm = mddev->new_layout; |
| 5563 | conf->max_nr_stripes = NR_STRIPES; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5564 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5565 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5566 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5567 | conf->prev_algo = mddev->layout; |
| 5568 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5569 | |
| 5570 | memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5571 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5572 | if (grow_stripes(conf, conf->max_nr_stripes)) { |
| 5573 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5574 | "md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 5575 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5576 | goto abort; |
| 5577 | } else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5578 | printk(KERN_INFO "md/raid:%s: allocated %dkB\n", |
| 5579 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5580 | |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 5581 | sprintf(pers_name, "raid%d", mddev->new_level); |
| 5582 | conf->thread = md_register_thread(raid5d, mddev, pers_name); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5583 | if (!conf->thread) { |
| 5584 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5585 | "md/raid:%s: couldn't allocate thread.\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5586 | mdname(mddev)); |
| 5587 | goto abort; |
| 5588 | } |
| 5589 | |
| 5590 | return conf; |
| 5591 | |
| 5592 | abort: |
| 5593 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5594 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5595 | return ERR_PTR(-EIO); |
| 5596 | } else |
| 5597 | return ERR_PTR(-ENOMEM); |
| 5598 | } |
| 5599 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5600 | |
| 5601 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 5602 | { |
| 5603 | switch (algo) { |
| 5604 | case ALGORITHM_PARITY_0: |
| 5605 | if (raid_disk < max_degraded) |
| 5606 | return 1; |
| 5607 | break; |
| 5608 | case ALGORITHM_PARITY_N: |
| 5609 | if (raid_disk >= raid_disks - max_degraded) |
| 5610 | return 1; |
| 5611 | break; |
| 5612 | case ALGORITHM_PARITY_0_6: |
| 5613 | if (raid_disk == 0 || |
| 5614 | raid_disk == raid_disks - 1) |
| 5615 | return 1; |
| 5616 | break; |
| 5617 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 5618 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 5619 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 5620 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 5621 | if (raid_disk == raid_disks - 1) |
| 5622 | return 1; |
| 5623 | } |
| 5624 | return 0; |
| 5625 | } |
| 5626 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5627 | static int run(struct mddev *mddev) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5628 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5629 | struct r5conf *conf; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5630 | int working_disks = 0; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5631 | int dirty_parity_disks = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5632 | struct md_rdev *rdev; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5633 | sector_t reshape_offset = 0; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5634 | int i; |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5635 | long long min_offset_diff = 0; |
| 5636 | int first = 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5637 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 5638 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5639 | printk(KERN_NOTICE "md/raid:%s: not clean" |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 5640 | " -- starting background reconstruction\n", |
| 5641 | mdname(mddev)); |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5642 | |
| 5643 | rdev_for_each(rdev, mddev) { |
| 5644 | long long diff; |
| 5645 | if (rdev->raid_disk < 0) |
| 5646 | continue; |
| 5647 | diff = (rdev->new_data_offset - rdev->data_offset); |
| 5648 | if (first) { |
| 5649 | min_offset_diff = diff; |
| 5650 | first = 0; |
| 5651 | } else if (mddev->reshape_backwards && |
| 5652 | diff < min_offset_diff) |
| 5653 | min_offset_diff = diff; |
| 5654 | else if (!mddev->reshape_backwards && |
| 5655 | diff > min_offset_diff) |
| 5656 | min_offset_diff = diff; |
| 5657 | } |
| 5658 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5659 | if (mddev->reshape_position != MaxSector) { |
| 5660 | /* Check that we can continue the reshape. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5661 | * Difficulties arise if the stripe we would write to |
| 5662 | * next is at or after the stripe we would read from next. |
| 5663 | * For a reshape that changes the number of devices, this |
| 5664 | * is only possible for a very short time, and mdadm makes |
| 5665 | * sure that time appears to have past before assembling |
| 5666 | * the array. So we fail if that time hasn't passed. |
| 5667 | * For a reshape that keeps the number of devices the same |
| 5668 | * mdadm must be monitoring the reshape can keeping the |
| 5669 | * critical areas read-only and backed up. It will start |
| 5670 | * the array in read-only mode, so we check for that. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5671 | */ |
| 5672 | sector_t here_new, here_old; |
| 5673 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 5674 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5675 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5676 | if (mddev->new_level != mddev->level) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5677 | printk(KERN_ERR "md/raid:%s: unsupported reshape " |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5678 | "required - aborting.\n", |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5679 | mdname(mddev)); |
| 5680 | return -EINVAL; |
| 5681 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5682 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 5683 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5684 | * further up in new geometry must map after here in old |
| 5685 | * geometry. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5686 | */ |
| 5687 | here_new = mddev->reshape_position; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5688 | if (sector_div(here_new, mddev->new_chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5689 | (mddev->raid_disks - max_degraded))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5690 | printk(KERN_ERR "md/raid:%s: reshape_position not " |
| 5691 | "on a stripe boundary\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5692 | return -EINVAL; |
| 5693 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5694 | reshape_offset = here_new * mddev->new_chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5695 | /* here_new is the stripe we will write to */ |
| 5696 | here_old = mddev->reshape_position; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5697 | sector_div(here_old, mddev->chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5698 | (old_disks-max_degraded)); |
| 5699 | /* here_old is the first stripe that we might need to read |
| 5700 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5701 | if (mddev->delta_disks == 0) { |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5702 | if ((here_new * mddev->new_chunk_sectors != |
| 5703 | here_old * mddev->chunk_sectors)) { |
| 5704 | printk(KERN_ERR "md/raid:%s: reshape position is" |
| 5705 | " confused - aborting\n", mdname(mddev)); |
| 5706 | return -EINVAL; |
| 5707 | } |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5708 | /* We cannot be sure it is safe to start an in-place |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5709 | * reshape. It is only safe if user-space is monitoring |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5710 | * and taking constant backups. |
| 5711 | * mdadm always starts a situation like this in |
| 5712 | * readonly mode so it can take control before |
| 5713 | * allowing any writes. So just check for that. |
| 5714 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5715 | if (abs(min_offset_diff) >= mddev->chunk_sectors && |
| 5716 | abs(min_offset_diff) >= mddev->new_chunk_sectors) |
| 5717 | /* not really in-place - so OK */; |
| 5718 | else if (mddev->ro == 0) { |
| 5719 | printk(KERN_ERR "md/raid:%s: in-place reshape " |
| 5720 | "must be started in read-only mode " |
| 5721 | "- aborting\n", |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5722 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5723 | return -EINVAL; |
| 5724 | } |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5725 | } else if (mddev->reshape_backwards |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5726 | ? (here_new * mddev->new_chunk_sectors + min_offset_diff <= |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5727 | here_old * mddev->chunk_sectors) |
| 5728 | : (here_new * mddev->new_chunk_sectors >= |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5729 | here_old * mddev->chunk_sectors + (-min_offset_diff))) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5730 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5731 | printk(KERN_ERR "md/raid:%s: reshape_position too early for " |
| 5732 | "auto-recovery - aborting.\n", |
| 5733 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5734 | return -EINVAL; |
| 5735 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5736 | printk(KERN_INFO "md/raid:%s: reshape will continue\n", |
| 5737 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5738 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5739 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5740 | BUG_ON(mddev->level != mddev->new_level); |
| 5741 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5742 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5743 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5744 | } |
| 5745 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5746 | if (mddev->private == NULL) |
| 5747 | conf = setup_conf(mddev); |
| 5748 | else |
| 5749 | conf = mddev->private; |
| 5750 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5751 | if (IS_ERR(conf)) |
| 5752 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 5753 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5754 | conf->min_offset_diff = min_offset_diff; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5755 | mddev->thread = conf->thread; |
| 5756 | conf->thread = NULL; |
| 5757 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5759 | for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; |
| 5760 | i++) { |
| 5761 | rdev = conf->disks[i].rdev; |
| 5762 | if (!rdev && conf->disks[i].replacement) { |
| 5763 | /* The replacement is all we have yet */ |
| 5764 | rdev = conf->disks[i].replacement; |
| 5765 | conf->disks[i].replacement = NULL; |
| 5766 | clear_bit(Replacement, &rdev->flags); |
| 5767 | conf->disks[i].rdev = rdev; |
| 5768 | } |
| 5769 | if (!rdev) |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5770 | continue; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5771 | if (conf->disks[i].replacement && |
| 5772 | conf->reshape_progress != MaxSector) { |
| 5773 | /* replacements and reshape simply do not mix. */ |
| 5774 | printk(KERN_ERR "md: cannot handle concurrent " |
| 5775 | "replacement and reshape.\n"); |
| 5776 | goto abort; |
| 5777 | } |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 5778 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5779 | working_disks++; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 5780 | continue; |
| 5781 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5782 | /* This disc is not fully in-sync. However if it |
| 5783 | * just stored parity (beyond the recovery_offset), |
| 5784 | * when we don't need to be concerned about the |
| 5785 | * array being dirty. |
| 5786 | * When reshape goes 'backwards', we never have |
| 5787 | * partially completed devices, so we only need |
| 5788 | * to worry about reshape going forwards. |
| 5789 | */ |
| 5790 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 5791 | if (mddev->major_version == 0 && |
| 5792 | mddev->minor_version > 90) |
| 5793 | rdev->recovery_offset = reshape_offset; |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 5794 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5795 | if (rdev->recovery_offset < reshape_offset) { |
| 5796 | /* We need to check old and new layout */ |
| 5797 | if (!only_parity(rdev->raid_disk, |
| 5798 | conf->algorithm, |
| 5799 | conf->raid_disks, |
| 5800 | conf->max_degraded)) |
| 5801 | continue; |
| 5802 | } |
| 5803 | if (!only_parity(rdev->raid_disk, |
| 5804 | conf->prev_algo, |
| 5805 | conf->previous_raid_disks, |
| 5806 | conf->max_degraded)) |
| 5807 | continue; |
| 5808 | dirty_parity_disks++; |
| 5809 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5810 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5811 | /* |
| 5812 | * 0 for a fully functional array, 1 or 2 for a degraded array. |
| 5813 | */ |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5814 | mddev->degraded = calc_degraded(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5816 | if (has_failed(conf)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5817 | printk(KERN_ERR "md/raid:%s: not enough operational devices" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | " (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5819 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | goto abort; |
| 5821 | } |
| 5822 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5823 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5824 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5825 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 5826 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5827 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5829 | if (mddev->ok_start_degraded) |
| 5830 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5831 | "md/raid:%s: starting dirty degraded array" |
| 5832 | " - data corruption possible.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5833 | mdname(mddev)); |
| 5834 | else { |
| 5835 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5836 | "md/raid:%s: cannot start dirty degraded array.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5837 | mdname(mddev)); |
| 5838 | goto abort; |
| 5839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5840 | } |
| 5841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | if (mddev->degraded == 0) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5843 | printk(KERN_INFO "md/raid:%s: raid level %d active with %d out of %d" |
| 5844 | " devices, algorithm %d\n", mdname(mddev), conf->level, |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5845 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 5846 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5848 | printk(KERN_ALERT "md/raid:%s: raid level %d active with %d" |
| 5849 | " out of %d devices, algorithm %d\n", |
| 5850 | mdname(mddev), conf->level, |
| 5851 | mddev->raid_disks - mddev->degraded, |
| 5852 | mddev->raid_disks, mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | |
| 5854 | print_raid5_conf(conf); |
| 5855 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5856 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5857 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5858 | atomic_set(&conf->reshape_stripes, 0); |
| 5859 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5860 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5861 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5862 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5863 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5864 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5865 | } |
| 5866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5867 | |
| 5868 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5869 | if (mddev->to_remove == &raid5_attrs_group) |
| 5870 | mddev->to_remove = NULL; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5871 | else if (mddev->kobj.sd && |
| 5872 | sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5873 | printk(KERN_WARNING |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5874 | "raid5: failed to create sysfs attributes for %s\n", |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5875 | mdname(mddev)); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5876 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5877 | |
| 5878 | if (mddev->queue) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5879 | int chunk_size; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5880 | bool discard_supported = true; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5881 | /* read-ahead size must cover two whole stripes, which |
| 5882 | * is 2 * (datadisks) * chunksize where 'n' is the |
| 5883 | * number of raid devices |
| 5884 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5885 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 5886 | int stripe = data_disks * |
| 5887 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
| 5888 | if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5889 | mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5890 | |
| 5891 | blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 5892 | |
| 5893 | mddev->queue->backing_dev_info.congested_data = mddev; |
| 5894 | mddev->queue->backing_dev_info.congested_fn = raid5_congested; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5895 | |
| 5896 | chunk_size = mddev->chunk_sectors << 9; |
| 5897 | blk_queue_io_min(mddev->queue, chunk_size); |
| 5898 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 5899 | (conf->raid_disks - conf->max_degraded)); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5900 | /* |
| 5901 | * We can only discard a whole stripe. It doesn't make sense to |
| 5902 | * discard data disk but write parity disk |
| 5903 | */ |
| 5904 | stripe = stripe * PAGE_SIZE; |
NeilBrown | 4ac6875 | 2012-11-19 13:11:26 +1100 | [diff] [blame] | 5905 | /* Round up to power of 2, as discard handling |
| 5906 | * currently assumes that */ |
| 5907 | while ((stripe-1) & stripe) |
| 5908 | stripe = (stripe | (stripe-1)) + 1; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5909 | mddev->queue->limits.discard_alignment = stripe; |
| 5910 | mddev->queue->limits.discard_granularity = stripe; |
| 5911 | /* |
| 5912 | * unaligned part of discard request will be ignored, so can't |
| 5913 | * guarantee discard_zerors_data |
| 5914 | */ |
| 5915 | mddev->queue->limits.discard_zeroes_data = 0; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5916 | |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 5917 | blk_queue_max_write_same_sectors(mddev->queue, 0); |
| 5918 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5919 | rdev_for_each(rdev, mddev) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5920 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5921 | rdev->data_offset << 9); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5922 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5923 | rdev->new_data_offset << 9); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5924 | /* |
| 5925 | * discard_zeroes_data is required, otherwise data |
| 5926 | * could be lost. Consider a scenario: discard a stripe |
| 5927 | * (the stripe could be inconsistent if |
| 5928 | * discard_zeroes_data is 0); write one disk of the |
| 5929 | * stripe (the stripe could be inconsistent again |
| 5930 | * depending on which disks are used to calculate |
| 5931 | * parity); the disk is broken; The stripe data of this |
| 5932 | * disk is lost. |
| 5933 | */ |
| 5934 | if (!blk_queue_discard(bdev_get_queue(rdev->bdev)) || |
| 5935 | !bdev_get_queue(rdev->bdev)-> |
| 5936 | limits.discard_zeroes_data) |
| 5937 | discard_supported = false; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5938 | } |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5939 | |
| 5940 | if (discard_supported && |
| 5941 | mddev->queue->limits.max_discard_sectors >= stripe && |
| 5942 | mddev->queue->limits.discard_granularity >= stripe) |
| 5943 | queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, |
| 5944 | mddev->queue); |
| 5945 | else |
| 5946 | queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, |
| 5947 | mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | } |
| 5949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5950 | return 0; |
| 5951 | abort: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 5952 | md_unregister_thread(&mddev->thread); |
NeilBrown | e4f869d | 2011-10-07 14:22:49 +1100 | [diff] [blame] | 5953 | print_raid5_conf(conf); |
| 5954 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | mddev->private = NULL; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5956 | 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] | 5957 | return -EIO; |
| 5958 | } |
| 5959 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5960 | static int stop(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5962 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 5964 | md_unregister_thread(&mddev->thread); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 5965 | if (mddev->queue) |
| 5966 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5967 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5968 | mddev->private = NULL; |
| 5969 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5970 | return 0; |
| 5971 | } |
| 5972 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5973 | static void status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5974 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5975 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5976 | int i; |
| 5977 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5978 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
| 5979 | mddev->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5980 | 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] | 5981 | for (i = 0; i < conf->raid_disks; i++) |
| 5982 | seq_printf (seq, "%s", |
| 5983 | conf->disks[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5984 | test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5985 | seq_printf (seq, "]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | } |
| 5987 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5988 | static void print_raid5_conf (struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | { |
| 5990 | int i; |
| 5991 | struct disk_info *tmp; |
| 5992 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5993 | printk(KERN_DEBUG "RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | if (!conf) { |
| 5995 | printk("(conf==NULL)\n"); |
| 5996 | return; |
| 5997 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5998 | printk(KERN_DEBUG " --- level:%d rd:%d wd:%d\n", conf->level, |
| 5999 | conf->raid_disks, |
| 6000 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6001 | |
| 6002 | for (i = 0; i < conf->raid_disks; i++) { |
| 6003 | char b[BDEVNAME_SIZE]; |
| 6004 | tmp = conf->disks + i; |
| 6005 | if (tmp->rdev) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 6006 | printk(KERN_DEBUG " disk %d, o:%d, dev:%s\n", |
| 6007 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 6008 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6012 | static int raid5_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | { |
| 6014 | int i; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6015 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | struct disk_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 6017 | int count = 0; |
| 6018 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | |
| 6020 | for (i = 0; i < conf->raid_disks; i++) { |
| 6021 | tmp = conf->disks + i; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 6022 | if (tmp->replacement |
| 6023 | && tmp->replacement->recovery_offset == MaxSector |
| 6024 | && !test_bit(Faulty, &tmp->replacement->flags) |
| 6025 | && !test_and_set_bit(In_sync, &tmp->replacement->flags)) { |
| 6026 | /* Replacement has just become active. */ |
| 6027 | if (!tmp->rdev |
| 6028 | || !test_and_clear_bit(In_sync, &tmp->rdev->flags)) |
| 6029 | count++; |
| 6030 | if (tmp->rdev) { |
| 6031 | /* Replaced device not technically faulty, |
| 6032 | * but we need to be sure it gets removed |
| 6033 | * and never re-added. |
| 6034 | */ |
| 6035 | set_bit(Faulty, &tmp->rdev->flags); |
| 6036 | sysfs_notify_dirent_safe( |
| 6037 | tmp->rdev->sysfs_state); |
| 6038 | } |
| 6039 | sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); |
| 6040 | } else if (tmp->rdev |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 6041 | && tmp->rdev->recovery_offset == MaxSector |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6042 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 6043 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 6044 | count++; |
Jonathan Brassow | 43c73ca | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 6045 | sysfs_notify_dirent_safe(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6046 | } |
| 6047 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 6048 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 6049 | mddev->degraded = calc_degraded(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 6050 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | print_raid5_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 6052 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 6055 | static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6056 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6057 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6058 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 6059 | int number = rdev->raid_disk; |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 6060 | struct md_rdev **rdevp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6061 | struct disk_info *p = conf->disks + number; |
| 6062 | |
| 6063 | print_raid5_conf(conf); |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 6064 | if (rdev == p->rdev) |
| 6065 | rdevp = &p->rdev; |
| 6066 | else if (rdev == p->replacement) |
| 6067 | rdevp = &p->replacement; |
| 6068 | else |
| 6069 | return 0; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6070 | |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 6071 | if (number >= conf->raid_disks && |
| 6072 | conf->reshape_progress == MaxSector) |
| 6073 | clear_bit(In_sync, &rdev->flags); |
| 6074 | |
| 6075 | if (test_bit(In_sync, &rdev->flags) || |
| 6076 | atomic_read(&rdev->nr_pending)) { |
| 6077 | err = -EBUSY; |
| 6078 | goto abort; |
| 6079 | } |
| 6080 | /* Only remove non-faulty devices if recovery |
| 6081 | * isn't possible. |
| 6082 | */ |
| 6083 | if (!test_bit(Faulty, &rdev->flags) && |
| 6084 | mddev->recovery_disabled != conf->recovery_disabled && |
| 6085 | !has_failed(conf) && |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 6086 | (!p->replacement || p->replacement == rdev) && |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 6087 | number < conf->raid_disks) { |
| 6088 | err = -EBUSY; |
| 6089 | goto abort; |
| 6090 | } |
| 6091 | *rdevp = NULL; |
| 6092 | synchronize_rcu(); |
| 6093 | if (atomic_read(&rdev->nr_pending)) { |
| 6094 | /* lost the race, try later */ |
| 6095 | err = -EBUSY; |
| 6096 | *rdevp = rdev; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 6097 | } else if (p->replacement) { |
| 6098 | /* We must have just cleared 'rdev' */ |
| 6099 | p->rdev = p->replacement; |
| 6100 | clear_bit(Replacement, &p->replacement->flags); |
| 6101 | smp_mb(); /* Make sure other CPUs may see both as identical |
| 6102 | * but will never see neither - if they are careful |
| 6103 | */ |
| 6104 | p->replacement = NULL; |
| 6105 | clear_bit(WantReplacement, &rdev->flags); |
| 6106 | } else |
| 6107 | /* We might have just removed the Replacement as faulty- |
| 6108 | * clear the bit just in case |
| 6109 | */ |
| 6110 | clear_bit(WantReplacement, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | abort: |
| 6112 | |
| 6113 | print_raid5_conf(conf); |
| 6114 | return err; |
| 6115 | } |
| 6116 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6117 | static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6118 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6119 | struct r5conf *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 6120 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | int disk; |
| 6122 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 6123 | int first = 0; |
| 6124 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 6126 | if (mddev->recovery_disabled == conf->recovery_disabled) |
| 6127 | return -EBUSY; |
| 6128 | |
NeilBrown | dc10c64 | 2012-03-19 12:46:37 +1100 | [diff] [blame] | 6129 | if (rdev->saved_raid_disk < 0 && has_failed(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 6131 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6132 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 6133 | if (rdev->raid_disk >= 0) |
| 6134 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6135 | |
| 6136 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6137 | * find the disk ... but prefer rdev->saved_raid_disk |
| 6138 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6139 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6140 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 6141 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6142 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 6143 | first = rdev->saved_raid_disk; |
| 6144 | |
| 6145 | for (disk = first; disk <= last; disk++) { |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 6146 | p = conf->disks + disk; |
| 6147 | if (p->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 6148 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6149 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 6150 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6151 | if (rdev->saved_raid_disk != disk) |
| 6152 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 6153 | rcu_assign_pointer(p->rdev, rdev); |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 6154 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6155 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 6156 | } |
| 6157 | for (disk = first; disk <= last; disk++) { |
| 6158 | p = conf->disks + disk; |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 6159 | if (test_bit(WantReplacement, &p->rdev->flags) && |
| 6160 | p->replacement == NULL) { |
| 6161 | clear_bit(In_sync, &rdev->flags); |
| 6162 | set_bit(Replacement, &rdev->flags); |
| 6163 | rdev->raid_disk = disk; |
| 6164 | err = 0; |
| 6165 | conf->fullsync = 1; |
| 6166 | rcu_assign_pointer(p->replacement, rdev); |
| 6167 | break; |
| 6168 | } |
| 6169 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 6170 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 6172 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | } |
| 6174 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6175 | static int raid5_resize(struct mddev *mddev, sector_t sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | { |
| 6177 | /* no resync is happening, and there is enough space |
| 6178 | * on all devices, so we can resize. |
| 6179 | * We need to make sure resync covers any new space. |
| 6180 | * If the array is shrinking we should possibly wait until |
| 6181 | * any io in the removed space completes, but it hardly seems |
| 6182 | * worth it. |
| 6183 | */ |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 6184 | sector_t newsize; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 6185 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 6186 | newsize = raid5_size(mddev, sectors, mddev->raid_disks); |
| 6187 | if (mddev->external_size && |
| 6188 | mddev->array_sectors > newsize) |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 6189 | return -EINVAL; |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 6190 | if (mddev->bitmap) { |
| 6191 | int ret = bitmap_resize(mddev->bitmap, sectors, 0, 0); |
| 6192 | if (ret) |
| 6193 | return ret; |
| 6194 | } |
| 6195 | md_set_array_sectors(mddev, newsize); |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 6196 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6197 | revalidate_disk(mddev->gendisk); |
NeilBrown | b098636 | 2011-05-11 15:52:21 +1000 | [diff] [blame] | 6198 | if (sectors > mddev->dev_sectors && |
| 6199 | mddev->recovery_cp > mddev->dev_sectors) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6200 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6201 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 6202 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6203 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 6204 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | return 0; |
| 6206 | } |
| 6207 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6208 | static int check_stripe_cache(struct mddev *mddev) |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 6209 | { |
| 6210 | /* Can only proceed if there are plenty of stripe_heads. |
| 6211 | * We need a minimum of one full stripe,, and for sensible progress |
| 6212 | * it is best to have about 4 times that. |
| 6213 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 6214 | * allow for chunk sizes up to 256K, which is probably OK. |
| 6215 | * If the chunk size is greater, user-space should request more |
| 6216 | * stripe_heads first. |
| 6217 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6218 | struct r5conf *conf = mddev->private; |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 6219 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 6220 | > conf->max_nr_stripes || |
| 6221 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 6222 | > conf->max_nr_stripes) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 6223 | printk(KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 6224 | mdname(mddev), |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 6225 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 6226 | / STRIPE_SIZE)*4); |
| 6227 | return 0; |
| 6228 | } |
| 6229 | return 1; |
| 6230 | } |
| 6231 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6232 | static int check_reshape(struct mddev *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6233 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6234 | struct r5conf *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6235 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6236 | if (mddev->delta_disks == 0 && |
| 6237 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 6238 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6239 | return 0; /* nothing to do */ |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 6240 | if (has_failed(conf)) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6241 | return -EINVAL; |
NeilBrown | fdcfbbb | 2013-07-04 16:38:16 +1000 | [diff] [blame] | 6242 | if (mddev->delta_disks < 0 && mddev->reshape_position == MaxSector) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6243 | /* We might be able to shrink, but the devices must |
| 6244 | * be made bigger first. |
| 6245 | * For raid6, 4 is the minimum size. |
| 6246 | * Otherwise 2 is the minimum |
| 6247 | */ |
| 6248 | int min = 2; |
| 6249 | if (mddev->level == 6) |
| 6250 | min = 4; |
| 6251 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 6252 | return -EINVAL; |
| 6253 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6254 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 6255 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6256 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6257 | |
NeilBrown | e56108d6 | 2012-10-11 14:24:13 +1100 | [diff] [blame] | 6258 | return resize_stripes(conf, (conf->previous_raid_disks |
| 6259 | + mddev->delta_disks)); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6260 | } |
| 6261 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6262 | static int raid5_start_reshape(struct mddev *mddev) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6263 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6264 | struct r5conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 6265 | struct md_rdev *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6266 | int spares = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 6267 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6268 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 6269 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6270 | return -EBUSY; |
| 6271 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 6272 | if (!check_stripe_cache(mddev)) |
| 6273 | return -ENOSPC; |
| 6274 | |
NeilBrown | 30b6764 | 2012-05-22 13:55:28 +1000 | [diff] [blame] | 6275 | if (has_failed(conf)) |
| 6276 | return -EINVAL; |
| 6277 | |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6278 | rdev_for_each(rdev, mddev) { |
NeilBrown | 469518a | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6279 | if (!test_bit(In_sync, &rdev->flags) |
| 6280 | && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6281 | spares++; |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6282 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6283 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 6284 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6285 | /* Not enough devices even to make a degraded array |
| 6286 | * of that size |
| 6287 | */ |
| 6288 | return -EINVAL; |
| 6289 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6290 | /* Refuse to reduce size of the array. Any reductions in |
| 6291 | * array size must be through explicit setting of array_size |
| 6292 | * attribute. |
| 6293 | */ |
| 6294 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 6295 | < mddev->array_sectors) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 6296 | printk(KERN_ERR "md/raid:%s: array size must be reduced " |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6297 | "before number of disks\n", mdname(mddev)); |
| 6298 | return -EINVAL; |
| 6299 | } |
| 6300 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6301 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6302 | spin_lock_irq(&conf->device_lock); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 6303 | write_seqcount_begin(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6304 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6305 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 6306 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 6307 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6308 | conf->prev_algo = conf->algorithm; |
| 6309 | conf->algorithm = mddev->new_layout; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6310 | conf->generation++; |
| 6311 | /* Code that selects data_offset needs to see the generation update |
| 6312 | * if reshape_progress has been set - so a memory barrier needed. |
| 6313 | */ |
| 6314 | smp_mb(); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6315 | if (mddev->reshape_backwards) |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6316 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 6317 | else |
| 6318 | conf->reshape_progress = 0; |
| 6319 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 6320 | write_seqcount_end(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6321 | spin_unlock_irq(&conf->device_lock); |
| 6322 | |
NeilBrown | 4d77e3b | 2013-08-27 15:57:47 +1000 | [diff] [blame] | 6323 | /* Now make sure any requests that proceeded on the assumption |
| 6324 | * the reshape wasn't running - like Discard or Read - have |
| 6325 | * completed. |
| 6326 | */ |
| 6327 | mddev_suspend(mddev); |
| 6328 | mddev_resume(mddev); |
| 6329 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6330 | /* Add some new drives, as many as will fit. |
| 6331 | * We know there are enough to make the newly sized array work. |
NeilBrown | 3424bf6 | 2010-06-17 17:48:26 +1000 | [diff] [blame] | 6332 | * Don't add devices if we are reducing the number of |
| 6333 | * devices in the array. This is because it is not possible |
| 6334 | * to correctly record the "partially reconstructed" state of |
| 6335 | * such devices during the reshape and confusion could result. |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6336 | */ |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6337 | if (mddev->delta_disks >= 0) { |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 6338 | rdev_for_each(rdev, mddev) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6339 | if (rdev->raid_disk < 0 && |
| 6340 | !test_bit(Faulty, &rdev->flags)) { |
| 6341 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6342 | if (rdev->raid_disk |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 6343 | >= conf->previous_raid_disks) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6344 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 6345 | else |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6346 | rdev->recovery_offset = 0; |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 6347 | |
| 6348 | if (sysfs_link_rdev(mddev, rdev)) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6349 | /* Failure here is OK */; |
NeilBrown | 50da084 | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6350 | } |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6351 | } else if (rdev->raid_disk >= conf->previous_raid_disks |
| 6352 | && !test_bit(Faulty, &rdev->flags)) { |
| 6353 | /* This is a spare that was manually added */ |
| 6354 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6355 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6356 | |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 6357 | /* When a reshape changes the number of devices, |
| 6358 | * ->degraded is measured against the larger of the |
| 6359 | * pre and post number of devices. |
| 6360 | */ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6361 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 6362 | mddev->degraded = calc_degraded(conf); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6363 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 6364 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6365 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 6366 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 6367 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6368 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6369 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 6370 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 6371 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 6372 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 6373 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 6374 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6375 | if (!mddev->sync_thread) { |
| 6376 | mddev->recovery = 0; |
| 6377 | spin_lock_irq(&conf->device_lock); |
| 6378 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6379 | rdev_for_each(rdev, mddev) |
| 6380 | rdev->new_data_offset = rdev->data_offset; |
| 6381 | smp_wmb(); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6382 | conf->reshape_progress = MaxSector; |
NeilBrown | 1e3fa9b | 2012-03-13 11:21:18 +1100 | [diff] [blame] | 6383 | mddev->reshape_position = MaxSector; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6384 | spin_unlock_irq(&conf->device_lock); |
| 6385 | return -EAGAIN; |
| 6386 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 6387 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6388 | md_wakeup_thread(mddev->sync_thread); |
| 6389 | md_new_event(mddev); |
| 6390 | return 0; |
| 6391 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6392 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6393 | /* This is called from the reshape thread and should make any |
| 6394 | * changes needed in 'conf' |
| 6395 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6396 | static void end_reshape(struct r5conf *conf) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6397 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6398 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6399 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6400 | struct md_rdev *rdev; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6401 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6402 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6403 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6404 | rdev_for_each(rdev, conf->mddev) |
| 6405 | rdev->data_offset = rdev->new_data_offset; |
| 6406 | smp_wmb(); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6407 | conf->reshape_progress = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6408 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 6409 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6410 | |
| 6411 | /* read-ahead size must cover two whole stripes, which is |
| 6412 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 6413 | */ |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 6414 | if (conf->mddev->queue) { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6415 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 6416 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6417 | / PAGE_SIZE); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6418 | if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 6419 | conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 6420 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6421 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6422 | } |
| 6423 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6424 | /* This is called from the raid5d thread with mddev_lock held. |
| 6425 | * It makes config changes to the device. |
| 6426 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6427 | static void raid5_finish_reshape(struct mddev *mddev) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6428 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6429 | struct r5conf *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6430 | |
| 6431 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 6432 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6433 | if (mddev->delta_disks > 0) { |
| 6434 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 6435 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6436 | revalidate_disk(mddev->gendisk); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6437 | } else { |
| 6438 | int d; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 6439 | spin_lock_irq(&conf->device_lock); |
| 6440 | mddev->degraded = calc_degraded(conf); |
| 6441 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6442 | for (d = conf->raid_disks ; |
| 6443 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 6444 | d++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 6445 | struct md_rdev *rdev = conf->disks[d].rdev; |
NeilBrown | da7613b | 2012-05-22 13:55:33 +1000 | [diff] [blame] | 6446 | if (rdev) |
| 6447 | clear_bit(In_sync, &rdev->flags); |
| 6448 | rdev = conf->disks[d].replacement; |
| 6449 | if (rdev) |
| 6450 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 6451 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6452 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6453 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 6454 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 6455 | mddev->reshape_position = MaxSector; |
| 6456 | mddev->delta_disks = 0; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 6457 | mddev->reshape_backwards = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6458 | } |
| 6459 | } |
| 6460 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6461 | static void raid5_quiesce(struct mddev *mddev, int state) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6462 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6463 | struct r5conf *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6464 | |
| 6465 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 6466 | case 2: /* resume for a suspend */ |
| 6467 | wake_up(&conf->wait_for_overlap); |
| 6468 | break; |
| 6469 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6470 | case 1: /* stop all writes */ |
| 6471 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6472 | /* '2' tells resync/reshape to pause so that all |
| 6473 | * active stripes can drain |
| 6474 | */ |
| 6475 | conf->quiesce = 2; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6476 | wait_event_lock_irq(conf->wait_for_stripe, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6477 | atomic_read(&conf->active_stripes) == 0 && |
| 6478 | atomic_read(&conf->active_aligned_reads) == 0, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 6479 | conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6480 | conf->quiesce = 1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6481 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6482 | /* allow reshape to continue */ |
| 6483 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6484 | break; |
| 6485 | |
| 6486 | case 0: /* re-enable writes */ |
| 6487 | spin_lock_irq(&conf->device_lock); |
| 6488 | conf->quiesce = 0; |
| 6489 | wake_up(&conf->wait_for_stripe); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 6490 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6491 | spin_unlock_irq(&conf->device_lock); |
| 6492 | break; |
| 6493 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6494 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 6495 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6496 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6497 | static void *raid45_takeover_raid0(struct mddev *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 6498 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 6499 | struct r0conf *raid0_conf = mddev->private; |
Randy Dunlap | d76c842 | 2011-04-21 09:07:26 -0700 | [diff] [blame] | 6500 | sector_t sectors; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 6501 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6502 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 6503 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 6504 | printk(KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 6505 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6506 | return ERR_PTR(-EINVAL); |
| 6507 | } |
| 6508 | |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 6509 | sectors = raid0_conf->strip_zone[0].zone_end; |
| 6510 | sector_div(sectors, raid0_conf->strip_zone[0].nb_dev); |
NeilBrown | 3b71bd9 | 2011-04-20 15:38:18 +1000 | [diff] [blame] | 6511 | mddev->dev_sectors = sectors; |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6512 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 6513 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 6514 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 6515 | mddev->raid_disks += 1; |
| 6516 | mddev->delta_disks = 1; |
| 6517 | /* make sure it will be not marked as dirty */ |
| 6518 | mddev->recovery_cp = MaxSector; |
| 6519 | |
| 6520 | return setup_conf(mddev); |
| 6521 | } |
| 6522 | |
| 6523 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6524 | static void *raid5_takeover_raid1(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6525 | { |
| 6526 | int chunksect; |
| 6527 | |
| 6528 | if (mddev->raid_disks != 2 || |
| 6529 | mddev->degraded > 1) |
| 6530 | return ERR_PTR(-EINVAL); |
| 6531 | |
| 6532 | /* Should check if there are write-behind devices? */ |
| 6533 | |
| 6534 | chunksect = 64*2; /* 64K by default */ |
| 6535 | |
| 6536 | /* The array must be an exact multiple of chunksize */ |
| 6537 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 6538 | chunksect >>= 1; |
| 6539 | |
| 6540 | if ((chunksect<<9) < STRIPE_SIZE) |
| 6541 | /* array size does not allow a suitable chunk size */ |
| 6542 | return ERR_PTR(-EINVAL); |
| 6543 | |
| 6544 | mddev->new_level = 5; |
| 6545 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 6546 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6547 | |
| 6548 | return setup_conf(mddev); |
| 6549 | } |
| 6550 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6551 | static void *raid5_takeover_raid6(struct mddev *mddev) |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 6552 | { |
| 6553 | int new_layout; |
| 6554 | |
| 6555 | switch (mddev->layout) { |
| 6556 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 6557 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 6558 | break; |
| 6559 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 6560 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 6561 | break; |
| 6562 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 6563 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 6564 | break; |
| 6565 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 6566 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 6567 | break; |
| 6568 | case ALGORITHM_PARITY_0_6: |
| 6569 | new_layout = ALGORITHM_PARITY_0; |
| 6570 | break; |
| 6571 | case ALGORITHM_PARITY_N: |
| 6572 | new_layout = ALGORITHM_PARITY_N; |
| 6573 | break; |
| 6574 | default: |
| 6575 | return ERR_PTR(-EINVAL); |
| 6576 | } |
| 6577 | mddev->new_level = 5; |
| 6578 | mddev->new_layout = new_layout; |
| 6579 | mddev->delta_disks = -1; |
| 6580 | mddev->raid_disks -= 1; |
| 6581 | return setup_conf(mddev); |
| 6582 | } |
| 6583 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6584 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6585 | static int raid5_check_reshape(struct mddev *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6586 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6587 | /* For a 2-drive array, the layout and chunk size can be changed |
| 6588 | * immediately as not restriping is needed. |
| 6589 | * For larger arrays we record the new value - after validation |
| 6590 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6591 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6592 | struct r5conf *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6593 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6594 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6595 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6596 | return -EINVAL; |
| 6597 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 6598 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6599 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6600 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6601 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6602 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6603 | /* not factor of array size */ |
| 6604 | return -EINVAL; |
| 6605 | } |
| 6606 | |
| 6607 | /* They look valid */ |
| 6608 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6609 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6610 | /* can make the change immediately */ |
| 6611 | if (mddev->new_layout >= 0) { |
| 6612 | conf->algorithm = mddev->new_layout; |
| 6613 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6614 | } |
| 6615 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6616 | conf->chunk_sectors = new_chunk ; |
| 6617 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6618 | } |
| 6619 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 6620 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6621 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6622 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6623 | } |
| 6624 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6625 | static int raid6_check_reshape(struct mddev *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6626 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6627 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6628 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6629 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6630 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6631 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 6632 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6633 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6634 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6635 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 6636 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6637 | /* not factor of array size */ |
| 6638 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6639 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 6640 | |
| 6641 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6642 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 6643 | } |
| 6644 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6645 | static void *raid5_takeover(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6646 | { |
| 6647 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6648 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6649 | * raid1 - if there are two drives. We need to know the chunk size |
| 6650 | * raid4 - trivial - just use a raid4 layout. |
| 6651 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6652 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6653 | if (mddev->level == 0) |
| 6654 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6655 | if (mddev->level == 1) |
| 6656 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 6657 | if (mddev->level == 4) { |
| 6658 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 6659 | mddev->new_level = 5; |
| 6660 | return setup_conf(mddev); |
| 6661 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 6662 | if (mddev->level == 6) |
| 6663 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6664 | |
| 6665 | return ERR_PTR(-EINVAL); |
| 6666 | } |
| 6667 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6668 | static void *raid4_takeover(struct mddev *mddev) |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6669 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6670 | /* raid4 can take over: |
| 6671 | * raid0 - if there is only one strip zone |
| 6672 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6673 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 6674 | if (mddev->level == 0) |
| 6675 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6676 | if (mddev->level == 5 && |
| 6677 | mddev->layout == ALGORITHM_PARITY_N) { |
| 6678 | mddev->new_layout = 0; |
| 6679 | mddev->new_level = 4; |
| 6680 | return setup_conf(mddev); |
| 6681 | } |
| 6682 | return ERR_PTR(-EINVAL); |
| 6683 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6684 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6685 | static struct md_personality raid5_personality; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6686 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6687 | static void *raid6_takeover(struct mddev *mddev) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6688 | { |
| 6689 | /* Currently can only take over a raid5. We map the |
| 6690 | * personality to an equivalent raid6 personality |
| 6691 | * with the Q block at the end. |
| 6692 | */ |
| 6693 | int new_layout; |
| 6694 | |
| 6695 | if (mddev->pers != &raid5_personality) |
| 6696 | return ERR_PTR(-EINVAL); |
| 6697 | if (mddev->degraded > 1) |
| 6698 | return ERR_PTR(-EINVAL); |
| 6699 | if (mddev->raid_disks > 253) |
| 6700 | return ERR_PTR(-EINVAL); |
| 6701 | if (mddev->raid_disks < 3) |
| 6702 | return ERR_PTR(-EINVAL); |
| 6703 | |
| 6704 | switch (mddev->layout) { |
| 6705 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 6706 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 6707 | break; |
| 6708 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 6709 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 6710 | break; |
| 6711 | case ALGORITHM_LEFT_SYMMETRIC: |
| 6712 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 6713 | break; |
| 6714 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 6715 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 6716 | break; |
| 6717 | case ALGORITHM_PARITY_0: |
| 6718 | new_layout = ALGORITHM_PARITY_0_6; |
| 6719 | break; |
| 6720 | case ALGORITHM_PARITY_N: |
| 6721 | new_layout = ALGORITHM_PARITY_N; |
| 6722 | break; |
| 6723 | default: |
| 6724 | return ERR_PTR(-EINVAL); |
| 6725 | } |
| 6726 | mddev->new_level = 6; |
| 6727 | mddev->new_layout = new_layout; |
| 6728 | mddev->delta_disks = 1; |
| 6729 | mddev->raid_disks += 1; |
| 6730 | return setup_conf(mddev); |
| 6731 | } |
| 6732 | |
| 6733 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6734 | static struct md_personality raid6_personality = |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6735 | { |
| 6736 | .name = "raid6", |
| 6737 | .level = 6, |
| 6738 | .owner = THIS_MODULE, |
| 6739 | .make_request = make_request, |
| 6740 | .run = run, |
| 6741 | .stop = stop, |
| 6742 | .status = status, |
| 6743 | .error_handler = error, |
| 6744 | .hot_add_disk = raid5_add_disk, |
| 6745 | .hot_remove_disk= raid5_remove_disk, |
| 6746 | .spare_active = raid5_spare_active, |
| 6747 | .sync_request = sync_request, |
| 6748 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6749 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 6750 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 6751 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6752 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6753 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6754 | .takeover = raid6_takeover, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6755 | }; |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6756 | static struct md_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6757 | { |
| 6758 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6759 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6760 | .owner = THIS_MODULE, |
| 6761 | .make_request = make_request, |
| 6762 | .run = run, |
| 6763 | .stop = stop, |
| 6764 | .status = status, |
| 6765 | .error_handler = error, |
| 6766 | .hot_add_disk = raid5_add_disk, |
| 6767 | .hot_remove_disk= raid5_remove_disk, |
| 6768 | .spare_active = raid5_spare_active, |
| 6769 | .sync_request = sync_request, |
| 6770 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6771 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 6772 | .check_reshape = raid5_check_reshape, |
| 6773 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6774 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6775 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6776 | .takeover = raid5_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6777 | }; |
| 6778 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 6779 | static struct md_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6780 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6781 | .name = "raid4", |
| 6782 | .level = 4, |
| 6783 | .owner = THIS_MODULE, |
| 6784 | .make_request = make_request, |
| 6785 | .run = run, |
| 6786 | .stop = stop, |
| 6787 | .status = status, |
| 6788 | .error_handler = error, |
| 6789 | .hot_add_disk = raid5_add_disk, |
| 6790 | .hot_remove_disk= raid5_remove_disk, |
| 6791 | .spare_active = raid5_spare_active, |
| 6792 | .sync_request = sync_request, |
| 6793 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6794 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 6795 | .check_reshape = raid5_check_reshape, |
| 6796 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6797 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6798 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6799 | .takeover = raid4_takeover, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6800 | }; |
| 6801 | |
| 6802 | static int __init raid5_init(void) |
| 6803 | { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6804 | raid5_wq = alloc_workqueue("raid5wq", |
| 6805 | WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE|WQ_SYSFS, 0); |
| 6806 | if (!raid5_wq) |
| 6807 | return -ENOMEM; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6808 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6809 | register_md_personality(&raid5_personality); |
| 6810 | register_md_personality(&raid4_personality); |
| 6811 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6812 | } |
| 6813 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6814 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6815 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6816 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6817 | unregister_md_personality(&raid5_personality); |
| 6818 | unregister_md_personality(&raid4_personality); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6819 | destroy_workqueue(raid5_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | module_init(raid5_init); |
| 6823 | module_exit(raid5_exit); |
| 6824 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 6825 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6826 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 6827 | MODULE_ALIAS("md-raid5"); |
| 6828 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6829 | MODULE_ALIAS("md-level-5"); |
| 6830 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6831 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 6832 | MODULE_ALIAS("md-raid6"); |
| 6833 | MODULE_ALIAS("md-level-6"); |
| 6834 | |
| 6835 | /* This used to be two separate modules, they were: */ |
| 6836 | MODULE_ALIAS("raid5"); |
| 6837 | MODULE_ALIAS("raid6"); |