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. |
| 30 | * conf->bm_write is the number of the last batch successfully written. |
| 31 | * conf->bm_flush is the number of the last batch that was closed to |
| 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 |
| 35 | * the number of the batch it will be in. This is bm_flush+1. |
| 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> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 53 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 54 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 55 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 56 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /* |
| 59 | * Stripe cache |
| 60 | */ |
| 61 | |
| 62 | #define NR_STRIPES 256 |
| 63 | #define STRIPE_SIZE PAGE_SIZE |
| 64 | #define STRIPE_SHIFT (PAGE_SHIFT - 9) |
| 65 | #define STRIPE_SECTORS (STRIPE_SIZE>>9) |
| 66 | #define IO_THRESHOLD 1 |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 67 | #define BYPASS_THRESHOLD 1 |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 68 | #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define HASH_MASK (NR_HASH - 1) |
| 70 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 71 | #define stripe_hash(conf, sect) (&((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* bio's attached to a stripe+device for I/O are linked together in bi_sector |
| 74 | * order without overlap. There may be several bio's per stripe+device, and |
| 75 | * a bio could span several devices. |
| 76 | * When walking this list for a particular stripe+device, we must never proceed |
| 77 | * beyond a bio that extends past this device, as the next bio might no longer |
| 78 | * be valid. |
| 79 | * This macro is used to determine the 'next' bio in the list, given the sector |
| 80 | * of the current stripe+device |
| 81 | */ |
| 82 | #define r5_next_bio(bio, sect) ( ( (bio)->bi_sector + ((bio)->bi_size>>9) < sect + STRIPE_SECTORS) ? (bio)->bi_next : NULL) |
| 83 | /* |
| 84 | * The following can be used to debug the driver |
| 85 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #define RAID5_PARANOIA 1 |
| 87 | #if RAID5_PARANOIA && defined(CONFIG_SMP) |
| 88 | # define CHECK_DEVLOCK() assert_spin_locked(&conf->device_lock) |
| 89 | #else |
| 90 | # define CHECK_DEVLOCK() |
| 91 | #endif |
| 92 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 93 | #ifdef DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define inline |
| 95 | #define __inline__ |
| 96 | #endif |
| 97 | |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 98 | #define printk_rl(args...) ((void) (printk_ratelimit() && printk(args))) |
| 99 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 100 | /* |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 101 | * We maintain a biased count of active stripes in the bottom 16 bits of |
| 102 | * bi_phys_segments, and a count of processed stripes in the upper 16 bits |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 103 | */ |
| 104 | static inline int raid5_bi_phys_segments(struct bio *bio) |
| 105 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 106 | return bio->bi_phys_segments & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static inline int raid5_bi_hw_segments(struct bio *bio) |
| 110 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 111 | return (bio->bi_phys_segments >> 16) & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static inline int raid5_dec_bi_phys_segments(struct bio *bio) |
| 115 | { |
| 116 | --bio->bi_phys_segments; |
| 117 | return raid5_bi_phys_segments(bio); |
| 118 | } |
| 119 | |
| 120 | static inline int raid5_dec_bi_hw_segments(struct bio *bio) |
| 121 | { |
| 122 | unsigned short val = raid5_bi_hw_segments(bio); |
| 123 | |
| 124 | --val; |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 125 | bio->bi_phys_segments = (val << 16) | raid5_bi_phys_segments(bio); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 126 | return val; |
| 127 | } |
| 128 | |
| 129 | static inline void raid5_set_bi_hw_segments(struct bio *bio, unsigned int cnt) |
| 130 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 131 | bio->bi_phys_segments = raid5_bi_phys_segments(bio) || (cnt << 16); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 132 | } |
| 133 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 134 | /* Find first data disk in a raid6 stripe */ |
| 135 | static inline int raid6_d0(struct stripe_head *sh) |
| 136 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 137 | if (sh->ddf_layout) |
| 138 | /* ddf always start from first device */ |
| 139 | return 0; |
| 140 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 141 | if (sh->qd_idx == sh->disks - 1) |
| 142 | return 0; |
| 143 | else |
| 144 | return sh->qd_idx + 1; |
| 145 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 146 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 147 | { |
| 148 | disk++; |
| 149 | return (disk < raid_disks) ? disk : 0; |
| 150 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 151 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 152 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 153 | * We need to map each disk to a 'slot', where the data disks are slot |
| 154 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 155 | * is raid_disks-1. This help does that mapping. |
| 156 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 157 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 158 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 159 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 160 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 161 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 162 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 163 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 164 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 165 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 166 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 167 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 168 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 169 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 170 | return slot; |
| 171 | } |
| 172 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 173 | static void return_io(struct bio *return_bi) |
| 174 | { |
| 175 | struct bio *bi = return_bi; |
| 176 | while (bi) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 177 | |
| 178 | return_bi = bi->bi_next; |
| 179 | bi->bi_next = NULL; |
| 180 | bi->bi_size = 0; |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 181 | bio_endio(bi, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 182 | bi = return_bi; |
| 183 | } |
| 184 | } |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static void print_raid5_conf (raid5_conf_t *conf); |
| 187 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 188 | static int stripe_operations_active(struct stripe_head *sh) |
| 189 | { |
| 190 | return sh->check_state || sh->reconstruct_state || |
| 191 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 192 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 193 | } |
| 194 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 195 | static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | if (atomic_dec_and_test(&sh->count)) { |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 198 | BUG_ON(!list_empty(&sh->lru)); |
| 199 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
NeilBrown | 7c785b7 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 201 | if (test_bit(STRIPE_DELAYED, &sh->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | list_add_tail(&sh->lru, &conf->delayed_list); |
NeilBrown | 7c785b7 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 203 | blk_plug_device(conf->mddev->queue); |
| 204 | } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 205 | sh->bm_seq - conf->seq_write > 0) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 206 | list_add_tail(&sh->lru, &conf->bitmap_list); |
NeilBrown | 7c785b7 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 207 | blk_plug_device(conf->mddev->queue); |
| 208 | } else { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 209 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | list_add_tail(&sh->lru, &conf->handle_list); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | md_wakeup_thread(conf->mddev->thread); |
| 213 | } else { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 214 | BUG_ON(stripe_operations_active(sh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
| 216 | atomic_dec(&conf->preread_active_stripes); |
| 217 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) |
| 218 | md_wakeup_thread(conf->mddev->thread); |
| 219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | atomic_dec(&conf->active_stripes); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 221 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 222 | list_add_tail(&sh->lru, &conf->inactive_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | wake_up(&conf->wait_for_stripe); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 224 | if (conf->retry_read_aligned) |
| 225 | md_wakeup_thread(conf->mddev->thread); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | static void release_stripe(struct stripe_head *sh) |
| 232 | { |
| 233 | raid5_conf_t *conf = sh->raid_conf; |
| 234 | unsigned long flags; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | spin_lock_irqsave(&conf->device_lock, flags); |
| 237 | __release_stripe(conf, sh); |
| 238 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 239 | } |
| 240 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 241 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 243 | pr_debug("remove_hash(), stripe %llu\n", |
| 244 | (unsigned long long)sh->sector); |
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 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 249 | static inline void insert_hash(raid5_conf_t *conf, struct stripe_head *sh) |
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 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 253 | pr_debug("insert_hash(), stripe %llu\n", |
| 254 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | CHECK_DEVLOCK(); |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 257 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
| 261 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
| 262 | static struct stripe_head *get_free_stripe(raid5_conf_t *conf) |
| 263 | { |
| 264 | struct stripe_head *sh = NULL; |
| 265 | struct list_head *first; |
| 266 | |
| 267 | CHECK_DEVLOCK(); |
| 268 | if (list_empty(&conf->inactive_list)) |
| 269 | goto out; |
| 270 | first = conf->inactive_list.next; |
| 271 | sh = list_entry(first, struct stripe_head, lru); |
| 272 | list_del_init(first); |
| 273 | remove_hash(sh); |
| 274 | atomic_inc(&conf->active_stripes); |
| 275 | out: |
| 276 | return sh; |
| 277 | } |
| 278 | |
| 279 | static void shrink_buffers(struct stripe_head *sh, int num) |
| 280 | { |
| 281 | struct page *p; |
| 282 | int i; |
| 283 | |
| 284 | for (i=0; i<num ; i++) { |
| 285 | p = sh->dev[i].page; |
| 286 | if (!p) |
| 287 | continue; |
| 288 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 289 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | static int grow_buffers(struct stripe_head *sh, int num) |
| 294 | { |
| 295 | int i; |
| 296 | |
| 297 | for (i=0; i<num; i++) { |
| 298 | struct page *page; |
| 299 | |
| 300 | if (!(page = alloc_page(GFP_KERNEL))) { |
| 301 | return 1; |
| 302 | } |
| 303 | sh->dev[i].page = page; |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 308 | static void raid5_build_block(struct stripe_head *sh, int i, int previous); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 309 | static void stripe_set_idx(sector_t stripe, raid5_conf_t *conf, int previous, |
| 310 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 312 | 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] | 313 | { |
| 314 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 315 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 317 | BUG_ON(atomic_read(&sh->count) != 0); |
| 318 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 319 | BUG_ON(stripe_operations_active(sh)); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | CHECK_DEVLOCK(); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 322 | pr_debug("init_stripe called, stripe %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | (unsigned long long)sh->sector); |
| 324 | |
| 325 | remove_hash(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 326 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 327 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 328 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 330 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | sh->state = 0; |
| 332 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 333 | |
| 334 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | struct r5dev *dev = &sh->dev[i]; |
| 336 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 337 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | test_bit(R5_LOCKED, &dev->flags)) { |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 339 | 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] | 340 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 341 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | test_bit(R5_LOCKED, &dev->flags)); |
| 343 | BUG(); |
| 344 | } |
| 345 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 346 | raid5_build_block(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | insert_hash(conf, sh); |
| 349 | } |
| 350 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 351 | static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector, |
| 352 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
| 354 | struct stripe_head *sh; |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 355 | struct hlist_node *hn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | CHECK_DEVLOCK(); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 358 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 359 | hlist_for_each_entry(sh, hn, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 360 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 362 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return NULL; |
| 364 | } |
| 365 | |
| 366 | static void unplug_slaves(mddev_t *mddev); |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 367 | static void raid5_unplug_device(struct request_queue *q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 369 | static struct stripe_head * |
| 370 | get_active_stripe(raid5_conf_t *conf, sector_t sector, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 371 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
| 373 | struct stripe_head *sh; |
| 374 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 375 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | spin_lock_irq(&conf->device_lock); |
| 378 | |
| 379 | do { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 380 | wait_event_lock_irq(conf->wait_for_stripe, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 381 | conf->quiesce == 0 || noquiesce, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 382 | conf->device_lock, /* nothing */); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 383 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (!sh) { |
| 385 | if (!conf->inactive_blocked) |
| 386 | sh = get_free_stripe(conf); |
| 387 | if (noblock && sh == NULL) |
| 388 | break; |
| 389 | if (!sh) { |
| 390 | conf->inactive_blocked = 1; |
| 391 | wait_event_lock_irq(conf->wait_for_stripe, |
| 392 | !list_empty(&conf->inactive_list) && |
NeilBrown | 5036805 | 2005-12-12 02:39:17 -0800 | [diff] [blame] | 393 | (atomic_read(&conf->active_stripes) |
| 394 | < (conf->max_nr_stripes *3/4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | || !conf->inactive_blocked), |
| 396 | conf->device_lock, |
NeilBrown | f437078 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 397 | raid5_unplug_device(conf->mddev->queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | ); |
| 399 | conf->inactive_blocked = 0; |
| 400 | } else |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 401 | init_stripe(sh, sector, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } else { |
| 403 | if (atomic_read(&sh->count)) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 404 | BUG_ON(!list_empty(&sh->lru) |
| 405 | && !test_bit(STRIPE_EXPANDING, &sh->state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } else { |
| 407 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 408 | atomic_inc(&conf->active_stripes); |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 409 | if (list_empty(&sh->lru) && |
| 410 | !test_bit(STRIPE_EXPANDING, &sh->state)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 411 | BUG(); |
| 412 | list_del_init(&sh->lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | } while (sh == NULL); |
| 416 | |
| 417 | if (sh) |
| 418 | atomic_inc(&sh->count); |
| 419 | |
| 420 | spin_unlock_irq(&conf->device_lock); |
| 421 | return sh; |
| 422 | } |
| 423 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 424 | static void |
| 425 | raid5_end_read_request(struct bio *bi, int error); |
| 426 | static void |
| 427 | raid5_end_write_request(struct bio *bi, int error); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 428 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 429 | 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] | 430 | { |
| 431 | raid5_conf_t *conf = sh->raid_conf; |
| 432 | int i, disks = sh->disks; |
| 433 | |
| 434 | might_sleep(); |
| 435 | |
| 436 | for (i = disks; i--; ) { |
| 437 | int rw; |
| 438 | struct bio *bi; |
| 439 | mdk_rdev_t *rdev; |
| 440 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) |
| 441 | rw = WRITE; |
| 442 | else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
| 443 | rw = READ; |
| 444 | else |
| 445 | continue; |
| 446 | |
| 447 | bi = &sh->dev[i].req; |
| 448 | |
| 449 | bi->bi_rw = rw; |
| 450 | if (rw == WRITE) |
| 451 | bi->bi_end_io = raid5_end_write_request; |
| 452 | else |
| 453 | bi->bi_end_io = raid5_end_read_request; |
| 454 | |
| 455 | rcu_read_lock(); |
| 456 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 457 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 458 | rdev = NULL; |
| 459 | if (rdev) |
| 460 | atomic_inc(&rdev->nr_pending); |
| 461 | rcu_read_unlock(); |
| 462 | |
| 463 | if (rdev) { |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 464 | if (s->syncing || s->expanding || s->expanded) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 465 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 466 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 467 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 468 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 469 | bi->bi_bdev = rdev->bdev; |
| 470 | pr_debug("%s: for %llu schedule op %ld on disc %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 471 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 472 | bi->bi_rw, i); |
| 473 | atomic_inc(&sh->count); |
| 474 | bi->bi_sector = sh->sector + rdev->data_offset; |
| 475 | bi->bi_flags = 1 << BIO_UPTODATE; |
| 476 | bi->bi_vcnt = 1; |
| 477 | bi->bi_max_vecs = 1; |
| 478 | bi->bi_idx = 0; |
| 479 | bi->bi_io_vec = &sh->dev[i].vec; |
| 480 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 481 | bi->bi_io_vec[0].bv_offset = 0; |
| 482 | bi->bi_size = STRIPE_SIZE; |
| 483 | bi->bi_next = NULL; |
| 484 | if (rw == WRITE && |
| 485 | test_bit(R5_ReWrite, &sh->dev[i].flags)) |
| 486 | atomic_add(STRIPE_SECTORS, |
| 487 | &rdev->corrected_errors); |
| 488 | generic_make_request(bi); |
| 489 | } else { |
| 490 | if (rw == WRITE) |
| 491 | set_bit(STRIPE_DEGRADED, &sh->state); |
| 492 | pr_debug("skip op %ld on disc %d for sector %llu\n", |
| 493 | bi->bi_rw, i, (unsigned long long)sh->sector); |
| 494 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 495 | set_bit(STRIPE_HANDLE, &sh->state); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | static struct dma_async_tx_descriptor * |
| 501 | async_copy_data(int frombio, struct bio *bio, struct page *page, |
| 502 | sector_t sector, struct dma_async_tx_descriptor *tx) |
| 503 | { |
| 504 | struct bio_vec *bvl; |
| 505 | struct page *bio_page; |
| 506 | int i; |
| 507 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 508 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 509 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 510 | |
| 511 | if (bio->bi_sector >= sector) |
| 512 | page_offset = (signed)(bio->bi_sector - sector) * 512; |
| 513 | else |
| 514 | page_offset = (signed)(sector - bio->bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 515 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 516 | if (frombio) |
| 517 | flags |= ASYNC_TX_FENCE; |
| 518 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 519 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 520 | bio_for_each_segment(bvl, bio, i) { |
| 521 | int len = bio_iovec_idx(bio, i)->bv_len; |
| 522 | int clen; |
| 523 | int b_offset = 0; |
| 524 | |
| 525 | if (page_offset < 0) { |
| 526 | b_offset = -page_offset; |
| 527 | page_offset += b_offset; |
| 528 | len -= b_offset; |
| 529 | } |
| 530 | |
| 531 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 532 | clen = STRIPE_SIZE - page_offset; |
| 533 | else |
| 534 | clen = len; |
| 535 | |
| 536 | if (clen > 0) { |
| 537 | b_offset += bio_iovec_idx(bio, i)->bv_offset; |
| 538 | bio_page = bio_iovec_idx(bio, i)->bv_page; |
| 539 | if (frombio) |
| 540 | tx = async_memcpy(page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 541 | b_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 542 | else |
| 543 | tx = async_memcpy(bio_page, page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 544 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 545 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 546 | /* chain the operations */ |
| 547 | submit.depend_tx = tx; |
| 548 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 549 | if (clen < len) /* hit end of page */ |
| 550 | break; |
| 551 | page_offset += len; |
| 552 | } |
| 553 | |
| 554 | return tx; |
| 555 | } |
| 556 | |
| 557 | static void ops_complete_biofill(void *stripe_head_ref) |
| 558 | { |
| 559 | struct stripe_head *sh = stripe_head_ref; |
| 560 | struct bio *return_bi = NULL; |
| 561 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 562 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 563 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 564 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 565 | (unsigned long long)sh->sector); |
| 566 | |
| 567 | /* clear completed biofills */ |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 568 | spin_lock_irq(&conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 569 | for (i = sh->disks; i--; ) { |
| 570 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 571 | |
| 572 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 573 | /* and check if we need to reply to a read request, |
| 574 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 575 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 576 | */ |
| 577 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 578 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 579 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 580 | BUG_ON(!dev->read); |
| 581 | rbi = dev->read; |
| 582 | dev->read = NULL; |
| 583 | while (rbi && rbi->bi_sector < |
| 584 | dev->sector + STRIPE_SECTORS) { |
| 585 | rbi2 = r5_next_bio(rbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 586 | if (!raid5_dec_bi_phys_segments(rbi)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 587 | rbi->bi_next = return_bi; |
| 588 | return_bi = rbi; |
| 589 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 590 | rbi = rbi2; |
| 591 | } |
| 592 | } |
| 593 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 594 | spin_unlock_irq(&conf->device_lock); |
| 595 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 596 | |
| 597 | return_io(return_bi); |
| 598 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 599 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 600 | release_stripe(sh); |
| 601 | } |
| 602 | |
| 603 | static void ops_run_biofill(struct stripe_head *sh) |
| 604 | { |
| 605 | struct dma_async_tx_descriptor *tx = NULL; |
| 606 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 607 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 608 | int i; |
| 609 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 610 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 611 | (unsigned long long)sh->sector); |
| 612 | |
| 613 | for (i = sh->disks; i--; ) { |
| 614 | struct r5dev *dev = &sh->dev[i]; |
| 615 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 616 | struct bio *rbi; |
| 617 | spin_lock_irq(&conf->device_lock); |
| 618 | dev->read = rbi = dev->toread; |
| 619 | dev->toread = NULL; |
| 620 | spin_unlock_irq(&conf->device_lock); |
| 621 | while (rbi && rbi->bi_sector < |
| 622 | dev->sector + STRIPE_SECTORS) { |
| 623 | tx = async_copy_data(0, rbi, dev->page, |
| 624 | dev->sector, tx); |
| 625 | rbi = r5_next_bio(rbi, dev->sector); |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 631 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 632 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 635 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 636 | { |
| 637 | struct r5dev *tgt; |
| 638 | |
| 639 | if (target < 0) |
| 640 | return; |
| 641 | |
| 642 | tgt = &sh->dev[target]; |
| 643 | set_bit(R5_UPTODATE, &tgt->flags); |
| 644 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 645 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 646 | } |
| 647 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 648 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 649 | { |
| 650 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 651 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 652 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 653 | (unsigned long long)sh->sector); |
| 654 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 655 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 656 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 657 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 658 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 659 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 660 | if (sh->check_state == check_state_compute_run) |
| 661 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 662 | set_bit(STRIPE_HANDLE, &sh->state); |
| 663 | release_stripe(sh); |
| 664 | } |
| 665 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 666 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 667 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 668 | struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 669 | { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 670 | return percpu->scribble + sizeof(struct page *) * (sh->disks + 2); |
| 671 | } |
| 672 | |
| 673 | static struct dma_async_tx_descriptor * |
| 674 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 675 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 676 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 677 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 678 | int target = sh->ops.target; |
| 679 | struct r5dev *tgt = &sh->dev[target]; |
| 680 | struct page *xor_dest = tgt->page; |
| 681 | int count = 0; |
| 682 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 683 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 684 | int i; |
| 685 | |
| 686 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 687 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 688 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 689 | |
| 690 | for (i = disks; i--; ) |
| 691 | if (i != target) |
| 692 | xor_srcs[count++] = sh->dev[i].page; |
| 693 | |
| 694 | atomic_inc(&sh->count); |
| 695 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 696 | 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] | 697 | ops_complete_compute, sh, to_addr_conv(sh, percpu)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 698 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 699 | 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] | 700 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 701 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 702 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 703 | return tx; |
| 704 | } |
| 705 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 706 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 707 | * @srcs - (struct page *) array of size sh->disks |
| 708 | * @sh - stripe_head to parse |
| 709 | * |
| 710 | * Populates srcs in proper layout order for the stripe and returns the |
| 711 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 712 | * destination buffer is recorded in srcs[count] and the Q destination |
| 713 | * is recorded in srcs[count+1]]. |
| 714 | */ |
| 715 | static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh) |
| 716 | { |
| 717 | int disks = sh->disks; |
| 718 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 719 | int d0_idx = raid6_d0(sh); |
| 720 | int count; |
| 721 | int i; |
| 722 | |
| 723 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 724 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 725 | |
| 726 | count = 0; |
| 727 | i = d0_idx; |
| 728 | do { |
| 729 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 730 | |
| 731 | srcs[slot] = sh->dev[i].page; |
| 732 | i = raid6_next_disk(i, disks); |
| 733 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 734 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 735 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | static struct dma_async_tx_descriptor * |
| 739 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 740 | { |
| 741 | int disks = sh->disks; |
| 742 | struct page **blocks = percpu->scribble; |
| 743 | int target; |
| 744 | int qd_idx = sh->qd_idx; |
| 745 | struct dma_async_tx_descriptor *tx; |
| 746 | struct async_submit_ctl submit; |
| 747 | struct r5dev *tgt; |
| 748 | struct page *dest; |
| 749 | int i; |
| 750 | int count; |
| 751 | |
| 752 | if (sh->ops.target < 0) |
| 753 | target = sh->ops.target2; |
| 754 | else if (sh->ops.target2 < 0) |
| 755 | target = sh->ops.target; |
| 756 | else |
| 757 | /* we should only have one valid target */ |
| 758 | BUG(); |
| 759 | BUG_ON(target < 0); |
| 760 | pr_debug("%s: stripe %llu block: %d\n", |
| 761 | __func__, (unsigned long long)sh->sector, target); |
| 762 | |
| 763 | tgt = &sh->dev[target]; |
| 764 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 765 | dest = tgt->page; |
| 766 | |
| 767 | atomic_inc(&sh->count); |
| 768 | |
| 769 | if (target == qd_idx) { |
| 770 | count = set_syndrome_sources(blocks, sh); |
| 771 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 772 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 773 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 774 | ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 775 | to_addr_conv(sh, percpu)); |
| 776 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 777 | } else { |
| 778 | /* Compute any data- or p-drive using XOR */ |
| 779 | count = 0; |
| 780 | for (i = disks; i-- ; ) { |
| 781 | if (i == target || i == qd_idx) |
| 782 | continue; |
| 783 | blocks[count++] = sh->dev[i].page; |
| 784 | } |
| 785 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 786 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 787 | NULL, ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 788 | to_addr_conv(sh, percpu)); |
| 789 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 790 | } |
| 791 | |
| 792 | return tx; |
| 793 | } |
| 794 | |
| 795 | static struct dma_async_tx_descriptor * |
| 796 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 797 | { |
| 798 | int i, count, disks = sh->disks; |
| 799 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 800 | int d0_idx = raid6_d0(sh); |
| 801 | int faila = -1, failb = -1; |
| 802 | int target = sh->ops.target; |
| 803 | int target2 = sh->ops.target2; |
| 804 | struct r5dev *tgt = &sh->dev[target]; |
| 805 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 806 | struct dma_async_tx_descriptor *tx; |
| 807 | struct page **blocks = percpu->scribble; |
| 808 | struct async_submit_ctl submit; |
| 809 | |
| 810 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 811 | __func__, (unsigned long long)sh->sector, target, target2); |
| 812 | BUG_ON(target < 0 || target2 < 0); |
| 813 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 814 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 815 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 816 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 817 | * slot number conversion for 'faila' and 'failb' |
| 818 | */ |
| 819 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 820 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 821 | count = 0; |
| 822 | i = d0_idx; |
| 823 | do { |
| 824 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 825 | |
| 826 | blocks[slot] = sh->dev[i].page; |
| 827 | |
| 828 | if (i == target) |
| 829 | faila = slot; |
| 830 | if (i == target2) |
| 831 | failb = slot; |
| 832 | i = raid6_next_disk(i, disks); |
| 833 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 834 | |
| 835 | BUG_ON(faila == failb); |
| 836 | if (failb < faila) |
| 837 | swap(faila, failb); |
| 838 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 839 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 840 | |
| 841 | atomic_inc(&sh->count); |
| 842 | |
| 843 | if (failb == syndrome_disks+1) { |
| 844 | /* Q disk is one of the missing disks */ |
| 845 | if (faila == syndrome_disks) { |
| 846 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 847 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 848 | ops_complete_compute, sh, |
| 849 | to_addr_conv(sh, percpu)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 850 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 851 | STRIPE_SIZE, &submit); |
| 852 | } else { |
| 853 | struct page *dest; |
| 854 | int data_target; |
| 855 | int qd_idx = sh->qd_idx; |
| 856 | |
| 857 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 858 | if (target == qd_idx) |
| 859 | data_target = target2; |
| 860 | else |
| 861 | data_target = target; |
| 862 | |
| 863 | count = 0; |
| 864 | for (i = disks; i-- ; ) { |
| 865 | if (i == data_target || i == qd_idx) |
| 866 | continue; |
| 867 | blocks[count++] = sh->dev[i].page; |
| 868 | } |
| 869 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 870 | init_async_submit(&submit, |
| 871 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 872 | NULL, NULL, NULL, |
| 873 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 874 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 875 | &submit); |
| 876 | |
| 877 | count = set_syndrome_sources(blocks, sh); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 878 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 879 | ops_complete_compute, sh, |
| 880 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 881 | return async_gen_syndrome(blocks, 0, count+2, |
| 882 | STRIPE_SIZE, &submit); |
| 883 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 884 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 885 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 886 | ops_complete_compute, sh, |
| 887 | to_addr_conv(sh, percpu)); |
| 888 | if (failb == syndrome_disks) { |
| 889 | /* We're missing D+P. */ |
| 890 | return async_raid6_datap_recov(syndrome_disks+2, |
| 891 | STRIPE_SIZE, faila, |
| 892 | blocks, &submit); |
| 893 | } else { |
| 894 | /* We're missing D+D. */ |
| 895 | return async_raid6_2data_recov(syndrome_disks+2, |
| 896 | STRIPE_SIZE, faila, failb, |
| 897 | blocks, &submit); |
| 898 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
| 902 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 903 | static void ops_complete_prexor(void *stripe_head_ref) |
| 904 | { |
| 905 | struct stripe_head *sh = stripe_head_ref; |
| 906 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 907 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 908 | (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static struct dma_async_tx_descriptor * |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 912 | ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 913 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 914 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 915 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 916 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 917 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 918 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 919 | |
| 920 | /* existing parity data subtracted */ |
| 921 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 922 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 923 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 924 | (unsigned long long)sh->sector); |
| 925 | |
| 926 | for (i = disks; i--; ) { |
| 927 | struct r5dev *dev = &sh->dev[i]; |
| 928 | /* Only process blocks that are known to be uptodate */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 929 | if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 930 | xor_srcs[count++] = dev->page; |
| 931 | } |
| 932 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 933 | 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] | 934 | ops_complete_prexor, sh, to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 935 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 936 | |
| 937 | return tx; |
| 938 | } |
| 939 | |
| 940 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 941 | 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] | 942 | { |
| 943 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 944 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 945 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 946 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 947 | (unsigned long long)sh->sector); |
| 948 | |
| 949 | for (i = disks; i--; ) { |
| 950 | struct r5dev *dev = &sh->dev[i]; |
| 951 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 952 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 953 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 954 | struct bio *wbi; |
| 955 | |
| 956 | spin_lock(&sh->lock); |
| 957 | chosen = dev->towrite; |
| 958 | dev->towrite = NULL; |
| 959 | BUG_ON(dev->written); |
| 960 | wbi = dev->written = chosen; |
| 961 | spin_unlock(&sh->lock); |
| 962 | |
| 963 | while (wbi && wbi->bi_sector < |
| 964 | dev->sector + STRIPE_SECTORS) { |
| 965 | tx = async_copy_data(1, wbi, dev->page, |
| 966 | dev->sector, tx); |
| 967 | wbi = r5_next_bio(wbi, dev->sector); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | return tx; |
| 973 | } |
| 974 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 975 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 976 | { |
| 977 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 978 | int disks = sh->disks; |
| 979 | int pd_idx = sh->pd_idx; |
| 980 | int qd_idx = sh->qd_idx; |
| 981 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 982 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 983 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 984 | (unsigned long long)sh->sector); |
| 985 | |
| 986 | for (i = disks; i--; ) { |
| 987 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 988 | |
| 989 | if (dev->written || i == pd_idx || i == qd_idx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 990 | set_bit(R5_UPTODATE, &dev->flags); |
| 991 | } |
| 992 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 993 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 994 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 995 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 996 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 997 | else { |
| 998 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 999 | sh->reconstruct_state = reconstruct_state_result; |
| 1000 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1001 | |
| 1002 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1003 | release_stripe(sh); |
| 1004 | } |
| 1005 | |
| 1006 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1007 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1008 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1009 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1010 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1011 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1012 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1013 | int count = 0, pd_idx = sh->pd_idx, i; |
| 1014 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1015 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1016 | unsigned long flags; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1017 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1018 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1019 | (unsigned long long)sh->sector); |
| 1020 | |
| 1021 | /* check if prexor is active which means only process blocks |
| 1022 | * that are part of a read-modify-write (written) |
| 1023 | */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1024 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1025 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1026 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1027 | for (i = disks; i--; ) { |
| 1028 | struct r5dev *dev = &sh->dev[i]; |
| 1029 | if (dev->written) |
| 1030 | xor_srcs[count++] = dev->page; |
| 1031 | } |
| 1032 | } else { |
| 1033 | xor_dest = sh->dev[pd_idx].page; |
| 1034 | for (i = disks; i--; ) { |
| 1035 | struct r5dev *dev = &sh->dev[i]; |
| 1036 | if (i != pd_idx) |
| 1037 | xor_srcs[count++] = dev->page; |
| 1038 | } |
| 1039 | } |
| 1040 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1041 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1042 | * 2/ if we did not prexor then we are redoing the parity |
| 1043 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1044 | * for the synchronous xor case |
| 1045 | */ |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 1046 | flags = ASYNC_TX_ACK | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1047 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
| 1048 | |
| 1049 | atomic_inc(&sh->count); |
| 1050 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1051 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, sh, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1052 | to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1053 | if (unlikely(count == 1)) |
| 1054 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1055 | else |
| 1056 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1059 | static void |
| 1060 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1061 | struct dma_async_tx_descriptor *tx) |
| 1062 | { |
| 1063 | struct async_submit_ctl submit; |
| 1064 | struct page **blocks = percpu->scribble; |
| 1065 | int count; |
| 1066 | |
| 1067 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1068 | |
| 1069 | count = set_syndrome_sources(blocks, sh); |
| 1070 | |
| 1071 | atomic_inc(&sh->count); |
| 1072 | |
| 1073 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct, |
| 1074 | sh, to_addr_conv(sh, percpu)); |
| 1075 | async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | static void ops_complete_check(void *stripe_head_ref) |
| 1079 | { |
| 1080 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1081 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1082 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1083 | (unsigned long long)sh->sector); |
| 1084 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1085 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1086 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1087 | release_stripe(sh); |
| 1088 | } |
| 1089 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1090 | 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] | 1091 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1092 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1093 | int pd_idx = sh->pd_idx; |
| 1094 | int qd_idx = sh->qd_idx; |
| 1095 | struct page *xor_dest; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1096 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1097 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1098 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1099 | int count; |
| 1100 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1101 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1102 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1103 | (unsigned long long)sh->sector); |
| 1104 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1105 | count = 0; |
| 1106 | xor_dest = sh->dev[pd_idx].page; |
| 1107 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1108 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1109 | if (i == pd_idx || i == qd_idx) |
| 1110 | continue; |
| 1111 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1114 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
| 1115 | to_addr_conv(sh, percpu)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1116 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1117 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1118 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1119 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1120 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 1121 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1124 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 1125 | { |
| 1126 | struct page **srcs = percpu->scribble; |
| 1127 | struct async_submit_ctl submit; |
| 1128 | int count; |
| 1129 | |
| 1130 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 1131 | (unsigned long long)sh->sector, checkp); |
| 1132 | |
| 1133 | count = set_syndrome_sources(srcs, sh); |
| 1134 | if (!checkp) |
| 1135 | srcs[count] = NULL; |
| 1136 | |
| 1137 | atomic_inc(&sh->count); |
| 1138 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
| 1139 | sh, to_addr_conv(sh, percpu)); |
| 1140 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 1141 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 1142 | } |
| 1143 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1144 | 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] | 1145 | { |
| 1146 | int overlap_clear = 0, i, disks = sh->disks; |
| 1147 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1148 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1149 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1150 | struct raid5_percpu *percpu; |
| 1151 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1152 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1153 | cpu = get_cpu(); |
| 1154 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1155 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1156 | ops_run_biofill(sh); |
| 1157 | overlap_clear++; |
| 1158 | } |
| 1159 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1160 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1161 | if (level < 6) |
| 1162 | tx = ops_run_compute5(sh, percpu); |
| 1163 | else { |
| 1164 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 1165 | tx = ops_run_compute6_1(sh, percpu); |
| 1166 | else |
| 1167 | tx = ops_run_compute6_2(sh, percpu); |
| 1168 | } |
| 1169 | /* terminate the chain if reconstruct is not set to be run */ |
| 1170 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1171 | async_tx_ack(tx); |
| 1172 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1173 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1174 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1175 | tx = ops_run_prexor(sh, percpu, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1176 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1177 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1178 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1179 | overlap_clear++; |
| 1180 | } |
| 1181 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1182 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 1183 | if (level < 6) |
| 1184 | ops_run_reconstruct5(sh, percpu, tx); |
| 1185 | else |
| 1186 | ops_run_reconstruct6(sh, percpu, tx); |
| 1187 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1188 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1189 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 1190 | if (sh->check_state == check_state_run) |
| 1191 | ops_run_check_p(sh, percpu); |
| 1192 | else if (sh->check_state == check_state_run_q) |
| 1193 | ops_run_check_pq(sh, percpu, 0); |
| 1194 | else if (sh->check_state == check_state_run_pq) |
| 1195 | ops_run_check_pq(sh, percpu, 1); |
| 1196 | else |
| 1197 | BUG(); |
| 1198 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1199 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1200 | if (overlap_clear) |
| 1201 | for (i = disks; i--; ) { |
| 1202 | struct r5dev *dev = &sh->dev[i]; |
| 1203 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 1204 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 1205 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1206 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1209 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1210 | static void async_run_ops(void *param, async_cookie_t cookie) |
| 1211 | { |
| 1212 | struct stripe_head *sh = param; |
| 1213 | unsigned long ops_request = sh->ops.request; |
| 1214 | |
| 1215 | clear_bit_unlock(STRIPE_OPS_REQ_PENDING, &sh->state); |
| 1216 | wake_up(&sh->ops.wait_for_ops); |
| 1217 | |
| 1218 | __raid_run_ops(sh, ops_request); |
| 1219 | release_stripe(sh); |
| 1220 | } |
| 1221 | |
| 1222 | static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) |
| 1223 | { |
| 1224 | /* since handle_stripe can be called outside of raid5d context |
| 1225 | * we need to ensure sh->ops.request is de-staged before another |
| 1226 | * request arrives |
| 1227 | */ |
| 1228 | wait_event(sh->ops.wait_for_ops, |
| 1229 | !test_and_set_bit_lock(STRIPE_OPS_REQ_PENDING, &sh->state)); |
| 1230 | sh->ops.request = ops_request; |
| 1231 | |
| 1232 | atomic_inc(&sh->count); |
| 1233 | async_schedule(async_run_ops, sh); |
| 1234 | } |
| 1235 | #else |
| 1236 | #define raid_run_ops __raid_run_ops |
| 1237 | #endif |
| 1238 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1239 | static int grow_one_stripe(raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | { |
| 1241 | struct stripe_head *sh; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1242 | int disks = max(conf->raid_disks, conf->previous_raid_disks); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1243 | sh = kmem_cache_alloc(conf->slab_cache, GFP_KERNEL); |
| 1244 | if (!sh) |
| 1245 | return 0; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1246 | memset(sh, 0, sizeof(*sh) + (disks-1)*sizeof(struct r5dev)); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1247 | sh->raid_conf = conf; |
| 1248 | spin_lock_init(&sh->lock); |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1249 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1250 | init_waitqueue_head(&sh->ops.wait_for_ops); |
| 1251 | #endif |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1252 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1253 | if (grow_buffers(sh, disks)) { |
| 1254 | shrink_buffers(sh, disks); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1255 | kmem_cache_free(conf->slab_cache, sh); |
| 1256 | return 0; |
| 1257 | } |
| 1258 | /* we just created an active stripe so... */ |
| 1259 | atomic_set(&sh->count, 1); |
| 1260 | atomic_inc(&conf->active_stripes); |
| 1261 | INIT_LIST_HEAD(&sh->lru); |
| 1262 | release_stripe(sh); |
| 1263 | return 1; |
| 1264 | } |
| 1265 | |
| 1266 | static int grow_stripes(raid5_conf_t *conf, int num) |
| 1267 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1268 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1269 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 1271 | sprintf(conf->cache_name[0], |
| 1272 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 1273 | sprintf(conf->cache_name[1], |
| 1274 | "raid%d-%s-alt", conf->level, mdname(conf->mddev)); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1275 | conf->active_name = 0; |
| 1276 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1278 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | if (!sc) |
| 1280 | return 1; |
| 1281 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1282 | conf->pool_size = devs; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1283 | while (num--) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1284 | if (!grow_one_stripe(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | return 0; |
| 1287 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 1288 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1289 | /** |
| 1290 | * scribble_len - return the required size of the scribble region |
| 1291 | * @num - total number of disks in the array |
| 1292 | * |
| 1293 | * The size must be enough to contain: |
| 1294 | * 1/ a struct page pointer for each device in the array +2 |
| 1295 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 1296 | * (dma_map_page()) or page (page_address()) address. |
| 1297 | * |
| 1298 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 1299 | * calculate over all devices (not just the data blocks), using zeros in place |
| 1300 | * of the P and Q blocks. |
| 1301 | */ |
| 1302 | static size_t scribble_len(int num) |
| 1303 | { |
| 1304 | size_t len; |
| 1305 | |
| 1306 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
| 1307 | |
| 1308 | return len; |
| 1309 | } |
| 1310 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1311 | static int resize_stripes(raid5_conf_t *conf, int newsize) |
| 1312 | { |
| 1313 | /* Make all the stripes able to hold 'newsize' devices. |
| 1314 | * New slots in each stripe get 'page' set to a new page. |
| 1315 | * |
| 1316 | * This happens in stages: |
| 1317 | * 1/ create a new kmem_cache and allocate the required number of |
| 1318 | * stripe_heads. |
| 1319 | * 2/ gather all the old stripe_heads and tranfer the pages across |
| 1320 | * to the new stripe_heads. This will have the side effect of |
| 1321 | * freezing the array as once all stripe_heads have been collected, |
| 1322 | * no IO will be possible. Old stripe heads are freed once their |
| 1323 | * pages have been transferred over, and the old kmem_cache is |
| 1324 | * freed when all stripes are done. |
| 1325 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 1326 | * we simple return a failre status - no need to clean anything up. |
| 1327 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 1328 | * If this fails, we don't bother trying the shrink the |
| 1329 | * stripe_heads down again, we just leave them as they are. |
| 1330 | * As each stripe_head is processed the new one is released into |
| 1331 | * active service. |
| 1332 | * |
| 1333 | * Once step2 is started, we cannot afford to wait for a write, |
| 1334 | * so we use GFP_NOIO allocations. |
| 1335 | */ |
| 1336 | struct stripe_head *osh, *nsh; |
| 1337 | LIST_HEAD(newstripes); |
| 1338 | struct disk_info *ndisks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1339 | unsigned long cpu; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1340 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1341 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1342 | int i; |
| 1343 | |
| 1344 | if (newsize <= conf->pool_size) |
| 1345 | return 0; /* never bother to shrink */ |
| 1346 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1347 | err = md_allow_write(conf->mddev); |
| 1348 | if (err) |
| 1349 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 1350 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1351 | /* Step 1 */ |
| 1352 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 1353 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1354 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1355 | if (!sc) |
| 1356 | return -ENOMEM; |
| 1357 | |
| 1358 | for (i = conf->max_nr_stripes; i; i--) { |
| 1359 | nsh = kmem_cache_alloc(sc, GFP_KERNEL); |
| 1360 | if (!nsh) |
| 1361 | break; |
| 1362 | |
| 1363 | memset(nsh, 0, sizeof(*nsh) + (newsize-1)*sizeof(struct r5dev)); |
| 1364 | |
| 1365 | nsh->raid_conf = conf; |
| 1366 | spin_lock_init(&nsh->lock); |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1367 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1368 | init_waitqueue_head(&nsh->ops.wait_for_ops); |
| 1369 | #endif |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1370 | |
| 1371 | list_add(&nsh->lru, &newstripes); |
| 1372 | } |
| 1373 | if (i) { |
| 1374 | /* didn't get enough, give up */ |
| 1375 | while (!list_empty(&newstripes)) { |
| 1376 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1377 | list_del(&nsh->lru); |
| 1378 | kmem_cache_free(sc, nsh); |
| 1379 | } |
| 1380 | kmem_cache_destroy(sc); |
| 1381 | return -ENOMEM; |
| 1382 | } |
| 1383 | /* Step 2 - Must use GFP_NOIO now. |
| 1384 | * OK, we have enough stripes, start collecting inactive |
| 1385 | * stripes and copying them over |
| 1386 | */ |
| 1387 | list_for_each_entry(nsh, &newstripes, lru) { |
| 1388 | spin_lock_irq(&conf->device_lock); |
| 1389 | wait_event_lock_irq(conf->wait_for_stripe, |
| 1390 | !list_empty(&conf->inactive_list), |
| 1391 | conf->device_lock, |
NeilBrown | b3b46be | 2006-03-27 01:18:16 -0800 | [diff] [blame] | 1392 | unplug_slaves(conf->mddev) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1393 | ); |
| 1394 | osh = get_free_stripe(conf); |
| 1395 | spin_unlock_irq(&conf->device_lock); |
| 1396 | atomic_set(&nsh->count, 1); |
| 1397 | for(i=0; i<conf->pool_size; i++) |
| 1398 | nsh->dev[i].page = osh->dev[i].page; |
| 1399 | for( ; i<newsize; i++) |
| 1400 | nsh->dev[i].page = NULL; |
| 1401 | kmem_cache_free(conf->slab_cache, osh); |
| 1402 | } |
| 1403 | kmem_cache_destroy(conf->slab_cache); |
| 1404 | |
| 1405 | /* Step 3. |
| 1406 | * At this point, we are holding all the stripes so the array |
| 1407 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1408 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1409 | */ |
| 1410 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 1411 | if (ndisks) { |
| 1412 | for (i=0; i<conf->raid_disks; i++) |
| 1413 | ndisks[i] = conf->disks[i]; |
| 1414 | kfree(conf->disks); |
| 1415 | conf->disks = ndisks; |
| 1416 | } else |
| 1417 | err = -ENOMEM; |
| 1418 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1419 | get_online_cpus(); |
| 1420 | conf->scribble_len = scribble_len(newsize); |
| 1421 | for_each_present_cpu(cpu) { |
| 1422 | struct raid5_percpu *percpu; |
| 1423 | void *scribble; |
| 1424 | |
| 1425 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 1426 | scribble = kmalloc(conf->scribble_len, GFP_NOIO); |
| 1427 | |
| 1428 | if (scribble) { |
| 1429 | kfree(percpu->scribble); |
| 1430 | percpu->scribble = scribble; |
| 1431 | } else { |
| 1432 | err = -ENOMEM; |
| 1433 | break; |
| 1434 | } |
| 1435 | } |
| 1436 | put_online_cpus(); |
| 1437 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1438 | /* Step 4, return new stripes to service */ |
| 1439 | while(!list_empty(&newstripes)) { |
| 1440 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1441 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1442 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1443 | for (i=conf->raid_disks; i < newsize; i++) |
| 1444 | if (nsh->dev[i].page == NULL) { |
| 1445 | struct page *p = alloc_page(GFP_NOIO); |
| 1446 | nsh->dev[i].page = p; |
| 1447 | if (!p) |
| 1448 | err = -ENOMEM; |
| 1449 | } |
| 1450 | release_stripe(nsh); |
| 1451 | } |
| 1452 | /* critical section pass, GFP_NOIO no longer needed */ |
| 1453 | |
| 1454 | conf->slab_cache = sc; |
| 1455 | conf->active_name = 1-conf->active_name; |
| 1456 | conf->pool_size = newsize; |
| 1457 | return err; |
| 1458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1460 | static int drop_one_stripe(raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | { |
| 1462 | struct stripe_head *sh; |
| 1463 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1464 | spin_lock_irq(&conf->device_lock); |
| 1465 | sh = get_free_stripe(conf); |
| 1466 | spin_unlock_irq(&conf->device_lock); |
| 1467 | if (!sh) |
| 1468 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 1469 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1470 | shrink_buffers(sh, conf->pool_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1471 | kmem_cache_free(conf->slab_cache, sh); |
| 1472 | atomic_dec(&conf->active_stripes); |
| 1473 | return 1; |
| 1474 | } |
| 1475 | |
| 1476 | static void shrink_stripes(raid5_conf_t *conf) |
| 1477 | { |
| 1478 | while (drop_one_stripe(conf)) |
| 1479 | ; |
| 1480 | |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1481 | if (conf->slab_cache) |
| 1482 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | conf->slab_cache = NULL; |
| 1484 | } |
| 1485 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1486 | static void raid5_end_read_request(struct bio * bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1488 | struct stripe_head *sh = bi->bi_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1490 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1492 | char b[BDEVNAME_SIZE]; |
| 1493 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
| 1496 | for (i=0 ; i<disks; i++) |
| 1497 | if (bi == &sh->dev[i].req) |
| 1498 | break; |
| 1499 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1500 | pr_debug("end_read_request %llu/%d, count: %d, uptodate %d.\n", |
| 1501 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | uptodate); |
| 1503 | if (i == disks) { |
| 1504 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1505 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1510 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1511 | rdev = conf->disks[i].rdev; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1512 | printk_rl(KERN_INFO "md/raid:%s: read error corrected" |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1513 | " (%lu sectors at %llu on %s)\n", |
| 1514 | mdname(conf->mddev), STRIPE_SECTORS, |
| 1515 | (unsigned long long)(sh->sector |
| 1516 | + rdev->data_offset), |
| 1517 | bdevname(rdev->bdev, b)); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1518 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1519 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
| 1520 | } |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1521 | if (atomic_read(&conf->disks[i].rdev->read_errors)) |
| 1522 | atomic_set(&conf->disks[i].rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } else { |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1524 | const char *bdn = bdevname(conf->disks[i].rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1525 | int retry = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1526 | rdev = conf->disks[i].rdev; |
| 1527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1529 | atomic_inc(&rdev->read_errors); |
Gabriele A. Trombetti | 7b0bb53 | 2010-04-28 11:51:17 +1000 | [diff] [blame^] | 1530 | if (conf->mddev->degraded >= conf->max_degraded) |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1531 | printk_rl(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1532 | "md/raid:%s: read error not correctable " |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1533 | "(sector %llu on %s).\n", |
| 1534 | mdname(conf->mddev), |
| 1535 | (unsigned long long)(sh->sector |
| 1536 | + rdev->data_offset), |
| 1537 | bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1538 | else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1539 | /* Oh, no!!! */ |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1540 | printk_rl(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1541 | "md/raid:%s: read error NOT corrected!! " |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1542 | "(sector %llu on %s).\n", |
| 1543 | mdname(conf->mddev), |
| 1544 | (unsigned long long)(sh->sector |
| 1545 | + rdev->data_offset), |
| 1546 | bdn); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1547 | else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1548 | > conf->max_nr_stripes) |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1549 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1550 | "md/raid:%s: Too many read errors, failing device %s.\n", |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1551 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1552 | else |
| 1553 | retry = 1; |
| 1554 | if (retry) |
| 1555 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 1556 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1557 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1558 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1559 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | } |
| 1562 | rdev_dec_pending(conf->disks[i].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1564 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1565 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1568 | static void raid5_end_write_request(struct bio *bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1570 | struct stripe_head *sh = bi->bi_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1572 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
| 1574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | for (i=0 ; i<disks; i++) |
| 1576 | if (bi == &sh->dev[i].req) |
| 1577 | break; |
| 1578 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1579 | pr_debug("end_write_request %llu/%d, count %d, uptodate: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
| 1581 | uptodate); |
| 1582 | if (i == disks) { |
| 1583 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1584 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | if (!uptodate) |
| 1588 | md_error(conf->mddev, conf->disks[i].rdev); |
| 1589 | |
| 1590 | rdev_dec_pending(conf->disks[i].rdev, conf->mddev); |
| 1591 | |
| 1592 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1593 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1594 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1598 | 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] | 1599 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1600 | 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] | 1601 | { |
| 1602 | struct r5dev *dev = &sh->dev[i]; |
| 1603 | |
| 1604 | bio_init(&dev->req); |
| 1605 | dev->req.bi_io_vec = &dev->vec; |
| 1606 | dev->req.bi_vcnt++; |
| 1607 | dev->req.bi_max_vecs++; |
| 1608 | dev->vec.bv_page = dev->page; |
| 1609 | dev->vec.bv_len = STRIPE_SIZE; |
| 1610 | dev->vec.bv_offset = 0; |
| 1611 | |
| 1612 | dev->req.bi_sector = sh->sector; |
| 1613 | dev->req.bi_private = sh; |
| 1614 | |
| 1615 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1616 | dev->sector = compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1620 | { |
| 1621 | char b[BDEVNAME_SIZE]; |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 1622 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1623 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1625 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1626 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1627 | if (test_and_clear_bit(In_sync, &rdev->flags)) { |
| 1628 | unsigned long flags; |
| 1629 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | mddev->degraded++; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1631 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | /* |
| 1633 | * if recovery was running, make sure it aborts. |
| 1634 | */ |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1635 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1637 | set_bit(Faulty, &rdev->flags); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1638 | printk(KERN_ALERT |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1639 | "md/raid:%s: Disk failure on %s, disabling device.\n" |
| 1640 | KERN_ALERT |
| 1641 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 1642 | mdname(mddev), |
| 1643 | bdevname(rdev->bdev, b), |
| 1644 | mdname(mddev), |
| 1645 | conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1647 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
| 1649 | /* |
| 1650 | * Input: a 'big' sector number, |
| 1651 | * Output: index of the data and parity disk, and the sector # in them. |
| 1652 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1653 | static sector_t raid5_compute_sector(raid5_conf_t *conf, sector_t r_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1654 | int previous, int *dd_idx, |
| 1655 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
| 1657 | long stripe; |
| 1658 | unsigned long chunk_number; |
| 1659 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1660 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1661 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1663 | int algorithm = previous ? conf->prev_algo |
| 1664 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1665 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1666 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1667 | int raid_disks = previous ? conf->previous_raid_disks |
| 1668 | : conf->raid_disks; |
| 1669 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | |
| 1671 | /* First compute the information on this sector */ |
| 1672 | |
| 1673 | /* |
| 1674 | * Compute the chunk number and the sector offset inside the chunk |
| 1675 | */ |
| 1676 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 1677 | chunk_number = r_sector; |
| 1678 | BUG_ON(r_sector != chunk_number); |
| 1679 | |
| 1680 | /* |
| 1681 | * Compute the stripe number |
| 1682 | */ |
| 1683 | stripe = chunk_number / data_disks; |
| 1684 | |
| 1685 | /* |
| 1686 | * Compute the data disk and parity disk indexes inside the stripe |
| 1687 | */ |
| 1688 | *dd_idx = chunk_number % data_disks; |
| 1689 | |
| 1690 | /* |
| 1691 | * Select the parity disk based on the user selected algorithm. |
| 1692 | */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1693 | pd_idx = qd_idx = ~0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1694 | switch(conf->level) { |
| 1695 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1696 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1697 | break; |
| 1698 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1699 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1701 | pd_idx = data_disks - stripe % raid_disks; |
| 1702 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | (*dd_idx)++; |
| 1704 | break; |
| 1705 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1706 | pd_idx = stripe % raid_disks; |
| 1707 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | (*dd_idx)++; |
| 1709 | break; |
| 1710 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1711 | pd_idx = data_disks - stripe % raid_disks; |
| 1712 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | break; |
| 1714 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1715 | pd_idx = stripe % raid_disks; |
| 1716 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1718 | case ALGORITHM_PARITY_0: |
| 1719 | pd_idx = 0; |
| 1720 | (*dd_idx)++; |
| 1721 | break; |
| 1722 | case ALGORITHM_PARITY_N: |
| 1723 | pd_idx = data_disks; |
| 1724 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1726 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1727 | } |
| 1728 | break; |
| 1729 | case 6: |
| 1730 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1731 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1732 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1733 | pd_idx = raid_disks - 1 - (stripe % raid_disks); |
| 1734 | qd_idx = pd_idx + 1; |
| 1735 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1736 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1737 | qd_idx = 0; |
| 1738 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1739 | (*dd_idx) += 2; /* D D P Q D */ |
| 1740 | break; |
| 1741 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1742 | pd_idx = stripe % raid_disks; |
| 1743 | qd_idx = pd_idx + 1; |
| 1744 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1745 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1746 | qd_idx = 0; |
| 1747 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1748 | (*dd_idx) += 2; /* D D P Q D */ |
| 1749 | break; |
| 1750 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1751 | pd_idx = raid_disks - 1 - (stripe % raid_disks); |
| 1752 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1753 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1754 | break; |
| 1755 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1756 | pd_idx = stripe % raid_disks; |
| 1757 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1758 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1759 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1760 | |
| 1761 | case ALGORITHM_PARITY_0: |
| 1762 | pd_idx = 0; |
| 1763 | qd_idx = 1; |
| 1764 | (*dd_idx) += 2; |
| 1765 | break; |
| 1766 | case ALGORITHM_PARITY_N: |
| 1767 | pd_idx = data_disks; |
| 1768 | qd_idx = data_disks + 1; |
| 1769 | break; |
| 1770 | |
| 1771 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 1772 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 1773 | * of blocks for computing Q is different. |
| 1774 | */ |
| 1775 | pd_idx = stripe % raid_disks; |
| 1776 | qd_idx = pd_idx + 1; |
| 1777 | if (pd_idx == raid_disks-1) { |
| 1778 | (*dd_idx)++; /* Q D D D P */ |
| 1779 | qd_idx = 0; |
| 1780 | } else if (*dd_idx >= pd_idx) |
| 1781 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1782 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1783 | break; |
| 1784 | |
| 1785 | case ALGORITHM_ROTATING_N_RESTART: |
| 1786 | /* Same a left_asymmetric, by first stripe is |
| 1787 | * D D D P Q rather than |
| 1788 | * Q D D D P |
| 1789 | */ |
| 1790 | pd_idx = raid_disks - 1 - ((stripe + 1) % raid_disks); |
| 1791 | qd_idx = pd_idx + 1; |
| 1792 | if (pd_idx == raid_disks-1) { |
| 1793 | (*dd_idx)++; /* Q D D D P */ |
| 1794 | qd_idx = 0; |
| 1795 | } else if (*dd_idx >= pd_idx) |
| 1796 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1797 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1798 | break; |
| 1799 | |
| 1800 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 1801 | /* Same as left_symmetric but Q is before P */ |
| 1802 | pd_idx = raid_disks - 1 - (stripe % raid_disks); |
| 1803 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 1804 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1805 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 1809 | /* RAID5 left_asymmetric, with Q on last device */ |
| 1810 | pd_idx = data_disks - stripe % (raid_disks-1); |
| 1811 | if (*dd_idx >= pd_idx) |
| 1812 | (*dd_idx)++; |
| 1813 | qd_idx = raid_disks - 1; |
| 1814 | break; |
| 1815 | |
| 1816 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 1817 | pd_idx = stripe % (raid_disks-1); |
| 1818 | if (*dd_idx >= pd_idx) |
| 1819 | (*dd_idx)++; |
| 1820 | qd_idx = raid_disks - 1; |
| 1821 | break; |
| 1822 | |
| 1823 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 1824 | pd_idx = data_disks - stripe % (raid_disks-1); |
| 1825 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 1826 | qd_idx = raid_disks - 1; |
| 1827 | break; |
| 1828 | |
| 1829 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 1830 | pd_idx = stripe % (raid_disks-1); |
| 1831 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 1832 | qd_idx = raid_disks - 1; |
| 1833 | break; |
| 1834 | |
| 1835 | case ALGORITHM_PARITY_0_6: |
| 1836 | pd_idx = 0; |
| 1837 | (*dd_idx)++; |
| 1838 | qd_idx = raid_disks - 1; |
| 1839 | break; |
| 1840 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1841 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1842 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1843 | } |
| 1844 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1847 | if (sh) { |
| 1848 | sh->pd_idx = pd_idx; |
| 1849 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1850 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1851 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | /* |
| 1853 | * Finally, compute the new sector number |
| 1854 | */ |
| 1855 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 1856 | return new_sector; |
| 1857 | } |
| 1858 | |
| 1859 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1860 | 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] | 1861 | { |
| 1862 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 1863 | int raid_disks = sh->disks; |
| 1864 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1866 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1867 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1868 | int algorithm = previous ? conf->prev_algo |
| 1869 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | sector_t stripe; |
| 1871 | int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1872 | int chunk_number, dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1874 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 1878 | stripe = new_sector; |
| 1879 | BUG_ON(new_sector != stripe); |
| 1880 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1881 | if (i == sh->pd_idx) |
| 1882 | return 0; |
| 1883 | switch(conf->level) { |
| 1884 | case 4: break; |
| 1885 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1886 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 1888 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 1889 | if (i > sh->pd_idx) |
| 1890 | i--; |
| 1891 | break; |
| 1892 | case ALGORITHM_LEFT_SYMMETRIC: |
| 1893 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 1894 | if (i < sh->pd_idx) |
| 1895 | i += raid_disks; |
| 1896 | i -= (sh->pd_idx + 1); |
| 1897 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1898 | case ALGORITHM_PARITY_0: |
| 1899 | i -= 1; |
| 1900 | break; |
| 1901 | case ALGORITHM_PARITY_N: |
| 1902 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1904 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1905 | } |
| 1906 | break; |
| 1907 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1908 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1909 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1910 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1911 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 1912 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1913 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 1914 | case ALGORITHM_ROTATING_N_RESTART: |
| 1915 | if (sh->pd_idx == raid_disks-1) |
| 1916 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1917 | else if (i > sh->pd_idx) |
| 1918 | i -= 2; /* D D P Q D */ |
| 1919 | break; |
| 1920 | case ALGORITHM_LEFT_SYMMETRIC: |
| 1921 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 1922 | if (sh->pd_idx == raid_disks-1) |
| 1923 | i--; /* Q D D D P */ |
| 1924 | else { |
| 1925 | /* D D P Q D */ |
| 1926 | if (i < sh->pd_idx) |
| 1927 | i += raid_disks; |
| 1928 | i -= (sh->pd_idx + 2); |
| 1929 | } |
| 1930 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1931 | case ALGORITHM_PARITY_0: |
| 1932 | i -= 2; |
| 1933 | break; |
| 1934 | case ALGORITHM_PARITY_N: |
| 1935 | break; |
| 1936 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1937 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1938 | if (sh->pd_idx == 0) |
| 1939 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1940 | else { |
| 1941 | /* D D Q P D */ |
| 1942 | if (i < sh->pd_idx) |
| 1943 | i += raid_disks; |
| 1944 | i -= (sh->pd_idx + 1); |
| 1945 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1946 | break; |
| 1947 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 1948 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 1949 | if (i > sh->pd_idx) |
| 1950 | i--; |
| 1951 | break; |
| 1952 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 1953 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 1954 | if (i < sh->pd_idx) |
| 1955 | i += data_disks + 1; |
| 1956 | i -= (sh->pd_idx + 1); |
| 1957 | break; |
| 1958 | case ALGORITHM_PARITY_0_6: |
| 1959 | i -= 1; |
| 1960 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1961 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1962 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1963 | } |
| 1964 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | chunk_number = stripe * data_disks + i; |
| 1968 | r_sector = (sector_t)chunk_number * sectors_per_chunk + chunk_offset; |
| 1969 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1970 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1971 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1972 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 1973 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 1974 | printk(KERN_ERR "md/raid:%s: compute_blocknr: map not correct\n", |
| 1975 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | return 0; |
| 1977 | } |
| 1978 | return r_sector; |
| 1979 | } |
| 1980 | |
| 1981 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1982 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 1983 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1984 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1985 | { |
| 1986 | int i, pd_idx = sh->pd_idx, disks = sh->disks; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 1987 | raid5_conf_t *conf = sh->raid_conf; |
| 1988 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1989 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1990 | if (rcw) { |
| 1991 | /* if we are not expanding this is a proper write request, and |
| 1992 | * there will be bios with new data to be drained into the |
| 1993 | * stripe cache |
| 1994 | */ |
| 1995 | if (!expand) { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1996 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 1997 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 1998 | } else |
| 1999 | sh->reconstruct_state = reconstruct_state_run; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2000 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2001 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2002 | |
| 2003 | for (i = disks; i--; ) { |
| 2004 | struct r5dev *dev = &sh->dev[i]; |
| 2005 | |
| 2006 | if (dev->towrite) { |
| 2007 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2008 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2009 | if (!expand) |
| 2010 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2011 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2014 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2015 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2016 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2017 | } else { |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2018 | BUG_ON(level == 6); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2019 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 2020 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
| 2021 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2022 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2023 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 2024 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2025 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2026 | |
| 2027 | for (i = disks; i--; ) { |
| 2028 | struct r5dev *dev = &sh->dev[i]; |
| 2029 | if (i == pd_idx) |
| 2030 | continue; |
| 2031 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2032 | if (dev->towrite && |
| 2033 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2034 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2035 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2036 | set_bit(R5_LOCKED, &dev->flags); |
| 2037 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2038 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | } |
| 2042 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2043 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2044 | * are in flight |
| 2045 | */ |
| 2046 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 2047 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2048 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2049 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2050 | if (level == 6) { |
| 2051 | int qd_idx = sh->qd_idx; |
| 2052 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 2053 | |
| 2054 | set_bit(R5_LOCKED, &dev->flags); |
| 2055 | clear_bit(R5_UPTODATE, &dev->flags); |
| 2056 | s->locked++; |
| 2057 | } |
| 2058 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2059 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2060 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2061 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2062 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | /* |
| 2065 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2066 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | * The bi_next chain must be in order. |
| 2068 | */ |
| 2069 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) |
| 2070 | { |
| 2071 | struct bio **bip; |
| 2072 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2073 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2075 | pr_debug("adding bh b#%llu to stripe s#%llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | (unsigned long long)bi->bi_sector, |
| 2077 | (unsigned long long)sh->sector); |
| 2078 | |
| 2079 | |
| 2080 | spin_lock(&sh->lock); |
| 2081 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2082 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | bip = &sh->dev[dd_idx].towrite; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2084 | if (*bip == NULL && sh->dev[dd_idx].written == NULL) |
| 2085 | firstwrite = 1; |
| 2086 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | bip = &sh->dev[dd_idx].toread; |
| 2088 | while (*bip && (*bip)->bi_sector < bi->bi_sector) { |
| 2089 | if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) |
| 2090 | goto overlap; |
| 2091 | bip = & (*bip)->bi_next; |
| 2092 | } |
| 2093 | if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) |
| 2094 | goto overlap; |
| 2095 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2096 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | if (*bip) |
| 2098 | bi->bi_next = *bip; |
| 2099 | *bip = bi; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2100 | bi->bi_phys_segments++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | spin_unlock_irq(&conf->device_lock); |
| 2102 | spin_unlock(&sh->lock); |
| 2103 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2104 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | (unsigned long long)bi->bi_sector, |
| 2106 | (unsigned long long)sh->sector, dd_idx); |
| 2107 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2108 | if (conf->mddev->bitmap && firstwrite) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2109 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 2110 | STRIPE_SECTORS, 0); |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 2111 | sh->bm_seq = conf->seq_flush+1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2112 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 2113 | } |
| 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | if (forwrite) { |
| 2116 | /* check if page is covered */ |
| 2117 | sector_t sector = sh->dev[dd_idx].sector; |
| 2118 | for (bi=sh->dev[dd_idx].towrite; |
| 2119 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
| 2120 | bi && bi->bi_sector <= sector; |
| 2121 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
| 2122 | if (bi->bi_sector + (bi->bi_size>>9) >= sector) |
| 2123 | sector = bi->bi_sector + (bi->bi_size>>9); |
| 2124 | } |
| 2125 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
| 2126 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
| 2127 | } |
| 2128 | return 1; |
| 2129 | |
| 2130 | overlap: |
| 2131 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
| 2132 | spin_unlock_irq(&conf->device_lock); |
| 2133 | spin_unlock(&sh->lock); |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2137 | static void end_reshape(raid5_conf_t *conf); |
| 2138 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2139 | static void stripe_set_idx(sector_t stripe, raid5_conf_t *conf, int previous, |
| 2140 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2141 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2142 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2143 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2144 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2145 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2146 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2147 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2148 | raid5_compute_sector(conf, |
| 2149 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2150 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2151 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2152 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2153 | } |
| 2154 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2155 | static void |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2156 | handle_failed_stripe(raid5_conf_t *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2157 | struct stripe_head_state *s, int disks, |
| 2158 | struct bio **return_bi) |
| 2159 | { |
| 2160 | int i; |
| 2161 | for (i = disks; i--; ) { |
| 2162 | struct bio *bi; |
| 2163 | int bitmap_end = 0; |
| 2164 | |
| 2165 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
| 2166 | mdk_rdev_t *rdev; |
| 2167 | rcu_read_lock(); |
| 2168 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 2169 | if (rdev && test_bit(In_sync, &rdev->flags)) |
| 2170 | /* multiple read failures in one stripe */ |
| 2171 | md_error(conf->mddev, rdev); |
| 2172 | rcu_read_unlock(); |
| 2173 | } |
| 2174 | spin_lock_irq(&conf->device_lock); |
| 2175 | /* fail all writes first */ |
| 2176 | bi = sh->dev[i].towrite; |
| 2177 | sh->dev[i].towrite = NULL; |
| 2178 | if (bi) { |
| 2179 | s->to_write--; |
| 2180 | bitmap_end = 1; |
| 2181 | } |
| 2182 | |
| 2183 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2184 | wake_up(&conf->wait_for_overlap); |
| 2185 | |
| 2186 | while (bi && bi->bi_sector < |
| 2187 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2188 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
| 2189 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2190 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2191 | md_write_end(conf->mddev); |
| 2192 | bi->bi_next = *return_bi; |
| 2193 | *return_bi = bi; |
| 2194 | } |
| 2195 | bi = nextbi; |
| 2196 | } |
| 2197 | /* and fail all 'written' */ |
| 2198 | bi = sh->dev[i].written; |
| 2199 | sh->dev[i].written = NULL; |
| 2200 | if (bi) bitmap_end = 1; |
| 2201 | while (bi && bi->bi_sector < |
| 2202 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2203 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
| 2204 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2205 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2206 | md_write_end(conf->mddev); |
| 2207 | bi->bi_next = *return_bi; |
| 2208 | *return_bi = bi; |
| 2209 | } |
| 2210 | bi = bi2; |
| 2211 | } |
| 2212 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2213 | /* fail any reads if this device is non-operational and |
| 2214 | * the data has not reached the cache yet. |
| 2215 | */ |
| 2216 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
| 2217 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 2218 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2219 | bi = sh->dev[i].toread; |
| 2220 | sh->dev[i].toread = NULL; |
| 2221 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2222 | wake_up(&conf->wait_for_overlap); |
| 2223 | if (bi) s->to_read--; |
| 2224 | while (bi && bi->bi_sector < |
| 2225 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2226 | struct bio *nextbi = |
| 2227 | r5_next_bio(bi, sh->dev[i].sector); |
| 2228 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2229 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2230 | bi->bi_next = *return_bi; |
| 2231 | *return_bi = bi; |
| 2232 | } |
| 2233 | bi = nextbi; |
| 2234 | } |
| 2235 | } |
| 2236 | spin_unlock_irq(&conf->device_lock); |
| 2237 | if (bitmap_end) |
| 2238 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2239 | STRIPE_SECTORS, 0, 0); |
| 2240 | } |
| 2241 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2242 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2243 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2244 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2247 | /* fetch_block5 - checks the given member device to see if its data needs |
| 2248 | * to be read or computed to satisfy a request. |
| 2249 | * |
| 2250 | * Returns 1 when no more member devices need to be checked, otherwise returns |
| 2251 | * 0 to tell the loop in handle_stripe_fill5 to continue |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2252 | */ |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2253 | static int fetch_block5(struct stripe_head *sh, struct stripe_head_state *s, |
| 2254 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2255 | { |
| 2256 | struct r5dev *dev = &sh->dev[disk_idx]; |
| 2257 | struct r5dev *failed_dev = &sh->dev[s->failed_num]; |
| 2258 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2259 | /* is the data in this block needed, and can we get it? */ |
| 2260 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2261 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2262 | (dev->toread || |
| 2263 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2264 | s->syncing || s->expanding || |
| 2265 | (s->failed && |
| 2266 | (failed_dev->toread || |
| 2267 | (failed_dev->towrite && |
| 2268 | !test_bit(R5_OVERWRITE, &failed_dev->flags)))))) { |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2269 | /* We would like to get this block, possibly by computing it, |
| 2270 | * otherwise read it if the backing disk is insync |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2271 | */ |
| 2272 | if ((s->uptodate == disks - 1) && |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2273 | (s->failed && disk_idx == s->failed_num)) { |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2274 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2275 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2276 | set_bit(R5_Wantcompute, &dev->flags); |
| 2277 | sh->ops.target = disk_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2278 | sh->ops.target2 = -1; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2279 | s->req_compute = 1; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2280 | /* Careful: from this point on 'uptodate' is in the eye |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2281 | * of raid_run_ops which services 'compute' operations |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2282 | * before writes. R5_Wantcompute flags a block that will |
| 2283 | * be R5_UPTODATE by the time it is needed for a |
| 2284 | * subsequent operation. |
| 2285 | */ |
| 2286 | s->uptodate++; |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2287 | return 1; /* uptodate + compute == disks */ |
Dan Williams | 7a1fc53 | 2008-07-10 04:54:57 -0700 | [diff] [blame] | 2288 | } else if (test_bit(R5_Insync, &dev->flags)) { |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2289 | set_bit(R5_LOCKED, &dev->flags); |
| 2290 | set_bit(R5_Wantread, &dev->flags); |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2291 | s->locked++; |
| 2292 | pr_debug("Reading block %d (sync=%d)\n", disk_idx, |
| 2293 | s->syncing); |
| 2294 | } |
| 2295 | } |
| 2296 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2297 | return 0; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2300 | /** |
| 2301 | * handle_stripe_fill5 - read or compute data to satisfy pending requests. |
| 2302 | */ |
| 2303 | static void handle_stripe_fill5(struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2304 | struct stripe_head_state *s, int disks) |
| 2305 | { |
| 2306 | int i; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2307 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2308 | /* look for blocks to read/compute, skip this if a compute |
| 2309 | * is already in flight, or if the stripe contents are in the |
| 2310 | * midst of changing due to a write |
| 2311 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2312 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2313 | !sh->reconstruct_state) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2314 | for (i = disks; i--; ) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2315 | if (fetch_block5(sh, s, i, disks)) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2316 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2317 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2318 | } |
| 2319 | |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2320 | /* fetch_block6 - checks the given member device to see if its data needs |
| 2321 | * to be read or computed to satisfy a request. |
| 2322 | * |
| 2323 | * Returns 1 when no more member devices need to be checked, otherwise returns |
| 2324 | * 0 to tell the loop in handle_stripe_fill6 to continue |
| 2325 | */ |
| 2326 | static int fetch_block6(struct stripe_head *sh, struct stripe_head_state *s, |
| 2327 | struct r6_state *r6s, int disk_idx, int disks) |
| 2328 | { |
| 2329 | struct r5dev *dev = &sh->dev[disk_idx]; |
| 2330 | struct r5dev *fdev[2] = { &sh->dev[r6s->failed_num[0]], |
| 2331 | &sh->dev[r6s->failed_num[1]] }; |
| 2332 | |
| 2333 | if (!test_bit(R5_LOCKED, &dev->flags) && |
| 2334 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2335 | (dev->toread || |
| 2336 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2337 | s->syncing || s->expanding || |
| 2338 | (s->failed >= 1 && |
| 2339 | (fdev[0]->toread || s->to_write)) || |
| 2340 | (s->failed >= 2 && |
| 2341 | (fdev[1]->toread || s->to_write)))) { |
| 2342 | /* we would like to get this block, possibly by computing it, |
| 2343 | * otherwise read it if the backing disk is insync |
| 2344 | */ |
| 2345 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 2346 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
| 2347 | if ((s->uptodate == disks - 1) && |
| 2348 | (s->failed && (disk_idx == r6s->failed_num[0] || |
| 2349 | disk_idx == r6s->failed_num[1]))) { |
| 2350 | /* have disk failed, and we're requested to fetch it; |
| 2351 | * do compute it |
| 2352 | */ |
| 2353 | pr_debug("Computing stripe %llu block %d\n", |
| 2354 | (unsigned long long)sh->sector, disk_idx); |
| 2355 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2356 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2357 | set_bit(R5_Wantcompute, &dev->flags); |
| 2358 | sh->ops.target = disk_idx; |
| 2359 | sh->ops.target2 = -1; /* no 2nd target */ |
| 2360 | s->req_compute = 1; |
| 2361 | s->uptodate++; |
| 2362 | return 1; |
| 2363 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 2364 | /* Computing 2-failure is *very* expensive; only |
| 2365 | * do it if failed >= 2 |
| 2366 | */ |
| 2367 | int other; |
| 2368 | for (other = disks; other--; ) { |
| 2369 | if (other == disk_idx) |
| 2370 | continue; |
| 2371 | if (!test_bit(R5_UPTODATE, |
| 2372 | &sh->dev[other].flags)) |
| 2373 | break; |
| 2374 | } |
| 2375 | BUG_ON(other < 0); |
| 2376 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 2377 | (unsigned long long)sh->sector, |
| 2378 | disk_idx, other); |
| 2379 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2380 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2381 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 2382 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 2383 | sh->ops.target = disk_idx; |
| 2384 | sh->ops.target2 = other; |
| 2385 | s->uptodate += 2; |
| 2386 | s->req_compute = 1; |
| 2387 | return 1; |
| 2388 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 2389 | set_bit(R5_LOCKED, &dev->flags); |
| 2390 | set_bit(R5_Wantread, &dev->flags); |
| 2391 | s->locked++; |
| 2392 | pr_debug("Reading block %d (sync=%d)\n", |
| 2393 | disk_idx, s->syncing); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | return 0; |
| 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * handle_stripe_fill6 - read or compute data to satisfy pending requests. |
| 2402 | */ |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2403 | static void handle_stripe_fill6(struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2404 | struct stripe_head_state *s, struct r6_state *r6s, |
| 2405 | int disks) |
| 2406 | { |
| 2407 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2408 | |
| 2409 | /* look for blocks to read/compute, skip this if a compute |
| 2410 | * is already in flight, or if the stripe contents are in the |
| 2411 | * midst of changing due to a write |
| 2412 | */ |
| 2413 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
| 2414 | !sh->reconstruct_state) |
| 2415 | for (i = disks; i--; ) |
| 2416 | if (fetch_block6(sh, s, r6s, i, disks)) |
| 2417 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2418 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2419 | } |
| 2420 | |
| 2421 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2422 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2423 | * any written block on an uptodate or failed drive can be returned. |
| 2424 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 2425 | * never LOCKED, so we don't need to test 'failed' directly. |
| 2426 | */ |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2427 | static void handle_stripe_clean_event(raid5_conf_t *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2428 | struct stripe_head *sh, int disks, struct bio **return_bi) |
| 2429 | { |
| 2430 | int i; |
| 2431 | struct r5dev *dev; |
| 2432 | |
| 2433 | for (i = disks; i--; ) |
| 2434 | if (sh->dev[i].written) { |
| 2435 | dev = &sh->dev[i]; |
| 2436 | if (!test_bit(R5_LOCKED, &dev->flags) && |
| 2437 | test_bit(R5_UPTODATE, &dev->flags)) { |
| 2438 | /* We can return any write requests */ |
| 2439 | struct bio *wbi, *wbi2; |
| 2440 | int bitmap_end = 0; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2441 | pr_debug("Return write for disc %d\n", i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2442 | spin_lock_irq(&conf->device_lock); |
| 2443 | wbi = dev->written; |
| 2444 | dev->written = NULL; |
| 2445 | while (wbi && wbi->bi_sector < |
| 2446 | dev->sector + STRIPE_SECTORS) { |
| 2447 | wbi2 = r5_next_bio(wbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2448 | if (!raid5_dec_bi_phys_segments(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2449 | md_write_end(conf->mddev); |
| 2450 | wbi->bi_next = *return_bi; |
| 2451 | *return_bi = wbi; |
| 2452 | } |
| 2453 | wbi = wbi2; |
| 2454 | } |
| 2455 | if (dev->towrite == NULL) |
| 2456 | bitmap_end = 1; |
| 2457 | spin_unlock_irq(&conf->device_lock); |
| 2458 | if (bitmap_end) |
| 2459 | bitmap_endwrite(conf->mddev->bitmap, |
| 2460 | sh->sector, |
| 2461 | STRIPE_SECTORS, |
| 2462 | !test_bit(STRIPE_DEGRADED, &sh->state), |
| 2463 | 0); |
| 2464 | } |
| 2465 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2466 | |
| 2467 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2468 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2469 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2472 | static void handle_stripe_dirtying5(raid5_conf_t *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2473 | struct stripe_head *sh, struct stripe_head_state *s, int disks) |
| 2474 | { |
| 2475 | int rmw = 0, rcw = 0, i; |
| 2476 | for (i = disks; i--; ) { |
| 2477 | /* would I have to read this buffer for read_modify_write */ |
| 2478 | struct r5dev *dev = &sh->dev[i]; |
| 2479 | if ((dev->towrite || i == sh->pd_idx) && |
| 2480 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2481 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2482 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2483 | if (test_bit(R5_Insync, &dev->flags)) |
| 2484 | rmw++; |
| 2485 | else |
| 2486 | rmw += 2*disks; /* cannot read it */ |
| 2487 | } |
| 2488 | /* Would I have to read this buffer for reconstruct_write */ |
| 2489 | if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && |
| 2490 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2491 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2492 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2493 | if (test_bit(R5_Insync, &dev->flags)) rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2494 | else |
| 2495 | rcw += 2*disks; |
| 2496 | } |
| 2497 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2498 | pr_debug("for sector %llu, rmw=%d rcw=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2499 | (unsigned long long)sh->sector, rmw, rcw); |
| 2500 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2501 | if (rmw < rcw && rmw > 0) |
| 2502 | /* prefer read-modify-write, but need to get some data */ |
| 2503 | for (i = disks; i--; ) { |
| 2504 | struct r5dev *dev = &sh->dev[i]; |
| 2505 | if ((dev->towrite || i == sh->pd_idx) && |
| 2506 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2507 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2508 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2509 | test_bit(R5_Insync, &dev->flags)) { |
| 2510 | if ( |
| 2511 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2512 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2513 | "%d for r-m-w\n", i); |
| 2514 | set_bit(R5_LOCKED, &dev->flags); |
| 2515 | set_bit(R5_Wantread, &dev->flags); |
| 2516 | s->locked++; |
| 2517 | } else { |
| 2518 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2519 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | if (rcw <= rmw && rcw > 0) |
| 2524 | /* want reconstruct write, but need to get some data */ |
| 2525 | for (i = disks; i--; ) { |
| 2526 | struct r5dev *dev = &sh->dev[i]; |
| 2527 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 2528 | i != sh->pd_idx && |
| 2529 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2530 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2531 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2532 | test_bit(R5_Insync, &dev->flags)) { |
| 2533 | if ( |
| 2534 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2535 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2536 | "%d for Reconstruct\n", i); |
| 2537 | set_bit(R5_LOCKED, &dev->flags); |
| 2538 | set_bit(R5_Wantread, &dev->flags); |
| 2539 | s->locked++; |
| 2540 | } else { |
| 2541 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2542 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | /* now if nothing is locked, and if we have enough data, |
| 2547 | * we can start a write request |
| 2548 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2549 | /* since handle_stripe can be called at any time we need to handle the |
| 2550 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2551 | * subsequent call wants to start a write request. raid_run_ops only |
| 2552 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2553 | * simultaneously. If this is not the case then new writes need to be |
| 2554 | * held off until the compute completes. |
| 2555 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2556 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2557 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
| 2558 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2559 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2562 | static void handle_stripe_dirtying6(raid5_conf_t *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2563 | struct stripe_head *sh, struct stripe_head_state *s, |
| 2564 | struct r6_state *r6s, int disks) |
| 2565 | { |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2566 | int rcw = 0, pd_idx = sh->pd_idx, i; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2567 | int qd_idx = sh->qd_idx; |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2568 | |
| 2569 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2570 | for (i = disks; i--; ) { |
| 2571 | struct r5dev *dev = &sh->dev[i]; |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2572 | /* check if we haven't enough data */ |
| 2573 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 2574 | i != pd_idx && i != qd_idx && |
| 2575 | !test_bit(R5_LOCKED, &dev->flags) && |
| 2576 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2577 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2578 | rcw++; |
| 2579 | if (!test_bit(R5_Insync, &dev->flags)) |
| 2580 | continue; /* it's a failed drive */ |
| 2581 | |
| 2582 | if ( |
| 2583 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
| 2584 | pr_debug("Read_old stripe %llu " |
| 2585 | "block %d for Reconstruct\n", |
| 2586 | (unsigned long long)sh->sector, i); |
| 2587 | set_bit(R5_LOCKED, &dev->flags); |
| 2588 | set_bit(R5_Wantread, &dev->flags); |
| 2589 | s->locked++; |
| 2590 | } else { |
| 2591 | pr_debug("Request delayed stripe %llu " |
| 2592 | "block %d for Reconstruct\n", |
| 2593 | (unsigned long long)sh->sector, i); |
| 2594 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2595 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2599 | /* now if nothing is locked, and if we have enough data, we can start a |
| 2600 | * write request |
| 2601 | */ |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2602 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2603 | s->locked == 0 && rcw == 0 && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2604 | !test_bit(STRIPE_BIT_DELAY, &sh->state)) { |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2605 | schedule_reconstruction(sh, s, 1, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh, |
| 2610 | struct stripe_head_state *s, int disks) |
| 2611 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2612 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2613 | |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2614 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2615 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2616 | switch (sh->check_state) { |
| 2617 | case check_state_idle: |
| 2618 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2619 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2620 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2621 | sh->check_state = check_state_run; |
| 2622 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2623 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2624 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2625 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2626 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2627 | dev = &sh->dev[s->failed_num]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2628 | /* fall through */ |
| 2629 | case check_state_compute_result: |
| 2630 | sh->check_state = check_state_idle; |
| 2631 | if (!dev) |
| 2632 | dev = &sh->dev[sh->pd_idx]; |
| 2633 | |
| 2634 | /* check that a write has not made the stripe insync */ |
| 2635 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2636 | break; |
| 2637 | |
| 2638 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2639 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 2640 | BUG_ON(s->uptodate != disks); |
| 2641 | |
| 2642 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2643 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2644 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2645 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2646 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2647 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2648 | break; |
| 2649 | case check_state_run: |
| 2650 | break; /* we will be called again upon completion */ |
| 2651 | case check_state_check_result: |
| 2652 | sh->check_state = check_state_idle; |
| 2653 | |
| 2654 | /* if a failure occurred during the check operation, leave |
| 2655 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 2656 | */ |
| 2657 | if (s->failed) |
| 2658 | break; |
| 2659 | |
| 2660 | /* handle a successful check operation, if parity is correct |
| 2661 | * we are done. Otherwise update the mismatch count and repair |
| 2662 | * parity if !MD_RECOVERY_CHECK |
| 2663 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 2664 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2665 | /* parity is correct (on disc, |
| 2666 | * not in buffer any more) |
| 2667 | */ |
| 2668 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2669 | else { |
| 2670 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2671 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2672 | /* don't try to repair!! */ |
| 2673 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2674 | else { |
| 2675 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2676 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2677 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2678 | set_bit(R5_Wantcompute, |
| 2679 | &sh->dev[sh->pd_idx].flags); |
| 2680 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2681 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2682 | s->uptodate++; |
| 2683 | } |
| 2684 | } |
| 2685 | break; |
| 2686 | case check_state_compute_run: |
| 2687 | break; |
| 2688 | default: |
| 2689 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2690 | __func__, sh->check_state, |
| 2691 | (unsigned long long) sh->sector); |
| 2692 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | |
| 2697 | static void handle_parity_checks6(raid5_conf_t *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2698 | struct stripe_head_state *s, |
| 2699 | struct r6_state *r6s, int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2700 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2701 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2702 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2703 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2704 | |
| 2705 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2706 | |
| 2707 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2708 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2709 | /* Want to check and possibly repair P and Q. |
| 2710 | * However there could be one 'failed' device, in which |
| 2711 | * case we can only check one of them, possibly using the |
| 2712 | * other to generate missing data |
| 2713 | */ |
| 2714 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2715 | switch (sh->check_state) { |
| 2716 | case check_state_idle: |
| 2717 | /* start a new check operation if there are < 2 failures */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2718 | if (s->failed == r6s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2719 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2720 | * makes sense to check P (If anything else were failed, |
| 2721 | * we would have used P to recreate it). |
| 2722 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2723 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2724 | } |
| 2725 | if (!r6s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2726 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2727 | * anything, so it makes sense to check it |
| 2728 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2729 | if (sh->check_state == check_state_run) |
| 2730 | sh->check_state = check_state_run_pq; |
| 2731 | else |
| 2732 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2733 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2734 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2735 | /* discard potentially stale zero_sum_result */ |
| 2736 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2737 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2738 | if (sh->check_state == check_state_run) { |
| 2739 | /* async_xor_zero_sum destroys the contents of P */ |
| 2740 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 2741 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2742 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2743 | if (sh->check_state >= check_state_run && |
| 2744 | sh->check_state <= check_state_run_pq) { |
| 2745 | /* async_syndrome_zero_sum preserves P and Q, so |
| 2746 | * no need to mark them !uptodate here |
| 2747 | */ |
| 2748 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 2749 | break; |
| 2750 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2751 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2752 | /* we have 2-disk failure */ |
| 2753 | BUG_ON(s->failed != 2); |
| 2754 | /* fall through */ |
| 2755 | case check_state_compute_result: |
| 2756 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2757 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2758 | /* check that a write has not made the stripe insync */ |
| 2759 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2760 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2761 | |
| 2762 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2763 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2764 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2765 | 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] | 2766 | if (s->failed == 2) { |
| 2767 | dev = &sh->dev[r6s->failed_num[1]]; |
| 2768 | s->locked++; |
| 2769 | set_bit(R5_LOCKED, &dev->flags); |
| 2770 | set_bit(R5_Wantwrite, &dev->flags); |
| 2771 | } |
| 2772 | if (s->failed >= 1) { |
| 2773 | dev = &sh->dev[r6s->failed_num[0]]; |
| 2774 | s->locked++; |
| 2775 | set_bit(R5_LOCKED, &dev->flags); |
| 2776 | set_bit(R5_Wantwrite, &dev->flags); |
| 2777 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2778 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2779 | dev = &sh->dev[pd_idx]; |
| 2780 | s->locked++; |
| 2781 | set_bit(R5_LOCKED, &dev->flags); |
| 2782 | set_bit(R5_Wantwrite, &dev->flags); |
| 2783 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2784 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2785 | dev = &sh->dev[qd_idx]; |
| 2786 | s->locked++; |
| 2787 | set_bit(R5_LOCKED, &dev->flags); |
| 2788 | set_bit(R5_Wantwrite, &dev->flags); |
| 2789 | } |
| 2790 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 2791 | |
| 2792 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2793 | break; |
| 2794 | case check_state_run: |
| 2795 | case check_state_run_q: |
| 2796 | case check_state_run_pq: |
| 2797 | break; /* we will be called again upon completion */ |
| 2798 | case check_state_check_result: |
| 2799 | sh->check_state = check_state_idle; |
| 2800 | |
| 2801 | /* handle a successful check operation, if parity is correct |
| 2802 | * we are done. Otherwise update the mismatch count and repair |
| 2803 | * parity if !MD_RECOVERY_CHECK |
| 2804 | */ |
| 2805 | if (sh->ops.zero_sum_result == 0) { |
| 2806 | /* both parities are correct */ |
| 2807 | if (!s->failed) |
| 2808 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2809 | else { |
| 2810 | /* in contrast to the raid5 case we can validate |
| 2811 | * parity, but still have a failure to write |
| 2812 | * back |
| 2813 | */ |
| 2814 | sh->check_state = check_state_compute_result; |
| 2815 | /* Returning at this point means that we may go |
| 2816 | * off and bring p and/or q uptodate again so |
| 2817 | * we make sure to check zero_sum_result again |
| 2818 | * to verify if p or q need writeback |
| 2819 | */ |
| 2820 | } |
| 2821 | } else { |
| 2822 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2823 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2824 | /* don't try to repair!! */ |
| 2825 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2826 | else { |
| 2827 | int *target = &sh->ops.target; |
| 2828 | |
| 2829 | sh->ops.target = -1; |
| 2830 | sh->ops.target2 = -1; |
| 2831 | sh->check_state = check_state_compute_run; |
| 2832 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2833 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2834 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 2835 | set_bit(R5_Wantcompute, |
| 2836 | &sh->dev[pd_idx].flags); |
| 2837 | *target = pd_idx; |
| 2838 | target = &sh->ops.target2; |
| 2839 | s->uptodate++; |
| 2840 | } |
| 2841 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 2842 | set_bit(R5_Wantcompute, |
| 2843 | &sh->dev[qd_idx].flags); |
| 2844 | *target = qd_idx; |
| 2845 | s->uptodate++; |
| 2846 | } |
| 2847 | } |
| 2848 | } |
| 2849 | break; |
| 2850 | case check_state_compute_run: |
| 2851 | break; |
| 2852 | default: |
| 2853 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2854 | __func__, sh->check_state, |
| 2855 | (unsigned long long) sh->sector); |
| 2856 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | static void handle_stripe_expansion(raid5_conf_t *conf, struct stripe_head *sh, |
| 2861 | struct r6_state *r6s) |
| 2862 | { |
| 2863 | int i; |
| 2864 | |
| 2865 | /* We have read all the blocks in this stripe and now we need to |
| 2866 | * copy some of them into a target stripe for expand. |
| 2867 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2868 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2869 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 2870 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2871 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2872 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2873 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2874 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2875 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2876 | sector_t bn = compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2877 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 2878 | &dd_idx, NULL); |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 2879 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2880 | if (sh2 == NULL) |
| 2881 | /* so far only the early blocks of this stripe |
| 2882 | * have been requested. When later blocks |
| 2883 | * get requested, we will try again |
| 2884 | */ |
| 2885 | continue; |
| 2886 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 2887 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 2888 | /* must have already done this block */ |
| 2889 | release_stripe(sh2); |
| 2890 | continue; |
| 2891 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2892 | |
| 2893 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2894 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2895 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 2896 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2897 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2898 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2899 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 2900 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 2901 | for (j = 0; j < conf->raid_disks; j++) |
| 2902 | if (j != sh2->pd_idx && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2903 | (!r6s || j != sh2->qd_idx) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2904 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 2905 | break; |
| 2906 | if (j == conf->raid_disks) { |
| 2907 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 2908 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 2909 | } |
| 2910 | release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2911 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2912 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 2913 | /* done submitting copies, wait for them to complete */ |
| 2914 | if (tx) { |
| 2915 | async_tx_ack(tx); |
| 2916 | dma_wait_for_async_tx(tx); |
| 2917 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | /* |
| 2922 | * handle_stripe - do things to a stripe. |
| 2923 | * |
| 2924 | * We lock the stripe and then examine the state of various bits |
| 2925 | * to see what needs to be done. |
| 2926 | * Possible results: |
| 2927 | * return some read request which now have data |
| 2928 | * return some write requests which are safely on disc |
| 2929 | * schedule a read on some buffers |
| 2930 | * schedule a write of some buffers |
| 2931 | * return confirmation of parity correctness |
| 2932 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | * buffers are taken off read_list or write_list, and bh_cache buffers |
| 2934 | * get BH_Lock set before the stripe lock is released. |
| 2935 | * |
| 2936 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2937 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 2938 | static void handle_stripe5(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | { |
| 2940 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2941 | int disks = sh->disks, i; |
| 2942 | struct bio *return_bi = NULL; |
| 2943 | struct stripe_head_state s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | struct r5dev *dev; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2945 | mdk_rdev_t *blocked_rdev = NULL; |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 2946 | int prexor; |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 2947 | int dec_preread_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2949 | memset(&s, 0, sizeof(s)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2950 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d check:%d " |
| 2951 | "reconstruct:%d\n", (unsigned long long)sh->sector, sh->state, |
| 2952 | atomic_read(&sh->count), sh->pd_idx, sh->check_state, |
| 2953 | sh->reconstruct_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | |
| 2955 | spin_lock(&sh->lock); |
| 2956 | clear_bit(STRIPE_HANDLE, &sh->state); |
| 2957 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 2958 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2959 | s.syncing = test_bit(STRIPE_SYNCING, &sh->state); |
| 2960 | s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 2961 | s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | /* Now to look around and see what can be done */ |
NeilBrown | 9910f16 | 2006-01-06 00:20:24 -0800 | [diff] [blame] | 2964 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | for (i=disks; i--; ) { |
| 2966 | mdk_rdev_t *rdev; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 2967 | |
| 2968 | dev = &sh->dev[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | clear_bit(R5_Insync, &dev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2971 | pr_debug("check %d: state 0x%lx toread %p read %p write %p " |
| 2972 | "written %p\n", i, dev->flags, dev->toread, dev->read, |
| 2973 | dev->towrite, dev->written); |
| 2974 | |
| 2975 | /* maybe we can request a biofill operation |
| 2976 | * |
| 2977 | * new wantfill requests are only permitted while |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2978 | * ops_complete_biofill is guaranteed to be inactive |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2979 | */ |
| 2980 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2981 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2982 | set_bit(R5_Wantfill, &dev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | |
| 2984 | /* now count some things */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2985 | if (test_bit(R5_LOCKED, &dev->flags)) s.locked++; |
| 2986 | if (test_bit(R5_UPTODATE, &dev->flags)) s.uptodate++; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2987 | if (test_bit(R5_Wantcompute, &dev->flags)) s.compute++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2989 | if (test_bit(R5_Wantfill, &dev->flags)) |
| 2990 | s.to_fill++; |
| 2991 | else if (dev->toread) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2992 | s.to_read++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | if (dev->towrite) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2994 | s.to_write++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2996 | s.non_overwrite++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2998 | if (dev->written) |
| 2999 | s.written++; |
NeilBrown | 9910f16 | 2006-01-06 00:20:24 -0800 | [diff] [blame] | 3000 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3001 | if (blocked_rdev == NULL && |
| 3002 | rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3003 | blocked_rdev = rdev; |
| 3004 | atomic_inc(&rdev->nr_pending); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3005 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3006 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 3007 | /* The ReadError flag will just be confusing now */ |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3008 | clear_bit(R5_ReadError, &dev->flags); |
| 3009 | clear_bit(R5_ReWrite, &dev->flags); |
| 3010 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3011 | if (!rdev || !test_bit(In_sync, &rdev->flags) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3012 | || test_bit(R5_ReadError, &dev->flags)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3013 | s.failed++; |
| 3014 | s.failed_num = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | } else |
| 3016 | set_bit(R5_Insync, &dev->flags); |
| 3017 | } |
NeilBrown | 9910f16 | 2006-01-06 00:20:24 -0800 | [diff] [blame] | 3018 | rcu_read_unlock(); |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3019 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3020 | if (unlikely(blocked_rdev)) { |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3021 | if (s.syncing || s.expanding || s.expanded || |
| 3022 | s.to_write || s.written) { |
| 3023 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3024 | goto unlock; |
| 3025 | } |
| 3026 | /* There is nothing for the blocked_rdev to block */ |
| 3027 | rdev_dec_pending(blocked_rdev, conf->mddev); |
| 3028 | blocked_rdev = NULL; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 3031 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3032 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3033 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3034 | } |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3035 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3036 | pr_debug("locked=%d uptodate=%d to_read=%d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | " to_write=%d failed=%d failed_num=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3038 | s.locked, s.uptodate, s.to_read, s.to_write, |
| 3039 | s.failed, s.failed_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | /* check if the array has lost two devices and, if so, some requests might |
| 3041 | * need to be failed |
| 3042 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3043 | if (s.failed > 1 && s.to_read+s.to_write+s.written) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3044 | handle_failed_stripe(conf, sh, &s, disks, &return_bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3045 | if (s.failed > 1 && s.syncing) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | md_done_sync(conf->mddev, STRIPE_SECTORS,0); |
| 3047 | clear_bit(STRIPE_SYNCING, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3048 | s.syncing = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | /* might be able to return some write requests if the parity block |
| 3052 | * is safe, or on a failed drive |
| 3053 | */ |
| 3054 | dev = &sh->dev[sh->pd_idx]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3055 | if ( s.written && |
| 3056 | ((test_bit(R5_Insync, &dev->flags) && |
| 3057 | !test_bit(R5_LOCKED, &dev->flags) && |
| 3058 | test_bit(R5_UPTODATE, &dev->flags)) || |
| 3059 | (s.failed == 1 && s.failed_num == sh->pd_idx))) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3060 | handle_stripe_clean_event(conf, sh, disks, &return_bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | |
| 3062 | /* Now we might consider reading some blocks, either to check/generate |
| 3063 | * parity, or to satisfy requests |
| 3064 | * or to load a block that is being partially written. |
| 3065 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3066 | if (s.to_read || s.non_overwrite || |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3067 | (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3068 | handle_stripe_fill5(sh, &s, disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3070 | /* Now we check to see if any write operations have recently |
| 3071 | * completed |
| 3072 | */ |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 3073 | prexor = 0; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3074 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 3075 | prexor = 1; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3076 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 3077 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3078 | sh->reconstruct_state = reconstruct_state_idle; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3079 | |
| 3080 | /* All the 'written' buffers and the parity block are ready to |
| 3081 | * be written back to disk |
| 3082 | */ |
| 3083 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); |
| 3084 | for (i = disks; i--; ) { |
| 3085 | dev = &sh->dev[i]; |
| 3086 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3087 | (i == sh->pd_idx || dev->written)) { |
| 3088 | pr_debug("Writing block %d\n", i); |
| 3089 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 3090 | if (prexor) |
| 3091 | continue; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3092 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3093 | (i == sh->pd_idx && s.failed == 0)) |
| 3094 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3095 | } |
| 3096 | } |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3097 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3098 | dec_preread_active = 1; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | /* Now to consider new write requests and what else, if anything |
| 3102 | * should be read. We do not handle new writes when: |
| 3103 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 3104 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3105 | * block. |
| 3106 | */ |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3107 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3108 | handle_stripe_dirtying5(conf, sh, &s, disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | |
| 3110 | /* maybe we need to check and possibly fix the parity for this stripe |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3111 | * Any reads will already have been scheduled, so we just see if enough |
| 3112 | * data is available. The parity check is held off while parity |
| 3113 | * dependent operations are in flight. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | */ |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3115 | if (sh->check_state || |
| 3116 | (s.syncing && s.locked == 0 && |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3117 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3118 | !test_bit(STRIPE_INSYNC, &sh->state))) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3119 | handle_parity_checks5(conf, sh, &s, disks); |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3120 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3121 | if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | md_done_sync(conf->mddev, STRIPE_SECTORS,1); |
| 3123 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 3124 | } |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3125 | |
| 3126 | /* If the failed drive is just a ReadError, then we might need to progress |
| 3127 | * the repair/check process |
| 3128 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3129 | if (s.failed == 1 && !conf->mddev->ro && |
| 3130 | test_bit(R5_ReadError, &sh->dev[s.failed_num].flags) |
| 3131 | && !test_bit(R5_LOCKED, &sh->dev[s.failed_num].flags) |
| 3132 | && test_bit(R5_UPTODATE, &sh->dev[s.failed_num].flags) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3133 | ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3134 | dev = &sh->dev[s.failed_num]; |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3135 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3136 | set_bit(R5_Wantwrite, &dev->flags); |
| 3137 | set_bit(R5_ReWrite, &dev->flags); |
| 3138 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3139 | s.locked++; |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3140 | } else { |
| 3141 | /* let's read it back */ |
| 3142 | set_bit(R5_Wantread, &dev->flags); |
| 3143 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3144 | s.locked++; |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3148 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3149 | if (sh->reconstruct_state == reconstruct_state_result) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3150 | struct stripe_head *sh2 |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3151 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3152 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { |
| 3153 | /* sh cannot be written until sh2 has been read. |
| 3154 | * so arrange for sh to be delayed a little |
| 3155 | */ |
| 3156 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3157 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3158 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3159 | &sh2->state)) |
| 3160 | atomic_inc(&conf->preread_active_stripes); |
| 3161 | release_stripe(sh2); |
| 3162 | goto unlock; |
| 3163 | } |
| 3164 | if (sh2) |
| 3165 | release_stripe(sh2); |
| 3166 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3167 | sh->reconstruct_state = reconstruct_state_idle; |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3168 | clear_bit(STRIPE_EXPANDING, &sh->state); |
Dan Williams | 2339788 | 2008-07-23 20:05:34 -0700 | [diff] [blame] | 3169 | for (i = conf->raid_disks; i--; ) { |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3170 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
Dan Williams | 2339788 | 2008-07-23 20:05:34 -0700 | [diff] [blame] | 3171 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
Neil Brown | efe3114 | 2008-06-28 08:31:14 +1000 | [diff] [blame] | 3172 | s.locked++; |
Dan Williams | 2339788 | 2008-07-23 20:05:34 -0700 | [diff] [blame] | 3173 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3177 | !sh->reconstruct_state) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3178 | /* Need to write out all blocks after computing parity */ |
| 3179 | sh->disks = conf->raid_disks; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3180 | stripe_set_idx(sh->sector, conf, 0, sh); |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3181 | schedule_reconstruction(sh, &s, 1, 1); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3182 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3183 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 3184 | atomic_dec(&conf->reshape_stripes); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3185 | wake_up(&conf->wait_for_overlap); |
| 3186 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3187 | } |
| 3188 | |
Dan Williams | 0f94e87 | 2008-01-08 15:32:53 -0800 | [diff] [blame] | 3189 | if (s.expanding && s.locked == 0 && |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3190 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3191 | handle_stripe_expansion(conf, sh, NULL); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3192 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3193 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | spin_unlock(&sh->lock); |
| 3195 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3196 | /* wait for this device to become unblocked */ |
| 3197 | if (unlikely(blocked_rdev)) |
| 3198 | md_wait_for_blocked_rdev(blocked_rdev, conf->mddev); |
| 3199 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3200 | if (s.ops_request) |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 3201 | raid_run_ops(sh, s.ops_request); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3202 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 3203 | ops_run_io(sh, &s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3205 | if (dec_preread_active) { |
| 3206 | /* We delay this until after ops_run_io so that if make_request |
| 3207 | * is waiting on a barrier, it won't continue until the writes |
| 3208 | * have actually been submitted. |
| 3209 | */ |
| 3210 | atomic_dec(&conf->preread_active_stripes); |
| 3211 | if (atomic_read(&conf->preread_active_stripes) < |
| 3212 | IO_THRESHOLD) |
| 3213 | md_wakeup_thread(conf->mddev->thread); |
| 3214 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3215 | return_io(return_bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3218 | static void handle_stripe6(struct stripe_head *sh) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3219 | { |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3220 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3221 | int disks = sh->disks; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3222 | struct bio *return_bi = NULL; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3223 | int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3224 | struct stripe_head_state s; |
| 3225 | struct r6_state r6s; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3226 | struct r5dev *dev, *pdev, *qdev; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3227 | mdk_rdev_t *blocked_rdev = NULL; |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3228 | int dec_preread_active = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3229 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3230 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3231 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3232 | (unsigned long long)sh->sector, sh->state, |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3233 | atomic_read(&sh->count), pd_idx, qd_idx, |
| 3234 | sh->check_state, sh->reconstruct_state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3235 | memset(&s, 0, sizeof(s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3236 | |
| 3237 | spin_lock(&sh->lock); |
| 3238 | clear_bit(STRIPE_HANDLE, &sh->state); |
| 3239 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3240 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3241 | s.syncing = test_bit(STRIPE_SYNCING, &sh->state); |
| 3242 | s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3243 | s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3244 | /* Now to look around and see what can be done */ |
| 3245 | |
| 3246 | rcu_read_lock(); |
| 3247 | for (i=disks; i--; ) { |
| 3248 | mdk_rdev_t *rdev; |
| 3249 | dev = &sh->dev[i]; |
| 3250 | clear_bit(R5_Insync, &dev->flags); |
| 3251 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3252 | 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] | 3253 | i, dev->flags, dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3254 | /* maybe we can reply to a read |
| 3255 | * |
| 3256 | * new wantfill requests are only permitted while |
| 3257 | * ops_complete_biofill is guaranteed to be inactive |
| 3258 | */ |
| 3259 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 3260 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 3261 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3262 | |
| 3263 | /* now count some things */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3264 | if (test_bit(R5_LOCKED, &dev->flags)) s.locked++; |
| 3265 | if (test_bit(R5_UPTODATE, &dev->flags)) s.uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3266 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
| 3267 | s.compute++; |
| 3268 | BUG_ON(s.compute > 2); |
| 3269 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3270 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3271 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 3272 | s.to_fill++; |
| 3273 | } else if (dev->toread) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3274 | s.to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3275 | if (dev->towrite) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3276 | s.to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3277 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3278 | s.non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3279 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3280 | if (dev->written) |
| 3281 | s.written++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3282 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3283 | if (blocked_rdev == NULL && |
| 3284 | rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3285 | blocked_rdev = rdev; |
| 3286 | atomic_inc(&rdev->nr_pending); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3287 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3288 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { |
| 3289 | /* The ReadError flag will just be confusing now */ |
| 3290 | clear_bit(R5_ReadError, &dev->flags); |
| 3291 | clear_bit(R5_ReWrite, &dev->flags); |
| 3292 | } |
| 3293 | if (!rdev || !test_bit(In_sync, &rdev->flags) |
| 3294 | || test_bit(R5_ReadError, &dev->flags)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3295 | if (s.failed < 2) |
| 3296 | r6s.failed_num[s.failed] = i; |
| 3297 | s.failed++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3298 | } else |
| 3299 | set_bit(R5_Insync, &dev->flags); |
| 3300 | } |
| 3301 | rcu_read_unlock(); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3302 | |
| 3303 | if (unlikely(blocked_rdev)) { |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3304 | if (s.syncing || s.expanding || s.expanded || |
| 3305 | s.to_write || s.written) { |
| 3306 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3307 | goto unlock; |
| 3308 | } |
| 3309 | /* There is nothing for the blocked_rdev to block */ |
| 3310 | rdev_dec_pending(blocked_rdev, conf->mddev); |
| 3311 | blocked_rdev = NULL; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3312 | } |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3313 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3314 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3315 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3316 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3317 | } |
| 3318 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3319 | pr_debug("locked=%d uptodate=%d to_read=%d" |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3320 | " to_write=%d failed=%d failed_num=%d,%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3321 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 3322 | r6s.failed_num[0], r6s.failed_num[1]); |
| 3323 | /* check if the array has lost >2 devices and, if so, some requests |
| 3324 | * might need to be failed |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3325 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3326 | if (s.failed > 2 && s.to_read+s.to_write+s.written) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3327 | handle_failed_stripe(conf, sh, &s, disks, &return_bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3328 | if (s.failed > 2 && s.syncing) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3329 | md_done_sync(conf->mddev, STRIPE_SECTORS,0); |
| 3330 | clear_bit(STRIPE_SYNCING, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3331 | s.syncing = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | /* |
| 3335 | * might be able to return some write requests if the parity blocks |
| 3336 | * are safe, or on a failed drive |
| 3337 | */ |
| 3338 | pdev = &sh->dev[pd_idx]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3339 | r6s.p_failed = (s.failed >= 1 && r6s.failed_num[0] == pd_idx) |
| 3340 | || (s.failed >= 2 && r6s.failed_num[1] == pd_idx); |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3341 | qdev = &sh->dev[qd_idx]; |
| 3342 | r6s.q_failed = (s.failed >= 1 && r6s.failed_num[0] == qd_idx) |
| 3343 | || (s.failed >= 2 && r6s.failed_num[1] == qd_idx); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3344 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3345 | if ( s.written && |
| 3346 | ( r6s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3347 | && !test_bit(R5_LOCKED, &pdev->flags) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3348 | && test_bit(R5_UPTODATE, &pdev->flags)))) && |
| 3349 | ( r6s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3350 | && !test_bit(R5_LOCKED, &qdev->flags) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3351 | && test_bit(R5_UPTODATE, &qdev->flags))))) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3352 | handle_stripe_clean_event(conf, sh, disks, &return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3353 | |
| 3354 | /* Now we might consider reading some blocks, either to check/generate |
| 3355 | * parity, or to satisfy requests |
| 3356 | * or to load a block that is being partially written. |
| 3357 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3358 | if (s.to_read || s.non_overwrite || (s.to_write && s.failed) || |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3359 | (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3360 | handle_stripe_fill6(sh, &s, &r6s, disks); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3361 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3362 | /* Now we check to see if any write operations have recently |
| 3363 | * completed |
| 3364 | */ |
| 3365 | if (sh->reconstruct_state == reconstruct_state_drain_result) { |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3366 | |
| 3367 | sh->reconstruct_state = reconstruct_state_idle; |
| 3368 | /* All the 'written' buffers and the parity blocks are ready to |
| 3369 | * be written back to disk |
| 3370 | */ |
| 3371 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); |
| 3372 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags)); |
| 3373 | for (i = disks; i--; ) { |
| 3374 | dev = &sh->dev[i]; |
| 3375 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3376 | (i == sh->pd_idx || i == qd_idx || |
| 3377 | dev->written)) { |
| 3378 | pr_debug("Writing block %d\n", i); |
| 3379 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 3380 | set_bit(R5_Wantwrite, &dev->flags); |
| 3381 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3382 | ((i == sh->pd_idx || i == qd_idx) && |
| 3383 | s.failed == 0)) |
| 3384 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3385 | } |
| 3386 | } |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3387 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3388 | dec_preread_active = 1; |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3391 | /* Now to consider new write requests and what else, if anything |
| 3392 | * should be read. We do not handle new writes when: |
| 3393 | * 1/ A 'write' operation (copy+gen_syndrome) is already in flight. |
| 3394 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3395 | * block. |
| 3396 | */ |
| 3397 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3398 | handle_stripe_dirtying6(conf, sh, &s, &r6s, disks); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3399 | |
| 3400 | /* maybe we need to check and possibly fix the parity for this stripe |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3401 | * Any reads will already have been scheduled, so we just see if enough |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3402 | * data is available. The parity check is held off while parity |
| 3403 | * dependent operations are in flight. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3404 | */ |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3405 | if (sh->check_state || |
| 3406 | (s.syncing && s.locked == 0 && |
| 3407 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 3408 | !test_bit(STRIPE_INSYNC, &sh->state))) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3409 | handle_parity_checks6(conf, sh, &s, &r6s, disks); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3410 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3411 | if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3412 | md_done_sync(conf->mddev, STRIPE_SECTORS,1); |
| 3413 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 3414 | } |
| 3415 | |
| 3416 | /* If the failed drives are just a ReadError, then we might need |
| 3417 | * to progress the repair/check process |
| 3418 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3419 | if (s.failed <= 2 && !conf->mddev->ro) |
| 3420 | for (i = 0; i < s.failed; i++) { |
| 3421 | dev = &sh->dev[r6s.failed_num[i]]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3422 | if (test_bit(R5_ReadError, &dev->flags) |
| 3423 | && !test_bit(R5_LOCKED, &dev->flags) |
| 3424 | && test_bit(R5_UPTODATE, &dev->flags) |
| 3425 | ) { |
| 3426 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3427 | set_bit(R5_Wantwrite, &dev->flags); |
| 3428 | set_bit(R5_ReWrite, &dev->flags); |
| 3429 | set_bit(R5_LOCKED, &dev->flags); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3430 | s.locked++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3431 | } else { |
| 3432 | /* let's read it back */ |
| 3433 | set_bit(R5_Wantread, &dev->flags); |
| 3434 | set_bit(R5_LOCKED, &dev->flags); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3435 | s.locked++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3436 | } |
| 3437 | } |
| 3438 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3439 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3440 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3441 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 3442 | sh->reconstruct_state = reconstruct_state_idle; |
| 3443 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 3444 | for (i = conf->raid_disks; i--; ) { |
| 3445 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 3446 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3447 | s.locked++; |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 3452 | !sh->reconstruct_state) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3453 | struct stripe_head *sh2 |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3454 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3455 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { |
| 3456 | /* sh cannot be written until sh2 has been read. |
| 3457 | * so arrange for sh to be delayed a little |
| 3458 | */ |
| 3459 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3460 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3461 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3462 | &sh2->state)) |
| 3463 | atomic_inc(&conf->preread_active_stripes); |
| 3464 | release_stripe(sh2); |
| 3465 | goto unlock; |
| 3466 | } |
| 3467 | if (sh2) |
| 3468 | release_stripe(sh2); |
| 3469 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3470 | /* Need to write out all blocks after computing P&Q */ |
| 3471 | sh->disks = conf->raid_disks; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3472 | stripe_set_idx(sh->sector, conf, 0, sh); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3473 | schedule_reconstruction(sh, &s, 1, 1); |
| 3474 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3475 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3476 | atomic_dec(&conf->reshape_stripes); |
| 3477 | wake_up(&conf->wait_for_overlap); |
| 3478 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3479 | } |
| 3480 | |
Dan Williams | 0f94e87 | 2008-01-08 15:32:53 -0800 | [diff] [blame] | 3481 | if (s.expanding && s.locked == 0 && |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3482 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3483 | handle_stripe_expansion(conf, sh, &r6s); |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3484 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3485 | unlock: |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3486 | spin_unlock(&sh->lock); |
| 3487 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3488 | /* wait for this device to become unblocked */ |
| 3489 | if (unlikely(blocked_rdev)) |
| 3490 | md_wait_for_blocked_rdev(blocked_rdev, conf->mddev); |
| 3491 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3492 | if (s.ops_request) |
| 3493 | raid_run_ops(sh, s.ops_request); |
| 3494 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 3495 | ops_run_io(sh, &s); |
| 3496 | |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3497 | |
| 3498 | if (dec_preread_active) { |
| 3499 | /* We delay this until after ops_run_io so that if make_request |
| 3500 | * is waiting on a barrier, it won't continue until the writes |
| 3501 | * have actually been submitted. |
| 3502 | */ |
| 3503 | atomic_dec(&conf->preread_active_stripes); |
| 3504 | if (atomic_read(&conf->preread_active_stripes) < |
| 3505 | IO_THRESHOLD) |
| 3506 | md_wakeup_thread(conf->mddev->thread); |
| 3507 | } |
| 3508 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3509 | return_io(return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3510 | } |
| 3511 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3512 | static void handle_stripe(struct stripe_head *sh) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3513 | { |
| 3514 | if (sh->raid_conf->level == 6) |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3515 | handle_stripe6(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3516 | else |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3517 | handle_stripe5(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3520 | static void raid5_activate_delayed(raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | { |
| 3522 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 3523 | while (!list_empty(&conf->delayed_list)) { |
| 3524 | struct list_head *l = conf->delayed_list.next; |
| 3525 | struct stripe_head *sh; |
| 3526 | sh = list_entry(l, struct stripe_head, lru); |
| 3527 | list_del_init(l); |
| 3528 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3529 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3530 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3531 | list_add_tail(&sh->lru, &conf->hold_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | } |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 3533 | } else |
| 3534 | blk_plug_device(conf->mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3537 | static void activate_bit_delay(raid5_conf_t *conf) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3538 | { |
| 3539 | /* device_lock is held */ |
| 3540 | struct list_head head; |
| 3541 | list_add(&head, &conf->bitmap_list); |
| 3542 | list_del_init(&conf->bitmap_list); |
| 3543 | while (!list_empty(&head)) { |
| 3544 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
| 3545 | list_del_init(&sh->lru); |
| 3546 | atomic_inc(&sh->count); |
| 3547 | __release_stripe(conf, sh); |
| 3548 | } |
| 3549 | } |
| 3550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | static void unplug_slaves(mddev_t *mddev) |
| 3552 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3553 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | int i; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 3555 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | |
| 3557 | rcu_read_lock(); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 3558 | for (i = 0; i < devs; i++) { |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 3559 | mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3560 | if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3561 | struct request_queue *r_queue = bdev_get_queue(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | |
| 3563 | atomic_inc(&rdev->nr_pending); |
| 3564 | rcu_read_unlock(); |
| 3565 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 3566 | blk_unplug(r_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | |
| 3568 | rdev_dec_pending(rdev, mddev); |
| 3569 | rcu_read_lock(); |
| 3570 | } |
| 3571 | } |
| 3572 | rcu_read_unlock(); |
| 3573 | } |
| 3574 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3575 | static void raid5_unplug_device(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | { |
| 3577 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3578 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | unsigned long flags; |
| 3580 | |
| 3581 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3582 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3583 | if (blk_remove_plug(q)) { |
| 3584 | conf->seq_flush++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | md_wakeup_thread(mddev->thread); |
| 3588 | |
| 3589 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3590 | |
| 3591 | unplug_slaves(mddev); |
| 3592 | } |
| 3593 | |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3594 | static int raid5_congested(void *data, int bits) |
| 3595 | { |
| 3596 | mddev_t *mddev = data; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3597 | raid5_conf_t *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3598 | |
| 3599 | /* No difference between reads and writes. Just check |
| 3600 | * how busy the stripe_cache is |
| 3601 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 3602 | |
| 3603 | if (mddev_congested(mddev, bits)) |
| 3604 | return 1; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3605 | if (conf->inactive_blocked) |
| 3606 | return 1; |
| 3607 | if (conf->quiesce) |
| 3608 | return 1; |
| 3609 | if (list_empty_careful(&conf->inactive_list)) |
| 3610 | return 1; |
| 3611 | |
| 3612 | return 0; |
| 3613 | } |
| 3614 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3615 | /* We want read requests to align with chunks where possible, |
| 3616 | * but write requests don't need to. |
| 3617 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3618 | static int raid5_mergeable_bvec(struct request_queue *q, |
| 3619 | struct bvec_merge_data *bvm, |
| 3620 | struct bio_vec *biovec) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3621 | { |
| 3622 | mddev_t *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3623 | 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] | 3624 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3625 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3626 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3627 | |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3628 | if ((bvm->bi_rw & 1) == WRITE) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3629 | return biovec->bv_len; /* always allow writes to be mergeable */ |
| 3630 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3631 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3632 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3633 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 3634 | if (max < 0) max = 0; |
| 3635 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 3636 | return biovec->bv_len; |
| 3637 | else |
| 3638 | return max; |
| 3639 | } |
| 3640 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3641 | |
| 3642 | static int in_chunk_boundary(mddev_t *mddev, struct bio *bio) |
| 3643 | { |
| 3644 | sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3645 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3646 | unsigned int bio_sectors = bio->bi_size >> 9; |
| 3647 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3648 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3649 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3650 | return chunk_sectors >= |
| 3651 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 3652 | } |
| 3653 | |
| 3654 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3655 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 3656 | * later sampled by raid5d. |
| 3657 | */ |
| 3658 | static void add_bio_to_retry(struct bio *bi,raid5_conf_t *conf) |
| 3659 | { |
| 3660 | unsigned long flags; |
| 3661 | |
| 3662 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3663 | |
| 3664 | bi->bi_next = conf->retry_read_aligned_list; |
| 3665 | conf->retry_read_aligned_list = bi; |
| 3666 | |
| 3667 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3668 | md_wakeup_thread(conf->mddev->thread); |
| 3669 | } |
| 3670 | |
| 3671 | |
| 3672 | static struct bio *remove_bio_from_retry(raid5_conf_t *conf) |
| 3673 | { |
| 3674 | struct bio *bi; |
| 3675 | |
| 3676 | bi = conf->retry_read_aligned; |
| 3677 | if (bi) { |
| 3678 | conf->retry_read_aligned = NULL; |
| 3679 | return bi; |
| 3680 | } |
| 3681 | bi = conf->retry_read_aligned_list; |
| 3682 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3683 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3684 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 3685 | /* |
| 3686 | * this sets the active strip count to 1 and the processed |
| 3687 | * strip count to zero (upper 8 bits) |
| 3688 | */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3689 | bi->bi_phys_segments = 1; /* biased count of active stripes */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | return bi; |
| 3693 | } |
| 3694 | |
| 3695 | |
| 3696 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3697 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 3698 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 3699 | * first). |
| 3700 | * If the read failed.. |
| 3701 | */ |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3702 | static void raid5_align_endio(struct bio *bi, int error) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3703 | { |
| 3704 | struct bio* raid_bi = bi->bi_private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3705 | mddev_t *mddev; |
| 3706 | raid5_conf_t *conf; |
| 3707 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
| 3708 | mdk_rdev_t *rdev; |
| 3709 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3710 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3711 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3712 | rdev = (void*)raid_bi->bi_next; |
| 3713 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 3714 | mddev = rdev->mddev; |
| 3715 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3716 | |
| 3717 | rdev_dec_pending(rdev, conf->mddev); |
| 3718 | |
| 3719 | if (!error && uptodate) { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3720 | bio_endio(raid_bi, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3721 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 3722 | wake_up(&conf->wait_for_stripe); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3723 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3727 | 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] | 3728 | |
| 3729 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3730 | } |
| 3731 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3732 | static int bio_fits_rdev(struct bio *bi) |
| 3733 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3734 | struct request_queue *q = bdev_get_queue(bi->bi_bdev); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3735 | |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 3736 | if ((bi->bi_size>>9) > queue_max_sectors(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3737 | return 0; |
| 3738 | blk_recount_segments(q, bi); |
Martin K. Petersen | 8a78362 | 2010-02-26 00:20:39 -0500 | [diff] [blame] | 3739 | if (bi->bi_phys_segments > queue_max_segments(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3740 | return 0; |
| 3741 | |
| 3742 | if (q->merge_bvec_fn) |
| 3743 | /* it's too hard to apply the merge_bvec_fn at this stage, |
| 3744 | * just just give up |
| 3745 | */ |
| 3746 | return 0; |
| 3747 | |
| 3748 | return 1; |
| 3749 | } |
| 3750 | |
| 3751 | |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 3752 | static int chunk_aligned_read(mddev_t *mddev, struct bio * raid_bio) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3753 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3754 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 8553fe7ec | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 3755 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3756 | struct bio* align_bi; |
| 3757 | mdk_rdev_t *rdev; |
| 3758 | |
| 3759 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3760 | pr_debug("chunk_aligned_read : non aligned\n"); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3761 | return 0; |
| 3762 | } |
| 3763 | /* |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3764 | * use bio_clone to make a copy of the bio |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3765 | */ |
| 3766 | align_bi = bio_clone(raid_bio, GFP_NOIO); |
| 3767 | if (!align_bi) |
| 3768 | return 0; |
| 3769 | /* |
| 3770 | * set bi_end_io to a new function, and set bi_private to the |
| 3771 | * original bio. |
| 3772 | */ |
| 3773 | align_bi->bi_end_io = raid5_align_endio; |
| 3774 | align_bi->bi_private = raid_bio; |
| 3775 | /* |
| 3776 | * compute position |
| 3777 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3778 | align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, |
| 3779 | 0, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3780 | &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3781 | |
| 3782 | rcu_read_lock(); |
| 3783 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 3784 | if (rdev && test_bit(In_sync, &rdev->flags)) { |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3785 | atomic_inc(&rdev->nr_pending); |
| 3786 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3787 | raid_bio->bi_next = (void*)rdev; |
| 3788 | align_bi->bi_bdev = rdev->bdev; |
| 3789 | align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); |
| 3790 | align_bi->bi_sector += rdev->data_offset; |
| 3791 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3792 | if (!bio_fits_rdev(align_bi)) { |
| 3793 | /* too big in some way */ |
| 3794 | bio_put(align_bi); |
| 3795 | rdev_dec_pending(rdev, mddev); |
| 3796 | return 0; |
| 3797 | } |
| 3798 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3799 | spin_lock_irq(&conf->device_lock); |
| 3800 | wait_event_lock_irq(conf->wait_for_stripe, |
| 3801 | conf->quiesce == 0, |
| 3802 | conf->device_lock, /* nothing */); |
| 3803 | atomic_inc(&conf->active_aligned_reads); |
| 3804 | spin_unlock_irq(&conf->device_lock); |
| 3805 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3806 | generic_make_request(align_bi); |
| 3807 | return 1; |
| 3808 | } else { |
| 3809 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3810 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3811 | return 0; |
| 3812 | } |
| 3813 | } |
| 3814 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3815 | /* __get_priority_stripe - get the next stripe to process |
| 3816 | * |
| 3817 | * Full stripe writes are allowed to pass preread active stripes up until |
| 3818 | * the bypass_threshold is exceeded. In general the bypass_count |
| 3819 | * increments when the handle_list is handled before the hold_list; however, it |
| 3820 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 3821 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 3822 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 3823 | * handle_list. |
| 3824 | */ |
| 3825 | static struct stripe_head *__get_priority_stripe(raid5_conf_t *conf) |
| 3826 | { |
| 3827 | struct stripe_head *sh; |
| 3828 | |
| 3829 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 3830 | __func__, |
| 3831 | list_empty(&conf->handle_list) ? "empty" : "busy", |
| 3832 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 3833 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 3834 | |
| 3835 | if (!list_empty(&conf->handle_list)) { |
| 3836 | sh = list_entry(conf->handle_list.next, typeof(*sh), lru); |
| 3837 | |
| 3838 | if (list_empty(&conf->hold_list)) |
| 3839 | conf->bypass_count = 0; |
| 3840 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 3841 | if (conf->hold_list.next == conf->last_hold) |
| 3842 | conf->bypass_count++; |
| 3843 | else { |
| 3844 | conf->last_hold = conf->hold_list.next; |
| 3845 | conf->bypass_count -= conf->bypass_threshold; |
| 3846 | if (conf->bypass_count < 0) |
| 3847 | conf->bypass_count = 0; |
| 3848 | } |
| 3849 | } |
| 3850 | } else if (!list_empty(&conf->hold_list) && |
| 3851 | ((conf->bypass_threshold && |
| 3852 | conf->bypass_count > conf->bypass_threshold) || |
| 3853 | atomic_read(&conf->pending_full_writes) == 0)) { |
| 3854 | sh = list_entry(conf->hold_list.next, |
| 3855 | typeof(*sh), lru); |
| 3856 | conf->bypass_count -= conf->bypass_threshold; |
| 3857 | if (conf->bypass_count < 0) |
| 3858 | conf->bypass_count = 0; |
| 3859 | } else |
| 3860 | return NULL; |
| 3861 | |
| 3862 | list_del_init(&sh->lru); |
| 3863 | atomic_inc(&sh->count); |
| 3864 | BUG_ON(atomic_read(&sh->count) != 1); |
| 3865 | return sh; |
| 3866 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3867 | |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 3868 | static int make_request(mddev_t *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3870 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3871 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | sector_t new_sector; |
| 3873 | sector_t logical_sector, last_sector; |
| 3874 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 3875 | const int rw = bio_data_dir(bi); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 3876 | int remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | |
Jens Axboe | 1f98a13 | 2009-09-11 14:32:04 +0200 | [diff] [blame] | 3878 | if (unlikely(bio_rw_flagged(bi, BIO_RW_BARRIER))) { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 3879 | /* Drain all pending writes. We only really need |
| 3880 | * to ensure they have been submitted, but this is |
| 3881 | * easier. |
| 3882 | */ |
| 3883 | mddev->pers->quiesce(mddev, 1); |
| 3884 | mddev->pers->quiesce(mddev, 0); |
| 3885 | md_barrier_request(mddev, bi); |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 3886 | return 0; |
| 3887 | } |
| 3888 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 3889 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3890 | |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 3891 | if (rw == READ && |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3892 | mddev->reshape_position == MaxSector && |
NeilBrown | 21a52c6 | 2010-04-01 15:02:13 +1100 | [diff] [blame] | 3893 | chunk_aligned_read(mddev,bi)) |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3894 | return 0; |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 3897 | last_sector = bi->bi_sector + (bi->bi_size>>9); |
| 3898 | bi->bi_next = NULL; |
| 3899 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
| 3902 | DEFINE_WAIT(w); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3903 | int disks, data_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3904 | int previous; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3905 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3906 | retry: |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3907 | previous = 0; |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3908 | disks = conf->raid_disks; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3909 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3910 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3911 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3912 | * 64bit on a 32bit platform, and so it might be |
| 3913 | * possible to see a half-updated value |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3914 | * Ofcourse reshape_progress could change after |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3915 | * the lock is dropped, so once we get a reference |
| 3916 | * to the stripe that we think it is, we will have |
| 3917 | * to check again. |
| 3918 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3919 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3920 | if (mddev->delta_disks < 0 |
| 3921 | ? logical_sector < conf->reshape_progress |
| 3922 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3923 | disks = conf->previous_raid_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3924 | previous = 1; |
| 3925 | } else { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3926 | if (mddev->delta_disks < 0 |
| 3927 | ? logical_sector < conf->reshape_safe |
| 3928 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3929 | spin_unlock_irq(&conf->device_lock); |
| 3930 | schedule(); |
| 3931 | goto retry; |
| 3932 | } |
| 3933 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3934 | spin_unlock_irq(&conf->device_lock); |
| 3935 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3936 | data_disks = disks - conf->max_degraded; |
| 3937 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3938 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 3939 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3940 | &dd_idx, NULL); |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 3941 | pr_debug("raid456: make_request, sector %llu logical %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | (unsigned long long)new_sector, |
| 3943 | (unsigned long long)logical_sector); |
| 3944 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3945 | sh = get_active_stripe(conf, new_sector, previous, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3946 | (bi->bi_rw&RWA_MASK), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3948 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3949 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3950 | * stripe, so we must do the range check again. |
| 3951 | * Expansion could still move past after this |
| 3952 | * test, but as we are holding a reference to |
| 3953 | * 'sh', we know that if that happens, |
| 3954 | * STRIPE_EXPANDING will get set and the expansion |
| 3955 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3956 | */ |
| 3957 | int must_retry = 0; |
| 3958 | spin_lock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3959 | if (mddev->delta_disks < 0 |
| 3960 | ? logical_sector >= conf->reshape_progress |
| 3961 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3962 | /* mismatch, need to try again */ |
| 3963 | must_retry = 1; |
| 3964 | spin_unlock_irq(&conf->device_lock); |
| 3965 | if (must_retry) { |
| 3966 | release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 3967 | schedule(); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3968 | goto retry; |
| 3969 | } |
| 3970 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3971 | |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3972 | if (bio_data_dir(bi) == WRITE && |
| 3973 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3974 | logical_sector < mddev->suspend_hi) { |
| 3975 | release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3976 | /* As the suspend_* range is controlled by |
| 3977 | * userspace, we want an interruptible |
| 3978 | * wait. |
| 3979 | */ |
| 3980 | flush_signals(current); |
| 3981 | prepare_to_wait(&conf->wait_for_overlap, |
| 3982 | &w, TASK_INTERRUPTIBLE); |
| 3983 | if (logical_sector >= mddev->suspend_lo && |
| 3984 | logical_sector < mddev->suspend_hi) |
| 3985 | schedule(); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3986 | goto retry; |
| 3987 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3988 | |
| 3989 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
| 3990 | !add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) { |
| 3991 | /* Stripe is busy expanding or |
| 3992 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | * and wait a while |
| 3994 | */ |
| 3995 | raid5_unplug_device(mddev->queue); |
| 3996 | release_stripe(sh); |
| 3997 | schedule(); |
| 3998 | goto retry; |
| 3999 | } |
| 4000 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4001 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4002 | clear_bit(STRIPE_DELAYED, &sh->state); |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4003 | if (mddev->barrier && |
| 4004 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4005 | atomic_inc(&conf->preread_active_stripes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | } else { |
| 4008 | /* cannot get stripe for read-ahead, just give-up */ |
| 4009 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
| 4010 | finish_wait(&conf->wait_for_overlap, &w); |
| 4011 | break; |
| 4012 | } |
| 4013 | |
| 4014 | } |
| 4015 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4016 | remaining = raid5_dec_bi_phys_segments(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 4017 | spin_unlock_irq(&conf->device_lock); |
| 4018 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4020 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4022 | |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4023 | bio_endio(bi, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | } |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4025 | |
| 4026 | if (mddev->barrier) { |
| 4027 | /* We need to wait for the stripes to all be handled. |
| 4028 | * So: wait for preread_active_stripes to drop to 0. |
| 4029 | */ |
| 4030 | wait_event(mddev->thread->wqueue, |
| 4031 | atomic_read(&conf->preread_active_stripes) == 0); |
| 4032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | return 0; |
| 4034 | } |
| 4035 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4036 | static sector_t raid5_size(mddev_t *mddev, sector_t sectors, int raid_disks); |
| 4037 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4038 | static sector_t reshape_request(mddev_t *mddev, sector_t sector_nr, int *skipped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4040 | /* reshaping is quite different to recovery/resync so it is |
| 4041 | * handled quite separately ... here. |
| 4042 | * |
| 4043 | * On each call to sync_request, we gather one chunk worth of |
| 4044 | * destination stripes and flag them as expanding. |
| 4045 | * Then we find all the source stripes and request reads. |
| 4046 | * As the reads complete, handle_stripe will copy the data |
| 4047 | * into the destination stripe and release that stripe. |
| 4048 | */ |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 4049 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4051 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4052 | int raid_disks = conf->previous_raid_disks; |
| 4053 | int data_disks = raid_disks - conf->max_degraded; |
| 4054 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4055 | int i; |
| 4056 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4057 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4058 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4059 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4060 | struct list_head stripes; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4061 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4062 | if (sector_nr == 0) { |
| 4063 | /* If restarting in the middle, skip the initial sectors */ |
| 4064 | if (mddev->delta_disks < 0 && |
| 4065 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 4066 | sector_nr = raid5_size(mddev, 0, 0) |
| 4067 | - conf->reshape_progress; |
NeilBrown | a639755 | 2009-08-13 10:13:00 +1000 | [diff] [blame] | 4068 | } else if (mddev->delta_disks >= 0 && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4069 | conf->reshape_progress > 0) |
| 4070 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4071 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4072 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 4073 | mddev->curr_resync_completed = sector_nr; |
| 4074 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4075 | *skipped = 1; |
| 4076 | return sector_nr; |
| 4077 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4078 | } |
| 4079 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4080 | /* We need to process a full chunk at a time. |
| 4081 | * If old and new chunk sizes differ, we need to process the |
| 4082 | * largest of these |
| 4083 | */ |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4084 | if (mddev->new_chunk_sectors > mddev->chunk_sectors) |
| 4085 | reshape_sectors = mddev->new_chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4086 | else |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4087 | reshape_sectors = mddev->chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4088 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4089 | /* we update the metadata when there is more than 3Meg |
| 4090 | * in the block range (that is rather arbitrary, should |
| 4091 | * probably be time based) or when the data about to be |
| 4092 | * copied would over-write the source of the data at |
| 4093 | * the front of the range. |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4094 | * i.e. one new_stripe along from reshape_progress new_maps |
| 4095 | * to after where reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4096 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4097 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4098 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4099 | readpos = conf->reshape_progress; |
| 4100 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4101 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4102 | sector_div(safepos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4103 | if (mddev->delta_disks < 0) { |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4104 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4105 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4106 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4107 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4108 | writepos += reshape_sectors; |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4109 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 4110 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4111 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4112 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4113 | /* 'writepos' is the most advanced device address we might write. |
| 4114 | * 'readpos' is the least advanced device address we might read. |
| 4115 | * 'safepos' is the least address recorded in the metadata as having |
| 4116 | * been reshaped. |
| 4117 | * If 'readpos' is behind 'writepos', then there is no way that we can |
| 4118 | * ensure safety in the face of a crash - that must be done by userspace |
| 4119 | * making a backup of the data. So in that case there is no particular |
| 4120 | * rush to update metadata. |
| 4121 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 4122 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 4123 | * we can be safe in the event of a crash. |
| 4124 | * So we insist on updating metadata if safepos is behind writepos and |
| 4125 | * readpos is beyond writepos. |
| 4126 | * In any case, update the metadata every 10 seconds. |
| 4127 | * Maybe that number should be configurable, but I'm not sure it is |
| 4128 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 4129 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4130 | if ((mddev->delta_disks < 0 |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4131 | ? (safepos > writepos && readpos < writepos) |
| 4132 | : (safepos < writepos && readpos > writepos)) || |
| 4133 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4134 | /* Cannot proceed until we've updated the superblock... */ |
| 4135 | wait_event(conf->wait_for_overlap, |
| 4136 | atomic_read(&conf->reshape_stripes)==0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4137 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4138 | mddev->curr_resync_completed = mddev->curr_resync; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4139 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4140 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4141 | md_wakeup_thread(mddev->thread); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4142 | wait_event(mddev->sb_wait, mddev->flags == 0 || |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4143 | kthread_should_stop()); |
| 4144 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4145 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4146 | spin_unlock_irq(&conf->device_lock); |
| 4147 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4148 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4151 | if (mddev->delta_disks < 0) { |
| 4152 | BUG_ON(conf->reshape_progress == 0); |
| 4153 | stripe_addr = writepos; |
| 4154 | BUG_ON((mddev->dev_sectors & |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4155 | ~((sector_t)reshape_sectors - 1)) |
| 4156 | - reshape_sectors - stripe_addr |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4157 | != sector_nr); |
| 4158 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4159 | BUG_ON(writepos != sector_nr + reshape_sectors); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4160 | stripe_addr = sector_nr; |
| 4161 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4162 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4163 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4164 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4165 | int skipped_disk = 0; |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4166 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4167 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 4168 | atomic_inc(&conf->reshape_stripes); |
| 4169 | /* If any of this stripe is beyond the end of the old |
| 4170 | * array, then we need to zero those blocks |
| 4171 | */ |
| 4172 | for (j=sh->disks; j--;) { |
| 4173 | sector_t s; |
| 4174 | if (j == sh->pd_idx) |
| 4175 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4176 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4177 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4178 | continue; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 4179 | s = compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4180 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4181 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4182 | continue; |
| 4183 | } |
| 4184 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 4185 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 4186 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 4187 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4188 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4189 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4190 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4191 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4192 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4193 | } |
| 4194 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4195 | if (mddev->delta_disks < 0) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4196 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4197 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4198 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4199 | spin_unlock_irq(&conf->device_lock); |
| 4200 | /* Ok, those stripe are ready. We can start scheduling |
| 4201 | * reads on the source stripes. |
| 4202 | * The source stripes are determined by mapping the first and last |
| 4203 | * block on the destination stripes. |
| 4204 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4205 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4206 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4207 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4208 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 4209 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4210 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4211 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4212 | if (last_sector >= mddev->dev_sectors) |
| 4213 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4214 | while (first_sector <= last_sector) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4215 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4216 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4217 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4218 | release_stripe(sh); |
| 4219 | first_sector += STRIPE_SECTORS; |
| 4220 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4221 | /* Now that the sources are clearly marked, we can release |
| 4222 | * the destination stripes |
| 4223 | */ |
| 4224 | while (!list_empty(&stripes)) { |
| 4225 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 4226 | list_del_init(&sh->lru); |
| 4227 | release_stripe(sh); |
| 4228 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4229 | /* If this takes us to the resync_max point where we have to pause, |
| 4230 | * then we need to write out the superblock. |
| 4231 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4232 | sector_nr += reshape_sectors; |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 4233 | if ((sector_nr - mddev->curr_resync_completed) * 2 |
| 4234 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4235 | /* Cannot proceed until we've updated the superblock... */ |
| 4236 | wait_event(conf->wait_for_overlap, |
| 4237 | atomic_read(&conf->reshape_stripes) == 0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4238 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 48606a9 | 2009-06-18 09:14:12 +1000 | [diff] [blame] | 4239 | mddev->curr_resync_completed = mddev->curr_resync + reshape_sectors; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4240 | conf->reshape_checkpoint = jiffies; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4241 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 4242 | md_wakeup_thread(mddev->thread); |
| 4243 | wait_event(mddev->sb_wait, |
| 4244 | !test_bit(MD_CHANGE_DEVS, &mddev->flags) |
| 4245 | || kthread_should_stop()); |
| 4246 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4247 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4248 | spin_unlock_irq(&conf->device_lock); |
| 4249 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4250 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4251 | } |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4252 | return reshape_sectors; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | /* FIXME go_faster isn't used */ |
| 4256 | static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster) |
| 4257 | { |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 4258 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4259 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4260 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4261 | int sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4262 | int still_degraded = 0; |
| 4263 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4265 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | /* just being told to finish up .. nothing much to do */ |
| 4267 | unplug_slaves(mddev); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 4268 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 4269 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 4270 | end_reshape(conf); |
| 4271 | return 0; |
| 4272 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4273 | |
| 4274 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 4275 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 4276 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4277 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4278 | conf->fullsync = 0; |
| 4279 | bitmap_close_sync(mddev->bitmap); |
| 4280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | return 0; |
| 4282 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4283 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4284 | /* Allow raid5_quiesce to complete */ |
| 4285 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 4286 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4287 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 4288 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4289 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4290 | /* No need to check resync_max as we never do more than one |
| 4291 | * stripe, and as resync_max will always be on a chunk boundary, |
| 4292 | * if the check in md_do_sync didn't fire, there is no chance |
| 4293 | * of overstepping resync_max here |
| 4294 | */ |
| 4295 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4296 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | * to resync, then assert that we are finished, because there is |
| 4298 | * nothing we can do. |
| 4299 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 4300 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4301 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4302 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 4303 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | return rv; |
| 4305 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4306 | if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
NeilBrown | 3855ad9 | 2005-11-08 21:39:38 -0800 | [diff] [blame] | 4307 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4308 | !conf->fullsync && sync_blocks >= STRIPE_SECTORS) { |
| 4309 | /* we can skip this block, and probably more */ |
| 4310 | sync_blocks /= STRIPE_SECTORS; |
| 4311 | *skipped = 1; |
| 4312 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 4313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 4315 | |
| 4316 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 4317 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4318 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | if (sh == NULL) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4320 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4322 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 4324 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4326 | /* Need to check if array will still be degraded after recovery/resync |
| 4327 | * We don't need to check the 'failed' flag as when that gets set, |
| 4328 | * recovery aborts. |
| 4329 | */ |
NeilBrown | f001a70 | 2009-06-09 14:30:31 +1000 | [diff] [blame] | 4330 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4331 | if (conf->disks[i].rdev == NULL) |
| 4332 | still_degraded = 1; |
| 4333 | |
| 4334 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 4335 | |
| 4336 | spin_lock(&sh->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4337 | set_bit(STRIPE_SYNCING, &sh->state); |
| 4338 | clear_bit(STRIPE_INSYNC, &sh->state); |
| 4339 | spin_unlock(&sh->lock); |
| 4340 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 4341 | handle_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | release_stripe(sh); |
| 4343 | |
| 4344 | return STRIPE_SECTORS; |
| 4345 | } |
| 4346 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4347 | static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio) |
| 4348 | { |
| 4349 | /* We may not be able to submit a whole bio at once as there |
| 4350 | * may not be enough stripe_heads available. |
| 4351 | * We cannot pre-allocate enough stripe_heads as we may need |
| 4352 | * more than exist in the cache (if we allow ever large chunks). |
| 4353 | * So we do one stripe head at a time and record in |
| 4354 | * ->bi_hw_segments how many have been done. |
| 4355 | * |
| 4356 | * We *know* that this entire raid_bio is in one chunk, so |
| 4357 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 4358 | */ |
| 4359 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4360 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4361 | sector_t sector, logical_sector, last_sector; |
| 4362 | int scnt = 0; |
| 4363 | int remaining; |
| 4364 | int handled = 0; |
| 4365 | |
| 4366 | logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4367 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4368 | 0, &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4369 | last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9); |
| 4370 | |
| 4371 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4372 | logical_sector += STRIPE_SECTORS, |
| 4373 | sector += STRIPE_SECTORS, |
| 4374 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4375 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4376 | if (scnt < raid5_bi_hw_segments(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4377 | /* already done this stripe */ |
| 4378 | continue; |
| 4379 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4380 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4381 | |
| 4382 | if (!sh) { |
| 4383 | /* failed to get a stripe - must wait */ |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4384 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4385 | conf->retry_read_aligned = raid_bio; |
| 4386 | return handled; |
| 4387 | } |
| 4388 | |
| 4389 | set_bit(R5_ReadError, &sh->dev[dd_idx].flags); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4390 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
| 4391 | release_stripe(sh); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4392 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4393 | conf->retry_read_aligned = raid_bio; |
| 4394 | return handled; |
| 4395 | } |
| 4396 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4397 | handle_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4398 | release_stripe(sh); |
| 4399 | handled++; |
| 4400 | } |
| 4401 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4402 | remaining = raid5_dec_bi_phys_segments(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4403 | spin_unlock_irq(&conf->device_lock); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4404 | if (remaining == 0) |
| 4405 | bio_endio(raid_bio, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4406 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4407 | wake_up(&conf->wait_for_stripe); |
| 4408 | return handled; |
| 4409 | } |
| 4410 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | /* |
| 4413 | * This is our raid5 kernel thread. |
| 4414 | * |
| 4415 | * We scan the hash table for stripes which can be handled now. |
| 4416 | * During the scan, completed stripes are saved for us by the interrupt |
| 4417 | * handler, so that they will not have to wait for our next wakeup. |
| 4418 | */ |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4419 | static void raid5d(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | { |
| 4421 | struct stripe_head *sh; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4422 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | int handled; |
| 4424 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4425 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | |
| 4427 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
| 4429 | handled = 0; |
| 4430 | spin_lock_irq(&conf->device_lock); |
| 4431 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4432 | struct bio *bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 4434 | if (conf->seq_flush != conf->seq_write) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4435 | int seq = conf->seq_flush; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4436 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4437 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4438 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4439 | conf->seq_write = seq; |
| 4440 | activate_bit_delay(conf); |
| 4441 | } |
| 4442 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4443 | while ((bio = remove_bio_from_retry(conf))) { |
| 4444 | int ok; |
| 4445 | spin_unlock_irq(&conf->device_lock); |
| 4446 | ok = retry_aligned_read(conf, bio); |
| 4447 | spin_lock_irq(&conf->device_lock); |
| 4448 | if (!ok) |
| 4449 | break; |
| 4450 | handled++; |
| 4451 | } |
| 4452 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4453 | sh = __get_priority_stripe(conf); |
| 4454 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4455 | if (!sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | spin_unlock_irq(&conf->device_lock); |
| 4458 | |
| 4459 | handled++; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 4460 | handle_stripe(sh); |
| 4461 | release_stripe(sh); |
| 4462 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | |
| 4464 | spin_lock_irq(&conf->device_lock); |
| 4465 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4466 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | |
| 4468 | spin_unlock_irq(&conf->device_lock); |
| 4469 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4470 | async_tx_issue_pending_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | unplug_slaves(mddev); |
| 4472 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4473 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | } |
| 4475 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4476 | static ssize_t |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4477 | raid5_show_stripe_cache_size(mddev_t *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4478 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4479 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4480 | if (conf) |
| 4481 | return sprintf(page, "%d\n", conf->max_nr_stripes); |
| 4482 | else |
| 4483 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | static ssize_t |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4487 | raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4488 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4489 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4490 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4491 | int err; |
| 4492 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4493 | if (len >= PAGE_SIZE) |
| 4494 | return -EINVAL; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4495 | if (!conf) |
| 4496 | return -ENODEV; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4497 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4498 | if (strict_strtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4499 | return -EINVAL; |
| 4500 | if (new <= 16 || new > 32768) |
| 4501 | return -EINVAL; |
| 4502 | while (new < conf->max_nr_stripes) { |
| 4503 | if (drop_one_stripe(conf)) |
| 4504 | conf->max_nr_stripes--; |
| 4505 | else |
| 4506 | break; |
| 4507 | } |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4508 | err = md_allow_write(mddev); |
| 4509 | if (err) |
| 4510 | return err; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4511 | while (new > conf->max_nr_stripes) { |
| 4512 | if (grow_one_stripe(conf)) |
| 4513 | conf->max_nr_stripes++; |
| 4514 | else break; |
| 4515 | } |
| 4516 | return len; |
| 4517 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4518 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4519 | static struct md_sysfs_entry |
| 4520 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 4521 | raid5_show_stripe_cache_size, |
| 4522 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4523 | |
| 4524 | static ssize_t |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4525 | raid5_show_preread_threshold(mddev_t *mddev, char *page) |
| 4526 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4527 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4528 | if (conf) |
| 4529 | return sprintf(page, "%d\n", conf->bypass_threshold); |
| 4530 | else |
| 4531 | return 0; |
| 4532 | } |
| 4533 | |
| 4534 | static ssize_t |
| 4535 | raid5_store_preread_threshold(mddev_t *mddev, const char *page, size_t len) |
| 4536 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4537 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4538 | unsigned long new; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4539 | if (len >= PAGE_SIZE) |
| 4540 | return -EINVAL; |
| 4541 | if (!conf) |
| 4542 | return -ENODEV; |
| 4543 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4544 | if (strict_strtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4545 | return -EINVAL; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4546 | if (new > conf->max_nr_stripes) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4547 | return -EINVAL; |
| 4548 | conf->bypass_threshold = new; |
| 4549 | return len; |
| 4550 | } |
| 4551 | |
| 4552 | static struct md_sysfs_entry |
| 4553 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 4554 | S_IRUGO | S_IWUSR, |
| 4555 | raid5_show_preread_threshold, |
| 4556 | raid5_store_preread_threshold); |
| 4557 | |
| 4558 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4559 | stripe_cache_active_show(mddev_t *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4560 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4561 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4562 | if (conf) |
| 4563 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 4564 | else |
| 4565 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4566 | } |
| 4567 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4568 | static struct md_sysfs_entry |
| 4569 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4570 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4571 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4572 | &raid5_stripecache_size.attr, |
| 4573 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4574 | &raid5_preread_bypass_threshold.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4575 | NULL, |
| 4576 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4577 | static struct attribute_group raid5_attrs_group = { |
| 4578 | .name = NULL, |
| 4579 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4580 | }; |
| 4581 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4582 | static sector_t |
| 4583 | raid5_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
| 4584 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4585 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4586 | |
| 4587 | if (!sectors) |
| 4588 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4589 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 4590 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4591 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4592 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4593 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4594 | sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4595 | return sectors * (raid_disks - conf->max_degraded); |
| 4596 | } |
| 4597 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4598 | static void raid5_free_percpu(raid5_conf_t *conf) |
| 4599 | { |
| 4600 | struct raid5_percpu *percpu; |
| 4601 | unsigned long cpu; |
| 4602 | |
| 4603 | if (!conf->percpu) |
| 4604 | return; |
| 4605 | |
| 4606 | get_online_cpus(); |
| 4607 | for_each_possible_cpu(cpu) { |
| 4608 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4609 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4610 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4611 | } |
| 4612 | #ifdef CONFIG_HOTPLUG_CPU |
| 4613 | unregister_cpu_notifier(&conf->cpu_notify); |
| 4614 | #endif |
| 4615 | put_online_cpus(); |
| 4616 | |
| 4617 | free_percpu(conf->percpu); |
| 4618 | } |
| 4619 | |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4620 | static void free_conf(raid5_conf_t *conf) |
| 4621 | { |
| 4622 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4623 | raid5_free_percpu(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4624 | kfree(conf->disks); |
| 4625 | kfree(conf->stripe_hashtbl); |
| 4626 | kfree(conf); |
| 4627 | } |
| 4628 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4629 | #ifdef CONFIG_HOTPLUG_CPU |
| 4630 | static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, |
| 4631 | void *hcpu) |
| 4632 | { |
| 4633 | raid5_conf_t *conf = container_of(nfb, raid5_conf_t, cpu_notify); |
| 4634 | long cpu = (long)hcpu; |
| 4635 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4636 | |
| 4637 | switch (action) { |
| 4638 | case CPU_UP_PREPARE: |
| 4639 | case CPU_UP_PREPARE_FROZEN: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4640 | if (conf->level == 6 && !percpu->spare_page) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4641 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4642 | if (!percpu->scribble) |
| 4643 | percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
| 4644 | |
| 4645 | if (!percpu->scribble || |
| 4646 | (conf->level == 6 && !percpu->spare_page)) { |
| 4647 | safe_put_page(percpu->spare_page); |
| 4648 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4649 | pr_err("%s: failed memory allocation for cpu%ld\n", |
| 4650 | __func__, cpu); |
| 4651 | return NOTIFY_BAD; |
| 4652 | } |
| 4653 | break; |
| 4654 | case CPU_DEAD: |
| 4655 | case CPU_DEAD_FROZEN: |
| 4656 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4657 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4658 | percpu->spare_page = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4659 | percpu->scribble = NULL; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4660 | break; |
| 4661 | default: |
| 4662 | break; |
| 4663 | } |
| 4664 | return NOTIFY_OK; |
| 4665 | } |
| 4666 | #endif |
| 4667 | |
| 4668 | static int raid5_alloc_percpu(raid5_conf_t *conf) |
| 4669 | { |
| 4670 | unsigned long cpu; |
| 4671 | struct page *spare_page; |
Tejun Heo | a29d8b8 | 2010-02-02 14:39:15 +0900 | [diff] [blame] | 4672 | struct raid5_percpu __percpu *allcpus; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4673 | void *scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4674 | int err; |
| 4675 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4676 | allcpus = alloc_percpu(struct raid5_percpu); |
| 4677 | if (!allcpus) |
| 4678 | return -ENOMEM; |
| 4679 | conf->percpu = allcpus; |
| 4680 | |
| 4681 | get_online_cpus(); |
| 4682 | err = 0; |
| 4683 | for_each_present_cpu(cpu) { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4684 | if (conf->level == 6) { |
| 4685 | spare_page = alloc_page(GFP_KERNEL); |
| 4686 | if (!spare_page) { |
| 4687 | err = -ENOMEM; |
| 4688 | break; |
| 4689 | } |
| 4690 | per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page; |
| 4691 | } |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4692 | scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4693 | if (!scribble) { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4694 | err = -ENOMEM; |
| 4695 | break; |
| 4696 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4697 | per_cpu_ptr(conf->percpu, cpu)->scribble = scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4698 | } |
| 4699 | #ifdef CONFIG_HOTPLUG_CPU |
| 4700 | conf->cpu_notify.notifier_call = raid456_cpu_notify; |
| 4701 | conf->cpu_notify.priority = 0; |
| 4702 | if (err == 0) |
| 4703 | err = register_cpu_notifier(&conf->cpu_notify); |
| 4704 | #endif |
| 4705 | put_online_cpus(); |
| 4706 | |
| 4707 | return err; |
| 4708 | } |
| 4709 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4710 | static raid5_conf_t *setup_conf(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | { |
| 4712 | raid5_conf_t *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4713 | int raid_disk, memory, max_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | mdk_rdev_t *rdev; |
| 4715 | struct disk_info *disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4717 | if (mddev->new_level != 5 |
| 4718 | && mddev->new_level != 4 |
| 4719 | && mddev->new_level != 6) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4720 | 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] | 4721 | mdname(mddev), mddev->new_level); |
| 4722 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4724 | if ((mddev->new_level == 5 |
| 4725 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 4726 | (mddev->new_level == 6 |
| 4727 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4728 | printk(KERN_ERR "md/raid:%s: layout %d not supported\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4729 | mdname(mddev), mddev->new_layout); |
| 4730 | return ERR_PTR(-EIO); |
| 4731 | } |
| 4732 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4733 | 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] | 4734 | mdname(mddev), mddev->raid_disks); |
| 4735 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4738 | if (!mddev->new_chunk_sectors || |
| 4739 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 4740 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4741 | printk(KERN_ERR "md/raid:%s: invalid chunk size %d\n", |
| 4742 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4743 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4744 | } |
| 4745 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4746 | conf = kzalloc(sizeof(raid5_conf_t), GFP_KERNEL); |
| 4747 | if (conf == NULL) |
| 4748 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 4749 | spin_lock_init(&conf->device_lock); |
| 4750 | init_waitqueue_head(&conf->wait_for_stripe); |
| 4751 | init_waitqueue_head(&conf->wait_for_overlap); |
| 4752 | INIT_LIST_HEAD(&conf->handle_list); |
| 4753 | INIT_LIST_HEAD(&conf->hold_list); |
| 4754 | INIT_LIST_HEAD(&conf->delayed_list); |
| 4755 | INIT_LIST_HEAD(&conf->bitmap_list); |
| 4756 | INIT_LIST_HEAD(&conf->inactive_list); |
| 4757 | atomic_set(&conf->active_stripes, 0); |
| 4758 | atomic_set(&conf->preread_active_stripes, 0); |
| 4759 | atomic_set(&conf->active_aligned_reads, 0); |
| 4760 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4761 | |
| 4762 | conf->raid_disks = mddev->raid_disks; |
| 4763 | if (mddev->reshape_position == MaxSector) |
| 4764 | conf->previous_raid_disks = mddev->raid_disks; |
| 4765 | else |
| 4766 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4767 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
| 4768 | conf->scribble_len = scribble_len(max_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4769 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4770 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4771 | GFP_KERNEL); |
| 4772 | if (!conf->disks) |
| 4773 | goto abort; |
| 4774 | |
| 4775 | conf->mddev = mddev; |
| 4776 | |
| 4777 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 4778 | goto abort; |
| 4779 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4780 | conf->level = mddev->new_level; |
| 4781 | if (raid5_alloc_percpu(conf) != 0) |
| 4782 | goto abort; |
| 4783 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4784 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4785 | |
| 4786 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 4787 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4788 | if (raid_disk >= max_disks |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4789 | || raid_disk < 0) |
| 4790 | continue; |
| 4791 | disk = conf->disks + raid_disk; |
| 4792 | |
| 4793 | disk->rdev = rdev; |
| 4794 | |
| 4795 | if (test_bit(In_sync, &rdev->flags)) { |
| 4796 | char b[BDEVNAME_SIZE]; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4797 | printk(KERN_INFO "md/raid:%s: device %s operational as raid" |
| 4798 | " disk %d\n", |
| 4799 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4800 | } else |
| 4801 | /* Cannot rely on bitmap to complete recovery */ |
| 4802 | conf->fullsync = 1; |
| 4803 | } |
| 4804 | |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4805 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4806 | conf->level = mddev->new_level; |
| 4807 | if (conf->level == 6) |
| 4808 | conf->max_degraded = 2; |
| 4809 | else |
| 4810 | conf->max_degraded = 1; |
| 4811 | conf->algorithm = mddev->new_layout; |
| 4812 | conf->max_nr_stripes = NR_STRIPES; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4813 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4814 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4815 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4816 | conf->prev_algo = mddev->layout; |
| 4817 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4818 | |
| 4819 | memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4820 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4821 | if (grow_stripes(conf, conf->max_nr_stripes)) { |
| 4822 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4823 | "md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 4824 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4825 | goto abort; |
| 4826 | } else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4827 | printk(KERN_INFO "md/raid:%s: allocated %dkB\n", |
| 4828 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4829 | |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 4830 | conf->thread = md_register_thread(raid5d, mddev, NULL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4831 | if (!conf->thread) { |
| 4832 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4833 | "md/raid:%s: couldn't allocate thread.\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4834 | mdname(mddev)); |
| 4835 | goto abort; |
| 4836 | } |
| 4837 | |
| 4838 | return conf; |
| 4839 | |
| 4840 | abort: |
| 4841 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4842 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4843 | return ERR_PTR(-EIO); |
| 4844 | } else |
| 4845 | return ERR_PTR(-ENOMEM); |
| 4846 | } |
| 4847 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4848 | |
| 4849 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 4850 | { |
| 4851 | switch (algo) { |
| 4852 | case ALGORITHM_PARITY_0: |
| 4853 | if (raid_disk < max_degraded) |
| 4854 | return 1; |
| 4855 | break; |
| 4856 | case ALGORITHM_PARITY_N: |
| 4857 | if (raid_disk >= raid_disks - max_degraded) |
| 4858 | return 1; |
| 4859 | break; |
| 4860 | case ALGORITHM_PARITY_0_6: |
| 4861 | if (raid_disk == 0 || |
| 4862 | raid_disk == raid_disks - 1) |
| 4863 | return 1; |
| 4864 | break; |
| 4865 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 4866 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 4867 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 4868 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 4869 | if (raid_disk == raid_disks - 1) |
| 4870 | return 1; |
| 4871 | } |
| 4872 | return 0; |
| 4873 | } |
| 4874 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4875 | static int run(mddev_t *mddev) |
| 4876 | { |
| 4877 | raid5_conf_t *conf; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 4878 | int working_disks = 0, chunk_size; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4879 | int dirty_parity_disks = 0; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4880 | mdk_rdev_t *rdev; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4881 | sector_t reshape_offset = 0; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4882 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4883 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4884 | printk(KERN_NOTICE "md/raid:%s: not clean" |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4885 | " -- starting background reconstruction\n", |
| 4886 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4887 | if (mddev->reshape_position != MaxSector) { |
| 4888 | /* Check that we can continue the reshape. |
| 4889 | * Currently only disks can change, it must |
| 4890 | * increase, and we must be past the point where |
| 4891 | * a stripe over-writes itself |
| 4892 | */ |
| 4893 | sector_t here_new, here_old; |
| 4894 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 4895 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4896 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 4897 | if (mddev->new_level != mddev->level) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4898 | printk(KERN_ERR "md/raid:%s: unsupported reshape " |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4899 | "required - aborting.\n", |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4900 | mdname(mddev)); |
| 4901 | return -EINVAL; |
| 4902 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4903 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 4904 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4905 | * further up in new geometry must map after here in old |
| 4906 | * geometry. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4907 | */ |
| 4908 | here_new = mddev->reshape_position; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4909 | if (sector_div(here_new, mddev->new_chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4910 | (mddev->raid_disks - max_degraded))) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4911 | printk(KERN_ERR "md/raid:%s: reshape_position not " |
| 4912 | "on a stripe boundary\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4913 | return -EINVAL; |
| 4914 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4915 | reshape_offset = here_new * mddev->new_chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4916 | /* here_new is the stripe we will write to */ |
| 4917 | here_old = mddev->reshape_position; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4918 | sector_div(here_old, mddev->chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4919 | (old_disks-max_degraded)); |
| 4920 | /* here_old is the first stripe that we might need to read |
| 4921 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 4922 | if (mddev->delta_disks == 0) { |
| 4923 | /* We cannot be sure it is safe to start an in-place |
| 4924 | * reshape. It is only safe if user-space if monitoring |
| 4925 | * and taking constant backups. |
| 4926 | * mdadm always starts a situation like this in |
| 4927 | * readonly mode so it can take control before |
| 4928 | * allowing any writes. So just check for that. |
| 4929 | */ |
| 4930 | if ((here_new * mddev->new_chunk_sectors != |
| 4931 | here_old * mddev->chunk_sectors) || |
| 4932 | mddev->ro == 0) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4933 | printk(KERN_ERR "md/raid:%s: in-place reshape must be started" |
| 4934 | " in read-only mode - aborting\n", |
| 4935 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 4936 | return -EINVAL; |
| 4937 | } |
| 4938 | } else if (mddev->delta_disks < 0 |
| 4939 | ? (here_new * mddev->new_chunk_sectors <= |
| 4940 | here_old * mddev->chunk_sectors) |
| 4941 | : (here_new * mddev->new_chunk_sectors >= |
| 4942 | here_old * mddev->chunk_sectors)) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4943 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4944 | printk(KERN_ERR "md/raid:%s: reshape_position too early for " |
| 4945 | "auto-recovery - aborting.\n", |
| 4946 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4947 | return -EINVAL; |
| 4948 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 4949 | printk(KERN_INFO "md/raid:%s: reshape will continue\n", |
| 4950 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4951 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4952 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4953 | BUG_ON(mddev->level != mddev->new_level); |
| 4954 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4955 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4956 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4957 | } |
| 4958 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4959 | if (mddev->private == NULL) |
| 4960 | conf = setup_conf(mddev); |
| 4961 | else |
| 4962 | conf = mddev->private; |
| 4963 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4964 | if (IS_ERR(conf)) |
| 4965 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 4966 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4967 | mddev->thread = conf->thread; |
| 4968 | conf->thread = NULL; |
| 4969 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4972 | * 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] | 4973 | */ |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4974 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 4975 | if (rdev->raid_disk < 0) |
| 4976 | continue; |
| 4977 | if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4978 | working_disks++; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4979 | /* This disc is not fully in-sync. However if it |
| 4980 | * just stored parity (beyond the recovery_offset), |
| 4981 | * when we don't need to be concerned about the |
| 4982 | * array being dirty. |
| 4983 | * When reshape goes 'backwards', we never have |
| 4984 | * partially completed devices, so we only need |
| 4985 | * to worry about reshape going forwards. |
| 4986 | */ |
| 4987 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 4988 | if (mddev->major_version == 0 && |
| 4989 | mddev->minor_version > 90) |
| 4990 | rdev->recovery_offset = reshape_offset; |
| 4991 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4992 | if (rdev->recovery_offset < reshape_offset) { |
| 4993 | /* We need to check old and new layout */ |
| 4994 | if (!only_parity(rdev->raid_disk, |
| 4995 | conf->algorithm, |
| 4996 | conf->raid_disks, |
| 4997 | conf->max_degraded)) |
| 4998 | continue; |
| 4999 | } |
| 5000 | if (!only_parity(rdev->raid_disk, |
| 5001 | conf->prev_algo, |
| 5002 | conf->previous_raid_disks, |
| 5003 | conf->max_degraded)) |
| 5004 | continue; |
| 5005 | dirty_parity_disks++; |
| 5006 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5007 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5008 | mddev->degraded = (max(conf->raid_disks, conf->previous_raid_disks) |
| 5009 | - working_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5011 | if (mddev->degraded > conf->max_degraded) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5012 | printk(KERN_ERR "md/raid:%s: not enough operational devices" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | " (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5014 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | goto abort; |
| 5016 | } |
| 5017 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5018 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5019 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5020 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 5021 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5022 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5024 | if (mddev->ok_start_degraded) |
| 5025 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5026 | "md/raid:%s: starting dirty degraded array" |
| 5027 | " - data corruption possible.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5028 | mdname(mddev)); |
| 5029 | else { |
| 5030 | printk(KERN_ERR |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5031 | "md/raid:%s: cannot start dirty degraded array.\n", |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5032 | mdname(mddev)); |
| 5033 | goto abort; |
| 5034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | } |
| 5036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | if (mddev->degraded == 0) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5038 | printk(KERN_INFO "md/raid:%s: raid level %d active with %d out of %d" |
| 5039 | " devices, algorithm %d\n", mdname(mddev), conf->level, |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5040 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 5041 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | else |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5043 | printk(KERN_ALERT "md/raid:%s: raid level %d active with %d" |
| 5044 | " out of %d devices, algorithm %d\n", |
| 5045 | mdname(mddev), conf->level, |
| 5046 | mddev->raid_disks - mddev->degraded, |
| 5047 | mddev->raid_disks, mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | |
| 5049 | print_raid5_conf(conf); |
| 5050 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5051 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5052 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5053 | atomic_set(&conf->reshape_stripes, 0); |
| 5054 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5055 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5056 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5057 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5058 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5059 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5060 | } |
| 5061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | /* read-ahead size must cover two whole stripes, which is |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5063 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | */ |
| 5065 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5066 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 5067 | int stripe = data_disks * |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5068 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5070 | mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 5071 | } |
| 5072 | |
| 5073 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5074 | if (mddev->to_remove == &raid5_attrs_group) |
| 5075 | mddev->to_remove = NULL; |
| 5076 | else if (sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5077 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5078 | "md/raid:%s: failed to create sysfs attributes.\n", |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5079 | mdname(mddev)); |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 5080 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5081 | mddev->queue->queue_lock = &conf->device_lock; |
| 5082 | |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 5083 | mddev->queue->unplug_fn = raid5_unplug_device; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5084 | mddev->queue->backing_dev_info.congested_data = mddev; |
NeilBrown | 041ae52 | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5085 | mddev->queue->backing_dev_info.congested_fn = raid5_congested; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5086 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5087 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 5088 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 5089 | blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 5090 | chunk_size = mddev->chunk_sectors << 9; |
| 5091 | blk_queue_io_min(mddev->queue, chunk_size); |
| 5092 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 5093 | (conf->raid_disks - conf->max_degraded)); |
| 5094 | |
| 5095 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 5096 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5097 | rdev->data_offset << 9); |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 5098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | return 0; |
| 5100 | abort: |
NeilBrown | e0cf8f0 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5101 | md_unregister_thread(mddev->thread); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5102 | mddev->thread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | if (conf) { |
| 5104 | print_raid5_conf(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5105 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | } |
| 5107 | mddev->private = NULL; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5108 | 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] | 5109 | return -EIO; |
| 5110 | } |
| 5111 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5112 | static int stop(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | { |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 5114 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | |
| 5116 | md_unregister_thread(mddev->thread); |
| 5117 | mddev->thread = NULL; |
NeilBrown | 041ae52 | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5118 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5120 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 5121 | mddev->private = NULL; |
| 5122 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | return 0; |
| 5124 | } |
| 5125 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5126 | #ifdef DEBUG |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5127 | static void print_sh(struct seq_file *seq, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | { |
| 5129 | int i; |
| 5130 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5131 | seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n", |
| 5132 | (unsigned long long)sh->sector, sh->pd_idx, sh->state); |
| 5133 | seq_printf(seq, "sh %llu, count %d.\n", |
| 5134 | (unsigned long long)sh->sector, atomic_read(&sh->count)); |
| 5135 | seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5136 | for (i = 0; i < sh->disks; i++) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5137 | seq_printf(seq, "(cache%d: %p %ld) ", |
| 5138 | i, sh->dev[i].page, sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5140 | seq_printf(seq, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5143 | static void printall(struct seq_file *seq, raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | { |
| 5145 | struct stripe_head *sh; |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 5146 | struct hlist_node *hn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | int i; |
| 5148 | |
| 5149 | spin_lock_irq(&conf->device_lock); |
| 5150 | for (i = 0; i < NR_HASH; i++) { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 5151 | hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | if (sh->raid_conf != conf) |
| 5153 | continue; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5154 | print_sh(seq, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | } |
| 5156 | } |
| 5157 | spin_unlock_irq(&conf->device_lock); |
| 5158 | } |
| 5159 | #endif |
| 5160 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5161 | static void status(struct seq_file *seq, mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | { |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 5163 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | int i; |
| 5165 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5166 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
| 5167 | mddev->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5168 | 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] | 5169 | for (i = 0; i < conf->raid_disks; i++) |
| 5170 | seq_printf (seq, "%s", |
| 5171 | conf->disks[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5172 | test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | seq_printf (seq, "]"); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5174 | #ifdef DEBUG |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5175 | seq_printf (seq, "\n"); |
| 5176 | printall(seq, conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | #endif |
| 5178 | } |
| 5179 | |
| 5180 | static void print_raid5_conf (raid5_conf_t *conf) |
| 5181 | { |
| 5182 | int i; |
| 5183 | struct disk_info *tmp; |
| 5184 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5185 | printk(KERN_DEBUG "RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 | if (!conf) { |
| 5187 | printk("(conf==NULL)\n"); |
| 5188 | return; |
| 5189 | } |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5190 | printk(KERN_DEBUG " --- level:%d rd:%d wd:%d\n", conf->level, |
| 5191 | conf->raid_disks, |
| 5192 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | |
| 5194 | for (i = 0; i < conf->raid_disks; i++) { |
| 5195 | char b[BDEVNAME_SIZE]; |
| 5196 | tmp = conf->disks + i; |
| 5197 | if (tmp->rdev) |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5198 | printk(KERN_DEBUG " disk %d, o:%d, dev:%s\n", |
| 5199 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 5200 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
| 5204 | static int raid5_spare_active(mddev_t *mddev) |
| 5205 | { |
| 5206 | int i; |
| 5207 | raid5_conf_t *conf = mddev->private; |
| 5208 | struct disk_info *tmp; |
| 5209 | |
| 5210 | for (i = 0; i < conf->raid_disks; i++) { |
| 5211 | tmp = conf->disks + i; |
| 5212 | if (tmp->rdev |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5213 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5214 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
| 5215 | unsigned long flags; |
| 5216 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | mddev->degraded--; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5218 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | } |
| 5220 | } |
| 5221 | print_raid5_conf(conf); |
| 5222 | return 0; |
| 5223 | } |
| 5224 | |
| 5225 | static int raid5_remove_disk(mddev_t *mddev, int number) |
| 5226 | { |
| 5227 | raid5_conf_t *conf = mddev->private; |
| 5228 | int err = 0; |
| 5229 | mdk_rdev_t *rdev; |
| 5230 | struct disk_info *p = conf->disks + number; |
| 5231 | |
| 5232 | print_raid5_conf(conf); |
| 5233 | rdev = p->rdev; |
| 5234 | if (rdev) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5235 | if (number >= conf->raid_disks && |
| 5236 | conf->reshape_progress == MaxSector) |
| 5237 | clear_bit(In_sync, &rdev->flags); |
| 5238 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5239 | if (test_bit(In_sync, &rdev->flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | atomic_read(&rdev->nr_pending)) { |
| 5241 | err = -EBUSY; |
| 5242 | goto abort; |
| 5243 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5244 | /* Only remove non-faulty devices if recovery |
| 5245 | * isn't possible. |
| 5246 | */ |
| 5247 | if (!test_bit(Faulty, &rdev->flags) && |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5248 | mddev->degraded <= conf->max_degraded && |
| 5249 | number < conf->raid_disks) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5250 | err = -EBUSY; |
| 5251 | goto abort; |
| 5252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5253 | p->rdev = NULL; |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 5254 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5255 | if (atomic_read(&rdev->nr_pending)) { |
| 5256 | /* lost the race, try later */ |
| 5257 | err = -EBUSY; |
| 5258 | p->rdev = rdev; |
| 5259 | } |
| 5260 | } |
| 5261 | abort: |
| 5262 | |
| 5263 | print_raid5_conf(conf); |
| 5264 | return err; |
| 5265 | } |
| 5266 | |
| 5267 | static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) |
| 5268 | { |
| 5269 | raid5_conf_t *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5270 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5271 | int disk; |
| 5272 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5273 | int first = 0; |
| 5274 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5276 | if (mddev->degraded > conf->max_degraded) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5278 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5280 | if (rdev->raid_disk >= 0) |
| 5281 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5282 | |
| 5283 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5284 | * find the disk ... but prefer rdev->saved_raid_disk |
| 5285 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5287 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5288 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5289 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
| 5290 | disk = rdev->saved_raid_disk; |
| 5291 | else |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5292 | disk = first; |
| 5293 | for ( ; disk <= last ; disk++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | if ((p=conf->disks + disk)->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5295 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5297 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5298 | if (rdev->saved_raid_disk != disk) |
| 5299 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 5300 | rcu_assign_pointer(p->rdev, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | break; |
| 5302 | } |
| 5303 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5304 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | static int raid5_resize(mddev_t *mddev, sector_t sectors) |
| 5308 | { |
| 5309 | /* no resync is happening, and there is enough space |
| 5310 | * on all devices, so we can resize. |
| 5311 | * We need to make sure resync covers any new space. |
| 5312 | * If the array is shrinking we should possibly wait until |
| 5313 | * any io in the removed space completes, but it hardly seems |
| 5314 | * worth it. |
| 5315 | */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5316 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5317 | md_set_array_sectors(mddev, raid5_size(mddev, sectors, |
| 5318 | mddev->raid_disks)); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5319 | if (mddev->array_sectors > |
| 5320 | raid5_size(mddev, sectors, mddev->raid_disks)) |
| 5321 | return -EINVAL; |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 5322 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5323 | revalidate_disk(mddev->gendisk); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5324 | if (sectors > mddev->dev_sectors && mddev->recovery_cp == MaxSector) { |
| 5325 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5327 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5328 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 5329 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | return 0; |
| 5331 | } |
| 5332 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5333 | static int check_stripe_cache(mddev_t *mddev) |
| 5334 | { |
| 5335 | /* Can only proceed if there are plenty of stripe_heads. |
| 5336 | * We need a minimum of one full stripe,, and for sensible progress |
| 5337 | * it is best to have about 4 times that. |
| 5338 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 5339 | * allow for chunk sizes up to 256K, which is probably OK. |
| 5340 | * If the chunk size is greater, user-space should request more |
| 5341 | * stripe_heads first. |
| 5342 | */ |
| 5343 | raid5_conf_t *conf = mddev->private; |
| 5344 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5345 | > conf->max_nr_stripes || |
| 5346 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5347 | > conf->max_nr_stripes) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5348 | printk(KERN_WARNING "md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 5349 | mdname(mddev), |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5350 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 5351 | / STRIPE_SIZE)*4); |
| 5352 | return 0; |
| 5353 | } |
| 5354 | return 1; |
| 5355 | } |
| 5356 | |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5357 | static int check_reshape(mddev_t *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5358 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5359 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5360 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5361 | if (mddev->delta_disks == 0 && |
| 5362 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5363 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5364 | return 0; /* nothing to do */ |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5365 | if (mddev->bitmap) |
| 5366 | /* Cannot grow a bitmap yet */ |
| 5367 | return -EBUSY; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5368 | if (mddev->degraded > conf->max_degraded) |
| 5369 | return -EINVAL; |
| 5370 | if (mddev->delta_disks < 0) { |
| 5371 | /* We might be able to shrink, but the devices must |
| 5372 | * be made bigger first. |
| 5373 | * For raid6, 4 is the minimum size. |
| 5374 | * Otherwise 2 is the minimum |
| 5375 | */ |
| 5376 | int min = 2; |
| 5377 | if (mddev->level == 6) |
| 5378 | min = 4; |
| 5379 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 5380 | return -EINVAL; |
| 5381 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5382 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5383 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5384 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5385 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5386 | return resize_stripes(conf, conf->raid_disks + mddev->delta_disks); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | static int raid5_start_reshape(mddev_t *mddev) |
| 5390 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5391 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5392 | mdk_rdev_t *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5393 | int spares = 0; |
| 5394 | int added_devices = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5395 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5396 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5397 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5398 | return -EBUSY; |
| 5399 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5400 | if (!check_stripe_cache(mddev)) |
| 5401 | return -ENOSPC; |
| 5402 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5403 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5404 | if (rdev->raid_disk < 0 && |
| 5405 | !test_bit(Faulty, &rdev->flags)) |
| 5406 | spares++; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5407 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5408 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5409 | /* Not enough devices even to make a degraded array |
| 5410 | * of that size |
| 5411 | */ |
| 5412 | return -EINVAL; |
| 5413 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5414 | /* Refuse to reduce size of the array. Any reductions in |
| 5415 | * array size must be through explicit setting of array_size |
| 5416 | * attribute. |
| 5417 | */ |
| 5418 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 5419 | < mddev->array_sectors) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5420 | printk(KERN_ERR "md/raid:%s: array size must be reduced " |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5421 | "before number of disks\n", mdname(mddev)); |
| 5422 | return -EINVAL; |
| 5423 | } |
| 5424 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5425 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5426 | spin_lock_irq(&conf->device_lock); |
| 5427 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5428 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5429 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 5430 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5431 | conf->prev_algo = conf->algorithm; |
| 5432 | conf->algorithm = mddev->new_layout; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5433 | if (mddev->delta_disks < 0) |
| 5434 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 5435 | else |
| 5436 | conf->reshape_progress = 0; |
| 5437 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 5438 | conf->generation++; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5439 | spin_unlock_irq(&conf->device_lock); |
| 5440 | |
| 5441 | /* Add some new drives, as many as will fit. |
| 5442 | * We know there are enough to make the newly sized array work. |
| 5443 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5444 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5445 | if (rdev->raid_disk < 0 && |
| 5446 | !test_bit(Faulty, &rdev->flags)) { |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5447 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5448 | char nm[20]; |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5449 | if (rdev->raid_disk >= conf->previous_raid_disks) { |
NeilBrown | 7ef9014 | 2009-11-13 17:40:51 +1100 | [diff] [blame] | 5450 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5451 | added_devices++; |
| 5452 | } else |
NeilBrown | 7ef9014 | 2009-11-13 17:40:51 +1100 | [diff] [blame] | 5453 | rdev->recovery_offset = 0; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5454 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5455 | if (sysfs_create_link(&mddev->kobj, |
| 5456 | &rdev->kobj, nm)) |
| 5457 | printk(KERN_WARNING |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5458 | "md/raid:%s: failed to create " |
| 5459 | " link %s\n", |
| 5460 | mdname(mddev), nm); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5461 | } else |
| 5462 | break; |
| 5463 | } |
| 5464 | |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5465 | /* When a reshape changes the number of devices, ->degraded |
| 5466 | * is measured against the large of the pre and post number of |
| 5467 | * devices.*/ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5468 | if (mddev->delta_disks > 0) { |
| 5469 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5470 | mddev->degraded += (conf->raid_disks - conf->previous_raid_disks) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5471 | - added_devices; |
| 5472 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 5473 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5474 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 5475 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5476 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5477 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5478 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5479 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5480 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5481 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5482 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5483 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5484 | if (!mddev->sync_thread) { |
| 5485 | mddev->recovery = 0; |
| 5486 | spin_lock_irq(&conf->device_lock); |
| 5487 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5488 | conf->reshape_progress = MaxSector; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5489 | spin_unlock_irq(&conf->device_lock); |
| 5490 | return -EAGAIN; |
| 5491 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5492 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5493 | md_wakeup_thread(mddev->sync_thread); |
| 5494 | md_new_event(mddev); |
| 5495 | return 0; |
| 5496 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5497 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5498 | /* This is called from the reshape thread and should make any |
| 5499 | * changes needed in 'conf' |
| 5500 | */ |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5501 | static void end_reshape(raid5_conf_t *conf) |
| 5502 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5503 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5504 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5505 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5506 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5507 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5508 | conf->reshape_progress = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5509 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5510 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5511 | |
| 5512 | /* read-ahead size must cover two whole stripes, which is |
| 5513 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 5514 | */ |
| 5515 | { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5516 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5517 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5518 | / PAGE_SIZE); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5519 | if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5520 | conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 5521 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5522 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5523 | } |
| 5524 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5525 | /* This is called from the raid5d thread with mddev_lock held. |
| 5526 | * It makes config changes to the device. |
| 5527 | */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5528 | static void raid5_finish_reshape(mddev_t *mddev) |
| 5529 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5530 | raid5_conf_t *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5531 | |
| 5532 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5533 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5534 | if (mddev->delta_disks > 0) { |
| 5535 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5536 | set_capacity(mddev->gendisk, mddev->array_sectors); |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5537 | revalidate_disk(mddev->gendisk); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5538 | } else { |
| 5539 | int d; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5540 | mddev->degraded = conf->raid_disks; |
| 5541 | for (d = 0; d < conf->raid_disks ; d++) |
| 5542 | if (conf->disks[d].rdev && |
| 5543 | test_bit(In_sync, |
| 5544 | &conf->disks[d].rdev->flags)) |
| 5545 | mddev->degraded--; |
| 5546 | for (d = conf->raid_disks ; |
| 5547 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5548 | d++) { |
| 5549 | mdk_rdev_t *rdev = conf->disks[d].rdev; |
| 5550 | if (rdev && raid5_remove_disk(mddev, d) == 0) { |
| 5551 | char nm[20]; |
| 5552 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 5553 | sysfs_remove_link(&mddev->kobj, nm); |
| 5554 | rdev->raid_disk = -1; |
| 5555 | } |
| 5556 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5557 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5558 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5559 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5560 | mddev->reshape_position = MaxSector; |
| 5561 | mddev->delta_disks = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5562 | } |
| 5563 | } |
| 5564 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5565 | static void raid5_quiesce(mddev_t *mddev, int state) |
| 5566 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5567 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5568 | |
| 5569 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5570 | case 2: /* resume for a suspend */ |
| 5571 | wake_up(&conf->wait_for_overlap); |
| 5572 | break; |
| 5573 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5574 | case 1: /* stop all writes */ |
| 5575 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5576 | /* '2' tells resync/reshape to pause so that all |
| 5577 | * active stripes can drain |
| 5578 | */ |
| 5579 | conf->quiesce = 2; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5580 | wait_event_lock_irq(conf->wait_for_stripe, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5581 | atomic_read(&conf->active_stripes) == 0 && |
| 5582 | atomic_read(&conf->active_aligned_reads) == 0, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5583 | conf->device_lock, /* nothing */); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5584 | conf->quiesce = 1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5585 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5586 | /* allow reshape to continue */ |
| 5587 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5588 | break; |
| 5589 | |
| 5590 | case 0: /* re-enable writes */ |
| 5591 | spin_lock_irq(&conf->device_lock); |
| 5592 | conf->quiesce = 0; |
| 5593 | wake_up(&conf->wait_for_stripe); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5594 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5595 | spin_unlock_irq(&conf->device_lock); |
| 5596 | break; |
| 5597 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5598 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 5599 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5600 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5601 | static void *raid45_takeover_raid0(mddev_t *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5602 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5603 | struct raid0_private_data *raid0_priv = mddev->private; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5604 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5605 | /* for raid0 takeover only one zone is supported */ |
| 5606 | if (raid0_priv->nr_strip_zones > 1) { |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 5607 | printk(KERN_ERR "md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 5608 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5609 | return ERR_PTR(-EINVAL); |
| 5610 | } |
| 5611 | |
| 5612 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 5613 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5614 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 5615 | mddev->raid_disks += 1; |
| 5616 | mddev->delta_disks = 1; |
| 5617 | /* make sure it will be not marked as dirty */ |
| 5618 | mddev->recovery_cp = MaxSector; |
| 5619 | |
| 5620 | return setup_conf(mddev); |
| 5621 | } |
| 5622 | |
| 5623 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5624 | static void *raid5_takeover_raid1(mddev_t *mddev) |
| 5625 | { |
| 5626 | int chunksect; |
| 5627 | |
| 5628 | if (mddev->raid_disks != 2 || |
| 5629 | mddev->degraded > 1) |
| 5630 | return ERR_PTR(-EINVAL); |
| 5631 | |
| 5632 | /* Should check if there are write-behind devices? */ |
| 5633 | |
| 5634 | chunksect = 64*2; /* 64K by default */ |
| 5635 | |
| 5636 | /* The array must be an exact multiple of chunksize */ |
| 5637 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 5638 | chunksect >>= 1; |
| 5639 | |
| 5640 | if ((chunksect<<9) < STRIPE_SIZE) |
| 5641 | /* array size does not allow a suitable chunk size */ |
| 5642 | return ERR_PTR(-EINVAL); |
| 5643 | |
| 5644 | mddev->new_level = 5; |
| 5645 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5646 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5647 | |
| 5648 | return setup_conf(mddev); |
| 5649 | } |
| 5650 | |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5651 | static void *raid5_takeover_raid6(mddev_t *mddev) |
| 5652 | { |
| 5653 | int new_layout; |
| 5654 | |
| 5655 | switch (mddev->layout) { |
| 5656 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 5657 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 5658 | break; |
| 5659 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 5660 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 5661 | break; |
| 5662 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 5663 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 5664 | break; |
| 5665 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 5666 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 5667 | break; |
| 5668 | case ALGORITHM_PARITY_0_6: |
| 5669 | new_layout = ALGORITHM_PARITY_0; |
| 5670 | break; |
| 5671 | case ALGORITHM_PARITY_N: |
| 5672 | new_layout = ALGORITHM_PARITY_N; |
| 5673 | break; |
| 5674 | default: |
| 5675 | return ERR_PTR(-EINVAL); |
| 5676 | } |
| 5677 | mddev->new_level = 5; |
| 5678 | mddev->new_layout = new_layout; |
| 5679 | mddev->delta_disks = -1; |
| 5680 | mddev->raid_disks -= 1; |
| 5681 | return setup_conf(mddev); |
| 5682 | } |
| 5683 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5684 | |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5685 | static int raid5_check_reshape(mddev_t *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5686 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5687 | /* For a 2-drive array, the layout and chunk size can be changed |
| 5688 | * immediately as not restriping is needed. |
| 5689 | * For larger arrays we record the new value - after validation |
| 5690 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5691 | */ |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5692 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5693 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5694 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5695 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5696 | return -EINVAL; |
| 5697 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5698 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5699 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5700 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5701 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5702 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5703 | /* not factor of array size */ |
| 5704 | return -EINVAL; |
| 5705 | } |
| 5706 | |
| 5707 | /* They look valid */ |
| 5708 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5709 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5710 | /* can make the change immediately */ |
| 5711 | if (mddev->new_layout >= 0) { |
| 5712 | conf->algorithm = mddev->new_layout; |
| 5713 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5714 | } |
| 5715 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5716 | conf->chunk_sectors = new_chunk ; |
| 5717 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5718 | } |
| 5719 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 5720 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5721 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5722 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5723 | } |
| 5724 | |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5725 | static int raid6_check_reshape(mddev_t *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5726 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5727 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5728 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5729 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5730 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5731 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5732 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5733 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5734 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5735 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5736 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5737 | /* not factor of array size */ |
| 5738 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5739 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5740 | |
| 5741 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5742 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5743 | } |
| 5744 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5745 | static void *raid5_takeover(mddev_t *mddev) |
| 5746 | { |
| 5747 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5748 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5749 | * raid1 - if there are two drives. We need to know the chunk size |
| 5750 | * raid4 - trivial - just use a raid4 layout. |
| 5751 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5752 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5753 | if (mddev->level == 0) |
| 5754 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5755 | if (mddev->level == 1) |
| 5756 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 5757 | if (mddev->level == 4) { |
| 5758 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5759 | mddev->new_level = 5; |
| 5760 | return setup_conf(mddev); |
| 5761 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5762 | if (mddev->level == 6) |
| 5763 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5764 | |
| 5765 | return ERR_PTR(-EINVAL); |
| 5766 | } |
| 5767 | |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5768 | static void *raid4_takeover(mddev_t *mddev) |
| 5769 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5770 | /* raid4 can take over: |
| 5771 | * raid0 - if there is only one strip zone |
| 5772 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5773 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 5774 | if (mddev->level == 0) |
| 5775 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5776 | if (mddev->level == 5 && |
| 5777 | mddev->layout == ALGORITHM_PARITY_N) { |
| 5778 | mddev->new_layout = 0; |
| 5779 | mddev->new_level = 4; |
| 5780 | return setup_conf(mddev); |
| 5781 | } |
| 5782 | return ERR_PTR(-EINVAL); |
| 5783 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5784 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5785 | static struct mdk_personality raid5_personality; |
| 5786 | |
| 5787 | static void *raid6_takeover(mddev_t *mddev) |
| 5788 | { |
| 5789 | /* Currently can only take over a raid5. We map the |
| 5790 | * personality to an equivalent raid6 personality |
| 5791 | * with the Q block at the end. |
| 5792 | */ |
| 5793 | int new_layout; |
| 5794 | |
| 5795 | if (mddev->pers != &raid5_personality) |
| 5796 | return ERR_PTR(-EINVAL); |
| 5797 | if (mddev->degraded > 1) |
| 5798 | return ERR_PTR(-EINVAL); |
| 5799 | if (mddev->raid_disks > 253) |
| 5800 | return ERR_PTR(-EINVAL); |
| 5801 | if (mddev->raid_disks < 3) |
| 5802 | return ERR_PTR(-EINVAL); |
| 5803 | |
| 5804 | switch (mddev->layout) { |
| 5805 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 5806 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 5807 | break; |
| 5808 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 5809 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 5810 | break; |
| 5811 | case ALGORITHM_LEFT_SYMMETRIC: |
| 5812 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 5813 | break; |
| 5814 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 5815 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 5816 | break; |
| 5817 | case ALGORITHM_PARITY_0: |
| 5818 | new_layout = ALGORITHM_PARITY_0_6; |
| 5819 | break; |
| 5820 | case ALGORITHM_PARITY_N: |
| 5821 | new_layout = ALGORITHM_PARITY_N; |
| 5822 | break; |
| 5823 | default: |
| 5824 | return ERR_PTR(-EINVAL); |
| 5825 | } |
| 5826 | mddev->new_level = 6; |
| 5827 | mddev->new_layout = new_layout; |
| 5828 | mddev->delta_disks = 1; |
| 5829 | mddev->raid_disks += 1; |
| 5830 | return setup_conf(mddev); |
| 5831 | } |
| 5832 | |
| 5833 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5834 | static struct mdk_personality raid6_personality = |
| 5835 | { |
| 5836 | .name = "raid6", |
| 5837 | .level = 6, |
| 5838 | .owner = THIS_MODULE, |
| 5839 | .make_request = make_request, |
| 5840 | .run = run, |
| 5841 | .stop = stop, |
| 5842 | .status = status, |
| 5843 | .error_handler = error, |
| 5844 | .hot_add_disk = raid5_add_disk, |
| 5845 | .hot_remove_disk= raid5_remove_disk, |
| 5846 | .spare_active = raid5_spare_active, |
| 5847 | .sync_request = sync_request, |
| 5848 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5849 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5850 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5851 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5852 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5853 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5854 | .takeover = raid6_takeover, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5855 | }; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5856 | static struct mdk_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | { |
| 5858 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5859 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5860 | .owner = THIS_MODULE, |
| 5861 | .make_request = make_request, |
| 5862 | .run = run, |
| 5863 | .stop = stop, |
| 5864 | .status = status, |
| 5865 | .error_handler = error, |
| 5866 | .hot_add_disk = raid5_add_disk, |
| 5867 | .hot_remove_disk= raid5_remove_disk, |
| 5868 | .spare_active = raid5_spare_active, |
| 5869 | .sync_request = sync_request, |
| 5870 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5871 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5872 | .check_reshape = raid5_check_reshape, |
| 5873 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5874 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5875 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5876 | .takeover = raid5_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | }; |
| 5878 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5879 | static struct mdk_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5881 | .name = "raid4", |
| 5882 | .level = 4, |
| 5883 | .owner = THIS_MODULE, |
| 5884 | .make_request = make_request, |
| 5885 | .run = run, |
| 5886 | .stop = stop, |
| 5887 | .status = status, |
| 5888 | .error_handler = error, |
| 5889 | .hot_add_disk = raid5_add_disk, |
| 5890 | .hot_remove_disk= raid5_remove_disk, |
| 5891 | .spare_active = raid5_spare_active, |
| 5892 | .sync_request = sync_request, |
| 5893 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5894 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 5895 | .check_reshape = raid5_check_reshape, |
| 5896 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5897 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5898 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 5899 | .takeover = raid4_takeover, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5900 | }; |
| 5901 | |
| 5902 | static int __init raid5_init(void) |
| 5903 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5904 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5905 | register_md_personality(&raid5_personality); |
| 5906 | register_md_personality(&raid4_personality); |
| 5907 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5910 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5912 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5913 | unregister_md_personality(&raid5_personality); |
| 5914 | unregister_md_personality(&raid4_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5915 | } |
| 5916 | |
| 5917 | module_init(raid5_init); |
| 5918 | module_exit(raid5_exit); |
| 5919 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 5920 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5921 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 5922 | MODULE_ALIAS("md-raid5"); |
| 5923 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5924 | MODULE_ALIAS("md-level-5"); |
| 5925 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5926 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 5927 | MODULE_ALIAS("md-raid6"); |
| 5928 | MODULE_ALIAS("md-level-6"); |
| 5929 | |
| 5930 | /* This used to be two separate modules, they were: */ |
| 5931 | MODULE_ALIAS("raid5"); |
| 5932 | MODULE_ALIAS("raid6"); |