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> |
Dan Williams | 07a3b41 | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 50 | #include <linux/async.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 51 | #include <linux/seq_file.h> |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 52 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 53 | #include <linux/slab.h> |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 54 | #include <linux/ratelimit.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 55 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 56 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 57 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 58 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* |
| 61 | * Stripe cache |
| 62 | */ |
| 63 | |
| 64 | #define NR_STRIPES 256 |
| 65 | #define STRIPE_SIZE PAGE_SIZE |
| 66 | #define STRIPE_SHIFT (PAGE_SHIFT - 9) |
| 67 | #define STRIPE_SECTORS (STRIPE_SIZE>>9) |
| 68 | #define IO_THRESHOLD 1 |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 69 | #define BYPASS_THRESHOLD 1 |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 70 | #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define HASH_MASK (NR_HASH - 1) |
| 72 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 73 | static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 74 | { |
| 75 | int hash = (sect >> STRIPE_SHIFT) & HASH_MASK; |
| 76 | return &conf->stripe_hashtbl[hash]; |
| 77 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* bio's attached to a stripe+device for I/O are linked together in bi_sector |
| 80 | * order without overlap. There may be several bio's per stripe+device, and |
| 81 | * a bio could span several devices. |
| 82 | * When walking this list for a particular stripe+device, we must never proceed |
| 83 | * beyond a bio that extends past this device, as the next bio might no longer |
| 84 | * be valid. |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 85 | * 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] | 86 | * of the current stripe+device |
| 87 | */ |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 88 | static inline struct bio *r5_next_bio(struct bio *bio, sector_t sector) |
| 89 | { |
| 90 | int sectors = bio->bi_size >> 9; |
| 91 | if (bio->bi_sector + sectors < sector + STRIPE_SECTORS) |
| 92 | return bio->bi_next; |
| 93 | else |
| 94 | return NULL; |
| 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 97 | /* |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 98 | * We maintain a biased count of active stripes in the bottom 16 bits of |
| 99 | * 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] | 100 | */ |
| 101 | static inline int raid5_bi_phys_segments(struct bio *bio) |
| 102 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 103 | return bio->bi_phys_segments & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static inline int raid5_bi_hw_segments(struct bio *bio) |
| 107 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 108 | return (bio->bi_phys_segments >> 16) & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static inline int raid5_dec_bi_phys_segments(struct bio *bio) |
| 112 | { |
| 113 | --bio->bi_phys_segments; |
| 114 | return raid5_bi_phys_segments(bio); |
| 115 | } |
| 116 | |
| 117 | static inline int raid5_dec_bi_hw_segments(struct bio *bio) |
| 118 | { |
| 119 | unsigned short val = raid5_bi_hw_segments(bio); |
| 120 | |
| 121 | --val; |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 122 | bio->bi_phys_segments = (val << 16) | raid5_bi_phys_segments(bio); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 123 | return val; |
| 124 | } |
| 125 | |
| 126 | static inline void raid5_set_bi_hw_segments(struct bio *bio, unsigned int cnt) |
| 127 | { |
Namhyung Kim | 9b2dc8b | 2011-06-13 14:48:22 +0900 | [diff] [blame] | 128 | bio->bi_phys_segments = raid5_bi_phys_segments(bio) | (cnt << 16); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 129 | } |
| 130 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 131 | /* Find first data disk in a raid6 stripe */ |
| 132 | static inline int raid6_d0(struct stripe_head *sh) |
| 133 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 134 | if (sh->ddf_layout) |
| 135 | /* ddf always start from first device */ |
| 136 | return 0; |
| 137 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 138 | if (sh->qd_idx == sh->disks - 1) |
| 139 | return 0; |
| 140 | else |
| 141 | return sh->qd_idx + 1; |
| 142 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 143 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 144 | { |
| 145 | disk++; |
| 146 | return (disk < raid_disks) ? disk : 0; |
| 147 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 148 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 149 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 150 | * We need to map each disk to a 'slot', where the data disks are slot |
| 151 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 152 | * is raid_disks-1. This help does that mapping. |
| 153 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 154 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 155 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 156 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 157 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 158 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 159 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 160 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 161 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 162 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 163 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 164 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 165 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 166 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 167 | return slot; |
| 168 | } |
| 169 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 170 | static void return_io(struct bio *return_bi) |
| 171 | { |
| 172 | struct bio *bi = return_bi; |
| 173 | while (bi) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 174 | |
| 175 | return_bi = bi->bi_next; |
| 176 | bi->bi_next = NULL; |
| 177 | bi->bi_size = 0; |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 178 | bio_endio(bi, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 179 | bi = return_bi; |
| 180 | } |
| 181 | } |
| 182 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 183 | static void print_raid5_conf (struct r5conf *conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 185 | static int stripe_operations_active(struct stripe_head *sh) |
| 186 | { |
| 187 | return sh->check_state || sh->reconstruct_state || |
| 188 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 189 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 190 | } |
| 191 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 192 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | if (atomic_dec_and_test(&sh->count)) { |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 195 | BUG_ON(!list_empty(&sh->lru)); |
| 196 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 198 | if (test_bit(STRIPE_DELAYED, &sh->state)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | list_add_tail(&sh->lru, &conf->delayed_list); |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 200 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
| 201 | sh->bm_seq - conf->seq_write > 0) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 202 | list_add_tail(&sh->lru, &conf->bitmap_list); |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 203 | else { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 204 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | list_add_tail(&sh->lru, &conf->handle_list); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | md_wakeup_thread(conf->mddev->thread); |
| 208 | } else { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 209 | BUG_ON(stripe_operations_active(sh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
| 211 | atomic_dec(&conf->preread_active_stripes); |
| 212 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) |
| 213 | md_wakeup_thread(conf->mddev->thread); |
| 214 | } |
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 | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 372 | static int has_failed(struct r5conf *conf) |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 373 | { |
| 374 | int degraded; |
| 375 | int i; |
| 376 | if (conf->mddev->reshape_position == MaxSector) |
| 377 | return conf->mddev->degraded > conf->max_degraded; |
| 378 | |
| 379 | rcu_read_lock(); |
| 380 | degraded = 0; |
| 381 | for (i = 0; i < conf->previous_raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 382 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 383 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 384 | degraded++; |
| 385 | else if (test_bit(In_sync, &rdev->flags)) |
| 386 | ; |
| 387 | else |
| 388 | /* not in-sync or faulty. |
| 389 | * If the reshape increases the number of devices, |
| 390 | * this is being recovered by the reshape, so |
| 391 | * this 'previous' section is not in_sync. |
| 392 | * If the number of devices is being reduced however, |
| 393 | * the device can only be part of the array if |
| 394 | * we are reverting a reshape, so this section will |
| 395 | * be in-sync. |
| 396 | */ |
| 397 | if (conf->raid_disks >= conf->previous_raid_disks) |
| 398 | degraded++; |
| 399 | } |
| 400 | rcu_read_unlock(); |
| 401 | if (degraded > conf->max_degraded) |
| 402 | return 1; |
| 403 | rcu_read_lock(); |
| 404 | degraded = 0; |
| 405 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 406 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 407 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 408 | degraded++; |
| 409 | else if (test_bit(In_sync, &rdev->flags)) |
| 410 | ; |
| 411 | else |
| 412 | /* not in-sync or faulty. |
| 413 | * If reshape increases the number of devices, this |
| 414 | * section has already been recovered, else it |
| 415 | * almost certainly hasn't. |
| 416 | */ |
| 417 | if (conf->raid_disks <= conf->previous_raid_disks) |
| 418 | degraded++; |
| 419 | } |
| 420 | rcu_read_unlock(); |
| 421 | if (degraded > conf->max_degraded) |
| 422 | return 1; |
| 423 | return 0; |
| 424 | } |
| 425 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 426 | static struct stripe_head * |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 427 | get_active_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 428 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
| 430 | struct stripe_head *sh; |
| 431 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 432 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | spin_lock_irq(&conf->device_lock); |
| 435 | |
| 436 | do { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 437 | wait_event_lock_irq(conf->wait_for_stripe, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 438 | conf->quiesce == 0 || noquiesce, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 439 | conf->device_lock, /* nothing */); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 440 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (!sh) { |
| 442 | if (!conf->inactive_blocked) |
| 443 | sh = get_free_stripe(conf); |
| 444 | if (noblock && sh == NULL) |
| 445 | break; |
| 446 | if (!sh) { |
| 447 | conf->inactive_blocked = 1; |
| 448 | wait_event_lock_irq(conf->wait_for_stripe, |
| 449 | !list_empty(&conf->inactive_list) && |
NeilBrown | 5036805 | 2005-12-12 02:39:17 -0800 | [diff] [blame] | 450 | (atomic_read(&conf->active_stripes) |
| 451 | < (conf->max_nr_stripes *3/4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | || !conf->inactive_blocked), |
| 453 | conf->device_lock, |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 454 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | conf->inactive_blocked = 0; |
| 456 | } else |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 457 | init_stripe(sh, sector, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } else { |
| 459 | if (atomic_read(&sh->count)) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 460 | BUG_ON(!list_empty(&sh->lru) |
| 461 | && !test_bit(STRIPE_EXPANDING, &sh->state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } else { |
| 463 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 464 | atomic_inc(&conf->active_stripes); |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 465 | if (list_empty(&sh->lru) && |
| 466 | !test_bit(STRIPE_EXPANDING, &sh->state)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 467 | BUG(); |
| 468 | list_del_init(&sh->lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } while (sh == NULL); |
| 472 | |
| 473 | if (sh) |
| 474 | atomic_inc(&sh->count); |
| 475 | |
| 476 | spin_unlock_irq(&conf->device_lock); |
| 477 | return sh; |
| 478 | } |
| 479 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 480 | static void |
| 481 | raid5_end_read_request(struct bio *bi, int error); |
| 482 | static void |
| 483 | raid5_end_write_request(struct bio *bi, int error); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 484 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 485 | 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] | 486 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 487 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 488 | int i, disks = sh->disks; |
| 489 | |
| 490 | might_sleep(); |
| 491 | |
| 492 | for (i = disks; i--; ) { |
| 493 | int rw; |
| 494 | struct bio *bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 495 | struct md_rdev *rdev; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 496 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { |
| 497 | if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) |
| 498 | rw = WRITE_FUA; |
| 499 | else |
| 500 | rw = WRITE; |
| 501 | } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 502 | rw = READ; |
| 503 | else |
| 504 | continue; |
| 505 | |
| 506 | bi = &sh->dev[i].req; |
| 507 | |
| 508 | bi->bi_rw = rw; |
Namhyung Kim | b062962 | 2011-06-14 14:20:19 +1000 | [diff] [blame] | 509 | if (rw & WRITE) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 510 | bi->bi_end_io = raid5_end_write_request; |
| 511 | else |
| 512 | bi->bi_end_io = raid5_end_read_request; |
| 513 | |
| 514 | rcu_read_lock(); |
| 515 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 516 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 517 | rdev = NULL; |
| 518 | if (rdev) |
| 519 | atomic_inc(&rdev->nr_pending); |
| 520 | rcu_read_unlock(); |
| 521 | |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 522 | /* We have already checked bad blocks for reads. Now |
| 523 | * need to check for writes. |
| 524 | */ |
| 525 | while ((rw & WRITE) && rdev && |
| 526 | test_bit(WriteErrorSeen, &rdev->flags)) { |
| 527 | sector_t first_bad; |
| 528 | int bad_sectors; |
| 529 | int bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 530 | &first_bad, &bad_sectors); |
| 531 | if (!bad) |
| 532 | break; |
| 533 | |
| 534 | if (bad < 0) { |
| 535 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 536 | if (!conf->mddev->external && |
| 537 | conf->mddev->flags) { |
| 538 | /* It is very unlikely, but we might |
| 539 | * still need to write out the |
| 540 | * bad block log - better give it |
| 541 | * a chance*/ |
| 542 | md_check_recovery(conf->mddev); |
| 543 | } |
| 544 | md_wait_for_blocked_rdev(rdev, conf->mddev); |
| 545 | } else { |
| 546 | /* Acknowledged bad block - skip the write */ |
| 547 | rdev_dec_pending(rdev, conf->mddev); |
| 548 | rdev = NULL; |
| 549 | } |
| 550 | } |
| 551 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 552 | if (rdev) { |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 553 | if (s->syncing || s->expanding || s->expanded) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 554 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 555 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 556 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 557 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 558 | bi->bi_bdev = rdev->bdev; |
| 559 | pr_debug("%s: for %llu schedule op %ld on disc %d\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 560 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 561 | bi->bi_rw, i); |
| 562 | atomic_inc(&sh->count); |
| 563 | bi->bi_sector = sh->sector + rdev->data_offset; |
| 564 | bi->bi_flags = 1 << BIO_UPTODATE; |
| 565 | bi->bi_vcnt = 1; |
| 566 | bi->bi_max_vecs = 1; |
| 567 | bi->bi_idx = 0; |
| 568 | bi->bi_io_vec = &sh->dev[i].vec; |
| 569 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 570 | bi->bi_io_vec[0].bv_offset = 0; |
| 571 | bi->bi_size = STRIPE_SIZE; |
| 572 | bi->bi_next = NULL; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 573 | generic_make_request(bi); |
| 574 | } else { |
Namhyung Kim | b062962 | 2011-06-14 14:20:19 +1000 | [diff] [blame] | 575 | if (rw & WRITE) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 576 | set_bit(STRIPE_DEGRADED, &sh->state); |
| 577 | pr_debug("skip op %ld on disc %d for sector %llu\n", |
| 578 | bi->bi_rw, i, (unsigned long long)sh->sector); |
| 579 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 580 | set_bit(STRIPE_HANDLE, &sh->state); |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | static struct dma_async_tx_descriptor * |
| 586 | async_copy_data(int frombio, struct bio *bio, struct page *page, |
| 587 | sector_t sector, struct dma_async_tx_descriptor *tx) |
| 588 | { |
| 589 | struct bio_vec *bvl; |
| 590 | struct page *bio_page; |
| 591 | int i; |
| 592 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 593 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 594 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 595 | |
| 596 | if (bio->bi_sector >= sector) |
| 597 | page_offset = (signed)(bio->bi_sector - sector) * 512; |
| 598 | else |
| 599 | page_offset = (signed)(sector - bio->bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 600 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 601 | if (frombio) |
| 602 | flags |= ASYNC_TX_FENCE; |
| 603 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 604 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 605 | bio_for_each_segment(bvl, bio, i) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 606 | int len = bvl->bv_len; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 607 | int clen; |
| 608 | int b_offset = 0; |
| 609 | |
| 610 | if (page_offset < 0) { |
| 611 | b_offset = -page_offset; |
| 612 | page_offset += b_offset; |
| 613 | len -= b_offset; |
| 614 | } |
| 615 | |
| 616 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 617 | clen = STRIPE_SIZE - page_offset; |
| 618 | else |
| 619 | clen = len; |
| 620 | |
| 621 | if (clen > 0) { |
Namhyung Kim | fcde907 | 2011-06-14 14:23:57 +1000 | [diff] [blame] | 622 | b_offset += bvl->bv_offset; |
| 623 | bio_page = bvl->bv_page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 624 | if (frombio) |
| 625 | tx = async_memcpy(page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 626 | b_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 627 | else |
| 628 | tx = async_memcpy(bio_page, page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 629 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 630 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 631 | /* chain the operations */ |
| 632 | submit.depend_tx = tx; |
| 633 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 634 | if (clen < len) /* hit end of page */ |
| 635 | break; |
| 636 | page_offset += len; |
| 637 | } |
| 638 | |
| 639 | return tx; |
| 640 | } |
| 641 | |
| 642 | static void ops_complete_biofill(void *stripe_head_ref) |
| 643 | { |
| 644 | struct stripe_head *sh = stripe_head_ref; |
| 645 | struct bio *return_bi = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 646 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 647 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 648 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 649 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 650 | (unsigned long long)sh->sector); |
| 651 | |
| 652 | /* clear completed biofills */ |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 653 | spin_lock_irq(&conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 654 | for (i = sh->disks; i--; ) { |
| 655 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 656 | |
| 657 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 658 | /* and check if we need to reply to a read request, |
| 659 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 660 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 661 | */ |
| 662 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 663 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 664 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 665 | BUG_ON(!dev->read); |
| 666 | rbi = dev->read; |
| 667 | dev->read = NULL; |
| 668 | while (rbi && rbi->bi_sector < |
| 669 | dev->sector + STRIPE_SECTORS) { |
| 670 | rbi2 = r5_next_bio(rbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 671 | if (!raid5_dec_bi_phys_segments(rbi)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 672 | rbi->bi_next = return_bi; |
| 673 | return_bi = rbi; |
| 674 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 675 | rbi = rbi2; |
| 676 | } |
| 677 | } |
| 678 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 679 | spin_unlock_irq(&conf->device_lock); |
| 680 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 681 | |
| 682 | return_io(return_bi); |
| 683 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 684 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 685 | release_stripe(sh); |
| 686 | } |
| 687 | |
| 688 | static void ops_run_biofill(struct stripe_head *sh) |
| 689 | { |
| 690 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 691 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 692 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 693 | int i; |
| 694 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 695 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 696 | (unsigned long long)sh->sector); |
| 697 | |
| 698 | for (i = sh->disks; i--; ) { |
| 699 | struct r5dev *dev = &sh->dev[i]; |
| 700 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 701 | struct bio *rbi; |
| 702 | spin_lock_irq(&conf->device_lock); |
| 703 | dev->read = rbi = dev->toread; |
| 704 | dev->toread = NULL; |
| 705 | spin_unlock_irq(&conf->device_lock); |
| 706 | while (rbi && rbi->bi_sector < |
| 707 | dev->sector + STRIPE_SECTORS) { |
| 708 | tx = async_copy_data(0, rbi, dev->page, |
| 709 | dev->sector, tx); |
| 710 | rbi = r5_next_bio(rbi, dev->sector); |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 716 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 717 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 720 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 721 | { |
| 722 | struct r5dev *tgt; |
| 723 | |
| 724 | if (target < 0) |
| 725 | return; |
| 726 | |
| 727 | tgt = &sh->dev[target]; |
| 728 | set_bit(R5_UPTODATE, &tgt->flags); |
| 729 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 730 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 731 | } |
| 732 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 733 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 734 | { |
| 735 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 736 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 737 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 738 | (unsigned long long)sh->sector); |
| 739 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 740 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 741 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 742 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 743 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 744 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 745 | if (sh->check_state == check_state_compute_run) |
| 746 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 747 | set_bit(STRIPE_HANDLE, &sh->state); |
| 748 | release_stripe(sh); |
| 749 | } |
| 750 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 751 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 752 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 753 | struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 754 | { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 755 | return percpu->scribble + sizeof(struct page *) * (sh->disks + 2); |
| 756 | } |
| 757 | |
| 758 | static struct dma_async_tx_descriptor * |
| 759 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 760 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 761 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 762 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 763 | int target = sh->ops.target; |
| 764 | struct r5dev *tgt = &sh->dev[target]; |
| 765 | struct page *xor_dest = tgt->page; |
| 766 | int count = 0; |
| 767 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 768 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 769 | int i; |
| 770 | |
| 771 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 772 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 773 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 774 | |
| 775 | for (i = disks; i--; ) |
| 776 | if (i != target) |
| 777 | xor_srcs[count++] = sh->dev[i].page; |
| 778 | |
| 779 | atomic_inc(&sh->count); |
| 780 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 781 | 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] | 782 | ops_complete_compute, sh, to_addr_conv(sh, percpu)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 783 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 784 | 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] | 785 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 786 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 787 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 788 | return tx; |
| 789 | } |
| 790 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 791 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 792 | * @srcs - (struct page *) array of size sh->disks |
| 793 | * @sh - stripe_head to parse |
| 794 | * |
| 795 | * Populates srcs in proper layout order for the stripe and returns the |
| 796 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 797 | * destination buffer is recorded in srcs[count] and the Q destination |
| 798 | * is recorded in srcs[count+1]]. |
| 799 | */ |
| 800 | static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh) |
| 801 | { |
| 802 | int disks = sh->disks; |
| 803 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 804 | int d0_idx = raid6_d0(sh); |
| 805 | int count; |
| 806 | int i; |
| 807 | |
| 808 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 809 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 810 | |
| 811 | count = 0; |
| 812 | i = d0_idx; |
| 813 | do { |
| 814 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 815 | |
| 816 | srcs[slot] = sh->dev[i].page; |
| 817 | i = raid6_next_disk(i, disks); |
| 818 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 819 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 820 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | static struct dma_async_tx_descriptor * |
| 824 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 825 | { |
| 826 | int disks = sh->disks; |
| 827 | struct page **blocks = percpu->scribble; |
| 828 | int target; |
| 829 | int qd_idx = sh->qd_idx; |
| 830 | struct dma_async_tx_descriptor *tx; |
| 831 | struct async_submit_ctl submit; |
| 832 | struct r5dev *tgt; |
| 833 | struct page *dest; |
| 834 | int i; |
| 835 | int count; |
| 836 | |
| 837 | if (sh->ops.target < 0) |
| 838 | target = sh->ops.target2; |
| 839 | else if (sh->ops.target2 < 0) |
| 840 | target = sh->ops.target; |
| 841 | else |
| 842 | /* we should only have one valid target */ |
| 843 | BUG(); |
| 844 | BUG_ON(target < 0); |
| 845 | pr_debug("%s: stripe %llu block: %d\n", |
| 846 | __func__, (unsigned long long)sh->sector, target); |
| 847 | |
| 848 | tgt = &sh->dev[target]; |
| 849 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 850 | dest = tgt->page; |
| 851 | |
| 852 | atomic_inc(&sh->count); |
| 853 | |
| 854 | if (target == qd_idx) { |
| 855 | count = set_syndrome_sources(blocks, sh); |
| 856 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 857 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 858 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 859 | ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 860 | to_addr_conv(sh, percpu)); |
| 861 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 862 | } else { |
| 863 | /* Compute any data- or p-drive using XOR */ |
| 864 | count = 0; |
| 865 | for (i = disks; i-- ; ) { |
| 866 | if (i == target || i == qd_idx) |
| 867 | continue; |
| 868 | blocks[count++] = sh->dev[i].page; |
| 869 | } |
| 870 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 871 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 872 | NULL, ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 873 | to_addr_conv(sh, percpu)); |
| 874 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 875 | } |
| 876 | |
| 877 | return tx; |
| 878 | } |
| 879 | |
| 880 | static struct dma_async_tx_descriptor * |
| 881 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 882 | { |
| 883 | int i, count, disks = sh->disks; |
| 884 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 885 | int d0_idx = raid6_d0(sh); |
| 886 | int faila = -1, failb = -1; |
| 887 | int target = sh->ops.target; |
| 888 | int target2 = sh->ops.target2; |
| 889 | struct r5dev *tgt = &sh->dev[target]; |
| 890 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 891 | struct dma_async_tx_descriptor *tx; |
| 892 | struct page **blocks = percpu->scribble; |
| 893 | struct async_submit_ctl submit; |
| 894 | |
| 895 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 896 | __func__, (unsigned long long)sh->sector, target, target2); |
| 897 | BUG_ON(target < 0 || target2 < 0); |
| 898 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 899 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 900 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 901 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 902 | * slot number conversion for 'faila' and 'failb' |
| 903 | */ |
| 904 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 905 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 906 | count = 0; |
| 907 | i = d0_idx; |
| 908 | do { |
| 909 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 910 | |
| 911 | blocks[slot] = sh->dev[i].page; |
| 912 | |
| 913 | if (i == target) |
| 914 | faila = slot; |
| 915 | if (i == target2) |
| 916 | failb = slot; |
| 917 | i = raid6_next_disk(i, disks); |
| 918 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 919 | |
| 920 | BUG_ON(faila == failb); |
| 921 | if (failb < faila) |
| 922 | swap(faila, failb); |
| 923 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 924 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 925 | |
| 926 | atomic_inc(&sh->count); |
| 927 | |
| 928 | if (failb == syndrome_disks+1) { |
| 929 | /* Q disk is one of the missing disks */ |
| 930 | if (faila == syndrome_disks) { |
| 931 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 932 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 933 | ops_complete_compute, sh, |
| 934 | to_addr_conv(sh, percpu)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 935 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 936 | STRIPE_SIZE, &submit); |
| 937 | } else { |
| 938 | struct page *dest; |
| 939 | int data_target; |
| 940 | int qd_idx = sh->qd_idx; |
| 941 | |
| 942 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 943 | if (target == qd_idx) |
| 944 | data_target = target2; |
| 945 | else |
| 946 | data_target = target; |
| 947 | |
| 948 | count = 0; |
| 949 | for (i = disks; i-- ; ) { |
| 950 | if (i == data_target || i == qd_idx) |
| 951 | continue; |
| 952 | blocks[count++] = sh->dev[i].page; |
| 953 | } |
| 954 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 955 | init_async_submit(&submit, |
| 956 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 957 | NULL, NULL, NULL, |
| 958 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 959 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 960 | &submit); |
| 961 | |
| 962 | count = set_syndrome_sources(blocks, sh); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 963 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 964 | ops_complete_compute, sh, |
| 965 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 966 | return async_gen_syndrome(blocks, 0, count+2, |
| 967 | STRIPE_SIZE, &submit); |
| 968 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 969 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 970 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 971 | ops_complete_compute, sh, |
| 972 | to_addr_conv(sh, percpu)); |
| 973 | if (failb == syndrome_disks) { |
| 974 | /* We're missing D+P. */ |
| 975 | return async_raid6_datap_recov(syndrome_disks+2, |
| 976 | STRIPE_SIZE, faila, |
| 977 | blocks, &submit); |
| 978 | } else { |
| 979 | /* We're missing D+D. */ |
| 980 | return async_raid6_2data_recov(syndrome_disks+2, |
| 981 | STRIPE_SIZE, faila, failb, |
| 982 | blocks, &submit); |
| 983 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 988 | static void ops_complete_prexor(void *stripe_head_ref) |
| 989 | { |
| 990 | struct stripe_head *sh = stripe_head_ref; |
| 991 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 992 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 993 | (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | static struct dma_async_tx_descriptor * |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 997 | ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 998 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 999 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1000 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1001 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1002 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1003 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1004 | |
| 1005 | /* existing parity data subtracted */ |
| 1006 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1007 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1008 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1009 | (unsigned long long)sh->sector); |
| 1010 | |
| 1011 | for (i = disks; i--; ) { |
| 1012 | struct r5dev *dev = &sh->dev[i]; |
| 1013 | /* Only process blocks that are known to be uptodate */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1014 | if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1015 | xor_srcs[count++] = dev->page; |
| 1016 | } |
| 1017 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1018 | 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] | 1019 | ops_complete_prexor, sh, to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1020 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1021 | |
| 1022 | return tx; |
| 1023 | } |
| 1024 | |
| 1025 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1026 | 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] | 1027 | { |
| 1028 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1029 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1030 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1031 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1032 | (unsigned long long)sh->sector); |
| 1033 | |
| 1034 | for (i = disks; i--; ) { |
| 1035 | struct r5dev *dev = &sh->dev[i]; |
| 1036 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1037 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1038 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1039 | struct bio *wbi; |
| 1040 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 1041 | spin_lock_irq(&sh->raid_conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1042 | chosen = dev->towrite; |
| 1043 | dev->towrite = NULL; |
| 1044 | BUG_ON(dev->written); |
| 1045 | wbi = dev->written = chosen; |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 1046 | spin_unlock_irq(&sh->raid_conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1047 | |
| 1048 | while (wbi && wbi->bi_sector < |
| 1049 | dev->sector + STRIPE_SECTORS) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1050 | if (wbi->bi_rw & REQ_FUA) |
| 1051 | set_bit(R5_WantFUA, &dev->flags); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1052 | tx = async_copy_data(1, wbi, dev->page, |
| 1053 | dev->sector, tx); |
| 1054 | wbi = r5_next_bio(wbi, dev->sector); |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | return tx; |
| 1060 | } |
| 1061 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1062 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1063 | { |
| 1064 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1065 | int disks = sh->disks; |
| 1066 | int pd_idx = sh->pd_idx; |
| 1067 | int qd_idx = sh->qd_idx; |
| 1068 | int i; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1069 | bool fua = false; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1070 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1071 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1072 | (unsigned long long)sh->sector); |
| 1073 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1074 | for (i = disks; i--; ) |
| 1075 | fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); |
| 1076 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1077 | for (i = disks; i--; ) { |
| 1078 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1079 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1080 | if (dev->written || i == pd_idx || i == qd_idx) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1081 | set_bit(R5_UPTODATE, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1082 | if (fua) |
| 1083 | set_bit(R5_WantFUA, &dev->flags); |
| 1084 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1087 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 1088 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 1089 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 1090 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 1091 | else { |
| 1092 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 1093 | sh->reconstruct_state = reconstruct_state_result; |
| 1094 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1095 | |
| 1096 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1097 | release_stripe(sh); |
| 1098 | } |
| 1099 | |
| 1100 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1101 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1102 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1103 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1104 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1105 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1106 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1107 | int count = 0, pd_idx = sh->pd_idx, i; |
| 1108 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1109 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1110 | unsigned long flags; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1111 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1112 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1113 | (unsigned long long)sh->sector); |
| 1114 | |
| 1115 | /* check if prexor is active which means only process blocks |
| 1116 | * that are part of a read-modify-write (written) |
| 1117 | */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1118 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1119 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1120 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1121 | for (i = disks; i--; ) { |
| 1122 | struct r5dev *dev = &sh->dev[i]; |
| 1123 | if (dev->written) |
| 1124 | xor_srcs[count++] = dev->page; |
| 1125 | } |
| 1126 | } else { |
| 1127 | xor_dest = sh->dev[pd_idx].page; |
| 1128 | for (i = disks; i--; ) { |
| 1129 | struct r5dev *dev = &sh->dev[i]; |
| 1130 | if (i != pd_idx) |
| 1131 | xor_srcs[count++] = dev->page; |
| 1132 | } |
| 1133 | } |
| 1134 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1135 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1136 | * 2/ if we did not prexor then we are redoing the parity |
| 1137 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1138 | * for the synchronous xor case |
| 1139 | */ |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 1140 | flags = ASYNC_TX_ACK | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1141 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
| 1142 | |
| 1143 | atomic_inc(&sh->count); |
| 1144 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1145 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, sh, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1146 | to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1147 | if (unlikely(count == 1)) |
| 1148 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1149 | else |
| 1150 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1153 | static void |
| 1154 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1155 | struct dma_async_tx_descriptor *tx) |
| 1156 | { |
| 1157 | struct async_submit_ctl submit; |
| 1158 | struct page **blocks = percpu->scribble; |
| 1159 | int count; |
| 1160 | |
| 1161 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1162 | |
| 1163 | count = set_syndrome_sources(blocks, sh); |
| 1164 | |
| 1165 | atomic_inc(&sh->count); |
| 1166 | |
| 1167 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct, |
| 1168 | sh, to_addr_conv(sh, percpu)); |
| 1169 | async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | static void ops_complete_check(void *stripe_head_ref) |
| 1173 | { |
| 1174 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1175 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1176 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1177 | (unsigned long long)sh->sector); |
| 1178 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1179 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1180 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1181 | release_stripe(sh); |
| 1182 | } |
| 1183 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1184 | 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] | 1185 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1186 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1187 | int pd_idx = sh->pd_idx; |
| 1188 | int qd_idx = sh->qd_idx; |
| 1189 | struct page *xor_dest; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1190 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1191 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1192 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1193 | int count; |
| 1194 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1195 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1196 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1197 | (unsigned long long)sh->sector); |
| 1198 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1199 | count = 0; |
| 1200 | xor_dest = sh->dev[pd_idx].page; |
| 1201 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1202 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1203 | if (i == pd_idx || i == qd_idx) |
| 1204 | continue; |
| 1205 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1208 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
| 1209 | to_addr_conv(sh, percpu)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1210 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1211 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1212 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1213 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1214 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 1215 | tx = async_trigger_callback(&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 ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 1219 | { |
| 1220 | struct page **srcs = percpu->scribble; |
| 1221 | struct async_submit_ctl submit; |
| 1222 | int count; |
| 1223 | |
| 1224 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 1225 | (unsigned long long)sh->sector, checkp); |
| 1226 | |
| 1227 | count = set_syndrome_sources(srcs, sh); |
| 1228 | if (!checkp) |
| 1229 | srcs[count] = NULL; |
| 1230 | |
| 1231 | atomic_inc(&sh->count); |
| 1232 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
| 1233 | sh, to_addr_conv(sh, percpu)); |
| 1234 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 1235 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 1236 | } |
| 1237 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1238 | 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] | 1239 | { |
| 1240 | int overlap_clear = 0, i, disks = sh->disks; |
| 1241 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1242 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1243 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1244 | struct raid5_percpu *percpu; |
| 1245 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1246 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1247 | cpu = get_cpu(); |
| 1248 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1249 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1250 | ops_run_biofill(sh); |
| 1251 | overlap_clear++; |
| 1252 | } |
| 1253 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1254 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1255 | if (level < 6) |
| 1256 | tx = ops_run_compute5(sh, percpu); |
| 1257 | else { |
| 1258 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 1259 | tx = ops_run_compute6_1(sh, percpu); |
| 1260 | else |
| 1261 | tx = ops_run_compute6_2(sh, percpu); |
| 1262 | } |
| 1263 | /* terminate the chain if reconstruct is not set to be run */ |
| 1264 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1265 | async_tx_ack(tx); |
| 1266 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1267 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1268 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1269 | tx = ops_run_prexor(sh, percpu, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1270 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1271 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1272 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1273 | overlap_clear++; |
| 1274 | } |
| 1275 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1276 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 1277 | if (level < 6) |
| 1278 | ops_run_reconstruct5(sh, percpu, tx); |
| 1279 | else |
| 1280 | ops_run_reconstruct6(sh, percpu, tx); |
| 1281 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1282 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1283 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 1284 | if (sh->check_state == check_state_run) |
| 1285 | ops_run_check_p(sh, percpu); |
| 1286 | else if (sh->check_state == check_state_run_q) |
| 1287 | ops_run_check_pq(sh, percpu, 0); |
| 1288 | else if (sh->check_state == check_state_run_pq) |
| 1289 | ops_run_check_pq(sh, percpu, 1); |
| 1290 | else |
| 1291 | BUG(); |
| 1292 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1293 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1294 | if (overlap_clear) |
| 1295 | for (i = disks; i--; ) { |
| 1296 | struct r5dev *dev = &sh->dev[i]; |
| 1297 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 1298 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 1299 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1300 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1303 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1304 | static void async_run_ops(void *param, async_cookie_t cookie) |
| 1305 | { |
| 1306 | struct stripe_head *sh = param; |
| 1307 | unsigned long ops_request = sh->ops.request; |
| 1308 | |
| 1309 | clear_bit_unlock(STRIPE_OPS_REQ_PENDING, &sh->state); |
| 1310 | wake_up(&sh->ops.wait_for_ops); |
| 1311 | |
| 1312 | __raid_run_ops(sh, ops_request); |
| 1313 | release_stripe(sh); |
| 1314 | } |
| 1315 | |
| 1316 | static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) |
| 1317 | { |
| 1318 | /* since handle_stripe can be called outside of raid5d context |
| 1319 | * we need to ensure sh->ops.request is de-staged before another |
| 1320 | * request arrives |
| 1321 | */ |
| 1322 | wait_event(sh->ops.wait_for_ops, |
| 1323 | !test_and_set_bit_lock(STRIPE_OPS_REQ_PENDING, &sh->state)); |
| 1324 | sh->ops.request = ops_request; |
| 1325 | |
| 1326 | atomic_inc(&sh->count); |
| 1327 | async_schedule(async_run_ops, sh); |
| 1328 | } |
| 1329 | #else |
| 1330 | #define raid_run_ops __raid_run_ops |
| 1331 | #endif |
| 1332 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1333 | static int grow_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | { |
| 1335 | struct stripe_head *sh; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1336 | sh = kmem_cache_zalloc(conf->slab_cache, GFP_KERNEL); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1337 | if (!sh) |
| 1338 | return 0; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1339 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1340 | sh->raid_conf = conf; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1341 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1342 | init_waitqueue_head(&sh->ops.wait_for_ops); |
| 1343 | #endif |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1344 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1345 | if (grow_buffers(sh)) { |
| 1346 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1347 | kmem_cache_free(conf->slab_cache, sh); |
| 1348 | return 0; |
| 1349 | } |
| 1350 | /* we just created an active stripe so... */ |
| 1351 | atomic_set(&sh->count, 1); |
| 1352 | atomic_inc(&conf->active_stripes); |
| 1353 | INIT_LIST_HEAD(&sh->lru); |
| 1354 | release_stripe(sh); |
| 1355 | return 1; |
| 1356 | } |
| 1357 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1358 | static int grow_stripes(struct r5conf *conf, int num) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1359 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1360 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1361 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 1363 | if (conf->mddev->gendisk) |
| 1364 | sprintf(conf->cache_name[0], |
| 1365 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 1366 | else |
| 1367 | sprintf(conf->cache_name[0], |
| 1368 | "raid%d-%p", conf->level, conf->mddev); |
| 1369 | sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]); |
| 1370 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1371 | conf->active_name = 0; |
| 1372 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1374 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | if (!sc) |
| 1376 | return 1; |
| 1377 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1378 | conf->pool_size = devs; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1379 | while (num--) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1380 | if (!grow_one_stripe(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | return 0; |
| 1383 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 1384 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1385 | /** |
| 1386 | * scribble_len - return the required size of the scribble region |
| 1387 | * @num - total number of disks in the array |
| 1388 | * |
| 1389 | * The size must be enough to contain: |
| 1390 | * 1/ a struct page pointer for each device in the array +2 |
| 1391 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 1392 | * (dma_map_page()) or page (page_address()) address. |
| 1393 | * |
| 1394 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 1395 | * calculate over all devices (not just the data blocks), using zeros in place |
| 1396 | * of the P and Q blocks. |
| 1397 | */ |
| 1398 | static size_t scribble_len(int num) |
| 1399 | { |
| 1400 | size_t len; |
| 1401 | |
| 1402 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
| 1403 | |
| 1404 | return len; |
| 1405 | } |
| 1406 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1407 | static int resize_stripes(struct r5conf *conf, int newsize) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1408 | { |
| 1409 | /* Make all the stripes able to hold 'newsize' devices. |
| 1410 | * New slots in each stripe get 'page' set to a new page. |
| 1411 | * |
| 1412 | * This happens in stages: |
| 1413 | * 1/ create a new kmem_cache and allocate the required number of |
| 1414 | * stripe_heads. |
| 1415 | * 2/ gather all the old stripe_heads and tranfer the pages across |
| 1416 | * to the new stripe_heads. This will have the side effect of |
| 1417 | * freezing the array as once all stripe_heads have been collected, |
| 1418 | * no IO will be possible. Old stripe heads are freed once their |
| 1419 | * pages have been transferred over, and the old kmem_cache is |
| 1420 | * freed when all stripes are done. |
| 1421 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 1422 | * we simple return a failre status - no need to clean anything up. |
| 1423 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 1424 | * If this fails, we don't bother trying the shrink the |
| 1425 | * stripe_heads down again, we just leave them as they are. |
| 1426 | * As each stripe_head is processed the new one is released into |
| 1427 | * active service. |
| 1428 | * |
| 1429 | * Once step2 is started, we cannot afford to wait for a write, |
| 1430 | * so we use GFP_NOIO allocations. |
| 1431 | */ |
| 1432 | struct stripe_head *osh, *nsh; |
| 1433 | LIST_HEAD(newstripes); |
| 1434 | struct disk_info *ndisks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1435 | unsigned long cpu; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1436 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1437 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1438 | int i; |
| 1439 | |
| 1440 | if (newsize <= conf->pool_size) |
| 1441 | return 0; /* never bother to shrink */ |
| 1442 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1443 | err = md_allow_write(conf->mddev); |
| 1444 | if (err) |
| 1445 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 1446 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1447 | /* Step 1 */ |
| 1448 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 1449 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1450 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1451 | if (!sc) |
| 1452 | return -ENOMEM; |
| 1453 | |
| 1454 | for (i = conf->max_nr_stripes; i; i--) { |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 1455 | nsh = kmem_cache_zalloc(sc, GFP_KERNEL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1456 | if (!nsh) |
| 1457 | break; |
| 1458 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1459 | nsh->raid_conf = conf; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1460 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1461 | init_waitqueue_head(&nsh->ops.wait_for_ops); |
| 1462 | #endif |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1463 | |
| 1464 | list_add(&nsh->lru, &newstripes); |
| 1465 | } |
| 1466 | if (i) { |
| 1467 | /* didn't get enough, give up */ |
| 1468 | while (!list_empty(&newstripes)) { |
| 1469 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1470 | list_del(&nsh->lru); |
| 1471 | kmem_cache_free(sc, nsh); |
| 1472 | } |
| 1473 | kmem_cache_destroy(sc); |
| 1474 | return -ENOMEM; |
| 1475 | } |
| 1476 | /* Step 2 - Must use GFP_NOIO now. |
| 1477 | * OK, we have enough stripes, start collecting inactive |
| 1478 | * stripes and copying them over |
| 1479 | */ |
| 1480 | list_for_each_entry(nsh, &newstripes, lru) { |
| 1481 | spin_lock_irq(&conf->device_lock); |
| 1482 | wait_event_lock_irq(conf->wait_for_stripe, |
| 1483 | !list_empty(&conf->inactive_list), |
| 1484 | conf->device_lock, |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 1485 | ); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1486 | osh = get_free_stripe(conf); |
| 1487 | spin_unlock_irq(&conf->device_lock); |
| 1488 | atomic_set(&nsh->count, 1); |
| 1489 | for(i=0; i<conf->pool_size; i++) |
| 1490 | nsh->dev[i].page = osh->dev[i].page; |
| 1491 | for( ; i<newsize; i++) |
| 1492 | nsh->dev[i].page = NULL; |
| 1493 | kmem_cache_free(conf->slab_cache, osh); |
| 1494 | } |
| 1495 | kmem_cache_destroy(conf->slab_cache); |
| 1496 | |
| 1497 | /* Step 3. |
| 1498 | * At this point, we are holding all the stripes so the array |
| 1499 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1500 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1501 | */ |
| 1502 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 1503 | if (ndisks) { |
| 1504 | for (i=0; i<conf->raid_disks; i++) |
| 1505 | ndisks[i] = conf->disks[i]; |
| 1506 | kfree(conf->disks); |
| 1507 | conf->disks = ndisks; |
| 1508 | } else |
| 1509 | err = -ENOMEM; |
| 1510 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1511 | get_online_cpus(); |
| 1512 | conf->scribble_len = scribble_len(newsize); |
| 1513 | for_each_present_cpu(cpu) { |
| 1514 | struct raid5_percpu *percpu; |
| 1515 | void *scribble; |
| 1516 | |
| 1517 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 1518 | scribble = kmalloc(conf->scribble_len, GFP_NOIO); |
| 1519 | |
| 1520 | if (scribble) { |
| 1521 | kfree(percpu->scribble); |
| 1522 | percpu->scribble = scribble; |
| 1523 | } else { |
| 1524 | err = -ENOMEM; |
| 1525 | break; |
| 1526 | } |
| 1527 | } |
| 1528 | put_online_cpus(); |
| 1529 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1530 | /* Step 4, return new stripes to service */ |
| 1531 | while(!list_empty(&newstripes)) { |
| 1532 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1533 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1534 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1535 | for (i=conf->raid_disks; i < newsize; i++) |
| 1536 | if (nsh->dev[i].page == NULL) { |
| 1537 | struct page *p = alloc_page(GFP_NOIO); |
| 1538 | nsh->dev[i].page = p; |
| 1539 | if (!p) |
| 1540 | err = -ENOMEM; |
| 1541 | } |
| 1542 | release_stripe(nsh); |
| 1543 | } |
| 1544 | /* critical section pass, GFP_NOIO no longer needed */ |
| 1545 | |
| 1546 | conf->slab_cache = sc; |
| 1547 | conf->active_name = 1-conf->active_name; |
| 1548 | conf->pool_size = newsize; |
| 1549 | return err; |
| 1550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1552 | static int drop_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | { |
| 1554 | struct stripe_head *sh; |
| 1555 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1556 | spin_lock_irq(&conf->device_lock); |
| 1557 | sh = get_free_stripe(conf); |
| 1558 | spin_unlock_irq(&conf->device_lock); |
| 1559 | if (!sh) |
| 1560 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 1561 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 1562 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1563 | kmem_cache_free(conf->slab_cache, sh); |
| 1564 | atomic_dec(&conf->active_stripes); |
| 1565 | return 1; |
| 1566 | } |
| 1567 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1568 | static void shrink_stripes(struct r5conf *conf) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1569 | { |
| 1570 | while (drop_one_stripe(conf)) |
| 1571 | ; |
| 1572 | |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1573 | if (conf->slab_cache) |
| 1574 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | conf->slab_cache = NULL; |
| 1576 | } |
| 1577 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1578 | static void raid5_end_read_request(struct bio * bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1580 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1581 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1582 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1584 | char b[BDEVNAME_SIZE]; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 1585 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
| 1588 | for (i=0 ; i<disks; i++) |
| 1589 | if (bi == &sh->dev[i].req) |
| 1590 | break; |
| 1591 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1592 | pr_debug("end_read_request %llu/%d, count: %d, uptodate %d.\n", |
| 1593 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | uptodate); |
| 1595 | if (i == disks) { |
| 1596 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1597 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1602 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1603 | rdev = conf->disks[i].rdev; |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1604 | printk_ratelimited( |
| 1605 | KERN_INFO |
| 1606 | "md/raid:%s: read error corrected" |
| 1607 | " (%lu sectors at %llu on %s)\n", |
| 1608 | mdname(conf->mddev), STRIPE_SECTORS, |
| 1609 | (unsigned long long)(sh->sector |
| 1610 | + rdev->data_offset), |
| 1611 | bdevname(rdev->bdev, b)); |
Namhyung Kim | ddd5115 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1612 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1613 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1614 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
| 1615 | } |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1616 | if (atomic_read(&conf->disks[i].rdev->read_errors)) |
| 1617 | atomic_set(&conf->disks[i].rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | } else { |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1619 | const char *bdn = bdevname(conf->disks[i].rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1620 | int retry = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1621 | rdev = conf->disks[i].rdev; |
| 1622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1624 | atomic_inc(&rdev->read_errors); |
Gabriele A. Trombetti | 7b0bb53 | 2010-04-28 11:51:17 +1000 | [diff] [blame] | 1625 | if (conf->mddev->degraded >= conf->max_degraded) |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1626 | printk_ratelimited( |
| 1627 | KERN_WARNING |
| 1628 | "md/raid:%s: read error not correctable " |
| 1629 | "(sector %llu on %s).\n", |
| 1630 | mdname(conf->mddev), |
| 1631 | (unsigned long long)(sh->sector |
| 1632 | + rdev->data_offset), |
| 1633 | bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1634 | else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1635 | /* Oh, no!!! */ |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1636 | printk_ratelimited( |
| 1637 | KERN_WARNING |
| 1638 | "md/raid:%s: read error NOT corrected!! " |
| 1639 | "(sector %llu on %s).\n", |
| 1640 | mdname(conf->mddev), |
| 1641 | (unsigned long long)(sh->sector |
| 1642 | + rdev->data_offset), |
| 1643 | bdn); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1644 | else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1645 | > conf->max_nr_stripes) |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1646 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1647 | "md/raid:%s: Too many read errors, failing device %s.\n", |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1648 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1649 | else |
| 1650 | retry = 1; |
| 1651 | if (retry) |
| 1652 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 1653 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1654 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1655 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1656 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | } |
| 1659 | rdev_dec_pending(conf->disks[i].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1661 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1662 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1665 | static void raid5_end_write_request(struct bio *bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1667 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1668 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1669 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1671 | sector_t first_bad; |
| 1672 | int bad_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | for (i=0 ; i<disks; i++) |
| 1675 | if (bi == &sh->dev[i].req) |
| 1676 | break; |
| 1677 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1678 | pr_debug("end_write_request %llu/%d, count %d, uptodate: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
| 1680 | uptodate); |
| 1681 | if (i == disks) { |
| 1682 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1683 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1686 | if (!uptodate) { |
| 1687 | set_bit(WriteErrorSeen, &conf->disks[i].rdev->flags); |
| 1688 | set_bit(R5_WriteError, &sh->dev[i].flags); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 1689 | } else if (is_badblock(conf->disks[i].rdev, sh->sector, STRIPE_SECTORS, |
| 1690 | &first_bad, &bad_sectors)) |
| 1691 | set_bit(R5_MadeGood, &sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
| 1693 | rdev_dec_pending(conf->disks[i].rdev, conf->mddev); |
| 1694 | |
| 1695 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1696 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1697 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1701 | 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] | 1702 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1703 | 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] | 1704 | { |
| 1705 | struct r5dev *dev = &sh->dev[i]; |
| 1706 | |
| 1707 | bio_init(&dev->req); |
| 1708 | dev->req.bi_io_vec = &dev->vec; |
| 1709 | dev->req.bi_vcnt++; |
| 1710 | dev->req.bi_max_vecs++; |
| 1711 | dev->vec.bv_page = dev->page; |
| 1712 | dev->vec.bv_len = STRIPE_SIZE; |
| 1713 | dev->vec.bv_offset = 0; |
| 1714 | |
| 1715 | dev->req.bi_sector = sh->sector; |
| 1716 | dev->req.bi_private = sh; |
| 1717 | |
| 1718 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1719 | dev->sector = compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1722 | static void error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | { |
| 1724 | char b[BDEVNAME_SIZE]; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1725 | struct r5conf *conf = mddev->private; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1726 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 1728 | if (test_and_clear_bit(In_sync, &rdev->flags)) { |
| 1729 | unsigned long flags; |
| 1730 | spin_lock_irqsave(&conf->device_lock, flags); |
| 1731 | mddev->degraded++; |
| 1732 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 1733 | /* |
| 1734 | * if recovery was running, make sure it aborts. |
| 1735 | */ |
| 1736 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | } |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 1738 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 1739 | set_bit(Faulty, &rdev->flags); |
| 1740 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 1741 | printk(KERN_ALERT |
| 1742 | "md/raid:%s: Disk failure on %s, disabling device.\n" |
| 1743 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 1744 | mdname(mddev), |
| 1745 | bdevname(rdev->bdev, b), |
| 1746 | mdname(mddev), |
| 1747 | conf->raid_disks - mddev->degraded); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
| 1750 | /* |
| 1751 | * Input: a 'big' sector number, |
| 1752 | * Output: index of the data and parity disk, and the sector # in them. |
| 1753 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1754 | static sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1755 | int previous, int *dd_idx, |
| 1756 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | { |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1758 | sector_t stripe, stripe2; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1759 | sector_t chunk_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1761 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1762 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1764 | int algorithm = previous ? conf->prev_algo |
| 1765 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1766 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1767 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1768 | int raid_disks = previous ? conf->previous_raid_disks |
| 1769 | : conf->raid_disks; |
| 1770 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
| 1772 | /* First compute the information on this sector */ |
| 1773 | |
| 1774 | /* |
| 1775 | * Compute the chunk number and the sector offset inside the chunk |
| 1776 | */ |
| 1777 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 1778 | chunk_number = r_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
| 1780 | /* |
| 1781 | * Compute the stripe number |
| 1782 | */ |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1783 | stripe = chunk_number; |
| 1784 | *dd_idx = sector_div(stripe, data_disks); |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1785 | stripe2 = stripe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | /* |
| 1787 | * Select the parity disk based on the user selected algorithm. |
| 1788 | */ |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 1789 | pd_idx = qd_idx = -1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1790 | switch(conf->level) { |
| 1791 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1792 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1793 | break; |
| 1794 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1795 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1797 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1798 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | (*dd_idx)++; |
| 1800 | break; |
| 1801 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1802 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1803 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | (*dd_idx)++; |
| 1805 | break; |
| 1806 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1807 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1808 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | break; |
| 1810 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1811 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1812 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1814 | case ALGORITHM_PARITY_0: |
| 1815 | pd_idx = 0; |
| 1816 | (*dd_idx)++; |
| 1817 | break; |
| 1818 | case ALGORITHM_PARITY_N: |
| 1819 | pd_idx = data_disks; |
| 1820 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1822 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1823 | } |
| 1824 | break; |
| 1825 | case 6: |
| 1826 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1827 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1828 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1829 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1830 | qd_idx = pd_idx + 1; |
| 1831 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1832 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1833 | qd_idx = 0; |
| 1834 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1835 | (*dd_idx) += 2; /* D D P Q D */ |
| 1836 | break; |
| 1837 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1838 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1839 | qd_idx = pd_idx + 1; |
| 1840 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1841 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1842 | qd_idx = 0; |
| 1843 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1844 | (*dd_idx) += 2; /* D D P Q D */ |
| 1845 | break; |
| 1846 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1847 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1848 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1849 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1850 | break; |
| 1851 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1852 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1853 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1854 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1855 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1856 | |
| 1857 | case ALGORITHM_PARITY_0: |
| 1858 | pd_idx = 0; |
| 1859 | qd_idx = 1; |
| 1860 | (*dd_idx) += 2; |
| 1861 | break; |
| 1862 | case ALGORITHM_PARITY_N: |
| 1863 | pd_idx = data_disks; |
| 1864 | qd_idx = data_disks + 1; |
| 1865 | break; |
| 1866 | |
| 1867 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 1868 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 1869 | * of blocks for computing Q is different. |
| 1870 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1871 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1872 | qd_idx = pd_idx + 1; |
| 1873 | if (pd_idx == raid_disks-1) { |
| 1874 | (*dd_idx)++; /* Q D D D P */ |
| 1875 | qd_idx = 0; |
| 1876 | } else if (*dd_idx >= pd_idx) |
| 1877 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1878 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1879 | break; |
| 1880 | |
| 1881 | case ALGORITHM_ROTATING_N_RESTART: |
| 1882 | /* Same a left_asymmetric, by first stripe is |
| 1883 | * D D D P Q rather than |
| 1884 | * Q D D D P |
| 1885 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1886 | stripe2 += 1; |
| 1887 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1888 | qd_idx = pd_idx + 1; |
| 1889 | if (pd_idx == raid_disks-1) { |
| 1890 | (*dd_idx)++; /* Q D D D P */ |
| 1891 | qd_idx = 0; |
| 1892 | } else if (*dd_idx >= pd_idx) |
| 1893 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1894 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1895 | break; |
| 1896 | |
| 1897 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 1898 | /* Same as left_symmetric but Q is before P */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1899 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1900 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 1901 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1902 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1903 | break; |
| 1904 | |
| 1905 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 1906 | /* RAID5 left_asymmetric, with Q on last device */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1907 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1908 | if (*dd_idx >= pd_idx) |
| 1909 | (*dd_idx)++; |
| 1910 | qd_idx = raid_disks - 1; |
| 1911 | break; |
| 1912 | |
| 1913 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1914 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1915 | if (*dd_idx >= pd_idx) |
| 1916 | (*dd_idx)++; |
| 1917 | qd_idx = raid_disks - 1; |
| 1918 | break; |
| 1919 | |
| 1920 | case ALGORITHM_LEFT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1921 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1922 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 1923 | qd_idx = raid_disks - 1; |
| 1924 | break; |
| 1925 | |
| 1926 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 1927 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1928 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 1929 | qd_idx = raid_disks - 1; |
| 1930 | break; |
| 1931 | |
| 1932 | case ALGORITHM_PARITY_0_6: |
| 1933 | pd_idx = 0; |
| 1934 | (*dd_idx)++; |
| 1935 | qd_idx = raid_disks - 1; |
| 1936 | break; |
| 1937 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1938 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1939 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1940 | } |
| 1941 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1944 | if (sh) { |
| 1945 | sh->pd_idx = pd_idx; |
| 1946 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1947 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1948 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | /* |
| 1950 | * Finally, compute the new sector number |
| 1951 | */ |
| 1952 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 1953 | return new_sector; |
| 1954 | } |
| 1955 | |
| 1956 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1957 | 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] | 1958 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1959 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 1960 | int raid_disks = sh->disks; |
| 1961 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1963 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1964 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1965 | int algorithm = previous ? conf->prev_algo |
| 1966 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | sector_t stripe; |
| 1968 | int chunk_offset; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 1969 | sector_t chunk_number; |
| 1970 | int dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1972 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 1976 | stripe = new_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1978 | if (i == sh->pd_idx) |
| 1979 | return 0; |
| 1980 | switch(conf->level) { |
| 1981 | case 4: break; |
| 1982 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1983 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 1985 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 1986 | if (i > sh->pd_idx) |
| 1987 | i--; |
| 1988 | break; |
| 1989 | case ALGORITHM_LEFT_SYMMETRIC: |
| 1990 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 1991 | if (i < sh->pd_idx) |
| 1992 | i += raid_disks; |
| 1993 | i -= (sh->pd_idx + 1); |
| 1994 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1995 | case ALGORITHM_PARITY_0: |
| 1996 | i -= 1; |
| 1997 | break; |
| 1998 | case ALGORITHM_PARITY_N: |
| 1999 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2001 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2002 | } |
| 2003 | break; |
| 2004 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2005 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2006 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2007 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2008 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2009 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2010 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2011 | case ALGORITHM_ROTATING_N_RESTART: |
| 2012 | if (sh->pd_idx == raid_disks-1) |
| 2013 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2014 | else if (i > sh->pd_idx) |
| 2015 | i -= 2; /* D D P Q D */ |
| 2016 | break; |
| 2017 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2018 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2019 | if (sh->pd_idx == raid_disks-1) |
| 2020 | i--; /* Q D D D P */ |
| 2021 | else { |
| 2022 | /* D D P Q D */ |
| 2023 | if (i < sh->pd_idx) |
| 2024 | i += raid_disks; |
| 2025 | i -= (sh->pd_idx + 2); |
| 2026 | } |
| 2027 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2028 | case ALGORITHM_PARITY_0: |
| 2029 | i -= 2; |
| 2030 | break; |
| 2031 | case ALGORITHM_PARITY_N: |
| 2032 | break; |
| 2033 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2034 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2035 | if (sh->pd_idx == 0) |
| 2036 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2037 | else { |
| 2038 | /* D D Q P D */ |
| 2039 | if (i < sh->pd_idx) |
| 2040 | i += raid_disks; |
| 2041 | i -= (sh->pd_idx + 1); |
| 2042 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2043 | break; |
| 2044 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2045 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 2046 | if (i > sh->pd_idx) |
| 2047 | i--; |
| 2048 | break; |
| 2049 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 2050 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 2051 | if (i < sh->pd_idx) |
| 2052 | i += data_disks + 1; |
| 2053 | i -= (sh->pd_idx + 1); |
| 2054 | break; |
| 2055 | case ALGORITHM_PARITY_0_6: |
| 2056 | i -= 1; |
| 2057 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2058 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2059 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2060 | } |
| 2061 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | chunk_number = stripe * data_disks + i; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2065 | r_sector = chunk_number * sectors_per_chunk + chunk_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2067 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2068 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2069 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 2070 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2071 | printk(KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n", |
| 2072 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | return 0; |
| 2074 | } |
| 2075 | return r_sector; |
| 2076 | } |
| 2077 | |
| 2078 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2079 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2080 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2081 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2082 | { |
| 2083 | int i, pd_idx = sh->pd_idx, disks = sh->disks; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2084 | struct r5conf *conf = sh->raid_conf; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2085 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2086 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2087 | if (rcw) { |
| 2088 | /* if we are not expanding this is a proper write request, and |
| 2089 | * there will be bios with new data to be drained into the |
| 2090 | * stripe cache |
| 2091 | */ |
| 2092 | if (!expand) { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2093 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 2094 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2095 | } else |
| 2096 | sh->reconstruct_state = reconstruct_state_run; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2097 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2098 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2099 | |
| 2100 | for (i = disks; i--; ) { |
| 2101 | struct r5dev *dev = &sh->dev[i]; |
| 2102 | |
| 2103 | if (dev->towrite) { |
| 2104 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2105 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2106 | if (!expand) |
| 2107 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2108 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2109 | } |
| 2110 | } |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2111 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2112 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2113 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2114 | } else { |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2115 | BUG_ON(level == 6); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2116 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 2117 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
| 2118 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2119 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2120 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 2121 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2122 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2123 | |
| 2124 | for (i = disks; i--; ) { |
| 2125 | struct r5dev *dev = &sh->dev[i]; |
| 2126 | if (i == pd_idx) |
| 2127 | continue; |
| 2128 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2129 | if (dev->towrite && |
| 2130 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2131 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2132 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2133 | set_bit(R5_LOCKED, &dev->flags); |
| 2134 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2135 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2140 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2141 | * are in flight |
| 2142 | */ |
| 2143 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 2144 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2145 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2146 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2147 | if (level == 6) { |
| 2148 | int qd_idx = sh->qd_idx; |
| 2149 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 2150 | |
| 2151 | set_bit(R5_LOCKED, &dev->flags); |
| 2152 | clear_bit(R5_UPTODATE, &dev->flags); |
| 2153 | s->locked++; |
| 2154 | } |
| 2155 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2156 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2157 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2158 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2159 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | /* |
| 2162 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2163 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | * The bi_next chain must be in order. |
| 2165 | */ |
| 2166 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) |
| 2167 | { |
| 2168 | struct bio **bip; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2169 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2170 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2172 | pr_debug("adding bi b#%llu to stripe s#%llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | (unsigned long long)bi->bi_sector, |
| 2174 | (unsigned long long)sh->sector); |
| 2175 | |
| 2176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2178 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | bip = &sh->dev[dd_idx].towrite; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2180 | if (*bip == NULL && sh->dev[dd_idx].written == NULL) |
| 2181 | firstwrite = 1; |
| 2182 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | bip = &sh->dev[dd_idx].toread; |
| 2184 | while (*bip && (*bip)->bi_sector < bi->bi_sector) { |
| 2185 | if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) |
| 2186 | goto overlap; |
| 2187 | bip = & (*bip)->bi_next; |
| 2188 | } |
| 2189 | if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) |
| 2190 | goto overlap; |
| 2191 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2192 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | if (*bip) |
| 2194 | bi->bi_next = *bip; |
| 2195 | *bip = bi; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2196 | bi->bi_phys_segments++; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | if (forwrite) { |
| 2199 | /* check if page is covered */ |
| 2200 | sector_t sector = sh->dev[dd_idx].sector; |
| 2201 | for (bi=sh->dev[dd_idx].towrite; |
| 2202 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
| 2203 | bi && bi->bi_sector <= sector; |
| 2204 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
| 2205 | if (bi->bi_sector + (bi->bi_size>>9) >= sector) |
| 2206 | sector = bi->bi_sector + (bi->bi_size>>9); |
| 2207 | } |
| 2208 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
| 2209 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
| 2210 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2211 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 2212 | |
| 2213 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
| 2214 | (unsigned long long)(*bip)->bi_sector, |
| 2215 | (unsigned long long)sh->sector, dd_idx); |
| 2216 | |
| 2217 | if (conf->mddev->bitmap && firstwrite) { |
| 2218 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 2219 | STRIPE_SECTORS, 0); |
| 2220 | sh->bm_seq = conf->seq_flush+1; |
| 2221 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 2222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | return 1; |
| 2224 | |
| 2225 | overlap: |
| 2226 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
| 2227 | spin_unlock_irq(&conf->device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | return 0; |
| 2229 | } |
| 2230 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2231 | static void end_reshape(struct r5conf *conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2232 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2233 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2234 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2235 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2236 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2237 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2238 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2239 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2240 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2241 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2242 | raid5_compute_sector(conf, |
| 2243 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2244 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2245 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2246 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2247 | } |
| 2248 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2249 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2250 | handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2251 | struct stripe_head_state *s, int disks, |
| 2252 | struct bio **return_bi) |
| 2253 | { |
| 2254 | int i; |
| 2255 | for (i = disks; i--; ) { |
| 2256 | struct bio *bi; |
| 2257 | int bitmap_end = 0; |
| 2258 | |
| 2259 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2260 | struct md_rdev *rdev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2261 | rcu_read_lock(); |
| 2262 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 2263 | if (rdev && test_bit(In_sync, &rdev->flags)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2264 | atomic_inc(&rdev->nr_pending); |
| 2265 | else |
| 2266 | rdev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2267 | rcu_read_unlock(); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2268 | if (rdev) { |
| 2269 | if (!rdev_set_badblocks( |
| 2270 | rdev, |
| 2271 | sh->sector, |
| 2272 | STRIPE_SECTORS, 0)) |
| 2273 | md_error(conf->mddev, rdev); |
| 2274 | rdev_dec_pending(rdev, conf->mddev); |
| 2275 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2276 | } |
| 2277 | spin_lock_irq(&conf->device_lock); |
| 2278 | /* fail all writes first */ |
| 2279 | bi = sh->dev[i].towrite; |
| 2280 | sh->dev[i].towrite = NULL; |
| 2281 | if (bi) { |
| 2282 | s->to_write--; |
| 2283 | bitmap_end = 1; |
| 2284 | } |
| 2285 | |
| 2286 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2287 | wake_up(&conf->wait_for_overlap); |
| 2288 | |
| 2289 | while (bi && bi->bi_sector < |
| 2290 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2291 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
| 2292 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2293 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2294 | md_write_end(conf->mddev); |
| 2295 | bi->bi_next = *return_bi; |
| 2296 | *return_bi = bi; |
| 2297 | } |
| 2298 | bi = nextbi; |
| 2299 | } |
| 2300 | /* and fail all 'written' */ |
| 2301 | bi = sh->dev[i].written; |
| 2302 | sh->dev[i].written = NULL; |
| 2303 | if (bi) bitmap_end = 1; |
| 2304 | while (bi && bi->bi_sector < |
| 2305 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2306 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
| 2307 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2308 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2309 | md_write_end(conf->mddev); |
| 2310 | bi->bi_next = *return_bi; |
| 2311 | *return_bi = bi; |
| 2312 | } |
| 2313 | bi = bi2; |
| 2314 | } |
| 2315 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2316 | /* fail any reads if this device is non-operational and |
| 2317 | * the data has not reached the cache yet. |
| 2318 | */ |
| 2319 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
| 2320 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 2321 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2322 | bi = sh->dev[i].toread; |
| 2323 | sh->dev[i].toread = NULL; |
| 2324 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2325 | wake_up(&conf->wait_for_overlap); |
| 2326 | if (bi) s->to_read--; |
| 2327 | while (bi && bi->bi_sector < |
| 2328 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2329 | struct bio *nextbi = |
| 2330 | r5_next_bio(bi, sh->dev[i].sector); |
| 2331 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2332 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2333 | bi->bi_next = *return_bi; |
| 2334 | *return_bi = bi; |
| 2335 | } |
| 2336 | bi = nextbi; |
| 2337 | } |
| 2338 | } |
| 2339 | spin_unlock_irq(&conf->device_lock); |
| 2340 | if (bitmap_end) |
| 2341 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2342 | STRIPE_SECTORS, 0, 0); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2343 | /* If we were in the middle of a write the parity block might |
| 2344 | * still be locked - so just clear all R5_LOCKED flags |
| 2345 | */ |
| 2346 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2349 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2350 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2351 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2354 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2355 | handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2356 | struct stripe_head_state *s) |
| 2357 | { |
| 2358 | int abort = 0; |
| 2359 | int i; |
| 2360 | |
| 2361 | md_done_sync(conf->mddev, STRIPE_SECTORS, 0); |
| 2362 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 2363 | s->syncing = 0; |
| 2364 | /* There is nothing more to do for sync/check/repair. |
| 2365 | * For recover we need to record a bad block on all |
| 2366 | * non-sync devices, or abort the recovery |
| 2367 | */ |
| 2368 | if (!test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) |
| 2369 | return; |
| 2370 | /* During recovery devices cannot be removed, so locking and |
| 2371 | * refcounting of rdevs is not needed |
| 2372 | */ |
| 2373 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2374 | struct md_rdev *rdev = conf->disks[i].rdev; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2375 | if (!rdev |
| 2376 | || test_bit(Faulty, &rdev->flags) |
| 2377 | || test_bit(In_sync, &rdev->flags)) |
| 2378 | continue; |
| 2379 | if (!rdev_set_badblocks(rdev, sh->sector, |
| 2380 | STRIPE_SECTORS, 0)) |
| 2381 | abort = 1; |
| 2382 | } |
| 2383 | if (abort) { |
| 2384 | conf->recovery_disabled = conf->mddev->recovery_disabled; |
| 2385 | set_bit(MD_RECOVERY_INTR, &conf->mddev->recovery); |
| 2386 | } |
| 2387 | } |
| 2388 | |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2389 | /* 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] | 2390 | * to be read or computed to satisfy a request. |
| 2391 | * |
| 2392 | * Returns 1 when no more member devices need to be checked, otherwise returns |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2393 | * 0 to tell the loop in handle_stripe_fill to continue |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2394 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2395 | static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 2396 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2397 | { |
| 2398 | struct r5dev *dev = &sh->dev[disk_idx]; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2399 | struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], |
| 2400 | &sh->dev[s->failed_num[1]] }; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2401 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2402 | /* is the data in this block needed, and can we get it? */ |
| 2403 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2404 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2405 | (dev->toread || |
| 2406 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2407 | s->syncing || s->expanding || |
NeilBrown | 5d35e09 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2408 | (s->failed >= 1 && fdev[0]->toread) || |
| 2409 | (s->failed >= 2 && fdev[1]->toread) || |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2410 | (sh->raid_conf->level <= 5 && s->failed && fdev[0]->towrite && |
| 2411 | !test_bit(R5_OVERWRITE, &fdev[0]->flags)) || |
| 2412 | (sh->raid_conf->level == 6 && s->failed && s->to_write))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2413 | /* we would like to get this block, possibly by computing it, |
| 2414 | * otherwise read it if the backing disk is insync |
| 2415 | */ |
| 2416 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 2417 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
| 2418 | if ((s->uptodate == disks - 1) && |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2419 | (s->failed && (disk_idx == s->failed_num[0] || |
| 2420 | disk_idx == s->failed_num[1]))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2421 | /* have disk failed, and we're requested to fetch it; |
| 2422 | * do compute it |
| 2423 | */ |
| 2424 | pr_debug("Computing stripe %llu block %d\n", |
| 2425 | (unsigned long long)sh->sector, disk_idx); |
| 2426 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2427 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2428 | set_bit(R5_Wantcompute, &dev->flags); |
| 2429 | sh->ops.target = disk_idx; |
| 2430 | sh->ops.target2 = -1; /* no 2nd target */ |
| 2431 | s->req_compute = 1; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2432 | /* Careful: from this point on 'uptodate' is in the eye |
| 2433 | * of raid_run_ops which services 'compute' operations |
| 2434 | * before writes. R5_Wantcompute flags a block that will |
| 2435 | * be R5_UPTODATE by the time it is needed for a |
| 2436 | * subsequent operation. |
| 2437 | */ |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2438 | s->uptodate++; |
| 2439 | return 1; |
| 2440 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 2441 | /* Computing 2-failure is *very* expensive; only |
| 2442 | * do it if failed >= 2 |
| 2443 | */ |
| 2444 | int other; |
| 2445 | for (other = disks; other--; ) { |
| 2446 | if (other == disk_idx) |
| 2447 | continue; |
| 2448 | if (!test_bit(R5_UPTODATE, |
| 2449 | &sh->dev[other].flags)) |
| 2450 | break; |
| 2451 | } |
| 2452 | BUG_ON(other < 0); |
| 2453 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 2454 | (unsigned long long)sh->sector, |
| 2455 | disk_idx, other); |
| 2456 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2457 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2458 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 2459 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 2460 | sh->ops.target = disk_idx; |
| 2461 | sh->ops.target2 = other; |
| 2462 | s->uptodate += 2; |
| 2463 | s->req_compute = 1; |
| 2464 | return 1; |
| 2465 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 2466 | set_bit(R5_LOCKED, &dev->flags); |
| 2467 | set_bit(R5_Wantread, &dev->flags); |
| 2468 | s->locked++; |
| 2469 | pr_debug("Reading block %d (sync=%d)\n", |
| 2470 | disk_idx, s->syncing); |
| 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
| 2477 | /** |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2478 | * handle_stripe_fill - read or compute data to satisfy pending requests. |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2479 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2480 | static void handle_stripe_fill(struct stripe_head *sh, |
| 2481 | struct stripe_head_state *s, |
| 2482 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2483 | { |
| 2484 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2485 | |
| 2486 | /* look for blocks to read/compute, skip this if a compute |
| 2487 | * is already in flight, or if the stripe contents are in the |
| 2488 | * midst of changing due to a write |
| 2489 | */ |
| 2490 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
| 2491 | !sh->reconstruct_state) |
| 2492 | for (i = disks; i--; ) |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2493 | if (fetch_block(sh, s, i, disks)) |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2494 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2495 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2496 | } |
| 2497 | |
| 2498 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2499 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2500 | * any written block on an uptodate or failed drive can be returned. |
| 2501 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 2502 | * never LOCKED, so we don't need to test 'failed' directly. |
| 2503 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2504 | static void handle_stripe_clean_event(struct r5conf *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2505 | struct stripe_head *sh, int disks, struct bio **return_bi) |
| 2506 | { |
| 2507 | int i; |
| 2508 | struct r5dev *dev; |
| 2509 | |
| 2510 | for (i = disks; i--; ) |
| 2511 | if (sh->dev[i].written) { |
| 2512 | dev = &sh->dev[i]; |
| 2513 | if (!test_bit(R5_LOCKED, &dev->flags) && |
| 2514 | test_bit(R5_UPTODATE, &dev->flags)) { |
| 2515 | /* We can return any write requests */ |
| 2516 | struct bio *wbi, *wbi2; |
| 2517 | int bitmap_end = 0; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2518 | pr_debug("Return write for disc %d\n", i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2519 | spin_lock_irq(&conf->device_lock); |
| 2520 | wbi = dev->written; |
| 2521 | dev->written = NULL; |
| 2522 | while (wbi && wbi->bi_sector < |
| 2523 | dev->sector + STRIPE_SECTORS) { |
| 2524 | wbi2 = r5_next_bio(wbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2525 | if (!raid5_dec_bi_phys_segments(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2526 | md_write_end(conf->mddev); |
| 2527 | wbi->bi_next = *return_bi; |
| 2528 | *return_bi = wbi; |
| 2529 | } |
| 2530 | wbi = wbi2; |
| 2531 | } |
| 2532 | if (dev->towrite == NULL) |
| 2533 | bitmap_end = 1; |
| 2534 | spin_unlock_irq(&conf->device_lock); |
| 2535 | if (bitmap_end) |
| 2536 | bitmap_endwrite(conf->mddev->bitmap, |
| 2537 | sh->sector, |
| 2538 | STRIPE_SECTORS, |
| 2539 | !test_bit(STRIPE_DEGRADED, &sh->state), |
| 2540 | 0); |
| 2541 | } |
| 2542 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2543 | |
| 2544 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2545 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2546 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2549 | static void handle_stripe_dirtying(struct r5conf *conf, |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2550 | struct stripe_head *sh, |
| 2551 | struct stripe_head_state *s, |
| 2552 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2553 | { |
| 2554 | int rmw = 0, rcw = 0, i; |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2555 | if (conf->max_degraded == 2) { |
| 2556 | /* RAID6 requires 'rcw' in current implementation |
| 2557 | * Calculate the real rcw later - for now fake it |
| 2558 | * look like rcw is cheaper |
| 2559 | */ |
| 2560 | rcw = 1; rmw = 2; |
| 2561 | } else for (i = disks; i--; ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2562 | /* would I have to read this buffer for read_modify_write */ |
| 2563 | struct r5dev *dev = &sh->dev[i]; |
| 2564 | if ((dev->towrite || i == sh->pd_idx) && |
| 2565 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2566 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2567 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2568 | if (test_bit(R5_Insync, &dev->flags)) |
| 2569 | rmw++; |
| 2570 | else |
| 2571 | rmw += 2*disks; /* cannot read it */ |
| 2572 | } |
| 2573 | /* Would I have to read this buffer for reconstruct_write */ |
| 2574 | if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && |
| 2575 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2576 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2577 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2578 | if (test_bit(R5_Insync, &dev->flags)) rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2579 | else |
| 2580 | rcw += 2*disks; |
| 2581 | } |
| 2582 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2583 | pr_debug("for sector %llu, rmw=%d rcw=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2584 | (unsigned long long)sh->sector, rmw, rcw); |
| 2585 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2586 | if (rmw < rcw && rmw > 0) |
| 2587 | /* prefer read-modify-write, but need to get some data */ |
| 2588 | for (i = disks; i--; ) { |
| 2589 | struct r5dev *dev = &sh->dev[i]; |
| 2590 | if ((dev->towrite || i == sh->pd_idx) && |
| 2591 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2592 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2593 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2594 | test_bit(R5_Insync, &dev->flags)) { |
| 2595 | if ( |
| 2596 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2597 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2598 | "%d for r-m-w\n", i); |
| 2599 | set_bit(R5_LOCKED, &dev->flags); |
| 2600 | set_bit(R5_Wantread, &dev->flags); |
| 2601 | s->locked++; |
| 2602 | } else { |
| 2603 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2604 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2605 | } |
| 2606 | } |
| 2607 | } |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2608 | if (rcw <= rmw && rcw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2609 | /* want reconstruct write, but need to get some data */ |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2610 | rcw = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2611 | for (i = disks; i--; ) { |
| 2612 | struct r5dev *dev = &sh->dev[i]; |
| 2613 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2614 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2615 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2616 | !(test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2617 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2618 | rcw++; |
| 2619 | if (!test_bit(R5_Insync, &dev->flags)) |
| 2620 | continue; /* it's a failed drive */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2621 | if ( |
| 2622 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2623 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2624 | "%d for Reconstruct\n", i); |
| 2625 | set_bit(R5_LOCKED, &dev->flags); |
| 2626 | set_bit(R5_Wantread, &dev->flags); |
| 2627 | s->locked++; |
| 2628 | } else { |
| 2629 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2630 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2631 | } |
| 2632 | } |
| 2633 | } |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2634 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2635 | /* now if nothing is locked, and if we have enough data, |
| 2636 | * we can start a write request |
| 2637 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2638 | /* since handle_stripe can be called at any time we need to handle the |
| 2639 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2640 | * subsequent call wants to start a write request. raid_run_ops only |
| 2641 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2642 | * simultaneously. If this is not the case then new writes need to be |
| 2643 | * held off until the compute completes. |
| 2644 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2645 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2646 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
| 2647 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2648 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2651 | static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2652 | struct stripe_head_state *s, int disks) |
| 2653 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2654 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2655 | |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2656 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2657 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2658 | switch (sh->check_state) { |
| 2659 | case check_state_idle: |
| 2660 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2661 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2662 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2663 | sh->check_state = check_state_run; |
| 2664 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2665 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2666 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2667 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2668 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2669 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2670 | /* fall through */ |
| 2671 | case check_state_compute_result: |
| 2672 | sh->check_state = check_state_idle; |
| 2673 | if (!dev) |
| 2674 | dev = &sh->dev[sh->pd_idx]; |
| 2675 | |
| 2676 | /* check that a write has not made the stripe insync */ |
| 2677 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2678 | break; |
| 2679 | |
| 2680 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2681 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 2682 | BUG_ON(s->uptodate != disks); |
| 2683 | |
| 2684 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2685 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2686 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2687 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2688 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2689 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2690 | break; |
| 2691 | case check_state_run: |
| 2692 | break; /* we will be called again upon completion */ |
| 2693 | case check_state_check_result: |
| 2694 | sh->check_state = check_state_idle; |
| 2695 | |
| 2696 | /* if a failure occurred during the check operation, leave |
| 2697 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 2698 | */ |
| 2699 | if (s->failed) |
| 2700 | break; |
| 2701 | |
| 2702 | /* handle a successful check operation, if parity is correct |
| 2703 | * we are done. Otherwise update the mismatch count and repair |
| 2704 | * parity if !MD_RECOVERY_CHECK |
| 2705 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 2706 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2707 | /* parity is correct (on disc, |
| 2708 | * not in buffer any more) |
| 2709 | */ |
| 2710 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2711 | else { |
| 2712 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2713 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2714 | /* don't try to repair!! */ |
| 2715 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2716 | else { |
| 2717 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2718 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2719 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2720 | set_bit(R5_Wantcompute, |
| 2721 | &sh->dev[sh->pd_idx].flags); |
| 2722 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2723 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2724 | s->uptodate++; |
| 2725 | } |
| 2726 | } |
| 2727 | break; |
| 2728 | case check_state_compute_run: |
| 2729 | break; |
| 2730 | default: |
| 2731 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2732 | __func__, sh->check_state, |
| 2733 | (unsigned long long) sh->sector); |
| 2734 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2739 | static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2740 | struct stripe_head_state *s, |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2741 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2742 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2743 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2744 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2745 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2746 | |
| 2747 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2748 | |
| 2749 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2750 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2751 | /* Want to check and possibly repair P and Q. |
| 2752 | * However there could be one 'failed' device, in which |
| 2753 | * case we can only check one of them, possibly using the |
| 2754 | * other to generate missing data |
| 2755 | */ |
| 2756 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2757 | switch (sh->check_state) { |
| 2758 | case check_state_idle: |
| 2759 | /* start a new check operation if there are < 2 failures */ |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2760 | if (s->failed == s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2761 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2762 | * makes sense to check P (If anything else were failed, |
| 2763 | * we would have used P to recreate it). |
| 2764 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2765 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2766 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2767 | if (!s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2768 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2769 | * anything, so it makes sense to check it |
| 2770 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2771 | if (sh->check_state == check_state_run) |
| 2772 | sh->check_state = check_state_run_pq; |
| 2773 | else |
| 2774 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2775 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2776 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2777 | /* discard potentially stale zero_sum_result */ |
| 2778 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2779 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2780 | if (sh->check_state == check_state_run) { |
| 2781 | /* async_xor_zero_sum destroys the contents of P */ |
| 2782 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 2783 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2784 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2785 | if (sh->check_state >= check_state_run && |
| 2786 | sh->check_state <= check_state_run_pq) { |
| 2787 | /* async_syndrome_zero_sum preserves P and Q, so |
| 2788 | * no need to mark them !uptodate here |
| 2789 | */ |
| 2790 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 2791 | break; |
| 2792 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2793 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2794 | /* we have 2-disk failure */ |
| 2795 | BUG_ON(s->failed != 2); |
| 2796 | /* fall through */ |
| 2797 | case check_state_compute_result: |
| 2798 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2799 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2800 | /* check that a write has not made the stripe insync */ |
| 2801 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2802 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2803 | |
| 2804 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2805 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2806 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2807 | 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] | 2808 | if (s->failed == 2) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2809 | dev = &sh->dev[s->failed_num[1]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2810 | s->locked++; |
| 2811 | set_bit(R5_LOCKED, &dev->flags); |
| 2812 | set_bit(R5_Wantwrite, &dev->flags); |
| 2813 | } |
| 2814 | if (s->failed >= 1) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 2815 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2816 | s->locked++; |
| 2817 | set_bit(R5_LOCKED, &dev->flags); |
| 2818 | set_bit(R5_Wantwrite, &dev->flags); |
| 2819 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2820 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2821 | dev = &sh->dev[pd_idx]; |
| 2822 | s->locked++; |
| 2823 | set_bit(R5_LOCKED, &dev->flags); |
| 2824 | set_bit(R5_Wantwrite, &dev->flags); |
| 2825 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2826 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2827 | dev = &sh->dev[qd_idx]; |
| 2828 | s->locked++; |
| 2829 | set_bit(R5_LOCKED, &dev->flags); |
| 2830 | set_bit(R5_Wantwrite, &dev->flags); |
| 2831 | } |
| 2832 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 2833 | |
| 2834 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2835 | break; |
| 2836 | case check_state_run: |
| 2837 | case check_state_run_q: |
| 2838 | case check_state_run_pq: |
| 2839 | break; /* we will be called again upon completion */ |
| 2840 | case check_state_check_result: |
| 2841 | sh->check_state = check_state_idle; |
| 2842 | |
| 2843 | /* handle a successful check operation, if parity is correct |
| 2844 | * we are done. Otherwise update the mismatch count and repair |
| 2845 | * parity if !MD_RECOVERY_CHECK |
| 2846 | */ |
| 2847 | if (sh->ops.zero_sum_result == 0) { |
| 2848 | /* both parities are correct */ |
| 2849 | if (!s->failed) |
| 2850 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2851 | else { |
| 2852 | /* in contrast to the raid5 case we can validate |
| 2853 | * parity, but still have a failure to write |
| 2854 | * back |
| 2855 | */ |
| 2856 | sh->check_state = check_state_compute_result; |
| 2857 | /* Returning at this point means that we may go |
| 2858 | * off and bring p and/or q uptodate again so |
| 2859 | * we make sure to check zero_sum_result again |
| 2860 | * to verify if p or q need writeback |
| 2861 | */ |
| 2862 | } |
| 2863 | } else { |
| 2864 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2865 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2866 | /* don't try to repair!! */ |
| 2867 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2868 | else { |
| 2869 | int *target = &sh->ops.target; |
| 2870 | |
| 2871 | sh->ops.target = -1; |
| 2872 | sh->ops.target2 = -1; |
| 2873 | sh->check_state = check_state_compute_run; |
| 2874 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2875 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2876 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 2877 | set_bit(R5_Wantcompute, |
| 2878 | &sh->dev[pd_idx].flags); |
| 2879 | *target = pd_idx; |
| 2880 | target = &sh->ops.target2; |
| 2881 | s->uptodate++; |
| 2882 | } |
| 2883 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 2884 | set_bit(R5_Wantcompute, |
| 2885 | &sh->dev[qd_idx].flags); |
| 2886 | *target = qd_idx; |
| 2887 | s->uptodate++; |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | break; |
| 2892 | case check_state_compute_run: |
| 2893 | break; |
| 2894 | default: |
| 2895 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2896 | __func__, sh->check_state, |
| 2897 | (unsigned long long) sh->sector); |
| 2898 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2899 | } |
| 2900 | } |
| 2901 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2902 | static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2903 | { |
| 2904 | int i; |
| 2905 | |
| 2906 | /* We have read all the blocks in this stripe and now we need to |
| 2907 | * copy some of them into a target stripe for expand. |
| 2908 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2909 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2910 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 2911 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2912 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2913 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2914 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2915 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2916 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2917 | sector_t bn = compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2918 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 2919 | &dd_idx, NULL); |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 2920 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2921 | if (sh2 == NULL) |
| 2922 | /* so far only the early blocks of this stripe |
| 2923 | * have been requested. When later blocks |
| 2924 | * get requested, we will try again |
| 2925 | */ |
| 2926 | continue; |
| 2927 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 2928 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 2929 | /* must have already done this block */ |
| 2930 | release_stripe(sh2); |
| 2931 | continue; |
| 2932 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2933 | |
| 2934 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2935 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2936 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 2937 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2938 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2939 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2940 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 2941 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 2942 | for (j = 0; j < conf->raid_disks; j++) |
| 2943 | if (j != sh2->pd_idx && |
NeilBrown | 86c374b | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2944 | j != sh2->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2945 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 2946 | break; |
| 2947 | if (j == conf->raid_disks) { |
| 2948 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 2949 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 2950 | } |
| 2951 | release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2952 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2953 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 2954 | /* done submitting copies, wait for them to complete */ |
| 2955 | if (tx) { |
| 2956 | async_tx_ack(tx); |
| 2957 | dma_wait_for_async_tx(tx); |
| 2958 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | /* |
| 2963 | * handle_stripe - do things to a stripe. |
| 2964 | * |
| 2965 | * We lock the stripe and then examine the state of various bits |
| 2966 | * to see what needs to be done. |
| 2967 | * Possible results: |
| 2968 | * return some read request which now have data |
| 2969 | * return some write requests which are safely on disc |
| 2970 | * schedule a read on some buffers |
| 2971 | * schedule a write of some buffers |
| 2972 | * return confirmation of parity correctness |
| 2973 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | * buffers are taken off read_list or write_list, and bh_cache buffers |
| 2975 | * get BH_Lock set before the stripe lock is released. |
| 2976 | * |
| 2977 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2978 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2979 | static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2980 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2981 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 2982 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2983 | struct r5dev *dev; |
| 2984 | int i; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2985 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2986 | memset(s, 0, sizeof(*s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2987 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2988 | s->syncing = test_bit(STRIPE_SYNCING, &sh->state); |
| 2989 | s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 2990 | s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
| 2991 | s->failed_num[0] = -1; |
| 2992 | s->failed_num[1] = -1; |
| 2993 | |
| 2994 | /* Now to look around and see what can be done */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2995 | rcu_read_lock(); |
NeilBrown | c4c1663 | 2011-07-26 11:34:20 +1000 | [diff] [blame] | 2996 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2997 | for (i=disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2998 | struct md_rdev *rdev; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 2999 | sector_t first_bad; |
| 3000 | int bad_sectors; |
| 3001 | int is_bad = 0; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3002 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3003 | dev = &sh->dev[i]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3004 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3005 | pr_debug("check %d: state 0x%lx read %p write %p written %p\n", |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3006 | i, dev->flags, dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3007 | /* maybe we can reply to a read |
| 3008 | * |
| 3009 | * new wantfill requests are only permitted while |
| 3010 | * ops_complete_biofill is guaranteed to be inactive |
| 3011 | */ |
| 3012 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 3013 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 3014 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3015 | |
| 3016 | /* now count some things */ |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3017 | if (test_bit(R5_LOCKED, &dev->flags)) |
| 3018 | s->locked++; |
| 3019 | if (test_bit(R5_UPTODATE, &dev->flags)) |
| 3020 | s->uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3021 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3022 | s->compute++; |
| 3023 | BUG_ON(s->compute > 2); |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3024 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3025 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3026 | if (test_bit(R5_Wantfill, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3027 | s->to_fill++; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3028 | else if (dev->toread) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3029 | s->to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3030 | if (dev->towrite) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3031 | s->to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3032 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3033 | s->non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3034 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3035 | if (dev->written) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3036 | s->written++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3037 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3038 | if (rdev) { |
| 3039 | is_bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 3040 | &first_bad, &bad_sectors); |
| 3041 | if (s->blocked_rdev == NULL |
| 3042 | && (test_bit(Blocked, &rdev->flags) |
| 3043 | || is_bad < 0)) { |
| 3044 | if (is_bad < 0) |
| 3045 | set_bit(BlockedBadBlocks, |
| 3046 | &rdev->flags); |
| 3047 | s->blocked_rdev = rdev; |
| 3048 | atomic_inc(&rdev->nr_pending); |
| 3049 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3050 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3051 | clear_bit(R5_Insync, &dev->flags); |
| 3052 | if (!rdev) |
| 3053 | /* Not in-sync */; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3054 | else if (is_bad) { |
| 3055 | /* also not in-sync */ |
| 3056 | if (!test_bit(WriteErrorSeen, &rdev->flags)) { |
| 3057 | /* treat as in-sync, but with a read error |
| 3058 | * which we can now try to correct |
| 3059 | */ |
| 3060 | set_bit(R5_Insync, &dev->flags); |
| 3061 | set_bit(R5_ReadError, &dev->flags); |
| 3062 | } |
| 3063 | } else if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3064 | set_bit(R5_Insync, &dev->flags); |
NeilBrown | 355840e | 2011-10-26 10:31:04 +1100 | [diff] [blame] | 3065 | else if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3066 | /* in sync if before recovery_offset */ |
| 3067 | if (sh->sector + STRIPE_SECTORS <= rdev->recovery_offset) |
| 3068 | set_bit(R5_Insync, &dev->flags); |
| 3069 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3070 | if (test_bit(R5_WriteError, &dev->flags)) { |
| 3071 | clear_bit(R5_Insync, &dev->flags); |
| 3072 | if (!test_bit(Faulty, &rdev->flags)) { |
| 3073 | s->handle_bad_blocks = 1; |
| 3074 | atomic_inc(&rdev->nr_pending); |
| 3075 | } else |
| 3076 | clear_bit(R5_WriteError, &dev->flags); |
| 3077 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3078 | if (test_bit(R5_MadeGood, &dev->flags)) { |
| 3079 | if (!test_bit(Faulty, &rdev->flags)) { |
| 3080 | s->handle_bad_blocks = 1; |
| 3081 | atomic_inc(&rdev->nr_pending); |
| 3082 | } else |
| 3083 | clear_bit(R5_MadeGood, &dev->flags); |
| 3084 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3085 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3086 | /* The ReadError flag will just be confusing now */ |
| 3087 | clear_bit(R5_ReadError, &dev->flags); |
| 3088 | clear_bit(R5_ReWrite, &dev->flags); |
| 3089 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3090 | if (test_bit(R5_ReadError, &dev->flags)) |
| 3091 | clear_bit(R5_Insync, &dev->flags); |
| 3092 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3093 | if (s->failed < 2) |
| 3094 | s->failed_num[s->failed] = i; |
| 3095 | s->failed++; |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 3096 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3097 | } |
NeilBrown | c4c1663 | 2011-07-26 11:34:20 +1000 | [diff] [blame] | 3098 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3099 | rcu_read_unlock(); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3100 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3101 | |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3102 | static void handle_stripe(struct stripe_head *sh) |
| 3103 | { |
| 3104 | struct stripe_head_state s; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3105 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3106 | int i; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3107 | int prexor; |
| 3108 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3109 | struct r5dev *pdev, *qdev; |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3110 | |
| 3111 | clear_bit(STRIPE_HANDLE, &sh->state); |
| 3112 | if (test_and_set_bit(STRIPE_ACTIVE, &sh->state)) { |
| 3113 | /* already being handled, ensure it gets handled |
| 3114 | * again when current action finishes */ |
| 3115 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3116 | return; |
| 3117 | } |
| 3118 | |
| 3119 | if (test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 3120 | set_bit(STRIPE_SYNCING, &sh->state); |
| 3121 | clear_bit(STRIPE_INSYNC, &sh->state); |
| 3122 | } |
| 3123 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3124 | |
| 3125 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
| 3126 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
| 3127 | (unsigned long long)sh->sector, sh->state, |
| 3128 | atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, |
| 3129 | sh->check_state, sh->reconstruct_state); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 3130 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3131 | analyse_stripe(sh, &s); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3132 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3133 | if (s.handle_bad_blocks) { |
| 3134 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3135 | goto finish; |
| 3136 | } |
| 3137 | |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3138 | if (unlikely(s.blocked_rdev)) { |
| 3139 | if (s.syncing || s.expanding || s.expanded || |
| 3140 | s.to_write || s.written) { |
| 3141 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3142 | goto finish; |
| 3143 | } |
| 3144 | /* There is nothing for the blocked_rdev to block */ |
| 3145 | rdev_dec_pending(s.blocked_rdev, conf->mddev); |
| 3146 | s.blocked_rdev = NULL; |
| 3147 | } |
| 3148 | |
| 3149 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3150 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3151 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3152 | } |
| 3153 | |
| 3154 | pr_debug("locked=%d uptodate=%d to_read=%d" |
| 3155 | " to_write=%d failed=%d failed_num=%d,%d\n", |
| 3156 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 3157 | s.failed_num[0], s.failed_num[1]); |
| 3158 | /* check if the array has lost more than max_degraded devices and, |
| 3159 | * if so, some requests might need to be failed. |
| 3160 | */ |
| 3161 | if (s.failed > conf->max_degraded && s.to_read+s.to_write+s.written) |
| 3162 | handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3163 | if (s.failed > conf->max_degraded && s.syncing) |
| 3164 | handle_failed_sync(conf, sh, &s); |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3165 | |
| 3166 | /* |
| 3167 | * might be able to return some write requests if the parity blocks |
| 3168 | * are safe, or on a failed drive |
| 3169 | */ |
| 3170 | pdev = &sh->dev[sh->pd_idx]; |
| 3171 | s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) |
| 3172 | || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); |
| 3173 | qdev = &sh->dev[sh->qd_idx]; |
| 3174 | s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) |
| 3175 | || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) |
| 3176 | || conf->level < 6; |
| 3177 | |
| 3178 | if (s.written && |
| 3179 | (s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
| 3180 | && !test_bit(R5_LOCKED, &pdev->flags) |
| 3181 | && test_bit(R5_UPTODATE, &pdev->flags)))) && |
| 3182 | (s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
| 3183 | && !test_bit(R5_LOCKED, &qdev->flags) |
| 3184 | && test_bit(R5_UPTODATE, &qdev->flags))))) |
| 3185 | handle_stripe_clean_event(conf, sh, disks, &s.return_bi); |
| 3186 | |
| 3187 | /* Now we might consider reading some blocks, either to check/generate |
| 3188 | * parity, or to satisfy requests |
| 3189 | * or to load a block that is being partially written. |
| 3190 | */ |
| 3191 | if (s.to_read || s.non_overwrite |
| 3192 | || (conf->level == 6 && s.to_write && s.failed) |
| 3193 | || (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding) |
| 3194 | handle_stripe_fill(sh, &s, disks); |
| 3195 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3196 | /* Now we check to see if any write operations have recently |
| 3197 | * completed |
| 3198 | */ |
| 3199 | prexor = 0; |
| 3200 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
| 3201 | prexor = 1; |
| 3202 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 3203 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
| 3204 | sh->reconstruct_state = reconstruct_state_idle; |
| 3205 | |
| 3206 | /* All the 'written' buffers and the parity block are ready to |
| 3207 | * be written back to disk |
| 3208 | */ |
| 3209 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); |
| 3210 | BUG_ON(sh->qd_idx >= 0 && |
| 3211 | !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags)); |
| 3212 | for (i = disks; i--; ) { |
| 3213 | struct r5dev *dev = &sh->dev[i]; |
| 3214 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3215 | (i == sh->pd_idx || i == sh->qd_idx || |
| 3216 | dev->written)) { |
| 3217 | pr_debug("Writing block %d\n", i); |
| 3218 | set_bit(R5_Wantwrite, &dev->flags); |
| 3219 | if (prexor) |
| 3220 | continue; |
| 3221 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3222 | ((i == sh->pd_idx || i == sh->qd_idx) && |
| 3223 | s.failed == 0)) |
| 3224 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3225 | } |
| 3226 | } |
| 3227 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3228 | s.dec_preread_active = 1; |
| 3229 | } |
| 3230 | |
| 3231 | /* Now to consider new write requests and what else, if anything |
| 3232 | * should be read. We do not handle new writes when: |
| 3233 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 3234 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3235 | * block. |
| 3236 | */ |
| 3237 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
| 3238 | handle_stripe_dirtying(conf, sh, &s, disks); |
| 3239 | |
| 3240 | /* maybe we need to check and possibly fix the parity for this stripe |
| 3241 | * Any reads will already have been scheduled, so we just see if enough |
| 3242 | * data is available. The parity check is held off while parity |
| 3243 | * dependent operations are in flight. |
| 3244 | */ |
| 3245 | if (sh->check_state || |
| 3246 | (s.syncing && s.locked == 0 && |
| 3247 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 3248 | !test_bit(STRIPE_INSYNC, &sh->state))) { |
| 3249 | if (conf->level == 6) |
| 3250 | handle_parity_checks6(conf, sh, &s, disks); |
| 3251 | else |
| 3252 | handle_parity_checks5(conf, sh, &s, disks); |
| 3253 | } |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3254 | |
| 3255 | if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { |
| 3256 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3257 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 3258 | } |
| 3259 | |
| 3260 | /* If the failed drives are just a ReadError, then we might need |
| 3261 | * to progress the repair/check process |
| 3262 | */ |
| 3263 | if (s.failed <= conf->max_degraded && !conf->mddev->ro) |
| 3264 | for (i = 0; i < s.failed; i++) { |
| 3265 | struct r5dev *dev = &sh->dev[s.failed_num[i]]; |
| 3266 | if (test_bit(R5_ReadError, &dev->flags) |
| 3267 | && !test_bit(R5_LOCKED, &dev->flags) |
| 3268 | && test_bit(R5_UPTODATE, &dev->flags) |
| 3269 | ) { |
| 3270 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3271 | set_bit(R5_Wantwrite, &dev->flags); |
| 3272 | set_bit(R5_ReWrite, &dev->flags); |
| 3273 | set_bit(R5_LOCKED, &dev->flags); |
| 3274 | s.locked++; |
| 3275 | } else { |
| 3276 | /* let's read it back */ |
| 3277 | set_bit(R5_Wantread, &dev->flags); |
| 3278 | set_bit(R5_LOCKED, &dev->flags); |
| 3279 | s.locked++; |
| 3280 | } |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3285 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3286 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 3287 | struct stripe_head *sh_src |
| 3288 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
| 3289 | if (sh_src && test_bit(STRIPE_EXPAND_SOURCE, &sh_src->state)) { |
| 3290 | /* sh cannot be written until sh_src has been read. |
| 3291 | * so arrange for sh to be delayed a little |
| 3292 | */ |
| 3293 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3294 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3295 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3296 | &sh_src->state)) |
| 3297 | atomic_inc(&conf->preread_active_stripes); |
| 3298 | release_stripe(sh_src); |
| 3299 | goto finish; |
| 3300 | } |
| 3301 | if (sh_src) |
| 3302 | release_stripe(sh_src); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3303 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3304 | sh->reconstruct_state = reconstruct_state_idle; |
| 3305 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 3306 | for (i = conf->raid_disks; i--; ) { |
| 3307 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 3308 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3309 | s.locked++; |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 3314 | !sh->reconstruct_state) { |
| 3315 | /* Need to write out all blocks after computing parity */ |
| 3316 | sh->disks = conf->raid_disks; |
| 3317 | stripe_set_idx(sh->sector, conf, 0, sh); |
| 3318 | schedule_reconstruction(sh, &s, 1, 1); |
| 3319 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
| 3320 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3321 | atomic_dec(&conf->reshape_stripes); |
| 3322 | wake_up(&conf->wait_for_overlap); |
| 3323 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3324 | } |
| 3325 | |
| 3326 | if (s.expanding && s.locked == 0 && |
| 3327 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
| 3328 | handle_stripe_expansion(conf, sh); |
| 3329 | |
| 3330 | finish: |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3331 | /* wait for this device to become unblocked */ |
NeilBrown | 43220aa | 2011-08-31 12:49:14 +1000 | [diff] [blame] | 3332 | if (conf->mddev->external && unlikely(s.blocked_rdev)) |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3333 | md_wait_for_blocked_rdev(s.blocked_rdev, conf->mddev); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3334 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3335 | if (s.handle_bad_blocks) |
| 3336 | for (i = disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3337 | struct md_rdev *rdev; |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3338 | struct r5dev *dev = &sh->dev[i]; |
| 3339 | if (test_and_clear_bit(R5_WriteError, &dev->flags)) { |
| 3340 | /* We own a safe reference to the rdev */ |
| 3341 | rdev = conf->disks[i].rdev; |
| 3342 | if (!rdev_set_badblocks(rdev, sh->sector, |
| 3343 | STRIPE_SECTORS, 0)) |
| 3344 | md_error(conf->mddev, rdev); |
| 3345 | rdev_dec_pending(rdev, conf->mddev); |
| 3346 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 3347 | if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { |
| 3348 | rdev = conf->disks[i].rdev; |
| 3349 | rdev_clear_badblocks(rdev, sh->sector, |
| 3350 | STRIPE_SECTORS); |
| 3351 | rdev_dec_pending(rdev, conf->mddev); |
| 3352 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3353 | } |
| 3354 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3355 | if (s.ops_request) |
| 3356 | raid_run_ops(sh, s.ops_request); |
| 3357 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 3358 | ops_run_io(sh, &s); |
| 3359 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3360 | if (s.dec_preread_active) { |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3361 | /* 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] | 3362 | * is waiting on a flush, it won't continue until the writes |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3363 | * have actually been submitted. |
| 3364 | */ |
| 3365 | atomic_dec(&conf->preread_active_stripes); |
| 3366 | if (atomic_read(&conf->preread_active_stripes) < |
| 3367 | IO_THRESHOLD) |
| 3368 | md_wakeup_thread(conf->mddev->thread); |
| 3369 | } |
| 3370 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 3371 | return_io(s.return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3372 | |
NeilBrown | c4c1663 | 2011-07-26 11:34:20 +1000 | [diff] [blame] | 3373 | clear_bit(STRIPE_ACTIVE, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3374 | } |
| 3375 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3376 | static void raid5_activate_delayed(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | { |
| 3378 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 3379 | while (!list_empty(&conf->delayed_list)) { |
| 3380 | struct list_head *l = conf->delayed_list.next; |
| 3381 | struct stripe_head *sh; |
| 3382 | sh = list_entry(l, struct stripe_head, lru); |
| 3383 | list_del_init(l); |
| 3384 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3385 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3386 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3387 | list_add_tail(&sh->lru, &conf->hold_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | } |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 3389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3392 | static void activate_bit_delay(struct r5conf *conf) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3393 | { |
| 3394 | /* device_lock is held */ |
| 3395 | struct list_head head; |
| 3396 | list_add(&head, &conf->bitmap_list); |
| 3397 | list_del_init(&conf->bitmap_list); |
| 3398 | while (!list_empty(&head)) { |
| 3399 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
| 3400 | list_del_init(&sh->lru); |
| 3401 | atomic_inc(&sh->count); |
| 3402 | __release_stripe(conf, sh); |
| 3403 | } |
| 3404 | } |
| 3405 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3406 | int md_raid5_congested(struct mddev *mddev, int bits) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3407 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3408 | struct r5conf *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3409 | |
| 3410 | /* No difference between reads and writes. Just check |
| 3411 | * how busy the stripe_cache is |
| 3412 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 3413 | |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3414 | if (conf->inactive_blocked) |
| 3415 | return 1; |
| 3416 | if (conf->quiesce) |
| 3417 | return 1; |
| 3418 | if (list_empty_careful(&conf->inactive_list)) |
| 3419 | return 1; |
| 3420 | |
| 3421 | return 0; |
| 3422 | } |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3423 | EXPORT_SYMBOL_GPL(md_raid5_congested); |
| 3424 | |
| 3425 | static int raid5_congested(void *data, int bits) |
| 3426 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3427 | struct mddev *mddev = data; |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 3428 | |
| 3429 | return mddev_congested(mddev, bits) || |
| 3430 | md_raid5_congested(mddev, bits); |
| 3431 | } |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3432 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3433 | /* We want read requests to align with chunks where possible, |
| 3434 | * but write requests don't need to. |
| 3435 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3436 | static int raid5_mergeable_bvec(struct request_queue *q, |
| 3437 | struct bvec_merge_data *bvm, |
| 3438 | struct bio_vec *biovec) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3439 | { |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3440 | struct mddev *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3441 | 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] | 3442 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3443 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3444 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3445 | |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3446 | if ((bvm->bi_rw & 1) == WRITE) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3447 | return biovec->bv_len; /* always allow writes to be mergeable */ |
| 3448 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3449 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3450 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3451 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 3452 | if (max < 0) max = 0; |
| 3453 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 3454 | return biovec->bv_len; |
| 3455 | else |
| 3456 | return max; |
| 3457 | } |
| 3458 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3459 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3460 | 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] | 3461 | { |
| 3462 | sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3463 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3464 | unsigned int bio_sectors = bio->bi_size >> 9; |
| 3465 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3466 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3467 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3468 | return chunk_sectors >= |
| 3469 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 3470 | } |
| 3471 | |
| 3472 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3473 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 3474 | * later sampled by raid5d. |
| 3475 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3476 | 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] | 3477 | { |
| 3478 | unsigned long flags; |
| 3479 | |
| 3480 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3481 | |
| 3482 | bi->bi_next = conf->retry_read_aligned_list; |
| 3483 | conf->retry_read_aligned_list = bi; |
| 3484 | |
| 3485 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3486 | md_wakeup_thread(conf->mddev->thread); |
| 3487 | } |
| 3488 | |
| 3489 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3490 | static struct bio *remove_bio_from_retry(struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3491 | { |
| 3492 | struct bio *bi; |
| 3493 | |
| 3494 | bi = conf->retry_read_aligned; |
| 3495 | if (bi) { |
| 3496 | conf->retry_read_aligned = NULL; |
| 3497 | return bi; |
| 3498 | } |
| 3499 | bi = conf->retry_read_aligned_list; |
| 3500 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3501 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3502 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 3503 | /* |
| 3504 | * this sets the active strip count to 1 and the processed |
| 3505 | * strip count to zero (upper 8 bits) |
| 3506 | */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3507 | bi->bi_phys_segments = 1; /* biased count of active stripes */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | return bi; |
| 3511 | } |
| 3512 | |
| 3513 | |
| 3514 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3515 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 3516 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 3517 | * first). |
| 3518 | * If the read failed.. |
| 3519 | */ |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3520 | static void raid5_align_endio(struct bio *bi, int error) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3521 | { |
| 3522 | struct bio* raid_bi = bi->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3523 | struct mddev *mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3524 | struct r5conf *conf; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3525 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3526 | struct md_rdev *rdev; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3527 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3528 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3529 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3530 | rdev = (void*)raid_bi->bi_next; |
| 3531 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 3532 | mddev = rdev->mddev; |
| 3533 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3534 | |
| 3535 | rdev_dec_pending(rdev, conf->mddev); |
| 3536 | |
| 3537 | if (!error && uptodate) { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3538 | bio_endio(raid_bi, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3539 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 3540 | wake_up(&conf->wait_for_stripe); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3541 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3545 | 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] | 3546 | |
| 3547 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3548 | } |
| 3549 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3550 | static int bio_fits_rdev(struct bio *bi) |
| 3551 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3552 | struct request_queue *q = bdev_get_queue(bi->bi_bdev); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3553 | |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 3554 | if ((bi->bi_size>>9) > queue_max_sectors(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3555 | return 0; |
| 3556 | blk_recount_segments(q, bi); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 3557 | if (bi->bi_phys_segments > queue_max_segments(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3558 | return 0; |
| 3559 | |
| 3560 | if (q->merge_bvec_fn) |
| 3561 | /* it's too hard to apply the merge_bvec_fn at this stage, |
| 3562 | * just just give up |
| 3563 | */ |
| 3564 | return 0; |
| 3565 | |
| 3566 | return 1; |
| 3567 | } |
| 3568 | |
| 3569 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3570 | 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] | 3571 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3572 | struct r5conf *conf = mddev->private; |
NeilBrown | 8553fe7ec | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 3573 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3574 | struct bio* align_bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3575 | struct md_rdev *rdev; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3576 | |
| 3577 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3578 | pr_debug("chunk_aligned_read : non aligned\n"); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3579 | return 0; |
| 3580 | } |
| 3581 | /* |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 3582 | * 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] | 3583 | */ |
NeilBrown | a167f66 | 2010-10-26 18:31:13 +1100 | [diff] [blame] | 3584 | align_bi = bio_clone_mddev(raid_bio, GFP_NOIO, mddev); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3585 | if (!align_bi) |
| 3586 | return 0; |
| 3587 | /* |
| 3588 | * set bi_end_io to a new function, and set bi_private to the |
| 3589 | * original bio. |
| 3590 | */ |
| 3591 | align_bi->bi_end_io = raid5_align_endio; |
| 3592 | align_bi->bi_private = raid_bio; |
| 3593 | /* |
| 3594 | * compute position |
| 3595 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3596 | align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, |
| 3597 | 0, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3598 | &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3599 | |
| 3600 | rcu_read_lock(); |
| 3601 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 3602 | if (rdev && test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3603 | sector_t first_bad; |
| 3604 | int bad_sectors; |
| 3605 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3606 | atomic_inc(&rdev->nr_pending); |
| 3607 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3608 | raid_bio->bi_next = (void*)rdev; |
| 3609 | align_bi->bi_bdev = rdev->bdev; |
| 3610 | align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); |
| 3611 | align_bi->bi_sector += rdev->data_offset; |
| 3612 | |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3613 | if (!bio_fits_rdev(align_bi) || |
| 3614 | is_badblock(rdev, align_bi->bi_sector, align_bi->bi_size>>9, |
| 3615 | &first_bad, &bad_sectors)) { |
| 3616 | /* too big in some way, or has a known bad block */ |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3617 | bio_put(align_bi); |
| 3618 | rdev_dec_pending(rdev, mddev); |
| 3619 | return 0; |
| 3620 | } |
| 3621 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3622 | spin_lock_irq(&conf->device_lock); |
| 3623 | wait_event_lock_irq(conf->wait_for_stripe, |
| 3624 | conf->quiesce == 0, |
| 3625 | conf->device_lock, /* nothing */); |
| 3626 | atomic_inc(&conf->active_aligned_reads); |
| 3627 | spin_unlock_irq(&conf->device_lock); |
| 3628 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3629 | generic_make_request(align_bi); |
| 3630 | return 1; |
| 3631 | } else { |
| 3632 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3633 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3634 | return 0; |
| 3635 | } |
| 3636 | } |
| 3637 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3638 | /* __get_priority_stripe - get the next stripe to process |
| 3639 | * |
| 3640 | * Full stripe writes are allowed to pass preread active stripes up until |
| 3641 | * the bypass_threshold is exceeded. In general the bypass_count |
| 3642 | * increments when the handle_list is handled before the hold_list; however, it |
| 3643 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 3644 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 3645 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 3646 | * handle_list. |
| 3647 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3648 | static struct stripe_head *__get_priority_stripe(struct r5conf *conf) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3649 | { |
| 3650 | struct stripe_head *sh; |
| 3651 | |
| 3652 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 3653 | __func__, |
| 3654 | list_empty(&conf->handle_list) ? "empty" : "busy", |
| 3655 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 3656 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 3657 | |
| 3658 | if (!list_empty(&conf->handle_list)) { |
| 3659 | sh = list_entry(conf->handle_list.next, typeof(*sh), lru); |
| 3660 | |
| 3661 | if (list_empty(&conf->hold_list)) |
| 3662 | conf->bypass_count = 0; |
| 3663 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 3664 | if (conf->hold_list.next == conf->last_hold) |
| 3665 | conf->bypass_count++; |
| 3666 | else { |
| 3667 | conf->last_hold = conf->hold_list.next; |
| 3668 | conf->bypass_count -= conf->bypass_threshold; |
| 3669 | if (conf->bypass_count < 0) |
| 3670 | conf->bypass_count = 0; |
| 3671 | } |
| 3672 | } |
| 3673 | } else if (!list_empty(&conf->hold_list) && |
| 3674 | ((conf->bypass_threshold && |
| 3675 | conf->bypass_count > conf->bypass_threshold) || |
| 3676 | atomic_read(&conf->pending_full_writes) == 0)) { |
| 3677 | sh = list_entry(conf->hold_list.next, |
| 3678 | typeof(*sh), lru); |
| 3679 | conf->bypass_count -= conf->bypass_threshold; |
| 3680 | if (conf->bypass_count < 0) |
| 3681 | conf->bypass_count = 0; |
| 3682 | } else |
| 3683 | return NULL; |
| 3684 | |
| 3685 | list_del_init(&sh->lru); |
| 3686 | atomic_inc(&sh->count); |
| 3687 | BUG_ON(atomic_read(&sh->count) != 1); |
| 3688 | return sh; |
| 3689 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3690 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame^] | 3691 | static void make_request(struct mddev *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3693 | struct r5conf *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3694 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | sector_t new_sector; |
| 3696 | sector_t logical_sector, last_sector; |
| 3697 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 3698 | const int rw = bio_data_dir(bi); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 3699 | int remaining; |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 3700 | int plugged; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 3702 | if (unlikely(bi->bi_rw & REQ_FLUSH)) { |
| 3703 | md_flush_request(mddev, bi); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 3704 | return; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 3705 | } |
| 3706 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 3707 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3708 | |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 3709 | if (rw == READ && |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3710 | mddev->reshape_position == MaxSector && |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 3711 | chunk_aligned_read(mddev,bi)) |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 3712 | return; |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 3715 | last_sector = bi->bi_sector + (bi->bi_size>>9); |
| 3716 | bi->bi_next = NULL; |
| 3717 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3718 | |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 3719 | plugged = mddev_check_plugged(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
| 3721 | DEFINE_WAIT(w); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3722 | int disks, data_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3723 | int previous; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3724 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3725 | retry: |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3726 | previous = 0; |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3727 | disks = conf->raid_disks; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3728 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3729 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3730 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3731 | * 64bit on a 32bit platform, and so it might be |
| 3732 | * possible to see a half-updated value |
Jesper Juhl | aeb878b | 2011-04-10 18:06:17 +0200 | [diff] [blame] | 3733 | * Of course reshape_progress could change after |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3734 | * the lock is dropped, so once we get a reference |
| 3735 | * to the stripe that we think it is, we will have |
| 3736 | * to check again. |
| 3737 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3738 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3739 | if (mddev->delta_disks < 0 |
| 3740 | ? logical_sector < conf->reshape_progress |
| 3741 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3742 | disks = conf->previous_raid_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3743 | previous = 1; |
| 3744 | } else { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3745 | if (mddev->delta_disks < 0 |
| 3746 | ? logical_sector < conf->reshape_safe |
| 3747 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3748 | spin_unlock_irq(&conf->device_lock); |
| 3749 | schedule(); |
| 3750 | goto retry; |
| 3751 | } |
| 3752 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3753 | spin_unlock_irq(&conf->device_lock); |
| 3754 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3755 | data_disks = disks - conf->max_degraded; |
| 3756 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3757 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 3758 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3759 | &dd_idx, NULL); |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 3760 | pr_debug("raid456: make_request, sector %llu logical %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | (unsigned long long)new_sector, |
| 3762 | (unsigned long long)logical_sector); |
| 3763 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3764 | sh = get_active_stripe(conf, new_sector, previous, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3765 | (bi->bi_rw&RWA_MASK), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3767 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3768 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3769 | * stripe, so we must do the range check again. |
| 3770 | * Expansion could still move past after this |
| 3771 | * test, but as we are holding a reference to |
| 3772 | * 'sh', we know that if that happens, |
| 3773 | * STRIPE_EXPANDING will get set and the expansion |
| 3774 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3775 | */ |
| 3776 | int must_retry = 0; |
| 3777 | spin_lock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3778 | if (mddev->delta_disks < 0 |
| 3779 | ? logical_sector >= conf->reshape_progress |
| 3780 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3781 | /* mismatch, need to try again */ |
| 3782 | must_retry = 1; |
| 3783 | spin_unlock_irq(&conf->device_lock); |
| 3784 | if (must_retry) { |
| 3785 | release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 3786 | schedule(); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3787 | goto retry; |
| 3788 | } |
| 3789 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3790 | |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 3791 | if (rw == WRITE && |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3792 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3793 | logical_sector < mddev->suspend_hi) { |
| 3794 | release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3795 | /* As the suspend_* range is controlled by |
| 3796 | * userspace, we want an interruptible |
| 3797 | * wait. |
| 3798 | */ |
| 3799 | flush_signals(current); |
| 3800 | prepare_to_wait(&conf->wait_for_overlap, |
| 3801 | &w, TASK_INTERRUPTIBLE); |
| 3802 | if (logical_sector >= mddev->suspend_lo && |
| 3803 | logical_sector < mddev->suspend_hi) |
| 3804 | schedule(); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3805 | goto retry; |
| 3806 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3807 | |
| 3808 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 3809 | !add_stripe_bio(sh, bi, dd_idx, rw)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3810 | /* Stripe is busy expanding or |
| 3811 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | * and wait a while |
| 3813 | */ |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 3814 | md_wakeup_thread(mddev->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | release_stripe(sh); |
| 3816 | schedule(); |
| 3817 | goto retry; |
| 3818 | } |
| 3819 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 3820 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3821 | clear_bit(STRIPE_DELAYED, &sh->state); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 3822 | if ((bi->bi_rw & REQ_SYNC) && |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3823 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3824 | atomic_inc(&conf->preread_active_stripes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | } else { |
| 3827 | /* cannot get stripe for read-ahead, just give-up */ |
| 3828 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
| 3829 | finish_wait(&conf->wait_for_overlap, &w); |
| 3830 | break; |
| 3831 | } |
| 3832 | |
| 3833 | } |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 3834 | if (!plugged) |
| 3835 | md_wakeup_thread(mddev->thread); |
| 3836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 3838 | remaining = raid5_dec_bi_phys_segments(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 3839 | spin_unlock_irq(&conf->device_lock); |
| 3840 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3842 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3844 | |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 3845 | bio_endio(bi, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | } |
| 3848 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3849 | 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] | 3850 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3851 | 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] | 3852 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3853 | /* reshaping is quite different to recovery/resync so it is |
| 3854 | * handled quite separately ... here. |
| 3855 | * |
| 3856 | * On each call to sync_request, we gather one chunk worth of |
| 3857 | * destination stripes and flag them as expanding. |
| 3858 | * Then we find all the source stripes and request reads. |
| 3859 | * As the reads complete, handle_stripe will copy the data |
| 3860 | * into the destination stripe and release that stripe. |
| 3861 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3862 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3864 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3865 | int raid_disks = conf->previous_raid_disks; |
| 3866 | int data_disks = raid_disks - conf->max_degraded; |
| 3867 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3868 | int i; |
| 3869 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 3870 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 3871 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3872 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3873 | struct list_head stripes; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3874 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3875 | if (sector_nr == 0) { |
| 3876 | /* If restarting in the middle, skip the initial sectors */ |
| 3877 | if (mddev->delta_disks < 0 && |
| 3878 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 3879 | sector_nr = raid5_size(mddev, 0, 0) |
| 3880 | - conf->reshape_progress; |
NeilBrown | a639755 | 2009-08-13 10:13:00 +1000 | [diff] [blame] | 3881 | } else if (mddev->delta_disks >= 0 && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3882 | conf->reshape_progress > 0) |
| 3883 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3884 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3885 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 3886 | mddev->curr_resync_completed = sector_nr; |
| 3887 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3888 | *skipped = 1; |
| 3889 | return sector_nr; |
| 3890 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3891 | } |
| 3892 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3893 | /* We need to process a full chunk at a time. |
| 3894 | * If old and new chunk sizes differ, we need to process the |
| 3895 | * largest of these |
| 3896 | */ |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3897 | if (mddev->new_chunk_sectors > mddev->chunk_sectors) |
| 3898 | reshape_sectors = mddev->new_chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3899 | else |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3900 | reshape_sectors = mddev->chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3901 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3902 | /* we update the metadata when there is more than 3Meg |
| 3903 | * in the block range (that is rather arbitrary, should |
| 3904 | * probably be time based) or when the data about to be |
| 3905 | * copied would over-write the source of the data at |
| 3906 | * the front of the range. |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3907 | * i.e. one new_stripe along from reshape_progress new_maps |
| 3908 | * to after where reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3909 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3910 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3911 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 3912 | readpos = conf->reshape_progress; |
| 3913 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3914 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3915 | sector_div(safepos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3916 | if (mddev->delta_disks < 0) { |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 3917 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 3918 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3919 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3920 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3921 | writepos += reshape_sectors; |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 3922 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 3923 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3924 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3925 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 3926 | /* 'writepos' is the most advanced device address we might write. |
| 3927 | * 'readpos' is the least advanced device address we might read. |
| 3928 | * 'safepos' is the least address recorded in the metadata as having |
| 3929 | * been reshaped. |
| 3930 | * If 'readpos' is behind 'writepos', then there is no way that we can |
| 3931 | * ensure safety in the face of a crash - that must be done by userspace |
| 3932 | * making a backup of the data. So in that case there is no particular |
| 3933 | * rush to update metadata. |
| 3934 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 3935 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 3936 | * we can be safe in the event of a crash. |
| 3937 | * So we insist on updating metadata if safepos is behind writepos and |
| 3938 | * readpos is beyond writepos. |
| 3939 | * In any case, update the metadata every 10 seconds. |
| 3940 | * Maybe that number should be configurable, but I'm not sure it is |
| 3941 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 3942 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3943 | if ((mddev->delta_disks < 0 |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 3944 | ? (safepos > writepos && readpos < writepos) |
| 3945 | : (safepos < writepos && readpos > writepos)) || |
| 3946 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3947 | /* Cannot proceed until we've updated the superblock... */ |
| 3948 | wait_event(conf->wait_for_overlap, |
| 3949 | atomic_read(&conf->reshape_stripes)==0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3950 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 3951 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 3952 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3953 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3954 | md_wakeup_thread(mddev->thread); |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 3955 | wait_event(mddev->sb_wait, mddev->flags == 0 || |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3956 | kthread_should_stop()); |
| 3957 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3958 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3959 | spin_unlock_irq(&conf->device_lock); |
| 3960 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 3961 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 3964 | if (mddev->delta_disks < 0) { |
| 3965 | BUG_ON(conf->reshape_progress == 0); |
| 3966 | stripe_addr = writepos; |
| 3967 | BUG_ON((mddev->dev_sectors & |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3968 | ~((sector_t)reshape_sectors - 1)) |
| 3969 | - reshape_sectors - stripe_addr |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 3970 | != sector_nr); |
| 3971 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3972 | BUG_ON(writepos != sector_nr + reshape_sectors); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 3973 | stripe_addr = sector_nr; |
| 3974 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3975 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 3976 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3977 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 3978 | int skipped_disk = 0; |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3979 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3980 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 3981 | atomic_inc(&conf->reshape_stripes); |
| 3982 | /* If any of this stripe is beyond the end of the old |
| 3983 | * array, then we need to zero those blocks |
| 3984 | */ |
| 3985 | for (j=sh->disks; j--;) { |
| 3986 | sector_t s; |
| 3987 | if (j == sh->pd_idx) |
| 3988 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3989 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3990 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3991 | continue; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3992 | s = compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 3993 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 3994 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 3995 | continue; |
| 3996 | } |
| 3997 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 3998 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 3999 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 4000 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4001 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4002 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4003 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4004 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4005 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4006 | } |
| 4007 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4008 | if (mddev->delta_disks < 0) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4009 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4010 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4011 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4012 | spin_unlock_irq(&conf->device_lock); |
| 4013 | /* Ok, those stripe are ready. We can start scheduling |
| 4014 | * reads on the source stripes. |
| 4015 | * The source stripes are determined by mapping the first and last |
| 4016 | * block on the destination stripes. |
| 4017 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4018 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4019 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4020 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4021 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 4022 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4023 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4024 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4025 | if (last_sector >= mddev->dev_sectors) |
| 4026 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4027 | while (first_sector <= last_sector) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4028 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4029 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4030 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4031 | release_stripe(sh); |
| 4032 | first_sector += STRIPE_SECTORS; |
| 4033 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4034 | /* Now that the sources are clearly marked, we can release |
| 4035 | * the destination stripes |
| 4036 | */ |
| 4037 | while (!list_empty(&stripes)) { |
| 4038 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 4039 | list_del_init(&sh->lru); |
| 4040 | release_stripe(sh); |
| 4041 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4042 | /* If this takes us to the resync_max point where we have to pause, |
| 4043 | * then we need to write out the superblock. |
| 4044 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4045 | sector_nr += reshape_sectors; |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 4046 | if ((sector_nr - mddev->curr_resync_completed) * 2 |
| 4047 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4048 | /* Cannot proceed until we've updated the superblock... */ |
| 4049 | wait_event(conf->wait_for_overlap, |
| 4050 | atomic_read(&conf->reshape_stripes) == 0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4051 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 4052 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4053 | conf->reshape_checkpoint = jiffies; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4054 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 4055 | md_wakeup_thread(mddev->thread); |
| 4056 | wait_event(mddev->sb_wait, |
| 4057 | !test_bit(MD_CHANGE_DEVS, &mddev->flags) |
| 4058 | || kthread_should_stop()); |
| 4059 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4060 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4061 | spin_unlock_irq(&conf->device_lock); |
| 4062 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4063 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4064 | } |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4065 | return reshape_sectors; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | /* FIXME go_faster isn't used */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4069 | 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] | 4070 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4071 | struct r5conf *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4072 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4073 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 4074 | sector_t sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4075 | int still_degraded = 0; |
| 4076 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4078 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | /* just being told to finish up .. nothing much to do */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 4080 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 4081 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 4082 | end_reshape(conf); |
| 4083 | return 0; |
| 4084 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4085 | |
| 4086 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 4087 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 4088 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4089 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4090 | conf->fullsync = 0; |
| 4091 | bitmap_close_sync(mddev->bitmap); |
| 4092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | return 0; |
| 4094 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4095 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4096 | /* Allow raid5_quiesce to complete */ |
| 4097 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 4098 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4099 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 4100 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4101 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4102 | /* No need to check resync_max as we never do more than one |
| 4103 | * stripe, and as resync_max will always be on a chunk boundary, |
| 4104 | * if the check in md_do_sync didn't fire, there is no chance |
| 4105 | * of overstepping resync_max here |
| 4106 | */ |
| 4107 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4108 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | * to resync, then assert that we are finished, because there is |
| 4110 | * nothing we can do. |
| 4111 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 4112 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4113 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4114 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 4115 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | return rv; |
| 4117 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4118 | if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
NeilBrown | 3855ad9 | 2005-11-08 21:39:38 -0800 | [diff] [blame] | 4119 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4120 | !conf->fullsync && sync_blocks >= STRIPE_SECTORS) { |
| 4121 | /* we can skip this block, and probably more */ |
| 4122 | sync_blocks /= STRIPE_SECTORS; |
| 4123 | *skipped = 1; |
| 4124 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 4125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 4127 | |
| 4128 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 4129 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4130 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | if (sh == NULL) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4132 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4134 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 4136 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4138 | /* Need to check if array will still be degraded after recovery/resync |
| 4139 | * We don't need to check the 'failed' flag as when that gets set, |
| 4140 | * recovery aborts. |
| 4141 | */ |
NeilBrown | f001a70 | 2009-06-09 14:30:31 +1000 | [diff] [blame] | 4142 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4143 | if (conf->disks[i].rdev == NULL) |
| 4144 | still_degraded = 1; |
| 4145 | |
| 4146 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 4147 | |
NeilBrown | 83206d6 | 2011-07-26 11:19:49 +1000 | [diff] [blame] | 4148 | set_bit(STRIPE_SYNC_REQUESTED, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 4150 | handle_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | release_stripe(sh); |
| 4152 | |
| 4153 | return STRIPE_SECTORS; |
| 4154 | } |
| 4155 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4156 | 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] | 4157 | { |
| 4158 | /* We may not be able to submit a whole bio at once as there |
| 4159 | * may not be enough stripe_heads available. |
| 4160 | * We cannot pre-allocate enough stripe_heads as we may need |
| 4161 | * more than exist in the cache (if we allow ever large chunks). |
| 4162 | * So we do one stripe head at a time and record in |
| 4163 | * ->bi_hw_segments how many have been done. |
| 4164 | * |
| 4165 | * We *know* that this entire raid_bio is in one chunk, so |
| 4166 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 4167 | */ |
| 4168 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4169 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4170 | sector_t sector, logical_sector, last_sector; |
| 4171 | int scnt = 0; |
| 4172 | int remaining; |
| 4173 | int handled = 0; |
| 4174 | |
| 4175 | logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4176 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4177 | 0, &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4178 | last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9); |
| 4179 | |
| 4180 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4181 | logical_sector += STRIPE_SECTORS, |
| 4182 | sector += STRIPE_SECTORS, |
| 4183 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4184 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4185 | if (scnt < raid5_bi_hw_segments(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4186 | /* already done this stripe */ |
| 4187 | continue; |
| 4188 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4189 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4190 | |
| 4191 | if (!sh) { |
| 4192 | /* failed to get a stripe - must wait */ |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4193 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4194 | conf->retry_read_aligned = raid_bio; |
| 4195 | return handled; |
| 4196 | } |
| 4197 | |
| 4198 | set_bit(R5_ReadError, &sh->dev[dd_idx].flags); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4199 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
| 4200 | release_stripe(sh); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4201 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4202 | conf->retry_read_aligned = raid_bio; |
| 4203 | return handled; |
| 4204 | } |
| 4205 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4206 | handle_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4207 | release_stripe(sh); |
| 4208 | handled++; |
| 4209 | } |
| 4210 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4211 | remaining = raid5_dec_bi_phys_segments(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4212 | spin_unlock_irq(&conf->device_lock); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4213 | if (remaining == 0) |
| 4214 | bio_endio(raid_bio, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4215 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4216 | wake_up(&conf->wait_for_stripe); |
| 4217 | return handled; |
| 4218 | } |
| 4219 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | /* |
| 4222 | * This is our raid5 kernel thread. |
| 4223 | * |
| 4224 | * We scan the hash table for stripes which can be handled now. |
| 4225 | * During the scan, completed stripes are saved for us by the interrupt |
| 4226 | * handler, so that they will not have to wait for our next wakeup. |
| 4227 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4228 | static void raid5d(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | { |
| 4230 | struct stripe_head *sh; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4231 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | int handled; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4233 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4235 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | |
| 4237 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4239 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | handled = 0; |
| 4241 | spin_lock_irq(&conf->device_lock); |
| 4242 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4243 | struct bio *bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4245 | if (atomic_read(&mddev->plug_cnt) == 0 && |
| 4246 | !list_empty(&conf->bitmap_list)) { |
| 4247 | /* Now is a good time to flush some bitmap updates */ |
| 4248 | conf->seq_flush++; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4249 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4250 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4251 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4252 | conf->seq_write = conf->seq_flush; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4253 | activate_bit_delay(conf); |
| 4254 | } |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 4255 | if (atomic_read(&mddev->plug_cnt) == 0) |
| 4256 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4257 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4258 | while ((bio = remove_bio_from_retry(conf))) { |
| 4259 | int ok; |
| 4260 | spin_unlock_irq(&conf->device_lock); |
| 4261 | ok = retry_aligned_read(conf, bio); |
| 4262 | spin_lock_irq(&conf->device_lock); |
| 4263 | if (!ok) |
| 4264 | break; |
| 4265 | handled++; |
| 4266 | } |
| 4267 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4268 | sh = __get_priority_stripe(conf); |
| 4269 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4270 | if (!sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | spin_unlock_irq(&conf->device_lock); |
| 4273 | |
| 4274 | handled++; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 4275 | handle_stripe(sh); |
| 4276 | release_stripe(sh); |
| 4277 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 4279 | if (mddev->flags & ~(1<<MD_CHANGE_PENDING)) |
| 4280 | md_check_recovery(mddev); |
| 4281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | spin_lock_irq(&conf->device_lock); |
| 4283 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4284 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
| 4286 | spin_unlock_irq(&conf->device_lock); |
| 4287 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4288 | async_tx_issue_pending_all(); |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 4289 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4291 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | } |
| 4293 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4294 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4295 | raid5_show_stripe_cache_size(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4296 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4297 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4298 | if (conf) |
| 4299 | return sprintf(page, "%d\n", conf->max_nr_stripes); |
| 4300 | else |
| 4301 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4302 | } |
| 4303 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4304 | int |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4305 | raid5_set_cache_size(struct mddev *mddev, int size) |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4306 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4307 | struct r5conf *conf = mddev->private; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4308 | int err; |
| 4309 | |
| 4310 | if (size <= 16 || size > 32768) |
| 4311 | return -EINVAL; |
| 4312 | while (size < conf->max_nr_stripes) { |
| 4313 | if (drop_one_stripe(conf)) |
| 4314 | conf->max_nr_stripes--; |
| 4315 | else |
| 4316 | break; |
| 4317 | } |
| 4318 | err = md_allow_write(mddev); |
| 4319 | if (err) |
| 4320 | return err; |
| 4321 | while (size > conf->max_nr_stripes) { |
| 4322 | if (grow_one_stripe(conf)) |
| 4323 | conf->max_nr_stripes++; |
| 4324 | else break; |
| 4325 | } |
| 4326 | return 0; |
| 4327 | } |
| 4328 | EXPORT_SYMBOL(raid5_set_cache_size); |
| 4329 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4330 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4331 | 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] | 4332 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4333 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4334 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4335 | int err; |
| 4336 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4337 | if (len >= PAGE_SIZE) |
| 4338 | return -EINVAL; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4339 | if (!conf) |
| 4340 | return -ENODEV; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4341 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4342 | if (strict_strtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4343 | return -EINVAL; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 4344 | err = raid5_set_cache_size(mddev, new); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4345 | if (err) |
| 4346 | return err; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4347 | return len; |
| 4348 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4349 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4350 | static struct md_sysfs_entry |
| 4351 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 4352 | raid5_show_stripe_cache_size, |
| 4353 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4354 | |
| 4355 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4356 | raid5_show_preread_threshold(struct mddev *mddev, char *page) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4357 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4358 | struct r5conf *conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4359 | if (conf) |
| 4360 | return sprintf(page, "%d\n", conf->bypass_threshold); |
| 4361 | else |
| 4362 | return 0; |
| 4363 | } |
| 4364 | |
| 4365 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4366 | 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] | 4367 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4368 | struct r5conf *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4369 | unsigned long new; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4370 | if (len >= PAGE_SIZE) |
| 4371 | return -EINVAL; |
| 4372 | if (!conf) |
| 4373 | return -ENODEV; |
| 4374 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4375 | if (strict_strtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4376 | return -EINVAL; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4377 | if (new > conf->max_nr_stripes) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4378 | return -EINVAL; |
| 4379 | conf->bypass_threshold = new; |
| 4380 | return len; |
| 4381 | } |
| 4382 | |
| 4383 | static struct md_sysfs_entry |
| 4384 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 4385 | S_IRUGO | S_IWUSR, |
| 4386 | raid5_show_preread_threshold, |
| 4387 | raid5_store_preread_threshold); |
| 4388 | |
| 4389 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4390 | stripe_cache_active_show(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4391 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4392 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4393 | if (conf) |
| 4394 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 4395 | else |
| 4396 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4397 | } |
| 4398 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4399 | static struct md_sysfs_entry |
| 4400 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4401 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4402 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4403 | &raid5_stripecache_size.attr, |
| 4404 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4405 | &raid5_preread_bypass_threshold.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4406 | NULL, |
| 4407 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4408 | static struct attribute_group raid5_attrs_group = { |
| 4409 | .name = NULL, |
| 4410 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4411 | }; |
| 4412 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4413 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4414 | raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4415 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4416 | struct r5conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4417 | |
| 4418 | if (!sectors) |
| 4419 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4420 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 4421 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4422 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4423 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4424 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4425 | sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4426 | return sectors * (raid_disks - conf->max_degraded); |
| 4427 | } |
| 4428 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4429 | static void raid5_free_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4430 | { |
| 4431 | struct raid5_percpu *percpu; |
| 4432 | unsigned long cpu; |
| 4433 | |
| 4434 | if (!conf->percpu) |
| 4435 | return; |
| 4436 | |
| 4437 | get_online_cpus(); |
| 4438 | for_each_possible_cpu(cpu) { |
| 4439 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4440 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4441 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4442 | } |
| 4443 | #ifdef CONFIG_HOTPLUG_CPU |
| 4444 | unregister_cpu_notifier(&conf->cpu_notify); |
| 4445 | #endif |
| 4446 | put_online_cpus(); |
| 4447 | |
| 4448 | free_percpu(conf->percpu); |
| 4449 | } |
| 4450 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4451 | static void free_conf(struct r5conf *conf) |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4452 | { |
| 4453 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4454 | raid5_free_percpu(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4455 | kfree(conf->disks); |
| 4456 | kfree(conf->stripe_hashtbl); |
| 4457 | kfree(conf); |
| 4458 | } |
| 4459 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4460 | #ifdef CONFIG_HOTPLUG_CPU |
| 4461 | static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, |
| 4462 | void *hcpu) |
| 4463 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4464 | struct r5conf *conf = container_of(nfb, struct r5conf, cpu_notify); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4465 | long cpu = (long)hcpu; |
| 4466 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4467 | |
| 4468 | switch (action) { |
| 4469 | case CPU_UP_PREPARE: |
| 4470 | case CPU_UP_PREPARE_FROZEN: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4471 | if (conf->level == 6 && !percpu->spare_page) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4472 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4473 | if (!percpu->scribble) |
| 4474 | percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
| 4475 | |
| 4476 | if (!percpu->scribble || |
| 4477 | (conf->level == 6 && !percpu->spare_page)) { |
| 4478 | safe_put_page(percpu->spare_page); |
| 4479 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4480 | pr_err("%s: failed memory allocation for cpu%ld\n", |
| 4481 | __func__, cpu); |
Akinobu Mita | 55af6bb | 2010-05-26 14:43:35 -0700 | [diff] [blame] | 4482 | return notifier_from_errno(-ENOMEM); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4483 | } |
| 4484 | break; |
| 4485 | case CPU_DEAD: |
| 4486 | case CPU_DEAD_FROZEN: |
| 4487 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4488 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4489 | percpu->spare_page = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4490 | percpu->scribble = NULL; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4491 | break; |
| 4492 | default: |
| 4493 | break; |
| 4494 | } |
| 4495 | return NOTIFY_OK; |
| 4496 | } |
| 4497 | #endif |
| 4498 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4499 | static int raid5_alloc_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4500 | { |
| 4501 | unsigned long cpu; |
| 4502 | struct page *spare_page; |
Tejun Heo | a29d8b8 | 2010-02-02 14:39:15 +0900 | [diff] [blame] | 4503 | struct raid5_percpu __percpu *allcpus; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4504 | void *scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4505 | int err; |
| 4506 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4507 | allcpus = alloc_percpu(struct raid5_percpu); |
| 4508 | if (!allcpus) |
| 4509 | return -ENOMEM; |
| 4510 | conf->percpu = allcpus; |
| 4511 | |
| 4512 | get_online_cpus(); |
| 4513 | err = 0; |
| 4514 | for_each_present_cpu(cpu) { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4515 | if (conf->level == 6) { |
| 4516 | spare_page = alloc_page(GFP_KERNEL); |
| 4517 | if (!spare_page) { |
| 4518 | err = -ENOMEM; |
| 4519 | break; |
| 4520 | } |
| 4521 | per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page; |
| 4522 | } |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4523 | scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4524 | if (!scribble) { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4525 | err = -ENOMEM; |
| 4526 | break; |
| 4527 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4528 | per_cpu_ptr(conf->percpu, cpu)->scribble = scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4529 | } |
| 4530 | #ifdef CONFIG_HOTPLUG_CPU |
| 4531 | conf->cpu_notify.notifier_call = raid456_cpu_notify; |
| 4532 | conf->cpu_notify.priority = 0; |
| 4533 | if (err == 0) |
| 4534 | err = register_cpu_notifier(&conf->cpu_notify); |
| 4535 | #endif |
| 4536 | put_online_cpus(); |
| 4537 | |
| 4538 | return err; |
| 4539 | } |
| 4540 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4541 | static struct r5conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4543 | struct r5conf *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4544 | int raid_disk, memory, max_disks; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4545 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | struct disk_info *disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4548 | if (mddev->new_level != 5 |
| 4549 | && mddev->new_level != 4 |
| 4550 | && mddev->new_level != 6) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4551 | 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] | 4552 | mdname(mddev), mddev->new_level); |
| 4553 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4555 | if ((mddev->new_level == 5 |
| 4556 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 4557 | (mddev->new_level == 6 |
| 4558 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4559 | printk(KERN_ERR "md/raid:%s: layout %d not supported\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4560 | mdname(mddev), mddev->new_layout); |
| 4561 | return ERR_PTR(-EIO); |
| 4562 | } |
| 4563 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4564 | 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] | 4565 | mdname(mddev), mddev->raid_disks); |
| 4566 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4569 | if (!mddev->new_chunk_sectors || |
| 4570 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 4571 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4572 | printk(KERN_ERR "md/raid:%s: invalid chunk size %d\n", |
| 4573 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4574 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4575 | } |
| 4576 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4577 | conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4578 | if (conf == NULL) |
| 4579 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 4580 | spin_lock_init(&conf->device_lock); |
| 4581 | init_waitqueue_head(&conf->wait_for_stripe); |
| 4582 | init_waitqueue_head(&conf->wait_for_overlap); |
| 4583 | INIT_LIST_HEAD(&conf->handle_list); |
| 4584 | INIT_LIST_HEAD(&conf->hold_list); |
| 4585 | INIT_LIST_HEAD(&conf->delayed_list); |
| 4586 | INIT_LIST_HEAD(&conf->bitmap_list); |
| 4587 | INIT_LIST_HEAD(&conf->inactive_list); |
| 4588 | atomic_set(&conf->active_stripes, 0); |
| 4589 | atomic_set(&conf->preread_active_stripes, 0); |
| 4590 | atomic_set(&conf->active_aligned_reads, 0); |
| 4591 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 4592 | conf->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4593 | |
| 4594 | conf->raid_disks = mddev->raid_disks; |
| 4595 | if (mddev->reshape_position == MaxSector) |
| 4596 | conf->previous_raid_disks = mddev->raid_disks; |
| 4597 | else |
| 4598 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4599 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
| 4600 | conf->scribble_len = scribble_len(max_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4601 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4602 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4603 | GFP_KERNEL); |
| 4604 | if (!conf->disks) |
| 4605 | goto abort; |
| 4606 | |
| 4607 | conf->mddev = mddev; |
| 4608 | |
| 4609 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 4610 | goto abort; |
| 4611 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4612 | conf->level = mddev->new_level; |
| 4613 | if (raid5_alloc_percpu(conf) != 0) |
| 4614 | goto abort; |
| 4615 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4616 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4617 | |
| 4618 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 4619 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4620 | if (raid_disk >= max_disks |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4621 | || raid_disk < 0) |
| 4622 | continue; |
| 4623 | disk = conf->disks + raid_disk; |
| 4624 | |
| 4625 | disk->rdev = rdev; |
| 4626 | |
| 4627 | if (test_bit(In_sync, &rdev->flags)) { |
| 4628 | char b[BDEVNAME_SIZE]; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4629 | printk(KERN_INFO "md/raid:%s: device %s operational as raid" |
| 4630 | " disk %d\n", |
| 4631 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
Jonathan Brassow | d6b212f | 2011-06-08 18:00:28 -0500 | [diff] [blame] | 4632 | } else if (rdev->saved_raid_disk != raid_disk) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4633 | /* Cannot rely on bitmap to complete recovery */ |
| 4634 | conf->fullsync = 1; |
| 4635 | } |
| 4636 | |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4637 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4638 | conf->level = mddev->new_level; |
| 4639 | if (conf->level == 6) |
| 4640 | conf->max_degraded = 2; |
| 4641 | else |
| 4642 | conf->max_degraded = 1; |
| 4643 | conf->algorithm = mddev->new_layout; |
| 4644 | conf->max_nr_stripes = NR_STRIPES; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4645 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4646 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4647 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4648 | conf->prev_algo = mddev->layout; |
| 4649 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4650 | |
| 4651 | memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4652 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4653 | if (grow_stripes(conf, conf->max_nr_stripes)) { |
| 4654 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4655 | "md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 4656 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4657 | goto abort; |
| 4658 | } else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4659 | printk(KERN_INFO "md/raid:%s: allocated %dkB\n", |
| 4660 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4661 | |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 4662 | conf->thread = md_register_thread(raid5d, mddev, NULL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4663 | if (!conf->thread) { |
| 4664 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4665 | "md/raid:%s: couldn't allocate thread.\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4666 | mdname(mddev)); |
| 4667 | goto abort; |
| 4668 | } |
| 4669 | |
| 4670 | return conf; |
| 4671 | |
| 4672 | abort: |
| 4673 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4674 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4675 | return ERR_PTR(-EIO); |
| 4676 | } else |
| 4677 | return ERR_PTR(-ENOMEM); |
| 4678 | } |
| 4679 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4680 | |
| 4681 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 4682 | { |
| 4683 | switch (algo) { |
| 4684 | case ALGORITHM_PARITY_0: |
| 4685 | if (raid_disk < max_degraded) |
| 4686 | return 1; |
| 4687 | break; |
| 4688 | case ALGORITHM_PARITY_N: |
| 4689 | if (raid_disk >= raid_disks - max_degraded) |
| 4690 | return 1; |
| 4691 | break; |
| 4692 | case ALGORITHM_PARITY_0_6: |
| 4693 | if (raid_disk == 0 || |
| 4694 | raid_disk == raid_disks - 1) |
| 4695 | return 1; |
| 4696 | break; |
| 4697 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 4698 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 4699 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 4700 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 4701 | if (raid_disk == raid_disks - 1) |
| 4702 | return 1; |
| 4703 | } |
| 4704 | return 0; |
| 4705 | } |
| 4706 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4707 | static int run(struct mddev *mddev) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4708 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4709 | struct r5conf *conf; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 4710 | int working_disks = 0; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4711 | int dirty_parity_disks = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4712 | struct md_rdev *rdev; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4713 | sector_t reshape_offset = 0; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4714 | |
Andre Noll | 8c6ac868 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4715 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4716 | printk(KERN_NOTICE "md/raid:%s: not clean" |
Andre Noll | 8c6ac868 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4717 | " -- starting background reconstruction\n", |
| 4718 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4719 | if (mddev->reshape_position != MaxSector) { |
| 4720 | /* Check that we can continue the reshape. |
| 4721 | * Currently only disks can change, it must |
| 4722 | * increase, and we must be past the point where |
| 4723 | * a stripe over-writes itself |
| 4724 | */ |
| 4725 | sector_t here_new, here_old; |
| 4726 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 4727 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4728 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 4729 | if (mddev->new_level != mddev->level) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4730 | printk(KERN_ERR "md/raid:%s: unsupported reshape " |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4731 | "required - aborting.\n", |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4732 | mdname(mddev)); |
| 4733 | return -EINVAL; |
| 4734 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4735 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 4736 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4737 | * further up in new geometry must map after here in old |
| 4738 | * geometry. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4739 | */ |
| 4740 | here_new = mddev->reshape_position; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4741 | if (sector_div(here_new, mddev->new_chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4742 | (mddev->raid_disks - max_degraded))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4743 | printk(KERN_ERR "md/raid:%s: reshape_position not " |
| 4744 | "on a stripe boundary\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4745 | return -EINVAL; |
| 4746 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4747 | reshape_offset = here_new * mddev->new_chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4748 | /* here_new is the stripe we will write to */ |
| 4749 | here_old = mddev->reshape_position; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4750 | sector_div(here_old, mddev->chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4751 | (old_disks-max_degraded)); |
| 4752 | /* here_old is the first stripe that we might need to read |
| 4753 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 4754 | if (mddev->delta_disks == 0) { |
| 4755 | /* We cannot be sure it is safe to start an in-place |
| 4756 | * reshape. It is only safe if user-space if monitoring |
| 4757 | * and taking constant backups. |
| 4758 | * mdadm always starts a situation like this in |
| 4759 | * readonly mode so it can take control before |
| 4760 | * allowing any writes. So just check for that. |
| 4761 | */ |
| 4762 | if ((here_new * mddev->new_chunk_sectors != |
| 4763 | here_old * mddev->chunk_sectors) || |
| 4764 | mddev->ro == 0) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4765 | printk(KERN_ERR "md/raid:%s: in-place reshape must be started" |
| 4766 | " in read-only mode - aborting\n", |
| 4767 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 4768 | return -EINVAL; |
| 4769 | } |
| 4770 | } else if (mddev->delta_disks < 0 |
| 4771 | ? (here_new * mddev->new_chunk_sectors <= |
| 4772 | here_old * mddev->chunk_sectors) |
| 4773 | : (here_new * mddev->new_chunk_sectors >= |
| 4774 | here_old * mddev->chunk_sectors)) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4775 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4776 | printk(KERN_ERR "md/raid:%s: reshape_position too early for " |
| 4777 | "auto-recovery - aborting.\n", |
| 4778 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4779 | return -EINVAL; |
| 4780 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4781 | printk(KERN_INFO "md/raid:%s: reshape will continue\n", |
| 4782 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4783 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4784 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4785 | BUG_ON(mddev->level != mddev->new_level); |
| 4786 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4787 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4788 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4789 | } |
| 4790 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4791 | if (mddev->private == NULL) |
| 4792 | conf = setup_conf(mddev); |
| 4793 | else |
| 4794 | conf = mddev->private; |
| 4795 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4796 | if (IS_ERR(conf)) |
| 4797 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 4798 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4799 | mddev->thread = conf->thread; |
| 4800 | conf->thread = NULL; |
| 4801 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4804 | * 0 for a fully functional array, 1 or 2 for a degraded array. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | */ |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4806 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 4807 | if (rdev->raid_disk < 0) |
| 4808 | continue; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 4809 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4810 | working_disks++; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 4811 | continue; |
| 4812 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4813 | /* This disc is not fully in-sync. However if it |
| 4814 | * just stored parity (beyond the recovery_offset), |
| 4815 | * when we don't need to be concerned about the |
| 4816 | * array being dirty. |
| 4817 | * When reshape goes 'backwards', we never have |
| 4818 | * partially completed devices, so we only need |
| 4819 | * to worry about reshape going forwards. |
| 4820 | */ |
| 4821 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 4822 | if (mddev->major_version == 0 && |
| 4823 | mddev->minor_version > 90) |
| 4824 | rdev->recovery_offset = reshape_offset; |
| 4825 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4826 | if (rdev->recovery_offset < reshape_offset) { |
| 4827 | /* We need to check old and new layout */ |
| 4828 | if (!only_parity(rdev->raid_disk, |
| 4829 | conf->algorithm, |
| 4830 | conf->raid_disks, |
| 4831 | conf->max_degraded)) |
| 4832 | continue; |
| 4833 | } |
| 4834 | if (!only_parity(rdev->raid_disk, |
| 4835 | conf->prev_algo, |
| 4836 | conf->previous_raid_disks, |
| 4837 | conf->max_degraded)) |
| 4838 | continue; |
| 4839 | dirty_parity_disks++; |
| 4840 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4841 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4842 | mddev->degraded = (max(conf->raid_disks, conf->previous_raid_disks) |
| 4843 | - working_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 4845 | if (has_failed(conf)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4846 | printk(KERN_ERR "md/raid:%s: not enough operational devices" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | " (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 4848 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | goto abort; |
| 4850 | } |
| 4851 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4852 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4853 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4854 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 4855 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4856 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4858 | if (mddev->ok_start_degraded) |
| 4859 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4860 | "md/raid:%s: starting dirty degraded array" |
| 4861 | " - data corruption possible.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4862 | mdname(mddev)); |
| 4863 | else { |
| 4864 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4865 | "md/raid:%s: cannot start dirty degraded array.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 4866 | mdname(mddev)); |
| 4867 | goto abort; |
| 4868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | if (mddev->degraded == 0) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4872 | printk(KERN_INFO "md/raid:%s: raid level %d active with %d out of %d" |
| 4873 | " devices, algorithm %d\n", mdname(mddev), conf->level, |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4874 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 4875 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4877 | printk(KERN_ALERT "md/raid:%s: raid level %d active with %d" |
| 4878 | " out of %d devices, algorithm %d\n", |
| 4879 | mdname(mddev), conf->level, |
| 4880 | mddev->raid_disks - mddev->degraded, |
| 4881 | mddev->raid_disks, mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | |
| 4883 | print_raid5_conf(conf); |
| 4884 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4885 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4886 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4887 | atomic_set(&conf->reshape_stripes, 0); |
| 4888 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 4889 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 4890 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 4891 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 4892 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 4893 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4894 | } |
| 4895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | |
| 4897 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 4898 | if (mddev->to_remove == &raid5_attrs_group) |
| 4899 | mddev->to_remove = NULL; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 4900 | else if (mddev->kobj.sd && |
| 4901 | sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4902 | printk(KERN_WARNING |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 4903 | "raid5: failed to create sysfs attributes for %s\n", |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 4904 | mdname(mddev)); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 4905 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 4906 | |
| 4907 | if (mddev->queue) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 4908 | int chunk_size; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 4909 | /* read-ahead size must cover two whole stripes, which |
| 4910 | * is 2 * (datadisks) * chunksize where 'n' is the |
| 4911 | * number of raid devices |
| 4912 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 4914 | int stripe = data_disks * |
| 4915 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
| 4916 | if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 4917 | mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 4918 | |
| 4919 | blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 4920 | |
| 4921 | mddev->queue->backing_dev_info.congested_data = mddev; |
| 4922 | mddev->queue->backing_dev_info.congested_fn = raid5_congested; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 4923 | |
| 4924 | chunk_size = mddev->chunk_sectors << 9; |
| 4925 | blk_queue_io_min(mddev->queue, chunk_size); |
| 4926 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 4927 | (conf->raid_disks - conf->max_degraded)); |
| 4928 | |
| 4929 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 4930 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 4931 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | return 0; |
| 4935 | abort: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 4936 | md_unregister_thread(&mddev->thread); |
NeilBrown | e4f869d | 2011-10-07 14:22:49 +1100 | [diff] [blame] | 4937 | print_raid5_conf(conf); |
| 4938 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | mddev->private = NULL; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4940 | 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] | 4941 | return -EIO; |
| 4942 | } |
| 4943 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4944 | static int stop(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4946 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 4948 | md_unregister_thread(&mddev->thread); |
NeilBrown | 11d8a6e | 2010-07-26 11:57:07 +1000 | [diff] [blame] | 4949 | if (mddev->queue) |
| 4950 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4951 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 4952 | mddev->private = NULL; |
| 4953 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | return 0; |
| 4955 | } |
| 4956 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4957 | static void status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4959 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | int i; |
| 4961 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4962 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
| 4963 | mddev->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 4964 | 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] | 4965 | for (i = 0; i < conf->raid_disks; i++) |
| 4966 | seq_printf (seq, "%s", |
| 4967 | conf->disks[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 4968 | test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | seq_printf (seq, "]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4972 | static void print_raid5_conf (struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4973 | { |
| 4974 | int i; |
| 4975 | struct disk_info *tmp; |
| 4976 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4977 | printk(KERN_DEBUG "RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | if (!conf) { |
| 4979 | printk("(conf==NULL)\n"); |
| 4980 | return; |
| 4981 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4982 | printk(KERN_DEBUG " --- level:%d rd:%d wd:%d\n", conf->level, |
| 4983 | conf->raid_disks, |
| 4984 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | |
| 4986 | for (i = 0; i < conf->raid_disks; i++) { |
| 4987 | char b[BDEVNAME_SIZE]; |
| 4988 | tmp = conf->disks + i; |
| 4989 | if (tmp->rdev) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4990 | printk(KERN_DEBUG " disk %d, o:%d, dev:%s\n", |
| 4991 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 4992 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 4996 | static int raid5_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | { |
| 4998 | int i; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4999 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | struct disk_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5001 | int count = 0; |
| 5002 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | |
| 5004 | for (i = 0; i < conf->raid_disks; i++) { |
| 5005 | tmp = conf->disks + i; |
| 5006 | if (tmp->rdev |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 5007 | && tmp->rdev->recovery_offset == MaxSector |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5008 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5009 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5010 | count++; |
Jonathan Brassow | 43c73ca | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 5011 | sysfs_notify_dirent_safe(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | } |
| 5013 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5014 | spin_lock_irqsave(&conf->device_lock, flags); |
| 5015 | mddev->degraded -= count; |
| 5016 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | print_raid5_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 5018 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5021 | static int raid5_remove_disk(struct mddev *mddev, int number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5023 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | int err = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5025 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | struct disk_info *p = conf->disks + number; |
| 5027 | |
| 5028 | print_raid5_conf(conf); |
| 5029 | rdev = p->rdev; |
| 5030 | if (rdev) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5031 | if (number >= conf->raid_disks && |
| 5032 | conf->reshape_progress == MaxSector) |
| 5033 | clear_bit(In_sync, &rdev->flags); |
| 5034 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5035 | if (test_bit(In_sync, &rdev->flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | atomic_read(&rdev->nr_pending)) { |
| 5037 | err = -EBUSY; |
| 5038 | goto abort; |
| 5039 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5040 | /* Only remove non-faulty devices if recovery |
| 5041 | * isn't possible. |
| 5042 | */ |
| 5043 | if (!test_bit(Faulty, &rdev->flags) && |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5044 | mddev->recovery_disabled != conf->recovery_disabled && |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5045 | !has_failed(conf) && |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5046 | number < conf->raid_disks) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5047 | err = -EBUSY; |
| 5048 | goto abort; |
| 5049 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | p->rdev = NULL; |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 5051 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | if (atomic_read(&rdev->nr_pending)) { |
| 5053 | /* lost the race, try later */ |
| 5054 | err = -EBUSY; |
| 5055 | p->rdev = rdev; |
| 5056 | } |
| 5057 | } |
| 5058 | abort: |
| 5059 | |
| 5060 | print_raid5_conf(conf); |
| 5061 | return err; |
| 5062 | } |
| 5063 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5064 | static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5066 | struct r5conf *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5067 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | int disk; |
| 5069 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5070 | int first = 0; |
| 5071 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5073 | if (mddev->recovery_disabled == conf->recovery_disabled) |
| 5074 | return -EBUSY; |
| 5075 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5076 | if (has_failed(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5078 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5080 | if (rdev->raid_disk >= 0) |
| 5081 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | |
| 5083 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5084 | * find the disk ... but prefer rdev->saved_raid_disk |
| 5085 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5087 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5088 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5089 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
| 5090 | disk = rdev->saved_raid_disk; |
| 5091 | else |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5092 | disk = first; |
| 5093 | for ( ; disk <= last ; disk++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | if ((p=conf->disks + disk)->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5095 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5097 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5098 | if (rdev->saved_raid_disk != disk) |
| 5099 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 5100 | rcu_assign_pointer(p->rdev, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | break; |
| 5102 | } |
| 5103 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5104 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5107 | static int raid5_resize(struct mddev *mddev, sector_t sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | { |
| 5109 | /* no resync is happening, and there is enough space |
| 5110 | * on all devices, so we can resize. |
| 5111 | * We need to make sure resync covers any new space. |
| 5112 | * If the array is shrinking we should possibly wait until |
| 5113 | * any io in the removed space completes, but it hardly seems |
| 5114 | * worth it. |
| 5115 | */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5116 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5117 | md_set_array_sectors(mddev, raid5_size(mddev, sectors, |
| 5118 | mddev->raid_disks)); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5119 | if (mddev->array_sectors > |
| 5120 | raid5_size(mddev, sectors, mddev->raid_disks)) |
| 5121 | return -EINVAL; |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 5122 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5123 | revalidate_disk(mddev->gendisk); |
NeilBrown | b098636 | 2011-05-11 15:52:21 +1000 | [diff] [blame] | 5124 | if (sectors > mddev->dev_sectors && |
| 5125 | mddev->recovery_cp > mddev->dev_sectors) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5126 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5128 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5129 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 5130 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | return 0; |
| 5132 | } |
| 5133 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5134 | static int check_stripe_cache(struct mddev *mddev) |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5135 | { |
| 5136 | /* Can only proceed if there are plenty of stripe_heads. |
| 5137 | * We need a minimum of one full stripe,, and for sensible progress |
| 5138 | * it is best to have about 4 times that. |
| 5139 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 5140 | * allow for chunk sizes up to 256K, which is probably OK. |
| 5141 | * If the chunk size is greater, user-space should request more |
| 5142 | * stripe_heads first. |
| 5143 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5144 | struct r5conf *conf = mddev->private; |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5145 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5146 | > conf->max_nr_stripes || |
| 5147 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5148 | > conf->max_nr_stripes) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5149 | printk(KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 5150 | mdname(mddev), |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5151 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 5152 | / STRIPE_SIZE)*4); |
| 5153 | return 0; |
| 5154 | } |
| 5155 | return 1; |
| 5156 | } |
| 5157 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5158 | static int check_reshape(struct mddev *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5159 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5160 | struct r5conf *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5161 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5162 | if (mddev->delta_disks == 0 && |
| 5163 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5164 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5165 | return 0; /* nothing to do */ |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5166 | if (mddev->bitmap) |
| 5167 | /* Cannot grow a bitmap yet */ |
| 5168 | return -EBUSY; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 5169 | if (has_failed(conf)) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5170 | return -EINVAL; |
| 5171 | if (mddev->delta_disks < 0) { |
| 5172 | /* We might be able to shrink, but the devices must |
| 5173 | * be made bigger first. |
| 5174 | * For raid6, 4 is the minimum size. |
| 5175 | * Otherwise 2 is the minimum |
| 5176 | */ |
| 5177 | int min = 2; |
| 5178 | if (mddev->level == 6) |
| 5179 | min = 4; |
| 5180 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 5181 | return -EINVAL; |
| 5182 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5183 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5184 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5185 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5186 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5187 | return resize_stripes(conf, conf->raid_disks + mddev->delta_disks); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5190 | static int raid5_start_reshape(struct mddev *mddev) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5191 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5192 | struct r5conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5193 | struct md_rdev *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5194 | int spares = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5195 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5196 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5197 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5198 | return -EBUSY; |
| 5199 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5200 | if (!check_stripe_cache(mddev)) |
| 5201 | return -ENOSPC; |
| 5202 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5203 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 469518a | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5204 | if (!test_bit(In_sync, &rdev->flags) |
| 5205 | && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5206 | spares++; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5207 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5208 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5209 | /* Not enough devices even to make a degraded array |
| 5210 | * of that size |
| 5211 | */ |
| 5212 | return -EINVAL; |
| 5213 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5214 | /* Refuse to reduce size of the array. Any reductions in |
| 5215 | * array size must be through explicit setting of array_size |
| 5216 | * attribute. |
| 5217 | */ |
| 5218 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 5219 | < mddev->array_sectors) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5220 | printk(KERN_ERR "md/raid:%s: array size must be reduced " |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5221 | "before number of disks\n", mdname(mddev)); |
| 5222 | return -EINVAL; |
| 5223 | } |
| 5224 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5225 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5226 | spin_lock_irq(&conf->device_lock); |
| 5227 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5228 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5229 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 5230 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5231 | conf->prev_algo = conf->algorithm; |
| 5232 | conf->algorithm = mddev->new_layout; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5233 | if (mddev->delta_disks < 0) |
| 5234 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 5235 | else |
| 5236 | conf->reshape_progress = 0; |
| 5237 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 5238 | conf->generation++; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5239 | spin_unlock_irq(&conf->device_lock); |
| 5240 | |
| 5241 | /* Add some new drives, as many as will fit. |
| 5242 | * We know there are enough to make the newly sized array work. |
NeilBrown | 3424bf6 | 2010-06-17 17:48:26 +1000 | [diff] [blame] | 5243 | * Don't add devices if we are reducing the number of |
| 5244 | * devices in the array. This is because it is not possible |
| 5245 | * to correctly record the "partially reconstructed" state of |
| 5246 | * such devices during the reshape and confusion could result. |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5247 | */ |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5248 | if (mddev->delta_disks >= 0) { |
| 5249 | int added_devices = 0; |
| 5250 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 5251 | if (rdev->raid_disk < 0 && |
| 5252 | !test_bit(Faulty, &rdev->flags)) { |
| 5253 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5254 | if (rdev->raid_disk |
| 5255 | >= conf->previous_raid_disks) { |
| 5256 | set_bit(In_sync, &rdev->flags); |
| 5257 | added_devices++; |
| 5258 | } else |
| 5259 | rdev->recovery_offset = 0; |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5260 | |
| 5261 | if (sysfs_link_rdev(mddev, rdev)) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5262 | /* Failure here is OK */; |
NeilBrown | 50da084 | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5263 | } |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5264 | } else if (rdev->raid_disk >= conf->previous_raid_disks |
| 5265 | && !test_bit(Faulty, &rdev->flags)) { |
| 5266 | /* This is a spare that was manually added */ |
| 5267 | set_bit(In_sync, &rdev->flags); |
| 5268 | added_devices++; |
| 5269 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5270 | |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 5271 | /* When a reshape changes the number of devices, |
| 5272 | * ->degraded is measured against the larger of the |
| 5273 | * pre and post number of devices. |
| 5274 | */ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5275 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5276 | mddev->degraded += (conf->raid_disks - conf->previous_raid_disks) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5277 | - added_devices; |
| 5278 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 5279 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5280 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 5281 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 850b2b42 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5282 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5283 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5284 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5285 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5286 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5287 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5288 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5289 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5290 | if (!mddev->sync_thread) { |
| 5291 | mddev->recovery = 0; |
| 5292 | spin_lock_irq(&conf->device_lock); |
| 5293 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5294 | conf->reshape_progress = MaxSector; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5295 | spin_unlock_irq(&conf->device_lock); |
| 5296 | return -EAGAIN; |
| 5297 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5298 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5299 | md_wakeup_thread(mddev->sync_thread); |
| 5300 | md_new_event(mddev); |
| 5301 | return 0; |
| 5302 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5303 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5304 | /* This is called from the reshape thread and should make any |
| 5305 | * changes needed in 'conf' |
| 5306 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5307 | static void end_reshape(struct r5conf *conf) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5308 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5309 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5310 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5311 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5312 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5313 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5314 | conf->reshape_progress = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5315 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5316 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5317 | |
| 5318 | /* read-ahead size must cover two whole stripes, which is |
| 5319 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 5320 | */ |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 5321 | if (conf->mddev->queue) { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5322 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5323 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5324 | / PAGE_SIZE); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5325 | if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5326 | conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 5327 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5328 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5329 | } |
| 5330 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5331 | /* This is called from the raid5d thread with mddev_lock held. |
| 5332 | * It makes config changes to the device. |
| 5333 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5334 | static void raid5_finish_reshape(struct mddev *mddev) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5335 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5336 | struct r5conf *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5337 | |
| 5338 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5339 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5340 | if (mddev->delta_disks > 0) { |
| 5341 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5342 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5343 | revalidate_disk(mddev->gendisk); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5344 | } else { |
| 5345 | int d; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5346 | mddev->degraded = conf->raid_disks; |
| 5347 | for (d = 0; d < conf->raid_disks ; d++) |
| 5348 | if (conf->disks[d].rdev && |
| 5349 | test_bit(In_sync, |
| 5350 | &conf->disks[d].rdev->flags)) |
| 5351 | mddev->degraded--; |
| 5352 | for (d = conf->raid_disks ; |
| 5353 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5354 | d++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5355 | struct md_rdev *rdev = conf->disks[d].rdev; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5356 | if (rdev && raid5_remove_disk(mddev, d) == 0) { |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5357 | sysfs_unlink_rdev(mddev, rdev); |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5358 | rdev->raid_disk = -1; |
| 5359 | } |
| 5360 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5361 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5362 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5363 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5364 | mddev->reshape_position = MaxSector; |
| 5365 | mddev->delta_disks = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5366 | } |
| 5367 | } |
| 5368 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5369 | static void raid5_quiesce(struct mddev *mddev, int state) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5370 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5371 | struct r5conf *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5372 | |
| 5373 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5374 | case 2: /* resume for a suspend */ |
| 5375 | wake_up(&conf->wait_for_overlap); |
| 5376 | break; |
| 5377 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5378 | case 1: /* stop all writes */ |
| 5379 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5380 | /* '2' tells resync/reshape to pause so that all |
| 5381 | * active stripes can drain |
| 5382 | */ |
| 5383 | conf->quiesce = 2; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5384 | wait_event_lock_irq(conf->wait_for_stripe, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5385 | atomic_read(&conf->active_stripes) == 0 && |
| 5386 | atomic_read(&conf->active_aligned_reads) == 0, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5387 | conf->device_lock, /* nothing */); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5388 | conf->quiesce = 1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5389 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5390 | /* allow reshape to continue */ |
| 5391 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5392 | break; |
| 5393 | |
| 5394 | case 0: /* re-enable writes */ |
| 5395 | spin_lock_irq(&conf->device_lock); |
| 5396 | conf->quiesce = 0; |
| 5397 | wake_up(&conf->wait_for_stripe); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5398 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5399 | spin_unlock_irq(&conf->device_lock); |
| 5400 | break; |
| 5401 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5402 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 5403 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5404 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5405 | static void *raid45_takeover_raid0(struct mddev *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5406 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 5407 | struct r0conf *raid0_conf = mddev->private; |
Randy Dunlap | d76c842 | 2011-04-21 09:07:26 -0700 | [diff] [blame] | 5408 | sector_t sectors; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5409 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5410 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 5411 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5412 | printk(KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 5413 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5414 | return ERR_PTR(-EINVAL); |
| 5415 | } |
| 5416 | |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 5417 | sectors = raid0_conf->strip_zone[0].zone_end; |
| 5418 | sector_div(sectors, raid0_conf->strip_zone[0].nb_dev); |
NeilBrown | 3b71bd9 | 2011-04-20 15:38:18 +1000 | [diff] [blame] | 5419 | mddev->dev_sectors = sectors; |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5420 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5421 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5422 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 5423 | mddev->raid_disks += 1; |
| 5424 | mddev->delta_disks = 1; |
| 5425 | /* make sure it will be not marked as dirty */ |
| 5426 | mddev->recovery_cp = MaxSector; |
| 5427 | |
| 5428 | return setup_conf(mddev); |
| 5429 | } |
| 5430 | |
| 5431 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5432 | static void *raid5_takeover_raid1(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5433 | { |
| 5434 | int chunksect; |
| 5435 | |
| 5436 | if (mddev->raid_disks != 2 || |
| 5437 | mddev->degraded > 1) |
| 5438 | return ERR_PTR(-EINVAL); |
| 5439 | |
| 5440 | /* Should check if there are write-behind devices? */ |
| 5441 | |
| 5442 | chunksect = 64*2; /* 64K by default */ |
| 5443 | |
| 5444 | /* The array must be an exact multiple of chunksize */ |
| 5445 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 5446 | chunksect >>= 1; |
| 5447 | |
| 5448 | if ((chunksect<<9) < STRIPE_SIZE) |
| 5449 | /* array size does not allow a suitable chunk size */ |
| 5450 | return ERR_PTR(-EINVAL); |
| 5451 | |
| 5452 | mddev->new_level = 5; |
| 5453 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5454 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5455 | |
| 5456 | return setup_conf(mddev); |
| 5457 | } |
| 5458 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5459 | static void *raid5_takeover_raid6(struct mddev *mddev) |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5460 | { |
| 5461 | int new_layout; |
| 5462 | |
| 5463 | switch (mddev->layout) { |
| 5464 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 5465 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 5466 | break; |
| 5467 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 5468 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 5469 | break; |
| 5470 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 5471 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 5472 | break; |
| 5473 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 5474 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 5475 | break; |
| 5476 | case ALGORITHM_PARITY_0_6: |
| 5477 | new_layout = ALGORITHM_PARITY_0; |
| 5478 | break; |
| 5479 | case ALGORITHM_PARITY_N: |
| 5480 | new_layout = ALGORITHM_PARITY_N; |
| 5481 | break; |
| 5482 | default: |
| 5483 | return ERR_PTR(-EINVAL); |
| 5484 | } |
| 5485 | mddev->new_level = 5; |
| 5486 | mddev->new_layout = new_layout; |
| 5487 | mddev->delta_disks = -1; |
| 5488 | mddev->raid_disks -= 1; |
| 5489 | return setup_conf(mddev); |
| 5490 | } |
| 5491 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5492 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5493 | static int raid5_check_reshape(struct mddev *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5494 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5495 | /* For a 2-drive array, the layout and chunk size can be changed |
| 5496 | * immediately as not restriping is needed. |
| 5497 | * For larger arrays we record the new value - after validation |
| 5498 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5499 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5500 | struct r5conf *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5501 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5502 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5503 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5504 | return -EINVAL; |
| 5505 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5506 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5507 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5508 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5509 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5510 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5511 | /* not factor of array size */ |
| 5512 | return -EINVAL; |
| 5513 | } |
| 5514 | |
| 5515 | /* They look valid */ |
| 5516 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5517 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5518 | /* can make the change immediately */ |
| 5519 | if (mddev->new_layout >= 0) { |
| 5520 | conf->algorithm = mddev->new_layout; |
| 5521 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5522 | } |
| 5523 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5524 | conf->chunk_sectors = new_chunk ; |
| 5525 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5526 | } |
| 5527 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 5528 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5529 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5530 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5531 | } |
| 5532 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5533 | static int raid6_check_reshape(struct mddev *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5534 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5535 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5536 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5537 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5538 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5539 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5540 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5541 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5542 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5543 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5544 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5545 | /* not factor of array size */ |
| 5546 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5547 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5548 | |
| 5549 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5550 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5551 | } |
| 5552 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5553 | static void *raid5_takeover(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5554 | { |
| 5555 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5556 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5557 | * raid1 - if there are two drives. We need to know the chunk size |
| 5558 | * raid4 - trivial - just use a raid4 layout. |
| 5559 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5560 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5561 | if (mddev->level == 0) |
| 5562 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5563 | if (mddev->level == 1) |
| 5564 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 5565 | if (mddev->level == 4) { |
| 5566 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5567 | mddev->new_level = 5; |
| 5568 | return setup_conf(mddev); |
| 5569 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5570 | if (mddev->level == 6) |
| 5571 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5572 | |
| 5573 | return ERR_PTR(-EINVAL); |
| 5574 | } |
| 5575 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5576 | static void *raid4_takeover(struct mddev *mddev) |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5577 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5578 | /* raid4 can take over: |
| 5579 | * raid0 - if there is only one strip zone |
| 5580 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5581 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5582 | if (mddev->level == 0) |
| 5583 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5584 | if (mddev->level == 5 && |
| 5585 | mddev->layout == ALGORITHM_PARITY_N) { |
| 5586 | mddev->new_layout = 0; |
| 5587 | mddev->new_level = 4; |
| 5588 | return setup_conf(mddev); |
| 5589 | } |
| 5590 | return ERR_PTR(-EINVAL); |
| 5591 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5592 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5593 | static struct md_personality raid5_personality; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5594 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5595 | static void *raid6_takeover(struct mddev *mddev) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5596 | { |
| 5597 | /* Currently can only take over a raid5. We map the |
| 5598 | * personality to an equivalent raid6 personality |
| 5599 | * with the Q block at the end. |
| 5600 | */ |
| 5601 | int new_layout; |
| 5602 | |
| 5603 | if (mddev->pers != &raid5_personality) |
| 5604 | return ERR_PTR(-EINVAL); |
| 5605 | if (mddev->degraded > 1) |
| 5606 | return ERR_PTR(-EINVAL); |
| 5607 | if (mddev->raid_disks > 253) |
| 5608 | return ERR_PTR(-EINVAL); |
| 5609 | if (mddev->raid_disks < 3) |
| 5610 | return ERR_PTR(-EINVAL); |
| 5611 | |
| 5612 | switch (mddev->layout) { |
| 5613 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 5614 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 5615 | break; |
| 5616 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 5617 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 5618 | break; |
| 5619 | case ALGORITHM_LEFT_SYMMETRIC: |
| 5620 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 5621 | break; |
| 5622 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 5623 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 5624 | break; |
| 5625 | case ALGORITHM_PARITY_0: |
| 5626 | new_layout = ALGORITHM_PARITY_0_6; |
| 5627 | break; |
| 5628 | case ALGORITHM_PARITY_N: |
| 5629 | new_layout = ALGORITHM_PARITY_N; |
| 5630 | break; |
| 5631 | default: |
| 5632 | return ERR_PTR(-EINVAL); |
| 5633 | } |
| 5634 | mddev->new_level = 6; |
| 5635 | mddev->new_layout = new_layout; |
| 5636 | mddev->delta_disks = 1; |
| 5637 | mddev->raid_disks += 1; |
| 5638 | return setup_conf(mddev); |
| 5639 | } |
| 5640 | |
| 5641 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5642 | static struct md_personality raid6_personality = |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5643 | { |
| 5644 | .name = "raid6", |
| 5645 | .level = 6, |
| 5646 | .owner = THIS_MODULE, |
| 5647 | .make_request = make_request, |
| 5648 | .run = run, |
| 5649 | .stop = stop, |
| 5650 | .status = status, |
| 5651 | .error_handler = error, |
| 5652 | .hot_add_disk = raid5_add_disk, |
| 5653 | .hot_remove_disk= raid5_remove_disk, |
| 5654 | .spare_active = raid5_spare_active, |
| 5655 | .sync_request = sync_request, |
| 5656 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5657 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5658 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5659 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5660 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5661 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5662 | .takeover = raid6_takeover, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5663 | }; |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5664 | static struct md_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | { |
| 5666 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5667 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5668 | .owner = THIS_MODULE, |
| 5669 | .make_request = make_request, |
| 5670 | .run = run, |
| 5671 | .stop = stop, |
| 5672 | .status = status, |
| 5673 | .error_handler = error, |
| 5674 | .hot_add_disk = raid5_add_disk, |
| 5675 | .hot_remove_disk= raid5_remove_disk, |
| 5676 | .spare_active = raid5_spare_active, |
| 5677 | .sync_request = sync_request, |
| 5678 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5679 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5680 | .check_reshape = raid5_check_reshape, |
| 5681 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5682 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5683 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5684 | .takeover = raid5_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | }; |
| 5686 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 5687 | static struct md_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5689 | .name = "raid4", |
| 5690 | .level = 4, |
| 5691 | .owner = THIS_MODULE, |
| 5692 | .make_request = make_request, |
| 5693 | .run = run, |
| 5694 | .stop = stop, |
| 5695 | .status = status, |
| 5696 | .error_handler = error, |
| 5697 | .hot_add_disk = raid5_add_disk, |
| 5698 | .hot_remove_disk= raid5_remove_disk, |
| 5699 | .spare_active = raid5_spare_active, |
| 5700 | .sync_request = sync_request, |
| 5701 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5702 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 5703 | .check_reshape = raid5_check_reshape, |
| 5704 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5705 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5706 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5707 | .takeover = raid4_takeover, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5708 | }; |
| 5709 | |
| 5710 | static int __init raid5_init(void) |
| 5711 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5712 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5713 | register_md_personality(&raid5_personality); |
| 5714 | register_md_personality(&raid4_personality); |
| 5715 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | } |
| 5717 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5718 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5720 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5721 | unregister_md_personality(&raid5_personality); |
| 5722 | unregister_md_personality(&raid4_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | module_init(raid5_init); |
| 5726 | module_exit(raid5_exit); |
| 5727 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 5728 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5729 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 5730 | MODULE_ALIAS("md-raid5"); |
| 5731 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5732 | MODULE_ALIAS("md-level-5"); |
| 5733 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5734 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 5735 | MODULE_ALIAS("md-raid6"); |
| 5736 | MODULE_ALIAS("md-level-6"); |
| 5737 | |
| 5738 | /* This used to be two separate modules, they were: */ |
| 5739 | MODULE_ALIAS("raid5"); |
| 5740 | MODULE_ALIAS("raid6"); |