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" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 55 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
| 58 | * Stripe cache |
| 59 | */ |
| 60 | |
| 61 | #define NR_STRIPES 256 |
| 62 | #define STRIPE_SIZE PAGE_SIZE |
| 63 | #define STRIPE_SHIFT (PAGE_SHIFT - 9) |
| 64 | #define STRIPE_SECTORS (STRIPE_SIZE>>9) |
| 65 | #define IO_THRESHOLD 1 |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 66 | #define BYPASS_THRESHOLD 1 |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 67 | #define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #define HASH_MASK (NR_HASH - 1) |
| 69 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 70 | #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] | 71 | |
| 72 | /* bio's attached to a stripe+device for I/O are linked together in bi_sector |
| 73 | * order without overlap. There may be several bio's per stripe+device, and |
| 74 | * a bio could span several devices. |
| 75 | * When walking this list for a particular stripe+device, we must never proceed |
| 76 | * beyond a bio that extends past this device, as the next bio might no longer |
| 77 | * be valid. |
| 78 | * This macro is used to determine the 'next' bio in the list, given the sector |
| 79 | * of the current stripe+device |
| 80 | */ |
| 81 | #define r5_next_bio(bio, sect) ( ( (bio)->bi_sector + ((bio)->bi_size>>9) < sect + STRIPE_SECTORS) ? (bio)->bi_next : NULL) |
| 82 | /* |
| 83 | * The following can be used to debug the driver |
| 84 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #define RAID5_PARANOIA 1 |
| 86 | #if RAID5_PARANOIA && defined(CONFIG_SMP) |
| 87 | # define CHECK_DEVLOCK() assert_spin_locked(&conf->device_lock) |
| 88 | #else |
| 89 | # define CHECK_DEVLOCK() |
| 90 | #endif |
| 91 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 92 | #ifdef DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #define inline |
| 94 | #define __inline__ |
| 95 | #endif |
| 96 | |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 97 | #define printk_rl(args...) ((void) (printk_ratelimit() && printk(args))) |
| 98 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 99 | /* |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 100 | * We maintain a biased count of active stripes in the bottom 16 bits of |
| 101 | * 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] | 102 | */ |
| 103 | static inline int raid5_bi_phys_segments(struct bio *bio) |
| 104 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 105 | return bio->bi_phys_segments & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static inline int raid5_bi_hw_segments(struct bio *bio) |
| 109 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 110 | return (bio->bi_phys_segments >> 16) & 0xffff; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static inline int raid5_dec_bi_phys_segments(struct bio *bio) |
| 114 | { |
| 115 | --bio->bi_phys_segments; |
| 116 | return raid5_bi_phys_segments(bio); |
| 117 | } |
| 118 | |
| 119 | static inline int raid5_dec_bi_hw_segments(struct bio *bio) |
| 120 | { |
| 121 | unsigned short val = raid5_bi_hw_segments(bio); |
| 122 | |
| 123 | --val; |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 124 | bio->bi_phys_segments = (val << 16) | raid5_bi_phys_segments(bio); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 125 | return val; |
| 126 | } |
| 127 | |
| 128 | static inline void raid5_set_bi_hw_segments(struct bio *bio, unsigned int cnt) |
| 129 | { |
Jens Axboe | 5b99c2f | 2008-08-15 10:56:11 +0200 | [diff] [blame] | 130 | bio->bi_phys_segments = raid5_bi_phys_segments(bio) || (cnt << 16); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 131 | } |
| 132 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 133 | /* Find first data disk in a raid6 stripe */ |
| 134 | static inline int raid6_d0(struct stripe_head *sh) |
| 135 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 136 | if (sh->ddf_layout) |
| 137 | /* ddf always start from first device */ |
| 138 | return 0; |
| 139 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 140 | if (sh->qd_idx == sh->disks - 1) |
| 141 | return 0; |
| 142 | else |
| 143 | return sh->qd_idx + 1; |
| 144 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 145 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 146 | { |
| 147 | disk++; |
| 148 | return (disk < raid_disks) ? disk : 0; |
| 149 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 150 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 151 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 152 | * We need to map each disk to a 'slot', where the data disks are slot |
| 153 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 154 | * is raid_disks-1. This help does that mapping. |
| 155 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 156 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 157 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 158 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 159 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 160 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 161 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 162 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 163 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 164 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 165 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 166 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 167 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 168 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 169 | return slot; |
| 170 | } |
| 171 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 172 | static void return_io(struct bio *return_bi) |
| 173 | { |
| 174 | struct bio *bi = return_bi; |
| 175 | while (bi) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 176 | |
| 177 | return_bi = bi->bi_next; |
| 178 | bi->bi_next = NULL; |
| 179 | bi->bi_size = 0; |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 180 | bio_endio(bi, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 181 | bi = return_bi; |
| 182 | } |
| 183 | } |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | static void print_raid5_conf (raid5_conf_t *conf); |
| 186 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 187 | static int stripe_operations_active(struct stripe_head *sh) |
| 188 | { |
| 189 | return sh->check_state || sh->reconstruct_state || |
| 190 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 191 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 192 | } |
| 193 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 194 | static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | if (atomic_dec_and_test(&sh->count)) { |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 197 | BUG_ON(!list_empty(&sh->lru)); |
| 198 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
NeilBrown | 7c785b7 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 200 | if (test_bit(STRIPE_DELAYED, &sh->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | list_add_tail(&sh->lru, &conf->delayed_list); |
NeilBrown | 7c785b7 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 202 | blk_plug_device(conf->mddev->queue); |
| 203 | } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 204 | sh->bm_seq - conf->seq_write > 0) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 205 | list_add_tail(&sh->lru, &conf->bitmap_list); |
NeilBrown | 7c785b7 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 206 | blk_plug_device(conf->mddev->queue); |
| 207 | } else { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 208 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | list_add_tail(&sh->lru, &conf->handle_list); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | md_wakeup_thread(conf->mddev->thread); |
| 212 | } else { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 213 | BUG_ON(stripe_operations_active(sh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
| 215 | atomic_dec(&conf->preread_active_stripes); |
| 216 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) |
| 217 | md_wakeup_thread(conf->mddev->thread); |
| 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | atomic_dec(&conf->active_stripes); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 220 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 221 | list_add_tail(&sh->lru, &conf->inactive_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | wake_up(&conf->wait_for_stripe); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 223 | if (conf->retry_read_aligned) |
| 224 | md_wakeup_thread(conf->mddev->thread); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | static void release_stripe(struct stripe_head *sh) |
| 231 | { |
| 232 | raid5_conf_t *conf = sh->raid_conf; |
| 233 | unsigned long flags; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | spin_lock_irqsave(&conf->device_lock, flags); |
| 236 | __release_stripe(conf, sh); |
| 237 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 238 | } |
| 239 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 240 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 242 | pr_debug("remove_hash(), stripe %llu\n", |
| 243 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 245 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 248 | 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] | 249 | { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 250 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 252 | pr_debug("insert_hash(), stripe %llu\n", |
| 253 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | CHECK_DEVLOCK(); |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 256 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
| 260 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
| 261 | static struct stripe_head *get_free_stripe(raid5_conf_t *conf) |
| 262 | { |
| 263 | struct stripe_head *sh = NULL; |
| 264 | struct list_head *first; |
| 265 | |
| 266 | CHECK_DEVLOCK(); |
| 267 | if (list_empty(&conf->inactive_list)) |
| 268 | goto out; |
| 269 | first = conf->inactive_list.next; |
| 270 | sh = list_entry(first, struct stripe_head, lru); |
| 271 | list_del_init(first); |
| 272 | remove_hash(sh); |
| 273 | atomic_inc(&conf->active_stripes); |
| 274 | out: |
| 275 | return sh; |
| 276 | } |
| 277 | |
| 278 | static void shrink_buffers(struct stripe_head *sh, int num) |
| 279 | { |
| 280 | struct page *p; |
| 281 | int i; |
| 282 | |
| 283 | for (i=0; i<num ; i++) { |
| 284 | p = sh->dev[i].page; |
| 285 | if (!p) |
| 286 | continue; |
| 287 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 288 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
| 292 | static int grow_buffers(struct stripe_head *sh, int num) |
| 293 | { |
| 294 | int i; |
| 295 | |
| 296 | for (i=0; i<num; i++) { |
| 297 | struct page *page; |
| 298 | |
| 299 | if (!(page = alloc_page(GFP_KERNEL))) { |
| 300 | return 1; |
| 301 | } |
| 302 | sh->dev[i].page = page; |
| 303 | } |
| 304 | return 0; |
| 305 | } |
| 306 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 307 | static void raid5_build_block(struct stripe_head *sh, int i, int previous); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 308 | static void stripe_set_idx(sector_t stripe, raid5_conf_t *conf, int previous, |
| 309 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 311 | 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] | 312 | { |
| 313 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 314 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 316 | BUG_ON(atomic_read(&sh->count) != 0); |
| 317 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 318 | BUG_ON(stripe_operations_active(sh)); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | CHECK_DEVLOCK(); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 321 | pr_debug("init_stripe called, stripe %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | (unsigned long long)sh->sector); |
| 323 | |
| 324 | remove_hash(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 325 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 326 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 327 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 329 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | sh->state = 0; |
| 331 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 332 | |
| 333 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | struct r5dev *dev = &sh->dev[i]; |
| 335 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 336 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | test_bit(R5_LOCKED, &dev->flags)) { |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 338 | 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] | 339 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 340 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | test_bit(R5_LOCKED, &dev->flags)); |
| 342 | BUG(); |
| 343 | } |
| 344 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 345 | raid5_build_block(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | insert_hash(conf, sh); |
| 348 | } |
| 349 | |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 350 | static struct stripe_head *__find_stripe(raid5_conf_t *conf, sector_t sector, |
| 351 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
| 353 | struct stripe_head *sh; |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 354 | struct hlist_node *hn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | CHECK_DEVLOCK(); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 357 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 358 | hlist_for_each_entry(sh, hn, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 359 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 361 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return NULL; |
| 363 | } |
| 364 | |
| 365 | static void unplug_slaves(mddev_t *mddev); |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 366 | static void raid5_unplug_device(struct request_queue *q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 368 | static struct stripe_head * |
| 369 | get_active_stripe(raid5_conf_t *conf, sector_t sector, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 370 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
| 372 | struct stripe_head *sh; |
| 373 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 374 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | spin_lock_irq(&conf->device_lock); |
| 377 | |
| 378 | do { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 379 | wait_event_lock_irq(conf->wait_for_stripe, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 380 | conf->quiesce == 0 || noquiesce, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 381 | conf->device_lock, /* nothing */); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 382 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (!sh) { |
| 384 | if (!conf->inactive_blocked) |
| 385 | sh = get_free_stripe(conf); |
| 386 | if (noblock && sh == NULL) |
| 387 | break; |
| 388 | if (!sh) { |
| 389 | conf->inactive_blocked = 1; |
| 390 | wait_event_lock_irq(conf->wait_for_stripe, |
| 391 | !list_empty(&conf->inactive_list) && |
NeilBrown | 5036805 | 2005-12-12 02:39:17 -0800 | [diff] [blame] | 392 | (atomic_read(&conf->active_stripes) |
| 393 | < (conf->max_nr_stripes *3/4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | || !conf->inactive_blocked), |
| 395 | conf->device_lock, |
NeilBrown | f437078 | 2006-07-10 04:44:14 -0700 | [diff] [blame] | 396 | raid5_unplug_device(conf->mddev->queue) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | ); |
| 398 | conf->inactive_blocked = 0; |
| 399 | } else |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 400 | init_stripe(sh, sector, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } else { |
| 402 | if (atomic_read(&sh->count)) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 403 | BUG_ON(!list_empty(&sh->lru) |
| 404 | && !test_bit(STRIPE_EXPANDING, &sh->state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } else { |
| 406 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 407 | atomic_inc(&conf->active_stripes); |
NeilBrown | ff4e8d9 | 2006-07-10 04:44:16 -0700 | [diff] [blame] | 408 | if (list_empty(&sh->lru) && |
| 409 | !test_bit(STRIPE_EXPANDING, &sh->state)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 410 | BUG(); |
| 411 | list_del_init(&sh->lru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | } while (sh == NULL); |
| 415 | |
| 416 | if (sh) |
| 417 | atomic_inc(&sh->count); |
| 418 | |
| 419 | spin_unlock_irq(&conf->device_lock); |
| 420 | return sh; |
| 421 | } |
| 422 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 423 | static void |
| 424 | raid5_end_read_request(struct bio *bi, int error); |
| 425 | static void |
| 426 | raid5_end_write_request(struct bio *bi, int error); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 427 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 428 | 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] | 429 | { |
| 430 | raid5_conf_t *conf = sh->raid_conf; |
| 431 | int i, disks = sh->disks; |
| 432 | |
| 433 | might_sleep(); |
| 434 | |
| 435 | for (i = disks; i--; ) { |
| 436 | int rw; |
| 437 | struct bio *bi; |
| 438 | mdk_rdev_t *rdev; |
| 439 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) |
| 440 | rw = WRITE; |
| 441 | else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
| 442 | rw = READ; |
| 443 | else |
| 444 | continue; |
| 445 | |
| 446 | bi = &sh->dev[i].req; |
| 447 | |
| 448 | bi->bi_rw = rw; |
| 449 | if (rw == WRITE) |
| 450 | bi->bi_end_io = raid5_end_write_request; |
| 451 | else |
| 452 | bi->bi_end_io = raid5_end_read_request; |
| 453 | |
| 454 | rcu_read_lock(); |
| 455 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 456 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 457 | rdev = NULL; |
| 458 | if (rdev) |
| 459 | atomic_inc(&rdev->nr_pending); |
| 460 | rcu_read_unlock(); |
| 461 | |
| 462 | if (rdev) { |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 463 | if (s->syncing || s->expanding || s->expanded) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 464 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 465 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 466 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 467 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 468 | bi->bi_bdev = rdev->bdev; |
| 469 | pr_debug("%s: for %llu schedule op %ld on disc %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 470 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 471 | bi->bi_rw, i); |
| 472 | atomic_inc(&sh->count); |
| 473 | bi->bi_sector = sh->sector + rdev->data_offset; |
| 474 | bi->bi_flags = 1 << BIO_UPTODATE; |
| 475 | bi->bi_vcnt = 1; |
| 476 | bi->bi_max_vecs = 1; |
| 477 | bi->bi_idx = 0; |
| 478 | bi->bi_io_vec = &sh->dev[i].vec; |
| 479 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 480 | bi->bi_io_vec[0].bv_offset = 0; |
| 481 | bi->bi_size = STRIPE_SIZE; |
| 482 | bi->bi_next = NULL; |
| 483 | if (rw == WRITE && |
| 484 | test_bit(R5_ReWrite, &sh->dev[i].flags)) |
| 485 | atomic_add(STRIPE_SECTORS, |
| 486 | &rdev->corrected_errors); |
| 487 | generic_make_request(bi); |
| 488 | } else { |
| 489 | if (rw == WRITE) |
| 490 | set_bit(STRIPE_DEGRADED, &sh->state); |
| 491 | pr_debug("skip op %ld on disc %d for sector %llu\n", |
| 492 | bi->bi_rw, i, (unsigned long long)sh->sector); |
| 493 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 494 | set_bit(STRIPE_HANDLE, &sh->state); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | static struct dma_async_tx_descriptor * |
| 500 | async_copy_data(int frombio, struct bio *bio, struct page *page, |
| 501 | sector_t sector, struct dma_async_tx_descriptor *tx) |
| 502 | { |
| 503 | struct bio_vec *bvl; |
| 504 | struct page *bio_page; |
| 505 | int i; |
| 506 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 507 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 508 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 509 | |
| 510 | if (bio->bi_sector >= sector) |
| 511 | page_offset = (signed)(bio->bi_sector - sector) * 512; |
| 512 | else |
| 513 | page_offset = (signed)(sector - bio->bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 514 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 515 | if (frombio) |
| 516 | flags |= ASYNC_TX_FENCE; |
| 517 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 518 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 519 | bio_for_each_segment(bvl, bio, i) { |
| 520 | int len = bio_iovec_idx(bio, i)->bv_len; |
| 521 | int clen; |
| 522 | int b_offset = 0; |
| 523 | |
| 524 | if (page_offset < 0) { |
| 525 | b_offset = -page_offset; |
| 526 | page_offset += b_offset; |
| 527 | len -= b_offset; |
| 528 | } |
| 529 | |
| 530 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 531 | clen = STRIPE_SIZE - page_offset; |
| 532 | else |
| 533 | clen = len; |
| 534 | |
| 535 | if (clen > 0) { |
| 536 | b_offset += bio_iovec_idx(bio, i)->bv_offset; |
| 537 | bio_page = bio_iovec_idx(bio, i)->bv_page; |
| 538 | if (frombio) |
| 539 | tx = async_memcpy(page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 540 | b_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 541 | else |
| 542 | tx = async_memcpy(bio_page, page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 543 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 544 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 545 | /* chain the operations */ |
| 546 | submit.depend_tx = tx; |
| 547 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 548 | if (clen < len) /* hit end of page */ |
| 549 | break; |
| 550 | page_offset += len; |
| 551 | } |
| 552 | |
| 553 | return tx; |
| 554 | } |
| 555 | |
| 556 | static void ops_complete_biofill(void *stripe_head_ref) |
| 557 | { |
| 558 | struct stripe_head *sh = stripe_head_ref; |
| 559 | struct bio *return_bi = NULL; |
| 560 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 561 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 562 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 563 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 564 | (unsigned long long)sh->sector); |
| 565 | |
| 566 | /* clear completed biofills */ |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 567 | spin_lock_irq(&conf->device_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 568 | for (i = sh->disks; i--; ) { |
| 569 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 570 | |
| 571 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 572 | /* and check if we need to reply to a read request, |
| 573 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 574 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 575 | */ |
| 576 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 577 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 578 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 579 | BUG_ON(!dev->read); |
| 580 | rbi = dev->read; |
| 581 | dev->read = NULL; |
| 582 | while (rbi && rbi->bi_sector < |
| 583 | dev->sector + STRIPE_SECTORS) { |
| 584 | rbi2 = r5_next_bio(rbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 585 | if (!raid5_dec_bi_phys_segments(rbi)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 586 | rbi->bi_next = return_bi; |
| 587 | return_bi = rbi; |
| 588 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 589 | rbi = rbi2; |
| 590 | } |
| 591 | } |
| 592 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 593 | spin_unlock_irq(&conf->device_lock); |
| 594 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 595 | |
| 596 | return_io(return_bi); |
| 597 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 598 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 599 | release_stripe(sh); |
| 600 | } |
| 601 | |
| 602 | static void ops_run_biofill(struct stripe_head *sh) |
| 603 | { |
| 604 | struct dma_async_tx_descriptor *tx = NULL; |
| 605 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 606 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 607 | int i; |
| 608 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 609 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 610 | (unsigned long long)sh->sector); |
| 611 | |
| 612 | for (i = sh->disks; i--; ) { |
| 613 | struct r5dev *dev = &sh->dev[i]; |
| 614 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 615 | struct bio *rbi; |
| 616 | spin_lock_irq(&conf->device_lock); |
| 617 | dev->read = rbi = dev->toread; |
| 618 | dev->toread = NULL; |
| 619 | spin_unlock_irq(&conf->device_lock); |
| 620 | while (rbi && rbi->bi_sector < |
| 621 | dev->sector + STRIPE_SECTORS) { |
| 622 | tx = async_copy_data(0, rbi, dev->page, |
| 623 | dev->sector, tx); |
| 624 | rbi = r5_next_bio(rbi, dev->sector); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 630 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 631 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 634 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 635 | { |
| 636 | struct r5dev *tgt; |
| 637 | |
| 638 | if (target < 0) |
| 639 | return; |
| 640 | |
| 641 | tgt = &sh->dev[target]; |
| 642 | set_bit(R5_UPTODATE, &tgt->flags); |
| 643 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 644 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 645 | } |
| 646 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 647 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 648 | { |
| 649 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 650 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 651 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 652 | (unsigned long long)sh->sector); |
| 653 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 654 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 655 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 656 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 657 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 658 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 659 | if (sh->check_state == check_state_compute_run) |
| 660 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 661 | set_bit(STRIPE_HANDLE, &sh->state); |
| 662 | release_stripe(sh); |
| 663 | } |
| 664 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 665 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 666 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 667 | struct raid5_percpu *percpu) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 668 | { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 669 | return percpu->scribble + sizeof(struct page *) * (sh->disks + 2); |
| 670 | } |
| 671 | |
| 672 | static struct dma_async_tx_descriptor * |
| 673 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 674 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 675 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 676 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 677 | int target = sh->ops.target; |
| 678 | struct r5dev *tgt = &sh->dev[target]; |
| 679 | struct page *xor_dest = tgt->page; |
| 680 | int count = 0; |
| 681 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 682 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 683 | int i; |
| 684 | |
| 685 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 686 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 687 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 688 | |
| 689 | for (i = disks; i--; ) |
| 690 | if (i != target) |
| 691 | xor_srcs[count++] = sh->dev[i].page; |
| 692 | |
| 693 | atomic_inc(&sh->count); |
| 694 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 695 | 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] | 696 | ops_complete_compute, sh, to_addr_conv(sh, percpu)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 697 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 698 | 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] | 699 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 700 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 701 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 702 | return tx; |
| 703 | } |
| 704 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 705 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 706 | * @srcs - (struct page *) array of size sh->disks |
| 707 | * @sh - stripe_head to parse |
| 708 | * |
| 709 | * Populates srcs in proper layout order for the stripe and returns the |
| 710 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 711 | * destination buffer is recorded in srcs[count] and the Q destination |
| 712 | * is recorded in srcs[count+1]]. |
| 713 | */ |
| 714 | static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh) |
| 715 | { |
| 716 | int disks = sh->disks; |
| 717 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 718 | int d0_idx = raid6_d0(sh); |
| 719 | int count; |
| 720 | int i; |
| 721 | |
| 722 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 723 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 724 | |
| 725 | count = 0; |
| 726 | i = d0_idx; |
| 727 | do { |
| 728 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 729 | |
| 730 | srcs[slot] = sh->dev[i].page; |
| 731 | i = raid6_next_disk(i, disks); |
| 732 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 733 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 734 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | static struct dma_async_tx_descriptor * |
| 738 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 739 | { |
| 740 | int disks = sh->disks; |
| 741 | struct page **blocks = percpu->scribble; |
| 742 | int target; |
| 743 | int qd_idx = sh->qd_idx; |
| 744 | struct dma_async_tx_descriptor *tx; |
| 745 | struct async_submit_ctl submit; |
| 746 | struct r5dev *tgt; |
| 747 | struct page *dest; |
| 748 | int i; |
| 749 | int count; |
| 750 | |
| 751 | if (sh->ops.target < 0) |
| 752 | target = sh->ops.target2; |
| 753 | else if (sh->ops.target2 < 0) |
| 754 | target = sh->ops.target; |
| 755 | else |
| 756 | /* we should only have one valid target */ |
| 757 | BUG(); |
| 758 | BUG_ON(target < 0); |
| 759 | pr_debug("%s: stripe %llu block: %d\n", |
| 760 | __func__, (unsigned long long)sh->sector, target); |
| 761 | |
| 762 | tgt = &sh->dev[target]; |
| 763 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 764 | dest = tgt->page; |
| 765 | |
| 766 | atomic_inc(&sh->count); |
| 767 | |
| 768 | if (target == qd_idx) { |
| 769 | count = set_syndrome_sources(blocks, sh); |
| 770 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 771 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 772 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 773 | ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 774 | to_addr_conv(sh, percpu)); |
| 775 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 776 | } else { |
| 777 | /* Compute any data- or p-drive using XOR */ |
| 778 | count = 0; |
| 779 | for (i = disks; i-- ; ) { |
| 780 | if (i == target || i == qd_idx) |
| 781 | continue; |
| 782 | blocks[count++] = sh->dev[i].page; |
| 783 | } |
| 784 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 785 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 786 | NULL, ops_complete_compute, sh, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 787 | to_addr_conv(sh, percpu)); |
| 788 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 789 | } |
| 790 | |
| 791 | return tx; |
| 792 | } |
| 793 | |
| 794 | static struct dma_async_tx_descriptor * |
| 795 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 796 | { |
| 797 | int i, count, disks = sh->disks; |
| 798 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 799 | int d0_idx = raid6_d0(sh); |
| 800 | int faila = -1, failb = -1; |
| 801 | int target = sh->ops.target; |
| 802 | int target2 = sh->ops.target2; |
| 803 | struct r5dev *tgt = &sh->dev[target]; |
| 804 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 805 | struct dma_async_tx_descriptor *tx; |
| 806 | struct page **blocks = percpu->scribble; |
| 807 | struct async_submit_ctl submit; |
| 808 | |
| 809 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 810 | __func__, (unsigned long long)sh->sector, target, target2); |
| 811 | BUG_ON(target < 0 || target2 < 0); |
| 812 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 813 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 814 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 815 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 816 | * slot number conversion for 'faila' and 'failb' |
| 817 | */ |
| 818 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 819 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 820 | count = 0; |
| 821 | i = d0_idx; |
| 822 | do { |
| 823 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 824 | |
| 825 | blocks[slot] = sh->dev[i].page; |
| 826 | |
| 827 | if (i == target) |
| 828 | faila = slot; |
| 829 | if (i == target2) |
| 830 | failb = slot; |
| 831 | i = raid6_next_disk(i, disks); |
| 832 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 833 | |
| 834 | BUG_ON(faila == failb); |
| 835 | if (failb < faila) |
| 836 | swap(faila, failb); |
| 837 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 838 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 839 | |
| 840 | atomic_inc(&sh->count); |
| 841 | |
| 842 | if (failb == syndrome_disks+1) { |
| 843 | /* Q disk is one of the missing disks */ |
| 844 | if (faila == syndrome_disks) { |
| 845 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 846 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 847 | ops_complete_compute, sh, |
| 848 | to_addr_conv(sh, percpu)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 849 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 850 | STRIPE_SIZE, &submit); |
| 851 | } else { |
| 852 | struct page *dest; |
| 853 | int data_target; |
| 854 | int qd_idx = sh->qd_idx; |
| 855 | |
| 856 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 857 | if (target == qd_idx) |
| 858 | data_target = target2; |
| 859 | else |
| 860 | data_target = target; |
| 861 | |
| 862 | count = 0; |
| 863 | for (i = disks; i-- ; ) { |
| 864 | if (i == data_target || i == qd_idx) |
| 865 | continue; |
| 866 | blocks[count++] = sh->dev[i].page; |
| 867 | } |
| 868 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 869 | init_async_submit(&submit, |
| 870 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 871 | NULL, NULL, NULL, |
| 872 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 873 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 874 | &submit); |
| 875 | |
| 876 | count = set_syndrome_sources(blocks, sh); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 877 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 878 | ops_complete_compute, sh, |
| 879 | to_addr_conv(sh, percpu)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 880 | return async_gen_syndrome(blocks, 0, count+2, |
| 881 | STRIPE_SIZE, &submit); |
| 882 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 883 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 884 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 885 | ops_complete_compute, sh, |
| 886 | to_addr_conv(sh, percpu)); |
| 887 | if (failb == syndrome_disks) { |
| 888 | /* We're missing D+P. */ |
| 889 | return async_raid6_datap_recov(syndrome_disks+2, |
| 890 | STRIPE_SIZE, faila, |
| 891 | blocks, &submit); |
| 892 | } else { |
| 893 | /* We're missing D+D. */ |
| 894 | return async_raid6_2data_recov(syndrome_disks+2, |
| 895 | STRIPE_SIZE, faila, failb, |
| 896 | blocks, &submit); |
| 897 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
| 901 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 902 | static void ops_complete_prexor(void *stripe_head_ref) |
| 903 | { |
| 904 | struct stripe_head *sh = stripe_head_ref; |
| 905 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 906 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 907 | (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static struct dma_async_tx_descriptor * |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 911 | ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 912 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 913 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 914 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 915 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 916 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 917 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 918 | |
| 919 | /* existing parity data subtracted */ |
| 920 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 921 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 922 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 923 | (unsigned long long)sh->sector); |
| 924 | |
| 925 | for (i = disks; i--; ) { |
| 926 | struct r5dev *dev = &sh->dev[i]; |
| 927 | /* Only process blocks that are known to be uptodate */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 928 | if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 929 | xor_srcs[count++] = dev->page; |
| 930 | } |
| 931 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 932 | 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] | 933 | ops_complete_prexor, sh, to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 934 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 935 | |
| 936 | return tx; |
| 937 | } |
| 938 | |
| 939 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 940 | 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] | 941 | { |
| 942 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 943 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 944 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 945 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 946 | (unsigned long long)sh->sector); |
| 947 | |
| 948 | for (i = disks; i--; ) { |
| 949 | struct r5dev *dev = &sh->dev[i]; |
| 950 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 951 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 952 | if (test_and_clear_bit(R5_Wantdrain, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 953 | struct bio *wbi; |
| 954 | |
| 955 | spin_lock(&sh->lock); |
| 956 | chosen = dev->towrite; |
| 957 | dev->towrite = NULL; |
| 958 | BUG_ON(dev->written); |
| 959 | wbi = dev->written = chosen; |
| 960 | spin_unlock(&sh->lock); |
| 961 | |
| 962 | while (wbi && wbi->bi_sector < |
| 963 | dev->sector + STRIPE_SECTORS) { |
| 964 | tx = async_copy_data(1, wbi, dev->page, |
| 965 | dev->sector, tx); |
| 966 | wbi = r5_next_bio(wbi, dev->sector); |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | return tx; |
| 972 | } |
| 973 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 974 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 975 | { |
| 976 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 977 | int disks = sh->disks; |
| 978 | int pd_idx = sh->pd_idx; |
| 979 | int qd_idx = sh->qd_idx; |
| 980 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 981 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 982 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 983 | (unsigned long long)sh->sector); |
| 984 | |
| 985 | for (i = disks; i--; ) { |
| 986 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 987 | |
| 988 | if (dev->written || i == pd_idx || i == qd_idx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 989 | set_bit(R5_UPTODATE, &dev->flags); |
| 990 | } |
| 991 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 992 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 993 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 994 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 995 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 996 | else { |
| 997 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 998 | sh->reconstruct_state = reconstruct_state_result; |
| 999 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1000 | |
| 1001 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1002 | release_stripe(sh); |
| 1003 | } |
| 1004 | |
| 1005 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1006 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1007 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1008 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1009 | int disks = sh->disks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1010 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1011 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1012 | int count = 0, pd_idx = sh->pd_idx, i; |
| 1013 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1014 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1015 | unsigned long flags; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1016 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1017 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1018 | (unsigned long long)sh->sector); |
| 1019 | |
| 1020 | /* check if prexor is active which means only process blocks |
| 1021 | * that are part of a read-modify-write (written) |
| 1022 | */ |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1023 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1024 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1025 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1026 | for (i = disks; i--; ) { |
| 1027 | struct r5dev *dev = &sh->dev[i]; |
| 1028 | if (dev->written) |
| 1029 | xor_srcs[count++] = dev->page; |
| 1030 | } |
| 1031 | } else { |
| 1032 | xor_dest = sh->dev[pd_idx].page; |
| 1033 | for (i = disks; i--; ) { |
| 1034 | struct r5dev *dev = &sh->dev[i]; |
| 1035 | if (i != pd_idx) |
| 1036 | xor_srcs[count++] = dev->page; |
| 1037 | } |
| 1038 | } |
| 1039 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1040 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1041 | * 2/ if we did not prexor then we are redoing the parity |
| 1042 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1043 | * for the synchronous xor case |
| 1044 | */ |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 1045 | flags = ASYNC_TX_ACK | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1046 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
| 1047 | |
| 1048 | atomic_inc(&sh->count); |
| 1049 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1050 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, sh, |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1051 | to_addr_conv(sh, percpu)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1052 | if (unlikely(count == 1)) |
| 1053 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1054 | else |
| 1055 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1058 | static void |
| 1059 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1060 | struct dma_async_tx_descriptor *tx) |
| 1061 | { |
| 1062 | struct async_submit_ctl submit; |
| 1063 | struct page **blocks = percpu->scribble; |
| 1064 | int count; |
| 1065 | |
| 1066 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1067 | |
| 1068 | count = set_syndrome_sources(blocks, sh); |
| 1069 | |
| 1070 | atomic_inc(&sh->count); |
| 1071 | |
| 1072 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct, |
| 1073 | sh, to_addr_conv(sh, percpu)); |
| 1074 | async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void ops_complete_check(void *stripe_head_ref) |
| 1078 | { |
| 1079 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1080 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1081 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1082 | (unsigned long long)sh->sector); |
| 1083 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1084 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1085 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1086 | release_stripe(sh); |
| 1087 | } |
| 1088 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1089 | 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] | 1090 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1091 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1092 | int pd_idx = sh->pd_idx; |
| 1093 | int qd_idx = sh->qd_idx; |
| 1094 | struct page *xor_dest; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1095 | struct page **xor_srcs = percpu->scribble; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1096 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1097 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1098 | int count; |
| 1099 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1100 | |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1101 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1102 | (unsigned long long)sh->sector); |
| 1103 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1104 | count = 0; |
| 1105 | xor_dest = sh->dev[pd_idx].page; |
| 1106 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1107 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1108 | if (i == pd_idx || i == qd_idx) |
| 1109 | continue; |
| 1110 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1113 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
| 1114 | to_addr_conv(sh, percpu)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 1115 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1116 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1117 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1118 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1119 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 1120 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1123 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 1124 | { |
| 1125 | struct page **srcs = percpu->scribble; |
| 1126 | struct async_submit_ctl submit; |
| 1127 | int count; |
| 1128 | |
| 1129 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 1130 | (unsigned long long)sh->sector, checkp); |
| 1131 | |
| 1132 | count = set_syndrome_sources(srcs, sh); |
| 1133 | if (!checkp) |
| 1134 | srcs[count] = NULL; |
| 1135 | |
| 1136 | atomic_inc(&sh->count); |
| 1137 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
| 1138 | sh, to_addr_conv(sh, percpu)); |
| 1139 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 1140 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 1141 | } |
| 1142 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1143 | 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] | 1144 | { |
| 1145 | int overlap_clear = 0, i, disks = sh->disks; |
| 1146 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1147 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1148 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1149 | struct raid5_percpu *percpu; |
| 1150 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1151 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1152 | cpu = get_cpu(); |
| 1153 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1154 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1155 | ops_run_biofill(sh); |
| 1156 | overlap_clear++; |
| 1157 | } |
| 1158 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1159 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1160 | if (level < 6) |
| 1161 | tx = ops_run_compute5(sh, percpu); |
| 1162 | else { |
| 1163 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 1164 | tx = ops_run_compute6_1(sh, percpu); |
| 1165 | else |
| 1166 | tx = ops_run_compute6_2(sh, percpu); |
| 1167 | } |
| 1168 | /* terminate the chain if reconstruct is not set to be run */ |
| 1169 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 1170 | async_tx_ack(tx); |
| 1171 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1172 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1173 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1174 | tx = ops_run_prexor(sh, percpu, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1175 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1176 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1177 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1178 | overlap_clear++; |
| 1179 | } |
| 1180 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1181 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 1182 | if (level < 6) |
| 1183 | ops_run_reconstruct5(sh, percpu, tx); |
| 1184 | else |
| 1185 | ops_run_reconstruct6(sh, percpu, tx); |
| 1186 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1187 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1188 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 1189 | if (sh->check_state == check_state_run) |
| 1190 | ops_run_check_p(sh, percpu); |
| 1191 | else if (sh->check_state == check_state_run_q) |
| 1192 | ops_run_check_pq(sh, percpu, 0); |
| 1193 | else if (sh->check_state == check_state_run_pq) |
| 1194 | ops_run_check_pq(sh, percpu, 1); |
| 1195 | else |
| 1196 | BUG(); |
| 1197 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1198 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1199 | if (overlap_clear) |
| 1200 | for (i = disks; i--; ) { |
| 1201 | struct r5dev *dev = &sh->dev[i]; |
| 1202 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 1203 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 1204 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1205 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1208 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1209 | static void async_run_ops(void *param, async_cookie_t cookie) |
| 1210 | { |
| 1211 | struct stripe_head *sh = param; |
| 1212 | unsigned long ops_request = sh->ops.request; |
| 1213 | |
| 1214 | clear_bit_unlock(STRIPE_OPS_REQ_PENDING, &sh->state); |
| 1215 | wake_up(&sh->ops.wait_for_ops); |
| 1216 | |
| 1217 | __raid_run_ops(sh, ops_request); |
| 1218 | release_stripe(sh); |
| 1219 | } |
| 1220 | |
| 1221 | static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request) |
| 1222 | { |
| 1223 | /* since handle_stripe can be called outside of raid5d context |
| 1224 | * we need to ensure sh->ops.request is de-staged before another |
| 1225 | * request arrives |
| 1226 | */ |
| 1227 | wait_event(sh->ops.wait_for_ops, |
| 1228 | !test_and_set_bit_lock(STRIPE_OPS_REQ_PENDING, &sh->state)); |
| 1229 | sh->ops.request = ops_request; |
| 1230 | |
| 1231 | atomic_inc(&sh->count); |
| 1232 | async_schedule(async_run_ops, sh); |
| 1233 | } |
| 1234 | #else |
| 1235 | #define raid_run_ops __raid_run_ops |
| 1236 | #endif |
| 1237 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1238 | static int grow_one_stripe(raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
| 1240 | struct stripe_head *sh; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1241 | int disks = max(conf->raid_disks, conf->previous_raid_disks); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1242 | sh = kmem_cache_alloc(conf->slab_cache, GFP_KERNEL); |
| 1243 | if (!sh) |
| 1244 | return 0; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1245 | memset(sh, 0, sizeof(*sh) + (disks-1)*sizeof(struct r5dev)); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1246 | sh->raid_conf = conf; |
| 1247 | spin_lock_init(&sh->lock); |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1248 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1249 | init_waitqueue_head(&sh->ops.wait_for_ops); |
| 1250 | #endif |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1251 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1252 | if (grow_buffers(sh, disks)) { |
| 1253 | shrink_buffers(sh, disks); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1254 | kmem_cache_free(conf->slab_cache, sh); |
| 1255 | return 0; |
| 1256 | } |
| 1257 | /* we just created an active stripe so... */ |
| 1258 | atomic_set(&sh->count, 1); |
| 1259 | atomic_inc(&conf->active_stripes); |
| 1260 | INIT_LIST_HEAD(&sh->lru); |
| 1261 | release_stripe(sh); |
| 1262 | return 1; |
| 1263 | } |
| 1264 | |
| 1265 | static int grow_stripes(raid5_conf_t *conf, int num) |
| 1266 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1267 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 1268 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 1270 | sprintf(conf->cache_name[0], |
| 1271 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 1272 | sprintf(conf->cache_name[1], |
| 1273 | "raid%d-%s-alt", conf->level, mdname(conf->mddev)); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1274 | conf->active_name = 0; |
| 1275 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1277 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | if (!sc) |
| 1279 | return 1; |
| 1280 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1281 | conf->pool_size = devs; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1282 | while (num--) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1283 | if (!grow_one_stripe(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | return 0; |
| 1286 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 1287 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1288 | /** |
| 1289 | * scribble_len - return the required size of the scribble region |
| 1290 | * @num - total number of disks in the array |
| 1291 | * |
| 1292 | * The size must be enough to contain: |
| 1293 | * 1/ a struct page pointer for each device in the array +2 |
| 1294 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 1295 | * (dma_map_page()) or page (page_address()) address. |
| 1296 | * |
| 1297 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 1298 | * calculate over all devices (not just the data blocks), using zeros in place |
| 1299 | * of the P and Q blocks. |
| 1300 | */ |
| 1301 | static size_t scribble_len(int num) |
| 1302 | { |
| 1303 | size_t len; |
| 1304 | |
| 1305 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
| 1306 | |
| 1307 | return len; |
| 1308 | } |
| 1309 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1310 | static int resize_stripes(raid5_conf_t *conf, int newsize) |
| 1311 | { |
| 1312 | /* Make all the stripes able to hold 'newsize' devices. |
| 1313 | * New slots in each stripe get 'page' set to a new page. |
| 1314 | * |
| 1315 | * This happens in stages: |
| 1316 | * 1/ create a new kmem_cache and allocate the required number of |
| 1317 | * stripe_heads. |
| 1318 | * 2/ gather all the old stripe_heads and tranfer the pages across |
| 1319 | * to the new stripe_heads. This will have the side effect of |
| 1320 | * freezing the array as once all stripe_heads have been collected, |
| 1321 | * no IO will be possible. Old stripe heads are freed once their |
| 1322 | * pages have been transferred over, and the old kmem_cache is |
| 1323 | * freed when all stripes are done. |
| 1324 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 1325 | * we simple return a failre status - no need to clean anything up. |
| 1326 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 1327 | * If this fails, we don't bother trying the shrink the |
| 1328 | * stripe_heads down again, we just leave them as they are. |
| 1329 | * As each stripe_head is processed the new one is released into |
| 1330 | * active service. |
| 1331 | * |
| 1332 | * Once step2 is started, we cannot afford to wait for a write, |
| 1333 | * so we use GFP_NOIO allocations. |
| 1334 | */ |
| 1335 | struct stripe_head *osh, *nsh; |
| 1336 | LIST_HEAD(newstripes); |
| 1337 | struct disk_info *ndisks; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1338 | unsigned long cpu; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1339 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 1340 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1341 | int i; |
| 1342 | |
| 1343 | if (newsize <= conf->pool_size) |
| 1344 | return 0; /* never bother to shrink */ |
| 1345 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 1346 | err = md_allow_write(conf->mddev); |
| 1347 | if (err) |
| 1348 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 1349 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1350 | /* Step 1 */ |
| 1351 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 1352 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 1353 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1354 | if (!sc) |
| 1355 | return -ENOMEM; |
| 1356 | |
| 1357 | for (i = conf->max_nr_stripes; i; i--) { |
| 1358 | nsh = kmem_cache_alloc(sc, GFP_KERNEL); |
| 1359 | if (!nsh) |
| 1360 | break; |
| 1361 | |
| 1362 | memset(nsh, 0, sizeof(*nsh) + (newsize-1)*sizeof(struct r5dev)); |
| 1363 | |
| 1364 | nsh->raid_conf = conf; |
| 1365 | spin_lock_init(&nsh->lock); |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 1366 | #ifdef CONFIG_MULTICORE_RAID456 |
| 1367 | init_waitqueue_head(&nsh->ops.wait_for_ops); |
| 1368 | #endif |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1369 | |
| 1370 | list_add(&nsh->lru, &newstripes); |
| 1371 | } |
| 1372 | if (i) { |
| 1373 | /* didn't get enough, give up */ |
| 1374 | while (!list_empty(&newstripes)) { |
| 1375 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1376 | list_del(&nsh->lru); |
| 1377 | kmem_cache_free(sc, nsh); |
| 1378 | } |
| 1379 | kmem_cache_destroy(sc); |
| 1380 | return -ENOMEM; |
| 1381 | } |
| 1382 | /* Step 2 - Must use GFP_NOIO now. |
| 1383 | * OK, we have enough stripes, start collecting inactive |
| 1384 | * stripes and copying them over |
| 1385 | */ |
| 1386 | list_for_each_entry(nsh, &newstripes, lru) { |
| 1387 | spin_lock_irq(&conf->device_lock); |
| 1388 | wait_event_lock_irq(conf->wait_for_stripe, |
| 1389 | !list_empty(&conf->inactive_list), |
| 1390 | conf->device_lock, |
NeilBrown | b3b46be | 2006-03-27 01:18:16 -0800 | [diff] [blame] | 1391 | unplug_slaves(conf->mddev) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1392 | ); |
| 1393 | osh = get_free_stripe(conf); |
| 1394 | spin_unlock_irq(&conf->device_lock); |
| 1395 | atomic_set(&nsh->count, 1); |
| 1396 | for(i=0; i<conf->pool_size; i++) |
| 1397 | nsh->dev[i].page = osh->dev[i].page; |
| 1398 | for( ; i<newsize; i++) |
| 1399 | nsh->dev[i].page = NULL; |
| 1400 | kmem_cache_free(conf->slab_cache, osh); |
| 1401 | } |
| 1402 | kmem_cache_destroy(conf->slab_cache); |
| 1403 | |
| 1404 | /* Step 3. |
| 1405 | * At this point, we are holding all the stripes so the array |
| 1406 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1407 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1408 | */ |
| 1409 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 1410 | if (ndisks) { |
| 1411 | for (i=0; i<conf->raid_disks; i++) |
| 1412 | ndisks[i] = conf->disks[i]; |
| 1413 | kfree(conf->disks); |
| 1414 | conf->disks = ndisks; |
| 1415 | } else |
| 1416 | err = -ENOMEM; |
| 1417 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1418 | get_online_cpus(); |
| 1419 | conf->scribble_len = scribble_len(newsize); |
| 1420 | for_each_present_cpu(cpu) { |
| 1421 | struct raid5_percpu *percpu; |
| 1422 | void *scribble; |
| 1423 | |
| 1424 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 1425 | scribble = kmalloc(conf->scribble_len, GFP_NOIO); |
| 1426 | |
| 1427 | if (scribble) { |
| 1428 | kfree(percpu->scribble); |
| 1429 | percpu->scribble = scribble; |
| 1430 | } else { |
| 1431 | err = -ENOMEM; |
| 1432 | break; |
| 1433 | } |
| 1434 | } |
| 1435 | put_online_cpus(); |
| 1436 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1437 | /* Step 4, return new stripes to service */ |
| 1438 | while(!list_empty(&newstripes)) { |
| 1439 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 1440 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1441 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1442 | for (i=conf->raid_disks; i < newsize; i++) |
| 1443 | if (nsh->dev[i].page == NULL) { |
| 1444 | struct page *p = alloc_page(GFP_NOIO); |
| 1445 | nsh->dev[i].page = p; |
| 1446 | if (!p) |
| 1447 | err = -ENOMEM; |
| 1448 | } |
| 1449 | release_stripe(nsh); |
| 1450 | } |
| 1451 | /* critical section pass, GFP_NOIO no longer needed */ |
| 1452 | |
| 1453 | conf->slab_cache = sc; |
| 1454 | conf->active_name = 1-conf->active_name; |
| 1455 | conf->pool_size = newsize; |
| 1456 | return err; |
| 1457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1459 | static int drop_one_stripe(raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | { |
| 1461 | struct stripe_head *sh; |
| 1462 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1463 | spin_lock_irq(&conf->device_lock); |
| 1464 | sh = get_free_stripe(conf); |
| 1465 | spin_unlock_irq(&conf->device_lock); |
| 1466 | if (!sh) |
| 1467 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 1468 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 1469 | shrink_buffers(sh, conf->pool_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 1470 | kmem_cache_free(conf->slab_cache, sh); |
| 1471 | atomic_dec(&conf->active_stripes); |
| 1472 | return 1; |
| 1473 | } |
| 1474 | |
| 1475 | static void shrink_stripes(raid5_conf_t *conf) |
| 1476 | { |
| 1477 | while (drop_one_stripe(conf)) |
| 1478 | ; |
| 1479 | |
NeilBrown | 29fc7e3 | 2006-02-03 03:03:41 -0800 | [diff] [blame] | 1480 | if (conf->slab_cache) |
| 1481 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | conf->slab_cache = NULL; |
| 1483 | } |
| 1484 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1485 | static void raid5_end_read_request(struct bio * bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1487 | struct stripe_head *sh = bi->bi_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1489 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1491 | char b[BDEVNAME_SIZE]; |
| 1492 | mdk_rdev_t *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
| 1495 | for (i=0 ; i<disks; i++) |
| 1496 | if (bi == &sh->dev[i].req) |
| 1497 | break; |
| 1498 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1499 | pr_debug("end_read_request %llu/%d, count: %d, uptodate %d.\n", |
| 1500 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | uptodate); |
| 1502 | if (i == disks) { |
| 1503 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1504 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | if (uptodate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1509 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1510 | rdev = conf->disks[i].rdev; |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1511 | printk_rl(KERN_INFO "raid5:%s: read error corrected" |
| 1512 | " (%lu sectors at %llu on %s)\n", |
| 1513 | mdname(conf->mddev), STRIPE_SECTORS, |
| 1514 | (unsigned long long)(sh->sector |
| 1515 | + rdev->data_offset), |
| 1516 | bdevname(rdev->bdev, b)); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1517 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1518 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
| 1519 | } |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1520 | if (atomic_read(&conf->disks[i].rdev->read_errors)) |
| 1521 | atomic_set(&conf->disks[i].rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | } else { |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1523 | const char *bdn = bdevname(conf->disks[i].rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1524 | int retry = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1525 | rdev = conf->disks[i].rdev; |
| 1526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1528 | atomic_inc(&rdev->read_errors); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1529 | if (conf->mddev->degraded) |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1530 | printk_rl(KERN_WARNING |
| 1531 | "raid5:%s: read error not correctable " |
| 1532 | "(sector %llu on %s).\n", |
| 1533 | mdname(conf->mddev), |
| 1534 | (unsigned long long)(sh->sector |
| 1535 | + rdev->data_offset), |
| 1536 | bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1537 | else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1538 | /* Oh, no!!! */ |
Bernd Schubert | 6be9d49 | 2008-05-23 13:04:34 -0700 | [diff] [blame] | 1539 | printk_rl(KERN_WARNING |
| 1540 | "raid5:%s: read error NOT corrected!! " |
| 1541 | "(sector %llu on %s).\n", |
| 1542 | mdname(conf->mddev), |
| 1543 | (unsigned long long)(sh->sector |
| 1544 | + rdev->data_offset), |
| 1545 | bdn); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1546 | else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1547 | > conf->max_nr_stripes) |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1548 | printk(KERN_WARNING |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1549 | "raid5:%s: Too many read errors, failing device %s.\n", |
| 1550 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1551 | else |
| 1552 | retry = 1; |
| 1553 | if (retry) |
| 1554 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 1555 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 1556 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 1557 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 1558 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | } |
| 1561 | rdev_dec_pending(conf->disks[i].rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1563 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1564 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1567 | static void raid5_end_write_request(struct bio *bi, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1569 | struct stripe_head *sh = bi->bi_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 1571 | int disks = sh->disks, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
| 1573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | for (i=0 ; i<disks; i++) |
| 1575 | if (bi == &sh->dev[i].req) |
| 1576 | break; |
| 1577 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1578 | pr_debug("end_write_request %llu/%d, count %d, uptodate: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
| 1580 | uptodate); |
| 1581 | if (i == disks) { |
| 1582 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 1583 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | if (!uptodate) |
| 1587 | md_error(conf->mddev, conf->disks[i].rdev); |
| 1588 | |
| 1589 | rdev_dec_pending(conf->disks[i].rdev, conf->mddev); |
| 1590 | |
| 1591 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1592 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1593 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1597 | 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] | 1598 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1599 | 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] | 1600 | { |
| 1601 | struct r5dev *dev = &sh->dev[i]; |
| 1602 | |
| 1603 | bio_init(&dev->req); |
| 1604 | dev->req.bi_io_vec = &dev->vec; |
| 1605 | dev->req.bi_vcnt++; |
| 1606 | dev->req.bi_max_vecs++; |
| 1607 | dev->vec.bv_page = dev->page; |
| 1608 | dev->vec.bv_len = STRIPE_SIZE; |
| 1609 | dev->vec.bv_offset = 0; |
| 1610 | |
| 1611 | dev->req.bi_sector = sh->sector; |
| 1612 | dev->req.bi_private = sh; |
| 1613 | |
| 1614 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1615 | dev->sector = compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | static void error(mddev_t *mddev, mdk_rdev_t *rdev) |
| 1619 | { |
| 1620 | char b[BDEVNAME_SIZE]; |
| 1621 | raid5_conf_t *conf = (raid5_conf_t *) mddev->private; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 1622 | pr_debug("raid5: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1624 | if (!test_bit(Faulty, &rdev->flags)) { |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 1625 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1626 | if (test_and_clear_bit(In_sync, &rdev->flags)) { |
| 1627 | unsigned long flags; |
| 1628 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | mddev->degraded++; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 1630 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | /* |
| 1632 | * if recovery was running, make sure it aborts. |
| 1633 | */ |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 1634 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 1636 | set_bit(Faulty, &rdev->flags); |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1637 | printk(KERN_ALERT |
| 1638 | "raid5: Disk failure on %s, disabling device.\n" |
| 1639 | "raid5: Operation continuing on %d devices.\n", |
| 1640 | bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1642 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | |
| 1644 | /* |
| 1645 | * Input: a 'big' sector number, |
| 1646 | * Output: index of the data and parity disk, and the sector # in them. |
| 1647 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1648 | 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] | 1649 | int previous, int *dd_idx, |
| 1650 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | { |
| 1652 | long stripe; |
| 1653 | unsigned long chunk_number; |
| 1654 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1655 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1656 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1658 | int algorithm = previous ? conf->prev_algo |
| 1659 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 1660 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 1661 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1662 | int raid_disks = previous ? conf->previous_raid_disks |
| 1663 | : conf->raid_disks; |
| 1664 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | |
| 1666 | /* First compute the information on this sector */ |
| 1667 | |
| 1668 | /* |
| 1669 | * Compute the chunk number and the sector offset inside the chunk |
| 1670 | */ |
| 1671 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 1672 | chunk_number = r_sector; |
| 1673 | BUG_ON(r_sector != chunk_number); |
| 1674 | |
| 1675 | /* |
| 1676 | * Compute the stripe number |
| 1677 | */ |
| 1678 | stripe = chunk_number / data_disks; |
| 1679 | |
| 1680 | /* |
| 1681 | * Compute the data disk and parity disk indexes inside the stripe |
| 1682 | */ |
| 1683 | *dd_idx = chunk_number % data_disks; |
| 1684 | |
| 1685 | /* |
| 1686 | * Select the parity disk based on the user selected algorithm. |
| 1687 | */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1688 | pd_idx = qd_idx = ~0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1689 | switch(conf->level) { |
| 1690 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1691 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1692 | break; |
| 1693 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1694 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1696 | pd_idx = data_disks - stripe % raid_disks; |
| 1697 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | (*dd_idx)++; |
| 1699 | break; |
| 1700 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1701 | pd_idx = 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_LEFT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1706 | pd_idx = data_disks - stripe % raid_disks; |
| 1707 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | break; |
| 1709 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1710 | pd_idx = stripe % raid_disks; |
| 1711 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1713 | case ALGORITHM_PARITY_0: |
| 1714 | pd_idx = 0; |
| 1715 | (*dd_idx)++; |
| 1716 | break; |
| 1717 | case ALGORITHM_PARITY_N: |
| 1718 | pd_idx = data_disks; |
| 1719 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | default: |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1721 | printk(KERN_ERR "raid5: unsupported algorithm %d\n", |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1722 | algorithm); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1723 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1724 | } |
| 1725 | break; |
| 1726 | case 6: |
| 1727 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1728 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1729 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1730 | pd_idx = raid_disks - 1 - (stripe % raid_disks); |
| 1731 | qd_idx = pd_idx + 1; |
| 1732 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1733 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1734 | qd_idx = 0; |
| 1735 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1736 | (*dd_idx) += 2; /* D D P Q D */ |
| 1737 | break; |
| 1738 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1739 | pd_idx = stripe % raid_disks; |
| 1740 | qd_idx = pd_idx + 1; |
| 1741 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1742 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1743 | qd_idx = 0; |
| 1744 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1745 | (*dd_idx) += 2; /* D D P Q D */ |
| 1746 | break; |
| 1747 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1748 | pd_idx = raid_disks - 1 - (stripe % raid_disks); |
| 1749 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1750 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1751 | break; |
| 1752 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1753 | pd_idx = stripe % raid_disks; |
| 1754 | qd_idx = (pd_idx + 1) % raid_disks; |
| 1755 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1756 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1757 | |
| 1758 | case ALGORITHM_PARITY_0: |
| 1759 | pd_idx = 0; |
| 1760 | qd_idx = 1; |
| 1761 | (*dd_idx) += 2; |
| 1762 | break; |
| 1763 | case ALGORITHM_PARITY_N: |
| 1764 | pd_idx = data_disks; |
| 1765 | qd_idx = data_disks + 1; |
| 1766 | break; |
| 1767 | |
| 1768 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 1769 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 1770 | * of blocks for computing Q is different. |
| 1771 | */ |
| 1772 | pd_idx = stripe % raid_disks; |
| 1773 | qd_idx = pd_idx + 1; |
| 1774 | if (pd_idx == raid_disks-1) { |
| 1775 | (*dd_idx)++; /* Q D D D P */ |
| 1776 | qd_idx = 0; |
| 1777 | } else if (*dd_idx >= pd_idx) |
| 1778 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1779 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1780 | break; |
| 1781 | |
| 1782 | case ALGORITHM_ROTATING_N_RESTART: |
| 1783 | /* Same a left_asymmetric, by first stripe is |
| 1784 | * D D D P Q rather than |
| 1785 | * Q D D D P |
| 1786 | */ |
| 1787 | pd_idx = raid_disks - 1 - ((stripe + 1) % raid_disks); |
| 1788 | qd_idx = pd_idx + 1; |
| 1789 | if (pd_idx == raid_disks-1) { |
| 1790 | (*dd_idx)++; /* Q D D D P */ |
| 1791 | qd_idx = 0; |
| 1792 | } else if (*dd_idx >= pd_idx) |
| 1793 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1794 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1795 | break; |
| 1796 | |
| 1797 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 1798 | /* Same as left_symmetric but Q is before P */ |
| 1799 | pd_idx = raid_disks - 1 - (stripe % raid_disks); |
| 1800 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 1801 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1802 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1803 | break; |
| 1804 | |
| 1805 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 1806 | /* RAID5 left_asymmetric, with Q on last device */ |
| 1807 | pd_idx = data_disks - stripe % (raid_disks-1); |
| 1808 | if (*dd_idx >= pd_idx) |
| 1809 | (*dd_idx)++; |
| 1810 | qd_idx = raid_disks - 1; |
| 1811 | break; |
| 1812 | |
| 1813 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 1814 | pd_idx = stripe % (raid_disks-1); |
| 1815 | if (*dd_idx >= pd_idx) |
| 1816 | (*dd_idx)++; |
| 1817 | qd_idx = raid_disks - 1; |
| 1818 | break; |
| 1819 | |
| 1820 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 1821 | pd_idx = data_disks - stripe % (raid_disks-1); |
| 1822 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 1823 | qd_idx = raid_disks - 1; |
| 1824 | break; |
| 1825 | |
| 1826 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 1827 | pd_idx = stripe % (raid_disks-1); |
| 1828 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 1829 | qd_idx = raid_disks - 1; |
| 1830 | break; |
| 1831 | |
| 1832 | case ALGORITHM_PARITY_0_6: |
| 1833 | pd_idx = 0; |
| 1834 | (*dd_idx)++; |
| 1835 | qd_idx = raid_disks - 1; |
| 1836 | break; |
| 1837 | |
| 1838 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1839 | default: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1840 | printk(KERN_CRIT "raid6: unsupported algorithm %d\n", |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1841 | algorithm); |
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 | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1904 | printk(KERN_ERR "raid5: unsupported algorithm %d\n", |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1905 | algorithm); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1906 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1907 | } |
| 1908 | break; |
| 1909 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1910 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1911 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1912 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1913 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 1914 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1915 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 1916 | case ALGORITHM_ROTATING_N_RESTART: |
| 1917 | if (sh->pd_idx == raid_disks-1) |
| 1918 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1919 | else if (i > sh->pd_idx) |
| 1920 | i -= 2; /* D D P Q D */ |
| 1921 | break; |
| 1922 | case ALGORITHM_LEFT_SYMMETRIC: |
| 1923 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 1924 | if (sh->pd_idx == raid_disks-1) |
| 1925 | i--; /* Q D D D P */ |
| 1926 | else { |
| 1927 | /* D D P Q D */ |
| 1928 | if (i < sh->pd_idx) |
| 1929 | i += raid_disks; |
| 1930 | i -= (sh->pd_idx + 2); |
| 1931 | } |
| 1932 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1933 | case ALGORITHM_PARITY_0: |
| 1934 | i -= 2; |
| 1935 | break; |
| 1936 | case ALGORITHM_PARITY_N: |
| 1937 | break; |
| 1938 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1939 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1940 | if (sh->pd_idx == 0) |
| 1941 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1942 | else { |
| 1943 | /* D D Q P D */ |
| 1944 | if (i < sh->pd_idx) |
| 1945 | i += raid_disks; |
| 1946 | i -= (sh->pd_idx + 1); |
| 1947 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1948 | break; |
| 1949 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 1950 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 1951 | if (i > sh->pd_idx) |
| 1952 | i--; |
| 1953 | break; |
| 1954 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 1955 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 1956 | if (i < sh->pd_idx) |
| 1957 | i += data_disks + 1; |
| 1958 | i -= (sh->pd_idx + 1); |
| 1959 | break; |
| 1960 | case ALGORITHM_PARITY_0_6: |
| 1961 | i -= 1; |
| 1962 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1963 | default: |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 1964 | printk(KERN_CRIT "raid6: unsupported algorithm %d\n", |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 1965 | algorithm); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1966 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1967 | } |
| 1968 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | chunk_number = stripe * data_disks + i; |
| 1972 | r_sector = (sector_t)chunk_number * sectors_per_chunk + chunk_offset; |
| 1973 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1974 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 1975 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 1976 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 1977 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 1978 | printk(KERN_ERR "compute_blocknr: map not correct\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | return 0; |
| 1980 | } |
| 1981 | return r_sector; |
| 1982 | } |
| 1983 | |
| 1984 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1985 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 1986 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1987 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1988 | { |
| 1989 | int i, pd_idx = sh->pd_idx, disks = sh->disks; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 1990 | raid5_conf_t *conf = sh->raid_conf; |
| 1991 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 1992 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1993 | if (rcw) { |
| 1994 | /* if we are not expanding this is a proper write request, and |
| 1995 | * there will be bios with new data to be drained into the |
| 1996 | * stripe cache |
| 1997 | */ |
| 1998 | if (!expand) { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 1999 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 2000 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 2001 | } else |
| 2002 | sh->reconstruct_state = reconstruct_state_run; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2003 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2004 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2005 | |
| 2006 | for (i = disks; i--; ) { |
| 2007 | struct r5dev *dev = &sh->dev[i]; |
| 2008 | |
| 2009 | if (dev->towrite) { |
| 2010 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2011 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2012 | if (!expand) |
| 2013 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2014 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2015 | } |
| 2016 | } |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2017 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2018 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2019 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2020 | } else { |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2021 | BUG_ON(level == 6); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2022 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 2023 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
| 2024 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2025 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2026 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 2027 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2028 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2029 | |
| 2030 | for (i = disks; i--; ) { |
| 2031 | struct r5dev *dev = &sh->dev[i]; |
| 2032 | if (i == pd_idx) |
| 2033 | continue; |
| 2034 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2035 | if (dev->towrite && |
| 2036 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2037 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2038 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2039 | set_bit(R5_LOCKED, &dev->flags); |
| 2040 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2041 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2046 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2047 | * are in flight |
| 2048 | */ |
| 2049 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 2050 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2051 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2052 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2053 | if (level == 6) { |
| 2054 | int qd_idx = sh->qd_idx; |
| 2055 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 2056 | |
| 2057 | set_bit(R5_LOCKED, &dev->flags); |
| 2058 | clear_bit(R5_UPTODATE, &dev->flags); |
| 2059 | s->locked++; |
| 2060 | } |
| 2061 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2062 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272 | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2063 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2064 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2065 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | /* |
| 2068 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2069 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | * The bi_next chain must be in order. |
| 2071 | */ |
| 2072 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, int forwrite) |
| 2073 | { |
| 2074 | struct bio **bip; |
| 2075 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2076 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2078 | pr_debug("adding bh b#%llu to stripe s#%llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | (unsigned long long)bi->bi_sector, |
| 2080 | (unsigned long long)sh->sector); |
| 2081 | |
| 2082 | |
| 2083 | spin_lock(&sh->lock); |
| 2084 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2085 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | bip = &sh->dev[dd_idx].towrite; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2087 | if (*bip == NULL && sh->dev[dd_idx].written == NULL) |
| 2088 | firstwrite = 1; |
| 2089 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | bip = &sh->dev[dd_idx].toread; |
| 2091 | while (*bip && (*bip)->bi_sector < bi->bi_sector) { |
| 2092 | if ((*bip)->bi_sector + ((*bip)->bi_size >> 9) > bi->bi_sector) |
| 2093 | goto overlap; |
| 2094 | bip = & (*bip)->bi_next; |
| 2095 | } |
| 2096 | if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) |
| 2097 | goto overlap; |
| 2098 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2099 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | if (*bip) |
| 2101 | bi->bi_next = *bip; |
| 2102 | *bip = bi; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2103 | bi->bi_phys_segments++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | spin_unlock_irq(&conf->device_lock); |
| 2105 | spin_unlock(&sh->lock); |
| 2106 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2107 | 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] | 2108 | (unsigned long long)bi->bi_sector, |
| 2109 | (unsigned long long)sh->sector, dd_idx); |
| 2110 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2111 | if (conf->mddev->bitmap && firstwrite) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2112 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 2113 | STRIPE_SECTORS, 0); |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 2114 | sh->bm_seq = conf->seq_flush+1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 2115 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 2116 | } |
| 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | if (forwrite) { |
| 2119 | /* check if page is covered */ |
| 2120 | sector_t sector = sh->dev[dd_idx].sector; |
| 2121 | for (bi=sh->dev[dd_idx].towrite; |
| 2122 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
| 2123 | bi && bi->bi_sector <= sector; |
| 2124 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
| 2125 | if (bi->bi_sector + (bi->bi_size>>9) >= sector) |
| 2126 | sector = bi->bi_sector + (bi->bi_size>>9); |
| 2127 | } |
| 2128 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
| 2129 | set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags); |
| 2130 | } |
| 2131 | return 1; |
| 2132 | |
| 2133 | overlap: |
| 2134 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
| 2135 | spin_unlock_irq(&conf->device_lock); |
| 2136 | spin_unlock(&sh->lock); |
| 2137 | return 0; |
| 2138 | } |
| 2139 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2140 | static void end_reshape(raid5_conf_t *conf); |
| 2141 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2142 | static void stripe_set_idx(sector_t stripe, raid5_conf_t *conf, int previous, |
| 2143 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2144 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2145 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2146 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2147 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2148 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2149 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 2150 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2151 | raid5_compute_sector(conf, |
| 2152 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2153 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2154 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2155 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 2156 | } |
| 2157 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2158 | static void |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2159 | handle_failed_stripe(raid5_conf_t *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2160 | struct stripe_head_state *s, int disks, |
| 2161 | struct bio **return_bi) |
| 2162 | { |
| 2163 | int i; |
| 2164 | for (i = disks; i--; ) { |
| 2165 | struct bio *bi; |
| 2166 | int bitmap_end = 0; |
| 2167 | |
| 2168 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
| 2169 | mdk_rdev_t *rdev; |
| 2170 | rcu_read_lock(); |
| 2171 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 2172 | if (rdev && test_bit(In_sync, &rdev->flags)) |
| 2173 | /* multiple read failures in one stripe */ |
| 2174 | md_error(conf->mddev, rdev); |
| 2175 | rcu_read_unlock(); |
| 2176 | } |
| 2177 | spin_lock_irq(&conf->device_lock); |
| 2178 | /* fail all writes first */ |
| 2179 | bi = sh->dev[i].towrite; |
| 2180 | sh->dev[i].towrite = NULL; |
| 2181 | if (bi) { |
| 2182 | s->to_write--; |
| 2183 | bitmap_end = 1; |
| 2184 | } |
| 2185 | |
| 2186 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2187 | wake_up(&conf->wait_for_overlap); |
| 2188 | |
| 2189 | while (bi && bi->bi_sector < |
| 2190 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2191 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
| 2192 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2193 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2194 | md_write_end(conf->mddev); |
| 2195 | bi->bi_next = *return_bi; |
| 2196 | *return_bi = bi; |
| 2197 | } |
| 2198 | bi = nextbi; |
| 2199 | } |
| 2200 | /* and fail all 'written' */ |
| 2201 | bi = sh->dev[i].written; |
| 2202 | sh->dev[i].written = NULL; |
| 2203 | if (bi) bitmap_end = 1; |
| 2204 | while (bi && bi->bi_sector < |
| 2205 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2206 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
| 2207 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2208 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2209 | md_write_end(conf->mddev); |
| 2210 | bi->bi_next = *return_bi; |
| 2211 | *return_bi = bi; |
| 2212 | } |
| 2213 | bi = bi2; |
| 2214 | } |
| 2215 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2216 | /* fail any reads if this device is non-operational and |
| 2217 | * the data has not reached the cache yet. |
| 2218 | */ |
| 2219 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
| 2220 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 2221 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2222 | bi = sh->dev[i].toread; |
| 2223 | sh->dev[i].toread = NULL; |
| 2224 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 2225 | wake_up(&conf->wait_for_overlap); |
| 2226 | if (bi) s->to_read--; |
| 2227 | while (bi && bi->bi_sector < |
| 2228 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 2229 | struct bio *nextbi = |
| 2230 | r5_next_bio(bi, sh->dev[i].sector); |
| 2231 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2232 | if (!raid5_dec_bi_phys_segments(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2233 | bi->bi_next = *return_bi; |
| 2234 | *return_bi = bi; |
| 2235 | } |
| 2236 | bi = nextbi; |
| 2237 | } |
| 2238 | } |
| 2239 | spin_unlock_irq(&conf->device_lock); |
| 2240 | if (bitmap_end) |
| 2241 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 2242 | STRIPE_SECTORS, 0, 0); |
| 2243 | } |
| 2244 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2245 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2246 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2247 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2250 | /* fetch_block5 - checks the given member device to see if its data needs |
| 2251 | * to be read or computed to satisfy a request. |
| 2252 | * |
| 2253 | * Returns 1 when no more member devices need to be checked, otherwise returns |
| 2254 | * 0 to tell the loop in handle_stripe_fill5 to continue |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2255 | */ |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2256 | static int fetch_block5(struct stripe_head *sh, struct stripe_head_state *s, |
| 2257 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2258 | { |
| 2259 | struct r5dev *dev = &sh->dev[disk_idx]; |
| 2260 | struct r5dev *failed_dev = &sh->dev[s->failed_num]; |
| 2261 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2262 | /* is the data in this block needed, and can we get it? */ |
| 2263 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2264 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2265 | (dev->toread || |
| 2266 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2267 | s->syncing || s->expanding || |
| 2268 | (s->failed && |
| 2269 | (failed_dev->toread || |
| 2270 | (failed_dev->towrite && |
| 2271 | !test_bit(R5_OVERWRITE, &failed_dev->flags)))))) { |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2272 | /* We would like to get this block, possibly by computing it, |
| 2273 | * otherwise read it if the backing disk is insync |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2274 | */ |
| 2275 | if ((s->uptodate == disks - 1) && |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2276 | (s->failed && disk_idx == s->failed_num)) { |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2277 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2278 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2279 | set_bit(R5_Wantcompute, &dev->flags); |
| 2280 | sh->ops.target = disk_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2281 | sh->ops.target2 = -1; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2282 | s->req_compute = 1; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2283 | /* Careful: from this point on 'uptodate' is in the eye |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2284 | * of raid_run_ops which services 'compute' operations |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2285 | * before writes. R5_Wantcompute flags a block that will |
| 2286 | * be R5_UPTODATE by the time it is needed for a |
| 2287 | * subsequent operation. |
| 2288 | */ |
| 2289 | s->uptodate++; |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2290 | return 1; /* uptodate + compute == disks */ |
Dan Williams | 7a1fc53 | 2008-07-10 04:54:57 -0700 | [diff] [blame] | 2291 | } else if (test_bit(R5_Insync, &dev->flags)) { |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2292 | set_bit(R5_LOCKED, &dev->flags); |
| 2293 | set_bit(R5_Wantread, &dev->flags); |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2294 | s->locked++; |
| 2295 | pr_debug("Reading block %d (sync=%d)\n", disk_idx, |
| 2296 | s->syncing); |
| 2297 | } |
| 2298 | } |
| 2299 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2300 | return 0; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2303 | /** |
| 2304 | * handle_stripe_fill5 - read or compute data to satisfy pending requests. |
| 2305 | */ |
| 2306 | static void handle_stripe_fill5(struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2307 | struct stripe_head_state *s, int disks) |
| 2308 | { |
| 2309 | int i; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2310 | |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2311 | /* look for blocks to read/compute, skip this if a compute |
| 2312 | * is already in flight, or if the stripe contents are in the |
| 2313 | * midst of changing due to a write |
| 2314 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2315 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2316 | !sh->reconstruct_state) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2317 | for (i = disks; i--; ) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2318 | if (fetch_block5(sh, s, i, disks)) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2319 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2320 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2321 | } |
| 2322 | |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2323 | /* fetch_block6 - checks the given member device to see if its data needs |
| 2324 | * to be read or computed to satisfy a request. |
| 2325 | * |
| 2326 | * Returns 1 when no more member devices need to be checked, otherwise returns |
| 2327 | * 0 to tell the loop in handle_stripe_fill6 to continue |
| 2328 | */ |
| 2329 | static int fetch_block6(struct stripe_head *sh, struct stripe_head_state *s, |
| 2330 | struct r6_state *r6s, int disk_idx, int disks) |
| 2331 | { |
| 2332 | struct r5dev *dev = &sh->dev[disk_idx]; |
| 2333 | struct r5dev *fdev[2] = { &sh->dev[r6s->failed_num[0]], |
| 2334 | &sh->dev[r6s->failed_num[1]] }; |
| 2335 | |
| 2336 | if (!test_bit(R5_LOCKED, &dev->flags) && |
| 2337 | !test_bit(R5_UPTODATE, &dev->flags) && |
| 2338 | (dev->toread || |
| 2339 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags)) || |
| 2340 | s->syncing || s->expanding || |
| 2341 | (s->failed >= 1 && |
| 2342 | (fdev[0]->toread || s->to_write)) || |
| 2343 | (s->failed >= 2 && |
| 2344 | (fdev[1]->toread || s->to_write)))) { |
| 2345 | /* we would like to get this block, possibly by computing it, |
| 2346 | * otherwise read it if the backing disk is insync |
| 2347 | */ |
| 2348 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 2349 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
| 2350 | if ((s->uptodate == disks - 1) && |
| 2351 | (s->failed && (disk_idx == r6s->failed_num[0] || |
| 2352 | disk_idx == r6s->failed_num[1]))) { |
| 2353 | /* have disk failed, and we're requested to fetch it; |
| 2354 | * do compute it |
| 2355 | */ |
| 2356 | pr_debug("Computing stripe %llu block %d\n", |
| 2357 | (unsigned long long)sh->sector, disk_idx); |
| 2358 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2359 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2360 | set_bit(R5_Wantcompute, &dev->flags); |
| 2361 | sh->ops.target = disk_idx; |
| 2362 | sh->ops.target2 = -1; /* no 2nd target */ |
| 2363 | s->req_compute = 1; |
| 2364 | s->uptodate++; |
| 2365 | return 1; |
| 2366 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 2367 | /* Computing 2-failure is *very* expensive; only |
| 2368 | * do it if failed >= 2 |
| 2369 | */ |
| 2370 | int other; |
| 2371 | for (other = disks; other--; ) { |
| 2372 | if (other == disk_idx) |
| 2373 | continue; |
| 2374 | if (!test_bit(R5_UPTODATE, |
| 2375 | &sh->dev[other].flags)) |
| 2376 | break; |
| 2377 | } |
| 2378 | BUG_ON(other < 0); |
| 2379 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 2380 | (unsigned long long)sh->sector, |
| 2381 | disk_idx, other); |
| 2382 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2383 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2384 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 2385 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 2386 | sh->ops.target = disk_idx; |
| 2387 | sh->ops.target2 = other; |
| 2388 | s->uptodate += 2; |
| 2389 | s->req_compute = 1; |
| 2390 | return 1; |
| 2391 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 2392 | set_bit(R5_LOCKED, &dev->flags); |
| 2393 | set_bit(R5_Wantread, &dev->flags); |
| 2394 | s->locked++; |
| 2395 | pr_debug("Reading block %d (sync=%d)\n", |
| 2396 | disk_idx, s->syncing); |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * handle_stripe_fill6 - read or compute data to satisfy pending requests. |
| 2405 | */ |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2406 | static void handle_stripe_fill6(struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2407 | struct stripe_head_state *s, struct r6_state *r6s, |
| 2408 | int disks) |
| 2409 | { |
| 2410 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2411 | |
| 2412 | /* look for blocks to read/compute, skip this if a compute |
| 2413 | * is already in flight, or if the stripe contents are in the |
| 2414 | * midst of changing due to a write |
| 2415 | */ |
| 2416 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
| 2417 | !sh->reconstruct_state) |
| 2418 | for (i = disks; i--; ) |
| 2419 | if (fetch_block6(sh, s, r6s, i, disks)) |
| 2420 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2421 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2422 | } |
| 2423 | |
| 2424 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2425 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2426 | * any written block on an uptodate or failed drive can be returned. |
| 2427 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 2428 | * never LOCKED, so we don't need to test 'failed' directly. |
| 2429 | */ |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2430 | static void handle_stripe_clean_event(raid5_conf_t *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2431 | struct stripe_head *sh, int disks, struct bio **return_bi) |
| 2432 | { |
| 2433 | int i; |
| 2434 | struct r5dev *dev; |
| 2435 | |
| 2436 | for (i = disks; i--; ) |
| 2437 | if (sh->dev[i].written) { |
| 2438 | dev = &sh->dev[i]; |
| 2439 | if (!test_bit(R5_LOCKED, &dev->flags) && |
| 2440 | test_bit(R5_UPTODATE, &dev->flags)) { |
| 2441 | /* We can return any write requests */ |
| 2442 | struct bio *wbi, *wbi2; |
| 2443 | int bitmap_end = 0; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2444 | pr_debug("Return write for disc %d\n", i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2445 | spin_lock_irq(&conf->device_lock); |
| 2446 | wbi = dev->written; |
| 2447 | dev->written = NULL; |
| 2448 | while (wbi && wbi->bi_sector < |
| 2449 | dev->sector + STRIPE_SECTORS) { |
| 2450 | wbi2 = r5_next_bio(wbi, dev->sector); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 2451 | if (!raid5_dec_bi_phys_segments(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2452 | md_write_end(conf->mddev); |
| 2453 | wbi->bi_next = *return_bi; |
| 2454 | *return_bi = wbi; |
| 2455 | } |
| 2456 | wbi = wbi2; |
| 2457 | } |
| 2458 | if (dev->towrite == NULL) |
| 2459 | bitmap_end = 1; |
| 2460 | spin_unlock_irq(&conf->device_lock); |
| 2461 | if (bitmap_end) |
| 2462 | bitmap_endwrite(conf->mddev->bitmap, |
| 2463 | sh->sector, |
| 2464 | STRIPE_SECTORS, |
| 2465 | !test_bit(STRIPE_DEGRADED, &sh->state), |
| 2466 | 0); |
| 2467 | } |
| 2468 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 2469 | |
| 2470 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 2471 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 2472 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2475 | static void handle_stripe_dirtying5(raid5_conf_t *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2476 | struct stripe_head *sh, struct stripe_head_state *s, int disks) |
| 2477 | { |
| 2478 | int rmw = 0, rcw = 0, i; |
| 2479 | for (i = disks; i--; ) { |
| 2480 | /* would I have to read this buffer for read_modify_write */ |
| 2481 | struct r5dev *dev = &sh->dev[i]; |
| 2482 | if ((dev->towrite || i == sh->pd_idx) && |
| 2483 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2484 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2485 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2486 | if (test_bit(R5_Insync, &dev->flags)) |
| 2487 | rmw++; |
| 2488 | else |
| 2489 | rmw += 2*disks; /* cannot read it */ |
| 2490 | } |
| 2491 | /* Would I have to read this buffer for reconstruct_write */ |
| 2492 | if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && |
| 2493 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2494 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2495 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2496 | if (test_bit(R5_Insync, &dev->flags)) rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2497 | else |
| 2498 | rcw += 2*disks; |
| 2499 | } |
| 2500 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2501 | pr_debug("for sector %llu, rmw=%d rcw=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2502 | (unsigned long long)sh->sector, rmw, rcw); |
| 2503 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2504 | if (rmw < rcw && rmw > 0) |
| 2505 | /* prefer read-modify-write, but need to get some data */ |
| 2506 | for (i = disks; i--; ) { |
| 2507 | struct r5dev *dev = &sh->dev[i]; |
| 2508 | if ((dev->towrite || i == sh->pd_idx) && |
| 2509 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2510 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2511 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2512 | test_bit(R5_Insync, &dev->flags)) { |
| 2513 | if ( |
| 2514 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2515 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2516 | "%d for r-m-w\n", i); |
| 2517 | set_bit(R5_LOCKED, &dev->flags); |
| 2518 | set_bit(R5_Wantread, &dev->flags); |
| 2519 | s->locked++; |
| 2520 | } else { |
| 2521 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2522 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | if (rcw <= rmw && rcw > 0) |
| 2527 | /* want reconstruct write, but need to get some data */ |
| 2528 | for (i = disks; i--; ) { |
| 2529 | struct r5dev *dev = &sh->dev[i]; |
| 2530 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 2531 | i != sh->pd_idx && |
| 2532 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2533 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2534 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2535 | test_bit(R5_Insync, &dev->flags)) { |
| 2536 | if ( |
| 2537 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2538 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2539 | "%d for Reconstruct\n", i); |
| 2540 | set_bit(R5_LOCKED, &dev->flags); |
| 2541 | set_bit(R5_Wantread, &dev->flags); |
| 2542 | s->locked++; |
| 2543 | } else { |
| 2544 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2545 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | /* now if nothing is locked, and if we have enough data, |
| 2550 | * we can start a write request |
| 2551 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2552 | /* since handle_stripe can be called at any time we need to handle the |
| 2553 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2554 | * subsequent call wants to start a write request. raid_run_ops only |
| 2555 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2556 | * simultaneously. If this is not the case then new writes need to be |
| 2557 | * held off until the compute completes. |
| 2558 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2559 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2560 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
| 2561 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2562 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2563 | } |
| 2564 | |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 2565 | static void handle_stripe_dirtying6(raid5_conf_t *conf, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2566 | struct stripe_head *sh, struct stripe_head_state *s, |
| 2567 | struct r6_state *r6s, int disks) |
| 2568 | { |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2569 | int rcw = 0, pd_idx = sh->pd_idx, i; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2570 | int qd_idx = sh->qd_idx; |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2571 | |
| 2572 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2573 | for (i = disks; i--; ) { |
| 2574 | struct r5dev *dev = &sh->dev[i]; |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2575 | /* check if we haven't enough data */ |
| 2576 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 2577 | i != pd_idx && i != qd_idx && |
| 2578 | !test_bit(R5_LOCKED, &dev->flags) && |
| 2579 | !(test_bit(R5_UPTODATE, &dev->flags) || |
| 2580 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 2581 | rcw++; |
| 2582 | if (!test_bit(R5_Insync, &dev->flags)) |
| 2583 | continue; /* it's a failed drive */ |
| 2584 | |
| 2585 | if ( |
| 2586 | test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) { |
| 2587 | pr_debug("Read_old stripe %llu " |
| 2588 | "block %d for Reconstruct\n", |
| 2589 | (unsigned long long)sh->sector, i); |
| 2590 | set_bit(R5_LOCKED, &dev->flags); |
| 2591 | set_bit(R5_Wantread, &dev->flags); |
| 2592 | s->locked++; |
| 2593 | } else { |
| 2594 | pr_debug("Request delayed stripe %llu " |
| 2595 | "block %d for Reconstruct\n", |
| 2596 | (unsigned long long)sh->sector, i); |
| 2597 | set_bit(STRIPE_DELAYED, &sh->state); |
| 2598 | set_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2602 | /* now if nothing is locked, and if we have enough data, we can start a |
| 2603 | * write request |
| 2604 | */ |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2605 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 2606 | s->locked == 0 && rcw == 0 && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2607 | !test_bit(STRIPE_BIT_DELAY, &sh->state)) { |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 2608 | schedule_reconstruction(sh, s, 1, 0); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | static void handle_parity_checks5(raid5_conf_t *conf, struct stripe_head *sh, |
| 2613 | struct stripe_head_state *s, int disks) |
| 2614 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2615 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2616 | |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2617 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2618 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2619 | switch (sh->check_state) { |
| 2620 | case check_state_idle: |
| 2621 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2622 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2623 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2624 | sh->check_state = check_state_run; |
| 2625 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2626 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2627 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2628 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 2629 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2630 | dev = &sh->dev[s->failed_num]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2631 | /* fall through */ |
| 2632 | case check_state_compute_result: |
| 2633 | sh->check_state = check_state_idle; |
| 2634 | if (!dev) |
| 2635 | dev = &sh->dev[sh->pd_idx]; |
| 2636 | |
| 2637 | /* check that a write has not made the stripe insync */ |
| 2638 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2639 | break; |
| 2640 | |
| 2641 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2642 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 2643 | BUG_ON(s->uptodate != disks); |
| 2644 | |
| 2645 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2646 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2647 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2648 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2649 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2650 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2651 | break; |
| 2652 | case check_state_run: |
| 2653 | break; /* we will be called again upon completion */ |
| 2654 | case check_state_check_result: |
| 2655 | sh->check_state = check_state_idle; |
| 2656 | |
| 2657 | /* if a failure occurred during the check operation, leave |
| 2658 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 2659 | */ |
| 2660 | if (s->failed) |
| 2661 | break; |
| 2662 | |
| 2663 | /* handle a successful check operation, if parity is correct |
| 2664 | * we are done. Otherwise update the mismatch count and repair |
| 2665 | * parity if !MD_RECOVERY_CHECK |
| 2666 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 2667 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2668 | /* parity is correct (on disc, |
| 2669 | * not in buffer any more) |
| 2670 | */ |
| 2671 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2672 | else { |
| 2673 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2674 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2675 | /* don't try to repair!! */ |
| 2676 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2677 | else { |
| 2678 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 2679 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2680 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2681 | set_bit(R5_Wantcompute, |
| 2682 | &sh->dev[sh->pd_idx].flags); |
| 2683 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2684 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2685 | s->uptodate++; |
| 2686 | } |
| 2687 | } |
| 2688 | break; |
| 2689 | case check_state_compute_run: |
| 2690 | break; |
| 2691 | default: |
| 2692 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2693 | __func__, sh->check_state, |
| 2694 | (unsigned long long) sh->sector); |
| 2695 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | |
| 2700 | 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] | 2701 | struct stripe_head_state *s, |
| 2702 | struct r6_state *r6s, int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2703 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2704 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2705 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2706 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2707 | |
| 2708 | set_bit(STRIPE_HANDLE, &sh->state); |
| 2709 | |
| 2710 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2711 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2712 | /* Want to check and possibly repair P and Q. |
| 2713 | * However there could be one 'failed' device, in which |
| 2714 | * case we can only check one of them, possibly using the |
| 2715 | * other to generate missing data |
| 2716 | */ |
| 2717 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2718 | switch (sh->check_state) { |
| 2719 | case check_state_idle: |
| 2720 | /* start a new check operation if there are < 2 failures */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2721 | if (s->failed == r6s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2722 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2723 | * makes sense to check P (If anything else were failed, |
| 2724 | * we would have used P to recreate it). |
| 2725 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2726 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2727 | } |
| 2728 | if (!r6s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2729 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2730 | * anything, so it makes sense to check it |
| 2731 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2732 | if (sh->check_state == check_state_run) |
| 2733 | sh->check_state = check_state_run_pq; |
| 2734 | else |
| 2735 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2736 | } |
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 | /* discard potentially stale zero_sum_result */ |
| 2739 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2740 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2741 | if (sh->check_state == check_state_run) { |
| 2742 | /* async_xor_zero_sum destroys the contents of P */ |
| 2743 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 2744 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2745 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2746 | if (sh->check_state >= check_state_run && |
| 2747 | sh->check_state <= check_state_run_pq) { |
| 2748 | /* async_syndrome_zero_sum preserves P and Q, so |
| 2749 | * no need to mark them !uptodate here |
| 2750 | */ |
| 2751 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 2752 | break; |
| 2753 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2754 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2755 | /* we have 2-disk failure */ |
| 2756 | BUG_ON(s->failed != 2); |
| 2757 | /* fall through */ |
| 2758 | case check_state_compute_result: |
| 2759 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 2760 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2761 | /* check that a write has not made the stripe insync */ |
| 2762 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 2763 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2764 | |
| 2765 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2766 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2767 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2768 | 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] | 2769 | if (s->failed == 2) { |
| 2770 | dev = &sh->dev[r6s->failed_num[1]]; |
| 2771 | s->locked++; |
| 2772 | set_bit(R5_LOCKED, &dev->flags); |
| 2773 | set_bit(R5_Wantwrite, &dev->flags); |
| 2774 | } |
| 2775 | if (s->failed >= 1) { |
| 2776 | dev = &sh->dev[r6s->failed_num[0]]; |
| 2777 | s->locked++; |
| 2778 | set_bit(R5_LOCKED, &dev->flags); |
| 2779 | set_bit(R5_Wantwrite, &dev->flags); |
| 2780 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2781 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2782 | dev = &sh->dev[pd_idx]; |
| 2783 | s->locked++; |
| 2784 | set_bit(R5_LOCKED, &dev->flags); |
| 2785 | set_bit(R5_Wantwrite, &dev->flags); |
| 2786 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2787 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2788 | dev = &sh->dev[qd_idx]; |
| 2789 | s->locked++; |
| 2790 | set_bit(R5_LOCKED, &dev->flags); |
| 2791 | set_bit(R5_Wantwrite, &dev->flags); |
| 2792 | } |
| 2793 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 2794 | |
| 2795 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 2796 | break; |
| 2797 | case check_state_run: |
| 2798 | case check_state_run_q: |
| 2799 | case check_state_run_pq: |
| 2800 | break; /* we will be called again upon completion */ |
| 2801 | case check_state_check_result: |
| 2802 | sh->check_state = check_state_idle; |
| 2803 | |
| 2804 | /* handle a successful check operation, if parity is correct |
| 2805 | * we are done. Otherwise update the mismatch count and repair |
| 2806 | * parity if !MD_RECOVERY_CHECK |
| 2807 | */ |
| 2808 | if (sh->ops.zero_sum_result == 0) { |
| 2809 | /* both parities are correct */ |
| 2810 | if (!s->failed) |
| 2811 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2812 | else { |
| 2813 | /* in contrast to the raid5 case we can validate |
| 2814 | * parity, but still have a failure to write |
| 2815 | * back |
| 2816 | */ |
| 2817 | sh->check_state = check_state_compute_result; |
| 2818 | /* Returning at this point means that we may go |
| 2819 | * off and bring p and/or q uptodate again so |
| 2820 | * we make sure to check zero_sum_result again |
| 2821 | * to verify if p or q need writeback |
| 2822 | */ |
| 2823 | } |
| 2824 | } else { |
| 2825 | conf->mddev->resync_mismatches += STRIPE_SECTORS; |
| 2826 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 2827 | /* don't try to repair!! */ |
| 2828 | set_bit(STRIPE_INSYNC, &sh->state); |
| 2829 | else { |
| 2830 | int *target = &sh->ops.target; |
| 2831 | |
| 2832 | sh->ops.target = -1; |
| 2833 | sh->ops.target2 = -1; |
| 2834 | sh->check_state = check_state_compute_run; |
| 2835 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 2836 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 2837 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 2838 | set_bit(R5_Wantcompute, |
| 2839 | &sh->dev[pd_idx].flags); |
| 2840 | *target = pd_idx; |
| 2841 | target = &sh->ops.target2; |
| 2842 | s->uptodate++; |
| 2843 | } |
| 2844 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 2845 | set_bit(R5_Wantcompute, |
| 2846 | &sh->dev[qd_idx].flags); |
| 2847 | *target = qd_idx; |
| 2848 | s->uptodate++; |
| 2849 | } |
| 2850 | } |
| 2851 | } |
| 2852 | break; |
| 2853 | case check_state_compute_run: |
| 2854 | break; |
| 2855 | default: |
| 2856 | printk(KERN_ERR "%s: unknown check_state: %d sector: %llu\n", |
| 2857 | __func__, sh->check_state, |
| 2858 | (unsigned long long) sh->sector); |
| 2859 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | static void handle_stripe_expansion(raid5_conf_t *conf, struct stripe_head *sh, |
| 2864 | struct r6_state *r6s) |
| 2865 | { |
| 2866 | int i; |
| 2867 | |
| 2868 | /* We have read all the blocks in this stripe and now we need to |
| 2869 | * copy some of them into a target stripe for expand. |
| 2870 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2871 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2872 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 2873 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 2874 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2875 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2876 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2877 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2878 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2879 | sector_t bn = compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2880 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 2881 | &dd_idx, NULL); |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 2882 | sh2 = get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2883 | if (sh2 == NULL) |
| 2884 | /* so far only the early blocks of this stripe |
| 2885 | * have been requested. When later blocks |
| 2886 | * get requested, we will try again |
| 2887 | */ |
| 2888 | continue; |
| 2889 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 2890 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 2891 | /* must have already done this block */ |
| 2892 | release_stripe(sh2); |
| 2893 | continue; |
| 2894 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2895 | |
| 2896 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2897 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2898 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 2899 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2900 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2901 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2902 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 2903 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 2904 | for (j = 0; j < conf->raid_disks; j++) |
| 2905 | if (j != sh2->pd_idx && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2906 | (!r6s || j != sh2->qd_idx) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2907 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 2908 | break; |
| 2909 | if (j == conf->raid_disks) { |
| 2910 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 2911 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 2912 | } |
| 2913 | release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2914 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2915 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 2916 | /* done submitting copies, wait for them to complete */ |
| 2917 | if (tx) { |
| 2918 | async_tx_ack(tx); |
| 2919 | dma_wait_for_async_tx(tx); |
| 2920 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | /* |
| 2925 | * handle_stripe - do things to a stripe. |
| 2926 | * |
| 2927 | * We lock the stripe and then examine the state of various bits |
| 2928 | * to see what needs to be done. |
| 2929 | * Possible results: |
| 2930 | * return some read request which now have data |
| 2931 | * return some write requests which are safely on disc |
| 2932 | * schedule a read on some buffers |
| 2933 | * schedule a write of some buffers |
| 2934 | * return confirmation of parity correctness |
| 2935 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | * buffers are taken off read_list or write_list, and bh_cache buffers |
| 2937 | * get BH_Lock set before the stripe lock is released. |
| 2938 | * |
| 2939 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2940 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 2941 | static void handle_stripe5(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | { |
| 2943 | raid5_conf_t *conf = sh->raid_conf; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2944 | int disks = sh->disks, i; |
| 2945 | struct bio *return_bi = NULL; |
| 2946 | struct stripe_head_state s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | struct r5dev *dev; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 2948 | mdk_rdev_t *blocked_rdev = NULL; |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 2949 | int prexor; |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 2950 | int dec_preread_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2952 | memset(&s, 0, sizeof(s)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2953 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d check:%d " |
| 2954 | "reconstruct:%d\n", (unsigned long long)sh->sector, sh->state, |
| 2955 | atomic_read(&sh->count), sh->pd_idx, sh->check_state, |
| 2956 | sh->reconstruct_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | |
| 2958 | spin_lock(&sh->lock); |
| 2959 | clear_bit(STRIPE_HANDLE, &sh->state); |
| 2960 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 2961 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2962 | s.syncing = test_bit(STRIPE_SYNCING, &sh->state); |
| 2963 | s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 2964 | s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | /* Now to look around and see what can be done */ |
NeilBrown | 9910f16 | 2006-01-06 00:20:24 -0800 | [diff] [blame] | 2967 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | for (i=disks; i--; ) { |
| 2969 | mdk_rdev_t *rdev; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 2970 | |
| 2971 | dev = &sh->dev[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | clear_bit(R5_Insync, &dev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2974 | pr_debug("check %d: state 0x%lx toread %p read %p write %p " |
| 2975 | "written %p\n", i, dev->flags, dev->toread, dev->read, |
| 2976 | dev->towrite, dev->written); |
| 2977 | |
| 2978 | /* maybe we can request a biofill operation |
| 2979 | * |
| 2980 | * new wantfill requests are only permitted while |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2981 | * ops_complete_biofill is guaranteed to be inactive |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2982 | */ |
| 2983 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2984 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2985 | set_bit(R5_Wantfill, &dev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | |
| 2987 | /* now count some things */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2988 | if (test_bit(R5_LOCKED, &dev->flags)) s.locked++; |
| 2989 | if (test_bit(R5_UPTODATE, &dev->flags)) s.uptodate++; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2990 | if (test_bit(R5_Wantcompute, &dev->flags)) s.compute++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 2992 | if (test_bit(R5_Wantfill, &dev->flags)) |
| 2993 | s.to_fill++; |
| 2994 | else if (dev->toread) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2995 | s.to_read++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | if (dev->towrite) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2997 | s.to_write++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2999 | s.non_overwrite++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3001 | if (dev->written) |
| 3002 | s.written++; |
NeilBrown | 9910f16 | 2006-01-06 00:20:24 -0800 | [diff] [blame] | 3003 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3004 | if (blocked_rdev == NULL && |
| 3005 | rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3006 | blocked_rdev = rdev; |
| 3007 | atomic_inc(&rdev->nr_pending); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3008 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3009 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 14f8d26 | 2006-01-06 00:20:14 -0800 | [diff] [blame] | 3010 | /* The ReadError flag will just be confusing now */ |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3011 | clear_bit(R5_ReadError, &dev->flags); |
| 3012 | clear_bit(R5_ReWrite, &dev->flags); |
| 3013 | } |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3014 | if (!rdev || !test_bit(In_sync, &rdev->flags) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3015 | || test_bit(R5_ReadError, &dev->flags)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3016 | s.failed++; |
| 3017 | s.failed_num = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | } else |
| 3019 | set_bit(R5_Insync, &dev->flags); |
| 3020 | } |
NeilBrown | 9910f16 | 2006-01-06 00:20:24 -0800 | [diff] [blame] | 3021 | rcu_read_unlock(); |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3022 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3023 | if (unlikely(blocked_rdev)) { |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3024 | if (s.syncing || s.expanding || s.expanded || |
| 3025 | s.to_write || s.written) { |
| 3026 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3027 | goto unlock; |
| 3028 | } |
| 3029 | /* There is nothing for the blocked_rdev to block */ |
| 3030 | rdev_dec_pending(blocked_rdev, conf->mddev); |
| 3031 | blocked_rdev = NULL; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 3034 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3035 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3036 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3037 | } |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3038 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3039 | pr_debug("locked=%d uptodate=%d to_read=%d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | " to_write=%d failed=%d failed_num=%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3041 | s.locked, s.uptodate, s.to_read, s.to_write, |
| 3042 | s.failed, s.failed_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | /* check if the array has lost two devices and, if so, some requests might |
| 3044 | * need to be failed |
| 3045 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3046 | if (s.failed > 1 && s.to_read+s.to_write+s.written) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3047 | handle_failed_stripe(conf, sh, &s, disks, &return_bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3048 | if (s.failed > 1 && s.syncing) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | md_done_sync(conf->mddev, STRIPE_SECTORS,0); |
| 3050 | clear_bit(STRIPE_SYNCING, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3051 | s.syncing = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | /* might be able to return some write requests if the parity block |
| 3055 | * is safe, or on a failed drive |
| 3056 | */ |
| 3057 | dev = &sh->dev[sh->pd_idx]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3058 | if ( s.written && |
| 3059 | ((test_bit(R5_Insync, &dev->flags) && |
| 3060 | !test_bit(R5_LOCKED, &dev->flags) && |
| 3061 | test_bit(R5_UPTODATE, &dev->flags)) || |
| 3062 | (s.failed == 1 && s.failed_num == sh->pd_idx))) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3063 | handle_stripe_clean_event(conf, sh, disks, &return_bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
| 3065 | /* Now we might consider reading some blocks, either to check/generate |
| 3066 | * parity, or to satisfy requests |
| 3067 | * or to load a block that is being partially written. |
| 3068 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3069 | if (s.to_read || s.non_overwrite || |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3070 | (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3071 | handle_stripe_fill5(sh, &s, disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3073 | /* Now we check to see if any write operations have recently |
| 3074 | * completed |
| 3075 | */ |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 3076 | prexor = 0; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3077 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 3078 | prexor = 1; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3079 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 3080 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3081 | sh->reconstruct_state = reconstruct_state_idle; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3082 | |
| 3083 | /* All the 'written' buffers and the parity block are ready to |
| 3084 | * be written back to disk |
| 3085 | */ |
| 3086 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); |
| 3087 | for (i = disks; i--; ) { |
| 3088 | dev = &sh->dev[i]; |
| 3089 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3090 | (i == sh->pd_idx || dev->written)) { |
| 3091 | pr_debug("Writing block %d\n", i); |
| 3092 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | e0a115e | 2008-06-05 22:45:52 -0700 | [diff] [blame] | 3093 | if (prexor) |
| 3094 | continue; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3095 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3096 | (i == sh->pd_idx && s.failed == 0)) |
| 3097 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3098 | } |
| 3099 | } |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3100 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3101 | dec_preread_active = 1; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | /* Now to consider new write requests and what else, if anything |
| 3105 | * should be read. We do not handle new writes when: |
| 3106 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 3107 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3108 | * block. |
| 3109 | */ |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3110 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3111 | handle_stripe_dirtying5(conf, sh, &s, disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | |
| 3113 | /* 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] | 3114 | * Any reads will already have been scheduled, so we just see if enough |
| 3115 | * data is available. The parity check is held off while parity |
| 3116 | * dependent operations are in flight. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | */ |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3118 | if (sh->check_state || |
| 3119 | (s.syncing && s.locked == 0 && |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3120 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3121 | !test_bit(STRIPE_INSYNC, &sh->state))) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3122 | handle_parity_checks5(conf, sh, &s, disks); |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3123 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3124 | if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | md_done_sync(conf->mddev, STRIPE_SECTORS,1); |
| 3126 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 3127 | } |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3128 | |
| 3129 | /* If the failed drive is just a ReadError, then we might need to progress |
| 3130 | * the repair/check process |
| 3131 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3132 | if (s.failed == 1 && !conf->mddev->ro && |
| 3133 | test_bit(R5_ReadError, &sh->dev[s.failed_num].flags) |
| 3134 | && !test_bit(R5_LOCKED, &sh->dev[s.failed_num].flags) |
| 3135 | && test_bit(R5_UPTODATE, &sh->dev[s.failed_num].flags) |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3136 | ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3137 | dev = &sh->dev[s.failed_num]; |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3138 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3139 | set_bit(R5_Wantwrite, &dev->flags); |
| 3140 | set_bit(R5_ReWrite, &dev->flags); |
| 3141 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3142 | s.locked++; |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3143 | } else { |
| 3144 | /* let's read it back */ |
| 3145 | set_bit(R5_Wantread, &dev->flags); |
| 3146 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3147 | s.locked++; |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3151 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3152 | if (sh->reconstruct_state == reconstruct_state_result) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3153 | struct stripe_head *sh2 |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3154 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3155 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { |
| 3156 | /* sh cannot be written until sh2 has been read. |
| 3157 | * so arrange for sh to be delayed a little |
| 3158 | */ |
| 3159 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3160 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3161 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3162 | &sh2->state)) |
| 3163 | atomic_inc(&conf->preread_active_stripes); |
| 3164 | release_stripe(sh2); |
| 3165 | goto unlock; |
| 3166 | } |
| 3167 | if (sh2) |
| 3168 | release_stripe(sh2); |
| 3169 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3170 | sh->reconstruct_state = reconstruct_state_idle; |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3171 | clear_bit(STRIPE_EXPANDING, &sh->state); |
Dan Williams | 2339788 | 2008-07-23 20:05:34 -0700 | [diff] [blame] | 3172 | for (i = conf->raid_disks; i--; ) { |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3173 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
Dan Williams | 2339788 | 2008-07-23 20:05:34 -0700 | [diff] [blame] | 3174 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
Neil Brown | efe3114 | 2008-06-28 08:31:14 +1000 | [diff] [blame] | 3175 | s.locked++; |
Dan Williams | 2339788 | 2008-07-23 20:05:34 -0700 | [diff] [blame] | 3176 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3180 | !sh->reconstruct_state) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3181 | /* Need to write out all blocks after computing parity */ |
| 3182 | sh->disks = conf->raid_disks; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3183 | stripe_set_idx(sh->sector, conf, 0, sh); |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3184 | schedule_reconstruction(sh, &s, 1, 1); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3185 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3186 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 3187 | atomic_dec(&conf->reshape_stripes); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3188 | wake_up(&conf->wait_for_overlap); |
| 3189 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3190 | } |
| 3191 | |
Dan Williams | 0f94e87 | 2008-01-08 15:32:53 -0800 | [diff] [blame] | 3192 | if (s.expanding && s.locked == 0 && |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3193 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3194 | handle_stripe_expansion(conf, sh, NULL); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3195 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3196 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | spin_unlock(&sh->lock); |
| 3198 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3199 | /* wait for this device to become unblocked */ |
| 3200 | if (unlikely(blocked_rdev)) |
| 3201 | md_wait_for_blocked_rdev(blocked_rdev, conf->mddev); |
| 3202 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3203 | if (s.ops_request) |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 3204 | raid_run_ops(sh, s.ops_request); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3205 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 3206 | ops_run_io(sh, &s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3208 | if (dec_preread_active) { |
| 3209 | /* We delay this until after ops_run_io so that if make_request |
| 3210 | * is waiting on a barrier, it won't continue until the writes |
| 3211 | * have actually been submitted. |
| 3212 | */ |
| 3213 | atomic_dec(&conf->preread_active_stripes); |
| 3214 | if (atomic_read(&conf->preread_active_stripes) < |
| 3215 | IO_THRESHOLD) |
| 3216 | md_wakeup_thread(conf->mddev->thread); |
| 3217 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3218 | return_io(return_bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3221 | static void handle_stripe6(struct stripe_head *sh) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3222 | { |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 3223 | raid5_conf_t *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3224 | int disks = sh->disks; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3225 | struct bio *return_bi = NULL; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3226 | int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3227 | struct stripe_head_state s; |
| 3228 | struct r6_state r6s; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3229 | struct r5dev *dev, *pdev, *qdev; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3230 | mdk_rdev_t *blocked_rdev = NULL; |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3231 | int dec_preread_active = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3232 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3233 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3234 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3235 | (unsigned long long)sh->sector, sh->state, |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3236 | atomic_read(&sh->count), pd_idx, qd_idx, |
| 3237 | sh->check_state, sh->reconstruct_state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3238 | memset(&s, 0, sizeof(s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3239 | |
| 3240 | spin_lock(&sh->lock); |
| 3241 | clear_bit(STRIPE_HANDLE, &sh->state); |
| 3242 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3243 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3244 | s.syncing = test_bit(STRIPE_SYNCING, &sh->state); |
| 3245 | s.expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 3246 | s.expanded = test_bit(STRIPE_EXPAND_READY, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3247 | /* Now to look around and see what can be done */ |
| 3248 | |
| 3249 | rcu_read_lock(); |
| 3250 | for (i=disks; i--; ) { |
| 3251 | mdk_rdev_t *rdev; |
| 3252 | dev = &sh->dev[i]; |
| 3253 | clear_bit(R5_Insync, &dev->flags); |
| 3254 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3255 | 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] | 3256 | i, dev->flags, dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3257 | /* maybe we can reply to a read |
| 3258 | * |
| 3259 | * new wantfill requests are only permitted while |
| 3260 | * ops_complete_biofill is guaranteed to be inactive |
| 3261 | */ |
| 3262 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 3263 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 3264 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3265 | |
| 3266 | /* now count some things */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3267 | if (test_bit(R5_LOCKED, &dev->flags)) s.locked++; |
| 3268 | if (test_bit(R5_UPTODATE, &dev->flags)) s.uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 3269 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
| 3270 | s.compute++; |
| 3271 | BUG_ON(s.compute > 2); |
| 3272 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3273 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3274 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 3275 | s.to_fill++; |
| 3276 | } else if (dev->toread) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3277 | s.to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3278 | if (dev->towrite) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3279 | s.to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3280 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3281 | s.non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3282 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3283 | if (dev->written) |
| 3284 | s.written++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3285 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3286 | if (blocked_rdev == NULL && |
| 3287 | rdev && unlikely(test_bit(Blocked, &rdev->flags))) { |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3288 | blocked_rdev = rdev; |
| 3289 | atomic_inc(&rdev->nr_pending); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3290 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3291 | if (!rdev || !test_bit(In_sync, &rdev->flags)) { |
| 3292 | /* The ReadError flag will just be confusing now */ |
| 3293 | clear_bit(R5_ReadError, &dev->flags); |
| 3294 | clear_bit(R5_ReWrite, &dev->flags); |
| 3295 | } |
| 3296 | if (!rdev || !test_bit(In_sync, &rdev->flags) |
| 3297 | || test_bit(R5_ReadError, &dev->flags)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3298 | if (s.failed < 2) |
| 3299 | r6s.failed_num[s.failed] = i; |
| 3300 | s.failed++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3301 | } else |
| 3302 | set_bit(R5_Insync, &dev->flags); |
| 3303 | } |
| 3304 | rcu_read_unlock(); |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3305 | |
| 3306 | if (unlikely(blocked_rdev)) { |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3307 | if (s.syncing || s.expanding || s.expanded || |
| 3308 | s.to_write || s.written) { |
| 3309 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3310 | goto unlock; |
| 3311 | } |
| 3312 | /* There is nothing for the blocked_rdev to block */ |
| 3313 | rdev_dec_pending(blocked_rdev, conf->mddev); |
| 3314 | blocked_rdev = NULL; |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3315 | } |
NeilBrown | ac4090d | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 3316 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3317 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 3318 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 3319 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 3320 | } |
| 3321 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3322 | pr_debug("locked=%d uptodate=%d to_read=%d" |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3323 | " to_write=%d failed=%d failed_num=%d,%d\n", |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3324 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 3325 | r6s.failed_num[0], r6s.failed_num[1]); |
| 3326 | /* check if the array has lost >2 devices and, if so, some requests |
| 3327 | * might need to be failed |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3328 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3329 | if (s.failed > 2 && s.to_read+s.to_write+s.written) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3330 | handle_failed_stripe(conf, sh, &s, disks, &return_bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3331 | if (s.failed > 2 && s.syncing) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3332 | md_done_sync(conf->mddev, STRIPE_SECTORS,0); |
| 3333 | clear_bit(STRIPE_SYNCING, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3334 | s.syncing = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3335 | } |
| 3336 | |
| 3337 | /* |
| 3338 | * might be able to return some write requests if the parity blocks |
| 3339 | * are safe, or on a failed drive |
| 3340 | */ |
| 3341 | pdev = &sh->dev[pd_idx]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3342 | r6s.p_failed = (s.failed >= 1 && r6s.failed_num[0] == pd_idx) |
| 3343 | || (s.failed >= 2 && r6s.failed_num[1] == pd_idx); |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 3344 | qdev = &sh->dev[qd_idx]; |
| 3345 | r6s.q_failed = (s.failed >= 1 && r6s.failed_num[0] == qd_idx) |
| 3346 | || (s.failed >= 2 && r6s.failed_num[1] == qd_idx); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3347 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3348 | if ( s.written && |
| 3349 | ( r6s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3350 | && !test_bit(R5_LOCKED, &pdev->flags) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3351 | && test_bit(R5_UPTODATE, &pdev->flags)))) && |
| 3352 | ( r6s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3353 | && !test_bit(R5_LOCKED, &qdev->flags) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3354 | && test_bit(R5_UPTODATE, &qdev->flags))))) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3355 | handle_stripe_clean_event(conf, sh, disks, &return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3356 | |
| 3357 | /* Now we might consider reading some blocks, either to check/generate |
| 3358 | * parity, or to satisfy requests |
| 3359 | * or to load a block that is being partially written. |
| 3360 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3361 | if (s.to_read || s.non_overwrite || (s.to_write && s.failed) || |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3362 | (s.syncing && (s.uptodate + s.compute < disks)) || s.expanding) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3363 | handle_stripe_fill6(sh, &s, &r6s, disks); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3364 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3365 | /* Now we check to see if any write operations have recently |
| 3366 | * completed |
| 3367 | */ |
| 3368 | if (sh->reconstruct_state == reconstruct_state_drain_result) { |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3369 | |
| 3370 | sh->reconstruct_state = reconstruct_state_idle; |
| 3371 | /* All the 'written' buffers and the parity blocks are ready to |
| 3372 | * be written back to disk |
| 3373 | */ |
| 3374 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); |
| 3375 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags)); |
| 3376 | for (i = disks; i--; ) { |
| 3377 | dev = &sh->dev[i]; |
| 3378 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 3379 | (i == sh->pd_idx || i == qd_idx || |
| 3380 | dev->written)) { |
| 3381 | pr_debug("Writing block %d\n", i); |
| 3382 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 3383 | set_bit(R5_Wantwrite, &dev->flags); |
| 3384 | if (!test_bit(R5_Insync, &dev->flags) || |
| 3385 | ((i == sh->pd_idx || i == qd_idx) && |
| 3386 | s.failed == 0)) |
| 3387 | set_bit(STRIPE_INSYNC, &sh->state); |
| 3388 | } |
| 3389 | } |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3390 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3391 | dec_preread_active = 1; |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Yuri Tikhonov | a9b39a7 | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3394 | /* Now to consider new write requests and what else, if anything |
| 3395 | * should be read. We do not handle new writes when: |
| 3396 | * 1/ A 'write' operation (copy+gen_syndrome) is already in flight. |
| 3397 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 3398 | * block. |
| 3399 | */ |
| 3400 | if (s.to_write && !sh->reconstruct_state && !sh->check_state) |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3401 | handle_stripe_dirtying6(conf, sh, &s, &r6s, disks); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3402 | |
| 3403 | /* 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] | 3404 | * 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] | 3405 | * data is available. The parity check is held off while parity |
| 3406 | * dependent operations are in flight. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3407 | */ |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3408 | if (sh->check_state || |
| 3409 | (s.syncing && s.locked == 0 && |
| 3410 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 3411 | !test_bit(STRIPE_INSYNC, &sh->state))) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 3412 | handle_parity_checks6(conf, sh, &s, &r6s, disks); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3413 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3414 | if (s.syncing && s.locked == 0 && test_bit(STRIPE_INSYNC, &sh->state)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3415 | md_done_sync(conf->mddev, STRIPE_SECTORS,1); |
| 3416 | clear_bit(STRIPE_SYNCING, &sh->state); |
| 3417 | } |
| 3418 | |
| 3419 | /* If the failed drives are just a ReadError, then we might need |
| 3420 | * to progress the repair/check process |
| 3421 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3422 | if (s.failed <= 2 && !conf->mddev->ro) |
| 3423 | for (i = 0; i < s.failed; i++) { |
| 3424 | dev = &sh->dev[r6s.failed_num[i]]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3425 | if (test_bit(R5_ReadError, &dev->flags) |
| 3426 | && !test_bit(R5_LOCKED, &dev->flags) |
| 3427 | && test_bit(R5_UPTODATE, &dev->flags) |
| 3428 | ) { |
| 3429 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 3430 | set_bit(R5_Wantwrite, &dev->flags); |
| 3431 | set_bit(R5_ReWrite, &dev->flags); |
| 3432 | set_bit(R5_LOCKED, &dev->flags); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3433 | s.locked++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3434 | } else { |
| 3435 | /* let's read it back */ |
| 3436 | set_bit(R5_Wantread, &dev->flags); |
| 3437 | set_bit(R5_LOCKED, &dev->flags); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3438 | s.locked++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3442 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3443 | /* Finish reconstruct operations initiated by the expansion process */ |
| 3444 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 3445 | sh->reconstruct_state = reconstruct_state_idle; |
| 3446 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 3447 | for (i = conf->raid_disks; i--; ) { |
| 3448 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 3449 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 3450 | s.locked++; |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 3455 | !sh->reconstruct_state) { |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3456 | struct stripe_head *sh2 |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3457 | = get_active_stripe(conf, sh->sector, 1, 1, 1); |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 3458 | if (sh2 && test_bit(STRIPE_EXPAND_SOURCE, &sh2->state)) { |
| 3459 | /* sh cannot be written until sh2 has been read. |
| 3460 | * so arrange for sh to be delayed a little |
| 3461 | */ |
| 3462 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3463 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3464 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 3465 | &sh2->state)) |
| 3466 | atomic_inc(&conf->preread_active_stripes); |
| 3467 | release_stripe(sh2); |
| 3468 | goto unlock; |
| 3469 | } |
| 3470 | if (sh2) |
| 3471 | release_stripe(sh2); |
| 3472 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3473 | /* Need to write out all blocks after computing P&Q */ |
| 3474 | sh->disks = conf->raid_disks; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3475 | stripe_set_idx(sh->sector, conf, 0, sh); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3476 | schedule_reconstruction(sh, &s, 1, 1); |
| 3477 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3478 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 3479 | atomic_dec(&conf->reshape_stripes); |
| 3480 | wake_up(&conf->wait_for_overlap); |
| 3481 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 3482 | } |
| 3483 | |
Dan Williams | 0f94e87 | 2008-01-08 15:32:53 -0800 | [diff] [blame] | 3484 | if (s.expanding && s.locked == 0 && |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3485 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3486 | handle_stripe_expansion(conf, sh, &r6s); |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 3487 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3488 | unlock: |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3489 | spin_unlock(&sh->lock); |
| 3490 | |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 3491 | /* wait for this device to become unblocked */ |
| 3492 | if (unlikely(blocked_rdev)) |
| 3493 | md_wait_for_blocked_rdev(blocked_rdev, conf->mddev); |
| 3494 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 3495 | if (s.ops_request) |
| 3496 | raid_run_ops(sh, s.ops_request); |
| 3497 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 3498 | ops_run_io(sh, &s); |
| 3499 | |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 3500 | |
| 3501 | if (dec_preread_active) { |
| 3502 | /* We delay this until after ops_run_io so that if make_request |
| 3503 | * is waiting on a barrier, it won't continue until the writes |
| 3504 | * have actually been submitted. |
| 3505 | */ |
| 3506 | atomic_dec(&conf->preread_active_stripes); |
| 3507 | if (atomic_read(&conf->preread_active_stripes) < |
| 3508 | IO_THRESHOLD) |
| 3509 | md_wakeup_thread(conf->mddev->thread); |
| 3510 | } |
| 3511 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3512 | return_io(return_bi); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3515 | static void handle_stripe(struct stripe_head *sh) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3516 | { |
| 3517 | if (sh->raid_conf->level == 6) |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3518 | handle_stripe6(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3519 | else |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 3520 | handle_stripe5(sh); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3523 | static void raid5_activate_delayed(raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | { |
| 3525 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 3526 | while (!list_empty(&conf->delayed_list)) { |
| 3527 | struct list_head *l = conf->delayed_list.next; |
| 3528 | struct stripe_head *sh; |
| 3529 | sh = list_entry(l, struct stripe_head, lru); |
| 3530 | list_del_init(l); |
| 3531 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 3532 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3533 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3534 | list_add_tail(&sh->lru, &conf->hold_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | } |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 3536 | } else |
| 3537 | blk_plug_device(conf->mddev->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3540 | static void activate_bit_delay(raid5_conf_t *conf) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3541 | { |
| 3542 | /* device_lock is held */ |
| 3543 | struct list_head head; |
| 3544 | list_add(&head, &conf->bitmap_list); |
| 3545 | list_del_init(&conf->bitmap_list); |
| 3546 | while (!list_empty(&head)) { |
| 3547 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
| 3548 | list_del_init(&sh->lru); |
| 3549 | atomic_inc(&sh->count); |
| 3550 | __release_stripe(conf, sh); |
| 3551 | } |
| 3552 | } |
| 3553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | static void unplug_slaves(mddev_t *mddev) |
| 3555 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3556 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | int i; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 3558 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | |
| 3560 | rcu_read_lock(); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 3561 | for (i = 0; i < devs; i++) { |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 3562 | mdk_rdev_t *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 3563 | if (rdev && !test_bit(Faulty, &rdev->flags) && atomic_read(&rdev->nr_pending)) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3564 | struct request_queue *r_queue = bdev_get_queue(rdev->bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | |
| 3566 | atomic_inc(&rdev->nr_pending); |
| 3567 | rcu_read_unlock(); |
| 3568 | |
Alan D. Brunelle | 2ad8b1e | 2007-11-07 14:26:56 -0500 | [diff] [blame] | 3569 | blk_unplug(r_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | |
| 3571 | rdev_dec_pending(rdev, mddev); |
| 3572 | rcu_read_lock(); |
| 3573 | } |
| 3574 | } |
| 3575 | rcu_read_unlock(); |
| 3576 | } |
| 3577 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3578 | static void raid5_unplug_device(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | { |
| 3580 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3581 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | unsigned long flags; |
| 3583 | |
| 3584 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3585 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3586 | if (blk_remove_plug(q)) { |
| 3587 | conf->seq_flush++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3588 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | md_wakeup_thread(mddev->thread); |
| 3591 | |
| 3592 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3593 | |
| 3594 | unplug_slaves(mddev); |
| 3595 | } |
| 3596 | |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3597 | static int raid5_congested(void *data, int bits) |
| 3598 | { |
| 3599 | mddev_t *mddev = data; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3600 | raid5_conf_t *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3601 | |
| 3602 | /* No difference between reads and writes. Just check |
| 3603 | * how busy the stripe_cache is |
| 3604 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 3605 | |
| 3606 | if (mddev_congested(mddev, bits)) |
| 3607 | return 1; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 3608 | if (conf->inactive_blocked) |
| 3609 | return 1; |
| 3610 | if (conf->quiesce) |
| 3611 | return 1; |
| 3612 | if (list_empty_careful(&conf->inactive_list)) |
| 3613 | return 1; |
| 3614 | |
| 3615 | return 0; |
| 3616 | } |
| 3617 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3618 | /* We want read requests to align with chunks where possible, |
| 3619 | * but write requests don't need to. |
| 3620 | */ |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3621 | static int raid5_mergeable_bvec(struct request_queue *q, |
| 3622 | struct bvec_merge_data *bvm, |
| 3623 | struct bio_vec *biovec) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3624 | { |
| 3625 | mddev_t *mddev = q->queuedata; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3626 | 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] | 3627 | int max; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3628 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3629 | unsigned int bio_sectors = bvm->bi_size >> 9; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3630 | |
Alasdair G Kergon | cc371e6 | 2008-07-03 09:53:43 +0200 | [diff] [blame] | 3631 | if ((bvm->bi_rw & 1) == WRITE) |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3632 | return biovec->bv_len; /* always allow writes to be mergeable */ |
| 3633 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3634 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3635 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 3636 | max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9; |
| 3637 | if (max < 0) max = 0; |
| 3638 | if (max <= biovec->bv_len && bio_sectors == 0) |
| 3639 | return biovec->bv_len; |
| 3640 | else |
| 3641 | return max; |
| 3642 | } |
| 3643 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3644 | |
| 3645 | static int in_chunk_boundary(mddev_t *mddev, struct bio *bio) |
| 3646 | { |
| 3647 | sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev); |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 3648 | unsigned int chunk_sectors = mddev->chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3649 | unsigned int bio_sectors = bio->bi_size >> 9; |
| 3650 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 3651 | if (mddev->new_chunk_sectors < mddev->chunk_sectors) |
| 3652 | chunk_sectors = mddev->new_chunk_sectors; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3653 | return chunk_sectors >= |
| 3654 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 3655 | } |
| 3656 | |
| 3657 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3658 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 3659 | * later sampled by raid5d. |
| 3660 | */ |
| 3661 | static void add_bio_to_retry(struct bio *bi,raid5_conf_t *conf) |
| 3662 | { |
| 3663 | unsigned long flags; |
| 3664 | |
| 3665 | spin_lock_irqsave(&conf->device_lock, flags); |
| 3666 | |
| 3667 | bi->bi_next = conf->retry_read_aligned_list; |
| 3668 | conf->retry_read_aligned_list = bi; |
| 3669 | |
| 3670 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 3671 | md_wakeup_thread(conf->mddev->thread); |
| 3672 | } |
| 3673 | |
| 3674 | |
| 3675 | static struct bio *remove_bio_from_retry(raid5_conf_t *conf) |
| 3676 | { |
| 3677 | struct bio *bi; |
| 3678 | |
| 3679 | bi = conf->retry_read_aligned; |
| 3680 | if (bi) { |
| 3681 | conf->retry_read_aligned = NULL; |
| 3682 | return bi; |
| 3683 | } |
| 3684 | bi = conf->retry_read_aligned_list; |
| 3685 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3686 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3687 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 3688 | /* |
| 3689 | * this sets the active strip count to 1 and the processed |
| 3690 | * strip count to zero (upper 8 bits) |
| 3691 | */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3692 | bi->bi_phys_segments = 1; /* biased count of active stripes */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | return bi; |
| 3696 | } |
| 3697 | |
| 3698 | |
| 3699 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3700 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 3701 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 3702 | * first). |
| 3703 | * If the read failed.. |
| 3704 | */ |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3705 | static void raid5_align_endio(struct bio *bi, int error) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3706 | { |
| 3707 | struct bio* raid_bi = bi->bi_private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3708 | mddev_t *mddev; |
| 3709 | raid5_conf_t *conf; |
| 3710 | int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); |
| 3711 | mdk_rdev_t *rdev; |
| 3712 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3713 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3714 | |
| 3715 | mddev = raid_bi->bi_bdev->bd_disk->queue->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3716 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3717 | rdev = (void*)raid_bi->bi_next; |
| 3718 | raid_bi->bi_next = NULL; |
| 3719 | |
| 3720 | rdev_dec_pending(rdev, conf->mddev); |
| 3721 | |
| 3722 | if (!error && uptodate) { |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3723 | bio_endio(raid_bi, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3724 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 3725 | wake_up(&conf->wait_for_stripe); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 3726 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3730 | 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] | 3731 | |
| 3732 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3733 | } |
| 3734 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3735 | static int bio_fits_rdev(struct bio *bi) |
| 3736 | { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3737 | struct request_queue *q = bdev_get_queue(bi->bi_bdev); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3738 | |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 3739 | if ((bi->bi_size>>9) > queue_max_sectors(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3740 | return 0; |
| 3741 | blk_recount_segments(q, bi); |
Martin K. Petersen | ae03bf6 | 2009-05-22 17:17:50 -0400 | [diff] [blame] | 3742 | if (bi->bi_phys_segments > queue_max_phys_segments(q)) |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3743 | return 0; |
| 3744 | |
| 3745 | if (q->merge_bvec_fn) |
| 3746 | /* it's too hard to apply the merge_bvec_fn at this stage, |
| 3747 | * just just give up |
| 3748 | */ |
| 3749 | return 0; |
| 3750 | |
| 3751 | return 1; |
| 3752 | } |
| 3753 | |
| 3754 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3755 | static int chunk_aligned_read(struct request_queue *q, struct bio * raid_bio) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3756 | { |
| 3757 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3758 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 8553fe7 | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 3759 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3760 | struct bio* align_bi; |
| 3761 | mdk_rdev_t *rdev; |
| 3762 | |
| 3763 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3764 | pr_debug("chunk_aligned_read : non aligned\n"); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3765 | return 0; |
| 3766 | } |
| 3767 | /* |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3768 | * use bio_clone to make a copy of the bio |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3769 | */ |
| 3770 | align_bi = bio_clone(raid_bio, GFP_NOIO); |
| 3771 | if (!align_bi) |
| 3772 | return 0; |
| 3773 | /* |
| 3774 | * set bi_end_io to a new function, and set bi_private to the |
| 3775 | * original bio. |
| 3776 | */ |
| 3777 | align_bi->bi_end_io = raid5_align_endio; |
| 3778 | align_bi->bi_private = raid_bio; |
| 3779 | /* |
| 3780 | * compute position |
| 3781 | */ |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3782 | align_bi->bi_sector = raid5_compute_sector(conf, raid_bio->bi_sector, |
| 3783 | 0, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3784 | &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3785 | |
| 3786 | rcu_read_lock(); |
| 3787 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 3788 | if (rdev && test_bit(In_sync, &rdev->flags)) { |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3789 | atomic_inc(&rdev->nr_pending); |
| 3790 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3791 | raid_bio->bi_next = (void*)rdev; |
| 3792 | align_bi->bi_bdev = rdev->bdev; |
| 3793 | align_bi->bi_flags &= ~(1 << BIO_SEG_VALID); |
| 3794 | align_bi->bi_sector += rdev->data_offset; |
| 3795 | |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 3796 | if (!bio_fits_rdev(align_bi)) { |
| 3797 | /* too big in some way */ |
| 3798 | bio_put(align_bi); |
| 3799 | rdev_dec_pending(rdev, mddev); |
| 3800 | return 0; |
| 3801 | } |
| 3802 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3803 | spin_lock_irq(&conf->device_lock); |
| 3804 | wait_event_lock_irq(conf->wait_for_stripe, |
| 3805 | conf->quiesce == 0, |
| 3806 | conf->device_lock, /* nothing */); |
| 3807 | atomic_inc(&conf->active_aligned_reads); |
| 3808 | spin_unlock_irq(&conf->device_lock); |
| 3809 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3810 | generic_make_request(align_bi); |
| 3811 | return 1; |
| 3812 | } else { |
| 3813 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 3814 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3815 | return 0; |
| 3816 | } |
| 3817 | } |
| 3818 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3819 | /* __get_priority_stripe - get the next stripe to process |
| 3820 | * |
| 3821 | * Full stripe writes are allowed to pass preread active stripes up until |
| 3822 | * the bypass_threshold is exceeded. In general the bypass_count |
| 3823 | * increments when the handle_list is handled before the hold_list; however, it |
| 3824 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 3825 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 3826 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 3827 | * handle_list. |
| 3828 | */ |
| 3829 | static struct stripe_head *__get_priority_stripe(raid5_conf_t *conf) |
| 3830 | { |
| 3831 | struct stripe_head *sh; |
| 3832 | |
| 3833 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 3834 | __func__, |
| 3835 | list_empty(&conf->handle_list) ? "empty" : "busy", |
| 3836 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 3837 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 3838 | |
| 3839 | if (!list_empty(&conf->handle_list)) { |
| 3840 | sh = list_entry(conf->handle_list.next, typeof(*sh), lru); |
| 3841 | |
| 3842 | if (list_empty(&conf->hold_list)) |
| 3843 | conf->bypass_count = 0; |
| 3844 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 3845 | if (conf->hold_list.next == conf->last_hold) |
| 3846 | conf->bypass_count++; |
| 3847 | else { |
| 3848 | conf->last_hold = conf->hold_list.next; |
| 3849 | conf->bypass_count -= conf->bypass_threshold; |
| 3850 | if (conf->bypass_count < 0) |
| 3851 | conf->bypass_count = 0; |
| 3852 | } |
| 3853 | } |
| 3854 | } else if (!list_empty(&conf->hold_list) && |
| 3855 | ((conf->bypass_threshold && |
| 3856 | conf->bypass_count > conf->bypass_threshold) || |
| 3857 | atomic_read(&conf->pending_full_writes) == 0)) { |
| 3858 | sh = list_entry(conf->hold_list.next, |
| 3859 | typeof(*sh), lru); |
| 3860 | conf->bypass_count -= conf->bypass_threshold; |
| 3861 | if (conf->bypass_count < 0) |
| 3862 | conf->bypass_count = 0; |
| 3863 | } else |
| 3864 | return NULL; |
| 3865 | |
| 3866 | list_del_init(&sh->lru); |
| 3867 | atomic_inc(&sh->count); |
| 3868 | BUG_ON(atomic_read(&sh->count) != 1); |
| 3869 | return sh; |
| 3870 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 3871 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3872 | static int make_request(struct request_queue *q, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | { |
| 3874 | mddev_t *mddev = q->queuedata; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 3875 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3876 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | sector_t new_sector; |
| 3878 | sector_t logical_sector, last_sector; |
| 3879 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 3880 | const int rw = bio_data_dir(bi); |
Tejun Heo | c995905 | 2008-08-25 19:47:21 +0900 | [diff] [blame] | 3881 | int cpu, remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | |
Jens Axboe | 1f98a13 | 2009-09-11 14:32:04 +0200 | [diff] [blame] | 3883 | if (unlikely(bio_rw_flagged(bi, BIO_RW_BARRIER))) { |
NeilBrown | a2826aa | 2009-12-14 12:49:49 +1100 | [diff] [blame] | 3884 | /* Drain all pending writes. We only really need |
| 3885 | * to ensure they have been submitted, but this is |
| 3886 | * easier. |
| 3887 | */ |
| 3888 | mddev->pers->quiesce(mddev, 1); |
| 3889 | mddev->pers->quiesce(mddev, 0); |
| 3890 | md_barrier_request(mddev, bi); |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 3891 | return 0; |
| 3892 | } |
| 3893 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 3894 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3895 | |
Tejun Heo | 074a7ac | 2008-08-25 19:56:14 +0900 | [diff] [blame] | 3896 | cpu = part_stat_lock(); |
| 3897 | part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); |
| 3898 | part_stat_add(cpu, &mddev->gendisk->part0, sectors[rw], |
| 3899 | bio_sectors(bi)); |
| 3900 | part_stat_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | |
NeilBrown | 802ba06 | 2006-12-13 00:34:13 -0800 | [diff] [blame] | 3902 | if (rw == READ && |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3903 | mddev->reshape_position == MaxSector && |
| 3904 | chunk_aligned_read(q,bi)) |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3905 | return 0; |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 3906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 3908 | last_sector = bi->bi_sector + (bi->bi_size>>9); |
| 3909 | bi->bi_next = NULL; |
| 3910 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 3911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
| 3913 | DEFINE_WAIT(w); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3914 | int disks, data_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3915 | int previous; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3916 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3917 | retry: |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3918 | previous = 0; |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3919 | disks = conf->raid_disks; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3920 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3921 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3922 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3923 | * 64bit on a 32bit platform, and so it might be |
| 3924 | * possible to see a half-updated value |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3925 | * Ofcourse reshape_progress could change after |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3926 | * the lock is dropped, so once we get a reference |
| 3927 | * to the stripe that we think it is, we will have |
| 3928 | * to check again. |
| 3929 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3930 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3931 | if (mddev->delta_disks < 0 |
| 3932 | ? logical_sector < conf->reshape_progress |
| 3933 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3934 | disks = conf->previous_raid_disks; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3935 | previous = 1; |
| 3936 | } else { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 3937 | if (mddev->delta_disks < 0 |
| 3938 | ? logical_sector < conf->reshape_safe |
| 3939 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 3940 | spin_unlock_irq(&conf->device_lock); |
| 3941 | schedule(); |
| 3942 | goto retry; |
| 3943 | } |
| 3944 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3945 | spin_unlock_irq(&conf->device_lock); |
| 3946 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3947 | data_disks = disks - conf->max_degraded; |
| 3948 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3949 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 3950 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3951 | &dd_idx, NULL); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3952 | pr_debug("raid5: make_request, sector %llu logical %llu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | (unsigned long long)new_sector, |
| 3954 | (unsigned long long)logical_sector); |
| 3955 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3956 | sh = get_active_stripe(conf, new_sector, previous, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 3957 | (bi->bi_rw&RWA_MASK), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3959 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3960 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f7 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 3961 | * stripe, so we must do the range check again. |
| 3962 | * Expansion could still move past after this |
| 3963 | * test, but as we are holding a reference to |
| 3964 | * 'sh', we know that if that happens, |
| 3965 | * STRIPE_EXPANDING will get set and the expansion |
| 3966 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3967 | */ |
| 3968 | int must_retry = 0; |
| 3969 | spin_lock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 3970 | if (mddev->delta_disks < 0 |
| 3971 | ? logical_sector >= conf->reshape_progress |
| 3972 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3973 | /* mismatch, need to try again */ |
| 3974 | must_retry = 1; |
| 3975 | spin_unlock_irq(&conf->device_lock); |
| 3976 | if (must_retry) { |
| 3977 | release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 3978 | schedule(); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3979 | goto retry; |
| 3980 | } |
| 3981 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3982 | |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3983 | if (bio_data_dir(bi) == WRITE && |
| 3984 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3985 | logical_sector < mddev->suspend_hi) { |
| 3986 | release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 3987 | /* As the suspend_* range is controlled by |
| 3988 | * userspace, we want an interruptible |
| 3989 | * wait. |
| 3990 | */ |
| 3991 | flush_signals(current); |
| 3992 | prepare_to_wait(&conf->wait_for_overlap, |
| 3993 | &w, TASK_INTERRUPTIBLE); |
| 3994 | if (logical_sector >= mddev->suspend_lo && |
| 3995 | logical_sector < mddev->suspend_hi) |
| 3996 | schedule(); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 3997 | goto retry; |
| 3998 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 3999 | |
| 4000 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
| 4001 | !add_stripe_bio(sh, bi, dd_idx, (bi->bi_rw&RW_MASK))) { |
| 4002 | /* Stripe is busy expanding or |
| 4003 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | * and wait a while |
| 4005 | */ |
| 4006 | raid5_unplug_device(mddev->queue); |
| 4007 | release_stripe(sh); |
| 4008 | schedule(); |
| 4009 | goto retry; |
| 4010 | } |
| 4011 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4012 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4013 | clear_bit(STRIPE_DELAYED, &sh->state); |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4014 | if (mddev->barrier && |
| 4015 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4016 | atomic_inc(&conf->preread_active_stripes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | } else { |
| 4019 | /* cannot get stripe for read-ahead, just give-up */ |
| 4020 | clear_bit(BIO_UPTODATE, &bi->bi_flags); |
| 4021 | finish_wait(&conf->wait_for_overlap, &w); |
| 4022 | break; |
| 4023 | } |
| 4024 | |
| 4025 | } |
| 4026 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4027 | remaining = raid5_dec_bi_phys_segments(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 4028 | spin_unlock_irq(&conf->device_lock); |
| 4029 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4031 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 4033 | |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4034 | bio_endio(bi, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | } |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4036 | |
| 4037 | if (mddev->barrier) { |
| 4038 | /* We need to wait for the stripes to all be handled. |
| 4039 | * So: wait for preread_active_stripes to drop to 0. |
| 4040 | */ |
| 4041 | wait_event(mddev->thread->wqueue, |
| 4042 | atomic_read(&conf->preread_active_stripes) == 0); |
| 4043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | return 0; |
| 4045 | } |
| 4046 | |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4047 | static sector_t raid5_size(mddev_t *mddev, sector_t sectors, int raid_disks); |
| 4048 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4049 | 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] | 4050 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4051 | /* reshaping is quite different to recovery/resync so it is |
| 4052 | * handled quite separately ... here. |
| 4053 | * |
| 4054 | * On each call to sync_request, we gather one chunk worth of |
| 4055 | * destination stripes and flag them as expanding. |
| 4056 | * Then we find all the source stripes and request reads. |
| 4057 | * As the reads complete, handle_stripe will copy the data |
| 4058 | * into the destination stripe and release that stripe. |
| 4059 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | raid5_conf_t *conf = (raid5_conf_t *) mddev->private; |
| 4061 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4062 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4063 | int raid_disks = conf->previous_raid_disks; |
| 4064 | int data_disks = raid_disks - conf->max_degraded; |
| 4065 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4066 | int i; |
| 4067 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4068 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4069 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4070 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4071 | struct list_head stripes; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4072 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4073 | if (sector_nr == 0) { |
| 4074 | /* If restarting in the middle, skip the initial sectors */ |
| 4075 | if (mddev->delta_disks < 0 && |
| 4076 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 4077 | sector_nr = raid5_size(mddev, 0, 0) |
| 4078 | - conf->reshape_progress; |
NeilBrown | a639755 | 2009-08-13 10:13:00 +1000 | [diff] [blame] | 4079 | } else if (mddev->delta_disks >= 0 && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4080 | conf->reshape_progress > 0) |
| 4081 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4082 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4083 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 4084 | mddev->curr_resync_completed = sector_nr; |
| 4085 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4086 | *skipped = 1; |
| 4087 | return sector_nr; |
| 4088 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4089 | } |
| 4090 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4091 | /* We need to process a full chunk at a time. |
| 4092 | * If old and new chunk sizes differ, we need to process the |
| 4093 | * largest of these |
| 4094 | */ |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4095 | if (mddev->new_chunk_sectors > mddev->chunk_sectors) |
| 4096 | reshape_sectors = mddev->new_chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4097 | else |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4098 | reshape_sectors = mddev->chunk_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4099 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4100 | /* we update the metadata when there is more than 3Meg |
| 4101 | * in the block range (that is rather arbitrary, should |
| 4102 | * probably be time based) or when the data about to be |
| 4103 | * copied would over-write the source of the data at |
| 4104 | * the front of the range. |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4105 | * i.e. one new_stripe along from reshape_progress new_maps |
| 4106 | * to after where reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4107 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4108 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4109 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4110 | readpos = conf->reshape_progress; |
| 4111 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4112 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4113 | sector_div(safepos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4114 | if (mddev->delta_disks < 0) { |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4115 | writepos -= min_t(sector_t, reshape_sectors, writepos); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4116 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4117 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4118 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4119 | writepos += reshape_sectors; |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 4120 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 4121 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4122 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4123 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4124 | /* 'writepos' is the most advanced device address we might write. |
| 4125 | * 'readpos' is the least advanced device address we might read. |
| 4126 | * 'safepos' is the least address recorded in the metadata as having |
| 4127 | * been reshaped. |
| 4128 | * If 'readpos' is behind 'writepos', then there is no way that we can |
| 4129 | * ensure safety in the face of a crash - that must be done by userspace |
| 4130 | * making a backup of the data. So in that case there is no particular |
| 4131 | * rush to update metadata. |
| 4132 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 4133 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 4134 | * we can be safe in the event of a crash. |
| 4135 | * So we insist on updating metadata if safepos is behind writepos and |
| 4136 | * readpos is beyond writepos. |
| 4137 | * In any case, update the metadata every 10 seconds. |
| 4138 | * Maybe that number should be configurable, but I'm not sure it is |
| 4139 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 4140 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4141 | if ((mddev->delta_disks < 0 |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4142 | ? (safepos > writepos && readpos < writepos) |
| 4143 | : (safepos < writepos && readpos > writepos)) || |
| 4144 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4145 | /* Cannot proceed until we've updated the superblock... */ |
| 4146 | wait_event(conf->wait_for_overlap, |
| 4147 | atomic_read(&conf->reshape_stripes)==0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4148 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4149 | mddev->curr_resync_completed = mddev->curr_resync; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4150 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4151 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4152 | md_wakeup_thread(mddev->thread); |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 4153 | wait_event(mddev->sb_wait, mddev->flags == 0 || |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4154 | kthread_should_stop()); |
| 4155 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4156 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4157 | spin_unlock_irq(&conf->device_lock); |
| 4158 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4159 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4160 | } |
| 4161 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4162 | if (mddev->delta_disks < 0) { |
| 4163 | BUG_ON(conf->reshape_progress == 0); |
| 4164 | stripe_addr = writepos; |
| 4165 | BUG_ON((mddev->dev_sectors & |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4166 | ~((sector_t)reshape_sectors - 1)) |
| 4167 | - reshape_sectors - stripe_addr |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4168 | != sector_nr); |
| 4169 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4170 | BUG_ON(writepos != sector_nr + reshape_sectors); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4171 | stripe_addr = sector_nr; |
| 4172 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4173 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4174 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4175 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4176 | int skipped_disk = 0; |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4177 | sh = get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4178 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 4179 | atomic_inc(&conf->reshape_stripes); |
| 4180 | /* If any of this stripe is beyond the end of the old |
| 4181 | * array, then we need to zero those blocks |
| 4182 | */ |
| 4183 | for (j=sh->disks; j--;) { |
| 4184 | sector_t s; |
| 4185 | if (j == sh->pd_idx) |
| 4186 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4187 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4188 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4189 | continue; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 4190 | s = compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 4191 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4192 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4193 | continue; |
| 4194 | } |
| 4195 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 4196 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 4197 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 4198 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 4199 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4200 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4201 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4202 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4203 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4204 | } |
| 4205 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4206 | if (mddev->delta_disks < 0) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4207 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4208 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4209 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4210 | spin_unlock_irq(&conf->device_lock); |
| 4211 | /* Ok, those stripe are ready. We can start scheduling |
| 4212 | * reads on the source stripes. |
| 4213 | * The source stripes are determined by mapping the first and last |
| 4214 | * block on the destination stripes. |
| 4215 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4216 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 4217 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4218 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4219 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 4220 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4221 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4222 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4223 | if (last_sector >= mddev->dev_sectors) |
| 4224 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4225 | while (first_sector <= last_sector) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4226 | sh = get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4227 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4228 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4229 | release_stripe(sh); |
| 4230 | first_sector += STRIPE_SECTORS; |
| 4231 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 4232 | /* Now that the sources are clearly marked, we can release |
| 4233 | * the destination stripes |
| 4234 | */ |
| 4235 | while (!list_empty(&stripes)) { |
| 4236 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 4237 | list_del_init(&sh->lru); |
| 4238 | release_stripe(sh); |
| 4239 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4240 | /* If this takes us to the resync_max point where we have to pause, |
| 4241 | * then we need to write out the superblock. |
| 4242 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4243 | sector_nr += reshape_sectors; |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 4244 | if ((sector_nr - mddev->curr_resync_completed) * 2 |
| 4245 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4246 | /* Cannot proceed until we've updated the superblock... */ |
| 4247 | wait_event(conf->wait_for_overlap, |
| 4248 | atomic_read(&conf->reshape_stripes) == 0); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4249 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 48606a9 | 2009-06-18 09:14:12 +1000 | [diff] [blame] | 4250 | mddev->curr_resync_completed = mddev->curr_resync + reshape_sectors; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 4251 | conf->reshape_checkpoint = jiffies; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4252 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 4253 | md_wakeup_thread(mddev->thread); |
| 4254 | wait_event(mddev->sb_wait, |
| 4255 | !test_bit(MD_CHANGE_DEVS, &mddev->flags) |
| 4256 | || kthread_should_stop()); |
| 4257 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4258 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4259 | spin_unlock_irq(&conf->device_lock); |
| 4260 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 4261 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4262 | } |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 4263 | return reshape_sectors; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | /* FIXME go_faster isn't used */ |
| 4267 | static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster) |
| 4268 | { |
| 4269 | raid5_conf_t *conf = (raid5_conf_t *) mddev->private; |
| 4270 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4271 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4272 | int sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4273 | int still_degraded = 0; |
| 4274 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4276 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | /* just being told to finish up .. nothing much to do */ |
| 4278 | unplug_slaves(mddev); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 4279 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 4280 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 4281 | end_reshape(conf); |
| 4282 | return 0; |
| 4283 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4284 | |
| 4285 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 4286 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 4287 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4288 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4289 | conf->fullsync = 0; |
| 4290 | bitmap_close_sync(mddev->bitmap); |
| 4291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | return 0; |
| 4293 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 4294 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 4295 | /* Allow raid5_quiesce to complete */ |
| 4296 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 4297 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 4298 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 4299 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4300 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 4301 | /* No need to check resync_max as we never do more than one |
| 4302 | * stripe, and as resync_max will always be on a chunk boundary, |
| 4303 | * if the check in md_do_sync didn't fire, there is no chance |
| 4304 | * of overstepping resync_max here |
| 4305 | */ |
| 4306 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4307 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | * to resync, then assert that we are finished, because there is |
| 4309 | * nothing we can do. |
| 4310 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 4311 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4312 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 4313 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 4314 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | return rv; |
| 4316 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4317 | if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
NeilBrown | 3855ad9 | 2005-11-08 21:39:38 -0800 | [diff] [blame] | 4318 | !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4319 | !conf->fullsync && sync_blocks >= STRIPE_SECTORS) { |
| 4320 | /* we can skip this block, and probably more */ |
| 4321 | sync_blocks /= STRIPE_SECTORS; |
| 4322 | *skipped = 1; |
| 4323 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 4324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 4326 | |
| 4327 | bitmap_cond_end_sync(mddev->bitmap, sector_nr); |
| 4328 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4329 | sh = get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | if (sh == NULL) { |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4331 | sh = get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4333 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 4335 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4337 | /* Need to check if array will still be degraded after recovery/resync |
| 4338 | * We don't need to check the 'failed' flag as when that gets set, |
| 4339 | * recovery aborts. |
| 4340 | */ |
NeilBrown | f001a70 | 2009-06-09 14:30:31 +1000 | [diff] [blame] | 4341 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4342 | if (conf->disks[i].rdev == NULL) |
| 4343 | still_degraded = 1; |
| 4344 | |
| 4345 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 4346 | |
| 4347 | spin_lock(&sh->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | set_bit(STRIPE_SYNCING, &sh->state); |
| 4349 | clear_bit(STRIPE_INSYNC, &sh->state); |
| 4350 | spin_unlock(&sh->lock); |
| 4351 | |
NeilBrown | 1442577 | 2009-10-16 15:55:25 +1100 | [diff] [blame] | 4352 | handle_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | release_stripe(sh); |
| 4354 | |
| 4355 | return STRIPE_SECTORS; |
| 4356 | } |
| 4357 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4358 | static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio) |
| 4359 | { |
| 4360 | /* We may not be able to submit a whole bio at once as there |
| 4361 | * may not be enough stripe_heads available. |
| 4362 | * We cannot pre-allocate enough stripe_heads as we may need |
| 4363 | * more than exist in the cache (if we allow ever large chunks). |
| 4364 | * So we do one stripe head at a time and record in |
| 4365 | * ->bi_hw_segments how many have been done. |
| 4366 | * |
| 4367 | * We *know* that this entire raid_bio is in one chunk, so |
| 4368 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 4369 | */ |
| 4370 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4371 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4372 | sector_t sector, logical_sector, last_sector; |
| 4373 | int scnt = 0; |
| 4374 | int remaining; |
| 4375 | int handled = 0; |
| 4376 | |
| 4377 | logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4378 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4379 | 0, &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4380 | last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9); |
| 4381 | |
| 4382 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4383 | logical_sector += STRIPE_SECTORS, |
| 4384 | sector += STRIPE_SECTORS, |
| 4385 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4386 | |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4387 | if (scnt < raid5_bi_hw_segments(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4388 | /* already done this stripe */ |
| 4389 | continue; |
| 4390 | |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 4391 | sh = get_active_stripe(conf, sector, 0, 1, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4392 | |
| 4393 | if (!sh) { |
| 4394 | /* failed to get a stripe - must wait */ |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4395 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4396 | conf->retry_read_aligned = raid_bio; |
| 4397 | return handled; |
| 4398 | } |
| 4399 | |
| 4400 | set_bit(R5_ReadError, &sh->dev[dd_idx].flags); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4401 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0)) { |
| 4402 | release_stripe(sh); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4403 | raid5_set_bi_hw_segments(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 4404 | conf->retry_read_aligned = raid_bio; |
| 4405 | return handled; |
| 4406 | } |
| 4407 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4408 | handle_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4409 | release_stripe(sh); |
| 4410 | handled++; |
| 4411 | } |
| 4412 | spin_lock_irq(&conf->device_lock); |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 4413 | remaining = raid5_dec_bi_phys_segments(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4414 | spin_unlock_irq(&conf->device_lock); |
Neil Brown | 0e13fe23 | 2008-06-28 08:31:20 +1000 | [diff] [blame] | 4415 | if (remaining == 0) |
| 4416 | bio_endio(raid_bio, 0); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4417 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
| 4418 | wake_up(&conf->wait_for_stripe); |
| 4419 | return handled; |
| 4420 | } |
| 4421 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | /* |
| 4424 | * This is our raid5 kernel thread. |
| 4425 | * |
| 4426 | * We scan the hash table for stripes which can be handled now. |
| 4427 | * During the scan, completed stripes are saved for us by the interrupt |
| 4428 | * handler, so that they will not have to wait for our next wakeup. |
| 4429 | */ |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 4430 | static void raid5d(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | { |
| 4432 | struct stripe_head *sh; |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4433 | raid5_conf_t *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4434 | int handled; |
| 4435 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4436 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | |
| 4438 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | |
| 4440 | handled = 0; |
| 4441 | spin_lock_irq(&conf->device_lock); |
| 4442 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4443 | struct bio *bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 4445 | if (conf->seq_flush != conf->seq_write) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4446 | int seq = conf->seq_flush; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4447 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4448 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 4449 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 4450 | conf->seq_write = seq; |
| 4451 | activate_bit_delay(conf); |
| 4452 | } |
| 4453 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 4454 | while ((bio = remove_bio_from_retry(conf))) { |
| 4455 | int ok; |
| 4456 | spin_unlock_irq(&conf->device_lock); |
| 4457 | ok = retry_aligned_read(conf, bio); |
| 4458 | spin_lock_irq(&conf->device_lock); |
| 4459 | if (!ok) |
| 4460 | break; |
| 4461 | handled++; |
| 4462 | } |
| 4463 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4464 | sh = __get_priority_stripe(conf); |
| 4465 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4466 | if (!sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | spin_unlock_irq(&conf->device_lock); |
| 4469 | |
| 4470 | handled++; |
Dan Williams | 417b8d4 | 2009-10-16 16:25:22 +1100 | [diff] [blame] | 4471 | handle_stripe(sh); |
| 4472 | release_stripe(sh); |
| 4473 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | |
| 4475 | spin_lock_irq(&conf->device_lock); |
| 4476 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4477 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | |
| 4479 | spin_unlock_irq(&conf->device_lock); |
| 4480 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 4481 | async_tx_issue_pending_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | unplug_slaves(mddev); |
| 4483 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4484 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4487 | static ssize_t |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4488 | raid5_show_stripe_cache_size(mddev_t *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4489 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4490 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4491 | if (conf) |
| 4492 | return sprintf(page, "%d\n", conf->max_nr_stripes); |
| 4493 | else |
| 4494 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | static ssize_t |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4498 | 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] | 4499 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4500 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4501 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4502 | int err; |
| 4503 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4504 | if (len >= PAGE_SIZE) |
| 4505 | return -EINVAL; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4506 | if (!conf) |
| 4507 | return -ENODEV; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4508 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4509 | if (strict_strtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4510 | return -EINVAL; |
| 4511 | if (new <= 16 || new > 32768) |
| 4512 | return -EINVAL; |
| 4513 | while (new < conf->max_nr_stripes) { |
| 4514 | if (drop_one_stripe(conf)) |
| 4515 | conf->max_nr_stripes--; |
| 4516 | else |
| 4517 | break; |
| 4518 | } |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 4519 | err = md_allow_write(mddev); |
| 4520 | if (err) |
| 4521 | return err; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4522 | while (new > conf->max_nr_stripes) { |
| 4523 | if (grow_one_stripe(conf)) |
| 4524 | conf->max_nr_stripes++; |
| 4525 | else break; |
| 4526 | } |
| 4527 | return len; |
| 4528 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4529 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4530 | static struct md_sysfs_entry |
| 4531 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 4532 | raid5_show_stripe_cache_size, |
| 4533 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4534 | |
| 4535 | static ssize_t |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4536 | raid5_show_preread_threshold(mddev_t *mddev, char *page) |
| 4537 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4538 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4539 | if (conf) |
| 4540 | return sprintf(page, "%d\n", conf->bypass_threshold); |
| 4541 | else |
| 4542 | return 0; |
| 4543 | } |
| 4544 | |
| 4545 | static ssize_t |
| 4546 | raid5_store_preread_threshold(mddev_t *mddev, const char *page, size_t len) |
| 4547 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4548 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4549 | unsigned long new; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4550 | if (len >= PAGE_SIZE) |
| 4551 | return -EINVAL; |
| 4552 | if (!conf) |
| 4553 | return -ENODEV; |
| 4554 | |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4555 | if (strict_strtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4556 | return -EINVAL; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 4557 | if (new > conf->max_nr_stripes) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4558 | return -EINVAL; |
| 4559 | conf->bypass_threshold = new; |
| 4560 | return len; |
| 4561 | } |
| 4562 | |
| 4563 | static struct md_sysfs_entry |
| 4564 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 4565 | S_IRUGO | S_IWUSR, |
| 4566 | raid5_show_preread_threshold, |
| 4567 | raid5_store_preread_threshold); |
| 4568 | |
| 4569 | static ssize_t |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4570 | stripe_cache_active_show(mddev_t *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4571 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4572 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4573 | if (conf) |
| 4574 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 4575 | else |
| 4576 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4577 | } |
| 4578 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 4579 | static struct md_sysfs_entry |
| 4580 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4581 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4582 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4583 | &raid5_stripecache_size.attr, |
| 4584 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 4585 | &raid5_preread_bypass_threshold.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4586 | NULL, |
| 4587 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 4588 | static struct attribute_group raid5_attrs_group = { |
| 4589 | .name = NULL, |
| 4590 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 4591 | }; |
| 4592 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4593 | static sector_t |
| 4594 | raid5_size(mddev_t *mddev, sector_t sectors, int raid_disks) |
| 4595 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 4596 | raid5_conf_t *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4597 | |
| 4598 | if (!sectors) |
| 4599 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4600 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 4601 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4602 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4603 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4604 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4605 | sectors &= ~((sector_t)mddev->new_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 4606 | return sectors * (raid_disks - conf->max_degraded); |
| 4607 | } |
| 4608 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4609 | static void raid5_free_percpu(raid5_conf_t *conf) |
| 4610 | { |
| 4611 | struct raid5_percpu *percpu; |
| 4612 | unsigned long cpu; |
| 4613 | |
| 4614 | if (!conf->percpu) |
| 4615 | return; |
| 4616 | |
| 4617 | get_online_cpus(); |
| 4618 | for_each_possible_cpu(cpu) { |
| 4619 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4620 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4621 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4622 | } |
| 4623 | #ifdef CONFIG_HOTPLUG_CPU |
| 4624 | unregister_cpu_notifier(&conf->cpu_notify); |
| 4625 | #endif |
| 4626 | put_online_cpus(); |
| 4627 | |
| 4628 | free_percpu(conf->percpu); |
| 4629 | } |
| 4630 | |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4631 | static void free_conf(raid5_conf_t *conf) |
| 4632 | { |
| 4633 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4634 | raid5_free_percpu(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4635 | kfree(conf->disks); |
| 4636 | kfree(conf->stripe_hashtbl); |
| 4637 | kfree(conf); |
| 4638 | } |
| 4639 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4640 | #ifdef CONFIG_HOTPLUG_CPU |
| 4641 | static int raid456_cpu_notify(struct notifier_block *nfb, unsigned long action, |
| 4642 | void *hcpu) |
| 4643 | { |
| 4644 | raid5_conf_t *conf = container_of(nfb, raid5_conf_t, cpu_notify); |
| 4645 | long cpu = (long)hcpu; |
| 4646 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 4647 | |
| 4648 | switch (action) { |
| 4649 | case CPU_UP_PREPARE: |
| 4650 | case CPU_UP_PREPARE_FROZEN: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4651 | if (conf->level == 6 && !percpu->spare_page) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4652 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4653 | if (!percpu->scribble) |
| 4654 | percpu->scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
| 4655 | |
| 4656 | if (!percpu->scribble || |
| 4657 | (conf->level == 6 && !percpu->spare_page)) { |
| 4658 | safe_put_page(percpu->spare_page); |
| 4659 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4660 | pr_err("%s: failed memory allocation for cpu%ld\n", |
| 4661 | __func__, cpu); |
| 4662 | return NOTIFY_BAD; |
| 4663 | } |
| 4664 | break; |
| 4665 | case CPU_DEAD: |
| 4666 | case CPU_DEAD_FROZEN: |
| 4667 | safe_put_page(percpu->spare_page); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4668 | kfree(percpu->scribble); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4669 | percpu->spare_page = NULL; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4670 | percpu->scribble = NULL; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4671 | break; |
| 4672 | default: |
| 4673 | break; |
| 4674 | } |
| 4675 | return NOTIFY_OK; |
| 4676 | } |
| 4677 | #endif |
| 4678 | |
| 4679 | static int raid5_alloc_percpu(raid5_conf_t *conf) |
| 4680 | { |
| 4681 | unsigned long cpu; |
| 4682 | struct page *spare_page; |
| 4683 | struct raid5_percpu *allcpus; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4684 | void *scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4685 | int err; |
| 4686 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4687 | allcpus = alloc_percpu(struct raid5_percpu); |
| 4688 | if (!allcpus) |
| 4689 | return -ENOMEM; |
| 4690 | conf->percpu = allcpus; |
| 4691 | |
| 4692 | get_online_cpus(); |
| 4693 | err = 0; |
| 4694 | for_each_present_cpu(cpu) { |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4695 | if (conf->level == 6) { |
| 4696 | spare_page = alloc_page(GFP_KERNEL); |
| 4697 | if (!spare_page) { |
| 4698 | err = -ENOMEM; |
| 4699 | break; |
| 4700 | } |
| 4701 | per_cpu_ptr(conf->percpu, cpu)->spare_page = spare_page; |
| 4702 | } |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4703 | scribble = kmalloc(conf->scribble_len, GFP_KERNEL); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4704 | if (!scribble) { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4705 | err = -ENOMEM; |
| 4706 | break; |
| 4707 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 4708 | per_cpu_ptr(conf->percpu, cpu)->scribble = scribble; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4709 | } |
| 4710 | #ifdef CONFIG_HOTPLUG_CPU |
| 4711 | conf->cpu_notify.notifier_call = raid456_cpu_notify; |
| 4712 | conf->cpu_notify.priority = 0; |
| 4713 | if (err == 0) |
| 4714 | err = register_cpu_notifier(&conf->cpu_notify); |
| 4715 | #endif |
| 4716 | put_online_cpus(); |
| 4717 | |
| 4718 | return err; |
| 4719 | } |
| 4720 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4721 | static raid5_conf_t *setup_conf(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | { |
| 4723 | raid5_conf_t *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4724 | int raid_disk, memory, max_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | mdk_rdev_t *rdev; |
| 4726 | struct disk_info *disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4728 | if (mddev->new_level != 5 |
| 4729 | && mddev->new_level != 4 |
| 4730 | && mddev->new_level != 6) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4731 | printk(KERN_ERR "raid5: %s: raid level not set to 4/5/6 (%d)\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4732 | mdname(mddev), mddev->new_level); |
| 4733 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4735 | if ((mddev->new_level == 5 |
| 4736 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 4737 | (mddev->new_level == 6 |
| 4738 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4739 | printk(KERN_ERR "raid5: %s: layout %d not supported\n", |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4740 | mdname(mddev), mddev->new_layout); |
| 4741 | return ERR_PTR(-EIO); |
| 4742 | } |
| 4743 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
| 4744 | printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n", |
| 4745 | mdname(mddev), mddev->raid_disks); |
| 4746 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4747 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4749 | if (!mddev->new_chunk_sectors || |
| 4750 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 4751 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4752 | printk(KERN_ERR "raid5: invalid chunk size %d for %s\n", |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4753 | mddev->new_chunk_sectors << 9, mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4754 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 4755 | } |
| 4756 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4757 | conf = kzalloc(sizeof(raid5_conf_t), GFP_KERNEL); |
| 4758 | if (conf == NULL) |
| 4759 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 4760 | spin_lock_init(&conf->device_lock); |
| 4761 | init_waitqueue_head(&conf->wait_for_stripe); |
| 4762 | init_waitqueue_head(&conf->wait_for_overlap); |
| 4763 | INIT_LIST_HEAD(&conf->handle_list); |
| 4764 | INIT_LIST_HEAD(&conf->hold_list); |
| 4765 | INIT_LIST_HEAD(&conf->delayed_list); |
| 4766 | INIT_LIST_HEAD(&conf->bitmap_list); |
| 4767 | INIT_LIST_HEAD(&conf->inactive_list); |
| 4768 | atomic_set(&conf->active_stripes, 0); |
| 4769 | atomic_set(&conf->preread_active_stripes, 0); |
| 4770 | atomic_set(&conf->active_aligned_reads, 0); |
| 4771 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4772 | |
| 4773 | conf->raid_disks = mddev->raid_disks; |
| 4774 | if (mddev->reshape_position == MaxSector) |
| 4775 | conf->previous_raid_disks = mddev->raid_disks; |
| 4776 | else |
| 4777 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4778 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
| 4779 | conf->scribble_len = scribble_len(max_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4780 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4781 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4782 | GFP_KERNEL); |
| 4783 | if (!conf->disks) |
| 4784 | goto abort; |
| 4785 | |
| 4786 | conf->mddev = mddev; |
| 4787 | |
| 4788 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 4789 | goto abort; |
| 4790 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4791 | conf->level = mddev->new_level; |
| 4792 | if (raid5_alloc_percpu(conf) != 0) |
| 4793 | goto abort; |
| 4794 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4795 | pr_debug("raid5: run(%s) called.\n", mdname(mddev)); |
| 4796 | |
| 4797 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 4798 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4799 | if (raid_disk >= max_disks |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4800 | || raid_disk < 0) |
| 4801 | continue; |
| 4802 | disk = conf->disks + raid_disk; |
| 4803 | |
| 4804 | disk->rdev = rdev; |
| 4805 | |
| 4806 | if (test_bit(In_sync, &rdev->flags)) { |
| 4807 | char b[BDEVNAME_SIZE]; |
| 4808 | printk(KERN_INFO "raid5: device %s operational as raid" |
| 4809 | " disk %d\n", bdevname(rdev->bdev,b), |
| 4810 | raid_disk); |
| 4811 | } else |
| 4812 | /* Cannot rely on bitmap to complete recovery */ |
| 4813 | conf->fullsync = 1; |
| 4814 | } |
| 4815 | |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4816 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4817 | conf->level = mddev->new_level; |
| 4818 | if (conf->level == 6) |
| 4819 | conf->max_degraded = 2; |
| 4820 | else |
| 4821 | conf->max_degraded = 1; |
| 4822 | conf->algorithm = mddev->new_layout; |
| 4823 | conf->max_nr_stripes = NR_STRIPES; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 4824 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4825 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 4826 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 4827 | conf->prev_algo = mddev->layout; |
| 4828 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4829 | |
| 4830 | memory = conf->max_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 4831 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4832 | if (grow_stripes(conf, conf->max_nr_stripes)) { |
| 4833 | printk(KERN_ERR |
| 4834 | "raid5: couldn't allocate %dkB for buffers\n", memory); |
| 4835 | goto abort; |
| 4836 | } else |
| 4837 | printk(KERN_INFO "raid5: allocated %dkB for %s\n", |
| 4838 | memory, mdname(mddev)); |
| 4839 | |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 4840 | conf->thread = md_register_thread(raid5d, mddev, NULL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4841 | if (!conf->thread) { |
| 4842 | printk(KERN_ERR |
| 4843 | "raid5: couldn't allocate thread for %s\n", |
| 4844 | mdname(mddev)); |
| 4845 | goto abort; |
| 4846 | } |
| 4847 | |
| 4848 | return conf; |
| 4849 | |
| 4850 | abort: |
| 4851 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 4852 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4853 | return ERR_PTR(-EIO); |
| 4854 | } else |
| 4855 | return ERR_PTR(-ENOMEM); |
| 4856 | } |
| 4857 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4858 | |
| 4859 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 4860 | { |
| 4861 | switch (algo) { |
| 4862 | case ALGORITHM_PARITY_0: |
| 4863 | if (raid_disk < max_degraded) |
| 4864 | return 1; |
| 4865 | break; |
| 4866 | case ALGORITHM_PARITY_N: |
| 4867 | if (raid_disk >= raid_disks - max_degraded) |
| 4868 | return 1; |
| 4869 | break; |
| 4870 | case ALGORITHM_PARITY_0_6: |
| 4871 | if (raid_disk == 0 || |
| 4872 | raid_disk == raid_disks - 1) |
| 4873 | return 1; |
| 4874 | break; |
| 4875 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 4876 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 4877 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 4878 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 4879 | if (raid_disk == raid_disks - 1) |
| 4880 | return 1; |
| 4881 | } |
| 4882 | return 0; |
| 4883 | } |
| 4884 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4885 | static int run(mddev_t *mddev) |
| 4886 | { |
| 4887 | raid5_conf_t *conf; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 4888 | int working_disks = 0, chunk_size; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4889 | int dirty_parity_disks = 0; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4890 | mdk_rdev_t *rdev; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4891 | sector_t reshape_offset = 0; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4892 | |
Andre Noll | 8c6ac86 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 4893 | if (mddev->recovery_cp != MaxSector) |
| 4894 | printk(KERN_NOTICE "raid5: %s is not clean" |
| 4895 | " -- starting background reconstruction\n", |
| 4896 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4897 | if (mddev->reshape_position != MaxSector) { |
| 4898 | /* Check that we can continue the reshape. |
| 4899 | * Currently only disks can change, it must |
| 4900 | * increase, and we must be past the point where |
| 4901 | * a stripe over-writes itself |
| 4902 | */ |
| 4903 | sector_t here_new, here_old; |
| 4904 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 4905 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4906 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 4907 | if (mddev->new_level != mddev->level) { |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4908 | printk(KERN_ERR "raid5: %s: unsupported reshape " |
| 4909 | "required - aborting.\n", |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4910 | mdname(mddev)); |
| 4911 | return -EINVAL; |
| 4912 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4913 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 4914 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4915 | * further up in new geometry must map after here in old |
| 4916 | * geometry. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4917 | */ |
| 4918 | here_new = mddev->reshape_position; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4919 | if (sector_div(here_new, mddev->new_chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4920 | (mddev->raid_disks - max_degraded))) { |
| 4921 | printk(KERN_ERR "raid5: reshape_position not " |
| 4922 | "on a stripe boundary\n"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4923 | return -EINVAL; |
| 4924 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4925 | reshape_offset = here_new * mddev->new_chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4926 | /* here_new is the stripe we will write to */ |
| 4927 | here_old = mddev->reshape_position; |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 4928 | sector_div(here_old, mddev->chunk_sectors * |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4929 | (old_disks-max_degraded)); |
| 4930 | /* here_old is the first stripe that we might need to read |
| 4931 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 4932 | if (mddev->delta_disks == 0) { |
| 4933 | /* We cannot be sure it is safe to start an in-place |
| 4934 | * reshape. It is only safe if user-space if monitoring |
| 4935 | * and taking constant backups. |
| 4936 | * mdadm always starts a situation like this in |
| 4937 | * readonly mode so it can take control before |
| 4938 | * allowing any writes. So just check for that. |
| 4939 | */ |
| 4940 | if ((here_new * mddev->new_chunk_sectors != |
| 4941 | here_old * mddev->chunk_sectors) || |
| 4942 | mddev->ro == 0) { |
| 4943 | printk(KERN_ERR "raid5: in-place reshape must be started" |
| 4944 | " in read-only mode - aborting\n"); |
| 4945 | return -EINVAL; |
| 4946 | } |
| 4947 | } else if (mddev->delta_disks < 0 |
| 4948 | ? (here_new * mddev->new_chunk_sectors <= |
| 4949 | here_old * mddev->chunk_sectors) |
| 4950 | : (here_new * mddev->new_chunk_sectors >= |
| 4951 | here_old * mddev->chunk_sectors)) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4952 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4953 | printk(KERN_ERR "raid5: reshape_position too early for " |
| 4954 | "auto-recovery - aborting.\n"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4955 | return -EINVAL; |
| 4956 | } |
| 4957 | printk(KERN_INFO "raid5: reshape will continue\n"); |
| 4958 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4959 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4960 | BUG_ON(mddev->level != mddev->new_level); |
| 4961 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 4962 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4963 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4966 | if (mddev->private == NULL) |
| 4967 | conf = setup_conf(mddev); |
| 4968 | else |
| 4969 | conf = mddev->private; |
| 4970 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4971 | if (IS_ERR(conf)) |
| 4972 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 4973 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4974 | mddev->thread = conf->thread; |
| 4975 | conf->thread = NULL; |
| 4976 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4979 | * 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] | 4980 | */ |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4981 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
| 4982 | if (rdev->raid_disk < 0) |
| 4983 | continue; |
| 4984 | if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 4985 | working_disks++; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 4986 | /* This disc is not fully in-sync. However if it |
| 4987 | * just stored parity (beyond the recovery_offset), |
| 4988 | * when we don't need to be concerned about the |
| 4989 | * array being dirty. |
| 4990 | * When reshape goes 'backwards', we never have |
| 4991 | * partially completed devices, so we only need |
| 4992 | * to worry about reshape going forwards. |
| 4993 | */ |
| 4994 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 4995 | if (mddev->major_version == 0 && |
| 4996 | mddev->minor_version > 90) |
| 4997 | rdev->recovery_offset = reshape_offset; |
| 4998 | |
| 4999 | printk("%d: w=%d pa=%d pr=%d m=%d a=%d r=%d op1=%d op2=%d\n", |
| 5000 | rdev->raid_disk, working_disks, conf->prev_algo, |
| 5001 | conf->previous_raid_disks, conf->max_degraded, |
| 5002 | conf->algorithm, conf->raid_disks, |
| 5003 | only_parity(rdev->raid_disk, |
| 5004 | conf->prev_algo, |
| 5005 | conf->previous_raid_disks, |
| 5006 | conf->max_degraded), |
| 5007 | only_parity(rdev->raid_disk, |
| 5008 | conf->algorithm, |
| 5009 | conf->raid_disks, |
| 5010 | conf->max_degraded)); |
| 5011 | if (rdev->recovery_offset < reshape_offset) { |
| 5012 | /* We need to check old and new layout */ |
| 5013 | if (!only_parity(rdev->raid_disk, |
| 5014 | conf->algorithm, |
| 5015 | conf->raid_disks, |
| 5016 | conf->max_degraded)) |
| 5017 | continue; |
| 5018 | } |
| 5019 | if (!only_parity(rdev->raid_disk, |
| 5020 | conf->prev_algo, |
| 5021 | conf->previous_raid_disks, |
| 5022 | conf->max_degraded)) |
| 5023 | continue; |
| 5024 | dirty_parity_disks++; |
| 5025 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5026 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 5027 | mddev->degraded = (max(conf->raid_disks, conf->previous_raid_disks) |
| 5028 | - working_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5030 | if (mddev->degraded > conf->max_degraded) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | printk(KERN_ERR "raid5: not enough operational devices for %s" |
| 5032 | " (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5033 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | goto abort; |
| 5035 | } |
| 5036 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5037 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5038 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5039 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 5040 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 5041 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8e | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 5043 | if (mddev->ok_start_degraded) |
| 5044 | printk(KERN_WARNING |
| 5045 | "raid5: starting dirty degraded array: %s" |
| 5046 | "- data corruption possible.\n", |
| 5047 | mdname(mddev)); |
| 5048 | else { |
| 5049 | printk(KERN_ERR |
| 5050 | "raid5: cannot start dirty degraded array for %s\n", |
| 5051 | mdname(mddev)); |
| 5052 | goto abort; |
| 5053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | if (mddev->degraded == 0) |
| 5057 | printk("raid5: raid level %d set %s active with %d out of %d" |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5058 | " devices, algorithm %d\n", conf->level, mdname(mddev), |
| 5059 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 5060 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | else |
| 5062 | printk(KERN_ALERT "raid5: raid level %d set %s active with %d" |
| 5063 | " out of %d devices, algorithm %d\n", conf->level, |
| 5064 | mdname(mddev), mddev->raid_disks - mddev->degraded, |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 5065 | mddev->raid_disks, mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | |
| 5067 | print_raid5_conf(conf); |
| 5068 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5069 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5070 | printk("...ok start reshape thread\n"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5071 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5072 | atomic_set(&conf->reshape_stripes, 0); |
| 5073 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5074 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5075 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5076 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5077 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5078 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5079 | } |
| 5080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | /* read-ahead size must cover two whole stripes, which is |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5082 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | */ |
| 5084 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5085 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 5086 | int stripe = data_disks * |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5087 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5089 | mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 5090 | } |
| 5091 | |
| 5092 | /* Ok, everything is just fine now */ |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5093 | if (sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
| 5094 | printk(KERN_WARNING |
| 5095 | "raid5: failed to create sysfs attributes for %s\n", |
| 5096 | mdname(mddev)); |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 5097 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5098 | mddev->queue->queue_lock = &conf->device_lock; |
| 5099 | |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 5100 | mddev->queue->unplug_fn = raid5_unplug_device; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5101 | mddev->queue->backing_dev_info.congested_data = mddev; |
NeilBrown | 041ae52 | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5102 | mddev->queue->backing_dev_info.congested_fn = raid5_congested; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5103 | |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5104 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 5105 | |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 5106 | blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 5107 | chunk_size = mddev->chunk_sectors << 9; |
| 5108 | blk_queue_io_min(mddev->queue, chunk_size); |
| 5109 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 5110 | (conf->raid_disks - conf->max_degraded)); |
| 5111 | |
| 5112 | list_for_each_entry(rdev, &mddev->disks, same_set) |
| 5113 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 5114 | rdev->data_offset << 9); |
Raz Ben-Jehuda(caro) | 23032a0 | 2006-12-10 02:20:45 -0800 | [diff] [blame] | 5115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | return 0; |
| 5117 | abort: |
NeilBrown | e0cf8f0 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5118 | md_unregister_thread(mddev->thread); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5119 | mddev->thread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | if (conf) { |
| 5121 | print_raid5_conf(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5122 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | } |
| 5124 | mddev->private = NULL; |
| 5125 | printk(KERN_ALERT "raid5: failed to run raid set %s\n", mdname(mddev)); |
| 5126 | return -EIO; |
| 5127 | } |
| 5128 | |
| 5129 | |
| 5130 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 5131 | static int stop(mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | { |
| 5133 | raid5_conf_t *conf = (raid5_conf_t *) mddev->private; |
| 5134 | |
| 5135 | md_unregister_thread(mddev->thread); |
| 5136 | mddev->thread = NULL; |
NeilBrown | 041ae52 | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5137 | mddev->queue->backing_dev_info.congested_fn = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 5139 | free_conf(conf); |
NeilBrown | ef286f6 | 2010-02-09 16:34:14 +1100 | [diff] [blame] | 5140 | mddev->private = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5141 | return 0; |
| 5142 | } |
| 5143 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5144 | #ifdef DEBUG |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5145 | static void print_sh(struct seq_file *seq, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | { |
| 5147 | int i; |
| 5148 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5149 | seq_printf(seq, "sh %llu, pd_idx %d, state %ld.\n", |
| 5150 | (unsigned long long)sh->sector, sh->pd_idx, sh->state); |
| 5151 | seq_printf(seq, "sh %llu, count %d.\n", |
| 5152 | (unsigned long long)sh->sector, atomic_read(&sh->count)); |
| 5153 | seq_printf(seq, "sh %llu, ", (unsigned long long)sh->sector); |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5154 | for (i = 0; i < sh->disks; i++) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5155 | seq_printf(seq, "(cache%d: %p %ld) ", |
| 5156 | i, sh->dev[i].page, sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5158 | seq_printf(seq, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5161 | static void printall(struct seq_file *seq, raid5_conf_t *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | { |
| 5163 | struct stripe_head *sh; |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 5164 | struct hlist_node *hn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | int i; |
| 5166 | |
| 5167 | spin_lock_irq(&conf->device_lock); |
| 5168 | for (i = 0; i < NR_HASH; i++) { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 5169 | hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | if (sh->raid_conf != conf) |
| 5171 | continue; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5172 | print_sh(seq, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | spin_unlock_irq(&conf->device_lock); |
| 5176 | } |
| 5177 | #endif |
| 5178 | |
NeilBrown | d710e13 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 5179 | static void status(struct seq_file *seq, mddev_t *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | { |
| 5181 | raid5_conf_t *conf = (raid5_conf_t *) mddev->private; |
| 5182 | int i; |
| 5183 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5184 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
| 5185 | mddev->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5186 | 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] | 5187 | for (i = 0; i < conf->raid_disks; i++) |
| 5188 | seq_printf (seq, "%s", |
| 5189 | conf->disks[i].rdev && |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5190 | test_bit(In_sync, &conf->disks[i].rdev->flags) ? "U" : "_"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | seq_printf (seq, "]"); |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5192 | #ifdef DEBUG |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5193 | seq_printf (seq, "\n"); |
| 5194 | printall(seq, conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5195 | #endif |
| 5196 | } |
| 5197 | |
| 5198 | static void print_raid5_conf (raid5_conf_t *conf) |
| 5199 | { |
| 5200 | int i; |
| 5201 | struct disk_info *tmp; |
| 5202 | |
| 5203 | printk("RAID5 conf printout:\n"); |
| 5204 | if (!conf) { |
| 5205 | printk("(conf==NULL)\n"); |
| 5206 | return; |
| 5207 | } |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 5208 | printk(" --- rd:%d wd:%d\n", conf->raid_disks, |
| 5209 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | |
| 5211 | for (i = 0; i < conf->raid_disks; i++) { |
| 5212 | char b[BDEVNAME_SIZE]; |
| 5213 | tmp = conf->disks + i; |
| 5214 | if (tmp->rdev) |
| 5215 | printk(" disk %d, o:%d, dev:%s\n", |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5216 | i, !test_bit(Faulty, &tmp->rdev->flags), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | bdevname(tmp->rdev->bdev,b)); |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | static int raid5_spare_active(mddev_t *mddev) |
| 5222 | { |
| 5223 | int i; |
| 5224 | raid5_conf_t *conf = mddev->private; |
| 5225 | struct disk_info *tmp; |
| 5226 | |
| 5227 | for (i = 0; i < conf->raid_disks; i++) { |
| 5228 | tmp = conf->disks + i; |
| 5229 | if (tmp->rdev |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5230 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5231 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
| 5232 | unsigned long flags; |
| 5233 | spin_lock_irqsave(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | mddev->degraded--; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5235 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | print_raid5_conf(conf); |
| 5239 | return 0; |
| 5240 | } |
| 5241 | |
| 5242 | static int raid5_remove_disk(mddev_t *mddev, int number) |
| 5243 | { |
| 5244 | raid5_conf_t *conf = mddev->private; |
| 5245 | int err = 0; |
| 5246 | mdk_rdev_t *rdev; |
| 5247 | struct disk_info *p = conf->disks + number; |
| 5248 | |
| 5249 | print_raid5_conf(conf); |
| 5250 | rdev = p->rdev; |
| 5251 | if (rdev) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5252 | if (number >= conf->raid_disks && |
| 5253 | conf->reshape_progress == MaxSector) |
| 5254 | clear_bit(In_sync, &rdev->flags); |
| 5255 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5256 | if (test_bit(In_sync, &rdev->flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | atomic_read(&rdev->nr_pending)) { |
| 5258 | err = -EBUSY; |
| 5259 | goto abort; |
| 5260 | } |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5261 | /* Only remove non-faulty devices if recovery |
| 5262 | * isn't possible. |
| 5263 | */ |
| 5264 | if (!test_bit(Faulty, &rdev->flags) && |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5265 | mddev->degraded <= conf->max_degraded && |
| 5266 | number < conf->raid_disks) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 5267 | err = -EBUSY; |
| 5268 | goto abort; |
| 5269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5270 | p->rdev = NULL; |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 5271 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | if (atomic_read(&rdev->nr_pending)) { |
| 5273 | /* lost the race, try later */ |
| 5274 | err = -EBUSY; |
| 5275 | p->rdev = rdev; |
| 5276 | } |
| 5277 | } |
| 5278 | abort: |
| 5279 | |
| 5280 | print_raid5_conf(conf); |
| 5281 | return err; |
| 5282 | } |
| 5283 | |
| 5284 | static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) |
| 5285 | { |
| 5286 | raid5_conf_t *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5287 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5288 | int disk; |
| 5289 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5290 | int first = 0; |
| 5291 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5293 | if (mddev->degraded > conf->max_degraded) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5295 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5297 | if (rdev->raid_disk >= 0) |
| 5298 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | |
| 5300 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5301 | * find the disk ... but prefer rdev->saved_raid_disk |
| 5302 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5304 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5305 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5306 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
| 5307 | disk = rdev->saved_raid_disk; |
| 5308 | else |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 5309 | disk = first; |
| 5310 | for ( ; disk <= last ; disk++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | if ((p=conf->disks + disk)->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 5312 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5314 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5315 | if (rdev->saved_raid_disk != disk) |
| 5316 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 5317 | rcu_assign_pointer(p->rdev, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | break; |
| 5319 | } |
| 5320 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5321 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | static int raid5_resize(mddev_t *mddev, sector_t sectors) |
| 5325 | { |
| 5326 | /* no resync is happening, and there is enough space |
| 5327 | * on all devices, so we can resize. |
| 5328 | * We need to make sure resync covers any new space. |
| 5329 | * If the array is shrinking we should possibly wait until |
| 5330 | * any io in the removed space completes, but it hardly seems |
| 5331 | * worth it. |
| 5332 | */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 5333 | sectors &= ~((sector_t)mddev->chunk_sectors - 1); |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 5334 | md_set_array_sectors(mddev, raid5_size(mddev, sectors, |
| 5335 | mddev->raid_disks)); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5336 | if (mddev->array_sectors > |
| 5337 | raid5_size(mddev, sectors, mddev->raid_disks)) |
| 5338 | return -EINVAL; |
Andre Noll | f233ea5 | 2008-07-21 17:05:22 +1000 | [diff] [blame] | 5339 | set_capacity(mddev->gendisk, mddev->array_sectors); |
Linus Torvalds | 44ce629 | 2007-05-09 18:51:36 -0700 | [diff] [blame] | 5340 | mddev->changed = 1; |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5341 | revalidate_disk(mddev->gendisk); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5342 | if (sectors > mddev->dev_sectors && mddev->recovery_cp == MaxSector) { |
| 5343 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 5345 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5346 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 5347 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5348 | return 0; |
| 5349 | } |
| 5350 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5351 | static int check_stripe_cache(mddev_t *mddev) |
| 5352 | { |
| 5353 | /* Can only proceed if there are plenty of stripe_heads. |
| 5354 | * We need a minimum of one full stripe,, and for sensible progress |
| 5355 | * it is best to have about 4 times that. |
| 5356 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 5357 | * allow for chunk sizes up to 256K, which is probably OK. |
| 5358 | * If the chunk size is greater, user-space should request more |
| 5359 | * stripe_heads first. |
| 5360 | */ |
| 5361 | raid5_conf_t *conf = mddev->private; |
| 5362 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5363 | > conf->max_nr_stripes || |
| 5364 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
| 5365 | > conf->max_nr_stripes) { |
| 5366 | printk(KERN_WARNING "raid5: reshape: not enough stripes. Needed %lu\n", |
| 5367 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 5368 | / STRIPE_SIZE)*4); |
| 5369 | return 0; |
| 5370 | } |
| 5371 | return 1; |
| 5372 | } |
| 5373 | |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5374 | static int check_reshape(mddev_t *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5375 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5376 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5377 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5378 | if (mddev->delta_disks == 0 && |
| 5379 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5380 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5381 | return 0; /* nothing to do */ |
NeilBrown | dba034e | 2008-08-05 15:54:13 +1000 | [diff] [blame] | 5382 | if (mddev->bitmap) |
| 5383 | /* Cannot grow a bitmap yet */ |
| 5384 | return -EBUSY; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5385 | if (mddev->degraded > conf->max_degraded) |
| 5386 | return -EINVAL; |
| 5387 | if (mddev->delta_disks < 0) { |
| 5388 | /* We might be able to shrink, but the devices must |
| 5389 | * be made bigger first. |
| 5390 | * For raid6, 4 is the minimum size. |
| 5391 | * Otherwise 2 is the minimum |
| 5392 | */ |
| 5393 | int min = 2; |
| 5394 | if (mddev->level == 6) |
| 5395 | min = 4; |
| 5396 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 5397 | return -EINVAL; |
| 5398 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5399 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5400 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5401 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5402 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5403 | return resize_stripes(conf, conf->raid_disks + mddev->delta_disks); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | static int raid5_start_reshape(mddev_t *mddev) |
| 5407 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5408 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5409 | mdk_rdev_t *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5410 | int spares = 0; |
| 5411 | int added_devices = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 5412 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5413 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5414 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5415 | return -EBUSY; |
| 5416 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 5417 | if (!check_stripe_cache(mddev)) |
| 5418 | return -ENOSPC; |
| 5419 | |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5420 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5421 | if (rdev->raid_disk < 0 && |
| 5422 | !test_bit(Faulty, &rdev->flags)) |
| 5423 | spares++; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5424 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5425 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5426 | /* Not enough devices even to make a degraded array |
| 5427 | * of that size |
| 5428 | */ |
| 5429 | return -EINVAL; |
| 5430 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5431 | /* Refuse to reduce size of the array. Any reductions in |
| 5432 | * array size must be through explicit setting of array_size |
| 5433 | * attribute. |
| 5434 | */ |
| 5435 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 5436 | < mddev->array_sectors) { |
| 5437 | printk(KERN_ERR "md: %s: array size must be reduced " |
| 5438 | "before number of disks\n", mdname(mddev)); |
| 5439 | return -EINVAL; |
| 5440 | } |
| 5441 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5442 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5443 | spin_lock_irq(&conf->device_lock); |
| 5444 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5445 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5446 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 5447 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5448 | conf->prev_algo = conf->algorithm; |
| 5449 | conf->algorithm = mddev->new_layout; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5450 | if (mddev->delta_disks < 0) |
| 5451 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 5452 | else |
| 5453 | conf->reshape_progress = 0; |
| 5454 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 5455 | conf->generation++; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5456 | spin_unlock_irq(&conf->device_lock); |
| 5457 | |
| 5458 | /* Add some new drives, as many as will fit. |
| 5459 | * We know there are enough to make the newly sized array work. |
| 5460 | */ |
Cheng Renquan | 159ec1f | 2009-01-09 08:31:08 +1100 | [diff] [blame] | 5461 | list_for_each_entry(rdev, &mddev->disks, same_set) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5462 | if (rdev->raid_disk < 0 && |
| 5463 | !test_bit(Faulty, &rdev->flags)) { |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 5464 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5465 | char nm[20]; |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5466 | if (rdev->raid_disk >= conf->previous_raid_disks) { |
NeilBrown | 7ef9014 | 2009-11-13 17:40:51 +1100 | [diff] [blame] | 5467 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5468 | added_devices++; |
| 5469 | } else |
NeilBrown | 7ef9014 | 2009-11-13 17:40:51 +1100 | [diff] [blame] | 5470 | rdev->recovery_offset = 0; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5471 | sprintf(nm, "rd%d", rdev->raid_disk); |
NeilBrown | 5e55e2f | 2007-03-26 21:32:14 -0800 | [diff] [blame] | 5472 | if (sysfs_create_link(&mddev->kobj, |
| 5473 | &rdev->kobj, nm)) |
| 5474 | printk(KERN_WARNING |
| 5475 | "raid5: failed to create " |
| 5476 | " link %s for %s\n", |
| 5477 | nm, mdname(mddev)); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5478 | } else |
| 5479 | break; |
| 5480 | } |
| 5481 | |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5482 | /* When a reshape changes the number of devices, ->degraded |
| 5483 | * is measured against the large of the pre and post number of |
| 5484 | * devices.*/ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5485 | if (mddev->delta_disks > 0) { |
| 5486 | spin_lock_irqsave(&conf->device_lock, flags); |
NeilBrown | 9eb07c2 | 2010-02-09 12:31:47 +1100 | [diff] [blame] | 5487 | mddev->degraded += (conf->raid_disks - conf->previous_raid_disks) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5488 | - added_devices; |
| 5489 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 5490 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5491 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 5492 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 850b2b4 | 2006-10-03 01:15:46 -0700 | [diff] [blame] | 5493 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5494 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5495 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 5496 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 5497 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 5498 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 5499 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 5500 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5501 | if (!mddev->sync_thread) { |
| 5502 | mddev->recovery = 0; |
| 5503 | spin_lock_irq(&conf->device_lock); |
| 5504 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5505 | conf->reshape_progress = MaxSector; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5506 | spin_unlock_irq(&conf->device_lock); |
| 5507 | return -EAGAIN; |
| 5508 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5509 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5510 | md_wakeup_thread(mddev->sync_thread); |
| 5511 | md_new_event(mddev); |
| 5512 | return 0; |
| 5513 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5514 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5515 | /* This is called from the reshape thread and should make any |
| 5516 | * changes needed in 'conf' |
| 5517 | */ |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5518 | static void end_reshape(raid5_conf_t *conf) |
| 5519 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5520 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5521 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5522 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5523 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5524 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5525 | conf->reshape_progress = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 5526 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5527 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5528 | |
| 5529 | /* read-ahead size must cover two whole stripes, which is |
| 5530 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 5531 | */ |
| 5532 | { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5533 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5534 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5535 | / PAGE_SIZE); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5536 | if (conf->mddev->queue->backing_dev_info.ra_pages < 2 * stripe) |
| 5537 | conf->mddev->queue->backing_dev_info.ra_pages = 2 * stripe; |
| 5538 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5539 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5540 | } |
| 5541 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5542 | /* This is called from the raid5d thread with mddev_lock held. |
| 5543 | * It makes config changes to the device. |
| 5544 | */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5545 | static void raid5_finish_reshape(mddev_t *mddev) |
| 5546 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5547 | raid5_conf_t *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5548 | |
| 5549 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 5550 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5551 | if (mddev->delta_disks > 0) { |
| 5552 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 5553 | set_capacity(mddev->gendisk, mddev->array_sectors); |
| 5554 | mddev->changed = 1; |
NeilBrown | 449aad3 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5555 | revalidate_disk(mddev->gendisk); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5556 | } else { |
| 5557 | int d; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5558 | mddev->degraded = conf->raid_disks; |
| 5559 | for (d = 0; d < conf->raid_disks ; d++) |
| 5560 | if (conf->disks[d].rdev && |
| 5561 | test_bit(In_sync, |
| 5562 | &conf->disks[d].rdev->flags)) |
| 5563 | mddev->degraded--; |
| 5564 | for (d = conf->raid_disks ; |
| 5565 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 5566 | d++) { |
| 5567 | mdk_rdev_t *rdev = conf->disks[d].rdev; |
| 5568 | if (rdev && raid5_remove_disk(mddev, d) == 0) { |
| 5569 | char nm[20]; |
| 5570 | sprintf(nm, "rd%d", rdev->raid_disk); |
| 5571 | sysfs_remove_link(&mddev->kobj, nm); |
| 5572 | rdev->raid_disk = -1; |
| 5573 | } |
| 5574 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5575 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5576 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5577 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5578 | mddev->reshape_position = MaxSector; |
| 5579 | mddev->delta_disks = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5580 | } |
| 5581 | } |
| 5582 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5583 | static void raid5_quiesce(mddev_t *mddev, int state) |
| 5584 | { |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5585 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5586 | |
| 5587 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5588 | case 2: /* resume for a suspend */ |
| 5589 | wake_up(&conf->wait_for_overlap); |
| 5590 | break; |
| 5591 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5592 | case 1: /* stop all writes */ |
| 5593 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5594 | /* '2' tells resync/reshape to pause so that all |
| 5595 | * active stripes can drain |
| 5596 | */ |
| 5597 | conf->quiesce = 2; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5598 | wait_event_lock_irq(conf->wait_for_stripe, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5599 | atomic_read(&conf->active_stripes) == 0 && |
| 5600 | atomic_read(&conf->active_aligned_reads) == 0, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5601 | conf->device_lock, /* nothing */); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5602 | conf->quiesce = 1; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5603 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 5604 | /* allow reshape to continue */ |
| 5605 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5606 | break; |
| 5607 | |
| 5608 | case 0: /* re-enable writes */ |
| 5609 | spin_lock_irq(&conf->device_lock); |
| 5610 | conf->quiesce = 0; |
| 5611 | wake_up(&conf->wait_for_stripe); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5612 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5613 | spin_unlock_irq(&conf->device_lock); |
| 5614 | break; |
| 5615 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5616 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 5617 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5618 | |
| 5619 | static void *raid5_takeover_raid1(mddev_t *mddev) |
| 5620 | { |
| 5621 | int chunksect; |
| 5622 | |
| 5623 | if (mddev->raid_disks != 2 || |
| 5624 | mddev->degraded > 1) |
| 5625 | return ERR_PTR(-EINVAL); |
| 5626 | |
| 5627 | /* Should check if there are write-behind devices? */ |
| 5628 | |
| 5629 | chunksect = 64*2; /* 64K by default */ |
| 5630 | |
| 5631 | /* The array must be an exact multiple of chunksize */ |
| 5632 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 5633 | chunksect >>= 1; |
| 5634 | |
| 5635 | if ((chunksect<<9) < STRIPE_SIZE) |
| 5636 | /* array size does not allow a suitable chunk size */ |
| 5637 | return ERR_PTR(-EINVAL); |
| 5638 | |
| 5639 | mddev->new_level = 5; |
| 5640 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 5641 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5642 | |
| 5643 | return setup_conf(mddev); |
| 5644 | } |
| 5645 | |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5646 | static void *raid5_takeover_raid6(mddev_t *mddev) |
| 5647 | { |
| 5648 | int new_layout; |
| 5649 | |
| 5650 | switch (mddev->layout) { |
| 5651 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 5652 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 5653 | break; |
| 5654 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 5655 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 5656 | break; |
| 5657 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 5658 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 5659 | break; |
| 5660 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 5661 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 5662 | break; |
| 5663 | case ALGORITHM_PARITY_0_6: |
| 5664 | new_layout = ALGORITHM_PARITY_0; |
| 5665 | break; |
| 5666 | case ALGORITHM_PARITY_N: |
| 5667 | new_layout = ALGORITHM_PARITY_N; |
| 5668 | break; |
| 5669 | default: |
| 5670 | return ERR_PTR(-EINVAL); |
| 5671 | } |
| 5672 | mddev->new_level = 5; |
| 5673 | mddev->new_layout = new_layout; |
| 5674 | mddev->delta_disks = -1; |
| 5675 | mddev->raid_disks -= 1; |
| 5676 | return setup_conf(mddev); |
| 5677 | } |
| 5678 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5679 | |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5680 | static int raid5_check_reshape(mddev_t *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5681 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5682 | /* For a 2-drive array, the layout and chunk size can be changed |
| 5683 | * immediately as not restriping is needed. |
| 5684 | * For larger arrays we record the new value - after validation |
| 5685 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5686 | */ |
NeilBrown | 070ec55 | 2009-06-16 16:54:21 +1000 | [diff] [blame] | 5687 | raid5_conf_t *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5688 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5689 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5690 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5691 | return -EINVAL; |
| 5692 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5693 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5694 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5695 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5696 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5697 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5698 | /* not factor of array size */ |
| 5699 | return -EINVAL; |
| 5700 | } |
| 5701 | |
| 5702 | /* They look valid */ |
| 5703 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5704 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5705 | /* can make the change immediately */ |
| 5706 | if (mddev->new_layout >= 0) { |
| 5707 | conf->algorithm = mddev->new_layout; |
| 5708 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5709 | } |
| 5710 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5711 | conf->chunk_sectors = new_chunk ; |
| 5712 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5713 | } |
| 5714 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 5715 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5716 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5717 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5718 | } |
| 5719 | |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5720 | static int raid6_check_reshape(mddev_t *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5721 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5722 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5723 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5724 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5725 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5726 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 5727 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5728 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5729 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5730 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 5731 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5732 | /* not factor of array size */ |
| 5733 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5734 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 5735 | |
| 5736 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5737 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 5738 | } |
| 5739 | |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5740 | static void *raid5_takeover(mddev_t *mddev) |
| 5741 | { |
| 5742 | /* raid5 can take over: |
| 5743 | * raid0 - if all devices are the same - make it a raid4 layout |
| 5744 | * raid1 - if there are two drives. We need to know the chunk size |
| 5745 | * raid4 - trivial - just use a raid4 layout. |
| 5746 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5747 | */ |
| 5748 | |
| 5749 | if (mddev->level == 1) |
| 5750 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 5751 | if (mddev->level == 4) { |
| 5752 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 5753 | mddev->new_level = 5; |
| 5754 | return setup_conf(mddev); |
| 5755 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 5756 | if (mddev->level == 6) |
| 5757 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5758 | |
| 5759 | return ERR_PTR(-EINVAL); |
| 5760 | } |
| 5761 | |
| 5762 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5763 | static struct mdk_personality raid5_personality; |
| 5764 | |
| 5765 | static void *raid6_takeover(mddev_t *mddev) |
| 5766 | { |
| 5767 | /* Currently can only take over a raid5. We map the |
| 5768 | * personality to an equivalent raid6 personality |
| 5769 | * with the Q block at the end. |
| 5770 | */ |
| 5771 | int new_layout; |
| 5772 | |
| 5773 | if (mddev->pers != &raid5_personality) |
| 5774 | return ERR_PTR(-EINVAL); |
| 5775 | if (mddev->degraded > 1) |
| 5776 | return ERR_PTR(-EINVAL); |
| 5777 | if (mddev->raid_disks > 253) |
| 5778 | return ERR_PTR(-EINVAL); |
| 5779 | if (mddev->raid_disks < 3) |
| 5780 | return ERR_PTR(-EINVAL); |
| 5781 | |
| 5782 | switch (mddev->layout) { |
| 5783 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 5784 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 5785 | break; |
| 5786 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 5787 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 5788 | break; |
| 5789 | case ALGORITHM_LEFT_SYMMETRIC: |
| 5790 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 5791 | break; |
| 5792 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 5793 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 5794 | break; |
| 5795 | case ALGORITHM_PARITY_0: |
| 5796 | new_layout = ALGORITHM_PARITY_0_6; |
| 5797 | break; |
| 5798 | case ALGORITHM_PARITY_N: |
| 5799 | new_layout = ALGORITHM_PARITY_N; |
| 5800 | break; |
| 5801 | default: |
| 5802 | return ERR_PTR(-EINVAL); |
| 5803 | } |
| 5804 | mddev->new_level = 6; |
| 5805 | mddev->new_layout = new_layout; |
| 5806 | mddev->delta_disks = 1; |
| 5807 | mddev->raid_disks += 1; |
| 5808 | return setup_conf(mddev); |
| 5809 | } |
| 5810 | |
| 5811 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5812 | static struct mdk_personality raid6_personality = |
| 5813 | { |
| 5814 | .name = "raid6", |
| 5815 | .level = 6, |
| 5816 | .owner = THIS_MODULE, |
| 5817 | .make_request = make_request, |
| 5818 | .run = run, |
| 5819 | .stop = stop, |
| 5820 | .status = status, |
| 5821 | .error_handler = error, |
| 5822 | .hot_add_disk = raid5_add_disk, |
| 5823 | .hot_remove_disk= raid5_remove_disk, |
| 5824 | .spare_active = raid5_spare_active, |
| 5825 | .sync_request = sync_request, |
| 5826 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5827 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 5828 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5829 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5830 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5831 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5832 | .takeover = raid6_takeover, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5833 | }; |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5834 | static struct mdk_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | { |
| 5836 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5837 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 5850 | .check_reshape = raid5_check_reshape, |
| 5851 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5852 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5853 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 5854 | .takeover = raid5_takeover, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | }; |
| 5856 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5857 | static struct mdk_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5859 | .name = "raid4", |
| 5860 | .level = 4, |
| 5861 | .owner = THIS_MODULE, |
| 5862 | .make_request = make_request, |
| 5863 | .run = run, |
| 5864 | .stop = stop, |
| 5865 | .status = status, |
| 5866 | .error_handler = error, |
| 5867 | .hot_add_disk = raid5_add_disk, |
| 5868 | .hot_remove_disk= raid5_remove_disk, |
| 5869 | .spare_active = raid5_spare_active, |
| 5870 | .sync_request = sync_request, |
| 5871 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 5872 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 5873 | .check_reshape = raid5_check_reshape, |
| 5874 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5875 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5876 | .quiesce = raid5_quiesce, |
| 5877 | }; |
| 5878 | |
| 5879 | static int __init raid5_init(void) |
| 5880 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5881 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5882 | register_md_personality(&raid5_personality); |
| 5883 | register_md_personality(&raid4_personality); |
| 5884 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5885 | } |
| 5886 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5887 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5888 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5889 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5890 | unregister_md_personality(&raid5_personality); |
| 5891 | unregister_md_personality(&raid4_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | module_init(raid5_init); |
| 5895 | module_exit(raid5_exit); |
| 5896 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 5897 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5898 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 5899 | MODULE_ALIAS("md-raid5"); |
| 5900 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 5901 | MODULE_ALIAS("md-level-5"); |
| 5902 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5903 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 5904 | MODULE_ALIAS("md-raid6"); |
| 5905 | MODULE_ALIAS("md-level-6"); |
| 5906 | |
| 5907 | /* This used to be two separate modules, they were: */ |
| 5908 | MODULE_ALIAS("raid5"); |
| 5909 | MODULE_ALIAS("raid6"); |