Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * raid5.c : Multiple Devices driver for Linux |
| 3 | * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman |
| 4 | * Copyright (C) 1999, 2000 Ingo Molnar |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5 | * Copyright (C) 2002, 2003 H. Peter Anvin |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7 | * RAID-4/5/6 management functions. |
| 8 | * Thanks to Penguin Computing for making the RAID-6 development possible |
| 9 | * by donating a test server! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * (for example /usr/src/linux/COPYING); if not, write to the Free |
| 18 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 21 | /* |
| 22 | * BITMAP UNPLUGGING: |
| 23 | * |
| 24 | * The sequencing for updating the bitmap reliably is a little |
| 25 | * subtle (and I got it wrong the first time) so it deserves some |
| 26 | * explanation. |
| 27 | * |
| 28 | * We group bitmap updates into batches. Each batch has a number. |
| 29 | * We may write out several batches at once, but that isn't very important. |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 30 | * conf->seq_write is the number of the last batch successfully written. |
| 31 | * conf->seq_flush is the number of the last batch that was closed to |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 32 | * new additions. |
| 33 | * When we discover that we will need to write to any block in a stripe |
| 34 | * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 35 | * the number of the batch it will be in. This is seq_flush+1. |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 36 | * When we are ready to do a write, if that batch hasn't been written yet, |
| 37 | * we plug the array and queue the stripe for later. |
| 38 | * When an unplug happens, we increment bm_flush, thus closing the current |
| 39 | * batch. |
| 40 | * When we notice that bm_flush > bm_write, we write out all pending updates |
| 41 | * to the bitmap, and advance bm_write to where bm_flush was. |
| 42 | * This may occasionally write a bit out twice, but is sure never to |
| 43 | * miss any bits. |
| 44 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 46 | #include <linux/blkdev.h> |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 47 | #include <linux/kthread.h> |
Dan Williams | f701d58 | 2009-03-31 15:09:39 +1100 | [diff] [blame] | 48 | #include <linux/raid/pq.h> |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 49 | #include <linux/async_tx.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Dan Williams | 07a3b41 | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 51 | #include <linux/async.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 52 | #include <linux/seq_file.h> |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 53 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 54 | #include <linux/slab.h> |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 55 | #include <linux/ratelimit.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 56 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 57 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 58 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 59 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Stripe cache |
| 63 | */ |
| 64 | |
| 65 | #define NR_STRIPES 256 |
| 66 | #define STRIPE_SIZE PAGE_SIZE |
| 67 | #define STRIPE_SHIFT (PAGE_SHIFT - 9) |
| 68 | #define STRIPE_SECTORS (STRIPE_SIZE>>9) |
| 69 | #define IO_THRESHOLD 1 |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 70 | #define BYPASS_THRESHOLD 1 |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 71 | #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define HASH_MASK (NR_HASH - 1) |
| 73 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 74 | static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 75 | { |
| 76 | int hash = (sect >> STRIPE_SHIFT) & HASH_MASK; |
| 77 | return &conf->stripe_hashtbl[hash]; |
| 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* bio's attached to a stripe+device for I/O are linked together in bi_sector |
| 81 | * order without overlap. There may be several bio's per stripe+device, and |
| 82 | * a bio could span several devices. |
| 83 | * When walking this list for a particular stripe+device, we must never proceed |
| 84 | * beyond a bio that extends past this device, as the next bio might no longer |
| 85 | * be valid. |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 86 | * 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] | 87 | * of the current stripe+device |
| 88 | */ |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 89 | static inline struct bio *r5_next_bio(struct bio *bio, sector_t sector) |
| 90 | { |
| 91 | int sectors = bio->bi_size >> 9; |
| 92 | if (bio->bi_sector + sectors < sector + STRIPE_SECTORS) |
| 93 | return bio->bi_next; |
| 94 | else |
| 95 | return NULL; |
| 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 98 | /* |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 99 | * We maintain a biased count of active stripes in the bottom 16 bits of |
| 100 | * 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] | 101 | */ |
| 102 | static inline int raid5_bi_phys_segments(struct bio *bio) |
| 103 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 104 | return bio->bi_phys_segments & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static inline int raid5_bi_hw_segments(struct bio *bio) |
| 108 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 109 | return (bio->bi_phys_segments >> 16) & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static inline int raid5_dec_bi_phys_segments(struct bio *bio) |
| 113 | { |
| 114 | --bio->bi_phys_segments; |
| 115 | return raid5_bi_phys_segments(bio); |
| 116 | } |
| 117 | |
| 118 | static inline int raid5_dec_bi_hw_segments(struct bio *bio) |
| 119 | { |
| 120 | unsigned short val = raid5_bi_hw_segments(bio); |
| 121 | |
| 122 | --val; |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 123 | bio->bi_phys_segments = (val << 16) | raid5_bi_phys_segments(bio); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 124 | return val; |
| 125 | } |
| 126 | |
| 127 | static inline void raid5_set_bi_hw_segments(struct bio *bio, unsigned int cnt) |
| 128 | { |
Namhyung Kim | 9b2dc8b | 2011-06-13 14:48:22 +0900 | [diff] [blame] | 129 | bio->bi_phys_segments = raid5_bi_phys_segments(bio) | (cnt << 16); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 130 | } |
| 131 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 132 | /* Find first data disk in a raid6 stripe */ |
| 133 | static inline int raid6_d0(struct stripe_head *sh) |
| 134 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 135 | if (sh->ddf_layout) |
| 136 | /* ddf always start from first device */ |
| 137 | return 0; |
| 138 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 139 | if (sh->qd_idx == sh->disks - 1) |
| 140 | return 0; |
| 141 | else |
| 142 | return sh->qd_idx + 1; |
| 143 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 144 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 145 | { |
| 146 | disk++; |
| 147 | return (disk < raid_disks) ? disk : 0; |
| 148 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 149 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 150 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 151 | * We need to map each disk to a 'slot', where the data disks are slot |
| 152 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 153 | * is raid_disks-1. This help does that mapping. |
| 154 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 155 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 156 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 157 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 158 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 159 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 160 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 161 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 162 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 163 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 164 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 165 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 166 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 167 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 168 | return slot; |
| 169 | } |
| 170 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 171 | static void return_io(struct bio *return_bi) |
| 172 | { |
| 173 | struct bio *bi = return_bi; |
| 174 | while (bi) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 175 | |
| 176 | return_bi = bi->bi_next; |
| 177 | bi->bi_next = NULL; |
| 178 | bi->bi_size = 0; |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 179 | bio_endio(bi, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 180 | bi = return_bi; |
| 181 | } |
| 182 | } |
| 183 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 184 | static void print_raid5_conf (struct r5conf *conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 186 | static int stripe_operations_active(struct stripe_head *sh) |
| 187 | { |
| 188 | return sh->check_state || sh->reconstruct_state || |
| 189 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 190 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 191 | } |
| 192 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 193 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | if (atomic_dec_and_test(&sh->count)) { |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 196 | BUG_ON(!list_empty(&sh->lru)); |
| 197 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 199 | if (test_bit(STRIPE_DELAYED, &sh->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | list_add_tail(&sh->lru, &conf->delayed_list); |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 201 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
| 202 | sh->bm_seq - conf->seq_write > 0) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 203 | list_add_tail(&sh->lru, &conf->bitmap_list); |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 204 | else { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 205 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | list_add_tail(&sh->lru, &conf->handle_list); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | md_wakeup_thread(conf->mddev->thread); |
| 209 | } else { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 210 | BUG_ON(stripe_operations_active(sh)); |
majianpeng | 41fe75f | 2012-03-13 11:21:25 +1100 | [diff] [blame] | 211 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 212 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 213 | < IO_THRESHOLD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | md_wakeup_thread(conf->mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | atomic_dec(&conf->active_stripes); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 216 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 217 | list_add_tail(&sh->lru, &conf->inactive_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | wake_up(&conf->wait_for_stripe); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 219 | if (conf->retry_read_aligned) |
| 220 | md_wakeup_thread(conf->mddev->thread); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | static void release_stripe(struct stripe_head *sh) |
| 227 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 228 | struct r5conf *conf = sh->raid_conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | unsigned long flags; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | spin_lock_irqsave(&conf->device_lock, flags); |
| 232 | __release_stripe(conf, sh); |
| 233 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 234 | } |
| 235 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 236 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 238 | pr_debug("remove_hash(), stripe %llu\n", |
| 239 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 241 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 244 | static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 246 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 248 | pr_debug("insert_hash(), stripe %llu\n", |
| 249 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 251 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | |
| 255 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 256 | static struct stripe_head *get_free_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
| 258 | struct stripe_head *sh = NULL; |
| 259 | struct list_head *first; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | if (list_empty(&conf->inactive_list)) |
| 262 | goto out; |
| 263 | first = conf->inactive_list.next; |
| 264 | sh = list_entry(first, struct stripe_head, lru); |
| 265 | list_del_init(first); |
| 266 | remove_hash(sh); |
| 267 | atomic_inc(&conf->active_stripes); |
| 268 | out: |
| 269 | return sh; |
| 270 | } |
| 271 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 272 | static void shrink_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
| 274 | struct page *p; |
| 275 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 276 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 278 | for (i = 0; i < num ; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | p = sh->dev[i].page; |
| 280 | if (!p) |
| 281 | continue; |
| 282 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 283 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 287 | static int grow_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
| 289 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 290 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 292 | for (i = 0; i < num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | struct page *page; |
| 294 | |
| 295 | if (!(page = alloc_page(GFP_KERNEL))) { |
| 296 | return 1; |
| 297 | } |
| 298 | sh->dev[i].page = page; |
| 299 | } |
| 300 | return 0; |
| 301 | } |
| 302 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 303 | static void raid5_build_block(struct stripe_head *sh, int i, int previous); |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 304 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 305 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 307 | 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] | 308 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 309 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 310 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 312 | BUG_ON(atomic_read(&sh->count) != 0); |
| 313 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 314 | BUG_ON(stripe_operations_active(sh)); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 315 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 316 | pr_debug("init_stripe called, stripe %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | (unsigned long long)sh->sector); |
| 318 | |
| 319 | remove_hash(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 320 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 321 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 322 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 324 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | sh->state = 0; |
| 326 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 327 | |
| 328 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | struct r5dev *dev = &sh->dev[i]; |
| 330 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 331 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | test_bit(R5_LOCKED, &dev->flags)) { |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 333 | 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] | 334 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 335 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | test_bit(R5_LOCKED, &dev->flags)); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 337 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 340 | raid5_build_block(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | insert_hash(conf, sh); |
| 343 | } |
| 344 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 345 | static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 346 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
| 348 | struct stripe_head *sh; |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 349 | struct hlist_node *hn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 351 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 352 | hlist_for_each_entry(sh, hn, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 353 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 355 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return NULL; |
| 357 | } |
| 358 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 359 | /* |
| 360 | * Need to check if array has failed when deciding whether to: |
| 361 | * - start an array |
| 362 | * - remove non-faulty devices |
| 363 | * - add a spare |
| 364 | * - allow a reshape |
| 365 | * This determination is simple when no reshape is happening. |
| 366 | * However if there is a reshape, we need to carefully check |
| 367 | * both the before and after sections. |
| 368 | * This is because some failed devices may only affect one |
| 369 | * of the two sections, and some non-in_sync devices may |
| 370 | * be insync in the section most affected by failed devices. |
| 371 | */ |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 372 | static int calc_degraded(struct r5conf *conf) |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 373 | { |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 374 | int degraded, degraded2; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 375 | int i; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 376 | |
| 377 | rcu_read_lock(); |
| 378 | degraded = 0; |
| 379 | for (i = 0; i < conf->previous_raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 380 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 381 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 382 | degraded++; |
| 383 | else if (test_bit(In_sync, &rdev->flags)) |
| 384 | ; |
| 385 | else |
| 386 | /* not in-sync or faulty. |
| 387 | * If the reshape increases the number of devices, |
| 388 | * this is being recovered by the reshape, so |
| 389 | * this 'previous' section is not in_sync. |
| 390 | * If the number of devices is being reduced however, |
| 391 | * the device can only be part of the array if |
| 392 | * we are reverting a reshape, so this section will |
| 393 | * be in-sync. |
| 394 | */ |
| 395 | if (conf->raid_disks >= conf->previous_raid_disks) |
| 396 | degraded++; |
| 397 | } |
| 398 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 399 | if (conf->raid_disks == conf->previous_raid_disks) |
| 400 | return degraded; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 401 | rcu_read_lock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 402 | degraded2 = 0; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 403 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 404 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 405 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 406 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 407 | else if (test_bit(In_sync, &rdev->flags)) |
| 408 | ; |
| 409 | else |
| 410 | /* not in-sync or faulty. |
| 411 | * If reshape increases the number of devices, this |
| 412 | * section has already been recovered, else it |
| 413 | * almost certainly hasn't. |
| 414 | */ |
| 415 | if (conf->raid_disks <= conf->previous_raid_disks) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 416 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 417 | } |
| 418 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 419 | if (degraded2 > degraded) |
| 420 | return degraded2; |
| 421 | return degraded; |
| 422 | } |
| 423 | |
| 424 | static int has_failed(struct r5conf *conf) |
| 425 | { |
| 426 | int degraded; |
| 427 | |
| 428 | if (conf->mddev->reshape_position == MaxSector) |
| 429 | return conf->mddev->degraded > conf->max_degraded; |
| 430 | |
| 431 | degraded = calc_degraded(conf); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 432 | if (degraded > conf->max_degraded) |
| 433 | return 1; |
| 434 | return 0; |
| 435 | } |
| 436 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 437 | static struct stripe_head * |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 438 | get_active_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 439 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
| 441 | struct stripe_head *sh; |
| 442 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 443 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | spin_lock_irq(&conf->device_lock); |
| 446 | |
| 447 | do { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 448 | wait_event_lock_irq(conf->wait_for_stripe, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 449 | conf->quiesce == 0 || noquiesce, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 450 | conf->device_lock, /* nothing */); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 451 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | if (!sh) { |
| 453 | if (!conf->inactive_blocked) |
| 454 | sh = get_free_stripe(conf); |
| 455 | if (noblock && sh == NULL) |
| 456 | break; |
| 457 | if (!sh) { |
| 458 | conf->inactive_blocked = 1; |
| 459 | wait_event_lock_irq(conf->wait_for_stripe, |
| 460 | !list_empty(&conf->inactive_list) && |
NeilBrown | 5036805 | 2005-12-12 02:39:17 -0800 | [diff] [blame] | 461 | (atomic_read(&conf->active_stripes) |
| 462 | < (conf->max_nr_stripes *3/4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | || !conf->inactive_blocked), |
| 464 | conf->device_lock, |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 465 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | conf->inactive_blocked = 0; |
| 467 | } else |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 468 | init_stripe(sh, sector, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } else { |
| 470 | if (atomic_read(&sh->count)) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 471 | BUG_ON(!list_empty(&sh->lru) |
| 472 | && !test_bit(STRIPE_EXPANDING, &sh->state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } else { |
| 474 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 475 | atomic_inc(&conf->active_stripes); |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 476 | if (list_empty(&sh->lru) && |
| 477 | !test_bit(STRIPE_EXPANDING, &sh->state)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 478 | BUG(); |
| 479 | list_del_init(&sh->lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | } while (sh == NULL); |
| 483 | |
| 484 | if (sh) |
| 485 | atomic_inc(&sh->count); |
| 486 | |
| 487 | spin_unlock_irq(&conf->device_lock); |
| 488 | return sh; |
| 489 | } |
| 490 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 491 | static void |
| 492 | raid5_end_read_request(struct bio *bi, int error); |
| 493 | static void |
| 494 | raid5_end_write_request(struct bio *bi, int error); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 495 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 496 | 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] | 497 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 498 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 499 | int i, disks = sh->disks; |
| 500 | |
| 501 | might_sleep(); |
| 502 | |
| 503 | for (i = disks; i--; ) { |
| 504 | int rw; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 505 | int replace_only = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 506 | struct bio *bi, *rbi; |
| 507 | struct md_rdev *rdev, *rrdev = NULL; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 508 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { |
| 509 | if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) |
| 510 | rw = WRITE_FUA; |
| 511 | else |
| 512 | rw = WRITE; |
| 513 | } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 514 | rw = READ; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 515 | else if (test_and_clear_bit(R5_WantReplace, |
| 516 | &sh->dev[i].flags)) { |
| 517 | rw = WRITE; |
| 518 | replace_only = 1; |
| 519 | } else |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 520 | continue; |
| 521 | |
| 522 | bi = &sh->dev[i].req; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 523 | rbi = &sh->dev[i].rreq; /* For writing to replacement */ |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 524 | |
| 525 | bi->bi_rw = rw; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 526 | rbi->bi_rw = rw; |
| 527 | if (rw & WRITE) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 528 | bi->bi_end_io = raid5_end_write_request; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 529 | rbi->bi_end_io = raid5_end_write_request; |
| 530 | } else |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 531 | bi->bi_end_io = raid5_end_read_request; |
| 532 | |
| 533 | rcu_read_lock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 534 | rrdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 535 | smp_mb(); /* Ensure that if rrdev is NULL, rdev won't be */ |
| 536 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 537 | if (!rdev) { |
| 538 | rdev = rrdev; |
| 539 | rrdev = NULL; |
| 540 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 541 | if (rw & WRITE) { |
| 542 | if (replace_only) |
| 543 | rdev = NULL; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 544 | if (rdev == rrdev) |
| 545 | /* We raced and saw duplicates */ |
| 546 | rrdev = NULL; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 547 | } else { |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 548 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags) && rrdev) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 549 | rdev = rrdev; |
| 550 | rrdev = NULL; |
| 551 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 552 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 553 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 554 | rdev = NULL; |
| 555 | if (rdev) |
| 556 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 557 | if (rrdev && test_bit(Faulty, &rrdev->flags)) |
| 558 | rrdev = NULL; |
| 559 | if (rrdev) |
| 560 | atomic_inc(&rrdev->nr_pending); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 561 | rcu_read_unlock(); |
| 562 | |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 563 | /* We have already checked bad blocks for reads. Now |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 564 | * need to check for writes. We never accept write errors |
| 565 | * on the replacement, so we don't to check rrdev. |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 566 | */ |
| 567 | while ((rw & WRITE) && rdev && |
| 568 | test_bit(WriteErrorSeen, &rdev->flags)) { |
| 569 | sector_t first_bad; |
| 570 | int bad_sectors; |
| 571 | int bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 572 | &first_bad, &bad_sectors); |
| 573 | if (!bad) |
| 574 | break; |
| 575 | |
| 576 | if (bad < 0) { |
| 577 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 578 | if (!conf->mddev->external && |
| 579 | conf->mddev->flags) { |
| 580 | /* It is very unlikely, but we might |
| 581 | * still need to write out the |
| 582 | * bad block log - better give it |
| 583 | * a chance*/ |
| 584 | md_check_recovery(conf->mddev); |
| 585 | } |
| 586 | md_wait_for_blocked_rdev(rdev, conf->mddev); |
| 587 | } else { |
| 588 | /* Acknowledged bad block - skip the write */ |
| 589 | rdev_dec_pending(rdev, conf->mddev); |
| 590 | rdev = NULL; |
| 591 | } |
| 592 | } |
| 593 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 594 | if (rdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 595 | if (s->syncing || s->expanding || s->expanded |
| 596 | || s->replacing) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 597 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 598 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 599 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 600 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 601 | bi->bi_bdev = rdev->bdev; |
| 602 | pr_debug("%s: for %llu schedule op %ld on disc %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 603 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 604 | bi->bi_rw, i); |
| 605 | atomic_inc(&sh->count); |
| 606 | bi->bi_sector = sh->sector + rdev->data_offset; |
| 607 | bi->bi_flags = 1 << BIO_UPTODATE; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 608 | bi->bi_idx = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 609 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 610 | bi->bi_io_vec[0].bv_offset = 0; |
| 611 | bi->bi_size = STRIPE_SIZE; |
| 612 | bi->bi_next = NULL; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 613 | if (rrdev) |
| 614 | set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 615 | generic_make_request(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 616 | } |
| 617 | if (rrdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 618 | if (s->syncing || s->expanding || s->expanded |
| 619 | || s->replacing) |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 620 | md_sync_acct(rrdev->bdev, STRIPE_SECTORS); |
| 621 | |
| 622 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 623 | |
| 624 | rbi->bi_bdev = rrdev->bdev; |
| 625 | pr_debug("%s: for %llu schedule op %ld on " |
| 626 | "replacement disc %d\n", |
| 627 | __func__, (unsigned long long)sh->sector, |
| 628 | rbi->bi_rw, i); |
| 629 | atomic_inc(&sh->count); |
| 630 | rbi->bi_sector = sh->sector + rrdev->data_offset; |
| 631 | rbi->bi_flags = 1 << BIO_UPTODATE; |
| 632 | rbi->bi_idx = 0; |
| 633 | rbi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 634 | rbi->bi_io_vec[0].bv_offset = 0; |
| 635 | rbi->bi_size = STRIPE_SIZE; |
| 636 | rbi->bi_next = NULL; |
| 637 | generic_make_request(rbi); |
| 638 | } |
| 639 | if (!rdev && !rrdev) { |
Namhyung Kim | b062962 | 2011-06-14 14:20:19 +1000 | [diff] [blame] | 640 | if (rw & WRITE) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 641 | set_bit(STRIPE_DEGRADED, &sh->state); |
| 642 | pr_debug("skip op %ld on disc %d for sector %llu\n", |
| 643 | bi->bi_rw, i, (unsigned long long)sh->sector); |
| 644 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 645 | set_bit(STRIPE_HANDLE, &sh->state); |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | static struct dma_async_tx_descriptor * |
| 651 | async_copy_data(int frombio, struct bio *bio, struct page *page, |
| 652 | sector_t sector, struct dma_async_tx_descriptor *tx) |
| 653 | { |
| 654 | struct bio_vec *bvl; |
| 655 | struct page *bio_page; |
| 656 | int i; |
| 657 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 658 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 659 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 660 | |
| 661 | if (bio->bi_sector >= sector) |
| 662 | page_offset = (signed)(bio->bi_sector - sector) * 512; |
| 663 | else |
| 664 | page_offset = (signed)(sector - bio->bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 665 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 666 | if (frombio) |
| 667 | flags |= ASYNC_TX_FENCE; |
| 668 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 669 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 670 | bio_for_each_segment(bvl, bio, i) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 671 | int len = bvl->bv_len; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 672 | int clen; |
| 673 | int b_offset = 0; |
| 674 | |
| 675 | if (page_offset < 0) { |
| 676 | b_offset = -page_offset; |
| 677 | page_offset += b_offset; |
| 678 | len -= b_offset; |
| 679 | } |
| 680 | |
| 681 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 682 | clen = STRIPE_SIZE - page_offset; |
| 683 | else |
| 684 | clen = len; |
| 685 | |
| 686 | if (clen > 0) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 687 | b_offset += bvl->bv_offset; |
| 688 | bio_page = bvl->bv_page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 689 | if (frombio) |
| 690 | tx = async_memcpy(page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 691 | b_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 692 | else |
| 693 | tx = async_memcpy(bio_page, page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 694 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 695 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 696 | /* chain the operations */ |
| 697 | submit.depend_tx = tx; |
| 698 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 699 | if (clen < len) /* hit end of page */ |
| 700 | break; |
| 701 | page_offset += len; |
| 702 | } |
| 703 | |
| 704 | return tx; |
| 705 | } |
| 706 | |
| 707 | static void ops_complete_biofill(void *stripe_head_ref) |
| 708 | { |
| 709 | struct stripe_head *sh = stripe_head_ref; |
| 710 | struct bio *return_bi = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 711 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 712 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 713 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 714 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 715 | (unsigned long long)sh->sector); |
| 716 | |
| 717 | /* clear completed biofills */ |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 718 | spin_lock_irq(&conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 719 | for (i = sh->disks; i--; ) { |
| 720 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 721 | |
| 722 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 723 | /* and check if we need to reply to a read request, |
| 724 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 725 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 726 | */ |
| 727 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 728 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 729 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 730 | BUG_ON(!dev->read); |
| 731 | rbi = dev->read; |
| 732 | dev->read = NULL; |
| 733 | while (rbi && rbi->bi_sector < |
| 734 | dev->sector + STRIPE_SECTORS) { |
| 735 | rbi2 = r5_next_bio(rbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 736 | if (!raid5_dec_bi_phys_segments(rbi)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 737 | rbi->bi_next = return_bi; |
| 738 | return_bi = rbi; |
| 739 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 740 | rbi = rbi2; |
| 741 | } |
| 742 | } |
| 743 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 744 | spin_unlock_irq(&conf->device_lock); |
| 745 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 746 | |
| 747 | return_io(return_bi); |
| 748 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 749 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 750 | release_stripe(sh); |
| 751 | } |
| 752 | |
| 753 | static void ops_run_biofill(struct stripe_head *sh) |
| 754 | { |
| 755 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 756 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 757 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 758 | int i; |
| 759 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 760 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 761 | (unsigned long long)sh->sector); |
| 762 | |
| 763 | for (i = sh->disks; i--; ) { |
| 764 | struct r5dev *dev = &sh->dev[i]; |
| 765 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 766 | struct bio *rbi; |
| 767 | spin_lock_irq(&conf->device_lock); |
| 768 | dev->read = rbi = dev->toread; |
| 769 | dev->toread = NULL; |
| 770 | spin_unlock_irq(&conf->device_lock); |
| 771 | while (rbi && rbi->bi_sector < |
| 772 | dev->sector + STRIPE_SECTORS) { |
| 773 | tx = async_copy_data(0, rbi, dev->page, |
| 774 | dev->sector, tx); |
| 775 | rbi = r5_next_bio(rbi, dev->sector); |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 781 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 782 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 785 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 786 | { |
| 787 | struct r5dev *tgt; |
| 788 | |
| 789 | if (target < 0) |
| 790 | return; |
| 791 | |
| 792 | tgt = &sh->dev[target]; |
| 793 | set_bit(R5_UPTODATE, &tgt->flags); |
| 794 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 795 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 796 | } |
| 797 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 798 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 799 | { |
| 800 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 801 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 802 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 803 | (unsigned long long)sh->sector); |
| 804 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 805 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 806 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 807 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 808 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 809 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 810 | if (sh->check_state == check_state_compute_run) |
| 811 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 812 | set_bit(STRIPE_HANDLE, &sh->state); |
| 813 | release_stripe(sh); |
| 814 | } |
| 815 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 816 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 817 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 818 | struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 819 | { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 820 | return percpu->scribble + sizeof(struct page *) * (sh->disks + 2); |
| 821 | } |
| 822 | |
| 823 | static struct dma_async_tx_descriptor * |
| 824 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 825 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 826 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 827 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 828 | int target = sh->ops.target; |
| 829 | struct r5dev *tgt = &sh->dev[target]; |
| 830 | struct page *xor_dest = tgt->page; |
| 831 | int count = 0; |
| 832 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 833 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 834 | int i; |
| 835 | |
| 836 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 837 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 838 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 839 | |
| 840 | for (i = disks; i--; ) |
| 841 | if (i != target) |
| 842 | xor_srcs[count++] = sh->dev[i].page; |
| 843 | |
| 844 | atomic_inc(&sh->count); |
| 845 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 846 | 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] | 847 | ops_complete_compute, sh, to_addr_conv(sh, percpu)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 848 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 849 | 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] | 850 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 851 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 852 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 853 | return tx; |
| 854 | } |
| 855 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 856 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 857 | * @srcs - (struct page *) array of size sh->disks |
| 858 | * @sh - stripe_head to parse |
| 859 | * |
| 860 | * Populates srcs in proper layout order for the stripe and returns the |
| 861 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 862 | * destination buffer is recorded in srcs[count] and the Q destination |
| 863 | * is recorded in srcs[count+1]]. |
| 864 | */ |
| 865 | static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh) |
| 866 | { |
| 867 | int disks = sh->disks; |
| 868 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 869 | int d0_idx = raid6_d0(sh); |
| 870 | int count; |
| 871 | int i; |
| 872 | |
| 873 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 874 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 875 | |
| 876 | count = 0; |
| 877 | i = d0_idx; |
| 878 | do { |
| 879 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 880 | |
| 881 | srcs[slot] = sh->dev[i].page; |
| 882 | i = raid6_next_disk(i, disks); |
| 883 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 884 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 885 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | static struct dma_async_tx_descriptor * |
| 889 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 890 | { |
| 891 | int disks = sh->disks; |
| 892 | struct page **blocks = percpu->scribble; |
| 893 | int target; |
| 894 | int qd_idx = sh->qd_idx; |
| 895 | struct dma_async_tx_descriptor *tx; |
| 896 | struct async_submit_ctl submit; |
| 897 | struct r5dev *tgt; |
| 898 | struct page *dest; |
| 899 | int i; |
| 900 | int count; |
| 901 | |
| 902 | if (sh->ops.target < 0) |
| 903 | target = sh->ops.target2; |
| 904 | else if (sh->ops.target2 < 0) |
| 905 | target = sh->ops.target; |
| 906 | else |
| 907 | /* we should only have one valid target */ |
| 908 | BUG(); |
| 909 | BUG_ON(target < 0); |
| 910 | pr_debug("%s: stripe %llu block: %d\n", |
| 911 | __func__, (unsigned long long)sh->sector, target); |
| 912 | |
| 913 | tgt = &sh->dev[target]; |
| 914 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 915 | dest = tgt->page; |
| 916 | |
| 917 | atomic_inc(&sh->count); |
| 918 | |
| 919 | if (target == qd_idx) { |
| 920 | count = set_syndrome_sources(blocks, sh); |
| 921 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 922 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 923 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 924 | ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 925 | to_addr_conv(sh, percpu)); |
| 926 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 927 | } else { |
| 928 | /* Compute any data- or p-drive using XOR */ |
| 929 | count = 0; |
| 930 | for (i = disks; i-- ; ) { |
| 931 | if (i == target || i == qd_idx) |
| 932 | continue; |
| 933 | blocks[count++] = sh->dev[i].page; |
| 934 | } |
| 935 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 936 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 937 | NULL, ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 938 | to_addr_conv(sh, percpu)); |
| 939 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 940 | } |
| 941 | |
| 942 | return tx; |
| 943 | } |
| 944 | |
| 945 | static struct dma_async_tx_descriptor * |
| 946 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 947 | { |
| 948 | int i, count, disks = sh->disks; |
| 949 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 950 | int d0_idx = raid6_d0(sh); |
| 951 | int faila = -1, failb = -1; |
| 952 | int target = sh->ops.target; |
| 953 | int target2 = sh->ops.target2; |
| 954 | struct r5dev *tgt = &sh->dev[target]; |
| 955 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 956 | struct dma_async_tx_descriptor *tx; |
| 957 | struct page **blocks = percpu->scribble; |
| 958 | struct async_submit_ctl submit; |
| 959 | |
| 960 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 961 | __func__, (unsigned long long)sh->sector, target, target2); |
| 962 | BUG_ON(target < 0 || target2 < 0); |
| 963 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 964 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 965 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 966 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 967 | * slot number conversion for 'faila' and 'failb' |
| 968 | */ |
| 969 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 970 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 971 | count = 0; |
| 972 | i = d0_idx; |
| 973 | do { |
| 974 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 975 | |
| 976 | blocks[slot] = sh->dev[i].page; |
| 977 | |
| 978 | if (i == target) |
| 979 | faila = slot; |
| 980 | if (i == target2) |
| 981 | failb = slot; |
| 982 | i = raid6_next_disk(i, disks); |
| 983 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 984 | |
| 985 | BUG_ON(faila == failb); |
| 986 | if (failb < faila) |
| 987 | swap(faila, failb); |
| 988 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 989 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 990 | |
| 991 | atomic_inc(&sh->count); |
| 992 | |
| 993 | if (failb == syndrome_disks+1) { |
| 994 | /* Q disk is one of the missing disks */ |
| 995 | if (faila == syndrome_disks) { |
| 996 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 997 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 998 | ops_complete_compute, sh, |
| 999 | to_addr_conv(sh, percpu)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1000 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1001 | STRIPE_SIZE, &submit); |
| 1002 | } else { |
| 1003 | struct page *dest; |
| 1004 | int data_target; |
| 1005 | int qd_idx = sh->qd_idx; |
| 1006 | |
| 1007 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 1008 | if (target == qd_idx) |
| 1009 | data_target = target2; |
| 1010 | else |
| 1011 | data_target = target; |
| 1012 | |
| 1013 | count = 0; |
| 1014 | for (i = disks; i-- ; ) { |
| 1015 | if (i == data_target || i == qd_idx) |
| 1016 | continue; |
| 1017 | blocks[count++] = sh->dev[i].page; |
| 1018 | } |
| 1019 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1020 | init_async_submit(&submit, |
| 1021 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1022 | NULL, NULL, NULL, |
| 1023 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1024 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 1025 | &submit); |
| 1026 | |
| 1027 | count = set_syndrome_sources(blocks, sh); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1028 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 1029 | ops_complete_compute, sh, |
| 1030 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1031 | return async_gen_syndrome(blocks, 0, count+2, |
| 1032 | STRIPE_SIZE, &submit); |
| 1033 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1034 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1035 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1036 | ops_complete_compute, sh, |
| 1037 | to_addr_conv(sh, percpu)); |
| 1038 | if (failb == syndrome_disks) { |
| 1039 | /* We're missing D+P. */ |
| 1040 | return async_raid6_datap_recov(syndrome_disks+2, |
| 1041 | STRIPE_SIZE, faila, |
| 1042 | blocks, &submit); |
| 1043 | } else { |
| 1044 | /* We're missing D+D. */ |
| 1045 | return async_raid6_2data_recov(syndrome_disks+2, |
| 1046 | STRIPE_SIZE, faila, failb, |
| 1047 | blocks, &submit); |
| 1048 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1053 | static void ops_complete_prexor(void *stripe_head_ref) |
| 1054 | { |
| 1055 | struct stripe_head *sh = stripe_head_ref; |
| 1056 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1057 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1058 | (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | static struct dma_async_tx_descriptor * |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1062 | ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1063 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1064 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1065 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1066 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1067 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1068 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1069 | |
| 1070 | /* existing parity data subtracted */ |
| 1071 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1072 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1073 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1074 | (unsigned long long)sh->sector); |
| 1075 | |
| 1076 | for (i = disks; i--; ) { |
| 1077 | struct r5dev *dev = &sh->dev[i]; |
| 1078 | /* Only process blocks that are known to be uptodate */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1079 | if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1080 | xor_srcs[count++] = dev->page; |
| 1081 | } |
| 1082 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1083 | 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] | 1084 | ops_complete_prexor, sh, to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1085 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1086 | |
| 1087 | return tx; |
| 1088 | } |
| 1089 | |
| 1090 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1091 | 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] | 1092 | { |
| 1093 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1094 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1095 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1096 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1097 | (unsigned long long)sh->sector); |
| 1098 | |
| 1099 | for (i = disks; i--; ) { |
| 1100 | struct r5dev *dev = &sh->dev[i]; |
| 1101 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1102 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1103 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1104 | struct bio *wbi; |
| 1105 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 1106 | spin_lock_irq(&sh->raid_conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1107 | chosen = dev->towrite; |
| 1108 | dev->towrite = NULL; |
| 1109 | BUG_ON(dev->written); |
| 1110 | wbi = dev->written = chosen; |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 1111 | spin_unlock_irq(&sh->raid_conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1112 | |
| 1113 | while (wbi && wbi->bi_sector < |
| 1114 | dev->sector + STRIPE_SECTORS) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1115 | if (wbi->bi_rw & REQ_FUA) |
| 1116 | set_bit(R5_WantFUA, &dev->flags); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1117 | tx = async_copy_data(1, wbi, dev->page, |
| 1118 | dev->sector, tx); |
| 1119 | wbi = r5_next_bio(wbi, dev->sector); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | return tx; |
| 1125 | } |
| 1126 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1127 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1128 | { |
| 1129 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1130 | int disks = sh->disks; |
| 1131 | int pd_idx = sh->pd_idx; |
| 1132 | int qd_idx = sh->qd_idx; |
| 1133 | int i; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1134 | bool fua = false; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1135 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1136 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1137 | (unsigned long long)sh->sector); |
| 1138 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1139 | for (i = disks; i--; ) |
| 1140 | fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); |
| 1141 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1142 | for (i = disks; i--; ) { |
| 1143 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1144 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1145 | if (dev->written || i == pd_idx || i == qd_idx) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1146 | set_bit(R5_UPTODATE, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1147 | if (fua) |
| 1148 | set_bit(R5_WantFUA, &dev->flags); |
| 1149 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1152 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 1153 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 1154 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 1155 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 1156 | else { |
| 1157 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 1158 | sh->reconstruct_state = reconstruct_state_result; |
| 1159 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1160 | |
| 1161 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1162 | release_stripe(sh); |
| 1163 | } |
| 1164 | |
| 1165 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1166 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1167 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1168 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1169 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1170 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1171 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1172 | int count = 0, pd_idx = sh->pd_idx, i; |
| 1173 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1174 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1175 | unsigned long flags; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1176 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1177 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1178 | (unsigned long long)sh->sector); |
| 1179 | |
| 1180 | /* check if prexor is active which means only process blocks |
| 1181 | * that are part of a read-modify-write (written) |
| 1182 | */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1183 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1184 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1185 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1186 | for (i = disks; i--; ) { |
| 1187 | struct r5dev *dev = &sh->dev[i]; |
| 1188 | if (dev->written) |
| 1189 | xor_srcs[count++] = dev->page; |
| 1190 | } |
| 1191 | } else { |
| 1192 | xor_dest = sh->dev[pd_idx].page; |
| 1193 | for (i = disks; i--; ) { |
| 1194 | struct r5dev *dev = &sh->dev[i]; |
| 1195 | if (i != pd_idx) |
| 1196 | xor_srcs[count++] = dev->page; |
| 1197 | } |
| 1198 | } |
| 1199 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1200 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1201 | * 2/ if we did not prexor then we are redoing the parity |
| 1202 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1203 | * for the synchronous xor case |
| 1204 | */ |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 1205 | flags = ASYNC_TX_ACK | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1206 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
| 1207 | |
| 1208 | atomic_inc(&sh->count); |
| 1209 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1210 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, sh, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1211 | to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1212 | if (unlikely(count == 1)) |
| 1213 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1214 | else |
| 1215 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1218 | static void |
| 1219 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1220 | struct dma_async_tx_descriptor *tx) |
| 1221 | { |
| 1222 | struct async_submit_ctl submit; |
| 1223 | struct page **blocks = percpu->scribble; |
| 1224 | int count; |
| 1225 | |
| 1226 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1227 | |
| 1228 | count = set_syndrome_sources(blocks, sh); |
| 1229 | |
| 1230 | atomic_inc(&sh->count); |
| 1231 | |
| 1232 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct, |
| 1233 | sh, to_addr_conv(sh, percpu)); |
| 1234 | async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static void ops_complete_check(void *stripe_head_ref) |
| 1238 | { |
| 1239 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1240 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1241 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1242 | (unsigned long long)sh->sector); |
| 1243 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1244 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1245 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1246 | release_stripe(sh); |
| 1247 | } |
| 1248 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1249 | 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] | 1250 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1251 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1252 | int pd_idx = sh->pd_idx; |
| 1253 | int qd_idx = sh->qd_idx; |
| 1254 | struct page *xor_dest; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1255 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1256 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1257 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1258 | int count; |
| 1259 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1260 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1261 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1262 | (unsigned long long)sh->sector); |
| 1263 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1264 | count = 0; |
| 1265 | xor_dest = sh->dev[pd_idx].page; |
| 1266 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1267 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1268 | if (i == pd_idx || i == qd_idx) |
| 1269 | continue; |
| 1270 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1273 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
| 1274 | to_addr_conv(sh, percpu)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1275 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1276 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1277 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1278 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1279 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 1280 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1283 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 1284 | { |
| 1285 | struct page **srcs = percpu->scribble; |
| 1286 | struct async_submit_ctl submit; |
| 1287 | int count; |
| 1288 | |
| 1289 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 1290 | (unsigned long long)sh->sector, checkp); |
| 1291 | |
| 1292 | count = set_syndrome_sources(srcs, sh); |
| 1293 | if (!checkp) |
| 1294 | srcs[count] = NULL; |
| 1295 | |
| 1296 | atomic_inc(&sh->count); |
| 1297 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
| 1298 | sh, to_addr_conv(sh, percpu)); |
| 1299 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 1300 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 1301 | } |
| 1302 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1303 | 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] | 1304 | { |
| 1305 | int overlap_clear = 0, i, disks = sh->disks; |
| 1306 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1307 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1308 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1309 | struct raid5_percpu *percpu; |
| 1310 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1311 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1312 | cpu = get_cpu(); |
| 1313 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1314 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1315 | ops_run_biofill(sh); |
| 1316 | overlap_clear++; |
| 1317 | } |
| 1318 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1319 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1320 | if (level < 6) |
| 1321 | tx = ops_run_compute5(sh, percpu); |
| 1322 | else { |
| 1323 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 1324 | tx = ops_run_compute6_1(sh, percpu); |
| 1325 | else |
| 1326 | tx = ops_run_compute6_2(sh, percpu); |
| 1327 | } |
| 1328 | /* terminate the chain if reconstruct is not set to be run */ |
| 1329 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1330 | async_tx_ack(tx); |
| 1331 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1332 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1333 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1334 | tx = ops_run_prexor(sh, percpu, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1335 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1336 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1337 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1338 | overlap_clear++; |
| 1339 | } |
| 1340 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1341 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 1342 | if (level < 6) |
| 1343 | ops_run_reconstruct5(sh, percpu, tx); |
| 1344 | else |
| 1345 | ops_run_reconstruct6(sh, percpu, tx); |
| 1346 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1347 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1348 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 1349 | if (sh->check_state == check_state_run) |
| 1350 | ops_run_check_p(sh, percpu); |
| 1351 | else if (sh->check_state == check_state_run_q) |
| 1352 | ops_run_check_pq(sh, percpu, 0); |
| 1353 | else if (sh->check_state == check_state_run_pq) |
| 1354 | ops_run_check_pq(sh, percpu, 1); |
| 1355 | else |
| 1356 | BUG(); |
| 1357 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1358 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1359 | if (overlap_clear) |
| 1360 | for (i = disks; i--; ) { |
| 1361 | struct r5dev *dev = &sh->dev[i]; |
| 1362 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 1363 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 1364 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1365 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1368 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1369 | static void async_run_ops(void *param, async_cookie_t cookie) |
| 1370 | { |
| 1371 | struct stripe_head *sh = param; |
| 1372 | unsigned long ops_request = sh->ops.request; |
| 1373 | |
| 1374 | clear_bit_unlock(STRIPE_OPS_REQ_PENDING, &sh->state); |
| 1375 | wake_up(&sh->ops.wait_for_ops); |
| 1376 | |
| 1377 | __raid_run_ops(sh, ops_request); |
| 1378 | release_stripe(sh); |
| 1379 | } |
| 1380 | |
| 1381 | static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) |
| 1382 | { |
| 1383 | /* since handle_stripe can be called outside of raid5d context |
| 1384 | * we need to ensure sh->ops.request is de-staged before another |
| 1385 | * request arrives |
| 1386 | */ |
| 1387 | wait_event(sh->ops.wait_for_ops, |
| 1388 | !test_and_set_bit_lock(STRIPE_OPS_REQ_PENDING, &sh->state)); |
| 1389 | sh->ops.request = ops_request; |
| 1390 | |
| 1391 | atomic_inc(&sh->count); |
| 1392 | async_schedule(async_run_ops, sh); |
| 1393 | } |
| 1394 | #else |
| 1395 | #define raid_run_ops __raid_run_ops |
| 1396 | #endif |
| 1397 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1398 | static int grow_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | { |
| 1400 | struct stripe_head *sh; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1401 | sh = kmem_cache_zalloc(conf->slab_cache, GFP_KERNEL); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1402 | if (!sh) |
| 1403 | return 0; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1404 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1405 | sh->raid_conf = conf; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1406 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1407 | init_waitqueue_head(&sh->ops.wait_for_ops); |
| 1408 | #endif |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1409 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1410 | if (grow_buffers(sh)) { |
| 1411 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1412 | kmem_cache_free(conf->slab_cache, sh); |
| 1413 | return 0; |
| 1414 | } |
| 1415 | /* we just created an active stripe so... */ |
| 1416 | atomic_set(&sh->count, 1); |
| 1417 | atomic_inc(&conf->active_stripes); |
| 1418 | INIT_LIST_HEAD(&sh->lru); |
| 1419 | release_stripe(sh); |
| 1420 | return 1; |
| 1421 | } |
| 1422 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1423 | static int grow_stripes(struct r5conf *conf, int num) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1424 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1425 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1426 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 1428 | if (conf->mddev->gendisk) |
| 1429 | sprintf(conf->cache_name[0], |
| 1430 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 1431 | else |
| 1432 | sprintf(conf->cache_name[0], |
| 1433 | "raid%d-%p", conf->level, conf->mddev); |
| 1434 | sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]); |
| 1435 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1436 | conf->active_name = 0; |
| 1437 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1439 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | if (!sc) |
| 1441 | return 1; |
| 1442 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1443 | conf->pool_size = devs; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1444 | while (num--) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1445 | if (!grow_one_stripe(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | return 0; |
| 1448 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 1449 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1450 | /** |
| 1451 | * scribble_len - return the required size of the scribble region |
| 1452 | * @num - total number of disks in the array |
| 1453 | * |
| 1454 | * The size must be enough to contain: |
| 1455 | * 1/ a struct page pointer for each device in the array +2 |
| 1456 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 1457 | * (dma_map_page()) or page (page_address()) address. |
| 1458 | * |
| 1459 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 1460 | * calculate over all devices (not just the data blocks), using zeros in place |
| 1461 | * of the P and Q blocks. |
| 1462 | */ |
| 1463 | static size_t scribble_len(int num) |
| 1464 | { |
| 1465 | size_t len; |
| 1466 | |
| 1467 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
| 1468 | |
| 1469 | return len; |
| 1470 | } |
| 1471 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1472 | static int resize_stripes(struct r5conf *conf, int newsize) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1473 | { |
| 1474 | /* Make all the stripes able to hold 'newsize' devices. |
| 1475 | * New slots in each stripe get 'page' set to a new page. |
| 1476 | * |
| 1477 | * This happens in stages: |
| 1478 | * 1/ create a new kmem_cache and allocate the required number of |
| 1479 | * stripe_heads. |
| 1480 | * 2/ gather all the old stripe_heads and tranfer the pages across |
| 1481 | * to the new stripe_heads. This will have the side effect of |
| 1482 | * freezing the array as once all stripe_heads have been collected, |
| 1483 | * no IO will be possible. Old stripe heads are freed once their |
| 1484 | * pages have been transferred over, and the old kmem_cache is |
| 1485 | * freed when all stripes are done. |
| 1486 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 1487 | * we simple return a failre status - no need to clean anything up. |
| 1488 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 1489 | * If this fails, we don't bother trying the shrink the |
| 1490 | * stripe_heads down again, we just leave them as they are. |
| 1491 | * As each stripe_head is processed the new one is released into |
| 1492 | * active service. |
| 1493 | * |
| 1494 | * Once step2 is started, we cannot afford to wait for a write, |
| 1495 | * so we use GFP_NOIO allocations. |
| 1496 | */ |
| 1497 | struct stripe_head *osh, *nsh; |
| 1498 | LIST_HEAD(newstripes); |
| 1499 | struct disk_info *ndisks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1500 | unsigned long cpu; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1501 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1502 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1503 | int i; |
| 1504 | |
| 1505 | if (newsize <= conf->pool_size) |
| 1506 | return 0; /* never bother to shrink */ |
| 1507 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1508 | err = md_allow_write(conf->mddev); |
| 1509 | if (err) |
| 1510 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 1511 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1512 | /* Step 1 */ |
| 1513 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 1514 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1515 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1516 | if (!sc) |
| 1517 | return -ENOMEM; |
| 1518 | |
| 1519 | for (i = conf->max_nr_stripes; i; i--) { |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1520 | nsh = kmem_cache_zalloc(sc, GFP_KERNEL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1521 | if (!nsh) |
| 1522 | break; |
| 1523 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1524 | nsh->raid_conf = conf; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1525 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1526 | init_waitqueue_head(&nsh->ops.wait_for_ops); |
| 1527 | #endif |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1528 | |
| 1529 | list_add(&nsh->lru, &newstripes); |
| 1530 | } |
| 1531 | if (i) { |
| 1532 | /* didn't get enough, give up */ |
| 1533 | while (!list_empty(&newstripes)) { |
| 1534 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1535 | list_del(&nsh->lru); |
| 1536 | kmem_cache_free(sc, nsh); |
| 1537 | } |
| 1538 | kmem_cache_destroy(sc); |
| 1539 | return -ENOMEM; |
| 1540 | } |
| 1541 | /* Step 2 - Must use GFP_NOIO now. |
| 1542 | * OK, we have enough stripes, start collecting inactive |
| 1543 | * stripes and copying them over |
| 1544 | */ |
| 1545 | list_for_each_entry(nsh, &newstripes, lru) { |
| 1546 | spin_lock_irq(&conf->device_lock); |
| 1547 | wait_event_lock_irq(conf->wait_for_stripe, |
| 1548 | !list_empty(&conf->inactive_list), |
| 1549 | conf->device_lock, |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 1550 | ); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1551 | osh = get_free_stripe(conf); |
| 1552 | spin_unlock_irq(&conf->device_lock); |
| 1553 | atomic_set(&nsh->count, 1); |
| 1554 | for(i=0; i<conf->pool_size; i++) |
| 1555 | nsh->dev[i].page = osh->dev[i].page; |
| 1556 | for( ; i<newsize; i++) |
| 1557 | nsh->dev[i].page = NULL; |
| 1558 | kmem_cache_free(conf->slab_cache, osh); |
| 1559 | } |
| 1560 | kmem_cache_destroy(conf->slab_cache); |
| 1561 | |
| 1562 | /* Step 3. |
| 1563 | * At this point, we are holding all the stripes so the array |
| 1564 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1565 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1566 | */ |
| 1567 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 1568 | if (ndisks) { |
| 1569 | for (i=0; i<conf->raid_disks; i++) |
| 1570 | ndisks[i] = conf->disks[i]; |
| 1571 | kfree(conf->disks); |
| 1572 | conf->disks = ndisks; |
| 1573 | } else |
| 1574 | err = -ENOMEM; |
| 1575 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1576 | get_online_cpus(); |
| 1577 | conf->scribble_len = scribble_len(newsize); |
| 1578 | for_each_present_cpu(cpu) { |
| 1579 | struct raid5_percpu *percpu; |
| 1580 | void *scribble; |
| 1581 | |
| 1582 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 1583 | scribble = kmalloc(conf->scribble_len, GFP_NOIO); |
| 1584 | |
| 1585 | if (scribble) { |
| 1586 | kfree(percpu->scribble); |
| 1587 | percpu->scribble = scribble; |
| 1588 | } else { |
| 1589 | err = -ENOMEM; |
| 1590 | break; |
| 1591 | } |
| 1592 | } |
| 1593 | put_online_cpus(); |
| 1594 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1595 | /* Step 4, return new stripes to service */ |
| 1596 | while(!list_empty(&newstripes)) { |
| 1597 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1598 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1599 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1600 | for (i=conf->raid_disks; i < newsize; i++) |
| 1601 | if (nsh->dev[i].page == NULL) { |
| 1602 | struct page *p = alloc_page(GFP_NOIO); |
| 1603 | nsh->dev[i].page = p; |
| 1604 | if (!p) |
| 1605 | err = -ENOMEM; |
| 1606 | } |
| 1607 | release_stripe(nsh); |
| 1608 | } |
| 1609 | /* critical section pass, GFP_NOIO no longer needed */ |
| 1610 | |
| 1611 | conf->slab_cache = sc; |
| 1612 | conf->active_name = 1-conf->active_name; |
| 1613 | conf->pool_size = newsize; |
| 1614 | return err; |
| 1615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1617 | static int drop_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | { |
| 1619 | struct stripe_head *sh; |
| 1620 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1621 | spin_lock_irq(&conf->device_lock); |
| 1622 | sh = get_free_stripe(conf); |
| 1623 | spin_unlock_irq(&conf->device_lock); |
| 1624 | if (!sh) |
| 1625 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 1626 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1627 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1628 | kmem_cache_free(conf->slab_cache, sh); |
| 1629 | atomic_dec(&conf->active_stripes); |
| 1630 | return 1; |
| 1631 | } |
| 1632 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1633 | static void shrink_stripes(struct r5conf *conf) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1634 | { |
| 1635 | while (drop_one_stripe(conf)) |
| 1636 | ; |
| 1637 | |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1638 | if (conf->slab_cache) |
| 1639 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | conf->slab_cache = NULL; |
| 1641 | } |
| 1642 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1643 | static void raid5_end_read_request(struct bio * bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1645 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1646 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1647 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1649 | char b[BDEVNAME_SIZE]; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1650 | struct md_rdev *rdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | |
| 1653 | for (i=0 ; i<disks; i++) |
| 1654 | if (bi == &sh->dev[i].req) |
| 1655 | break; |
| 1656 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1657 | pr_debug("end_read_request %llu/%d, count: %d, uptodate %d.\n", |
| 1658 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | uptodate); |
| 1660 | if (i == disks) { |
| 1661 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1662 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1664 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1665 | /* If replacement finished while this request was outstanding, |
| 1666 | * 'replacement' might be NULL already. |
| 1667 | * In that case it moved down to 'rdev'. |
| 1668 | * rdev is not removed until all requests are finished. |
| 1669 | */ |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1670 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1671 | if (!rdev) |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1672 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | |
| 1674 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1676 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1677 | /* Note that this cannot happen on a |
| 1678 | * replacement device. We just fail those on |
| 1679 | * any error |
| 1680 | */ |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1681 | printk_ratelimited( |
| 1682 | KERN_INFO |
| 1683 | "md/raid:%s: read error corrected" |
| 1684 | " (%lu sectors at %llu on %s)\n", |
| 1685 | mdname(conf->mddev), STRIPE_SECTORS, |
| 1686 | (unsigned long long)(sh->sector |
| 1687 | + rdev->data_offset), |
| 1688 | bdevname(rdev->bdev, b)); |
Namhyung Kim | ddd5115 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1689 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1690 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1691 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
| 1692 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1693 | if (atomic_read(&rdev->read_errors)) |
| 1694 | atomic_set(&rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | } else { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1696 | const char *bdn = bdevname(rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1697 | int retry = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1700 | atomic_inc(&rdev->read_errors); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1701 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
| 1702 | printk_ratelimited( |
| 1703 | KERN_WARNING |
| 1704 | "md/raid:%s: read error on replacement device " |
| 1705 | "(sector %llu on %s).\n", |
| 1706 | mdname(conf->mddev), |
| 1707 | (unsigned long long)(sh->sector |
| 1708 | + rdev->data_offset), |
| 1709 | bdn); |
| 1710 | else if (conf->mddev->degraded >= conf->max_degraded) |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1711 | printk_ratelimited( |
| 1712 | KERN_WARNING |
| 1713 | "md/raid:%s: read error not correctable " |
| 1714 | "(sector %llu on %s).\n", |
| 1715 | mdname(conf->mddev), |
| 1716 | (unsigned long long)(sh->sector |
| 1717 | + rdev->data_offset), |
| 1718 | bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1719 | else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1720 | /* Oh, no!!! */ |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1721 | printk_ratelimited( |
| 1722 | KERN_WARNING |
| 1723 | "md/raid:%s: read error NOT corrected!! " |
| 1724 | "(sector %llu on %s).\n", |
| 1725 | mdname(conf->mddev), |
| 1726 | (unsigned long long)(sh->sector |
| 1727 | + rdev->data_offset), |
| 1728 | bdn); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1729 | else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1730 | > conf->max_nr_stripes) |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1731 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1732 | "md/raid:%s: Too many read errors, failing device %s.\n", |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1733 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1734 | else |
| 1735 | retry = 1; |
| 1736 | if (retry) |
| 1737 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 1738 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1739 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1740 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1741 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1744 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1746 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1747 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1750 | static void raid5_end_write_request(struct bio *bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1752 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1753 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1754 | int disks = sh->disks, i; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1755 | struct md_rdev *uninitialized_var(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1757 | sector_t first_bad; |
| 1758 | int bad_sectors; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1759 | int replacement = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1761 | for (i = 0 ; i < disks; i++) { |
| 1762 | if (bi == &sh->dev[i].req) { |
| 1763 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | break; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1765 | } |
| 1766 | if (bi == &sh->dev[i].rreq) { |
| 1767 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1768 | if (rdev) |
| 1769 | replacement = 1; |
| 1770 | else |
| 1771 | /* rdev was removed and 'replacement' |
| 1772 | * replaced it. rdev is not removed |
| 1773 | * until all requests are finished. |
| 1774 | */ |
| 1775 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1776 | break; |
| 1777 | } |
| 1778 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1779 | pr_debug("end_write_request %llu/%d, count %d, uptodate: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
| 1781 | uptodate); |
| 1782 | if (i == disks) { |
| 1783 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1784 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1787 | if (replacement) { |
| 1788 | if (!uptodate) |
| 1789 | md_error(conf->mddev, rdev); |
| 1790 | else if (is_badblock(rdev, sh->sector, |
| 1791 | STRIPE_SECTORS, |
| 1792 | &first_bad, &bad_sectors)) |
| 1793 | set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); |
| 1794 | } else { |
| 1795 | if (!uptodate) { |
| 1796 | set_bit(WriteErrorSeen, &rdev->flags); |
| 1797 | set_bit(R5_WriteError, &sh->dev[i].flags); |
NeilBrown | 3a6de29 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 1798 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) |
| 1799 | set_bit(MD_RECOVERY_NEEDED, |
| 1800 | &rdev->mddev->recovery); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1801 | } else if (is_badblock(rdev, sh->sector, |
| 1802 | STRIPE_SECTORS, |
| 1803 | &first_bad, &bad_sectors)) |
| 1804 | set_bit(R5_MadeGood, &sh->dev[i].flags); |
| 1805 | } |
| 1806 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1808 | if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) |
| 1809 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1811 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1814 | 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] | 1815 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1816 | 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] | 1817 | { |
| 1818 | struct r5dev *dev = &sh->dev[i]; |
| 1819 | |
| 1820 | bio_init(&dev->req); |
| 1821 | dev->req.bi_io_vec = &dev->vec; |
| 1822 | dev->req.bi_vcnt++; |
| 1823 | dev->req.bi_max_vecs++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | dev->req.bi_private = sh; |
NeilBrown | 995c427 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 1825 | dev->vec.bv_page = dev->page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1827 | bio_init(&dev->rreq); |
| 1828 | dev->rreq.bi_io_vec = &dev->rvec; |
| 1829 | dev->rreq.bi_vcnt++; |
| 1830 | dev->rreq.bi_max_vecs++; |
| 1831 | dev->rreq.bi_private = sh; |
| 1832 | dev->rvec.bv_page = dev->page; |
| 1833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1835 | dev->sector = compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1838 | static void error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | { |
| 1840 | char b[BDEVNAME_SIZE]; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1841 | struct r5conf *conf = mddev->private; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 1842 | unsigned long flags; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1843 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 1845 | spin_lock_irqsave(&conf->device_lock, flags); |
| 1846 | clear_bit(In_sync, &rdev->flags); |
| 1847 | mddev->degraded = calc_degraded(conf); |
| 1848 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 1849 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 1850 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 1851 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 1852 | set_bit(Faulty, &rdev->flags); |
| 1853 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 1854 | printk(KERN_ALERT |
| 1855 | "md/raid:%s: Disk failure on %s, disabling device.\n" |
| 1856 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 1857 | mdname(mddev), |
| 1858 | bdevname(rdev->bdev, b), |
| 1859 | mdname(mddev), |
| 1860 | conf->raid_disks - mddev->degraded); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
| 1863 | /* |
| 1864 | * Input: a 'big' sector number, |
| 1865 | * Output: index of the data and parity disk, and the sector # in them. |
| 1866 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1867 | static sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1868 | int previous, int *dd_idx, |
| 1869 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | { |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1871 | sector_t stripe, stripe2; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1872 | sector_t chunk_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1874 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1875 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1877 | int algorithm = previous ? conf->prev_algo |
| 1878 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1879 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1880 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1881 | int raid_disks = previous ? conf->previous_raid_disks |
| 1882 | : conf->raid_disks; |
| 1883 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
| 1885 | /* First compute the information on this sector */ |
| 1886 | |
| 1887 | /* |
| 1888 | * Compute the chunk number and the sector offset inside the chunk |
| 1889 | */ |
| 1890 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 1891 | chunk_number = r_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
| 1893 | /* |
| 1894 | * Compute the stripe number |
| 1895 | */ |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1896 | stripe = chunk_number; |
| 1897 | *dd_idx = sector_div(stripe, data_disks); |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1898 | stripe2 = stripe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | /* |
| 1900 | * Select the parity disk based on the user selected algorithm. |
| 1901 | */ |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1902 | pd_idx = qd_idx = -1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1903 | switch(conf->level) { |
| 1904 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1905 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1906 | break; |
| 1907 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1908 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1910 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1911 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | (*dd_idx)++; |
| 1913 | break; |
| 1914 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1915 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1916 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | (*dd_idx)++; |
| 1918 | break; |
| 1919 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1920 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1921 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | break; |
| 1923 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1924 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1925 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1927 | case ALGORITHM_PARITY_0: |
| 1928 | pd_idx = 0; |
| 1929 | (*dd_idx)++; |
| 1930 | break; |
| 1931 | case ALGORITHM_PARITY_N: |
| 1932 | pd_idx = data_disks; |
| 1933 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1935 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1936 | } |
| 1937 | break; |
| 1938 | case 6: |
| 1939 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1940 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1941 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1942 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1943 | qd_idx = pd_idx + 1; |
| 1944 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1945 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1946 | qd_idx = 0; |
| 1947 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1948 | (*dd_idx) += 2; /* D D P Q D */ |
| 1949 | break; |
| 1950 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1951 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1952 | qd_idx = pd_idx + 1; |
| 1953 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1954 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1955 | qd_idx = 0; |
| 1956 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1957 | (*dd_idx) += 2; /* D D P Q D */ |
| 1958 | break; |
| 1959 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1960 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1961 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1962 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1963 | break; |
| 1964 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1965 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1966 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1967 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1968 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1969 | |
| 1970 | case ALGORITHM_PARITY_0: |
| 1971 | pd_idx = 0; |
| 1972 | qd_idx = 1; |
| 1973 | (*dd_idx) += 2; |
| 1974 | break; |
| 1975 | case ALGORITHM_PARITY_N: |
| 1976 | pd_idx = data_disks; |
| 1977 | qd_idx = data_disks + 1; |
| 1978 | break; |
| 1979 | |
| 1980 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 1981 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 1982 | * of blocks for computing Q is different. |
| 1983 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1984 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1985 | qd_idx = pd_idx + 1; |
| 1986 | if (pd_idx == raid_disks-1) { |
| 1987 | (*dd_idx)++; /* Q D D D P */ |
| 1988 | qd_idx = 0; |
| 1989 | } else if (*dd_idx >= pd_idx) |
| 1990 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1991 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1992 | break; |
| 1993 | |
| 1994 | case ALGORITHM_ROTATING_N_RESTART: |
| 1995 | /* Same a left_asymmetric, by first stripe is |
| 1996 | * D D D P Q rather than |
| 1997 | * Q D D D P |
| 1998 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1999 | stripe2 += 1; |
| 2000 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2001 | qd_idx = pd_idx + 1; |
| 2002 | if (pd_idx == raid_disks-1) { |
| 2003 | (*dd_idx)++; /* Q D D D P */ |
| 2004 | qd_idx = 0; |
| 2005 | } else if (*dd_idx >= pd_idx) |
| 2006 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2007 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2008 | break; |
| 2009 | |
| 2010 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 2011 | /* Same as left_symmetric but Q is before P */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2012 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2013 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 2014 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2015 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2016 | break; |
| 2017 | |
| 2018 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2019 | /* RAID5 left_asymmetric, with Q on last device */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2020 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2021 | if (*dd_idx >= pd_idx) |
| 2022 | (*dd_idx)++; |
| 2023 | qd_idx = raid_disks - 1; |
| 2024 | break; |
| 2025 | |
| 2026 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2027 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2028 | if (*dd_idx >= pd_idx) |
| 2029 | (*dd_idx)++; |
| 2030 | qd_idx = raid_disks - 1; |
| 2031 | break; |
| 2032 | |
| 2033 | case ALGORITHM_LEFT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2034 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2035 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2036 | qd_idx = raid_disks - 1; |
| 2037 | break; |
| 2038 | |
| 2039 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2040 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2041 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2042 | qd_idx = raid_disks - 1; |
| 2043 | break; |
| 2044 | |
| 2045 | case ALGORITHM_PARITY_0_6: |
| 2046 | pd_idx = 0; |
| 2047 | (*dd_idx)++; |
| 2048 | qd_idx = raid_disks - 1; |
| 2049 | break; |
| 2050 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2051 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2052 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2053 | } |
| 2054 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2057 | if (sh) { |
| 2058 | sh->pd_idx = pd_idx; |
| 2059 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2060 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | /* |
| 2063 | * Finally, compute the new sector number |
| 2064 | */ |
| 2065 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 2066 | return new_sector; |
| 2067 | } |
| 2068 | |
| 2069 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2070 | 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] | 2071 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2072 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2073 | int raid_disks = sh->disks; |
| 2074 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2076 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2077 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2078 | int algorithm = previous ? conf->prev_algo |
| 2079 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | sector_t stripe; |
| 2081 | int chunk_offset; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2082 | sector_t chunk_number; |
| 2083 | int dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2085 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 2089 | stripe = new_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2091 | if (i == sh->pd_idx) |
| 2092 | return 0; |
| 2093 | switch(conf->level) { |
| 2094 | case 4: break; |
| 2095 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2096 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2098 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 2099 | if (i > sh->pd_idx) |
| 2100 | i--; |
| 2101 | break; |
| 2102 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2103 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2104 | if (i < sh->pd_idx) |
| 2105 | i += raid_disks; |
| 2106 | i -= (sh->pd_idx + 1); |
| 2107 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2108 | case ALGORITHM_PARITY_0: |
| 2109 | i -= 1; |
| 2110 | break; |
| 2111 | case ALGORITHM_PARITY_N: |
| 2112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2114 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2115 | } |
| 2116 | break; |
| 2117 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2118 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2119 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2120 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2121 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2122 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2123 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2124 | case ALGORITHM_ROTATING_N_RESTART: |
| 2125 | if (sh->pd_idx == raid_disks-1) |
| 2126 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2127 | else if (i > sh->pd_idx) |
| 2128 | i -= 2; /* D D P Q D */ |
| 2129 | break; |
| 2130 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2131 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2132 | if (sh->pd_idx == raid_disks-1) |
| 2133 | i--; /* Q D D D P */ |
| 2134 | else { |
| 2135 | /* D D P Q D */ |
| 2136 | if (i < sh->pd_idx) |
| 2137 | i += raid_disks; |
| 2138 | i -= (sh->pd_idx + 2); |
| 2139 | } |
| 2140 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2141 | case ALGORITHM_PARITY_0: |
| 2142 | i -= 2; |
| 2143 | break; |
| 2144 | case ALGORITHM_PARITY_N: |
| 2145 | break; |
| 2146 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2147 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2148 | if (sh->pd_idx == 0) |
| 2149 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2150 | else { |
| 2151 | /* D D Q P D */ |
| 2152 | if (i < sh->pd_idx) |
| 2153 | i += raid_disks; |
| 2154 | i -= (sh->pd_idx + 1); |
| 2155 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2156 | break; |
| 2157 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2158 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 2159 | if (i > sh->pd_idx) |
| 2160 | i--; |
| 2161 | break; |
| 2162 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 2163 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 2164 | if (i < sh->pd_idx) |
| 2165 | i += data_disks + 1; |
| 2166 | i -= (sh->pd_idx + 1); |
| 2167 | break; |
| 2168 | case ALGORITHM_PARITY_0_6: |
| 2169 | i -= 1; |
| 2170 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2171 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2172 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2173 | } |
| 2174 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | chunk_number = stripe * data_disks + i; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2178 | r_sector = chunk_number * sectors_per_chunk + chunk_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2180 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2181 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2182 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 2183 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2184 | printk(KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n", |
| 2185 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return 0; |
| 2187 | } |
| 2188 | return r_sector; |
| 2189 | } |
| 2190 | |
| 2191 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2192 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2193 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2194 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2195 | { |
| 2196 | int i, pd_idx = sh->pd_idx, disks = sh->disks; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2197 | struct r5conf *conf = sh->raid_conf; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2198 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2199 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2200 | if (rcw) { |
| 2201 | /* if we are not expanding this is a proper write request, and |
| 2202 | * there will be bios with new data to be drained into the |
| 2203 | * stripe cache |
| 2204 | */ |
| 2205 | if (!expand) { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2206 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 2207 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2208 | } else |
| 2209 | sh->reconstruct_state = reconstruct_state_run; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2210 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2211 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2212 | |
| 2213 | for (i = disks; i--; ) { |
| 2214 | struct r5dev *dev = &sh->dev[i]; |
| 2215 | |
| 2216 | if (dev->towrite) { |
| 2217 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2218 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2219 | if (!expand) |
| 2220 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2221 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2224 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2225 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2226 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2227 | } else { |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2228 | BUG_ON(level == 6); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2229 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 2230 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
| 2231 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2232 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2233 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 2234 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2235 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2236 | |
| 2237 | for (i = disks; i--; ) { |
| 2238 | struct r5dev *dev = &sh->dev[i]; |
| 2239 | if (i == pd_idx) |
| 2240 | continue; |
| 2241 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2242 | if (dev->towrite && |
| 2243 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2244 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2245 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2246 | set_bit(R5_LOCKED, &dev->flags); |
| 2247 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2248 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | } |
| 2252 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2253 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2254 | * are in flight |
| 2255 | */ |
| 2256 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 2257 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2258 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2259 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2260 | if (level == 6) { |
| 2261 | int qd_idx = sh->qd_idx; |
| 2262 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 2263 | |
| 2264 | set_bit(R5_LOCKED, &dev->flags); |
| 2265 | clear_bit(R5_UPTODATE, &dev->flags); |
| 2266 | s->locked++; |
| 2267 | } |
| 2268 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2269 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2270 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2271 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2272 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | /* |
| 2275 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2276 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | * The bi_next chain must be in order. |
| 2278 | */ |
| 2279 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) |
| 2280 | { |
| 2281 | struct bio **bip; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2282 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2283 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2285 | pr_debug("adding bi b#%llu to stripe s#%llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | (unsigned long long)bi->bi_sector, |
| 2287 | (unsigned long long)sh->sector); |
| 2288 | |
| 2289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2291 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | bip = &sh->dev[dd_idx].towrite; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2293 | if (*bip == NULL && sh->dev[dd_idx].written == NULL) |
| 2294 | firstwrite = 1; |
| 2295 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | bip = &sh->dev[dd_idx].toread; |
| 2297 | while (*bip && (*bip)->bi_sector < bi->bi_sector) { |
| 2298 | if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) |
| 2299 | goto overlap; |
| 2300 | bip = & (*bip)->bi_next; |
| 2301 | } |
| 2302 | if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) |
| 2303 | goto overlap; |
| 2304 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2305 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | if (*bip) |
| 2307 | bi->bi_next = *bip; |
| 2308 | *bip = bi; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2309 | bi->bi_phys_segments++; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | if (forwrite) { |
| 2312 | /* check if page is covered */ |
| 2313 | sector_t sector = sh->dev[dd_idx].sector; |
| 2314 | for (bi=sh->dev[dd_idx].towrite; |
| 2315 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
| 2316 | bi && bi->bi_sector <= sector; |
| 2317 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
| 2318 | if (bi->bi_sector + (bi->bi_size>>9) >= sector) |
| 2319 | sector = bi->bi_sector + (bi->bi_size>>9); |
| 2320 | } |
| 2321 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
| 2322 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
| 2323 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2324 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2325 | |
| 2326 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
| 2327 | (unsigned long long)(*bip)->bi_sector, |
| 2328 | (unsigned long long)sh->sector, dd_idx); |
| 2329 | |
| 2330 | if (conf->mddev->bitmap && firstwrite) { |
| 2331 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 2332 | STRIPE_SECTORS, 0); |
| 2333 | sh->bm_seq = conf->seq_flush+1; |
| 2334 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 2335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | return 1; |
| 2337 | |
| 2338 | overlap: |
| 2339 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
| 2340 | spin_unlock_irq(&conf->device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | return 0; |
| 2342 | } |
| 2343 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2344 | static void end_reshape(struct r5conf *conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2345 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2346 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2347 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2348 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2349 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2350 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2351 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2352 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2353 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2354 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2355 | raid5_compute_sector(conf, |
| 2356 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2357 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2358 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2359 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2360 | } |
| 2361 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2362 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2363 | handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2364 | struct stripe_head_state *s, int disks, |
| 2365 | struct bio **return_bi) |
| 2366 | { |
| 2367 | int i; |
| 2368 | for (i = disks; i--; ) { |
| 2369 | struct bio *bi; |
| 2370 | int bitmap_end = 0; |
| 2371 | |
| 2372 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2373 | struct md_rdev *rdev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2374 | rcu_read_lock(); |
| 2375 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 2376 | if (rdev && test_bit(In_sync, &rdev->flags)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2377 | atomic_inc(&rdev->nr_pending); |
| 2378 | else |
| 2379 | rdev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2380 | rcu_read_unlock(); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2381 | if (rdev) { |
| 2382 | if (!rdev_set_badblocks( |
| 2383 | rdev, |
| 2384 | sh->sector, |
| 2385 | STRIPE_SECTORS, 0)) |
| 2386 | md_error(conf->mddev, rdev); |
| 2387 | rdev_dec_pending(rdev, conf->mddev); |
| 2388 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2389 | } |
| 2390 | spin_lock_irq(&conf->device_lock); |
| 2391 | /* fail all writes first */ |
| 2392 | bi = sh->dev[i].towrite; |
| 2393 | sh->dev[i].towrite = NULL; |
| 2394 | if (bi) { |
| 2395 | s->to_write--; |
| 2396 | bitmap_end = 1; |
| 2397 | } |
| 2398 | |
| 2399 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2400 | wake_up(&conf->wait_for_overlap); |
| 2401 | |
| 2402 | while (bi && bi->bi_sector < |
| 2403 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2404 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
| 2405 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2406 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2407 | md_write_end(conf->mddev); |
| 2408 | bi->bi_next = *return_bi; |
| 2409 | *return_bi = bi; |
| 2410 | } |
| 2411 | bi = nextbi; |
| 2412 | } |
| 2413 | /* and fail all 'written' */ |
| 2414 | bi = sh->dev[i].written; |
| 2415 | sh->dev[i].written = NULL; |
| 2416 | if (bi) bitmap_end = 1; |
| 2417 | while (bi && bi->bi_sector < |
| 2418 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2419 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
| 2420 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2421 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2422 | md_write_end(conf->mddev); |
| 2423 | bi->bi_next = *return_bi; |
| 2424 | *return_bi = bi; |
| 2425 | } |
| 2426 | bi = bi2; |
| 2427 | } |
| 2428 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2429 | /* fail any reads if this device is non-operational and |
| 2430 | * the data has not reached the cache yet. |
| 2431 | */ |
| 2432 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
| 2433 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 2434 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2435 | bi = sh->dev[i].toread; |
| 2436 | sh->dev[i].toread = NULL; |
| 2437 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2438 | wake_up(&conf->wait_for_overlap); |
| 2439 | if (bi) s->to_read--; |
| 2440 | while (bi && bi->bi_sector < |
| 2441 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2442 | struct bio *nextbi = |
| 2443 | r5_next_bio(bi, sh->dev[i].sector); |
| 2444 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2445 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2446 | bi->bi_next = *return_bi; |
| 2447 | *return_bi = bi; |
| 2448 | } |
| 2449 | bi = nextbi; |
| 2450 | } |
| 2451 | } |
| 2452 | spin_unlock_irq(&conf->device_lock); |
| 2453 | if (bitmap_end) |
| 2454 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2455 | STRIPE_SECTORS, 0, 0); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2456 | /* If we were in the middle of a write the parity block might |
| 2457 | * still be locked - so just clear all R5_LOCKED flags |
| 2458 | */ |
| 2459 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2462 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2463 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2464 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2467 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2468 | handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2469 | struct stripe_head_state *s) |
| 2470 | { |
| 2471 | int abort = 0; |
| 2472 | int i; |
| 2473 | |
| 2474 | md_done_sync(conf->mddev, STRIPE_SECTORS, 0); |
| 2475 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 2476 | s->syncing = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2477 | s->replacing = 0; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2478 | /* There is nothing more to do for sync/check/repair. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2479 | * For recover/replace we need to record a bad block on all |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2480 | * non-sync devices, or abort the recovery |
| 2481 | */ |
| 2482 | if (!test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) |
| 2483 | return; |
| 2484 | /* During recovery devices cannot be removed, so locking and |
| 2485 | * refcounting of rdevs is not needed |
| 2486 | */ |
| 2487 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2488 | struct md_rdev *rdev = conf->disks[i].rdev; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2489 | if (rdev |
| 2490 | && !test_bit(Faulty, &rdev->flags) |
| 2491 | && !test_bit(In_sync, &rdev->flags) |
| 2492 | && !rdev_set_badblocks(rdev, sh->sector, |
| 2493 | STRIPE_SECTORS, 0)) |
| 2494 | abort = 1; |
| 2495 | rdev = conf->disks[i].replacement; |
| 2496 | if (rdev |
| 2497 | && !test_bit(Faulty, &rdev->flags) |
| 2498 | && !test_bit(In_sync, &rdev->flags) |
| 2499 | && !rdev_set_badblocks(rdev, sh->sector, |
| 2500 | STRIPE_SECTORS, 0)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2501 | abort = 1; |
| 2502 | } |
| 2503 | if (abort) { |
| 2504 | conf->recovery_disabled = conf->mddev->recovery_disabled; |
| 2505 | set_bit(MD_RECOVERY_INTR, &conf->mddev->recovery); |
| 2506 | } |
| 2507 | } |
| 2508 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2509 | static int want_replace(struct stripe_head *sh, int disk_idx) |
| 2510 | { |
| 2511 | struct md_rdev *rdev; |
| 2512 | int rv = 0; |
| 2513 | /* Doing recovery so rcu locking not required */ |
| 2514 | rdev = sh->raid_conf->disks[disk_idx].replacement; |
| 2515 | if (rdev |
| 2516 | && !test_bit(Faulty, &rdev->flags) |
| 2517 | && !test_bit(In_sync, &rdev->flags) |
| 2518 | && (rdev->recovery_offset <= sh->sector |
| 2519 | || rdev->mddev->recovery_cp <= sh->sector)) |
| 2520 | rv = 1; |
| 2521 | |
| 2522 | return rv; |
| 2523 | } |
| 2524 | |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2525 | /* 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] | 2526 | * to be read or computed to satisfy a request. |
| 2527 | * |
| 2528 | * Returns 1 when no more member devices need to be checked, otherwise returns |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2529 | * 0 to tell the loop in handle_stripe_fill to continue |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2530 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2531 | static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 2532 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2533 | { |
| 2534 | struct r5dev *dev = &sh->dev[disk_idx]; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2535 | struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], |
| 2536 | &sh->dev[s->failed_num[1]] }; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2537 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2538 | /* is the data in this block needed, and can we get it? */ |
| 2539 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2540 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2541 | (dev->toread || |
| 2542 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2543 | s->syncing || s->expanding || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2544 | (s->replacing && want_replace(sh, disk_idx)) || |
NeilBrown | 5d35e09 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2545 | (s->failed >= 1 && fdev[0]->toread) || |
| 2546 | (s->failed >= 2 && fdev[1]->toread) || |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2547 | (sh->raid_conf->level <= 5 && s->failed && fdev[0]->towrite && |
| 2548 | !test_bit(R5_OVERWRITE, &fdev[0]->flags)) || |
| 2549 | (sh->raid_conf->level == 6 && s->failed && s->to_write))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2550 | /* we would like to get this block, possibly by computing it, |
| 2551 | * otherwise read it if the backing disk is insync |
| 2552 | */ |
| 2553 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 2554 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
| 2555 | if ((s->uptodate == disks - 1) && |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2556 | (s->failed && (disk_idx == s->failed_num[0] || |
| 2557 | disk_idx == s->failed_num[1]))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2558 | /* have disk failed, and we're requested to fetch it; |
| 2559 | * do compute it |
| 2560 | */ |
| 2561 | pr_debug("Computing stripe %llu block %d\n", |
| 2562 | (unsigned long long)sh->sector, disk_idx); |
| 2563 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2564 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2565 | set_bit(R5_Wantcompute, &dev->flags); |
| 2566 | sh->ops.target = disk_idx; |
| 2567 | sh->ops.target2 = -1; /* no 2nd target */ |
| 2568 | s->req_compute = 1; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2569 | /* Careful: from this point on 'uptodate' is in the eye |
| 2570 | * of raid_run_ops which services 'compute' operations |
| 2571 | * before writes. R5_Wantcompute flags a block that will |
| 2572 | * be R5_UPTODATE by the time it is needed for a |
| 2573 | * subsequent operation. |
| 2574 | */ |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2575 | s->uptodate++; |
| 2576 | return 1; |
| 2577 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 2578 | /* Computing 2-failure is *very* expensive; only |
| 2579 | * do it if failed >= 2 |
| 2580 | */ |
| 2581 | int other; |
| 2582 | for (other = disks; other--; ) { |
| 2583 | if (other == disk_idx) |
| 2584 | continue; |
| 2585 | if (!test_bit(R5_UPTODATE, |
| 2586 | &sh->dev[other].flags)) |
| 2587 | break; |
| 2588 | } |
| 2589 | BUG_ON(other < 0); |
| 2590 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 2591 | (unsigned long long)sh->sector, |
| 2592 | disk_idx, other); |
| 2593 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2594 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2595 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 2596 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 2597 | sh->ops.target = disk_idx; |
| 2598 | sh->ops.target2 = other; |
| 2599 | s->uptodate += 2; |
| 2600 | s->req_compute = 1; |
| 2601 | return 1; |
| 2602 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 2603 | set_bit(R5_LOCKED, &dev->flags); |
| 2604 | set_bit(R5_Wantread, &dev->flags); |
| 2605 | s->locked++; |
| 2606 | pr_debug("Reading block %d (sync=%d)\n", |
| 2607 | disk_idx, s->syncing); |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
| 2614 | /** |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2615 | * handle_stripe_fill - read or compute data to satisfy pending requests. |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2616 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2617 | static void handle_stripe_fill(struct stripe_head *sh, |
| 2618 | struct stripe_head_state *s, |
| 2619 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2620 | { |
| 2621 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2622 | |
| 2623 | /* look for blocks to read/compute, skip this if a compute |
| 2624 | * is already in flight, or if the stripe contents are in the |
| 2625 | * midst of changing due to a write |
| 2626 | */ |
| 2627 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
| 2628 | !sh->reconstruct_state) |
| 2629 | for (i = disks; i--; ) |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2630 | if (fetch_block(sh, s, i, disks)) |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2631 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2632 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2633 | } |
| 2634 | |
| 2635 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2636 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2637 | * any written block on an uptodate or failed drive can be returned. |
| 2638 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 2639 | * never LOCKED, so we don't need to test 'failed' directly. |
| 2640 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2641 | static void handle_stripe_clean_event(struct r5conf *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2642 | struct stripe_head *sh, int disks, struct bio **return_bi) |
| 2643 | { |
| 2644 | int i; |
| 2645 | struct r5dev *dev; |
| 2646 | |
| 2647 | for (i = disks; i--; ) |
| 2648 | if (sh->dev[i].written) { |
| 2649 | dev = &sh->dev[i]; |
| 2650 | if (!test_bit(R5_LOCKED, &dev->flags) && |
| 2651 | test_bit(R5_UPTODATE, &dev->flags)) { |
| 2652 | /* We can return any write requests */ |
| 2653 | struct bio *wbi, *wbi2; |
| 2654 | int bitmap_end = 0; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2655 | pr_debug("Return write for disc %d\n", i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2656 | spin_lock_irq(&conf->device_lock); |
| 2657 | wbi = dev->written; |
| 2658 | dev->written = NULL; |
| 2659 | while (wbi && wbi->bi_sector < |
| 2660 | dev->sector + STRIPE_SECTORS) { |
| 2661 | wbi2 = r5_next_bio(wbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2662 | if (!raid5_dec_bi_phys_segments(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2663 | md_write_end(conf->mddev); |
| 2664 | wbi->bi_next = *return_bi; |
| 2665 | *return_bi = wbi; |
| 2666 | } |
| 2667 | wbi = wbi2; |
| 2668 | } |
| 2669 | if (dev->towrite == NULL) |
| 2670 | bitmap_end = 1; |
| 2671 | spin_unlock_irq(&conf->device_lock); |
| 2672 | if (bitmap_end) |
| 2673 | bitmap_endwrite(conf->mddev->bitmap, |
| 2674 | sh->sector, |
| 2675 | STRIPE_SECTORS, |
| 2676 | !test_bit(STRIPE_DEGRADED, &sh->state), |
| 2677 | 0); |
| 2678 | } |
| 2679 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2680 | |
| 2681 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2682 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2683 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2686 | static void handle_stripe_dirtying(struct r5conf *conf, |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2687 | struct stripe_head *sh, |
| 2688 | struct stripe_head_state *s, |
| 2689 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2690 | { |
| 2691 | int rmw = 0, rcw = 0, i; |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2692 | if (conf->max_degraded == 2) { |
| 2693 | /* RAID6 requires 'rcw' in current implementation |
| 2694 | * Calculate the real rcw later - for now fake it |
| 2695 | * look like rcw is cheaper |
| 2696 | */ |
| 2697 | rcw = 1; rmw = 2; |
| 2698 | } else for (i = disks; i--; ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2699 | /* would I have to read this buffer for read_modify_write */ |
| 2700 | struct r5dev *dev = &sh->dev[i]; |
| 2701 | if ((dev->towrite || i == sh->pd_idx) && |
| 2702 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2703 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2704 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2705 | if (test_bit(R5_Insync, &dev->flags)) |
| 2706 | rmw++; |
| 2707 | else |
| 2708 | rmw += 2*disks; /* cannot read it */ |
| 2709 | } |
| 2710 | /* Would I have to read this buffer for reconstruct_write */ |
| 2711 | if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && |
| 2712 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2713 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2714 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2715 | if (test_bit(R5_Insync, &dev->flags)) rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2716 | else |
| 2717 | rcw += 2*disks; |
| 2718 | } |
| 2719 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2720 | pr_debug("for sector %llu, rmw=%d rcw=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2721 | (unsigned long long)sh->sector, rmw, rcw); |
| 2722 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2723 | if (rmw < rcw && rmw > 0) |
| 2724 | /* prefer read-modify-write, but need to get some data */ |
| 2725 | for (i = disks; i--; ) { |
| 2726 | struct r5dev *dev = &sh->dev[i]; |
| 2727 | if ((dev->towrite || i == sh->pd_idx) && |
| 2728 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2729 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2730 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2731 | test_bit(R5_Insync, &dev->flags)) { |
| 2732 | if ( |
| 2733 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2734 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2735 | "%d for r-m-w\n", i); |
| 2736 | set_bit(R5_LOCKED, &dev->flags); |
| 2737 | set_bit(R5_Wantread, &dev->flags); |
| 2738 | s->locked++; |
| 2739 | } else { |
| 2740 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2741 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2742 | } |
| 2743 | } |
| 2744 | } |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2745 | if (rcw <= rmw && rcw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2746 | /* want reconstruct write, but need to get some data */ |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2747 | rcw = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2748 | for (i = disks; i--; ) { |
| 2749 | struct r5dev *dev = &sh->dev[i]; |
| 2750 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2751 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2752 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2753 | !(test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2754 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2755 | rcw++; |
| 2756 | if (!test_bit(R5_Insync, &dev->flags)) |
| 2757 | continue; /* it's a failed drive */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2758 | if ( |
| 2759 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2760 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2761 | "%d for Reconstruct\n", i); |
| 2762 | set_bit(R5_LOCKED, &dev->flags); |
| 2763 | set_bit(R5_Wantread, &dev->flags); |
| 2764 | s->locked++; |
| 2765 | } else { |
| 2766 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2767 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2768 | } |
| 2769 | } |
| 2770 | } |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2771 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2772 | /* now if nothing is locked, and if we have enough data, |
| 2773 | * we can start a write request |
| 2774 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2775 | /* since handle_stripe can be called at any time we need to handle the |
| 2776 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2777 | * subsequent call wants to start a write request. raid_run_ops only |
| 2778 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2779 | * simultaneously. If this is not the case then new writes need to be |
| 2780 | * held off until the compute completes. |
| 2781 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2782 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2783 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
| 2784 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2785 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2788 | static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2789 | struct stripe_head_state *s, int disks) |
| 2790 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2791 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2792 | |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2793 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2794 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2795 | switch (sh->check_state) { |
| 2796 | case check_state_idle: |
| 2797 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2798 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2799 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2800 | sh->check_state = check_state_run; |
| 2801 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2802 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2803 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2804 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2805 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2806 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2807 | /* fall through */ |
| 2808 | case check_state_compute_result: |
| 2809 | sh->check_state = check_state_idle; |
| 2810 | if (!dev) |
| 2811 | dev = &sh->dev[sh->pd_idx]; |
| 2812 | |
| 2813 | /* check that a write has not made the stripe insync */ |
| 2814 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2815 | break; |
| 2816 | |
| 2817 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2818 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 2819 | BUG_ON(s->uptodate != disks); |
| 2820 | |
| 2821 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2822 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2823 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2824 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2825 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2826 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2827 | break; |
| 2828 | case check_state_run: |
| 2829 | break; /* we will be called again upon completion */ |
| 2830 | case check_state_check_result: |
| 2831 | sh->check_state = check_state_idle; |
| 2832 | |
| 2833 | /* if a failure occurred during the check operation, leave |
| 2834 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 2835 | */ |
| 2836 | if (s->failed) |
| 2837 | break; |
| 2838 | |
| 2839 | /* handle a successful check operation, if parity is correct |
| 2840 | * we are done. Otherwise update the mismatch count and repair |
| 2841 | * parity if !MD_RECOVERY_CHECK |
| 2842 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 2843 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2844 | /* parity is correct (on disc, |
| 2845 | * not in buffer any more) |
| 2846 | */ |
| 2847 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2848 | else { |
| 2849 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2850 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2851 | /* don't try to repair!! */ |
| 2852 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2853 | else { |
| 2854 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2855 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2856 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2857 | set_bit(R5_Wantcompute, |
| 2858 | &sh->dev[sh->pd_idx].flags); |
| 2859 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2860 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2861 | s->uptodate++; |
| 2862 | } |
| 2863 | } |
| 2864 | break; |
| 2865 | case check_state_compute_run: |
| 2866 | break; |
| 2867 | default: |
| 2868 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2869 | __func__, sh->check_state, |
| 2870 | (unsigned long long) sh->sector); |
| 2871 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2872 | } |
| 2873 | } |
| 2874 | |
| 2875 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2876 | static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2877 | struct stripe_head_state *s, |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2878 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2879 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2880 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2881 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2882 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2883 | |
| 2884 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2885 | |
| 2886 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2887 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2888 | /* Want to check and possibly repair P and Q. |
| 2889 | * However there could be one 'failed' device, in which |
| 2890 | * case we can only check one of them, possibly using the |
| 2891 | * other to generate missing data |
| 2892 | */ |
| 2893 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2894 | switch (sh->check_state) { |
| 2895 | case check_state_idle: |
| 2896 | /* start a new check operation if there are < 2 failures */ |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2897 | if (s->failed == s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2898 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2899 | * makes sense to check P (If anything else were failed, |
| 2900 | * we would have used P to recreate it). |
| 2901 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2902 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2903 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2904 | if (!s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2905 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2906 | * anything, so it makes sense to check it |
| 2907 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2908 | if (sh->check_state == check_state_run) |
| 2909 | sh->check_state = check_state_run_pq; |
| 2910 | else |
| 2911 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2912 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2913 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2914 | /* discard potentially stale zero_sum_result */ |
| 2915 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2916 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2917 | if (sh->check_state == check_state_run) { |
| 2918 | /* async_xor_zero_sum destroys the contents of P */ |
| 2919 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 2920 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2921 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2922 | if (sh->check_state >= check_state_run && |
| 2923 | sh->check_state <= check_state_run_pq) { |
| 2924 | /* async_syndrome_zero_sum preserves P and Q, so |
| 2925 | * no need to mark them !uptodate here |
| 2926 | */ |
| 2927 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 2928 | break; |
| 2929 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2930 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2931 | /* we have 2-disk failure */ |
| 2932 | BUG_ON(s->failed != 2); |
| 2933 | /* fall through */ |
| 2934 | case check_state_compute_result: |
| 2935 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2936 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2937 | /* check that a write has not made the stripe insync */ |
| 2938 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2939 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2940 | |
| 2941 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2942 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2943 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2944 | 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] | 2945 | if (s->failed == 2) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2946 | dev = &sh->dev[s->failed_num[1]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2947 | s->locked++; |
| 2948 | set_bit(R5_LOCKED, &dev->flags); |
| 2949 | set_bit(R5_Wantwrite, &dev->flags); |
| 2950 | } |
| 2951 | if (s->failed >= 1) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2952 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2953 | s->locked++; |
| 2954 | set_bit(R5_LOCKED, &dev->flags); |
| 2955 | set_bit(R5_Wantwrite, &dev->flags); |
| 2956 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2957 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2958 | dev = &sh->dev[pd_idx]; |
| 2959 | s->locked++; |
| 2960 | set_bit(R5_LOCKED, &dev->flags); |
| 2961 | set_bit(R5_Wantwrite, &dev->flags); |
| 2962 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2963 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2964 | dev = &sh->dev[qd_idx]; |
| 2965 | s->locked++; |
| 2966 | set_bit(R5_LOCKED, &dev->flags); |
| 2967 | set_bit(R5_Wantwrite, &dev->flags); |
| 2968 | } |
| 2969 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 2970 | |
| 2971 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2972 | break; |
| 2973 | case check_state_run: |
| 2974 | case check_state_run_q: |
| 2975 | case check_state_run_pq: |
| 2976 | break; /* we will be called again upon completion */ |
| 2977 | case check_state_check_result: |
| 2978 | sh->check_state = check_state_idle; |
| 2979 | |
| 2980 | /* handle a successful check operation, if parity is correct |
| 2981 | * we are done. Otherwise update the mismatch count and repair |
| 2982 | * parity if !MD_RECOVERY_CHECK |
| 2983 | */ |
| 2984 | if (sh->ops.zero_sum_result == 0) { |
| 2985 | /* both parities are correct */ |
| 2986 | if (!s->failed) |
| 2987 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2988 | else { |
| 2989 | /* in contrast to the raid5 case we can validate |
| 2990 | * parity, but still have a failure to write |
| 2991 | * back |
| 2992 | */ |
| 2993 | sh->check_state = check_state_compute_result; |
| 2994 | /* Returning at this point means that we may go |
| 2995 | * off and bring p and/or q uptodate again so |
| 2996 | * we make sure to check zero_sum_result again |
| 2997 | * to verify if p or q need writeback |
| 2998 | */ |
| 2999 | } |
| 3000 | } else { |
| 3001 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 3002 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 3003 | /* don't try to repair!! */ |
| 3004 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3005 | else { |
| 3006 | int *target = &sh->ops.target; |
| 3007 | |
| 3008 | sh->ops.target = -1; |
| 3009 | sh->ops.target2 = -1; |
| 3010 | sh->check_state = check_state_compute_run; |
| 3011 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3012 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3013 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 3014 | set_bit(R5_Wantcompute, |
| 3015 | &sh->dev[pd_idx].flags); |
| 3016 | *target = pd_idx; |
| 3017 | target = &sh->ops.target2; |
| 3018 | s->uptodate++; |
| 3019 | } |
| 3020 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 3021 | set_bit(R5_Wantcompute, |
| 3022 | &sh->dev[qd_idx].flags); |
| 3023 | *target = qd_idx; |
| 3024 | s->uptodate++; |
| 3025 | } |
| 3026 | } |
| 3027 | } |
| 3028 | break; |
| 3029 | case check_state_compute_run: |
| 3030 | break; |
| 3031 | default: |
| 3032 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 3033 | __func__, sh->check_state, |
| 3034 | (unsigned long long) sh->sector); |
| 3035 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3039 | static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3040 | { |
| 3041 | int i; |
| 3042 | |
| 3043 | /* We have read all the blocks in this stripe and now we need to |
| 3044 | * copy some of them into a target stripe for expand. |
| 3045 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3046 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3047 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3048 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3049 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3050 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3051 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3052 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3053 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3054 | sector_t bn = compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3055 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 3056 | &dd_idx, NULL); |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3057 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3058 | if (sh2 == NULL) |
| 3059 | /* so far only the early blocks of this stripe |
| 3060 | * have been requested. When later blocks |
| 3061 | * get requested, we will try again |
| 3062 | */ |
| 3063 | continue; |
| 3064 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 3065 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 3066 | /* must have already done this block */ |
| 3067 | release_stripe(sh2); |
| 3068 | continue; |
| 3069 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3070 | |
| 3071 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3072 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3073 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 3074 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 3075 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3076 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3077 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 3078 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 3079 | for (j = 0; j < conf->raid_disks; j++) |
| 3080 | if (j != sh2->pd_idx && |
NeilBrown | 86c374b | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3081 | j != sh2->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3082 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 3083 | break; |
| 3084 | if (j == conf->raid_disks) { |
| 3085 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 3086 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 3087 | } |
| 3088 | release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3089 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3090 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 3091 | /* done submitting copies, wait for them to complete */ |
| 3092 | if (tx) { |
| 3093 | async_tx_ack(tx); |
| 3094 | dma_wait_for_async_tx(tx); |
| 3095 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | |
| 3098 | /* |
| 3099 | * handle_stripe - do things to a stripe. |
| 3100 | * |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3101 | * We lock the stripe by setting STRIPE_ACTIVE and then examine the |
| 3102 | * state of various bits to see what needs to be done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | * Possible results: |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3104 | * return some read requests which now have data |
| 3105 | * return some write requests which are safely on storage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | * schedule a read on some buffers |
| 3107 | * schedule a write of some buffers |
| 3108 | * return confirmation of parity correctness |
| 3109 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3111 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3112 | static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3113 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3114 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3115 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3116 | struct r5dev *dev; |
| 3117 | int i; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3118 | int do_recovery = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3119 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3120 | memset(s, 0, sizeof(*s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3121 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3122 | s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3123 | s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3124 | s->failed_num[0] = -1; |
| 3125 | s->failed_num[1] = -1; |
| 3126 | |
| 3127 | /* Now to look around and see what can be done */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3128 | rcu_read_lock(); |
NeilBrown | c4c1663 | 2011-07-26 11:34:20 +1000 | [diff] [blame] | 3129 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3130 | for (i=disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3131 | struct md_rdev *rdev; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3132 | sector_t first_bad; |
| 3133 | int bad_sectors; |
| 3134 | int is_bad = 0; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3135 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3136 | dev = &sh->dev[i]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3137 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3138 | 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] | 3139 | i, dev->flags, |
| 3140 | dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3141 | /* maybe we can reply to a read |
| 3142 | * |
| 3143 | * new wantfill requests are only permitted while |
| 3144 | * ops_complete_biofill is guaranteed to be inactive |
| 3145 | */ |
| 3146 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 3147 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 3148 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3149 | |
| 3150 | /* now count some things */ |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3151 | if (test_bit(R5_LOCKED, &dev->flags)) |
| 3152 | s->locked++; |
| 3153 | if (test_bit(R5_UPTODATE, &dev->flags)) |
| 3154 | s->uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3155 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3156 | s->compute++; |
| 3157 | BUG_ON(s->compute > 2); |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3158 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3159 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3160 | if (test_bit(R5_Wantfill, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3161 | s->to_fill++; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3162 | else if (dev->toread) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3163 | s->to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3164 | if (dev->towrite) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3165 | s->to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3166 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3167 | s->non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3168 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3169 | if (dev->written) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3170 | s->written++; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3171 | /* Prefer to use the replacement for reads, but only |
| 3172 | * if it is recovered enough and has no bad blocks. |
| 3173 | */ |
| 3174 | rdev = rcu_dereference(conf->disks[i].replacement); |
| 3175 | if (rdev && !test_bit(Faulty, &rdev->flags) && |
| 3176 | rdev->recovery_offset >= sh->sector + STRIPE_SECTORS && |
| 3177 | !is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3178 | &first_bad, &bad_sectors)) |
| 3179 | set_bit(R5_ReadRepl, &dev->flags); |
| 3180 | else { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3181 | if (rdev) |
| 3182 | set_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3183 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 3184 | clear_bit(R5_ReadRepl, &dev->flags); |
| 3185 | } |
NeilBrown | 9283d8c | 2011-12-08 16:27:57 +1100 | [diff] [blame] | 3186 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 3187 | rdev = NULL; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3188 | if (rdev) { |
| 3189 | is_bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3190 | &first_bad, &bad_sectors); |
| 3191 | if (s->blocked_rdev == NULL |
| 3192 | && (test_bit(Blocked, &rdev->flags) |
| 3193 | || is_bad < 0)) { |
| 3194 | if (is_bad < 0) |
| 3195 | set_bit(BlockedBadBlocks, |
| 3196 | &rdev->flags); |
| 3197 | s->blocked_rdev = rdev; |
| 3198 | atomic_inc(&rdev->nr_pending); |
| 3199 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3200 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3201 | clear_bit(R5_Insync, &dev->flags); |
| 3202 | if (!rdev) |
| 3203 | /* Not in-sync */; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3204 | else if (is_bad) { |
| 3205 | /* also not in-sync */ |
| 3206 | if (!test_bit(WriteErrorSeen, &rdev->flags)) { |
| 3207 | /* treat as in-sync, but with a read error |
| 3208 | * which we can now try to correct |
| 3209 | */ |
| 3210 | set_bit(R5_Insync, &dev->flags); |
| 3211 | set_bit(R5_ReadError, &dev->flags); |
| 3212 | } |
| 3213 | } else if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3214 | set_bit(R5_Insync, &dev->flags); |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 3215 | else if (sh->sector + STRIPE_SECTORS <= rdev->recovery_offset) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3216 | /* in sync if before recovery_offset */ |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 3217 | set_bit(R5_Insync, &dev->flags); |
| 3218 | else if (test_bit(R5_UPTODATE, &dev->flags) && |
| 3219 | test_bit(R5_Expanded, &dev->flags)) |
| 3220 | /* If we've reshaped into here, we assume it is Insync. |
| 3221 | * We will shortly update recovery_offset to make |
| 3222 | * it official. |
| 3223 | */ |
| 3224 | set_bit(R5_Insync, &dev->flags); |
| 3225 | |
Adam Kwolek | 5d8c71f | 2011-12-09 14:26:11 +1100 | [diff] [blame] | 3226 | if (rdev && test_bit(R5_WriteError, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3227 | /* This flag does not apply to '.replacement' |
| 3228 | * only to .rdev, so make sure to check that*/ |
| 3229 | struct md_rdev *rdev2 = rcu_dereference( |
| 3230 | conf->disks[i].rdev); |
| 3231 | if (rdev2 == rdev) |
| 3232 | clear_bit(R5_Insync, &dev->flags); |
| 3233 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3234 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3235 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3236 | } else |
| 3237 | clear_bit(R5_WriteError, &dev->flags); |
| 3238 | } |
Adam Kwolek | 5d8c71f | 2011-12-09 14:26:11 +1100 | [diff] [blame] | 3239 | if (rdev && test_bit(R5_MadeGood, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3240 | /* This flag does not apply to '.replacement' |
| 3241 | * only to .rdev, so make sure to check that*/ |
| 3242 | struct md_rdev *rdev2 = rcu_dereference( |
| 3243 | conf->disks[i].rdev); |
| 3244 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3245 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3246 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3247 | } else |
| 3248 | clear_bit(R5_MadeGood, &dev->flags); |
| 3249 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3250 | if (test_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 3251 | struct md_rdev *rdev2 = rcu_dereference( |
| 3252 | conf->disks[i].replacement); |
| 3253 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
| 3254 | s->handle_bad_blocks = 1; |
| 3255 | atomic_inc(&rdev2->nr_pending); |
| 3256 | } else |
| 3257 | clear_bit(R5_MadeGoodRepl, &dev->flags); |
| 3258 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3259 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3260 | /* The ReadError flag will just be confusing now */ |
| 3261 | clear_bit(R5_ReadError, &dev->flags); |
| 3262 | clear_bit(R5_ReWrite, &dev->flags); |
| 3263 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3264 | if (test_bit(R5_ReadError, &dev->flags)) |
| 3265 | clear_bit(R5_Insync, &dev->flags); |
| 3266 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3267 | if (s->failed < 2) |
| 3268 | s->failed_num[s->failed] = i; |
| 3269 | s->failed++; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3270 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
| 3271 | do_recovery = 1; |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3272 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3273 | } |
NeilBrown | c4c1663 | 2011-07-26 11:34:20 +1000 | [diff] [blame] | 3274 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3275 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 3276 | /* If there is a failed device being replaced, |
| 3277 | * we must be recovering. |
| 3278 | * else if we are after recovery_cp, we must be syncing |
| 3279 | * else we can only be replacing |
| 3280 | * sync and recovery both need to read all devices, and so |
| 3281 | * use the same flag. |
| 3282 | */ |
| 3283 | if (do_recovery || |
| 3284 | sh->sector >= conf->mddev->recovery_cp) |
| 3285 | s->syncing = 1; |
| 3286 | else |
| 3287 | s->replacing = 1; |
| 3288 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3289 | rcu_read_unlock(); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3290 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3291 | |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3292 | static void handle_stripe(struct stripe_head *sh) |
| 3293 | { |
| 3294 | struct stripe_head_state s; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3295 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3296 | int i; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3297 | int prexor; |
| 3298 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3299 | struct r5dev *pdev, *qdev; |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3300 | |
| 3301 | clear_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 3302 | if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3303 | /* already being handled, ensure it gets handled |
| 3304 | * again when current action finishes */ |
| 3305 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3306 | return; |
| 3307 | } |
| 3308 | |
| 3309 | if (test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 3310 | set_bit(STRIPE_SYNCING, &sh->state); |
| 3311 | clear_bit(STRIPE_INSYNC, &sh->state); |
| 3312 | } |
| 3313 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3314 | |
| 3315 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
| 3316 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
| 3317 | (unsigned long long)sh->sector, sh->state, |
| 3318 | atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, |
| 3319 | sh->check_state, sh->reconstruct_state); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3320 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3321 | analyse_stripe(sh, &s); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3322 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3323 | if (s.handle_bad_blocks) { |
| 3324 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3325 | goto finish; |
| 3326 | } |
| 3327 | |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3328 | if (unlikely(s.blocked_rdev)) { |
| 3329 | if (s.syncing || s.expanding || s.expanded || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3330 | s.replacing || s.to_write || s.written) { |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3331 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3332 | goto finish; |
| 3333 | } |
| 3334 | /* There is nothing for the blocked_rdev to block */ |
| 3335 | rdev_dec_pending(s.blocked_rdev, conf->mddev); |
| 3336 | s.blocked_rdev = NULL; |
| 3337 | } |
| 3338 | |
| 3339 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3340 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3341 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3342 | } |
| 3343 | |
| 3344 | pr_debug("locked=%d uptodate=%d to_read=%d" |
| 3345 | " to_write=%d failed=%d failed_num=%d,%d\n", |
| 3346 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 3347 | s.failed_num[0], s.failed_num[1]); |
| 3348 | /* check if the array has lost more than max_degraded devices and, |
| 3349 | * if so, some requests might need to be failed. |
| 3350 | */ |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 3351 | if (s.failed > conf->max_degraded) { |
| 3352 | sh->check_state = 0; |
| 3353 | sh->reconstruct_state = 0; |
| 3354 | if (s.to_read+s.to_write+s.written) |
| 3355 | handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3356 | if (s.syncing + s.replacing) |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 3357 | handle_failed_sync(conf, sh, &s); |
| 3358 | } |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3359 | |
| 3360 | /* |
| 3361 | * might be able to return some write requests if the parity blocks |
| 3362 | * are safe, or on a failed drive |
| 3363 | */ |
| 3364 | pdev = &sh->dev[sh->pd_idx]; |
| 3365 | s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) |
| 3366 | || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); |
| 3367 | qdev = &sh->dev[sh->qd_idx]; |
| 3368 | s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) |
| 3369 | || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) |
| 3370 | || conf->level < 6; |
| 3371 | |
| 3372 | if (s.written && |
| 3373 | (s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
| 3374 | && !test_bit(R5_LOCKED, &pdev->flags) |
| 3375 | && test_bit(R5_UPTODATE, &pdev->flags)))) && |
| 3376 | (s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
| 3377 | && !test_bit(R5_LOCKED, &qdev->flags) |
| 3378 | && test_bit(R5_UPTODATE, &qdev->flags))))) |
| 3379 | handle_stripe_clean_event(conf, sh, disks, &s.return_bi); |
| 3380 | |
| 3381 | /* Now we might consider reading some blocks, either to check/generate |
| 3382 | * parity, or to satisfy requests |
| 3383 | * or to load a block that is being partially written. |
| 3384 | */ |
| 3385 | if (s.to_read || s.non_overwrite |
| 3386 | || (conf->level == 6 && s.to_write && s.failed) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3387 | || (s.syncing && (s.uptodate + s.compute < disks)) |
| 3388 | || s.replacing |
| 3389 | || s.expanding) |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3390 | handle_stripe_fill(sh, &s, disks); |
| 3391 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3392 | /* Now we check to see if any write operations have recently |
| 3393 | * completed |
| 3394 | */ |
| 3395 | prexor = 0; |
| 3396 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
| 3397 | prexor = 1; |
| 3398 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 3399 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
| 3400 | sh->reconstruct_state = reconstruct_state_idle; |
| 3401 | |
| 3402 | /* All the 'written' buffers and the parity block are ready to |
| 3403 | * be written back to disk |
| 3404 | */ |
| 3405 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); |
| 3406 | BUG_ON(sh->qd_idx >= 0 && |
| 3407 | !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags)); |
| 3408 | for (i = disks; i--; ) { |
| 3409 | struct r5dev *dev = &sh->dev[i]; |
| 3410 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3411 | (i == sh->pd_idx || i == sh->qd_idx || |
| 3412 | dev->written)) { |
| 3413 | pr_debug("Writing block %d\n", i); |
| 3414 | set_bit(R5_Wantwrite, &dev->flags); |
| 3415 | if (prexor) |
| 3416 | continue; |
| 3417 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3418 | ((i == sh->pd_idx || i == sh->qd_idx) && |
| 3419 | s.failed == 0)) |
| 3420 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3421 | } |
| 3422 | } |
| 3423 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3424 | s.dec_preread_active = 1; |
| 3425 | } |
| 3426 | |
| 3427 | /* Now to consider new write requests and what else, if anything |
| 3428 | * should be read. We do not handle new writes when: |
| 3429 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 3430 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3431 | * block. |
| 3432 | */ |
| 3433 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
| 3434 | handle_stripe_dirtying(conf, sh, &s, disks); |
| 3435 | |
| 3436 | /* maybe we need to check and possibly fix the parity for this stripe |
| 3437 | * Any reads will already have been scheduled, so we just see if enough |
| 3438 | * data is available. The parity check is held off while parity |
| 3439 | * dependent operations are in flight. |
| 3440 | */ |
| 3441 | if (sh->check_state || |
| 3442 | (s.syncing && s.locked == 0 && |
| 3443 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 3444 | !test_bit(STRIPE_INSYNC, &sh->state))) { |
| 3445 | if (conf->level == 6) |
| 3446 | handle_parity_checks6(conf, sh, &s, disks); |
| 3447 | else |
| 3448 | handle_parity_checks5(conf, sh, &s, disks); |
| 3449 | } |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3450 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3451 | if (s.replacing && s.locked == 0 |
| 3452 | && !test_bit(STRIPE_INSYNC, &sh->state)) { |
| 3453 | /* Write out to replacement devices where possible */ |
| 3454 | for (i = 0; i < conf->raid_disks; i++) |
| 3455 | if (test_bit(R5_UPTODATE, &sh->dev[i].flags) && |
| 3456 | test_bit(R5_NeedReplace, &sh->dev[i].flags)) { |
| 3457 | set_bit(R5_WantReplace, &sh->dev[i].flags); |
| 3458 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3459 | s.locked++; |
| 3460 | } |
| 3461 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3462 | } |
| 3463 | if ((s.syncing || s.replacing) && s.locked == 0 && |
| 3464 | test_bit(STRIPE_INSYNC, &sh->state)) { |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3465 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3466 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 3467 | } |
| 3468 | |
| 3469 | /* If the failed drives are just a ReadError, then we might need |
| 3470 | * to progress the repair/check process |
| 3471 | */ |
| 3472 | if (s.failed <= conf->max_degraded && !conf->mddev->ro) |
| 3473 | for (i = 0; i < s.failed; i++) { |
| 3474 | struct r5dev *dev = &sh->dev[s.failed_num[i]]; |
| 3475 | if (test_bit(R5_ReadError, &dev->flags) |
| 3476 | && !test_bit(R5_LOCKED, &dev->flags) |
| 3477 | && test_bit(R5_UPTODATE, &dev->flags) |
| 3478 | ) { |
| 3479 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3480 | set_bit(R5_Wantwrite, &dev->flags); |
| 3481 | set_bit(R5_ReWrite, &dev->flags); |
| 3482 | set_bit(R5_LOCKED, &dev->flags); |
| 3483 | s.locked++; |
| 3484 | } else { |
| 3485 | /* let's read it back */ |
| 3486 | set_bit(R5_Wantread, &dev->flags); |
| 3487 | set_bit(R5_LOCKED, &dev->flags); |
| 3488 | s.locked++; |
| 3489 | } |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3494 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3495 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 3496 | struct stripe_head *sh_src |
| 3497 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
| 3498 | if (sh_src && test_bit(STRIPE_EXPAND_SOURCE, &sh_src->state)) { |
| 3499 | /* sh cannot be written until sh_src has been read. |
| 3500 | * so arrange for sh to be delayed a little |
| 3501 | */ |
| 3502 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3503 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3504 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3505 | &sh_src->state)) |
| 3506 | atomic_inc(&conf->preread_active_stripes); |
| 3507 | release_stripe(sh_src); |
| 3508 | goto finish; |
| 3509 | } |
| 3510 | if (sh_src) |
| 3511 | release_stripe(sh_src); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3512 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3513 | sh->reconstruct_state = reconstruct_state_idle; |
| 3514 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 3515 | for (i = conf->raid_disks; i--; ) { |
| 3516 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 3517 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3518 | s.locked++; |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 3523 | !sh->reconstruct_state) { |
| 3524 | /* Need to write out all blocks after computing parity */ |
| 3525 | sh->disks = conf->raid_disks; |
| 3526 | stripe_set_idx(sh->sector, conf, 0, sh); |
| 3527 | schedule_reconstruction(sh, &s, 1, 1); |
| 3528 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
| 3529 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3530 | atomic_dec(&conf->reshape_stripes); |
| 3531 | wake_up(&conf->wait_for_overlap); |
| 3532 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3533 | } |
| 3534 | |
| 3535 | if (s.expanding && s.locked == 0 && |
| 3536 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
| 3537 | handle_stripe_expansion(conf, sh); |
| 3538 | |
| 3539 | finish: |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3540 | /* wait for this device to become unblocked */ |
NeilBrown | 43220aa | 2011-08-31 12:49:14 +1000 | [diff] [blame] | 3541 | if (conf->mddev->external && unlikely(s.blocked_rdev)) |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3542 | md_wait_for_blocked_rdev(s.blocked_rdev, conf->mddev); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3543 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3544 | if (s.handle_bad_blocks) |
| 3545 | for (i = disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3546 | struct md_rdev *rdev; |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3547 | struct r5dev *dev = &sh->dev[i]; |
| 3548 | if (test_and_clear_bit(R5_WriteError, &dev->flags)) { |
| 3549 | /* We own a safe reference to the rdev */ |
| 3550 | rdev = conf->disks[i].rdev; |
| 3551 | if (!rdev_set_badblocks(rdev, sh->sector, |
| 3552 | STRIPE_SECTORS, 0)) |
| 3553 | md_error(conf->mddev, rdev); |
| 3554 | rdev_dec_pending(rdev, conf->mddev); |
| 3555 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3556 | if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { |
| 3557 | rdev = conf->disks[i].rdev; |
| 3558 | rdev_clear_badblocks(rdev, sh->sector, |
| 3559 | STRIPE_SECTORS); |
| 3560 | rdev_dec_pending(rdev, conf->mddev); |
| 3561 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3562 | if (test_and_clear_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 3563 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3564 | if (!rdev) |
| 3565 | /* rdev have been moved down */ |
| 3566 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3567 | rdev_clear_badblocks(rdev, sh->sector, |
| 3568 | STRIPE_SECTORS); |
| 3569 | rdev_dec_pending(rdev, conf->mddev); |
| 3570 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3571 | } |
| 3572 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3573 | if (s.ops_request) |
| 3574 | raid_run_ops(sh, s.ops_request); |
| 3575 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 3576 | ops_run_io(sh, &s); |
| 3577 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3578 | if (s.dec_preread_active) { |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3579 | /* 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] | 3580 | * is waiting on a flush, it won't continue until the writes |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3581 | * have actually been submitted. |
| 3582 | */ |
| 3583 | atomic_dec(&conf->preread_active_stripes); |
| 3584 | if (atomic_read(&conf->preread_active_stripes) < |
| 3585 | IO_THRESHOLD) |
| 3586 | md_wakeup_thread(conf->mddev->thread); |
| 3587 | } |
| 3588 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3589 | return_io(s.return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3590 | |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 3591 | clear_bit_unlock(STRIPE_ACTIVE, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3594 | static void raid5_activate_delayed(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | { |
| 3596 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 3597 | while (!list_empty(&conf->delayed_list)) { |
| 3598 | struct list_head *l = conf->delayed_list.next; |
| 3599 | struct stripe_head *sh; |
| 3600 | sh = list_entry(l, struct stripe_head, lru); |
| 3601 | list_del_init(l); |
| 3602 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3603 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3604 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3605 | list_add_tail(&sh->lru, &conf->hold_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | } |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 3607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3610 | static void activate_bit_delay(struct r5conf *conf) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3611 | { |
| 3612 | /* device_lock is held */ |
| 3613 | struct list_head head; |
| 3614 | list_add(&head, &conf->bitmap_list); |
| 3615 | list_del_init(&conf->bitmap_list); |
| 3616 | while (!list_empty(&head)) { |
| 3617 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
| 3618 | list_del_init(&sh->lru); |
| 3619 | atomic_inc(&sh->count); |
| 3620 | __release_stripe(conf, sh); |
| 3621 | } |
| 3622 | } |
| 3623 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3624 | int md_raid5_congested(struct mddev *mddev, int bits) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3625 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3626 | struct r5conf *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3627 | |
| 3628 | /* No difference between reads and writes. Just check |
| 3629 | * how busy the stripe_cache is |
| 3630 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 3631 | |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3632 | if (conf->inactive_blocked) |
| 3633 | return 1; |
| 3634 | if (conf->quiesce) |
| 3635 | return 1; |
| 3636 | if (list_empty_careful(&conf->inactive_list)) |
| 3637 | return 1; |
| 3638 | |
| 3639 | return 0; |
| 3640 | } |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3641 | EXPORT_SYMBOL_GPL(md_raid5_congested); |
| 3642 | |
| 3643 | static int raid5_congested(void *data, int bits) |
| 3644 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3645 | struct mddev *mddev = data; |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3646 | |
| 3647 | return mddev_congested(mddev, bits) || |
| 3648 | md_raid5_congested(mddev, bits); |
| 3649 | } |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3650 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3651 | /* We want read requests to align with chunks where possible, |
| 3652 | * but write requests don't need to. |
| 3653 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3654 | static int raid5_mergeable_bvec(struct request_queue *q, |
| 3655 | struct bvec_merge_data *bvm, |
| 3656 | struct bio_vec *biovec) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3657 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3658 | struct mddev *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3659 | 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] | 3660 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3661 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3662 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3663 | |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3664 | if ((bvm->bi_rw & 1) == WRITE) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3665 | return biovec->bv_len; /* always allow writes to be mergeable */ |
| 3666 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3667 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3668 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3669 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 3670 | if (max < 0) max = 0; |
| 3671 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 3672 | return biovec->bv_len; |
| 3673 | else |
| 3674 | return max; |
| 3675 | } |
| 3676 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3677 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3678 | 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] | 3679 | { |
| 3680 | sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3681 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3682 | unsigned int bio_sectors = bio->bi_size >> 9; |
| 3683 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3684 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3685 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3686 | return chunk_sectors >= |
| 3687 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 3688 | } |
| 3689 | |
| 3690 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3691 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 3692 | * later sampled by raid5d. |
| 3693 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3694 | 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] | 3695 | { |
| 3696 | unsigned long flags; |
| 3697 | |
| 3698 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3699 | |
| 3700 | bi->bi_next = conf->retry_read_aligned_list; |
| 3701 | conf->retry_read_aligned_list = bi; |
| 3702 | |
| 3703 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3704 | md_wakeup_thread(conf->mddev->thread); |
| 3705 | } |
| 3706 | |
| 3707 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3708 | static struct bio *remove_bio_from_retry(struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3709 | { |
| 3710 | struct bio *bi; |
| 3711 | |
| 3712 | bi = conf->retry_read_aligned; |
| 3713 | if (bi) { |
| 3714 | conf->retry_read_aligned = NULL; |
| 3715 | return bi; |
| 3716 | } |
| 3717 | bi = conf->retry_read_aligned_list; |
| 3718 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3719 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3720 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 3721 | /* |
| 3722 | * this sets the active strip count to 1 and the processed |
| 3723 | * strip count to zero (upper 8 bits) |
| 3724 | */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3725 | bi->bi_phys_segments = 1; /* biased count of active stripes */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | return bi; |
| 3729 | } |
| 3730 | |
| 3731 | |
| 3732 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3733 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 3734 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 3735 | * first). |
| 3736 | * If the read failed.. |
| 3737 | */ |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3738 | static void raid5_align_endio(struct bio *bi, int error) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3739 | { |
| 3740 | struct bio* raid_bi = bi->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3741 | struct mddev *mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3742 | struct r5conf *conf; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3743 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3744 | struct md_rdev *rdev; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3745 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3746 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3747 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3748 | rdev = (void*)raid_bi->bi_next; |
| 3749 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 3750 | mddev = rdev->mddev; |
| 3751 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3752 | |
| 3753 | rdev_dec_pending(rdev, conf->mddev); |
| 3754 | |
| 3755 | if (!error && uptodate) { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3756 | bio_endio(raid_bi, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3757 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 3758 | wake_up(&conf->wait_for_stripe); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3759 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3763 | 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] | 3764 | |
| 3765 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3766 | } |
| 3767 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3768 | static int bio_fits_rdev(struct bio *bi) |
| 3769 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3770 | struct request_queue *q = bdev_get_queue(bi->bi_bdev); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3771 | |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 3772 | if ((bi->bi_size>>9) > queue_max_sectors(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3773 | return 0; |
| 3774 | blk_recount_segments(q, bi); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 3775 | if (bi->bi_phys_segments > queue_max_segments(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3776 | return 0; |
| 3777 | |
| 3778 | if (q->merge_bvec_fn) |
| 3779 | /* it's too hard to apply the merge_bvec_fn at this stage, |
| 3780 | * just just give up |
| 3781 | */ |
| 3782 | return 0; |
| 3783 | |
| 3784 | return 1; |
| 3785 | } |
| 3786 | |
| 3787 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3788 | 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] | 3789 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3790 | struct r5conf *conf = mddev->private; |
NeilBrown | 8553fe7ec | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 3791 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3792 | struct bio* align_bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3793 | struct md_rdev *rdev; |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3794 | sector_t end_sector; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3795 | |
| 3796 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3797 | pr_debug("chunk_aligned_read : non aligned\n"); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3798 | return 0; |
| 3799 | } |
| 3800 | /* |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 3801 | * 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] | 3802 | */ |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 3803 | align_bi = bio_clone_mddev(raid_bio, GFP_NOIO, mddev); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3804 | if (!align_bi) |
| 3805 | return 0; |
| 3806 | /* |
| 3807 | * set bi_end_io to a new function, and set bi_private to the |
| 3808 | * original bio. |
| 3809 | */ |
| 3810 | align_bi->bi_end_io = raid5_align_endio; |
| 3811 | align_bi->bi_private = raid_bio; |
| 3812 | /* |
| 3813 | * compute position |
| 3814 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3815 | align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, |
| 3816 | 0, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3817 | &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3818 | |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3819 | end_sector = align_bi->bi_sector + (align_bi->bi_size >> 9); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3820 | rcu_read_lock(); |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 3821 | rdev = rcu_dereference(conf->disks[dd_idx].replacement); |
| 3822 | if (!rdev || test_bit(Faulty, &rdev->flags) || |
| 3823 | rdev->recovery_offset < end_sector) { |
| 3824 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 3825 | if (rdev && |
| 3826 | (test_bit(Faulty, &rdev->flags) || |
| 3827 | !(test_bit(In_sync, &rdev->flags) || |
| 3828 | rdev->recovery_offset >= end_sector))) |
| 3829 | rdev = NULL; |
| 3830 | } |
| 3831 | if (rdev) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3832 | sector_t first_bad; |
| 3833 | int bad_sectors; |
| 3834 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3835 | atomic_inc(&rdev->nr_pending); |
| 3836 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3837 | raid_bio->bi_next = (void*)rdev; |
| 3838 | align_bi->bi_bdev = rdev->bdev; |
| 3839 | align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); |
| 3840 | align_bi->bi_sector += rdev->data_offset; |
| 3841 | |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3842 | if (!bio_fits_rdev(align_bi) || |
| 3843 | is_badblock(rdev, align_bi->bi_sector, align_bi->bi_size>>9, |
| 3844 | &first_bad, &bad_sectors)) { |
| 3845 | /* too big in some way, or has a known bad block */ |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3846 | bio_put(align_bi); |
| 3847 | rdev_dec_pending(rdev, mddev); |
| 3848 | return 0; |
| 3849 | } |
| 3850 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3851 | spin_lock_irq(&conf->device_lock); |
| 3852 | wait_event_lock_irq(conf->wait_for_stripe, |
| 3853 | conf->quiesce == 0, |
| 3854 | conf->device_lock, /* nothing */); |
| 3855 | atomic_inc(&conf->active_aligned_reads); |
| 3856 | spin_unlock_irq(&conf->device_lock); |
| 3857 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3858 | generic_make_request(align_bi); |
| 3859 | return 1; |
| 3860 | } else { |
| 3861 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3862 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3863 | return 0; |
| 3864 | } |
| 3865 | } |
| 3866 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3867 | /* __get_priority_stripe - get the next stripe to process |
| 3868 | * |
| 3869 | * Full stripe writes are allowed to pass preread active stripes up until |
| 3870 | * the bypass_threshold is exceeded. In general the bypass_count |
| 3871 | * increments when the handle_list is handled before the hold_list; however, it |
| 3872 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 3873 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 3874 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 3875 | * handle_list. |
| 3876 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3877 | static struct stripe_head *__get_priority_stripe(struct r5conf *conf) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3878 | { |
| 3879 | struct stripe_head *sh; |
| 3880 | |
| 3881 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 3882 | __func__, |
| 3883 | list_empty(&conf->handle_list) ? "empty" : "busy", |
| 3884 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 3885 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 3886 | |
| 3887 | if (!list_empty(&conf->handle_list)) { |
| 3888 | sh = list_entry(conf->handle_list.next, typeof(*sh), lru); |
| 3889 | |
| 3890 | if (list_empty(&conf->hold_list)) |
| 3891 | conf->bypass_count = 0; |
| 3892 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 3893 | if (conf->hold_list.next == conf->last_hold) |
| 3894 | conf->bypass_count++; |
| 3895 | else { |
| 3896 | conf->last_hold = conf->hold_list.next; |
| 3897 | conf->bypass_count -= conf->bypass_threshold; |
| 3898 | if (conf->bypass_count < 0) |
| 3899 | conf->bypass_count = 0; |
| 3900 | } |
| 3901 | } |
| 3902 | } else if (!list_empty(&conf->hold_list) && |
| 3903 | ((conf->bypass_threshold && |
| 3904 | conf->bypass_count > conf->bypass_threshold) || |
| 3905 | atomic_read(&conf->pending_full_writes) == 0)) { |
| 3906 | sh = list_entry(conf->hold_list.next, |
| 3907 | typeof(*sh), lru); |
| 3908 | conf->bypass_count -= conf->bypass_threshold; |
| 3909 | if (conf->bypass_count < 0) |
| 3910 | conf->bypass_count = 0; |
| 3911 | } else |
| 3912 | return NULL; |
| 3913 | |
| 3914 | list_del_init(&sh->lru); |
| 3915 | atomic_inc(&sh->count); |
| 3916 | BUG_ON(atomic_read(&sh->count) != 1); |
| 3917 | return sh; |
| 3918 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3919 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame] | 3920 | static void make_request(struct mddev *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3922 | struct r5conf *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3923 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | sector_t new_sector; |
| 3925 | sector_t logical_sector, last_sector; |
| 3926 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 3927 | const int rw = bio_data_dir(bi); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 3928 | int remaining; |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 3929 | int plugged; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 3931 | if (unlikely(bi->bi_rw & REQ_FLUSH)) { |
| 3932 | md_flush_request(mddev, bi); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 3933 | return; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 3936 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3937 | |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 3938 | if (rw == READ && |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3939 | mddev->reshape_position == MaxSector && |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 3940 | chunk_aligned_read(mddev,bi)) |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 3941 | return; |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 3944 | last_sector = bi->bi_sector + (bi->bi_size>>9); |
| 3945 | bi->bi_next = NULL; |
| 3946 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3947 | |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 3948 | plugged = mddev_check_plugged(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
| 3950 | DEFINE_WAIT(w); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3951 | int disks, data_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3952 | int previous; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3953 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3954 | retry: |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3955 | previous = 0; |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3956 | disks = conf->raid_disks; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3957 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3958 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3959 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3960 | * 64bit on a 32bit platform, and so it might be |
| 3961 | * possible to see a half-updated value |
Jesper Juhl | aeb878b | 2011-04-10 18:06:17 +0200 | [diff] [blame] | 3962 | * Of course reshape_progress could change after |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3963 | * the lock is dropped, so once we get a reference |
| 3964 | * to the stripe that we think it is, we will have |
| 3965 | * to check again. |
| 3966 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3967 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3968 | if (mddev->delta_disks < 0 |
| 3969 | ? logical_sector < conf->reshape_progress |
| 3970 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3971 | disks = conf->previous_raid_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3972 | previous = 1; |
| 3973 | } else { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3974 | if (mddev->delta_disks < 0 |
| 3975 | ? logical_sector < conf->reshape_safe |
| 3976 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3977 | spin_unlock_irq(&conf->device_lock); |
| 3978 | schedule(); |
| 3979 | goto retry; |
| 3980 | } |
| 3981 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3982 | spin_unlock_irq(&conf->device_lock); |
| 3983 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3984 | data_disks = disks - conf->max_degraded; |
| 3985 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3986 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 3987 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3988 | &dd_idx, NULL); |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 3989 | pr_debug("raid456: make_request, sector %llu logical %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | (unsigned long long)new_sector, |
| 3991 | (unsigned long long)logical_sector); |
| 3992 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3993 | sh = get_active_stripe(conf, new_sector, previous, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3994 | (bi->bi_rw&RWA_MASK), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3996 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3997 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3998 | * stripe, so we must do the range check again. |
| 3999 | * Expansion could still move past after this |
| 4000 | * test, but as we are holding a reference to |
| 4001 | * 'sh', we know that if that happens, |
| 4002 | * STRIPE_EXPANDING will get set and the expansion |
| 4003 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4004 | */ |
| 4005 | int must_retry = 0; |
| 4006 | spin_lock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 4007 | if (mddev->delta_disks < 0 |
| 4008 | ? logical_sector >= conf->reshape_progress |
| 4009 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4010 | /* mismatch, need to try again */ |
| 4011 | must_retry = 1; |
| 4012 | spin_unlock_irq(&conf->device_lock); |
| 4013 | if (must_retry) { |
| 4014 | release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 4015 | schedule(); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4016 | goto retry; |
| 4017 | } |
| 4018 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4019 | |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 4020 | if (rw == WRITE && |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4021 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4022 | logical_sector < mddev->suspend_hi) { |
| 4023 | release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 4024 | /* As the suspend_* range is controlled by |
| 4025 | * userspace, we want an interruptible |
| 4026 | * wait. |
| 4027 | */ |
| 4028 | flush_signals(current); |
| 4029 | prepare_to_wait(&conf->wait_for_overlap, |
| 4030 | &w, TASK_INTERRUPTIBLE); |
| 4031 | if (logical_sector >= mddev->suspend_lo && |
| 4032 | logical_sector < mddev->suspend_hi) |
| 4033 | schedule(); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 4034 | goto retry; |
| 4035 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4036 | |
| 4037 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 4038 | !add_stripe_bio(sh, bi, dd_idx, rw)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 4039 | /* Stripe is busy expanding or |
| 4040 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | * and wait a while |
| 4042 | */ |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 4043 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | release_stripe(sh); |
| 4045 | schedule(); |
| 4046 | goto retry; |
| 4047 | } |
| 4048 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4049 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4050 | clear_bit(STRIPE_DELAYED, &sh->state); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 4051 | if ((bi->bi_rw & REQ_SYNC) && |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4052 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4053 | atomic_inc(&conf->preread_active_stripes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | } else { |
| 4056 | /* cannot get stripe for read-ahead, just give-up */ |
| 4057 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
| 4058 | finish_wait(&conf->wait_for_overlap, &w); |
| 4059 | break; |
| 4060 | } |
| 4061 | |
| 4062 | } |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4063 | if (!plugged) |
| 4064 | md_wakeup_thread(mddev->thread); |
| 4065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4067 | remaining = raid5_dec_bi_phys_segments(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 4068 | spin_unlock_irq(&conf->device_lock); |
| 4069 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4071 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4073 | |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4074 | bio_endio(bi, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | } |
| 4077 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4078 | 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] | 4079 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4080 | 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] | 4081 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4082 | /* reshaping is quite different to recovery/resync so it is |
| 4083 | * handled quite separately ... here. |
| 4084 | * |
| 4085 | * On each call to sync_request, we gather one chunk worth of |
| 4086 | * destination stripes and flag them as expanding. |
| 4087 | * Then we find all the source stripes and request reads. |
| 4088 | * As the reads complete, handle_stripe will copy the data |
| 4089 | * into the destination stripe and release that stripe. |
| 4090 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4091 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4093 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4094 | int raid_disks = conf->previous_raid_disks; |
| 4095 | int data_disks = raid_disks - conf->max_degraded; |
| 4096 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4097 | int i; |
| 4098 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4099 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4100 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4101 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4102 | struct list_head stripes; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4103 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4104 | if (sector_nr == 0) { |
| 4105 | /* If restarting in the middle, skip the initial sectors */ |
| 4106 | if (mddev->delta_disks < 0 && |
| 4107 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 4108 | sector_nr = raid5_size(mddev, 0, 0) |
| 4109 | - conf->reshape_progress; |
NeilBrown | a639755 | 2009-08-13 10:13:00 +1000 | [diff] [blame] | 4110 | } else if (mddev->delta_disks >= 0 && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4111 | conf->reshape_progress > 0) |
| 4112 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4113 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4114 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 4115 | mddev->curr_resync_completed = sector_nr; |
| 4116 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4117 | *skipped = 1; |
| 4118 | return sector_nr; |
| 4119 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4122 | /* We need to process a full chunk at a time. |
| 4123 | * If old and new chunk sizes differ, we need to process the |
| 4124 | * largest of these |
| 4125 | */ |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4126 | if (mddev->new_chunk_sectors > mddev->chunk_sectors) |
| 4127 | reshape_sectors = mddev->new_chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4128 | else |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4129 | reshape_sectors = mddev->chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4130 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4131 | /* we update the metadata when there is more than 3Meg |
| 4132 | * in the block range (that is rather arbitrary, should |
| 4133 | * probably be time based) or when the data about to be |
| 4134 | * copied would over-write the source of the data at |
| 4135 | * the front of the range. |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4136 | * i.e. one new_stripe along from reshape_progress new_maps |
| 4137 | * to after where reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4138 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4139 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4140 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4141 | readpos = conf->reshape_progress; |
| 4142 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4143 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4144 | sector_div(safepos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4145 | if (mddev->delta_disks < 0) { |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4146 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4147 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4148 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4149 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4150 | writepos += reshape_sectors; |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4151 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 4152 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4153 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4154 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4155 | /* 'writepos' is the most advanced device address we might write. |
| 4156 | * 'readpos' is the least advanced device address we might read. |
| 4157 | * 'safepos' is the least address recorded in the metadata as having |
| 4158 | * been reshaped. |
| 4159 | * If 'readpos' is behind 'writepos', then there is no way that we can |
| 4160 | * ensure safety in the face of a crash - that must be done by userspace |
| 4161 | * making a backup of the data. So in that case there is no particular |
| 4162 | * rush to update metadata. |
| 4163 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 4164 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 4165 | * we can be safe in the event of a crash. |
| 4166 | * So we insist on updating metadata if safepos is behind writepos and |
| 4167 | * readpos is beyond writepos. |
| 4168 | * In any case, update the metadata every 10 seconds. |
| 4169 | * Maybe that number should be configurable, but I'm not sure it is |
| 4170 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 4171 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4172 | if ((mddev->delta_disks < 0 |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4173 | ? (safepos > writepos && readpos < writepos) |
| 4174 | : (safepos < writepos && readpos > writepos)) || |
| 4175 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4176 | /* Cannot proceed until we've updated the superblock... */ |
| 4177 | wait_event(conf->wait_for_overlap, |
| 4178 | atomic_read(&conf->reshape_stripes)==0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4179 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4180 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4181 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4182 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4183 | md_wakeup_thread(mddev->thread); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4184 | wait_event(mddev->sb_wait, mddev->flags == 0 || |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4185 | kthread_should_stop()); |
| 4186 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4187 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4188 | spin_unlock_irq(&conf->device_lock); |
| 4189 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4190 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4193 | if (mddev->delta_disks < 0) { |
| 4194 | BUG_ON(conf->reshape_progress == 0); |
| 4195 | stripe_addr = writepos; |
| 4196 | BUG_ON((mddev->dev_sectors & |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4197 | ~((sector_t)reshape_sectors - 1)) |
| 4198 | - reshape_sectors - stripe_addr |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4199 | != sector_nr); |
| 4200 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4201 | BUG_ON(writepos != sector_nr + reshape_sectors); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4202 | stripe_addr = sector_nr; |
| 4203 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4204 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4205 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4206 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4207 | int skipped_disk = 0; |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4208 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4209 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 4210 | atomic_inc(&conf->reshape_stripes); |
| 4211 | /* If any of this stripe is beyond the end of the old |
| 4212 | * array, then we need to zero those blocks |
| 4213 | */ |
| 4214 | for (j=sh->disks; j--;) { |
| 4215 | sector_t s; |
| 4216 | if (j == sh->pd_idx) |
| 4217 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4218 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4219 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4220 | continue; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 4221 | s = compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4222 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4223 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4224 | continue; |
| 4225 | } |
| 4226 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 4227 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 4228 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 4229 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4230 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4231 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4232 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4233 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4234 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4235 | } |
| 4236 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4237 | if (mddev->delta_disks < 0) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4238 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4239 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4240 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4241 | spin_unlock_irq(&conf->device_lock); |
| 4242 | /* Ok, those stripe are ready. We can start scheduling |
| 4243 | * reads on the source stripes. |
| 4244 | * The source stripes are determined by mapping the first and last |
| 4245 | * block on the destination stripes. |
| 4246 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4247 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4248 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4249 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4250 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 4251 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4252 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4253 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4254 | if (last_sector >= mddev->dev_sectors) |
| 4255 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4256 | while (first_sector <= last_sector) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4257 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4258 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4259 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4260 | release_stripe(sh); |
| 4261 | first_sector += STRIPE_SECTORS; |
| 4262 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4263 | /* Now that the sources are clearly marked, we can release |
| 4264 | * the destination stripes |
| 4265 | */ |
| 4266 | while (!list_empty(&stripes)) { |
| 4267 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 4268 | list_del_init(&sh->lru); |
| 4269 | release_stripe(sh); |
| 4270 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4271 | /* If this takes us to the resync_max point where we have to pause, |
| 4272 | * then we need to write out the superblock. |
| 4273 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4274 | sector_nr += reshape_sectors; |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 4275 | if ((sector_nr - mddev->curr_resync_completed) * 2 |
| 4276 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4277 | /* Cannot proceed until we've updated the superblock... */ |
| 4278 | wait_event(conf->wait_for_overlap, |
| 4279 | atomic_read(&conf->reshape_stripes) == 0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4280 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4281 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4282 | conf->reshape_checkpoint = jiffies; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4283 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 4284 | md_wakeup_thread(mddev->thread); |
| 4285 | wait_event(mddev->sb_wait, |
| 4286 | !test_bit(MD_CHANGE_DEVS, &mddev->flags) |
| 4287 | || kthread_should_stop()); |
| 4288 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4289 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4290 | spin_unlock_irq(&conf->device_lock); |
| 4291 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4292 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4293 | } |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4294 | return reshape_sectors; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | /* FIXME go_faster isn't used */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4298 | 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] | 4299 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4300 | struct r5conf *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4301 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4302 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 4303 | sector_t sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4304 | int still_degraded = 0; |
| 4305 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4307 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | /* just being told to finish up .. nothing much to do */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 4309 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 4310 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 4311 | end_reshape(conf); |
| 4312 | return 0; |
| 4313 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4314 | |
| 4315 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 4316 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 4317 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4318 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4319 | conf->fullsync = 0; |
| 4320 | bitmap_close_sync(mddev->bitmap); |
| 4321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | return 0; |
| 4323 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4324 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4325 | /* Allow raid5_quiesce to complete */ |
| 4326 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 4327 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4328 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 4329 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4330 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4331 | /* No need to check resync_max as we never do more than one |
| 4332 | * stripe, and as resync_max will always be on a chunk boundary, |
| 4333 | * if the check in md_do_sync didn't fire, there is no chance |
| 4334 | * of overstepping resync_max here |
| 4335 | */ |
| 4336 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4337 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | * to resync, then assert that we are finished, because there is |
| 4339 | * nothing we can do. |
| 4340 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 4341 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4342 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4343 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 4344 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | return rv; |
| 4346 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4347 | if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
NeilBrown | 3855ad9 | 2005-11-08 21:39:38 -0800 | [diff] [blame] | 4348 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4349 | !conf->fullsync && sync_blocks >= STRIPE_SECTORS) { |
| 4350 | /* we can skip this block, and probably more */ |
| 4351 | sync_blocks /= STRIPE_SECTORS; |
| 4352 | *skipped = 1; |
| 4353 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 4354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 4356 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 4357 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4358 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | if (sh == NULL) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4360 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4362 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 4364 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4366 | /* Need to check if array will still be degraded after recovery/resync |
| 4367 | * We don't need to check the 'failed' flag as when that gets set, |
| 4368 | * recovery aborts. |
| 4369 | */ |
NeilBrown | f001a70 | 2009-06-09 14:30:31 +1000 | [diff] [blame] | 4370 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4371 | if (conf->disks[i].rdev == NULL) |
| 4372 | still_degraded = 1; |
| 4373 | |
| 4374 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 4375 | |
NeilBrown | 83206d6 | 2011-07-26 11:19:49 +1000 | [diff] [blame] | 4376 | set_bit(STRIPE_SYNC_REQUESTED, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 4378 | handle_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | release_stripe(sh); |
| 4380 | |
| 4381 | return STRIPE_SECTORS; |
| 4382 | } |
| 4383 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4384 | 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] | 4385 | { |
| 4386 | /* We may not be able to submit a whole bio at once as there |
| 4387 | * may not be enough stripe_heads available. |
| 4388 | * We cannot pre-allocate enough stripe_heads as we may need |
| 4389 | * more than exist in the cache (if we allow ever large chunks). |
| 4390 | * So we do one stripe head at a time and record in |
| 4391 | * ->bi_hw_segments how many have been done. |
| 4392 | * |
| 4393 | * We *know* that this entire raid_bio is in one chunk, so |
| 4394 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 4395 | */ |
| 4396 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4397 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4398 | sector_t sector, logical_sector, last_sector; |
| 4399 | int scnt = 0; |
| 4400 | int remaining; |
| 4401 | int handled = 0; |
| 4402 | |
| 4403 | logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4404 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4405 | 0, &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4406 | last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9); |
| 4407 | |
| 4408 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4409 | logical_sector += STRIPE_SECTORS, |
| 4410 | sector += STRIPE_SECTORS, |
| 4411 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4412 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4413 | if (scnt < raid5_bi_hw_segments(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4414 | /* already done this stripe */ |
| 4415 | continue; |
| 4416 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4417 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4418 | |
| 4419 | if (!sh) { |
| 4420 | /* failed to get a stripe - must wait */ |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4421 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4422 | conf->retry_read_aligned = raid_bio; |
| 4423 | return handled; |
| 4424 | } |
| 4425 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4426 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
| 4427 | release_stripe(sh); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4428 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4429 | conf->retry_read_aligned = raid_bio; |
| 4430 | return handled; |
| 4431 | } |
| 4432 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4433 | handle_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4434 | release_stripe(sh); |
| 4435 | handled++; |
| 4436 | } |
| 4437 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4438 | remaining = raid5_dec_bi_phys_segments(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4439 | spin_unlock_irq(&conf->device_lock); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4440 | if (remaining == 0) |
| 4441 | bio_endio(raid_bio, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4442 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4443 | wake_up(&conf->wait_for_stripe); |
| 4444 | return handled; |
| 4445 | } |
| 4446 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | /* |
| 4449 | * This is our raid5 kernel thread. |
| 4450 | * |
| 4451 | * We scan the hash table for stripes which can be handled now. |
| 4452 | * During the scan, completed stripes are saved for us by the interrupt |
| 4453 | * handler, so that they will not have to wait for our next wakeup. |
| 4454 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4455 | static void raid5d(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | { |
| 4457 | struct stripe_head *sh; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4458 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | int handled; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4460 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4462 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | |
| 4464 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4466 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | handled = 0; |
| 4468 | spin_lock_irq(&conf->device_lock); |
| 4469 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4470 | struct bio *bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4472 | if (atomic_read(&mddev->plug_cnt) == 0 && |
| 4473 | !list_empty(&conf->bitmap_list)) { |
| 4474 | /* Now is a good time to flush some bitmap updates */ |
| 4475 | conf->seq_flush++; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4476 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4477 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4478 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4479 | conf->seq_write = conf->seq_flush; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4480 | activate_bit_delay(conf); |
| 4481 | } |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4482 | if (atomic_read(&mddev->plug_cnt) == 0) |
| 4483 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4484 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4485 | while ((bio = remove_bio_from_retry(conf))) { |
| 4486 | int ok; |
| 4487 | spin_unlock_irq(&conf->device_lock); |
| 4488 | ok = retry_aligned_read(conf, bio); |
| 4489 | spin_lock_irq(&conf->device_lock); |
| 4490 | if (!ok) |
| 4491 | break; |
| 4492 | handled++; |
| 4493 | } |
| 4494 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4495 | sh = __get_priority_stripe(conf); |
| 4496 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4497 | if (!sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | spin_unlock_irq(&conf->device_lock); |
| 4500 | |
| 4501 | handled++; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 4502 | handle_stripe(sh); |
| 4503 | release_stripe(sh); |
| 4504 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 4506 | if (mddev->flags & ~(1<<MD_CHANGE_PENDING)) |
| 4507 | md_check_recovery(mddev); |
| 4508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | spin_lock_irq(&conf->device_lock); |
| 4510 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4511 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | |
| 4513 | spin_unlock_irq(&conf->device_lock); |
| 4514 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4515 | async_tx_issue_pending_all(); |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4516 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4518 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | } |
| 4520 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4521 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4522 | raid5_show_stripe_cache_size(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4523 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4524 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4525 | if (conf) |
| 4526 | return sprintf(page, "%d\n", conf->max_nr_stripes); |
| 4527 | else |
| 4528 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4529 | } |
| 4530 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4531 | int |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4532 | raid5_set_cache_size(struct mddev *mddev, int size) |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4533 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4534 | struct r5conf *conf = mddev->private; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4535 | int err; |
| 4536 | |
| 4537 | if (size <= 16 || size > 32768) |
| 4538 | return -EINVAL; |
| 4539 | while (size < conf->max_nr_stripes) { |
| 4540 | if (drop_one_stripe(conf)) |
| 4541 | conf->max_nr_stripes--; |
| 4542 | else |
| 4543 | break; |
| 4544 | } |
| 4545 | err = md_allow_write(mddev); |
| 4546 | if (err) |
| 4547 | return err; |
| 4548 | while (size > conf->max_nr_stripes) { |
| 4549 | if (grow_one_stripe(conf)) |
| 4550 | conf->max_nr_stripes++; |
| 4551 | else break; |
| 4552 | } |
| 4553 | return 0; |
| 4554 | } |
| 4555 | EXPORT_SYMBOL(raid5_set_cache_size); |
| 4556 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4557 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4558 | 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] | 4559 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4560 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4561 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4562 | int err; |
| 4563 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4564 | if (len >= PAGE_SIZE) |
| 4565 | return -EINVAL; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4566 | if (!conf) |
| 4567 | return -ENODEV; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4568 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4569 | if (strict_strtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4570 | return -EINVAL; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4571 | err = raid5_set_cache_size(mddev, new); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4572 | if (err) |
| 4573 | return err; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4574 | return len; |
| 4575 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4576 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4577 | static struct md_sysfs_entry |
| 4578 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 4579 | raid5_show_stripe_cache_size, |
| 4580 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4581 | |
| 4582 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4583 | raid5_show_preread_threshold(struct mddev *mddev, char *page) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4584 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4585 | struct r5conf *conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4586 | if (conf) |
| 4587 | return sprintf(page, "%d\n", conf->bypass_threshold); |
| 4588 | else |
| 4589 | return 0; |
| 4590 | } |
| 4591 | |
| 4592 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4593 | 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] | 4594 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4595 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4596 | unsigned long new; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4597 | if (len >= PAGE_SIZE) |
| 4598 | return -EINVAL; |
| 4599 | if (!conf) |
| 4600 | return -ENODEV; |
| 4601 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4602 | if (strict_strtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4603 | return -EINVAL; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4604 | if (new > conf->max_nr_stripes) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4605 | return -EINVAL; |
| 4606 | conf->bypass_threshold = new; |
| 4607 | return len; |
| 4608 | } |
| 4609 | |
| 4610 | static struct md_sysfs_entry |
| 4611 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 4612 | S_IRUGO | S_IWUSR, |
| 4613 | raid5_show_preread_threshold, |
| 4614 | raid5_store_preread_threshold); |
| 4615 | |
| 4616 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4617 | stripe_cache_active_show(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4618 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4619 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4620 | if (conf) |
| 4621 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 4622 | else |
| 4623 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4624 | } |
| 4625 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4626 | static struct md_sysfs_entry |
| 4627 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4628 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4629 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4630 | &raid5_stripecache_size.attr, |
| 4631 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4632 | &raid5_preread_bypass_threshold.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4633 | NULL, |
| 4634 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4635 | static struct attribute_group raid5_attrs_group = { |
| 4636 | .name = NULL, |
| 4637 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4638 | }; |
| 4639 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4640 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4641 | raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4642 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4643 | struct r5conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4644 | |
| 4645 | if (!sectors) |
| 4646 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4647 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 4648 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4649 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4650 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4651 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4652 | sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4653 | return sectors * (raid_disks - conf->max_degraded); |
| 4654 | } |
| 4655 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4656 | static void raid5_free_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4657 | { |
| 4658 | struct raid5_percpu *percpu; |
| 4659 | unsigned long cpu; |
| 4660 | |
| 4661 | if (!conf->percpu) |
| 4662 | return; |
| 4663 | |
| 4664 | get_online_cpus(); |
| 4665 | for_each_possible_cpu(cpu) { |
| 4666 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4667 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4668 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4669 | } |
| 4670 | #ifdef CONFIG_HOTPLUG_CPU |
| 4671 | unregister_cpu_notifier(&conf->cpu_notify); |
| 4672 | #endif |
| 4673 | put_online_cpus(); |
| 4674 | |
| 4675 | free_percpu(conf->percpu); |
| 4676 | } |
| 4677 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4678 | static void free_conf(struct r5conf *conf) |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4679 | { |
| 4680 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4681 | raid5_free_percpu(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4682 | kfree(conf->disks); |
| 4683 | kfree(conf->stripe_hashtbl); |
| 4684 | kfree(conf); |
| 4685 | } |
| 4686 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4687 | #ifdef CONFIG_HOTPLUG_CPU |
| 4688 | static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, |
| 4689 | void *hcpu) |
| 4690 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4691 | struct r5conf *conf = container_of(nfb, struct r5conf, cpu_notify); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4692 | long cpu = (long)hcpu; |
| 4693 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4694 | |
| 4695 | switch (action) { |
| 4696 | case CPU_UP_PREPARE: |
| 4697 | case CPU_UP_PREPARE_FROZEN: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4698 | if (conf->level == 6 && !percpu->spare_page) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4699 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4700 | if (!percpu->scribble) |
| 4701 | percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
| 4702 | |
| 4703 | if (!percpu->scribble || |
| 4704 | (conf->level == 6 && !percpu->spare_page)) { |
| 4705 | safe_put_page(percpu->spare_page); |
| 4706 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4707 | pr_err("%s: failed memory allocation for cpu%ld\n", |
| 4708 | __func__, cpu); |
Akinobu Mita | 55af6bb | 2010-05-26 14:43:35 -0700 | [diff] [blame] | 4709 | return notifier_from_errno(-ENOMEM); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4710 | } |
| 4711 | break; |
| 4712 | case CPU_DEAD: |
| 4713 | case CPU_DEAD_FROZEN: |
| 4714 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4715 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4716 | percpu->spare_page = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4717 | percpu->scribble = NULL; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4718 | break; |
| 4719 | default: |
| 4720 | break; |
| 4721 | } |
| 4722 | return NOTIFY_OK; |
| 4723 | } |
| 4724 | #endif |
| 4725 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4726 | static int raid5_alloc_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4727 | { |
| 4728 | unsigned long cpu; |
| 4729 | struct page *spare_page; |
Tejun Heo | a29d8b8 | 2010-02-02 14:39:15 +0900 | [diff] [blame] | 4730 | struct raid5_percpu __percpu *allcpus; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4731 | void *scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4732 | int err; |
| 4733 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4734 | allcpus = alloc_percpu(struct raid5_percpu); |
| 4735 | if (!allcpus) |
| 4736 | return -ENOMEM; |
| 4737 | conf->percpu = allcpus; |
| 4738 | |
| 4739 | get_online_cpus(); |
| 4740 | err = 0; |
| 4741 | for_each_present_cpu(cpu) { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4742 | if (conf->level == 6) { |
| 4743 | spare_page = alloc_page(GFP_KERNEL); |
| 4744 | if (!spare_page) { |
| 4745 | err = -ENOMEM; |
| 4746 | break; |
| 4747 | } |
| 4748 | per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page; |
| 4749 | } |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4750 | scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4751 | if (!scribble) { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4752 | err = -ENOMEM; |
| 4753 | break; |
| 4754 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4755 | per_cpu_ptr(conf->percpu, cpu)->scribble = scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4756 | } |
| 4757 | #ifdef CONFIG_HOTPLUG_CPU |
| 4758 | conf->cpu_notify.notifier_call = raid456_cpu_notify; |
| 4759 | conf->cpu_notify.priority = 0; |
| 4760 | if (err == 0) |
| 4761 | err = register_cpu_notifier(&conf->cpu_notify); |
| 4762 | #endif |
| 4763 | put_online_cpus(); |
| 4764 | |
| 4765 | return err; |
| 4766 | } |
| 4767 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4768 | static struct r5conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4770 | struct r5conf *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4771 | int raid_disk, memory, max_disks; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4772 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | struct disk_info *disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4775 | if (mddev->new_level != 5 |
| 4776 | && mddev->new_level != 4 |
| 4777 | && mddev->new_level != 6) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4778 | 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] | 4779 | mdname(mddev), mddev->new_level); |
| 4780 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4782 | if ((mddev->new_level == 5 |
| 4783 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 4784 | (mddev->new_level == 6 |
| 4785 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4786 | printk(KERN_ERR "md/raid:%s: layout %d not supported\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4787 | mdname(mddev), mddev->new_layout); |
| 4788 | return ERR_PTR(-EIO); |
| 4789 | } |
| 4790 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4791 | 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] | 4792 | mdname(mddev), mddev->raid_disks); |
| 4793 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4796 | if (!mddev->new_chunk_sectors || |
| 4797 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 4798 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4799 | printk(KERN_ERR "md/raid:%s: invalid chunk size %d\n", |
| 4800 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4801 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4802 | } |
| 4803 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4804 | conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4805 | if (conf == NULL) |
| 4806 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 4807 | spin_lock_init(&conf->device_lock); |
| 4808 | init_waitqueue_head(&conf->wait_for_stripe); |
| 4809 | init_waitqueue_head(&conf->wait_for_overlap); |
| 4810 | INIT_LIST_HEAD(&conf->handle_list); |
| 4811 | INIT_LIST_HEAD(&conf->hold_list); |
| 4812 | INIT_LIST_HEAD(&conf->delayed_list); |
| 4813 | INIT_LIST_HEAD(&conf->bitmap_list); |
| 4814 | INIT_LIST_HEAD(&conf->inactive_list); |
| 4815 | atomic_set(&conf->active_stripes, 0); |
| 4816 | atomic_set(&conf->preread_active_stripes, 0); |
| 4817 | atomic_set(&conf->active_aligned_reads, 0); |
| 4818 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 4819 | conf->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4820 | |
| 4821 | conf->raid_disks = mddev->raid_disks; |
| 4822 | if (mddev->reshape_position == MaxSector) |
| 4823 | conf->previous_raid_disks = mddev->raid_disks; |
| 4824 | else |
| 4825 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4826 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
| 4827 | conf->scribble_len = scribble_len(max_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4828 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4829 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4830 | GFP_KERNEL); |
| 4831 | if (!conf->disks) |
| 4832 | goto abort; |
| 4833 | |
| 4834 | conf->mddev = mddev; |
| 4835 | |
| 4836 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 4837 | goto abort; |
| 4838 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4839 | conf->level = mddev->new_level; |
| 4840 | if (raid5_alloc_percpu(conf) != 0) |
| 4841 | goto abort; |
| 4842 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4843 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4844 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 4845 | rdev_for_each(rdev, mddev) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4846 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4847 | if (raid_disk >= max_disks |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4848 | || raid_disk < 0) |
| 4849 | continue; |
| 4850 | disk = conf->disks + raid_disk; |
| 4851 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4852 | if (test_bit(Replacement, &rdev->flags)) { |
| 4853 | if (disk->replacement) |
| 4854 | goto abort; |
| 4855 | disk->replacement = rdev; |
| 4856 | } else { |
| 4857 | if (disk->rdev) |
| 4858 | goto abort; |
| 4859 | disk->rdev = rdev; |
| 4860 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4861 | |
| 4862 | if (test_bit(In_sync, &rdev->flags)) { |
| 4863 | char b[BDEVNAME_SIZE]; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4864 | printk(KERN_INFO "md/raid:%s: device %s operational as raid" |
| 4865 | " disk %d\n", |
| 4866 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
Jonathan Brassow | d6b212f | 2011-06-08 18:00:28 -0500 | [diff] [blame] | 4867 | } else if (rdev->saved_raid_disk != raid_disk) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4868 | /* Cannot rely on bitmap to complete recovery */ |
| 4869 | conf->fullsync = 1; |
| 4870 | } |
| 4871 | |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4872 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4873 | conf->level = mddev->new_level; |
| 4874 | if (conf->level == 6) |
| 4875 | conf->max_degraded = 2; |
| 4876 | else |
| 4877 | conf->max_degraded = 1; |
| 4878 | conf->algorithm = mddev->new_layout; |
| 4879 | conf->max_nr_stripes = NR_STRIPES; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4880 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4881 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4882 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4883 | conf->prev_algo = mddev->layout; |
| 4884 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4885 | |
| 4886 | memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4887 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4888 | if (grow_stripes(conf, conf->max_nr_stripes)) { |
| 4889 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4890 | "md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 4891 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4892 | goto abort; |
| 4893 | } else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4894 | printk(KERN_INFO "md/raid:%s: allocated %dkB\n", |
| 4895 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4896 | |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 4897 | conf->thread = md_register_thread(raid5d, mddev, NULL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4898 | if (!conf->thread) { |
| 4899 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4900 | "md/raid:%s: couldn't allocate thread.\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4901 | mdname(mddev)); |
| 4902 | goto abort; |
| 4903 | } |
| 4904 | |
| 4905 | return conf; |
| 4906 | |
| 4907 | abort: |
| 4908 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4909 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4910 | return ERR_PTR(-EIO); |
| 4911 | } else |
| 4912 | return ERR_PTR(-ENOMEM); |
| 4913 | } |
| 4914 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4915 | |
| 4916 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 4917 | { |
| 4918 | switch (algo) { |
| 4919 | case ALGORITHM_PARITY_0: |
| 4920 | if (raid_disk < max_degraded) |
| 4921 | return 1; |
| 4922 | break; |
| 4923 | case ALGORITHM_PARITY_N: |
| 4924 | if (raid_disk >= raid_disks - max_degraded) |
| 4925 | return 1; |
| 4926 | break; |
| 4927 | case ALGORITHM_PARITY_0_6: |
| 4928 | if (raid_disk == 0 || |
| 4929 | raid_disk == raid_disks - 1) |
| 4930 | return 1; |
| 4931 | break; |
| 4932 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 4933 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 4934 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 4935 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 4936 | if (raid_disk == raid_disks - 1) |
| 4937 | return 1; |
| 4938 | } |
| 4939 | return 0; |
| 4940 | } |
| 4941 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4942 | static int run(struct mddev *mddev) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4943 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4944 | struct r5conf *conf; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 4945 | int working_disks = 0; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4946 | int dirty_parity_disks = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4947 | struct md_rdev *rdev; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4948 | sector_t reshape_offset = 0; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4949 | int i; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4950 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4951 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4952 | printk(KERN_NOTICE "md/raid:%s: not clean" |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4953 | " -- starting background reconstruction\n", |
| 4954 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4955 | if (mddev->reshape_position != MaxSector) { |
| 4956 | /* Check that we can continue the reshape. |
| 4957 | * Currently only disks can change, it must |
| 4958 | * increase, and we must be past the point where |
| 4959 | * a stripe over-writes itself |
| 4960 | */ |
| 4961 | sector_t here_new, here_old; |
| 4962 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 4963 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4964 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 4965 | if (mddev->new_level != mddev->level) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4966 | printk(KERN_ERR "md/raid:%s: unsupported reshape " |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4967 | "required - aborting.\n", |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4968 | mdname(mddev)); |
| 4969 | return -EINVAL; |
| 4970 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4971 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 4972 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4973 | * further up in new geometry must map after here in old |
| 4974 | * geometry. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4975 | */ |
| 4976 | here_new = mddev->reshape_position; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4977 | if (sector_div(here_new, mddev->new_chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4978 | (mddev->raid_disks - max_degraded))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4979 | printk(KERN_ERR "md/raid:%s: reshape_position not " |
| 4980 | "on a stripe boundary\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4981 | return -EINVAL; |
| 4982 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4983 | reshape_offset = here_new * mddev->new_chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4984 | /* here_new is the stripe we will write to */ |
| 4985 | here_old = mddev->reshape_position; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4986 | sector_div(here_old, mddev->chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4987 | (old_disks-max_degraded)); |
| 4988 | /* here_old is the first stripe that we might need to read |
| 4989 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 4990 | if (mddev->delta_disks == 0) { |
| 4991 | /* We cannot be sure it is safe to start an in-place |
| 4992 | * reshape. It is only safe if user-space if monitoring |
| 4993 | * and taking constant backups. |
| 4994 | * mdadm always starts a situation like this in |
| 4995 | * readonly mode so it can take control before |
| 4996 | * allowing any writes. So just check for that. |
| 4997 | */ |
| 4998 | if ((here_new * mddev->new_chunk_sectors != |
| 4999 | here_old * mddev->chunk_sectors) || |
| 5000 | mddev->ro == 0) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5001 | printk(KERN_ERR "md/raid:%s: in-place reshape must be started" |
| 5002 | " in read-only mode - aborting\n", |
| 5003 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 5004 | return -EINVAL; |
| 5005 | } |
| 5006 | } else if (mddev->delta_disks < 0 |
| 5007 | ? (here_new * mddev->new_chunk_sectors <= |
| 5008 | here_old * mddev->chunk_sectors) |
| 5009 | : (here_new * mddev->new_chunk_sectors >= |
| 5010 | here_old * mddev->chunk_sectors)) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5011 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5012 | printk(KERN_ERR "md/raid:%s: reshape_position too early for " |
| 5013 | "auto-recovery - aborting.\n", |
| 5014 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5015 | return -EINVAL; |
| 5016 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5017 | printk(KERN_INFO "md/raid:%s: reshape will continue\n", |
| 5018 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5019 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5020 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5021 | BUG_ON(mddev->level != mddev->new_level); |
| 5022 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5023 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5024 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5025 | } |
| 5026 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5027 | if (mddev->private == NULL) |
| 5028 | conf = setup_conf(mddev); |
| 5029 | else |
| 5030 | conf = mddev->private; |
| 5031 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5032 | if (IS_ERR(conf)) |
| 5033 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 5034 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5035 | mddev->thread = conf->thread; |
| 5036 | conf->thread = NULL; |
| 5037 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5039 | for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; |
| 5040 | i++) { |
| 5041 | rdev = conf->disks[i].rdev; |
| 5042 | if (!rdev && conf->disks[i].replacement) { |
| 5043 | /* The replacement is all we have yet */ |
| 5044 | rdev = conf->disks[i].replacement; |
| 5045 | conf->disks[i].replacement = NULL; |
| 5046 | clear_bit(Replacement, &rdev->flags); |
| 5047 | conf->disks[i].rdev = rdev; |
| 5048 | } |
| 5049 | if (!rdev) |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5050 | continue; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5051 | if (conf->disks[i].replacement && |
| 5052 | conf->reshape_progress != MaxSector) { |
| 5053 | /* replacements and reshape simply do not mix. */ |
| 5054 | printk(KERN_ERR "md: cannot handle concurrent " |
| 5055 | "replacement and reshape.\n"); |
| 5056 | goto abort; |
| 5057 | } |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 5058 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5059 | working_disks++; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 5060 | continue; |
| 5061 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5062 | /* This disc is not fully in-sync. However if it |
| 5063 | * just stored parity (beyond the recovery_offset), |
| 5064 | * when we don't need to be concerned about the |
| 5065 | * array being dirty. |
| 5066 | * When reshape goes 'backwards', we never have |
| 5067 | * partially completed devices, so we only need |
| 5068 | * to worry about reshape going forwards. |
| 5069 | */ |
| 5070 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 5071 | if (mddev->major_version == 0 && |
| 5072 | mddev->minor_version > 90) |
| 5073 | rdev->recovery_offset = reshape_offset; |
| 5074 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5075 | if (rdev->recovery_offset < reshape_offset) { |
| 5076 | /* We need to check old and new layout */ |
| 5077 | if (!only_parity(rdev->raid_disk, |
| 5078 | conf->algorithm, |
| 5079 | conf->raid_disks, |
| 5080 | conf->max_degraded)) |
| 5081 | continue; |
| 5082 | } |
| 5083 | if (!only_parity(rdev->raid_disk, |
| 5084 | conf->prev_algo, |
| 5085 | conf->previous_raid_disks, |
| 5086 | conf->max_degraded)) |
| 5087 | continue; |
| 5088 | dirty_parity_disks++; |
| 5089 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5090 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5091 | /* |
| 5092 | * 0 for a fully functional array, 1 or 2 for a degraded array. |
| 5093 | */ |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5094 | mddev->degraded = calc_degraded(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5096 | if (has_failed(conf)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5097 | printk(KERN_ERR "md/raid:%s: not enough operational devices" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | " (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5099 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | goto abort; |
| 5101 | } |
| 5102 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5103 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5104 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5105 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 5106 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5107 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5109 | if (mddev->ok_start_degraded) |
| 5110 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5111 | "md/raid:%s: starting dirty degraded array" |
| 5112 | " - data corruption possible.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5113 | mdname(mddev)); |
| 5114 | else { |
| 5115 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5116 | "md/raid:%s: cannot start dirty degraded array.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5117 | mdname(mddev)); |
| 5118 | goto abort; |
| 5119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | if (mddev->degraded == 0) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5123 | printk(KERN_INFO "md/raid:%s: raid level %d active with %d out of %d" |
| 5124 | " devices, algorithm %d\n", mdname(mddev), conf->level, |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5125 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 5126 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5128 | printk(KERN_ALERT "md/raid:%s: raid level %d active with %d" |
| 5129 | " out of %d devices, algorithm %d\n", |
| 5130 | mdname(mddev), conf->level, |
| 5131 | mddev->raid_disks - mddev->degraded, |
| 5132 | mddev->raid_disks, mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | |
| 5134 | print_raid5_conf(conf); |
| 5135 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5136 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5137 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5138 | atomic_set(&conf->reshape_stripes, 0); |
| 5139 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5140 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5141 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5142 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5143 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5144 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5145 | } |
| 5146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | |
| 5148 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5149 | if (mddev->to_remove == &raid5_attrs_group) |
| 5150 | mddev->to_remove = NULL; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 5151 | else if (mddev->kobj.sd && |
| 5152 | sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5153 | printk(KERN_WARNING |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5154 | "raid5: failed to create sysfs attributes for %s\n", |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5155 | mdname(mddev)); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5156 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5157 | |
| 5158 | if (mddev->queue) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5159 | int chunk_size; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5160 | /* read-ahead size must cover two whole stripes, which |
| 5161 | * is 2 * (datadisks) * chunksize where 'n' is the |
| 5162 | * number of raid devices |
| 5163 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 5165 | int stripe = data_disks * |
| 5166 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
| 5167 | if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5168 | mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5169 | |
| 5170 | blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 5171 | |
| 5172 | mddev->queue->backing_dev_info.congested_data = mddev; |
| 5173 | mddev->queue->backing_dev_info.congested_fn = raid5_congested; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5174 | |
| 5175 | chunk_size = mddev->chunk_sectors << 9; |
| 5176 | blk_queue_io_min(mddev->queue, chunk_size); |
| 5177 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 5178 | (conf->raid_disks - conf->max_degraded)); |
| 5179 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 5180 | rdev_for_each(rdev, mddev) |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 5181 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5182 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | return 0; |
| 5186 | abort: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 5187 | md_unregister_thread(&mddev->thread); |
NeilBrown | e4f869d | 2011-10-07 14:22:49 +1100 | [diff] [blame] | 5188 | print_raid5_conf(conf); |
| 5189 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | mddev->private = NULL; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5191 | 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] | 5192 | return -EIO; |
| 5193 | } |
| 5194 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5195 | static int stop(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5197 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 5199 | md_unregister_thread(&mddev->thread); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 5200 | if (mddev->queue) |
| 5201 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5202 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5203 | mddev->private = NULL; |
| 5204 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | return 0; |
| 5206 | } |
| 5207 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5208 | static void status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5210 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | int i; |
| 5212 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5213 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
| 5214 | mddev->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5215 | 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] | 5216 | for (i = 0; i < conf->raid_disks; i++) |
| 5217 | seq_printf (seq, "%s", |
| 5218 | conf->disks[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5219 | test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | seq_printf (seq, "]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5223 | static void print_raid5_conf (struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | { |
| 5225 | int i; |
| 5226 | struct disk_info *tmp; |
| 5227 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5228 | printk(KERN_DEBUG "RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | if (!conf) { |
| 5230 | printk("(conf==NULL)\n"); |
| 5231 | return; |
| 5232 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5233 | printk(KERN_DEBUG " --- level:%d rd:%d wd:%d\n", conf->level, |
| 5234 | conf->raid_disks, |
| 5235 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | |
| 5237 | for (i = 0; i < conf->raid_disks; i++) { |
| 5238 | char b[BDEVNAME_SIZE]; |
| 5239 | tmp = conf->disks + i; |
| 5240 | if (tmp->rdev) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5241 | printk(KERN_DEBUG " disk %d, o:%d, dev:%s\n", |
| 5242 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 5243 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5244 | } |
| 5245 | } |
| 5246 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5247 | static int raid5_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | { |
| 5249 | int i; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5250 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | struct disk_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5252 | int count = 0; |
| 5253 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | |
| 5255 | for (i = 0; i < conf->raid_disks; i++) { |
| 5256 | tmp = conf->disks + i; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5257 | if (tmp->replacement |
| 5258 | && tmp->replacement->recovery_offset == MaxSector |
| 5259 | && !test_bit(Faulty, &tmp->replacement->flags) |
| 5260 | && !test_and_set_bit(In_sync, &tmp->replacement->flags)) { |
| 5261 | /* Replacement has just become active. */ |
| 5262 | if (!tmp->rdev |
| 5263 | || !test_and_clear_bit(In_sync, &tmp->rdev->flags)) |
| 5264 | count++; |
| 5265 | if (tmp->rdev) { |
| 5266 | /* Replaced device not technically faulty, |
| 5267 | * but we need to be sure it gets removed |
| 5268 | * and never re-added. |
| 5269 | */ |
| 5270 | set_bit(Faulty, &tmp->rdev->flags); |
| 5271 | sysfs_notify_dirent_safe( |
| 5272 | tmp->rdev->sysfs_state); |
| 5273 | } |
| 5274 | sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); |
| 5275 | } else if (tmp->rdev |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 5276 | && tmp->rdev->recovery_offset == MaxSector |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5277 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5278 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5279 | count++; |
Jonathan Brassow | 43c73ca | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 5280 | sysfs_notify_dirent_safe(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | } |
| 5282 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5283 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5284 | mddev->degraded = calc_degraded(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5285 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | print_raid5_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5287 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5288 | } |
| 5289 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 5290 | static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5292 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 5294 | int number = rdev->raid_disk; |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5295 | struct md_rdev **rdevp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | struct disk_info *p = conf->disks + number; |
| 5297 | |
| 5298 | print_raid5_conf(conf); |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5299 | if (rdev == p->rdev) |
| 5300 | rdevp = &p->rdev; |
| 5301 | else if (rdev == p->replacement) |
| 5302 | rdevp = &p->replacement; |
| 5303 | else |
| 5304 | return 0; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5305 | |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5306 | if (number >= conf->raid_disks && |
| 5307 | conf->reshape_progress == MaxSector) |
| 5308 | clear_bit(In_sync, &rdev->flags); |
| 5309 | |
| 5310 | if (test_bit(In_sync, &rdev->flags) || |
| 5311 | atomic_read(&rdev->nr_pending)) { |
| 5312 | err = -EBUSY; |
| 5313 | goto abort; |
| 5314 | } |
| 5315 | /* Only remove non-faulty devices if recovery |
| 5316 | * isn't possible. |
| 5317 | */ |
| 5318 | if (!test_bit(Faulty, &rdev->flags) && |
| 5319 | mddev->recovery_disabled != conf->recovery_disabled && |
| 5320 | !has_failed(conf) && |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5321 | (!p->replacement || p->replacement == rdev) && |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5322 | number < conf->raid_disks) { |
| 5323 | err = -EBUSY; |
| 5324 | goto abort; |
| 5325 | } |
| 5326 | *rdevp = NULL; |
| 5327 | synchronize_rcu(); |
| 5328 | if (atomic_read(&rdev->nr_pending)) { |
| 5329 | /* lost the race, try later */ |
| 5330 | err = -EBUSY; |
| 5331 | *rdevp = rdev; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5332 | } else if (p->replacement) { |
| 5333 | /* We must have just cleared 'rdev' */ |
| 5334 | p->rdev = p->replacement; |
| 5335 | clear_bit(Replacement, &p->replacement->flags); |
| 5336 | smp_mb(); /* Make sure other CPUs may see both as identical |
| 5337 | * but will never see neither - if they are careful |
| 5338 | */ |
| 5339 | p->replacement = NULL; |
| 5340 | clear_bit(WantReplacement, &rdev->flags); |
| 5341 | } else |
| 5342 | /* We might have just removed the Replacement as faulty- |
| 5343 | * clear the bit just in case |
| 5344 | */ |
| 5345 | clear_bit(WantReplacement, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | abort: |
| 5347 | |
| 5348 | print_raid5_conf(conf); |
| 5349 | return err; |
| 5350 | } |
| 5351 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5352 | static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5353 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5354 | struct r5conf *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5355 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | int disk; |
| 5357 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5358 | int first = 0; |
| 5359 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5361 | if (mddev->recovery_disabled == conf->recovery_disabled) |
| 5362 | return -EBUSY; |
| 5363 | |
NeilBrown | dc10c64 | 2012-03-19 12:46:37 +1100 | [diff] [blame] | 5364 | if (rdev->saved_raid_disk < 0 && has_failed(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5366 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5367 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5368 | if (rdev->raid_disk >= 0) |
| 5369 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | |
| 5371 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5372 | * find the disk ... but prefer rdev->saved_raid_disk |
| 5373 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5375 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5376 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5377 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
| 5378 | disk = rdev->saved_raid_disk; |
| 5379 | else |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5380 | disk = first; |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5381 | for ( ; disk <= last ; disk++) { |
| 5382 | p = conf->disks + disk; |
| 5383 | if (p->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5384 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5386 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5387 | if (rdev->saved_raid_disk != disk) |
| 5388 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 5389 | rcu_assign_pointer(p->rdev, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | break; |
| 5391 | } |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5392 | if (test_bit(WantReplacement, &p->rdev->flags) && |
| 5393 | p->replacement == NULL) { |
| 5394 | clear_bit(In_sync, &rdev->flags); |
| 5395 | set_bit(Replacement, &rdev->flags); |
| 5396 | rdev->raid_disk = disk; |
| 5397 | err = 0; |
| 5398 | conf->fullsync = 1; |
| 5399 | rcu_assign_pointer(p->replacement, rdev); |
| 5400 | break; |
| 5401 | } |
| 5402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5403 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5404 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | } |
| 5406 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5407 | static int raid5_resize(struct mddev *mddev, sector_t sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | { |
| 5409 | /* no resync is happening, and there is enough space |
| 5410 | * on all devices, so we can resize. |
| 5411 | * We need to make sure resync covers any new space. |
| 5412 | * If the array is shrinking we should possibly wait until |
| 5413 | * any io in the removed space completes, but it hardly seems |
| 5414 | * worth it. |
| 5415 | */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5416 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5417 | md_set_array_sectors(mddev, raid5_size(mddev, sectors, |
| 5418 | mddev->raid_disks)); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5419 | if (mddev->array_sectors > |
| 5420 | raid5_size(mddev, sectors, mddev->raid_disks)) |
| 5421 | return -EINVAL; |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 5422 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5423 | revalidate_disk(mddev->gendisk); |
NeilBrown | b098636 | 2011-05-11 15:52:21 +1000 | [diff] [blame] | 5424 | if (sectors > mddev->dev_sectors && |
| 5425 | mddev->recovery_cp > mddev->dev_sectors) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5426 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5428 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5429 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 5430 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5431 | return 0; |
| 5432 | } |
| 5433 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5434 | static int check_stripe_cache(struct mddev *mddev) |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5435 | { |
| 5436 | /* Can only proceed if there are plenty of stripe_heads. |
| 5437 | * We need a minimum of one full stripe,, and for sensible progress |
| 5438 | * it is best to have about 4 times that. |
| 5439 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 5440 | * allow for chunk sizes up to 256K, which is probably OK. |
| 5441 | * If the chunk size is greater, user-space should request more |
| 5442 | * stripe_heads first. |
| 5443 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5444 | struct r5conf *conf = mddev->private; |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5445 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5446 | > conf->max_nr_stripes || |
| 5447 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5448 | > conf->max_nr_stripes) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5449 | printk(KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 5450 | mdname(mddev), |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5451 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 5452 | / STRIPE_SIZE)*4); |
| 5453 | return 0; |
| 5454 | } |
| 5455 | return 1; |
| 5456 | } |
| 5457 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5458 | static int check_reshape(struct mddev *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5459 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5460 | struct r5conf *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5461 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5462 | if (mddev->delta_disks == 0 && |
| 5463 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5464 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5465 | return 0; /* nothing to do */ |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5466 | if (mddev->bitmap) |
| 5467 | /* Cannot grow a bitmap yet */ |
| 5468 | return -EBUSY; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5469 | if (has_failed(conf)) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5470 | return -EINVAL; |
| 5471 | if (mddev->delta_disks < 0) { |
| 5472 | /* We might be able to shrink, but the devices must |
| 5473 | * be made bigger first. |
| 5474 | * For raid6, 4 is the minimum size. |
| 5475 | * Otherwise 2 is the minimum |
| 5476 | */ |
| 5477 | int min = 2; |
| 5478 | if (mddev->level == 6) |
| 5479 | min = 4; |
| 5480 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 5481 | return -EINVAL; |
| 5482 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5483 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5484 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5485 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5486 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5487 | return resize_stripes(conf, conf->raid_disks + mddev->delta_disks); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5490 | static int raid5_start_reshape(struct mddev *mddev) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5491 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5492 | struct r5conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5493 | struct md_rdev *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5494 | int spares = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5495 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5496 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5497 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5498 | return -EBUSY; |
| 5499 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5500 | if (!check_stripe_cache(mddev)) |
| 5501 | return -ENOSPC; |
| 5502 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 5503 | rdev_for_each(rdev, mddev) |
NeilBrown | 469518a | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5504 | if (!test_bit(In_sync, &rdev->flags) |
| 5505 | && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5506 | spares++; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5507 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5508 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5509 | /* Not enough devices even to make a degraded array |
| 5510 | * of that size |
| 5511 | */ |
| 5512 | return -EINVAL; |
| 5513 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5514 | /* Refuse to reduce size of the array. Any reductions in |
| 5515 | * array size must be through explicit setting of array_size |
| 5516 | * attribute. |
| 5517 | */ |
| 5518 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 5519 | < mddev->array_sectors) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5520 | printk(KERN_ERR "md/raid:%s: array size must be reduced " |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5521 | "before number of disks\n", mdname(mddev)); |
| 5522 | return -EINVAL; |
| 5523 | } |
| 5524 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5525 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5526 | spin_lock_irq(&conf->device_lock); |
| 5527 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5528 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5529 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 5530 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5531 | conf->prev_algo = conf->algorithm; |
| 5532 | conf->algorithm = mddev->new_layout; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5533 | if (mddev->delta_disks < 0) |
| 5534 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 5535 | else |
| 5536 | conf->reshape_progress = 0; |
| 5537 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 5538 | conf->generation++; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5539 | spin_unlock_irq(&conf->device_lock); |
| 5540 | |
| 5541 | /* Add some new drives, as many as will fit. |
| 5542 | * We know there are enough to make the newly sized array work. |
NeilBrown | 3424bf6 | 2010-06-17 17:48:26 +1000 | [diff] [blame] | 5543 | * Don't add devices if we are reducing the number of |
| 5544 | * devices in the array. This is because it is not possible |
| 5545 | * to correctly record the "partially reconstructed" state of |
| 5546 | * such devices during the reshape and confusion could result. |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5547 | */ |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5548 | if (mddev->delta_disks >= 0) { |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 5549 | rdev_for_each(rdev, mddev) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5550 | if (rdev->raid_disk < 0 && |
| 5551 | !test_bit(Faulty, &rdev->flags)) { |
| 5552 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5553 | if (rdev->raid_disk |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 5554 | >= conf->previous_raid_disks) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5555 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 5556 | else |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5557 | rdev->recovery_offset = 0; |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5558 | |
| 5559 | if (sysfs_link_rdev(mddev, rdev)) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5560 | /* Failure here is OK */; |
NeilBrown | 50da084 | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5561 | } |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5562 | } else if (rdev->raid_disk >= conf->previous_raid_disks |
| 5563 | && !test_bit(Faulty, &rdev->flags)) { |
| 5564 | /* This is a spare that was manually added */ |
| 5565 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5566 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5567 | |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5568 | /* When a reshape changes the number of devices, |
| 5569 | * ->degraded is measured against the larger of the |
| 5570 | * pre and post number of devices. |
| 5571 | */ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5572 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5573 | mddev->degraded = calc_degraded(conf); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5574 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 5575 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5576 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 5577 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5578 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5579 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5580 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5581 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5582 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5583 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5584 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5585 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5586 | if (!mddev->sync_thread) { |
| 5587 | mddev->recovery = 0; |
| 5588 | spin_lock_irq(&conf->device_lock); |
| 5589 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5590 | conf->reshape_progress = MaxSector; |
NeilBrown | 1e3fa9b | 2012-03-13 11:21:18 +1100 | [diff] [blame] | 5591 | mddev->reshape_position = MaxSector; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5592 | spin_unlock_irq(&conf->device_lock); |
| 5593 | return -EAGAIN; |
| 5594 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5595 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5596 | md_wakeup_thread(mddev->sync_thread); |
| 5597 | md_new_event(mddev); |
| 5598 | return 0; |
| 5599 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5600 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5601 | /* This is called from the reshape thread and should make any |
| 5602 | * changes needed in 'conf' |
| 5603 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5604 | static void end_reshape(struct r5conf *conf) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5605 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5606 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5607 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5608 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5609 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5610 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5611 | conf->reshape_progress = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5612 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5613 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5614 | |
| 5615 | /* read-ahead size must cover two whole stripes, which is |
| 5616 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 5617 | */ |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5618 | if (conf->mddev->queue) { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5619 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5620 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5621 | / PAGE_SIZE); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5622 | if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5623 | conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 5624 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5625 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5626 | } |
| 5627 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5628 | /* This is called from the raid5d thread with mddev_lock held. |
| 5629 | * It makes config changes to the device. |
| 5630 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5631 | static void raid5_finish_reshape(struct mddev *mddev) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5632 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5633 | struct r5conf *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5634 | |
| 5635 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5636 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5637 | if (mddev->delta_disks > 0) { |
| 5638 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5639 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5640 | revalidate_disk(mddev->gendisk); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5641 | } else { |
| 5642 | int d; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 5643 | spin_lock_irq(&conf->device_lock); |
| 5644 | mddev->degraded = calc_degraded(conf); |
| 5645 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5646 | for (d = conf->raid_disks ; |
| 5647 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5648 | d++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5649 | struct md_rdev *rdev = conf->disks[d].rdev; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 5650 | if (rdev && |
| 5651 | raid5_remove_disk(mddev, rdev) == 0) { |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5652 | sysfs_unlink_rdev(mddev, rdev); |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5653 | rdev->raid_disk = -1; |
| 5654 | } |
| 5655 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5656 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5657 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5658 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5659 | mddev->reshape_position = MaxSector; |
| 5660 | mddev->delta_disks = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5661 | } |
| 5662 | } |
| 5663 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5664 | static void raid5_quiesce(struct mddev *mddev, int state) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5665 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5666 | struct r5conf *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5667 | |
| 5668 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5669 | case 2: /* resume for a suspend */ |
| 5670 | wake_up(&conf->wait_for_overlap); |
| 5671 | break; |
| 5672 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5673 | case 1: /* stop all writes */ |
| 5674 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5675 | /* '2' tells resync/reshape to pause so that all |
| 5676 | * active stripes can drain |
| 5677 | */ |
| 5678 | conf->quiesce = 2; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5679 | wait_event_lock_irq(conf->wait_for_stripe, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5680 | atomic_read(&conf->active_stripes) == 0 && |
| 5681 | atomic_read(&conf->active_aligned_reads) == 0, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5682 | conf->device_lock, /* nothing */); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5683 | conf->quiesce = 1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5684 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5685 | /* allow reshape to continue */ |
| 5686 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5687 | break; |
| 5688 | |
| 5689 | case 0: /* re-enable writes */ |
| 5690 | spin_lock_irq(&conf->device_lock); |
| 5691 | conf->quiesce = 0; |
| 5692 | wake_up(&conf->wait_for_stripe); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5693 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5694 | spin_unlock_irq(&conf->device_lock); |
| 5695 | break; |
| 5696 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5697 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 5698 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5699 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5700 | static void *raid45_takeover_raid0(struct mddev *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5701 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 5702 | struct r0conf *raid0_conf = mddev->private; |
Randy Dunlap | d76c842 | 2011-04-21 09:07:26 -0700 | [diff] [blame] | 5703 | sector_t sectors; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5704 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5705 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 5706 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5707 | printk(KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 5708 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5709 | return ERR_PTR(-EINVAL); |
| 5710 | } |
| 5711 | |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 5712 | sectors = raid0_conf->strip_zone[0].zone_end; |
| 5713 | sector_div(sectors, raid0_conf->strip_zone[0].nb_dev); |
NeilBrown | 3b71bd9 | 2011-04-20 15:38:18 +1000 | [diff] [blame] | 5714 | mddev->dev_sectors = sectors; |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5715 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5716 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5717 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 5718 | mddev->raid_disks += 1; |
| 5719 | mddev->delta_disks = 1; |
| 5720 | /* make sure it will be not marked as dirty */ |
| 5721 | mddev->recovery_cp = MaxSector; |
| 5722 | |
| 5723 | return setup_conf(mddev); |
| 5724 | } |
| 5725 | |
| 5726 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5727 | static void *raid5_takeover_raid1(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5728 | { |
| 5729 | int chunksect; |
| 5730 | |
| 5731 | if (mddev->raid_disks != 2 || |
| 5732 | mddev->degraded > 1) |
| 5733 | return ERR_PTR(-EINVAL); |
| 5734 | |
| 5735 | /* Should check if there are write-behind devices? */ |
| 5736 | |
| 5737 | chunksect = 64*2; /* 64K by default */ |
| 5738 | |
| 5739 | /* The array must be an exact multiple of chunksize */ |
| 5740 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 5741 | chunksect >>= 1; |
| 5742 | |
| 5743 | if ((chunksect<<9) < STRIPE_SIZE) |
| 5744 | /* array size does not allow a suitable chunk size */ |
| 5745 | return ERR_PTR(-EINVAL); |
| 5746 | |
| 5747 | mddev->new_level = 5; |
| 5748 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5749 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5750 | |
| 5751 | return setup_conf(mddev); |
| 5752 | } |
| 5753 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5754 | static void *raid5_takeover_raid6(struct mddev *mddev) |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5755 | { |
| 5756 | int new_layout; |
| 5757 | |
| 5758 | switch (mddev->layout) { |
| 5759 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 5760 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 5761 | break; |
| 5762 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 5763 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 5764 | break; |
| 5765 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 5766 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 5767 | break; |
| 5768 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 5769 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 5770 | break; |
| 5771 | case ALGORITHM_PARITY_0_6: |
| 5772 | new_layout = ALGORITHM_PARITY_0; |
| 5773 | break; |
| 5774 | case ALGORITHM_PARITY_N: |
| 5775 | new_layout = ALGORITHM_PARITY_N; |
| 5776 | break; |
| 5777 | default: |
| 5778 | return ERR_PTR(-EINVAL); |
| 5779 | } |
| 5780 | mddev->new_level = 5; |
| 5781 | mddev->new_layout = new_layout; |
| 5782 | mddev->delta_disks = -1; |
| 5783 | mddev->raid_disks -= 1; |
| 5784 | return setup_conf(mddev); |
| 5785 | } |
| 5786 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5787 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5788 | static int raid5_check_reshape(struct mddev *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5789 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5790 | /* For a 2-drive array, the layout and chunk size can be changed |
| 5791 | * immediately as not restriping is needed. |
| 5792 | * For larger arrays we record the new value - after validation |
| 5793 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5794 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5795 | struct r5conf *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5796 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5797 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5798 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5799 | return -EINVAL; |
| 5800 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5801 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5802 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5803 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5804 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5805 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5806 | /* not factor of array size */ |
| 5807 | return -EINVAL; |
| 5808 | } |
| 5809 | |
| 5810 | /* They look valid */ |
| 5811 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5812 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5813 | /* can make the change immediately */ |
| 5814 | if (mddev->new_layout >= 0) { |
| 5815 | conf->algorithm = mddev->new_layout; |
| 5816 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5817 | } |
| 5818 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5819 | conf->chunk_sectors = new_chunk ; |
| 5820 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5821 | } |
| 5822 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 5823 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5824 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5825 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5826 | } |
| 5827 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5828 | static int raid6_check_reshape(struct mddev *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5829 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5830 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5831 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5832 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5833 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5834 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5835 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5836 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5837 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5838 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5839 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5840 | /* not factor of array size */ |
| 5841 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5842 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5843 | |
| 5844 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5845 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5846 | } |
| 5847 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5848 | static void *raid5_takeover(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5849 | { |
| 5850 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5851 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5852 | * raid1 - if there are two drives. We need to know the chunk size |
| 5853 | * raid4 - trivial - just use a raid4 layout. |
| 5854 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5855 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5856 | if (mddev->level == 0) |
| 5857 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5858 | if (mddev->level == 1) |
| 5859 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 5860 | if (mddev->level == 4) { |
| 5861 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5862 | mddev->new_level = 5; |
| 5863 | return setup_conf(mddev); |
| 5864 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5865 | if (mddev->level == 6) |
| 5866 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5867 | |
| 5868 | return ERR_PTR(-EINVAL); |
| 5869 | } |
| 5870 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5871 | static void *raid4_takeover(struct mddev *mddev) |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5872 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5873 | /* raid4 can take over: |
| 5874 | * raid0 - if there is only one strip zone |
| 5875 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5876 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5877 | if (mddev->level == 0) |
| 5878 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5879 | if (mddev->level == 5 && |
| 5880 | mddev->layout == ALGORITHM_PARITY_N) { |
| 5881 | mddev->new_layout = 0; |
| 5882 | mddev->new_level = 4; |
| 5883 | return setup_conf(mddev); |
| 5884 | } |
| 5885 | return ERR_PTR(-EINVAL); |
| 5886 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5887 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5888 | static struct md_personality raid5_personality; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5889 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5890 | static void *raid6_takeover(struct mddev *mddev) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5891 | { |
| 5892 | /* Currently can only take over a raid5. We map the |
| 5893 | * personality to an equivalent raid6 personality |
| 5894 | * with the Q block at the end. |
| 5895 | */ |
| 5896 | int new_layout; |
| 5897 | |
| 5898 | if (mddev->pers != &raid5_personality) |
| 5899 | return ERR_PTR(-EINVAL); |
| 5900 | if (mddev->degraded > 1) |
| 5901 | return ERR_PTR(-EINVAL); |
| 5902 | if (mddev->raid_disks > 253) |
| 5903 | return ERR_PTR(-EINVAL); |
| 5904 | if (mddev->raid_disks < 3) |
| 5905 | return ERR_PTR(-EINVAL); |
| 5906 | |
| 5907 | switch (mddev->layout) { |
| 5908 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 5909 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 5910 | break; |
| 5911 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 5912 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 5913 | break; |
| 5914 | case ALGORITHM_LEFT_SYMMETRIC: |
| 5915 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 5916 | break; |
| 5917 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 5918 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 5919 | break; |
| 5920 | case ALGORITHM_PARITY_0: |
| 5921 | new_layout = ALGORITHM_PARITY_0_6; |
| 5922 | break; |
| 5923 | case ALGORITHM_PARITY_N: |
| 5924 | new_layout = ALGORITHM_PARITY_N; |
| 5925 | break; |
| 5926 | default: |
| 5927 | return ERR_PTR(-EINVAL); |
| 5928 | } |
| 5929 | mddev->new_level = 6; |
| 5930 | mddev->new_layout = new_layout; |
| 5931 | mddev->delta_disks = 1; |
| 5932 | mddev->raid_disks += 1; |
| 5933 | return setup_conf(mddev); |
| 5934 | } |
| 5935 | |
| 5936 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5937 | static struct md_personality raid6_personality = |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5938 | { |
| 5939 | .name = "raid6", |
| 5940 | .level = 6, |
| 5941 | .owner = THIS_MODULE, |
| 5942 | .make_request = make_request, |
| 5943 | .run = run, |
| 5944 | .stop = stop, |
| 5945 | .status = status, |
| 5946 | .error_handler = error, |
| 5947 | .hot_add_disk = raid5_add_disk, |
| 5948 | .hot_remove_disk= raid5_remove_disk, |
| 5949 | .spare_active = raid5_spare_active, |
| 5950 | .sync_request = sync_request, |
| 5951 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5952 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5953 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5954 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5955 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5956 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5957 | .takeover = raid6_takeover, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5958 | }; |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5959 | static struct md_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | { |
| 5961 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5962 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | .owner = THIS_MODULE, |
| 5964 | .make_request = make_request, |
| 5965 | .run = run, |
| 5966 | .stop = stop, |
| 5967 | .status = status, |
| 5968 | .error_handler = error, |
| 5969 | .hot_add_disk = raid5_add_disk, |
| 5970 | .hot_remove_disk= raid5_remove_disk, |
| 5971 | .spare_active = raid5_spare_active, |
| 5972 | .sync_request = sync_request, |
| 5973 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5974 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5975 | .check_reshape = raid5_check_reshape, |
| 5976 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5977 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5978 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5979 | .takeover = raid5_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5980 | }; |
| 5981 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5982 | static struct md_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5983 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5984 | .name = "raid4", |
| 5985 | .level = 4, |
| 5986 | .owner = THIS_MODULE, |
| 5987 | .make_request = make_request, |
| 5988 | .run = run, |
| 5989 | .stop = stop, |
| 5990 | .status = status, |
| 5991 | .error_handler = error, |
| 5992 | .hot_add_disk = raid5_add_disk, |
| 5993 | .hot_remove_disk= raid5_remove_disk, |
| 5994 | .spare_active = raid5_spare_active, |
| 5995 | .sync_request = sync_request, |
| 5996 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5997 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 5998 | .check_reshape = raid5_check_reshape, |
| 5999 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6000 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6001 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 6002 | .takeover = raid4_takeover, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6003 | }; |
| 6004 | |
| 6005 | static int __init raid5_init(void) |
| 6006 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6007 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6008 | register_md_personality(&raid5_personality); |
| 6009 | register_md_personality(&raid4_personality); |
| 6010 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6013 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6015 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6016 | unregister_md_personality(&raid5_personality); |
| 6017 | unregister_md_personality(&raid4_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | } |
| 6019 | |
| 6020 | module_init(raid5_init); |
| 6021 | module_exit(raid5_exit); |
| 6022 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 6023 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6024 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 6025 | MODULE_ALIAS("md-raid5"); |
| 6026 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 6027 | MODULE_ALIAS("md-level-5"); |
| 6028 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6029 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 6030 | MODULE_ALIAS("md-raid6"); |
| 6031 | MODULE_ALIAS("md-level-6"); |
| 6032 | |
| 6033 | /* This used to be two separate modules, they were: */ |
| 6034 | MODULE_ALIAS("raid5"); |
| 6035 | MODULE_ALIAS("raid6"); |