Thomas Gleixner | af1a889 | 2019-05-20 19:08:12 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * raid5.c : Multiple Devices driver for Linux |
| 4 | * Copyright (C) 1996, 1997 Ingo Molnar, Miguel de Icaza, Gadi Oxman |
| 5 | * Copyright (C) 1999, 2000 Ingo Molnar |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002, 2003 H. Peter Anvin |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8 | * RAID-4/5/6 management functions. |
| 9 | * Thanks to Penguin Computing for making the RAID-6 development possible |
| 10 | * by donating a test server! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
NeilBrown | ae3c20c | 2006-07-10 04:44:17 -0700 | [diff] [blame] | 13 | /* |
| 14 | * BITMAP UNPLUGGING: |
| 15 | * |
| 16 | * The sequencing for updating the bitmap reliably is a little |
| 17 | * subtle (and I got it wrong the first time) so it deserves some |
| 18 | * explanation. |
| 19 | * |
| 20 | * We group bitmap updates into batches. Each batch has a number. |
| 21 | * 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] | 22 | * conf->seq_write is the number of the last batch successfully written. |
| 23 | * 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] | 24 | * new additions. |
| 25 | * When we discover that we will need to write to any block in a stripe |
| 26 | * (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] | 27 | * 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] | 28 | * When we are ready to do a write, if that batch hasn't been written yet, |
| 29 | * we plug the array and queue the stripe for later. |
| 30 | * When an unplug happens, we increment bm_flush, thus closing the current |
| 31 | * batch. |
| 32 | * When we notice that bm_flush > bm_write, we write out all pending updates |
| 33 | * to the bitmap, and advance bm_write to where bm_flush was. |
| 34 | * This may occasionally write a bit out twice, but is sure never to |
| 35 | * miss any bits. |
| 36 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 38 | #include <linux/blkdev.h> |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 39 | #include <linux/kthread.h> |
Dan Williams | f701d58 | 2009-03-31 15:09:39 +1100 | [diff] [blame] | 40 | #include <linux/raid/pq.h> |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 41 | #include <linux/async_tx.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 42 | #include <linux/module.h> |
Dan Williams | 07a3b41 | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 43 | #include <linux/async.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 44 | #include <linux/seq_file.h> |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 45 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 46 | #include <linux/slab.h> |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 47 | #include <linux/ratelimit.h> |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 48 | #include <linux/nodemask.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 49 | |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 50 | #include <trace/events/block.h> |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 51 | #include <linux/list_sort.h> |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 52 | |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 53 | #include "md.h" |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 54 | #include "raid5.h" |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 55 | #include "raid0.h" |
Mike Snitzer | 935fe09 | 2017-10-10 17:02:41 -0400 | [diff] [blame] | 56 | #include "md-bitmap.h" |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 57 | #include "raid5-log.h" |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 58 | |
Shaohua Li | 394ed8e | 2017-01-04 16:10:19 -0800 | [diff] [blame] | 59 | #define UNSUPPORTED_MDDEV_FLAGS (1L << MD_FAILFAST_SUPPORTED) |
| 60 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 61 | #define cpu_to_group(cpu) cpu_to_node(cpu) |
| 62 | #define ANY_GROUP NUMA_NO_NODE |
| 63 | |
NeilBrown | 8e0e99b | 2014-10-02 13:45:00 +1000 | [diff] [blame] | 64 | static bool devices_handle_discard_safely = false; |
| 65 | module_param(devices_handle_discard_safely, bool, 0644); |
| 66 | MODULE_PARM_DESC(devices_handle_discard_safely, |
| 67 | "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] | 68 | static struct workqueue_struct *raid5_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 70 | static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect) |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 71 | { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 72 | int hash = (sect >> RAID5_STRIPE_SHIFT(conf)) & HASH_MASK; |
NeilBrown | db298e1 | 2011-10-07 14:23:00 +1100 | [diff] [blame] | 73 | return &conf->stripe_hashtbl[hash]; |
| 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 76 | static inline int stripe_hash_locks_hash(struct r5conf *conf, sector_t sect) |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 77 | { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 78 | return (sect >> RAID5_STRIPE_SHIFT(conf)) & STRIPE_HASH_LOCKS_MASK; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline void lock_device_hash_lock(struct r5conf *conf, int hash) |
| 82 | { |
| 83 | spin_lock_irq(conf->hash_locks + hash); |
| 84 | spin_lock(&conf->device_lock); |
| 85 | } |
| 86 | |
| 87 | static inline void unlock_device_hash_lock(struct r5conf *conf, int hash) |
| 88 | { |
| 89 | spin_unlock(&conf->device_lock); |
| 90 | spin_unlock_irq(conf->hash_locks + hash); |
| 91 | } |
| 92 | |
| 93 | static inline void lock_all_device_hash_locks_irq(struct r5conf *conf) |
| 94 | { |
| 95 | int i; |
Julia Cartwright | 3d05f3a | 2017-04-28 12:41:02 -0500 | [diff] [blame] | 96 | spin_lock_irq(conf->hash_locks); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 97 | for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++) |
| 98 | spin_lock_nest_lock(conf->hash_locks + i, conf->hash_locks); |
| 99 | spin_lock(&conf->device_lock); |
| 100 | } |
| 101 | |
| 102 | static inline void unlock_all_device_hash_locks_irq(struct r5conf *conf) |
| 103 | { |
| 104 | int i; |
| 105 | spin_unlock(&conf->device_lock); |
Julia Cartwright | 3d05f3a | 2017-04-28 12:41:02 -0500 | [diff] [blame] | 106 | for (i = NR_STRIPE_HASH_LOCKS - 1; i; i--) |
| 107 | spin_unlock(conf->hash_locks + i); |
| 108 | spin_unlock_irq(conf->hash_locks); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 109 | } |
| 110 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 111 | /* Find first data disk in a raid6 stripe */ |
| 112 | static inline int raid6_d0(struct stripe_head *sh) |
| 113 | { |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 114 | if (sh->ddf_layout) |
| 115 | /* ddf always start from first device */ |
| 116 | return 0; |
| 117 | /* md starts just after Q block */ |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 118 | if (sh->qd_idx == sh->disks - 1) |
| 119 | return 0; |
| 120 | else |
| 121 | return sh->qd_idx + 1; |
| 122 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 123 | static inline int raid6_next_disk(int disk, int raid_disks) |
| 124 | { |
| 125 | disk++; |
| 126 | return (disk < raid_disks) ? disk : 0; |
| 127 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 128 | |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 129 | /* When walking through the disks in a raid5, starting at raid6_d0, |
| 130 | * We need to map each disk to a 'slot', where the data disks are slot |
| 131 | * 0 .. raid_disks-3, the parity disk is raid_disks-2 and the Q disk |
| 132 | * is raid_disks-1. This help does that mapping. |
| 133 | */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 134 | static int raid6_idx_to_slot(int idx, struct stripe_head *sh, |
| 135 | int *count, int syndrome_disks) |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 136 | { |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 137 | int slot = *count; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 138 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 139 | if (sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 140 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 141 | if (idx == sh->pd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 142 | return syndrome_disks; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 143 | if (idx == sh->qd_idx) |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 144 | return syndrome_disks + 1; |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 145 | if (!sh->ddf_layout) |
Dan Williams | 6629542 | 2009-10-19 18:09:32 -0700 | [diff] [blame] | 146 | (*count)++; |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 147 | return slot; |
| 148 | } |
| 149 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 150 | static void print_raid5_conf (struct r5conf *conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 152 | static int stripe_operations_active(struct stripe_head *sh) |
| 153 | { |
| 154 | return sh->check_state || sh->reconstruct_state || |
| 155 | test_bit(STRIPE_BIOFILL_RUN, &sh->state) || |
| 156 | test_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 157 | } |
| 158 | |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 159 | static bool stripe_is_lowprio(struct stripe_head *sh) |
| 160 | { |
| 161 | return (test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) || |
| 162 | test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) && |
| 163 | !test_bit(STRIPE_R5C_CACHING, &sh->state); |
| 164 | } |
| 165 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 166 | static void raid5_wakeup_stripe_thread(struct stripe_head *sh) |
| 167 | { |
| 168 | struct r5conf *conf = sh->raid_conf; |
| 169 | struct r5worker_group *group; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 170 | int thread_cnt; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 171 | int i, cpu = sh->cpu; |
| 172 | |
| 173 | if (!cpu_online(cpu)) { |
| 174 | cpu = cpumask_any(cpu_online_mask); |
| 175 | sh->cpu = cpu; |
| 176 | } |
| 177 | |
| 178 | if (list_empty(&sh->lru)) { |
| 179 | struct r5worker_group *group; |
| 180 | group = conf->worker_groups + cpu_to_group(cpu); |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 181 | if (stripe_is_lowprio(sh)) |
| 182 | list_add_tail(&sh->lru, &group->loprio_list); |
| 183 | else |
| 184 | list_add_tail(&sh->lru, &group->handle_list); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 185 | group->stripes_cnt++; |
| 186 | sh->group = group; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | if (conf->worker_cnt_per_group == 0) { |
| 190 | md_wakeup_thread(conf->mddev->thread); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | group = conf->worker_groups + cpu_to_group(sh->cpu); |
| 195 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 196 | group->workers[0].working = true; |
| 197 | /* at least one worker should run to avoid race */ |
| 198 | queue_work_on(sh->cpu, raid5_wq, &group->workers[0].work); |
| 199 | |
| 200 | thread_cnt = group->stripes_cnt / MAX_STRIPE_BATCH - 1; |
| 201 | /* wakeup more workers */ |
| 202 | for (i = 1; i < conf->worker_cnt_per_group && thread_cnt > 0; i++) { |
| 203 | if (group->workers[i].working == false) { |
| 204 | group->workers[i].working = true; |
| 205 | queue_work_on(sh->cpu, raid5_wq, |
| 206 | &group->workers[i].work); |
| 207 | thread_cnt--; |
| 208 | } |
| 209 | } |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 210 | } |
| 211 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 212 | static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh, |
| 213 | struct list_head *temp_inactive_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 215 | int i; |
| 216 | int injournal = 0; /* number of date pages with R5_InJournal */ |
| 217 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 218 | BUG_ON(!list_empty(&sh->lru)); |
| 219 | BUG_ON(atomic_read(&conf->active_stripes)==0); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 220 | |
| 221 | if (r5c_is_writeback(conf->log)) |
| 222 | for (i = sh->disks; i--; ) |
| 223 | if (test_bit(R5_InJournal, &sh->dev[i].flags)) |
| 224 | injournal++; |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 225 | /* |
Song Liu | 5ddf044 | 2017-05-11 17:03:44 -0700 | [diff] [blame] | 226 | * In the following cases, the stripe cannot be released to cached |
| 227 | * lists. Therefore, we make the stripe write out and set |
| 228 | * STRIPE_HANDLE: |
| 229 | * 1. when quiesce in r5c write back; |
| 230 | * 2. when resync is requested fot the stripe. |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 231 | */ |
Song Liu | 5ddf044 | 2017-05-11 17:03:44 -0700 | [diff] [blame] | 232 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) || |
| 233 | (conf->quiesce && r5c_is_writeback(conf->log) && |
| 234 | !test_bit(STRIPE_HANDLE, &sh->state) && injournal != 0)) { |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 235 | if (test_bit(STRIPE_R5C_CACHING, &sh->state)) |
| 236 | r5c_make_stripe_write_out(sh); |
| 237 | set_bit(STRIPE_HANDLE, &sh->state); |
| 238 | } |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 239 | |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 240 | if (test_bit(STRIPE_HANDLE, &sh->state)) { |
| 241 | if (test_bit(STRIPE_DELAYED, &sh->state) && |
Jes Sorensen | ad3ab8b | 2015-01-29 12:38:29 -0500 | [diff] [blame] | 242 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 243 | list_add_tail(&sh->lru, &conf->delayed_list); |
Jes Sorensen | ad3ab8b | 2015-01-29 12:38:29 -0500 | [diff] [blame] | 244 | else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 245 | sh->bm_seq - conf->seq_write > 0) |
| 246 | list_add_tail(&sh->lru, &conf->bitmap_list); |
| 247 | else { |
| 248 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 249 | clear_bit(STRIPE_BIT_DELAY, &sh->state); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 250 | if (conf->worker_cnt_per_group == 0) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 251 | if (stripe_is_lowprio(sh)) |
| 252 | list_add_tail(&sh->lru, |
| 253 | &conf->loprio_list); |
| 254 | else |
| 255 | list_add_tail(&sh->lru, |
| 256 | &conf->handle_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 257 | } else { |
| 258 | raid5_wakeup_stripe_thread(sh); |
| 259 | return; |
| 260 | } |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 261 | } |
| 262 | md_wakeup_thread(conf->mddev->thread); |
| 263 | } else { |
| 264 | BUG_ON(stripe_operations_active(sh)); |
| 265 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 266 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 267 | < IO_THRESHOLD) |
| 268 | md_wakeup_thread(conf->mddev->thread); |
| 269 | atomic_dec(&conf->active_stripes); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 270 | if (!test_bit(STRIPE_EXPANDING, &sh->state)) { |
| 271 | if (!r5c_is_writeback(conf->log)) |
| 272 | list_add_tail(&sh->lru, temp_inactive_list); |
| 273 | else { |
| 274 | WARN_ON(test_bit(R5_InJournal, &sh->dev[sh->pd_idx].flags)); |
| 275 | if (injournal == 0) |
| 276 | list_add_tail(&sh->lru, temp_inactive_list); |
| 277 | else if (injournal == conf->raid_disks - conf->max_degraded) { |
| 278 | /* full stripe */ |
| 279 | if (!test_and_set_bit(STRIPE_R5C_FULL_STRIPE, &sh->state)) |
| 280 | atomic_inc(&conf->r5c_cached_full_stripes); |
| 281 | if (test_and_clear_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state)) |
| 282 | atomic_dec(&conf->r5c_cached_partial_stripes); |
| 283 | list_add_tail(&sh->lru, &conf->r5c_full_stripe_list); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 284 | r5c_check_cached_full_stripe(conf); |
Song Liu | 03b047f | 2017-01-11 13:39:14 -0800 | [diff] [blame] | 285 | } else |
| 286 | /* |
| 287 | * STRIPE_R5C_PARTIAL_STRIPE is set in |
| 288 | * r5c_try_caching_write(). No need to |
| 289 | * set it again. |
| 290 | */ |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 291 | list_add_tail(&sh->lru, &conf->r5c_partial_stripe_list); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 292 | } |
| 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 296 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 297 | static void __release_stripe(struct r5conf *conf, struct stripe_head *sh, |
| 298 | struct list_head *temp_inactive_list) |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 299 | { |
| 300 | if (atomic_dec_and_test(&sh->count)) |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 301 | do_release_stripe(conf, sh, temp_inactive_list); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * @hash could be NR_STRIPE_HASH_LOCKS, then we have a list of inactive_list |
| 306 | * |
| 307 | * Be careful: Only one task can add/delete stripes from temp_inactive_list at |
| 308 | * given time. Adding stripes only takes device lock, while deleting stripes |
| 309 | * only takes hash lock. |
| 310 | */ |
| 311 | static void release_inactive_stripe_list(struct r5conf *conf, |
| 312 | struct list_head *temp_inactive_list, |
| 313 | int hash) |
| 314 | { |
| 315 | int size; |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 316 | bool do_wakeup = false; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 317 | unsigned long flags; |
| 318 | |
| 319 | if (hash == NR_STRIPE_HASH_LOCKS) { |
| 320 | size = NR_STRIPE_HASH_LOCKS; |
| 321 | hash = NR_STRIPE_HASH_LOCKS - 1; |
| 322 | } else |
| 323 | size = 1; |
| 324 | while (size) { |
| 325 | struct list_head *list = &temp_inactive_list[size - 1]; |
| 326 | |
| 327 | /* |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 328 | * 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] | 329 | * remove stripes from the list |
| 330 | */ |
| 331 | if (!list_empty_careful(list)) { |
| 332 | spin_lock_irqsave(conf->hash_locks + hash, flags); |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 333 | if (list_empty(conf->inactive_list + hash) && |
| 334 | !list_empty(list)) |
| 335 | atomic_dec(&conf->empty_inactive_list_nr); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 336 | list_splice_tail_init(list, conf->inactive_list + hash); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 337 | do_wakeup = true; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 338 | spin_unlock_irqrestore(conf->hash_locks + hash, flags); |
| 339 | } |
| 340 | size--; |
| 341 | hash--; |
| 342 | } |
| 343 | |
| 344 | if (do_wakeup) { |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 345 | wake_up(&conf->wait_for_stripe); |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 346 | if (atomic_read(&conf->active_stripes) == 0) |
| 347 | wake_up(&conf->wait_for_quiescent); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 348 | if (conf->retry_read_aligned) |
| 349 | md_wakeup_thread(conf->mddev->thread); |
| 350 | } |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 351 | } |
| 352 | |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 353 | /* should hold conf->device_lock already */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 354 | static int release_stripe_list(struct r5conf *conf, |
| 355 | struct list_head *temp_inactive_list) |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 356 | { |
Byungchul Park | eae8263 | 2017-02-14 16:26:24 +0900 | [diff] [blame] | 357 | struct stripe_head *sh, *t; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 358 | int count = 0; |
| 359 | struct llist_node *head; |
| 360 | |
| 361 | head = llist_del_all(&conf->released_stripes); |
Shaohua Li | d265d9d | 2013-08-28 14:29:05 +0800 | [diff] [blame] | 362 | head = llist_reverse_order(head); |
Byungchul Park | eae8263 | 2017-02-14 16:26:24 +0900 | [diff] [blame] | 363 | llist_for_each_entry_safe(sh, t, head, release_list) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 364 | int hash; |
| 365 | |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 366 | /* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ |
| 367 | smp_mb(); |
| 368 | clear_bit(STRIPE_ON_RELEASE_LIST, &sh->state); |
| 369 | /* |
| 370 | * Don't worry the bit is set here, because if the bit is set |
| 371 | * again, the count is always > 1. This is true for |
| 372 | * STRIPE_ON_UNPLUG_LIST bit too. |
| 373 | */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 374 | hash = sh->hash_lock_index; |
| 375 | __release_stripe(conf, sh, &temp_inactive_list[hash]); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 376 | count++; |
| 377 | } |
| 378 | |
| 379 | return count; |
| 380 | } |
| 381 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 382 | void raid5_release_stripe(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 384 | struct r5conf *conf = sh->raid_conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | unsigned long flags; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 386 | struct list_head list; |
| 387 | int hash; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 388 | bool wakeup; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 389 | |
Eivind Sarto | cf170f3 | 2014-05-28 13:39:23 +1000 | [diff] [blame] | 390 | /* Avoid release_list until the last reference. |
| 391 | */ |
| 392 | if (atomic_add_unless(&sh->count, -1, 1)) |
| 393 | return; |
| 394 | |
majianpeng | ad4068d | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 395 | if (unlikely(!conf->mddev->thread) || |
| 396 | test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state)) |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 397 | goto slow_path; |
| 398 | wakeup = llist_add(&sh->release_list, &conf->released_stripes); |
| 399 | if (wakeup) |
| 400 | md_wakeup_thread(conf->mddev->thread); |
| 401 | return; |
| 402 | slow_path: |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 403 | /* we are ok here if STRIPE_ON_RELEASE_LIST is set or not */ |
Anna-Maria Gleixner | 685dbca | 2018-07-03 22:01:36 +0200 | [diff] [blame] | 404 | if (atomic_dec_and_lock_irqsave(&sh->count, &conf->device_lock, flags)) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 405 | INIT_LIST_HEAD(&list); |
| 406 | hash = sh->hash_lock_index; |
| 407 | do_release_stripe(conf, sh, &list); |
Anna-Maria Gleixner | 08edaaa | 2018-07-03 22:01:37 +0200 | [diff] [blame] | 408 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 409 | release_inactive_stripe_list(conf, &list, hash); |
Shaohua Li | 4eb788d | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 413 | static inline void remove_hash(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 415 | pr_debug("remove_hash(), stripe %llu\n", |
| 416 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 418 | hlist_del_init(&sh->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 421 | static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 423 | struct hlist_head *hp = stripe_hash(conf, sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 425 | pr_debug("insert_hash(), stripe %llu\n", |
| 426 | (unsigned long long)sh->sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
NeilBrown | fccddba | 2006-01-06 00:20:33 -0800 | [diff] [blame] | 428 | hlist_add_head(&sh->hash, hp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* find an idle stripe, make sure it is unhashed, and return it. */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 432 | static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
| 434 | struct stripe_head *sh = NULL; |
| 435 | struct list_head *first; |
| 436 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 437 | if (list_empty(conf->inactive_list + hash)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | goto out; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 439 | first = (conf->inactive_list + hash)->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | sh = list_entry(first, struct stripe_head, lru); |
| 441 | list_del_init(first); |
| 442 | remove_hash(sh); |
| 443 | atomic_inc(&conf->active_stripes); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 444 | BUG_ON(hash != sh->hash_lock_index); |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 445 | if (list_empty(conf->inactive_list + hash)) |
| 446 | atomic_inc(&conf->empty_inactive_list_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | out: |
| 448 | return sh; |
| 449 | } |
| 450 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 451 | static void shrink_buffers(struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
| 453 | struct page *p; |
| 454 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 455 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 457 | for (i = 0; i < num ; i++) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 458 | WARN_ON(sh->dev[i].page != sh->dev[i].orig_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | p = sh->dev[i].page; |
| 460 | if (!p) |
| 461 | continue; |
| 462 | sh->dev[i].page = NULL; |
NeilBrown | 2d1f3b5 | 2006-01-06 00:20:31 -0800 | [diff] [blame] | 463 | put_page(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
NeilBrown | a9683a7 | 2015-02-25 12:02:51 +1100 | [diff] [blame] | 467 | static int grow_buffers(struct stripe_head *sh, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | { |
| 469 | int i; |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 470 | int num = sh->raid_conf->pool_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 472 | for (i = 0; i < num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | struct page *page; |
| 474 | |
NeilBrown | a9683a7 | 2015-02-25 12:02:51 +1100 | [diff] [blame] | 475 | if (!(page = alloc_page(gfp))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | return 1; |
| 477 | } |
| 478 | sh->dev[i].page = page; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 479 | sh->dev[i].orig_page = page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 480 | sh->dev[i].offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
Artur Paszkiewicz | 3418d03 | 2017-03-09 09:59:59 +0100 | [diff] [blame] | 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 486 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 487 | struct stripe_head *sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 489 | 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] | 490 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 491 | struct r5conf *conf = sh->raid_conf; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 492 | int i, seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 494 | BUG_ON(atomic_read(&sh->count) != 0); |
| 495 | BUG_ON(test_bit(STRIPE_HANDLE, &sh->state)); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 496 | BUG_ON(stripe_operations_active(sh)); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 497 | BUG_ON(sh->batch_head); |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 498 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 499 | pr_debug("init_stripe called, stripe %llu\n", |
Markus Stockhausen | b8e6a15 | 2014-08-23 20:19:27 +1000 | [diff] [blame] | 500 | (unsigned long long)sector); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 501 | retry: |
| 502 | seq = read_seqcount_begin(&conf->gen_lock); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 503 | sh->generation = conf->generation - previous; |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 504 | sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | sh->sector = sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 506 | stripe_set_idx(sector, conf, previous, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | sh->state = 0; |
| 508 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 509 | for (i = sh->disks; i--; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | struct r5dev *dev = &sh->dev[i]; |
| 511 | |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 512 | if (dev->toread || dev->read || dev->towrite || dev->written || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | test_bit(R5_LOCKED, &dev->flags)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 514 | pr_err("sector=%llx i=%d %p %p %p %p %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | (unsigned long long)sh->sector, i, dev->toread, |
Dan Williams | d84e0f1 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 516 | dev->read, dev->towrite, dev->written, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | test_bit(R5_LOCKED, &dev->flags)); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 518 | WARN_ON(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | dev->flags = 0; |
Guoqing Jiang | 27a4ff8 | 2017-08-10 16:12:17 +0800 | [diff] [blame] | 521 | dev->sector = raid5_compute_blocknr(sh, i, previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 523 | if (read_seqcount_retry(&conf->gen_lock, seq)) |
| 524 | goto retry; |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 525 | sh->overwrite_disks = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | insert_hash(conf, sh); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 527 | sh->cpu = smp_processor_id(); |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 528 | set_bit(STRIPE_BATCH_READY, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 531 | static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector, |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 532 | short generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
| 534 | struct stripe_head *sh; |
| 535 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 536 | pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 537 | hlist_for_each_entry(sh, stripe_hash(conf, sector), hash) |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 538 | if (sh->sector == sector && sh->generation == generation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return sh; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 540 | pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | return NULL; |
| 542 | } |
| 543 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 544 | /* |
| 545 | * Need to check if array has failed when deciding whether to: |
| 546 | * - start an array |
| 547 | * - remove non-faulty devices |
| 548 | * - add a spare |
| 549 | * - allow a reshape |
| 550 | * This determination is simple when no reshape is happening. |
| 551 | * However if there is a reshape, we need to carefully check |
| 552 | * both the before and after sections. |
| 553 | * This is because some failed devices may only affect one |
| 554 | * of the two sections, and some non-in_sync devices may |
| 555 | * be insync in the section most affected by failed devices. |
| 556 | */ |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 557 | int raid5_calc_degraded(struct r5conf *conf) |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 558 | { |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 559 | int degraded, degraded2; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 560 | int i; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 561 | |
| 562 | rcu_read_lock(); |
| 563 | degraded = 0; |
| 564 | for (i = 0; i < conf->previous_raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 565 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 566 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 567 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 568 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
| 569 | degraded++; |
| 570 | else if (test_bit(In_sync, &rdev->flags)) |
| 571 | ; |
| 572 | else |
| 573 | /* not in-sync or faulty. |
| 574 | * If the reshape increases the number of devices, |
| 575 | * this is being recovered by the reshape, so |
| 576 | * this 'previous' section is not in_sync. |
| 577 | * If the number of devices is being reduced however, |
| 578 | * the device can only be part of the array if |
| 579 | * we are reverting a reshape, so this section will |
| 580 | * be in-sync. |
| 581 | */ |
| 582 | if (conf->raid_disks >= conf->previous_raid_disks) |
| 583 | degraded++; |
| 584 | } |
| 585 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 586 | if (conf->raid_disks == conf->previous_raid_disks) |
| 587 | return degraded; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 588 | rcu_read_lock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 589 | degraded2 = 0; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 590 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 591 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | e5c8647 | 2012-09-19 12:52:30 +1000 | [diff] [blame] | 592 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 593 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 594 | if (!rdev || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 595 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 596 | else if (test_bit(In_sync, &rdev->flags)) |
| 597 | ; |
| 598 | else |
| 599 | /* not in-sync or faulty. |
| 600 | * If reshape increases the number of devices, this |
| 601 | * section has already been recovered, else it |
| 602 | * almost certainly hasn't. |
| 603 | */ |
| 604 | if (conf->raid_disks <= conf->previous_raid_disks) |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 605 | degraded2++; |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 606 | } |
| 607 | rcu_read_unlock(); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 608 | if (degraded2 > degraded) |
| 609 | return degraded2; |
| 610 | return degraded; |
| 611 | } |
| 612 | |
| 613 | static int has_failed(struct r5conf *conf) |
| 614 | { |
| 615 | int degraded; |
| 616 | |
| 617 | if (conf->mddev->reshape_position == MaxSector) |
| 618 | return conf->mddev->degraded > conf->max_degraded; |
| 619 | |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 620 | degraded = raid5_calc_degraded(conf); |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 621 | if (degraded > conf->max_degraded) |
| 622 | return 1; |
| 623 | return 0; |
| 624 | } |
| 625 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 626 | struct stripe_head * |
| 627 | raid5_get_active_stripe(struct r5conf *conf, sector_t sector, |
| 628 | int previous, int noblock, int noquiesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
| 630 | struct stripe_head *sh; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 631 | int hash = stripe_hash_locks_hash(conf, sector); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 632 | int inc_empty_inactive_list_flag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 634 | pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 636 | spin_lock_irq(conf->hash_locks + hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
| 638 | do { |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 639 | wait_event_lock_irq(conf->wait_for_quiescent, |
NeilBrown | a8c906c | 2009-06-09 14:39:59 +1000 | [diff] [blame] | 640 | conf->quiesce == 0 || noquiesce, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 641 | *(conf->hash_locks + hash)); |
NeilBrown | 86b42c7 | 2009-03-31 15:19:03 +1100 | [diff] [blame] | 642 | sh = __find_stripe(conf, sector, conf->generation - previous); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | if (!sh) { |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 644 | if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 645 | sh = get_free_stripe(conf, hash); |
Shaohua Li | 713bc5c | 2015-05-28 17:33:47 -0700 | [diff] [blame] | 646 | if (!sh && !test_bit(R5_DID_ALLOC, |
| 647 | &conf->cache_state)) |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 648 | set_bit(R5_ALLOC_MORE, |
| 649 | &conf->cache_state); |
| 650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | if (noblock && sh == NULL) |
| 652 | break; |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 653 | |
| 654 | r5c_check_stripe_cache_usage(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | if (!sh) { |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 656 | set_bit(R5_INACTIVE_BLOCKED, |
| 657 | &conf->cache_state); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 658 | r5l_wake_reclaim(conf->log, 0); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 659 | wait_event_lock_irq( |
| 660 | conf->wait_for_stripe, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 661 | !list_empty(conf->inactive_list + hash) && |
| 662 | (atomic_read(&conf->active_stripes) |
| 663 | < (conf->max_nr_stripes * 3 / 4) |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 664 | || !test_bit(R5_INACTIVE_BLOCKED, |
| 665 | &conf->cache_state)), |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 666 | *(conf->hash_locks + hash)); |
NeilBrown | 5423399 | 2015-02-26 12:21:04 +1100 | [diff] [blame] | 667 | clear_bit(R5_INACTIVE_BLOCKED, |
| 668 | &conf->cache_state); |
NeilBrown | 7da9d45 | 2014-01-22 11:45:03 +1100 | [diff] [blame] | 669 | } else { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 670 | init_stripe(sh, sector, previous); |
NeilBrown | 7da9d45 | 2014-01-22 11:45:03 +1100 | [diff] [blame] | 671 | atomic_inc(&sh->count); |
| 672 | } |
Shaohua Li | e240c18 | 2014-04-09 11:27:42 +0800 | [diff] [blame] | 673 | } else if (!atomic_inc_not_zero(&sh->count)) { |
NeilBrown | 6d183de | 2013-11-28 10:55:27 +1100 | [diff] [blame] | 674 | spin_lock(&conf->device_lock); |
Shaohua Li | e240c18 | 2014-04-09 11:27:42 +0800 | [diff] [blame] | 675 | if (!atomic_read(&sh->count)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | if (!test_bit(STRIPE_HANDLE, &sh->state)) |
| 677 | atomic_inc(&conf->active_stripes); |
NeilBrown | 5af9bef | 2014-01-14 15:16:10 +1100 | [diff] [blame] | 678 | BUG_ON(list_empty(&sh->lru) && |
| 679 | !test_bit(STRIPE_EXPANDING, &sh->state)); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 680 | inc_empty_inactive_list_flag = 0; |
| 681 | if (!list_empty(conf->inactive_list + hash)) |
| 682 | inc_empty_inactive_list_flag = 1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 683 | list_del_init(&sh->lru); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 684 | if (list_empty(conf->inactive_list + hash) && inc_empty_inactive_list_flag) |
| 685 | atomic_inc(&conf->empty_inactive_list_nr); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 686 | if (sh->group) { |
| 687 | sh->group->stripes_cnt--; |
| 688 | sh->group = NULL; |
| 689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | } |
NeilBrown | 7da9d45 | 2014-01-22 11:45:03 +1100 | [diff] [blame] | 691 | atomic_inc(&sh->count); |
NeilBrown | 6d183de | 2013-11-28 10:55:27 +1100 | [diff] [blame] | 692 | spin_unlock(&conf->device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | } while (sh == NULL); |
| 695 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 696 | spin_unlock_irq(conf->hash_locks + hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | return sh; |
| 698 | } |
| 699 | |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 700 | static bool is_full_stripe_write(struct stripe_head *sh) |
| 701 | { |
| 702 | BUG_ON(sh->overwrite_disks > (sh->disks - sh->raid_conf->max_degraded)); |
| 703 | return sh->overwrite_disks == (sh->disks - sh->raid_conf->max_degraded); |
| 704 | } |
| 705 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 706 | static void lock_two_stripes(struct stripe_head *sh1, struct stripe_head *sh2) |
Christoph Hellwig | 368ecad | 2019-04-04 18:56:15 +0200 | [diff] [blame] | 707 | __acquires(&sh1->stripe_lock) |
| 708 | __acquires(&sh2->stripe_lock) |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 709 | { |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 710 | if (sh1 > sh2) { |
Julia Cartwright | 3d05f3a | 2017-04-28 12:41:02 -0500 | [diff] [blame] | 711 | spin_lock_irq(&sh2->stripe_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 712 | spin_lock_nested(&sh1->stripe_lock, 1); |
| 713 | } else { |
Julia Cartwright | 3d05f3a | 2017-04-28 12:41:02 -0500 | [diff] [blame] | 714 | spin_lock_irq(&sh1->stripe_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 715 | spin_lock_nested(&sh2->stripe_lock, 1); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | static void unlock_two_stripes(struct stripe_head *sh1, struct stripe_head *sh2) |
Christoph Hellwig | 368ecad | 2019-04-04 18:56:15 +0200 | [diff] [blame] | 720 | __releases(&sh1->stripe_lock) |
| 721 | __releases(&sh2->stripe_lock) |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 722 | { |
| 723 | spin_unlock(&sh1->stripe_lock); |
Julia Cartwright | 3d05f3a | 2017-04-28 12:41:02 -0500 | [diff] [blame] | 724 | spin_unlock_irq(&sh2->stripe_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /* Only freshly new full stripe normal write stripe can be added to a batch list */ |
| 728 | static bool stripe_can_batch(struct stripe_head *sh) |
| 729 | { |
Shaohua Li | 9c3e333 | 2015-08-13 14:32:02 -0700 | [diff] [blame] | 730 | struct r5conf *conf = sh->raid_conf; |
| 731 | |
Shaohua Li | e254de6 | 2018-08-29 11:05:42 -0700 | [diff] [blame] | 732 | if (raid5_has_log(conf) || raid5_has_ppl(conf)) |
Shaohua Li | 9c3e333 | 2015-08-13 14:32:02 -0700 | [diff] [blame] | 733 | return false; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 734 | return test_bit(STRIPE_BATCH_READY, &sh->state) && |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 735 | !test_bit(STRIPE_BITMAP_PENDING, &sh->state) && |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 736 | is_full_stripe_write(sh); |
| 737 | } |
| 738 | |
| 739 | /* we only do back search */ |
| 740 | static void stripe_add_to_batch_list(struct r5conf *conf, struct stripe_head *sh) |
| 741 | { |
| 742 | struct stripe_head *head; |
| 743 | sector_t head_sector, tmp_sec; |
| 744 | int hash; |
| 745 | int dd_idx; |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 746 | int inc_empty_inactive_list_flag; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 747 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 748 | /* Don't cross chunks, so stripe pd_idx/qd_idx is the same */ |
| 749 | tmp_sec = sh->sector; |
| 750 | if (!sector_div(tmp_sec, conf->chunk_sectors)) |
| 751 | return; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 752 | head_sector = sh->sector - RAID5_STRIPE_SECTORS(conf); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 753 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 754 | hash = stripe_hash_locks_hash(conf, head_sector); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 755 | spin_lock_irq(conf->hash_locks + hash); |
| 756 | head = __find_stripe(conf, head_sector, conf->generation); |
| 757 | if (head && !atomic_inc_not_zero(&head->count)) { |
| 758 | spin_lock(&conf->device_lock); |
| 759 | if (!atomic_read(&head->count)) { |
| 760 | if (!test_bit(STRIPE_HANDLE, &head->state)) |
| 761 | atomic_inc(&conf->active_stripes); |
| 762 | BUG_ON(list_empty(&head->lru) && |
| 763 | !test_bit(STRIPE_EXPANDING, &head->state)); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 764 | inc_empty_inactive_list_flag = 0; |
| 765 | if (!list_empty(conf->inactive_list + hash)) |
| 766 | inc_empty_inactive_list_flag = 1; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 767 | list_del_init(&head->lru); |
ZhengYuan Liu | ff00d3b | 2016-07-28 14:22:14 +0800 | [diff] [blame] | 768 | if (list_empty(conf->inactive_list + hash) && inc_empty_inactive_list_flag) |
| 769 | atomic_inc(&conf->empty_inactive_list_nr); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 770 | if (head->group) { |
| 771 | head->group->stripes_cnt--; |
| 772 | head->group = NULL; |
| 773 | } |
| 774 | } |
| 775 | atomic_inc(&head->count); |
| 776 | spin_unlock(&conf->device_lock); |
| 777 | } |
| 778 | spin_unlock_irq(conf->hash_locks + hash); |
| 779 | |
| 780 | if (!head) |
| 781 | return; |
| 782 | if (!stripe_can_batch(head)) |
| 783 | goto out; |
| 784 | |
| 785 | lock_two_stripes(head, sh); |
| 786 | /* clear_batch_ready clear the flag */ |
| 787 | if (!stripe_can_batch(head) || !stripe_can_batch(sh)) |
| 788 | goto unlock_out; |
| 789 | |
| 790 | if (sh->batch_head) |
| 791 | goto unlock_out; |
| 792 | |
| 793 | dd_idx = 0; |
| 794 | while (dd_idx == sh->pd_idx || dd_idx == sh->qd_idx) |
| 795 | dd_idx++; |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 796 | 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] | 797 | 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] | 798 | goto unlock_out; |
| 799 | |
| 800 | if (head->batch_head) { |
| 801 | spin_lock(&head->batch_head->batch_lock); |
| 802 | /* This batch list is already running */ |
| 803 | if (!stripe_can_batch(head)) { |
| 804 | spin_unlock(&head->batch_head->batch_lock); |
| 805 | goto unlock_out; |
| 806 | } |
Shaohua Li | 3664847 | 2017-08-25 10:40:02 -0700 | [diff] [blame] | 807 | /* |
| 808 | * We must assign batch_head of this stripe within the |
| 809 | * batch_lock, otherwise clear_batch_ready of batch head |
| 810 | * stripe could clear BATCH_READY bit of this stripe and |
| 811 | * this stripe->batch_head doesn't get assigned, which |
| 812 | * could confuse clear_batch_ready for this stripe |
| 813 | */ |
| 814 | sh->batch_head = head->batch_head; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 815 | |
| 816 | /* |
| 817 | * at this point, head's BATCH_READY could be cleared, but we |
| 818 | * can still add the stripe to batch list |
| 819 | */ |
| 820 | list_add(&sh->batch_list, &head->batch_list); |
| 821 | spin_unlock(&head->batch_head->batch_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 822 | } else { |
| 823 | head->batch_head = head; |
| 824 | sh->batch_head = head->batch_head; |
| 825 | spin_lock(&head->batch_lock); |
| 826 | list_add_tail(&sh->batch_list, &head->batch_list); |
| 827 | spin_unlock(&head->batch_lock); |
| 828 | } |
| 829 | |
| 830 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 831 | if (atomic_dec_return(&conf->preread_active_stripes) |
| 832 | < IO_THRESHOLD) |
| 833 | md_wakeup_thread(conf->mddev->thread); |
| 834 | |
NeilBrown | 2b6b245 | 2015-05-21 15:10:01 +1000 | [diff] [blame] | 835 | if (test_and_clear_bit(STRIPE_BIT_DELAY, &sh->state)) { |
| 836 | int seq = sh->bm_seq; |
| 837 | if (test_bit(STRIPE_BIT_DELAY, &sh->batch_head->state) && |
| 838 | sh->batch_head->bm_seq > seq) |
| 839 | seq = sh->batch_head->bm_seq; |
| 840 | set_bit(STRIPE_BIT_DELAY, &sh->batch_head->state); |
| 841 | sh->batch_head->bm_seq = seq; |
| 842 | } |
| 843 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 844 | atomic_inc(&sh->count); |
| 845 | unlock_out: |
| 846 | unlock_two_stripes(head, sh); |
| 847 | out: |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 848 | raid5_release_stripe(head); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 849 | } |
| 850 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 851 | /* Determine if 'data_offset' or 'new_data_offset' should be used |
| 852 | * in this stripe_head. |
| 853 | */ |
| 854 | static int use_new_offset(struct r5conf *conf, struct stripe_head *sh) |
| 855 | { |
| 856 | sector_t progress = conf->reshape_progress; |
| 857 | /* Need a memory barrier to make sure we see the value |
| 858 | * of conf->generation, or ->data_offset that was set before |
| 859 | * reshape_progress was updated. |
| 860 | */ |
| 861 | smp_rmb(); |
| 862 | if (progress == MaxSector) |
| 863 | return 0; |
| 864 | if (sh->generation == conf->generation - 1) |
| 865 | return 0; |
| 866 | /* We are in a reshape, and this is a new-generation stripe, |
| 867 | * so use new_data_offset. |
| 868 | */ |
| 869 | return 1; |
| 870 | } |
| 871 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 872 | static void dispatch_bio_list(struct bio_list *tmp) |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 873 | { |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 874 | struct bio *bio; |
| 875 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 876 | while ((bio = bio_list_pop(tmp))) |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 877 | submit_bio_noacct(bio); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 878 | } |
| 879 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 880 | 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] | 881 | { |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 882 | const struct r5pending_data *da = list_entry(a, |
| 883 | struct r5pending_data, sibling); |
| 884 | const struct r5pending_data *db = list_entry(b, |
| 885 | struct r5pending_data, sibling); |
| 886 | if (da->sector > db->sector) |
| 887 | return 1; |
| 888 | if (da->sector < db->sector) |
| 889 | return -1; |
| 890 | return 0; |
| 891 | } |
| 892 | |
| 893 | static void dispatch_defer_bios(struct r5conf *conf, int target, |
| 894 | struct bio_list *list) |
| 895 | { |
| 896 | struct r5pending_data *data; |
| 897 | struct list_head *first, *next = NULL; |
| 898 | int cnt = 0; |
| 899 | |
| 900 | if (conf->pending_data_cnt == 0) |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 901 | return; |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 902 | |
| 903 | list_sort(NULL, &conf->pending_list, cmp_stripe); |
| 904 | |
| 905 | first = conf->pending_list.next; |
| 906 | |
| 907 | /* temporarily move the head */ |
| 908 | if (conf->next_pending_data) |
| 909 | list_move_tail(&conf->pending_list, |
| 910 | &conf->next_pending_data->sibling); |
| 911 | |
| 912 | while (!list_empty(&conf->pending_list)) { |
| 913 | data = list_first_entry(&conf->pending_list, |
| 914 | struct r5pending_data, sibling); |
| 915 | if (&data->sibling == first) |
| 916 | first = data->sibling.next; |
| 917 | next = data->sibling.next; |
| 918 | |
| 919 | bio_list_merge(list, &data->bios); |
| 920 | list_move(&data->sibling, &conf->free_list); |
| 921 | cnt++; |
| 922 | if (cnt >= target) |
| 923 | break; |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 924 | } |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 925 | conf->pending_data_cnt -= cnt; |
| 926 | BUG_ON(conf->pending_data_cnt < 0 || cnt < target); |
| 927 | |
| 928 | if (next != &conf->pending_list) |
| 929 | conf->next_pending_data = list_entry(next, |
| 930 | struct r5pending_data, sibling); |
| 931 | else |
| 932 | conf->next_pending_data = NULL; |
| 933 | /* list isn't empty */ |
| 934 | if (first != &conf->pending_list) |
| 935 | list_move_tail(&conf->pending_list, first); |
| 936 | } |
| 937 | |
| 938 | static void flush_deferred_bios(struct r5conf *conf) |
| 939 | { |
| 940 | struct bio_list tmp = BIO_EMPTY_LIST; |
| 941 | |
| 942 | if (conf->pending_data_cnt == 0) |
| 943 | return; |
| 944 | |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 945 | spin_lock(&conf->pending_bios_lock); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 946 | dispatch_defer_bios(conf, conf->pending_data_cnt, &tmp); |
| 947 | BUG_ON(conf->pending_data_cnt != 0); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 948 | spin_unlock(&conf->pending_bios_lock); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 949 | |
| 950 | dispatch_bio_list(&tmp); |
| 951 | } |
| 952 | |
| 953 | static void defer_issue_bios(struct r5conf *conf, sector_t sector, |
| 954 | struct bio_list *bios) |
| 955 | { |
| 956 | struct bio_list tmp = BIO_EMPTY_LIST; |
| 957 | struct r5pending_data *ent; |
| 958 | |
| 959 | spin_lock(&conf->pending_bios_lock); |
| 960 | ent = list_first_entry(&conf->free_list, struct r5pending_data, |
| 961 | sibling); |
| 962 | list_move_tail(&ent->sibling, &conf->pending_list); |
| 963 | ent->sector = sector; |
| 964 | bio_list_init(&ent->bios); |
| 965 | bio_list_merge(&ent->bios, bios); |
| 966 | conf->pending_data_cnt++; |
| 967 | if (conf->pending_data_cnt >= PENDING_IO_MAX) |
| 968 | dispatch_defer_bios(conf, PENDING_IO_ONE_FLUSH, &tmp); |
| 969 | |
| 970 | spin_unlock(&conf->pending_bios_lock); |
| 971 | |
| 972 | dispatch_bio_list(&tmp); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 973 | } |
| 974 | |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 975 | static void |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 976 | raid5_end_read_request(struct bio *bi); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 977 | static void |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 978 | raid5_end_write_request(struct bio *bi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 979 | |
Dan Williams | c4e5ac0 | 2008-06-28 08:31:53 +1000 | [diff] [blame] | 980 | 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] | 981 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 982 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 983 | int i, disks = sh->disks; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 984 | struct stripe_head *head_sh = sh; |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 985 | struct bio_list pending_bios = BIO_EMPTY_LIST; |
| 986 | bool should_defer; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 987 | |
| 988 | might_sleep(); |
| 989 | |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 990 | if (log_stripe(sh, s) == 0) |
| 991 | return; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 992 | |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 993 | should_defer = conf->batch_bio_dispatch && conf->group_cnt; |
Shaohua Li | f6bed0e | 2015-08-13 14:31:59 -0700 | [diff] [blame] | 994 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 995 | for (i = disks; i--; ) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 996 | int op, op_flags = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 997 | int replace_only = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 998 | struct bio *bi, *rbi; |
| 999 | struct md_rdev *rdev, *rrdev = NULL; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1000 | |
| 1001 | sh = head_sh; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1002 | if (test_and_clear_bit(R5_Wantwrite, &sh->dev[i].flags)) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1003 | op = REQ_OP_WRITE; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1004 | if (test_and_clear_bit(R5_WantFUA, &sh->dev[i].flags)) |
Christoph Hellwig | 70fd761 | 2016-11-01 07:40:10 -0600 | [diff] [blame] | 1005 | op_flags = REQ_FUA; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1006 | if (test_bit(R5_Discard, &sh->dev[i].flags)) |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1007 | op = REQ_OP_DISCARD; |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1008 | } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1009 | op = REQ_OP_READ; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1010 | else if (test_and_clear_bit(R5_WantReplace, |
| 1011 | &sh->dev[i].flags)) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1012 | op = REQ_OP_WRITE; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1013 | replace_only = 1; |
| 1014 | } else |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1015 | continue; |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1016 | if (test_and_clear_bit(R5_SyncIO, &sh->dev[i].flags)) |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1017 | op_flags |= REQ_SYNC; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1018 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1019 | again: |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1020 | bi = &sh->dev[i].req; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1021 | rbi = &sh->dev[i].rreq; /* For writing to replacement */ |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1022 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1023 | rcu_read_lock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1024 | rrdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1025 | smp_mb(); /* Ensure that if rrdev is NULL, rdev won't be */ |
| 1026 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 1027 | if (!rdev) { |
| 1028 | rdev = rrdev; |
| 1029 | rrdev = NULL; |
| 1030 | } |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1031 | if (op_is_write(op)) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1032 | if (replace_only) |
| 1033 | rdev = NULL; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1034 | if (rdev == rrdev) |
| 1035 | /* We raced and saw duplicates */ |
| 1036 | rrdev = NULL; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1037 | } else { |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1038 | if (test_bit(R5_ReadRepl, &head_sh->dev[i].flags) && rrdev) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1039 | rdev = rrdev; |
| 1040 | rrdev = NULL; |
| 1041 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1042 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1043 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 1044 | rdev = NULL; |
| 1045 | if (rdev) |
| 1046 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1047 | if (rrdev && test_bit(Faulty, &rrdev->flags)) |
| 1048 | rrdev = NULL; |
| 1049 | if (rrdev) |
| 1050 | atomic_inc(&rrdev->nr_pending); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1051 | rcu_read_unlock(); |
| 1052 | |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1053 | /* We have already checked bad blocks for reads. Now |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1054 | * need to check for writes. We never accept write errors |
| 1055 | * on the replacement, so we don't to check rrdev. |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1056 | */ |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1057 | while (op_is_write(op) && rdev && |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1058 | test_bit(WriteErrorSeen, &rdev->flags)) { |
| 1059 | sector_t first_bad; |
| 1060 | int bad_sectors; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1061 | int bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1062 | &first_bad, &bad_sectors); |
| 1063 | if (!bad) |
| 1064 | break; |
| 1065 | |
| 1066 | if (bad < 0) { |
| 1067 | set_bit(BlockedBadBlocks, &rdev->flags); |
| 1068 | if (!conf->mddev->external && |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 1069 | conf->mddev->sb_flags) { |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1070 | /* It is very unlikely, but we might |
| 1071 | * still need to write out the |
| 1072 | * bad block log - better give it |
| 1073 | * a chance*/ |
| 1074 | md_check_recovery(conf->mddev); |
| 1075 | } |
majianpeng | 1850753 | 2012-07-03 12:11:54 +1000 | [diff] [blame] | 1076 | /* |
| 1077 | * Because md_wait_for_blocked_rdev |
| 1078 | * will dec nr_pending, we must |
| 1079 | * increment it first. |
| 1080 | */ |
| 1081 | atomic_inc(&rdev->nr_pending); |
NeilBrown | 73e92e5 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 1082 | md_wait_for_blocked_rdev(rdev, conf->mddev); |
| 1083 | } else { |
| 1084 | /* Acknowledged bad block - skip the write */ |
| 1085 | rdev_dec_pending(rdev, conf->mddev); |
| 1086 | rdev = NULL; |
| 1087 | } |
| 1088 | } |
| 1089 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1090 | if (rdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1091 | if (s->syncing || s->expanding || s->expanded |
| 1092 | || s->replacing) |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1093 | md_sync_acct(rdev->bdev, RAID5_STRIPE_SECTORS(conf)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1094 | |
Dan Williams | 2b7497f | 2008-06-28 08:31:52 +1000 | [diff] [blame] | 1095 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 1096 | |
Christoph Hellwig | 74d4699 | 2017-08-23 19:10:32 +0200 | [diff] [blame] | 1097 | bio_set_dev(bi, rdev->bdev); |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1098 | bio_set_op_attrs(bi, op, op_flags); |
| 1099 | bi->bi_end_io = op_is_write(op) |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 1100 | ? raid5_end_write_request |
| 1101 | : raid5_end_read_request; |
| 1102 | bi->bi_private = sh; |
| 1103 | |
Mike Christie | 6296b96 | 2016-06-05 14:32:21 -0500 | [diff] [blame] | 1104 | pr_debug("%s: for %llu schedule op %d on disc %d\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1105 | __func__, (unsigned long long)sh->sector, |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1106 | bi->bi_opf, i); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1107 | atomic_inc(&sh->count); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1108 | if (sh != head_sh) |
| 1109 | atomic_inc(&head_sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1110 | if (use_new_offset(conf, sh)) |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1111 | bi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1112 | + rdev->new_data_offset); |
| 1113 | else |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1114 | bi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1115 | + rdev->data_offset); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1116 | if (test_bit(R5_ReadNoMerge, &head_sh->dev[i].flags)) |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1117 | bi->bi_opf |= REQ_NOMERGE; |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 1118 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1119 | if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) |
| 1120 | WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 1121 | |
| 1122 | if (!op_is_write(op) && |
| 1123 | test_bit(R5_InJournal, &sh->dev[i].flags)) |
| 1124 | /* |
| 1125 | * issuing read for a page in journal, this |
| 1126 | * must be preparing for prexor in rmw; read |
| 1127 | * the data into orig_page |
| 1128 | */ |
| 1129 | sh->dev[i].vec.bv_page = sh->dev[i].orig_page; |
| 1130 | else |
| 1131 | sh->dev[i].vec.bv_page = sh->dev[i].page; |
Kent Overstreet | 4997b72 | 2013-05-30 08:44:39 +0200 | [diff] [blame] | 1132 | bi->bi_vcnt = 1; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1133 | bi->bi_io_vec[0].bv_len = RAID5_STRIPE_SIZE(conf); |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1134 | bi->bi_io_vec[0].bv_offset = sh->dev[i].offset; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1135 | bi->bi_iter.bi_size = RAID5_STRIPE_SIZE(conf); |
Mariusz Dabrowski | 2cd259a | 2018-04-19 19:28:10 +0200 | [diff] [blame] | 1136 | bi->bi_write_hint = sh->dev[i].write_hint; |
| 1137 | if (!rrdev) |
Eugene Syromiatnikov | f193489 | 2019-09-20 17:58:28 +0200 | [diff] [blame] | 1138 | sh->dev[i].write_hint = RWH_WRITE_LIFE_NOT_SET; |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1139 | /* |
| 1140 | * If this is discard request, set bi_vcnt 0. We don't |
| 1141 | * want to confuse SCSI because SCSI will replace payload |
| 1142 | */ |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1143 | if (op == REQ_OP_DISCARD) |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1144 | bi->bi_vcnt = 0; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1145 | if (rrdev) |
| 1146 | set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 1147 | |
| 1148 | if (conf->mddev->gendisk) |
Christoph Hellwig | 74d4699 | 2017-08-23 19:10:32 +0200 | [diff] [blame] | 1149 | trace_block_bio_remap(bi->bi_disk->queue, |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 1150 | bi, disk_devt(conf->mddev->gendisk), |
| 1151 | sh->dev[i].sector); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 1152 | if (should_defer && op_is_write(op)) |
| 1153 | bio_list_add(&pending_bios, bi); |
| 1154 | else |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 1155 | submit_bio_noacct(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1156 | } |
| 1157 | if (rrdev) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1158 | if (s->syncing || s->expanding || s->expanded |
| 1159 | || s->replacing) |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1160 | md_sync_acct(rrdev->bdev, RAID5_STRIPE_SECTORS(conf)); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1161 | |
| 1162 | set_bit(STRIPE_IO_STARTED, &sh->state); |
| 1163 | |
Christoph Hellwig | 74d4699 | 2017-08-23 19:10:32 +0200 | [diff] [blame] | 1164 | bio_set_dev(rbi, rrdev->bdev); |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1165 | bio_set_op_attrs(rbi, op, op_flags); |
| 1166 | BUG_ON(!op_is_write(op)); |
Kent Overstreet | 2f6db2a | 2012-09-11 12:26:38 -0700 | [diff] [blame] | 1167 | rbi->bi_end_io = raid5_end_write_request; |
| 1168 | rbi->bi_private = sh; |
| 1169 | |
Mike Christie | 6296b96 | 2016-06-05 14:32:21 -0500 | [diff] [blame] | 1170 | pr_debug("%s: for %llu schedule op %d on " |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1171 | "replacement disc %d\n", |
| 1172 | __func__, (unsigned long long)sh->sector, |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1173 | rbi->bi_opf, i); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1174 | atomic_inc(&sh->count); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1175 | if (sh != head_sh) |
| 1176 | atomic_inc(&head_sh->count); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1177 | if (use_new_offset(conf, sh)) |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1178 | rbi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1179 | + rrdev->new_data_offset); |
| 1180 | else |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1181 | rbi->bi_iter.bi_sector = (sh->sector |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 1182 | + rrdev->data_offset); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1183 | if (test_bit(R5_SkipCopy, &sh->dev[i].flags)) |
| 1184 | WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
| 1185 | sh->dev[i].rvec.bv_page = sh->dev[i].page; |
Kent Overstreet | 4997b72 | 2013-05-30 08:44:39 +0200 | [diff] [blame] | 1186 | rbi->bi_vcnt = 1; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1187 | rbi->bi_io_vec[0].bv_len = RAID5_STRIPE_SIZE(conf); |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1188 | rbi->bi_io_vec[0].bv_offset = sh->dev[i].offset; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1189 | rbi->bi_iter.bi_size = RAID5_STRIPE_SIZE(conf); |
Mariusz Dabrowski | 2cd259a | 2018-04-19 19:28:10 +0200 | [diff] [blame] | 1190 | rbi->bi_write_hint = sh->dev[i].write_hint; |
Eugene Syromiatnikov | f193489 | 2019-09-20 17:58:28 +0200 | [diff] [blame] | 1191 | sh->dev[i].write_hint = RWH_WRITE_LIFE_NOT_SET; |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1192 | /* |
| 1193 | * If this is discard request, set bi_vcnt 0. We don't |
| 1194 | * want to confuse SCSI because SCSI will replace payload |
| 1195 | */ |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1196 | if (op == REQ_OP_DISCARD) |
Shaohua Li | 37c61ff | 2013-10-19 14:50:28 +0800 | [diff] [blame] | 1197 | rbi->bi_vcnt = 0; |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 1198 | if (conf->mddev->gendisk) |
Christoph Hellwig | 74d4699 | 2017-08-23 19:10:32 +0200 | [diff] [blame] | 1199 | trace_block_bio_remap(rbi->bi_disk->queue, |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 1200 | rbi, disk_devt(conf->mddev->gendisk), |
| 1201 | sh->dev[i].sector); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 1202 | if (should_defer && op_is_write(op)) |
| 1203 | bio_list_add(&pending_bios, rbi); |
| 1204 | else |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 1205 | submit_bio_noacct(rbi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 1206 | } |
| 1207 | if (!rdev && !rrdev) { |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1208 | if (op_is_write(op)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1209 | set_bit(STRIPE_DEGRADED, &sh->state); |
Mike Christie | 6296b96 | 2016-06-05 14:32:21 -0500 | [diff] [blame] | 1210 | pr_debug("skip op %d on disc %d for sector %llu\n", |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1211 | bi->bi_opf, i, (unsigned long long)sh->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1212 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 1213 | set_bit(STRIPE_HANDLE, &sh->state); |
| 1214 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1215 | |
| 1216 | if (!head_sh->batch_head) |
| 1217 | continue; |
| 1218 | sh = list_first_entry(&sh->batch_list, struct stripe_head, |
| 1219 | batch_list); |
| 1220 | if (sh != head_sh) |
| 1221 | goto again; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1222 | } |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 1223 | |
| 1224 | if (should_defer && !bio_list_empty(&pending_bios)) |
| 1225 | defer_issue_bios(conf, head_sh->sector, &pending_bios); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | static struct dma_async_tx_descriptor * |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1229 | async_copy_data(int frombio, struct bio *bio, struct page **page, |
Yufen Yu | 248728d | 2020-08-20 09:22:07 -0400 | [diff] [blame^] | 1230 | unsigned int poff, sector_t sector, struct dma_async_tx_descriptor *tx, |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1231 | struct stripe_head *sh, int no_skipcopy) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1232 | { |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1233 | struct bio_vec bvl; |
| 1234 | struct bvec_iter iter; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1235 | struct page *bio_page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1236 | int page_offset; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1237 | struct async_submit_ctl submit; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1238 | enum async_tx_flags flags = 0; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1239 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1240 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1241 | if (bio->bi_iter.bi_sector >= sector) |
| 1242 | page_offset = (signed)(bio->bi_iter.bi_sector - sector) * 512; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1243 | else |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1244 | page_offset = (signed)(sector - bio->bi_iter.bi_sector) * -512; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1245 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1246 | if (frombio) |
| 1247 | flags |= ASYNC_TX_FENCE; |
| 1248 | init_async_submit(&submit, flags, tx, NULL, NULL, NULL); |
| 1249 | |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1250 | bio_for_each_segment(bvl, bio, iter) { |
| 1251 | int len = bvl.bv_len; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1252 | int clen; |
| 1253 | int b_offset = 0; |
| 1254 | |
| 1255 | if (page_offset < 0) { |
| 1256 | b_offset = -page_offset; |
| 1257 | page_offset += b_offset; |
| 1258 | len -= b_offset; |
| 1259 | } |
| 1260 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1261 | if (len > 0 && page_offset + len > RAID5_STRIPE_SIZE(conf)) |
| 1262 | clen = RAID5_STRIPE_SIZE(conf) - page_offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1263 | else |
| 1264 | clen = len; |
| 1265 | |
| 1266 | if (clen > 0) { |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1267 | b_offset += bvl.bv_offset; |
| 1268 | bio_page = bvl.bv_page; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1269 | if (frombio) { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1270 | if (conf->skip_copy && |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1271 | b_offset == 0 && page_offset == 0 && |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1272 | clen == RAID5_STRIPE_SIZE(conf) && |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1273 | !no_skipcopy) |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1274 | *page = bio_page; |
| 1275 | else |
Yufen Yu | 248728d | 2020-08-20 09:22:07 -0400 | [diff] [blame^] | 1276 | tx = async_memcpy(*page, bio_page, page_offset + poff, |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1277 | b_offset, clen, &submit); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1278 | } else |
| 1279 | tx = async_memcpy(bio_page, *page, b_offset, |
Yufen Yu | 248728d | 2020-08-20 09:22:07 -0400 | [diff] [blame^] | 1280 | page_offset + poff, clen, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1281 | } |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1282 | /* chain the operations */ |
| 1283 | submit.depend_tx = tx; |
| 1284 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1285 | if (clen < len) /* hit end of page */ |
| 1286 | break; |
| 1287 | page_offset += len; |
| 1288 | } |
| 1289 | |
| 1290 | return tx; |
| 1291 | } |
| 1292 | |
| 1293 | static void ops_complete_biofill(void *stripe_head_ref) |
| 1294 | { |
| 1295 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1296 | int i; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1297 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1298 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1299 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1300 | (unsigned long long)sh->sector); |
| 1301 | |
| 1302 | /* clear completed biofills */ |
| 1303 | for (i = sh->disks; i--; ) { |
| 1304 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1305 | |
| 1306 | /* acknowledge completion of a biofill operation */ |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1307 | /* and check if we need to reply to a read request, |
| 1308 | * new R5_Wantfill requests are held off until |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1309 | * !STRIPE_BIOFILL_RUN |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1310 | */ |
| 1311 | if (test_and_clear_bit(R5_Wantfill, &dev->flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1312 | struct bio *rbi, *rbi2; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1313 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1314 | BUG_ON(!dev->read); |
| 1315 | rbi = dev->read; |
| 1316 | dev->read = NULL; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1317 | while (rbi && rbi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1318 | dev->sector + RAID5_STRIPE_SECTORS(conf)) { |
| 1319 | rbi2 = r5_next_bio(conf, rbi, dev->sector); |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 1320 | bio_endio(rbi); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1321 | rbi = rbi2; |
| 1322 | } |
| 1323 | } |
| 1324 | } |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 1325 | clear_bit(STRIPE_BIOFILL_RUN, &sh->state); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1326 | |
Dan Williams | e4d8490 | 2007-09-24 10:06:13 -0700 | [diff] [blame] | 1327 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 1328 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static void ops_run_biofill(struct stripe_head *sh) |
| 1332 | { |
| 1333 | struct dma_async_tx_descriptor *tx = NULL; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1334 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1335 | int i; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1336 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1337 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1338 | BUG_ON(sh->batch_head); |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1339 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1340 | (unsigned long long)sh->sector); |
| 1341 | |
| 1342 | for (i = sh->disks; i--; ) { |
| 1343 | struct r5dev *dev = &sh->dev[i]; |
| 1344 | if (test_bit(R5_Wantfill, &dev->flags)) { |
| 1345 | struct bio *rbi; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1346 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1347 | dev->read = rbi = dev->toread; |
| 1348 | dev->toread = NULL; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1349 | spin_unlock_irq(&sh->stripe_lock); |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1350 | while (rbi && rbi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1351 | dev->sector + RAID5_STRIPE_SECTORS(conf)) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1352 | tx = async_copy_data(0, rbi, &dev->page, |
Yufen Yu | 248728d | 2020-08-20 09:22:07 -0400 | [diff] [blame^] | 1353 | dev->offset, |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1354 | dev->sector, tx, sh, 0); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1355 | rbi = r5_next_bio(conf, rbi, dev->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1361 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_biofill, sh, NULL); |
| 1362 | async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1365 | static void mark_target_uptodate(struct stripe_head *sh, int target) |
| 1366 | { |
| 1367 | struct r5dev *tgt; |
| 1368 | |
| 1369 | if (target < 0) |
| 1370 | return; |
| 1371 | |
| 1372 | tgt = &sh->dev[target]; |
| 1373 | set_bit(R5_UPTODATE, &tgt->flags); |
| 1374 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1375 | clear_bit(R5_Wantcompute, &tgt->flags); |
| 1376 | } |
| 1377 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1378 | static void ops_complete_compute(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1379 | { |
| 1380 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1381 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1382 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1383 | (unsigned long long)sh->sector); |
| 1384 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1385 | /* mark the computed target(s) as uptodate */ |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1386 | mark_target_uptodate(sh, sh->ops.target); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1387 | mark_target_uptodate(sh, sh->ops.target2); |
Dan Williams | 4e7d2c0 | 2009-08-29 19:13:11 -0700 | [diff] [blame] | 1388 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 1389 | clear_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 1390 | if (sh->check_state == check_state_compute_run) |
| 1391 | sh->check_state = check_state_compute_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1392 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 1393 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1396 | /* return a pointer to the address conversion region of the scribble buffer */ |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 1397 | static struct page **to_addr_page(struct raid5_percpu *percpu, int i) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1398 | { |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 1399 | return percpu->scribble + i * percpu->scribble_obj_size; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /* return a pointer to the address conversion region of the scribble buffer */ |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 1403 | static addr_conv_t *to_addr_conv(struct stripe_head *sh, |
| 1404 | struct raid5_percpu *percpu, int i) |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1405 | { |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 1406 | return (void *) (to_addr_page(percpu, i) + sh->disks + 2); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1409 | /* |
| 1410 | * Return a pointer to record offset address. |
| 1411 | */ |
| 1412 | static unsigned int * |
| 1413 | to_addr_offs(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1414 | { |
| 1415 | return (unsigned int *) (to_addr_conv(sh, percpu, 0) + sh->disks + 2); |
| 1416 | } |
| 1417 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 1418 | static struct dma_async_tx_descriptor * |
| 1419 | ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1420 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1421 | int disks = sh->disks; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1422 | struct page **xor_srcs = to_addr_page(percpu, 0); |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1423 | unsigned int *off_srcs = to_addr_offs(sh, percpu); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1424 | int target = sh->ops.target; |
| 1425 | struct r5dev *tgt = &sh->dev[target]; |
| 1426 | struct page *xor_dest = tgt->page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1427 | unsigned int off_dest = tgt->offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1428 | int count = 0; |
| 1429 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1430 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1431 | int i; |
| 1432 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1433 | BUG_ON(sh->batch_head); |
| 1434 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1435 | pr_debug("%s: stripe %llu block: %d\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1436 | __func__, (unsigned long long)sh->sector, target); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1437 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1438 | |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1439 | for (i = disks; i--; ) { |
| 1440 | if (i != target) { |
| 1441 | off_srcs[count] = sh->dev[i].offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1442 | xor_srcs[count++] = sh->dev[i].page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1443 | } |
| 1444 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1445 | |
| 1446 | atomic_inc(&sh->count); |
| 1447 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1448 | 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] | 1449 | ops_complete_compute, sh, to_addr_conv(sh, percpu, 0)); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1450 | if (unlikely(count == 1)) |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1451 | tx = async_memcpy(xor_dest, xor_srcs[0], off_dest, off_srcs[0], |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1452 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1453 | else |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1454 | tx = async_xor(xor_dest, xor_srcs, 0, count, |
| 1455 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1456 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1457 | return tx; |
| 1458 | } |
| 1459 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1460 | /* set_syndrome_sources - populate source buffers for gen_syndrome |
| 1461 | * @srcs - (struct page *) array of size sh->disks |
| 1462 | * @sh - stripe_head to parse |
| 1463 | * |
| 1464 | * Populates srcs in proper layout order for the stripe and returns the |
| 1465 | * 'count' of sources to be used in a call to async_gen_syndrome. The P |
| 1466 | * destination buffer is recorded in srcs[count] and the Q destination |
| 1467 | * is recorded in srcs[count+1]]. |
| 1468 | */ |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1469 | static int set_syndrome_sources(struct page **srcs, |
| 1470 | struct stripe_head *sh, |
| 1471 | int srctype) |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1472 | { |
| 1473 | int disks = sh->disks; |
| 1474 | int syndrome_disks = sh->ddf_layout ? disks : (disks - 2); |
| 1475 | int d0_idx = raid6_d0(sh); |
| 1476 | int count; |
| 1477 | int i; |
| 1478 | |
| 1479 | for (i = 0; i < disks; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1480 | srcs[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1481 | |
| 1482 | count = 0; |
| 1483 | i = d0_idx; |
| 1484 | do { |
| 1485 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1486 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1487 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1488 | if (i == sh->qd_idx || i == sh->pd_idx || |
| 1489 | (srctype == SYNDROME_SRC_ALL) || |
| 1490 | (srctype == SYNDROME_SRC_WANT_DRAIN && |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1491 | (test_bit(R5_Wantdrain, &dev->flags) || |
| 1492 | test_bit(R5_InJournal, &dev->flags))) || |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1493 | (srctype == SYNDROME_SRC_WRITTEN && |
Song Liu | 0977762 | 2017-03-13 13:44:35 -0700 | [diff] [blame] | 1494 | (dev->written || |
| 1495 | test_bit(R5_InJournal, &dev->flags)))) { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1496 | if (test_bit(R5_InJournal, &dev->flags)) |
| 1497 | srcs[slot] = sh->dev[i].orig_page; |
| 1498 | else |
| 1499 | srcs[slot] = sh->dev[i].page; |
| 1500 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1501 | i = raid6_next_disk(i, disks); |
| 1502 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1503 | |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1504 | return syndrome_disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static struct dma_async_tx_descriptor * |
| 1508 | ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1509 | { |
| 1510 | int disks = sh->disks; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1511 | struct page **blocks = to_addr_page(percpu, 0); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1512 | int target; |
| 1513 | int qd_idx = sh->qd_idx; |
| 1514 | struct dma_async_tx_descriptor *tx; |
| 1515 | struct async_submit_ctl submit; |
| 1516 | struct r5dev *tgt; |
| 1517 | struct page *dest; |
| 1518 | int i; |
| 1519 | int count; |
| 1520 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1521 | BUG_ON(sh->batch_head); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1522 | if (sh->ops.target < 0) |
| 1523 | target = sh->ops.target2; |
| 1524 | else if (sh->ops.target2 < 0) |
| 1525 | target = sh->ops.target; |
| 1526 | else |
| 1527 | /* we should only have one valid target */ |
| 1528 | BUG(); |
| 1529 | BUG_ON(target < 0); |
| 1530 | pr_debug("%s: stripe %llu block: %d\n", |
| 1531 | __func__, (unsigned long long)sh->sector, target); |
| 1532 | |
| 1533 | tgt = &sh->dev[target]; |
| 1534 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1535 | dest = tgt->page; |
| 1536 | |
| 1537 | atomic_inc(&sh->count); |
| 1538 | |
| 1539 | if (target == qd_idx) { |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1540 | count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_ALL); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1541 | blocks[count] = NULL; /* regenerating p is not necessary */ |
| 1542 | BUG_ON(blocks[count+1] != dest); /* q should already be set */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1543 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1544 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1545 | to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1546 | tx = async_gen_syndrome(blocks, 0, count+2, |
| 1547 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1548 | } else { |
| 1549 | /* Compute any data- or p-drive using XOR */ |
| 1550 | count = 0; |
| 1551 | for (i = disks; i-- ; ) { |
| 1552 | if (i == target || i == qd_idx) |
| 1553 | continue; |
| 1554 | blocks[count++] = sh->dev[i].page; |
| 1555 | } |
| 1556 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1557 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1558 | NULL, ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1559 | to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1560 | tx = async_xor(dest, blocks, 0, count, |
| 1561 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | return tx; |
| 1565 | } |
| 1566 | |
| 1567 | static struct dma_async_tx_descriptor * |
| 1568 | ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu) |
| 1569 | { |
| 1570 | int i, count, disks = sh->disks; |
| 1571 | int syndrome_disks = sh->ddf_layout ? disks : disks-2; |
| 1572 | int d0_idx = raid6_d0(sh); |
| 1573 | int faila = -1, failb = -1; |
| 1574 | int target = sh->ops.target; |
| 1575 | int target2 = sh->ops.target2; |
| 1576 | struct r5dev *tgt = &sh->dev[target]; |
| 1577 | struct r5dev *tgt2 = &sh->dev[target2]; |
| 1578 | struct dma_async_tx_descriptor *tx; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1579 | struct page **blocks = to_addr_page(percpu, 0); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1580 | struct async_submit_ctl submit; |
| 1581 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1582 | BUG_ON(sh->batch_head); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1583 | pr_debug("%s: stripe %llu block1: %d block2: %d\n", |
| 1584 | __func__, (unsigned long long)sh->sector, target, target2); |
| 1585 | BUG_ON(target < 0 || target2 < 0); |
| 1586 | BUG_ON(!test_bit(R5_Wantcompute, &tgt->flags)); |
| 1587 | BUG_ON(!test_bit(R5_Wantcompute, &tgt2->flags)); |
| 1588 | |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1589 | /* we need to open-code set_syndrome_sources to handle the |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1590 | * slot number conversion for 'faila' and 'failb' |
| 1591 | */ |
| 1592 | for (i = 0; i < disks ; i++) |
NeilBrown | 5dd33c9 | 2009-10-16 16:40:25 +1100 | [diff] [blame] | 1593 | blocks[i] = NULL; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1594 | count = 0; |
| 1595 | i = d0_idx; |
| 1596 | do { |
| 1597 | int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks); |
| 1598 | |
| 1599 | blocks[slot] = sh->dev[i].page; |
| 1600 | |
| 1601 | if (i == target) |
| 1602 | faila = slot; |
| 1603 | if (i == target2) |
| 1604 | failb = slot; |
| 1605 | i = raid6_next_disk(i, disks); |
| 1606 | } while (i != d0_idx); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1607 | |
| 1608 | BUG_ON(faila == failb); |
| 1609 | if (failb < faila) |
| 1610 | swap(faila, failb); |
| 1611 | pr_debug("%s: stripe: %llu faila: %d failb: %d\n", |
| 1612 | __func__, (unsigned long long)sh->sector, faila, failb); |
| 1613 | |
| 1614 | atomic_inc(&sh->count); |
| 1615 | |
| 1616 | if (failb == syndrome_disks+1) { |
| 1617 | /* Q disk is one of the missing disks */ |
| 1618 | if (faila == syndrome_disks) { |
| 1619 | /* Missing P+Q, just recompute */ |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1620 | init_async_submit(&submit, ASYNC_TX_FENCE, NULL, |
| 1621 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1622 | to_addr_conv(sh, percpu, 0)); |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 1623 | return async_gen_syndrome(blocks, 0, syndrome_disks+2, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1624 | RAID5_STRIPE_SIZE(sh->raid_conf), |
| 1625 | &submit); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1626 | } else { |
| 1627 | struct page *dest; |
| 1628 | int data_target; |
| 1629 | int qd_idx = sh->qd_idx; |
| 1630 | |
| 1631 | /* Missing D+Q: recompute D from P, then recompute Q */ |
| 1632 | if (target == qd_idx) |
| 1633 | data_target = target2; |
| 1634 | else |
| 1635 | data_target = target; |
| 1636 | |
| 1637 | count = 0; |
| 1638 | for (i = disks; i-- ; ) { |
| 1639 | if (i == data_target || i == qd_idx) |
| 1640 | continue; |
| 1641 | blocks[count++] = sh->dev[i].page; |
| 1642 | } |
| 1643 | dest = sh->dev[data_target].page; |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1644 | init_async_submit(&submit, |
| 1645 | ASYNC_TX_FENCE|ASYNC_TX_XOR_ZERO_DST, |
| 1646 | NULL, NULL, NULL, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1647 | to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1648 | tx = async_xor(dest, blocks, 0, count, |
| 1649 | RAID5_STRIPE_SIZE(sh->raid_conf), |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1650 | &submit); |
| 1651 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1652 | count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_ALL); |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1653 | init_async_submit(&submit, ASYNC_TX_FENCE, tx, |
| 1654 | ops_complete_compute, sh, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1655 | to_addr_conv(sh, percpu, 0)); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1656 | return async_gen_syndrome(blocks, 0, count+2, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1657 | RAID5_STRIPE_SIZE(sh->raid_conf), |
| 1658 | &submit); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 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, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1667 | RAID5_STRIPE_SIZE(sh->raid_conf), |
| 1668 | faila, |
| 1669 | blocks, &submit); |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1670 | } else { |
| 1671 | /* We're missing D+D. */ |
| 1672 | return async_raid6_2data_recov(syndrome_disks+2, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1673 | RAID5_STRIPE_SIZE(sh->raid_conf), |
| 1674 | faila, failb, |
| 1675 | blocks, &submit); |
Dan Williams | 6c910a7 | 2009-09-16 12:24:54 -0700 | [diff] [blame] | 1676 | } |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1680 | static void ops_complete_prexor(void *stripe_head_ref) |
| 1681 | { |
| 1682 | struct stripe_head *sh = stripe_head_ref; |
| 1683 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1684 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1685 | (unsigned long long)sh->sector); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1686 | |
| 1687 | if (r5c_is_writeback(sh->raid_conf->log)) |
| 1688 | /* |
| 1689 | * raid5-cache write back uses orig_page during prexor. |
| 1690 | * After prexor, it is time to free orig_page |
| 1691 | */ |
| 1692 | r5c_release_extra_page(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | static struct dma_async_tx_descriptor * |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1696 | ops_run_prexor5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1697 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1698 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1699 | int disks = sh->disks; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 1700 | struct page **xor_srcs = to_addr_page(percpu, 0); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1701 | int count = 0, pd_idx = sh->pd_idx, i; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1702 | struct async_submit_ctl submit; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1703 | |
| 1704 | /* existing parity data subtracted */ |
| 1705 | struct page *xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1706 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1707 | BUG_ON(sh->batch_head); |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1708 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1709 | (unsigned long long)sh->sector); |
| 1710 | |
| 1711 | for (i = disks; i--; ) { |
| 1712 | struct r5dev *dev = &sh->dev[i]; |
| 1713 | /* Only process blocks that are known to be uptodate */ |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1714 | if (test_bit(R5_InJournal, &dev->flags)) |
| 1715 | xor_srcs[count++] = dev->orig_page; |
| 1716 | else if (test_bit(R5_Wantdrain, &dev->flags)) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1717 | xor_srcs[count++] = dev->page; |
| 1718 | } |
| 1719 | |
Dan Williams | 0403e38 | 2009-09-08 17:42:50 -0700 | [diff] [blame] | 1720 | 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] | 1721 | ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1722 | tx = async_xor(xor_dest, xor_srcs, 0, count, |
| 1723 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1724 | |
| 1725 | return tx; |
| 1726 | } |
| 1727 | |
| 1728 | static struct dma_async_tx_descriptor * |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1729 | ops_run_prexor6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1730 | struct dma_async_tx_descriptor *tx) |
| 1731 | { |
| 1732 | struct page **blocks = to_addr_page(percpu, 0); |
| 1733 | int count; |
| 1734 | struct async_submit_ctl submit; |
| 1735 | |
| 1736 | pr_debug("%s: stripe %llu\n", __func__, |
| 1737 | (unsigned long long)sh->sector); |
| 1738 | |
| 1739 | count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_WANT_DRAIN); |
| 1740 | |
| 1741 | init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_PQ_XOR_DST, tx, |
| 1742 | ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1743 | tx = async_gen_syndrome(blocks, 0, count+2, |
| 1744 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1745 | |
| 1746 | return tx; |
| 1747 | } |
| 1748 | |
| 1749 | static struct dma_async_tx_descriptor * |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1750 | 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] | 1751 | { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1752 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1753 | int disks = sh->disks; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1754 | int i; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1755 | struct stripe_head *head_sh = sh; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1756 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1757 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1758 | (unsigned long long)sh->sector); |
| 1759 | |
| 1760 | for (i = disks; i--; ) { |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1761 | struct r5dev *dev; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1762 | struct bio *chosen; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1763 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1764 | sh = head_sh; |
| 1765 | if (test_and_clear_bit(R5_Wantdrain, &head_sh->dev[i].flags)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1766 | struct bio *wbi; |
| 1767 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1768 | again: |
| 1769 | dev = &sh->dev[i]; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1770 | /* |
| 1771 | * clear R5_InJournal, so when rewriting a page in |
| 1772 | * journal, it is not skipped by r5l_log_stripe() |
| 1773 | */ |
| 1774 | clear_bit(R5_InJournal, &dev->flags); |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1775 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1776 | chosen = dev->towrite; |
| 1777 | dev->towrite = NULL; |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1778 | sh->overwrite_disks = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1779 | BUG_ON(dev->written); |
| 1780 | wbi = dev->written = chosen; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 1781 | spin_unlock_irq(&sh->stripe_lock); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1782 | WARN_ON(dev->page != dev->orig_page); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1783 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1784 | while (wbi && wbi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1785 | dev->sector + RAID5_STRIPE_SECTORS(conf)) { |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1786 | if (wbi->bi_opf & REQ_FUA) |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1787 | set_bit(R5_WantFUA, &dev->flags); |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 1788 | if (wbi->bi_opf & REQ_SYNC) |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1789 | set_bit(R5_SyncIO, &dev->flags); |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 1790 | if (bio_op(wbi) == REQ_OP_DISCARD) |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1791 | set_bit(R5_Discard, &dev->flags); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1792 | else { |
| 1793 | tx = async_copy_data(1, wbi, &dev->page, |
Yufen Yu | 248728d | 2020-08-20 09:22:07 -0400 | [diff] [blame^] | 1794 | dev->offset, |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1795 | dev->sector, tx, sh, |
| 1796 | r5c_is_writeback(conf->log)); |
| 1797 | if (dev->page != dev->orig_page && |
| 1798 | !r5c_is_writeback(conf->log)) { |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 1799 | set_bit(R5_SkipCopy, &dev->flags); |
| 1800 | clear_bit(R5_UPTODATE, &dev->flags); |
| 1801 | clear_bit(R5_OVERWRITE, &dev->flags); |
| 1802 | } |
| 1803 | } |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1804 | wbi = r5_next_bio(conf, wbi, dev->sector); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1805 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1806 | |
| 1807 | if (head_sh->batch_head) { |
| 1808 | sh = list_first_entry(&sh->batch_list, |
| 1809 | struct stripe_head, |
| 1810 | batch_list); |
| 1811 | if (sh == head_sh) |
| 1812 | continue; |
| 1813 | goto again; |
| 1814 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | return tx; |
| 1819 | } |
| 1820 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1821 | static void ops_complete_reconstruct(void *stripe_head_ref) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1822 | { |
| 1823 | struct stripe_head *sh = stripe_head_ref; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1824 | int disks = sh->disks; |
| 1825 | int pd_idx = sh->pd_idx; |
| 1826 | int qd_idx = sh->qd_idx; |
| 1827 | int i; |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1828 | bool fua = false, sync = false, discard = false; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1829 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1830 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1831 | (unsigned long long)sh->sector); |
| 1832 | |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1833 | for (i = disks; i--; ) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1834 | fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1835 | sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1836 | discard |= test_bit(R5_Discard, &sh->dev[i].flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1837 | } |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1838 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1839 | for (i = disks; i--; ) { |
| 1840 | struct r5dev *dev = &sh->dev[i]; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1841 | |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1842 | if (dev->written || i == pd_idx || i == qd_idx) { |
NeilBrown | 235b600 | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 1843 | if (!discard && !test_bit(R5_SkipCopy, &dev->flags)) { |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 1844 | set_bit(R5_UPTODATE, &dev->flags); |
NeilBrown | 235b600 | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 1845 | if (test_bit(STRIPE_EXPAND_READY, &sh->state)) |
| 1846 | set_bit(R5_Expanded, &dev->flags); |
| 1847 | } |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1848 | if (fua) |
| 1849 | set_bit(R5_WantFUA, &dev->flags); |
Shaohua Li | bc0934f | 2012-05-22 13:55:05 +1000 | [diff] [blame] | 1850 | if (sync) |
| 1851 | set_bit(R5_SyncIO, &dev->flags); |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 1852 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1855 | if (sh->reconstruct_state == reconstruct_state_drain_run) |
| 1856 | sh->reconstruct_state = reconstruct_state_drain_result; |
| 1857 | else if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) |
| 1858 | sh->reconstruct_state = reconstruct_state_prexor_drain_result; |
| 1859 | else { |
| 1860 | BUG_ON(sh->reconstruct_state != reconstruct_state_run); |
| 1861 | sh->reconstruct_state = reconstruct_state_result; |
| 1862 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1863 | |
| 1864 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 1865 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | static void |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1869 | ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1870 | struct dma_async_tx_descriptor *tx) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1871 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1872 | int disks = sh->disks; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1873 | struct page **xor_srcs; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1874 | unsigned int *off_srcs; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1875 | struct async_submit_ctl submit; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1876 | int count, pd_idx = sh->pd_idx, i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1877 | struct page *xor_dest; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1878 | unsigned int off_dest; |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1879 | int prexor = 0; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1880 | unsigned long flags; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1881 | int j = 0; |
| 1882 | struct stripe_head *head_sh = sh; |
| 1883 | int last_stripe; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1884 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 1885 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1886 | (unsigned long long)sh->sector); |
| 1887 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1888 | for (i = 0; i < sh->disks; i++) { |
| 1889 | if (pd_idx == i) |
| 1890 | continue; |
| 1891 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1892 | break; |
| 1893 | } |
| 1894 | if (i >= sh->disks) { |
| 1895 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1896 | set_bit(R5_Discard, &sh->dev[pd_idx].flags); |
| 1897 | ops_complete_reconstruct(sh); |
| 1898 | return; |
| 1899 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1900 | again: |
| 1901 | count = 0; |
| 1902 | xor_srcs = to_addr_page(percpu, j); |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1903 | off_srcs = to_addr_offs(sh, percpu); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1904 | /* check if prexor is active which means only process blocks |
| 1905 | * that are part of a read-modify-write (written) |
| 1906 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1907 | if (head_sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 1908 | prexor = 1; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1909 | off_dest = off_srcs[count] = sh->dev[pd_idx].offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1910 | xor_dest = xor_srcs[count++] = sh->dev[pd_idx].page; |
| 1911 | for (i = disks; i--; ) { |
| 1912 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 1913 | if (head_sh->dev[i].written || |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1914 | test_bit(R5_InJournal, &head_sh->dev[i].flags)) { |
| 1915 | off_srcs[count] = dev->offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1916 | xor_srcs[count++] = dev->page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1917 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1918 | } |
| 1919 | } else { |
| 1920 | xor_dest = sh->dev[pd_idx].page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1921 | off_dest = sh->dev[pd_idx].offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1922 | for (i = disks; i--; ) { |
| 1923 | struct r5dev *dev = &sh->dev[i]; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1924 | if (i != pd_idx) { |
| 1925 | off_srcs[count] = dev->offset; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1926 | xor_srcs[count++] = dev->page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1927 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1931 | /* 1/ if we prexor'd then the dest is reused as a source |
| 1932 | * 2/ if we did not prexor then we are redoing the parity |
| 1933 | * set ASYNC_TX_XOR_DROP_DST and ASYNC_TX_XOR_ZERO_DST |
| 1934 | * for the synchronous xor case |
| 1935 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1936 | last_stripe = !head_sh->batch_head || |
| 1937 | list_first_entry(&sh->batch_list, |
| 1938 | struct stripe_head, batch_list) == head_sh; |
| 1939 | if (last_stripe) { |
| 1940 | flags = ASYNC_TX_ACK | |
| 1941 | (prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1942 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1943 | atomic_inc(&head_sh->count); |
| 1944 | init_async_submit(&submit, flags, tx, ops_complete_reconstruct, head_sh, |
| 1945 | to_addr_conv(sh, percpu, j)); |
| 1946 | } else { |
| 1947 | flags = prexor ? ASYNC_TX_XOR_DROP_DST : ASYNC_TX_XOR_ZERO_DST; |
| 1948 | init_async_submit(&submit, flags, tx, NULL, NULL, |
| 1949 | to_addr_conv(sh, percpu, j)); |
| 1950 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1951 | |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1952 | if (unlikely(count == 1)) |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 1953 | tx = async_memcpy(xor_dest, xor_srcs[0], off_dest, off_srcs[0], |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1954 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 1955 | else |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 1956 | tx = async_xor(xor_dest, xor_srcs, 0, count, |
| 1957 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1958 | if (!last_stripe) { |
| 1959 | j++; |
| 1960 | sh = list_first_entry(&sh->batch_list, struct stripe_head, |
| 1961 | batch_list); |
| 1962 | goto again; |
| 1963 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1966 | static void |
| 1967 | ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, |
| 1968 | struct dma_async_tx_descriptor *tx) |
| 1969 | { |
| 1970 | struct async_submit_ctl submit; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1971 | struct page **blocks; |
| 1972 | int count, i, j = 0; |
| 1973 | struct stripe_head *head_sh = sh; |
| 1974 | int last_stripe; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1975 | int synflags; |
| 1976 | unsigned long txflags; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 1977 | |
| 1978 | pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector); |
| 1979 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1980 | for (i = 0; i < sh->disks; i++) { |
| 1981 | if (sh->pd_idx == i || sh->qd_idx == i) |
| 1982 | continue; |
| 1983 | if (!test_bit(R5_Discard, &sh->dev[i].flags)) |
| 1984 | break; |
| 1985 | } |
| 1986 | if (i >= sh->disks) { |
| 1987 | atomic_inc(&sh->count); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 1988 | set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 1989 | set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 1990 | ops_complete_reconstruct(sh); |
| 1991 | return; |
| 1992 | } |
| 1993 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 1994 | again: |
| 1995 | blocks = to_addr_page(percpu, j); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 1996 | |
| 1997 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) { |
| 1998 | synflags = SYNDROME_SRC_WRITTEN; |
| 1999 | txflags = ASYNC_TX_ACK | ASYNC_TX_PQ_XOR_DST; |
| 2000 | } else { |
| 2001 | synflags = SYNDROME_SRC_ALL; |
| 2002 | txflags = ASYNC_TX_ACK; |
| 2003 | } |
| 2004 | |
| 2005 | count = set_syndrome_sources(blocks, sh, synflags); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2006 | last_stripe = !head_sh->batch_head || |
| 2007 | list_first_entry(&sh->batch_list, |
| 2008 | struct stripe_head, batch_list) == head_sh; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2009 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2010 | if (last_stripe) { |
| 2011 | atomic_inc(&head_sh->count); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 2012 | init_async_submit(&submit, txflags, tx, ops_complete_reconstruct, |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2013 | head_sh, to_addr_conv(sh, percpu, j)); |
| 2014 | } else |
| 2015 | init_async_submit(&submit, 0, tx, NULL, NULL, |
| 2016 | to_addr_conv(sh, percpu, j)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2017 | tx = async_gen_syndrome(blocks, 0, count+2, |
| 2018 | RAID5_STRIPE_SIZE(sh->raid_conf), &submit); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2019 | if (!last_stripe) { |
| 2020 | j++; |
| 2021 | sh = list_first_entry(&sh->batch_list, struct stripe_head, |
| 2022 | batch_list); |
| 2023 | goto again; |
| 2024 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | static void ops_complete_check(void *stripe_head_ref) |
| 2028 | { |
| 2029 | struct stripe_head *sh = stripe_head_ref; |
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 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 2034 | sh->check_state = check_state_check_result; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2035 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2036 | raid5_release_stripe(sh); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2039 | 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] | 2040 | { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2041 | int disks = sh->disks; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2042 | int pd_idx = sh->pd_idx; |
| 2043 | int qd_idx = sh->qd_idx; |
| 2044 | struct page *xor_dest; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2045 | struct page **xor_srcs = to_addr_page(percpu, 0); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2046 | struct dma_async_tx_descriptor *tx; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2047 | struct async_submit_ctl submit; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2048 | int count; |
| 2049 | int i; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2050 | |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 2051 | pr_debug("%s: stripe %llu\n", __func__, |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2052 | (unsigned long long)sh->sector); |
| 2053 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2054 | BUG_ON(sh->batch_head); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2055 | count = 0; |
| 2056 | xor_dest = sh->dev[pd_idx].page; |
| 2057 | xor_srcs[count++] = xor_dest; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2058 | for (i = disks; i--; ) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2059 | if (i == pd_idx || i == qd_idx) |
| 2060 | continue; |
| 2061 | xor_srcs[count++] = sh->dev[i].page; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2064 | init_async_submit(&submit, 0, NULL, NULL, NULL, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2065 | to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2066 | tx = async_xor_val(xor_dest, xor_srcs, 0, count, |
| 2067 | RAID5_STRIPE_SIZE(sh->raid_conf), |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2068 | &sh->ops.zero_sum_result, &submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2069 | |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2070 | atomic_inc(&sh->count); |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 2071 | init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_check, sh, NULL); |
| 2072 | tx = async_trigger_callback(&submit); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2075 | static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu, int checkp) |
| 2076 | { |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2077 | struct page **srcs = to_addr_page(percpu, 0); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2078 | struct async_submit_ctl submit; |
| 2079 | int count; |
| 2080 | |
| 2081 | pr_debug("%s: stripe %llu checkp: %d\n", __func__, |
| 2082 | (unsigned long long)sh->sector, checkp); |
| 2083 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2084 | BUG_ON(sh->batch_head); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 2085 | count = set_syndrome_sources(srcs, sh, SYNDROME_SRC_ALL); |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2086 | if (!checkp) |
| 2087 | srcs[count] = NULL; |
| 2088 | |
| 2089 | atomic_inc(&sh->count); |
| 2090 | init_async_submit(&submit, ASYNC_TX_ACK, NULL, ops_complete_check, |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 2091 | sh, to_addr_conv(sh, percpu, 0)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2092 | async_syndrome_val(srcs, 0, count+2, |
| 2093 | RAID5_STRIPE_SIZE(sh->raid_conf), |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2094 | &sh->ops.zero_sum_result, percpu->spare_page, &submit); |
| 2095 | } |
| 2096 | |
NeilBrown | 51acbce | 2013-02-28 09:08:34 +1100 | [diff] [blame] | 2097 | 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] | 2098 | { |
| 2099 | int overlap_clear = 0, i, disks = sh->disks; |
| 2100 | struct dma_async_tx_descriptor *tx = NULL; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2101 | struct r5conf *conf = sh->raid_conf; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2102 | int level = conf->level; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2103 | struct raid5_percpu *percpu; |
| 2104 | unsigned long cpu; |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2105 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2106 | cpu = get_cpu(); |
| 2107 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Dan Williams | 83de75c | 2008-06-28 08:31:58 +1000 | [diff] [blame] | 2108 | if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) { |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2109 | ops_run_biofill(sh); |
| 2110 | overlap_clear++; |
| 2111 | } |
| 2112 | |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 2113 | if (test_bit(STRIPE_OP_COMPUTE_BLK, &ops_request)) { |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2114 | if (level < 6) |
| 2115 | tx = ops_run_compute5(sh, percpu); |
| 2116 | else { |
| 2117 | if (sh->ops.target2 < 0 || sh->ops.target < 0) |
| 2118 | tx = ops_run_compute6_1(sh, percpu); |
| 2119 | else |
| 2120 | tx = ops_run_compute6_2(sh, percpu); |
| 2121 | } |
| 2122 | /* terminate the chain if reconstruct is not set to be run */ |
| 2123 | if (tx && !test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) |
Dan Williams | 7b3a871 | 2008-06-28 08:32:09 +1000 | [diff] [blame] | 2124 | async_tx_ack(tx); |
| 2125 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2126 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 2127 | if (test_bit(STRIPE_OP_PREXOR, &ops_request)) { |
| 2128 | if (level < 6) |
| 2129 | tx = ops_run_prexor5(sh, percpu, tx); |
| 2130 | else |
| 2131 | tx = ops_run_prexor6(sh, percpu, tx); |
| 2132 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2133 | |
Artur Paszkiewicz | ae1713e | 2017-04-04 13:13:58 +0200 | [diff] [blame] | 2134 | if (test_bit(STRIPE_OP_PARTIAL_PARITY, &ops_request)) |
| 2135 | tx = ops_run_partial_parity(sh, percpu, tx); |
| 2136 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 2137 | if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) { |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 2138 | tx = ops_run_biodrain(sh, tx); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2139 | overlap_clear++; |
| 2140 | } |
| 2141 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2142 | if (test_bit(STRIPE_OP_RECONSTRUCT, &ops_request)) { |
| 2143 | if (level < 6) |
| 2144 | ops_run_reconstruct5(sh, percpu, tx); |
| 2145 | else |
| 2146 | ops_run_reconstruct6(sh, percpu, tx); |
| 2147 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2148 | |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 2149 | if (test_bit(STRIPE_OP_CHECK, &ops_request)) { |
| 2150 | if (sh->check_state == check_state_run) |
| 2151 | ops_run_check_p(sh, percpu); |
| 2152 | else if (sh->check_state == check_state_run_q) |
| 2153 | ops_run_check_pq(sh, percpu, 0); |
| 2154 | else if (sh->check_state == check_state_run_pq) |
| 2155 | ops_run_check_pq(sh, percpu, 1); |
| 2156 | else |
| 2157 | BUG(); |
| 2158 | } |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2159 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2160 | if (overlap_clear && !sh->batch_head) |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2161 | for (i = disks; i--; ) { |
| 2162 | struct r5dev *dev = &sh->dev[i]; |
| 2163 | if (test_and_clear_bit(R5_Overlap, &dev->flags)) |
| 2164 | wake_up(&sh->raid_conf->wait_for_overlap); |
| 2165 | } |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2166 | put_cpu(); |
Dan Williams | 91c0092 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2169 | static void free_stripe(struct kmem_cache *sc, struct stripe_head *sh) |
| 2170 | { |
| 2171 | if (sh->ppl_page) |
| 2172 | __free_page(sh->ppl_page); |
| 2173 | kmem_cache_free(sc, sh); |
| 2174 | } |
| 2175 | |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2176 | static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp, |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2177 | int disks, struct r5conf *conf) |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2178 | { |
| 2179 | struct stripe_head *sh; |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2180 | int i; |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2181 | |
| 2182 | sh = kmem_cache_zalloc(sc, gfp); |
| 2183 | if (sh) { |
| 2184 | spin_lock_init(&sh->stripe_lock); |
| 2185 | spin_lock_init(&sh->batch_lock); |
| 2186 | INIT_LIST_HEAD(&sh->batch_list); |
| 2187 | INIT_LIST_HEAD(&sh->lru); |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 2188 | INIT_LIST_HEAD(&sh->r5c); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 2189 | INIT_LIST_HEAD(&sh->log_list); |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2190 | atomic_set(&sh->count, 1); |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2191 | sh->raid_conf = conf; |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 2192 | sh->log_start = MaxSector; |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2193 | for (i = 0; i < disks; i++) { |
| 2194 | struct r5dev *dev = &sh->dev[i]; |
| 2195 | |
Ming Lei | 3a83f46 | 2016-11-22 08:57:21 -0700 | [diff] [blame] | 2196 | bio_init(&dev->req, &dev->vec, 1); |
| 2197 | bio_init(&dev->rreq, &dev->rvec, 1); |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2198 | } |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2199 | |
| 2200 | if (raid5_has_ppl(conf)) { |
| 2201 | sh->ppl_page = alloc_page(gfp); |
| 2202 | if (!sh->ppl_page) { |
| 2203 | free_stripe(sc, sh); |
| 2204 | sh = NULL; |
| 2205 | } |
| 2206 | } |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2207 | } |
| 2208 | return sh; |
| 2209 | } |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2210 | static int grow_one_stripe(struct r5conf *conf, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | { |
| 2212 | struct stripe_head *sh; |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2213 | |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2214 | sh = alloc_stripe(conf->slab_cache, gfp, conf->pool_size, conf); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2215 | if (!sh) |
| 2216 | return 0; |
Namhyung Kim | 6ce3284 | 2011-07-18 17:38:50 +1000 | [diff] [blame] | 2217 | |
NeilBrown | a9683a7 | 2015-02-25 12:02:51 +1100 | [diff] [blame] | 2218 | if (grow_buffers(sh, gfp)) { |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 2219 | shrink_buffers(sh); |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2220 | free_stripe(conf->slab_cache, sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2221 | return 0; |
| 2222 | } |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2223 | sh->hash_lock_index = |
| 2224 | conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2225 | /* we just created an active stripe so... */ |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2226 | atomic_inc(&conf->active_stripes); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2227 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2228 | raid5_release_stripe(sh); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2229 | conf->max_nr_stripes++; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2230 | return 1; |
| 2231 | } |
| 2232 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2233 | static int grow_stripes(struct r5conf *conf, int num) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2234 | { |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 2235 | struct kmem_cache *sc; |
Arnd Bergmann | 53b8d89 | 2018-02-20 14:09:11 +0100 | [diff] [blame] | 2236 | size_t namelen = sizeof(conf->cache_name[0]); |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 2237 | int devs = max(conf->raid_disks, conf->previous_raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 2239 | if (conf->mddev->gendisk) |
Arnd Bergmann | 53b8d89 | 2018-02-20 14:09:11 +0100 | [diff] [blame] | 2240 | snprintf(conf->cache_name[0], namelen, |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 2241 | "raid%d-%s", conf->level, mdname(conf->mddev)); |
| 2242 | else |
Arnd Bergmann | 53b8d89 | 2018-02-20 14:09:11 +0100 | [diff] [blame] | 2243 | snprintf(conf->cache_name[0], namelen, |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 2244 | "raid%d-%p", conf->level, conf->mddev); |
Arnd Bergmann | 53b8d89 | 2018-02-20 14:09:11 +0100 | [diff] [blame] | 2245 | snprintf(conf->cache_name[1], namelen, "%.27s-alt", conf->cache_name[0]); |
NeilBrown | f4be6b4 | 2010-06-01 19:37:25 +1000 | [diff] [blame] | 2246 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2247 | conf->active_name = 0; |
| 2248 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2250 | 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | if (!sc) |
| 2252 | return 1; |
| 2253 | conf->slab_cache = sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2254 | conf->pool_size = devs; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2255 | while (num--) |
| 2256 | if (!grow_one_stripe(conf, GFP_KERNEL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | return 1; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | return 0; |
| 2260 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 2261 | |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2262 | /** |
Coly Li | 7f8a30e | 2020-04-09 22:17:22 +0800 | [diff] [blame] | 2263 | * scribble_alloc - allocate percpu scribble buffer for required size |
| 2264 | * of the scribble region |
Damien Le Moal | 2aada5b | 2020-07-16 13:54:42 +0900 | [diff] [blame] | 2265 | * @percpu: from for_each_present_cpu() of the caller |
| 2266 | * @num: total number of disks in the array |
| 2267 | * @cnt: scribble objs count for required size of the scribble region |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2268 | * |
Coly Li | 7f8a30e | 2020-04-09 22:17:22 +0800 | [diff] [blame] | 2269 | * The scribble buffer size must be enough to contain: |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2270 | * 1/ a struct page pointer for each device in the array +2 |
| 2271 | * 2/ room to convert each entry in (1) to its corresponding dma |
| 2272 | * (dma_map_page()) or page (page_address()) address. |
| 2273 | * |
| 2274 | * Note: the +2 is for the destination buffers of the ddf/raid6 case where we |
| 2275 | * calculate over all devices (not just the data blocks), using zeros in place |
| 2276 | * of the P and Q blocks. |
| 2277 | */ |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2278 | static int scribble_alloc(struct raid5_percpu *percpu, |
Coly Li | ba54d4d | 2020-04-09 22:17:21 +0800 | [diff] [blame] | 2279 | int num, int cnt) |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2280 | { |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2281 | size_t obj_size = |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 2282 | sizeof(struct page *) * (num + 2) + |
| 2283 | sizeof(addr_conv_t) * (num + 2) + |
| 2284 | sizeof(unsigned int) * (num + 2); |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2285 | void *scribble; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2286 | |
Coly Li | ba54d4d | 2020-04-09 22:17:21 +0800 | [diff] [blame] | 2287 | /* |
| 2288 | * If here is in raid array suspend context, it is in memalloc noio |
| 2289 | * context as well, there is no potential recursive memory reclaim |
| 2290 | * I/Os with the GFP_KERNEL flag. |
| 2291 | */ |
| 2292 | scribble = kvmalloc_array(cnt, obj_size, GFP_KERNEL); |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2293 | if (!scribble) |
| 2294 | return -ENOMEM; |
| 2295 | |
| 2296 | kvfree(percpu->scribble); |
| 2297 | |
| 2298 | percpu->scribble = scribble; |
| 2299 | percpu->scribble_obj_size = obj_size; |
| 2300 | return 0; |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2303 | static int resize_chunks(struct r5conf *conf, int new_disks, int new_sectors) |
| 2304 | { |
| 2305 | unsigned long cpu; |
| 2306 | int err = 0; |
| 2307 | |
Shaohua Li | 27a353c | 2016-02-24 17:38:28 -0800 | [diff] [blame] | 2308 | /* |
| 2309 | * Never shrink. And mddev_suspend() could deadlock if this is called |
| 2310 | * from raid5d. In that case, scribble_disks and scribble_sectors |
| 2311 | * should equal to new_disks and new_sectors |
| 2312 | */ |
| 2313 | if (conf->scribble_disks >= new_disks && |
| 2314 | conf->scribble_sectors >= new_sectors) |
| 2315 | return 0; |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2316 | mddev_suspend(conf->mddev); |
| 2317 | get_online_cpus(); |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2318 | |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2319 | for_each_present_cpu(cpu) { |
| 2320 | struct raid5_percpu *percpu; |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2321 | |
| 2322 | percpu = per_cpu_ptr(conf->percpu, cpu); |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2323 | err = scribble_alloc(percpu, new_disks, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2324 | new_sectors / RAID5_STRIPE_SECTORS(conf)); |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2325 | if (err) |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2326 | break; |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2327 | } |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 2328 | |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2329 | put_online_cpus(); |
| 2330 | mddev_resume(conf->mddev); |
Shaohua Li | 27a353c | 2016-02-24 17:38:28 -0800 | [diff] [blame] | 2331 | if (!err) { |
| 2332 | conf->scribble_disks = new_disks; |
| 2333 | conf->scribble_sectors = new_sectors; |
| 2334 | } |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 2335 | return err; |
| 2336 | } |
| 2337 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2338 | static int resize_stripes(struct r5conf *conf, int newsize) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2339 | { |
| 2340 | /* Make all the stripes able to hold 'newsize' devices. |
| 2341 | * New slots in each stripe get 'page' set to a new page. |
| 2342 | * |
| 2343 | * This happens in stages: |
| 2344 | * 1/ create a new kmem_cache and allocate the required number of |
| 2345 | * stripe_heads. |
Masanari Iida | 83f0d77 | 2012-10-30 00:18:08 +0900 | [diff] [blame] | 2346 | * 2/ gather all the old stripe_heads and transfer the pages across |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2347 | * to the new stripe_heads. This will have the side effect of |
| 2348 | * freezing the array as once all stripe_heads have been collected, |
| 2349 | * no IO will be possible. Old stripe heads are freed once their |
| 2350 | * pages have been transferred over, and the old kmem_cache is |
| 2351 | * freed when all stripes are done. |
| 2352 | * 3/ reallocate conf->disks to be suitable bigger. If this fails, |
Zhilong Liu | 3560741e | 2017-03-15 16:14:53 +0800 | [diff] [blame] | 2353 | * we simple return a failure status - no need to clean anything up. |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2354 | * 4/ allocate new pages for the new slots in the new stripe_heads. |
| 2355 | * If this fails, we don't bother trying the shrink the |
| 2356 | * stripe_heads down again, we just leave them as they are. |
| 2357 | * As each stripe_head is processed the new one is released into |
| 2358 | * active service. |
| 2359 | * |
| 2360 | * Once step2 is started, we cannot afford to wait for a write, |
| 2361 | * so we use GFP_NOIO allocations. |
| 2362 | */ |
| 2363 | struct stripe_head *osh, *nsh; |
| 2364 | LIST_HEAD(newstripes); |
| 2365 | struct disk_info *ndisks; |
Artur Paszkiewicz | 2214c26 | 2017-05-08 11:56:55 +0200 | [diff] [blame] | 2366 | int err = 0; |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 2367 | struct kmem_cache *sc; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2368 | int i; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2369 | int hash, cnt; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2370 | |
Artur Paszkiewicz | 2214c26 | 2017-05-08 11:56:55 +0200 | [diff] [blame] | 2371 | md_allow_write(conf->mddev); |
NeilBrown | 2a2275d | 2007-01-26 00:57:11 -0800 | [diff] [blame] | 2372 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2373 | /* Step 1 */ |
| 2374 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
| 2375 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2376 | 0, 0, NULL); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2377 | if (!sc) |
| 2378 | return -ENOMEM; |
| 2379 | |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 2380 | /* Need to ensure auto-resizing doesn't interfere */ |
| 2381 | mutex_lock(&conf->cache_size_mutex); |
| 2382 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2383 | for (i = conf->max_nr_stripes; i; i--) { |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2384 | nsh = alloc_stripe(sc, GFP_KERNEL, newsize, conf); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2385 | if (!nsh) |
| 2386 | break; |
| 2387 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2388 | list_add(&nsh->lru, &newstripes); |
| 2389 | } |
| 2390 | if (i) { |
| 2391 | /* didn't get enough, give up */ |
| 2392 | while (!list_empty(&newstripes)) { |
| 2393 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 2394 | list_del(&nsh->lru); |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2395 | free_stripe(sc, nsh); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2396 | } |
| 2397 | kmem_cache_destroy(sc); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 2398 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2399 | return -ENOMEM; |
| 2400 | } |
| 2401 | /* Step 2 - Must use GFP_NOIO now. |
| 2402 | * OK, we have enough stripes, start collecting inactive |
| 2403 | * stripes and copying them over |
| 2404 | */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2405 | hash = 0; |
| 2406 | cnt = 0; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2407 | list_for_each_entry(nsh, &newstripes, lru) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2408 | lock_device_hash_lock(conf, hash); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 2409 | wait_event_cmd(conf->wait_for_stripe, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2410 | !list_empty(conf->inactive_list + hash), |
| 2411 | unlock_device_hash_lock(conf, hash), |
| 2412 | lock_device_hash_lock(conf, hash)); |
| 2413 | osh = get_free_stripe(conf, hash); |
| 2414 | unlock_device_hash_lock(conf, hash); |
NeilBrown | f18c1a3 | 2015-05-08 18:19:04 +1000 | [diff] [blame] | 2415 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2416 | for(i=0; i<conf->pool_size; i++) { |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2417 | nsh->dev[i].page = osh->dev[i].page; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2418 | nsh->dev[i].orig_page = osh->dev[i].page; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 2419 | nsh->dev[i].offset = osh->dev[i].offset; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2420 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2421 | nsh->hash_lock_index = hash; |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2422 | free_stripe(conf->slab_cache, osh); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2423 | cnt++; |
| 2424 | if (cnt >= conf->max_nr_stripes / NR_STRIPE_HASH_LOCKS + |
| 2425 | !!((conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS) > hash)) { |
| 2426 | hash++; |
| 2427 | cnt = 0; |
| 2428 | } |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2429 | } |
| 2430 | kmem_cache_destroy(conf->slab_cache); |
| 2431 | |
| 2432 | /* Step 3. |
| 2433 | * At this point, we are holding all the stripes so the array |
| 2434 | * is completely stalled, so now is a good time to resize |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2435 | * conf->disks and the scribble region |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2436 | */ |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2437 | ndisks = kcalloc(newsize, sizeof(struct disk_info), GFP_NOIO); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2438 | if (ndisks) { |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 2439 | for (i = 0; i < conf->pool_size; i++) |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2440 | ndisks[i] = conf->disks[i]; |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 2441 | |
| 2442 | for (i = conf->pool_size; i < newsize; i++) { |
| 2443 | ndisks[i].extra_page = alloc_page(GFP_NOIO); |
| 2444 | if (!ndisks[i].extra_page) |
| 2445 | err = -ENOMEM; |
| 2446 | } |
| 2447 | |
| 2448 | if (err) { |
| 2449 | for (i = conf->pool_size; i < newsize; i++) |
| 2450 | if (ndisks[i].extra_page) |
| 2451 | put_page(ndisks[i].extra_page); |
| 2452 | kfree(ndisks); |
| 2453 | } else { |
| 2454 | kfree(conf->disks); |
| 2455 | conf->disks = ndisks; |
| 2456 | } |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2457 | } else |
| 2458 | err = -ENOMEM; |
| 2459 | |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 2460 | mutex_unlock(&conf->cache_size_mutex); |
Dennis Yang | 583da48 | 2017-03-29 15:46:13 +0800 | [diff] [blame] | 2461 | |
| 2462 | conf->slab_cache = sc; |
| 2463 | conf->active_name = 1-conf->active_name; |
| 2464 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2465 | /* Step 4, return new stripes to service */ |
| 2466 | while(!list_empty(&newstripes)) { |
| 2467 | nsh = list_entry(newstripes.next, struct stripe_head, lru); |
| 2468 | list_del_init(&nsh->lru); |
Dan Williams | d6f38f3 | 2009-07-14 11:50:52 -0700 | [diff] [blame] | 2469 | |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2470 | for (i=conf->raid_disks; i < newsize; i++) |
| 2471 | if (nsh->dev[i].page == NULL) { |
| 2472 | struct page *p = alloc_page(GFP_NOIO); |
| 2473 | nsh->dev[i].page = p; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 2474 | nsh->dev[i].orig_page = p; |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 2475 | nsh->dev[i].offset = 0; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2476 | if (!p) |
| 2477 | err = -ENOMEM; |
| 2478 | } |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2479 | raid5_release_stripe(nsh); |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2480 | } |
| 2481 | /* critical section pass, GFP_NOIO no longer needed */ |
| 2482 | |
NeilBrown | 6e9eac2 | 2015-05-08 18:19:34 +1000 | [diff] [blame] | 2483 | if (!err) |
| 2484 | conf->pool_size = newsize; |
NeilBrown | ad01c9e | 2006-03-27 01:18:07 -0800 | [diff] [blame] | 2485 | return err; |
| 2486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2488 | static int drop_one_stripe(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | { |
| 2490 | struct stripe_head *sh; |
NeilBrown | 49895bc | 2015-08-03 17:09:57 +1000 | [diff] [blame] | 2491 | int hash = (conf->max_nr_stripes - 1) & STRIPE_HASH_LOCKS_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2493 | spin_lock_irq(conf->hash_locks + hash); |
| 2494 | sh = get_free_stripe(conf, hash); |
| 2495 | spin_unlock_irq(conf->hash_locks + hash); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2496 | if (!sh) |
| 2497 | return 0; |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 2498 | BUG_ON(atomic_read(&sh->count)); |
NeilBrown | e4e11e3 | 2010-06-16 16:45:16 +1000 | [diff] [blame] | 2499 | shrink_buffers(sh); |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 2500 | free_stripe(conf->slab_cache, sh); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2501 | atomic_dec(&conf->active_stripes); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2502 | conf->max_nr_stripes--; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2503 | return 1; |
| 2504 | } |
| 2505 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2506 | static void shrink_stripes(struct r5conf *conf) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2507 | { |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 2508 | while (conf->max_nr_stripes && |
| 2509 | drop_one_stripe(conf)) |
| 2510 | ; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 2511 | |
Julia Lawall | 644df1a | 2015-09-13 14:15:10 +0200 | [diff] [blame] | 2512 | kmem_cache_destroy(conf->slab_cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | conf->slab_cache = NULL; |
| 2514 | } |
| 2515 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2516 | static void raid5_end_read_request(struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2518 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2519 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 2520 | int disks = sh->disks, i; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 2521 | char b[BDEVNAME_SIZE]; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2522 | struct md_rdev *rdev = NULL; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2523 | sector_t s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
| 2525 | for (i=0 ; i<disks; i++) |
| 2526 | if (bi == &sh->dev[i].req) |
| 2527 | break; |
| 2528 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2529 | pr_debug("end_read_request %llu/%d, count: %d, error %d.\n", |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 2530 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 2531 | bi->bi_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | if (i == disks) { |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2533 | bio_reset(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 2535 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2537 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2538 | /* If replacement finished while this request was outstanding, |
| 2539 | * 'replacement' might be NULL already. |
| 2540 | * In that case it moved down to 'rdev'. |
| 2541 | * rdev is not removed until all requests are finished. |
| 2542 | */ |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2543 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2544 | if (!rdev) |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2545 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2547 | if (use_new_offset(conf, sh)) |
| 2548 | s = sh->sector + rdev->new_data_offset; |
| 2549 | else |
| 2550 | s = sh->sector + rdev->data_offset; |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 2551 | if (!bi->bi_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | set_bit(R5_UPTODATE, &sh->dev[i].flags); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2553 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2554 | /* Note that this cannot happen on a |
| 2555 | * replacement device. We just fail those on |
| 2556 | * any error |
| 2557 | */ |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2558 | pr_info_ratelimited( |
| 2559 | "md/raid:%s: read error corrected (%lu sectors at %llu on %s)\n", |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2560 | mdname(conf->mddev), RAID5_STRIPE_SECTORS(conf), |
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 | bdevname(rdev->bdev, b)); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2563 | atomic_add(RAID5_STRIPE_SECTORS(conf), &rdev->corrected_errors); |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2564 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 2565 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 2566 | } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 2567 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 2568 | |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 2569 | if (test_bit(R5_InJournal, &sh->dev[i].flags)) |
| 2570 | /* |
| 2571 | * end read for a page in journal, this |
| 2572 | * must be preparing for prexor in rmw |
| 2573 | */ |
| 2574 | set_bit(R5_OrigPageUPTDODATE, &sh->dev[i].flags); |
| 2575 | |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2576 | if (atomic_read(&rdev->read_errors)) |
| 2577 | atomic_set(&rdev->read_errors, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | } else { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2579 | const char *bdn = bdevname(rdev->bdev, b); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2580 | int retry = 0; |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2581 | int set_bad = 0; |
NeilBrown | d695043 | 2006-07-10 04:44:20 -0700 | [diff] [blame] | 2582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | clear_bit(R5_UPTODATE, &sh->dev[i].flags); |
Nigel Croxon | b76b471 | 2019-09-06 09:21:33 -0400 | [diff] [blame] | 2584 | if (!(bi->bi_status == BLK_STS_PROTECTION)) |
| 2585 | atomic_inc(&rdev->read_errors); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2586 | if (test_bit(R5_ReadRepl, &sh->dev[i].flags)) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2587 | pr_warn_ratelimited( |
| 2588 | "md/raid:%s: read error on replacement device (sector %llu on %s).\n", |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2589 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2590 | (unsigned long long)s, |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2591 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2592 | else if (conf->mddev->degraded >= conf->max_degraded) { |
| 2593 | set_bad = 1; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2594 | pr_warn_ratelimited( |
| 2595 | "md/raid:%s: read error not correctable (sector %llu on %s).\n", |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2596 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2597 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2598 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2599 | } else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2600 | /* Oh, no!!! */ |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2601 | set_bad = 1; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2602 | pr_warn_ratelimited( |
| 2603 | "md/raid:%s: read error NOT corrected!! (sector %llu on %s).\n", |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2604 | mdname(conf->mddev), |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 2605 | (unsigned long long)s, |
Christian Dietrich | 8bda470 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2606 | bdn); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2607 | } else if (atomic_read(&rdev->read_errors) |
Nigel Croxon | 0009fad | 2019-08-21 09:27:08 -0400 | [diff] [blame] | 2608 | > conf->max_nr_stripes) { |
| 2609 | if (!test_bit(Faulty, &rdev->flags)) { |
| 2610 | pr_warn("md/raid:%s: %d read_errors > %d stripes\n", |
| 2611 | mdname(conf->mddev), |
| 2612 | atomic_read(&rdev->read_errors), |
| 2613 | conf->max_nr_stripes); |
| 2614 | pr_warn("md/raid:%s: Too many read errors, failing device %s.\n", |
| 2615 | mdname(conf->mddev), bdn); |
| 2616 | } |
| 2617 | } else |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2618 | retry = 1; |
Bian Yu | edfa1f6 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 2619 | if (set_bad && test_bit(In_sync, &rdev->flags) |
| 2620 | && !test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) |
| 2621 | retry = 1; |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2622 | if (retry) |
Xiao Ni | 143f6e7 | 2019-07-08 10:14:32 +0800 | [diff] [blame] | 2623 | if (sh->qd_idx >= 0 && sh->pd_idx == i) |
| 2624 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 2625 | else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) { |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 2626 | set_bit(R5_ReadError, &sh->dev[i].flags); |
| 2627 | clear_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
| 2628 | } else |
| 2629 | set_bit(R5_ReadNoMerge, &sh->dev[i].flags); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2630 | else { |
NeilBrown | 4e5314b | 2005-11-08 21:39:22 -0800 | [diff] [blame] | 2631 | clear_bit(R5_ReadError, &sh->dev[i].flags); |
| 2632 | clear_bit(R5_ReWrite, &sh->dev[i].flags); |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2633 | if (!(set_bad |
| 2634 | && test_bit(In_sync, &rdev->flags) |
| 2635 | && rdev_set_badblocks( |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2636 | rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), 0))) |
majianpeng | 2e8ac303 | 2012-07-03 15:57:02 +1000 | [diff] [blame] | 2637 | md_error(conf->mddev, rdev); |
NeilBrown | ba22dcb | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 2638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | } |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 2640 | rdev_dec_pending(rdev, conf->mddev); |
Shaohua Li | c944555 | 2016-09-08 10:43:58 -0700 | [diff] [blame] | 2641 | bio_reset(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
| 2643 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2644 | raid5_release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2647 | static void raid5_end_write_request(struct bio *bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2649 | struct stripe_head *sh = bi->bi_private; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2650 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 2651 | int disks = sh->disks, i; |
Kees Cook | 3f649ab | 2020-06-03 13:09:38 -0700 | [diff] [blame] | 2652 | struct md_rdev *rdev; |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 2653 | sector_t first_bad; |
| 2654 | int bad_sectors; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2655 | int replacement = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2657 | for (i = 0 ; i < disks; i++) { |
| 2658 | if (bi == &sh->dev[i].req) { |
| 2659 | rdev = conf->disks[i].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | break; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2661 | } |
| 2662 | if (bi == &sh->dev[i].rreq) { |
| 2663 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2664 | if (rdev) |
| 2665 | replacement = 1; |
| 2666 | else |
| 2667 | /* rdev was removed and 'replacement' |
| 2668 | * replaced it. rdev is not removed |
| 2669 | * until all requests are finished. |
| 2670 | */ |
| 2671 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2672 | break; |
| 2673 | } |
| 2674 | } |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 2675 | pr_debug("end_write_request %llu/%d, count %d, error: %d.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | (unsigned long long)sh->sector, i, atomic_read(&sh->count), |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 2677 | bi->bi_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | if (i == disks) { |
Shaohua Li | 5f9d1fd | 2016-08-22 21:14:01 -0700 | [diff] [blame] | 2679 | bio_reset(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | BUG(); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 2681 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2684 | if (replacement) { |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 2685 | if (bi->bi_status) |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2686 | md_error(conf->mddev, rdev); |
| 2687 | else if (is_badblock(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2688 | RAID5_STRIPE_SECTORS(conf), |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2689 | &first_bad, &bad_sectors)) |
| 2690 | set_bit(R5_MadeGoodRepl, &sh->dev[i].flags); |
| 2691 | } else { |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 2692 | if (bi->bi_status) { |
NeilBrown | 9f97e4b | 2014-01-16 09:35:38 +1100 | [diff] [blame] | 2693 | set_bit(STRIPE_DEGRADED, &sh->state); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2694 | set_bit(WriteErrorSeen, &rdev->flags); |
| 2695 | set_bit(R5_WriteError, &sh->dev[i].flags); |
NeilBrown | 3a6de29 | 2011-12-23 10:17:54 +1100 | [diff] [blame] | 2696 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) |
| 2697 | set_bit(MD_RECOVERY_NEEDED, |
| 2698 | &rdev->mddev->recovery); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2699 | } else if (is_badblock(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 2700 | RAID5_STRIPE_SECTORS(conf), |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 2701 | &first_bad, &bad_sectors)) { |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2702 | set_bit(R5_MadeGood, &sh->dev[i].flags); |
NeilBrown | c0b3297 | 2013-04-24 11:42:42 +1000 | [diff] [blame] | 2703 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) |
| 2704 | /* That was a successful write so make |
| 2705 | * sure it looks like we already did |
| 2706 | * a re-write. |
| 2707 | */ |
| 2708 | set_bit(R5_ReWrite, &sh->dev[i].flags); |
| 2709 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2710 | } |
| 2711 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 2713 | if (sh->batch_head && bi->bi_status && !replacement) |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2714 | set_bit(STRIPE_BATCH_ERR, &sh->batch_head->state); |
| 2715 | |
Shaohua Li | c944555 | 2016-09-08 10:43:58 -0700 | [diff] [blame] | 2716 | bio_reset(bi); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 2717 | if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) |
| 2718 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2720 | raid5_release_stripe(sh); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 2721 | |
| 2722 | if (sh->batch_head && sh != sh->batch_head) |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2723 | raid5_release_stripe(sh->batch_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 2726 | static void raid5_error(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | { |
| 2728 | char b[BDEVNAME_SIZE]; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2729 | struct r5conf *conf = mddev->private; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2730 | unsigned long flags; |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 2731 | pr_debug("raid456: error called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2733 | spin_lock_irqsave(&conf->device_lock, flags); |
Mariusz Tkaczyk | fb73b35 | 2018-09-04 15:08:30 +0200 | [diff] [blame] | 2734 | |
| 2735 | if (test_bit(In_sync, &rdev->flags) && |
| 2736 | mddev->degraded == conf->max_degraded) { |
| 2737 | /* |
| 2738 | * Don't allow to achieve failed state |
| 2739 | * Don't try to recover this device |
| 2740 | */ |
| 2741 | conf->recovery_disabled = mddev->recovery_disabled; |
| 2742 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 2743 | return; |
| 2744 | } |
| 2745 | |
bingjingc | aff69d8 | 2017-11-17 10:57:44 +0800 | [diff] [blame] | 2746 | set_bit(Faulty, &rdev->flags); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2747 | clear_bit(In_sync, &rdev->flags); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 2748 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 2749 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 2750 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 2751 | |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 2752 | set_bit(Blocked, &rdev->flags); |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 2753 | set_mask_bits(&mddev->sb_flags, 0, |
| 2754 | BIT(MD_SB_CHANGE_DEVS) | BIT(MD_SB_CHANGE_PENDING)); |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 2755 | pr_crit("md/raid:%s: Disk failure on %s, disabling device.\n" |
| 2756 | "md/raid:%s: Operation continuing on %d devices.\n", |
| 2757 | mdname(mddev), |
| 2758 | bdevname(rdev->bdev, b), |
| 2759 | mdname(mddev), |
| 2760 | conf->raid_disks - mddev->degraded); |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 2761 | r5c_update_on_rdev_error(mddev, rdev); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2762 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
| 2764 | /* |
| 2765 | * Input: a 'big' sector number, |
| 2766 | * Output: index of the data and parity disk, and the sector # in them. |
| 2767 | */ |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2768 | sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector, |
| 2769 | int previous, int *dd_idx, |
| 2770 | struct stripe_head *sh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | { |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2772 | sector_t stripe, stripe2; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2773 | sector_t chunk_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | unsigned int chunk_offset; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2775 | int pd_idx, qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2776 | int ddf_layout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | sector_t new_sector; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2778 | int algorithm = previous ? conf->prev_algo |
| 2779 | : conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2780 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2781 | : conf->chunk_sectors; |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2782 | int raid_disks = previous ? conf->previous_raid_disks |
| 2783 | : conf->raid_disks; |
| 2784 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | |
| 2786 | /* First compute the information on this sector */ |
| 2787 | |
| 2788 | /* |
| 2789 | * Compute the chunk number and the sector offset inside the chunk |
| 2790 | */ |
| 2791 | chunk_offset = sector_div(r_sector, sectors_per_chunk); |
| 2792 | chunk_number = r_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | |
| 2794 | /* |
| 2795 | * Compute the stripe number |
| 2796 | */ |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2797 | stripe = chunk_number; |
| 2798 | *dd_idx = sector_div(stripe, data_disks); |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2799 | stripe2 = stripe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | /* |
| 2801 | * Select the parity disk based on the user selected algorithm. |
| 2802 | */ |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 2803 | pd_idx = qd_idx = -1; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2804 | switch(conf->level) { |
| 2805 | case 4: |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2806 | pd_idx = data_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2807 | break; |
| 2808 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2809 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2811 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2812 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | (*dd_idx)++; |
| 2814 | break; |
| 2815 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2816 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2817 | if (*dd_idx >= pd_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | (*dd_idx)++; |
| 2819 | break; |
| 2820 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2821 | pd_idx = data_disks - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2822 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | break; |
| 2824 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2825 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2826 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2828 | case ALGORITHM_PARITY_0: |
| 2829 | pd_idx = 0; |
| 2830 | (*dd_idx)++; |
| 2831 | break; |
| 2832 | case ALGORITHM_PARITY_N: |
| 2833 | pd_idx = data_disks; |
| 2834 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2836 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2837 | } |
| 2838 | break; |
| 2839 | case 6: |
| 2840 | |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2841 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2842 | case ALGORITHM_LEFT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2843 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2844 | qd_idx = pd_idx + 1; |
| 2845 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2846 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2847 | qd_idx = 0; |
| 2848 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2849 | (*dd_idx) += 2; /* D D P Q D */ |
| 2850 | break; |
| 2851 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2852 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2853 | qd_idx = pd_idx + 1; |
| 2854 | if (pd_idx == raid_disks-1) { |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2855 | (*dd_idx)++; /* Q D D D P */ |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2856 | qd_idx = 0; |
| 2857 | } else if (*dd_idx >= pd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2858 | (*dd_idx) += 2; /* D D P Q D */ |
| 2859 | break; |
| 2860 | case ALGORITHM_LEFT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2861 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2862 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2863 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2864 | break; |
| 2865 | case ALGORITHM_RIGHT_SYMMETRIC: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2866 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2867 | qd_idx = (pd_idx + 1) % raid_disks; |
| 2868 | *dd_idx = (pd_idx + 2 + *dd_idx) % raid_disks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2869 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2870 | |
| 2871 | case ALGORITHM_PARITY_0: |
| 2872 | pd_idx = 0; |
| 2873 | qd_idx = 1; |
| 2874 | (*dd_idx) += 2; |
| 2875 | break; |
| 2876 | case ALGORITHM_PARITY_N: |
| 2877 | pd_idx = data_disks; |
| 2878 | qd_idx = data_disks + 1; |
| 2879 | break; |
| 2880 | |
| 2881 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 2882 | /* Exactly the same as RIGHT_ASYMMETRIC, but or |
| 2883 | * of blocks for computing Q is different. |
| 2884 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2885 | pd_idx = sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2886 | qd_idx = pd_idx + 1; |
| 2887 | if (pd_idx == raid_disks-1) { |
| 2888 | (*dd_idx)++; /* Q D D D P */ |
| 2889 | qd_idx = 0; |
| 2890 | } else if (*dd_idx >= pd_idx) |
| 2891 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2892 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2893 | break; |
| 2894 | |
| 2895 | case ALGORITHM_ROTATING_N_RESTART: |
| 2896 | /* Same a left_asymmetric, by first stripe is |
| 2897 | * D D D P Q rather than |
| 2898 | * Q D D D P |
| 2899 | */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2900 | stripe2 += 1; |
| 2901 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2902 | qd_idx = pd_idx + 1; |
| 2903 | if (pd_idx == raid_disks-1) { |
| 2904 | (*dd_idx)++; /* Q D D D P */ |
| 2905 | qd_idx = 0; |
| 2906 | } else if (*dd_idx >= pd_idx) |
| 2907 | (*dd_idx) += 2; /* D D P Q D */ |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2908 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2909 | break; |
| 2910 | |
| 2911 | case ALGORITHM_ROTATING_N_CONTINUE: |
| 2912 | /* Same as left_symmetric but Q is before P */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2913 | pd_idx = raid_disks - 1 - sector_div(stripe2, raid_disks); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2914 | qd_idx = (pd_idx + raid_disks - 1) % raid_disks; |
| 2915 | *dd_idx = (pd_idx + 1 + *dd_idx) % raid_disks; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2916 | ddf_layout = 1; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2917 | break; |
| 2918 | |
| 2919 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 2920 | /* RAID5 left_asymmetric, with Q on last device */ |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2921 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2922 | if (*dd_idx >= pd_idx) |
| 2923 | (*dd_idx)++; |
| 2924 | qd_idx = raid_disks - 1; |
| 2925 | break; |
| 2926 | |
| 2927 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2928 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2929 | if (*dd_idx >= pd_idx) |
| 2930 | (*dd_idx)++; |
| 2931 | qd_idx = raid_disks - 1; |
| 2932 | break; |
| 2933 | |
| 2934 | case ALGORITHM_LEFT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2935 | pd_idx = data_disks - sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2936 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2937 | qd_idx = raid_disks - 1; |
| 2938 | break; |
| 2939 | |
| 2940 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
NeilBrown | 6e3b96e | 2010-04-23 07:08:28 +1000 | [diff] [blame] | 2941 | pd_idx = sector_div(stripe2, raid_disks-1); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2942 | *dd_idx = (pd_idx + 1 + *dd_idx) % (raid_disks-1); |
| 2943 | qd_idx = raid_disks - 1; |
| 2944 | break; |
| 2945 | |
| 2946 | case ALGORITHM_PARITY_0_6: |
| 2947 | pd_idx = 0; |
| 2948 | (*dd_idx)++; |
| 2949 | qd_idx = raid_disks - 1; |
| 2950 | break; |
| 2951 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2952 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2953 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2954 | } |
| 2955 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | } |
| 2957 | |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2958 | if (sh) { |
| 2959 | sh->pd_idx = pd_idx; |
| 2960 | sh->qd_idx = qd_idx; |
NeilBrown | 67cc2b8 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2961 | sh->ddf_layout = ddf_layout; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | /* |
| 2964 | * Finally, compute the new sector number |
| 2965 | */ |
| 2966 | new_sector = (sector_t)stripe * sectors_per_chunk + chunk_offset; |
| 2967 | return new_sector; |
| 2968 | } |
| 2969 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 2970 | 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] | 2971 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 2972 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 2973 | int raid_disks = sh->disks; |
| 2974 | int data_disks = raid_disks - conf->max_degraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | sector_t new_sector = sh->sector, check; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 2976 | int sectors_per_chunk = previous ? conf->prev_chunk_sectors |
| 2977 | : conf->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2978 | int algorithm = previous ? conf->prev_algo |
| 2979 | : conf->algorithm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | sector_t stripe; |
| 2981 | int chunk_offset; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 2982 | sector_t chunk_number; |
| 2983 | int dummy1, dd_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | sector_t r_sector; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 2985 | struct stripe_head sh2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | |
| 2987 | chunk_offset = sector_div(new_sector, sectors_per_chunk); |
| 2988 | stripe = new_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 2990 | if (i == sh->pd_idx) |
| 2991 | return 0; |
| 2992 | switch(conf->level) { |
| 2993 | case 4: break; |
| 2994 | case 5: |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 2995 | switch (algorithm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 2997 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 2998 | if (i > sh->pd_idx) |
| 2999 | i--; |
| 3000 | break; |
| 3001 | case ALGORITHM_LEFT_SYMMETRIC: |
| 3002 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 3003 | if (i < sh->pd_idx) |
| 3004 | i += raid_disks; |
| 3005 | i -= (sh->pd_idx + 1); |
| 3006 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3007 | case ALGORITHM_PARITY_0: |
| 3008 | i -= 1; |
| 3009 | break; |
| 3010 | case ALGORITHM_PARITY_N: |
| 3011 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3013 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3014 | } |
| 3015 | break; |
| 3016 | case 6: |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3017 | if (i == sh->qd_idx) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3018 | return 0; /* It is the Q disk */ |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 3019 | switch (algorithm) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3020 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 3021 | case ALGORITHM_RIGHT_ASYMMETRIC: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3022 | case ALGORITHM_ROTATING_ZERO_RESTART: |
| 3023 | case ALGORITHM_ROTATING_N_RESTART: |
| 3024 | if (sh->pd_idx == raid_disks-1) |
| 3025 | i--; /* Q D D D P */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3026 | else if (i > sh->pd_idx) |
| 3027 | i -= 2; /* D D P Q D */ |
| 3028 | break; |
| 3029 | case ALGORITHM_LEFT_SYMMETRIC: |
| 3030 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 3031 | if (sh->pd_idx == raid_disks-1) |
| 3032 | i--; /* Q D D D P */ |
| 3033 | else { |
| 3034 | /* D D P Q D */ |
| 3035 | if (i < sh->pd_idx) |
| 3036 | i += raid_disks; |
| 3037 | i -= (sh->pd_idx + 2); |
| 3038 | } |
| 3039 | break; |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3040 | case ALGORITHM_PARITY_0: |
| 3041 | i -= 2; |
| 3042 | break; |
| 3043 | case ALGORITHM_PARITY_N: |
| 3044 | break; |
| 3045 | case ALGORITHM_ROTATING_N_CONTINUE: |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 3046 | /* Like left_symmetric, but P is before Q */ |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3047 | if (sh->pd_idx == 0) |
| 3048 | i--; /* P D D D Q */ |
NeilBrown | e4424fe | 2009-10-16 16:27:34 +1100 | [diff] [blame] | 3049 | else { |
| 3050 | /* D D Q P D */ |
| 3051 | if (i < sh->pd_idx) |
| 3052 | i += raid_disks; |
| 3053 | i -= (sh->pd_idx + 1); |
| 3054 | } |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3055 | break; |
| 3056 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 3057 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 3058 | if (i > sh->pd_idx) |
| 3059 | i--; |
| 3060 | break; |
| 3061 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 3062 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 3063 | if (i < sh->pd_idx) |
| 3064 | i += data_disks + 1; |
| 3065 | i -= (sh->pd_idx + 1); |
| 3066 | break; |
| 3067 | case ALGORITHM_PARITY_0_6: |
| 3068 | i -= 1; |
| 3069 | break; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3070 | default: |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3071 | BUG(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3072 | } |
| 3073 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | chunk_number = stripe * data_disks + i; |
NeilBrown | 35f2a59 | 2010-04-20 14:13:34 +1000 | [diff] [blame] | 3077 | r_sector = chunk_number * sectors_per_chunk + chunk_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3079 | check = raid5_compute_sector(conf, r_sector, |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3080 | previous, &dummy1, &sh2); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3081 | if (check != sh->sector || dummy1 != dd_idx || sh2.pd_idx != sh->pd_idx |
| 3082 | || sh2.qd_idx != sh->qd_idx) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 3083 | pr_warn("md/raid:%s: compute_blocknr: map not correct\n", |
| 3084 | mdname(conf->mddev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | return 0; |
| 3086 | } |
| 3087 | return r_sector; |
| 3088 | } |
| 3089 | |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3090 | /* |
| 3091 | * There are cases where we want handle_stripe_dirtying() and |
| 3092 | * schedule_reconstruction() to delay towrite to some dev of a stripe. |
| 3093 | * |
| 3094 | * This function checks whether we want to delay the towrite. Specifically, |
| 3095 | * we delay the towrite when: |
| 3096 | * |
| 3097 | * 1. degraded stripe has a non-overwrite to the missing dev, AND this |
| 3098 | * stripe has data in journal (for other devices). |
| 3099 | * |
| 3100 | * In this case, when reading data for the non-overwrite dev, it is |
| 3101 | * necessary to handle complex rmw of write back cache (prexor with |
| 3102 | * orig_page, and xor with page). To keep read path simple, we would |
| 3103 | * like to flush data in journal to RAID disks first, so complex rmw |
| 3104 | * is handled in the write patch (handle_stripe_dirtying). |
| 3105 | * |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3106 | * 2. when journal space is critical (R5C_LOG_CRITICAL=1) |
| 3107 | * |
| 3108 | * It is important to be able to flush all stripes in raid5-cache. |
| 3109 | * Therefore, we need reserve some space on the journal device for |
| 3110 | * these flushes. If flush operation includes pending writes to the |
| 3111 | * stripe, we need to reserve (conf->raid_disk + 1) pages per stripe |
| 3112 | * for the flush out. If we exclude these pending writes from flush |
| 3113 | * operation, we only need (conf->max_degraded + 1) pages per stripe. |
| 3114 | * Therefore, excluding pending writes in these cases enables more |
| 3115 | * efficient use of the journal device. |
| 3116 | * |
| 3117 | * Note: To make sure the stripe makes progress, we only delay |
| 3118 | * towrite for stripes with data already in journal (injournal > 0). |
| 3119 | * When LOG_CRITICAL, stripes with injournal == 0 will be sent to |
| 3120 | * no_space_stripes list. |
| 3121 | * |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 3122 | * 3. during journal failure |
| 3123 | * In journal failure, we try to flush all cached data to raid disks |
| 3124 | * based on data in stripe cache. The array is read-only to upper |
| 3125 | * layers, so we would skip all pending writes. |
| 3126 | * |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3127 | */ |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3128 | static inline bool delay_towrite(struct r5conf *conf, |
| 3129 | struct r5dev *dev, |
| 3130 | struct stripe_head_state *s) |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3131 | { |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3132 | /* case 1 above */ |
| 3133 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 3134 | !test_bit(R5_Insync, &dev->flags) && s->injournal) |
| 3135 | return true; |
| 3136 | /* case 2 above */ |
| 3137 | if (test_bit(R5C_LOG_CRITICAL, &conf->cache_state) && |
| 3138 | s->injournal > 0) |
| 3139 | return true; |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 3140 | /* case 3 above */ |
| 3141 | if (s->log_failed && s->injournal) |
| 3142 | return true; |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3143 | return false; |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3144 | } |
| 3145 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3146 | static void |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3147 | schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3148 | int rcw, int expand) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3149 | { |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3150 | 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] | 3151 | struct r5conf *conf = sh->raid_conf; |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3152 | int level = conf->level; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3153 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3154 | if (rcw) { |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3155 | /* |
| 3156 | * In some cases, handle_stripe_dirtying initially decided to |
| 3157 | * run rmw and allocates extra page for prexor. However, rcw is |
| 3158 | * cheaper later on. We need to free the extra page now, |
| 3159 | * because we won't be able to do that in ops_complete_prexor(). |
| 3160 | */ |
| 3161 | r5c_release_extra_page(sh); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3162 | |
| 3163 | for (i = disks; i--; ) { |
| 3164 | struct r5dev *dev = &sh->dev[i]; |
| 3165 | |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3166 | if (dev->towrite && !delay_towrite(conf, dev, s)) { |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3167 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3168 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3169 | if (!expand) |
| 3170 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3171 | s->locked++; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3172 | } else if (test_bit(R5_InJournal, &dev->flags)) { |
| 3173 | set_bit(R5_LOCKED, &dev->flags); |
| 3174 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3175 | } |
| 3176 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 3177 | /* if we are not expanding this is a proper write request, and |
| 3178 | * there will be bios with new data to be drained into the |
| 3179 | * stripe cache |
| 3180 | */ |
| 3181 | if (!expand) { |
| 3182 | if (!s->locked) |
| 3183 | /* False alarm, nothing to do */ |
| 3184 | return; |
| 3185 | sh->reconstruct_state = reconstruct_state_drain_run; |
| 3186 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 3187 | } else |
| 3188 | sh->reconstruct_state = reconstruct_state_run; |
| 3189 | |
| 3190 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
| 3191 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3192 | if (s->locked + conf->max_degraded == disks) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3193 | if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3194 | atomic_inc(&conf->pending_full_writes); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3195 | } else { |
| 3196 | BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || |
| 3197 | test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3198 | BUG_ON(level == 6 && |
| 3199 | (!(test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags) || |
| 3200 | test_bit(R5_Wantcompute, &sh->dev[qd_idx].flags)))); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3201 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3202 | for (i = disks; i--; ) { |
| 3203 | struct r5dev *dev = &sh->dev[i]; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3204 | if (i == pd_idx || i == qd_idx) |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3205 | continue; |
| 3206 | |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3207 | if (dev->towrite && |
| 3208 | (test_bit(R5_UPTODATE, &dev->flags) || |
Dan Williams | d8ee072 | 2008-06-28 08:32:06 +1000 | [diff] [blame] | 3209 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 3210 | set_bit(R5_Wantdrain, &dev->flags); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3211 | set_bit(R5_LOCKED, &dev->flags); |
| 3212 | clear_bit(R5_UPTODATE, &dev->flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3213 | s->locked++; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3214 | } else if (test_bit(R5_InJournal, &dev->flags)) { |
| 3215 | set_bit(R5_LOCKED, &dev->flags); |
| 3216 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3217 | } |
| 3218 | } |
NeilBrown | ce7d363 | 2013-03-04 12:37:14 +1100 | [diff] [blame] | 3219 | if (!s->locked) |
| 3220 | /* False alarm - nothing to do */ |
| 3221 | return; |
| 3222 | sh->reconstruct_state = reconstruct_state_prexor_drain_run; |
| 3223 | set_bit(STRIPE_OP_PREXOR, &s->ops_request); |
| 3224 | set_bit(STRIPE_OP_BIODRAIN, &s->ops_request); |
| 3225 | set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3228 | /* keep the parity disk(s) locked while asynchronous operations |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3229 | * are in flight |
| 3230 | */ |
| 3231 | set_bit(R5_LOCKED, &sh->dev[pd_idx].flags); |
| 3232 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3233 | s->locked++; |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3234 | |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3235 | if (level == 6) { |
| 3236 | int qd_idx = sh->qd_idx; |
| 3237 | struct r5dev *dev = &sh->dev[qd_idx]; |
| 3238 | |
| 3239 | set_bit(R5_LOCKED, &dev->flags); |
| 3240 | clear_bit(R5_UPTODATE, &dev->flags); |
| 3241 | s->locked++; |
| 3242 | } |
| 3243 | |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 3244 | if (raid5_has_ppl(sh->raid_conf) && sh->ppl_page && |
Artur Paszkiewicz | 3418d03 | 2017-03-09 09:59:59 +0100 | [diff] [blame] | 3245 | test_bit(STRIPE_OP_BIODRAIN, &s->ops_request) && |
| 3246 | !test_bit(STRIPE_FULL_WRITE, &sh->state) && |
| 3247 | test_bit(R5_Insync, &sh->dev[pd_idx].flags)) |
| 3248 | set_bit(STRIPE_OP_PARTIAL_PARITY, &s->ops_request); |
| 3249 | |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3250 | pr_debug("%s: stripe %llu locked: %d ops_request: %lx\n", |
Harvey Harrison | e46b272b | 2008-04-28 02:15:50 -0700 | [diff] [blame] | 3251 | __func__, (unsigned long long)sh->sector, |
Dan Williams | 600aa10 | 2008-06-28 08:32:05 +1000 | [diff] [blame] | 3252 | s->locked, s->ops_request); |
Dan Williams | e33129d | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3253 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | /* |
| 3256 | * Each stripe/dev can have one or more bion attached. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 3257 | * toread/towrite point to the first in a chain. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | * The bi_next chain must be in order. |
| 3259 | */ |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3260 | static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, |
| 3261 | int forwrite, int previous) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | { |
| 3263 | struct bio **bip; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3264 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3265 | int firstwrite=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3267 | pr_debug("adding bi b#%llu to stripe s#%llu\n", |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3268 | (unsigned long long)bi->bi_iter.bi_sector, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | (unsigned long long)sh->sector); |
| 3270 | |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3271 | spin_lock_irq(&sh->stripe_lock); |
Mariusz Dabrowski | 2cd259a | 2018-04-19 19:28:10 +0200 | [diff] [blame] | 3272 | sh->dev[dd_idx].write_hint = bi->bi_write_hint; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3273 | /* Don't allow new IO added to stripes in batch list */ |
| 3274 | if (sh->batch_head) |
| 3275 | goto overlap; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3276 | if (forwrite) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | bip = &sh->dev[dd_idx].towrite; |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3278 | if (*bip == NULL) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3279 | firstwrite = 1; |
| 3280 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | bip = &sh->dev[dd_idx].toread; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3282 | while (*bip && (*bip)->bi_iter.bi_sector < bi->bi_iter.bi_sector) { |
| 3283 | if (bio_end_sector(*bip) > bi->bi_iter.bi_sector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | goto overlap; |
| 3285 | bip = & (*bip)->bi_next; |
| 3286 | } |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3287 | if (*bip && (*bip)->bi_iter.bi_sector < bio_end_sector(bi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | goto overlap; |
| 3289 | |
Artur Paszkiewicz | 3418d03 | 2017-03-09 09:59:59 +0100 | [diff] [blame] | 3290 | if (forwrite && raid5_has_ppl(conf)) { |
| 3291 | /* |
| 3292 | * With PPL only writes to consecutive data chunks within a |
| 3293 | * stripe are allowed because for a single stripe_head we can |
| 3294 | * only have one PPL entry at a time, which describes one data |
| 3295 | * range. Not really an overlap, but wait_for_overlap can be |
| 3296 | * used to handle this. |
| 3297 | */ |
| 3298 | sector_t sector; |
| 3299 | sector_t first = 0; |
| 3300 | sector_t last = 0; |
| 3301 | int count = 0; |
| 3302 | int i; |
| 3303 | |
| 3304 | for (i = 0; i < sh->disks; i++) { |
| 3305 | if (i != sh->pd_idx && |
| 3306 | (i == dd_idx || sh->dev[i].towrite)) { |
| 3307 | sector = sh->dev[i].sector; |
| 3308 | if (count == 0 || sector < first) |
| 3309 | first = sector; |
| 3310 | if (sector > last) |
| 3311 | last = sector; |
| 3312 | count++; |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | if (first + conf->chunk_sectors * (count - 1) != last) |
| 3317 | goto overlap; |
| 3318 | } |
| 3319 | |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3320 | if (!forwrite || previous) |
| 3321 | clear_bit(STRIPE_BATCH_READY, &sh->state); |
| 3322 | |
Eric Sesterhenn | 78bafeb | 2006-04-02 13:31:42 +0200 | [diff] [blame] | 3323 | BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | if (*bip) |
| 3325 | bi->bi_next = *bip; |
| 3326 | *bip = bi; |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 3327 | bio_inc_remaining(bi); |
NeilBrown | 4972805 | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 3328 | md_write_inc(conf->mddev, bi); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 3329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | if (forwrite) { |
| 3331 | /* check if page is covered */ |
| 3332 | sector_t sector = sh->dev[dd_idx].sector; |
| 3333 | for (bi=sh->dev[dd_idx].towrite; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3334 | sector < sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf) && |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3335 | bi && bi->bi_iter.bi_sector <= sector; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3336 | bi = r5_next_bio(conf, bi, sh->dev[dd_idx].sector)) { |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 3337 | if (bio_end_sector(bi) >= sector) |
| 3338 | sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | } |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3340 | if (sector >= sh->dev[dd_idx].sector + RAID5_STRIPE_SECTORS(conf)) |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3341 | if (!test_and_set_bit(R5_OVERWRITE, &sh->dev[dd_idx].flags)) |
| 3342 | sh->overwrite_disks++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3344 | |
| 3345 | 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] | 3346 | (unsigned long long)(*bip)->bi_iter.bi_sector, |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3347 | (unsigned long long)sh->sector, dd_idx); |
| 3348 | |
| 3349 | if (conf->mddev->bitmap && firstwrite) { |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 3350 | /* Cannot hold spinlock over bitmap_startwrite, |
| 3351 | * but must ensure this isn't added to a batch until |
| 3352 | * we have added to the bitmap and set bm_seq. |
| 3353 | * So set STRIPE_BITMAP_PENDING to prevent |
| 3354 | * batching. |
| 3355 | * If multiple add_stripe_bio() calls race here they |
| 3356 | * much all set STRIPE_BITMAP_PENDING. So only the first one |
| 3357 | * to complete "bitmap_startwrite" gets to set |
| 3358 | * STRIPE_BIT_DELAY. This is important as once a stripe |
| 3359 | * is added to a batch, STRIPE_BIT_DELAY cannot be changed |
| 3360 | * any more. |
| 3361 | */ |
| 3362 | set_bit(STRIPE_BITMAP_PENDING, &sh->state); |
| 3363 | spin_unlock_irq(&sh->stripe_lock); |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 3364 | md_bitmap_startwrite(conf->mddev->bitmap, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3365 | RAID5_STRIPE_SECTORS(conf), 0); |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 3366 | spin_lock_irq(&sh->stripe_lock); |
| 3367 | clear_bit(STRIPE_BITMAP_PENDING, &sh->state); |
| 3368 | if (!sh->batch_head) { |
| 3369 | sh->bm_seq = conf->seq_flush+1; |
| 3370 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 3371 | } |
NeilBrown | cbe47ec | 2011-07-26 11:20:35 +1000 | [diff] [blame] | 3372 | } |
NeilBrown | d0852df5 | 2015-05-27 08:43:45 +1000 | [diff] [blame] | 3373 | spin_unlock_irq(&sh->stripe_lock); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3374 | |
| 3375 | if (stripe_can_batch(sh)) |
| 3376 | stripe_add_to_batch_list(conf, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | return 1; |
| 3378 | |
| 3379 | overlap: |
| 3380 | set_bit(R5_Overlap, &sh->dev[dd_idx].flags); |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3381 | spin_unlock_irq(&sh->stripe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | return 0; |
| 3383 | } |
| 3384 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3385 | static void end_reshape(struct r5conf *conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 3386 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3387 | static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3388 | struct stripe_head *sh) |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3389 | { |
NeilBrown | 784052e | 2009-03-31 15:19:07 +1100 | [diff] [blame] | 3390 | int sectors_per_chunk = |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 3391 | previous ? conf->prev_chunk_sectors : conf->chunk_sectors; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3392 | int dd_idx; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 3393 | int chunk_offset = sector_div(stripe, sectors_per_chunk); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3394 | int disks = previous ? conf->previous_raid_disks : conf->raid_disks; |
Coywolf Qi Hunt | 2d2063c | 2006-10-03 01:15:50 -0700 | [diff] [blame] | 3395 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3396 | raid5_compute_sector(conf, |
| 3397 | stripe * (disks - conf->max_degraded) |
NeilBrown | b875e53 | 2006-12-10 02:20:49 -0800 | [diff] [blame] | 3398 | *sectors_per_chunk + chunk_offset, |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3399 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 3400 | &dd_idx, sh); |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 3401 | } |
| 3402 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3403 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3404 | handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | bd83d0a | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 3405 | struct stripe_head_state *s, int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3406 | { |
| 3407 | int i; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3408 | BUG_ON(sh->batch_head); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3409 | for (i = disks; i--; ) { |
| 3410 | struct bio *bi; |
| 3411 | int bitmap_end = 0; |
| 3412 | |
| 3413 | if (test_bit(R5_ReadError, &sh->dev[i].flags)) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 3414 | struct md_rdev *rdev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3415 | rcu_read_lock(); |
| 3416 | rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | f5b67ae | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 3417 | if (rdev && test_bit(In_sync, &rdev->flags) && |
| 3418 | !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3419 | atomic_inc(&rdev->nr_pending); |
| 3420 | else |
| 3421 | rdev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3422 | rcu_read_unlock(); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3423 | if (rdev) { |
| 3424 | if (!rdev_set_badblocks( |
| 3425 | rdev, |
| 3426 | sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3427 | RAID5_STRIPE_SECTORS(conf), 0)) |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3428 | md_error(conf->mddev, rdev); |
| 3429 | rdev_dec_pending(rdev, conf->mddev); |
| 3430 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3431 | } |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3432 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3433 | /* fail all writes first */ |
| 3434 | bi = sh->dev[i].towrite; |
| 3435 | sh->dev[i].towrite = NULL; |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3436 | sh->overwrite_disks = 0; |
Shaohua Li | b17459c | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3437 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | 1ed850f | 2012-10-11 13:50:13 +1100 | [diff] [blame] | 3438 | if (bi) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3439 | bitmap_end = 1; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3440 | |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 3441 | log_stripe_write_finished(sh); |
Shaohua Li | 0576b1c | 2015-08-13 14:32:00 -0700 | [diff] [blame] | 3442 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3443 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 3444 | wake_up(&conf->wait_for_overlap); |
| 3445 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3446 | while (bi && bi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3447 | sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { |
| 3448 | struct bio *nextbi = r5_next_bio(conf, bi, sh->dev[i].sector); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 3449 | |
NeilBrown | 4972805 | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 3450 | md_write_end(conf->mddev); |
Guoqing Jiang | 6308d8e | 2017-07-21 16:33:44 +0800 | [diff] [blame] | 3451 | bio_io_error(bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3452 | bi = nextbi; |
| 3453 | } |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3454 | if (bitmap_end) |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 3455 | md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3456 | RAID5_STRIPE_SECTORS(conf), 0, 0); |
Shaohua Li | 7eaf7e8 | 2012-07-19 16:01:31 +1000 | [diff] [blame] | 3457 | bitmap_end = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3458 | /* and fail all 'written' */ |
| 3459 | bi = sh->dev[i].written; |
| 3460 | sh->dev[i].written = NULL; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3461 | if (test_and_clear_bit(R5_SkipCopy, &sh->dev[i].flags)) { |
| 3462 | WARN_ON(test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
| 3463 | sh->dev[i].page = sh->dev[i].orig_page; |
| 3464 | } |
| 3465 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3466 | if (bi) bitmap_end = 1; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3467 | while (bi && bi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3468 | sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { |
| 3469 | struct bio *bi2 = r5_next_bio(conf, bi, sh->dev[i].sector); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 3470 | |
NeilBrown | 4972805 | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 3471 | md_write_end(conf->mddev); |
Guoqing Jiang | 6308d8e | 2017-07-21 16:33:44 +0800 | [diff] [blame] | 3472 | bio_io_error(bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3473 | bi = bi2; |
| 3474 | } |
| 3475 | |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3476 | /* fail any reads if this device is non-operational and |
| 3477 | * the data has not reached the cache yet. |
| 3478 | */ |
| 3479 | if (!test_bit(R5_Wantfill, &sh->dev[i].flags) && |
Shaohua Li | 6e74a9c | 2015-10-08 21:54:08 -0700 | [diff] [blame] | 3480 | s->failed > conf->max_degraded && |
Dan Williams | b5e98d6 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 3481 | (!test_bit(R5_Insync, &sh->dev[i].flags) || |
| 3482 | test_bit(R5_ReadError, &sh->dev[i].flags))) { |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3483 | spin_lock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3484 | bi = sh->dev[i].toread; |
| 3485 | sh->dev[i].toread = NULL; |
NeilBrown | 143c4d0 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3486 | spin_unlock_irq(&sh->stripe_lock); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3487 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 3488 | wake_up(&conf->wait_for_overlap); |
Shaohua Li | ebda780 | 2015-09-18 10:20:13 -0700 | [diff] [blame] | 3489 | if (bi) |
| 3490 | s->to_read--; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3491 | while (bi && bi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3492 | sh->dev[i].sector + RAID5_STRIPE_SECTORS(conf)) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3493 | struct bio *nextbi = |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3494 | r5_next_bio(conf, bi, sh->dev[i].sector); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 3495 | |
Guoqing Jiang | 6308d8e | 2017-07-21 16:33:44 +0800 | [diff] [blame] | 3496 | bio_io_error(bi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3497 | bi = nextbi; |
| 3498 | } |
| 3499 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3500 | if (bitmap_end) |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 3501 | md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3502 | RAID5_STRIPE_SECTORS(conf), 0, 0); |
NeilBrown | 8cfa7b0 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3503 | /* If we were in the middle of a write the parity block might |
| 3504 | * still be locked - so just clear all R5_LOCKED flags |
| 3505 | */ |
| 3506 | clear_bit(R5_LOCKED, &sh->dev[i].flags); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3507 | } |
Shaohua Li | ebda780 | 2015-09-18 10:20:13 -0700 | [diff] [blame] | 3508 | s->to_write = 0; |
| 3509 | s->written = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3510 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3511 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 3512 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 3513 | md_wakeup_thread(conf->mddev->thread); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3516 | static void |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3517 | handle_failed_sync(struct r5conf *conf, struct stripe_head *sh, |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3518 | struct stripe_head_state *s) |
| 3519 | { |
| 3520 | int abort = 0; |
| 3521 | int i; |
| 3522 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3523 | BUG_ON(sh->batch_head); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3524 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3525 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 3526 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3527 | s->syncing = 0; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3528 | s->replacing = 0; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3529 | /* There is nothing more to do for sync/check/repair. |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3530 | * Don't even need to abort as that is handled elsewhere |
| 3531 | * if needed, and not always wanted e.g. if there is a known |
| 3532 | * bad block here. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3533 | * For recover/replace we need to record a bad block on all |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3534 | * non-sync devices, or abort the recovery |
| 3535 | */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3536 | if (test_bit(MD_RECOVERY_RECOVER, &conf->mddev->recovery)) { |
| 3537 | /* During recovery devices cannot be removed, so |
| 3538 | * locking and refcounting of rdevs is not needed |
| 3539 | */ |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3540 | rcu_read_lock(); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3541 | for (i = 0; i < conf->raid_disks; i++) { |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3542 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3543 | if (rdev |
| 3544 | && !test_bit(Faulty, &rdev->flags) |
| 3545 | && !test_bit(In_sync, &rdev->flags) |
| 3546 | && !rdev_set_badblocks(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3547 | RAID5_STRIPE_SECTORS(conf), 0)) |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3548 | abort = 1; |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3549 | rdev = rcu_dereference(conf->disks[i].replacement); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3550 | if (rdev |
| 3551 | && !test_bit(Faulty, &rdev->flags) |
| 3552 | && !test_bit(In_sync, &rdev->flags) |
| 3553 | && !rdev_set_badblocks(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3554 | RAID5_STRIPE_SECTORS(conf), 0)) |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3555 | abort = 1; |
| 3556 | } |
NeilBrown | e50d399 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3557 | rcu_read_unlock(); |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 3558 | if (abort) |
| 3559 | conf->recovery_disabled = |
| 3560 | conf->mddev->recovery_disabled; |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3561 | } |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3562 | md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), !abort); |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 3563 | } |
| 3564 | |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3565 | static int want_replace(struct stripe_head *sh, int disk_idx) |
| 3566 | { |
| 3567 | struct md_rdev *rdev; |
| 3568 | int rv = 0; |
NeilBrown | 3f232d6 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3569 | |
| 3570 | rcu_read_lock(); |
| 3571 | rdev = rcu_dereference(sh->raid_conf->disks[disk_idx].replacement); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3572 | if (rdev |
| 3573 | && !test_bit(Faulty, &rdev->flags) |
| 3574 | && !test_bit(In_sync, &rdev->flags) |
| 3575 | && (rdev->recovery_offset <= sh->sector |
| 3576 | || rdev->mddev->recovery_cp <= sh->sector)) |
| 3577 | rv = 1; |
NeilBrown | 3f232d6 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 3578 | rcu_read_unlock(); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 3579 | return rv; |
| 3580 | } |
| 3581 | |
NeilBrown | 2c58f06 | 2015-02-02 11:32:23 +1100 | [diff] [blame] | 3582 | static int need_this_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 3583 | int disk_idx, int disks) |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3584 | { |
| 3585 | struct r5dev *dev = &sh->dev[disk_idx]; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3586 | struct r5dev *fdev[2] = { &sh->dev[s->failed_num[0]], |
| 3587 | &sh->dev[s->failed_num[1]] }; |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3588 | int i; |
ChangSyun Peng | 45a4d8f | 2020-07-31 17:50:31 +0800 | [diff] [blame] | 3589 | bool force_rcw = (sh->raid_conf->rmw_level == PARITY_DISABLE_RMW); |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3590 | |
NeilBrown | a79cfe1 | 2015-02-02 11:37:59 +1100 | [diff] [blame] | 3591 | |
| 3592 | if (test_bit(R5_LOCKED, &dev->flags) || |
| 3593 | test_bit(R5_UPTODATE, &dev->flags)) |
| 3594 | /* No point reading this as we already have it or have |
| 3595 | * decided to get it. |
| 3596 | */ |
| 3597 | return 0; |
| 3598 | |
| 3599 | if (dev->toread || |
| 3600 | (dev->towrite && !test_bit(R5_OVERWRITE, &dev->flags))) |
| 3601 | /* We need this block to directly satisfy a request */ |
| 3602 | return 1; |
| 3603 | |
| 3604 | if (s->syncing || s->expanding || |
| 3605 | (s->replacing && want_replace(sh, disk_idx))) |
| 3606 | /* When syncing, or expanding we read everything. |
| 3607 | * When replacing, we need the replaced block. |
| 3608 | */ |
| 3609 | return 1; |
| 3610 | |
| 3611 | if ((s->failed >= 1 && fdev[0]->toread) || |
| 3612 | (s->failed >= 2 && fdev[1]->toread)) |
| 3613 | /* If we want to read from a failed device, then |
| 3614 | * we need to actually read every other device. |
| 3615 | */ |
| 3616 | return 1; |
| 3617 | |
NeilBrown | a9d5695 | 2015-02-02 11:49:10 +1100 | [diff] [blame] | 3618 | /* Sometimes neither read-modify-write nor reconstruct-write |
| 3619 | * cycles can work. In those cases we read every block we |
| 3620 | * can. Then the parity-update is certain to have enough to |
| 3621 | * work with. |
| 3622 | * This can only be a problem when we need to write something, |
| 3623 | * and some device has failed. If either of those tests |
| 3624 | * fail we need look no further. |
| 3625 | */ |
| 3626 | if (!s->failed || !s->to_write) |
| 3627 | return 0; |
| 3628 | |
| 3629 | if (test_bit(R5_Insync, &dev->flags) && |
| 3630 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 3631 | /* Pre-reads at not permitted until after short delay |
| 3632 | * to gather multiple requests. However if this |
Zhilong Liu | 3560741e | 2017-03-15 16:14:53 +0800 | [diff] [blame] | 3633 | * device is no Insync, the block could only be computed |
NeilBrown | a9d5695 | 2015-02-02 11:49:10 +1100 | [diff] [blame] | 3634 | * and there is no need to delay that. |
| 3635 | */ |
| 3636 | return 0; |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3637 | |
NeilBrown | 36707bb | 2015-09-24 15:25:36 +1000 | [diff] [blame] | 3638 | for (i = 0; i < s->failed && i < 2; i++) { |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3639 | if (fdev[i]->towrite && |
| 3640 | !test_bit(R5_UPTODATE, &fdev[i]->flags) && |
| 3641 | !test_bit(R5_OVERWRITE, &fdev[i]->flags)) |
| 3642 | /* If we have a partial write to a failed |
| 3643 | * device, then we will need to reconstruct |
| 3644 | * the content of that device, so all other |
| 3645 | * devices must be read. |
| 3646 | */ |
| 3647 | return 1; |
ChangSyun Peng | 45a4d8f | 2020-07-31 17:50:31 +0800 | [diff] [blame] | 3648 | |
| 3649 | if (s->failed >= 2 && |
| 3650 | (fdev[i]->towrite || |
| 3651 | s->failed_num[i] == sh->pd_idx || |
| 3652 | s->failed_num[i] == sh->qd_idx) && |
| 3653 | !test_bit(R5_UPTODATE, &fdev[i]->flags)) |
| 3654 | /* In max degraded raid6, If the failed disk is P, Q, |
| 3655 | * or we want to read the failed disk, we need to do |
| 3656 | * reconstruct-write. |
| 3657 | */ |
| 3658 | force_rcw = true; |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3659 | } |
| 3660 | |
ChangSyun Peng | 45a4d8f | 2020-07-31 17:50:31 +0800 | [diff] [blame] | 3661 | /* If we are forced to do a reconstruct-write, because parity |
| 3662 | * cannot be trusted and we are currently recovering it, there |
| 3663 | * is extra need to be careful. |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3664 | * If one of the devices that we would need to read, because |
| 3665 | * it is not being overwritten (and maybe not written at all) |
| 3666 | * is missing/faulty, then we need to read everything we can. |
| 3667 | */ |
ChangSyun Peng | 45a4d8f | 2020-07-31 17:50:31 +0800 | [diff] [blame] | 3668 | if (!force_rcw && |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3669 | sh->sector < sh->raid_conf->mddev->recovery_cp) |
| 3670 | /* reconstruct-write isn't being forced */ |
| 3671 | return 0; |
NeilBrown | 36707bb | 2015-09-24 15:25:36 +1000 | [diff] [blame] | 3672 | for (i = 0; i < s->failed && i < 2; i++) { |
NeilBrown | 10d82c5 | 2015-05-08 18:19:33 +1000 | [diff] [blame] | 3673 | if (s->failed_num[i] != sh->pd_idx && |
| 3674 | s->failed_num[i] != sh->qd_idx && |
| 3675 | !test_bit(R5_UPTODATE, &fdev[i]->flags) && |
NeilBrown | ea664c8 | 2015-02-02 14:03:28 +1100 | [diff] [blame] | 3676 | !test_bit(R5_OVERWRITE, &fdev[i]->flags)) |
| 3677 | return 1; |
| 3678 | } |
| 3679 | |
NeilBrown | 2c58f06 | 2015-02-02 11:32:23 +1100 | [diff] [blame] | 3680 | return 0; |
| 3681 | } |
| 3682 | |
Song Liu | ba02684 | 2017-01-12 17:22:42 -0800 | [diff] [blame] | 3683 | /* fetch_block - checks the given member device to see if its data needs |
| 3684 | * to be read or computed to satisfy a request. |
| 3685 | * |
| 3686 | * Returns 1 when no more member devices need to be checked, otherwise returns |
| 3687 | * 0 to tell the loop in handle_stripe_fill to continue |
| 3688 | */ |
NeilBrown | 2c58f06 | 2015-02-02 11:32:23 +1100 | [diff] [blame] | 3689 | static int fetch_block(struct stripe_head *sh, struct stripe_head_state *s, |
| 3690 | int disk_idx, int disks) |
| 3691 | { |
| 3692 | struct r5dev *dev = &sh->dev[disk_idx]; |
| 3693 | |
| 3694 | /* is the data in this block needed, and can we get it? */ |
| 3695 | if (need_this_block(sh, s, disk_idx, disks)) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3696 | /* we would like to get this block, possibly by computing it, |
| 3697 | * otherwise read it if the backing disk is insync |
| 3698 | */ |
| 3699 | BUG_ON(test_bit(R5_Wantcompute, &dev->flags)); |
| 3700 | BUG_ON(test_bit(R5_Wantread, &dev->flags)); |
NeilBrown | b0c783b | 2015-05-08 18:19:32 +1000 | [diff] [blame] | 3701 | BUG_ON(sh->batch_head); |
NeilBrown | 7471fb7 | 2017-04-03 12:11:32 +1000 | [diff] [blame] | 3702 | |
| 3703 | /* |
| 3704 | * In the raid6 case if the only non-uptodate disk is P |
| 3705 | * then we already trusted P to compute the other failed |
| 3706 | * drives. It is safe to compute rather than re-read P. |
| 3707 | * In other cases we only compute blocks from failed |
| 3708 | * devices, otherwise check/repair might fail to detect |
| 3709 | * a real inconsistency. |
| 3710 | */ |
| 3711 | |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3712 | if ((s->uptodate == disks - 1) && |
NeilBrown | 7471fb7 | 2017-04-03 12:11:32 +1000 | [diff] [blame] | 3713 | ((sh->qd_idx >= 0 && sh->pd_idx == disk_idx) || |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 3714 | (s->failed && (disk_idx == s->failed_num[0] || |
NeilBrown | 7471fb7 | 2017-04-03 12:11:32 +1000 | [diff] [blame] | 3715 | disk_idx == s->failed_num[1])))) { |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3716 | /* have disk failed, and we're requested to fetch it; |
| 3717 | * do compute it |
| 3718 | */ |
| 3719 | pr_debug("Computing stripe %llu block %d\n", |
| 3720 | (unsigned long long)sh->sector, disk_idx); |
| 3721 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3722 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3723 | set_bit(R5_Wantcompute, &dev->flags); |
| 3724 | sh->ops.target = disk_idx; |
| 3725 | sh->ops.target2 = -1; /* no 2nd target */ |
| 3726 | s->req_compute = 1; |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3727 | /* Careful: from this point on 'uptodate' is in the eye |
| 3728 | * of raid_run_ops which services 'compute' operations |
| 3729 | * before writes. R5_Wantcompute flags a block that will |
| 3730 | * be R5_UPTODATE by the time it is needed for a |
| 3731 | * subsequent operation. |
| 3732 | */ |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3733 | s->uptodate++; |
| 3734 | return 1; |
| 3735 | } else if (s->uptodate == disks-2 && s->failed >= 2) { |
| 3736 | /* Computing 2-failure is *very* expensive; only |
| 3737 | * do it if failed >= 2 |
| 3738 | */ |
| 3739 | int other; |
| 3740 | for (other = disks; other--; ) { |
| 3741 | if (other == disk_idx) |
| 3742 | continue; |
| 3743 | if (!test_bit(R5_UPTODATE, |
| 3744 | &sh->dev[other].flags)) |
| 3745 | break; |
| 3746 | } |
| 3747 | BUG_ON(other < 0); |
| 3748 | pr_debug("Computing stripe %llu blocks %d,%d\n", |
| 3749 | (unsigned long long)sh->sector, |
| 3750 | disk_idx, other); |
| 3751 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 3752 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 3753 | set_bit(R5_Wantcompute, &sh->dev[disk_idx].flags); |
| 3754 | set_bit(R5_Wantcompute, &sh->dev[other].flags); |
| 3755 | sh->ops.target = disk_idx; |
| 3756 | sh->ops.target2 = other; |
| 3757 | s->uptodate += 2; |
| 3758 | s->req_compute = 1; |
| 3759 | return 1; |
| 3760 | } else if (test_bit(R5_Insync, &dev->flags)) { |
| 3761 | set_bit(R5_LOCKED, &dev->flags); |
| 3762 | set_bit(R5_Wantread, &dev->flags); |
| 3763 | s->locked++; |
| 3764 | pr_debug("Reading block %d (sync=%d)\n", |
| 3765 | disk_idx, s->syncing); |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | return 0; |
| 3770 | } |
| 3771 | |
Damien Le Moal | 2aada5b | 2020-07-16 13:54:42 +0900 | [diff] [blame] | 3772 | /* |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3773 | * handle_stripe_fill - read or compute data to satisfy pending requests. |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3774 | */ |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3775 | static void handle_stripe_fill(struct stripe_head *sh, |
| 3776 | struct stripe_head_state *s, |
| 3777 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3778 | { |
| 3779 | int i; |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3780 | |
| 3781 | /* look for blocks to read/compute, skip this if a compute |
| 3782 | * is already in flight, or if the stripe contents are in the |
| 3783 | * midst of changing due to a write |
| 3784 | */ |
| 3785 | if (!test_bit(STRIPE_COMPUTE_RUN, &sh->state) && !sh->check_state && |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3786 | !sh->reconstruct_state) { |
| 3787 | |
| 3788 | /* |
| 3789 | * For degraded stripe with data in journal, do not handle |
| 3790 | * read requests yet, instead, flush the stripe to raid |
| 3791 | * disks first, this avoids handling complex rmw of write |
| 3792 | * back cache (prexor with orig_page, and then xor with |
| 3793 | * page) in the read path |
| 3794 | */ |
| 3795 | if (s->injournal && s->failed) { |
| 3796 | if (test_bit(STRIPE_R5C_CACHING, &sh->state)) |
| 3797 | r5c_make_stripe_write_out(sh); |
| 3798 | goto out; |
| 3799 | } |
| 3800 | |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3801 | for (i = disks; i--; ) |
NeilBrown | 93b3dbc | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3802 | if (fetch_block(sh, s, i, disks)) |
Yuri Tikhonov | 5599bec | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 3803 | break; |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3804 | } |
| 3805 | out: |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3806 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3807 | } |
| 3808 | |
NeilBrown | 787b76f | 2015-05-21 12:56:41 +1000 | [diff] [blame] | 3809 | static void break_stripe_batch_list(struct stripe_head *head_sh, |
| 3810 | unsigned long handle_flags); |
Dan Williams | 1fe797e | 2008-06-28 09:16:30 +1000 | [diff] [blame] | 3811 | /* handle_stripe_clean_event |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3812 | * any written block on an uptodate or failed drive can be returned. |
| 3813 | * Note that if we 'wrote' to a failed drive, it will be UPTODATE, but |
| 3814 | * never LOCKED, so we don't need to test 'failed' directly. |
| 3815 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 3816 | static void handle_stripe_clean_event(struct r5conf *conf, |
NeilBrown | bd83d0a | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 3817 | struct stripe_head *sh, int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3818 | { |
| 3819 | int i; |
| 3820 | struct r5dev *dev; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3821 | int discard_pending = 0; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3822 | struct stripe_head *head_sh = sh; |
| 3823 | bool do_endio = false; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3824 | |
| 3825 | for (i = disks; i--; ) |
| 3826 | if (sh->dev[i].written) { |
| 3827 | dev = &sh->dev[i]; |
| 3828 | if (!test_bit(R5_LOCKED, &dev->flags) && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 3829 | (test_bit(R5_UPTODATE, &dev->flags) || |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3830 | test_bit(R5_Discard, &dev->flags) || |
| 3831 | test_bit(R5_SkipCopy, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3832 | /* We can return any write requests */ |
| 3833 | struct bio *wbi, *wbi2; |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3834 | pr_debug("Return write for disc %d\n", i); |
NeilBrown | ca64cae | 2012-11-21 16:33:40 +1100 | [diff] [blame] | 3835 | if (test_and_clear_bit(R5_Discard, &dev->flags)) |
| 3836 | clear_bit(R5_UPTODATE, &dev->flags); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3837 | if (test_and_clear_bit(R5_SkipCopy, &dev->flags)) { |
| 3838 | WARN_ON(test_bit(R5_UPTODATE, &dev->flags)); |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 3839 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3840 | do_endio = true; |
| 3841 | |
| 3842 | returnbi: |
| 3843 | dev->page = dev->orig_page; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3844 | wbi = dev->written; |
| 3845 | dev->written = NULL; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 3846 | while (wbi && wbi->bi_iter.bi_sector < |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3847 | dev->sector + RAID5_STRIPE_SECTORS(conf)) { |
| 3848 | wbi2 = r5_next_bio(conf, wbi, dev->sector); |
NeilBrown | 4972805 | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 3849 | md_write_end(conf->mddev); |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 3850 | bio_endio(wbi); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3851 | wbi = wbi2; |
| 3852 | } |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 3853 | md_bitmap_endwrite(conf->mddev->bitmap, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 3854 | RAID5_STRIPE_SECTORS(conf), |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 3855 | !test_bit(STRIPE_DEGRADED, &sh->state), |
| 3856 | 0); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3857 | if (head_sh->batch_head) { |
| 3858 | sh = list_first_entry(&sh->batch_list, |
| 3859 | struct stripe_head, |
| 3860 | batch_list); |
| 3861 | if (sh != head_sh) { |
| 3862 | dev = &sh->dev[i]; |
| 3863 | goto returnbi; |
| 3864 | } |
| 3865 | } |
| 3866 | sh = head_sh; |
| 3867 | dev = &sh->dev[i]; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3868 | } else if (test_bit(R5_Discard, &dev->flags)) |
| 3869 | discard_pending = 1; |
| 3870 | } |
Shaohua Li | f6bed0e | 2015-08-13 14:31:59 -0700 | [diff] [blame] | 3871 | |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 3872 | log_stripe_write_finished(sh); |
Shaohua Li | 0576b1c | 2015-08-13 14:32:00 -0700 | [diff] [blame] | 3873 | |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3874 | if (!discard_pending && |
| 3875 | test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) { |
Roman Gushchin | b8a9d66 | 2015-10-31 10:53:50 +1100 | [diff] [blame] | 3876 | int hash; |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3877 | clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); |
| 3878 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
| 3879 | if (sh->qd_idx >= 0) { |
| 3880 | clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); |
| 3881 | clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags); |
| 3882 | } |
| 3883 | /* now that discard is done we can proceed with any sync */ |
| 3884 | clear_bit(STRIPE_DISCARD, &sh->state); |
Shaohua Li | d47648f | 2013-10-19 14:51:42 +0800 | [diff] [blame] | 3885 | /* |
| 3886 | * SCSI discard will change some bio fields and the stripe has |
| 3887 | * no updated data, so remove it from hash list and the stripe |
| 3888 | * will be reinitialized |
| 3889 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3890 | unhash: |
Roman Gushchin | b8a9d66 | 2015-10-31 10:53:50 +1100 | [diff] [blame] | 3891 | hash = sh->hash_lock_index; |
| 3892 | spin_lock_irq(conf->hash_locks + hash); |
Shaohua Li | d47648f | 2013-10-19 14:51:42 +0800 | [diff] [blame] | 3893 | remove_hash(sh); |
Roman Gushchin | b8a9d66 | 2015-10-31 10:53:50 +1100 | [diff] [blame] | 3894 | spin_unlock_irq(conf->hash_locks + hash); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3895 | if (head_sh->batch_head) { |
| 3896 | sh = list_first_entry(&sh->batch_list, |
| 3897 | struct stripe_head, batch_list); |
| 3898 | if (sh != head_sh) |
| 3899 | goto unhash; |
| 3900 | } |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3901 | sh = head_sh; |
| 3902 | |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 3903 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) |
| 3904 | set_bit(STRIPE_HANDLE, &sh->state); |
| 3905 | |
| 3906 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 3907 | |
| 3908 | if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) |
| 3909 | if (atomic_dec_and_test(&conf->pending_full_writes)) |
| 3910 | md_wakeup_thread(conf->mddev->thread); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 3911 | |
NeilBrown | 787b76f | 2015-05-21 12:56:41 +1000 | [diff] [blame] | 3912 | if (head_sh->batch_head && do_endio) |
| 3913 | break_stripe_batch_list(head_sh, STRIPE_EXPAND_SYNC_FLAGS); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 3916 | /* |
| 3917 | * For RMW in write back cache, we need extra page in prexor to store the |
| 3918 | * old data. This page is stored in dev->orig_page. |
| 3919 | * |
| 3920 | * This function checks whether we have data for prexor. The exact logic |
| 3921 | * is: |
| 3922 | * R5_UPTODATE && (!R5_InJournal || R5_OrigPageUPTDODATE) |
| 3923 | */ |
| 3924 | static inline bool uptodate_for_rmw(struct r5dev *dev) |
| 3925 | { |
| 3926 | return (test_bit(R5_UPTODATE, &dev->flags)) && |
| 3927 | (!test_bit(R5_InJournal, &dev->flags) || |
| 3928 | test_bit(R5_OrigPageUPTDODATE, &dev->flags)); |
| 3929 | } |
| 3930 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3931 | static int handle_stripe_dirtying(struct r5conf *conf, |
| 3932 | struct stripe_head *sh, |
| 3933 | struct stripe_head_state *s, |
| 3934 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3935 | { |
| 3936 | int rmw = 0, rcw = 0, i; |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3937 | sector_t recovery_cp = conf->mddev->recovery_cp; |
| 3938 | |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3939 | /* Check whether resync is now happening or should start. |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3940 | * If yes, then the array is dirty (after unclean shutdown or |
| 3941 | * initial creation), so parity in some stripes might be inconsistent. |
| 3942 | * In this case, we need to always do reconstruct-write, to ensure |
| 3943 | * that in case of drive failure or read-error correction, we |
| 3944 | * generate correct data from the parity. |
| 3945 | */ |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3946 | if (conf->rmw_level == PARITY_DISABLE_RMW || |
NeilBrown | 26ac107 | 2015-02-18 11:35:14 +1100 | [diff] [blame] | 3947 | (recovery_cp < MaxSector && sh->sector >= recovery_cp && |
| 3948 | s->failed == 0)) { |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3949 | /* Calculate the real rcw later - for now make it |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3950 | * look like rcw is cheaper |
| 3951 | */ |
| 3952 | rcw = 1; rmw = 2; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3953 | pr_debug("force RCW rmw_level=%u, recovery_cp=%llu sh->sector=%llu\n", |
| 3954 | conf->rmw_level, (unsigned long long)recovery_cp, |
Alexander Lyakas | a785448 | 2012-10-11 13:50:12 +1100 | [diff] [blame] | 3955 | (unsigned long long)sh->sector); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 3956 | } else for (i = disks; i--; ) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3957 | /* would I have to read this buffer for read_modify_write */ |
| 3958 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3959 | if (((dev->towrite && !delay_towrite(conf, dev, s)) || |
Song Liu | 07e8336 | 2017-01-23 17:12:58 -0800 | [diff] [blame] | 3960 | i == sh->pd_idx || i == sh->qd_idx || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3961 | test_bit(R5_InJournal, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3962 | !test_bit(R5_LOCKED, &dev->flags) && |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 3963 | !(uptodate_for_rmw(dev) || |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3964 | test_bit(R5_Wantcompute, &dev->flags))) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3965 | if (test_bit(R5_Insync, &dev->flags)) |
| 3966 | rmw++; |
| 3967 | else |
| 3968 | rmw += 2*disks; /* cannot read it */ |
| 3969 | } |
| 3970 | /* Would I have to read this buffer for reconstruct_write */ |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 3971 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
| 3972 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3973 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 3974 | !(test_bit(R5_UPTODATE, &dev->flags) || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3975 | test_bit(R5_Wantcompute, &dev->flags))) { |
NeilBrown | 67f4554 | 2014-05-28 13:39:22 +1000 | [diff] [blame] | 3976 | if (test_bit(R5_Insync, &dev->flags)) |
| 3977 | rcw++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3978 | else |
| 3979 | rcw += 2*disks; |
| 3980 | } |
| 3981 | } |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3982 | |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 3983 | pr_debug("for sector %llu state 0x%lx, rmw=%d rcw=%d\n", |
| 3984 | (unsigned long long)sh->sector, sh->state, rmw, rcw); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3985 | set_bit(STRIPE_HANDLE, &sh->state); |
Song Liu | 4125758 | 2016-05-23 17:25:06 -0700 | [diff] [blame] | 3986 | 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] | 3987 | /* prefer read-modify-write, but need to get some data */ |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 3988 | if (conf->mddev->queue) |
| 3989 | blk_add_trace_msg(conf->mddev->queue, |
| 3990 | "raid5 rmw %llu %d", |
| 3991 | (unsigned long long)sh->sector, rmw); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 3992 | for (i = disks; i--; ) { |
| 3993 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3994 | if (test_bit(R5_InJournal, &dev->flags) && |
| 3995 | dev->page == dev->orig_page && |
| 3996 | !test_bit(R5_LOCKED, &sh->dev[sh->pd_idx].flags)) { |
| 3997 | /* alloc page for prexor */ |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 3998 | struct page *p = alloc_page(GFP_NOIO); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 3999 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 4000 | if (p) { |
| 4001 | dev->orig_page = p; |
| 4002 | continue; |
| 4003 | } |
| 4004 | |
| 4005 | /* |
| 4006 | * alloc_page() failed, try use |
| 4007 | * disk_info->extra_page |
| 4008 | */ |
| 4009 | if (!test_and_set_bit(R5C_EXTRA_PAGE_IN_USE, |
| 4010 | &conf->cache_state)) { |
| 4011 | r5c_use_extra_page(sh); |
| 4012 | break; |
| 4013 | } |
| 4014 | |
| 4015 | /* extra_page in use, add to delayed_list */ |
| 4016 | set_bit(STRIPE_DELAYED, &sh->state); |
| 4017 | s->waiting_extra_page = 1; |
| 4018 | return -EAGAIN; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4019 | } |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 4020 | } |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4021 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 4022 | for (i = disks; i--; ) { |
| 4023 | struct r5dev *dev = &sh->dev[i]; |
Song Liu | 39b9958 | 2017-01-24 14:08:23 -0800 | [diff] [blame] | 4024 | if (((dev->towrite && !delay_towrite(conf, dev, s)) || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4025 | i == sh->pd_idx || i == sh->qd_idx || |
| 4026 | test_bit(R5_InJournal, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4027 | !test_bit(R5_LOCKED, &dev->flags) && |
Song Liu | 86aa139 | 2017-01-12 17:22:41 -0800 | [diff] [blame] | 4028 | !(uptodate_for_rmw(dev) || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4029 | test_bit(R5_Wantcompute, &dev->flags)) && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4030 | test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 67f4554 | 2014-05-28 13:39:22 +1000 | [diff] [blame] | 4031 | if (test_bit(STRIPE_PREREAD_ACTIVE, |
| 4032 | &sh->state)) { |
| 4033 | pr_debug("Read_old block %d for r-m-w\n", |
| 4034 | i); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4035 | set_bit(R5_LOCKED, &dev->flags); |
| 4036 | set_bit(R5_Wantread, &dev->flags); |
| 4037 | s->locked++; |
Guoqing Jiang | e3914d5 | 2020-07-28 12:01:40 +0200 | [diff] [blame] | 4038 | } else |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4039 | set_bit(STRIPE_DELAYED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4040 | } |
| 4041 | } |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4042 | } |
Song Liu | 4125758 | 2016-05-23 17:25:06 -0700 | [diff] [blame] | 4043 | 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] | 4044 | /* want reconstruct write, but need to get some data */ |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4045 | int qread =0; |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4046 | rcw = 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4047 | for (i = disks; i--; ) { |
| 4048 | struct r5dev *dev = &sh->dev[i]; |
| 4049 | if (!test_bit(R5_OVERWRITE, &dev->flags) && |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4050 | i != sh->pd_idx && i != sh->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4051 | !test_bit(R5_LOCKED, &dev->flags) && |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 4052 | !(test_bit(R5_UPTODATE, &dev->flags) || |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4053 | test_bit(R5_Wantcompute, &dev->flags))) { |
| 4054 | rcw++; |
NeilBrown | 67f4554 | 2014-05-28 13:39:22 +1000 | [diff] [blame] | 4055 | if (test_bit(R5_Insync, &dev->flags) && |
| 4056 | test_bit(STRIPE_PREREAD_ACTIVE, |
| 4057 | &sh->state)) { |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4058 | pr_debug("Read_old block " |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4059 | "%d for Reconstruct\n", i); |
| 4060 | set_bit(R5_LOCKED, &dev->flags); |
| 4061 | set_bit(R5_Wantread, &dev->flags); |
| 4062 | s->locked++; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4063 | qread++; |
Guoqing Jiang | e3914d5 | 2020-07-28 12:01:40 +0200 | [diff] [blame] | 4064 | } else |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4065 | set_bit(STRIPE_DELAYED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4066 | } |
| 4067 | } |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 4068 | if (rcw && conf->mddev->queue) |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 4069 | blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", |
| 4070 | (unsigned long long)sh->sector, |
| 4071 | rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); |
NeilBrown | c8ac180 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4072 | } |
NeilBrown | b1b02fe | 2015-02-02 10:44:29 +1100 | [diff] [blame] | 4073 | |
| 4074 | if (rcw > disks && rmw > disks && |
| 4075 | !test_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4076 | set_bit(STRIPE_DELAYED, &sh->state); |
| 4077 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4078 | /* now if nothing is locked, and if we have enough data, |
| 4079 | * we can start a write request |
| 4080 | */ |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 4081 | /* since handle_stripe can be called at any time we need to handle the |
| 4082 | * case where a compute block operation has been submitted and then a |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 4083 | * subsequent call wants to start a write request. raid_run_ops only |
| 4084 | * handles the case where compute block and reconstruct are requested |
Dan Williams | f38e121 | 2007-01-02 13:52:30 -0700 | [diff] [blame] | 4085 | * simultaneously. If this is not the case then new writes need to be |
| 4086 | * held off until the compute completes. |
| 4087 | */ |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 4088 | if ((s->req_compute || !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) && |
| 4089 | (s->locked == 0 && (rcw == 0 || rmw == 0) && |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4090 | !test_bit(STRIPE_BIT_DELAY, &sh->state))) |
Yuri Tikhonov | c0f7bdd | 2009-08-29 19:13:12 -0700 | [diff] [blame] | 4091 | schedule_reconstruction(sh, s, rcw == 0, 0); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 4092 | return 0; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4095 | static void handle_parity_checks5(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4096 | struct stripe_head_state *s, int disks) |
| 4097 | { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4098 | struct r5dev *dev = NULL; |
Dan Williams | e89f896 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4099 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4100 | BUG_ON(sh->batch_head); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4101 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4102 | |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4103 | switch (sh->check_state) { |
| 4104 | case check_state_idle: |
| 4105 | /* start a new check operation if there are no failures */ |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4106 | if (s->failed == 0) { |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4107 | BUG_ON(s->uptodate != disks); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4108 | sh->check_state = check_state_run; |
| 4109 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4110 | clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags); |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4111 | s->uptodate--; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4112 | break; |
Dan Williams | bd2ab67 | 2008-04-10 21:29:27 -0700 | [diff] [blame] | 4113 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4114 | dev = &sh->dev[s->failed_num[0]]; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4115 | fallthrough; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4116 | case check_state_compute_result: |
| 4117 | sh->check_state = check_state_idle; |
| 4118 | if (!dev) |
| 4119 | dev = &sh->dev[sh->pd_idx]; |
| 4120 | |
| 4121 | /* check that a write has not made the stripe insync */ |
| 4122 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 4123 | break; |
| 4124 | |
| 4125 | /* either failed parity check, or recovery is happening */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4126 | BUG_ON(!test_bit(R5_UPTODATE, &dev->flags)); |
| 4127 | BUG_ON(s->uptodate != disks); |
| 4128 | |
| 4129 | set_bit(R5_LOCKED, &dev->flags); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4130 | s->locked++; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4131 | set_bit(R5_Wantwrite, &dev->flags); |
Dan Williams | 830ea01 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4132 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4133 | clear_bit(STRIPE_DEGRADED, &sh->state); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4134 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4135 | break; |
| 4136 | case check_state_run: |
| 4137 | break; /* we will be called again upon completion */ |
| 4138 | case check_state_check_result: |
| 4139 | sh->check_state = check_state_idle; |
| 4140 | |
| 4141 | /* if a failure occurred during the check operation, leave |
| 4142 | * STRIPE_INSYNC not set and let the stripe be handled again |
| 4143 | */ |
| 4144 | if (s->failed) |
| 4145 | break; |
| 4146 | |
| 4147 | /* handle a successful check operation, if parity is correct |
| 4148 | * we are done. Otherwise update the mismatch count and repair |
| 4149 | * parity if !MD_RECOVERY_CHECK |
| 4150 | */ |
Dan Williams | ad283ea | 2009-08-29 19:09:26 -0700 | [diff] [blame] | 4151 | if ((sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) == 0) |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4152 | /* parity is correct (on disc, |
| 4153 | * not in buffer any more) |
| 4154 | */ |
| 4155 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4156 | else { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4157 | atomic64_add(RAID5_STRIPE_SECTORS(conf), &conf->mddev->resync_mismatches); |
Nix | e153903 | 2017-05-16 10:13:31 +0100 | [diff] [blame] | 4158 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4159 | /* don't try to repair!! */ |
| 4160 | set_bit(STRIPE_INSYNC, &sh->state); |
Nix | e153903 | 2017-05-16 10:13:31 +0100 | [diff] [blame] | 4161 | pr_warn_ratelimited("%s: mismatch sector in range " |
| 4162 | "%llu-%llu\n", mdname(conf->mddev), |
| 4163 | (unsigned long long) sh->sector, |
| 4164 | (unsigned long long) sh->sector + |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4165 | RAID5_STRIPE_SECTORS(conf)); |
Nix | e153903 | 2017-05-16 10:13:31 +0100 | [diff] [blame] | 4166 | } else { |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4167 | sh->check_state = check_state_compute_run; |
Dan Williams | 976ea8d | 2008-06-28 08:32:03 +1000 | [diff] [blame] | 4168 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4169 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 4170 | set_bit(R5_Wantcompute, |
| 4171 | &sh->dev[sh->pd_idx].flags); |
| 4172 | sh->ops.target = sh->pd_idx; |
Dan Williams | ac6b53b | 2009-07-14 13:40:19 -0700 | [diff] [blame] | 4173 | sh->ops.target2 = -1; |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4174 | s->uptodate++; |
| 4175 | } |
| 4176 | } |
| 4177 | break; |
| 4178 | case check_state_compute_run: |
| 4179 | break; |
| 4180 | default: |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 4181 | pr_err("%s: unknown check_state: %d sector: %llu\n", |
Dan Williams | ecc65c9 | 2008-06-28 08:31:57 +1000 | [diff] [blame] | 4182 | __func__, sh->check_state, |
| 4183 | (unsigned long long) sh->sector); |
| 4184 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4185 | } |
| 4186 | } |
| 4187 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4188 | static void handle_parity_checks6(struct r5conf *conf, struct stripe_head *sh, |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4189 | struct stripe_head_state *s, |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4190 | int disks) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4191 | { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4192 | int pd_idx = sh->pd_idx; |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 4193 | int qd_idx = sh->qd_idx; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4194 | struct r5dev *dev; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4195 | |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4196 | BUG_ON(sh->batch_head); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4197 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4198 | |
| 4199 | BUG_ON(s->failed > 2); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4200 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4201 | /* Want to check and possibly repair P and Q. |
| 4202 | * However there could be one 'failed' device, in which |
| 4203 | * case we can only check one of them, possibly using the |
| 4204 | * other to generate missing data |
| 4205 | */ |
| 4206 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4207 | switch (sh->check_state) { |
| 4208 | case check_state_idle: |
| 4209 | /* start a new check operation if there are < 2 failures */ |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4210 | if (s->failed == s->q_failed) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4211 | /* The only possible failed device holds Q, so it |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4212 | * makes sense to check P (If anything else were failed, |
| 4213 | * we would have used P to recreate it). |
| 4214 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4215 | sh->check_state = check_state_run; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4216 | } |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4217 | if (!s->q_failed && s->failed < 2) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4218 | /* Q is not failed, and we didn't use it to generate |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4219 | * anything, so it makes sense to check it |
| 4220 | */ |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4221 | if (sh->check_state == check_state_run) |
| 4222 | sh->check_state = check_state_run_pq; |
| 4223 | else |
| 4224 | sh->check_state = check_state_run_q; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4225 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4226 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4227 | /* discard potentially stale zero_sum_result */ |
| 4228 | sh->ops.zero_sum_result = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4229 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4230 | if (sh->check_state == check_state_run) { |
| 4231 | /* async_xor_zero_sum destroys the contents of P */ |
| 4232 | clear_bit(R5_UPTODATE, &sh->dev[pd_idx].flags); |
| 4233 | s->uptodate--; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4234 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4235 | if (sh->check_state >= check_state_run && |
| 4236 | sh->check_state <= check_state_run_pq) { |
| 4237 | /* async_syndrome_zero_sum preserves P and Q, so |
| 4238 | * no need to mark them !uptodate here |
| 4239 | */ |
| 4240 | set_bit(STRIPE_OP_CHECK, &s->ops_request); |
| 4241 | break; |
| 4242 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4243 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4244 | /* we have 2-disk failure */ |
| 4245 | BUG_ON(s->failed != 2); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 4246 | fallthrough; |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4247 | case check_state_compute_result: |
| 4248 | sh->check_state = check_state_idle; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 4249 | |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4250 | /* check that a write has not made the stripe insync */ |
| 4251 | if (test_bit(STRIPE_INSYNC, &sh->state)) |
| 4252 | break; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4253 | |
| 4254 | /* now write out any block on a failed drive, |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4255 | * or P or Q if they were recomputed |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4256 | */ |
Nigel Croxon | b2176a1 | 2019-04-16 09:50:09 -0700 | [diff] [blame] | 4257 | dev = NULL; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4258 | if (s->failed == 2) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4259 | dev = &sh->dev[s->failed_num[1]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4260 | s->locked++; |
| 4261 | set_bit(R5_LOCKED, &dev->flags); |
| 4262 | set_bit(R5_Wantwrite, &dev->flags); |
| 4263 | } |
| 4264 | if (s->failed >= 1) { |
NeilBrown | f2b3b44 | 2011-07-26 11:35:19 +1000 | [diff] [blame] | 4265 | dev = &sh->dev[s->failed_num[0]]; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4266 | s->locked++; |
| 4267 | set_bit(R5_LOCKED, &dev->flags); |
| 4268 | set_bit(R5_Wantwrite, &dev->flags); |
| 4269 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4270 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4271 | dev = &sh->dev[pd_idx]; |
| 4272 | s->locked++; |
| 4273 | set_bit(R5_LOCKED, &dev->flags); |
| 4274 | set_bit(R5_Wantwrite, &dev->flags); |
| 4275 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4276 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4277 | dev = &sh->dev[qd_idx]; |
| 4278 | s->locked++; |
| 4279 | set_bit(R5_LOCKED, &dev->flags); |
| 4280 | set_bit(R5_Wantwrite, &dev->flags); |
| 4281 | } |
Nigel Croxon | b2176a1 | 2019-04-16 09:50:09 -0700 | [diff] [blame] | 4282 | if (WARN_ONCE(dev && !test_bit(R5_UPTODATE, &dev->flags), |
| 4283 | "%s: disk%td not up to date\n", |
| 4284 | mdname(conf->mddev), |
| 4285 | dev - (struct r5dev *) &sh->dev)) { |
| 4286 | clear_bit(R5_LOCKED, &dev->flags); |
| 4287 | clear_bit(R5_Wantwrite, &dev->flags); |
| 4288 | s->locked--; |
| 4289 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4290 | clear_bit(STRIPE_DEGRADED, &sh->state); |
| 4291 | |
| 4292 | set_bit(STRIPE_INSYNC, &sh->state); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4293 | break; |
| 4294 | case check_state_run: |
| 4295 | case check_state_run_q: |
| 4296 | case check_state_run_pq: |
| 4297 | break; /* we will be called again upon completion */ |
| 4298 | case check_state_check_result: |
| 4299 | sh->check_state = check_state_idle; |
| 4300 | |
| 4301 | /* handle a successful check operation, if parity is correct |
| 4302 | * we are done. Otherwise update the mismatch count and repair |
| 4303 | * parity if !MD_RECOVERY_CHECK |
| 4304 | */ |
| 4305 | if (sh->ops.zero_sum_result == 0) { |
Song Liu | a25d8c3 | 2019-04-16 09:34:21 -0700 | [diff] [blame] | 4306 | /* both parities are correct */ |
| 4307 | if (!s->failed) |
| 4308 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4309 | else { |
| 4310 | /* in contrast to the raid5 case we can validate |
| 4311 | * parity, but still have a failure to write |
| 4312 | * back |
| 4313 | */ |
| 4314 | sh->check_state = check_state_compute_result; |
| 4315 | /* Returning at this point means that we may go |
| 4316 | * off and bring p and/or q uptodate again so |
| 4317 | * we make sure to check zero_sum_result again |
| 4318 | * to verify if p or q need writeback |
| 4319 | */ |
| 4320 | } |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4321 | } else { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4322 | atomic64_add(RAID5_STRIPE_SECTORS(conf), &conf->mddev->resync_mismatches); |
Nix | e153903 | 2017-05-16 10:13:31 +0100 | [diff] [blame] | 4323 | if (test_bit(MD_RECOVERY_CHECK, &conf->mddev->recovery)) { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4324 | /* don't try to repair!! */ |
| 4325 | set_bit(STRIPE_INSYNC, &sh->state); |
Nix | e153903 | 2017-05-16 10:13:31 +0100 | [diff] [blame] | 4326 | pr_warn_ratelimited("%s: mismatch sector in range " |
| 4327 | "%llu-%llu\n", mdname(conf->mddev), |
| 4328 | (unsigned long long) sh->sector, |
| 4329 | (unsigned long long) sh->sector + |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4330 | RAID5_STRIPE_SECTORS(conf)); |
Nix | e153903 | 2017-05-16 10:13:31 +0100 | [diff] [blame] | 4331 | } else { |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4332 | int *target = &sh->ops.target; |
| 4333 | |
| 4334 | sh->ops.target = -1; |
| 4335 | sh->ops.target2 = -1; |
| 4336 | sh->check_state = check_state_compute_run; |
| 4337 | set_bit(STRIPE_COMPUTE_RUN, &sh->state); |
| 4338 | set_bit(STRIPE_OP_COMPUTE_BLK, &s->ops_request); |
| 4339 | if (sh->ops.zero_sum_result & SUM_CHECK_P_RESULT) { |
| 4340 | set_bit(R5_Wantcompute, |
| 4341 | &sh->dev[pd_idx].flags); |
| 4342 | *target = pd_idx; |
| 4343 | target = &sh->ops.target2; |
| 4344 | s->uptodate++; |
| 4345 | } |
| 4346 | if (sh->ops.zero_sum_result & SUM_CHECK_Q_RESULT) { |
| 4347 | set_bit(R5_Wantcompute, |
| 4348 | &sh->dev[qd_idx].flags); |
| 4349 | *target = qd_idx; |
| 4350 | s->uptodate++; |
| 4351 | } |
| 4352 | } |
| 4353 | } |
| 4354 | break; |
| 4355 | case check_state_compute_run: |
| 4356 | break; |
| 4357 | default: |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 4358 | pr_warn("%s: unknown check_state: %d sector: %llu\n", |
| 4359 | __func__, sh->check_state, |
| 4360 | (unsigned long long) sh->sector); |
Dan Williams | d82dfee | 2009-07-14 13:40:57 -0700 | [diff] [blame] | 4361 | BUG(); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4362 | } |
| 4363 | } |
| 4364 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4365 | static void handle_stripe_expansion(struct r5conf *conf, struct stripe_head *sh) |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4366 | { |
| 4367 | int i; |
| 4368 | |
| 4369 | /* We have read all the blocks in this stripe and now we need to |
| 4370 | * copy some of them into a target stripe for expand. |
| 4371 | */ |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4372 | struct dma_async_tx_descriptor *tx = NULL; |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4373 | BUG_ON(sh->batch_head); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4374 | clear_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 4375 | for (i = 0; i < sh->disks; i++) |
NeilBrown | 34e04e8 | 2009-03-31 15:10:16 +1100 | [diff] [blame] | 4376 | if (i != sh->pd_idx && i != sh->qd_idx) { |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4377 | int dd_idx, j; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4378 | struct stripe_head *sh2; |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 4379 | struct async_submit_ctl submit; |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4380 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4381 | sector_t bn = raid5_compute_blocknr(sh, i, 1); |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 4382 | sector_t s = raid5_compute_sector(conf, bn, 0, |
| 4383 | &dd_idx, NULL); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4384 | sh2 = raid5_get_active_stripe(conf, s, 0, 1, 1); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4385 | if (sh2 == NULL) |
| 4386 | /* so far only the early blocks of this stripe |
| 4387 | * have been requested. When later blocks |
| 4388 | * get requested, we will try again |
| 4389 | */ |
| 4390 | continue; |
| 4391 | if (!test_bit(STRIPE_EXPANDING, &sh2->state) || |
| 4392 | test_bit(R5_Expanded, &sh2->dev[dd_idx].flags)) { |
| 4393 | /* must have already done this block */ |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4394 | raid5_release_stripe(sh2); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4395 | continue; |
| 4396 | } |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4397 | |
| 4398 | /* place all the copies on one channel */ |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 4399 | init_async_submit(&submit, 0, tx, NULL, NULL, NULL); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4400 | tx = async_memcpy(sh2->dev[dd_idx].page, |
Yufen Yu | 7aba13b | 2020-08-20 09:22:06 -0400 | [diff] [blame] | 4401 | sh->dev[i].page, sh2->dev[dd_idx].offset, |
| 4402 | sh->dev[i].offset, RAID5_STRIPE_SIZE(conf), |
Dan Williams | a08abd8 | 2009-06-03 11:43:59 -0700 | [diff] [blame] | 4403 | &submit); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4404 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4405 | set_bit(R5_Expanded, &sh2->dev[dd_idx].flags); |
| 4406 | set_bit(R5_UPTODATE, &sh2->dev[dd_idx].flags); |
| 4407 | for (j = 0; j < conf->raid_disks; j++) |
| 4408 | if (j != sh2->pd_idx && |
NeilBrown | 86c374b | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4409 | j != sh2->qd_idx && |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4410 | !test_bit(R5_Expanded, &sh2->dev[j].flags)) |
| 4411 | break; |
| 4412 | if (j == conf->raid_disks) { |
| 4413 | set_bit(STRIPE_EXPAND_READY, &sh2->state); |
| 4414 | set_bit(STRIPE_HANDLE, &sh2->state); |
| 4415 | } |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4416 | raid5_release_stripe(sh2); |
Dan Williams | f0a50d3 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 4417 | |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4418 | } |
NeilBrown | a2e0855 | 2007-09-11 15:23:36 -0700 | [diff] [blame] | 4419 | /* done submitting copies, wait for them to complete */ |
NeilBrown | 749586b | 2012-11-20 14:11:15 +1100 | [diff] [blame] | 4420 | async_tx_quiesce(&tx); |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | |
| 4423 | /* |
| 4424 | * handle_stripe - do things to a stripe. |
| 4425 | * |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4426 | * We lock the stripe by setting STRIPE_ACTIVE and then examine the |
| 4427 | * state of various bits to see what needs to be done. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | * Possible results: |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4429 | * return some read requests which now have data |
| 4430 | * return some write requests which are safely on storage |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | * schedule a read on some buffers |
| 4432 | * schedule a write of some buffers |
| 4433 | * return confirmation of parity correctness |
| 4434 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | */ |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4436 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4437 | static void analyse_stripe(struct stripe_head *sh, struct stripe_head_state *s) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4438 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4439 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4440 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4441 | struct r5dev *dev; |
| 4442 | int i; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4443 | int do_recovery = 0; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4444 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4445 | memset(s, 0, sizeof(*s)); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4446 | |
shli@kernel.org | dabc4ec | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 4447 | s->expanding = test_bit(STRIPE_EXPAND_SOURCE, &sh->state) && !sh->batch_head; |
| 4448 | s->expanded = test_bit(STRIPE_EXPAND_READY, &sh->state) && !sh->batch_head; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4449 | s->failed_num[0] = -1; |
| 4450 | s->failed_num[1] = -1; |
Shaohua Li | 6e74a9c | 2015-10-08 21:54:08 -0700 | [diff] [blame] | 4451 | s->log_failed = r5l_log_disk_error(conf); |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4452 | |
| 4453 | /* Now to look around and see what can be done */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4454 | rcu_read_lock(); |
| 4455 | for (i=disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 4456 | struct md_rdev *rdev; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4457 | sector_t first_bad; |
| 4458 | int bad_sectors; |
| 4459 | int is_bad = 0; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4460 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4461 | dev = &sh->dev[i]; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4462 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4463 | 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] | 4464 | i, dev->flags, |
| 4465 | dev->toread, dev->towrite, dev->written); |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 4466 | /* maybe we can reply to a read |
| 4467 | * |
| 4468 | * new wantfill requests are only permitted while |
| 4469 | * ops_complete_biofill is guaranteed to be inactive |
| 4470 | */ |
| 4471 | if (test_bit(R5_UPTODATE, &dev->flags) && dev->toread && |
| 4472 | !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) |
| 4473 | set_bit(R5_Wantfill, &dev->flags); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4474 | |
| 4475 | /* now count some things */ |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4476 | if (test_bit(R5_LOCKED, &dev->flags)) |
| 4477 | s->locked++; |
| 4478 | if (test_bit(R5_UPTODATE, &dev->flags)) |
| 4479 | s->uptodate++; |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 4480 | if (test_bit(R5_Wantcompute, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4481 | s->compute++; |
| 4482 | BUG_ON(s->compute > 2); |
Dan Williams | 2d6e4ec | 2009-09-16 12:11:54 -0700 | [diff] [blame] | 4483 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4484 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4485 | if (test_bit(R5_Wantfill, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4486 | s->to_fill++; |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4487 | else if (dev->toread) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4488 | s->to_read++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4489 | if (dev->towrite) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4490 | s->to_write++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4491 | if (!test_bit(R5_OVERWRITE, &dev->flags)) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4492 | s->non_overwrite++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4493 | } |
Dan Williams | a445685 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 4494 | if (dev->written) |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4495 | s->written++; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4496 | /* Prefer to use the replacement for reads, but only |
| 4497 | * if it is recovered enough and has no bad blocks. |
| 4498 | */ |
| 4499 | rdev = rcu_dereference(conf->disks[i].replacement); |
| 4500 | if (rdev && !test_bit(Faulty, &rdev->flags) && |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4501 | rdev->recovery_offset >= sh->sector + RAID5_STRIPE_SECTORS(conf) && |
| 4502 | !is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4503 | &first_bad, &bad_sectors)) |
| 4504 | set_bit(R5_ReadRepl, &dev->flags); |
| 4505 | else { |
NeilBrown | e6030cb | 2015-07-17 13:26:23 +1000 | [diff] [blame] | 4506 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4507 | set_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | e6030cb | 2015-07-17 13:26:23 +1000 | [diff] [blame] | 4508 | else |
| 4509 | clear_bit(R5_NeedReplace, &dev->flags); |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4510 | rdev = rcu_dereference(conf->disks[i].rdev); |
| 4511 | clear_bit(R5_ReadRepl, &dev->flags); |
| 4512 | } |
NeilBrown | 9283d8c | 2011-12-08 16:27:57 +1100 | [diff] [blame] | 4513 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 4514 | rdev = NULL; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4515 | if (rdev) { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4516 | is_bad = is_badblock(rdev, sh->sector, RAID5_STRIPE_SECTORS(conf), |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4517 | &first_bad, &bad_sectors); |
| 4518 | if (s->blocked_rdev == NULL |
| 4519 | && (test_bit(Blocked, &rdev->flags) |
| 4520 | || is_bad < 0)) { |
| 4521 | if (is_bad < 0) |
| 4522 | set_bit(BlockedBadBlocks, |
| 4523 | &rdev->flags); |
| 4524 | s->blocked_rdev = rdev; |
| 4525 | atomic_inc(&rdev->nr_pending); |
| 4526 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 4527 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4528 | clear_bit(R5_Insync, &dev->flags); |
| 4529 | if (!rdev) |
| 4530 | /* Not in-sync */; |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4531 | else if (is_bad) { |
| 4532 | /* also not in-sync */ |
NeilBrown | 18b9837 | 2012-04-01 23:48:38 +1000 | [diff] [blame] | 4533 | if (!test_bit(WriteErrorSeen, &rdev->flags) && |
| 4534 | test_bit(R5_UPTODATE, &dev->flags)) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4535 | /* treat as in-sync, but with a read error |
| 4536 | * which we can now try to correct |
| 4537 | */ |
| 4538 | set_bit(R5_Insync, &dev->flags); |
| 4539 | set_bit(R5_ReadError, &dev->flags); |
| 4540 | } |
| 4541 | } else if (test_bit(In_sync, &rdev->flags)) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4542 | set_bit(R5_Insync, &dev->flags); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4543 | else if (sh->sector + RAID5_STRIPE_SECTORS(conf) <= rdev->recovery_offset) |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4544 | /* in sync if before recovery_offset */ |
NeilBrown | 30d7a48 | 2011-12-23 09:57:00 +1100 | [diff] [blame] | 4545 | set_bit(R5_Insync, &dev->flags); |
| 4546 | else if (test_bit(R5_UPTODATE, &dev->flags) && |
| 4547 | test_bit(R5_Expanded, &dev->flags)) |
| 4548 | /* If we've reshaped into here, we assume it is Insync. |
| 4549 | * We will shortly update recovery_offset to make |
| 4550 | * it official. |
| 4551 | */ |
| 4552 | set_bit(R5_Insync, &dev->flags); |
| 4553 | |
NeilBrown | 1cc03eb | 2014-01-06 13:19:42 +1100 | [diff] [blame] | 4554 | if (test_bit(R5_WriteError, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4555 | /* This flag does not apply to '.replacement' |
| 4556 | * only to .rdev, so make sure to check that*/ |
| 4557 | struct md_rdev *rdev2 = rcu_dereference( |
| 4558 | conf->disks[i].rdev); |
| 4559 | if (rdev2 == rdev) |
| 4560 | clear_bit(R5_Insync, &dev->flags); |
| 4561 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4562 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4563 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4564 | } else |
| 4565 | clear_bit(R5_WriteError, &dev->flags); |
| 4566 | } |
NeilBrown | 1cc03eb | 2014-01-06 13:19:42 +1100 | [diff] [blame] | 4567 | if (test_bit(R5_MadeGood, &dev->flags)) { |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4568 | /* This flag does not apply to '.replacement' |
| 4569 | * only to .rdev, so make sure to check that*/ |
| 4570 | struct md_rdev *rdev2 = rcu_dereference( |
| 4571 | conf->disks[i].rdev); |
| 4572 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 4573 | s->handle_bad_blocks = 1; |
NeilBrown | 14a75d3 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 4574 | atomic_inc(&rdev2->nr_pending); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 4575 | } else |
| 4576 | clear_bit(R5_MadeGood, &dev->flags); |
| 4577 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4578 | if (test_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 4579 | struct md_rdev *rdev2 = rcu_dereference( |
| 4580 | conf->disks[i].replacement); |
| 4581 | if (rdev2 && !test_bit(Faulty, &rdev2->flags)) { |
| 4582 | s->handle_bad_blocks = 1; |
| 4583 | atomic_inc(&rdev2->nr_pending); |
| 4584 | } else |
| 4585 | clear_bit(R5_MadeGoodRepl, &dev->flags); |
| 4586 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4587 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4588 | /* The ReadError flag will just be confusing now */ |
| 4589 | clear_bit(R5_ReadError, &dev->flags); |
| 4590 | clear_bit(R5_ReWrite, &dev->flags); |
| 4591 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4592 | if (test_bit(R5_ReadError, &dev->flags)) |
| 4593 | clear_bit(R5_Insync, &dev->flags); |
| 4594 | if (!test_bit(R5_Insync, &dev->flags)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4595 | if (s->failed < 2) |
| 4596 | s->failed_num[s->failed] = i; |
| 4597 | s->failed++; |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4598 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
| 4599 | do_recovery = 1; |
BingJing Chang | d63e2fc | 2018-08-01 17:08:36 +0800 | [diff] [blame] | 4600 | else if (!rdev) { |
| 4601 | rdev = rcu_dereference( |
| 4602 | conf->disks[i].replacement); |
| 4603 | if (rdev && !test_bit(Faulty, &rdev->flags)) |
| 4604 | do_recovery = 1; |
| 4605 | } |
NeilBrown | 415e72d | 2010-06-17 17:25:21 +1000 | [diff] [blame] | 4606 | } |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4607 | |
| 4608 | if (test_bit(R5_InJournal, &dev->flags)) |
| 4609 | s->injournal++; |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4610 | if (test_bit(R5_InJournal, &dev->flags) && dev->written) |
| 4611 | s->just_cached++; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4612 | } |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4613 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
| 4614 | /* If there is a failed device being replaced, |
| 4615 | * we must be recovering. |
| 4616 | * else if we are after recovery_cp, we must be syncing |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 4617 | * else if MD_RECOVERY_REQUESTED is set, we also are syncing. |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4618 | * else we can only be replacing |
| 4619 | * sync and recovery both need to read all devices, and so |
| 4620 | * use the same flag. |
| 4621 | */ |
| 4622 | if (do_recovery || |
majianpeng | c6d2e08 | 2012-04-02 01:16:59 +1000 | [diff] [blame] | 4623 | sh->sector >= conf->mddev->recovery_cp || |
| 4624 | test_bit(MD_RECOVERY_REQUESTED, &(conf->mddev->recovery))) |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4625 | s->syncing = 1; |
| 4626 | else |
| 4627 | s->replacing = 1; |
| 4628 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 4629 | rcu_read_unlock(); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4630 | } |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 4631 | |
Guoqing Jiang | cb9902d | 2020-06-16 11:25:51 +0200 | [diff] [blame] | 4632 | /* |
| 4633 | * Return '1' if this is a member of batch, or '0' if it is a lone stripe or |
| 4634 | * a head which can now be handled. |
| 4635 | */ |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4636 | static int clear_batch_ready(struct stripe_head *sh) |
| 4637 | { |
| 4638 | struct stripe_head *tmp; |
| 4639 | if (!test_and_clear_bit(STRIPE_BATCH_READY, &sh->state)) |
NeilBrown | b15a9db | 2015-05-22 15:20:04 +1000 | [diff] [blame] | 4640 | return (sh->batch_head && sh->batch_head != sh); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4641 | spin_lock(&sh->stripe_lock); |
| 4642 | if (!sh->batch_head) { |
| 4643 | spin_unlock(&sh->stripe_lock); |
| 4644 | return 0; |
| 4645 | } |
| 4646 | |
| 4647 | /* |
| 4648 | * this stripe could be added to a batch list before we check |
| 4649 | * BATCH_READY, skips it |
| 4650 | */ |
| 4651 | if (sh->batch_head != sh) { |
| 4652 | spin_unlock(&sh->stripe_lock); |
| 4653 | return 1; |
| 4654 | } |
| 4655 | spin_lock(&sh->batch_lock); |
| 4656 | list_for_each_entry(tmp, &sh->batch_list, batch_list) |
| 4657 | clear_bit(STRIPE_BATCH_READY, &tmp->state); |
| 4658 | spin_unlock(&sh->batch_lock); |
| 4659 | spin_unlock(&sh->stripe_lock); |
| 4660 | |
| 4661 | /* |
| 4662 | * BATCH_READY is cleared, no new stripes can be added. |
| 4663 | * batch_list can be accessed without lock |
| 4664 | */ |
| 4665 | return 0; |
| 4666 | } |
| 4667 | |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4668 | static void break_stripe_batch_list(struct stripe_head *head_sh, |
| 4669 | unsigned long handle_flags) |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4670 | { |
NeilBrown | 4e3d62f | 2015-05-21 11:50:16 +1000 | [diff] [blame] | 4671 | struct stripe_head *sh, *next; |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4672 | int i; |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4673 | int do_wakeup = 0; |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4674 | |
NeilBrown | bb27051 | 2015-05-08 18:19:40 +1000 | [diff] [blame] | 4675 | list_for_each_entry_safe(sh, next, &head_sh->batch_list, batch_list) { |
| 4676 | |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4677 | list_del_init(&sh->batch_list); |
| 4678 | |
Shaohua Li | fb3229d | 2016-03-09 10:08:38 -0800 | [diff] [blame] | 4679 | WARN_ONCE(sh->state & ((1 << STRIPE_ACTIVE) | |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4680 | (1 << STRIPE_SYNCING) | |
| 4681 | (1 << STRIPE_REPLACED) | |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4682 | (1 << STRIPE_DELAYED) | |
| 4683 | (1 << STRIPE_BIT_DELAY) | |
| 4684 | (1 << STRIPE_FULL_WRITE) | |
| 4685 | (1 << STRIPE_BIOFILL_RUN) | |
| 4686 | (1 << STRIPE_COMPUTE_RUN) | |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4687 | (1 << STRIPE_DISCARD) | |
| 4688 | (1 << STRIPE_BATCH_READY) | |
| 4689 | (1 << STRIPE_BATCH_ERR) | |
Shaohua Li | fb3229d | 2016-03-09 10:08:38 -0800 | [diff] [blame] | 4690 | (1 << STRIPE_BITMAP_PENDING)), |
| 4691 | "stripe state: %lx\n", sh->state); |
| 4692 | WARN_ONCE(head_sh->state & ((1 << STRIPE_DISCARD) | |
| 4693 | (1 << STRIPE_REPLACED)), |
| 4694 | "head stripe state: %lx\n", head_sh->state); |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4695 | |
| 4696 | set_mask_bits(&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | |
NeilBrown | 550da24 | 2016-03-09 12:58:25 +1100 | [diff] [blame] | 4697 | (1 << STRIPE_PREREAD_ACTIVE) | |
Dennis Yang | 184a09e | 2017-09-06 11:02:35 +0800 | [diff] [blame] | 4698 | (1 << STRIPE_DEGRADED) | |
| 4699 | (1 << STRIPE_ON_UNPLUG_LIST)), |
NeilBrown | 1b956f7 | 2015-05-21 12:40:26 +1000 | [diff] [blame] | 4700 | head_sh->state & (1 << STRIPE_INSYNC)); |
| 4701 | |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4702 | sh->check_state = head_sh->check_state; |
| 4703 | sh->reconstruct_state = head_sh->reconstruct_state; |
Amy Chiang | 448ec63 | 2018-05-16 18:59:35 +0800 | [diff] [blame] | 4704 | spin_lock_irq(&sh->stripe_lock); |
| 4705 | sh->batch_head = NULL; |
| 4706 | spin_unlock_irq(&sh->stripe_lock); |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4707 | for (i = 0; i < sh->disks; i++) { |
| 4708 | if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) |
| 4709 | do_wakeup = 1; |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4710 | sh->dev[i].flags = head_sh->dev[i].flags & |
| 4711 | (~((1 << R5_WriteError) | (1 << R5_Overlap))); |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4712 | } |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4713 | if (handle_flags == 0 || |
| 4714 | sh->state & handle_flags) |
| 4715 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 4716 | raid5_release_stripe(sh); |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4717 | } |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4718 | spin_lock_irq(&head_sh->stripe_lock); |
| 4719 | head_sh->batch_head = NULL; |
| 4720 | spin_unlock_irq(&head_sh->stripe_lock); |
| 4721 | for (i = 0; i < head_sh->disks; i++) |
| 4722 | if (test_and_clear_bit(R5_Overlap, &head_sh->dev[i].flags)) |
| 4723 | do_wakeup = 1; |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4724 | if (head_sh->state & handle_flags) |
| 4725 | set_bit(STRIPE_HANDLE, &head_sh->state); |
NeilBrown | fb642b9 | 2015-05-21 12:00:47 +1000 | [diff] [blame] | 4726 | |
| 4727 | if (do_wakeup) |
| 4728 | wake_up(&head_sh->raid_conf->wait_for_overlap); |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4729 | } |
| 4730 | |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4731 | static void handle_stripe(struct stripe_head *sh) |
| 4732 | { |
| 4733 | struct stripe_head_state s; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 4734 | struct r5conf *conf = sh->raid_conf; |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4735 | int i; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4736 | int prexor; |
| 4737 | int disks = sh->disks; |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4738 | struct r5dev *pdev, *qdev; |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4739 | |
| 4740 | clear_bit(STRIPE_HANDLE, &sh->state); |
Guoqing Jiang | a377a47 | 2020-06-16 11:25:50 +0200 | [diff] [blame] | 4741 | |
| 4742 | /* |
| 4743 | * handle_stripe should not continue handle the batched stripe, only |
| 4744 | * the head of batch list or lone stripe can continue. Otherwise we |
| 4745 | * could see break_stripe_batch_list warns about the STRIPE_ACTIVE |
| 4746 | * is set for the batched stripe. |
| 4747 | */ |
| 4748 | if (clear_batch_ready(sh)) |
| 4749 | return; |
| 4750 | |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 4751 | if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) { |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4752 | /* already being handled, ensure it gets handled |
| 4753 | * again when current action finishes */ |
| 4754 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4755 | return; |
| 4756 | } |
| 4757 | |
NeilBrown | 4e3d62f | 2015-05-21 11:50:16 +1000 | [diff] [blame] | 4758 | if (test_and_clear_bit(STRIPE_BATCH_ERR, &sh->state)) |
NeilBrown | 3960ce7 | 2015-05-21 12:20:36 +1000 | [diff] [blame] | 4759 | break_stripe_batch_list(sh, 0); |
shli@kernel.org | 72ac733 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 4760 | |
shli@kernel.org | dabc4ec | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 4761 | if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state) && !sh->batch_head) { |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4762 | spin_lock(&sh->stripe_lock); |
Song Liu | 5ddf044 | 2017-05-11 17:03:44 -0700 | [diff] [blame] | 4763 | /* |
| 4764 | * Cannot process 'sync' concurrently with 'discard'. |
| 4765 | * Flush data in r5cache before 'sync'. |
| 4766 | */ |
| 4767 | if (!test_bit(STRIPE_R5C_PARTIAL_STRIPE, &sh->state) && |
| 4768 | !test_bit(STRIPE_R5C_FULL_STRIPE, &sh->state) && |
| 4769 | !test_bit(STRIPE_DISCARD, &sh->state) && |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4770 | test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { |
| 4771 | set_bit(STRIPE_SYNCING, &sh->state); |
| 4772 | clear_bit(STRIPE_INSYNC, &sh->state); |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4773 | clear_bit(STRIPE_REPLACED, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4774 | } |
| 4775 | spin_unlock(&sh->stripe_lock); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4776 | } |
| 4777 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 4778 | |
| 4779 | pr_debug("handling stripe %llu, state=%#lx cnt=%d, " |
| 4780 | "pd_idx=%d, qd_idx=%d\n, check:%d, reconstruct:%d\n", |
| 4781 | (unsigned long long)sh->sector, sh->state, |
| 4782 | atomic_read(&sh->count), sh->pd_idx, sh->qd_idx, |
| 4783 | sh->check_state, sh->reconstruct_state); |
NeilBrown | cc94015 | 2011-07-26 11:35:35 +1000 | [diff] [blame] | 4784 | |
NeilBrown | acfe726 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4785 | analyse_stripe(sh, &s); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4786 | |
Shaohua Li | b70abcb | 2015-08-13 14:31:58 -0700 | [diff] [blame] | 4787 | if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) |
| 4788 | goto finish; |
| 4789 | |
NeilBrown | 16d997b | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 4790 | if (s.handle_bad_blocks || |
| 4791 | test_bit(MD_SB_CHANGE_PENDING, &conf->mddev->sb_flags)) { |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 4792 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4793 | goto finish; |
| 4794 | } |
| 4795 | |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4796 | if (unlikely(s.blocked_rdev)) { |
| 4797 | if (s.syncing || s.expanding || s.expanded || |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4798 | s.replacing || s.to_write || s.written) { |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4799 | set_bit(STRIPE_HANDLE, &sh->state); |
| 4800 | goto finish; |
| 4801 | } |
| 4802 | /* There is nothing for the blocked_rdev to block */ |
| 4803 | rdev_dec_pending(s.blocked_rdev, conf->mddev); |
| 4804 | s.blocked_rdev = NULL; |
| 4805 | } |
| 4806 | |
| 4807 | if (s.to_fill && !test_bit(STRIPE_BIOFILL_RUN, &sh->state)) { |
| 4808 | set_bit(STRIPE_OP_BIOFILL, &s.ops_request); |
| 4809 | set_bit(STRIPE_BIOFILL_RUN, &sh->state); |
| 4810 | } |
| 4811 | |
| 4812 | pr_debug("locked=%d uptodate=%d to_read=%d" |
| 4813 | " to_write=%d failed=%d failed_num=%d,%d\n", |
| 4814 | s.locked, s.uptodate, s.to_read, s.to_write, s.failed, |
| 4815 | s.failed_num[0], s.failed_num[1]); |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 4816 | /* |
| 4817 | * check if the array has lost more than max_degraded devices and, |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4818 | * if so, some requests might need to be failed. |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 4819 | * |
| 4820 | * When journal device failed (log_failed), we will only process |
| 4821 | * the stripe if there is data need write to raid disks |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4822 | */ |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 4823 | if (s.failed > conf->max_degraded || |
| 4824 | (s.log_failed && s.injournal == 0)) { |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 4825 | sh->check_state = 0; |
| 4826 | sh->reconstruct_state = 0; |
NeilBrown | 626f209 | 2015-05-22 14:03:10 +1000 | [diff] [blame] | 4827 | break_stripe_batch_list(sh, 0); |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 4828 | if (s.to_read+s.to_write+s.written) |
NeilBrown | bd83d0a | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 4829 | handle_failed_stripe(conf, sh, &s, disks); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4830 | if (s.syncing + s.replacing) |
NeilBrown | 9a3f530 | 2011-11-08 16:22:01 +1100 | [diff] [blame] | 4831 | handle_failed_sync(conf, sh, &s); |
| 4832 | } |
NeilBrown | 474af965fe | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4833 | |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4834 | /* Now we check to see if any write operations have recently |
| 4835 | * completed |
| 4836 | */ |
| 4837 | prexor = 0; |
| 4838 | if (sh->reconstruct_state == reconstruct_state_prexor_drain_result) |
| 4839 | prexor = 1; |
| 4840 | if (sh->reconstruct_state == reconstruct_state_drain_result || |
| 4841 | sh->reconstruct_state == reconstruct_state_prexor_drain_result) { |
| 4842 | sh->reconstruct_state = reconstruct_state_idle; |
| 4843 | |
| 4844 | /* All the 'written' buffers and the parity block are ready to |
| 4845 | * be written back to disk |
| 4846 | */ |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 4847 | BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) && |
| 4848 | !test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4849 | BUG_ON(sh->qd_idx >= 0 && |
Shaohua Li | 9e444768 | 2012-10-11 13:49:49 +1100 | [diff] [blame] | 4850 | !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) && |
| 4851 | !test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags)); |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4852 | for (i = disks; i--; ) { |
| 4853 | struct r5dev *dev = &sh->dev[i]; |
| 4854 | if (test_bit(R5_LOCKED, &dev->flags) && |
| 4855 | (i == sh->pd_idx || i == sh->qd_idx || |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4856 | dev->written || test_bit(R5_InJournal, |
| 4857 | &dev->flags))) { |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4858 | pr_debug("Writing block %d\n", i); |
| 4859 | set_bit(R5_Wantwrite, &dev->flags); |
| 4860 | if (prexor) |
| 4861 | continue; |
NeilBrown | 9c4bdf6 | 2014-08-13 09:57:07 +1000 | [diff] [blame] | 4862 | if (s.failed > 1) |
| 4863 | continue; |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4864 | if (!test_bit(R5_Insync, &dev->flags) || |
| 4865 | ((i == sh->pd_idx || i == sh->qd_idx) && |
| 4866 | s.failed == 0)) |
| 4867 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4868 | } |
| 4869 | } |
| 4870 | if (test_and_clear_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 4871 | s.dec_preread_active = 1; |
| 4872 | } |
| 4873 | |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 4874 | /* |
| 4875 | * might be able to return some write requests if the parity blocks |
| 4876 | * are safe, or on a failed drive |
| 4877 | */ |
| 4878 | pdev = &sh->dev[sh->pd_idx]; |
| 4879 | s.p_failed = (s.failed >= 1 && s.failed_num[0] == sh->pd_idx) |
| 4880 | || (s.failed >= 2 && s.failed_num[1] == sh->pd_idx); |
| 4881 | qdev = &sh->dev[sh->qd_idx]; |
| 4882 | s.q_failed = (s.failed >= 1 && s.failed_num[0] == sh->qd_idx) |
| 4883 | || (s.failed >= 2 && s.failed_num[1] == sh->qd_idx) |
| 4884 | || conf->level < 6; |
| 4885 | |
| 4886 | if (s.written && |
| 4887 | (s.p_failed || ((test_bit(R5_Insync, &pdev->flags) |
| 4888 | && !test_bit(R5_LOCKED, &pdev->flags) |
| 4889 | && (test_bit(R5_UPTODATE, &pdev->flags) || |
| 4890 | test_bit(R5_Discard, &pdev->flags))))) && |
| 4891 | (s.q_failed || ((test_bit(R5_Insync, &qdev->flags) |
| 4892 | && !test_bit(R5_LOCKED, &qdev->flags) |
| 4893 | && (test_bit(R5_UPTODATE, &qdev->flags) || |
| 4894 | test_bit(R5_Discard, &qdev->flags)))))) |
NeilBrown | bd83d0a | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 4895 | handle_stripe_clean_event(conf, sh, disks); |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 4896 | |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4897 | if (s.just_cached) |
NeilBrown | bd83d0a | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 4898 | r5c_handle_cached_data_endio(conf, sh, disks); |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 4899 | log_stripe_write_finished(sh); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 4900 | |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 4901 | /* Now we might consider reading some blocks, either to check/generate |
| 4902 | * parity, or to satisfy requests |
| 4903 | * or to load a block that is being partially written. |
| 4904 | */ |
| 4905 | if (s.to_read || s.non_overwrite |
ChangSyun Peng | a1c6ae3 | 2020-07-31 17:50:17 +0800 | [diff] [blame] | 4906 | || (s.to_write && s.failed) |
NeilBrown | ef5b7c6 | 2012-11-22 09:13:36 +1100 | [diff] [blame] | 4907 | || (s.syncing && (s.uptodate + s.compute < disks)) |
| 4908 | || s.replacing |
| 4909 | || s.expanding) |
| 4910 | handle_stripe_fill(sh, &s, disks); |
| 4911 | |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4912 | /* |
| 4913 | * When the stripe finishes full journal write cycle (write to journal |
| 4914 | * and raid disk), this is the clean up procedure so it is ready for |
| 4915 | * next operation. |
| 4916 | */ |
| 4917 | r5c_finish_stripe_write_out(conf, sh, &s); |
| 4918 | |
| 4919 | /* |
| 4920 | * Now to consider new write requests, cache write back and what else, |
| 4921 | * if anything should be read. We do not handle new writes when: |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4922 | * 1/ A 'write' operation (copy+xor) is already in flight. |
| 4923 | * 2/ A 'check' operation is in flight, as it may clobber the parity |
| 4924 | * block. |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4925 | * 3/ A r5c cache log write is in flight. |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4926 | */ |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4927 | |
| 4928 | if (!sh->reconstruct_state && !sh->check_state && !sh->log_io) { |
| 4929 | if (!r5c_is_writeback(conf->log)) { |
| 4930 | if (s.to_write) |
| 4931 | handle_stripe_dirtying(conf, sh, &s, disks); |
| 4932 | } else { /* write back cache */ |
| 4933 | int ret = 0; |
| 4934 | |
| 4935 | /* First, try handle writes in caching phase */ |
| 4936 | if (s.to_write) |
| 4937 | ret = r5c_try_caching_write(conf, sh, &s, |
| 4938 | disks); |
| 4939 | /* |
| 4940 | * If caching phase failed: ret == -EAGAIN |
| 4941 | * OR |
| 4942 | * stripe under reclaim: !caching && injournal |
| 4943 | * |
| 4944 | * fall back to handle_stripe_dirtying() |
| 4945 | */ |
| 4946 | if (ret == -EAGAIN || |
| 4947 | /* stripe under reclaim: !caching && injournal */ |
| 4948 | (!test_bit(STRIPE_R5C_CACHING, &sh->state) && |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 4949 | s.injournal > 0)) { |
| 4950 | ret = handle_stripe_dirtying(conf, sh, &s, |
| 4951 | disks); |
| 4952 | if (ret == -EAGAIN) |
| 4953 | goto finish; |
| 4954 | } |
Song Liu | 2ded370 | 2016-11-17 15:24:38 -0800 | [diff] [blame] | 4955 | } |
| 4956 | } |
NeilBrown | 8478955 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4957 | |
| 4958 | /* maybe we need to check and possibly fix the parity for this stripe |
| 4959 | * Any reads will already have been scheduled, so we just see if enough |
| 4960 | * data is available. The parity check is held off while parity |
| 4961 | * dependent operations are in flight. |
| 4962 | */ |
| 4963 | if (sh->check_state || |
| 4964 | (s.syncing && s.locked == 0 && |
| 4965 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
| 4966 | !test_bit(STRIPE_INSYNC, &sh->state))) { |
| 4967 | if (conf->level == 6) |
| 4968 | handle_parity_checks6(conf, sh, &s, disks); |
| 4969 | else |
| 4970 | handle_parity_checks5(conf, sh, &s, disks); |
| 4971 | } |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4972 | |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4973 | if ((s.replacing || s.syncing) && s.locked == 0 |
| 4974 | && !test_bit(STRIPE_COMPUTE_RUN, &sh->state) |
| 4975 | && !test_bit(STRIPE_REPLACED, &sh->state)) { |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4976 | /* Write out to replacement devices where possible */ |
| 4977 | for (i = 0; i < conf->raid_disks; i++) |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4978 | if (test_bit(R5_NeedReplace, &sh->dev[i].flags)) { |
| 4979 | WARN_ON(!test_bit(R5_UPTODATE, &sh->dev[i].flags)); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4980 | set_bit(R5_WantReplace, &sh->dev[i].flags); |
| 4981 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 4982 | s.locked++; |
| 4983 | } |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4984 | if (s.replacing) |
| 4985 | set_bit(STRIPE_INSYNC, &sh->state); |
| 4986 | set_bit(STRIPE_REPLACED, &sh->state); |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4987 | } |
| 4988 | if ((s.syncing || s.replacing) && s.locked == 0 && |
NeilBrown | f94c0b6 | 2013-07-22 12:57:21 +1000 | [diff] [blame] | 4989 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state) && |
NeilBrown | 9a3e110 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 4990 | test_bit(STRIPE_INSYNC, &sh->state)) { |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 4991 | md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4992 | clear_bit(STRIPE_SYNCING, &sh->state); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 4993 | if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags)) |
| 4994 | wake_up(&conf->wait_for_overlap); |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | /* If the failed drives are just a ReadError, then we might need |
| 4998 | * to progress the repair/check process |
| 4999 | */ |
| 5000 | if (s.failed <= conf->max_degraded && !conf->mddev->ro) |
| 5001 | for (i = 0; i < s.failed; i++) { |
| 5002 | struct r5dev *dev = &sh->dev[s.failed_num[i]]; |
| 5003 | if (test_bit(R5_ReadError, &dev->flags) |
| 5004 | && !test_bit(R5_LOCKED, &dev->flags) |
| 5005 | && test_bit(R5_UPTODATE, &dev->flags) |
| 5006 | ) { |
| 5007 | if (!test_bit(R5_ReWrite, &dev->flags)) { |
| 5008 | set_bit(R5_Wantwrite, &dev->flags); |
| 5009 | set_bit(R5_ReWrite, &dev->flags); |
Guoqing Jiang | 3a31cf3 | 2020-07-28 12:01:43 +0200 | [diff] [blame] | 5010 | } else |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5011 | /* let's read it back */ |
| 5012 | set_bit(R5_Wantread, &dev->flags); |
Guoqing Jiang | 3a31cf3 | 2020-07-28 12:01:43 +0200 | [diff] [blame] | 5013 | set_bit(R5_LOCKED, &dev->flags); |
| 5014 | s.locked++; |
NeilBrown | c5a3100 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5015 | } |
| 5016 | } |
| 5017 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5018 | /* Finish reconstruct operations initiated by the expansion process */ |
| 5019 | if (sh->reconstruct_state == reconstruct_state_result) { |
| 5020 | struct stripe_head *sh_src |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5021 | = raid5_get_active_stripe(conf, sh->sector, 1, 1, 1); |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5022 | if (sh_src && test_bit(STRIPE_EXPAND_SOURCE, &sh_src->state)) { |
| 5023 | /* sh cannot be written until sh_src has been read. |
| 5024 | * so arrange for sh to be delayed a little |
| 5025 | */ |
| 5026 | set_bit(STRIPE_DELAYED, &sh->state); |
| 5027 | set_bit(STRIPE_HANDLE, &sh->state); |
| 5028 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, |
| 5029 | &sh_src->state)) |
| 5030 | atomic_inc(&conf->preread_active_stripes); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5031 | raid5_release_stripe(sh_src); |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5032 | goto finish; |
| 5033 | } |
| 5034 | if (sh_src) |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5035 | raid5_release_stripe(sh_src); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5036 | |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5037 | sh->reconstruct_state = reconstruct_state_idle; |
| 5038 | clear_bit(STRIPE_EXPANDING, &sh->state); |
| 5039 | for (i = conf->raid_disks; i--; ) { |
| 5040 | set_bit(R5_Wantwrite, &sh->dev[i].flags); |
| 5041 | set_bit(R5_LOCKED, &sh->dev[i].flags); |
| 5042 | s.locked++; |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | if (s.expanded && test_bit(STRIPE_EXPANDING, &sh->state) && |
| 5047 | !sh->reconstruct_state) { |
| 5048 | /* Need to write out all blocks after computing parity */ |
| 5049 | sh->disks = conf->raid_disks; |
| 5050 | stripe_set_idx(sh->sector, conf, 0, sh); |
| 5051 | schedule_reconstruction(sh, &s, 1, 1); |
| 5052 | } else if (s.expanded && !sh->reconstruct_state && s.locked == 0) { |
| 5053 | clear_bit(STRIPE_EXPAND_READY, &sh->state); |
| 5054 | atomic_dec(&conf->reshape_stripes); |
| 5055 | wake_up(&conf->wait_for_overlap); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5056 | md_done_sync(conf->mddev, RAID5_STRIPE_SECTORS(conf), 1); |
NeilBrown | 3687c06 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | if (s.expanding && s.locked == 0 && |
| 5060 | !test_bit(STRIPE_COMPUTE_RUN, &sh->state)) |
| 5061 | handle_stripe_expansion(conf, sh); |
| 5062 | |
| 5063 | finish: |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 5064 | /* wait for this device to become unblocked */ |
NeilBrown | 5f066c6 | 2012-07-03 12:13:29 +1000 | [diff] [blame] | 5065 | if (unlikely(s.blocked_rdev)) { |
| 5066 | if (conf->mddev->external) |
| 5067 | md_wait_for_blocked_rdev(s.blocked_rdev, |
| 5068 | conf->mddev); |
| 5069 | else |
| 5070 | /* Internal metadata will immediately |
| 5071 | * be written by raid5d, so we don't |
| 5072 | * need to wait here. |
| 5073 | */ |
| 5074 | rdev_dec_pending(s.blocked_rdev, |
| 5075 | conf->mddev); |
| 5076 | } |
Dan Williams | 6bfe0b4 | 2008-04-30 00:52:32 -0700 | [diff] [blame] | 5077 | |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5078 | if (s.handle_bad_blocks) |
| 5079 | for (i = disks; i--; ) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5080 | struct md_rdev *rdev; |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5081 | struct r5dev *dev = &sh->dev[i]; |
| 5082 | if (test_and_clear_bit(R5_WriteError, &dev->flags)) { |
| 5083 | /* We own a safe reference to the rdev */ |
| 5084 | rdev = conf->disks[i].rdev; |
| 5085 | if (!rdev_set_badblocks(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5086 | RAID5_STRIPE_SECTORS(conf), 0)) |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5087 | md_error(conf->mddev, rdev); |
| 5088 | rdev_dec_pending(rdev, conf->mddev); |
| 5089 | } |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 5090 | if (test_and_clear_bit(R5_MadeGood, &dev->flags)) { |
| 5091 | rdev = conf->disks[i].rdev; |
| 5092 | rdev_clear_badblocks(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5093 | RAID5_STRIPE_SECTORS(conf), 0); |
NeilBrown | b84db56 | 2011-07-28 11:39:23 +1000 | [diff] [blame] | 5094 | rdev_dec_pending(rdev, conf->mddev); |
| 5095 | } |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5096 | if (test_and_clear_bit(R5_MadeGoodRepl, &dev->flags)) { |
| 5097 | rdev = conf->disks[i].replacement; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5098 | if (!rdev) |
| 5099 | /* rdev have been moved down */ |
| 5100 | rdev = conf->disks[i].rdev; |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5101 | rdev_clear_badblocks(rdev, sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5102 | RAID5_STRIPE_SECTORS(conf), 0); |
NeilBrown | 977df36 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 5103 | rdev_dec_pending(rdev, conf->mddev); |
| 5104 | } |
NeilBrown | bc2607f | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5105 | } |
| 5106 | |
Yuri Tikhonov | 6c0069c | 2009-08-29 19:13:13 -0700 | [diff] [blame] | 5107 | if (s.ops_request) |
| 5108 | raid_run_ops(sh, s.ops_request); |
| 5109 | |
Dan Williams | f0e43bc | 2008-06-28 08:31:55 +1000 | [diff] [blame] | 5110 | ops_run_io(sh, &s); |
| 5111 | |
NeilBrown | c5709ef | 2011-07-26 11:35:20 +1000 | [diff] [blame] | 5112 | if (s.dec_preread_active) { |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 5113 | /* 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] | 5114 | * is waiting on a flush, it won't continue until the writes |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 5115 | * have actually been submitted. |
| 5116 | */ |
| 5117 | atomic_dec(&conf->preread_active_stripes); |
| 5118 | if (atomic_read(&conf->preread_active_stripes) < |
| 5119 | IO_THRESHOLD) |
| 5120 | md_wakeup_thread(conf->mddev->thread); |
| 5121 | } |
| 5122 | |
Dan Williams | 257a4b4 | 2011-11-08 16:22:06 +1100 | [diff] [blame] | 5123 | clear_bit_unlock(STRIPE_ACTIVE, &sh->state); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5126 | static void raid5_activate_delayed(struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | { |
| 5128 | if (atomic_read(&conf->preread_active_stripes) < IO_THRESHOLD) { |
| 5129 | while (!list_empty(&conf->delayed_list)) { |
| 5130 | struct list_head *l = conf->delayed_list.next; |
| 5131 | struct stripe_head *sh; |
| 5132 | sh = list_entry(l, struct stripe_head, lru); |
| 5133 | list_del_init(l); |
| 5134 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 5135 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 5136 | atomic_inc(&conf->preread_active_stripes); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5137 | list_add_tail(&sh->lru, &conf->hold_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5138 | raid5_wakeup_stripe_thread(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | } |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 5140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5143 | static void activate_bit_delay(struct r5conf *conf, |
| 5144 | struct list_head *temp_inactive_list) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5145 | { |
| 5146 | /* device_lock is held */ |
| 5147 | struct list_head head; |
| 5148 | list_add(&head, &conf->bitmap_list); |
| 5149 | list_del_init(&conf->bitmap_list); |
| 5150 | while (!list_empty(&head)) { |
| 5151 | struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5152 | int hash; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5153 | list_del_init(&sh->lru); |
| 5154 | atomic_inc(&sh->count); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5155 | hash = sh->hash_lock_index; |
| 5156 | __release_stripe(conf, sh, &temp_inactive_list[hash]); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 5157 | } |
| 5158 | } |
| 5159 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5160 | 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] | 5161 | { |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5162 | struct r5conf *conf = mddev->private; |
Christoph Hellwig | 10433d0 | 2017-08-23 19:10:28 +0200 | [diff] [blame] | 5163 | sector_t sector = bio->bi_iter.bi_sector; |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5164 | unsigned int chunk_sectors; |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 5165 | unsigned int bio_sectors = bio_sectors(bio); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5166 | |
Christoph Hellwig | 10433d0 | 2017-08-23 19:10:28 +0200 | [diff] [blame] | 5167 | WARN_ON_ONCE(bio->bi_partno); |
| 5168 | |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5169 | chunk_sectors = min(conf->chunk_sectors, conf->prev_chunk_sectors); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5170 | return chunk_sectors >= |
| 5171 | ((sector & (chunk_sectors - 1)) + bio_sectors); |
| 5172 | } |
| 5173 | |
| 5174 | /* |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5175 | * add bio to the retry LIFO ( in O(1) ... we are in interrupt ) |
| 5176 | * later sampled by raid5d. |
| 5177 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5178 | 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] | 5179 | { |
| 5180 | unsigned long flags; |
| 5181 | |
| 5182 | spin_lock_irqsave(&conf->device_lock, flags); |
| 5183 | |
| 5184 | bi->bi_next = conf->retry_read_aligned_list; |
| 5185 | conf->retry_read_aligned_list = bi; |
| 5186 | |
| 5187 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 5188 | md_wakeup_thread(conf->mddev->thread); |
| 5189 | } |
| 5190 | |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 5191 | static struct bio *remove_bio_from_retry(struct r5conf *conf, |
| 5192 | unsigned int *offset) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5193 | { |
| 5194 | struct bio *bi; |
| 5195 | |
| 5196 | bi = conf->retry_read_aligned; |
| 5197 | if (bi) { |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 5198 | *offset = conf->retry_read_offset; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5199 | conf->retry_read_aligned = NULL; |
| 5200 | return bi; |
| 5201 | } |
| 5202 | bi = conf->retry_read_aligned_list; |
| 5203 | if(bi) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 5204 | conf->retry_read_aligned_list = bi->bi_next; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5205 | bi->bi_next = NULL; |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 5206 | *offset = 0; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | return bi; |
| 5210 | } |
| 5211 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5212 | /* |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5213 | * The "raid5_align_endio" should check if the read succeeded and if it |
| 5214 | * did, call bio_endio on the original bio (having bio_put the new bio |
| 5215 | * first). |
| 5216 | * If the read failed.. |
| 5217 | */ |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5218 | static void raid5_align_endio(struct bio *bi) |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5219 | { |
| 5220 | struct bio* raid_bi = bi->bi_private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5221 | struct mddev *mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5222 | struct r5conf *conf; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5223 | struct md_rdev *rdev; |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 5224 | blk_status_t error = bi->bi_status; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5225 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5226 | bio_put(bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5227 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5228 | rdev = (void*)raid_bi->bi_next; |
| 5229 | raid_bi->bi_next = NULL; |
NeilBrown | 2b7f222 | 2010-03-25 16:06:03 +1100 | [diff] [blame] | 5230 | mddev = rdev->mddev; |
| 5231 | conf = mddev->private; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5232 | |
| 5233 | rdev_dec_pending(rdev, conf->mddev); |
| 5234 | |
Sasha Levin | 9b81c84 | 2015-08-10 19:05:18 -0400 | [diff] [blame] | 5235 | if (!error) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 5236 | bio_endio(raid_bi); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5237 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 5238 | wake_up(&conf->wait_for_quiescent); |
NeilBrown | 6712ecf | 2007-09-27 12:47:43 +0200 | [diff] [blame] | 5239 | return; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5240 | } |
| 5241 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 5242 | 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] | 5243 | |
| 5244 | add_bio_to_retry(raid_bi, conf); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5245 | } |
| 5246 | |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5247 | 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] | 5248 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5249 | struct r5conf *conf = mddev->private; |
NeilBrown | 8553fe7ec | 2009-12-14 12:49:47 +1100 | [diff] [blame] | 5250 | int dd_idx; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5251 | struct bio* align_bi; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 5252 | struct md_rdev *rdev; |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5253 | sector_t end_sector; |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5254 | |
| 5255 | if (!in_chunk_boundary(mddev, raid_bio)) { |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5256 | pr_debug("%s: non aligned\n", __func__); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5257 | return 0; |
| 5258 | } |
| 5259 | /* |
Ming Lei | d7a1030 | 2017-02-14 23:29:03 +0800 | [diff] [blame] | 5260 | * 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] | 5261 | */ |
Kent Overstreet | afeee51 | 2018-05-20 18:25:52 -0400 | [diff] [blame] | 5262 | 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] | 5263 | if (!align_bi) |
| 5264 | return 0; |
| 5265 | /* |
| 5266 | * set bi_end_io to a new function, and set bi_private to the |
| 5267 | * original bio. |
| 5268 | */ |
| 5269 | align_bi->bi_end_io = raid5_align_endio; |
| 5270 | align_bi->bi_private = raid_bio; |
| 5271 | /* |
| 5272 | * compute position |
| 5273 | */ |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5274 | align_bi->bi_iter.bi_sector = |
| 5275 | raid5_compute_sector(conf, raid_bio->bi_iter.bi_sector, |
| 5276 | 0, &dd_idx, NULL); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5277 | |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 5278 | end_sector = bio_end_sector(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5279 | rcu_read_lock(); |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5280 | rdev = rcu_dereference(conf->disks[dd_idx].replacement); |
| 5281 | if (!rdev || test_bit(Faulty, &rdev->flags) || |
| 5282 | rdev->recovery_offset < end_sector) { |
| 5283 | rdev = rcu_dereference(conf->disks[dd_idx].rdev); |
| 5284 | if (rdev && |
| 5285 | (test_bit(Faulty, &rdev->flags) || |
| 5286 | !(test_bit(In_sync, &rdev->flags) || |
| 5287 | rdev->recovery_offset >= end_sector))) |
| 5288 | rdev = NULL; |
| 5289 | } |
Song Liu | 03b047f | 2017-01-11 13:39:14 -0800 | [diff] [blame] | 5290 | |
| 5291 | if (r5c_big_stripe_cached(conf, align_bi->bi_iter.bi_sector)) { |
| 5292 | rcu_read_unlock(); |
| 5293 | bio_put(align_bi); |
| 5294 | return 0; |
| 5295 | } |
| 5296 | |
NeilBrown | 671488c | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 5297 | if (rdev) { |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5298 | sector_t first_bad; |
| 5299 | int bad_sectors; |
| 5300 | |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5301 | atomic_inc(&rdev->nr_pending); |
| 5302 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5303 | raid_bio->bi_next = (void*)rdev; |
Christoph Hellwig | 74d4699 | 2017-08-23 19:10:32 +0200 | [diff] [blame] | 5304 | bio_set_dev(align_bi, rdev->bdev); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5305 | |
Kent Overstreet | 7140aaf | 2013-09-25 13:37:01 -0700 | [diff] [blame] | 5306 | if (is_badblock(rdev, align_bi->bi_iter.bi_sector, |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5307 | bio_sectors(align_bi), |
NeilBrown | 31c176e | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 5308 | &first_bad, &bad_sectors)) { |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 5309 | bio_put(align_bi); |
| 5310 | rdev_dec_pending(rdev, mddev); |
| 5311 | return 0; |
| 5312 | } |
| 5313 | |
majianpeng | 6c0544e | 2012-06-12 08:31:10 +0800 | [diff] [blame] | 5314 | /* No reshape active, so we can trust rdev->data_offset */ |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5315 | align_bi->bi_iter.bi_sector += rdev->data_offset; |
majianpeng | 6c0544e | 2012-06-12 08:31:10 +0800 | [diff] [blame] | 5316 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5317 | spin_lock_irq(&conf->device_lock); |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 5318 | wait_event_lock_irq(conf->wait_for_quiescent, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5319 | conf->quiesce == 0, |
Lukas Czerner | eed8c02 | 2012-11-30 11:42:40 +0100 | [diff] [blame] | 5320 | conf->device_lock); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5321 | atomic_inc(&conf->active_aligned_reads); |
| 5322 | spin_unlock_irq(&conf->device_lock); |
| 5323 | |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 5324 | if (mddev->gendisk) |
Christoph Hellwig | 74d4699 | 2017-08-23 19:10:32 +0200 | [diff] [blame] | 5325 | trace_block_bio_remap(align_bi->bi_disk->queue, |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 5326 | align_bi, disk_devt(mddev->gendisk), |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 5327 | raid_bio->bi_iter.bi_sector); |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 5328 | submit_bio_noacct(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5329 | return 1; |
| 5330 | } else { |
| 5331 | rcu_read_unlock(); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 5332 | bio_put(align_bi); |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5333 | return 0; |
| 5334 | } |
| 5335 | } |
| 5336 | |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5337 | static struct bio *chunk_aligned_read(struct mddev *mddev, struct bio *raid_bio) |
| 5338 | { |
| 5339 | struct bio *split; |
NeilBrown | dd7a8f5 | 2017-04-05 14:05:51 +1000 | [diff] [blame] | 5340 | sector_t sector = raid_bio->bi_iter.bi_sector; |
| 5341 | unsigned chunk_sects = mddev->chunk_sectors; |
| 5342 | unsigned sectors = chunk_sects - (sector & (chunk_sects-1)); |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5343 | |
NeilBrown | dd7a8f5 | 2017-04-05 14:05:51 +1000 | [diff] [blame] | 5344 | if (sectors < bio_sectors(raid_bio)) { |
| 5345 | struct r5conf *conf = mddev->private; |
Kent Overstreet | afeee51 | 2018-05-20 18:25:52 -0400 | [diff] [blame] | 5346 | split = bio_split(raid_bio, sectors, GFP_NOIO, &conf->bio_split); |
NeilBrown | dd7a8f5 | 2017-04-05 14:05:51 +1000 | [diff] [blame] | 5347 | bio_chain(split, raid_bio); |
Christoph Hellwig | ed00aab | 2020-07-01 10:59:44 +0200 | [diff] [blame] | 5348 | submit_bio_noacct(raid_bio); |
NeilBrown | dd7a8f5 | 2017-04-05 14:05:51 +1000 | [diff] [blame] | 5349 | raid_bio = split; |
| 5350 | } |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5351 | |
NeilBrown | dd7a8f5 | 2017-04-05 14:05:51 +1000 | [diff] [blame] | 5352 | if (!raid5_read_one_chunk(mddev, raid_bio)) |
| 5353 | return raid_bio; |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5354 | |
| 5355 | return NULL; |
| 5356 | } |
| 5357 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5358 | /* __get_priority_stripe - get the next stripe to process |
| 5359 | * |
| 5360 | * Full stripe writes are allowed to pass preread active stripes up until |
| 5361 | * the bypass_threshold is exceeded. In general the bypass_count |
| 5362 | * increments when the handle_list is handled before the hold_list; however, it |
| 5363 | * will not be incremented when STRIPE_IO_STARTED is sampled set signifying a |
| 5364 | * stripe with in flight i/o. The bypass_count will be reset when the |
| 5365 | * head of the hold_list has changed, i.e. the head was promoted to the |
| 5366 | * handle_list. |
| 5367 | */ |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5368 | static struct stripe_head *__get_priority_stripe(struct r5conf *conf, int group) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5369 | { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5370 | struct stripe_head *sh, *tmp; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5371 | struct list_head *handle_list = NULL; |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5372 | struct r5worker_group *wg; |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 5373 | bool second_try = !r5c_is_writeback(conf->log) && |
| 5374 | !r5l_log_disk_error(conf); |
| 5375 | bool try_loprio = test_bit(R5C_LOG_TIGHT, &conf->cache_state) || |
| 5376 | r5l_log_disk_error(conf); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5377 | |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5378 | again: |
| 5379 | wg = NULL; |
| 5380 | sh = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5381 | if (conf->worker_cnt_per_group == 0) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5382 | handle_list = try_loprio ? &conf->loprio_list : |
| 5383 | &conf->handle_list; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5384 | } else if (group != ANY_GROUP) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5385 | handle_list = try_loprio ? &conf->worker_groups[group].loprio_list : |
| 5386 | &conf->worker_groups[group].handle_list; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5387 | wg = &conf->worker_groups[group]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5388 | } else { |
| 5389 | int i; |
| 5390 | for (i = 0; i < conf->group_cnt; i++) { |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5391 | handle_list = try_loprio ? &conf->worker_groups[i].loprio_list : |
| 5392 | &conf->worker_groups[i].handle_list; |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5393 | wg = &conf->worker_groups[i]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5394 | if (!list_empty(handle_list)) |
| 5395 | break; |
| 5396 | } |
| 5397 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5398 | |
| 5399 | pr_debug("%s: handle: %s hold: %s full_writes: %d bypass_count: %d\n", |
| 5400 | __func__, |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5401 | list_empty(handle_list) ? "empty" : "busy", |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5402 | list_empty(&conf->hold_list) ? "empty" : "busy", |
| 5403 | atomic_read(&conf->pending_full_writes), conf->bypass_count); |
| 5404 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5405 | if (!list_empty(handle_list)) { |
| 5406 | sh = list_entry(handle_list->next, typeof(*sh), lru); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5407 | |
| 5408 | if (list_empty(&conf->hold_list)) |
| 5409 | conf->bypass_count = 0; |
| 5410 | else if (!test_bit(STRIPE_IO_STARTED, &sh->state)) { |
| 5411 | if (conf->hold_list.next == conf->last_hold) |
| 5412 | conf->bypass_count++; |
| 5413 | else { |
| 5414 | conf->last_hold = conf->hold_list.next; |
| 5415 | conf->bypass_count -= conf->bypass_threshold; |
| 5416 | if (conf->bypass_count < 0) |
| 5417 | conf->bypass_count = 0; |
| 5418 | } |
| 5419 | } |
| 5420 | } else if (!list_empty(&conf->hold_list) && |
| 5421 | ((conf->bypass_threshold && |
| 5422 | conf->bypass_count > conf->bypass_threshold) || |
| 5423 | atomic_read(&conf->pending_full_writes) == 0)) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5424 | |
| 5425 | list_for_each_entry(tmp, &conf->hold_list, lru) { |
| 5426 | if (conf->worker_cnt_per_group == 0 || |
| 5427 | group == ANY_GROUP || |
| 5428 | !cpu_online(tmp->cpu) || |
| 5429 | cpu_to_group(tmp->cpu) == group) { |
| 5430 | sh = tmp; |
| 5431 | break; |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | if (sh) { |
| 5436 | conf->bypass_count -= conf->bypass_threshold; |
| 5437 | if (conf->bypass_count < 0) |
| 5438 | conf->bypass_count = 0; |
| 5439 | } |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5440 | wg = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 5441 | } |
| 5442 | |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 5443 | if (!sh) { |
| 5444 | if (second_try) |
| 5445 | return NULL; |
| 5446 | second_try = true; |
| 5447 | try_loprio = !try_loprio; |
| 5448 | goto again; |
| 5449 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5450 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 5451 | if (wg) { |
| 5452 | wg->stripes_cnt--; |
| 5453 | sh->group = NULL; |
| 5454 | } |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5455 | list_del_init(&sh->lru); |
Shaohua Li | c7a6d35 | 2014-04-15 09:12:54 +0800 | [diff] [blame] | 5456 | BUG_ON(atomic_inc_return(&sh->count) != 1); |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 5457 | return sh; |
| 5458 | } |
Raz Ben-Jehuda(caro) | f679623 | 2006-12-10 02:20:46 -0800 | [diff] [blame] | 5459 | |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5460 | struct raid5_plug_cb { |
| 5461 | struct blk_plug_cb cb; |
| 5462 | struct list_head list; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5463 | struct list_head temp_inactive_list[NR_STRIPE_HASH_LOCKS]; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5464 | }; |
| 5465 | |
| 5466 | static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule) |
| 5467 | { |
| 5468 | struct raid5_plug_cb *cb = container_of( |
| 5469 | blk_cb, struct raid5_plug_cb, cb); |
| 5470 | struct stripe_head *sh; |
| 5471 | struct mddev *mddev = cb->cb.data; |
| 5472 | struct r5conf *conf = mddev->private; |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 5473 | int cnt = 0; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5474 | int hash; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5475 | |
| 5476 | if (cb->list.next && !list_empty(&cb->list)) { |
| 5477 | spin_lock_irq(&conf->device_lock); |
| 5478 | while (!list_empty(&cb->list)) { |
| 5479 | sh = list_first_entry(&cb->list, struct stripe_head, lru); |
| 5480 | list_del_init(&sh->lru); |
| 5481 | /* |
| 5482 | * avoid race release_stripe_plug() sees |
| 5483 | * STRIPE_ON_UNPLUG_LIST clear but the stripe |
| 5484 | * is still in our list |
| 5485 | */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5486 | smp_mb__before_atomic(); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5487 | clear_bit(STRIPE_ON_UNPLUG_LIST, &sh->state); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 5488 | /* |
| 5489 | * STRIPE_ON_RELEASE_LIST could be set here. In that |
| 5490 | * case, the count is always > 1 here |
| 5491 | */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5492 | hash = sh->hash_lock_index; |
| 5493 | __release_stripe(conf, sh, &cb->temp_inactive_list[hash]); |
NeilBrown | a9add5d | 2012-10-31 11:59:09 +1100 | [diff] [blame] | 5494 | cnt++; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5495 | } |
| 5496 | spin_unlock_irq(&conf->device_lock); |
| 5497 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5498 | release_inactive_stripe_list(conf, cb->temp_inactive_list, |
| 5499 | NR_STRIPE_HASH_LOCKS); |
Jonathan Brassow | e3620a3 | 2013-03-07 16:22:01 -0600 | [diff] [blame] | 5500 | if (mddev->queue) |
| 5501 | trace_block_unplug(mddev->queue, cnt, !from_schedule); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5502 | kfree(cb); |
| 5503 | } |
| 5504 | |
| 5505 | static void release_stripe_plug(struct mddev *mddev, |
| 5506 | struct stripe_head *sh) |
| 5507 | { |
| 5508 | struct blk_plug_cb *blk_cb = blk_check_plugged( |
| 5509 | raid5_unplug, mddev, |
| 5510 | sizeof(struct raid5_plug_cb)); |
| 5511 | struct raid5_plug_cb *cb; |
| 5512 | |
| 5513 | if (!blk_cb) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5514 | raid5_release_stripe(sh); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5515 | return; |
| 5516 | } |
| 5517 | |
| 5518 | cb = container_of(blk_cb, struct raid5_plug_cb, cb); |
| 5519 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5520 | if (cb->list.next == NULL) { |
| 5521 | int i; |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5522 | INIT_LIST_HEAD(&cb->list); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 5523 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 5524 | INIT_LIST_HEAD(cb->temp_inactive_list + i); |
| 5525 | } |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5526 | |
| 5527 | if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)) |
| 5528 | list_add_tail(&sh->lru, &cb->list); |
| 5529 | else |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5530 | raid5_release_stripe(sh); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5531 | } |
| 5532 | |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5533 | static void make_discard_request(struct mddev *mddev, struct bio *bi) |
| 5534 | { |
| 5535 | struct r5conf *conf = mddev->private; |
| 5536 | sector_t logical_sector, last_sector; |
| 5537 | struct stripe_head *sh; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5538 | int stripe_sectors; |
| 5539 | |
| 5540 | if (mddev->reshape_position != MaxSector) |
| 5541 | /* Skip discard while reshape is happening */ |
| 5542 | return; |
| 5543 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5544 | logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); |
Guoqing Jiang | b0f01ec | 2019-09-03 11:41:03 +0200 | [diff] [blame] | 5545 | last_sector = bio_end_sector(bi); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5546 | |
| 5547 | bi->bi_next = NULL; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5548 | |
| 5549 | stripe_sectors = conf->chunk_sectors * |
| 5550 | (conf->raid_disks - conf->max_degraded); |
| 5551 | logical_sector = DIV_ROUND_UP_SECTOR_T(logical_sector, |
| 5552 | stripe_sectors); |
| 5553 | sector_div(last_sector, stripe_sectors); |
| 5554 | |
| 5555 | logical_sector *= conf->chunk_sectors; |
| 5556 | last_sector *= conf->chunk_sectors; |
| 5557 | |
| 5558 | for (; logical_sector < last_sector; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5559 | logical_sector += RAID5_STRIPE_SECTORS(conf)) { |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5560 | DEFINE_WAIT(w); |
| 5561 | int d; |
| 5562 | again: |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5563 | sh = raid5_get_active_stripe(conf, logical_sector, 0, 0, 0); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5564 | prepare_to_wait(&conf->wait_for_overlap, &w, |
| 5565 | TASK_UNINTERRUPTIBLE); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 5566 | set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
| 5567 | if (test_bit(STRIPE_SYNCING, &sh->state)) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5568 | raid5_release_stripe(sh); |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 5569 | schedule(); |
| 5570 | goto again; |
| 5571 | } |
| 5572 | clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5573 | spin_lock_irq(&sh->stripe_lock); |
| 5574 | for (d = 0; d < conf->raid_disks; d++) { |
| 5575 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 5576 | continue; |
| 5577 | if (sh->dev[d].towrite || sh->dev[d].toread) { |
| 5578 | set_bit(R5_Overlap, &sh->dev[d].flags); |
| 5579 | spin_unlock_irq(&sh->stripe_lock); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5580 | raid5_release_stripe(sh); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5581 | schedule(); |
| 5582 | goto again; |
| 5583 | } |
| 5584 | } |
NeilBrown | f8dfcff | 2013-03-12 12:18:06 +1100 | [diff] [blame] | 5585 | set_bit(STRIPE_DISCARD, &sh->state); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5586 | finish_wait(&conf->wait_for_overlap, &w); |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5587 | sh->overwrite_disks = 0; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5588 | for (d = 0; d < conf->raid_disks; d++) { |
| 5589 | if (d == sh->pd_idx || d == sh->qd_idx) |
| 5590 | continue; |
| 5591 | sh->dev[d].towrite = bi; |
| 5592 | set_bit(R5_OVERWRITE, &sh->dev[d].flags); |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 5593 | bio_inc_remaining(bi); |
NeilBrown | 4972805 | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 5594 | md_write_inc(mddev, bi); |
shli@kernel.org | 7a87f43 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5595 | sh->overwrite_disks++; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5596 | } |
| 5597 | spin_unlock_irq(&sh->stripe_lock); |
| 5598 | if (conf->mddev->bitmap) { |
| 5599 | for (d = 0; |
| 5600 | d < conf->raid_disks - conf->max_degraded; |
| 5601 | d++) |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 5602 | md_bitmap_startwrite(mddev->bitmap, |
| 5603 | sh->sector, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5604 | RAID5_STRIPE_SECTORS(conf), |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 5605 | 0); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5606 | sh->bm_seq = conf->seq_flush + 1; |
| 5607 | set_bit(STRIPE_BIT_DELAY, &sh->state); |
| 5608 | } |
| 5609 | |
| 5610 | set_bit(STRIPE_HANDLE, &sh->state); |
| 5611 | clear_bit(STRIPE_DELAYED, &sh->state); |
| 5612 | if (!test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 5613 | atomic_inc(&conf->preread_active_stripes); |
| 5614 | release_stripe_plug(mddev, sh); |
| 5615 | } |
| 5616 | |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 5617 | bio_endio(bi); |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5618 | } |
| 5619 | |
NeilBrown | cc27b0c | 2017-06-05 16:49:39 +1000 | [diff] [blame] | 5620 | static bool raid5_make_request(struct mddev *mddev, struct bio * bi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5621 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5622 | struct r5conf *conf = mddev->private; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5623 | int dd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | sector_t new_sector; |
| 5625 | sector_t logical_sector, last_sector; |
| 5626 | struct stripe_head *sh; |
Jens Axboe | a362357 | 2005-11-01 09:26:16 +0100 | [diff] [blame] | 5627 | const int rw = bio_data_dir(bi); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5628 | DEFINE_WAIT(w); |
| 5629 | bool do_prepare; |
Song Liu | 3bddb7f | 2016-11-18 16:46:50 -0800 | [diff] [blame] | 5630 | bool do_flush = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 5632 | if (unlikely(bi->bi_opf & REQ_PREFLUSH)) { |
Tomasz Majchrzak | 1532d9e | 2017-12-27 10:31:40 +0100 | [diff] [blame] | 5633 | int ret = log_handle_flush_request(conf, bi); |
Shaohua Li | 828cbe9 | 2015-09-02 13:49:49 -0700 | [diff] [blame] | 5634 | |
| 5635 | if (ret == 0) |
NeilBrown | cc27b0c | 2017-06-05 16:49:39 +1000 | [diff] [blame] | 5636 | return true; |
Shaohua Li | 828cbe9 | 2015-09-02 13:49:49 -0700 | [diff] [blame] | 5637 | if (ret == -ENODEV) { |
David Jeffery | 775d783 | 2019-09-16 13:15:14 -0400 | [diff] [blame] | 5638 | if (md_flush_request(mddev, bi)) |
| 5639 | return true; |
Shaohua Li | 828cbe9 | 2015-09-02 13:49:49 -0700 | [diff] [blame] | 5640 | } |
| 5641 | /* ret == -EAGAIN, fallback */ |
Song Liu | 3bddb7f | 2016-11-18 16:46:50 -0800 | [diff] [blame] | 5642 | /* |
| 5643 | * if r5l_handle_flush_request() didn't clear REQ_PREFLUSH, |
| 5644 | * we need to flush journal device |
| 5645 | */ |
| 5646 | do_flush = bi->bi_opf & REQ_PREFLUSH; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
NeilBrown | cc27b0c | 2017-06-05 16:49:39 +1000 | [diff] [blame] | 5649 | if (!md_write_start(mddev, bi)) |
| 5650 | return false; |
Eric Mei | 9ffc8f7 | 2015-03-18 23:39:11 -0600 | [diff] [blame] | 5651 | /* |
| 5652 | * If array is degraded, better not do chunk aligned read because |
| 5653 | * later we might have to read it again in order to reconstruct |
| 5654 | * data on failed drives. |
| 5655 | */ |
| 5656 | if (rw == READ && mddev->degraded == 0 && |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5657 | mddev->reshape_position == MaxSector) { |
| 5658 | bi = chunk_aligned_read(mddev, bi); |
| 5659 | if (!bi) |
NeilBrown | cc27b0c | 2017-06-05 16:49:39 +1000 | [diff] [blame] | 5660 | return true; |
Ming Lin | 7ef6b12 | 2015-05-06 22:51:24 -0700 | [diff] [blame] | 5661 | } |
Raz Ben-Jehuda(caro) | 5248861 | 2006-12-10 02:20:48 -0800 | [diff] [blame] | 5662 | |
Mike Christie | 796a5cf | 2016-06-05 14:32:07 -0500 | [diff] [blame] | 5663 | if (unlikely(bio_op(bi) == REQ_OP_DISCARD)) { |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5664 | make_discard_request(mddev, bi); |
NeilBrown | cc27b0c | 2017-06-05 16:49:39 +1000 | [diff] [blame] | 5665 | md_write_end(mddev); |
| 5666 | return true; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 5667 | } |
| 5668 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5669 | logical_sector = bi->bi_iter.bi_sector & ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 5670 | last_sector = bio_end_sector(bi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | bi->bi_next = NULL; |
NeilBrown | 06d91a5 | 2005-06-21 17:17:12 -0700 | [diff] [blame] | 5672 | |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5673 | prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5674 | for (; logical_sector < last_sector; logical_sector += RAID5_STRIPE_SECTORS(conf)) { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5675 | int previous; |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5676 | int seq; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 5677 | |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5678 | do_prepare = false; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5679 | retry: |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5680 | seq = read_seqcount_begin(&conf->gen_lock); |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5681 | previous = 0; |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5682 | if (do_prepare) |
| 5683 | prepare_to_wait(&conf->wait_for_overlap, &w, |
| 5684 | TASK_UNINTERRUPTIBLE); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5685 | if (unlikely(conf->reshape_progress != MaxSector)) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5686 | /* spinlock is needed as reshape_progress may be |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 5687 | * 64bit on a 32bit platform, and so it might be |
| 5688 | * possible to see a half-updated value |
Jesper Juhl | aeb878b | 2011-04-10 18:06:17 +0200 | [diff] [blame] | 5689 | * Of course reshape_progress could change after |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 5690 | * the lock is dropped, so once we get a reference |
| 5691 | * to the stripe that we think it is, we will have |
| 5692 | * to check again. |
| 5693 | */ |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5694 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5695 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5696 | ? logical_sector < conf->reshape_progress |
| 5697 | : logical_sector >= conf->reshape_progress) { |
NeilBrown | b5663ba | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5698 | previous = 1; |
| 5699 | } else { |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5700 | if (mddev->reshape_backwards |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5701 | ? logical_sector < conf->reshape_safe |
| 5702 | : logical_sector >= conf->reshape_safe) { |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 5703 | spin_unlock_irq(&conf->device_lock); |
| 5704 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5705 | do_prepare = true; |
NeilBrown | b578d55 | 2006-03-27 01:18:12 -0800 | [diff] [blame] | 5706 | goto retry; |
| 5707 | } |
| 5708 | } |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5709 | spin_unlock_irq(&conf->device_lock); |
| 5710 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 5711 | |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5712 | new_sector = raid5_compute_sector(conf, logical_sector, |
| 5713 | previous, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5714 | &dd_idx, NULL); |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 5715 | pr_debug("raid456: raid5_make_request, sector %llu logical %llu\n", |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5716 | (unsigned long long)new_sector, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | (unsigned long long)logical_sector); |
| 5718 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5719 | sh = raid5_get_active_stripe(conf, new_sector, previous, |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 5720 | (bi->bi_opf & REQ_RAHEAD), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | if (sh) { |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5722 | if (unlikely(previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5723 | /* expansion might have moved on while waiting for a |
NeilBrown | df8e7f76 | 2006-03-27 01:18:15 -0800 | [diff] [blame] | 5724 | * stripe, so we must do the range check again. |
| 5725 | * Expansion could still move past after this |
| 5726 | * test, but as we are holding a reference to |
| 5727 | * 'sh', we know that if that happens, |
| 5728 | * STRIPE_EXPANDING will get set and the expansion |
| 5729 | * won't proceed until we finish with the stripe. |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5730 | */ |
| 5731 | int must_retry = 0; |
| 5732 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5733 | if (mddev->reshape_backwards |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 5734 | ? logical_sector >= conf->reshape_progress |
| 5735 | : logical_sector < conf->reshape_progress) |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5736 | /* mismatch, need to try again */ |
| 5737 | must_retry = 1; |
| 5738 | spin_unlock_irq(&conf->device_lock); |
| 5739 | if (must_retry) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5740 | raid5_release_stripe(sh); |
Dan Williams | 7a3ab90 | 2009-06-16 16:00:33 -0700 | [diff] [blame] | 5741 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5742 | do_prepare = true; |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5743 | goto retry; |
| 5744 | } |
| 5745 | } |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5746 | if (read_seqcount_retry(&conf->gen_lock, seq)) { |
| 5747 | /* Might have got the wrong stripe_head |
| 5748 | * by accident |
| 5749 | */ |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5750 | raid5_release_stripe(sh); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 5751 | goto retry; |
| 5752 | } |
NeilBrown | e62e58a | 2009-07-01 13:15:35 +1000 | [diff] [blame] | 5753 | |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5754 | if (test_bit(STRIPE_EXPANDING, &sh->state) || |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5755 | !add_stripe_bio(sh, bi, dd_idx, rw, previous)) { |
NeilBrown | 7ecaa1e | 2006-03-27 01:18:08 -0800 | [diff] [blame] | 5756 | /* Stripe is busy expanding or |
| 5757 | * add failed due to overlap. Flush everything |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | * and wait a while |
| 5759 | */ |
NeilBrown | 482c083 | 2011-04-18 18:25:42 +1000 | [diff] [blame] | 5760 | md_wakeup_thread(mddev->thread); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5761 | raid5_release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | schedule(); |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5763 | do_prepare = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | goto retry; |
| 5765 | } |
Song Liu | 3bddb7f | 2016-11-18 16:46:50 -0800 | [diff] [blame] | 5766 | if (do_flush) { |
| 5767 | set_bit(STRIPE_R5C_PREFLUSH, &sh->state); |
| 5768 | /* we only need flush for one stripe */ |
| 5769 | do_flush = false; |
| 5770 | } |
| 5771 | |
Guoqing Jiang | 1684e97 | 2020-06-16 11:25:52 +0200 | [diff] [blame] | 5772 | set_bit(STRIPE_HANDLE, &sh->state); |
NeilBrown | 6ed3003 | 2008-02-06 01:40:00 -0800 | [diff] [blame] | 5773 | clear_bit(STRIPE_DELAYED, &sh->state); |
shli@kernel.org | 59fc630 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 5774 | if ((!sh->batch_head || sh == sh->batch_head) && |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 5775 | (bi->bi_opf & REQ_SYNC) && |
NeilBrown | 729a186 | 2009-12-14 12:49:50 +1100 | [diff] [blame] | 5776 | !test_and_set_bit(STRIPE_PREREAD_ACTIVE, &sh->state)) |
| 5777 | atomic_inc(&conf->preread_active_stripes); |
Shaohua Li | 8811b59 | 2012-08-02 08:33:00 +1000 | [diff] [blame] | 5778 | release_stripe_plug(mddev, sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5779 | } else { |
| 5780 | /* cannot get stripe for read-ahead, just give-up */ |
Christoph Hellwig | 4e4cbee | 2017-06-03 09:38:06 +0200 | [diff] [blame] | 5781 | bi->bi_status = BLK_STS_IOERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | break; |
| 5783 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | } |
Shaohua Li | 27c0f68 | 2014-04-09 11:25:47 +0800 | [diff] [blame] | 5785 | finish_wait(&conf->wait_for_overlap, &w); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 5786 | |
NeilBrown | 4972805 | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 5787 | if (rw == WRITE) |
| 5788 | md_write_end(mddev); |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 5789 | bio_endio(bi); |
NeilBrown | cc27b0c | 2017-06-05 16:49:39 +1000 | [diff] [blame] | 5790 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5791 | } |
| 5792 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5793 | 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] | 5794 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 5795 | 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] | 5796 | { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5797 | /* reshaping is quite different to recovery/resync so it is |
| 5798 | * handled quite separately ... here. |
| 5799 | * |
| 5800 | * On each call to sync_request, we gather one chunk worth of |
| 5801 | * destination stripes and flag them as expanding. |
| 5802 | * Then we find all the source stripes and request reads. |
| 5803 | * As the reads complete, handle_stripe will copy the data |
| 5804 | * into the destination stripe and release that stripe. |
| 5805 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 5806 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5807 | struct stripe_head *sh; |
NeilBrown | db0505d | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 5808 | struct md_rdev *rdev; |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 5809 | sector_t first_sector, last_sector; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5810 | int raid_disks = conf->previous_raid_disks; |
| 5811 | int data_disks = raid_disks - conf->max_degraded; |
| 5812 | int new_data_disks = conf->raid_disks - conf->max_degraded; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5813 | int i; |
| 5814 | int dd_idx; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5815 | sector_t writepos, readpos, safepos; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5816 | sector_t stripe_addr; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5817 | int reshape_sectors; |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5818 | struct list_head stripes; |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 5819 | sector_t retn; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5820 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5821 | if (sector_nr == 0) { |
| 5822 | /* If restarting in the middle, skip the initial sectors */ |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5823 | if (mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5824 | conf->reshape_progress < raid5_size(mddev, 0, 0)) { |
| 5825 | sector_nr = raid5_size(mddev, 0, 0) |
| 5826 | - conf->reshape_progress; |
NeilBrown | 6cbd814 | 2015-07-24 13:30:32 +1000 | [diff] [blame] | 5827 | } else if (mddev->reshape_backwards && |
| 5828 | conf->reshape_progress == MaxSector) { |
| 5829 | /* shouldn't happen, but just in case, finish up.*/ |
| 5830 | sector_nr = MaxSector; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5831 | } else if (!mddev->reshape_backwards && |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5832 | conf->reshape_progress > 0) |
| 5833 | sector_nr = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5834 | sector_div(sector_nr, new_data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5835 | if (sector_nr) { |
NeilBrown | 8dee721 | 2009-11-06 14:59:29 +1100 | [diff] [blame] | 5836 | mddev->curr_resync_completed = sector_nr; |
Junxiao Bi | e1a86db | 2020-07-14 16:10:26 -0700 | [diff] [blame] | 5837 | sysfs_notify_dirent_safe(mddev->sysfs_completed); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5838 | *skipped = 1; |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 5839 | retn = sector_nr; |
| 5840 | goto finish; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5841 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5844 | /* We need to process a full chunk at a time. |
| 5845 | * If old and new chunk sizes differ, we need to process the |
| 5846 | * largest of these |
| 5847 | */ |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 5848 | |
| 5849 | reshape_sectors = max(conf->chunk_sectors, conf->prev_chunk_sectors); |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5850 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5851 | /* We update the metadata at least every 10 seconds, or when |
| 5852 | * the data about to be copied would over-write the source of |
| 5853 | * the data at the front of the range. i.e. one new_stripe |
| 5854 | * along from reshape_progress new_maps to after where |
| 5855 | * reshape_safe old_maps to |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5856 | */ |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5857 | writepos = conf->reshape_progress; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5858 | sector_div(writepos, new_data_disks); |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5859 | readpos = conf->reshape_progress; |
| 5860 | sector_div(readpos, data_disks); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5861 | safepos = conf->reshape_safe; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5862 | sector_div(safepos, data_disks); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5863 | if (mddev->reshape_backwards) { |
NeilBrown | c74c0d7 | 2015-07-15 17:54:15 +1000 | [diff] [blame] | 5864 | BUG_ON(writepos < reshape_sectors); |
| 5865 | writepos -= reshape_sectors; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5866 | readpos += reshape_sectors; |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5867 | safepos += reshape_sectors; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5868 | } else { |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5869 | writepos += reshape_sectors; |
NeilBrown | c74c0d7 | 2015-07-15 17:54:15 +1000 | [diff] [blame] | 5870 | /* readpos and safepos are worst-case calculations. |
| 5871 | * A negative number is overly pessimistic, and causes |
| 5872 | * obvious problems for unsigned storage. So clip to 0. |
| 5873 | */ |
NeilBrown | ed37d83 | 2009-05-27 21:39:05 +1000 | [diff] [blame] | 5874 | readpos -= min_t(sector_t, reshape_sectors, readpos); |
| 5875 | safepos -= min_t(sector_t, reshape_sectors, safepos); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5876 | } |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5877 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5878 | /* Having calculated the 'writepos' possibly use it |
| 5879 | * to set 'stripe_addr' which is where we will write to. |
| 5880 | */ |
| 5881 | if (mddev->reshape_backwards) { |
| 5882 | BUG_ON(conf->reshape_progress == 0); |
| 5883 | stripe_addr = writepos; |
| 5884 | BUG_ON((mddev->dev_sectors & |
| 5885 | ~((sector_t)reshape_sectors - 1)) |
| 5886 | - reshape_sectors - stripe_addr |
| 5887 | != sector_nr); |
| 5888 | } else { |
| 5889 | BUG_ON(writepos != sector_nr + reshape_sectors); |
| 5890 | stripe_addr = sector_nr; |
| 5891 | } |
| 5892 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5893 | /* 'writepos' is the most advanced device address we might write. |
| 5894 | * 'readpos' is the least advanced device address we might read. |
| 5895 | * 'safepos' is the least address recorded in the metadata as having |
| 5896 | * been reshaped. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5897 | * If there is a min_offset_diff, these are adjusted either by |
| 5898 | * increasing the safepos/readpos if diff is negative, or |
| 5899 | * increasing writepos if diff is positive. |
| 5900 | * If 'readpos' is then behind 'writepos', there is no way that we can |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5901 | * ensure safety in the face of a crash - that must be done by userspace |
| 5902 | * making a backup of the data. So in that case there is no particular |
| 5903 | * rush to update metadata. |
| 5904 | * Otherwise if 'safepos' is behind 'writepos', then we really need to |
| 5905 | * update the metadata to advance 'safepos' to match 'readpos' so that |
| 5906 | * we can be safe in the event of a crash. |
| 5907 | * So we insist on updating metadata if safepos is behind writepos and |
| 5908 | * readpos is beyond writepos. |
| 5909 | * In any case, update the metadata every 10 seconds. |
| 5910 | * Maybe that number should be configurable, but I'm not sure it is |
| 5911 | * worth it.... maybe it could be a multiple of safemode_delay??? |
| 5912 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 5913 | if (conf->min_offset_diff < 0) { |
| 5914 | safepos += -conf->min_offset_diff; |
| 5915 | readpos += -conf->min_offset_diff; |
| 5916 | } else |
| 5917 | writepos += conf->min_offset_diff; |
| 5918 | |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5919 | if ((mddev->reshape_backwards |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5920 | ? (safepos > writepos && readpos < writepos) |
| 5921 | : (safepos < writepos && readpos > writepos)) || |
| 5922 | time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5923 | /* Cannot proceed until we've updated the superblock... */ |
| 5924 | wait_event(conf->wait_for_overlap, |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5925 | atomic_read(&conf->reshape_stripes)==0 |
| 5926 | || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 5927 | if (atomic_read(&conf->reshape_stripes) != 0) |
| 5928 | return 0; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5929 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 5930 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | db0505d | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 5931 | if (!mddev->reshape_backwards) |
| 5932 | /* Can update recovery_offset */ |
| 5933 | rdev_for_each(rdev, mddev) |
| 5934 | if (rdev->raid_disk >= 0 && |
| 5935 | !test_bit(Journal, &rdev->flags) && |
| 5936 | !test_bit(In_sync, &rdev->flags) && |
| 5937 | rdev->recovery_offset < sector_nr) |
| 5938 | rdev->recovery_offset = sector_nr; |
| 5939 | |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 5940 | conf->reshape_checkpoint = jiffies; |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 5941 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5942 | md_wakeup_thread(mddev->thread); |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 5943 | wait_event(mddev->sb_wait, mddev->sb_flags == 0 || |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 5944 | test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 5945 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 5946 | return 0; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5947 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5948 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5949 | spin_unlock_irq(&conf->device_lock); |
| 5950 | wake_up(&conf->wait_for_overlap); |
Junxiao Bi | e1a86db | 2020-07-14 16:10:26 -0700 | [diff] [blame] | 5951 | sysfs_notify_dirent_safe(mddev->sysfs_completed); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5952 | } |
| 5953 | |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5954 | INIT_LIST_HEAD(&stripes); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5955 | for (i = 0; i < reshape_sectors; i += RAID5_STRIPE_SECTORS(conf)) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5956 | int j; |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5957 | int skipped_disk = 0; |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5958 | sh = raid5_get_active_stripe(conf, stripe_addr+i, 0, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5959 | set_bit(STRIPE_EXPANDING, &sh->state); |
| 5960 | atomic_inc(&conf->reshape_stripes); |
| 5961 | /* If any of this stripe is beyond the end of the old |
| 5962 | * array, then we need to zero those blocks |
| 5963 | */ |
| 5964 | for (j=sh->disks; j--;) { |
| 5965 | sector_t s; |
| 5966 | if (j == sh->pd_idx) |
| 5967 | continue; |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5968 | if (conf->level == 6 && |
NeilBrown | d0dabf7 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5969 | j == sh->qd_idx) |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 5970 | continue; |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 5971 | s = raid5_compute_blocknr(sh, j, 0); |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 5972 | if (s < raid5_size(mddev, 0, 0)) { |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5973 | skipped_disk = 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5974 | continue; |
| 5975 | } |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 5976 | memset(page_address(sh->dev[j].page), 0, RAID5_STRIPE_SIZE(conf)); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5977 | set_bit(R5_Expanded, &sh->dev[j].flags); |
| 5978 | set_bit(R5_UPTODATE, &sh->dev[j].flags); |
| 5979 | } |
NeilBrown | a9f326e | 2009-09-23 18:06:41 +1000 | [diff] [blame] | 5980 | if (!skipped_disk) { |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5981 | set_bit(STRIPE_EXPAND_READY, &sh->state); |
| 5982 | set_bit(STRIPE_HANDLE, &sh->state); |
| 5983 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 5984 | list_add(&sh->lru, &stripes); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5985 | } |
| 5986 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 5987 | if (mddev->reshape_backwards) |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5988 | conf->reshape_progress -= reshape_sectors * new_data_disks; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 5989 | else |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 5990 | conf->reshape_progress += reshape_sectors * new_data_disks; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5991 | spin_unlock_irq(&conf->device_lock); |
| 5992 | /* Ok, those stripe are ready. We can start scheduling |
| 5993 | * reads on the source stripes. |
| 5994 | * The source stripes are determined by mapping the first and last |
| 5995 | * block on the destination stripes. |
| 5996 | */ |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 5997 | first_sector = |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 5998 | raid5_compute_sector(conf, stripe_addr*(new_data_disks), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 5999 | 1, &dd_idx, NULL); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6000 | last_sector = |
NeilBrown | 0e6e027 | 2009-06-09 16:32:22 +1000 | [diff] [blame] | 6001 | raid5_compute_sector(conf, ((stripe_addr+reshape_sectors) |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 6002 | * new_data_disks - 1), |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6003 | 1, &dd_idx, NULL); |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6004 | if (last_sector >= mddev->dev_sectors) |
| 6005 | last_sector = mddev->dev_sectors - 1; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6006 | while (first_sector <= last_sector) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6007 | sh = raid5_get_active_stripe(conf, first_sector, 1, 0, 1); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6008 | set_bit(STRIPE_EXPAND_SOURCE, &sh->state); |
| 6009 | set_bit(STRIPE_HANDLE, &sh->state); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6010 | raid5_release_stripe(sh); |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6011 | first_sector += RAID5_STRIPE_SECTORS(conf); |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6012 | } |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 6013 | /* Now that the sources are clearly marked, we can release |
| 6014 | * the destination stripes |
| 6015 | */ |
| 6016 | while (!list_empty(&stripes)) { |
| 6017 | sh = list_entry(stripes.next, struct stripe_head, lru); |
| 6018 | list_del_init(&sh->lru); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6019 | raid5_release_stripe(sh); |
NeilBrown | ab69ae1 | 2009-03-31 15:26:47 +1100 | [diff] [blame] | 6020 | } |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6021 | /* If this takes us to the resync_max point where we have to pause, |
| 6022 | * then we need to write out the superblock. |
| 6023 | */ |
NeilBrown | 7a66138 | 2009-03-31 15:21:40 +1100 | [diff] [blame] | 6024 | sector_nr += reshape_sectors; |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 6025 | retn = reshape_sectors; |
| 6026 | finish: |
NeilBrown | c5e19d9 | 2015-07-17 12:06:02 +1000 | [diff] [blame] | 6027 | if (mddev->curr_resync_completed > mddev->resync_max || |
| 6028 | (sector_nr - mddev->curr_resync_completed) * 2 |
NeilBrown | c03f6a1 | 2009-04-17 11:06:30 +1000 | [diff] [blame] | 6029 | >= mddev->resync_max - mddev->curr_resync_completed) { |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6030 | /* Cannot proceed until we've updated the superblock... */ |
| 6031 | wait_event(conf->wait_for_overlap, |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 6032 | atomic_read(&conf->reshape_stripes) == 0 |
| 6033 | || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 6034 | if (atomic_read(&conf->reshape_stripes) != 0) |
| 6035 | goto ret; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6036 | mddev->reshape_position = conf->reshape_progress; |
NeilBrown | 75d3da4 | 2011-01-14 09:14:34 +1100 | [diff] [blame] | 6037 | mddev->curr_resync_completed = sector_nr; |
NeilBrown | db0505d | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 6038 | if (!mddev->reshape_backwards) |
| 6039 | /* Can update recovery_offset */ |
| 6040 | rdev_for_each(rdev, mddev) |
| 6041 | if (rdev->raid_disk >= 0 && |
| 6042 | !test_bit(Journal, &rdev->flags) && |
| 6043 | !test_bit(In_sync, &rdev->flags) && |
| 6044 | rdev->recovery_offset < sector_nr) |
| 6045 | rdev->recovery_offset = sector_nr; |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 6046 | conf->reshape_checkpoint = jiffies; |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 6047 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6048 | md_wakeup_thread(mddev->thread); |
| 6049 | wait_event(mddev->sb_wait, |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 6050 | !test_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags) |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 6051 | || test_bit(MD_RECOVERY_INTR, &mddev->recovery)); |
| 6052 | if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) |
| 6053 | goto ret; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6054 | spin_lock_irq(&conf->device_lock); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 6055 | conf->reshape_safe = mddev->reshape_position; |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6056 | spin_unlock_irq(&conf->device_lock); |
| 6057 | wake_up(&conf->wait_for_overlap); |
Junxiao Bi | e1a86db | 2020-07-14 16:10:26 -0700 | [diff] [blame] | 6058 | sysfs_notify_dirent_safe(mddev->sysfs_completed); |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6059 | } |
NeilBrown | c91abf5 | 2013-11-19 12:02:01 +1100 | [diff] [blame] | 6060 | ret: |
NeilBrown | 9214048 | 2015-07-06 12:28:45 +1000 | [diff] [blame] | 6061 | return retn; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6062 | } |
| 6063 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 6064 | static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_nr, |
| 6065 | int *skipped) |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6066 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6067 | struct r5conf *conf = mddev->private; |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6068 | struct stripe_head *sh; |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6069 | sector_t max_sector = mddev->dev_sectors; |
NeilBrown | 57dab0b | 2010-10-19 10:03:39 +1100 | [diff] [blame] | 6070 | sector_t sync_blocks; |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6071 | int still_degraded = 0; |
| 6072 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6073 | |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6074 | if (sector_nr >= max_sector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6075 | /* just being told to finish up .. nothing much to do */ |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 6076 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 6077 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) { |
| 6078 | end_reshape(conf); |
| 6079 | return 0; |
| 6080 | } |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6081 | |
| 6082 | if (mddev->curr_resync < max_sector) /* aborted */ |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 6083 | md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync, |
| 6084 | &sync_blocks, 1); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6085 | else /* completed sync */ |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6086 | conf->fullsync = 0; |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 6087 | md_bitmap_close_sync(mddev->bitmap); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6089 | return 0; |
| 6090 | } |
NeilBrown | ccfcc3c | 2006-03-27 01:18:09 -0800 | [diff] [blame] | 6091 | |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 6092 | /* Allow raid5_quiesce to complete */ |
| 6093 | wait_event(conf->wait_for_overlap, conf->quiesce != 2); |
| 6094 | |
NeilBrown | 52c0329 | 2006-06-26 00:27:43 -0700 | [diff] [blame] | 6095 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 6096 | return reshape_request(mddev, sector_nr, skipped); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 6097 | |
NeilBrown | c620727 | 2008-02-06 01:39:52 -0800 | [diff] [blame] | 6098 | /* No need to check resync_max as we never do more than one |
| 6099 | * stripe, and as resync_max will always be on a chunk boundary, |
| 6100 | * if the check in md_do_sync didn't fire, there is no chance |
| 6101 | * of overstepping resync_max here |
| 6102 | */ |
| 6103 | |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6104 | /* if there is too many failed drives and we are trying |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6105 | * to resync, then assert that we are finished, because there is |
| 6106 | * nothing we can do. |
| 6107 | */ |
NeilBrown | 3285edf | 2006-06-26 00:27:55 -0700 | [diff] [blame] | 6108 | if (mddev->degraded >= conf->max_degraded && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6109 | test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 6110 | sector_t rv = mddev->dev_sectors - sector_nr; |
NeilBrown | 57afd89 | 2005-06-21 17:17:13 -0700 | [diff] [blame] | 6111 | *skipped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | return rv; |
| 6113 | } |
majianpeng | 6f60804 | 2013-04-24 11:42:41 +1000 | [diff] [blame] | 6114 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) && |
| 6115 | !conf->fullsync && |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 6116 | !md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) && |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6117 | sync_blocks >= RAID5_STRIPE_SECTORS(conf)) { |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6118 | /* we can skip this block, and probably more */ |
Yufen Yu | 83c3e5e | 2020-07-22 23:29:05 -0400 | [diff] [blame] | 6119 | do_div(sync_blocks, RAID5_STRIPE_SECTORS(conf)); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6120 | *skipped = 1; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6121 | /* keep things rounded to whole stripes */ |
| 6122 | return sync_blocks * RAID5_STRIPE_SECTORS(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 6125 | md_bitmap_cond_end_sync(mddev->bitmap, sector_nr, false); |
NeilBrown | b47490c | 2008-02-06 01:39:50 -0800 | [diff] [blame] | 6126 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6127 | sh = raid5_get_active_stripe(conf, sector_nr, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6128 | if (sh == NULL) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6129 | sh = raid5_get_active_stripe(conf, sector_nr, 0, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | /* make sure we don't swamp the stripe cache if someone else |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6131 | * is trying to get access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6132 | */ |
Nishanth Aravamudan | 66c006a | 2005-11-07 01:01:17 -0800 | [diff] [blame] | 6133 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6135 | /* Need to check if array will still be degraded after recovery/resync |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6136 | * Note in case of > 1 drive failures it's possible we're rebuilding |
| 6137 | * one drive while leaving another faulty drive in array. |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6138 | */ |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6139 | rcu_read_lock(); |
| 6140 | for (i = 0; i < conf->raid_disks; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 6141 | struct md_rdev *rdev = READ_ONCE(conf->disks[i].rdev); |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6142 | |
| 6143 | if (rdev == NULL || test_bit(Faulty, &rdev->flags)) |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6144 | still_degraded = 1; |
Eric Mei | 16d9cfa | 2015-01-06 09:35:02 -0800 | [diff] [blame] | 6145 | } |
| 6146 | rcu_read_unlock(); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6147 | |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 6148 | md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 6149 | |
NeilBrown | 83206d6 | 2011-07-26 11:19:49 +1000 | [diff] [blame] | 6150 | set_bit(STRIPE_SYNC_REQUESTED, &sh->state); |
Eivind Sarto | 053f5b6 | 2014-06-09 17:06:19 -0700 | [diff] [blame] | 6151 | set_bit(STRIPE_HANDLE, &sh->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6153 | raid5_release_stripe(sh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6154 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6155 | return RAID5_STRIPE_SECTORS(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | } |
| 6157 | |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6158 | static int retry_aligned_read(struct r5conf *conf, struct bio *raid_bio, |
| 6159 | unsigned int offset) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6160 | { |
| 6161 | /* We may not be able to submit a whole bio at once as there |
| 6162 | * may not be enough stripe_heads available. |
| 6163 | * We cannot pre-allocate enough stripe_heads as we may need |
| 6164 | * more than exist in the cache (if we allow ever large chunks). |
| 6165 | * So we do one stripe head at a time and record in |
| 6166 | * ->bi_hw_segments how many have been done. |
| 6167 | * |
| 6168 | * We *know* that this entire raid_bio is in one chunk, so |
| 6169 | * it will be only one 'dd_idx' and only need one call to raid5_compute_sector. |
| 6170 | */ |
| 6171 | struct stripe_head *sh; |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6172 | int dd_idx; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6173 | sector_t sector, logical_sector, last_sector; |
| 6174 | int scnt = 0; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6175 | int handled = 0; |
| 6176 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 6177 | logical_sector = raid_bio->bi_iter.bi_sector & |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6178 | ~((sector_t)RAID5_STRIPE_SECTORS(conf)-1); |
NeilBrown | 112bf89 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6179 | sector = raid5_compute_sector(conf, logical_sector, |
NeilBrown | 911d4ee | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 6180 | 0, &dd_idx, NULL); |
Kent Overstreet | f73a1c7 | 2012-09-25 15:05:12 -0700 | [diff] [blame] | 6181 | last_sector = bio_end_sector(raid_bio); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6182 | |
| 6183 | for (; logical_sector < last_sector; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6184 | logical_sector += RAID5_STRIPE_SECTORS(conf), |
| 6185 | sector += RAID5_STRIPE_SECTORS(conf), |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 6186 | scnt++) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6187 | |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6188 | if (scnt < offset) |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6189 | /* already done this stripe */ |
| 6190 | continue; |
| 6191 | |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6192 | sh = raid5_get_active_stripe(conf, sector, 0, 1, 1); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6193 | |
| 6194 | if (!sh) { |
| 6195 | /* failed to get a stripe - must wait */ |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6196 | conf->retry_read_aligned = raid_bio; |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6197 | conf->retry_read_offset = scnt; |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6198 | return handled; |
| 6199 | } |
| 6200 | |
shli@kernel.org | da41ba6 | 2014-12-15 12:57:03 +1100 | [diff] [blame] | 6201 | if (!add_stripe_bio(sh, raid_bio, dd_idx, 0, 0)) { |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6202 | raid5_release_stripe(sh); |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 6203 | conf->retry_read_aligned = raid_bio; |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6204 | conf->retry_read_offset = scnt; |
Neil Brown | 387bb17 | 2007-02-08 14:20:29 -0800 | [diff] [blame] | 6205 | return handled; |
| 6206 | } |
| 6207 | |
majianpeng | 3f9e7c1 | 2012-07-31 10:04:21 +1000 | [diff] [blame] | 6208 | set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6209 | handle_stripe(sh); |
Shaohua Li | 6d036f7 | 2015-08-13 14:31:57 -0700 | [diff] [blame] | 6210 | raid5_release_stripe(sh); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6211 | handled++; |
| 6212 | } |
NeilBrown | 016c76a | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6213 | |
| 6214 | bio_endio(raid_bio); |
| 6215 | |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6216 | if (atomic_dec_and_test(&conf->active_aligned_reads)) |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 6217 | wake_up(&conf->wait_for_quiescent); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6218 | return handled; |
| 6219 | } |
| 6220 | |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 6221 | static int handle_active_stripes(struct r5conf *conf, int group, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6222 | struct r5worker *worker, |
| 6223 | struct list_head *temp_inactive_list) |
Christoph Hellwig | efcd487 | 2019-04-04 18:56:16 +0200 | [diff] [blame] | 6224 | __releases(&conf->device_lock) |
| 6225 | __acquires(&conf->device_lock) |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6226 | { |
| 6227 | struct stripe_head *batch[MAX_STRIPE_BATCH], *sh; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6228 | int i, batch_size = 0, hash; |
| 6229 | bool release_inactive = false; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6230 | |
| 6231 | while (batch_size < MAX_STRIPE_BATCH && |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6232 | (sh = __get_priority_stripe(conf, group)) != NULL) |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6233 | batch[batch_size++] = sh; |
| 6234 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6235 | if (batch_size == 0) { |
| 6236 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 6237 | if (!list_empty(temp_inactive_list + i)) |
| 6238 | break; |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6239 | if (i == NR_STRIPE_HASH_LOCKS) { |
| 6240 | spin_unlock_irq(&conf->device_lock); |
Tomasz Majchrzak | 1532d9e | 2017-12-27 10:31:40 +0100 | [diff] [blame] | 6241 | log_flush_stripe_to_raid(conf); |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6242 | spin_lock_irq(&conf->device_lock); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6243 | return batch_size; |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6244 | } |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6245 | release_inactive = true; |
| 6246 | } |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6247 | spin_unlock_irq(&conf->device_lock); |
| 6248 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6249 | release_inactive_stripe_list(conf, temp_inactive_list, |
| 6250 | NR_STRIPE_HASH_LOCKS); |
| 6251 | |
Shaohua Li | a8c34f9 | 2015-09-02 13:49:46 -0700 | [diff] [blame] | 6252 | r5l_flush_stripe_to_raid(conf->log); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6253 | if (release_inactive) { |
| 6254 | spin_lock_irq(&conf->device_lock); |
| 6255 | return 0; |
| 6256 | } |
| 6257 | |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6258 | for (i = 0; i < batch_size; i++) |
| 6259 | handle_stripe(batch[i]); |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 6260 | log_write_stripe_run(conf); |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6261 | |
| 6262 | cond_resched(); |
| 6263 | |
| 6264 | spin_lock_irq(&conf->device_lock); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6265 | for (i = 0; i < batch_size; i++) { |
| 6266 | hash = batch[i]->hash_lock_index; |
| 6267 | __release_stripe(conf, batch[i], &temp_inactive_list[hash]); |
| 6268 | } |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6269 | return batch_size; |
| 6270 | } |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6271 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6272 | static void raid5_do_work(struct work_struct *work) |
| 6273 | { |
| 6274 | struct r5worker *worker = container_of(work, struct r5worker, work); |
| 6275 | struct r5worker_group *group = worker->group; |
| 6276 | struct r5conf *conf = group->conf; |
NeilBrown | 16d997b | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 6277 | struct mddev *mddev = conf->mddev; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6278 | int group_id = group - conf->worker_groups; |
| 6279 | int handled; |
| 6280 | struct blk_plug plug; |
| 6281 | |
| 6282 | pr_debug("+++ raid5worker active\n"); |
| 6283 | |
| 6284 | blk_start_plug(&plug); |
| 6285 | handled = 0; |
| 6286 | spin_lock_irq(&conf->device_lock); |
| 6287 | while (1) { |
| 6288 | int batch_size, released; |
| 6289 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6290 | released = release_stripe_list(conf, worker->temp_inactive_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6291 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6292 | batch_size = handle_active_stripes(conf, group_id, worker, |
| 6293 | worker->temp_inactive_list); |
Shaohua Li | bfc90cb | 2013-08-29 15:40:32 +0800 | [diff] [blame] | 6294 | worker->working = false; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6295 | if (!batch_size && !released) |
| 6296 | break; |
| 6297 | handled += batch_size; |
NeilBrown | 16d997b | 2017-03-15 14:05:12 +1100 | [diff] [blame] | 6298 | wait_event_lock_irq(mddev->sb_wait, |
| 6299 | !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags), |
| 6300 | conf->device_lock); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6301 | } |
| 6302 | pr_debug("%d stripes handled\n", handled); |
| 6303 | |
| 6304 | spin_unlock_irq(&conf->device_lock); |
Ofer Heifetz | 7e96d55 | 2017-07-24 09:17:40 +0300 | [diff] [blame] | 6305 | |
Song Liu | 9c72a18e4 | 2017-08-24 09:53:59 -0700 | [diff] [blame] | 6306 | flush_deferred_bios(conf); |
| 6307 | |
| 6308 | r5l_flush_stripe_to_raid(conf->log); |
| 6309 | |
Ofer Heifetz | 7e96d55 | 2017-07-24 09:17:40 +0300 | [diff] [blame] | 6310 | async_tx_issue_pending_all(); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6311 | blk_finish_plug(&plug); |
| 6312 | |
| 6313 | pr_debug("--- raid5worker inactive\n"); |
| 6314 | } |
| 6315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6316 | /* |
| 6317 | * This is our raid5 kernel thread. |
| 6318 | * |
| 6319 | * We scan the hash table for stripes which can be handled now. |
| 6320 | * During the scan, completed stripes are saved for us by the interrupt |
| 6321 | * handler, so that they will not have to wait for our next wakeup. |
| 6322 | */ |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 6323 | static void raid5d(struct md_thread *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6324 | { |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 6325 | struct mddev *mddev = thread->mddev; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6326 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6327 | int handled; |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 6328 | struct blk_plug plug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6329 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 6330 | pr_debug("+++ raid5d active\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6331 | |
| 6332 | md_check_recovery(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 6334 | blk_start_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6335 | handled = 0; |
| 6336 | spin_lock_irq(&conf->device_lock); |
| 6337 | while (1) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6338 | struct bio *bio; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 6339 | int batch_size, released; |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6340 | unsigned int offset; |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 6341 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6342 | released = release_stripe_list(conf, conf->temp_inactive_list); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6343 | if (released) |
| 6344 | clear_bit(R5_DID_ALLOC, &conf->cache_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 6346 | if ( |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 6347 | !list_empty(&conf->bitmap_list)) { |
| 6348 | /* Now is a good time to flush some bitmap updates */ |
| 6349 | conf->seq_flush++; |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 6350 | spin_unlock_irq(&conf->device_lock); |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 6351 | md_bitmap_unplug(mddev->bitmap); |
NeilBrown | 700e432 | 2005-11-28 13:44:10 -0800 | [diff] [blame] | 6352 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 7c13edc | 2011-04-18 18:25:43 +1000 | [diff] [blame] | 6353 | conf->seq_write = conf->seq_flush; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6354 | activate_bit_delay(conf, conf->temp_inactive_list); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6355 | } |
NeilBrown | 0021b7b | 2012-07-31 09:08:14 +0200 | [diff] [blame] | 6356 | raid5_activate_delayed(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 6357 | |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6358 | while ((bio = remove_bio_from_retry(conf, &offset))) { |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6359 | int ok; |
| 6360 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 0472a42 | 2017-03-15 14:05:13 +1100 | [diff] [blame] | 6361 | ok = retry_aligned_read(conf, bio, offset); |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 6362 | spin_lock_irq(&conf->device_lock); |
| 6363 | if (!ok) |
| 6364 | break; |
| 6365 | handled++; |
| 6366 | } |
| 6367 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6368 | batch_size = handle_active_stripes(conf, ANY_GROUP, NULL, |
| 6369 | conf->temp_inactive_list); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 6370 | if (!batch_size && !released) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6371 | break; |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6372 | handled += batch_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 6374 | if (mddev->sb_flags & ~(1 << MD_SB_CHANGE_PENDING)) { |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6375 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | de393cd | 2011-07-28 11:31:48 +1000 | [diff] [blame] | 6376 | md_check_recovery(mddev); |
Shaohua Li | 46a0640 | 2012-08-02 08:33:15 +1000 | [diff] [blame] | 6377 | spin_lock_irq(&conf->device_lock); |
| 6378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6379 | } |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 6380 | pr_debug("%d stripes handled\n", handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6381 | |
| 6382 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6383 | if (test_and_clear_bit(R5_ALLOC_MORE, &conf->cache_state) && |
| 6384 | mutex_trylock(&conf->cache_size_mutex)) { |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6385 | grow_one_stripe(conf, __GFP_NOWARN); |
| 6386 | /* Set flag even if allocation failed. This helps |
| 6387 | * slow down allocation requests when mem is short |
| 6388 | */ |
| 6389 | set_bit(R5_DID_ALLOC, &conf->cache_state); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6390 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6392 | |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 6393 | flush_deferred_bios(conf); |
| 6394 | |
Shaohua Li | 0576b1c | 2015-08-13 14:32:00 -0700 | [diff] [blame] | 6395 | r5l_flush_stripe_to_raid(conf->log); |
| 6396 | |
Dan Williams | c9f21aa | 2008-07-23 12:05:51 -0700 | [diff] [blame] | 6397 | async_tx_issue_pending_all(); |
NeilBrown | e1dfa0a | 2011-04-18 18:25:41 +1000 | [diff] [blame] | 6398 | blk_finish_plug(&plug); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | |
Dan Williams | 45b4233 | 2007-07-09 11:56:43 -0700 | [diff] [blame] | 6400 | pr_debug("--- raid5d inactive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6401 | } |
| 6402 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6403 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6404 | raid5_show_stripe_cache_size(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6405 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6406 | struct r5conf *conf; |
| 6407 | int ret = 0; |
| 6408 | spin_lock(&mddev->lock); |
| 6409 | conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6410 | if (conf) |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6411 | ret = sprintf(page, "%d\n", conf->min_nr_stripes); |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6412 | spin_unlock(&mddev->lock); |
| 6413 | return ret; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6414 | } |
| 6415 | |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6416 | int |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6417 | raid5_set_cache_size(struct mddev *mddev, int size) |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6418 | { |
Alexei Naberezhnov | 483cbbe | 2018-03-27 16:54:16 -0700 | [diff] [blame] | 6419 | int result = 0; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6420 | struct r5conf *conf = mddev->private; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6421 | |
| 6422 | if (size <= 16 || size > 32768) |
| 6423 | return -EINVAL; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6424 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6425 | conf->min_nr_stripes = size; |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6426 | mutex_lock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6427 | while (size < conf->max_nr_stripes && |
| 6428 | drop_one_stripe(conf)) |
| 6429 | ; |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6430 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6431 | |
Artur Paszkiewicz | 2214c26 | 2017-05-08 11:56:55 +0200 | [diff] [blame] | 6432 | md_allow_write(mddev); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6433 | |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6434 | mutex_lock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6435 | while (size > conf->max_nr_stripes) |
Alexei Naberezhnov | 483cbbe | 2018-03-27 16:54:16 -0700 | [diff] [blame] | 6436 | if (!grow_one_stripe(conf, GFP_KERNEL)) { |
| 6437 | conf->min_nr_stripes = conf->max_nr_stripes; |
| 6438 | result = -ENOMEM; |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6439 | break; |
Alexei Naberezhnov | 483cbbe | 2018-03-27 16:54:16 -0700 | [diff] [blame] | 6440 | } |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6441 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | 486f064 | 2015-02-25 12:10:35 +1100 | [diff] [blame] | 6442 | |
Alexei Naberezhnov | 483cbbe | 2018-03-27 16:54:16 -0700 | [diff] [blame] | 6443 | return result; |
NeilBrown | c41d4ac | 2010-06-01 19:37:24 +1000 | [diff] [blame] | 6444 | } |
| 6445 | EXPORT_SYMBOL(raid5_set_cache_size); |
| 6446 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6447 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6448 | 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] | 6449 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6450 | struct r5conf *conf; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 6451 | unsigned long new; |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6452 | int err; |
| 6453 | |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6454 | if (len >= PAGE_SIZE) |
| 6455 | return -EINVAL; |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 6456 | if (kstrtoul(page, 10, &new)) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6457 | return -EINVAL; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6458 | err = mddev_lock(mddev); |
Dan Williams | b5470dc | 2008-06-27 21:44:04 -0700 | [diff] [blame] | 6459 | if (err) |
| 6460 | return err; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6461 | conf = mddev->private; |
| 6462 | if (!conf) |
| 6463 | err = -ENODEV; |
| 6464 | else |
| 6465 | err = raid5_set_cache_size(mddev, new); |
| 6466 | mddev_unlock(mddev); |
| 6467 | |
| 6468 | return err ?: len; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6469 | } |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 6470 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6471 | static struct md_sysfs_entry |
| 6472 | raid5_stripecache_size = __ATTR(stripe_cache_size, S_IRUGO | S_IWUSR, |
| 6473 | raid5_show_stripe_cache_size, |
| 6474 | raid5_store_stripe_cache_size); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6475 | |
| 6476 | static ssize_t |
Markus Stockhausen | d06f191 | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6477 | raid5_show_rmw_level(struct mddev *mddev, char *page) |
| 6478 | { |
| 6479 | struct r5conf *conf = mddev->private; |
| 6480 | if (conf) |
| 6481 | return sprintf(page, "%d\n", conf->rmw_level); |
| 6482 | else |
| 6483 | return 0; |
| 6484 | } |
| 6485 | |
| 6486 | static ssize_t |
| 6487 | raid5_store_rmw_level(struct mddev *mddev, const char *page, size_t len) |
| 6488 | { |
| 6489 | struct r5conf *conf = mddev->private; |
| 6490 | unsigned long new; |
| 6491 | |
| 6492 | if (!conf) |
| 6493 | return -ENODEV; |
| 6494 | |
| 6495 | if (len >= PAGE_SIZE) |
| 6496 | return -EINVAL; |
| 6497 | |
| 6498 | if (kstrtoul(page, 10, &new)) |
| 6499 | return -EINVAL; |
| 6500 | |
| 6501 | if (new != PARITY_DISABLE_RMW && !raid6_call.xor_syndrome) |
| 6502 | return -EINVAL; |
| 6503 | |
| 6504 | if (new != PARITY_DISABLE_RMW && |
| 6505 | new != PARITY_ENABLE_RMW && |
| 6506 | new != PARITY_PREFER_RMW) |
| 6507 | return -EINVAL; |
| 6508 | |
| 6509 | conf->rmw_level = new; |
| 6510 | return len; |
| 6511 | } |
| 6512 | |
| 6513 | static struct md_sysfs_entry |
| 6514 | raid5_rmw_level = __ATTR(rmw_level, S_IRUGO | S_IWUSR, |
| 6515 | raid5_show_rmw_level, |
| 6516 | raid5_store_rmw_level); |
| 6517 | |
Yufen Yu | 3b5408b | 2020-07-18 05:29:09 -0400 | [diff] [blame] | 6518 | static ssize_t |
| 6519 | raid5_show_stripe_size(struct mddev *mddev, char *page) |
| 6520 | { |
| 6521 | struct r5conf *conf; |
| 6522 | int ret = 0; |
| 6523 | |
| 6524 | spin_lock(&mddev->lock); |
| 6525 | conf = mddev->private; |
| 6526 | if (conf) |
| 6527 | ret = sprintf(page, "%lu\n", RAID5_STRIPE_SIZE(conf)); |
| 6528 | spin_unlock(&mddev->lock); |
| 6529 | return ret; |
| 6530 | } |
| 6531 | |
| 6532 | #if PAGE_SIZE != DEFAULT_STRIPE_SIZE |
| 6533 | static ssize_t |
| 6534 | raid5_store_stripe_size(struct mddev *mddev, const char *page, size_t len) |
| 6535 | { |
| 6536 | struct r5conf *conf; |
| 6537 | unsigned long new; |
| 6538 | int err; |
| 6539 | |
| 6540 | if (len >= PAGE_SIZE) |
| 6541 | return -EINVAL; |
| 6542 | if (kstrtoul(page, 10, &new)) |
| 6543 | return -EINVAL; |
| 6544 | |
| 6545 | /* |
| 6546 | * The value should not be bigger than PAGE_SIZE. It requires to |
Yufen Yu | 6af10a3 | 2020-08-20 09:22:05 -0400 | [diff] [blame] | 6547 | * be multiple of DEFAULT_STRIPE_SIZE and the value should be power |
| 6548 | * of two. |
Yufen Yu | 3b5408b | 2020-07-18 05:29:09 -0400 | [diff] [blame] | 6549 | */ |
Yufen Yu | 6af10a3 | 2020-08-20 09:22:05 -0400 | [diff] [blame] | 6550 | if (new % DEFAULT_STRIPE_SIZE != 0 || |
| 6551 | new > PAGE_SIZE || new == 0 || |
| 6552 | new != roundup_pow_of_two(new)) |
Yufen Yu | 3b5408b | 2020-07-18 05:29:09 -0400 | [diff] [blame] | 6553 | return -EINVAL; |
| 6554 | |
| 6555 | err = mddev_lock(mddev); |
| 6556 | if (err) |
| 6557 | return err; |
| 6558 | |
| 6559 | conf = mddev->private; |
| 6560 | if (!conf) { |
| 6561 | err = -ENODEV; |
| 6562 | goto out_unlock; |
| 6563 | } |
| 6564 | |
| 6565 | if (new == conf->stripe_size) |
| 6566 | goto out_unlock; |
| 6567 | |
| 6568 | pr_debug("md/raid: change stripe_size from %lu to %lu\n", |
| 6569 | conf->stripe_size, new); |
| 6570 | |
| 6571 | mddev_suspend(mddev); |
| 6572 | conf->stripe_size = new; |
| 6573 | conf->stripe_shift = ilog2(new) - 9; |
| 6574 | conf->stripe_sectors = new >> 9; |
| 6575 | mddev_resume(mddev); |
| 6576 | |
| 6577 | out_unlock: |
| 6578 | mddev_unlock(mddev); |
| 6579 | return err ?: len; |
| 6580 | } |
| 6581 | |
| 6582 | static struct md_sysfs_entry |
| 6583 | raid5_stripe_size = __ATTR(stripe_size, 0644, |
| 6584 | raid5_show_stripe_size, |
| 6585 | raid5_store_stripe_size); |
| 6586 | #else |
| 6587 | static struct md_sysfs_entry |
| 6588 | raid5_stripe_size = __ATTR(stripe_size, 0444, |
| 6589 | raid5_show_stripe_size, |
| 6590 | NULL); |
| 6591 | #endif |
Markus Stockhausen | d06f191 | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6592 | |
| 6593 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6594 | raid5_show_preread_threshold(struct mddev *mddev, char *page) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6595 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6596 | struct r5conf *conf; |
| 6597 | int ret = 0; |
| 6598 | spin_lock(&mddev->lock); |
| 6599 | conf = mddev->private; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6600 | if (conf) |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6601 | ret = sprintf(page, "%d\n", conf->bypass_threshold); |
| 6602 | spin_unlock(&mddev->lock); |
| 6603 | return ret; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6607 | 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] | 6608 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6609 | struct r5conf *conf; |
Dan Williams | 4ef197d8 | 2008-04-28 02:15:54 -0700 | [diff] [blame] | 6610 | unsigned long new; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6611 | int err; |
| 6612 | |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6613 | if (len >= PAGE_SIZE) |
| 6614 | return -EINVAL; |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 6615 | if (kstrtoul(page, 10, &new)) |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6616 | return -EINVAL; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6617 | |
| 6618 | err = mddev_lock(mddev); |
| 6619 | if (err) |
| 6620 | return err; |
| 6621 | conf = mddev->private; |
| 6622 | if (!conf) |
| 6623 | err = -ENODEV; |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6624 | else if (new > conf->min_nr_stripes) |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6625 | err = -EINVAL; |
| 6626 | else |
| 6627 | conf->bypass_threshold = new; |
| 6628 | mddev_unlock(mddev); |
| 6629 | return err ?: len; |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6630 | } |
| 6631 | |
| 6632 | static struct md_sysfs_entry |
| 6633 | raid5_preread_bypass_threshold = __ATTR(preread_bypass_threshold, |
| 6634 | S_IRUGO | S_IWUSR, |
| 6635 | raid5_show_preread_threshold, |
| 6636 | raid5_store_preread_threshold); |
| 6637 | |
| 6638 | static ssize_t |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6639 | raid5_show_skip_copy(struct mddev *mddev, char *page) |
| 6640 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6641 | struct r5conf *conf; |
| 6642 | int ret = 0; |
| 6643 | spin_lock(&mddev->lock); |
| 6644 | conf = mddev->private; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6645 | if (conf) |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6646 | ret = sprintf(page, "%d\n", conf->skip_copy); |
| 6647 | spin_unlock(&mddev->lock); |
| 6648 | return ret; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6649 | } |
| 6650 | |
| 6651 | static ssize_t |
| 6652 | raid5_store_skip_copy(struct mddev *mddev, const char *page, size_t len) |
| 6653 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6654 | struct r5conf *conf; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6655 | unsigned long new; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6656 | int err; |
| 6657 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6658 | if (len >= PAGE_SIZE) |
| 6659 | return -EINVAL; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6660 | if (kstrtoul(page, 10, &new)) |
| 6661 | return -EINVAL; |
| 6662 | new = !!new; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6663 | |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6664 | err = mddev_lock(mddev); |
| 6665 | if (err) |
| 6666 | return err; |
| 6667 | conf = mddev->private; |
| 6668 | if (!conf) |
| 6669 | err = -ENODEV; |
| 6670 | else if (new != conf->skip_copy) { |
Christoph Hellwig | 1cb039f | 2020-09-24 08:51:38 +0200 | [diff] [blame] | 6671 | struct request_queue *q = mddev->queue; |
| 6672 | |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6673 | mddev_suspend(mddev); |
| 6674 | conf->skip_copy = new; |
| 6675 | if (new) |
Christoph Hellwig | 1cb039f | 2020-09-24 08:51:38 +0200 | [diff] [blame] | 6676 | blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, q); |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6677 | else |
Christoph Hellwig | 1cb039f | 2020-09-24 08:51:38 +0200 | [diff] [blame] | 6678 | blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, q); |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6679 | mddev_resume(mddev); |
| 6680 | } |
| 6681 | mddev_unlock(mddev); |
| 6682 | return err ?: len; |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | static struct md_sysfs_entry |
| 6686 | raid5_skip_copy = __ATTR(skip_copy, S_IRUGO | S_IWUSR, |
| 6687 | raid5_show_skip_copy, |
| 6688 | raid5_store_skip_copy); |
| 6689 | |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6690 | static ssize_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6691 | stripe_cache_active_show(struct mddev *mddev, char *page) |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6692 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6693 | struct r5conf *conf = mddev->private; |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6694 | if (conf) |
| 6695 | return sprintf(page, "%d\n", atomic_read(&conf->active_stripes)); |
| 6696 | else |
| 6697 | return 0; |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6698 | } |
| 6699 | |
NeilBrown | 96de1e6 | 2005-11-08 21:39:39 -0800 | [diff] [blame] | 6700 | static struct md_sysfs_entry |
| 6701 | raid5_stripecache_active = __ATTR_RO(stripe_cache_active); |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6702 | |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6703 | static ssize_t |
| 6704 | raid5_show_group_thread_cnt(struct mddev *mddev, char *page) |
| 6705 | { |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6706 | struct r5conf *conf; |
| 6707 | int ret = 0; |
| 6708 | spin_lock(&mddev->lock); |
| 6709 | conf = mddev->private; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6710 | if (conf) |
NeilBrown | 7b1485b | 2014-12-15 12:56:59 +1100 | [diff] [blame] | 6711 | ret = sprintf(page, "%d\n", conf->worker_cnt_per_group); |
| 6712 | spin_unlock(&mddev->lock); |
| 6713 | return ret; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6714 | } |
| 6715 | |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6716 | static int alloc_thread_groups(struct r5conf *conf, int cnt, |
| 6717 | int *group_cnt, |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6718 | struct r5worker_group **worker_groups); |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6719 | static ssize_t |
| 6720 | raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) |
| 6721 | { |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6722 | struct r5conf *conf; |
Shaohua Li | 7d5d7b5 | 2017-09-21 11:03:52 -0700 | [diff] [blame] | 6723 | unsigned int new; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6724 | int err; |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6725 | struct r5worker_group *new_groups, *old_groups; |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 6726 | int group_cnt; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6727 | |
| 6728 | if (len >= PAGE_SIZE) |
| 6729 | return -EINVAL; |
Shaohua Li | 7d5d7b5 | 2017-09-21 11:03:52 -0700 | [diff] [blame] | 6730 | if (kstrtouint(page, 10, &new)) |
| 6731 | return -EINVAL; |
| 6732 | /* 8192 should be big enough */ |
| 6733 | if (new > 8192) |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6734 | return -EINVAL; |
| 6735 | |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6736 | err = mddev_lock(mddev); |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6737 | if (err) |
| 6738 | return err; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6739 | conf = mddev->private; |
| 6740 | if (!conf) |
| 6741 | err = -ENODEV; |
| 6742 | else if (new != conf->worker_cnt_per_group) { |
| 6743 | mddev_suspend(mddev); |
| 6744 | |
| 6745 | old_groups = conf->worker_groups; |
| 6746 | if (old_groups) |
| 6747 | flush_workqueue(raid5_wq); |
| 6748 | |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 6749 | err = alloc_thread_groups(conf, new, &group_cnt, &new_groups); |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6750 | if (!err) { |
| 6751 | spin_lock_irq(&conf->device_lock); |
| 6752 | conf->group_cnt = group_cnt; |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 6753 | conf->worker_cnt_per_group = new; |
NeilBrown | 6791875 | 2014-12-15 12:57:01 +1100 | [diff] [blame] | 6754 | conf->worker_groups = new_groups; |
| 6755 | spin_unlock_irq(&conf->device_lock); |
| 6756 | |
| 6757 | if (old_groups) |
| 6758 | kfree(old_groups[0].workers); |
| 6759 | kfree(old_groups); |
| 6760 | } |
| 6761 | mddev_resume(mddev); |
| 6762 | } |
| 6763 | mddev_unlock(mddev); |
| 6764 | |
| 6765 | return err ?: len; |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | static struct md_sysfs_entry |
| 6769 | raid5_group_thread_cnt = __ATTR(group_thread_cnt, S_IRUGO | S_IWUSR, |
| 6770 | raid5_show_group_thread_cnt, |
| 6771 | raid5_store_group_thread_cnt); |
| 6772 | |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 6773 | static struct attribute *raid5_attrs[] = { |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6774 | &raid5_stripecache_size.attr, |
| 6775 | &raid5_stripecache_active.attr, |
Dan Williams | 8b3e6cd | 2008-04-28 02:15:53 -0700 | [diff] [blame] | 6776 | &raid5_preread_bypass_threshold.attr, |
Shaohua Li | b721420 | 2013-08-27 17:50:42 +0800 | [diff] [blame] | 6777 | &raid5_group_thread_cnt.attr, |
Shaohua Li | d592a99 | 2014-05-21 17:57:44 +0800 | [diff] [blame] | 6778 | &raid5_skip_copy.attr, |
Markus Stockhausen | d06f191 | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 6779 | &raid5_rmw_level.attr, |
Yufen Yu | 3b5408b | 2020-07-18 05:29:09 -0400 | [diff] [blame] | 6780 | &raid5_stripe_size.attr, |
Song Liu | 2c7da14 | 2016-11-17 15:24:41 -0800 | [diff] [blame] | 6781 | &r5c_journal_mode.attr, |
Mariusz Dabrowski | a596d08 | 2019-02-18 15:04:09 +0100 | [diff] [blame] | 6782 | &ppl_write_hint.attr, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6783 | NULL, |
| 6784 | }; |
NeilBrown | 007583c | 2005-11-08 21:39:30 -0800 | [diff] [blame] | 6785 | static struct attribute_group raid5_attrs_group = { |
| 6786 | .name = NULL, |
| 6787 | .attrs = raid5_attrs, |
NeilBrown | 3f294f4 | 2005-11-08 21:39:25 -0800 | [diff] [blame] | 6788 | }; |
| 6789 | |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 6790 | static int alloc_thread_groups(struct r5conf *conf, int cnt, int *group_cnt, |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6791 | struct r5worker_group **worker_groups) |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6792 | { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6793 | int i, j, k; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6794 | ssize_t size; |
| 6795 | struct r5worker *workers; |
| 6796 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6797 | if (cnt == 0) { |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6798 | *group_cnt = 0; |
| 6799 | *worker_groups = NULL; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6800 | return 0; |
| 6801 | } |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6802 | *group_cnt = num_possible_nodes(); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6803 | size = sizeof(struct r5worker) * cnt; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6804 | workers = kcalloc(size, *group_cnt, GFP_NOIO); |
| 6805 | *worker_groups = kcalloc(*group_cnt, sizeof(struct r5worker_group), |
| 6806 | GFP_NOIO); |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6807 | if (!*worker_groups || !workers) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6808 | kfree(workers); |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6809 | kfree(*worker_groups); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6810 | return -ENOMEM; |
| 6811 | } |
| 6812 | |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6813 | for (i = 0; i < *group_cnt; i++) { |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6814 | struct r5worker_group *group; |
| 6815 | |
NeilBrown | 0c775d5 | 2013-11-25 11:12:43 +1100 | [diff] [blame] | 6816 | group = &(*worker_groups)[i]; |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6817 | INIT_LIST_HEAD(&group->handle_list); |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 6818 | INIT_LIST_HEAD(&group->loprio_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6819 | group->conf = conf; |
| 6820 | group->workers = workers + i * cnt; |
| 6821 | |
| 6822 | for (j = 0; j < cnt; j++) { |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6823 | struct r5worker *worker = group->workers + j; |
| 6824 | worker->group = group; |
| 6825 | INIT_WORK(&worker->work, raid5_do_work); |
| 6826 | |
| 6827 | for (k = 0; k < NR_STRIPE_HASH_LOCKS; k++) |
| 6828 | INIT_LIST_HEAD(worker->temp_inactive_list + k); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | return 0; |
| 6833 | } |
| 6834 | |
| 6835 | static void free_thread_groups(struct r5conf *conf) |
| 6836 | { |
| 6837 | if (conf->worker_groups) |
| 6838 | kfree(conf->worker_groups[0].workers); |
| 6839 | kfree(conf->worker_groups); |
| 6840 | conf->worker_groups = NULL; |
| 6841 | } |
| 6842 | |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6843 | static sector_t |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 6844 | raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6845 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6846 | struct r5conf *conf = mddev->private; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6847 | |
| 6848 | if (!sectors) |
| 6849 | sectors = mddev->dev_sectors; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6850 | if (!raid_disks) |
NeilBrown | 7ec0547 | 2009-03-31 15:10:36 +1100 | [diff] [blame] | 6851 | /* size is defined by the smallest of previous and new size */ |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6852 | raid_disks = min(conf->raid_disks, conf->previous_raid_disks); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6853 | |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 6854 | sectors &= ~((sector_t)conf->chunk_sectors - 1); |
| 6855 | sectors &= ~((sector_t)conf->prev_chunk_sectors - 1); |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 6856 | return sectors * (raid_disks - conf->max_degraded); |
| 6857 | } |
| 6858 | |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6859 | static void free_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) |
| 6860 | { |
| 6861 | safe_put_page(percpu->spare_page); |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6862 | percpu->spare_page = NULL; |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 6863 | kvfree(percpu->scribble); |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6864 | percpu->scribble = NULL; |
| 6865 | } |
| 6866 | |
| 6867 | static int alloc_scratch_buffer(struct r5conf *conf, struct raid5_percpu *percpu) |
| 6868 | { |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 6869 | if (conf->level == 6 && !percpu->spare_page) { |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6870 | percpu->spare_page = alloc_page(GFP_KERNEL); |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 6871 | if (!percpu->spare_page) |
| 6872 | return -ENOMEM; |
| 6873 | } |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6874 | |
Kent Overstreet | b330e6a | 2019-03-11 23:31:06 -0700 | [diff] [blame] | 6875 | if (scribble_alloc(percpu, |
| 6876 | max(conf->raid_disks, |
| 6877 | conf->previous_raid_disks), |
| 6878 | max(conf->chunk_sectors, |
| 6879 | conf->prev_chunk_sectors) |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 6880 | / RAID5_STRIPE_SECTORS(conf))) { |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6881 | free_scratch_buffer(conf, percpu); |
| 6882 | return -ENOMEM; |
| 6883 | } |
| 6884 | |
| 6885 | return 0; |
| 6886 | } |
| 6887 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6888 | static int raid456_cpu_dead(unsigned int cpu, struct hlist_node *node) |
| 6889 | { |
| 6890 | struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); |
| 6891 | |
| 6892 | free_scratch_buffer(conf, per_cpu_ptr(conf->percpu, cpu)); |
| 6893 | return 0; |
| 6894 | } |
| 6895 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6896 | static void raid5_free_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6897 | { |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6898 | if (!conf->percpu) |
| 6899 | return; |
| 6900 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6901 | cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6902 | free_percpu(conf->percpu); |
| 6903 | } |
| 6904 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6905 | static void free_conf(struct r5conf *conf) |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6906 | { |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 6907 | int i; |
| 6908 | |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 6909 | log_exit(conf); |
| 6910 | |
Aliaksei Karaliou | 565e045 | 2017-12-23 21:20:31 +0300 | [diff] [blame] | 6911 | unregister_shrinker(&conf->shrinker); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 6912 | free_thread_groups(conf); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6913 | shrink_stripes(conf); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6914 | raid5_free_percpu(conf); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 6915 | for (i = 0; i < conf->pool_size; i++) |
| 6916 | if (conf->disks[i].extra_page) |
| 6917 | put_page(conf->disks[i].extra_page); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6918 | kfree(conf->disks); |
Kent Overstreet | afeee51 | 2018-05-20 18:25:52 -0400 | [diff] [blame] | 6919 | bioset_exit(&conf->bio_split); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6920 | kfree(conf->stripe_hashtbl); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 6921 | kfree(conf->pending_data); |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 6922 | kfree(conf); |
| 6923 | } |
| 6924 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6925 | 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] | 6926 | { |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6927 | struct r5conf *conf = hlist_entry_safe(node, struct r5conf, node); |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6928 | struct raid5_percpu *percpu = per_cpu_ptr(conf->percpu, cpu); |
| 6929 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6930 | if (alloc_scratch_buffer(conf, percpu)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 6931 | pr_warn("%s: failed memory allocation for cpu%u\n", |
| 6932 | __func__, cpu); |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6933 | return -ENOMEM; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6934 | } |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6935 | return 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6936 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6937 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6938 | static int raid5_alloc_percpu(struct r5conf *conf) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6939 | { |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6940 | int err = 0; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6941 | |
Oleg Nesterov | 789b5e0 | 2014-02-06 03:42:45 +0530 | [diff] [blame] | 6942 | conf->percpu = alloc_percpu(struct raid5_percpu); |
| 6943 | if (!conf->percpu) |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6944 | return -ENOMEM; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6945 | |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 6946 | err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node); |
Shaohua Li | 27a353c | 2016-02-24 17:38:28 -0800 | [diff] [blame] | 6947 | if (!err) { |
| 6948 | conf->scribble_disks = max(conf->raid_disks, |
| 6949 | conf->previous_raid_disks); |
| 6950 | conf->scribble_sectors = max(conf->chunk_sectors, |
| 6951 | conf->prev_chunk_sectors); |
| 6952 | } |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 6953 | return err; |
| 6954 | } |
| 6955 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6956 | static unsigned long raid5_cache_scan(struct shrinker *shrink, |
| 6957 | struct shrink_control *sc) |
| 6958 | { |
| 6959 | struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6960 | unsigned long ret = SHRINK_STOP; |
| 6961 | |
| 6962 | if (mutex_trylock(&conf->cache_size_mutex)) { |
| 6963 | ret= 0; |
NeilBrown | 49895bc | 2015-08-03 17:09:57 +1000 | [diff] [blame] | 6964 | while (ret < sc->nr_to_scan && |
| 6965 | conf->max_nr_stripes > conf->min_nr_stripes) { |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 6966 | if (drop_one_stripe(conf) == 0) { |
| 6967 | ret = SHRINK_STOP; |
| 6968 | break; |
| 6969 | } |
| 6970 | ret++; |
| 6971 | } |
| 6972 | mutex_unlock(&conf->cache_size_mutex); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 6973 | } |
| 6974 | return ret; |
| 6975 | } |
| 6976 | |
| 6977 | static unsigned long raid5_cache_count(struct shrinker *shrink, |
| 6978 | struct shrink_control *sc) |
| 6979 | { |
| 6980 | struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); |
| 6981 | |
| 6982 | if (conf->max_nr_stripes < conf->min_nr_stripes) |
| 6983 | /* unlikely, but not impossible */ |
| 6984 | return 0; |
| 6985 | return conf->max_nr_stripes - conf->min_nr_stripes; |
| 6986 | } |
| 6987 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6988 | static struct r5conf *setup_conf(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6989 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 6990 | struct r5conf *conf; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 6991 | int raid_disk, memory, max_disks; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 6992 | struct md_rdev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6993 | struct disk_info *disk; |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 6994 | char pers_name[6]; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 6995 | int i; |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 6996 | int group_cnt; |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 6997 | struct r5worker_group *new_group; |
Kent Overstreet | afeee51 | 2018-05-20 18:25:52 -0400 | [diff] [blame] | 6998 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6999 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7000 | if (mddev->new_level != 5 |
| 7001 | && mddev->new_level != 4 |
| 7002 | && mddev->new_level != 6) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7003 | pr_warn("md/raid:%s: raid level not set to 4/5/6 (%d)\n", |
| 7004 | mdname(mddev), mddev->new_level); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7005 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7006 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7007 | if ((mddev->new_level == 5 |
| 7008 | && !algorithm_valid_raid5(mddev->new_layout)) || |
| 7009 | (mddev->new_level == 6 |
| 7010 | && !algorithm_valid_raid6(mddev->new_layout))) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7011 | pr_warn("md/raid:%s: layout %d not supported\n", |
| 7012 | mdname(mddev), mddev->new_layout); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7013 | return ERR_PTR(-EIO); |
| 7014 | } |
| 7015 | if (mddev->new_level == 6 && mddev->raid_disks < 4) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7016 | pr_warn("md/raid:%s: not enough configured devices (%d, minimum 4)\n", |
| 7017 | mdname(mddev), mddev->raid_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7018 | return ERR_PTR(-EINVAL); |
NeilBrown | 99c0fb5 | 2009-03-31 14:39:38 +1100 | [diff] [blame] | 7019 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7020 | |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 7021 | if (!mddev->new_chunk_sectors || |
| 7022 | (mddev->new_chunk_sectors << 9) % PAGE_SIZE || |
| 7023 | !is_power_of_2(mddev->new_chunk_sectors)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7024 | pr_warn("md/raid:%s: invalid chunk size %d\n", |
| 7025 | mdname(mddev), mddev->new_chunk_sectors << 9); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7026 | return ERR_PTR(-EINVAL); |
NeilBrown | 4bbf377 | 2008-10-13 11:55:12 +1100 | [diff] [blame] | 7027 | } |
| 7028 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7029 | conf = kzalloc(sizeof(struct r5conf), GFP_KERNEL); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7030 | if (conf == NULL) |
| 7031 | goto abort; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 7032 | |
Yufen Yu | e236858 | 2020-07-18 05:29:08 -0400 | [diff] [blame] | 7033 | #if PAGE_SIZE != DEFAULT_STRIPE_SIZE |
| 7034 | conf->stripe_size = DEFAULT_STRIPE_SIZE; |
| 7035 | conf->stripe_shift = ilog2(DEFAULT_STRIPE_SIZE) - 9; |
| 7036 | conf->stripe_sectors = DEFAULT_STRIPE_SIZE >> 9; |
| 7037 | #endif |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 7038 | INIT_LIST_HEAD(&conf->free_list); |
| 7039 | INIT_LIST_HEAD(&conf->pending_list); |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7040 | conf->pending_data = kcalloc(PENDING_IO_MAX, |
| 7041 | sizeof(struct r5pending_data), |
| 7042 | GFP_KERNEL); |
Shaohua Li | aaf9f12 | 2017-03-03 22:06:12 -0800 | [diff] [blame] | 7043 | if (!conf->pending_data) |
| 7044 | goto abort; |
| 7045 | for (i = 0; i < PENDING_IO_MAX; i++) |
| 7046 | list_add(&conf->pending_data[i].sibling, &conf->free_list); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 7047 | /* Don't enable multi-threading by default*/ |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 7048 | if (!alloc_thread_groups(conf, 0, &group_cnt, &new_group)) { |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 7049 | conf->group_cnt = group_cnt; |
Guoqing Jiang | d2c9ad4 | 2019-12-20 15:46:29 +0100 | [diff] [blame] | 7050 | conf->worker_cnt_per_group = 0; |
majianpeng | 60aaf93 | 2013-11-14 15:16:20 +1100 | [diff] [blame] | 7051 | conf->worker_groups = new_group; |
| 7052 | } else |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 7053 | goto abort; |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 7054 | spin_lock_init(&conf->device_lock); |
Ahmed S. Darwish | 0a87b25 | 2020-07-20 17:55:25 +0200 | [diff] [blame] | 7055 | seqcount_spinlock_init(&conf->gen_lock, &conf->device_lock); |
NeilBrown | 2d5b569 | 2015-07-06 12:49:23 +1000 | [diff] [blame] | 7056 | mutex_init(&conf->cache_size_mutex); |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 7057 | init_waitqueue_head(&conf->wait_for_quiescent); |
Shaohua Li | 6ab2a4b | 2016-02-25 16:24:42 -0800 | [diff] [blame] | 7058 | init_waitqueue_head(&conf->wait_for_stripe); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 7059 | init_waitqueue_head(&conf->wait_for_overlap); |
| 7060 | INIT_LIST_HEAD(&conf->handle_list); |
Shaohua Li | 535ae4e | 2017-02-15 19:37:32 -0800 | [diff] [blame] | 7061 | INIT_LIST_HEAD(&conf->loprio_list); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 7062 | INIT_LIST_HEAD(&conf->hold_list); |
| 7063 | INIT_LIST_HEAD(&conf->delayed_list); |
| 7064 | INIT_LIST_HEAD(&conf->bitmap_list); |
Shaohua Li | 773ca82 | 2013-08-27 17:50:39 +0800 | [diff] [blame] | 7065 | init_llist_head(&conf->released_stripes); |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 7066 | atomic_set(&conf->active_stripes, 0); |
| 7067 | atomic_set(&conf->preread_active_stripes, 0); |
| 7068 | atomic_set(&conf->active_aligned_reads, 0); |
Shaohua Li | 765d704 | 2017-01-04 09:33:23 -0800 | [diff] [blame] | 7069 | spin_lock_init(&conf->pending_bios_lock); |
| 7070 | conf->batch_bio_dispatch = true; |
| 7071 | rdev_for_each(rdev, mddev) { |
| 7072 | if (test_bit(Journal, &rdev->flags)) |
| 7073 | continue; |
| 7074 | if (blk_queue_nonrot(bdev_get_queue(rdev->bdev))) { |
| 7075 | conf->batch_bio_dispatch = false; |
| 7076 | break; |
| 7077 | } |
| 7078 | } |
| 7079 | |
Dan Williams | f5efd45 | 2009-10-16 15:55:38 +1100 | [diff] [blame] | 7080 | conf->bypass_threshold = BYPASS_THRESHOLD; |
NeilBrown | d890fa2 | 2011-10-26 11:54:39 +1100 | [diff] [blame] | 7081 | conf->recovery_disabled = mddev->recovery_disabled - 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7082 | |
| 7083 | conf->raid_disks = mddev->raid_disks; |
| 7084 | if (mddev->reshape_position == MaxSector) |
| 7085 | conf->previous_raid_disks = mddev->raid_disks; |
| 7086 | else |
| 7087 | conf->previous_raid_disks = mddev->raid_disks - mddev->delta_disks; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 7088 | max_disks = max(conf->raid_disks, conf->previous_raid_disks); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7089 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7090 | conf->disks = kcalloc(max_disks, sizeof(struct disk_info), |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7091 | GFP_KERNEL); |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 7092 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7093 | if (!conf->disks) |
| 7094 | goto abort; |
| 7095 | |
Song Liu | d7bd398 | 2016-11-23 22:50:39 -0800 | [diff] [blame] | 7096 | for (i = 0; i < max_disks; i++) { |
| 7097 | conf->disks[i].extra_page = alloc_page(GFP_KERNEL); |
| 7098 | if (!conf->disks[i].extra_page) |
| 7099 | goto abort; |
| 7100 | } |
| 7101 | |
Kent Overstreet | afeee51 | 2018-05-20 18:25:52 -0400 | [diff] [blame] | 7102 | ret = bioset_init(&conf->bio_split, BIO_POOL_SIZE, 0, 0); |
| 7103 | if (ret) |
NeilBrown | dd7a8f5 | 2017-04-05 14:05:51 +1000 | [diff] [blame] | 7104 | goto abort; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7105 | conf->mddev = mddev; |
| 7106 | |
| 7107 | if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL) |
| 7108 | goto abort; |
| 7109 | |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 7110 | /* We init hash_locks[0] separately to that it can be used |
| 7111 | * as the reference lock in the spin_lock_nest_lock() call |
| 7112 | * in lock_all_device_hash_locks_irq in order to convince |
| 7113 | * lockdep that we know what we are doing. |
| 7114 | */ |
| 7115 | spin_lock_init(conf->hash_locks); |
| 7116 | for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++) |
| 7117 | spin_lock_init(conf->hash_locks + i); |
| 7118 | |
| 7119 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 7120 | INIT_LIST_HEAD(conf->inactive_list + i); |
| 7121 | |
| 7122 | for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++) |
| 7123 | INIT_LIST_HEAD(conf->temp_inactive_list + i); |
| 7124 | |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 7125 | atomic_set(&conf->r5c_cached_full_stripes, 0); |
| 7126 | INIT_LIST_HEAD(&conf->r5c_full_stripe_list); |
| 7127 | atomic_set(&conf->r5c_cached_partial_stripes, 0); |
| 7128 | INIT_LIST_HEAD(&conf->r5c_partial_stripe_list); |
Shaohua Li | e33fbb9 | 2017-02-10 16:18:09 -0800 | [diff] [blame] | 7129 | atomic_set(&conf->r5c_flushing_full_stripes, 0); |
| 7130 | atomic_set(&conf->r5c_flushing_partial_stripes, 0); |
Song Liu | 1e6d690 | 2016-11-17 15:24:39 -0800 | [diff] [blame] | 7131 | |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 7132 | conf->level = mddev->new_level; |
shli@kernel.org | 46d5b78 | 2014-12-15 12:57:02 +1100 | [diff] [blame] | 7133 | conf->chunk_sectors = mddev->new_chunk_sectors; |
Dan Williams | 36d1c64 | 2009-07-14 11:48:22 -0700 | [diff] [blame] | 7134 | if (raid5_alloc_percpu(conf) != 0) |
| 7135 | goto abort; |
| 7136 | |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 7137 | pr_debug("raid456: run(%s) called.\n", mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7138 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 7139 | rdev_for_each(rdev, mddev) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7140 | raid_disk = rdev->raid_disk; |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 7141 | if (raid_disk >= max_disks |
Shaohua Li | f2076e7 | 2015-10-08 21:54:12 -0700 | [diff] [blame] | 7142 | || raid_disk < 0 || test_bit(Journal, &rdev->flags)) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7143 | continue; |
| 7144 | disk = conf->disks + raid_disk; |
| 7145 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7146 | if (test_bit(Replacement, &rdev->flags)) { |
| 7147 | if (disk->replacement) |
| 7148 | goto abort; |
| 7149 | disk->replacement = rdev; |
| 7150 | } else { |
| 7151 | if (disk->rdev) |
| 7152 | goto abort; |
| 7153 | disk->rdev = rdev; |
| 7154 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7155 | |
| 7156 | if (test_bit(In_sync, &rdev->flags)) { |
| 7157 | char b[BDEVNAME_SIZE]; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7158 | pr_info("md/raid:%s: device %s operational as raid disk %d\n", |
| 7159 | mdname(mddev), bdevname(rdev->bdev, b), raid_disk); |
Jonathan Brassow | d6b212f | 2011-06-08 18:00:28 -0500 | [diff] [blame] | 7160 | } else if (rdev->saved_raid_disk != raid_disk) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7161 | /* Cannot rely on bitmap to complete recovery */ |
| 7162 | conf->fullsync = 1; |
| 7163 | } |
| 7164 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7165 | conf->level = mddev->new_level; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 7166 | if (conf->level == 6) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7167 | conf->max_degraded = 2; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 7168 | if (raid6_call.xor_syndrome) |
| 7169 | conf->rmw_level = PARITY_ENABLE_RMW; |
| 7170 | else |
| 7171 | conf->rmw_level = PARITY_DISABLE_RMW; |
| 7172 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7173 | conf->max_degraded = 1; |
Markus Stockhausen | 584acdd | 2014-12-15 12:57:05 +1100 | [diff] [blame] | 7174 | conf->rmw_level = PARITY_ENABLE_RMW; |
| 7175 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7176 | conf->algorithm = mddev->new_layout; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7177 | conf->reshape_progress = mddev->reshape_position; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 7178 | if (conf->reshape_progress != MaxSector) { |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 7179 | conf->prev_chunk_sectors = mddev->chunk_sectors; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 7180 | conf->prev_algo = mddev->layout; |
NeilBrown | 5cac6bc | 2015-07-17 12:17:50 +1000 | [diff] [blame] | 7181 | } else { |
| 7182 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 7183 | conf->prev_algo = conf->algorithm; |
NeilBrown | e183eae | 2009-03-31 15:20:22 +1100 | [diff] [blame] | 7184 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7185 | |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7186 | conf->min_nr_stripes = NR_STRIPES; |
Shaohua Li | ad5b0f7 | 2016-08-30 10:29:33 -0700 | [diff] [blame] | 7187 | if (mddev->reshape_position != MaxSector) { |
| 7188 | int stripes = max_t(int, |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 7189 | ((mddev->chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4, |
| 7190 | ((mddev->new_chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4); |
Shaohua Li | ad5b0f7 | 2016-08-30 10:29:33 -0700 | [diff] [blame] | 7191 | conf->min_nr_stripes = max(NR_STRIPES, stripes); |
| 7192 | if (conf->min_nr_stripes != NR_STRIPES) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7193 | pr_info("md/raid:%s: force stripe size %d for reshape\n", |
Shaohua Li | ad5b0f7 | 2016-08-30 10:29:33 -0700 | [diff] [blame] | 7194 | mdname(mddev), conf->min_nr_stripes); |
| 7195 | } |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7196 | memory = conf->min_nr_stripes * (sizeof(struct stripe_head) + |
NeilBrown | 5e5e3e7 | 2009-10-16 16:35:30 +1100 | [diff] [blame] | 7197 | max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024; |
Shaohua Li | 4bda556 | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 7198 | atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7199 | if (grow_stripes(conf, conf->min_nr_stripes)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7200 | pr_warn("md/raid:%s: couldn't allocate %dkB for buffers\n", |
| 7201 | mdname(mddev), memory); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7202 | goto abort; |
| 7203 | } else |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7204 | pr_debug("md/raid:%s: allocated %dkB\n", mdname(mddev), memory); |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7205 | /* |
| 7206 | * Losing a stripe head costs more than the time to refill it, |
| 7207 | * it reduces the queue depth and so can hurt throughput. |
| 7208 | * So set it rather large, scaled by number of devices. |
| 7209 | */ |
| 7210 | conf->shrinker.seeks = DEFAULT_SEEKS * conf->raid_disks * 4; |
| 7211 | conf->shrinker.scan_objects = raid5_cache_scan; |
| 7212 | conf->shrinker.count_objects = raid5_cache_count; |
| 7213 | conf->shrinker.batch = 128; |
| 7214 | conf->shrinker.flags = 0; |
Chao Yu | 6a0f53f | 2016-09-20 10:33:57 +0800 | [diff] [blame] | 7215 | if (register_shrinker(&conf->shrinker)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7216 | pr_warn("md/raid:%s: couldn't register shrinker.\n", |
| 7217 | mdname(mddev)); |
Chao Yu | 6a0f53f | 2016-09-20 10:33:57 +0800 | [diff] [blame] | 7218 | goto abort; |
| 7219 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7220 | |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 7221 | sprintf(pers_name, "raid%d", mddev->new_level); |
| 7222 | conf->thread = md_register_thread(raid5d, mddev, pers_name); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7223 | if (!conf->thread) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7224 | pr_warn("md/raid:%s: couldn't allocate thread.\n", |
| 7225 | mdname(mddev)); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7226 | goto abort; |
| 7227 | } |
| 7228 | |
| 7229 | return conf; |
| 7230 | |
| 7231 | abort: |
| 7232 | if (conf) { |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 7233 | free_conf(conf); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7234 | return ERR_PTR(-EIO); |
| 7235 | } else |
| 7236 | return ERR_PTR(-ENOMEM); |
| 7237 | } |
| 7238 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7239 | static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded) |
| 7240 | { |
| 7241 | switch (algo) { |
| 7242 | case ALGORITHM_PARITY_0: |
| 7243 | if (raid_disk < max_degraded) |
| 7244 | return 1; |
| 7245 | break; |
| 7246 | case ALGORITHM_PARITY_N: |
| 7247 | if (raid_disk >= raid_disks - max_degraded) |
| 7248 | return 1; |
| 7249 | break; |
| 7250 | case ALGORITHM_PARITY_0_6: |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 7251 | if (raid_disk == 0 || |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7252 | raid_disk == raid_disks - 1) |
| 7253 | return 1; |
| 7254 | break; |
| 7255 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 7256 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 7257 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 7258 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 7259 | if (raid_disk == raid_disks - 1) |
| 7260 | return 1; |
| 7261 | } |
| 7262 | return 0; |
| 7263 | } |
| 7264 | |
Christoph Hellwig | 16ef510 | 2020-09-24 08:51:33 +0200 | [diff] [blame] | 7265 | static void raid5_set_io_opt(struct r5conf *conf) |
| 7266 | { |
| 7267 | blk_queue_io_opt(conf->mddev->queue, (conf->chunk_sectors << 9) * |
| 7268 | (conf->raid_disks - conf->max_degraded)); |
| 7269 | } |
| 7270 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 7271 | static int raid5_run(struct mddev *mddev) |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7272 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7273 | struct r5conf *conf; |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7274 | int working_disks = 0; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7275 | int dirty_parity_disks = 0; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 7276 | struct md_rdev *rdev; |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7277 | struct md_rdev *journal_dev = NULL; |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7278 | sector_t reshape_offset = 0; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7279 | int i; |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7280 | long long min_offset_diff = 0; |
| 7281 | int first = 1; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7282 | |
NeilBrown | a415c0f | 2017-06-05 16:05:13 +1000 | [diff] [blame] | 7283 | if (mddev_init_writes_pending(mddev) < 0) |
| 7284 | return -ENOMEM; |
| 7285 | |
Andre Noll | 8c6ac868 | 2009-06-18 08:48:06 +1000 | [diff] [blame] | 7286 | if (mddev->recovery_cp != MaxSector) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7287 | pr_notice("md/raid:%s: not clean -- starting background reconstruction\n", |
| 7288 | mdname(mddev)); |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7289 | |
| 7290 | rdev_for_each(rdev, mddev) { |
| 7291 | long long diff; |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7292 | |
Shaohua Li | f2076e7 | 2015-10-08 21:54:12 -0700 | [diff] [blame] | 7293 | if (test_bit(Journal, &rdev->flags)) { |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7294 | journal_dev = rdev; |
Shaohua Li | f2076e7 | 2015-10-08 21:54:12 -0700 | [diff] [blame] | 7295 | continue; |
| 7296 | } |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7297 | if (rdev->raid_disk < 0) |
| 7298 | continue; |
| 7299 | diff = (rdev->new_data_offset - rdev->data_offset); |
| 7300 | if (first) { |
| 7301 | min_offset_diff = diff; |
| 7302 | first = 0; |
| 7303 | } else if (mddev->reshape_backwards && |
| 7304 | diff < min_offset_diff) |
| 7305 | min_offset_diff = diff; |
| 7306 | else if (!mddev->reshape_backwards && |
| 7307 | diff > min_offset_diff) |
| 7308 | min_offset_diff = diff; |
| 7309 | } |
| 7310 | |
NeilBrown | 230b55f | 2017-10-17 14:24:09 +1100 | [diff] [blame] | 7311 | if ((test_bit(MD_HAS_JOURNAL, &mddev->flags) || journal_dev) && |
| 7312 | (mddev->bitmap_info.offset || mddev->bitmap_info.file)) { |
| 7313 | pr_notice("md/raid:%s: array cannot have both journal and bitmap\n", |
| 7314 | mdname(mddev)); |
| 7315 | return -EINVAL; |
| 7316 | } |
| 7317 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7318 | if (mddev->reshape_position != MaxSector) { |
| 7319 | /* Check that we can continue the reshape. |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7320 | * Difficulties arise if the stripe we would write to |
| 7321 | * next is at or after the stripe we would read from next. |
| 7322 | * For a reshape that changes the number of devices, this |
| 7323 | * is only possible for a very short time, and mdadm makes |
| 7324 | * sure that time appears to have past before assembling |
| 7325 | * the array. So we fail if that time hasn't passed. |
| 7326 | * For a reshape that keeps the number of devices the same |
| 7327 | * mdadm must be monitoring the reshape can keeping the |
| 7328 | * critical areas read-only and backed up. It will start |
| 7329 | * the array in read-only mode, so we check for that. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7330 | */ |
| 7331 | sector_t here_new, here_old; |
| 7332 | int old_disks; |
Andre Noll | 18b0033 | 2009-03-31 15:00:56 +1100 | [diff] [blame] | 7333 | int max_degraded = (mddev->level == 6 ? 2 : 1); |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7334 | int chunk_sectors; |
| 7335 | int new_data_disks; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7336 | |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7337 | if (journal_dev) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7338 | pr_warn("md/raid:%s: don't support reshape with journal - aborting.\n", |
| 7339 | mdname(mddev)); |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7340 | return -EINVAL; |
| 7341 | } |
| 7342 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 7343 | if (mddev->new_level != mddev->level) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7344 | pr_warn("md/raid:%s: unsupported reshape required - aborting.\n", |
| 7345 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7346 | return -EINVAL; |
| 7347 | } |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7348 | old_disks = mddev->raid_disks - mddev->delta_disks; |
| 7349 | /* reshape_position must be on a new-stripe boundary, and one |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7350 | * further up in new geometry must map after here in old |
| 7351 | * geometry. |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7352 | * If the chunk sizes are different, then as we perform reshape |
| 7353 | * in units of the largest of the two, reshape_position needs |
| 7354 | * be a multiple of the largest chunk size times new data disks. |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7355 | */ |
| 7356 | here_new = mddev->reshape_position; |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7357 | chunk_sectors = max(mddev->chunk_sectors, mddev->new_chunk_sectors); |
| 7358 | new_data_disks = mddev->raid_disks - max_degraded; |
| 7359 | if (sector_div(here_new, chunk_sectors * new_data_disks)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7360 | pr_warn("md/raid:%s: reshape_position not on a stripe boundary\n", |
| 7361 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7362 | return -EINVAL; |
| 7363 | } |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7364 | reshape_offset = here_new * chunk_sectors; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7365 | /* here_new is the stripe we will write to */ |
| 7366 | here_old = mddev->reshape_position; |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7367 | sector_div(here_old, chunk_sectors * (old_disks-max_degraded)); |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7368 | /* here_old is the first stripe that we might need to read |
| 7369 | * from */ |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 7370 | if (mddev->delta_disks == 0) { |
| 7371 | /* We cannot be sure it is safe to start an in-place |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7372 | * reshape. It is only safe if user-space is monitoring |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 7373 | * and taking constant backups. |
| 7374 | * mdadm always starts a situation like this in |
| 7375 | * readonly mode so it can take control before |
| 7376 | * allowing any writes. So just check for that. |
| 7377 | */ |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7378 | if (abs(min_offset_diff) >= mddev->chunk_sectors && |
| 7379 | abs(min_offset_diff) >= mddev->new_chunk_sectors) |
| 7380 | /* not really in-place - so OK */; |
| 7381 | else if (mddev->ro == 0) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7382 | pr_warn("md/raid:%s: in-place reshape must be started in read-only mode - aborting\n", |
| 7383 | mdname(mddev)); |
NeilBrown | 67ac601 | 2009-08-13 10:06:24 +1000 | [diff] [blame] | 7384 | return -EINVAL; |
| 7385 | } |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7386 | } else if (mddev->reshape_backwards |
NeilBrown | 05256d9 | 2015-07-15 17:36:21 +1000 | [diff] [blame] | 7387 | ? (here_new * chunk_sectors + min_offset_diff <= |
| 7388 | here_old * chunk_sectors) |
| 7389 | : (here_new * chunk_sectors >= |
| 7390 | here_old * chunk_sectors + (-min_offset_diff))) { |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7391 | /* Reading from the same stripe as writing to - bad */ |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7392 | pr_warn("md/raid:%s: reshape_position too early for auto-recovery - aborting.\n", |
| 7393 | mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7394 | return -EINVAL; |
| 7395 | } |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7396 | pr_debug("md/raid:%s: reshape will continue\n", mdname(mddev)); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7397 | /* OK, we should be able to continue; */ |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7398 | } else { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7399 | BUG_ON(mddev->level != mddev->new_level); |
| 7400 | BUG_ON(mddev->layout != mddev->new_layout); |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 7401 | BUG_ON(mddev->chunk_sectors != mddev->new_chunk_sectors); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7402 | BUG_ON(mddev->delta_disks != 0); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7403 | } |
| 7404 | |
Artur Paszkiewicz | 3418d03 | 2017-03-09 09:59:59 +0100 | [diff] [blame] | 7405 | if (test_bit(MD_HAS_JOURNAL, &mddev->flags) && |
| 7406 | test_bit(MD_HAS_PPL, &mddev->flags)) { |
| 7407 | pr_warn("md/raid:%s: using journal device and PPL not allowed - disabling PPL\n", |
| 7408 | mdname(mddev)); |
| 7409 | clear_bit(MD_HAS_PPL, &mddev->flags); |
Pawel Baldysiak | ddc0882 | 2017-08-16 17:13:45 +0200 | [diff] [blame] | 7410 | clear_bit(MD_HAS_MULTIPLE_PPLS, &mddev->flags); |
Artur Paszkiewicz | 3418d03 | 2017-03-09 09:59:59 +0100 | [diff] [blame] | 7411 | } |
| 7412 | |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7413 | if (mddev->private == NULL) |
| 7414 | conf = setup_conf(mddev); |
| 7415 | else |
| 7416 | conf = mddev->private; |
| 7417 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7418 | if (IS_ERR(conf)) |
| 7419 | return PTR_ERR(conf); |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 7420 | |
Song Liu | 486b0f7 | 2016-08-19 15:34:01 -0700 | [diff] [blame] | 7421 | if (test_bit(MD_HAS_JOURNAL, &mddev->flags)) { |
| 7422 | if (!journal_dev) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7423 | pr_warn("md/raid:%s: journal disk is missing, force array readonly\n", |
| 7424 | mdname(mddev)); |
Song Liu | 486b0f7 | 2016-08-19 15:34:01 -0700 | [diff] [blame] | 7425 | mddev->ro = 1; |
| 7426 | set_disk_ro(mddev->gendisk, 1); |
| 7427 | } else if (mddev->recovery_cp == MaxSector) |
| 7428 | set_bit(MD_JOURNAL_CLEAN, &mddev->flags); |
Shaohua Li | 7dde2ad | 2015-10-08 21:54:10 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
NeilBrown | b5254dd | 2012-05-21 09:27:01 +1000 | [diff] [blame] | 7431 | conf->min_offset_diff = min_offset_diff; |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7432 | mddev->thread = conf->thread; |
| 7433 | conf->thread = NULL; |
| 7434 | mddev->private = conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7435 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7436 | for (i = 0; i < conf->raid_disks && conf->previous_raid_disks; |
| 7437 | i++) { |
| 7438 | rdev = conf->disks[i].rdev; |
| 7439 | if (!rdev && conf->disks[i].replacement) { |
| 7440 | /* The replacement is all we have yet */ |
| 7441 | rdev = conf->disks[i].replacement; |
| 7442 | conf->disks[i].replacement = NULL; |
| 7443 | clear_bit(Replacement, &rdev->flags); |
| 7444 | conf->disks[i].rdev = rdev; |
| 7445 | } |
| 7446 | if (!rdev) |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7447 | continue; |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7448 | if (conf->disks[i].replacement && |
| 7449 | conf->reshape_progress != MaxSector) { |
| 7450 | /* replacements and reshape simply do not mix. */ |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7451 | pr_warn("md: cannot handle concurrent replacement and reshape.\n"); |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7452 | goto abort; |
| 7453 | } |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 7454 | if (test_bit(In_sync, &rdev->flags)) { |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7455 | working_disks++; |
NeilBrown | 2f11588 | 2010-06-17 17:41:03 +1000 | [diff] [blame] | 7456 | continue; |
| 7457 | } |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7458 | /* This disc is not fully in-sync. However if it |
| 7459 | * just stored parity (beyond the recovery_offset), |
| 7460 | * when we don't need to be concerned about the |
| 7461 | * array being dirty. |
| 7462 | * When reshape goes 'backwards', we never have |
| 7463 | * partially completed devices, so we only need |
| 7464 | * to worry about reshape going forwards. |
| 7465 | */ |
| 7466 | /* Hack because v0.91 doesn't store recovery_offset properly. */ |
| 7467 | if (mddev->major_version == 0 && |
| 7468 | mddev->minor_version > 90) |
| 7469 | rdev->recovery_offset = reshape_offset; |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 7470 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7471 | if (rdev->recovery_offset < reshape_offset) { |
| 7472 | /* We need to check old and new layout */ |
| 7473 | if (!only_parity(rdev->raid_disk, |
| 7474 | conf->algorithm, |
| 7475 | conf->raid_disks, |
| 7476 | conf->max_degraded)) |
| 7477 | continue; |
| 7478 | } |
| 7479 | if (!only_parity(rdev->raid_disk, |
| 7480 | conf->prev_algo, |
| 7481 | conf->previous_raid_disks, |
| 7482 | conf->max_degraded)) |
| 7483 | continue; |
| 7484 | dirty_parity_disks++; |
| 7485 | } |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7486 | |
NeilBrown | 17045f5 | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7487 | /* |
| 7488 | * 0 for a fully functional array, 1 or 2 for a degraded array. |
| 7489 | */ |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 7490 | mddev->degraded = raid5_calc_degraded(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7491 | |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 7492 | if (has_failed(conf)) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7493 | pr_crit("md/raid:%s: not enough operational devices (%d/%d failed)\n", |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 7494 | mdname(mddev), mddev->degraded, conf->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7495 | goto abort; |
| 7496 | } |
| 7497 | |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7498 | /* device size must be a multiple of chunk size */ |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 7499 | mddev->dev_sectors &= ~(mddev->chunk_sectors - 1); |
NeilBrown | 91adb56 | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 7500 | mddev->resync_max_sectors = mddev->dev_sectors; |
| 7501 | |
NeilBrown | c148ffd | 2009-11-13 17:47:00 +1100 | [diff] [blame] | 7502 | if (mddev->degraded > dirty_parity_disks && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7503 | mddev->recovery_cp != MaxSector) { |
Artur Paszkiewicz | 4536bf9b | 2017-03-09 10:00:01 +0100 | [diff] [blame] | 7504 | if (test_bit(MD_HAS_PPL, &mddev->flags)) |
| 7505 | pr_crit("md/raid:%s: starting dirty degraded array with PPL.\n", |
| 7506 | mdname(mddev)); |
| 7507 | else if (mddev->ok_start_degraded) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7508 | pr_crit("md/raid:%s: starting dirty degraded array - data corruption possible.\n", |
| 7509 | mdname(mddev)); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7510 | else { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7511 | pr_crit("md/raid:%s: cannot start dirty degraded array.\n", |
| 7512 | mdname(mddev)); |
NeilBrown | 6ff8d8ec | 2006-01-06 00:20:15 -0800 | [diff] [blame] | 7513 | goto abort; |
| 7514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7515 | } |
| 7516 | |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7517 | pr_info("md/raid:%s: raid level %d active with %d out of %d devices, algorithm %d\n", |
| 7518 | mdname(mddev), conf->level, |
| 7519 | mddev->raid_disks-mddev->degraded, mddev->raid_disks, |
| 7520 | mddev->new_layout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7521 | |
| 7522 | print_raid5_conf(conf); |
| 7523 | |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7524 | if (conf->reshape_progress != MaxSector) { |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 7525 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7526 | atomic_set(&conf->reshape_stripes, 0); |
| 7527 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 7528 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 7529 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 7530 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 7531 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 7532 | "reshape"); |
Aditya Pakki | e406f12 | 2019-03-04 16:48:54 -0600 | [diff] [blame] | 7533 | if (!mddev->sync_thread) |
| 7534 | goto abort; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 7535 | } |
| 7536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7537 | /* Ok, everything is just fine now */ |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 7538 | if (mddev->to_remove == &raid5_attrs_group) |
| 7539 | mddev->to_remove = NULL; |
NeilBrown | 00bcb4a | 2010-06-01 19:37:23 +1000 | [diff] [blame] | 7540 | else if (mddev->kobj.sd && |
| 7541 | sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7542 | pr_warn("raid5: failed to create sysfs attributes for %s\n", |
| 7543 | mdname(mddev)); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7544 | md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); |
| 7545 | |
| 7546 | if (mddev->queue) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7547 | int chunk_size; |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7548 | /* read-ahead size must cover two whole stripes, which |
| 7549 | * is 2 * (datadisks) * chunksize where 'n' is the |
| 7550 | * number of raid devices |
| 7551 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7552 | int data_disks = conf->previous_raid_disks - conf->max_degraded; |
| 7553 | int stripe = data_disks * |
| 7554 | ((mddev->chunk_sectors << 9) / PAGE_SIZE); |
NeilBrown | 4a5add4 | 2010-06-01 19:37:28 +1000 | [diff] [blame] | 7555 | |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7556 | chunk_size = mddev->chunk_sectors << 9; |
| 7557 | blk_queue_io_min(mddev->queue, chunk_size); |
Christoph Hellwig | 16ef510 | 2020-09-24 08:51:33 +0200 | [diff] [blame] | 7558 | raid5_set_io_opt(conf); |
Kent Overstreet | c78afc6 | 2013-07-11 22:39:53 -0700 | [diff] [blame] | 7559 | mddev->queue->limits.raid_partial_stripes_expensive = 1; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7560 | /* |
| 7561 | * We can only discard a whole stripe. It doesn't make sense to |
| 7562 | * discard data disk but write parity disk |
| 7563 | */ |
| 7564 | stripe = stripe * PAGE_SIZE; |
NeilBrown | 4ac6875 | 2012-11-19 13:11:26 +1100 | [diff] [blame] | 7565 | /* Round up to power of 2, as discard handling |
| 7566 | * currently assumes that */ |
| 7567 | while ((stripe-1) & stripe) |
| 7568 | stripe = (stripe | (stripe-1)) + 1; |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7569 | mddev->queue->limits.discard_alignment = stripe; |
| 7570 | mddev->queue->limits.discard_granularity = stripe; |
Konstantin Khlebnikov | e8d7c33 | 2016-11-27 19:32:32 +0300 | [diff] [blame] | 7571 | |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 7572 | blk_queue_max_write_same_sectors(mddev->queue, 0); |
Christoph Hellwig | 3deff1a | 2017-04-05 19:21:03 +0200 | [diff] [blame] | 7573 | blk_queue_max_write_zeroes_sectors(mddev->queue, 0); |
H. Peter Anvin | 5026d7a | 2013-06-12 07:37:43 -0700 | [diff] [blame] | 7574 | |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7575 | rdev_for_each(rdev, mddev) { |
NeilBrown | 9f7c222 | 2010-07-26 12:04:13 +1000 | [diff] [blame] | 7576 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 7577 | rdev->data_offset << 9); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7578 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 7579 | rdev->new_data_offset << 9); |
| 7580 | } |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7581 | |
Christoph Hellwig | 48920ff | 2017-04-05 19:21:23 +0200 | [diff] [blame] | 7582 | /* |
| 7583 | * zeroing is required, otherwise data |
| 7584 | * could be lost. Consider a scenario: discard a stripe |
| 7585 | * (the stripe could be inconsistent if |
| 7586 | * discard_zeroes_data is 0); write one disk of the |
| 7587 | * stripe (the stripe could be inconsistent again |
| 7588 | * depending on which disks are used to calculate |
| 7589 | * parity); the disk is broken; The stripe data of this |
| 7590 | * disk is lost. |
| 7591 | * |
| 7592 | * We only allow DISCARD if the sysadmin has confirmed that |
| 7593 | * only safe devices are in use by setting a module parameter. |
| 7594 | * A better idea might be to turn DISCARD into WRITE_ZEROES |
| 7595 | * requests, as that is required to be safe. |
| 7596 | */ |
| 7597 | if (devices_handle_discard_safely && |
Jes Sorensen | e7597e6 | 2016-02-16 16:44:24 -0500 | [diff] [blame] | 7598 | mddev->queue->limits.max_discard_sectors >= (stripe >> 9) && |
| 7599 | mddev->queue->limits.discard_granularity >= stripe) |
Bart Van Assche | 8b904b5 | 2018-03-07 17:10:10 -0800 | [diff] [blame] | 7600 | blk_queue_flag_set(QUEUE_FLAG_DISCARD, |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7601 | mddev->queue); |
| 7602 | else |
Bart Van Assche | 8b904b5 | 2018-03-07 17:10:10 -0800 | [diff] [blame] | 7603 | blk_queue_flag_clear(QUEUE_FLAG_DISCARD, |
Shaohua Li | 620125f | 2012-10-11 13:49:05 +1100 | [diff] [blame] | 7604 | mddev->queue); |
Shaohua Li | 1dffddd | 2016-09-08 10:49:06 -0700 | [diff] [blame] | 7605 | |
| 7606 | blk_queue_max_hw_sectors(mddev->queue, UINT_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7607 | } |
| 7608 | |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 7609 | if (log_init(conf, journal_dev, raid5_has_ppl(conf))) |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 7610 | goto abort; |
Shaohua Li | 5c7e81c | 2015-08-13 14:32:04 -0700 | [diff] [blame] | 7611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7612 | return 0; |
| 7613 | abort: |
NeilBrown | 01f96c0 | 2011-09-21 15:30:20 +1000 | [diff] [blame] | 7614 | md_unregister_thread(&mddev->thread); |
NeilBrown | e4f869d | 2011-10-07 14:22:49 +1100 | [diff] [blame] | 7615 | print_raid5_conf(conf); |
| 7616 | free_conf(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7617 | mddev->private = NULL; |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7618 | 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] | 7619 | return -EIO; |
| 7620 | } |
| 7621 | |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 7622 | static void raid5_free(struct mddev *mddev, void *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7623 | { |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 7624 | struct r5conf *conf = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7625 | |
Dan Williams | 95fc17a | 2009-07-31 12:39:15 +1000 | [diff] [blame] | 7626 | free_conf(conf); |
NeilBrown | a64c876 | 2010-04-14 17:15:37 +1000 | [diff] [blame] | 7627 | mddev->to_remove = &raid5_attrs_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7628 | } |
| 7629 | |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 7630 | static void raid5_status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7631 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7632 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7633 | int i; |
| 7634 | |
Andre Noll | 9d8f036 | 2009-06-18 08:45:01 +1000 | [diff] [blame] | 7635 | seq_printf(seq, " level %d, %dk chunk, algorithm %d", mddev->level, |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 7636 | conf->chunk_sectors / 2, mddev->layout); |
NeilBrown | 02c2de8 | 2006-10-03 01:15:47 -0700 | [diff] [blame] | 7637 | seq_printf (seq, " [%d/%d] [", conf->raid_disks, conf->raid_disks - mddev->degraded); |
NeilBrown | 5fd1335 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 7638 | rcu_read_lock(); |
| 7639 | for (i = 0; i < conf->raid_disks; i++) { |
| 7640 | struct md_rdev *rdev = rcu_dereference(conf->disks[i].rdev); |
| 7641 | seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); |
| 7642 | } |
| 7643 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7644 | seq_printf (seq, "]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7645 | } |
| 7646 | |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7647 | static void print_raid5_conf (struct r5conf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7648 | { |
| 7649 | int i; |
| 7650 | struct disk_info *tmp; |
| 7651 | |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7652 | pr_debug("RAID conf printout:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7653 | if (!conf) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7654 | pr_debug("(conf==NULL)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7655 | return; |
| 7656 | } |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7657 | pr_debug(" --- level:%d rd:%d wd:%d\n", conf->level, |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 7658 | conf->raid_disks, |
| 7659 | conf->raid_disks - conf->mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7660 | |
| 7661 | for (i = 0; i < conf->raid_disks; i++) { |
| 7662 | char b[BDEVNAME_SIZE]; |
| 7663 | tmp = conf->disks + i; |
| 7664 | if (tmp->rdev) |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7665 | pr_debug(" disk %d, o:%d, dev:%s\n", |
NeilBrown | 0c55e02 | 2010-05-03 14:09:02 +1000 | [diff] [blame] | 7666 | i, !test_bit(Faulty, &tmp->rdev->flags), |
| 7667 | bdevname(tmp->rdev->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7668 | } |
| 7669 | } |
| 7670 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7671 | static int raid5_spare_active(struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7672 | { |
| 7673 | int i; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7674 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7675 | struct disk_info *tmp; |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7676 | int count = 0; |
| 7677 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7678 | |
| 7679 | for (i = 0; i < conf->raid_disks; i++) { |
| 7680 | tmp = conf->disks + i; |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7681 | if (tmp->replacement |
| 7682 | && tmp->replacement->recovery_offset == MaxSector |
| 7683 | && !test_bit(Faulty, &tmp->replacement->flags) |
| 7684 | && !test_and_set_bit(In_sync, &tmp->replacement->flags)) { |
| 7685 | /* Replacement has just become active. */ |
| 7686 | if (!tmp->rdev |
| 7687 | || !test_and_clear_bit(In_sync, &tmp->rdev->flags)) |
| 7688 | count++; |
| 7689 | if (tmp->rdev) { |
| 7690 | /* Replaced device not technically faulty, |
| 7691 | * but we need to be sure it gets removed |
| 7692 | * and never re-added. |
| 7693 | */ |
| 7694 | set_bit(Faulty, &tmp->rdev->flags); |
| 7695 | sysfs_notify_dirent_safe( |
| 7696 | tmp->rdev->sysfs_state); |
| 7697 | } |
| 7698 | sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); |
| 7699 | } else if (tmp->rdev |
NeilBrown | 70fffd0 | 2010-06-16 17:01:25 +1000 | [diff] [blame] | 7700 | && tmp->rdev->recovery_offset == MaxSector |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7701 | && !test_bit(Faulty, &tmp->rdev->flags) |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 7702 | && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7703 | count++; |
Jonathan Brassow | 43c73ca | 2011-01-14 09:14:33 +1100 | [diff] [blame] | 7704 | sysfs_notify_dirent_safe(tmp->rdev->sysfs_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7705 | } |
| 7706 | } |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7707 | spin_lock_irqsave(&conf->device_lock, flags); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 7708 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7709 | spin_unlock_irqrestore(&conf->device_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7710 | print_raid5_conf(conf); |
NeilBrown | 6b96562 | 2010-08-18 11:56:59 +1000 | [diff] [blame] | 7711 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7712 | } |
| 7713 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 7714 | static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7715 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7716 | struct r5conf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7717 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 7718 | int number = rdev->raid_disk; |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7719 | struct md_rdev **rdevp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7720 | struct disk_info *p = conf->disks + number; |
| 7721 | |
| 7722 | print_raid5_conf(conf); |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7723 | if (test_bit(Journal, &rdev->flags) && conf->log) { |
Shaohua Li | c2bb624 | 2015-10-08 21:54:07 -0700 | [diff] [blame] | 7724 | /* |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7725 | * we can't wait pending write here, as this is called in |
| 7726 | * raid5d, wait will deadlock. |
NeilBrown | 84dd97a | 2017-03-15 14:05:14 +1100 | [diff] [blame] | 7727 | * neilb: there is no locking about new writes here, |
| 7728 | * so this cannot be safe. |
Shaohua Li | c2bb624 | 2015-10-08 21:54:07 -0700 | [diff] [blame] | 7729 | */ |
Song Liu | 70d466f | 2017-05-11 15:28:28 -0700 | [diff] [blame] | 7730 | if (atomic_read(&conf->active_stripes) || |
| 7731 | atomic_read(&conf->r5c_cached_full_stripes) || |
| 7732 | atomic_read(&conf->r5c_cached_partial_stripes)) { |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7733 | return -EBUSY; |
NeilBrown | 84dd97a | 2017-03-15 14:05:14 +1100 | [diff] [blame] | 7734 | } |
Artur Paszkiewicz | ff87573 | 2017-03-09 09:59:58 +0100 | [diff] [blame] | 7735 | log_exit(conf); |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7736 | return 0; |
Shaohua Li | c2bb624 | 2015-10-08 21:54:07 -0700 | [diff] [blame] | 7737 | } |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7738 | if (rdev == p->rdev) |
| 7739 | rdevp = &p->rdev; |
| 7740 | else if (rdev == p->replacement) |
| 7741 | rdevp = &p->replacement; |
| 7742 | else |
| 7743 | return 0; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7744 | |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7745 | if (number >= conf->raid_disks && |
| 7746 | conf->reshape_progress == MaxSector) |
| 7747 | clear_bit(In_sync, &rdev->flags); |
| 7748 | |
| 7749 | if (test_bit(In_sync, &rdev->flags) || |
| 7750 | atomic_read(&rdev->nr_pending)) { |
| 7751 | err = -EBUSY; |
| 7752 | goto abort; |
| 7753 | } |
| 7754 | /* Only remove non-faulty devices if recovery |
| 7755 | * isn't possible. |
| 7756 | */ |
| 7757 | if (!test_bit(Faulty, &rdev->flags) && |
| 7758 | mddev->recovery_disabled != conf->recovery_disabled && |
| 7759 | !has_failed(conf) && |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7760 | (!p->replacement || p->replacement == rdev) && |
NeilBrown | 657e3e4 | 2011-12-23 10:17:52 +1100 | [diff] [blame] | 7761 | number < conf->raid_disks) { |
| 7762 | err = -EBUSY; |
| 7763 | goto abort; |
| 7764 | } |
| 7765 | *rdevp = NULL; |
NeilBrown | d787be4 | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 7766 | if (!test_bit(RemoveSynchronized, &rdev->flags)) { |
| 7767 | synchronize_rcu(); |
| 7768 | if (atomic_read(&rdev->nr_pending)) { |
| 7769 | /* lost the race, try later */ |
| 7770 | err = -EBUSY; |
| 7771 | *rdevp = rdev; |
| 7772 | } |
| 7773 | } |
Artur Paszkiewicz | 6358c23 | 2017-03-09 10:00:02 +0100 | [diff] [blame] | 7774 | if (!err) { |
| 7775 | err = log_modify(conf, rdev, false); |
| 7776 | if (err) |
| 7777 | goto abort; |
| 7778 | } |
NeilBrown | d787be4 | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 7779 | if (p->replacement) { |
NeilBrown | dd054fc | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7780 | /* We must have just cleared 'rdev' */ |
| 7781 | p->rdev = p->replacement; |
| 7782 | clear_bit(Replacement, &p->replacement->flags); |
| 7783 | smp_mb(); /* Make sure other CPUs may see both as identical |
| 7784 | * but will never see neither - if they are careful |
| 7785 | */ |
| 7786 | p->replacement = NULL; |
Artur Paszkiewicz | 6358c23 | 2017-03-09 10:00:02 +0100 | [diff] [blame] | 7787 | |
| 7788 | if (!err) |
| 7789 | err = log_modify(conf, p->rdev, true); |
Guoqing Jiang | e5bc9c3 | 2017-04-24 15:58:04 +0800 | [diff] [blame] | 7790 | } |
| 7791 | |
| 7792 | clear_bit(WantReplacement, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7793 | abort: |
| 7794 | |
| 7795 | print_raid5_conf(conf); |
| 7796 | return err; |
| 7797 | } |
| 7798 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7799 | static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7800 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7801 | struct r5conf *conf = mddev->private; |
Xiao Ni | d9771f5 | 2019-06-14 15:41:05 -0700 | [diff] [blame] | 7802 | int ret, err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7803 | int disk; |
| 7804 | struct disk_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 7805 | int first = 0; |
| 7806 | int last = conf->raid_disks - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7807 | |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7808 | if (test_bit(Journal, &rdev->flags)) { |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7809 | if (conf->log) |
| 7810 | return -EBUSY; |
| 7811 | |
| 7812 | rdev->raid_disk = 0; |
| 7813 | /* |
| 7814 | * The array is in readonly mode if journal is missing, so no |
| 7815 | * write requests running. We should be safe |
| 7816 | */ |
Xiao Ni | d9771f5 | 2019-06-14 15:41:05 -0700 | [diff] [blame] | 7817 | ret = log_init(conf, rdev, false); |
| 7818 | if (ret) |
| 7819 | return ret; |
| 7820 | |
| 7821 | ret = r5l_start(conf->log); |
| 7822 | if (ret) |
| 7823 | return ret; |
| 7824 | |
Shaohua Li | f6b6ec5 | 2015-12-21 10:51:02 +1100 | [diff] [blame] | 7825 | return 0; |
| 7826 | } |
NeilBrown | 7f0da59 | 2011-07-28 11:39:22 +1000 | [diff] [blame] | 7827 | if (mddev->recovery_disabled == conf->recovery_disabled) |
| 7828 | return -EBUSY; |
| 7829 | |
NeilBrown | dc10c64 | 2012-03-19 12:46:37 +1100 | [diff] [blame] | 7830 | if (rdev->saved_raid_disk < 0 && has_failed(conf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7831 | /* no point adding a device */ |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7832 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7833 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 7834 | if (rdev->raid_disk >= 0) |
| 7835 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7836 | |
| 7837 | /* |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7838 | * find the disk ... but prefer rdev->saved_raid_disk |
| 7839 | * if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7840 | */ |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7841 | if (rdev->saved_raid_disk >= 0 && |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 7842 | rdev->saved_raid_disk >= first && |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 7843 | conf->disks[rdev->saved_raid_disk].rdev == NULL) |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7844 | first = rdev->saved_raid_disk; |
| 7845 | |
| 7846 | for (disk = first; disk <= last; disk++) { |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7847 | p = conf->disks + disk; |
| 7848 | if (p->rdev == NULL) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 7849 | clear_bit(In_sync, &rdev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7850 | rdev->raid_disk = disk; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 7851 | if (rdev->saved_raid_disk != disk) |
| 7852 | conf->fullsync = 1; |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 7853 | rcu_assign_pointer(p->rdev, rdev); |
Artur Paszkiewicz | 6358c23 | 2017-03-09 10:00:02 +0100 | [diff] [blame] | 7854 | |
| 7855 | err = log_modify(conf, rdev, true); |
| 7856 | |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7857 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7858 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7859 | } |
| 7860 | for (disk = first; disk <= last; disk++) { |
| 7861 | p = conf->disks + disk; |
NeilBrown | 7bfec5f | 2011-12-23 10:17:53 +1100 | [diff] [blame] | 7862 | if (test_bit(WantReplacement, &p->rdev->flags) && |
| 7863 | p->replacement == NULL) { |
| 7864 | clear_bit(In_sync, &rdev->flags); |
| 7865 | set_bit(Replacement, &rdev->flags); |
| 7866 | rdev->raid_disk = disk; |
| 7867 | err = 0; |
| 7868 | conf->fullsync = 1; |
| 7869 | rcu_assign_pointer(p->replacement, rdev); |
| 7870 | break; |
| 7871 | } |
| 7872 | } |
NeilBrown | 5cfb22a | 2012-07-03 11:46:53 +1000 | [diff] [blame] | 7873 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7874 | print_raid5_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 7875 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7876 | } |
| 7877 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7878 | static int raid5_resize(struct mddev *mddev, sector_t sectors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7879 | { |
| 7880 | /* no resync is happening, and there is enough space |
| 7881 | * on all devices, so we can resize. |
| 7882 | * We need to make sure resync covers any new space. |
| 7883 | * If the array is shrinking we should possibly wait until |
| 7884 | * any io in the removed space completes, but it hardly seems |
| 7885 | * worth it. |
| 7886 | */ |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7887 | sector_t newsize; |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 7888 | struct r5conf *conf = mddev->private; |
| 7889 | |
Shaohua Li | e254de6 | 2018-08-29 11:05:42 -0700 | [diff] [blame] | 7890 | if (raid5_has_log(conf) || raid5_has_ppl(conf)) |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7891 | return -EINVAL; |
NeilBrown | 3cb5edf | 2015-07-15 17:24:17 +1000 | [diff] [blame] | 7892 | sectors &= ~((sector_t)conf->chunk_sectors - 1); |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7893 | newsize = raid5_size(mddev, sectors, mddev->raid_disks); |
| 7894 | if (mddev->external_size && |
| 7895 | mddev->array_sectors > newsize) |
Dan Williams | b522adc | 2009-03-31 15:00:31 +1100 | [diff] [blame] | 7896 | return -EINVAL; |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7897 | if (mddev->bitmap) { |
Andy Shevchenko | e64e4018 | 2018-08-01 15:20:50 -0700 | [diff] [blame] | 7898 | int ret = md_bitmap_resize(mddev->bitmap, sectors, 0, 0); |
NeilBrown | a4a6125 | 2012-05-22 13:55:27 +1000 | [diff] [blame] | 7899 | if (ret) |
| 7900 | return ret; |
| 7901 | } |
| 7902 | md_set_array_sectors(mddev, newsize); |
NeilBrown | b098636 | 2011-05-11 15:52:21 +1000 | [diff] [blame] | 7903 | if (sectors > mddev->dev_sectors && |
| 7904 | mddev->recovery_cp > mddev->dev_sectors) { |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 7905 | mddev->recovery_cp = mddev->dev_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7906 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 7907 | } |
Andre Noll | 58c0fed | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 7908 | mddev->dev_sectors = sectors; |
NeilBrown | 4b5c7ae | 2005-07-27 11:43:28 -0700 | [diff] [blame] | 7909 | mddev->resync_max_sectors = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7910 | return 0; |
| 7911 | } |
| 7912 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7913 | static int check_stripe_cache(struct mddev *mddev) |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7914 | { |
| 7915 | /* Can only proceed if there are plenty of stripe_heads. |
| 7916 | * We need a minimum of one full stripe,, and for sensible progress |
| 7917 | * it is best to have about 4 times that. |
| 7918 | * If we require 4 times, then the default 256 4K stripe_heads will |
| 7919 | * allow for chunk sizes up to 256K, which is probably OK. |
| 7920 | * If the chunk size is greater, user-space should request more |
| 7921 | * stripe_heads first. |
| 7922 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7923 | struct r5conf *conf = mddev->private; |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 7924 | if (((mddev->chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4 |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7925 | > conf->min_nr_stripes || |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 7926 | ((mddev->new_chunk_sectors << 9) / RAID5_STRIPE_SIZE(conf)) * 4 |
NeilBrown | edbe83a | 2015-02-26 12:47:56 +1100 | [diff] [blame] | 7927 | > conf->min_nr_stripes) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 7928 | pr_warn("md/raid:%s: reshape: not enough stripes. Needed %lu\n", |
| 7929 | mdname(mddev), |
| 7930 | ((max(mddev->chunk_sectors, mddev->new_chunk_sectors) << 9) |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 7931 | / RAID5_STRIPE_SIZE(conf))*4); |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7932 | return 0; |
| 7933 | } |
| 7934 | return 1; |
| 7935 | } |
| 7936 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7937 | static int check_reshape(struct mddev *mddev) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7938 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7939 | struct r5conf *conf = mddev->private; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7940 | |
Shaohua Li | e254de6 | 2018-08-29 11:05:42 -0700 | [diff] [blame] | 7941 | if (raid5_has_log(conf) || raid5_has_ppl(conf)) |
Shaohua Li | 713cf5a | 2015-08-13 14:32:03 -0700 | [diff] [blame] | 7942 | return -EINVAL; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 7943 | if (mddev->delta_disks == 0 && |
| 7944 | mddev->new_layout == mddev->layout && |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 7945 | mddev->new_chunk_sectors == mddev->chunk_sectors) |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 7946 | return 0; /* nothing to do */ |
NeilBrown | 674806d | 2010-06-16 17:17:53 +1000 | [diff] [blame] | 7947 | if (has_failed(conf)) |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7948 | return -EINVAL; |
NeilBrown | fdcfbbb | 2013-07-04 16:38:16 +1000 | [diff] [blame] | 7949 | if (mddev->delta_disks < 0 && mddev->reshape_position == MaxSector) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 7950 | /* We might be able to shrink, but the devices must |
| 7951 | * be made bigger first. |
| 7952 | * For raid6, 4 is the minimum size. |
| 7953 | * Otherwise 2 is the minimum |
| 7954 | */ |
| 7955 | int min = 2; |
| 7956 | if (mddev->level == 6) |
| 7957 | min = 4; |
| 7958 | if (mddev->raid_disks + mddev->delta_disks < min) |
| 7959 | return -EINVAL; |
| 7960 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7961 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7962 | if (!check_stripe_cache(mddev)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7963 | return -ENOSPC; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 7964 | |
NeilBrown | 738a273 | 2015-05-08 18:19:39 +1000 | [diff] [blame] | 7965 | if (mddev->new_chunk_sectors > mddev->chunk_sectors || |
| 7966 | mddev->delta_disks > 0) |
| 7967 | if (resize_chunks(conf, |
| 7968 | conf->previous_raid_disks |
| 7969 | + max(0, mddev->delta_disks), |
| 7970 | max(mddev->new_chunk_sectors, |
| 7971 | mddev->chunk_sectors) |
| 7972 | ) < 0) |
| 7973 | return -ENOMEM; |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 7974 | |
| 7975 | if (conf->previous_raid_disks + mddev->delta_disks <= conf->pool_size) |
| 7976 | return 0; /* never bother to shrink */ |
NeilBrown | e56108d6 | 2012-10-11 14:24:13 +1100 | [diff] [blame] | 7977 | return resize_stripes(conf, (conf->previous_raid_disks |
| 7978 | + mddev->delta_disks)); |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7979 | } |
| 7980 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 7981 | static int raid5_start_reshape(struct mddev *mddev) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7982 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 7983 | struct r5conf *conf = mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 7984 | struct md_rdev *rdev; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7985 | int spares = 0; |
NeilBrown | c04be0a | 2006-10-03 01:15:53 -0700 | [diff] [blame] | 7986 | unsigned long flags; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7987 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 7988 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 7989 | return -EBUSY; |
| 7990 | |
NeilBrown | 01ee22b | 2009-06-18 08:47:20 +1000 | [diff] [blame] | 7991 | if (!check_stripe_cache(mddev)) |
| 7992 | return -ENOSPC; |
| 7993 | |
NeilBrown | 30b6764 | 2012-05-22 13:55:28 +1000 | [diff] [blame] | 7994 | if (has_failed(conf)) |
| 7995 | return -EINVAL; |
| 7996 | |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 7997 | rdev_for_each(rdev, mddev) { |
NeilBrown | 469518a | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 7998 | if (!test_bit(In_sync, &rdev->flags) |
| 7999 | && !test_bit(Faulty, &rdev->flags)) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8000 | spares++; |
NeilBrown | c6563a8 | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8001 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 8002 | |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 8003 | if (spares - mddev->degraded < mddev->delta_disks - conf->max_degraded) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8004 | /* Not enough devices even to make a degraded array |
| 8005 | * of that size |
| 8006 | */ |
| 8007 | return -EINVAL; |
| 8008 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8009 | /* Refuse to reduce size of the array. Any reductions in |
| 8010 | * array size must be through explicit setting of array_size |
| 8011 | * attribute. |
| 8012 | */ |
| 8013 | if (raid5_size(mddev, 0, conf->raid_disks + mddev->delta_disks) |
| 8014 | < mddev->array_sectors) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 8015 | pr_warn("md/raid:%s: array size must be reduced before number of disks\n", |
| 8016 | mdname(mddev)); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8017 | return -EINVAL; |
| 8018 | } |
| 8019 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 8020 | atomic_set(&conf->reshape_stripes, 0); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8021 | spin_lock_irq(&conf->device_lock); |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 8022 | write_seqcount_begin(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8023 | conf->previous_raid_disks = conf->raid_disks; |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 8024 | conf->raid_disks += mddev->delta_disks; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 8025 | conf->prev_chunk_sectors = conf->chunk_sectors; |
| 8026 | conf->chunk_sectors = mddev->new_chunk_sectors; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8027 | conf->prev_algo = conf->algorithm; |
| 8028 | conf->algorithm = mddev->new_layout; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8029 | conf->generation++; |
| 8030 | /* Code that selects data_offset needs to see the generation update |
| 8031 | * if reshape_progress has been set - so a memory barrier needed. |
| 8032 | */ |
| 8033 | smp_mb(); |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8034 | if (mddev->reshape_backwards) |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 8035 | conf->reshape_progress = raid5_size(mddev, 0, 0); |
| 8036 | else |
| 8037 | conf->reshape_progress = 0; |
| 8038 | conf->reshape_safe = conf->reshape_progress; |
NeilBrown | c46501b | 2013-08-27 15:52:13 +1000 | [diff] [blame] | 8039 | write_seqcount_end(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8040 | spin_unlock_irq(&conf->device_lock); |
| 8041 | |
NeilBrown | 4d77e3b | 2013-08-27 15:57:47 +1000 | [diff] [blame] | 8042 | /* Now make sure any requests that proceeded on the assumption |
| 8043 | * the reshape wasn't running - like Discard or Read - have |
| 8044 | * completed. |
| 8045 | */ |
| 8046 | mddev_suspend(mddev); |
| 8047 | mddev_resume(mddev); |
| 8048 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8049 | /* Add some new drives, as many as will fit. |
| 8050 | * We know there are enough to make the newly sized array work. |
NeilBrown | 3424bf6 | 2010-06-17 17:48:26 +1000 | [diff] [blame] | 8051 | * Don't add devices if we are reducing the number of |
| 8052 | * devices in the array. This is because it is not possible |
| 8053 | * to correctly record the "partially reconstructed" state of |
| 8054 | * such devices during the reshape and confusion could result. |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8055 | */ |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8056 | if (mddev->delta_disks >= 0) { |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 8057 | rdev_for_each(rdev, mddev) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8058 | if (rdev->raid_disk < 0 && |
| 8059 | !test_bit(Faulty, &rdev->flags)) { |
| 8060 | if (raid5_add_disk(mddev, rdev) == 0) { |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8061 | if (rdev->raid_disk |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 8062 | >= conf->previous_raid_disks) |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8063 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 9d4c7d8 | 2012-03-13 11:21:21 +1100 | [diff] [blame] | 8064 | else |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8065 | rdev->recovery_offset = 0; |
Namhyung Kim | 36fad85 | 2011-07-27 11:00:36 +1000 | [diff] [blame] | 8066 | |
Damien Le Moal | 2aada5b | 2020-07-16 13:54:42 +0900 | [diff] [blame] | 8067 | /* Failure here is OK */ |
| 8068 | sysfs_link_rdev(mddev, rdev); |
NeilBrown | 50da084 | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8069 | } |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8070 | } else if (rdev->raid_disk >= conf->previous_raid_disks |
| 8071 | && !test_bit(Faulty, &rdev->flags)) { |
| 8072 | /* This is a spare that was manually added */ |
| 8073 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8074 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8075 | |
NeilBrown | 87a8dec | 2011-01-31 11:57:43 +1100 | [diff] [blame] | 8076 | /* When a reshape changes the number of devices, |
| 8077 | * ->degraded is measured against the larger of the |
| 8078 | * pre and post number of devices. |
| 8079 | */ |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8080 | spin_lock_irqsave(&conf->device_lock, flags); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 8081 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8082 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 8083 | } |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 8084 | mddev->raid_disks = conf->raid_disks; |
NeilBrown | e516402 | 2009-08-03 10:59:57 +1000 | [diff] [blame] | 8085 | mddev->reshape_position = conf->reshape_progress; |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 8086 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 8087 | |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8088 | clear_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 8089 | clear_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
NeilBrown | ea358cd | 2015-06-12 20:05:04 +1000 | [diff] [blame] | 8090 | clear_bit(MD_RECOVERY_DONE, &mddev->recovery); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8091 | set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery); |
| 8092 | set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); |
| 8093 | mddev->sync_thread = md_register_thread(md_do_sync, mddev, |
NeilBrown | 0da3c61 | 2009-09-23 18:09:45 +1000 | [diff] [blame] | 8094 | "reshape"); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8095 | if (!mddev->sync_thread) { |
| 8096 | mddev->recovery = 0; |
| 8097 | spin_lock_irq(&conf->device_lock); |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 8098 | write_seqcount_begin(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8099 | mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks; |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 8100 | mddev->new_chunk_sectors = |
| 8101 | conf->chunk_sectors = conf->prev_chunk_sectors; |
| 8102 | mddev->new_layout = conf->algorithm = conf->prev_algo; |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8103 | rdev_for_each(rdev, mddev) |
| 8104 | rdev->new_data_offset = rdev->data_offset; |
| 8105 | smp_wmb(); |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 8106 | conf->generation --; |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 8107 | conf->reshape_progress = MaxSector; |
NeilBrown | 1e3fa9b | 2012-03-13 11:21:18 +1100 | [diff] [blame] | 8108 | mddev->reshape_position = MaxSector; |
NeilBrown | ba8805b | 2013-11-14 15:16:15 +1100 | [diff] [blame] | 8109 | write_seqcount_end(&conf->gen_lock); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8110 | spin_unlock_irq(&conf->device_lock); |
| 8111 | return -EAGAIN; |
| 8112 | } |
NeilBrown | c8f517c | 2009-03-31 15:28:40 +1100 | [diff] [blame] | 8113 | conf->reshape_checkpoint = jiffies; |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8114 | md_wakeup_thread(mddev->sync_thread); |
| 8115 | md_new_event(mddev); |
| 8116 | return 0; |
| 8117 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8118 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8119 | /* This is called from the reshape thread and should make any |
| 8120 | * changes needed in 'conf' |
| 8121 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 8122 | static void end_reshape(struct r5conf *conf) |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8123 | { |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8124 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 8125 | if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { |
NeilBrown | db0505d | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 8126 | struct md_rdev *rdev; |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8127 | |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 8128 | spin_lock_irq(&conf->device_lock); |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8129 | conf->previous_raid_disks = conf->raid_disks; |
Xiao Ni | b5d2771 | 2017-07-05 17:34:04 +0800 | [diff] [blame] | 8130 | md_finish_reshape(conf->mddev); |
NeilBrown | 05616be | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8131 | smp_wmb(); |
NeilBrown | fef9c61 | 2009-03-31 15:16:46 +1100 | [diff] [blame] | 8132 | conf->reshape_progress = MaxSector; |
NeilBrown | 6cbd814 | 2015-07-24 13:30:32 +1000 | [diff] [blame] | 8133 | conf->mddev->reshape_position = MaxSector; |
NeilBrown | db0505d | 2017-10-17 16:18:36 +1100 | [diff] [blame] | 8134 | rdev_for_each(rdev, conf->mddev) |
| 8135 | if (rdev->raid_disk >= 0 && |
| 8136 | !test_bit(Journal, &rdev->flags) && |
| 8137 | !test_bit(In_sync, &rdev->flags)) |
| 8138 | rdev->recovery_offset = MaxSector; |
NeilBrown | f670557 | 2006-03-27 01:18:11 -0800 | [diff] [blame] | 8139 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | b0f9ec0 | 2009-03-31 15:27:18 +1100 | [diff] [blame] | 8140 | wake_up(&conf->wait_for_overlap); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8141 | |
Christoph Hellwig | c2e4cd5 | 2020-09-24 08:51:34 +0200 | [diff] [blame] | 8142 | if (conf->mddev->queue) |
Christoph Hellwig | 16ef510 | 2020-09-24 08:51:33 +0200 | [diff] [blame] | 8143 | raid5_set_io_opt(conf); |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8144 | } |
NeilBrown | 2926955 | 2006-03-27 01:18:10 -0800 | [diff] [blame] | 8145 | } |
| 8146 | |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8147 | /* This is called from the raid5d thread with mddev_lock held. |
| 8148 | * It makes config changes to the device. |
| 8149 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8150 | static void raid5_finish_reshape(struct mddev *mddev) |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8151 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 8152 | struct r5conf *conf = mddev->private; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8153 | |
| 8154 | if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { |
| 8155 | |
BingJing Chang | 8876391 | 2018-02-22 13:34:46 +0800 | [diff] [blame] | 8156 | if (mddev->delta_disks <= 0) { |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8157 | int d; |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 8158 | spin_lock_irq(&conf->device_lock); |
Song Liu | 2e38a37 | 2017-01-24 10:45:30 -0800 | [diff] [blame] | 8159 | mddev->degraded = raid5_calc_degraded(conf); |
NeilBrown | 908f4fb | 2011-12-23 10:17:50 +1100 | [diff] [blame] | 8160 | spin_unlock_irq(&conf->device_lock); |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8161 | for (d = conf->raid_disks ; |
| 8162 | d < conf->raid_disks - mddev->delta_disks; |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 8163 | d++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 8164 | struct md_rdev *rdev = conf->disks[d].rdev; |
NeilBrown | da7613b | 2012-05-22 13:55:33 +1000 | [diff] [blame] | 8165 | if (rdev) |
| 8166 | clear_bit(In_sync, &rdev->flags); |
| 8167 | rdev = conf->disks[d].replacement; |
| 8168 | if (rdev) |
| 8169 | clear_bit(In_sync, &rdev->flags); |
NeilBrown | 1a67dde | 2009-08-13 10:41:49 +1000 | [diff] [blame] | 8170 | } |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8171 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8172 | mddev->layout = conf->algorithm; |
Andre Noll | 09c9e5f | 2009-06-18 08:45:55 +1000 | [diff] [blame] | 8173 | mddev->chunk_sectors = conf->chunk_sectors; |
NeilBrown | ec32a2b | 2009-03-31 15:17:38 +1100 | [diff] [blame] | 8174 | mddev->reshape_position = MaxSector; |
| 8175 | mddev->delta_disks = 0; |
NeilBrown | 2c810cd | 2012-05-21 09:27:00 +1000 | [diff] [blame] | 8176 | mddev->reshape_backwards = 0; |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8177 | } |
| 8178 | } |
| 8179 | |
NeilBrown | b03e0cc | 2017-10-19 12:49:15 +1100 | [diff] [blame] | 8180 | static void raid5_quiesce(struct mddev *mddev, int quiesce) |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8181 | { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 8182 | struct r5conf *conf = mddev->private; |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8183 | |
NeilBrown | b03e0cc | 2017-10-19 12:49:15 +1100 | [diff] [blame] | 8184 | if (quiesce) { |
| 8185 | /* stop all writes */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8186 | lock_all_device_hash_locks_irq(conf); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8187 | /* '2' tells resync/reshape to pause so that all |
| 8188 | * active stripes can drain |
| 8189 | */ |
Song Liu | a39f7af | 2016-11-17 15:24:40 -0800 | [diff] [blame] | 8190 | r5c_flush_cache(conf, INT_MAX); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8191 | conf->quiesce = 2; |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 8192 | wait_event_cmd(conf->wait_for_quiescent, |
Raz Ben-Jehuda(caro) | 46031f9 | 2006-12-10 02:20:47 -0800 | [diff] [blame] | 8193 | atomic_read(&conf->active_stripes) == 0 && |
| 8194 | atomic_read(&conf->active_aligned_reads) == 0, |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8195 | unlock_all_device_hash_locks_irq(conf), |
| 8196 | lock_all_device_hash_locks_irq(conf)); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8197 | conf->quiesce = 1; |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8198 | unlock_all_device_hash_locks_irq(conf); |
NeilBrown | 64bd660 | 2009-08-03 10:59:58 +1000 | [diff] [blame] | 8199 | /* allow reshape to continue */ |
| 8200 | wake_up(&conf->wait_for_overlap); |
NeilBrown | b03e0cc | 2017-10-19 12:49:15 +1100 | [diff] [blame] | 8201 | } else { |
| 8202 | /* re-enable writes */ |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8203 | lock_all_device_hash_locks_irq(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8204 | conf->quiesce = 0; |
Yuanhan Liu | b1b4648 | 2015-05-08 18:19:06 +1000 | [diff] [blame] | 8205 | wake_up(&conf->wait_for_quiescent); |
NeilBrown | e464eaf | 2006-03-27 01:18:14 -0800 | [diff] [blame] | 8206 | wake_up(&conf->wait_for_overlap); |
Shaohua Li | 566c09c | 2013-11-14 15:16:17 +1100 | [diff] [blame] | 8207 | unlock_all_device_hash_locks_irq(conf); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8208 | } |
Tomasz Majchrzak | 1532d9e | 2017-12-27 10:31:40 +0100 | [diff] [blame] | 8209 | log_quiesce(conf, quiesce); |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8210 | } |
NeilBrown | b15c2e5 | 2006-01-06 00:20:16 -0800 | [diff] [blame] | 8211 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8212 | static void *raid45_takeover_raid0(struct mddev *mddev, int level) |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 8213 | { |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 8214 | struct r0conf *raid0_conf = mddev->private; |
Randy Dunlap | d76c842 | 2011-04-21 09:07:26 -0700 | [diff] [blame] | 8215 | sector_t sectors; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 8216 | |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8217 | /* for raid0 takeover only one zone is supported */ |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 8218 | if (raid0_conf->nr_strip_zones > 1) { |
NeilBrown | cc6167b | 2016-11-02 14:16:50 +1100 | [diff] [blame] | 8219 | pr_warn("md/raid:%s: cannot takeover raid0 with more than one zone.\n", |
| 8220 | mdname(mddev)); |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8221 | return ERR_PTR(-EINVAL); |
| 8222 | } |
| 8223 | |
NeilBrown | e373ab1 | 2011-10-11 16:48:59 +1100 | [diff] [blame] | 8224 | sectors = raid0_conf->strip_zone[0].zone_end; |
| 8225 | sector_div(sectors, raid0_conf->strip_zone[0].nb_dev); |
NeilBrown | 3b71bd9 | 2011-04-20 15:38:18 +1000 | [diff] [blame] | 8226 | mddev->dev_sectors = sectors; |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8227 | mddev->new_level = level; |
Trela Maciej | 54071b3 | 2010-03-08 16:02:42 +1100 | [diff] [blame] | 8228 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 8229 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 8230 | mddev->raid_disks += 1; |
| 8231 | mddev->delta_disks = 1; |
| 8232 | /* make sure it will be not marked as dirty */ |
| 8233 | mddev->recovery_cp = MaxSector; |
| 8234 | |
| 8235 | return setup_conf(mddev); |
| 8236 | } |
| 8237 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8238 | static void *raid5_takeover_raid1(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8239 | { |
| 8240 | int chunksect; |
Shaohua Li | 6995f0b | 2016-12-08 15:48:17 -0800 | [diff] [blame] | 8241 | void *ret; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8242 | |
| 8243 | if (mddev->raid_disks != 2 || |
| 8244 | mddev->degraded > 1) |
| 8245 | return ERR_PTR(-EINVAL); |
| 8246 | |
| 8247 | /* Should check if there are write-behind devices? */ |
| 8248 | |
| 8249 | chunksect = 64*2; /* 64K by default */ |
| 8250 | |
| 8251 | /* The array must be an exact multiple of chunksize */ |
| 8252 | while (chunksect && (mddev->array_sectors & (chunksect-1))) |
| 8253 | chunksect >>= 1; |
| 8254 | |
Yufen Yu | c911c46 | 2020-07-18 05:29:07 -0400 | [diff] [blame] | 8255 | if ((chunksect<<9) < RAID5_STRIPE_SIZE((struct r5conf *)mddev->private)) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8256 | /* array size does not allow a suitable chunk size */ |
| 8257 | return ERR_PTR(-EINVAL); |
| 8258 | |
| 8259 | mddev->new_level = 5; |
| 8260 | mddev->new_layout = ALGORITHM_LEFT_SYMMETRIC; |
Andre Noll | 664e7c4 | 2009-06-18 08:45:27 +1000 | [diff] [blame] | 8261 | mddev->new_chunk_sectors = chunksect; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8262 | |
Shaohua Li | 6995f0b | 2016-12-08 15:48:17 -0800 | [diff] [blame] | 8263 | ret = setup_conf(mddev); |
Jes Sorensen | 32cd7cb | 2017-01-06 19:31:35 -0500 | [diff] [blame] | 8264 | if (!IS_ERR(ret)) |
Shaohua Li | 394ed8e | 2017-01-04 16:10:19 -0800 | [diff] [blame] | 8265 | mddev_clear_unsupported_flags(mddev, |
| 8266 | UNSUPPORTED_MDDEV_FLAGS); |
Shaohua Li | 6995f0b | 2016-12-08 15:48:17 -0800 | [diff] [blame] | 8267 | return ret; |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8268 | } |
| 8269 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8270 | static void *raid5_takeover_raid6(struct mddev *mddev) |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 8271 | { |
| 8272 | int new_layout; |
| 8273 | |
| 8274 | switch (mddev->layout) { |
| 8275 | case ALGORITHM_LEFT_ASYMMETRIC_6: |
| 8276 | new_layout = ALGORITHM_LEFT_ASYMMETRIC; |
| 8277 | break; |
| 8278 | case ALGORITHM_RIGHT_ASYMMETRIC_6: |
| 8279 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC; |
| 8280 | break; |
| 8281 | case ALGORITHM_LEFT_SYMMETRIC_6: |
| 8282 | new_layout = ALGORITHM_LEFT_SYMMETRIC; |
| 8283 | break; |
| 8284 | case ALGORITHM_RIGHT_SYMMETRIC_6: |
| 8285 | new_layout = ALGORITHM_RIGHT_SYMMETRIC; |
| 8286 | break; |
| 8287 | case ALGORITHM_PARITY_0_6: |
| 8288 | new_layout = ALGORITHM_PARITY_0; |
| 8289 | break; |
| 8290 | case ALGORITHM_PARITY_N: |
| 8291 | new_layout = ALGORITHM_PARITY_N; |
| 8292 | break; |
| 8293 | default: |
| 8294 | return ERR_PTR(-EINVAL); |
| 8295 | } |
| 8296 | mddev->new_level = 5; |
| 8297 | mddev->new_layout = new_layout; |
| 8298 | mddev->delta_disks = -1; |
| 8299 | mddev->raid_disks -= 1; |
| 8300 | return setup_conf(mddev); |
| 8301 | } |
| 8302 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8303 | static int raid5_check_reshape(struct mddev *mddev) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8304 | { |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8305 | /* For a 2-drive array, the layout and chunk size can be changed |
| 8306 | * immediately as not restriping is needed. |
| 8307 | * For larger arrays we record the new value - after validation |
| 8308 | * to be used by a reshape pass. |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8309 | */ |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 8310 | struct r5conf *conf = mddev->private; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8311 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8312 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8313 | if (mddev->new_layout >= 0 && !algorithm_valid_raid5(mddev->new_layout)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8314 | return -EINVAL; |
| 8315 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 8316 | if (!is_power_of_2(new_chunk)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8317 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8318 | if (new_chunk < (PAGE_SIZE>>9)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8319 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8320 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8321 | /* not factor of array size */ |
| 8322 | return -EINVAL; |
| 8323 | } |
| 8324 | |
| 8325 | /* They look valid */ |
| 8326 | |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8327 | if (mddev->raid_disks == 2) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8328 | /* can make the change immediately */ |
| 8329 | if (mddev->new_layout >= 0) { |
| 8330 | conf->algorithm = mddev->new_layout; |
| 8331 | mddev->layout = mddev->new_layout; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8332 | } |
| 8333 | if (new_chunk > 0) { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8334 | conf->chunk_sectors = new_chunk ; |
| 8335 | mddev->chunk_sectors = new_chunk; |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8336 | } |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 8337 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8338 | md_wakeup_thread(mddev->thread); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8339 | } |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8340 | return check_reshape(mddev); |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8341 | } |
| 8342 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8343 | static int raid6_check_reshape(struct mddev *mddev) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8344 | { |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8345 | int new_chunk = mddev->new_chunk_sectors; |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8346 | |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8347 | if (mddev->new_layout >= 0 && !algorithm_valid_raid6(mddev->new_layout)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8348 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8349 | if (new_chunk > 0) { |
Andre Noll | 0ba459d | 2009-06-18 08:46:10 +1000 | [diff] [blame] | 8350 | if (!is_power_of_2(new_chunk)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8351 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8352 | if (new_chunk < (PAGE_SIZE >> 9)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8353 | return -EINVAL; |
NeilBrown | 597a711 | 2009-06-18 08:47:42 +1000 | [diff] [blame] | 8354 | if (mddev->array_sectors & (new_chunk-1)) |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8355 | /* not factor of array size */ |
| 8356 | return -EINVAL; |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8357 | } |
NeilBrown | 88ce493 | 2009-03-31 15:24:23 +1100 | [diff] [blame] | 8358 | |
| 8359 | /* They look valid */ |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8360 | return check_reshape(mddev); |
NeilBrown | b354603 | 2009-03-31 14:56:41 +1100 | [diff] [blame] | 8361 | } |
| 8362 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8363 | static void *raid5_takeover(struct mddev *mddev) |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8364 | { |
| 8365 | /* raid5 can take over: |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8366 | * raid0 - if there is only one strip zone - make it a raid4 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8367 | * raid1 - if there are two drives. We need to know the chunk size |
| 8368 | * raid4 - trivial - just use a raid4 layout. |
| 8369 | * raid6 - Providing it is a *_6 layout |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8370 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8371 | if (mddev->level == 0) |
| 8372 | return raid45_takeover_raid0(mddev, 5); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8373 | if (mddev->level == 1) |
| 8374 | return raid5_takeover_raid1(mddev); |
NeilBrown | e9d4758 | 2009-03-31 14:57:09 +1100 | [diff] [blame] | 8375 | if (mddev->level == 4) { |
| 8376 | mddev->new_layout = ALGORITHM_PARITY_N; |
| 8377 | mddev->new_level = 5; |
| 8378 | return setup_conf(mddev); |
| 8379 | } |
NeilBrown | fc9739c | 2009-03-31 14:57:20 +1100 | [diff] [blame] | 8380 | if (mddev->level == 6) |
| 8381 | return raid5_takeover_raid6(mddev); |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8382 | |
| 8383 | return ERR_PTR(-EINVAL); |
| 8384 | } |
| 8385 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8386 | static void *raid4_takeover(struct mddev *mddev) |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8387 | { |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8388 | /* raid4 can take over: |
| 8389 | * raid0 - if there is only one strip zone |
| 8390 | * raid5 - if layout is right |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8391 | */ |
Dan Williams | f1b29bc | 2010-05-01 18:09:05 -0700 | [diff] [blame] | 8392 | if (mddev->level == 0) |
| 8393 | return raid45_takeover_raid0(mddev, 4); |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8394 | if (mddev->level == 5 && |
| 8395 | mddev->layout == ALGORITHM_PARITY_N) { |
| 8396 | mddev->new_layout = 0; |
| 8397 | mddev->new_level = 4; |
| 8398 | return setup_conf(mddev); |
| 8399 | } |
| 8400 | return ERR_PTR(-EINVAL); |
| 8401 | } |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8402 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8403 | static struct md_personality raid5_personality; |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8404 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 8405 | static void *raid6_takeover(struct mddev *mddev) |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8406 | { |
| 8407 | /* Currently can only take over a raid5. We map the |
| 8408 | * personality to an equivalent raid6 personality |
| 8409 | * with the Q block at the end. |
| 8410 | */ |
| 8411 | int new_layout; |
| 8412 | |
| 8413 | if (mddev->pers != &raid5_personality) |
| 8414 | return ERR_PTR(-EINVAL); |
| 8415 | if (mddev->degraded > 1) |
| 8416 | return ERR_PTR(-EINVAL); |
| 8417 | if (mddev->raid_disks > 253) |
| 8418 | return ERR_PTR(-EINVAL); |
| 8419 | if (mddev->raid_disks < 3) |
| 8420 | return ERR_PTR(-EINVAL); |
| 8421 | |
| 8422 | switch (mddev->layout) { |
| 8423 | case ALGORITHM_LEFT_ASYMMETRIC: |
| 8424 | new_layout = ALGORITHM_LEFT_ASYMMETRIC_6; |
| 8425 | break; |
| 8426 | case ALGORITHM_RIGHT_ASYMMETRIC: |
| 8427 | new_layout = ALGORITHM_RIGHT_ASYMMETRIC_6; |
| 8428 | break; |
| 8429 | case ALGORITHM_LEFT_SYMMETRIC: |
| 8430 | new_layout = ALGORITHM_LEFT_SYMMETRIC_6; |
| 8431 | break; |
| 8432 | case ALGORITHM_RIGHT_SYMMETRIC: |
| 8433 | new_layout = ALGORITHM_RIGHT_SYMMETRIC_6; |
| 8434 | break; |
| 8435 | case ALGORITHM_PARITY_0: |
| 8436 | new_layout = ALGORITHM_PARITY_0_6; |
| 8437 | break; |
| 8438 | case ALGORITHM_PARITY_N: |
| 8439 | new_layout = ALGORITHM_PARITY_N; |
| 8440 | break; |
| 8441 | default: |
| 8442 | return ERR_PTR(-EINVAL); |
| 8443 | } |
| 8444 | mddev->new_level = 6; |
| 8445 | mddev->new_layout = new_layout; |
| 8446 | mddev->delta_disks = 1; |
| 8447 | mddev->raid_disks += 1; |
| 8448 | return setup_conf(mddev); |
| 8449 | } |
| 8450 | |
Artur Paszkiewicz | ba903a3 | 2017-03-09 10:00:03 +0100 | [diff] [blame] | 8451 | static int raid5_change_consistency_policy(struct mddev *mddev, const char *buf) |
| 8452 | { |
| 8453 | struct r5conf *conf; |
| 8454 | int err; |
| 8455 | |
| 8456 | err = mddev_lock(mddev); |
| 8457 | if (err) |
| 8458 | return err; |
| 8459 | conf = mddev->private; |
| 8460 | if (!conf) { |
| 8461 | mddev_unlock(mddev); |
| 8462 | return -ENODEV; |
| 8463 | } |
| 8464 | |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 8465 | if (strncmp(buf, "ppl", 3) == 0) { |
Song Liu | 0bb0c10 | 2017-03-27 10:51:33 -0700 | [diff] [blame] | 8466 | /* ppl only works with RAID 5 */ |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 8467 | if (!raid5_has_ppl(conf) && conf->level == 5) { |
| 8468 | err = log_init(conf, NULL, true); |
| 8469 | if (!err) { |
| 8470 | err = resize_stripes(conf, conf->pool_size); |
| 8471 | if (err) |
| 8472 | log_exit(conf); |
| 8473 | } |
Song Liu | 0bb0c10 | 2017-03-27 10:51:33 -0700 | [diff] [blame] | 8474 | } else |
| 8475 | err = -EINVAL; |
| 8476 | } else if (strncmp(buf, "resync", 6) == 0) { |
| 8477 | if (raid5_has_ppl(conf)) { |
| 8478 | mddev_suspend(mddev); |
| 8479 | log_exit(conf); |
Song Liu | 0bb0c10 | 2017-03-27 10:51:33 -0700 | [diff] [blame] | 8480 | mddev_resume(mddev); |
Artur Paszkiewicz | 845b9e2 | 2017-04-04 13:13:57 +0200 | [diff] [blame] | 8481 | err = resize_stripes(conf, conf->pool_size); |
Song Liu | 0bb0c10 | 2017-03-27 10:51:33 -0700 | [diff] [blame] | 8482 | } else if (test_bit(MD_HAS_JOURNAL, &conf->mddev->flags) && |
| 8483 | r5l_log_disk_error(conf)) { |
| 8484 | bool journal_dev_exists = false; |
| 8485 | struct md_rdev *rdev; |
| 8486 | |
| 8487 | rdev_for_each(rdev, mddev) |
| 8488 | if (test_bit(Journal, &rdev->flags)) { |
| 8489 | journal_dev_exists = true; |
| 8490 | break; |
| 8491 | } |
| 8492 | |
| 8493 | if (!journal_dev_exists) { |
| 8494 | mddev_suspend(mddev); |
| 8495 | clear_bit(MD_HAS_JOURNAL, &mddev->flags); |
| 8496 | mddev_resume(mddev); |
| 8497 | } else /* need remove journal device first */ |
| 8498 | err = -EBUSY; |
| 8499 | } else |
| 8500 | err = -EINVAL; |
Artur Paszkiewicz | ba903a3 | 2017-03-09 10:00:03 +0100 | [diff] [blame] | 8501 | } else { |
| 8502 | err = -EINVAL; |
| 8503 | } |
| 8504 | |
| 8505 | if (!err) |
| 8506 | md_update_sb(mddev, 1); |
| 8507 | |
| 8508 | mddev_unlock(mddev); |
| 8509 | |
| 8510 | return err; |
| 8511 | } |
| 8512 | |
Song Liu | d5d885f | 2017-11-19 22:17:01 -0800 | [diff] [blame] | 8513 | static int raid5_start(struct mddev *mddev) |
| 8514 | { |
| 8515 | struct r5conf *conf = mddev->private; |
| 8516 | |
| 8517 | return r5l_start(conf->log); |
| 8518 | } |
| 8519 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8520 | static struct md_personality raid6_personality = |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8521 | { |
| 8522 | .name = "raid6", |
| 8523 | .level = 6, |
| 8524 | .owner = THIS_MODULE, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8525 | .make_request = raid5_make_request, |
| 8526 | .run = raid5_run, |
Song Liu | d5d885f | 2017-11-19 22:17:01 -0800 | [diff] [blame] | 8527 | .start = raid5_start, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 8528 | .free = raid5_free, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8529 | .status = raid5_status, |
| 8530 | .error_handler = raid5_error, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8531 | .hot_add_disk = raid5_add_disk, |
| 8532 | .hot_remove_disk= raid5_remove_disk, |
| 8533 | .spare_active = raid5_spare_active, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8534 | .sync_request = raid5_sync_request, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8535 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8536 | .size = raid5_size, |
NeilBrown | 50ac168 | 2009-06-18 08:47:55 +1000 | [diff] [blame] | 8537 | .check_reshape = raid6_check_reshape, |
NeilBrown | f416885 | 2007-02-28 20:11:53 -0800 | [diff] [blame] | 8538 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8539 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8540 | .quiesce = raid5_quiesce, |
NeilBrown | 245f46c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8541 | .takeover = raid6_takeover, |
Song Liu | 0bb0c10 | 2017-03-27 10:51:33 -0700 | [diff] [blame] | 8542 | .change_consistency_policy = raid5_change_consistency_policy, |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8543 | }; |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8544 | static struct md_personality raid5_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8545 | { |
| 8546 | .name = "raid5", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8547 | .level = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8548 | .owner = THIS_MODULE, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8549 | .make_request = raid5_make_request, |
| 8550 | .run = raid5_run, |
Song Liu | d5d885f | 2017-11-19 22:17:01 -0800 | [diff] [blame] | 8551 | .start = raid5_start, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 8552 | .free = raid5_free, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8553 | .status = raid5_status, |
| 8554 | .error_handler = raid5_error, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8555 | .hot_add_disk = raid5_add_disk, |
| 8556 | .hot_remove_disk= raid5_remove_disk, |
| 8557 | .spare_active = raid5_spare_active, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8558 | .sync_request = raid5_sync_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8559 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8560 | .size = raid5_size, |
NeilBrown | 63c70c4 | 2006-03-27 01:18:13 -0800 | [diff] [blame] | 8561 | .check_reshape = raid5_check_reshape, |
| 8562 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8563 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 7262668 | 2005-09-09 16:23:54 -0700 | [diff] [blame] | 8564 | .quiesce = raid5_quiesce, |
NeilBrown | d562b0c | 2009-03-31 14:39:39 +1100 | [diff] [blame] | 8565 | .takeover = raid5_takeover, |
Artur Paszkiewicz | ba903a3 | 2017-03-09 10:00:03 +0100 | [diff] [blame] | 8566 | .change_consistency_policy = raid5_change_consistency_policy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8567 | }; |
| 8568 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 8569 | static struct md_personality raid4_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8570 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8571 | .name = "raid4", |
| 8572 | .level = 4, |
| 8573 | .owner = THIS_MODULE, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8574 | .make_request = raid5_make_request, |
| 8575 | .run = raid5_run, |
Song Liu | d5d885f | 2017-11-19 22:17:01 -0800 | [diff] [blame] | 8576 | .start = raid5_start, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 8577 | .free = raid5_free, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8578 | .status = raid5_status, |
| 8579 | .error_handler = raid5_error, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8580 | .hot_add_disk = raid5_add_disk, |
| 8581 | .hot_remove_disk= raid5_remove_disk, |
| 8582 | .spare_active = raid5_spare_active, |
Shaohua Li | 849674e | 2016-01-20 13:52:20 -0800 | [diff] [blame] | 8583 | .sync_request = raid5_sync_request, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8584 | .resize = raid5_resize, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 8585 | .size = raid5_size, |
NeilBrown | 3d37890 | 2007-03-26 21:32:13 -0800 | [diff] [blame] | 8586 | .check_reshape = raid5_check_reshape, |
| 8587 | .start_reshape = raid5_start_reshape, |
NeilBrown | cea9c22 | 2009-03-31 15:15:05 +1100 | [diff] [blame] | 8588 | .finish_reshape = raid5_finish_reshape, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8589 | .quiesce = raid5_quiesce, |
NeilBrown | a78d38a | 2010-03-22 16:53:49 +1100 | [diff] [blame] | 8590 | .takeover = raid4_takeover, |
Song Liu | 0bb0c10 | 2017-03-27 10:51:33 -0700 | [diff] [blame] | 8591 | .change_consistency_policy = raid5_change_consistency_policy, |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8592 | }; |
| 8593 | |
| 8594 | static int __init raid5_init(void) |
| 8595 | { |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 8596 | int ret; |
| 8597 | |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 8598 | raid5_wq = alloc_workqueue("raid5wq", |
| 8599 | WQ_UNBOUND|WQ_MEM_RECLAIM|WQ_CPU_INTENSIVE|WQ_SYSFS, 0); |
| 8600 | if (!raid5_wq) |
| 8601 | return -ENOMEM; |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 8602 | |
| 8603 | ret = cpuhp_setup_state_multi(CPUHP_MD_RAID5_PREPARE, |
| 8604 | "md/raid5:prepare", |
| 8605 | raid456_cpu_up_prepare, |
| 8606 | raid456_cpu_dead); |
| 8607 | if (ret) { |
| 8608 | destroy_workqueue(raid5_wq); |
| 8609 | return ret; |
| 8610 | } |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8611 | register_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8612 | register_md_personality(&raid5_personality); |
| 8613 | register_md_personality(&raid4_personality); |
| 8614 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8615 | } |
| 8616 | |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8617 | static void raid5_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8618 | { |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8619 | unregister_md_personality(&raid6_personality); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8620 | unregister_md_personality(&raid5_personality); |
| 8621 | unregister_md_personality(&raid4_personality); |
Sebastian Andrzej Siewior | 29c6d1b | 2016-08-18 14:57:24 +0200 | [diff] [blame] | 8622 | cpuhp_remove_multi_state(CPUHP_MD_RAID5_PREPARE); |
Shaohua Li | 851c30c | 2013-08-28 14:30:16 +0800 | [diff] [blame] | 8623 | destroy_workqueue(raid5_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8624 | } |
| 8625 | |
| 8626 | module_init(raid5_init); |
| 8627 | module_exit(raid5_exit); |
| 8628 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 8629 | MODULE_DESCRIPTION("RAID4/5/6 (striping with parity) personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8630 | MODULE_ALIAS("md-personality-4"); /* RAID5 */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 8631 | MODULE_ALIAS("md-raid5"); |
| 8632 | MODULE_ALIAS("md-raid4"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 8633 | MODULE_ALIAS("md-level-5"); |
| 8634 | MODULE_ALIAS("md-level-4"); |
NeilBrown | 16a53ec | 2006-06-26 00:27:38 -0700 | [diff] [blame] | 8635 | MODULE_ALIAS("md-personality-8"); /* RAID6 */ |
| 8636 | MODULE_ALIAS("md-raid6"); |
| 8637 | MODULE_ALIAS("md-level-6"); |
| 8638 | |
| 8639 | /* This used to be two separate modules, they were: */ |
| 8640 | MODULE_ALIAS("raid5"); |
| 8641 | MODULE_ALIAS("raid6"); |