Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * raid5.c : Multiple Devices driver for Linux |
| 3 | * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman |
| 4 | * Copyright (C) 1999, 2000 Ingo Molnar |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5 | * Copyright (C) 2002, 2003 H. Peter Anvin |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7 | * RAID-4/5/6 management functions. |
| 8 | * Thanks to Penguin Computing for making the RAID-6 development possible |
| 9 | * by donating a test server! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * (for example /usr/src/linux/COPYING); if not, write to the Free |
| 18 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 21 | /* |
| 22 | * BITMAP UNPLUGGING: |
| 23 | * |
| 24 | * The sequencing for updating the bitmap reliably is a little |
| 25 | * subtle (and I got it wrong the first time) so it deserves some |
| 26 | * explanation. |
| 27 | * |
| 28 | * We group bitmap updates into batches. Each batch has a number. |
| 29 | * We may write out several batches at once, but that isn't very important. |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 30 | * conf->seq_write is the number of the last batch successfully written. |
| 31 | * conf->seq_flush is the number of the last batch that was closed to |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 32 | * new additions. |
| 33 | * When we discover that we will need to write to any block in a stripe |
| 34 | * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 35 | * the number of the batch it will be in. This is seq_flush+1. |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 36 | * When we are ready to do a write, if that batch hasn't been written yet, |
| 37 | * we plug the array and queue the stripe for later. |
| 38 | * When an unplug happens, we increment bm_flush, thus closing the current |
| 39 | * batch. |
| 40 | * When we notice that bm_flush > bm_write, we write out all pending updates |
| 41 | * to the bitmap, and advance bm_write to where bm_flush was. |
| 42 | * This may occasionally write a bit out twice, but is sure never to |
| 43 | * miss any bits. |
| 44 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 46 | #include <linux/blkdev.h> |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 47 | #include <linux/kthread.h> |
Dan Williams | f701d58 | 2009-03-31 15:09:39 +1100 | [diff] [blame] | 48 | #include <linux/raid/pq.h> |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 49 | #include <linux/async_tx.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Dan Williams | 07a3b41 | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 51 | #include <linux/async.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 52 | #include <linux/seq_file.h> |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 53 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 54 | #include <linux/slab.h> |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 55 | #include <linux/ratelimit.h> |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 56 | #include <linux/nodemask.h> |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 57 | #include <linux/flex_array.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 58 | #include <linux/sched/signal.h> |
| 59 | |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 60 | #include <trace/events/block.h> |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 61 | #include <linux/list_sort.h> |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 62 | |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 63 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 64 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 65 | #include "raid0.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 66 | #include "bitmap.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 67 | |
Shaohua Li | 394ed8e | 2017-01-04 16:10:19 -0800 | [diff] [blame] | 68 | #define UNSUPPORTED_MDDEV_FLAGS (1L << MD_FAILFAST_SUPPORTED) |
| 69 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 70 | #define cpu_to_group(cpu) cpu_to_node(cpu) |
| 71 | #define ANY_GROUP NUMA_NO_NODE |
| 72 | |
NeilBrown | 8e0e99b | 2014-10-02 13:45:00 +1000 | [diff] [blame] | 73 | static bool devices_handle_discard_safely = false; |
| 74 | module_param(devices_handle_discard_safely, bool, 0644); |
| 75 | MODULE_PARM_DESC(devices_handle_discard_safely, |
| 76 | "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions"); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 77 | static struct workqueue_struct *raid5_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 79 | static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 80 | { |
| 81 | int hash = (sect >> STRIPE_SHIFT) & HASH_MASK; |
| 82 | return &conf->stripe_hashtbl[hash]; |
| 83 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 85 | static inline int stripe_hash_locks_hash(sector_t sect) |
| 86 | { |
| 87 | return (sect >> STRIPE_SHIFT) & STRIPE_HASH_LOCKS_MASK; |
| 88 | } |
| 89 | |
| 90 | static inline void lock_device_hash_lock(struct r5conf *conf, int hash) |
| 91 | { |
| 92 | spin_lock_irq(conf->hash_locks + hash); |
| 93 | spin_lock(&conf->device_lock); |
| 94 | } |
| 95 | |
| 96 | static inline void unlock_device_hash_lock(struct r5conf *conf, int hash) |
| 97 | { |
| 98 | spin_unlock(&conf->device_lock); |
| 99 | spin_unlock_irq(conf->hash_locks + hash); |
| 100 | } |
| 101 | |
| 102 | static inline void lock_all_device_hash_locks_irq(struct r5conf *conf) |
| 103 | { |
| 104 | int i; |
| 105 | local_irq_disable(); |
| 106 | spin_lock(conf->hash_locks); |
| 107 | for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++) |
| 108 | spin_lock_nest_lock(conf->hash_locks + i, conf->hash_locks); |
| 109 | spin_lock(&conf->device_lock); |
| 110 | } |
| 111 | |
| 112 | static inline void unlock_all_device_hash_locks_irq(struct r5conf *conf) |
| 113 | { |
| 114 | int i; |
| 115 | spin_unlock(&conf->device_lock); |
| 116 | for (i = NR_STRIPE_HASH_LOCKS; i; i--) |
| 117 | spin_unlock(conf->hash_locks + i - 1); |
| 118 | local_irq_enable(); |
| 119 | } |
| 120 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 121 | /* Find first data disk in a raid6 stripe */ |
| 122 | static inline int raid6_d0(struct stripe_head *sh) |
| 123 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 124 | if (sh->ddf_layout) |
| 125 | /* ddf always start from first device */ |
| 126 | return 0; |
| 127 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 128 | if (sh->qd_idx == sh->disks - 1) |
| 129 | return 0; |
| 130 | else |
| 131 | return sh->qd_idx + 1; |
| 132 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 133 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 134 | { |
| 135 | disk++; |
| 136 | return (disk < raid_disks) ? disk : 0; |
| 137 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 138 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 139 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 140 | * We need to map each disk to a 'slot', where the data disks are slot |
| 141 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 142 | * is raid_disks-1. This help does that mapping. |
| 143 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 144 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 145 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 146 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 147 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 148 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 149 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 150 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 151 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 152 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 153 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 154 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 155 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 156 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 157 | return slot; |
| 158 | } |
| 159 | |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 160 | static void return_io(struct bio_list *return_bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 161 | { |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 162 | struct bio *bi; |
| 163 | while ((bi = bio_list_pop(return_bi)) != NULL) { |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 164 | bi->bi_iter.bi_size = 0; |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 165 | trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), |
| 166 | bi, 0); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 167 | bio_endio(bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 171 | static void print_raid5_conf (struct r5conf *conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 173 | static int stripe_operations_active(struct stripe_head *sh) |
| 174 | { |
| 175 | return sh->check_state || sh->reconstruct_state || |
| 176 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 177 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 178 | } |
| 179 | |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 180 | static bool stripe_is_lowprio(struct stripe_head *sh) |
| 181 | { |
| 182 | return (test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) || |
| 183 | test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) && |
| 184 | !test_bit(STRIPE_R5C_CACHING, &sh->state); |
| 185 | } |
| 186 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 187 | static void raid5_wakeup_stripe_thread(struct stripe_head *sh) |
| 188 | { |
| 189 | struct r5conf *conf = sh->raid_conf; |
| 190 | struct r5worker_group *group; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 191 | int thread_cnt; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 192 | int i, cpu = sh->cpu; |
| 193 | |
| 194 | if (!cpu_online(cpu)) { |
| 195 | cpu = cpumask_any(cpu_online_mask); |
| 196 | sh->cpu = cpu; |
| 197 | } |
| 198 | |
| 199 | if (list_empty(&sh->lru)) { |
| 200 | struct r5worker_group *group; |
| 201 | group = conf->worker_groups + cpu_to_group(cpu); |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 202 | if (stripe_is_lowprio(sh)) |
| 203 | list_add_tail(&sh->lru, &group->loprio_list); |
| 204 | else |
| 205 | list_add_tail(&sh->lru, &group->handle_list); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 206 | group->stripes_cnt++; |
| 207 | sh->group = group; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | if (conf->worker_cnt_per_group == 0) { |
| 211 | md_wakeup_thread(conf->mddev->thread); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | group = conf->worker_groups + cpu_to_group(sh->cpu); |
| 216 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 217 | group->workers[0].working = true; |
| 218 | /* at least one worker should run to avoid race */ |
| 219 | queue_work_on(sh->cpu, raid5_wq, &group->workers[0].work); |
| 220 | |
| 221 | thread_cnt = group->stripes_cnt / MAX_STRIPE_BATCH - 1; |
| 222 | /* wakeup more workers */ |
| 223 | for (i = 1; i < conf->worker_cnt_per_group && thread_cnt > 0; i++) { |
| 224 | if (group->workers[i].working == false) { |
| 225 | group->workers[i].working = true; |
| 226 | queue_work_on(sh->cpu, raid5_wq, |
| 227 | &group->workers[i].work); |
| 228 | thread_cnt--; |
| 229 | } |
| 230 | } |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 231 | } |
| 232 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 233 | static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, |
| 234 | struct list_head *temp_inactive_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 236 | int i; |
| 237 | int injournal = 0; /* number of date pages with R5_InJournal */ |
| 238 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 239 | BUG_ON(!list_empty(&sh->lru)); |
| 240 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 241 | |
| 242 | if (r5c_is_writeback(conf->log)) |
| 243 | for (i = sh->disks; i--; ) |
| 244 | if (test_bit(R5_InJournal, &sh->dev[i].flags)) |
| 245 | injournal++; |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 246 | /* |
| 247 | * When quiesce in r5c write back, set STRIPE_HANDLE for stripes with |
| 248 | * data in journal, so they are not released to cached lists |
| 249 | */ |
| 250 | if (conf->quiesce && r5c_is_writeback(conf->log) && |
| 251 | !test_bit(STRIPE_HANDLE, &sh->state) && injournal != 0) { |
| 252 | if (test_bit(STRIPE_R5C_CACHING, &sh->state)) |
| 253 | r5c_make_stripe_write_out(sh); |
| 254 | set_bit(STRIPE_HANDLE, &sh->state); |
| 255 | } |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 256 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 257 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
| 258 | if (test_bit(STRIPE_DELAYED, &sh->state) && |
Jes Sorensen | ad3ab8b | 2015-01-29 12:38:29 -0500 | [diff] [blame] | 259 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 260 | list_add_tail(&sh->lru, &conf->delayed_list); |
Jes Sorensen | ad3ab8b | 2015-01-29 12:38:29 -0500 | [diff] [blame] | 261 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 262 | sh->bm_seq - conf->seq_write > 0) |
| 263 | list_add_tail(&sh->lru, &conf->bitmap_list); |
| 264 | else { |
| 265 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 266 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 267 | if (conf->worker_cnt_per_group == 0) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 268 | if (stripe_is_lowprio(sh)) |
| 269 | list_add_tail(&sh->lru, |
| 270 | &conf->loprio_list); |
| 271 | else |
| 272 | list_add_tail(&sh->lru, |
| 273 | &conf->handle_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 274 | } else { |
| 275 | raid5_wakeup_stripe_thread(sh); |
| 276 | return; |
| 277 | } |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 278 | } |
| 279 | md_wakeup_thread(conf->mddev->thread); |
| 280 | } else { |
| 281 | BUG_ON(stripe_operations_active(sh)); |
| 282 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 283 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 284 | < IO_THRESHOLD) |
| 285 | md_wakeup_thread(conf->mddev->thread); |
| 286 | atomic_dec(&conf->active_stripes); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 287 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 288 | if (!r5c_is_writeback(conf->log)) |
| 289 | list_add_tail(&sh->lru, temp_inactive_list); |
| 290 | else { |
| 291 | WARN_ON(test_bit(R5_InJournal, &sh->dev[sh->pd_idx].flags)); |
| 292 | if (injournal == 0) |
| 293 | list_add_tail(&sh->lru, temp_inactive_list); |
| 294 | else if (injournal == conf->raid_disks - conf->max_degraded) { |
| 295 | /* full stripe */ |
| 296 | if (!test_and_set_bit(STRIPE_R5C_FULL_STRIPE, &sh->state)) |
| 297 | atomic_inc(&conf->r5c_cached_full_stripes); |
| 298 | if (test_and_clear_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) |
| 299 | atomic_dec(&conf->r5c_cached_partial_stripes); |
| 300 | list_add_tail(&sh->lru, &conf->r5c_full_stripe_list); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 301 | r5c_check_cached_full_stripe(conf); |
Song Liu | 03b047f | 2017-01-11 13:39:14 -0800 | [diff] [blame] | 302 | } else |
| 303 | /* |
| 304 | * STRIPE_R5C_PARTIAL_STRIPE is set in |
| 305 | * r5c_try_caching_write(). No need to |
| 306 | * set it again. |
| 307 | */ |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 308 | list_add_tail(&sh->lru, &conf->r5c_partial_stripe_list); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 309 | } |
| 310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 313 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 314 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh, |
| 315 | struct list_head *temp_inactive_list) |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 316 | { |
| 317 | if (atomic_dec_and_test(&sh->count)) |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 318 | do_release_stripe(conf, sh, temp_inactive_list); |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * @hash could be NR_STRIPE_HASH_LOCKS, then we have a list of inactive_list |
| 323 | * |
| 324 | * Be careful: Only one task can add/delete stripes from temp_inactive_list at |
| 325 | * given time. Adding stripes only takes device lock, while deleting stripes |
| 326 | * only takes hash lock. |
| 327 | */ |
| 328 | static void release_inactive_stripe_list(struct r5conf *conf, |
| 329 | struct list_head *temp_inactive_list, |
| 330 | int hash) |
| 331 | { |
| 332 | int size; |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 333 | bool do_wakeup = false; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 334 | unsigned long flags; |
| 335 | |
| 336 | if (hash == NR_STRIPE_HASH_LOCKS) { |
| 337 | size = NR_STRIPE_HASH_LOCKS; |
| 338 | hash = NR_STRIPE_HASH_LOCKS - 1; |
| 339 | } else |
| 340 | size = 1; |
| 341 | while (size) { |
| 342 | struct list_head *list = &temp_inactive_list[size - 1]; |
| 343 | |
| 344 | /* |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 345 | * We don't hold any lock here yet, raid5_get_active_stripe() might |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 346 | * remove stripes from the list |
| 347 | */ |
| 348 | if (!list_empty_careful(list)) { |
| 349 | spin_lock_irqsave(conf->hash_locks + hash, flags); |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 350 | if (list_empty(conf->inactive_list + hash) && |
| 351 | !list_empty(list)) |
| 352 | atomic_dec(&conf->empty_inactive_list_nr); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 353 | list_splice_tail_init(list, conf->inactive_list + hash); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 354 | do_wakeup = true; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 355 | spin_unlock_irqrestore(conf->hash_locks + hash, flags); |
| 356 | } |
| 357 | size--; |
| 358 | hash--; |
| 359 | } |
| 360 | |
| 361 | if (do_wakeup) { |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 362 | wake_up(&conf->wait_for_stripe); |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 363 | if (atomic_read(&conf->active_stripes) == 0) |
| 364 | wake_up(&conf->wait_for_quiescent); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 365 | if (conf->retry_read_aligned) |
| 366 | md_wakeup_thread(conf->mddev->thread); |
| 367 | } |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 368 | } |
| 369 | |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 370 | /* should hold conf->device_lock already */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 371 | static int release_stripe_list(struct r5conf *conf, |
| 372 | struct list_head *temp_inactive_list) |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 373 | { |
Byungchul Park | eae8263 | 2017-02-14 16:26:24 +0900 | [diff] [blame] | 374 | struct stripe_head *sh, *t; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 375 | int count = 0; |
| 376 | struct llist_node *head; |
| 377 | |
| 378 | head = llist_del_all(&conf->released_stripes); |
Shaohua Li | d265d9d | 2013-08-28 14:29:05 +0800 | [diff] [blame] | 379 | head = llist_reverse_order(head); |
Byungchul Park | eae8263 | 2017-02-14 16:26:24 +0900 | [diff] [blame] | 380 | llist_for_each_entry_safe(sh, t, head, release_list) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 381 | int hash; |
| 382 | |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 383 | /* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ |
| 384 | smp_mb(); |
| 385 | clear_bit(STRIPE_ON_RELEASE_LIST, &sh->state); |
| 386 | /* |
| 387 | * Don't worry the bit is set here, because if the bit is set |
| 388 | * again, the count is always > 1. This is true for |
| 389 | * STRIPE_ON_UNPLUG_LIST bit too. |
| 390 | */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 391 | hash = sh->hash_lock_index; |
| 392 | __release_stripe(conf, sh, &temp_inactive_list[hash]); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 393 | count++; |
| 394 | } |
| 395 | |
| 396 | return count; |
| 397 | } |
| 398 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 399 | void raid5_release_stripe(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 401 | struct r5conf *conf = sh->raid_conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | unsigned long flags; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 403 | struct list_head list; |
| 404 | int hash; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 405 | bool wakeup; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 406 | |
Eivind Sarto | cf170f3 | 2014-05-28 13:39:23 +1000 | [diff] [blame] | 407 | /* Avoid release_list until the last reference. |
| 408 | */ |
| 409 | if (atomic_add_unless(&sh->count, -1, 1)) |
| 410 | return; |
| 411 | |
majianpeng | ad4068d | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 412 | if (unlikely(!conf->mddev->thread) || |
| 413 | test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state)) |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 414 | goto slow_path; |
| 415 | wakeup = llist_add(&sh->release_list, &conf->released_stripes); |
| 416 | if (wakeup) |
| 417 | md_wakeup_thread(conf->mddev->thread); |
| 418 | return; |
| 419 | slow_path: |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 420 | local_irq_save(flags); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 421 | /* we are ok here if STRIPE_ON_RELEASE_LIST is set or not */ |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 422 | if (atomic_dec_and_lock(&sh->count, &conf->device_lock)) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 423 | INIT_LIST_HEAD(&list); |
| 424 | hash = sh->hash_lock_index; |
| 425 | do_release_stripe(conf, sh, &list); |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 426 | spin_unlock(&conf->device_lock); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 427 | release_inactive_stripe_list(conf, &list, hash); |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 428 | } |
| 429 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 432 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 434 | pr_debug("remove_hash(), stripe %llu\n", |
| 435 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 437 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 440 | static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 442 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 444 | pr_debug("insert_hash(), stripe %llu\n", |
| 445 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 447 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 451 | static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
| 453 | struct stripe_head *sh = NULL; |
| 454 | struct list_head *first; |
| 455 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 456 | if (list_empty(conf->inactive_list + hash)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | goto out; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 458 | first = (conf->inactive_list + hash)->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | sh = list_entry(first, struct stripe_head, lru); |
| 460 | list_del_init(first); |
| 461 | remove_hash(sh); |
| 462 | atomic_inc(&conf->active_stripes); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 463 | BUG_ON(hash != sh->hash_lock_index); |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 464 | if (list_empty(conf->inactive_list + hash)) |
| 465 | atomic_inc(&conf->empty_inactive_list_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | out: |
| 467 | return sh; |
| 468 | } |
| 469 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 470 | static void shrink_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
| 472 | struct page *p; |
| 473 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 474 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 476 | for (i = 0; i < num ; i++) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 477 | WARN_ON(sh->dev[i].page != sh->dev[i].orig_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | p = sh->dev[i].page; |
| 479 | if (!p) |
| 480 | continue; |
| 481 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 482 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
NeilBrown | a9683a7 | 2015-02-25 12:02:51 +1100 | [diff] [blame] | 486 | static int grow_buffers(struct stripe_head *sh, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
| 488 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 489 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 491 | for (i = 0; i < num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | struct page *page; |
| 493 | |
NeilBrown | a9683a7 | 2015-02-25 12:02:51 +1100 | [diff] [blame] | 494 | if (!(page = alloc_page(gfp))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | return 1; |
| 496 | } |
| 497 | sh->dev[i].page = page; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 498 | sh->dev[i].orig_page = page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | return 0; |
| 501 | } |
| 502 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 503 | static void raid5_build_block(struct stripe_head *sh, int i, int previous); |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 504 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 505 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 507 | 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] | 508 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 509 | struct r5conf *conf = sh->raid_conf; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 510 | int i, seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 512 | BUG_ON(atomic_read(&sh->count) != 0); |
| 513 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 514 | BUG_ON(stripe_operations_active(sh)); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 515 | BUG_ON(sh->batch_head); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 516 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 517 | pr_debug("init_stripe called, stripe %llu\n", |
Markus Stockhausen | b8e6a15 | 2014-08-23 20:19:27 +1000 | [diff] [blame] | 518 | (unsigned long long)sector); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 519 | retry: |
| 520 | seq = read_seqcount_begin(&conf->gen_lock); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 521 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 522 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 524 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | sh->state = 0; |
| 526 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 527 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | struct r5dev *dev = &sh->dev[i]; |
| 529 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 530 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | test_bit(R5_LOCKED, &dev->flags)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 532 | pr_err("sector=%llx i=%d %p %p %p %p %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 534 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | test_bit(R5_LOCKED, &dev->flags)); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 536 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | dev->flags = 0; |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 539 | raid5_build_block(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 541 | if (read_seqcount_retry(&conf->gen_lock, seq)) |
| 542 | goto retry; |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 543 | sh->overwrite_disks = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | insert_hash(conf, sh); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 545 | sh->cpu = smp_processor_id(); |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 546 | set_bit(STRIPE_BATCH_READY, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 549 | static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 550 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
| 552 | struct stripe_head *sh; |
| 553 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 554 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 555 | hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 556 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 558 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | return NULL; |
| 560 | } |
| 561 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 562 | /* |
| 563 | * Need to check if array has failed when deciding whether to: |
| 564 | * - start an array |
| 565 | * - remove non-faulty devices |
| 566 | * - add a spare |
| 567 | * - allow a reshape |
| 568 | * This determination is simple when no reshape is happening. |
| 569 | * However if there is a reshape, we need to carefully check |
| 570 | * both the before and after sections. |
| 571 | * This is because some failed devices may only affect one |
| 572 | * of the two sections, and some non-in_sync devices may |
| 573 | * be insync in the section most affected by failed devices. |
| 574 | */ |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 575 | int raid5_calc_degraded(struct r5conf *conf) |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 576 | { |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 577 | int degraded, degraded2; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 578 | int i; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 579 | |
| 580 | rcu_read_lock(); |
| 581 | degraded = 0; |
| 582 | for (i = 0; i < conf->previous_raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 583 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 584 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 585 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 586 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 587 | degraded++; |
| 588 | else if (test_bit(In_sync, &rdev->flags)) |
| 589 | ; |
| 590 | else |
| 591 | /* not in-sync or faulty. |
| 592 | * If the reshape increases the number of devices, |
| 593 | * this is being recovered by the reshape, so |
| 594 | * this 'previous' section is not in_sync. |
| 595 | * If the number of devices is being reduced however, |
| 596 | * the device can only be part of the array if |
| 597 | * we are reverting a reshape, so this section will |
| 598 | * be in-sync. |
| 599 | */ |
| 600 | if (conf->raid_disks >= conf->previous_raid_disks) |
| 601 | degraded++; |
| 602 | } |
| 603 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 604 | if (conf->raid_disks == conf->previous_raid_disks) |
| 605 | return degraded; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 606 | rcu_read_lock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 607 | degraded2 = 0; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 608 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 609 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 610 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 611 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 612 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 613 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 614 | else if (test_bit(In_sync, &rdev->flags)) |
| 615 | ; |
| 616 | else |
| 617 | /* not in-sync or faulty. |
| 618 | * If reshape increases the number of devices, this |
| 619 | * section has already been recovered, else it |
| 620 | * almost certainly hasn't. |
| 621 | */ |
| 622 | if (conf->raid_disks <= conf->previous_raid_disks) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 623 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 624 | } |
| 625 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 626 | if (degraded2 > degraded) |
| 627 | return degraded2; |
| 628 | return degraded; |
| 629 | } |
| 630 | |
| 631 | static int has_failed(struct r5conf *conf) |
| 632 | { |
| 633 | int degraded; |
| 634 | |
| 635 | if (conf->mddev->reshape_position == MaxSector) |
| 636 | return conf->mddev->degraded > conf->max_degraded; |
| 637 | |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 638 | degraded = raid5_calc_degraded(conf); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 639 | if (degraded > conf->max_degraded) |
| 640 | return 1; |
| 641 | return 0; |
| 642 | } |
| 643 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 644 | struct stripe_head * |
| 645 | raid5_get_active_stripe(struct r5conf *conf, sector_t sector, |
| 646 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
| 648 | struct stripe_head *sh; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 649 | int hash = stripe_hash_locks_hash(sector); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 650 | int inc_empty_inactive_list_flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 652 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 654 | spin_lock_irq(conf->hash_locks + hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | do { |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 657 | wait_event_lock_irq(conf->wait_for_quiescent, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 658 | conf->quiesce == 0 || noquiesce, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 659 | *(conf->hash_locks + hash)); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 660 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | if (!sh) { |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 662 | if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 663 | sh = get_free_stripe(conf, hash); |
Shaohua Li | 713bc5c | 2015-05-28 17:33:47 -0700 | [diff] [blame] | 664 | if (!sh && !test_bit(R5_DID_ALLOC, |
| 665 | &conf->cache_state)) |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 666 | set_bit(R5_ALLOC_MORE, |
| 667 | &conf->cache_state); |
| 668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | if (noblock && sh == NULL) |
| 670 | break; |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 671 | |
| 672 | r5c_check_stripe_cache_usage(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | if (!sh) { |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 674 | set_bit(R5_INACTIVE_BLOCKED, |
| 675 | &conf->cache_state); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 676 | r5l_wake_reclaim(conf->log, 0); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 677 | wait_event_lock_irq( |
| 678 | conf->wait_for_stripe, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 679 | !list_empty(conf->inactive_list + hash) && |
| 680 | (atomic_read(&conf->active_stripes) |
| 681 | < (conf->max_nr_stripes * 3 / 4) |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 682 | || !test_bit(R5_INACTIVE_BLOCKED, |
| 683 | &conf->cache_state)), |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 684 | *(conf->hash_locks + hash)); |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 685 | clear_bit(R5_INACTIVE_BLOCKED, |
| 686 | &conf->cache_state); |
NeilBrown | 7da9d45 | 2014-01-22 11:45:03 +1100 | [diff] [blame] | 687 | } else { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 688 | init_stripe(sh, sector, previous); |
NeilBrown | 7da9d45 | 2014-01-22 11:45:03 +1100 | [diff] [blame] | 689 | atomic_inc(&sh->count); |
| 690 | } |
Shaohua Li | e240c18 | 2014-04-09 11:27:42 +0800 | [diff] [blame] | 691 | } else if (!atomic_inc_not_zero(&sh->count)) { |
NeilBrown | 6d183de | 2013-11-28 10:55:27 +1100 | [diff] [blame] | 692 | spin_lock(&conf->device_lock); |
Shaohua Li | e240c18 | 2014-04-09 11:27:42 +0800 | [diff] [blame] | 693 | if (!atomic_read(&sh->count)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 695 | atomic_inc(&conf->active_stripes); |
NeilBrown | 5af9bef | 2014-01-14 15:16:10 +1100 | [diff] [blame] | 696 | BUG_ON(list_empty(&sh->lru) && |
| 697 | !test_bit(STRIPE_EXPANDING, &sh->state)); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 698 | inc_empty_inactive_list_flag = 0; |
| 699 | if (!list_empty(conf->inactive_list + hash)) |
| 700 | inc_empty_inactive_list_flag = 1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 701 | list_del_init(&sh->lru); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 702 | if (list_empty(conf->inactive_list + hash) && inc_empty_inactive_list_flag) |
| 703 | atomic_inc(&conf->empty_inactive_list_nr); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 704 | if (sh->group) { |
| 705 | sh->group->stripes_cnt--; |
| 706 | sh->group = NULL; |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
NeilBrown | 7da9d45 | 2014-01-22 11:45:03 +1100 | [diff] [blame] | 709 | atomic_inc(&sh->count); |
NeilBrown | 6d183de | 2013-11-28 10:55:27 +1100 | [diff] [blame] | 710 | spin_unlock(&conf->device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | } while (sh == NULL); |
| 713 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 714 | spin_unlock_irq(conf->hash_locks + hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | return sh; |
| 716 | } |
| 717 | |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 718 | static bool is_full_stripe_write(struct stripe_head *sh) |
| 719 | { |
| 720 | BUG_ON(sh->overwrite_disks > (sh->disks - sh->raid_conf->max_degraded)); |
| 721 | return sh->overwrite_disks == (sh->disks - sh->raid_conf->max_degraded); |
| 722 | } |
| 723 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 724 | static void lock_two_stripes(struct stripe_head *sh1, struct stripe_head *sh2) |
| 725 | { |
| 726 | local_irq_disable(); |
| 727 | if (sh1 > sh2) { |
| 728 | spin_lock(&sh2->stripe_lock); |
| 729 | spin_lock_nested(&sh1->stripe_lock, 1); |
| 730 | } else { |
| 731 | spin_lock(&sh1->stripe_lock); |
| 732 | spin_lock_nested(&sh2->stripe_lock, 1); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | static void unlock_two_stripes(struct stripe_head *sh1, struct stripe_head *sh2) |
| 737 | { |
| 738 | spin_unlock(&sh1->stripe_lock); |
| 739 | spin_unlock(&sh2->stripe_lock); |
| 740 | local_irq_enable(); |
| 741 | } |
| 742 | |
| 743 | /* Only freshly new full stripe normal write stripe can be added to a batch list */ |
| 744 | static bool stripe_can_batch(struct stripe_head *sh) |
| 745 | { |
Shaohua Li | 9c3e333 | 2015-08-13 14:32:02 -0700 | [diff] [blame] | 746 | struct r5conf *conf = sh->raid_conf; |
| 747 | |
| 748 | if (conf->log) |
| 749 | return false; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 750 | return test_bit(STRIPE_BATCH_READY, &sh->state) && |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 751 | !test_bit(STRIPE_BITMAP_PENDING, &sh->state) && |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 752 | is_full_stripe_write(sh); |
| 753 | } |
| 754 | |
| 755 | /* we only do back search */ |
| 756 | static void stripe_add_to_batch_list(struct r5conf *conf, struct stripe_head *sh) |
| 757 | { |
| 758 | struct stripe_head *head; |
| 759 | sector_t head_sector, tmp_sec; |
| 760 | int hash; |
| 761 | int dd_idx; |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 762 | int inc_empty_inactive_list_flag; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 763 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 764 | /* Don't cross chunks, so stripe pd_idx/qd_idx is the same */ |
| 765 | tmp_sec = sh->sector; |
| 766 | if (!sector_div(tmp_sec, conf->chunk_sectors)) |
| 767 | return; |
| 768 | head_sector = sh->sector - STRIPE_SECTORS; |
| 769 | |
| 770 | hash = stripe_hash_locks_hash(head_sector); |
| 771 | spin_lock_irq(conf->hash_locks + hash); |
| 772 | head = __find_stripe(conf, head_sector, conf->generation); |
| 773 | if (head && !atomic_inc_not_zero(&head->count)) { |
| 774 | spin_lock(&conf->device_lock); |
| 775 | if (!atomic_read(&head->count)) { |
| 776 | if (!test_bit(STRIPE_HANDLE, &head->state)) |
| 777 | atomic_inc(&conf->active_stripes); |
| 778 | BUG_ON(list_empty(&head->lru) && |
| 779 | !test_bit(STRIPE_EXPANDING, &head->state)); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 780 | inc_empty_inactive_list_flag = 0; |
| 781 | if (!list_empty(conf->inactive_list + hash)) |
| 782 | inc_empty_inactive_list_flag = 1; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 783 | list_del_init(&head->lru); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 784 | if (list_empty(conf->inactive_list + hash) && inc_empty_inactive_list_flag) |
| 785 | atomic_inc(&conf->empty_inactive_list_nr); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 786 | if (head->group) { |
| 787 | head->group->stripes_cnt--; |
| 788 | head->group = NULL; |
| 789 | } |
| 790 | } |
| 791 | atomic_inc(&head->count); |
| 792 | spin_unlock(&conf->device_lock); |
| 793 | } |
| 794 | spin_unlock_irq(conf->hash_locks + hash); |
| 795 | |
| 796 | if (!head) |
| 797 | return; |
| 798 | if (!stripe_can_batch(head)) |
| 799 | goto out; |
| 800 | |
| 801 | lock_two_stripes(head, sh); |
| 802 | /* clear_batch_ready clear the flag */ |
| 803 | if (!stripe_can_batch(head) || !stripe_can_batch(sh)) |
| 804 | goto unlock_out; |
| 805 | |
| 806 | if (sh->batch_head) |
| 807 | goto unlock_out; |
| 808 | |
| 809 | dd_idx = 0; |
| 810 | while (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) |
| 811 | dd_idx++; |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 812 | if (head->dev[dd_idx].towrite->bi_opf != sh->dev[dd_idx].towrite->bi_opf || |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 813 | bio_op(head->dev[dd_idx].towrite) != bio_op(sh->dev[dd_idx].towrite)) |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 814 | goto unlock_out; |
| 815 | |
| 816 | if (head->batch_head) { |
| 817 | spin_lock(&head->batch_head->batch_lock); |
| 818 | /* This batch list is already running */ |
| 819 | if (!stripe_can_batch(head)) { |
| 820 | spin_unlock(&head->batch_head->batch_lock); |
| 821 | goto unlock_out; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * at this point, head's BATCH_READY could be cleared, but we |
| 826 | * can still add the stripe to batch list |
| 827 | */ |
| 828 | list_add(&sh->batch_list, &head->batch_list); |
| 829 | spin_unlock(&head->batch_head->batch_lock); |
| 830 | |
| 831 | sh->batch_head = head->batch_head; |
| 832 | } else { |
| 833 | head->batch_head = head; |
| 834 | sh->batch_head = head->batch_head; |
| 835 | spin_lock(&head->batch_lock); |
| 836 | list_add_tail(&sh->batch_list, &head->batch_list); |
| 837 | spin_unlock(&head->batch_lock); |
| 838 | } |
| 839 | |
| 840 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 841 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 842 | < IO_THRESHOLD) |
| 843 | md_wakeup_thread(conf->mddev->thread); |
| 844 | |
NeilBrown | 2b6b245 | 2015-05-21 15:10:01 +1000 | [diff] [blame] | 845 | if (test_and_clear_bit(STRIPE_BIT_DELAY, &sh->state)) { |
| 846 | int seq = sh->bm_seq; |
| 847 | if (test_bit(STRIPE_BIT_DELAY, &sh->batch_head->state) && |
| 848 | sh->batch_head->bm_seq > seq) |
| 849 | seq = sh->batch_head->bm_seq; |
| 850 | set_bit(STRIPE_BIT_DELAY, &sh->batch_head->state); |
| 851 | sh->batch_head->bm_seq = seq; |
| 852 | } |
| 853 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 854 | atomic_inc(&sh->count); |
| 855 | unlock_out: |
| 856 | unlock_two_stripes(head, sh); |
| 857 | out: |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 858 | raid5_release_stripe(head); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 859 | } |
| 860 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 861 | /* Determine if 'data_offset' or 'new_data_offset' should be used |
| 862 | * in this stripe_head. |
| 863 | */ |
| 864 | static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) |
| 865 | { |
| 866 | sector_t progress = conf->reshape_progress; |
| 867 | /* Need a memory barrier to make sure we see the value |
| 868 | * of conf->generation, or ->data_offset that was set before |
| 869 | * reshape_progress was updated. |
| 870 | */ |
| 871 | smp_rmb(); |
| 872 | if (progress == MaxSector) |
| 873 | return 0; |
| 874 | if (sh->generation == conf->generation - 1) |
| 875 | return 0; |
| 876 | /* We are in a reshape, and this is a new-generation stripe, |
| 877 | * so use new_data_offset. |
| 878 | */ |
| 879 | return 1; |
| 880 | } |
| 881 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 882 | static void dispatch_bio_list(struct bio_list *tmp) |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 883 | { |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 884 | struct bio *bio; |
| 885 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 886 | while ((bio = bio_list_pop(tmp))) |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 887 | generic_make_request(bio); |
| 888 | } |
| 889 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 890 | static int cmp_stripe(void *priv, struct list_head *a, struct list_head *b) |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 891 | { |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 892 | const struct r5pending_data *da = list_entry(a, |
| 893 | struct r5pending_data, sibling); |
| 894 | const struct r5pending_data *db = list_entry(b, |
| 895 | struct r5pending_data, sibling); |
| 896 | if (da->sector > db->sector) |
| 897 | return 1; |
| 898 | if (da->sector < db->sector) |
| 899 | return -1; |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static void dispatch_defer_bios(struct r5conf *conf, int target, |
| 904 | struct bio_list *list) |
| 905 | { |
| 906 | struct r5pending_data *data; |
| 907 | struct list_head *first, *next = NULL; |
| 908 | int cnt = 0; |
| 909 | |
| 910 | if (conf->pending_data_cnt == 0) |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 911 | return; |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 912 | |
| 913 | list_sort(NULL, &conf->pending_list, cmp_stripe); |
| 914 | |
| 915 | first = conf->pending_list.next; |
| 916 | |
| 917 | /* temporarily move the head */ |
| 918 | if (conf->next_pending_data) |
| 919 | list_move_tail(&conf->pending_list, |
| 920 | &conf->next_pending_data->sibling); |
| 921 | |
| 922 | while (!list_empty(&conf->pending_list)) { |
| 923 | data = list_first_entry(&conf->pending_list, |
| 924 | struct r5pending_data, sibling); |
| 925 | if (&data->sibling == first) |
| 926 | first = data->sibling.next; |
| 927 | next = data->sibling.next; |
| 928 | |
| 929 | bio_list_merge(list, &data->bios); |
| 930 | list_move(&data->sibling, &conf->free_list); |
| 931 | cnt++; |
| 932 | if (cnt >= target) |
| 933 | break; |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 934 | } |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 935 | conf->pending_data_cnt -= cnt; |
| 936 | BUG_ON(conf->pending_data_cnt < 0 || cnt < target); |
| 937 | |
| 938 | if (next != &conf->pending_list) |
| 939 | conf->next_pending_data = list_entry(next, |
| 940 | struct r5pending_data, sibling); |
| 941 | else |
| 942 | conf->next_pending_data = NULL; |
| 943 | /* list isn't empty */ |
| 944 | if (first != &conf->pending_list) |
| 945 | list_move_tail(&conf->pending_list, first); |
| 946 | } |
| 947 | |
| 948 | static void flush_deferred_bios(struct r5conf *conf) |
| 949 | { |
| 950 | struct bio_list tmp = BIO_EMPTY_LIST; |
| 951 | |
| 952 | if (conf->pending_data_cnt == 0) |
| 953 | return; |
| 954 | |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 955 | spin_lock(&conf->pending_bios_lock); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 956 | dispatch_defer_bios(conf, conf->pending_data_cnt, &tmp); |
| 957 | BUG_ON(conf->pending_data_cnt != 0); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 958 | spin_unlock(&conf->pending_bios_lock); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 959 | |
| 960 | dispatch_bio_list(&tmp); |
| 961 | } |
| 962 | |
| 963 | static void defer_issue_bios(struct r5conf *conf, sector_t sector, |
| 964 | struct bio_list *bios) |
| 965 | { |
| 966 | struct bio_list tmp = BIO_EMPTY_LIST; |
| 967 | struct r5pending_data *ent; |
| 968 | |
| 969 | spin_lock(&conf->pending_bios_lock); |
| 970 | ent = list_first_entry(&conf->free_list, struct r5pending_data, |
| 971 | sibling); |
| 972 | list_move_tail(&ent->sibling, &conf->pending_list); |
| 973 | ent->sector = sector; |
| 974 | bio_list_init(&ent->bios); |
| 975 | bio_list_merge(&ent->bios, bios); |
| 976 | conf->pending_data_cnt++; |
| 977 | if (conf->pending_data_cnt >= PENDING_IO_MAX) |
| 978 | dispatch_defer_bios(conf, PENDING_IO_ONE_FLUSH, &tmp); |
| 979 | |
| 980 | spin_unlock(&conf->pending_bios_lock); |
| 981 | |
| 982 | dispatch_bio_list(&tmp); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 983 | } |
| 984 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 985 | static void |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 986 | raid5_end_read_request(struct bio *bi); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 987 | static void |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 988 | raid5_end_write_request(struct bio *bi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 989 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 990 | 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] | 991 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 992 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 993 | int i, disks = sh->disks; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 994 | struct stripe_head *head_sh = sh; |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 995 | struct bio_list pending_bios = BIO_EMPTY_LIST; |
| 996 | bool should_defer; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 997 | |
| 998 | might_sleep(); |
| 999 | |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1000 | if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) { |
| 1001 | /* writing out phase */ |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 1002 | if (s->waiting_extra_page) |
| 1003 | return; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1004 | if (r5l_write_stripe(conf->log, sh) == 0) |
| 1005 | return; |
| 1006 | } else { /* caching phase */ |
| 1007 | if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) { |
| 1008 | r5c_cache_data(conf->log, sh, s); |
| 1009 | return; |
| 1010 | } |
| 1011 | } |
| 1012 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 1013 | should_defer = conf->batch_bio_dispatch && conf->group_cnt; |
| 1014 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1015 | for (i = disks; i--; ) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1016 | int op, op_flags = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1017 | int replace_only = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1018 | struct bio *bi, *rbi; |
| 1019 | struct md_rdev *rdev, *rrdev = NULL; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1020 | |
| 1021 | sh = head_sh; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1022 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1023 | op = REQ_OP_WRITE; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1024 | if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) |
Christoph Hellwig | 70fd761 | 2016-11-01 07:40:10 -0600 | [diff] [blame] | 1025 | op_flags = REQ_FUA; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1026 | if (test_bit(R5_Discard, &sh->dev[i].flags)) |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1027 | op = REQ_OP_DISCARD; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1028 | } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1029 | op = REQ_OP_READ; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1030 | else if (test_and_clear_bit(R5_WantReplace, |
| 1031 | &sh->dev[i].flags)) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1032 | op = REQ_OP_WRITE; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1033 | replace_only = 1; |
| 1034 | } else |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1035 | continue; |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1036 | if (test_and_clear_bit(R5_SyncIO, &sh->dev[i].flags)) |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1037 | op_flags |= REQ_SYNC; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1038 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1039 | again: |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1040 | bi = &sh->dev[i].req; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1041 | rbi = &sh->dev[i].rreq; /* For writing to replacement */ |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1042 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1043 | rcu_read_lock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1044 | rrdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1045 | smp_mb(); /* Ensure that if rrdev is NULL, rdev won't be */ |
| 1046 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 1047 | if (!rdev) { |
| 1048 | rdev = rrdev; |
| 1049 | rrdev = NULL; |
| 1050 | } |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1051 | if (op_is_write(op)) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1052 | if (replace_only) |
| 1053 | rdev = NULL; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1054 | if (rdev == rrdev) |
| 1055 | /* We raced and saw duplicates */ |
| 1056 | rrdev = NULL; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1057 | } else { |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1058 | if (test_bit(R5_ReadRepl, &head_sh->dev[i].flags) && rrdev) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1059 | rdev = rrdev; |
| 1060 | rrdev = NULL; |
| 1061 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1062 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1063 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 1064 | rdev = NULL; |
| 1065 | if (rdev) |
| 1066 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1067 | if (rrdev && test_bit(Faulty, &rrdev->flags)) |
| 1068 | rrdev = NULL; |
| 1069 | if (rrdev) |
| 1070 | atomic_inc(&rrdev->nr_pending); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1071 | rcu_read_unlock(); |
| 1072 | |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1073 | /* We have already checked bad blocks for reads. Now |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1074 | * need to check for writes. We never accept write errors |
| 1075 | * on the replacement, so we don't to check rrdev. |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1076 | */ |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1077 | while (op_is_write(op) && rdev && |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1078 | test_bit(WriteErrorSeen, &rdev->flags)) { |
| 1079 | sector_t first_bad; |
| 1080 | int bad_sectors; |
| 1081 | int bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 1082 | &first_bad, &bad_sectors); |
| 1083 | if (!bad) |
| 1084 | break; |
| 1085 | |
| 1086 | if (bad < 0) { |
| 1087 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 1088 | if (!conf->mddev->external && |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 1089 | conf->mddev->sb_flags) { |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1090 | /* It is very unlikely, but we might |
| 1091 | * still need to write out the |
| 1092 | * bad block log - better give it |
| 1093 | * a chance*/ |
| 1094 | md_check_recovery(conf->mddev); |
| 1095 | } |
majianpeng | 1850753 | 2012-07-03 12:11:54 +1000 | [diff] [blame] | 1096 | /* |
| 1097 | * Because md_wait_for_blocked_rdev |
| 1098 | * will dec nr_pending, we must |
| 1099 | * increment it first. |
| 1100 | */ |
| 1101 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1102 | md_wait_for_blocked_rdev(rdev, conf->mddev); |
| 1103 | } else { |
| 1104 | /* Acknowledged bad block - skip the write */ |
| 1105 | rdev_dec_pending(rdev, conf->mddev); |
| 1106 | rdev = NULL; |
| 1107 | } |
| 1108 | } |
| 1109 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1110 | if (rdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1111 | if (s->syncing || s->expanding || s->expanded |
| 1112 | || s->replacing) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1113 | md_sync_acct(rdev->bdev, STRIPE_SECTORS); |
| 1114 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 1115 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 1116 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1117 | bi->bi_bdev = rdev->bdev; |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1118 | bio_set_op_attrs(bi, op, op_flags); |
| 1119 | bi->bi_end_io = op_is_write(op) |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 1120 | ? raid5_end_write_request |
| 1121 | : raid5_end_read_request; |
| 1122 | bi->bi_private = sh; |
| 1123 | |
Mike Christie | 6296b96 | 2016-06-05 14:32:21 -0500 | [diff] [blame] | 1124 | pr_debug("%s: for %llu schedule op %d on disc %d\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1125 | __func__, (unsigned long long)sh->sector, |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1126 | bi->bi_opf, i); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1127 | atomic_inc(&sh->count); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1128 | if (sh != head_sh) |
| 1129 | atomic_inc(&head_sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1130 | if (use_new_offset(conf, sh)) |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1131 | bi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1132 | + rdev->new_data_offset); |
| 1133 | else |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1134 | bi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1135 | + rdev->data_offset); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1136 | if (test_bit(R5_ReadNoMerge, &head_sh->dev[i].flags)) |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1137 | bi->bi_opf |= REQ_NOMERGE; |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 1138 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1139 | if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) |
| 1140 | WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 1141 | |
| 1142 | if (!op_is_write(op) && |
| 1143 | test_bit(R5_InJournal, &sh->dev[i].flags)) |
| 1144 | /* |
| 1145 | * issuing read for a page in journal, this |
| 1146 | * must be preparing for prexor in rmw; read |
| 1147 | * the data into orig_page |
| 1148 | */ |
| 1149 | sh->dev[i].vec.bv_page = sh->dev[i].orig_page; |
| 1150 | else |
| 1151 | sh->dev[i].vec.bv_page = sh->dev[i].page; |
Kent Overstreet | 4997b72 | 2013-05-30 08:44:39 +0200 | [diff] [blame] | 1152 | bi->bi_vcnt = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1153 | bi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 1154 | bi->bi_io_vec[0].bv_offset = 0; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1155 | bi->bi_iter.bi_size = STRIPE_SIZE; |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1156 | /* |
| 1157 | * If this is discard request, set bi_vcnt 0. We don't |
| 1158 | * want to confuse SCSI because SCSI will replace payload |
| 1159 | */ |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1160 | if (op == REQ_OP_DISCARD) |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1161 | bi->bi_vcnt = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1162 | if (rrdev) |
| 1163 | set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 1164 | |
| 1165 | if (conf->mddev->gendisk) |
| 1166 | trace_block_bio_remap(bdev_get_queue(bi->bi_bdev), |
| 1167 | bi, disk_devt(conf->mddev->gendisk), |
| 1168 | sh->dev[i].sector); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 1169 | if (should_defer && op_is_write(op)) |
| 1170 | bio_list_add(&pending_bios, bi); |
| 1171 | else |
| 1172 | generic_make_request(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1173 | } |
| 1174 | if (rrdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1175 | if (s->syncing || s->expanding || s->expanded |
| 1176 | || s->replacing) |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1177 | md_sync_acct(rrdev->bdev, STRIPE_SECTORS); |
| 1178 | |
| 1179 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 1180 | |
| 1181 | rbi->bi_bdev = rrdev->bdev; |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1182 | bio_set_op_attrs(rbi, op, op_flags); |
| 1183 | BUG_ON(!op_is_write(op)); |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 1184 | rbi->bi_end_io = raid5_end_write_request; |
| 1185 | rbi->bi_private = sh; |
| 1186 | |
Mike Christie | 6296b96 | 2016-06-05 14:32:21 -0500 | [diff] [blame] | 1187 | pr_debug("%s: for %llu schedule op %d on " |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1188 | "replacement disc %d\n", |
| 1189 | __func__, (unsigned long long)sh->sector, |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1190 | rbi->bi_opf, i); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1191 | atomic_inc(&sh->count); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1192 | if (sh != head_sh) |
| 1193 | atomic_inc(&head_sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1194 | if (use_new_offset(conf, sh)) |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1195 | rbi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1196 | + rrdev->new_data_offset); |
| 1197 | else |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1198 | rbi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1199 | + rrdev->data_offset); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1200 | if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) |
| 1201 | WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
| 1202 | sh->dev[i].rvec.bv_page = sh->dev[i].page; |
Kent Overstreet | 4997b72 | 2013-05-30 08:44:39 +0200 | [diff] [blame] | 1203 | rbi->bi_vcnt = 1; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1204 | rbi->bi_io_vec[0].bv_len = STRIPE_SIZE; |
| 1205 | rbi->bi_io_vec[0].bv_offset = 0; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1206 | rbi->bi_iter.bi_size = STRIPE_SIZE; |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1207 | /* |
| 1208 | * If this is discard request, set bi_vcnt 0. We don't |
| 1209 | * want to confuse SCSI because SCSI will replace payload |
| 1210 | */ |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1211 | if (op == REQ_OP_DISCARD) |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1212 | rbi->bi_vcnt = 0; |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 1213 | if (conf->mddev->gendisk) |
| 1214 | trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev), |
| 1215 | rbi, disk_devt(conf->mddev->gendisk), |
| 1216 | sh->dev[i].sector); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 1217 | if (should_defer && op_is_write(op)) |
| 1218 | bio_list_add(&pending_bios, rbi); |
| 1219 | else |
| 1220 | generic_make_request(rbi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1221 | } |
| 1222 | if (!rdev && !rrdev) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1223 | if (op_is_write(op)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1224 | set_bit(STRIPE_DEGRADED, &sh->state); |
Mike Christie | 6296b96 | 2016-06-05 14:32:21 -0500 | [diff] [blame] | 1225 | pr_debug("skip op %d on disc %d for sector %llu\n", |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1226 | bi->bi_opf, i, (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1227 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1228 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1229 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1230 | |
| 1231 | if (!head_sh->batch_head) |
| 1232 | continue; |
| 1233 | sh = list_first_entry(&sh->batch_list, struct stripe_head, |
| 1234 | batch_list); |
| 1235 | if (sh != head_sh) |
| 1236 | goto again; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1237 | } |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 1238 | |
| 1239 | if (should_defer && !bio_list_empty(&pending_bios)) |
| 1240 | defer_issue_bios(conf, head_sh->sector, &pending_bios); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | static struct dma_async_tx_descriptor * |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1244 | async_copy_data(int frombio, struct bio *bio, struct page **page, |
| 1245 | sector_t sector, struct dma_async_tx_descriptor *tx, |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1246 | struct stripe_head *sh, int no_skipcopy) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1247 | { |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1248 | struct bio_vec bvl; |
| 1249 | struct bvec_iter iter; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1250 | struct page *bio_page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1251 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1252 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1253 | enum async_tx_flags flags = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1254 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1255 | if (bio->bi_iter.bi_sector >= sector) |
| 1256 | page_offset = (signed)(bio->bi_iter.bi_sector - sector) * 512; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1257 | else |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1258 | page_offset = (signed)(sector - bio->bi_iter.bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1259 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1260 | if (frombio) |
| 1261 | flags |= ASYNC_TX_FENCE; |
| 1262 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 1263 | |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1264 | bio_for_each_segment(bvl, bio, iter) { |
| 1265 | int len = bvl.bv_len; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1266 | int clen; |
| 1267 | int b_offset = 0; |
| 1268 | |
| 1269 | if (page_offset < 0) { |
| 1270 | b_offset = -page_offset; |
| 1271 | page_offset += b_offset; |
| 1272 | len -= b_offset; |
| 1273 | } |
| 1274 | |
| 1275 | if (len > 0 && page_offset + len > STRIPE_SIZE) |
| 1276 | clen = STRIPE_SIZE - page_offset; |
| 1277 | else |
| 1278 | clen = len; |
| 1279 | |
| 1280 | if (clen > 0) { |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1281 | b_offset += bvl.bv_offset; |
| 1282 | bio_page = bvl.bv_page; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1283 | if (frombio) { |
| 1284 | if (sh->raid_conf->skip_copy && |
| 1285 | b_offset == 0 && page_offset == 0 && |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1286 | clen == STRIPE_SIZE && |
| 1287 | !no_skipcopy) |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1288 | *page = bio_page; |
| 1289 | else |
| 1290 | tx = async_memcpy(*page, bio_page, page_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1291 | b_offset, clen, &submit); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1292 | } else |
| 1293 | tx = async_memcpy(bio_page, *page, b_offset, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1294 | page_offset, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1295 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1296 | /* chain the operations */ |
| 1297 | submit.depend_tx = tx; |
| 1298 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1299 | if (clen < len) /* hit end of page */ |
| 1300 | break; |
| 1301 | page_offset += len; |
| 1302 | } |
| 1303 | |
| 1304 | return tx; |
| 1305 | } |
| 1306 | |
| 1307 | static void ops_complete_biofill(void *stripe_head_ref) |
| 1308 | { |
| 1309 | struct stripe_head *sh = stripe_head_ref; |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 1310 | struct bio_list return_bi = BIO_EMPTY_LIST; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1311 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1312 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1313 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1314 | (unsigned long long)sh->sector); |
| 1315 | |
| 1316 | /* clear completed biofills */ |
| 1317 | for (i = sh->disks; i--; ) { |
| 1318 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1319 | |
| 1320 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1321 | /* and check if we need to reply to a read request, |
| 1322 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1323 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1324 | */ |
| 1325 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1326 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1327 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1328 | BUG_ON(!dev->read); |
| 1329 | rbi = dev->read; |
| 1330 | dev->read = NULL; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1331 | while (rbi && rbi->bi_iter.bi_sector < |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1332 | dev->sector + STRIPE_SECTORS) { |
| 1333 | rbi2 = r5_next_bio(rbi, dev->sector); |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 1334 | if (!raid5_dec_bi_active_stripes(rbi)) |
| 1335 | bio_list_add(&return_bi, rbi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1336 | rbi = rbi2; |
| 1337 | } |
| 1338 | } |
| 1339 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1340 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1341 | |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 1342 | return_io(&return_bi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1343 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1344 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 1345 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void ops_run_biofill(struct stripe_head *sh) |
| 1349 | { |
| 1350 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1351 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1352 | int i; |
| 1353 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1354 | BUG_ON(sh->batch_head); |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1355 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1356 | (unsigned long long)sh->sector); |
| 1357 | |
| 1358 | for (i = sh->disks; i--; ) { |
| 1359 | struct r5dev *dev = &sh->dev[i]; |
| 1360 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 1361 | struct bio *rbi; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1362 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1363 | dev->read = rbi = dev->toread; |
| 1364 | dev->toread = NULL; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1365 | spin_unlock_irq(&sh->stripe_lock); |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1366 | while (rbi && rbi->bi_iter.bi_sector < |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1367 | dev->sector + STRIPE_SECTORS) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1368 | tx = async_copy_data(0, rbi, &dev->page, |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1369 | dev->sector, tx, sh, 0); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1370 | rbi = r5_next_bio(rbi, dev->sector); |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1376 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 1377 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1380 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 1381 | { |
| 1382 | struct r5dev *tgt; |
| 1383 | |
| 1384 | if (target < 0) |
| 1385 | return; |
| 1386 | |
| 1387 | tgt = &sh->dev[target]; |
| 1388 | set_bit(R5_UPTODATE, &tgt->flags); |
| 1389 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1390 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 1391 | } |
| 1392 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1393 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1394 | { |
| 1395 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1396 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1397 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1398 | (unsigned long long)sh->sector); |
| 1399 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1400 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1401 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1402 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1403 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1404 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 1405 | if (sh->check_state == check_state_compute_run) |
| 1406 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1407 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 1408 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1411 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 1412 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1413 | struct raid5_percpu *percpu, int i) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1414 | { |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1415 | void *addr; |
| 1416 | |
| 1417 | addr = flex_array_get(percpu->scribble, i); |
| 1418 | return addr + sizeof(struct page *) * (sh->disks + 2); |
| 1419 | } |
| 1420 | |
| 1421 | /* return a pointer to the address conversion region of the scribble buffer */ |
| 1422 | static struct page **to_addr_page(struct raid5_percpu *percpu, int i) |
| 1423 | { |
| 1424 | void *addr; |
| 1425 | |
| 1426 | addr = flex_array_get(percpu->scribble, i); |
| 1427 | return addr; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | static struct dma_async_tx_descriptor * |
| 1431 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1432 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1433 | int disks = sh->disks; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1434 | struct page **xor_srcs = to_addr_page(percpu, 0); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1435 | int target = sh->ops.target; |
| 1436 | struct r5dev *tgt = &sh->dev[target]; |
| 1437 | struct page *xor_dest = tgt->page; |
| 1438 | int count = 0; |
| 1439 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1440 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1441 | int i; |
| 1442 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1443 | BUG_ON(sh->batch_head); |
| 1444 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1445 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1446 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1447 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1448 | |
| 1449 | for (i = disks; i--; ) |
| 1450 | if (i != target) |
| 1451 | xor_srcs[count++] = sh->dev[i].page; |
| 1452 | |
| 1453 | atomic_inc(&sh->count); |
| 1454 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1455 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, NULL, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1456 | ops_complete_compute, sh, to_addr_conv(sh, percpu, 0)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1457 | if (unlikely(count == 1)) |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1458 | 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] | 1459 | else |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1460 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1461 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1462 | return tx; |
| 1463 | } |
| 1464 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1465 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 1466 | * @srcs - (struct page *) array of size sh->disks |
| 1467 | * @sh - stripe_head to parse |
| 1468 | * |
| 1469 | * Populates srcs in proper layout order for the stripe and returns the |
| 1470 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 1471 | * destination buffer is recorded in srcs[count] and the Q destination |
| 1472 | * is recorded in srcs[count+1]]. |
| 1473 | */ |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1474 | static int set_syndrome_sources(struct page **srcs, |
| 1475 | struct stripe_head *sh, |
| 1476 | int srctype) |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1477 | { |
| 1478 | int disks = sh->disks; |
| 1479 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 1480 | int d0_idx = raid6_d0(sh); |
| 1481 | int count; |
| 1482 | int i; |
| 1483 | |
| 1484 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1485 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1486 | |
| 1487 | count = 0; |
| 1488 | i = d0_idx; |
| 1489 | do { |
| 1490 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1491 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1492 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1493 | if (i == sh->qd_idx || i == sh->pd_idx || |
| 1494 | (srctype == SYNDROME_SRC_ALL) || |
| 1495 | (srctype == SYNDROME_SRC_WANT_DRAIN && |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1496 | (test_bit(R5_Wantdrain, &dev->flags) || |
| 1497 | test_bit(R5_InJournal, &dev->flags))) || |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1498 | (srctype == SYNDROME_SRC_WRITTEN && |
Song Liu | 0977762 | 2017-03-13 13:44:35 -0700 | [diff] [blame] | 1499 | (dev->written || |
| 1500 | test_bit(R5_InJournal, &dev->flags)))) { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1501 | if (test_bit(R5_InJournal, &dev->flags)) |
| 1502 | srcs[slot] = sh->dev[i].orig_page; |
| 1503 | else |
| 1504 | srcs[slot] = sh->dev[i].page; |
| 1505 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1506 | i = raid6_next_disk(i, disks); |
| 1507 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1508 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1509 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | static struct dma_async_tx_descriptor * |
| 1513 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1514 | { |
| 1515 | int disks = sh->disks; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1516 | struct page **blocks = to_addr_page(percpu, 0); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1517 | int target; |
| 1518 | int qd_idx = sh->qd_idx; |
| 1519 | struct dma_async_tx_descriptor *tx; |
| 1520 | struct async_submit_ctl submit; |
| 1521 | struct r5dev *tgt; |
| 1522 | struct page *dest; |
| 1523 | int i; |
| 1524 | int count; |
| 1525 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1526 | BUG_ON(sh->batch_head); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1527 | if (sh->ops.target < 0) |
| 1528 | target = sh->ops.target2; |
| 1529 | else if (sh->ops.target2 < 0) |
| 1530 | target = sh->ops.target; |
| 1531 | else |
| 1532 | /* we should only have one valid target */ |
| 1533 | BUG(); |
| 1534 | BUG_ON(target < 0); |
| 1535 | pr_debug("%s: stripe %llu block: %d\n", |
| 1536 | __func__, (unsigned long long)sh->sector, target); |
| 1537 | |
| 1538 | tgt = &sh->dev[target]; |
| 1539 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1540 | dest = tgt->page; |
| 1541 | |
| 1542 | atomic_inc(&sh->count); |
| 1543 | |
| 1544 | if (target == qd_idx) { |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1545 | count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_ALL); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1546 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 1547 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1548 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1549 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1550 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1551 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 1552 | } else { |
| 1553 | /* Compute any data- or p-drive using XOR */ |
| 1554 | count = 0; |
| 1555 | for (i = disks; i-- ; ) { |
| 1556 | if (i == target || i == qd_idx) |
| 1557 | continue; |
| 1558 | blocks[count++] = sh->dev[i].page; |
| 1559 | } |
| 1560 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1561 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1562 | NULL, ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1563 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1564 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, &submit); |
| 1565 | } |
| 1566 | |
| 1567 | return tx; |
| 1568 | } |
| 1569 | |
| 1570 | static struct dma_async_tx_descriptor * |
| 1571 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1572 | { |
| 1573 | int i, count, disks = sh->disks; |
| 1574 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 1575 | int d0_idx = raid6_d0(sh); |
| 1576 | int faila = -1, failb = -1; |
| 1577 | int target = sh->ops.target; |
| 1578 | int target2 = sh->ops.target2; |
| 1579 | struct r5dev *tgt = &sh->dev[target]; |
| 1580 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 1581 | struct dma_async_tx_descriptor *tx; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1582 | struct page **blocks = to_addr_page(percpu, 0); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1583 | struct async_submit_ctl submit; |
| 1584 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1585 | BUG_ON(sh->batch_head); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1586 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 1587 | __func__, (unsigned long long)sh->sector, target, target2); |
| 1588 | BUG_ON(target < 0 || target2 < 0); |
| 1589 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1590 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 1591 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1592 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1593 | * slot number conversion for 'faila' and 'failb' |
| 1594 | */ |
| 1595 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1596 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1597 | count = 0; |
| 1598 | i = d0_idx; |
| 1599 | do { |
| 1600 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 1601 | |
| 1602 | blocks[slot] = sh->dev[i].page; |
| 1603 | |
| 1604 | if (i == target) |
| 1605 | faila = slot; |
| 1606 | if (i == target2) |
| 1607 | failb = slot; |
| 1608 | i = raid6_next_disk(i, disks); |
| 1609 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1610 | |
| 1611 | BUG_ON(faila == failb); |
| 1612 | if (failb < faila) |
| 1613 | swap(faila, failb); |
| 1614 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 1615 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 1616 | |
| 1617 | atomic_inc(&sh->count); |
| 1618 | |
| 1619 | if (failb == syndrome_disks+1) { |
| 1620 | /* Q disk is one of the missing disks */ |
| 1621 | if (faila == syndrome_disks) { |
| 1622 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1623 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1624 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1625 | to_addr_conv(sh, percpu, 0)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1626 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1627 | STRIPE_SIZE, &submit); |
| 1628 | } else { |
| 1629 | struct page *dest; |
| 1630 | int data_target; |
| 1631 | int qd_idx = sh->qd_idx; |
| 1632 | |
| 1633 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 1634 | if (target == qd_idx) |
| 1635 | data_target = target2; |
| 1636 | else |
| 1637 | data_target = target; |
| 1638 | |
| 1639 | count = 0; |
| 1640 | for (i = disks; i-- ; ) { |
| 1641 | if (i == data_target || i == qd_idx) |
| 1642 | continue; |
| 1643 | blocks[count++] = sh->dev[i].page; |
| 1644 | } |
| 1645 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1646 | init_async_submit(&submit, |
| 1647 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1648 | NULL, NULL, NULL, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1649 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1650 | tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE, |
| 1651 | &submit); |
| 1652 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1653 | count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_ALL); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1654 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 1655 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1656 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1657 | return async_gen_syndrome(blocks, 0, count+2, |
| 1658 | STRIPE_SIZE, &submit); |
| 1659 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1660 | } else { |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1661 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1662 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1663 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1664 | if (failb == syndrome_disks) { |
| 1665 | /* We're missing D+P. */ |
| 1666 | return async_raid6_datap_recov(syndrome_disks+2, |
| 1667 | STRIPE_SIZE, faila, |
| 1668 | blocks, &submit); |
| 1669 | } else { |
| 1670 | /* We're missing D+D. */ |
| 1671 | return async_raid6_2data_recov(syndrome_disks+2, |
| 1672 | STRIPE_SIZE, faila, failb, |
| 1673 | blocks, &submit); |
| 1674 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1678 | static void ops_complete_prexor(void *stripe_head_ref) |
| 1679 | { |
| 1680 | struct stripe_head *sh = stripe_head_ref; |
| 1681 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1682 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1683 | (unsigned long long)sh->sector); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1684 | |
| 1685 | if (r5c_is_writeback(sh->raid_conf->log)) |
| 1686 | /* |
| 1687 | * raid5-cache write back uses orig_page during prexor. |
| 1688 | * After prexor, it is time to free orig_page |
| 1689 | */ |
| 1690 | r5c_release_extra_page(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | static struct dma_async_tx_descriptor * |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1694 | ops_run_prexor5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1695 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1696 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1697 | int disks = sh->disks; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1698 | struct page **xor_srcs = to_addr_page(percpu, 0); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1699 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1700 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1701 | |
| 1702 | /* existing parity data subtracted */ |
| 1703 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1704 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1705 | BUG_ON(sh->batch_head); |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1706 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1707 | (unsigned long long)sh->sector); |
| 1708 | |
| 1709 | for (i = disks; i--; ) { |
| 1710 | struct r5dev *dev = &sh->dev[i]; |
| 1711 | /* Only process blocks that are known to be uptodate */ |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1712 | if (test_bit(R5_InJournal, &dev->flags)) |
| 1713 | xor_srcs[count++] = dev->orig_page; |
| 1714 | else if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1715 | xor_srcs[count++] = dev->page; |
| 1716 | } |
| 1717 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1718 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_DROP_DST, tx, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1719 | ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1720 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1721 | |
| 1722 | return tx; |
| 1723 | } |
| 1724 | |
| 1725 | static struct dma_async_tx_descriptor * |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1726 | ops_run_prexor6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1727 | struct dma_async_tx_descriptor *tx) |
| 1728 | { |
| 1729 | struct page **blocks = to_addr_page(percpu, 0); |
| 1730 | int count; |
| 1731 | struct async_submit_ctl submit; |
| 1732 | |
| 1733 | pr_debug("%s: stripe %llu\n", __func__, |
| 1734 | (unsigned long long)sh->sector); |
| 1735 | |
| 1736 | count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_WANT_DRAIN); |
| 1737 | |
| 1738 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_PQ_XOR_DST, tx, |
| 1739 | ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); |
| 1740 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
| 1741 | |
| 1742 | return tx; |
| 1743 | } |
| 1744 | |
| 1745 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1746 | 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] | 1747 | { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1748 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1749 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1750 | int i; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1751 | struct stripe_head *head_sh = sh; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1752 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1753 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1754 | (unsigned long long)sh->sector); |
| 1755 | |
| 1756 | for (i = disks; i--; ) { |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1757 | struct r5dev *dev; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1758 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1759 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1760 | sh = head_sh; |
| 1761 | if (test_and_clear_bit(R5_Wantdrain, &head_sh->dev[i].flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1762 | struct bio *wbi; |
| 1763 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1764 | again: |
| 1765 | dev = &sh->dev[i]; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1766 | /* |
| 1767 | * clear R5_InJournal, so when rewriting a page in |
| 1768 | * journal, it is not skipped by r5l_log_stripe() |
| 1769 | */ |
| 1770 | clear_bit(R5_InJournal, &dev->flags); |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1771 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1772 | chosen = dev->towrite; |
| 1773 | dev->towrite = NULL; |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1774 | sh->overwrite_disks = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1775 | BUG_ON(dev->written); |
| 1776 | wbi = dev->written = chosen; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1777 | spin_unlock_irq(&sh->stripe_lock); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1778 | WARN_ON(dev->page != dev->orig_page); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1779 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1780 | while (wbi && wbi->bi_iter.bi_sector < |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1781 | dev->sector + STRIPE_SECTORS) { |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1782 | if (wbi->bi_opf & REQ_FUA) |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1783 | set_bit(R5_WantFUA, &dev->flags); |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1784 | if (wbi->bi_opf & REQ_SYNC) |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1785 | set_bit(R5_SyncIO, &dev->flags); |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1786 | if (bio_op(wbi) == REQ_OP_DISCARD) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1787 | set_bit(R5_Discard, &dev->flags); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1788 | else { |
| 1789 | tx = async_copy_data(1, wbi, &dev->page, |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1790 | dev->sector, tx, sh, |
| 1791 | r5c_is_writeback(conf->log)); |
| 1792 | if (dev->page != dev->orig_page && |
| 1793 | !r5c_is_writeback(conf->log)) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1794 | set_bit(R5_SkipCopy, &dev->flags); |
| 1795 | clear_bit(R5_UPTODATE, &dev->flags); |
| 1796 | clear_bit(R5_OVERWRITE, &dev->flags); |
| 1797 | } |
| 1798 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1799 | wbi = r5_next_bio(wbi, dev->sector); |
| 1800 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1801 | |
| 1802 | if (head_sh->batch_head) { |
| 1803 | sh = list_first_entry(&sh->batch_list, |
| 1804 | struct stripe_head, |
| 1805 | batch_list); |
| 1806 | if (sh == head_sh) |
| 1807 | continue; |
| 1808 | goto again; |
| 1809 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | return tx; |
| 1814 | } |
| 1815 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1816 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1817 | { |
| 1818 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1819 | int disks = sh->disks; |
| 1820 | int pd_idx = sh->pd_idx; |
| 1821 | int qd_idx = sh->qd_idx; |
| 1822 | int i; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1823 | bool fua = false, sync = false, discard = false; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1824 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1825 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1826 | (unsigned long long)sh->sector); |
| 1827 | |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1828 | for (i = disks; i--; ) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1829 | fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1830 | sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1831 | discard |= test_bit(R5_Discard, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1832 | } |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1833 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1834 | for (i = disks; i--; ) { |
| 1835 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1836 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1837 | if (dev->written || i == pd_idx || i == qd_idx) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1838 | if (!discard && !test_bit(R5_SkipCopy, &dev->flags)) |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1839 | set_bit(R5_UPTODATE, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1840 | if (fua) |
| 1841 | set_bit(R5_WantFUA, &dev->flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1842 | if (sync) |
| 1843 | set_bit(R5_SyncIO, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1844 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1847 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 1848 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 1849 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 1850 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 1851 | else { |
| 1852 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 1853 | sh->reconstruct_state = reconstruct_state_result; |
| 1854 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1855 | |
| 1856 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 1857 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1861 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1862 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1863 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1864 | int disks = sh->disks; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1865 | struct page **xor_srcs; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1866 | struct async_submit_ctl submit; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1867 | int count, pd_idx = sh->pd_idx, i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1868 | struct page *xor_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1869 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1870 | unsigned long flags; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1871 | int j = 0; |
| 1872 | struct stripe_head *head_sh = sh; |
| 1873 | int last_stripe; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1874 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1875 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1876 | (unsigned long long)sh->sector); |
| 1877 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1878 | for (i = 0; i < sh->disks; i++) { |
| 1879 | if (pd_idx == i) |
| 1880 | continue; |
| 1881 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1882 | break; |
| 1883 | } |
| 1884 | if (i >= sh->disks) { |
| 1885 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1886 | set_bit(R5_Discard, &sh->dev[pd_idx].flags); |
| 1887 | ops_complete_reconstruct(sh); |
| 1888 | return; |
| 1889 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1890 | again: |
| 1891 | count = 0; |
| 1892 | xor_srcs = to_addr_page(percpu, j); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1893 | /* check if prexor is active which means only process blocks |
| 1894 | * that are part of a read-modify-write (written) |
| 1895 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1896 | if (head_sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1897 | prexor = 1; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1898 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1899 | for (i = disks; i--; ) { |
| 1900 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1901 | if (head_sh->dev[i].written || |
| 1902 | test_bit(R5_InJournal, &head_sh->dev[i].flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1903 | xor_srcs[count++] = dev->page; |
| 1904 | } |
| 1905 | } else { |
| 1906 | xor_dest = sh->dev[pd_idx].page; |
| 1907 | for (i = disks; i--; ) { |
| 1908 | struct r5dev *dev = &sh->dev[i]; |
| 1909 | if (i != pd_idx) |
| 1910 | xor_srcs[count++] = dev->page; |
| 1911 | } |
| 1912 | } |
| 1913 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1914 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1915 | * 2/ if we did not prexor then we are redoing the parity |
| 1916 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1917 | * for the synchronous xor case |
| 1918 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1919 | last_stripe = !head_sh->batch_head || |
| 1920 | list_first_entry(&sh->batch_list, |
| 1921 | struct stripe_head, batch_list) == head_sh; |
| 1922 | if (last_stripe) { |
| 1923 | flags = ASYNC_TX_ACK | |
| 1924 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1925 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1926 | atomic_inc(&head_sh->count); |
| 1927 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, head_sh, |
| 1928 | to_addr_conv(sh, percpu, j)); |
| 1929 | } else { |
| 1930 | flags = prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST; |
| 1931 | init_async_submit(&submit, flags, tx, NULL, NULL, |
| 1932 | to_addr_conv(sh, percpu, j)); |
| 1933 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1934 | |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1935 | if (unlikely(count == 1)) |
| 1936 | tx = async_memcpy(xor_dest, xor_srcs[0], 0, 0, STRIPE_SIZE, &submit); |
| 1937 | else |
| 1938 | tx = async_xor(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, &submit); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1939 | if (!last_stripe) { |
| 1940 | j++; |
| 1941 | sh = list_first_entry(&sh->batch_list, struct stripe_head, |
| 1942 | batch_list); |
| 1943 | goto again; |
| 1944 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1947 | static void |
| 1948 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1949 | struct dma_async_tx_descriptor *tx) |
| 1950 | { |
| 1951 | struct async_submit_ctl submit; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1952 | struct page **blocks; |
| 1953 | int count, i, j = 0; |
| 1954 | struct stripe_head *head_sh = sh; |
| 1955 | int last_stripe; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1956 | int synflags; |
| 1957 | unsigned long txflags; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1958 | |
| 1959 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1960 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1961 | for (i = 0; i < sh->disks; i++) { |
| 1962 | if (sh->pd_idx == i || sh->qd_idx == i) |
| 1963 | continue; |
| 1964 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1965 | break; |
| 1966 | } |
| 1967 | if (i >= sh->disks) { |
| 1968 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1969 | set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 1970 | set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 1971 | ops_complete_reconstruct(sh); |
| 1972 | return; |
| 1973 | } |
| 1974 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1975 | again: |
| 1976 | blocks = to_addr_page(percpu, j); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1977 | |
| 1978 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1979 | synflags = SYNDROME_SRC_WRITTEN; |
| 1980 | txflags = ASYNC_TX_ACK | ASYNC_TX_PQ_XOR_DST; |
| 1981 | } else { |
| 1982 | synflags = SYNDROME_SRC_ALL; |
| 1983 | txflags = ASYNC_TX_ACK; |
| 1984 | } |
| 1985 | |
| 1986 | count = set_syndrome_sources(blocks, sh, synflags); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1987 | last_stripe = !head_sh->batch_head || |
| 1988 | list_first_entry(&sh->batch_list, |
| 1989 | struct stripe_head, batch_list) == head_sh; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1990 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1991 | if (last_stripe) { |
| 1992 | atomic_inc(&head_sh->count); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1993 | init_async_submit(&submit, txflags, tx, ops_complete_reconstruct, |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1994 | head_sh, to_addr_conv(sh, percpu, j)); |
| 1995 | } else |
| 1996 | init_async_submit(&submit, 0, tx, NULL, NULL, |
| 1997 | to_addr_conv(sh, percpu, j)); |
Shaohua Li | 4876969 | 2015-05-13 09:30:08 -0700 | [diff] [blame] | 1998 | tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1999 | if (!last_stripe) { |
| 2000 | j++; |
| 2001 | sh = list_first_entry(&sh->batch_list, struct stripe_head, |
| 2002 | batch_list); |
| 2003 | goto again; |
| 2004 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | static void ops_complete_check(void *stripe_head_ref) |
| 2008 | { |
| 2009 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2010 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2011 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2012 | (unsigned long long)sh->sector); |
| 2013 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2014 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2015 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2016 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2019 | 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] | 2020 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2021 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2022 | int pd_idx = sh->pd_idx; |
| 2023 | int qd_idx = sh->qd_idx; |
| 2024 | struct page *xor_dest; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2025 | struct page **xor_srcs = to_addr_page(percpu, 0); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2026 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2027 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2028 | int count; |
| 2029 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2030 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2031 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2032 | (unsigned long long)sh->sector); |
| 2033 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2034 | BUG_ON(sh->batch_head); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2035 | count = 0; |
| 2036 | xor_dest = sh->dev[pd_idx].page; |
| 2037 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2038 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2039 | if (i == pd_idx || i == qd_idx) |
| 2040 | continue; |
| 2041 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2044 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2045 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | 099f53c | 2009-04-08 14:28:37 -0700 | [diff] [blame] | 2046 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2047 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2048 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2049 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2050 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 2051 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2054 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 2055 | { |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2056 | struct page **srcs = to_addr_page(percpu, 0); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2057 | struct async_submit_ctl submit; |
| 2058 | int count; |
| 2059 | |
| 2060 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 2061 | (unsigned long long)sh->sector, checkp); |
| 2062 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2063 | BUG_ON(sh->batch_head); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 2064 | count = set_syndrome_sources(srcs, sh, SYNDROME_SRC_ALL); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2065 | if (!checkp) |
| 2066 | srcs[count] = NULL; |
| 2067 | |
| 2068 | atomic_inc(&sh->count); |
| 2069 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2070 | sh, to_addr_conv(sh, percpu, 0)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2071 | async_syndrome_val(srcs, 0, count+2, STRIPE_SIZE, |
| 2072 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 2073 | } |
| 2074 | |
NeilBrown | 51acbce | 2013-02-28 09:08:34 +1100 | [diff] [blame] | 2075 | 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] | 2076 | { |
| 2077 | int overlap_clear = 0, i, disks = sh->disks; |
| 2078 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2079 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2080 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2081 | struct raid5_percpu *percpu; |
| 2082 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2083 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2084 | cpu = get_cpu(); |
| 2085 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2086 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2087 | ops_run_biofill(sh); |
| 2088 | overlap_clear++; |
| 2089 | } |
| 2090 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 2091 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2092 | if (level < 6) |
| 2093 | tx = ops_run_compute5(sh, percpu); |
| 2094 | else { |
| 2095 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 2096 | tx = ops_run_compute6_1(sh, percpu); |
| 2097 | else |
| 2098 | tx = ops_run_compute6_2(sh, percpu); |
| 2099 | } |
| 2100 | /* terminate the chain if reconstruct is not set to be run */ |
| 2101 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 2102 | async_tx_ack(tx); |
| 2103 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2104 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 2105 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) { |
| 2106 | if (level < 6) |
| 2107 | tx = ops_run_prexor5(sh, percpu, tx); |
| 2108 | else |
| 2109 | tx = ops_run_prexor6(sh, percpu, tx); |
| 2110 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2111 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2112 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2113 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2114 | overlap_clear++; |
| 2115 | } |
| 2116 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2117 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 2118 | if (level < 6) |
| 2119 | ops_run_reconstruct5(sh, percpu, tx); |
| 2120 | else |
| 2121 | ops_run_reconstruct6(sh, percpu, tx); |
| 2122 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2123 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2124 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 2125 | if (sh->check_state == check_state_run) |
| 2126 | ops_run_check_p(sh, percpu); |
| 2127 | else if (sh->check_state == check_state_run_q) |
| 2128 | ops_run_check_pq(sh, percpu, 0); |
| 2129 | else if (sh->check_state == check_state_run_pq) |
| 2130 | ops_run_check_pq(sh, percpu, 1); |
| 2131 | else |
| 2132 | BUG(); |
| 2133 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2134 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2135 | if (overlap_clear && !sh->batch_head) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2136 | for (i = disks; i--; ) { |
| 2137 | struct r5dev *dev = &sh->dev[i]; |
| 2138 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 2139 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 2140 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2141 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2144 | static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp, |
| 2145 | int disks) |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2146 | { |
| 2147 | struct stripe_head *sh; |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2148 | int i; |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2149 | |
| 2150 | sh = kmem_cache_zalloc(sc, gfp); |
| 2151 | if (sh) { |
| 2152 | spin_lock_init(&sh->stripe_lock); |
| 2153 | spin_lock_init(&sh->batch_lock); |
| 2154 | INIT_LIST_HEAD(&sh->batch_list); |
| 2155 | INIT_LIST_HEAD(&sh->lru); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 2156 | INIT_LIST_HEAD(&sh->r5c); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 2157 | INIT_LIST_HEAD(&sh->log_list); |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2158 | atomic_set(&sh->count, 1); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 2159 | sh->log_start = MaxSector; |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2160 | for (i = 0; i < disks; i++) { |
| 2161 | struct r5dev *dev = &sh->dev[i]; |
| 2162 | |
Ming Lei | 3a83f46 | 2016-11-22 08:57:21 -0700 | [diff] [blame] | 2163 | bio_init(&dev->req, &dev->vec, 1); |
| 2164 | bio_init(&dev->rreq, &dev->rvec, 1); |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2165 | } |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2166 | } |
| 2167 | return sh; |
| 2168 | } |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2169 | static int grow_one_stripe(struct r5conf *conf, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | { |
| 2171 | struct stripe_head *sh; |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2172 | |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2173 | sh = alloc_stripe(conf->slab_cache, gfp, conf->pool_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2174 | if (!sh) |
| 2175 | return 0; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 2176 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2177 | sh->raid_conf = conf; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2178 | |
NeilBrown | a9683a7 | 2015-02-25 12:02:51 +1100 | [diff] [blame] | 2179 | if (grow_buffers(sh, gfp)) { |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 2180 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2181 | kmem_cache_free(conf->slab_cache, sh); |
| 2182 | return 0; |
| 2183 | } |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2184 | sh->hash_lock_index = |
| 2185 | conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2186 | /* we just created an active stripe so... */ |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2187 | atomic_inc(&conf->active_stripes); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2188 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2189 | raid5_release_stripe(sh); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2190 | conf->max_nr_stripes++; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2191 | return 1; |
| 2192 | } |
| 2193 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2194 | static int grow_stripes(struct r5conf *conf, int num) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2195 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 2196 | struct kmem_cache *sc; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 2197 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 2199 | if (conf->mddev->gendisk) |
| 2200 | sprintf(conf->cache_name[0], |
| 2201 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 2202 | else |
| 2203 | sprintf(conf->cache_name[0], |
| 2204 | "raid%d-%p", conf->level, conf->mddev); |
| 2205 | sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]); |
| 2206 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2207 | conf->active_name = 0; |
| 2208 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2210 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | if (!sc) |
| 2212 | return 1; |
| 2213 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2214 | conf->pool_size = devs; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2215 | while (num--) |
| 2216 | if (!grow_one_stripe(conf, GFP_KERNEL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | return 1; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | return 0; |
| 2220 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2221 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2222 | /** |
| 2223 | * scribble_len - return the required size of the scribble region |
| 2224 | * @num - total number of disks in the array |
| 2225 | * |
| 2226 | * The size must be enough to contain: |
| 2227 | * 1/ a struct page pointer for each device in the array +2 |
| 2228 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 2229 | * (dma_map_page()) or page (page_address()) address. |
| 2230 | * |
| 2231 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 2232 | * calculate over all devices (not just the data blocks), using zeros in place |
| 2233 | * of the P and Q blocks. |
| 2234 | */ |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2235 | static struct flex_array *scribble_alloc(int num, int cnt, gfp_t flags) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2236 | { |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2237 | struct flex_array *ret; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2238 | size_t len; |
| 2239 | |
| 2240 | len = sizeof(struct page *) * (num+2) + sizeof(addr_conv_t) * (num+2); |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2241 | ret = flex_array_alloc(len, cnt, flags); |
| 2242 | if (!ret) |
| 2243 | return NULL; |
| 2244 | /* always prealloc all elements, so no locking is required */ |
| 2245 | if (flex_array_prealloc(ret, 0, cnt, flags)) { |
| 2246 | flex_array_free(ret); |
| 2247 | return NULL; |
| 2248 | } |
| 2249 | return ret; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2252 | static int resize_chunks(struct r5conf *conf, int new_disks, int new_sectors) |
| 2253 | { |
| 2254 | unsigned long cpu; |
| 2255 | int err = 0; |
| 2256 | |
Shaohua Li | 27a353c | 2016-02-24 17:38:28 -0800 | [diff] [blame] | 2257 | /* |
| 2258 | * Never shrink. And mddev_suspend() could deadlock if this is called |
| 2259 | * from raid5d. In that case, scribble_disks and scribble_sectors |
| 2260 | * should equal to new_disks and new_sectors |
| 2261 | */ |
| 2262 | if (conf->scribble_disks >= new_disks && |
| 2263 | conf->scribble_sectors >= new_sectors) |
| 2264 | return 0; |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2265 | mddev_suspend(conf->mddev); |
| 2266 | get_online_cpus(); |
| 2267 | for_each_present_cpu(cpu) { |
| 2268 | struct raid5_percpu *percpu; |
| 2269 | struct flex_array *scribble; |
| 2270 | |
| 2271 | percpu = per_cpu_ptr(conf->percpu, cpu); |
| 2272 | scribble = scribble_alloc(new_disks, |
| 2273 | new_sectors / STRIPE_SECTORS, |
| 2274 | GFP_NOIO); |
| 2275 | |
| 2276 | if (scribble) { |
| 2277 | flex_array_free(percpu->scribble); |
| 2278 | percpu->scribble = scribble; |
| 2279 | } else { |
| 2280 | err = -ENOMEM; |
| 2281 | break; |
| 2282 | } |
| 2283 | } |
| 2284 | put_online_cpus(); |
| 2285 | mddev_resume(conf->mddev); |
Shaohua Li | 27a353c | 2016-02-24 17:38:28 -0800 | [diff] [blame] | 2286 | if (!err) { |
| 2287 | conf->scribble_disks = new_disks; |
| 2288 | conf->scribble_sectors = new_sectors; |
| 2289 | } |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2290 | return err; |
| 2291 | } |
| 2292 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2293 | static int resize_stripes(struct r5conf *conf, int newsize) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2294 | { |
| 2295 | /* Make all the stripes able to hold 'newsize' devices. |
| 2296 | * New slots in each stripe get 'page' set to a new page. |
| 2297 | * |
| 2298 | * This happens in stages: |
| 2299 | * 1/ create a new kmem_cache and allocate the required number of |
| 2300 | * stripe_heads. |
Masanari Iida | 83f0d77 | 2012-10-30 00:18:08 +0900 | [diff] [blame] | 2301 | * 2/ gather all the old stripe_heads and transfer the pages across |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2302 | * to the new stripe_heads. This will have the side effect of |
| 2303 | * freezing the array as once all stripe_heads have been collected, |
| 2304 | * no IO will be possible. Old stripe heads are freed once their |
| 2305 | * pages have been transferred over, and the old kmem_cache is |
| 2306 | * freed when all stripes are done. |
| 2307 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
| 2308 | * we simple return a failre status - no need to clean anything up. |
| 2309 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 2310 | * If this fails, we don't bother trying the shrink the |
| 2311 | * stripe_heads down again, we just leave them as they are. |
| 2312 | * As each stripe_head is processed the new one is released into |
| 2313 | * active service. |
| 2314 | * |
| 2315 | * Once step2 is started, we cannot afford to wait for a write, |
| 2316 | * so we use GFP_NOIO allocations. |
| 2317 | */ |
| 2318 | struct stripe_head *osh, *nsh; |
| 2319 | LIST_HEAD(newstripes); |
| 2320 | struct disk_info *ndisks; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 2321 | int err; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 2322 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2323 | int i; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2324 | int hash, cnt; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2325 | |
| 2326 | if (newsize <= conf->pool_size) |
| 2327 | return 0; /* never bother to shrink */ |
| 2328 | |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 2329 | err = md_allow_write(conf->mddev); |
| 2330 | if (err) |
| 2331 | return err; |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 2332 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2333 | /* Step 1 */ |
| 2334 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 2335 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2336 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2337 | if (!sc) |
| 2338 | return -ENOMEM; |
| 2339 | |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 2340 | /* Need to ensure auto-resizing doesn't interfere */ |
| 2341 | mutex_lock(&conf->cache_size_mutex); |
| 2342 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2343 | for (i = conf->max_nr_stripes; i; i--) { |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2344 | nsh = alloc_stripe(sc, GFP_KERNEL, newsize); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2345 | if (!nsh) |
| 2346 | break; |
| 2347 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2348 | nsh->raid_conf = conf; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2349 | list_add(&nsh->lru, &newstripes); |
| 2350 | } |
| 2351 | if (i) { |
| 2352 | /* didn't get enough, give up */ |
| 2353 | while (!list_empty(&newstripes)) { |
| 2354 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 2355 | list_del(&nsh->lru); |
| 2356 | kmem_cache_free(sc, nsh); |
| 2357 | } |
| 2358 | kmem_cache_destroy(sc); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 2359 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2360 | return -ENOMEM; |
| 2361 | } |
| 2362 | /* Step 2 - Must use GFP_NOIO now. |
| 2363 | * OK, we have enough stripes, start collecting inactive |
| 2364 | * stripes and copying them over |
| 2365 | */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2366 | hash = 0; |
| 2367 | cnt = 0; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2368 | list_for_each_entry(nsh, &newstripes, lru) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2369 | lock_device_hash_lock(conf, hash); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 2370 | wait_event_cmd(conf->wait_for_stripe, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2371 | !list_empty(conf->inactive_list + hash), |
| 2372 | unlock_device_hash_lock(conf, hash), |
| 2373 | lock_device_hash_lock(conf, hash)); |
| 2374 | osh = get_free_stripe(conf, hash); |
| 2375 | unlock_device_hash_lock(conf, hash); |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2376 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2377 | for(i=0; i<conf->pool_size; i++) { |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2378 | nsh->dev[i].page = osh->dev[i].page; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2379 | nsh->dev[i].orig_page = osh->dev[i].page; |
| 2380 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2381 | nsh->hash_lock_index = hash; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2382 | kmem_cache_free(conf->slab_cache, osh); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2383 | cnt++; |
| 2384 | if (cnt >= conf->max_nr_stripes / NR_STRIPE_HASH_LOCKS + |
| 2385 | !!((conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS) > hash)) { |
| 2386 | hash++; |
| 2387 | cnt = 0; |
| 2388 | } |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2389 | } |
| 2390 | kmem_cache_destroy(conf->slab_cache); |
| 2391 | |
| 2392 | /* Step 3. |
| 2393 | * At this point, we are holding all the stripes so the array |
| 2394 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2395 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2396 | */ |
| 2397 | ndisks = kzalloc(newsize * sizeof(struct disk_info), GFP_NOIO); |
| 2398 | if (ndisks) { |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 2399 | for (i = 0; i < conf->pool_size; i++) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2400 | ndisks[i] = conf->disks[i]; |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 2401 | |
| 2402 | for (i = conf->pool_size; i < newsize; i++) { |
| 2403 | ndisks[i].extra_page = alloc_page(GFP_NOIO); |
| 2404 | if (!ndisks[i].extra_page) |
| 2405 | err = -ENOMEM; |
| 2406 | } |
| 2407 | |
| 2408 | if (err) { |
| 2409 | for (i = conf->pool_size; i < newsize; i++) |
| 2410 | if (ndisks[i].extra_page) |
| 2411 | put_page(ndisks[i].extra_page); |
| 2412 | kfree(ndisks); |
| 2413 | } else { |
| 2414 | kfree(conf->disks); |
| 2415 | conf->disks = ndisks; |
| 2416 | } |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2417 | } else |
| 2418 | err = -ENOMEM; |
| 2419 | |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 2420 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2421 | /* Step 4, return new stripes to service */ |
| 2422 | while(!list_empty(&newstripes)) { |
| 2423 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 2424 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2425 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2426 | for (i=conf->raid_disks; i < newsize; i++) |
| 2427 | if (nsh->dev[i].page == NULL) { |
| 2428 | struct page *p = alloc_page(GFP_NOIO); |
| 2429 | nsh->dev[i].page = p; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2430 | nsh->dev[i].orig_page = p; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2431 | if (!p) |
| 2432 | err = -ENOMEM; |
| 2433 | } |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2434 | raid5_release_stripe(nsh); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2435 | } |
| 2436 | /* critical section pass, GFP_NOIO no longer needed */ |
| 2437 | |
| 2438 | conf->slab_cache = sc; |
| 2439 | conf->active_name = 1-conf->active_name; |
NeilBrown | 6e9eac2 | 2015-05-08 18:19:34 +1000 | [diff] [blame] | 2440 | if (!err) |
| 2441 | conf->pool_size = newsize; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2442 | return err; |
| 2443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2445 | static int drop_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | { |
| 2447 | struct stripe_head *sh; |
NeilBrown | 49895bc | 2015-08-03 17:09:57 +1000 | [diff] [blame] | 2448 | int hash = (conf->max_nr_stripes - 1) & STRIPE_HASH_LOCKS_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2450 | spin_lock_irq(conf->hash_locks + hash); |
| 2451 | sh = get_free_stripe(conf, hash); |
| 2452 | spin_unlock_irq(conf->hash_locks + hash); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2453 | if (!sh) |
| 2454 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2455 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 2456 | shrink_buffers(sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2457 | kmem_cache_free(conf->slab_cache, sh); |
| 2458 | atomic_dec(&conf->active_stripes); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2459 | conf->max_nr_stripes--; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2460 | return 1; |
| 2461 | } |
| 2462 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2463 | static void shrink_stripes(struct r5conf *conf) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2464 | { |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2465 | while (conf->max_nr_stripes && |
| 2466 | drop_one_stripe(conf)) |
| 2467 | ; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2468 | |
Julia Lawall | 644df1a | 2015-09-13 14:15:10 +0200 | [diff] [blame] | 2469 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | conf->slab_cache = NULL; |
| 2471 | } |
| 2472 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2473 | static void raid5_end_read_request(struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2475 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2476 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 2477 | int disks = sh->disks, i; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 2478 | char b[BDEVNAME_SIZE]; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2479 | struct md_rdev *rdev = NULL; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2480 | sector_t s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | |
| 2482 | for (i=0 ; i<disks; i++) |
| 2483 | if (bi == &sh->dev[i].req) |
| 2484 | break; |
| 2485 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2486 | pr_debug("end_read_request %llu/%d, count: %d, error %d.\n", |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2487 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2488 | bi->bi_error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | if (i == disks) { |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2490 | bio_reset(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 2492 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2494 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2495 | /* If replacement finished while this request was outstanding, |
| 2496 | * 'replacement' might be NULL already. |
| 2497 | * In that case it moved down to 'rdev'. |
| 2498 | * rdev is not removed until all requests are finished. |
| 2499 | */ |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2500 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2501 | if (!rdev) |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2502 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2504 | if (use_new_offset(conf, sh)) |
| 2505 | s = sh->sector + rdev->new_data_offset; |
| 2506 | else |
| 2507 | s = sh->sector + rdev->data_offset; |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2508 | if (!bi->bi_error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2510 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2511 | /* Note that this cannot happen on a |
| 2512 | * replacement device. We just fail those on |
| 2513 | * any error |
| 2514 | */ |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2515 | pr_info_ratelimited( |
| 2516 | "md/raid:%s: read error corrected (%lu sectors at %llu on %s)\n", |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2517 | mdname(conf->mddev), STRIPE_SECTORS, |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2518 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2519 | bdevname(rdev->bdev, b)); |
Namhyung Kim | ddd5115 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2520 | atomic_add(STRIPE_SECTORS, &rdev->corrected_errors); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2521 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 2522 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 2523 | } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 2524 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 2525 | |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 2526 | if (test_bit(R5_InJournal, &sh->dev[i].flags)) |
| 2527 | /* |
| 2528 | * end read for a page in journal, this |
| 2529 | * must be preparing for prexor in rmw |
| 2530 | */ |
| 2531 | set_bit(R5_OrigPageUPTDODATE, &sh->dev[i].flags); |
| 2532 | |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2533 | if (atomic_read(&rdev->read_errors)) |
| 2534 | atomic_set(&rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | } else { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2536 | const char *bdn = bdevname(rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2537 | int retry = 0; |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2538 | int set_bad = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 2539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 2541 | atomic_inc(&rdev->read_errors); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2542 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2543 | pr_warn_ratelimited( |
| 2544 | "md/raid:%s: read error on replacement device (sector %llu on %s).\n", |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2545 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2546 | (unsigned long long)s, |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2547 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2548 | else if (conf->mddev->degraded >= conf->max_degraded) { |
| 2549 | set_bad = 1; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2550 | pr_warn_ratelimited( |
| 2551 | "md/raid:%s: read error not correctable (sector %llu on %s).\n", |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2552 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2553 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2554 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2555 | } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2556 | /* Oh, no!!! */ |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2557 | set_bad = 1; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2558 | pr_warn_ratelimited( |
| 2559 | "md/raid:%s: read error NOT corrected!! (sector %llu on %s).\n", |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2560 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2561 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2562 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2563 | } else if (atomic_read(&rdev->read_errors) |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2564 | > conf->max_nr_stripes) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2565 | pr_warn("md/raid:%s: Too many read errors, failing device %s.\n", |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 2566 | mdname(conf->mddev), bdn); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2567 | else |
| 2568 | retry = 1; |
Bian Yu | edfa1f6 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2569 | if (set_bad && test_bit(In_sync, &rdev->flags) |
| 2570 | && !test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 2571 | retry = 1; |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2572 | if (retry) |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 2573 | if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { |
| 2574 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 2575 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 2576 | } else |
| 2577 | set_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2578 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2579 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 2580 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2581 | if (!(set_bad |
| 2582 | && test_bit(In_sync, &rdev->flags) |
| 2583 | && rdev_set_badblocks( |
| 2584 | rdev, sh->sector, STRIPE_SECTORS, 0))) |
| 2585 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2588 | rdev_dec_pending(rdev, conf->mddev); |
Shaohua Li | c944555 | 2016-09-08 10:43:58 -0700 | [diff] [blame] | 2589 | bio_reset(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 2591 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2592 | raid5_release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2595 | static void raid5_end_write_request(struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2597 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2598 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 2599 | int disks = sh->disks, i; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2600 | struct md_rdev *uninitialized_var(rdev); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2601 | sector_t first_bad; |
| 2602 | int bad_sectors; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2603 | int replacement = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2605 | for (i = 0 ; i < disks; i++) { |
| 2606 | if (bi == &sh->dev[i].req) { |
| 2607 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | break; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2609 | } |
| 2610 | if (bi == &sh->dev[i].rreq) { |
| 2611 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2612 | if (rdev) |
| 2613 | replacement = 1; |
| 2614 | else |
| 2615 | /* rdev was removed and 'replacement' |
| 2616 | * replaced it. rdev is not removed |
| 2617 | * until all requests are finished. |
| 2618 | */ |
| 2619 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2620 | break; |
| 2621 | } |
| 2622 | } |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2623 | pr_debug("end_write_request %llu/%d, count %d, error: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2625 | bi->bi_error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | if (i == disks) { |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2627 | bio_reset(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 2629 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2632 | if (replacement) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2633 | if (bi->bi_error) |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2634 | md_error(conf->mddev, rdev); |
| 2635 | else if (is_badblock(rdev, sh->sector, |
| 2636 | STRIPE_SECTORS, |
| 2637 | &first_bad, &bad_sectors)) |
| 2638 | set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); |
| 2639 | } else { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2640 | if (bi->bi_error) { |
NeilBrown | 9f97e4b | 2014-01-16 09:35:38 +1100 | [diff] [blame] | 2641 | set_bit(STRIPE_DEGRADED, &sh->state); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2642 | set_bit(WriteErrorSeen, &rdev->flags); |
| 2643 | set_bit(R5_WriteError, &sh->dev[i].flags); |
NeilBrown | 3a6de29 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2644 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) |
| 2645 | set_bit(MD_RECOVERY_NEEDED, |
| 2646 | &rdev->mddev->recovery); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2647 | } else if (is_badblock(rdev, sh->sector, |
| 2648 | STRIPE_SECTORS, |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 2649 | &first_bad, &bad_sectors)) { |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2650 | set_bit(R5_MadeGood, &sh->dev[i].flags); |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 2651 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) |
| 2652 | /* That was a successful write so make |
| 2653 | * sure it looks like we already did |
| 2654 | * a re-write. |
| 2655 | */ |
| 2656 | set_bit(R5_ReWrite, &sh->dev[i].flags); |
| 2657 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2658 | } |
| 2659 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2661 | if (sh->batch_head && bi->bi_error && !replacement) |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2662 | set_bit(STRIPE_BATCH_ERR, &sh->batch_head->state); |
| 2663 | |
Shaohua Li | c944555 | 2016-09-08 10:43:58 -0700 | [diff] [blame] | 2664 | bio_reset(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2665 | if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) |
| 2666 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2668 | raid5_release_stripe(sh); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2669 | |
| 2670 | if (sh->batch_head && sh != sh->batch_head) |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2671 | raid5_release_stripe(sh->batch_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 2674 | 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] | 2675 | { |
| 2676 | struct r5dev *dev = &sh->dev[i]; |
| 2677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | dev->flags = 0; |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2679 | dev->sector = raid5_compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 2682 | static void raid5_error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | { |
| 2684 | char b[BDEVNAME_SIZE]; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2685 | struct r5conf *conf = mddev->private; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2686 | unsigned long flags; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2687 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2689 | spin_lock_irqsave(&conf->device_lock, flags); |
| 2690 | clear_bit(In_sync, &rdev->flags); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 2691 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2692 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 2693 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 2694 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 2695 | set_bit(Blocked, &rdev->flags); |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 2696 | set_bit(Faulty, &rdev->flags); |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 2697 | set_mask_bits(&mddev->sb_flags, 0, |
| 2698 | BIT(MD_SB_CHANGE_DEVS) | BIT(MD_SB_CHANGE_PENDING)); |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2699 | pr_crit("md/raid:%s: Disk failure on %s, disabling device.\n" |
| 2700 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 2701 | mdname(mddev), |
| 2702 | bdevname(rdev->bdev, b), |
| 2703 | mdname(mddev), |
| 2704 | conf->raid_disks - mddev->degraded); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 2705 | r5c_update_on_rdev_error(mddev); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
| 2708 | /* |
| 2709 | * Input: a 'big' sector number, |
| 2710 | * Output: index of the data and parity disk, and the sector # in them. |
| 2711 | */ |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2712 | sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, |
| 2713 | int previous, int *dd_idx, |
| 2714 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | { |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2716 | sector_t stripe, stripe2; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2717 | sector_t chunk_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2719 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2720 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2722 | int algorithm = previous ? conf->prev_algo |
| 2723 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2724 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2725 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2726 | int raid_disks = previous ? conf->previous_raid_disks |
| 2727 | : conf->raid_disks; |
| 2728 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | |
| 2730 | /* First compute the information on this sector */ |
| 2731 | |
| 2732 | /* |
| 2733 | * Compute the chunk number and the sector offset inside the chunk |
| 2734 | */ |
| 2735 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 2736 | chunk_number = r_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
| 2738 | /* |
| 2739 | * Compute the stripe number |
| 2740 | */ |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2741 | stripe = chunk_number; |
| 2742 | *dd_idx = sector_div(stripe, data_disks); |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2743 | stripe2 = stripe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | /* |
| 2745 | * Select the parity disk based on the user selected algorithm. |
| 2746 | */ |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2747 | pd_idx = qd_idx = -1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2748 | switch(conf->level) { |
| 2749 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2750 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2751 | break; |
| 2752 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2753 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2755 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2756 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | (*dd_idx)++; |
| 2758 | break; |
| 2759 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2760 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2761 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | (*dd_idx)++; |
| 2763 | break; |
| 2764 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2765 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2766 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | break; |
| 2768 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2769 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2770 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2772 | case ALGORITHM_PARITY_0: |
| 2773 | pd_idx = 0; |
| 2774 | (*dd_idx)++; |
| 2775 | break; |
| 2776 | case ALGORITHM_PARITY_N: |
| 2777 | pd_idx = data_disks; |
| 2778 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2780 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2781 | } |
| 2782 | break; |
| 2783 | case 6: |
| 2784 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2785 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2786 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2787 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2788 | qd_idx = pd_idx + 1; |
| 2789 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2790 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2791 | qd_idx = 0; |
| 2792 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2793 | (*dd_idx) += 2; /* D D P Q D */ |
| 2794 | break; |
| 2795 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2796 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2797 | qd_idx = pd_idx + 1; |
| 2798 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2799 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2800 | qd_idx = 0; |
| 2801 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2802 | (*dd_idx) += 2; /* D D P Q D */ |
| 2803 | break; |
| 2804 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2805 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2806 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2807 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2808 | break; |
| 2809 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2810 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2811 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2812 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2813 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2814 | |
| 2815 | case ALGORITHM_PARITY_0: |
| 2816 | pd_idx = 0; |
| 2817 | qd_idx = 1; |
| 2818 | (*dd_idx) += 2; |
| 2819 | break; |
| 2820 | case ALGORITHM_PARITY_N: |
| 2821 | pd_idx = data_disks; |
| 2822 | qd_idx = data_disks + 1; |
| 2823 | break; |
| 2824 | |
| 2825 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2826 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 2827 | * of blocks for computing Q is different. |
| 2828 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2829 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2830 | qd_idx = pd_idx + 1; |
| 2831 | if (pd_idx == raid_disks-1) { |
| 2832 | (*dd_idx)++; /* Q D D D P */ |
| 2833 | qd_idx = 0; |
| 2834 | } else if (*dd_idx >= pd_idx) |
| 2835 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2836 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2837 | break; |
| 2838 | |
| 2839 | case ALGORITHM_ROTATING_N_RESTART: |
| 2840 | /* Same a left_asymmetric, by first stripe is |
| 2841 | * D D D P Q rather than |
| 2842 | * Q D D D P |
| 2843 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2844 | stripe2 += 1; |
| 2845 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2846 | qd_idx = pd_idx + 1; |
| 2847 | if (pd_idx == raid_disks-1) { |
| 2848 | (*dd_idx)++; /* Q D D D P */ |
| 2849 | qd_idx = 0; |
| 2850 | } else if (*dd_idx >= pd_idx) |
| 2851 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2852 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2853 | break; |
| 2854 | |
| 2855 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 2856 | /* Same as left_symmetric but Q is before P */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2857 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2858 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 2859 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2860 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2861 | break; |
| 2862 | |
| 2863 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2864 | /* RAID5 left_asymmetric, with Q on last device */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2865 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2866 | if (*dd_idx >= pd_idx) |
| 2867 | (*dd_idx)++; |
| 2868 | qd_idx = raid_disks - 1; |
| 2869 | break; |
| 2870 | |
| 2871 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2872 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2873 | if (*dd_idx >= pd_idx) |
| 2874 | (*dd_idx)++; |
| 2875 | qd_idx = raid_disks - 1; |
| 2876 | break; |
| 2877 | |
| 2878 | case ALGORITHM_LEFT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2879 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2880 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2881 | qd_idx = raid_disks - 1; |
| 2882 | break; |
| 2883 | |
| 2884 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2885 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2886 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2887 | qd_idx = raid_disks - 1; |
| 2888 | break; |
| 2889 | |
| 2890 | case ALGORITHM_PARITY_0_6: |
| 2891 | pd_idx = 0; |
| 2892 | (*dd_idx)++; |
| 2893 | qd_idx = raid_disks - 1; |
| 2894 | break; |
| 2895 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2896 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2897 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2898 | } |
| 2899 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2902 | if (sh) { |
| 2903 | sh->pd_idx = pd_idx; |
| 2904 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2905 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | /* |
| 2908 | * Finally, compute the new sector number |
| 2909 | */ |
| 2910 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 2911 | return new_sector; |
| 2912 | } |
| 2913 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2914 | sector_t raid5_compute_blocknr(struct stripe_head *sh, int i, int previous) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2916 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2917 | int raid_disks = sh->disks; |
| 2918 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2920 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2921 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2922 | int algorithm = previous ? conf->prev_algo |
| 2923 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | sector_t stripe; |
| 2925 | int chunk_offset; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2926 | sector_t chunk_number; |
| 2927 | int dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2929 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | |
| 2931 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 2932 | stripe = new_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2934 | if (i == sh->pd_idx) |
| 2935 | return 0; |
| 2936 | switch(conf->level) { |
| 2937 | case 4: break; |
| 2938 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2939 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2941 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 2942 | if (i > sh->pd_idx) |
| 2943 | i--; |
| 2944 | break; |
| 2945 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2946 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2947 | if (i < sh->pd_idx) |
| 2948 | i += raid_disks; |
| 2949 | i -= (sh->pd_idx + 1); |
| 2950 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2951 | case ALGORITHM_PARITY_0: |
| 2952 | i -= 1; |
| 2953 | break; |
| 2954 | case ALGORITHM_PARITY_N: |
| 2955 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2957 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2958 | } |
| 2959 | break; |
| 2960 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2961 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2962 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2963 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2964 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2965 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2966 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2967 | case ALGORITHM_ROTATING_N_RESTART: |
| 2968 | if (sh->pd_idx == raid_disks-1) |
| 2969 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2970 | else if (i > sh->pd_idx) |
| 2971 | i -= 2; /* D D P Q D */ |
| 2972 | break; |
| 2973 | case ALGORITHM_LEFT_SYMMETRIC: |
| 2974 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 2975 | if (sh->pd_idx == raid_disks-1) |
| 2976 | i--; /* Q D D D P */ |
| 2977 | else { |
| 2978 | /* D D P Q D */ |
| 2979 | if (i < sh->pd_idx) |
| 2980 | i += raid_disks; |
| 2981 | i -= (sh->pd_idx + 2); |
| 2982 | } |
| 2983 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2984 | case ALGORITHM_PARITY_0: |
| 2985 | i -= 2; |
| 2986 | break; |
| 2987 | case ALGORITHM_PARITY_N: |
| 2988 | break; |
| 2989 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2990 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2991 | if (sh->pd_idx == 0) |
| 2992 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 2993 | else { |
| 2994 | /* D D Q P D */ |
| 2995 | if (i < sh->pd_idx) |
| 2996 | i += raid_disks; |
| 2997 | i -= (sh->pd_idx + 1); |
| 2998 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2999 | break; |
| 3000 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 3001 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 3002 | if (i > sh->pd_idx) |
| 3003 | i--; |
| 3004 | break; |
| 3005 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 3006 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 3007 | if (i < sh->pd_idx) |
| 3008 | i += data_disks + 1; |
| 3009 | i -= (sh->pd_idx + 1); |
| 3010 | break; |
| 3011 | case ALGORITHM_PARITY_0_6: |
| 3012 | i -= 1; |
| 3013 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3014 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3015 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3016 | } |
| 3017 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | chunk_number = stripe * data_disks + i; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 3021 | r_sector = chunk_number * sectors_per_chunk + chunk_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3023 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3024 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3025 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 3026 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 3027 | pr_warn("md/raid:%s: compute_blocknr: map not correct\n", |
| 3028 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | return 0; |
| 3030 | } |
| 3031 | return r_sector; |
| 3032 | } |
| 3033 | |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3034 | /* |
| 3035 | * There are cases where we want handle_stripe_dirtying() and |
| 3036 | * schedule_reconstruction() to delay towrite to some dev of a stripe. |
| 3037 | * |
| 3038 | * This function checks whether we want to delay the towrite. Specifically, |
| 3039 | * we delay the towrite when: |
| 3040 | * |
| 3041 | * 1. degraded stripe has a non-overwrite to the missing dev, AND this |
| 3042 | * stripe has data in journal (for other devices). |
| 3043 | * |
| 3044 | * In this case, when reading data for the non-overwrite dev, it is |
| 3045 | * necessary to handle complex rmw of write back cache (prexor with |
| 3046 | * orig_page, and xor with page). To keep read path simple, we would |
| 3047 | * like to flush data in journal to RAID disks first, so complex rmw |
| 3048 | * is handled in the write patch (handle_stripe_dirtying). |
| 3049 | * |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3050 | * 2. when journal space is critical (R5C_LOG_CRITICAL=1) |
| 3051 | * |
| 3052 | * It is important to be able to flush all stripes in raid5-cache. |
| 3053 | * Therefore, we need reserve some space on the journal device for |
| 3054 | * these flushes. If flush operation includes pending writes to the |
| 3055 | * stripe, we need to reserve (conf->raid_disk + 1) pages per stripe |
| 3056 | * for the flush out. If we exclude these pending writes from flush |
| 3057 | * operation, we only need (conf->max_degraded + 1) pages per stripe. |
| 3058 | * Therefore, excluding pending writes in these cases enables more |
| 3059 | * efficient use of the journal device. |
| 3060 | * |
| 3061 | * Note: To make sure the stripe makes progress, we only delay |
| 3062 | * towrite for stripes with data already in journal (injournal > 0). |
| 3063 | * When LOG_CRITICAL, stripes with injournal == 0 will be sent to |
| 3064 | * no_space_stripes list. |
| 3065 | * |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3066 | */ |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3067 | static inline bool delay_towrite(struct r5conf *conf, |
| 3068 | struct r5dev *dev, |
| 3069 | struct stripe_head_state *s) |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3070 | { |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3071 | /* case 1 above */ |
| 3072 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 3073 | !test_bit(R5_Insync, &dev->flags) && s->injournal) |
| 3074 | return true; |
| 3075 | /* case 2 above */ |
| 3076 | if (test_bit(R5C_LOG_CRITICAL, &conf->cache_state) && |
| 3077 | s->injournal > 0) |
| 3078 | return true; |
| 3079 | return false; |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3080 | } |
| 3081 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3082 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3083 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3084 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3085 | { |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3086 | int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx, disks = sh->disks; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3087 | struct r5conf *conf = sh->raid_conf; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3088 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3089 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3090 | if (rcw) { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3091 | /* |
| 3092 | * In some cases, handle_stripe_dirtying initially decided to |
| 3093 | * run rmw and allocates extra page for prexor. However, rcw is |
| 3094 | * cheaper later on. We need to free the extra page now, |
| 3095 | * because we won't be able to do that in ops_complete_prexor(). |
| 3096 | */ |
| 3097 | r5c_release_extra_page(sh); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3098 | |
| 3099 | for (i = disks; i--; ) { |
| 3100 | struct r5dev *dev = &sh->dev[i]; |
| 3101 | |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3102 | if (dev->towrite && !delay_towrite(conf, dev, s)) { |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3103 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3104 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3105 | if (!expand) |
| 3106 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3107 | s->locked++; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3108 | } else if (test_bit(R5_InJournal, &dev->flags)) { |
| 3109 | set_bit(R5_LOCKED, &dev->flags); |
| 3110 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3111 | } |
| 3112 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 3113 | /* if we are not expanding this is a proper write request, and |
| 3114 | * there will be bios with new data to be drained into the |
| 3115 | * stripe cache |
| 3116 | */ |
| 3117 | if (!expand) { |
| 3118 | if (!s->locked) |
| 3119 | /* False alarm, nothing to do */ |
| 3120 | return; |
| 3121 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 3122 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 3123 | } else |
| 3124 | sh->reconstruct_state = reconstruct_state_run; |
| 3125 | |
| 3126 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
| 3127 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3128 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3129 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3130 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3131 | } else { |
| 3132 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 3133 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3134 | BUG_ON(level == 6 && |
| 3135 | (!(test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags) || |
| 3136 | test_bit(R5_Wantcompute, &sh->dev[qd_idx].flags)))); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3137 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3138 | for (i = disks; i--; ) { |
| 3139 | struct r5dev *dev = &sh->dev[i]; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3140 | if (i == pd_idx || i == qd_idx) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3141 | continue; |
| 3142 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3143 | if (dev->towrite && |
| 3144 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3145 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 3146 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3147 | set_bit(R5_LOCKED, &dev->flags); |
| 3148 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3149 | s->locked++; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3150 | } else if (test_bit(R5_InJournal, &dev->flags)) { |
| 3151 | set_bit(R5_LOCKED, &dev->flags); |
| 3152 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3153 | } |
| 3154 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 3155 | if (!s->locked) |
| 3156 | /* False alarm - nothing to do */ |
| 3157 | return; |
| 3158 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
| 3159 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 3160 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 3161 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3164 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3165 | * are in flight |
| 3166 | */ |
| 3167 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 3168 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3169 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3170 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3171 | if (level == 6) { |
| 3172 | int qd_idx = sh->qd_idx; |
| 3173 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 3174 | |
| 3175 | set_bit(R5_LOCKED, &dev->flags); |
| 3176 | clear_bit(R5_UPTODATE, &dev->flags); |
| 3177 | s->locked++; |
| 3178 | } |
| 3179 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3180 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 3181 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3182 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3183 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | /* |
| 3186 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3187 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | * The bi_next chain must be in order. |
| 3189 | */ |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3190 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, |
| 3191 | int forwrite, int previous) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | { |
| 3193 | struct bio **bip; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3194 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3195 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3197 | pr_debug("adding bi b#%llu to stripe s#%llu\n", |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3198 | (unsigned long long)bi->bi_iter.bi_sector, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | (unsigned long long)sh->sector); |
| 3200 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3201 | /* |
| 3202 | * If several bio share a stripe. The bio bi_phys_segments acts as a |
| 3203 | * reference count to avoid race. The reference count should already be |
| 3204 | * increased before this function is called (for example, in |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 3205 | * raid5_make_request()), so other bio sharing this stripe will not free the |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3206 | * stripe. If a stripe is owned by one stripe, the stripe lock will |
| 3207 | * protect it. |
| 3208 | */ |
| 3209 | spin_lock_irq(&sh->stripe_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3210 | /* Don't allow new IO added to stripes in batch list */ |
| 3211 | if (sh->batch_head) |
| 3212 | goto overlap; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3213 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | bip = &sh->dev[dd_idx].towrite; |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3215 | if (*bip == NULL) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3216 | firstwrite = 1; |
| 3217 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | bip = &sh->dev[dd_idx].toread; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3219 | while (*bip && (*bip)->bi_iter.bi_sector < bi->bi_iter.bi_sector) { |
| 3220 | if (bio_end_sector(*bip) > bi->bi_iter.bi_sector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | goto overlap; |
| 3222 | bip = & (*bip)->bi_next; |
| 3223 | } |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3224 | if (*bip && (*bip)->bi_iter.bi_sector < bio_end_sector(bi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | goto overlap; |
| 3226 | |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3227 | if (!forwrite || previous) |
| 3228 | clear_bit(STRIPE_BATCH_READY, &sh->state); |
| 3229 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 3230 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | if (*bip) |
| 3232 | bi->bi_next = *bip; |
| 3233 | *bip = bi; |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3234 | raid5_inc_bi_active_stripes(bi); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | if (forwrite) { |
| 3237 | /* check if page is covered */ |
| 3238 | sector_t sector = sh->dev[dd_idx].sector; |
| 3239 | for (bi=sh->dev[dd_idx].towrite; |
| 3240 | sector < sh->dev[dd_idx].sector + STRIPE_SECTORS && |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3241 | bi && bi->bi_iter.bi_sector <= sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | bi = r5_next_bio(bi, sh->dev[dd_idx].sector)) { |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 3243 | if (bio_end_sector(bi) >= sector) |
| 3244 | sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | } |
| 3246 | if (sector >= sh->dev[dd_idx].sector + STRIPE_SECTORS) |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3247 | if (!test_and_set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags)) |
| 3248 | sh->overwrite_disks++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3250 | |
| 3251 | pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n", |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3252 | (unsigned long long)(*bip)->bi_iter.bi_sector, |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3253 | (unsigned long long)sh->sector, dd_idx); |
| 3254 | |
| 3255 | if (conf->mddev->bitmap && firstwrite) { |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 3256 | /* Cannot hold spinlock over bitmap_startwrite, |
| 3257 | * but must ensure this isn't added to a batch until |
| 3258 | * we have added to the bitmap and set bm_seq. |
| 3259 | * So set STRIPE_BITMAP_PENDING to prevent |
| 3260 | * batching. |
| 3261 | * If multiple add_stripe_bio() calls race here they |
| 3262 | * much all set STRIPE_BITMAP_PENDING. So only the first one |
| 3263 | * to complete "bitmap_startwrite" gets to set |
| 3264 | * STRIPE_BIT_DELAY. This is important as once a stripe |
| 3265 | * is added to a batch, STRIPE_BIT_DELAY cannot be changed |
| 3266 | * any more. |
| 3267 | */ |
| 3268 | set_bit(STRIPE_BITMAP_PENDING, &sh->state); |
| 3269 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3270 | bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
| 3271 | STRIPE_SECTORS, 0); |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 3272 | spin_lock_irq(&sh->stripe_lock); |
| 3273 | clear_bit(STRIPE_BITMAP_PENDING, &sh->state); |
| 3274 | if (!sh->batch_head) { |
| 3275 | sh->bm_seq = conf->seq_flush+1; |
| 3276 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 3277 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3278 | } |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 3279 | spin_unlock_irq(&sh->stripe_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3280 | |
| 3281 | if (stripe_can_batch(sh)) |
| 3282 | stripe_add_to_batch_list(conf, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | return 1; |
| 3284 | |
| 3285 | overlap: |
| 3286 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3287 | spin_unlock_irq(&sh->stripe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | return 0; |
| 3289 | } |
| 3290 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3291 | static void end_reshape(struct r5conf *conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 3292 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3293 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3294 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3295 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3296 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 3297 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3298 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 3299 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3300 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 3301 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3302 | raid5_compute_sector(conf, |
| 3303 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 3304 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3305 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3306 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3307 | } |
| 3308 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3309 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3310 | handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3311 | struct stripe_head_state *s, int disks, |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 3312 | struct bio_list *return_bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3313 | { |
| 3314 | int i; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3315 | BUG_ON(sh->batch_head); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3316 | for (i = disks; i--; ) { |
| 3317 | struct bio *bi; |
| 3318 | int bitmap_end = 0; |
| 3319 | |
| 3320 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3321 | struct md_rdev *rdev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3322 | rcu_read_lock(); |
| 3323 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | f5b67ae | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 3324 | if (rdev && test_bit(In_sync, &rdev->flags) && |
| 3325 | !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3326 | atomic_inc(&rdev->nr_pending); |
| 3327 | else |
| 3328 | rdev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3329 | rcu_read_unlock(); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3330 | if (rdev) { |
| 3331 | if (!rdev_set_badblocks( |
| 3332 | rdev, |
| 3333 | sh->sector, |
| 3334 | STRIPE_SECTORS, 0)) |
| 3335 | md_error(conf->mddev, rdev); |
| 3336 | rdev_dec_pending(rdev, conf->mddev); |
| 3337 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3338 | } |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3339 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3340 | /* fail all writes first */ |
| 3341 | bi = sh->dev[i].towrite; |
| 3342 | sh->dev[i].towrite = NULL; |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3343 | sh->overwrite_disks = 0; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3344 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | 1ed850f | 2012-10-11 13:50:13 +1100 | [diff] [blame] | 3345 | if (bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3346 | bitmap_end = 1; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3347 | |
Shaohua Li | 0576b1c | 2015-08-13 14:32:00 -0700 | [diff] [blame] | 3348 | r5l_stripe_write_finished(sh); |
| 3349 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3350 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 3351 | wake_up(&conf->wait_for_overlap); |
| 3352 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3353 | while (bi && bi->bi_iter.bi_sector < |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3354 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 3355 | struct bio *nextbi = r5_next_bio(bi, sh->dev[i].sector); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 3356 | |
| 3357 | bi->bi_error = -EIO; |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3358 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3359 | md_write_end(conf->mddev); |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 3360 | bio_list_add(return_bi, bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3361 | } |
| 3362 | bi = nextbi; |
| 3363 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3364 | if (bitmap_end) |
| 3365 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 3366 | STRIPE_SECTORS, 0, 0); |
| 3367 | bitmap_end = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3368 | /* and fail all 'written' */ |
| 3369 | bi = sh->dev[i].written; |
| 3370 | sh->dev[i].written = NULL; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3371 | if (test_and_clear_bit(R5_SkipCopy, &sh->dev[i].flags)) { |
| 3372 | WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
| 3373 | sh->dev[i].page = sh->dev[i].orig_page; |
| 3374 | } |
| 3375 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3376 | if (bi) bitmap_end = 1; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3377 | while (bi && bi->bi_iter.bi_sector < |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3378 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 3379 | struct bio *bi2 = r5_next_bio(bi, sh->dev[i].sector); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 3380 | |
| 3381 | bi->bi_error = -EIO; |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3382 | if (!raid5_dec_bi_active_stripes(bi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3383 | md_write_end(conf->mddev); |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 3384 | bio_list_add(return_bi, bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3385 | } |
| 3386 | bi = bi2; |
| 3387 | } |
| 3388 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3389 | /* fail any reads if this device is non-operational and |
| 3390 | * the data has not reached the cache yet. |
| 3391 | */ |
| 3392 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
Shaohua Li | 6e74a9c | 2015-10-08 21:54:08 -0700 | [diff] [blame] | 3393 | s->failed > conf->max_degraded && |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3394 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 3395 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3396 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3397 | bi = sh->dev[i].toread; |
| 3398 | sh->dev[i].toread = NULL; |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3399 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3400 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 3401 | wake_up(&conf->wait_for_overlap); |
Shaohua Li | ebda780 | 2015-09-18 10:20:13 -0700 | [diff] [blame] | 3402 | if (bi) |
| 3403 | s->to_read--; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3404 | while (bi && bi->bi_iter.bi_sector < |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3405 | sh->dev[i].sector + STRIPE_SECTORS) { |
| 3406 | struct bio *nextbi = |
| 3407 | r5_next_bio(bi, sh->dev[i].sector); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 3408 | |
| 3409 | bi->bi_error = -EIO; |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 3410 | if (!raid5_dec_bi_active_stripes(bi)) |
| 3411 | bio_list_add(return_bi, bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3412 | bi = nextbi; |
| 3413 | } |
| 3414 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3415 | if (bitmap_end) |
| 3416 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 3417 | STRIPE_SECTORS, 0, 0); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3418 | /* If we were in the middle of a write the parity block might |
| 3419 | * still be locked - so just clear all R5_LOCKED flags |
| 3420 | */ |
| 3421 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3422 | } |
Shaohua Li | ebda780 | 2015-09-18 10:20:13 -0700 | [diff] [blame] | 3423 | s->to_write = 0; |
| 3424 | s->written = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3425 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3426 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 3427 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 3428 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3431 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3432 | handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3433 | struct stripe_head_state *s) |
| 3434 | { |
| 3435 | int abort = 0; |
| 3436 | int i; |
| 3437 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3438 | BUG_ON(sh->batch_head); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3439 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3440 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 3441 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3442 | s->syncing = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3443 | s->replacing = 0; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3444 | /* There is nothing more to do for sync/check/repair. |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3445 | * Don't even need to abort as that is handled elsewhere |
| 3446 | * if needed, and not always wanted e.g. if there is a known |
| 3447 | * bad block here. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3448 | * For recover/replace we need to record a bad block on all |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3449 | * non-sync devices, or abort the recovery |
| 3450 | */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3451 | if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { |
| 3452 | /* During recovery devices cannot be removed, so |
| 3453 | * locking and refcounting of rdevs is not needed |
| 3454 | */ |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3455 | rcu_read_lock(); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3456 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3457 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3458 | if (rdev |
| 3459 | && !test_bit(Faulty, &rdev->flags) |
| 3460 | && !test_bit(In_sync, &rdev->flags) |
| 3461 | && !rdev_set_badblocks(rdev, sh->sector, |
| 3462 | STRIPE_SECTORS, 0)) |
| 3463 | abort = 1; |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3464 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3465 | if (rdev |
| 3466 | && !test_bit(Faulty, &rdev->flags) |
| 3467 | && !test_bit(In_sync, &rdev->flags) |
| 3468 | && !rdev_set_badblocks(rdev, sh->sector, |
| 3469 | STRIPE_SECTORS, 0)) |
| 3470 | abort = 1; |
| 3471 | } |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3472 | rcu_read_unlock(); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3473 | if (abort) |
| 3474 | conf->recovery_disabled = |
| 3475 | conf->mddev->recovery_disabled; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3476 | } |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3477 | md_done_sync(conf->mddev, STRIPE_SECTORS, !abort); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3478 | } |
| 3479 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3480 | static int want_replace(struct stripe_head *sh, int disk_idx) |
| 3481 | { |
| 3482 | struct md_rdev *rdev; |
| 3483 | int rv = 0; |
NeilBrown | 3f232d6 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3484 | |
| 3485 | rcu_read_lock(); |
| 3486 | rdev = rcu_dereference(sh->raid_conf->disks[disk_idx].replacement); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3487 | if (rdev |
| 3488 | && !test_bit(Faulty, &rdev->flags) |
| 3489 | && !test_bit(In_sync, &rdev->flags) |
| 3490 | && (rdev->recovery_offset <= sh->sector |
| 3491 | || rdev->mddev->recovery_cp <= sh->sector)) |
| 3492 | rv = 1; |
NeilBrown | 3f232d6 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3493 | rcu_read_unlock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3494 | return rv; |
| 3495 | } |
| 3496 | |
NeilBrown | 2c58f06 | 2015-02-02 11:32:23 +1100 | [diff] [blame] | 3497 | static int need_this_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 3498 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3499 | { |
| 3500 | struct r5dev *dev = &sh->dev[disk_idx]; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3501 | struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], |
| 3502 | &sh->dev[s->failed_num[1]] }; |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3503 | int i; |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3504 | |
NeilBrown | a79cfe1 | 2015-02-02 11:37:59 +1100 | [diff] [blame] | 3505 | |
| 3506 | if (test_bit(R5_LOCKED, &dev->flags) || |
| 3507 | test_bit(R5_UPTODATE, &dev->flags)) |
| 3508 | /* No point reading this as we already have it or have |
| 3509 | * decided to get it. |
| 3510 | */ |
| 3511 | return 0; |
| 3512 | |
| 3513 | if (dev->toread || |
| 3514 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags))) |
| 3515 | /* We need this block to directly satisfy a request */ |
| 3516 | return 1; |
| 3517 | |
| 3518 | if (s->syncing || s->expanding || |
| 3519 | (s->replacing && want_replace(sh, disk_idx))) |
| 3520 | /* When syncing, or expanding we read everything. |
| 3521 | * When replacing, we need the replaced block. |
| 3522 | */ |
| 3523 | return 1; |
| 3524 | |
| 3525 | if ((s->failed >= 1 && fdev[0]->toread) || |
| 3526 | (s->failed >= 2 && fdev[1]->toread)) |
| 3527 | /* If we want to read from a failed device, then |
| 3528 | * we need to actually read every other device. |
| 3529 | */ |
| 3530 | return 1; |
| 3531 | |
NeilBrown | a9d5695 | 2015-02-02 11:49:10 +1100 | [diff] [blame] | 3532 | /* Sometimes neither read-modify-write nor reconstruct-write |
| 3533 | * cycles can work. In those cases we read every block we |
| 3534 | * can. Then the parity-update is certain to have enough to |
| 3535 | * work with. |
| 3536 | * This can only be a problem when we need to write something, |
| 3537 | * and some device has failed. If either of those tests |
| 3538 | * fail we need look no further. |
| 3539 | */ |
| 3540 | if (!s->failed || !s->to_write) |
| 3541 | return 0; |
| 3542 | |
| 3543 | if (test_bit(R5_Insync, &dev->flags) && |
| 3544 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3545 | /* Pre-reads at not permitted until after short delay |
| 3546 | * to gather multiple requests. However if this |
| 3547 | * device is no Insync, the block could only be be computed |
| 3548 | * and there is no need to delay that. |
| 3549 | */ |
| 3550 | return 0; |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3551 | |
NeilBrown | 36707bb | 2015-09-24 15:25:36 +1000 | [diff] [blame] | 3552 | for (i = 0; i < s->failed && i < 2; i++) { |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3553 | if (fdev[i]->towrite && |
| 3554 | !test_bit(R5_UPTODATE, &fdev[i]->flags) && |
| 3555 | !test_bit(R5_OVERWRITE, &fdev[i]->flags)) |
| 3556 | /* If we have a partial write to a failed |
| 3557 | * device, then we will need to reconstruct |
| 3558 | * the content of that device, so all other |
| 3559 | * devices must be read. |
| 3560 | */ |
| 3561 | return 1; |
| 3562 | } |
| 3563 | |
| 3564 | /* If we are forced to do a reconstruct-write, either because |
| 3565 | * the current RAID6 implementation only supports that, or |
| 3566 | * or because parity cannot be trusted and we are currently |
| 3567 | * recovering it, there is extra need to be careful. |
| 3568 | * If one of the devices that we would need to read, because |
| 3569 | * it is not being overwritten (and maybe not written at all) |
| 3570 | * is missing/faulty, then we need to read everything we can. |
| 3571 | */ |
| 3572 | if (sh->raid_conf->level != 6 && |
| 3573 | sh->sector < sh->raid_conf->mddev->recovery_cp) |
| 3574 | /* reconstruct-write isn't being forced */ |
| 3575 | return 0; |
NeilBrown | 36707bb | 2015-09-24 15:25:36 +1000 | [diff] [blame] | 3576 | for (i = 0; i < s->failed && i < 2; i++) { |
NeilBrown | 10d82c5 | 2015-05-08 18:19:33 +1000 | [diff] [blame] | 3577 | if (s->failed_num[i] != sh->pd_idx && |
| 3578 | s->failed_num[i] != sh->qd_idx && |
| 3579 | !test_bit(R5_UPTODATE, &fdev[i]->flags) && |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3580 | !test_bit(R5_OVERWRITE, &fdev[i]->flags)) |
| 3581 | return 1; |
| 3582 | } |
| 3583 | |
NeilBrown | 2c58f06 | 2015-02-02 11:32:23 +1100 | [diff] [blame] | 3584 | return 0; |
| 3585 | } |
| 3586 | |
Song Liu | ba02684 | 2017-01-12 17:22:42 -0800 | [diff] [blame] | 3587 | /* fetch_block - checks the given member device to see if its data needs |
| 3588 | * to be read or computed to satisfy a request. |
| 3589 | * |
| 3590 | * Returns 1 when no more member devices need to be checked, otherwise returns |
| 3591 | * 0 to tell the loop in handle_stripe_fill to continue |
| 3592 | */ |
NeilBrown | 2c58f06 | 2015-02-02 11:32:23 +1100 | [diff] [blame] | 3593 | static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 3594 | int disk_idx, int disks) |
| 3595 | { |
| 3596 | struct r5dev *dev = &sh->dev[disk_idx]; |
| 3597 | |
| 3598 | /* is the data in this block needed, and can we get it? */ |
| 3599 | if (need_this_block(sh, s, disk_idx, disks)) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3600 | /* we would like to get this block, possibly by computing it, |
| 3601 | * otherwise read it if the backing disk is insync |
| 3602 | */ |
| 3603 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 3604 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
NeilBrown | b0c783b | 2015-05-08 18:19:32 +1000 | [diff] [blame] | 3605 | BUG_ON(sh->batch_head); |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3606 | if ((s->uptodate == disks - 1) && |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3607 | (s->failed && (disk_idx == s->failed_num[0] || |
| 3608 | disk_idx == s->failed_num[1]))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3609 | /* have disk failed, and we're requested to fetch it; |
| 3610 | * do compute it |
| 3611 | */ |
| 3612 | pr_debug("Computing stripe %llu block %d\n", |
| 3613 | (unsigned long long)sh->sector, disk_idx); |
| 3614 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3615 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3616 | set_bit(R5_Wantcompute, &dev->flags); |
| 3617 | sh->ops.target = disk_idx; |
| 3618 | sh->ops.target2 = -1; /* no 2nd target */ |
| 3619 | s->req_compute = 1; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3620 | /* Careful: from this point on 'uptodate' is in the eye |
| 3621 | * of raid_run_ops which services 'compute' operations |
| 3622 | * before writes. R5_Wantcompute flags a block that will |
| 3623 | * be R5_UPTODATE by the time it is needed for a |
| 3624 | * subsequent operation. |
| 3625 | */ |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3626 | s->uptodate++; |
| 3627 | return 1; |
| 3628 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 3629 | /* Computing 2-failure is *very* expensive; only |
| 3630 | * do it if failed >= 2 |
| 3631 | */ |
| 3632 | int other; |
| 3633 | for (other = disks; other--; ) { |
| 3634 | if (other == disk_idx) |
| 3635 | continue; |
| 3636 | if (!test_bit(R5_UPTODATE, |
| 3637 | &sh->dev[other].flags)) |
| 3638 | break; |
| 3639 | } |
| 3640 | BUG_ON(other < 0); |
| 3641 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 3642 | (unsigned long long)sh->sector, |
| 3643 | disk_idx, other); |
| 3644 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3645 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3646 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 3647 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 3648 | sh->ops.target = disk_idx; |
| 3649 | sh->ops.target2 = other; |
| 3650 | s->uptodate += 2; |
| 3651 | s->req_compute = 1; |
| 3652 | return 1; |
| 3653 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 3654 | set_bit(R5_LOCKED, &dev->flags); |
| 3655 | set_bit(R5_Wantread, &dev->flags); |
| 3656 | s->locked++; |
| 3657 | pr_debug("Reading block %d (sync=%d)\n", |
| 3658 | disk_idx, s->syncing); |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | return 0; |
| 3663 | } |
| 3664 | |
| 3665 | /** |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3666 | * handle_stripe_fill - read or compute data to satisfy pending requests. |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3667 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3668 | static void handle_stripe_fill(struct stripe_head *sh, |
| 3669 | struct stripe_head_state *s, |
| 3670 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3671 | { |
| 3672 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3673 | |
| 3674 | /* look for blocks to read/compute, skip this if a compute |
| 3675 | * is already in flight, or if the stripe contents are in the |
| 3676 | * midst of changing due to a write |
| 3677 | */ |
| 3678 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3679 | !sh->reconstruct_state) { |
| 3680 | |
| 3681 | /* |
| 3682 | * For degraded stripe with data in journal, do not handle |
| 3683 | * read requests yet, instead, flush the stripe to raid |
| 3684 | * disks first, this avoids handling complex rmw of write |
| 3685 | * back cache (prexor with orig_page, and then xor with |
| 3686 | * page) in the read path |
| 3687 | */ |
| 3688 | if (s->injournal && s->failed) { |
| 3689 | if (test_bit(STRIPE_R5C_CACHING, &sh->state)) |
| 3690 | r5c_make_stripe_write_out(sh); |
| 3691 | goto out; |
| 3692 | } |
| 3693 | |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3694 | for (i = disks; i--; ) |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3695 | if (fetch_block(sh, s, i, disks)) |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3696 | break; |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3697 | } |
| 3698 | out: |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3699 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3700 | } |
| 3701 | |
NeilBrown | 787b76f | 2015-05-21 12:56:41 +1000 | [diff] [blame] | 3702 | static void break_stripe_batch_list(struct stripe_head *head_sh, |
| 3703 | unsigned long handle_flags); |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3704 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3705 | * any written block on an uptodate or failed drive can be returned. |
| 3706 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 3707 | * never LOCKED, so we don't need to test 'failed' directly. |
| 3708 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3709 | static void handle_stripe_clean_event(struct r5conf *conf, |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 3710 | struct stripe_head *sh, int disks, struct bio_list *return_bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3711 | { |
| 3712 | int i; |
| 3713 | struct r5dev *dev; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3714 | int discard_pending = 0; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3715 | struct stripe_head *head_sh = sh; |
| 3716 | bool do_endio = false; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3717 | |
| 3718 | for (i = disks; i--; ) |
| 3719 | if (sh->dev[i].written) { |
| 3720 | dev = &sh->dev[i]; |
| 3721 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 3722 | (test_bit(R5_UPTODATE, &dev->flags) || |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3723 | test_bit(R5_Discard, &dev->flags) || |
| 3724 | test_bit(R5_SkipCopy, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3725 | /* We can return any write requests */ |
| 3726 | struct bio *wbi, *wbi2; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3727 | pr_debug("Return write for disc %d\n", i); |
NeilBrown | ca64cae | 2012-11-21 16:33:40 +1100 | [diff] [blame] | 3728 | if (test_and_clear_bit(R5_Discard, &dev->flags)) |
| 3729 | clear_bit(R5_UPTODATE, &dev->flags); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3730 | if (test_and_clear_bit(R5_SkipCopy, &dev->flags)) { |
| 3731 | WARN_ON(test_bit(R5_UPTODATE, &dev->flags)); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3732 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3733 | do_endio = true; |
| 3734 | |
| 3735 | returnbi: |
| 3736 | dev->page = dev->orig_page; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3737 | wbi = dev->written; |
| 3738 | dev->written = NULL; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3739 | while (wbi && wbi->bi_iter.bi_sector < |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3740 | dev->sector + STRIPE_SECTORS) { |
| 3741 | wbi2 = r5_next_bio(wbi, dev->sector); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3742 | if (!raid5_dec_bi_active_stripes(wbi)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3743 | md_write_end(conf->mddev); |
NeilBrown | 34a6f80 | 2015-08-14 12:07:57 +1000 | [diff] [blame] | 3744 | bio_list_add(return_bi, wbi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3745 | } |
| 3746 | wbi = wbi2; |
| 3747 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3748 | bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
| 3749 | STRIPE_SECTORS, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3750 | !test_bit(STRIPE_DEGRADED, &sh->state), |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3751 | 0); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3752 | if (head_sh->batch_head) { |
| 3753 | sh = list_first_entry(&sh->batch_list, |
| 3754 | struct stripe_head, |
| 3755 | batch_list); |
| 3756 | if (sh != head_sh) { |
| 3757 | dev = &sh->dev[i]; |
| 3758 | goto returnbi; |
| 3759 | } |
| 3760 | } |
| 3761 | sh = head_sh; |
| 3762 | dev = &sh->dev[i]; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3763 | } else if (test_bit(R5_Discard, &dev->flags)) |
| 3764 | discard_pending = 1; |
| 3765 | } |
Shaohua Li | f6bed0e | 2015-08-13 14:31:59 -0700 | [diff] [blame] | 3766 | |
Shaohua Li | 0576b1c | 2015-08-13 14:32:00 -0700 | [diff] [blame] | 3767 | r5l_stripe_write_finished(sh); |
| 3768 | |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3769 | if (!discard_pending && |
| 3770 | test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { |
Roman Gushchin | b8a9d66 | 2015-10-31 10:53:50 +1100 | [diff] [blame] | 3771 | int hash; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3772 | clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 3773 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
| 3774 | if (sh->qd_idx >= 0) { |
| 3775 | clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 3776 | clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); |
| 3777 | } |
| 3778 | /* now that discard is done we can proceed with any sync */ |
| 3779 | clear_bit(STRIPE_DISCARD, &sh->state); |
Shaohua Li | d47648f | 2013-10-19 14:51:42 +0800 | [diff] [blame] | 3780 | /* |
| 3781 | * SCSI discard will change some bio fields and the stripe has |
| 3782 | * no updated data, so remove it from hash list and the stripe |
| 3783 | * will be reinitialized |
| 3784 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3785 | unhash: |
Roman Gushchin | b8a9d66 | 2015-10-31 10:53:50 +1100 | [diff] [blame] | 3786 | hash = sh->hash_lock_index; |
| 3787 | spin_lock_irq(conf->hash_locks + hash); |
Shaohua Li | d47648f | 2013-10-19 14:51:42 +0800 | [diff] [blame] | 3788 | remove_hash(sh); |
Roman Gushchin | b8a9d66 | 2015-10-31 10:53:50 +1100 | [diff] [blame] | 3789 | spin_unlock_irq(conf->hash_locks + hash); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3790 | if (head_sh->batch_head) { |
| 3791 | sh = list_first_entry(&sh->batch_list, |
| 3792 | struct stripe_head, batch_list); |
| 3793 | if (sh != head_sh) |
| 3794 | goto unhash; |
| 3795 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3796 | sh = head_sh; |
| 3797 | |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3798 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) |
| 3799 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3800 | |
| 3801 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3802 | |
| 3803 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 3804 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 3805 | md_wakeup_thread(conf->mddev->thread); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3806 | |
NeilBrown | 787b76f | 2015-05-21 12:56:41 +1000 | [diff] [blame] | 3807 | if (head_sh->batch_head && do_endio) |
| 3808 | break_stripe_batch_list(head_sh, STRIPE_EXPAND_SYNC_FLAGS); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 3811 | /* |
| 3812 | * For RMW in write back cache, we need extra page in prexor to store the |
| 3813 | * old data. This page is stored in dev->orig_page. |
| 3814 | * |
| 3815 | * This function checks whether we have data for prexor. The exact logic |
| 3816 | * is: |
| 3817 | * R5_UPTODATE && (!R5_InJournal || R5_OrigPageUPTDODATE) |
| 3818 | */ |
| 3819 | static inline bool uptodate_for_rmw(struct r5dev *dev) |
| 3820 | { |
| 3821 | return (test_bit(R5_UPTODATE, &dev->flags)) && |
| 3822 | (!test_bit(R5_InJournal, &dev->flags) || |
| 3823 | test_bit(R5_OrigPageUPTDODATE, &dev->flags)); |
| 3824 | } |
| 3825 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3826 | static int handle_stripe_dirtying(struct r5conf *conf, |
| 3827 | struct stripe_head *sh, |
| 3828 | struct stripe_head_state *s, |
| 3829 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3830 | { |
| 3831 | int rmw = 0, rcw = 0, i; |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3832 | sector_t recovery_cp = conf->mddev->recovery_cp; |
| 3833 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3834 | /* Check whether resync is now happening or should start. |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3835 | * If yes, then the array is dirty (after unclean shutdown or |
| 3836 | * initial creation), so parity in some stripes might be inconsistent. |
| 3837 | * In this case, we need to always do reconstruct-write, to ensure |
| 3838 | * that in case of drive failure or read-error correction, we |
| 3839 | * generate correct data from the parity. |
| 3840 | */ |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3841 | if (conf->rmw_level == PARITY_DISABLE_RMW || |
NeilBrown | 26ac107 | 2015-02-18 11:35:14 +1100 | [diff] [blame] | 3842 | (recovery_cp < MaxSector && sh->sector >= recovery_cp && |
| 3843 | s->failed == 0)) { |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3844 | /* Calculate the real rcw later - for now make it |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3845 | * look like rcw is cheaper |
| 3846 | */ |
| 3847 | rcw = 1; rmw = 2; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3848 | pr_debug("force RCW rmw_level=%u, recovery_cp=%llu sh->sector=%llu\n", |
| 3849 | conf->rmw_level, (unsigned long long)recovery_cp, |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3850 | (unsigned long long)sh->sector); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3851 | } else for (i = disks; i--; ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3852 | /* would I have to read this buffer for read_modify_write */ |
| 3853 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3854 | if (((dev->towrite && !delay_towrite(conf, dev, s)) || |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3855 | i == sh->pd_idx || i == sh->qd_idx || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3856 | test_bit(R5_InJournal, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3857 | !test_bit(R5_LOCKED, &dev->flags) && |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 3858 | !(uptodate_for_rmw(dev) || |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3859 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3860 | if (test_bit(R5_Insync, &dev->flags)) |
| 3861 | rmw++; |
| 3862 | else |
| 3863 | rmw += 2*disks; /* cannot read it */ |
| 3864 | } |
| 3865 | /* Would I have to read this buffer for reconstruct_write */ |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3866 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 3867 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3868 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3869 | !(test_bit(R5_UPTODATE, &dev->flags) || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3870 | test_bit(R5_Wantcompute, &dev->flags))) { |
NeilBrown | 67f4554 | 2014-05-28 13:39:22 +1000 | [diff] [blame] | 3871 | if (test_bit(R5_Insync, &dev->flags)) |
| 3872 | rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3873 | else |
| 3874 | rcw += 2*disks; |
| 3875 | } |
| 3876 | } |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3877 | |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3878 | pr_debug("for sector %llu state 0x%lx, rmw=%d rcw=%d\n", |
| 3879 | (unsigned long long)sh->sector, sh->state, rmw, rcw); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3880 | set_bit(STRIPE_HANDLE, &sh->state); |
Song Liu | 4125758 | 2016-05-23 17:25:06 -0700 | [diff] [blame] | 3881 | if ((rmw < rcw || (rmw == rcw && conf->rmw_level == PARITY_PREFER_RMW)) && rmw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3882 | /* prefer read-modify-write, but need to get some data */ |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 3883 | if (conf->mddev->queue) |
| 3884 | blk_add_trace_msg(conf->mddev->queue, |
| 3885 | "raid5 rmw %llu %d", |
| 3886 | (unsigned long long)sh->sector, rmw); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3887 | for (i = disks; i--; ) { |
| 3888 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3889 | if (test_bit(R5_InJournal, &dev->flags) && |
| 3890 | dev->page == dev->orig_page && |
| 3891 | !test_bit(R5_LOCKED, &sh->dev[sh->pd_idx].flags)) { |
| 3892 | /* alloc page for prexor */ |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3893 | struct page *p = alloc_page(GFP_NOIO); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3894 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3895 | if (p) { |
| 3896 | dev->orig_page = p; |
| 3897 | continue; |
| 3898 | } |
| 3899 | |
| 3900 | /* |
| 3901 | * alloc_page() failed, try use |
| 3902 | * disk_info->extra_page |
| 3903 | */ |
| 3904 | if (!test_and_set_bit(R5C_EXTRA_PAGE_IN_USE, |
| 3905 | &conf->cache_state)) { |
| 3906 | r5c_use_extra_page(sh); |
| 3907 | break; |
| 3908 | } |
| 3909 | |
| 3910 | /* extra_page in use, add to delayed_list */ |
| 3911 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3912 | s->waiting_extra_page = 1; |
| 3913 | return -EAGAIN; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3914 | } |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3915 | } |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3916 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3917 | for (i = disks; i--; ) { |
| 3918 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3919 | if (((dev->towrite && !delay_towrite(conf, dev, s)) || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3920 | i == sh->pd_idx || i == sh->qd_idx || |
| 3921 | test_bit(R5_InJournal, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3922 | !test_bit(R5_LOCKED, &dev->flags) && |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 3923 | !(uptodate_for_rmw(dev) || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3924 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3925 | test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 67f4554 | 2014-05-28 13:39:22 +1000 | [diff] [blame] | 3926 | if (test_bit(STRIPE_PREREAD_ACTIVE, |
| 3927 | &sh->state)) { |
| 3928 | pr_debug("Read_old block %d for r-m-w\n", |
| 3929 | i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3930 | set_bit(R5_LOCKED, &dev->flags); |
| 3931 | set_bit(R5_Wantread, &dev->flags); |
| 3932 | s->locked++; |
| 3933 | } else { |
| 3934 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3935 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3936 | } |
| 3937 | } |
| 3938 | } |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3939 | } |
Song Liu | 4125758 | 2016-05-23 17:25:06 -0700 | [diff] [blame] | 3940 | if ((rcw < rmw || (rcw == rmw && conf->rmw_level != PARITY_PREFER_RMW)) && rcw > 0) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3941 | /* want reconstruct write, but need to get some data */ |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3942 | int qread =0; |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3943 | rcw = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3944 | for (i = disks; i--; ) { |
| 3945 | struct r5dev *dev = &sh->dev[i]; |
| 3946 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3947 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3948 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3949 | !(test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3950 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 3951 | rcw++; |
NeilBrown | 67f4554 | 2014-05-28 13:39:22 +1000 | [diff] [blame] | 3952 | if (test_bit(R5_Insync, &dev->flags) && |
| 3953 | test_bit(STRIPE_PREREAD_ACTIVE, |
| 3954 | &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3955 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3956 | "%d for Reconstruct\n", i); |
| 3957 | set_bit(R5_LOCKED, &dev->flags); |
| 3958 | set_bit(R5_Wantread, &dev->flags); |
| 3959 | s->locked++; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3960 | qread++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3961 | } else { |
| 3962 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3963 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3964 | } |
| 3965 | } |
| 3966 | } |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 3967 | if (rcw && conf->mddev->queue) |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 3968 | blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", |
| 3969 | (unsigned long long)sh->sector, |
| 3970 | rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3971 | } |
NeilBrown | b1b02fe | 2015-02-02 10:44:29 +1100 | [diff] [blame] | 3972 | |
| 3973 | if (rcw > disks && rmw > disks && |
| 3974 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3975 | set_bit(STRIPE_DELAYED, &sh->state); |
| 3976 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3977 | /* now if nothing is locked, and if we have enough data, |
| 3978 | * we can start a write request |
| 3979 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3980 | /* since handle_stripe can be called at any time we need to handle the |
| 3981 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 3982 | * subsequent call wants to start a write request. raid_run_ops only |
| 3983 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3984 | * simultaneously. If this is not the case then new writes need to be |
| 3985 | * held off until the compute completes. |
| 3986 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 3987 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 3988 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3989 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3990 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3991 | return 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3994 | static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3995 | struct stripe_head_state *s, int disks) |
| 3996 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 3997 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3998 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3999 | BUG_ON(sh->batch_head); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4000 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4001 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4002 | switch (sh->check_state) { |
| 4003 | case check_state_idle: |
| 4004 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4005 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4006 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4007 | sh->check_state = check_state_run; |
| 4008 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4009 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4010 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4011 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4012 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4013 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4014 | /* fall through */ |
| 4015 | case check_state_compute_result: |
| 4016 | sh->check_state = check_state_idle; |
| 4017 | if (!dev) |
| 4018 | dev = &sh->dev[sh->pd_idx]; |
| 4019 | |
| 4020 | /* check that a write has not made the stripe insync */ |
| 4021 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 4022 | break; |
| 4023 | |
| 4024 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4025 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 4026 | BUG_ON(s->uptodate != disks); |
| 4027 | |
| 4028 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4029 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4030 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4031 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4032 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4033 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4034 | break; |
| 4035 | case check_state_run: |
| 4036 | break; /* we will be called again upon completion */ |
| 4037 | case check_state_check_result: |
| 4038 | sh->check_state = check_state_idle; |
| 4039 | |
| 4040 | /* if a failure occurred during the check operation, leave |
| 4041 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 4042 | */ |
| 4043 | if (s->failed) |
| 4044 | break; |
| 4045 | |
| 4046 | /* handle a successful check operation, if parity is correct |
| 4047 | * we are done. Otherwise update the mismatch count and repair |
| 4048 | * parity if !MD_RECOVERY_CHECK |
| 4049 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 4050 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4051 | /* parity is correct (on disc, |
| 4052 | * not in buffer any more) |
| 4053 | */ |
| 4054 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4055 | else { |
Jianpeng Ma | 7f7583d | 2012-10-11 14:17:59 +1100 | [diff] [blame] | 4056 | atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4057 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 4058 | /* don't try to repair!! */ |
| 4059 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4060 | else { |
| 4061 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 4062 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4063 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 4064 | set_bit(R5_Wantcompute, |
| 4065 | &sh->dev[sh->pd_idx].flags); |
| 4066 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 4067 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4068 | s->uptodate++; |
| 4069 | } |
| 4070 | } |
| 4071 | break; |
| 4072 | case check_state_compute_run: |
| 4073 | break; |
| 4074 | default: |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 4075 | pr_err("%s: unknown check_state: %d sector: %llu\n", |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4076 | __func__, sh->check_state, |
| 4077 | (unsigned long long) sh->sector); |
| 4078 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4082 | static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4083 | struct stripe_head_state *s, |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4084 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4085 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4086 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 4087 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4088 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4089 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4090 | BUG_ON(sh->batch_head); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4091 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4092 | |
| 4093 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4094 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4095 | /* Want to check and possibly repair P and Q. |
| 4096 | * However there could be one 'failed' device, in which |
| 4097 | * case we can only check one of them, possibly using the |
| 4098 | * other to generate missing data |
| 4099 | */ |
| 4100 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4101 | switch (sh->check_state) { |
| 4102 | case check_state_idle: |
| 4103 | /* start a new check operation if there are < 2 failures */ |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4104 | if (s->failed == s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4105 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4106 | * makes sense to check P (If anything else were failed, |
| 4107 | * we would have used P to recreate it). |
| 4108 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4109 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4110 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4111 | if (!s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4112 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4113 | * anything, so it makes sense to check it |
| 4114 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4115 | if (sh->check_state == check_state_run) |
| 4116 | sh->check_state = check_state_run_pq; |
| 4117 | else |
| 4118 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4119 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4120 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4121 | /* discard potentially stale zero_sum_result */ |
| 4122 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4123 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4124 | if (sh->check_state == check_state_run) { |
| 4125 | /* async_xor_zero_sum destroys the contents of P */ |
| 4126 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 4127 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4128 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4129 | if (sh->check_state >= check_state_run && |
| 4130 | sh->check_state <= check_state_run_pq) { |
| 4131 | /* async_syndrome_zero_sum preserves P and Q, so |
| 4132 | * no need to mark them !uptodate here |
| 4133 | */ |
| 4134 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 4135 | break; |
| 4136 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4137 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4138 | /* we have 2-disk failure */ |
| 4139 | BUG_ON(s->failed != 2); |
| 4140 | /* fall through */ |
| 4141 | case check_state_compute_result: |
| 4142 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4143 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4144 | /* check that a write has not made the stripe insync */ |
| 4145 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 4146 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4147 | |
| 4148 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4149 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4150 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4151 | 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] | 4152 | if (s->failed == 2) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4153 | dev = &sh->dev[s->failed_num[1]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4154 | s->locked++; |
| 4155 | set_bit(R5_LOCKED, &dev->flags); |
| 4156 | set_bit(R5_Wantwrite, &dev->flags); |
| 4157 | } |
| 4158 | if (s->failed >= 1) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4159 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4160 | s->locked++; |
| 4161 | set_bit(R5_LOCKED, &dev->flags); |
| 4162 | set_bit(R5_Wantwrite, &dev->flags); |
| 4163 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4164 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4165 | dev = &sh->dev[pd_idx]; |
| 4166 | s->locked++; |
| 4167 | set_bit(R5_LOCKED, &dev->flags); |
| 4168 | set_bit(R5_Wantwrite, &dev->flags); |
| 4169 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4170 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4171 | dev = &sh->dev[qd_idx]; |
| 4172 | s->locked++; |
| 4173 | set_bit(R5_LOCKED, &dev->flags); |
| 4174 | set_bit(R5_Wantwrite, &dev->flags); |
| 4175 | } |
| 4176 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 4177 | |
| 4178 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4179 | break; |
| 4180 | case check_state_run: |
| 4181 | case check_state_run_q: |
| 4182 | case check_state_run_pq: |
| 4183 | break; /* we will be called again upon completion */ |
| 4184 | case check_state_check_result: |
| 4185 | sh->check_state = check_state_idle; |
| 4186 | |
| 4187 | /* handle a successful check operation, if parity is correct |
| 4188 | * we are done. Otherwise update the mismatch count and repair |
| 4189 | * parity if !MD_RECOVERY_CHECK |
| 4190 | */ |
| 4191 | if (sh->ops.zero_sum_result == 0) { |
| 4192 | /* both parities are correct */ |
| 4193 | if (!s->failed) |
| 4194 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4195 | else { |
| 4196 | /* in contrast to the raid5 case we can validate |
| 4197 | * parity, but still have a failure to write |
| 4198 | * back |
| 4199 | */ |
| 4200 | sh->check_state = check_state_compute_result; |
| 4201 | /* Returning at this point means that we may go |
| 4202 | * off and bring p and/or q uptodate again so |
| 4203 | * we make sure to check zero_sum_result again |
| 4204 | * to verify if p or q need writeback |
| 4205 | */ |
| 4206 | } |
| 4207 | } else { |
Jianpeng Ma | 7f7583d | 2012-10-11 14:17:59 +1100 | [diff] [blame] | 4208 | atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4209 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) |
| 4210 | /* don't try to repair!! */ |
| 4211 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4212 | else { |
| 4213 | int *target = &sh->ops.target; |
| 4214 | |
| 4215 | sh->ops.target = -1; |
| 4216 | sh->ops.target2 = -1; |
| 4217 | sh->check_state = check_state_compute_run; |
| 4218 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 4219 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 4220 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 4221 | set_bit(R5_Wantcompute, |
| 4222 | &sh->dev[pd_idx].flags); |
| 4223 | *target = pd_idx; |
| 4224 | target = &sh->ops.target2; |
| 4225 | s->uptodate++; |
| 4226 | } |
| 4227 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 4228 | set_bit(R5_Wantcompute, |
| 4229 | &sh->dev[qd_idx].flags); |
| 4230 | *target = qd_idx; |
| 4231 | s->uptodate++; |
| 4232 | } |
| 4233 | } |
| 4234 | } |
| 4235 | break; |
| 4236 | case check_state_compute_run: |
| 4237 | break; |
| 4238 | default: |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 4239 | pr_warn("%s: unknown check_state: %d sector: %llu\n", |
| 4240 | __func__, sh->check_state, |
| 4241 | (unsigned long long) sh->sector); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4242 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4246 | static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4247 | { |
| 4248 | int i; |
| 4249 | |
| 4250 | /* We have read all the blocks in this stripe and now we need to |
| 4251 | * copy some of them into a target stripe for expand. |
| 4252 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4253 | struct dma_async_tx_descriptor *tx = NULL; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4254 | BUG_ON(sh->batch_head); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4255 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4256 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 4257 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4258 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4259 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 4260 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4261 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4262 | sector_t bn = raid5_compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4263 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 4264 | &dd_idx, NULL); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4265 | sh2 = raid5_get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4266 | if (sh2 == NULL) |
| 4267 | /* so far only the early blocks of this stripe |
| 4268 | * have been requested. When later blocks |
| 4269 | * get requested, we will try again |
| 4270 | */ |
| 4271 | continue; |
| 4272 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 4273 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 4274 | /* must have already done this block */ |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4275 | raid5_release_stripe(sh2); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4276 | continue; |
| 4277 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4278 | |
| 4279 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 4280 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4281 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Dan Williams | 88ba2aa | 2009-04-09 16:16:18 -0700 | [diff] [blame] | 4282 | sh->dev[i].page, 0, 0, STRIPE_SIZE, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 4283 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4284 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4285 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 4286 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 4287 | for (j = 0; j < conf->raid_disks; j++) |
| 4288 | if (j != sh2->pd_idx && |
NeilBrown | 86c374b | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4289 | j != sh2->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4290 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 4291 | break; |
| 4292 | if (j == conf->raid_disks) { |
| 4293 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 4294 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 4295 | } |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4296 | raid5_release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4297 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4298 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 4299 | /* done submitting copies, wait for them to complete */ |
NeilBrown | 749586b | 2012-11-20 14:11:15 +1100 | [diff] [blame] | 4300 | async_tx_quiesce(&tx); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4302 | |
| 4303 | /* |
| 4304 | * handle_stripe - do things to a stripe. |
| 4305 | * |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4306 | * We lock the stripe by setting STRIPE_ACTIVE and then examine the |
| 4307 | * state of various bits to see what needs to be done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | * Possible results: |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4309 | * return some read requests which now have data |
| 4310 | * return some write requests which are safely on storage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | * schedule a read on some buffers |
| 4312 | * schedule a write of some buffers |
| 4313 | * return confirmation of parity correctness |
| 4314 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4316 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4317 | static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4318 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4319 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4320 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4321 | struct r5dev *dev; |
| 4322 | int i; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4323 | int do_recovery = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4324 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4325 | memset(s, 0, sizeof(*s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4326 | |
shli@kernel.org | dabc4ec | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 4327 | s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state) && !sh->batch_head; |
| 4328 | s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state) && !sh->batch_head; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4329 | s->failed_num[0] = -1; |
| 4330 | s->failed_num[1] = -1; |
Shaohua Li | 6e74a9c | 2015-10-08 21:54:08 -0700 | [diff] [blame] | 4331 | s->log_failed = r5l_log_disk_error(conf); |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4332 | |
| 4333 | /* Now to look around and see what can be done */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4334 | rcu_read_lock(); |
| 4335 | for (i=disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4336 | struct md_rdev *rdev; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4337 | sector_t first_bad; |
| 4338 | int bad_sectors; |
| 4339 | int is_bad = 0; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4340 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4341 | dev = &sh->dev[i]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4342 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4343 | pr_debug("check %d: state 0x%lx read %p write %p written %p\n", |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4344 | i, dev->flags, |
| 4345 | dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 4346 | /* maybe we can reply to a read |
| 4347 | * |
| 4348 | * new wantfill requests are only permitted while |
| 4349 | * ops_complete_biofill is guaranteed to be inactive |
| 4350 | */ |
| 4351 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 4352 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 4353 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4354 | |
| 4355 | /* now count some things */ |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4356 | if (test_bit(R5_LOCKED, &dev->flags)) |
| 4357 | s->locked++; |
| 4358 | if (test_bit(R5_UPTODATE, &dev->flags)) |
| 4359 | s->uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 4360 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4361 | s->compute++; |
| 4362 | BUG_ON(s->compute > 2); |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 4363 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4364 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4365 | if (test_bit(R5_Wantfill, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4366 | s->to_fill++; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4367 | else if (dev->toread) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4368 | s->to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4369 | if (dev->towrite) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4370 | s->to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4371 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4372 | s->non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4373 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4374 | if (dev->written) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4375 | s->written++; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4376 | /* Prefer to use the replacement for reads, but only |
| 4377 | * if it is recovered enough and has no bad blocks. |
| 4378 | */ |
| 4379 | rdev = rcu_dereference(conf->disks[i].replacement); |
| 4380 | if (rdev && !test_bit(Faulty, &rdev->flags) && |
| 4381 | rdev->recovery_offset >= sh->sector + STRIPE_SECTORS && |
| 4382 | !is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 4383 | &first_bad, &bad_sectors)) |
| 4384 | set_bit(R5_ReadRepl, &dev->flags); |
| 4385 | else { |
NeilBrown | e6030cb | 2015-07-17 13:26:23 +1000 | [diff] [blame] | 4386 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4387 | set_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | e6030cb | 2015-07-17 13:26:23 +1000 | [diff] [blame] | 4388 | else |
| 4389 | clear_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4390 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 4391 | clear_bit(R5_ReadRepl, &dev->flags); |
| 4392 | } |
NeilBrown | 9283d8c | 2011-12-08 16:27:57 +1100 | [diff] [blame] | 4393 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 4394 | rdev = NULL; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4395 | if (rdev) { |
| 4396 | is_bad = is_badblock(rdev, sh->sector, STRIPE_SECTORS, |
| 4397 | &first_bad, &bad_sectors); |
| 4398 | if (s->blocked_rdev == NULL |
| 4399 | && (test_bit(Blocked, &rdev->flags) |
| 4400 | || is_bad < 0)) { |
| 4401 | if (is_bad < 0) |
| 4402 | set_bit(BlockedBadBlocks, |
| 4403 | &rdev->flags); |
| 4404 | s->blocked_rdev = rdev; |
| 4405 | atomic_inc(&rdev->nr_pending); |
| 4406 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 4407 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4408 | clear_bit(R5_Insync, &dev->flags); |
| 4409 | if (!rdev) |
| 4410 | /* Not in-sync */; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4411 | else if (is_bad) { |
| 4412 | /* also not in-sync */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 4413 | if (!test_bit(WriteErrorSeen, &rdev->flags) && |
| 4414 | test_bit(R5_UPTODATE, &dev->flags)) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4415 | /* treat as in-sync, but with a read error |
| 4416 | * which we can now try to correct |
| 4417 | */ |
| 4418 | set_bit(R5_Insync, &dev->flags); |
| 4419 | set_bit(R5_ReadError, &dev->flags); |
| 4420 | } |
| 4421 | } else if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4422 | set_bit(R5_Insync, &dev->flags); |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 4423 | else if (sh->sector + STRIPE_SECTORS <= rdev->recovery_offset) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4424 | /* in sync if before recovery_offset */ |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 4425 | set_bit(R5_Insync, &dev->flags); |
| 4426 | else if (test_bit(R5_UPTODATE, &dev->flags) && |
| 4427 | test_bit(R5_Expanded, &dev->flags)) |
| 4428 | /* If we've reshaped into here, we assume it is Insync. |
| 4429 | * We will shortly update recovery_offset to make |
| 4430 | * it official. |
| 4431 | */ |
| 4432 | set_bit(R5_Insync, &dev->flags); |
| 4433 | |
NeilBrown | 1cc03eb | 2014-01-06 13:19:42 +1100 | [diff] [blame] | 4434 | if (test_bit(R5_WriteError, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4435 | /* This flag does not apply to '.replacement' |
| 4436 | * only to .rdev, so make sure to check that*/ |
| 4437 | struct md_rdev *rdev2 = rcu_dereference( |
| 4438 | conf->disks[i].rdev); |
| 4439 | if (rdev2 == rdev) |
| 4440 | clear_bit(R5_Insync, &dev->flags); |
| 4441 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4442 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4443 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4444 | } else |
| 4445 | clear_bit(R5_WriteError, &dev->flags); |
| 4446 | } |
NeilBrown | 1cc03eb | 2014-01-06 13:19:42 +1100 | [diff] [blame] | 4447 | if (test_bit(R5_MadeGood, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4448 | /* This flag does not apply to '.replacement' |
| 4449 | * only to .rdev, so make sure to check that*/ |
| 4450 | struct md_rdev *rdev2 = rcu_dereference( |
| 4451 | conf->disks[i].rdev); |
| 4452 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 4453 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4454 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 4455 | } else |
| 4456 | clear_bit(R5_MadeGood, &dev->flags); |
| 4457 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4458 | if (test_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 4459 | struct md_rdev *rdev2 = rcu_dereference( |
| 4460 | conf->disks[i].replacement); |
| 4461 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
| 4462 | s->handle_bad_blocks = 1; |
| 4463 | atomic_inc(&rdev2->nr_pending); |
| 4464 | } else |
| 4465 | clear_bit(R5_MadeGoodRepl, &dev->flags); |
| 4466 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4467 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4468 | /* The ReadError flag will just be confusing now */ |
| 4469 | clear_bit(R5_ReadError, &dev->flags); |
| 4470 | clear_bit(R5_ReWrite, &dev->flags); |
| 4471 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4472 | if (test_bit(R5_ReadError, &dev->flags)) |
| 4473 | clear_bit(R5_Insync, &dev->flags); |
| 4474 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4475 | if (s->failed < 2) |
| 4476 | s->failed_num[s->failed] = i; |
| 4477 | s->failed++; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4478 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
| 4479 | do_recovery = 1; |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4480 | } |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4481 | |
| 4482 | if (test_bit(R5_InJournal, &dev->flags)) |
| 4483 | s->injournal++; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4484 | if (test_bit(R5_InJournal, &dev->flags) && dev->written) |
| 4485 | s->just_cached++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4486 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4487 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 4488 | /* If there is a failed device being replaced, |
| 4489 | * we must be recovering. |
| 4490 | * else if we are after recovery_cp, we must be syncing |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 4491 | * else if MD_RECOVERY_REQUESTED is set, we also are syncing. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4492 | * else we can only be replacing |
| 4493 | * sync and recovery both need to read all devices, and so |
| 4494 | * use the same flag. |
| 4495 | */ |
| 4496 | if (do_recovery || |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 4497 | sh->sector >= conf->mddev->recovery_cp || |
| 4498 | test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4499 | s->syncing = 1; |
| 4500 | else |
| 4501 | s->replacing = 1; |
| 4502 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4503 | rcu_read_unlock(); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4504 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4505 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4506 | static int clear_batch_ready(struct stripe_head *sh) |
| 4507 | { |
NeilBrown | b15a9db | 2015-05-22 15:20:04 +1000 | [diff] [blame] | 4508 | /* Return '1' if this is a member of batch, or |
| 4509 | * '0' if it is a lone stripe or a head which can now be |
| 4510 | * handled. |
| 4511 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4512 | struct stripe_head *tmp; |
| 4513 | if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state)) |
NeilBrown | b15a9db | 2015-05-22 15:20:04 +1000 | [diff] [blame] | 4514 | return (sh->batch_head && sh->batch_head != sh); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4515 | spin_lock(&sh->stripe_lock); |
| 4516 | if (!sh->batch_head) { |
| 4517 | spin_unlock(&sh->stripe_lock); |
| 4518 | return 0; |
| 4519 | } |
| 4520 | |
| 4521 | /* |
| 4522 | * this stripe could be added to a batch list before we check |
| 4523 | * BATCH_READY, skips it |
| 4524 | */ |
| 4525 | if (sh->batch_head != sh) { |
| 4526 | spin_unlock(&sh->stripe_lock); |
| 4527 | return 1; |
| 4528 | } |
| 4529 | spin_lock(&sh->batch_lock); |
| 4530 | list_for_each_entry(tmp, &sh->batch_list, batch_list) |
| 4531 | clear_bit(STRIPE_BATCH_READY, &tmp->state); |
| 4532 | spin_unlock(&sh->batch_lock); |
| 4533 | spin_unlock(&sh->stripe_lock); |
| 4534 | |
| 4535 | /* |
| 4536 | * BATCH_READY is cleared, no new stripes can be added. |
| 4537 | * batch_list can be accessed without lock |
| 4538 | */ |
| 4539 | return 0; |
| 4540 | } |
| 4541 | |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4542 | static void break_stripe_batch_list(struct stripe_head *head_sh, |
| 4543 | unsigned long handle_flags) |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4544 | { |
NeilBrown | 4e3d62f | 2015-05-21 11:50:16 +1000 | [diff] [blame] | 4545 | struct stripe_head *sh, *next; |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4546 | int i; |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4547 | int do_wakeup = 0; |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4548 | |
NeilBrown | bb27051 | 2015-05-08 18:19:40 +1000 | [diff] [blame] | 4549 | list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) { |
| 4550 | |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4551 | list_del_init(&sh->batch_list); |
| 4552 | |
Shaohua Li | fb3229d | 2016-03-09 10:08:38 -0800 | [diff] [blame] | 4553 | WARN_ONCE(sh->state & ((1 << STRIPE_ACTIVE) | |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4554 | (1 << STRIPE_SYNCING) | |
| 4555 | (1 << STRIPE_REPLACED) | |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4556 | (1 << STRIPE_DELAYED) | |
| 4557 | (1 << STRIPE_BIT_DELAY) | |
| 4558 | (1 << STRIPE_FULL_WRITE) | |
| 4559 | (1 << STRIPE_BIOFILL_RUN) | |
| 4560 | (1 << STRIPE_COMPUTE_RUN) | |
| 4561 | (1 << STRIPE_OPS_REQ_PENDING) | |
| 4562 | (1 << STRIPE_DISCARD) | |
| 4563 | (1 << STRIPE_BATCH_READY) | |
| 4564 | (1 << STRIPE_BATCH_ERR) | |
Shaohua Li | fb3229d | 2016-03-09 10:08:38 -0800 | [diff] [blame] | 4565 | (1 << STRIPE_BITMAP_PENDING)), |
| 4566 | "stripe state: %lx\n", sh->state); |
| 4567 | WARN_ONCE(head_sh->state & ((1 << STRIPE_DISCARD) | |
| 4568 | (1 << STRIPE_REPLACED)), |
| 4569 | "head stripe state: %lx\n", head_sh->state); |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4570 | |
| 4571 | set_mask_bits(&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | |
NeilBrown | 550da24 | 2016-03-09 12:58:25 +1100 | [diff] [blame] | 4572 | (1 << STRIPE_PREREAD_ACTIVE) | |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4573 | (1 << STRIPE_DEGRADED)), |
| 4574 | head_sh->state & (1 << STRIPE_INSYNC)); |
| 4575 | |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4576 | sh->check_state = head_sh->check_state; |
| 4577 | sh->reconstruct_state = head_sh->reconstruct_state; |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4578 | for (i = 0; i < sh->disks; i++) { |
| 4579 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 4580 | do_wakeup = 1; |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4581 | sh->dev[i].flags = head_sh->dev[i].flags & |
| 4582 | (~((1 << R5_WriteError) | (1 << R5_Overlap))); |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4583 | } |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4584 | spin_lock_irq(&sh->stripe_lock); |
| 4585 | sh->batch_head = NULL; |
| 4586 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4587 | if (handle_flags == 0 || |
| 4588 | sh->state & handle_flags) |
| 4589 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4590 | raid5_release_stripe(sh); |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4591 | } |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4592 | spin_lock_irq(&head_sh->stripe_lock); |
| 4593 | head_sh->batch_head = NULL; |
| 4594 | spin_unlock_irq(&head_sh->stripe_lock); |
| 4595 | for (i = 0; i < head_sh->disks; i++) |
| 4596 | if (test_and_clear_bit(R5_Overlap, &head_sh->dev[i].flags)) |
| 4597 | do_wakeup = 1; |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4598 | if (head_sh->state & handle_flags) |
| 4599 | set_bit(STRIPE_HANDLE, &head_sh->state); |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4600 | |
| 4601 | if (do_wakeup) |
| 4602 | wake_up(&head_sh->raid_conf->wait_for_overlap); |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4603 | } |
| 4604 | |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4605 | static void handle_stripe(struct stripe_head *sh) |
| 4606 | { |
| 4607 | struct stripe_head_state s; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4608 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4609 | int i; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4610 | int prexor; |
| 4611 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4612 | struct r5dev *pdev, *qdev; |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4613 | |
| 4614 | clear_bit(STRIPE_HANDLE, &sh->state); |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 4615 | if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4616 | /* already being handled, ensure it gets handled |
| 4617 | * again when current action finishes */ |
| 4618 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4619 | return; |
| 4620 | } |
| 4621 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4622 | if (clear_batch_ready(sh) ) { |
| 4623 | clear_bit_unlock(STRIPE_ACTIVE, &sh->state); |
| 4624 | return; |
| 4625 | } |
| 4626 | |
NeilBrown | 4e3d62f | 2015-05-21 11:50:16 +1000 | [diff] [blame] | 4627 | if (test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state)) |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4628 | break_stripe_batch_list(sh, 0); |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4629 | |
shli@kernel.org | dabc4ec | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 4630 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) { |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4631 | spin_lock(&sh->stripe_lock); |
| 4632 | /* Cannot process 'sync' concurrently with 'discard' */ |
| 4633 | if (!test_bit(STRIPE_DISCARD, &sh->state) && |
| 4634 | test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 4635 | set_bit(STRIPE_SYNCING, &sh->state); |
| 4636 | clear_bit(STRIPE_INSYNC, &sh->state); |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4637 | clear_bit(STRIPE_REPLACED, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4638 | } |
| 4639 | spin_unlock(&sh->stripe_lock); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4640 | } |
| 4641 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 4642 | |
| 4643 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
| 4644 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
| 4645 | (unsigned long long)sh->sector, sh->state, |
| 4646 | atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, |
| 4647 | sh->check_state, sh->reconstruct_state); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4648 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4649 | analyse_stripe(sh, &s); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4650 | |
Shaohua Li | b70abcb | 2015-08-13 14:31:58 -0700 | [diff] [blame] | 4651 | if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) |
| 4652 | goto finish; |
| 4653 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4654 | if (s.handle_bad_blocks) { |
| 4655 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4656 | goto finish; |
| 4657 | } |
| 4658 | |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4659 | if (unlikely(s.blocked_rdev)) { |
| 4660 | if (s.syncing || s.expanding || s.expanded || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4661 | s.replacing || s.to_write || s.written) { |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4662 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4663 | goto finish; |
| 4664 | } |
| 4665 | /* There is nothing for the blocked_rdev to block */ |
| 4666 | rdev_dec_pending(s.blocked_rdev, conf->mddev); |
| 4667 | s.blocked_rdev = NULL; |
| 4668 | } |
| 4669 | |
| 4670 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 4671 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 4672 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 4673 | } |
| 4674 | |
| 4675 | pr_debug("locked=%d uptodate=%d to_read=%d" |
| 4676 | " to_write=%d failed=%d failed_num=%d,%d\n", |
| 4677 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 4678 | s.failed_num[0], s.failed_num[1]); |
| 4679 | /* check if the array has lost more than max_degraded devices and, |
| 4680 | * if so, some requests might need to be failed. |
| 4681 | */ |
Shaohua Li | 6e74a9c | 2015-10-08 21:54:08 -0700 | [diff] [blame] | 4682 | if (s.failed > conf->max_degraded || s.log_failed) { |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 4683 | sh->check_state = 0; |
| 4684 | sh->reconstruct_state = 0; |
NeilBrown | 626f209 | 2015-05-22 14:03:10 +1000 | [diff] [blame] | 4685 | break_stripe_batch_list(sh, 0); |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 4686 | if (s.to_read+s.to_write+s.written) |
| 4687 | handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4688 | if (s.syncing + s.replacing) |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 4689 | handle_failed_sync(conf, sh, &s); |
| 4690 | } |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4691 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4692 | /* Now we check to see if any write operations have recently |
| 4693 | * completed |
| 4694 | */ |
| 4695 | prexor = 0; |
| 4696 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
| 4697 | prexor = 1; |
| 4698 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 4699 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
| 4700 | sh->reconstruct_state = reconstruct_state_idle; |
| 4701 | |
| 4702 | /* All the 'written' buffers and the parity block are ready to |
| 4703 | * be written back to disk |
| 4704 | */ |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 4705 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && |
| 4706 | !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4707 | BUG_ON(sh->qd_idx >= 0 && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 4708 | !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && |
| 4709 | !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4710 | for (i = disks; i--; ) { |
| 4711 | struct r5dev *dev = &sh->dev[i]; |
| 4712 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 4713 | (i == sh->pd_idx || i == sh->qd_idx || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4714 | dev->written || test_bit(R5_InJournal, |
| 4715 | &dev->flags))) { |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4716 | pr_debug("Writing block %d\n", i); |
| 4717 | set_bit(R5_Wantwrite, &dev->flags); |
| 4718 | if (prexor) |
| 4719 | continue; |
NeilBrown | 9c4bdf6 | 2014-08-13 09:57:07 +1000 | [diff] [blame] | 4720 | if (s.failed > 1) |
| 4721 | continue; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4722 | if (!test_bit(R5_Insync, &dev->flags) || |
| 4723 | ((i == sh->pd_idx || i == sh->qd_idx) && |
| 4724 | s.failed == 0)) |
| 4725 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4726 | } |
| 4727 | } |
| 4728 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4729 | s.dec_preread_active = 1; |
| 4730 | } |
| 4731 | |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 4732 | /* |
| 4733 | * might be able to return some write requests if the parity blocks |
| 4734 | * are safe, or on a failed drive |
| 4735 | */ |
| 4736 | pdev = &sh->dev[sh->pd_idx]; |
| 4737 | s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) |
| 4738 | || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); |
| 4739 | qdev = &sh->dev[sh->qd_idx]; |
| 4740 | s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) |
| 4741 | || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) |
| 4742 | || conf->level < 6; |
| 4743 | |
| 4744 | if (s.written && |
| 4745 | (s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
| 4746 | && !test_bit(R5_LOCKED, &pdev->flags) |
| 4747 | && (test_bit(R5_UPTODATE, &pdev->flags) || |
| 4748 | test_bit(R5_Discard, &pdev->flags))))) && |
| 4749 | (s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
| 4750 | && !test_bit(R5_LOCKED, &qdev->flags) |
| 4751 | && (test_bit(R5_UPTODATE, &qdev->flags) || |
| 4752 | test_bit(R5_Discard, &qdev->flags)))))) |
| 4753 | handle_stripe_clean_event(conf, sh, disks, &s.return_bi); |
| 4754 | |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4755 | if (s.just_cached) |
| 4756 | r5c_handle_cached_data_endio(conf, sh, disks, &s.return_bi); |
| 4757 | r5l_stripe_write_finished(sh); |
| 4758 | |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 4759 | /* Now we might consider reading some blocks, either to check/generate |
| 4760 | * parity, or to satisfy requests |
| 4761 | * or to load a block that is being partially written. |
| 4762 | */ |
| 4763 | if (s.to_read || s.non_overwrite |
| 4764 | || (conf->level == 6 && s.to_write && s.failed) |
| 4765 | || (s.syncing && (s.uptodate + s.compute < disks)) |
| 4766 | || s.replacing |
| 4767 | || s.expanding) |
| 4768 | handle_stripe_fill(sh, &s, disks); |
| 4769 | |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4770 | /* |
| 4771 | * When the stripe finishes full journal write cycle (write to journal |
| 4772 | * and raid disk), this is the clean up procedure so it is ready for |
| 4773 | * next operation. |
| 4774 | */ |
| 4775 | r5c_finish_stripe_write_out(conf, sh, &s); |
| 4776 | |
| 4777 | /* |
| 4778 | * Now to consider new write requests, cache write back and what else, |
| 4779 | * if anything should be read. We do not handle new writes when: |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4780 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 4781 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 4782 | * block. |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4783 | * 3/ A r5c cache log write is in flight. |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4784 | */ |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4785 | |
| 4786 | if (!sh->reconstruct_state && !sh->check_state && !sh->log_io) { |
| 4787 | if (!r5c_is_writeback(conf->log)) { |
| 4788 | if (s.to_write) |
| 4789 | handle_stripe_dirtying(conf, sh, &s, disks); |
| 4790 | } else { /* write back cache */ |
| 4791 | int ret = 0; |
| 4792 | |
| 4793 | /* First, try handle writes in caching phase */ |
| 4794 | if (s.to_write) |
| 4795 | ret = r5c_try_caching_write(conf, sh, &s, |
| 4796 | disks); |
| 4797 | /* |
| 4798 | * If caching phase failed: ret == -EAGAIN |
| 4799 | * OR |
| 4800 | * stripe under reclaim: !caching && injournal |
| 4801 | * |
| 4802 | * fall back to handle_stripe_dirtying() |
| 4803 | */ |
| 4804 | if (ret == -EAGAIN || |
| 4805 | /* stripe under reclaim: !caching && injournal */ |
| 4806 | (!test_bit(STRIPE_R5C_CACHING, &sh->state) && |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 4807 | s.injournal > 0)) { |
| 4808 | ret = handle_stripe_dirtying(conf, sh, &s, |
| 4809 | disks); |
| 4810 | if (ret == -EAGAIN) |
| 4811 | goto finish; |
| 4812 | } |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4813 | } |
| 4814 | } |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4815 | |
| 4816 | /* maybe we need to check and possibly fix the parity for this stripe |
| 4817 | * Any reads will already have been scheduled, so we just see if enough |
| 4818 | * data is available. The parity check is held off while parity |
| 4819 | * dependent operations are in flight. |
| 4820 | */ |
| 4821 | if (sh->check_state || |
| 4822 | (s.syncing && s.locked == 0 && |
| 4823 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 4824 | !test_bit(STRIPE_INSYNC, &sh->state))) { |
| 4825 | if (conf->level == 6) |
| 4826 | handle_parity_checks6(conf, sh, &s, disks); |
| 4827 | else |
| 4828 | handle_parity_checks5(conf, sh, &s, disks); |
| 4829 | } |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4830 | |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4831 | if ((s.replacing || s.syncing) && s.locked == 0 |
| 4832 | && !test_bit(STRIPE_COMPUTE_RUN, &sh->state) |
| 4833 | && !test_bit(STRIPE_REPLACED, &sh->state)) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4834 | /* Write out to replacement devices where possible */ |
| 4835 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4836 | if (test_bit(R5_NeedReplace, &sh->dev[i].flags)) { |
| 4837 | WARN_ON(!test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4838 | set_bit(R5_WantReplace, &sh->dev[i].flags); |
| 4839 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 4840 | s.locked++; |
| 4841 | } |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4842 | if (s.replacing) |
| 4843 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4844 | set_bit(STRIPE_REPLACED, &sh->state); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4845 | } |
| 4846 | if ((s.syncing || s.replacing) && s.locked == 0 && |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4847 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4848 | test_bit(STRIPE_INSYNC, &sh->state)) { |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4849 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 4850 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4851 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 4852 | wake_up(&conf->wait_for_overlap); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | /* If the failed drives are just a ReadError, then we might need |
| 4856 | * to progress the repair/check process |
| 4857 | */ |
| 4858 | if (s.failed <= conf->max_degraded && !conf->mddev->ro) |
| 4859 | for (i = 0; i < s.failed; i++) { |
| 4860 | struct r5dev *dev = &sh->dev[s.failed_num[i]]; |
| 4861 | if (test_bit(R5_ReadError, &dev->flags) |
| 4862 | && !test_bit(R5_LOCKED, &dev->flags) |
| 4863 | && test_bit(R5_UPTODATE, &dev->flags) |
| 4864 | ) { |
| 4865 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 4866 | set_bit(R5_Wantwrite, &dev->flags); |
| 4867 | set_bit(R5_ReWrite, &dev->flags); |
| 4868 | set_bit(R5_LOCKED, &dev->flags); |
| 4869 | s.locked++; |
| 4870 | } else { |
| 4871 | /* let's read it back */ |
| 4872 | set_bit(R5_Wantread, &dev->flags); |
| 4873 | set_bit(R5_LOCKED, &dev->flags); |
| 4874 | s.locked++; |
| 4875 | } |
| 4876 | } |
| 4877 | } |
| 4878 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4879 | /* Finish reconstruct operations initiated by the expansion process */ |
| 4880 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 4881 | struct stripe_head *sh_src |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4882 | = raid5_get_active_stripe(conf, sh->sector, 1, 1, 1); |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4883 | if (sh_src && test_bit(STRIPE_EXPAND_SOURCE, &sh_src->state)) { |
| 4884 | /* sh cannot be written until sh_src has been read. |
| 4885 | * so arrange for sh to be delayed a little |
| 4886 | */ |
| 4887 | set_bit(STRIPE_DELAYED, &sh->state); |
| 4888 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4889 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 4890 | &sh_src->state)) |
| 4891 | atomic_inc(&conf->preread_active_stripes); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4892 | raid5_release_stripe(sh_src); |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4893 | goto finish; |
| 4894 | } |
| 4895 | if (sh_src) |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4896 | raid5_release_stripe(sh_src); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4897 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4898 | sh->reconstruct_state = reconstruct_state_idle; |
| 4899 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 4900 | for (i = conf->raid_disks; i--; ) { |
| 4901 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 4902 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 4903 | s.locked++; |
| 4904 | } |
| 4905 | } |
| 4906 | |
| 4907 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 4908 | !sh->reconstruct_state) { |
| 4909 | /* Need to write out all blocks after computing parity */ |
| 4910 | sh->disks = conf->raid_disks; |
| 4911 | stripe_set_idx(sh->sector, conf, 0, sh); |
| 4912 | schedule_reconstruction(sh, &s, 1, 1); |
| 4913 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
| 4914 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 4915 | atomic_dec(&conf->reshape_stripes); |
| 4916 | wake_up(&conf->wait_for_overlap); |
| 4917 | md_done_sync(conf->mddev, STRIPE_SECTORS, 1); |
| 4918 | } |
| 4919 | |
| 4920 | if (s.expanding && s.locked == 0 && |
| 4921 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
| 4922 | handle_stripe_expansion(conf, sh); |
| 4923 | |
| 4924 | finish: |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 4925 | /* wait for this device to become unblocked */ |
NeilBrown | 5f066c6 | 2012-07-03 12:13:29 +1000 | [diff] [blame] | 4926 | if (unlikely(s.blocked_rdev)) { |
| 4927 | if (conf->mddev->external) |
| 4928 | md_wait_for_blocked_rdev(s.blocked_rdev, |
| 4929 | conf->mddev); |
| 4930 | else |
| 4931 | /* Internal metadata will immediately |
| 4932 | * be written by raid5d, so we don't |
| 4933 | * need to wait here. |
| 4934 | */ |
| 4935 | rdev_dec_pending(s.blocked_rdev, |
| 4936 | conf->mddev); |
| 4937 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 4938 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4939 | if (s.handle_bad_blocks) |
| 4940 | for (i = disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4941 | struct md_rdev *rdev; |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4942 | struct r5dev *dev = &sh->dev[i]; |
| 4943 | if (test_and_clear_bit(R5_WriteError, &dev->flags)) { |
| 4944 | /* We own a safe reference to the rdev */ |
| 4945 | rdev = conf->disks[i].rdev; |
| 4946 | if (!rdev_set_badblocks(rdev, sh->sector, |
| 4947 | STRIPE_SECTORS, 0)) |
| 4948 | md_error(conf->mddev, rdev); |
| 4949 | rdev_dec_pending(rdev, conf->mddev); |
| 4950 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 4951 | if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { |
| 4952 | rdev = conf->disks[i].rdev; |
| 4953 | rdev_clear_badblocks(rdev, sh->sector, |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4954 | STRIPE_SECTORS, 0); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 4955 | rdev_dec_pending(rdev, conf->mddev); |
| 4956 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4957 | if (test_and_clear_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 4958 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4959 | if (!rdev) |
| 4960 | /* rdev have been moved down */ |
| 4961 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4962 | rdev_clear_badblocks(rdev, sh->sector, |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 4963 | STRIPE_SECTORS, 0); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4964 | rdev_dec_pending(rdev, conf->mddev); |
| 4965 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4966 | } |
| 4967 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 4968 | if (s.ops_request) |
| 4969 | raid_run_ops(sh, s.ops_request); |
| 4970 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 4971 | ops_run_io(sh, &s); |
| 4972 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 4973 | if (s.dec_preread_active) { |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4974 | /* We delay this until after ops_run_io so that if make_request |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 4975 | * is waiting on a flush, it won't continue until the writes |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 4976 | * have actually been submitted. |
| 4977 | */ |
| 4978 | atomic_dec(&conf->preread_active_stripes); |
| 4979 | if (atomic_read(&conf->preread_active_stripes) < |
| 4980 | IO_THRESHOLD) |
| 4981 | md_wakeup_thread(conf->mddev->thread); |
| 4982 | } |
| 4983 | |
NeilBrown | c3cce6c | 2015-08-14 12:47:33 +1000 | [diff] [blame] | 4984 | if (!bio_list_empty(&s.return_bi)) { |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 4985 | if (test_bit(MD_SB_CHANGE_PENDING, &conf->mddev->sb_flags)) { |
NeilBrown | c3cce6c | 2015-08-14 12:47:33 +1000 | [diff] [blame] | 4986 | spin_lock_irq(&conf->device_lock); |
| 4987 | bio_list_merge(&conf->return_bi, &s.return_bi); |
| 4988 | spin_unlock_irq(&conf->device_lock); |
| 4989 | md_wakeup_thread(conf->mddev->thread); |
| 4990 | } else |
| 4991 | return_io(&s.return_bi); |
| 4992 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4993 | |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 4994 | clear_bit_unlock(STRIPE_ACTIVE, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4995 | } |
| 4996 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4997 | static void raid5_activate_delayed(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | { |
| 4999 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 5000 | while (!list_empty(&conf->delayed_list)) { |
| 5001 | struct list_head *l = conf->delayed_list.next; |
| 5002 | struct stripe_head *sh; |
| 5003 | sh = list_entry(l, struct stripe_head, lru); |
| 5004 | list_del_init(l); |
| 5005 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 5006 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 5007 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5008 | list_add_tail(&sh->lru, &conf->hold_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5009 | raid5_wakeup_stripe_thread(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | } |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 5011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5014 | static void activate_bit_delay(struct r5conf *conf, |
| 5015 | struct list_head *temp_inactive_list) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5016 | { |
| 5017 | /* device_lock is held */ |
| 5018 | struct list_head head; |
| 5019 | list_add(&head, &conf->bitmap_list); |
| 5020 | list_del_init(&conf->bitmap_list); |
| 5021 | while (!list_empty(&head)) { |
| 5022 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5023 | int hash; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5024 | list_del_init(&sh->lru); |
| 5025 | atomic_inc(&sh->count); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5026 | hash = sh->hash_lock_index; |
| 5027 | __release_stripe(conf, sh, &temp_inactive_list[hash]); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5028 | } |
| 5029 | } |
| 5030 | |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 5031 | static int raid5_congested(struct mddev *mddev, int bits) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5032 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5033 | struct r5conf *conf = mddev->private; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5034 | |
| 5035 | /* No difference between reads and writes. Just check |
| 5036 | * how busy the stripe_cache is |
| 5037 | */ |
NeilBrown | 3fa841d | 2009-09-23 18:10:29 +1000 | [diff] [blame] | 5038 | |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 5039 | if (test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5040 | return 1; |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 5041 | |
| 5042 | /* Also checks whether there is pressure on r5cache log space */ |
| 5043 | if (test_bit(R5C_LOG_TIGHT, &conf->cache_state)) |
| 5044 | return 1; |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5045 | if (conf->quiesce) |
| 5046 | return 1; |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5047 | if (atomic_read(&conf->empty_inactive_list_nr)) |
NeilBrown | f022b2f | 2006-10-03 01:15:56 -0700 | [diff] [blame] | 5048 | return 1; |
| 5049 | |
| 5050 | return 0; |
| 5051 | } |
| 5052 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5053 | static int in_chunk_boundary(struct mddev *mddev, struct bio *bio) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5054 | { |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5055 | struct r5conf *conf = mddev->private; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5056 | sector_t sector = bio->bi_iter.bi_sector + get_start_sect(bio->bi_bdev); |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5057 | unsigned int chunk_sectors; |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 5058 | unsigned int bio_sectors = bio_sectors(bio); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5059 | |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5060 | chunk_sectors = min(conf->chunk_sectors, conf->prev_chunk_sectors); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5061 | return chunk_sectors >= |
| 5062 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 5063 | } |
| 5064 | |
| 5065 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5066 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 5067 | * later sampled by raid5d. |
| 5068 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5069 | static void add_bio_to_retry(struct bio *bi,struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5070 | { |
| 5071 | unsigned long flags; |
| 5072 | |
| 5073 | spin_lock_irqsave(&conf->device_lock, flags); |
| 5074 | |
| 5075 | bi->bi_next = conf->retry_read_aligned_list; |
| 5076 | conf->retry_read_aligned_list = bi; |
| 5077 | |
| 5078 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 5079 | md_wakeup_thread(conf->mddev->thread); |
| 5080 | } |
| 5081 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5082 | static struct bio *remove_bio_from_retry(struct r5conf *conf) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5083 | { |
| 5084 | struct bio *bi; |
| 5085 | |
| 5086 | bi = conf->retry_read_aligned; |
| 5087 | if (bi) { |
| 5088 | conf->retry_read_aligned = NULL; |
| 5089 | return bi; |
| 5090 | } |
| 5091 | bi = conf->retry_read_aligned_list; |
| 5092 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 5093 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5094 | bi->bi_next = NULL; |
Jens Axboe | 960e739 | 2008-08-15 10:41:18 +0200 | [diff] [blame] | 5095 | /* |
| 5096 | * this sets the active strip count to 1 and the processed |
| 5097 | * strip count to zero (upper 8 bits) |
| 5098 | */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 5099 | raid5_set_bi_stripes(bi, 1); /* biased count of active stripes */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | return bi; |
| 5103 | } |
| 5104 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5105 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5106 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 5107 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 5108 | * first). |
| 5109 | * If the read failed.. |
| 5110 | */ |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5111 | static void raid5_align_endio(struct bio *bi) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5112 | { |
| 5113 | struct bio* raid_bi = bi->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5114 | struct mddev *mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5115 | struct r5conf *conf; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5116 | struct md_rdev *rdev; |
Sasha Levin | 9b81c84 | 2015-08-10 19:05:18 -0400 | [diff] [blame] | 5117 | int error = bi->bi_error; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5118 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5119 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5120 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5121 | rdev = (void*)raid_bi->bi_next; |
| 5122 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 5123 | mddev = rdev->mddev; |
| 5124 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5125 | |
| 5126 | rdev_dec_pending(rdev, conf->mddev); |
| 5127 | |
Sasha Levin | 9b81c84 | 2015-08-10 19:05:18 -0400 | [diff] [blame] | 5128 | if (!error) { |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 5129 | trace_block_bio_complete(bdev_get_queue(raid_bi->bi_bdev), |
| 5130 | raid_bi, 0); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5131 | bio_endio(raid_bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5132 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 5133 | wake_up(&conf->wait_for_quiescent); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 5134 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5135 | } |
| 5136 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5137 | 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] | 5138 | |
| 5139 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5140 | } |
| 5141 | |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5142 | static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5143 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5144 | struct r5conf *conf = mddev->private; |
NeilBrown | 8553fe7ec | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 5145 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5146 | struct bio* align_bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5147 | struct md_rdev *rdev; |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5148 | sector_t end_sector; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5149 | |
| 5150 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5151 | pr_debug("%s: non aligned\n", __func__); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5152 | return 0; |
| 5153 | } |
| 5154 | /* |
Ming Lei | d7a1030 | 2017-02-14 23:29:03 +0800 | [diff] [blame] | 5155 | * use bio_clone_fast to make a copy of the bio |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5156 | */ |
Ming Lei | d7a1030 | 2017-02-14 23:29:03 +0800 | [diff] [blame] | 5157 | align_bi = bio_clone_fast(raid_bio, GFP_NOIO, mddev->bio_set); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5158 | if (!align_bi) |
| 5159 | return 0; |
| 5160 | /* |
| 5161 | * set bi_end_io to a new function, and set bi_private to the |
| 5162 | * original bio. |
| 5163 | */ |
| 5164 | align_bi->bi_end_io = raid5_align_endio; |
| 5165 | align_bi->bi_private = raid_bio; |
| 5166 | /* |
| 5167 | * compute position |
| 5168 | */ |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5169 | align_bi->bi_iter.bi_sector = |
| 5170 | raid5_compute_sector(conf, raid_bio->bi_iter.bi_sector, |
| 5171 | 0, &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5172 | |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 5173 | end_sector = bio_end_sector(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5174 | rcu_read_lock(); |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5175 | rdev = rcu_dereference(conf->disks[dd_idx].replacement); |
| 5176 | if (!rdev || test_bit(Faulty, &rdev->flags) || |
| 5177 | rdev->recovery_offset < end_sector) { |
| 5178 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 5179 | if (rdev && |
| 5180 | (test_bit(Faulty, &rdev->flags) || |
| 5181 | !(test_bit(In_sync, &rdev->flags) || |
| 5182 | rdev->recovery_offset >= end_sector))) |
| 5183 | rdev = NULL; |
| 5184 | } |
Song Liu | 03b047f | 2017-01-11 13:39:14 -0800 | [diff] [blame] | 5185 | |
| 5186 | if (r5c_big_stripe_cached(conf, align_bi->bi_iter.bi_sector)) { |
| 5187 | rcu_read_unlock(); |
| 5188 | bio_put(align_bi); |
| 5189 | return 0; |
| 5190 | } |
| 5191 | |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5192 | if (rdev) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5193 | sector_t first_bad; |
| 5194 | int bad_sectors; |
| 5195 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5196 | atomic_inc(&rdev->nr_pending); |
| 5197 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5198 | raid_bio->bi_next = (void*)rdev; |
| 5199 | align_bi->bi_bdev = rdev->bdev; |
Jens Axboe | b7c44ed | 2015-07-24 12:37:59 -0600 | [diff] [blame] | 5200 | bio_clear_flag(align_bi, BIO_SEG_VALID); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5201 | |
Kent Overstreet | 7140aaf | 2013-09-25 13:37:01 -0700 | [diff] [blame] | 5202 | if (is_badblock(rdev, align_bi->bi_iter.bi_sector, |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5203 | bio_sectors(align_bi), |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5204 | &first_bad, &bad_sectors)) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 5205 | bio_put(align_bi); |
| 5206 | rdev_dec_pending(rdev, mddev); |
| 5207 | return 0; |
| 5208 | } |
| 5209 | |
majianpeng | 6c0544e | 2012-06-12 08:31:10 +0800 | [diff] [blame] | 5210 | /* No reshape active, so we can trust rdev->data_offset */ |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5211 | align_bi->bi_iter.bi_sector += rdev->data_offset; |
majianpeng | 6c0544e | 2012-06-12 08:31:10 +0800 | [diff] [blame] | 5212 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5213 | spin_lock_irq(&conf->device_lock); |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 5214 | wait_event_lock_irq(conf->wait_for_quiescent, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5215 | conf->quiesce == 0, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 5216 | conf->device_lock); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5217 | atomic_inc(&conf->active_aligned_reads); |
| 5218 | spin_unlock_irq(&conf->device_lock); |
| 5219 | |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 5220 | if (mddev->gendisk) |
| 5221 | trace_block_bio_remap(bdev_get_queue(align_bi->bi_bdev), |
| 5222 | align_bi, disk_devt(mddev->gendisk), |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5223 | raid_bio->bi_iter.bi_sector); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5224 | generic_make_request(align_bi); |
| 5225 | return 1; |
| 5226 | } else { |
| 5227 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5228 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5229 | return 0; |
| 5230 | } |
| 5231 | } |
| 5232 | |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5233 | static struct bio *chunk_aligned_read(struct mddev *mddev, struct bio *raid_bio) |
| 5234 | { |
| 5235 | struct bio *split; |
| 5236 | |
| 5237 | do { |
| 5238 | sector_t sector = raid_bio->bi_iter.bi_sector; |
| 5239 | unsigned chunk_sects = mddev->chunk_sectors; |
| 5240 | unsigned sectors = chunk_sects - (sector & (chunk_sects-1)); |
| 5241 | |
| 5242 | if (sectors < bio_sectors(raid_bio)) { |
| 5243 | split = bio_split(raid_bio, sectors, GFP_NOIO, fs_bio_set); |
| 5244 | bio_chain(split, raid_bio); |
| 5245 | } else |
| 5246 | split = raid_bio; |
| 5247 | |
| 5248 | if (!raid5_read_one_chunk(mddev, split)) { |
| 5249 | if (split != raid_bio) |
| 5250 | generic_make_request(raid_bio); |
| 5251 | return split; |
| 5252 | } |
| 5253 | } while (split != raid_bio); |
| 5254 | |
| 5255 | return NULL; |
| 5256 | } |
| 5257 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5258 | /* __get_priority_stripe - get the next stripe to process |
| 5259 | * |
| 5260 | * Full stripe writes are allowed to pass preread active stripes up until |
| 5261 | * the bypass_threshold is exceeded. In general the bypass_count |
| 5262 | * increments when the handle_list is handled before the hold_list; however, it |
| 5263 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 5264 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 5265 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 5266 | * handle_list. |
| 5267 | */ |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5268 | static struct stripe_head *__get_priority_stripe(struct r5conf *conf, int group) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5269 | { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5270 | struct stripe_head *sh, *tmp; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5271 | struct list_head *handle_list = NULL; |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5272 | struct r5worker_group *wg; |
| 5273 | bool second_try = !r5c_is_writeback(conf->log); |
| 5274 | bool try_loprio = test_bit(R5C_LOG_TIGHT, &conf->cache_state); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5275 | |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5276 | again: |
| 5277 | wg = NULL; |
| 5278 | sh = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5279 | if (conf->worker_cnt_per_group == 0) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5280 | handle_list = try_loprio ? &conf->loprio_list : |
| 5281 | &conf->handle_list; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5282 | } else if (group != ANY_GROUP) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5283 | handle_list = try_loprio ? &conf->worker_groups[group].loprio_list : |
| 5284 | &conf->worker_groups[group].handle_list; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5285 | wg = &conf->worker_groups[group]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5286 | } else { |
| 5287 | int i; |
| 5288 | for (i = 0; i < conf->group_cnt; i++) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5289 | handle_list = try_loprio ? &conf->worker_groups[i].loprio_list : |
| 5290 | &conf->worker_groups[i].handle_list; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5291 | wg = &conf->worker_groups[i]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5292 | if (!list_empty(handle_list)) |
| 5293 | break; |
| 5294 | } |
| 5295 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5296 | |
| 5297 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 5298 | __func__, |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5299 | list_empty(handle_list) ? "empty" : "busy", |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5300 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 5301 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 5302 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5303 | if (!list_empty(handle_list)) { |
| 5304 | sh = list_entry(handle_list->next, typeof(*sh), lru); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5305 | |
| 5306 | if (list_empty(&conf->hold_list)) |
| 5307 | conf->bypass_count = 0; |
| 5308 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 5309 | if (conf->hold_list.next == conf->last_hold) |
| 5310 | conf->bypass_count++; |
| 5311 | else { |
| 5312 | conf->last_hold = conf->hold_list.next; |
| 5313 | conf->bypass_count -= conf->bypass_threshold; |
| 5314 | if (conf->bypass_count < 0) |
| 5315 | conf->bypass_count = 0; |
| 5316 | } |
| 5317 | } |
| 5318 | } else if (!list_empty(&conf->hold_list) && |
| 5319 | ((conf->bypass_threshold && |
| 5320 | conf->bypass_count > conf->bypass_threshold) || |
| 5321 | atomic_read(&conf->pending_full_writes) == 0)) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5322 | |
| 5323 | list_for_each_entry(tmp, &conf->hold_list, lru) { |
| 5324 | if (conf->worker_cnt_per_group == 0 || |
| 5325 | group == ANY_GROUP || |
| 5326 | !cpu_online(tmp->cpu) || |
| 5327 | cpu_to_group(tmp->cpu) == group) { |
| 5328 | sh = tmp; |
| 5329 | break; |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | if (sh) { |
| 5334 | conf->bypass_count -= conf->bypass_threshold; |
| 5335 | if (conf->bypass_count < 0) |
| 5336 | conf->bypass_count = 0; |
| 5337 | } |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5338 | wg = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5339 | } |
| 5340 | |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5341 | if (!sh) { |
| 5342 | if (second_try) |
| 5343 | return NULL; |
| 5344 | second_try = true; |
| 5345 | try_loprio = !try_loprio; |
| 5346 | goto again; |
| 5347 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5348 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5349 | if (wg) { |
| 5350 | wg->stripes_cnt--; |
| 5351 | sh->group = NULL; |
| 5352 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5353 | list_del_init(&sh->lru); |
Shaohua Li | c7a6d35 | 2014-04-15 09:12:54 +0800 | [diff] [blame] | 5354 | BUG_ON(atomic_inc_return(&sh->count) != 1); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5355 | return sh; |
| 5356 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5357 | |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5358 | struct raid5_plug_cb { |
| 5359 | struct blk_plug_cb cb; |
| 5360 | struct list_head list; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5361 | struct list_head temp_inactive_list[NR_STRIPE_HASH_LOCKS]; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5362 | }; |
| 5363 | |
| 5364 | static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule) |
| 5365 | { |
| 5366 | struct raid5_plug_cb *cb = container_of( |
| 5367 | blk_cb, struct raid5_plug_cb, cb); |
| 5368 | struct stripe_head *sh; |
| 5369 | struct mddev *mddev = cb->cb.data; |
| 5370 | struct r5conf *conf = mddev->private; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 5371 | int cnt = 0; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5372 | int hash; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5373 | |
| 5374 | if (cb->list.next && !list_empty(&cb->list)) { |
| 5375 | spin_lock_irq(&conf->device_lock); |
| 5376 | while (!list_empty(&cb->list)) { |
| 5377 | sh = list_first_entry(&cb->list, struct stripe_head, lru); |
| 5378 | list_del_init(&sh->lru); |
| 5379 | /* |
| 5380 | * avoid race release_stripe_plug() sees |
| 5381 | * STRIPE_ON_UNPLUG_LIST clear but the stripe |
| 5382 | * is still in our list |
| 5383 | */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5384 | smp_mb__before_atomic(); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5385 | clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 5386 | /* |
| 5387 | * STRIPE_ON_RELEASE_LIST could be set here. In that |
| 5388 | * case, the count is always > 1 here |
| 5389 | */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5390 | hash = sh->hash_lock_index; |
| 5391 | __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 5392 | cnt++; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5393 | } |
| 5394 | spin_unlock_irq(&conf->device_lock); |
| 5395 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5396 | release_inactive_stripe_list(conf, cb->temp_inactive_list, |
| 5397 | NR_STRIPE_HASH_LOCKS); |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 5398 | if (mddev->queue) |
| 5399 | trace_block_unplug(mddev->queue, cnt, !from_schedule); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5400 | kfree(cb); |
| 5401 | } |
| 5402 | |
| 5403 | static void release_stripe_plug(struct mddev *mddev, |
| 5404 | struct stripe_head *sh) |
| 5405 | { |
| 5406 | struct blk_plug_cb *blk_cb = blk_check_plugged( |
| 5407 | raid5_unplug, mddev, |
| 5408 | sizeof(struct raid5_plug_cb)); |
| 5409 | struct raid5_plug_cb *cb; |
| 5410 | |
| 5411 | if (!blk_cb) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5412 | raid5_release_stripe(sh); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5413 | return; |
| 5414 | } |
| 5415 | |
| 5416 | cb = container_of(blk_cb, struct raid5_plug_cb, cb); |
| 5417 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5418 | if (cb->list.next == NULL) { |
| 5419 | int i; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5420 | INIT_LIST_HEAD(&cb->list); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5421 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 5422 | INIT_LIST_HEAD(cb->temp_inactive_list + i); |
| 5423 | } |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5424 | |
| 5425 | if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) |
| 5426 | list_add_tail(&sh->lru, &cb->list); |
| 5427 | else |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5428 | raid5_release_stripe(sh); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5429 | } |
| 5430 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5431 | static void make_discard_request(struct mddev *mddev, struct bio *bi) |
| 5432 | { |
| 5433 | struct r5conf *conf = mddev->private; |
| 5434 | sector_t logical_sector, last_sector; |
| 5435 | struct stripe_head *sh; |
| 5436 | int remaining; |
| 5437 | int stripe_sectors; |
| 5438 | |
| 5439 | if (mddev->reshape_position != MaxSector) |
| 5440 | /* Skip discard while reshape is happening */ |
| 5441 | return; |
| 5442 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5443 | logical_sector = bi->bi_iter.bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
| 5444 | last_sector = bi->bi_iter.bi_sector + (bi->bi_iter.bi_size>>9); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5445 | |
| 5446 | bi->bi_next = NULL; |
| 5447 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
| 5448 | |
| 5449 | stripe_sectors = conf->chunk_sectors * |
| 5450 | (conf->raid_disks - conf->max_degraded); |
| 5451 | logical_sector = DIV_ROUND_UP_SECTOR_T(logical_sector, |
| 5452 | stripe_sectors); |
| 5453 | sector_div(last_sector, stripe_sectors); |
| 5454 | |
| 5455 | logical_sector *= conf->chunk_sectors; |
| 5456 | last_sector *= conf->chunk_sectors; |
| 5457 | |
| 5458 | for (; logical_sector < last_sector; |
| 5459 | logical_sector += STRIPE_SECTORS) { |
| 5460 | DEFINE_WAIT(w); |
| 5461 | int d; |
| 5462 | again: |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5463 | sh = raid5_get_active_stripe(conf, logical_sector, 0, 0, 0); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5464 | prepare_to_wait(&conf->wait_for_overlap, &w, |
| 5465 | TASK_UNINTERRUPTIBLE); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 5466 | set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
| 5467 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5468 | raid5_release_stripe(sh); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 5469 | schedule(); |
| 5470 | goto again; |
| 5471 | } |
| 5472 | clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5473 | spin_lock_irq(&sh->stripe_lock); |
| 5474 | for (d = 0; d < conf->raid_disks; d++) { |
| 5475 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 5476 | continue; |
| 5477 | if (sh->dev[d].towrite || sh->dev[d].toread) { |
| 5478 | set_bit(R5_Overlap, &sh->dev[d].flags); |
| 5479 | spin_unlock_irq(&sh->stripe_lock); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5480 | raid5_release_stripe(sh); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5481 | schedule(); |
| 5482 | goto again; |
| 5483 | } |
| 5484 | } |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 5485 | set_bit(STRIPE_DISCARD, &sh->state); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5486 | finish_wait(&conf->wait_for_overlap, &w); |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5487 | sh->overwrite_disks = 0; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5488 | for (d = 0; d < conf->raid_disks; d++) { |
| 5489 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 5490 | continue; |
| 5491 | sh->dev[d].towrite = bi; |
| 5492 | set_bit(R5_OVERWRITE, &sh->dev[d].flags); |
| 5493 | raid5_inc_bi_active_stripes(bi); |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5494 | sh->overwrite_disks++; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5495 | } |
| 5496 | spin_unlock_irq(&sh->stripe_lock); |
| 5497 | if (conf->mddev->bitmap) { |
| 5498 | for (d = 0; |
| 5499 | d < conf->raid_disks - conf->max_degraded; |
| 5500 | d++) |
| 5501 | bitmap_startwrite(mddev->bitmap, |
| 5502 | sh->sector, |
| 5503 | STRIPE_SECTORS, |
| 5504 | 0); |
| 5505 | sh->bm_seq = conf->seq_flush + 1; |
| 5506 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 5507 | } |
| 5508 | |
| 5509 | set_bit(STRIPE_HANDLE, &sh->state); |
| 5510 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 5511 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 5512 | atomic_inc(&conf->preread_active_stripes); |
| 5513 | release_stripe_plug(mddev, sh); |
| 5514 | } |
| 5515 | |
| 5516 | remaining = raid5_dec_bi_active_stripes(bi); |
| 5517 | if (remaining == 0) { |
| 5518 | md_write_end(mddev); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5519 | bio_endio(bi); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5520 | } |
| 5521 | } |
| 5522 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 5523 | static void raid5_make_request(struct mddev *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5525 | struct r5conf *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5526 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | sector_t new_sector; |
| 5528 | sector_t logical_sector, last_sector; |
| 5529 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 5530 | const int rw = bio_data_dir(bi); |
NeilBrown | 4907732 | 2010-03-25 16:20:56 +1100 | [diff] [blame] | 5531 | int remaining; |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5532 | DEFINE_WAIT(w); |
| 5533 | bool do_prepare; |
Song Liu | 3bddb7f | 2016-11-18 16:46:50 -0800 | [diff] [blame] | 5534 | bool do_flush = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 5536 | if (unlikely(bi->bi_opf & REQ_PREFLUSH)) { |
Shaohua Li | 828cbe9 | 2015-09-02 13:49:49 -0700 | [diff] [blame] | 5537 | int ret = r5l_handle_flush_request(conf->log, bi); |
| 5538 | |
| 5539 | if (ret == 0) |
| 5540 | return; |
| 5541 | if (ret == -ENODEV) { |
| 5542 | md_flush_request(mddev, bi); |
| 5543 | return; |
| 5544 | } |
| 5545 | /* ret == -EAGAIN, fallback */ |
Song Liu | 3bddb7f | 2016-11-18 16:46:50 -0800 | [diff] [blame] | 5546 | /* |
| 5547 | * if r5l_handle_flush_request() didn't clear REQ_PREFLUSH, |
| 5548 | * we need to flush journal device |
| 5549 | */ |
| 5550 | do_flush = bi->bi_opf & REQ_PREFLUSH; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 5551 | } |
| 5552 | |
NeilBrown | 3d310eb | 2005-06-21 17:17:26 -0700 | [diff] [blame] | 5553 | md_write_start(mddev, bi); |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5554 | |
Eric Mei | 9ffc8f7 | 2015-03-18 23:39:11 -0600 | [diff] [blame] | 5555 | /* |
| 5556 | * If array is degraded, better not do chunk aligned read because |
| 5557 | * later we might have to read it again in order to reconstruct |
| 5558 | * data on failed drives. |
| 5559 | */ |
| 5560 | if (rw == READ && mddev->degraded == 0 && |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5561 | mddev->reshape_position == MaxSector) { |
| 5562 | bi = chunk_aligned_read(mddev, bi); |
| 5563 | if (!bi) |
| 5564 | return; |
| 5565 | } |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 5566 | |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 5567 | if (unlikely(bio_op(bi) == REQ_OP_DISCARD)) { |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5568 | make_discard_request(mddev, bi); |
| 5569 | return; |
| 5570 | } |
| 5571 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5572 | logical_sector = bi->bi_iter.bi_sector & ~((sector_t)STRIPE_SECTORS-1); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 5573 | last_sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | bi->bi_next = NULL; |
| 5575 | bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5576 | |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5577 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5579 | int previous; |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5580 | int seq; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 5581 | |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5582 | do_prepare = false; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5583 | retry: |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5584 | seq = read_seqcount_begin(&conf->gen_lock); |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5585 | previous = 0; |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5586 | if (do_prepare) |
| 5587 | prepare_to_wait(&conf->wait_for_overlap, &w, |
| 5588 | TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5589 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5590 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 5591 | * 64bit on a 32bit platform, and so it might be |
| 5592 | * possible to see a half-updated value |
Jesper Juhl | aeb878b | 2011-04-10 18:06:17 +0200 | [diff] [blame] | 5593 | * Of course reshape_progress could change after |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 5594 | * the lock is dropped, so once we get a reference |
| 5595 | * to the stripe that we think it is, we will have |
| 5596 | * to check again. |
| 5597 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5598 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5599 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5600 | ? logical_sector < conf->reshape_progress |
| 5601 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5602 | previous = 1; |
| 5603 | } else { |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5604 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5605 | ? logical_sector < conf->reshape_safe |
| 5606 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 5607 | spin_unlock_irq(&conf->device_lock); |
| 5608 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5609 | do_prepare = true; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 5610 | goto retry; |
| 5611 | } |
| 5612 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5613 | spin_unlock_irq(&conf->device_lock); |
| 5614 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5615 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5616 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 5617 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5618 | &dd_idx, NULL); |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 5619 | pr_debug("raid456: raid5_make_request, sector %llu logical %llu\n", |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5620 | (unsigned long long)new_sector, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5621 | (unsigned long long)logical_sector); |
| 5622 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5623 | sh = raid5_get_active_stripe(conf, new_sector, previous, |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 5624 | (bi->bi_opf & REQ_RAHEAD), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5626 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5627 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 5628 | * stripe, so we must do the range check again. |
| 5629 | * Expansion could still move past after this |
| 5630 | * test, but as we are holding a reference to |
| 5631 | * 'sh', we know that if that happens, |
| 5632 | * STRIPE_EXPANDING will get set and the expansion |
| 5633 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5634 | */ |
| 5635 | int must_retry = 0; |
| 5636 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5637 | if (mddev->reshape_backwards |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5638 | ? logical_sector >= conf->reshape_progress |
| 5639 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5640 | /* mismatch, need to try again */ |
| 5641 | must_retry = 1; |
| 5642 | spin_unlock_irq(&conf->device_lock); |
| 5643 | if (must_retry) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5644 | raid5_release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 5645 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5646 | do_prepare = true; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5647 | goto retry; |
| 5648 | } |
| 5649 | } |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5650 | if (read_seqcount_retry(&conf->gen_lock, seq)) { |
| 5651 | /* Might have got the wrong stripe_head |
| 5652 | * by accident |
| 5653 | */ |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5654 | raid5_release_stripe(sh); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5655 | goto retry; |
| 5656 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 5657 | |
Namhyung Kim | ffd96e3 | 2011-07-18 17:38:51 +1000 | [diff] [blame] | 5658 | if (rw == WRITE && |
NeilBrown | a5c308d | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 5659 | logical_sector >= mddev->suspend_lo && |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5660 | logical_sector < mddev->suspend_hi) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5661 | raid5_release_stripe(sh); |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 5662 | /* As the suspend_* range is controlled by |
| 5663 | * userspace, we want an interruptible |
| 5664 | * wait. |
| 5665 | */ |
| 5666 | flush_signals(current); |
| 5667 | prepare_to_wait(&conf->wait_for_overlap, |
| 5668 | &w, TASK_INTERRUPTIBLE); |
| 5669 | if (logical_sector >= mddev->suspend_lo && |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5670 | logical_sector < mddev->suspend_hi) { |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 5671 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5672 | do_prepare = true; |
| 5673 | } |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 5674 | goto retry; |
| 5675 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5676 | |
| 5677 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5678 | !add_stripe_bio(sh, bi, dd_idx, rw, previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5679 | /* Stripe is busy expanding or |
| 5680 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | * and wait a while |
| 5682 | */ |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 5683 | md_wakeup_thread(mddev->thread); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5684 | raid5_release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5686 | do_prepare = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | goto retry; |
| 5688 | } |
Song Liu | 3bddb7f | 2016-11-18 16:46:50 -0800 | [diff] [blame] | 5689 | if (do_flush) { |
| 5690 | set_bit(STRIPE_R5C_PREFLUSH, &sh->state); |
| 5691 | /* we only need flush for one stripe */ |
| 5692 | do_flush = false; |
| 5693 | } |
| 5694 | |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 5695 | set_bit(STRIPE_HANDLE, &sh->state); |
| 5696 | clear_bit(STRIPE_DELAYED, &sh->state); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5697 | if ((!sh->batch_head || sh == sh->batch_head) && |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 5698 | (bi->bi_opf & REQ_SYNC) && |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 5699 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 5700 | atomic_inc(&conf->preread_active_stripes); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5701 | release_stripe_plug(mddev, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | } else { |
| 5703 | /* cannot get stripe for read-ahead, just give-up */ |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5704 | bi->bi_error = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5705 | break; |
| 5706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | } |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5708 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 5709 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 5710 | remaining = raid5_dec_bi_active_stripes(bi); |
NeilBrown | f634475 | 2006-03-27 01:18:17 -0800 | [diff] [blame] | 5711 | if (remaining == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5712 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5713 | if ( rw == WRITE ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5714 | md_write_end(mddev); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 5715 | |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 5716 | trace_block_bio_complete(bdev_get_queue(bi->bi_bdev), |
| 5717 | bi, 0); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5718 | bio_endio(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | } |
| 5721 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5722 | static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5723 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5724 | static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *skipped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5726 | /* reshaping is quite different to recovery/resync so it is |
| 5727 | * handled quite separately ... here. |
| 5728 | * |
| 5729 | * On each call to sync_request, we gather one chunk worth of |
| 5730 | * destination stripes and flag them as expanding. |
| 5731 | * Then we find all the source stripes and request reads. |
| 5732 | * As the reads complete, handle_stripe will copy the data |
| 5733 | * into the destination stripe and release that stripe. |
| 5734 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5735 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | struct stripe_head *sh; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5737 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5738 | int raid_disks = conf->previous_raid_disks; |
| 5739 | int data_disks = raid_disks - conf->max_degraded; |
| 5740 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5741 | int i; |
| 5742 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5743 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5744 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5745 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5746 | struct list_head stripes; |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 5747 | sector_t retn; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5748 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5749 | if (sector_nr == 0) { |
| 5750 | /* If restarting in the middle, skip the initial sectors */ |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5751 | if (mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5752 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 5753 | sector_nr = raid5_size(mddev, 0, 0) |
| 5754 | - conf->reshape_progress; |
NeilBrown | 6cbd814 | 2015-07-24 13:30:32 +1000 | [diff] [blame] | 5755 | } else if (mddev->reshape_backwards && |
| 5756 | conf->reshape_progress == MaxSector) { |
| 5757 | /* shouldn't happen, but just in case, finish up.*/ |
| 5758 | sector_nr = MaxSector; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5759 | } else if (!mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5760 | conf->reshape_progress > 0) |
| 5761 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5762 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5763 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 5764 | mddev->curr_resync_completed = sector_nr; |
| 5765 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5766 | *skipped = 1; |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 5767 | retn = sector_nr; |
| 5768 | goto finish; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5769 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5772 | /* We need to process a full chunk at a time. |
| 5773 | * If old and new chunk sizes differ, we need to process the |
| 5774 | * largest of these |
| 5775 | */ |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5776 | |
| 5777 | reshape_sectors = max(conf->chunk_sectors, conf->prev_chunk_sectors); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5778 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5779 | /* We update the metadata at least every 10 seconds, or when |
| 5780 | * the data about to be copied would over-write the source of |
| 5781 | * the data at the front of the range. i.e. one new_stripe |
| 5782 | * along from reshape_progress new_maps to after where |
| 5783 | * reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5784 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5785 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5786 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5787 | readpos = conf->reshape_progress; |
| 5788 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5789 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5790 | sector_div(safepos, data_disks); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5791 | if (mddev->reshape_backwards) { |
NeilBrown | c74c0d7 | 2015-07-15 17:54:15 +1000 | [diff] [blame] | 5792 | BUG_ON(writepos < reshape_sectors); |
| 5793 | writepos -= reshape_sectors; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5794 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5795 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5796 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5797 | writepos += reshape_sectors; |
NeilBrown | c74c0d7 | 2015-07-15 17:54:15 +1000 | [diff] [blame] | 5798 | /* readpos and safepos are worst-case calculations. |
| 5799 | * A negative number is overly pessimistic, and causes |
| 5800 | * obvious problems for unsigned storage. So clip to 0. |
| 5801 | */ |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 5802 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 5803 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5804 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5805 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5806 | /* Having calculated the 'writepos' possibly use it |
| 5807 | * to set 'stripe_addr' which is where we will write to. |
| 5808 | */ |
| 5809 | if (mddev->reshape_backwards) { |
| 5810 | BUG_ON(conf->reshape_progress == 0); |
| 5811 | stripe_addr = writepos; |
| 5812 | BUG_ON((mddev->dev_sectors & |
| 5813 | ~((sector_t)reshape_sectors - 1)) |
| 5814 | - reshape_sectors - stripe_addr |
| 5815 | != sector_nr); |
| 5816 | } else { |
| 5817 | BUG_ON(writepos != sector_nr + reshape_sectors); |
| 5818 | stripe_addr = sector_nr; |
| 5819 | } |
| 5820 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5821 | /* 'writepos' is the most advanced device address we might write. |
| 5822 | * 'readpos' is the least advanced device address we might read. |
| 5823 | * 'safepos' is the least address recorded in the metadata as having |
| 5824 | * been reshaped. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5825 | * If there is a min_offset_diff, these are adjusted either by |
| 5826 | * increasing the safepos/readpos if diff is negative, or |
| 5827 | * increasing writepos if diff is positive. |
| 5828 | * If 'readpos' is then behind 'writepos', there is no way that we can |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5829 | * ensure safety in the face of a crash - that must be done by userspace |
| 5830 | * making a backup of the data. So in that case there is no particular |
| 5831 | * rush to update metadata. |
| 5832 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 5833 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 5834 | * we can be safe in the event of a crash. |
| 5835 | * So we insist on updating metadata if safepos is behind writepos and |
| 5836 | * readpos is beyond writepos. |
| 5837 | * In any case, update the metadata every 10 seconds. |
| 5838 | * Maybe that number should be configurable, but I'm not sure it is |
| 5839 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 5840 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5841 | if (conf->min_offset_diff < 0) { |
| 5842 | safepos += -conf->min_offset_diff; |
| 5843 | readpos += -conf->min_offset_diff; |
| 5844 | } else |
| 5845 | writepos += conf->min_offset_diff; |
| 5846 | |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5847 | if ((mddev->reshape_backwards |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5848 | ? (safepos > writepos && readpos < writepos) |
| 5849 | : (safepos < writepos && readpos > writepos)) || |
| 5850 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5851 | /* Cannot proceed until we've updated the superblock... */ |
| 5852 | wait_event(conf->wait_for_overlap, |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5853 | atomic_read(&conf->reshape_stripes)==0 |
| 5854 | || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 5855 | if (atomic_read(&conf->reshape_stripes) != 0) |
| 5856 | return 0; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5857 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 5858 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5859 | conf->reshape_checkpoint = jiffies; |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 5860 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5861 | md_wakeup_thread(mddev->thread); |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 5862 | wait_event(mddev->sb_wait, mddev->sb_flags == 0 || |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5863 | test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 5864 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 5865 | return 0; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5866 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5867 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5868 | spin_unlock_irq(&conf->device_lock); |
| 5869 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 5870 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5871 | } |
| 5872 | |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5873 | INIT_LIST_HEAD(&stripes); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5874 | for (i = 0; i < reshape_sectors; i += STRIPE_SECTORS) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5875 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5876 | int skipped_disk = 0; |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5877 | sh = raid5_get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5878 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 5879 | atomic_inc(&conf->reshape_stripes); |
| 5880 | /* If any of this stripe is beyond the end of the old |
| 5881 | * array, then we need to zero those blocks |
| 5882 | */ |
| 5883 | for (j=sh->disks; j--;) { |
| 5884 | sector_t s; |
| 5885 | if (j == sh->pd_idx) |
| 5886 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5887 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5888 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5889 | continue; |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5890 | s = raid5_compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5891 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5892 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5893 | continue; |
| 5894 | } |
| 5895 | memset(page_address(sh->dev[j].page), 0, STRIPE_SIZE); |
| 5896 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 5897 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 5898 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5899 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5900 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 5901 | set_bit(STRIPE_HANDLE, &sh->state); |
| 5902 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5903 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5904 | } |
| 5905 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5906 | if (mddev->reshape_backwards) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5907 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5908 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5909 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5910 | spin_unlock_irq(&conf->device_lock); |
| 5911 | /* Ok, those stripe are ready. We can start scheduling |
| 5912 | * reads on the source stripes. |
| 5913 | * The source stripes are determined by mapping the first and last |
| 5914 | * block on the destination stripes. |
| 5915 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5916 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5917 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5918 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5919 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 5920 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 5921 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5922 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5923 | if (last_sector >= mddev->dev_sectors) |
| 5924 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5925 | while (first_sector <= last_sector) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5926 | sh = raid5_get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5927 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 5928 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5929 | raid5_release_stripe(sh); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5930 | first_sector += STRIPE_SECTORS; |
| 5931 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5932 | /* Now that the sources are clearly marked, we can release |
| 5933 | * the destination stripes |
| 5934 | */ |
| 5935 | while (!list_empty(&stripes)) { |
| 5936 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 5937 | list_del_init(&sh->lru); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5938 | raid5_release_stripe(sh); |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5939 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5940 | /* If this takes us to the resync_max point where we have to pause, |
| 5941 | * then we need to write out the superblock. |
| 5942 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5943 | sector_nr += reshape_sectors; |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 5944 | retn = reshape_sectors; |
| 5945 | finish: |
NeilBrown | c5e19d9 | 2015-07-17 12:06:02 +1000 | [diff] [blame] | 5946 | if (mddev->curr_resync_completed > mddev->resync_max || |
| 5947 | (sector_nr - mddev->curr_resync_completed) * 2 |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 5948 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5949 | /* Cannot proceed until we've updated the superblock... */ |
| 5950 | wait_event(conf->wait_for_overlap, |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5951 | atomic_read(&conf->reshape_stripes) == 0 |
| 5952 | || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 5953 | if (atomic_read(&conf->reshape_stripes) != 0) |
| 5954 | goto ret; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5955 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 5956 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5957 | conf->reshape_checkpoint = jiffies; |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 5958 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5959 | md_wakeup_thread(mddev->thread); |
| 5960 | wait_event(mddev->sb_wait, |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 5961 | !test_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags) |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5962 | || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 5963 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 5964 | goto ret; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5965 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5966 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5967 | spin_unlock_irq(&conf->device_lock); |
| 5968 | wake_up(&conf->wait_for_overlap); |
NeilBrown | acb180b | 2009-04-14 16:28:34 +1000 | [diff] [blame] | 5969 | sysfs_notify(&mddev->kobj, NULL, "sync_completed"); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 5970 | } |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5971 | ret: |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 5972 | return retn; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 5975 | static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_nr, |
| 5976 | int *skipped) |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5977 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5978 | struct r5conf *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5979 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 5980 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 5981 | sector_t sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5982 | int still_degraded = 0; |
| 5983 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5984 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5985 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | /* just being told to finish up .. nothing much to do */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 5987 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 5988 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 5989 | end_reshape(conf); |
| 5990 | return 0; |
| 5991 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5992 | |
| 5993 | if (mddev->curr_resync < max_sector) /* aborted */ |
| 5994 | bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 5995 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5996 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5997 | conf->fullsync = 0; |
| 5998 | bitmap_close_sync(mddev->bitmap); |
| 5999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6000 | return 0; |
| 6001 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6002 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6003 | /* Allow raid5_quiesce to complete */ |
| 6004 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 6005 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6006 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 6007 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6008 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6009 | /* No need to check resync_max as we never do more than one |
| 6010 | * stripe, and as resync_max will always be on a chunk boundary, |
| 6011 | * if the check in md_do_sync didn't fire, there is no chance |
| 6012 | * of overstepping resync_max here |
| 6013 | */ |
| 6014 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6015 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | * to resync, then assert that we are finished, because there is |
| 6017 | * nothing we can do. |
| 6018 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 6019 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6020 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6021 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6022 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | return rv; |
| 6024 | } |
majianpeng | 6f60804 | 2013-04-24 11:42:41 +1000 | [diff] [blame] | 6025 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
| 6026 | !conf->fullsync && |
| 6027 | !bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
| 6028 | sync_blocks >= STRIPE_SECTORS) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6029 | /* we can skip this block, and probably more */ |
| 6030 | sync_blocks /= STRIPE_SECTORS; |
| 6031 | *skipped = 1; |
| 6032 | return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */ |
| 6033 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | |
Goldwyn Rodrigues | c40f341 | 2015-08-19 08:14:42 +1000 | [diff] [blame] | 6035 | bitmap_cond_end_sync(mddev->bitmap, sector_nr, false); |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 6036 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6037 | sh = raid5_get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6038 | if (sh == NULL) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6039 | sh = raid5_get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6040 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6041 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6042 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 6043 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6045 | /* Need to check if array will still be degraded after recovery/resync |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6046 | * Note in case of > 1 drive failures it's possible we're rebuilding |
| 6047 | * one drive while leaving another faulty drive in array. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6048 | */ |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6049 | rcu_read_lock(); |
| 6050 | for (i = 0; i < conf->raid_disks; i++) { |
| 6051 | struct md_rdev *rdev = ACCESS_ONCE(conf->disks[i].rdev); |
| 6052 | |
| 6053 | if (rdev == NULL || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6054 | still_degraded = 1; |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6055 | } |
| 6056 | rcu_read_unlock(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6057 | |
| 6058 | bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
| 6059 | |
NeilBrown | 83206d6 | 2011-07-26 11:19:49 +1000 | [diff] [blame] | 6060 | set_bit(STRIPE_SYNC_REQUESTED, &sh->state); |
Eivind Sarto | 053f5b6 | 2014-06-09 17:06:19 -0700 | [diff] [blame] | 6061 | set_bit(STRIPE_HANDLE, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6062 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6063 | raid5_release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6064 | |
| 6065 | return STRIPE_SECTORS; |
| 6066 | } |
| 6067 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6068 | static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6069 | { |
| 6070 | /* We may not be able to submit a whole bio at once as there |
| 6071 | * may not be enough stripe_heads available. |
| 6072 | * We cannot pre-allocate enough stripe_heads as we may need |
| 6073 | * more than exist in the cache (if we allow ever large chunks). |
| 6074 | * So we do one stripe head at a time and record in |
| 6075 | * ->bi_hw_segments how many have been done. |
| 6076 | * |
| 6077 | * We *know* that this entire raid_bio is in one chunk, so |
| 6078 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 6079 | */ |
| 6080 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6081 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6082 | sector_t sector, logical_sector, last_sector; |
| 6083 | int scnt = 0; |
| 6084 | int remaining; |
| 6085 | int handled = 0; |
| 6086 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 6087 | logical_sector = raid_bio->bi_iter.bi_sector & |
| 6088 | ~((sector_t)STRIPE_SECTORS-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6089 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6090 | 0, &dd_idx, NULL); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 6091 | last_sector = bio_end_sector(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6092 | |
| 6093 | for (; logical_sector < last_sector; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 6094 | logical_sector += STRIPE_SECTORS, |
| 6095 | sector += STRIPE_SECTORS, |
| 6096 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6097 | |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 6098 | if (scnt < raid5_bi_processed_stripes(raid_bio)) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6099 | /* already done this stripe */ |
| 6100 | continue; |
| 6101 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6102 | sh = raid5_get_active_stripe(conf, sector, 0, 1, 1); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6103 | |
| 6104 | if (!sh) { |
| 6105 | /* failed to get a stripe - must wait */ |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 6106 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6107 | conf->retry_read_aligned = raid_bio; |
| 6108 | return handled; |
| 6109 | } |
| 6110 | |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 6111 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0, 0)) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6112 | raid5_release_stripe(sh); |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 6113 | raid5_set_bi_processed_stripes(raid_bio, scnt); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 6114 | conf->retry_read_aligned = raid_bio; |
| 6115 | return handled; |
| 6116 | } |
| 6117 | |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 6118 | set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6119 | handle_stripe(sh); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6120 | raid5_release_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6121 | handled++; |
| 6122 | } |
Shaohua Li | e7836bd6 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 6123 | remaining = raid5_dec_bi_active_stripes(raid_bio); |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 6124 | if (remaining == 0) { |
| 6125 | trace_block_bio_complete(bdev_get_queue(raid_bio->bi_bdev), |
| 6126 | raid_bio, 0); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 6127 | bio_endio(raid_bio); |
Linus Torvalds | 0a82a8d | 2013-04-18 09:00:26 -0700 | [diff] [blame] | 6128 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6129 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 6130 | wake_up(&conf->wait_for_quiescent); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6131 | return handled; |
| 6132 | } |
| 6133 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 6134 | static int handle_active_stripes(struct r5conf *conf, int group, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6135 | struct r5worker *worker, |
| 6136 | struct list_head *temp_inactive_list) |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6137 | { |
| 6138 | struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6139 | int i, batch_size = 0, hash; |
| 6140 | bool release_inactive = false; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6141 | |
| 6142 | while (batch_size < MAX_STRIPE_BATCH && |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6143 | (sh = __get_priority_stripe(conf, group)) != NULL) |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6144 | batch[batch_size++] = sh; |
| 6145 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6146 | if (batch_size == 0) { |
| 6147 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 6148 | if (!list_empty(temp_inactive_list + i)) |
| 6149 | break; |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6150 | if (i == NR_STRIPE_HASH_LOCKS) { |
| 6151 | spin_unlock_irq(&conf->device_lock); |
| 6152 | r5l_flush_stripe_to_raid(conf->log); |
| 6153 | spin_lock_irq(&conf->device_lock); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6154 | return batch_size; |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6155 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6156 | release_inactive = true; |
| 6157 | } |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6158 | spin_unlock_irq(&conf->device_lock); |
| 6159 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6160 | release_inactive_stripe_list(conf, temp_inactive_list, |
| 6161 | NR_STRIPE_HASH_LOCKS); |
| 6162 | |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6163 | r5l_flush_stripe_to_raid(conf->log); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6164 | if (release_inactive) { |
| 6165 | spin_lock_irq(&conf->device_lock); |
| 6166 | return 0; |
| 6167 | } |
| 6168 | |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6169 | for (i = 0; i < batch_size; i++) |
| 6170 | handle_stripe(batch[i]); |
Shaohua Li | f6bed0e | 2015-08-13 14:31:59 -0700 | [diff] [blame] | 6171 | r5l_write_stripe_run(conf->log); |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6172 | |
| 6173 | cond_resched(); |
| 6174 | |
| 6175 | spin_lock_irq(&conf->device_lock); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6176 | for (i = 0; i < batch_size; i++) { |
| 6177 | hash = batch[i]->hash_lock_index; |
| 6178 | __release_stripe(conf, batch[i], &temp_inactive_list[hash]); |
| 6179 | } |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6180 | return batch_size; |
| 6181 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6182 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6183 | static void raid5_do_work(struct work_struct *work) |
| 6184 | { |
| 6185 | struct r5worker *worker = container_of(work, struct r5worker, work); |
| 6186 | struct r5worker_group *group = worker->group; |
| 6187 | struct r5conf *conf = group->conf; |
| 6188 | int group_id = group - conf->worker_groups; |
| 6189 | int handled; |
| 6190 | struct blk_plug plug; |
| 6191 | |
| 6192 | pr_debug("+++ raid5worker active\n"); |
| 6193 | |
| 6194 | blk_start_plug(&plug); |
| 6195 | handled = 0; |
| 6196 | spin_lock_irq(&conf->device_lock); |
| 6197 | while (1) { |
| 6198 | int batch_size, released; |
| 6199 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6200 | released = release_stripe_list(conf, worker->temp_inactive_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6201 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6202 | batch_size = handle_active_stripes(conf, group_id, worker, |
| 6203 | worker->temp_inactive_list); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 6204 | worker->working = false; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6205 | if (!batch_size && !released) |
| 6206 | break; |
| 6207 | handled += batch_size; |
| 6208 | } |
| 6209 | pr_debug("%d stripes handled\n", handled); |
| 6210 | |
| 6211 | spin_unlock_irq(&conf->device_lock); |
| 6212 | blk_finish_plug(&plug); |
| 6213 | |
| 6214 | pr_debug("--- raid5worker inactive\n"); |
| 6215 | } |
| 6216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | /* |
| 6218 | * This is our raid5 kernel thread. |
| 6219 | * |
| 6220 | * We scan the hash table for stripes which can be handled now. |
| 6221 | * During the scan, completed stripes are saved for us by the interrupt |
| 6222 | * handler, so that they will not have to wait for our next wakeup. |
| 6223 | */ |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 6224 | static void raid5d(struct md_thread *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6225 | { |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 6226 | struct mddev *mddev = thread->mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6227 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | int handled; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 6229 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6230 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 6231 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6232 | |
| 6233 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6234 | |
NeilBrown | c3cce6c | 2015-08-14 12:47:33 +1000 | [diff] [blame] | 6235 | if (!bio_list_empty(&conf->return_bi) && |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 6236 | !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) { |
NeilBrown | c3cce6c | 2015-08-14 12:47:33 +1000 | [diff] [blame] | 6237 | struct bio_list tmp = BIO_EMPTY_LIST; |
| 6238 | spin_lock_irq(&conf->device_lock); |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 6239 | if (!test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) { |
NeilBrown | c3cce6c | 2015-08-14 12:47:33 +1000 | [diff] [blame] | 6240 | bio_list_merge(&tmp, &conf->return_bi); |
| 6241 | bio_list_init(&conf->return_bi); |
| 6242 | } |
| 6243 | spin_unlock_irq(&conf->device_lock); |
| 6244 | return_io(&tmp); |
| 6245 | } |
| 6246 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 6247 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | handled = 0; |
| 6249 | spin_lock_irq(&conf->device_lock); |
| 6250 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6251 | struct bio *bio; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 6252 | int batch_size, released; |
| 6253 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6254 | released = release_stripe_list(conf, conf->temp_inactive_list); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6255 | if (released) |
| 6256 | clear_bit(R5_DID_ALLOC, &conf->cache_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 6258 | if ( |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 6259 | !list_empty(&conf->bitmap_list)) { |
| 6260 | /* Now is a good time to flush some bitmap updates */ |
| 6261 | conf->seq_flush++; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 6262 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6263 | bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 6264 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 6265 | conf->seq_write = conf->seq_flush; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6266 | activate_bit_delay(conf, conf->temp_inactive_list); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6267 | } |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 6268 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6269 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6270 | while ((bio = remove_bio_from_retry(conf))) { |
| 6271 | int ok; |
| 6272 | spin_unlock_irq(&conf->device_lock); |
| 6273 | ok = retry_aligned_read(conf, bio); |
| 6274 | spin_lock_irq(&conf->device_lock); |
| 6275 | if (!ok) |
| 6276 | break; |
| 6277 | handled++; |
| 6278 | } |
| 6279 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6280 | batch_size = handle_active_stripes(conf, ANY_GROUP, NULL, |
| 6281 | conf->temp_inactive_list); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 6282 | if (!batch_size && !released) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6283 | break; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6284 | handled += batch_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 6286 | if (mddev->sb_flags & ~(1 << MD_SB_CHANGE_PENDING)) { |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6287 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 6288 | md_check_recovery(mddev); |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6289 | spin_lock_irq(&conf->device_lock); |
| 6290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 6292 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6293 | |
| 6294 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6295 | if (test_and_clear_bit(R5_ALLOC_MORE, &conf->cache_state) && |
| 6296 | mutex_trylock(&conf->cache_size_mutex)) { |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6297 | grow_one_stripe(conf, __GFP_NOWARN); |
| 6298 | /* Set flag even if allocation failed. This helps |
| 6299 | * slow down allocation requests when mem is short |
| 6300 | */ |
| 6301 | set_bit(R5_DID_ALLOC, &conf->cache_state); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6302 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6304 | |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 6305 | flush_deferred_bios(conf); |
| 6306 | |
Shaohua Li | 0576b1c | 2015-08-13 14:32:00 -0700 | [diff] [blame] | 6307 | r5l_flush_stripe_to_raid(conf->log); |
| 6308 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 6309 | async_tx_issue_pending_all(); |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 6310 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 6312 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6313 | } |
| 6314 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6315 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6316 | raid5_show_stripe_cache_size(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6317 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6318 | struct r5conf *conf; |
| 6319 | int ret = 0; |
| 6320 | spin_lock(&mddev->lock); |
| 6321 | conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6322 | if (conf) |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6323 | ret = sprintf(page, "%d\n", conf->min_nr_stripes); |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6324 | spin_unlock(&mddev->lock); |
| 6325 | return ret; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6326 | } |
| 6327 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6328 | int |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6329 | raid5_set_cache_size(struct mddev *mddev, int size) |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6330 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6331 | struct r5conf *conf = mddev->private; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6332 | int err; |
| 6333 | |
| 6334 | if (size <= 16 || size > 32768) |
| 6335 | return -EINVAL; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6336 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6337 | conf->min_nr_stripes = size; |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6338 | mutex_lock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6339 | while (size < conf->max_nr_stripes && |
| 6340 | drop_one_stripe(conf)) |
| 6341 | ; |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6342 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6343 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6344 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6345 | err = md_allow_write(mddev); |
| 6346 | if (err) |
| 6347 | return err; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6348 | |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6349 | mutex_lock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6350 | while (size > conf->max_nr_stripes) |
| 6351 | if (!grow_one_stripe(conf, GFP_KERNEL)) |
| 6352 | break; |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6353 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6354 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6355 | return 0; |
| 6356 | } |
| 6357 | EXPORT_SYMBOL(raid5_set_cache_size); |
| 6358 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6359 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6360 | raid5_store_stripe_cache_size(struct mddev *mddev, const char *page, size_t len) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6361 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6362 | struct r5conf *conf; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 6363 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6364 | int err; |
| 6365 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6366 | if (len >= PAGE_SIZE) |
| 6367 | return -EINVAL; |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 6368 | if (kstrtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6369 | return -EINVAL; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6370 | err = mddev_lock(mddev); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6371 | if (err) |
| 6372 | return err; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6373 | conf = mddev->private; |
| 6374 | if (!conf) |
| 6375 | err = -ENODEV; |
| 6376 | else |
| 6377 | err = raid5_set_cache_size(mddev, new); |
| 6378 | mddev_unlock(mddev); |
| 6379 | |
| 6380 | return err ?: len; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6381 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 6382 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6383 | static struct md_sysfs_entry |
| 6384 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 6385 | raid5_show_stripe_cache_size, |
| 6386 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6387 | |
| 6388 | static ssize_t |
Markus Stockhausen | d06f191 | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6389 | raid5_show_rmw_level(struct mddev *mddev, char *page) |
| 6390 | { |
| 6391 | struct r5conf *conf = mddev->private; |
| 6392 | if (conf) |
| 6393 | return sprintf(page, "%d\n", conf->rmw_level); |
| 6394 | else |
| 6395 | return 0; |
| 6396 | } |
| 6397 | |
| 6398 | static ssize_t |
| 6399 | raid5_store_rmw_level(struct mddev *mddev, const char *page, size_t len) |
| 6400 | { |
| 6401 | struct r5conf *conf = mddev->private; |
| 6402 | unsigned long new; |
| 6403 | |
| 6404 | if (!conf) |
| 6405 | return -ENODEV; |
| 6406 | |
| 6407 | if (len >= PAGE_SIZE) |
| 6408 | return -EINVAL; |
| 6409 | |
| 6410 | if (kstrtoul(page, 10, &new)) |
| 6411 | return -EINVAL; |
| 6412 | |
| 6413 | if (new != PARITY_DISABLE_RMW && !raid6_call.xor_syndrome) |
| 6414 | return -EINVAL; |
| 6415 | |
| 6416 | if (new != PARITY_DISABLE_RMW && |
| 6417 | new != PARITY_ENABLE_RMW && |
| 6418 | new != PARITY_PREFER_RMW) |
| 6419 | return -EINVAL; |
| 6420 | |
| 6421 | conf->rmw_level = new; |
| 6422 | return len; |
| 6423 | } |
| 6424 | |
| 6425 | static struct md_sysfs_entry |
| 6426 | raid5_rmw_level = __ATTR(rmw_level, S_IRUGO | S_IWUSR, |
| 6427 | raid5_show_rmw_level, |
| 6428 | raid5_store_rmw_level); |
| 6429 | |
| 6430 | |
| 6431 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6432 | raid5_show_preread_threshold(struct mddev *mddev, char *page) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6433 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6434 | struct r5conf *conf; |
| 6435 | int ret = 0; |
| 6436 | spin_lock(&mddev->lock); |
| 6437 | conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6438 | if (conf) |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6439 | ret = sprintf(page, "%d\n", conf->bypass_threshold); |
| 6440 | spin_unlock(&mddev->lock); |
| 6441 | return ret; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6445 | raid5_store_preread_threshold(struct mddev *mddev, const char *page, size_t len) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6446 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6447 | struct r5conf *conf; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 6448 | unsigned long new; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6449 | int err; |
| 6450 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6451 | if (len >= PAGE_SIZE) |
| 6452 | return -EINVAL; |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 6453 | if (kstrtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6454 | return -EINVAL; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6455 | |
| 6456 | err = mddev_lock(mddev); |
| 6457 | if (err) |
| 6458 | return err; |
| 6459 | conf = mddev->private; |
| 6460 | if (!conf) |
| 6461 | err = -ENODEV; |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6462 | else if (new > conf->min_nr_stripes) |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6463 | err = -EINVAL; |
| 6464 | else |
| 6465 | conf->bypass_threshold = new; |
| 6466 | mddev_unlock(mddev); |
| 6467 | return err ?: len; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | static struct md_sysfs_entry |
| 6471 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 6472 | S_IRUGO | S_IWUSR, |
| 6473 | raid5_show_preread_threshold, |
| 6474 | raid5_store_preread_threshold); |
| 6475 | |
| 6476 | static ssize_t |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6477 | raid5_show_skip_copy(struct mddev *mddev, char *page) |
| 6478 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6479 | struct r5conf *conf; |
| 6480 | int ret = 0; |
| 6481 | spin_lock(&mddev->lock); |
| 6482 | conf = mddev->private; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6483 | if (conf) |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6484 | ret = sprintf(page, "%d\n", conf->skip_copy); |
| 6485 | spin_unlock(&mddev->lock); |
| 6486 | return ret; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | static ssize_t |
| 6490 | raid5_store_skip_copy(struct mddev *mddev, const char *page, size_t len) |
| 6491 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6492 | struct r5conf *conf; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6493 | unsigned long new; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6494 | int err; |
| 6495 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6496 | if (len >= PAGE_SIZE) |
| 6497 | return -EINVAL; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6498 | if (kstrtoul(page, 10, &new)) |
| 6499 | return -EINVAL; |
| 6500 | new = !!new; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6501 | |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6502 | err = mddev_lock(mddev); |
| 6503 | if (err) |
| 6504 | return err; |
| 6505 | conf = mddev->private; |
| 6506 | if (!conf) |
| 6507 | err = -ENODEV; |
| 6508 | else if (new != conf->skip_copy) { |
| 6509 | mddev_suspend(mddev); |
| 6510 | conf->skip_copy = new; |
| 6511 | if (new) |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 6512 | mddev->queue->backing_dev_info->capabilities |= |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6513 | BDI_CAP_STABLE_WRITES; |
| 6514 | else |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 6515 | mddev->queue->backing_dev_info->capabilities &= |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6516 | ~BDI_CAP_STABLE_WRITES; |
| 6517 | mddev_resume(mddev); |
| 6518 | } |
| 6519 | mddev_unlock(mddev); |
| 6520 | return err ?: len; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6521 | } |
| 6522 | |
| 6523 | static struct md_sysfs_entry |
| 6524 | raid5_skip_copy = __ATTR(skip_copy, S_IRUGO | S_IWUSR, |
| 6525 | raid5_show_skip_copy, |
| 6526 | raid5_store_skip_copy); |
| 6527 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6528 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6529 | stripe_cache_active_show(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6530 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6531 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6532 | if (conf) |
| 6533 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 6534 | else |
| 6535 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6536 | } |
| 6537 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6538 | static struct md_sysfs_entry |
| 6539 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6540 | |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6541 | static ssize_t |
| 6542 | raid5_show_group_thread_cnt(struct mddev *mddev, char *page) |
| 6543 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6544 | struct r5conf *conf; |
| 6545 | int ret = 0; |
| 6546 | spin_lock(&mddev->lock); |
| 6547 | conf = mddev->private; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6548 | if (conf) |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6549 | ret = sprintf(page, "%d\n", conf->worker_cnt_per_group); |
| 6550 | spin_unlock(&mddev->lock); |
| 6551 | return ret; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6552 | } |
| 6553 | |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6554 | static int alloc_thread_groups(struct r5conf *conf, int cnt, |
| 6555 | int *group_cnt, |
| 6556 | int *worker_cnt_per_group, |
| 6557 | struct r5worker_group **worker_groups); |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6558 | static ssize_t |
| 6559 | raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) |
| 6560 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6561 | struct r5conf *conf; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6562 | unsigned long new; |
| 6563 | int err; |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6564 | struct r5worker_group *new_groups, *old_groups; |
| 6565 | int group_cnt, worker_cnt_per_group; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6566 | |
| 6567 | if (len >= PAGE_SIZE) |
| 6568 | return -EINVAL; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6569 | if (kstrtoul(page, 10, &new)) |
| 6570 | return -EINVAL; |
| 6571 | |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6572 | err = mddev_lock(mddev); |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6573 | if (err) |
| 6574 | return err; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6575 | conf = mddev->private; |
| 6576 | if (!conf) |
| 6577 | err = -ENODEV; |
| 6578 | else if (new != conf->worker_cnt_per_group) { |
| 6579 | mddev_suspend(mddev); |
| 6580 | |
| 6581 | old_groups = conf->worker_groups; |
| 6582 | if (old_groups) |
| 6583 | flush_workqueue(raid5_wq); |
| 6584 | |
| 6585 | err = alloc_thread_groups(conf, new, |
| 6586 | &group_cnt, &worker_cnt_per_group, |
| 6587 | &new_groups); |
| 6588 | if (!err) { |
| 6589 | spin_lock_irq(&conf->device_lock); |
| 6590 | conf->group_cnt = group_cnt; |
| 6591 | conf->worker_cnt_per_group = worker_cnt_per_group; |
| 6592 | conf->worker_groups = new_groups; |
| 6593 | spin_unlock_irq(&conf->device_lock); |
| 6594 | |
| 6595 | if (old_groups) |
| 6596 | kfree(old_groups[0].workers); |
| 6597 | kfree(old_groups); |
| 6598 | } |
| 6599 | mddev_resume(mddev); |
| 6600 | } |
| 6601 | mddev_unlock(mddev); |
| 6602 | |
| 6603 | return err ?: len; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | static struct md_sysfs_entry |
| 6607 | raid5_group_thread_cnt = __ATTR(group_thread_cnt, S_IRUGO | S_IWUSR, |
| 6608 | raid5_show_group_thread_cnt, |
| 6609 | raid5_store_group_thread_cnt); |
| 6610 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 6611 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6612 | &raid5_stripecache_size.attr, |
| 6613 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6614 | &raid5_preread_bypass_threshold.attr, |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6615 | &raid5_group_thread_cnt.attr, |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6616 | &raid5_skip_copy.attr, |
Markus Stockhausen | d06f191 | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6617 | &raid5_rmw_level.attr, |
Song Liu | 2c7da14 | 2016-11-17 15:24:41 -0800 | [diff] [blame] | 6618 | &r5c_journal_mode.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6619 | NULL, |
| 6620 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 6621 | static struct attribute_group raid5_attrs_group = { |
| 6622 | .name = NULL, |
| 6623 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6624 | }; |
| 6625 | |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6626 | static int alloc_thread_groups(struct r5conf *conf, int cnt, |
| 6627 | int *group_cnt, |
| 6628 | int *worker_cnt_per_group, |
| 6629 | struct r5worker_group **worker_groups) |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6630 | { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6631 | int i, j, k; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6632 | ssize_t size; |
| 6633 | struct r5worker *workers; |
| 6634 | |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6635 | *worker_cnt_per_group = cnt; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6636 | if (cnt == 0) { |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6637 | *group_cnt = 0; |
| 6638 | *worker_groups = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6639 | return 0; |
| 6640 | } |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6641 | *group_cnt = num_possible_nodes(); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6642 | size = sizeof(struct r5worker) * cnt; |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6643 | workers = kzalloc(size * *group_cnt, GFP_NOIO); |
| 6644 | *worker_groups = kzalloc(sizeof(struct r5worker_group) * |
| 6645 | *group_cnt, GFP_NOIO); |
| 6646 | if (!*worker_groups || !workers) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6647 | kfree(workers); |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6648 | kfree(*worker_groups); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6649 | return -ENOMEM; |
| 6650 | } |
| 6651 | |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6652 | for (i = 0; i < *group_cnt; i++) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6653 | struct r5worker_group *group; |
| 6654 | |
NeilBrown | 0c775d5 | 2013-11-25 11:12:43 +1100 | [diff] [blame] | 6655 | group = &(*worker_groups)[i]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6656 | INIT_LIST_HEAD(&group->handle_list); |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 6657 | INIT_LIST_HEAD(&group->loprio_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6658 | group->conf = conf; |
| 6659 | group->workers = workers + i * cnt; |
| 6660 | |
| 6661 | for (j = 0; j < cnt; j++) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6662 | struct r5worker *worker = group->workers + j; |
| 6663 | worker->group = group; |
| 6664 | INIT_WORK(&worker->work, raid5_do_work); |
| 6665 | |
| 6666 | for (k = 0; k < NR_STRIPE_HASH_LOCKS; k++) |
| 6667 | INIT_LIST_HEAD(worker->temp_inactive_list + k); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6668 | } |
| 6669 | } |
| 6670 | |
| 6671 | return 0; |
| 6672 | } |
| 6673 | |
| 6674 | static void free_thread_groups(struct r5conf *conf) |
| 6675 | { |
| 6676 | if (conf->worker_groups) |
| 6677 | kfree(conf->worker_groups[0].workers); |
| 6678 | kfree(conf->worker_groups); |
| 6679 | conf->worker_groups = NULL; |
| 6680 | } |
| 6681 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6682 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6683 | raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6684 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6685 | struct r5conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6686 | |
| 6687 | if (!sectors) |
| 6688 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6689 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 6690 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6691 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6692 | |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 6693 | sectors &= ~((sector_t)conf->chunk_sectors - 1); |
| 6694 | sectors &= ~((sector_t)conf->prev_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6695 | return sectors * (raid_disks - conf->max_degraded); |
| 6696 | } |
| 6697 | |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6698 | static void free_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) |
| 6699 | { |
| 6700 | safe_put_page(percpu->spare_page); |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 6701 | if (percpu->scribble) |
| 6702 | flex_array_free(percpu->scribble); |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6703 | percpu->spare_page = NULL; |
| 6704 | percpu->scribble = NULL; |
| 6705 | } |
| 6706 | |
| 6707 | static int alloc_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) |
| 6708 | { |
| 6709 | if (conf->level == 6 && !percpu->spare_page) |
| 6710 | percpu->spare_page = alloc_page(GFP_KERNEL); |
| 6711 | if (!percpu->scribble) |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 6712 | percpu->scribble = scribble_alloc(max(conf->raid_disks, |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 6713 | conf->previous_raid_disks), |
| 6714 | max(conf->chunk_sectors, |
| 6715 | conf->prev_chunk_sectors) |
| 6716 | / STRIPE_SECTORS, |
| 6717 | GFP_KERNEL); |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6718 | |
| 6719 | if (!percpu->scribble || (conf->level == 6 && !percpu->spare_page)) { |
| 6720 | free_scratch_buffer(conf, percpu); |
| 6721 | return -ENOMEM; |
| 6722 | } |
| 6723 | |
| 6724 | return 0; |
| 6725 | } |
| 6726 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6727 | static int raid456_cpu_dead(unsigned int cpu, struct hlist_node *node) |
| 6728 | { |
| 6729 | struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); |
| 6730 | |
| 6731 | free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); |
| 6732 | return 0; |
| 6733 | } |
| 6734 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6735 | static void raid5_free_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6736 | { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6737 | if (!conf->percpu) |
| 6738 | return; |
| 6739 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6740 | cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6741 | free_percpu(conf->percpu); |
| 6742 | } |
| 6743 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6744 | static void free_conf(struct r5conf *conf) |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6745 | { |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 6746 | int i; |
| 6747 | |
Shaohua Li | 5c7e81c | 2015-08-13 14:32:04 -0700 | [diff] [blame] | 6748 | if (conf->log) |
| 6749 | r5l_exit_log(conf->log); |
Shaohua Li | 30c8946 | 2016-09-21 09:07:13 -0700 | [diff] [blame] | 6750 | if (conf->shrinker.nr_deferred) |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6751 | unregister_shrinker(&conf->shrinker); |
Shaohua Li | 5c7e81c | 2015-08-13 14:32:04 -0700 | [diff] [blame] | 6752 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6753 | free_thread_groups(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6754 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6755 | raid5_free_percpu(conf); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 6756 | for (i = 0; i < conf->pool_size; i++) |
| 6757 | if (conf->disks[i].extra_page) |
| 6758 | put_page(conf->disks[i].extra_page); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6759 | kfree(conf->disks); |
| 6760 | kfree(conf->stripe_hashtbl); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 6761 | kfree(conf->pending_data); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6762 | kfree(conf); |
| 6763 | } |
| 6764 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6765 | static int raid456_cpu_up_prepare(unsigned int cpu, struct hlist_node *node) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6766 | { |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6767 | struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6768 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 6769 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6770 | if (alloc_scratch_buffer(conf, percpu)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6771 | pr_warn("%s: failed memory allocation for cpu%u\n", |
| 6772 | __func__, cpu); |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6773 | return -ENOMEM; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6774 | } |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6775 | return 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6776 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6777 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6778 | static int raid5_alloc_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6779 | { |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6780 | int err = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6781 | |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6782 | conf->percpu = alloc_percpu(struct raid5_percpu); |
| 6783 | if (!conf->percpu) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6784 | return -ENOMEM; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6785 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6786 | err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); |
Shaohua Li | 27a353c | 2016-02-24 17:38:28 -0800 | [diff] [blame] | 6787 | if (!err) { |
| 6788 | conf->scribble_disks = max(conf->raid_disks, |
| 6789 | conf->previous_raid_disks); |
| 6790 | conf->scribble_sectors = max(conf->chunk_sectors, |
| 6791 | conf->prev_chunk_sectors); |
| 6792 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6793 | return err; |
| 6794 | } |
| 6795 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6796 | static unsigned long raid5_cache_scan(struct shrinker *shrink, |
| 6797 | struct shrink_control *sc) |
| 6798 | { |
| 6799 | struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6800 | unsigned long ret = SHRINK_STOP; |
| 6801 | |
| 6802 | if (mutex_trylock(&conf->cache_size_mutex)) { |
| 6803 | ret= 0; |
NeilBrown | 49895bc | 2015-08-03 17:09:57 +1000 | [diff] [blame] | 6804 | while (ret < sc->nr_to_scan && |
| 6805 | conf->max_nr_stripes > conf->min_nr_stripes) { |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6806 | if (drop_one_stripe(conf) == 0) { |
| 6807 | ret = SHRINK_STOP; |
| 6808 | break; |
| 6809 | } |
| 6810 | ret++; |
| 6811 | } |
| 6812 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6813 | } |
| 6814 | return ret; |
| 6815 | } |
| 6816 | |
| 6817 | static unsigned long raid5_cache_count(struct shrinker *shrink, |
| 6818 | struct shrink_control *sc) |
| 6819 | { |
| 6820 | struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); |
| 6821 | |
| 6822 | if (conf->max_nr_stripes < conf->min_nr_stripes) |
| 6823 | /* unlikely, but not impossible */ |
| 6824 | return 0; |
| 6825 | return conf->max_nr_stripes - conf->min_nr_stripes; |
| 6826 | } |
| 6827 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6828 | static struct r5conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6829 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6830 | struct r5conf *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6831 | int raid_disk, memory, max_disks; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 6832 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6833 | struct disk_info *disk; |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 6834 | char pers_name[6]; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6835 | int i; |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6836 | int group_cnt, worker_cnt_per_group; |
| 6837 | struct r5worker_group *new_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6838 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6839 | if (mddev->new_level != 5 |
| 6840 | && mddev->new_level != 4 |
| 6841 | && mddev->new_level != 6) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6842 | pr_warn("md/raid:%s: raid level not set to 4/5/6 (%d)\n", |
| 6843 | mdname(mddev), mddev->new_level); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6844 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6845 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6846 | if ((mddev->new_level == 5 |
| 6847 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 6848 | (mddev->new_level == 6 |
| 6849 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6850 | pr_warn("md/raid:%s: layout %d not supported\n", |
| 6851 | mdname(mddev), mddev->new_layout); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6852 | return ERR_PTR(-EIO); |
| 6853 | } |
| 6854 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6855 | pr_warn("md/raid:%s: not enough configured devices (%d, minimum 4)\n", |
| 6856 | mdname(mddev), mddev->raid_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6857 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6859 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 6860 | if (!mddev->new_chunk_sectors || |
| 6861 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 6862 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6863 | pr_warn("md/raid:%s: invalid chunk size %d\n", |
| 6864 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6865 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 6866 | } |
| 6867 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6868 | conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6869 | if (conf == NULL) |
| 6870 | goto abort; |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame^] | 6871 | INIT_LIST_HEAD(&conf->free_list); |
| 6872 | INIT_LIST_HEAD(&conf->pending_list); |
| 6873 | conf->pending_data = kzalloc(sizeof(struct r5pending_data) * |
| 6874 | PENDING_IO_MAX, GFP_KERNEL); |
| 6875 | if (!conf->pending_data) |
| 6876 | goto abort; |
| 6877 | for (i = 0; i < PENDING_IO_MAX; i++) |
| 6878 | list_add(&conf->pending_data[i].sibling, &conf->free_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6879 | /* Don't enable multi-threading by default*/ |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6880 | if (!alloc_thread_groups(conf, 0, &group_cnt, &worker_cnt_per_group, |
| 6881 | &new_group)) { |
| 6882 | conf->group_cnt = group_cnt; |
| 6883 | conf->worker_cnt_per_group = worker_cnt_per_group; |
| 6884 | conf->worker_groups = new_group; |
| 6885 | } else |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6886 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 6887 | spin_lock_init(&conf->device_lock); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 6888 | seqcount_init(&conf->gen_lock); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6889 | mutex_init(&conf->cache_size_mutex); |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 6890 | init_waitqueue_head(&conf->wait_for_quiescent); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 6891 | init_waitqueue_head(&conf->wait_for_stripe); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 6892 | init_waitqueue_head(&conf->wait_for_overlap); |
| 6893 | INIT_LIST_HEAD(&conf->handle_list); |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 6894 | INIT_LIST_HEAD(&conf->loprio_list); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 6895 | INIT_LIST_HEAD(&conf->hold_list); |
| 6896 | INIT_LIST_HEAD(&conf->delayed_list); |
| 6897 | INIT_LIST_HEAD(&conf->bitmap_list); |
NeilBrown | c3cce6c | 2015-08-14 12:47:33 +1000 | [diff] [blame] | 6898 | bio_list_init(&conf->return_bi); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 6899 | init_llist_head(&conf->released_stripes); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 6900 | atomic_set(&conf->active_stripes, 0); |
| 6901 | atomic_set(&conf->preread_active_stripes, 0); |
| 6902 | atomic_set(&conf->active_aligned_reads, 0); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 6903 | spin_lock_init(&conf->pending_bios_lock); |
| 6904 | conf->batch_bio_dispatch = true; |
| 6905 | rdev_for_each(rdev, mddev) { |
| 6906 | if (test_bit(Journal, &rdev->flags)) |
| 6907 | continue; |
| 6908 | if (blk_queue_nonrot(bdev_get_queue(rdev->bdev))) { |
| 6909 | conf->batch_bio_dispatch = false; |
| 6910 | break; |
| 6911 | } |
| 6912 | } |
| 6913 | |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 6914 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 6915 | conf->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6916 | |
| 6917 | conf->raid_disks = mddev->raid_disks; |
| 6918 | if (mddev->reshape_position == MaxSector) |
| 6919 | conf->previous_raid_disks = mddev->raid_disks; |
| 6920 | else |
| 6921 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6922 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6923 | |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6924 | conf->disks = kzalloc(max_disks * sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6925 | GFP_KERNEL); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 6926 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6927 | if (!conf->disks) |
| 6928 | goto abort; |
| 6929 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 6930 | for (i = 0; i < max_disks; i++) { |
| 6931 | conf->disks[i].extra_page = alloc_page(GFP_KERNEL); |
| 6932 | if (!conf->disks[i].extra_page) |
| 6933 | goto abort; |
| 6934 | } |
| 6935 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6936 | conf->mddev = mddev; |
| 6937 | |
| 6938 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 6939 | goto abort; |
| 6940 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6941 | /* We init hash_locks[0] separately to that it can be used |
| 6942 | * as the reference lock in the spin_lock_nest_lock() call |
| 6943 | * in lock_all_device_hash_locks_irq in order to convince |
| 6944 | * lockdep that we know what we are doing. |
| 6945 | */ |
| 6946 | spin_lock_init(conf->hash_locks); |
| 6947 | for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++) |
| 6948 | spin_lock_init(conf->hash_locks + i); |
| 6949 | |
| 6950 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 6951 | INIT_LIST_HEAD(conf->inactive_list + i); |
| 6952 | |
| 6953 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 6954 | INIT_LIST_HEAD(conf->temp_inactive_list + i); |
| 6955 | |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 6956 | atomic_set(&conf->r5c_cached_full_stripes, 0); |
| 6957 | INIT_LIST_HEAD(&conf->r5c_full_stripe_list); |
| 6958 | atomic_set(&conf->r5c_cached_partial_stripes, 0); |
| 6959 | INIT_LIST_HEAD(&conf->r5c_partial_stripe_list); |
Shaohua Li | e33fbb9 | 2017-02-10 16:18:09 -0800 | [diff] [blame] | 6960 | atomic_set(&conf->r5c_flushing_full_stripes, 0); |
| 6961 | atomic_set(&conf->r5c_flushing_partial_stripes, 0); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 6962 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6963 | conf->level = mddev->new_level; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 6964 | conf->chunk_sectors = mddev->new_chunk_sectors; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6965 | if (raid5_alloc_percpu(conf) != 0) |
| 6966 | goto abort; |
| 6967 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 6968 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6969 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 6970 | rdev_for_each(rdev, mddev) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6971 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6972 | if (raid_disk >= max_disks |
Shaohua Li | f2076e7 | 2015-10-08 21:54:12 -0700 | [diff] [blame] | 6973 | || raid_disk < 0 || test_bit(Journal, &rdev->flags)) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6974 | continue; |
| 6975 | disk = conf->disks + raid_disk; |
| 6976 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 6977 | if (test_bit(Replacement, &rdev->flags)) { |
| 6978 | if (disk->replacement) |
| 6979 | goto abort; |
| 6980 | disk->replacement = rdev; |
| 6981 | } else { |
| 6982 | if (disk->rdev) |
| 6983 | goto abort; |
| 6984 | disk->rdev = rdev; |
| 6985 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6986 | |
| 6987 | if (test_bit(In_sync, &rdev->flags)) { |
| 6988 | char b[BDEVNAME_SIZE]; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6989 | pr_info("md/raid:%s: device %s operational as raid disk %d\n", |
| 6990 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
Jonathan Brassow | d6b212f | 2011-06-08 18:00:28 -0500 | [diff] [blame] | 6991 | } else if (rdev->saved_raid_disk != raid_disk) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6992 | /* Cannot rely on bitmap to complete recovery */ |
| 6993 | conf->fullsync = 1; |
| 6994 | } |
| 6995 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6996 | conf->level = mddev->new_level; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6997 | if (conf->level == 6) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 6998 | conf->max_degraded = 2; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6999 | if (raid6_call.xor_syndrome) |
| 7000 | conf->rmw_level = PARITY_ENABLE_RMW; |
| 7001 | else |
| 7002 | conf->rmw_level = PARITY_DISABLE_RMW; |
| 7003 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7004 | conf->max_degraded = 1; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 7005 | conf->rmw_level = PARITY_ENABLE_RMW; |
| 7006 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7007 | conf->algorithm = mddev->new_layout; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7008 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 7009 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 7010 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 7011 | conf->prev_algo = mddev->layout; |
NeilBrown | 5cac6bc | 2015-07-17 12:17:50 +1000 | [diff] [blame] | 7012 | } else { |
| 7013 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 7014 | conf->prev_algo = conf->algorithm; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 7015 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7016 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7017 | conf->min_nr_stripes = NR_STRIPES; |
Shaohua Li | ad5b0f7 | 2016-08-30 10:29:33 -0700 | [diff] [blame] | 7018 | if (mddev->reshape_position != MaxSector) { |
| 7019 | int stripes = max_t(int, |
| 7020 | ((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4, |
| 7021 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4); |
| 7022 | conf->min_nr_stripes = max(NR_STRIPES, stripes); |
| 7023 | if (conf->min_nr_stripes != NR_STRIPES) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7024 | pr_info("md/raid:%s: force stripe size %d for reshape\n", |
Shaohua Li | ad5b0f7 | 2016-08-30 10:29:33 -0700 | [diff] [blame] | 7025 | mdname(mddev), conf->min_nr_stripes); |
| 7026 | } |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7027 | memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 7028 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 7029 | atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7030 | if (grow_stripes(conf, conf->min_nr_stripes)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7031 | pr_warn("md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 7032 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7033 | goto abort; |
| 7034 | } else |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7035 | pr_debug("md/raid:%s: allocated %dkB\n", mdname(mddev), memory); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7036 | /* |
| 7037 | * Losing a stripe head costs more than the time to refill it, |
| 7038 | * it reduces the queue depth and so can hurt throughput. |
| 7039 | * So set it rather large, scaled by number of devices. |
| 7040 | */ |
| 7041 | conf->shrinker.seeks = DEFAULT_SEEKS * conf->raid_disks * 4; |
| 7042 | conf->shrinker.scan_objects = raid5_cache_scan; |
| 7043 | conf->shrinker.count_objects = raid5_cache_count; |
| 7044 | conf->shrinker.batch = 128; |
| 7045 | conf->shrinker.flags = 0; |
Chao Yu | 6a0f53f | 2016-09-20 10:33:57 +0800 | [diff] [blame] | 7046 | if (register_shrinker(&conf->shrinker)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7047 | pr_warn("md/raid:%s: couldn't register shrinker.\n", |
| 7048 | mdname(mddev)); |
Chao Yu | 6a0f53f | 2016-09-20 10:33:57 +0800 | [diff] [blame] | 7049 | goto abort; |
| 7050 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7051 | |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 7052 | sprintf(pers_name, "raid%d", mddev->new_level); |
| 7053 | conf->thread = md_register_thread(raid5d, mddev, pers_name); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7054 | if (!conf->thread) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7055 | pr_warn("md/raid:%s: couldn't allocate thread.\n", |
| 7056 | mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7057 | goto abort; |
| 7058 | } |
| 7059 | |
| 7060 | return conf; |
| 7061 | |
| 7062 | abort: |
| 7063 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 7064 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7065 | return ERR_PTR(-EIO); |
| 7066 | } else |
| 7067 | return ERR_PTR(-ENOMEM); |
| 7068 | } |
| 7069 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7070 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 7071 | { |
| 7072 | switch (algo) { |
| 7073 | case ALGORITHM_PARITY_0: |
| 7074 | if (raid_disk < max_degraded) |
| 7075 | return 1; |
| 7076 | break; |
| 7077 | case ALGORITHM_PARITY_N: |
| 7078 | if (raid_disk >= raid_disks - max_degraded) |
| 7079 | return 1; |
| 7080 | break; |
| 7081 | case ALGORITHM_PARITY_0_6: |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 7082 | if (raid_disk == 0 || |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7083 | raid_disk == raid_disks - 1) |
| 7084 | return 1; |
| 7085 | break; |
| 7086 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 7087 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 7088 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 7089 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 7090 | if (raid_disk == raid_disks - 1) |
| 7091 | return 1; |
| 7092 | } |
| 7093 | return 0; |
| 7094 | } |
| 7095 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 7096 | static int raid5_run(struct mddev *mddev) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7097 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7098 | struct r5conf *conf; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7099 | int working_disks = 0; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7100 | int dirty_parity_disks = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 7101 | struct md_rdev *rdev; |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7102 | struct md_rdev *journal_dev = NULL; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7103 | sector_t reshape_offset = 0; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7104 | int i; |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7105 | long long min_offset_diff = 0; |
| 7106 | int first = 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7107 | |
Andre Noll | 8c6ac868 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 7108 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7109 | pr_notice("md/raid:%s: not clean -- starting background reconstruction\n", |
| 7110 | mdname(mddev)); |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7111 | |
| 7112 | rdev_for_each(rdev, mddev) { |
| 7113 | long long diff; |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7114 | |
Shaohua Li | f2076e7 | 2015-10-08 21:54:12 -0700 | [diff] [blame] | 7115 | if (test_bit(Journal, &rdev->flags)) { |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7116 | journal_dev = rdev; |
Shaohua Li | f2076e7 | 2015-10-08 21:54:12 -0700 | [diff] [blame] | 7117 | continue; |
| 7118 | } |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7119 | if (rdev->raid_disk < 0) |
| 7120 | continue; |
| 7121 | diff = (rdev->new_data_offset - rdev->data_offset); |
| 7122 | if (first) { |
| 7123 | min_offset_diff = diff; |
| 7124 | first = 0; |
| 7125 | } else if (mddev->reshape_backwards && |
| 7126 | diff < min_offset_diff) |
| 7127 | min_offset_diff = diff; |
| 7128 | else if (!mddev->reshape_backwards && |
| 7129 | diff > min_offset_diff) |
| 7130 | min_offset_diff = diff; |
| 7131 | } |
| 7132 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7133 | if (mddev->reshape_position != MaxSector) { |
| 7134 | /* Check that we can continue the reshape. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7135 | * Difficulties arise if the stripe we would write to |
| 7136 | * next is at or after the stripe we would read from next. |
| 7137 | * For a reshape that changes the number of devices, this |
| 7138 | * is only possible for a very short time, and mdadm makes |
| 7139 | * sure that time appears to have past before assembling |
| 7140 | * the array. So we fail if that time hasn't passed. |
| 7141 | * For a reshape that keeps the number of devices the same |
| 7142 | * mdadm must be monitoring the reshape can keeping the |
| 7143 | * critical areas read-only and backed up. It will start |
| 7144 | * the array in read-only mode, so we check for that. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7145 | */ |
| 7146 | sector_t here_new, here_old; |
| 7147 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 7148 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7149 | int chunk_sectors; |
| 7150 | int new_data_disks; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7151 | |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7152 | if (journal_dev) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7153 | pr_warn("md/raid:%s: don't support reshape with journal - aborting.\n", |
| 7154 | mdname(mddev)); |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7155 | return -EINVAL; |
| 7156 | } |
| 7157 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 7158 | if (mddev->new_level != mddev->level) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7159 | pr_warn("md/raid:%s: unsupported reshape required - aborting.\n", |
| 7160 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7161 | return -EINVAL; |
| 7162 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7163 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 7164 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7165 | * further up in new geometry must map after here in old |
| 7166 | * geometry. |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7167 | * If the chunk sizes are different, then as we perform reshape |
| 7168 | * in units of the largest of the two, reshape_position needs |
| 7169 | * be a multiple of the largest chunk size times new data disks. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7170 | */ |
| 7171 | here_new = mddev->reshape_position; |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7172 | chunk_sectors = max(mddev->chunk_sectors, mddev->new_chunk_sectors); |
| 7173 | new_data_disks = mddev->raid_disks - max_degraded; |
| 7174 | if (sector_div(here_new, chunk_sectors * new_data_disks)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7175 | pr_warn("md/raid:%s: reshape_position not on a stripe boundary\n", |
| 7176 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7177 | return -EINVAL; |
| 7178 | } |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7179 | reshape_offset = here_new * chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7180 | /* here_new is the stripe we will write to */ |
| 7181 | here_old = mddev->reshape_position; |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7182 | sector_div(here_old, chunk_sectors * (old_disks-max_degraded)); |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7183 | /* here_old is the first stripe that we might need to read |
| 7184 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 7185 | if (mddev->delta_disks == 0) { |
| 7186 | /* We cannot be sure it is safe to start an in-place |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7187 | * reshape. It is only safe if user-space is monitoring |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 7188 | * and taking constant backups. |
| 7189 | * mdadm always starts a situation like this in |
| 7190 | * readonly mode so it can take control before |
| 7191 | * allowing any writes. So just check for that. |
| 7192 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7193 | if (abs(min_offset_diff) >= mddev->chunk_sectors && |
| 7194 | abs(min_offset_diff) >= mddev->new_chunk_sectors) |
| 7195 | /* not really in-place - so OK */; |
| 7196 | else if (mddev->ro == 0) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7197 | pr_warn("md/raid:%s: in-place reshape must be started in read-only mode - aborting\n", |
| 7198 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 7199 | return -EINVAL; |
| 7200 | } |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7201 | } else if (mddev->reshape_backwards |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7202 | ? (here_new * chunk_sectors + min_offset_diff <= |
| 7203 | here_old * chunk_sectors) |
| 7204 | : (here_new * chunk_sectors >= |
| 7205 | here_old * chunk_sectors + (-min_offset_diff))) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7206 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7207 | pr_warn("md/raid:%s: reshape_position too early for auto-recovery - aborting.\n", |
| 7208 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7209 | return -EINVAL; |
| 7210 | } |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7211 | pr_debug("md/raid:%s: reshape will continue\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7212 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7213 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7214 | BUG_ON(mddev->level != mddev->new_level); |
| 7215 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 7216 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7217 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7218 | } |
| 7219 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7220 | if (mddev->private == NULL) |
| 7221 | conf = setup_conf(mddev); |
| 7222 | else |
| 7223 | conf = mddev->private; |
| 7224 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7225 | if (IS_ERR(conf)) |
| 7226 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 7227 | |
Song Liu | 486b0f7 | 2016-08-19 15:34:01 -0700 | [diff] [blame] | 7228 | if (test_bit(MD_HAS_JOURNAL, &mddev->flags)) { |
| 7229 | if (!journal_dev) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7230 | pr_warn("md/raid:%s: journal disk is missing, force array readonly\n", |
| 7231 | mdname(mddev)); |
Song Liu | 486b0f7 | 2016-08-19 15:34:01 -0700 | [diff] [blame] | 7232 | mddev->ro = 1; |
| 7233 | set_disk_ro(mddev->gendisk, 1); |
| 7234 | } else if (mddev->recovery_cp == MaxSector) |
| 7235 | set_bit(MD_JOURNAL_CLEAN, &mddev->flags); |
Shaohua Li | 7dde2ad | 2015-10-08 21:54:10 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7238 | conf->min_offset_diff = min_offset_diff; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7239 | mddev->thread = conf->thread; |
| 7240 | conf->thread = NULL; |
| 7241 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7242 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7243 | for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; |
| 7244 | i++) { |
| 7245 | rdev = conf->disks[i].rdev; |
| 7246 | if (!rdev && conf->disks[i].replacement) { |
| 7247 | /* The replacement is all we have yet */ |
| 7248 | rdev = conf->disks[i].replacement; |
| 7249 | conf->disks[i].replacement = NULL; |
| 7250 | clear_bit(Replacement, &rdev->flags); |
| 7251 | conf->disks[i].rdev = rdev; |
| 7252 | } |
| 7253 | if (!rdev) |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7254 | continue; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7255 | if (conf->disks[i].replacement && |
| 7256 | conf->reshape_progress != MaxSector) { |
| 7257 | /* replacements and reshape simply do not mix. */ |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7258 | pr_warn("md: cannot handle concurrent replacement and reshape.\n"); |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7259 | goto abort; |
| 7260 | } |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 7261 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7262 | working_disks++; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 7263 | continue; |
| 7264 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7265 | /* This disc is not fully in-sync. However if it |
| 7266 | * just stored parity (beyond the recovery_offset), |
| 7267 | * when we don't need to be concerned about the |
| 7268 | * array being dirty. |
| 7269 | * When reshape goes 'backwards', we never have |
| 7270 | * partially completed devices, so we only need |
| 7271 | * to worry about reshape going forwards. |
| 7272 | */ |
| 7273 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 7274 | if (mddev->major_version == 0 && |
| 7275 | mddev->minor_version > 90) |
| 7276 | rdev->recovery_offset = reshape_offset; |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 7277 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7278 | if (rdev->recovery_offset < reshape_offset) { |
| 7279 | /* We need to check old and new layout */ |
| 7280 | if (!only_parity(rdev->raid_disk, |
| 7281 | conf->algorithm, |
| 7282 | conf->raid_disks, |
| 7283 | conf->max_degraded)) |
| 7284 | continue; |
| 7285 | } |
| 7286 | if (!only_parity(rdev->raid_disk, |
| 7287 | conf->prev_algo, |
| 7288 | conf->previous_raid_disks, |
| 7289 | conf->max_degraded)) |
| 7290 | continue; |
| 7291 | dirty_parity_disks++; |
| 7292 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7293 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7294 | /* |
| 7295 | * 0 for a fully functional array, 1 or 2 for a degraded array. |
| 7296 | */ |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 7297 | mddev->degraded = raid5_calc_degraded(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7298 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 7299 | if (has_failed(conf)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7300 | pr_crit("md/raid:%s: not enough operational devices (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 7301 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7302 | goto abort; |
| 7303 | } |
| 7304 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7305 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 7306 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7307 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 7308 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7309 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7310 | mddev->recovery_cp != MaxSector) { |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7311 | if (mddev->ok_start_degraded) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7312 | pr_crit("md/raid:%s: starting dirty degraded array - data corruption possible.\n", |
| 7313 | mdname(mddev)); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7314 | else { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7315 | pr_crit("md/raid:%s: cannot start dirty degraded array.\n", |
| 7316 | mdname(mddev)); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7317 | goto abort; |
| 7318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7319 | } |
| 7320 | |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7321 | pr_info("md/raid:%s: raid level %d active with %d out of %d devices, algorithm %d\n", |
| 7322 | mdname(mddev), conf->level, |
| 7323 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 7324 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7325 | |
| 7326 | print_raid5_conf(conf); |
| 7327 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7328 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7329 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7330 | atomic_set(&conf->reshape_stripes, 0); |
| 7331 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 7332 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 7333 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 7334 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7335 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 7336 | "reshape"); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7337 | } |
| 7338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7339 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 7340 | if (mddev->to_remove == &raid5_attrs_group) |
| 7341 | mddev->to_remove = NULL; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7342 | else if (mddev->kobj.sd && |
| 7343 | sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7344 | pr_warn("raid5: failed to create sysfs attributes for %s\n", |
| 7345 | mdname(mddev)); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7346 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 7347 | |
| 7348 | if (mddev->queue) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7349 | int chunk_size; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7350 | bool discard_supported = true; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7351 | /* read-ahead size must cover two whole stripes, which |
| 7352 | * is 2 * (datadisks) * chunksize where 'n' is the |
| 7353 | * number of raid devices |
| 7354 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7355 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 7356 | int stripe = data_disks * |
| 7357 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 7358 | if (mddev->queue->backing_dev_info->ra_pages < 2 * stripe) |
| 7359 | mddev->queue->backing_dev_info->ra_pages = 2 * stripe; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7360 | |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7361 | chunk_size = mddev->chunk_sectors << 9; |
| 7362 | blk_queue_io_min(mddev->queue, chunk_size); |
| 7363 | blk_queue_io_opt(mddev->queue, chunk_size * |
| 7364 | (conf->raid_disks - conf->max_degraded)); |
Kent Overstreet | c78afc6 | 2013-07-11 22:39:53 -0700 | [diff] [blame] | 7365 | mddev->queue->limits.raid_partial_stripes_expensive = 1; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7366 | /* |
| 7367 | * We can only discard a whole stripe. It doesn't make sense to |
| 7368 | * discard data disk but write parity disk |
| 7369 | */ |
| 7370 | stripe = stripe * PAGE_SIZE; |
NeilBrown | 4ac6875 | 2012-11-19 13:11:26 +1100 | [diff] [blame] | 7371 | /* Round up to power of 2, as discard handling |
| 7372 | * currently assumes that */ |
| 7373 | while ((stripe-1) & stripe) |
| 7374 | stripe = (stripe | (stripe-1)) + 1; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7375 | mddev->queue->limits.discard_alignment = stripe; |
| 7376 | mddev->queue->limits.discard_granularity = stripe; |
Konstantin Khlebnikov | e8d7c33 | 2016-11-27 19:32:32 +0300 | [diff] [blame] | 7377 | |
| 7378 | /* |
| 7379 | * We use 16-bit counter of active stripes in bi_phys_segments |
| 7380 | * (minus one for over-loaded initialization) |
| 7381 | */ |
| 7382 | blk_queue_max_hw_sectors(mddev->queue, 0xfffe * STRIPE_SECTORS); |
| 7383 | blk_queue_max_discard_sectors(mddev->queue, |
| 7384 | 0xfffe * STRIPE_SECTORS); |
| 7385 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7386 | /* |
| 7387 | * unaligned part of discard request will be ignored, so can't |
NeilBrown | 8e0e99b | 2014-10-02 13:45:00 +1000 | [diff] [blame] | 7388 | * guarantee discard_zeroes_data |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7389 | */ |
| 7390 | mddev->queue->limits.discard_zeroes_data = 0; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7391 | |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 7392 | blk_queue_max_write_same_sectors(mddev->queue, 0); |
| 7393 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7394 | rdev_for_each(rdev, mddev) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7395 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 7396 | rdev->data_offset << 9); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7397 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 7398 | rdev->new_data_offset << 9); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7399 | /* |
| 7400 | * discard_zeroes_data is required, otherwise data |
| 7401 | * could be lost. Consider a scenario: discard a stripe |
| 7402 | * (the stripe could be inconsistent if |
| 7403 | * discard_zeroes_data is 0); write one disk of the |
| 7404 | * stripe (the stripe could be inconsistent again |
| 7405 | * depending on which disks are used to calculate |
| 7406 | * parity); the disk is broken; The stripe data of this |
| 7407 | * disk is lost. |
| 7408 | */ |
| 7409 | if (!blk_queue_discard(bdev_get_queue(rdev->bdev)) || |
| 7410 | !bdev_get_queue(rdev->bdev)-> |
| 7411 | limits.discard_zeroes_data) |
| 7412 | discard_supported = false; |
NeilBrown | 8e0e99b | 2014-10-02 13:45:00 +1000 | [diff] [blame] | 7413 | /* Unfortunately, discard_zeroes_data is not currently |
| 7414 | * a guarantee - just a hint. So we only allow DISCARD |
| 7415 | * if the sysadmin has confirmed that only safe devices |
| 7416 | * are in use by setting a module parameter. |
| 7417 | */ |
| 7418 | if (!devices_handle_discard_safely) { |
| 7419 | if (discard_supported) { |
| 7420 | pr_info("md/raid456: discard support disabled due to uncertainty.\n"); |
| 7421 | pr_info("Set raid456.devices_handle_discard_safely=Y to override.\n"); |
| 7422 | } |
| 7423 | discard_supported = false; |
| 7424 | } |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7425 | } |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7426 | |
| 7427 | if (discard_supported && |
Jes Sorensen | e7597e6 | 2016-02-16 16:44:24 -0500 | [diff] [blame] | 7428 | mddev->queue->limits.max_discard_sectors >= (stripe >> 9) && |
| 7429 | mddev->queue->limits.discard_granularity >= stripe) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7430 | queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, |
| 7431 | mddev->queue); |
| 7432 | else |
| 7433 | queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, |
| 7434 | mddev->queue); |
Shaohua Li | 1dffddd | 2016-09-08 10:49:06 -0700 | [diff] [blame] | 7435 | |
| 7436 | blk_queue_max_hw_sectors(mddev->queue, UINT_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
Shaohua Li | 5c7e81c | 2015-08-13 14:32:04 -0700 | [diff] [blame] | 7439 | if (journal_dev) { |
| 7440 | char b[BDEVNAME_SIZE]; |
| 7441 | |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7442 | pr_debug("md/raid:%s: using device %s as journal\n", |
| 7443 | mdname(mddev), bdevname(journal_dev->bdev, b)); |
Song Liu | 5aabf7c | 2016-11-17 15:24:44 -0800 | [diff] [blame] | 7444 | if (r5l_init_log(conf, journal_dev)) |
| 7445 | goto abort; |
Shaohua Li | 5c7e81c | 2015-08-13 14:32:04 -0700 | [diff] [blame] | 7446 | } |
| 7447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7448 | return 0; |
| 7449 | abort: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 7450 | md_unregister_thread(&mddev->thread); |
NeilBrown | e4f869d | 2011-10-07 14:22:49 +1100 | [diff] [blame] | 7451 | print_raid5_conf(conf); |
| 7452 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7453 | mddev->private = NULL; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7454 | pr_warn("md/raid:%s: failed to run raid set.\n", mdname(mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7455 | return -EIO; |
| 7456 | } |
| 7457 | |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 7458 | static void raid5_free(struct mddev *mddev, void *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7459 | { |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 7460 | struct r5conf *conf = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7461 | |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 7462 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 7463 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7464 | } |
| 7465 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 7466 | static void raid5_status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7467 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7468 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7469 | int i; |
| 7470 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 7471 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 7472 | conf->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 7473 | seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); |
NeilBrown | 5fd1335 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 7474 | rcu_read_lock(); |
| 7475 | for (i = 0; i < conf->raid_disks; i++) { |
| 7476 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
| 7477 | seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); |
| 7478 | } |
| 7479 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7480 | seq_printf (seq, "]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7481 | } |
| 7482 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7483 | static void print_raid5_conf (struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7484 | { |
| 7485 | int i; |
| 7486 | struct disk_info *tmp; |
| 7487 | |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7488 | pr_debug("RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7489 | if (!conf) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7490 | pr_debug("(conf==NULL)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7491 | return; |
| 7492 | } |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7493 | pr_debug(" --- level:%d rd:%d wd:%d\n", conf->level, |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 7494 | conf->raid_disks, |
| 7495 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7496 | |
| 7497 | for (i = 0; i < conf->raid_disks; i++) { |
| 7498 | char b[BDEVNAME_SIZE]; |
| 7499 | tmp = conf->disks + i; |
| 7500 | if (tmp->rdev) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7501 | pr_debug(" disk %d, o:%d, dev:%s\n", |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 7502 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 7503 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7504 | } |
| 7505 | } |
| 7506 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7507 | static int raid5_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7508 | { |
| 7509 | int i; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7510 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7511 | struct disk_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7512 | int count = 0; |
| 7513 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7514 | |
| 7515 | for (i = 0; i < conf->raid_disks; i++) { |
| 7516 | tmp = conf->disks + i; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7517 | if (tmp->replacement |
| 7518 | && tmp->replacement->recovery_offset == MaxSector |
| 7519 | && !test_bit(Faulty, &tmp->replacement->flags) |
| 7520 | && !test_and_set_bit(In_sync, &tmp->replacement->flags)) { |
| 7521 | /* Replacement has just become active. */ |
| 7522 | if (!tmp->rdev |
| 7523 | || !test_and_clear_bit(In_sync, &tmp->rdev->flags)) |
| 7524 | count++; |
| 7525 | if (tmp->rdev) { |
| 7526 | /* Replaced device not technically faulty, |
| 7527 | * but we need to be sure it gets removed |
| 7528 | * and never re-added. |
| 7529 | */ |
| 7530 | set_bit(Faulty, &tmp->rdev->flags); |
| 7531 | sysfs_notify_dirent_safe( |
| 7532 | tmp->rdev->sysfs_state); |
| 7533 | } |
| 7534 | sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); |
| 7535 | } else if (tmp->rdev |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 7536 | && tmp->rdev->recovery_offset == MaxSector |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7537 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 7538 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7539 | count++; |
Jonathan Brassow | 43c73ca | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 7540 | sysfs_notify_dirent_safe(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7541 | } |
| 7542 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7543 | spin_lock_irqsave(&conf->device_lock, flags); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 7544 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7545 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7546 | print_raid5_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7547 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7548 | } |
| 7549 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 7550 | static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7551 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7552 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7553 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 7554 | int number = rdev->raid_disk; |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7555 | struct md_rdev **rdevp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7556 | struct disk_info *p = conf->disks + number; |
| 7557 | |
| 7558 | print_raid5_conf(conf); |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7559 | if (test_bit(Journal, &rdev->flags) && conf->log) { |
| 7560 | struct r5l_log *log; |
Shaohua Li | c2bb624 | 2015-10-08 21:54:07 -0700 | [diff] [blame] | 7561 | /* |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7562 | * we can't wait pending write here, as this is called in |
| 7563 | * raid5d, wait will deadlock. |
Shaohua Li | c2bb624 | 2015-10-08 21:54:07 -0700 | [diff] [blame] | 7564 | */ |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7565 | if (atomic_read(&mddev->writes_pending)) |
| 7566 | return -EBUSY; |
| 7567 | log = conf->log; |
| 7568 | conf->log = NULL; |
| 7569 | synchronize_rcu(); |
| 7570 | r5l_exit_log(log); |
| 7571 | return 0; |
Shaohua Li | c2bb624 | 2015-10-08 21:54:07 -0700 | [diff] [blame] | 7572 | } |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7573 | if (rdev == p->rdev) |
| 7574 | rdevp = &p->rdev; |
| 7575 | else if (rdev == p->replacement) |
| 7576 | rdevp = &p->replacement; |
| 7577 | else |
| 7578 | return 0; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7579 | |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7580 | if (number >= conf->raid_disks && |
| 7581 | conf->reshape_progress == MaxSector) |
| 7582 | clear_bit(In_sync, &rdev->flags); |
| 7583 | |
| 7584 | if (test_bit(In_sync, &rdev->flags) || |
| 7585 | atomic_read(&rdev->nr_pending)) { |
| 7586 | err = -EBUSY; |
| 7587 | goto abort; |
| 7588 | } |
| 7589 | /* Only remove non-faulty devices if recovery |
| 7590 | * isn't possible. |
| 7591 | */ |
| 7592 | if (!test_bit(Faulty, &rdev->flags) && |
| 7593 | mddev->recovery_disabled != conf->recovery_disabled && |
| 7594 | !has_failed(conf) && |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7595 | (!p->replacement || p->replacement == rdev) && |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7596 | number < conf->raid_disks) { |
| 7597 | err = -EBUSY; |
| 7598 | goto abort; |
| 7599 | } |
| 7600 | *rdevp = NULL; |
NeilBrown | d787be4 | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 7601 | if (!test_bit(RemoveSynchronized, &rdev->flags)) { |
| 7602 | synchronize_rcu(); |
| 7603 | if (atomic_read(&rdev->nr_pending)) { |
| 7604 | /* lost the race, try later */ |
| 7605 | err = -EBUSY; |
| 7606 | *rdevp = rdev; |
| 7607 | } |
| 7608 | } |
| 7609 | if (p->replacement) { |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7610 | /* We must have just cleared 'rdev' */ |
| 7611 | p->rdev = p->replacement; |
| 7612 | clear_bit(Replacement, &p->replacement->flags); |
| 7613 | smp_mb(); /* Make sure other CPUs may see both as identical |
| 7614 | * but will never see neither - if they are careful |
| 7615 | */ |
| 7616 | p->replacement = NULL; |
| 7617 | clear_bit(WantReplacement, &rdev->flags); |
| 7618 | } else |
| 7619 | /* We might have just removed the Replacement as faulty- |
| 7620 | * clear the bit just in case |
| 7621 | */ |
| 7622 | clear_bit(WantReplacement, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7623 | abort: |
| 7624 | |
| 7625 | print_raid5_conf(conf); |
| 7626 | return err; |
| 7627 | } |
| 7628 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7629 | static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7630 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7631 | struct r5conf *conf = mddev->private; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7632 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7633 | int disk; |
| 7634 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 7635 | int first = 0; |
| 7636 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7637 | |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7638 | if (test_bit(Journal, &rdev->flags)) { |
| 7639 | char b[BDEVNAME_SIZE]; |
| 7640 | if (conf->log) |
| 7641 | return -EBUSY; |
| 7642 | |
| 7643 | rdev->raid_disk = 0; |
| 7644 | /* |
| 7645 | * The array is in readonly mode if journal is missing, so no |
| 7646 | * write requests running. We should be safe |
| 7647 | */ |
| 7648 | r5l_init_log(conf, rdev); |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7649 | pr_debug("md/raid:%s: using device %s as journal\n", |
| 7650 | mdname(mddev), bdevname(rdev->bdev, b)); |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7651 | return 0; |
| 7652 | } |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 7653 | if (mddev->recovery_disabled == conf->recovery_disabled) |
| 7654 | return -EBUSY; |
| 7655 | |
NeilBrown | dc10c64 | 2012-03-19 12:46:37 +1100 | [diff] [blame] | 7656 | if (rdev->saved_raid_disk < 0 && has_failed(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7657 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7658 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7659 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 7660 | if (rdev->raid_disk >= 0) |
| 7661 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7662 | |
| 7663 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7664 | * find the disk ... but prefer rdev->saved_raid_disk |
| 7665 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7666 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7667 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 7668 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7669 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7670 | first = rdev->saved_raid_disk; |
| 7671 | |
| 7672 | for (disk = first; disk <= last; disk++) { |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7673 | p = conf->disks + disk; |
| 7674 | if (p->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7675 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7676 | rdev->raid_disk = disk; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7677 | err = 0; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 7678 | if (rdev->saved_raid_disk != disk) |
| 7679 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 7680 | rcu_assign_pointer(p->rdev, rdev); |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7681 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7682 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7683 | } |
| 7684 | for (disk = first; disk <= last; disk++) { |
| 7685 | p = conf->disks + disk; |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7686 | if (test_bit(WantReplacement, &p->rdev->flags) && |
| 7687 | p->replacement == NULL) { |
| 7688 | clear_bit(In_sync, &rdev->flags); |
| 7689 | set_bit(Replacement, &rdev->flags); |
| 7690 | rdev->raid_disk = disk; |
| 7691 | err = 0; |
| 7692 | conf->fullsync = 1; |
| 7693 | rcu_assign_pointer(p->replacement, rdev); |
| 7694 | break; |
| 7695 | } |
| 7696 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7697 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7698 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7699 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7700 | } |
| 7701 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7702 | static int raid5_resize(struct mddev *mddev, sector_t sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7703 | { |
| 7704 | /* no resync is happening, and there is enough space |
| 7705 | * on all devices, so we can resize. |
| 7706 | * We need to make sure resync covers any new space. |
| 7707 | * If the array is shrinking we should possibly wait until |
| 7708 | * any io in the removed space completes, but it hardly seems |
| 7709 | * worth it. |
| 7710 | */ |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7711 | sector_t newsize; |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 7712 | struct r5conf *conf = mddev->private; |
| 7713 | |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7714 | if (conf->log) |
| 7715 | return -EINVAL; |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 7716 | sectors &= ~((sector_t)conf->chunk_sectors - 1); |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7717 | newsize = raid5_size(mddev, sectors, mddev->raid_disks); |
| 7718 | if (mddev->external_size && |
| 7719 | mddev->array_sectors > newsize) |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 7720 | return -EINVAL; |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7721 | if (mddev->bitmap) { |
| 7722 | int ret = bitmap_resize(mddev->bitmap, sectors, 0, 0); |
| 7723 | if (ret) |
| 7724 | return ret; |
| 7725 | } |
| 7726 | md_set_array_sectors(mddev, newsize); |
NeilBrown | b098636 | 2011-05-11 15:52:21 +1000 | [diff] [blame] | 7727 | if (sectors > mddev->dev_sectors && |
| 7728 | mddev->recovery_cp > mddev->dev_sectors) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 7729 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7730 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7731 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 7732 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 7733 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7734 | return 0; |
| 7735 | } |
| 7736 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7737 | static int check_stripe_cache(struct mddev *mddev) |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7738 | { |
| 7739 | /* Can only proceed if there are plenty of stripe_heads. |
| 7740 | * We need a minimum of one full stripe,, and for sensible progress |
| 7741 | * it is best to have about 4 times that. |
| 7742 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 7743 | * allow for chunk sizes up to 256K, which is probably OK. |
| 7744 | * If the chunk size is greater, user-space should request more |
| 7745 | * stripe_heads first. |
| 7746 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7747 | struct r5conf *conf = mddev->private; |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7748 | if (((mddev->chunk_sectors << 9) / STRIPE_SIZE) * 4 |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7749 | > conf->min_nr_stripes || |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7750 | ((mddev->new_chunk_sectors << 9) / STRIPE_SIZE) * 4 |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7751 | > conf->min_nr_stripes) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7752 | pr_warn("md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 7753 | mdname(mddev), |
| 7754 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
| 7755 | / STRIPE_SIZE)*4); |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7756 | return 0; |
| 7757 | } |
| 7758 | return 1; |
| 7759 | } |
| 7760 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7761 | static int check_reshape(struct mddev *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7762 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7763 | struct r5conf *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7764 | |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7765 | if (conf->log) |
| 7766 | return -EINVAL; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 7767 | if (mddev->delta_disks == 0 && |
| 7768 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 7769 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 7770 | return 0; /* nothing to do */ |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 7771 | if (has_failed(conf)) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7772 | return -EINVAL; |
NeilBrown | fdcfbbb | 2013-07-04 16:38:16 +1000 | [diff] [blame] | 7773 | if (mddev->delta_disks < 0 && mddev->reshape_position == MaxSector) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7774 | /* We might be able to shrink, but the devices must |
| 7775 | * be made bigger first. |
| 7776 | * For raid6, 4 is the minimum size. |
| 7777 | * Otherwise 2 is the minimum |
| 7778 | */ |
| 7779 | int min = 2; |
| 7780 | if (mddev->level == 6) |
| 7781 | min = 4; |
| 7782 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 7783 | return -EINVAL; |
| 7784 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7785 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7786 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7787 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7788 | |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 7789 | if (mddev->new_chunk_sectors > mddev->chunk_sectors || |
| 7790 | mddev->delta_disks > 0) |
| 7791 | if (resize_chunks(conf, |
| 7792 | conf->previous_raid_disks |
| 7793 | + max(0, mddev->delta_disks), |
| 7794 | max(mddev->new_chunk_sectors, |
| 7795 | mddev->chunk_sectors) |
| 7796 | ) < 0) |
| 7797 | return -ENOMEM; |
NeilBrown | e56108d6 | 2012-10-11 14:24:13 +1100 | [diff] [blame] | 7798 | return resize_stripes(conf, (conf->previous_raid_disks |
| 7799 | + mddev->delta_disks)); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7800 | } |
| 7801 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7802 | static int raid5_start_reshape(struct mddev *mddev) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7803 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7804 | struct r5conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 7805 | struct md_rdev *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7806 | int spares = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 7807 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7808 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7809 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7810 | return -EBUSY; |
| 7811 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7812 | if (!check_stripe_cache(mddev)) |
| 7813 | return -ENOSPC; |
| 7814 | |
NeilBrown | 30b6764 | 2012-05-22 13:55:28 +1000 | [diff] [blame] | 7815 | if (has_failed(conf)) |
| 7816 | return -EINVAL; |
| 7817 | |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7818 | rdev_for_each(rdev, mddev) { |
NeilBrown | 469518a | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7819 | if (!test_bit(In_sync, &rdev->flags) |
| 7820 | && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7821 | spares++; |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7822 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7823 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7824 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7825 | /* Not enough devices even to make a degraded array |
| 7826 | * of that size |
| 7827 | */ |
| 7828 | return -EINVAL; |
| 7829 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7830 | /* Refuse to reduce size of the array. Any reductions in |
| 7831 | * array size must be through explicit setting of array_size |
| 7832 | * attribute. |
| 7833 | */ |
| 7834 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 7835 | < mddev->array_sectors) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7836 | pr_warn("md/raid:%s: array size must be reduced before number of disks\n", |
| 7837 | mdname(mddev)); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7838 | return -EINVAL; |
| 7839 | } |
| 7840 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7841 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7842 | spin_lock_irq(&conf->device_lock); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 7843 | write_seqcount_begin(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7844 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7845 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 7846 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 7847 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 7848 | conf->prev_algo = conf->algorithm; |
| 7849 | conf->algorithm = mddev->new_layout; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7850 | conf->generation++; |
| 7851 | /* Code that selects data_offset needs to see the generation update |
| 7852 | * if reshape_progress has been set - so a memory barrier needed. |
| 7853 | */ |
| 7854 | smp_mb(); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7855 | if (mddev->reshape_backwards) |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7856 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 7857 | else |
| 7858 | conf->reshape_progress = 0; |
| 7859 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 7860 | write_seqcount_end(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7861 | spin_unlock_irq(&conf->device_lock); |
| 7862 | |
NeilBrown | 4d77e3b | 2013-08-27 15:57:47 +1000 | [diff] [blame] | 7863 | /* Now make sure any requests that proceeded on the assumption |
| 7864 | * the reshape wasn't running - like Discard or Read - have |
| 7865 | * completed. |
| 7866 | */ |
| 7867 | mddev_suspend(mddev); |
| 7868 | mddev_resume(mddev); |
| 7869 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7870 | /* Add some new drives, as many as will fit. |
| 7871 | * We know there are enough to make the newly sized array work. |
NeilBrown | 3424bf6 | 2010-06-17 17:48:26 +1000 | [diff] [blame] | 7872 | * Don't add devices if we are reducing the number of |
| 7873 | * devices in the array. This is because it is not possible |
| 7874 | * to correctly record the "partially reconstructed" state of |
| 7875 | * such devices during the reshape and confusion could result. |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7876 | */ |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7877 | if (mddev->delta_disks >= 0) { |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 7878 | rdev_for_each(rdev, mddev) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7879 | if (rdev->raid_disk < 0 && |
| 7880 | !test_bit(Faulty, &rdev->flags)) { |
| 7881 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7882 | if (rdev->raid_disk |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 7883 | >= conf->previous_raid_disks) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7884 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 7885 | else |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7886 | rdev->recovery_offset = 0; |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 7887 | |
| 7888 | if (sysfs_link_rdev(mddev, rdev)) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7889 | /* Failure here is OK */; |
NeilBrown | 50da084 | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7890 | } |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7891 | } else if (rdev->raid_disk >= conf->previous_raid_disks |
| 7892 | && !test_bit(Faulty, &rdev->flags)) { |
| 7893 | /* This is a spare that was manually added */ |
| 7894 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7895 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7896 | |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7897 | /* When a reshape changes the number of devices, |
| 7898 | * ->degraded is measured against the larger of the |
| 7899 | * pre and post number of devices. |
| 7900 | */ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7901 | spin_lock_irqsave(&conf->device_lock, flags); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 7902 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7903 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 7904 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7905 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 7906 | mddev->reshape_position = conf->reshape_progress; |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 7907 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7908 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7909 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 7910 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | ea358cd | 2015-06-12 20:05:04 +1000 | [diff] [blame] | 7911 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7912 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 7913 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7914 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 7915 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7916 | if (!mddev->sync_thread) { |
| 7917 | mddev->recovery = 0; |
| 7918 | spin_lock_irq(&conf->device_lock); |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 7919 | write_seqcount_begin(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7920 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 7921 | mddev->new_chunk_sectors = |
| 7922 | conf->chunk_sectors = conf->prev_chunk_sectors; |
| 7923 | mddev->new_layout = conf->algorithm = conf->prev_algo; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7924 | rdev_for_each(rdev, mddev) |
| 7925 | rdev->new_data_offset = rdev->data_offset; |
| 7926 | smp_wmb(); |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 7927 | conf->generation --; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7928 | conf->reshape_progress = MaxSector; |
NeilBrown | 1e3fa9b | 2012-03-13 11:21:18 +1100 | [diff] [blame] | 7929 | mddev->reshape_position = MaxSector; |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 7930 | write_seqcount_end(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7931 | spin_unlock_irq(&conf->device_lock); |
| 7932 | return -EAGAIN; |
| 7933 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 7934 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7935 | md_wakeup_thread(mddev->sync_thread); |
| 7936 | md_new_event(mddev); |
| 7937 | return 0; |
| 7938 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7939 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7940 | /* This is called from the reshape thread and should make any |
| 7941 | * changes needed in 'conf' |
| 7942 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7943 | static void end_reshape(struct r5conf *conf) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7944 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7945 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7946 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7947 | struct md_rdev *rdev; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 7948 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7949 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7950 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7951 | rdev_for_each(rdev, conf->mddev) |
| 7952 | rdev->data_offset = rdev->new_data_offset; |
| 7953 | smp_wmb(); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7954 | conf->reshape_progress = MaxSector; |
NeilBrown | 6cbd814 | 2015-07-24 13:30:32 +1000 | [diff] [blame] | 7955 | conf->mddev->reshape_position = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7956 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 7957 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7958 | |
| 7959 | /* read-ahead size must cover two whole stripes, which is |
| 7960 | * 2 * (datadisks) * chunksize where 'n' is the number of raid devices |
| 7961 | */ |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7962 | if (conf->mddev->queue) { |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7963 | int data_disks = conf->raid_disks - conf->max_degraded; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 7964 | int stripe = data_disks * ((conf->chunk_sectors << 9) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7965 | / PAGE_SIZE); |
Jan Kara | dc3b17c | 2017-02-02 15:56:50 +0100 | [diff] [blame] | 7966 | if (conf->mddev->queue->backing_dev_info->ra_pages < 2 * stripe) |
| 7967 | conf->mddev->queue->backing_dev_info->ra_pages = 2 * stripe; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7968 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7969 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7970 | } |
| 7971 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7972 | /* This is called from the raid5d thread with mddev_lock held. |
| 7973 | * It makes config changes to the device. |
| 7974 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7975 | static void raid5_finish_reshape(struct mddev *mddev) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7976 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7977 | struct r5conf *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 7978 | |
| 7979 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 7980 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7981 | if (mddev->delta_disks > 0) { |
| 7982 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
Heinz Mauelshagen | fe67d19 | 2016-05-03 22:15:31 +0200 | [diff] [blame] | 7983 | if (mddev->queue) { |
| 7984 | set_capacity(mddev->gendisk, mddev->array_sectors); |
| 7985 | revalidate_disk(mddev->gendisk); |
| 7986 | } |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7987 | } else { |
| 7988 | int d; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 7989 | spin_lock_irq(&conf->device_lock); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 7990 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 7991 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7992 | for (d = conf->raid_disks ; |
| 7993 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 7994 | d++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 7995 | struct md_rdev *rdev = conf->disks[d].rdev; |
NeilBrown | da7613b | 2012-05-22 13:55:33 +1000 | [diff] [blame] | 7996 | if (rdev) |
| 7997 | clear_bit(In_sync, &rdev->flags); |
| 7998 | rdev = conf->disks[d].replacement; |
| 7999 | if (rdev) |
| 8000 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 8001 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8002 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8003 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 8004 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8005 | mddev->reshape_position = MaxSector; |
| 8006 | mddev->delta_disks = 0; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8007 | mddev->reshape_backwards = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8008 | } |
| 8009 | } |
| 8010 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8011 | static void raid5_quiesce(struct mddev *mddev, int state) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8012 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 8013 | struct r5conf *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8014 | |
| 8015 | switch(state) { |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 8016 | case 2: /* resume for a suspend */ |
| 8017 | wake_up(&conf->wait_for_overlap); |
| 8018 | break; |
| 8019 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8020 | case 1: /* stop all writes */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8021 | lock_all_device_hash_locks_irq(conf); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8022 | /* '2' tells resync/reshape to pause so that all |
| 8023 | * active stripes can drain |
| 8024 | */ |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 8025 | r5c_flush_cache(conf, INT_MAX); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8026 | conf->quiesce = 2; |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 8027 | wait_event_cmd(conf->wait_for_quiescent, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 8028 | atomic_read(&conf->active_stripes) == 0 && |
| 8029 | atomic_read(&conf->active_aligned_reads) == 0, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8030 | unlock_all_device_hash_locks_irq(conf), |
| 8031 | lock_all_device_hash_locks_irq(conf)); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8032 | conf->quiesce = 1; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8033 | unlock_all_device_hash_locks_irq(conf); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8034 | /* allow reshape to continue */ |
| 8035 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8036 | break; |
| 8037 | |
| 8038 | case 0: /* re-enable writes */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8039 | lock_all_device_hash_locks_irq(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8040 | conf->quiesce = 0; |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 8041 | wake_up(&conf->wait_for_quiescent); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 8042 | wake_up(&conf->wait_for_overlap); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8043 | unlock_all_device_hash_locks_irq(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8044 | break; |
| 8045 | } |
Shaohua Li | e6c033f | 2015-10-04 09:20:12 -0700 | [diff] [blame] | 8046 | r5l_quiesce(conf->log, state); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8047 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 8048 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8049 | static void *raid45_takeover_raid0(struct mddev *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 8050 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 8051 | struct r0conf *raid0_conf = mddev->private; |
Randy Dunlap | d76c842 | 2011-04-21 09:07:26 -0700 | [diff] [blame] | 8052 | sector_t sectors; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 8053 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8054 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 8055 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 8056 | pr_warn("md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 8057 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8058 | return ERR_PTR(-EINVAL); |
| 8059 | } |
| 8060 | |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 8061 | sectors = raid0_conf->strip_zone[0].zone_end; |
| 8062 | sector_div(sectors, raid0_conf->strip_zone[0].nb_dev); |
NeilBrown | 3b71bd9 | 2011-04-20 15:38:18 +1000 | [diff] [blame] | 8063 | mddev->dev_sectors = sectors; |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8064 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 8065 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 8066 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 8067 | mddev->raid_disks += 1; |
| 8068 | mddev->delta_disks = 1; |
| 8069 | /* make sure it will be not marked as dirty */ |
| 8070 | mddev->recovery_cp = MaxSector; |
| 8071 | |
| 8072 | return setup_conf(mddev); |
| 8073 | } |
| 8074 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8075 | static void *raid5_takeover_raid1(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8076 | { |
| 8077 | int chunksect; |
Shaohua Li | 6995f0b | 2016-12-08 15:48:17 -0800 | [diff] [blame] | 8078 | void *ret; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8079 | |
| 8080 | if (mddev->raid_disks != 2 || |
| 8081 | mddev->degraded > 1) |
| 8082 | return ERR_PTR(-EINVAL); |
| 8083 | |
| 8084 | /* Should check if there are write-behind devices? */ |
| 8085 | |
| 8086 | chunksect = 64*2; /* 64K by default */ |
| 8087 | |
| 8088 | /* The array must be an exact multiple of chunksize */ |
| 8089 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 8090 | chunksect >>= 1; |
| 8091 | |
| 8092 | if ((chunksect<<9) < STRIPE_SIZE) |
| 8093 | /* array size does not allow a suitable chunk size */ |
| 8094 | return ERR_PTR(-EINVAL); |
| 8095 | |
| 8096 | mddev->new_level = 5; |
| 8097 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 8098 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8099 | |
Shaohua Li | 6995f0b | 2016-12-08 15:48:17 -0800 | [diff] [blame] | 8100 | ret = setup_conf(mddev); |
Jes Sorensen | 32cd7cb | 2017-01-06 19:31:35 -0500 | [diff] [blame] | 8101 | if (!IS_ERR(ret)) |
Shaohua Li | 394ed8e | 2017-01-04 16:10:19 -0800 | [diff] [blame] | 8102 | mddev_clear_unsupported_flags(mddev, |
| 8103 | UNSUPPORTED_MDDEV_FLAGS); |
Shaohua Li | 6995f0b | 2016-12-08 15:48:17 -0800 | [diff] [blame] | 8104 | return ret; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8105 | } |
| 8106 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8107 | static void *raid5_takeover_raid6(struct mddev *mddev) |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 8108 | { |
| 8109 | int new_layout; |
| 8110 | |
| 8111 | switch (mddev->layout) { |
| 8112 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 8113 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 8114 | break; |
| 8115 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 8116 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 8117 | break; |
| 8118 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 8119 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 8120 | break; |
| 8121 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 8122 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 8123 | break; |
| 8124 | case ALGORITHM_PARITY_0_6: |
| 8125 | new_layout = ALGORITHM_PARITY_0; |
| 8126 | break; |
| 8127 | case ALGORITHM_PARITY_N: |
| 8128 | new_layout = ALGORITHM_PARITY_N; |
| 8129 | break; |
| 8130 | default: |
| 8131 | return ERR_PTR(-EINVAL); |
| 8132 | } |
| 8133 | mddev->new_level = 5; |
| 8134 | mddev->new_layout = new_layout; |
| 8135 | mddev->delta_disks = -1; |
| 8136 | mddev->raid_disks -= 1; |
| 8137 | return setup_conf(mddev); |
| 8138 | } |
| 8139 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8140 | static int raid5_check_reshape(struct mddev *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8141 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8142 | /* For a 2-drive array, the layout and chunk size can be changed |
| 8143 | * immediately as not restriping is needed. |
| 8144 | * For larger arrays we record the new value - after validation |
| 8145 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8146 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 8147 | struct r5conf *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8148 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8149 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8150 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8151 | return -EINVAL; |
| 8152 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 8153 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8154 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8155 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8156 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8157 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8158 | /* not factor of array size */ |
| 8159 | return -EINVAL; |
| 8160 | } |
| 8161 | |
| 8162 | /* They look valid */ |
| 8163 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8164 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8165 | /* can make the change immediately */ |
| 8166 | if (mddev->new_layout >= 0) { |
| 8167 | conf->algorithm = mddev->new_layout; |
| 8168 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8169 | } |
| 8170 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8171 | conf->chunk_sectors = new_chunk ; |
| 8172 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8173 | } |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 8174 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8175 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8176 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8177 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8178 | } |
| 8179 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8180 | static int raid6_check_reshape(struct mddev *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8181 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8182 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8183 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8184 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8185 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8186 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 8187 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8188 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8189 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8190 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8191 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8192 | /* not factor of array size */ |
| 8193 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8194 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8195 | |
| 8196 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8197 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8198 | } |
| 8199 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8200 | static void *raid5_takeover(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8201 | { |
| 8202 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8203 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8204 | * raid1 - if there are two drives. We need to know the chunk size |
| 8205 | * raid4 - trivial - just use a raid4 layout. |
| 8206 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8207 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8208 | if (mddev->level == 0) |
| 8209 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8210 | if (mddev->level == 1) |
| 8211 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 8212 | if (mddev->level == 4) { |
| 8213 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 8214 | mddev->new_level = 5; |
| 8215 | return setup_conf(mddev); |
| 8216 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 8217 | if (mddev->level == 6) |
| 8218 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8219 | |
| 8220 | return ERR_PTR(-EINVAL); |
| 8221 | } |
| 8222 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8223 | static void *raid4_takeover(struct mddev *mddev) |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8224 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8225 | /* raid4 can take over: |
| 8226 | * raid0 - if there is only one strip zone |
| 8227 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8228 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8229 | if (mddev->level == 0) |
| 8230 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8231 | if (mddev->level == 5 && |
| 8232 | mddev->layout == ALGORITHM_PARITY_N) { |
| 8233 | mddev->new_layout = 0; |
| 8234 | mddev->new_level = 4; |
| 8235 | return setup_conf(mddev); |
| 8236 | } |
| 8237 | return ERR_PTR(-EINVAL); |
| 8238 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8239 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8240 | static struct md_personality raid5_personality; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8241 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8242 | static void *raid6_takeover(struct mddev *mddev) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8243 | { |
| 8244 | /* Currently can only take over a raid5. We map the |
| 8245 | * personality to an equivalent raid6 personality |
| 8246 | * with the Q block at the end. |
| 8247 | */ |
| 8248 | int new_layout; |
| 8249 | |
| 8250 | if (mddev->pers != &raid5_personality) |
| 8251 | return ERR_PTR(-EINVAL); |
| 8252 | if (mddev->degraded > 1) |
| 8253 | return ERR_PTR(-EINVAL); |
| 8254 | if (mddev->raid_disks > 253) |
| 8255 | return ERR_PTR(-EINVAL); |
| 8256 | if (mddev->raid_disks < 3) |
| 8257 | return ERR_PTR(-EINVAL); |
| 8258 | |
| 8259 | switch (mddev->layout) { |
| 8260 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 8261 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 8262 | break; |
| 8263 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 8264 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 8265 | break; |
| 8266 | case ALGORITHM_LEFT_SYMMETRIC: |
| 8267 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 8268 | break; |
| 8269 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 8270 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 8271 | break; |
| 8272 | case ALGORITHM_PARITY_0: |
| 8273 | new_layout = ALGORITHM_PARITY_0_6; |
| 8274 | break; |
| 8275 | case ALGORITHM_PARITY_N: |
| 8276 | new_layout = ALGORITHM_PARITY_N; |
| 8277 | break; |
| 8278 | default: |
| 8279 | return ERR_PTR(-EINVAL); |
| 8280 | } |
| 8281 | mddev->new_level = 6; |
| 8282 | mddev->new_layout = new_layout; |
| 8283 | mddev->delta_disks = 1; |
| 8284 | mddev->raid_disks += 1; |
| 8285 | return setup_conf(mddev); |
| 8286 | } |
| 8287 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8288 | static struct md_personality raid6_personality = |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8289 | { |
| 8290 | .name = "raid6", |
| 8291 | .level = 6, |
| 8292 | .owner = THIS_MODULE, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8293 | .make_request = raid5_make_request, |
| 8294 | .run = raid5_run, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 8295 | .free = raid5_free, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8296 | .status = raid5_status, |
| 8297 | .error_handler = raid5_error, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8298 | .hot_add_disk = raid5_add_disk, |
| 8299 | .hot_remove_disk= raid5_remove_disk, |
| 8300 | .spare_active = raid5_spare_active, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8301 | .sync_request = raid5_sync_request, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8302 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8303 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8304 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 8305 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8306 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8307 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8308 | .takeover = raid6_takeover, |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 8309 | .congested = raid5_congested, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8310 | }; |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8311 | static struct md_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8312 | { |
| 8313 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8314 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8315 | .owner = THIS_MODULE, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8316 | .make_request = raid5_make_request, |
| 8317 | .run = raid5_run, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 8318 | .free = raid5_free, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8319 | .status = raid5_status, |
| 8320 | .error_handler = raid5_error, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8321 | .hot_add_disk = raid5_add_disk, |
| 8322 | .hot_remove_disk= raid5_remove_disk, |
| 8323 | .spare_active = raid5_spare_active, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8324 | .sync_request = raid5_sync_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8325 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8326 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 8327 | .check_reshape = raid5_check_reshape, |
| 8328 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8329 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8330 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8331 | .takeover = raid5_takeover, |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 8332 | .congested = raid5_congested, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8333 | }; |
| 8334 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8335 | static struct md_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8336 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8337 | .name = "raid4", |
| 8338 | .level = 4, |
| 8339 | .owner = THIS_MODULE, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8340 | .make_request = raid5_make_request, |
| 8341 | .run = raid5_run, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 8342 | .free = raid5_free, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8343 | .status = raid5_status, |
| 8344 | .error_handler = raid5_error, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8345 | .hot_add_disk = raid5_add_disk, |
| 8346 | .hot_remove_disk= raid5_remove_disk, |
| 8347 | .spare_active = raid5_spare_active, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8348 | .sync_request = raid5_sync_request, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8349 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8350 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 8351 | .check_reshape = raid5_check_reshape, |
| 8352 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8353 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8354 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8355 | .takeover = raid4_takeover, |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 8356 | .congested = raid5_congested, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8357 | }; |
| 8358 | |
| 8359 | static int __init raid5_init(void) |
| 8360 | { |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 8361 | int ret; |
| 8362 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 8363 | raid5_wq = alloc_workqueue("raid5wq", |
| 8364 | WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE|WQ_SYSFS, 0); |
| 8365 | if (!raid5_wq) |
| 8366 | return -ENOMEM; |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 8367 | |
| 8368 | ret = cpuhp_setup_state_multi(CPUHP_MD_RAID5_PREPARE, |
| 8369 | "md/raid5:prepare", |
| 8370 | raid456_cpu_up_prepare, |
| 8371 | raid456_cpu_dead); |
| 8372 | if (ret) { |
| 8373 | destroy_workqueue(raid5_wq); |
| 8374 | return ret; |
| 8375 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8376 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8377 | register_md_personality(&raid5_personality); |
| 8378 | register_md_personality(&raid4_personality); |
| 8379 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8380 | } |
| 8381 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8382 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8383 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8384 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8385 | unregister_md_personality(&raid5_personality); |
| 8386 | unregister_md_personality(&raid4_personality); |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 8387 | cpuhp_remove_multi_state(CPUHP_MD_RAID5_PREPARE); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 8388 | destroy_workqueue(raid5_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8389 | } |
| 8390 | |
| 8391 | module_init(raid5_init); |
| 8392 | module_exit(raid5_exit); |
| 8393 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 8394 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8395 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 8396 | MODULE_ALIAS("md-raid5"); |
| 8397 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8398 | MODULE_ALIAS("md-level-5"); |
| 8399 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8400 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 8401 | MODULE_ALIAS("md-raid6"); |
| 8402 | MODULE_ALIAS("md-level-6"); |
| 8403 | |
| 8404 | /* This used to be two separate modules, they were: */ |
| 8405 | MODULE_ALIAS("raid5"); |
| 8406 | MODULE_ALIAS("raid6"); |