NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2011 Neil Brown |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3 | * Copyright (C) 2010-2017 Red Hat, Inc. All rights reserved. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4 | * |
| 5 | * This file is released under the GPL. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/slab.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 9 | #include <linux/module.h> |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 10 | |
| 11 | #include "md.h" |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 12 | #include "raid1.h" |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 13 | #include "raid5.h" |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 14 | #include "raid10.h" |
Mike Snitzer | 935fe09 | 2017-10-10 17:02:41 -0400 | [diff] [blame] | 15 | #include "md-bitmap.h" |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 16 | |
Alasdair G Kergon | 3e8dbb7 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 17 | #include <linux/device-mapper.h> |
| 18 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 19 | #define DM_MSG_PREFIX "raid" |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 20 | #define MAX_RAID_DEVICES 253 /* md-raid kernel limit */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 21 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 22 | /* |
| 23 | * Minimum sectors of free reshape space per raid device |
| 24 | */ |
| 25 | #define MIN_FREE_RESHAPE_SPACE to_sector(4*4096) |
| 26 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 27 | /* |
| 28 | * Minimum journal space 4 MiB in sectors. |
| 29 | */ |
| 30 | #define MIN_RAID456_JOURNAL_SPACE (4*2048) |
| 31 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 32 | /* Global list of all raid sets */ |
Wei Yongjun | 67ac901 | 2018-01-02 06:18:10 +0000 | [diff] [blame] | 33 | static LIST_HEAD(raid_sets); |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 34 | |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 35 | static bool devices_handle_discard_safely = false; |
| 36 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 37 | /* |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 38 | * The following flags are used by dm-raid.c to set up the array state. |
| 39 | * They must be cleared before md_run is called. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 40 | */ |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 41 | #define FirstUse 10 /* rdev flag */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 42 | |
| 43 | struct raid_dev { |
| 44 | /* |
| 45 | * Two DM devices, one to hold metadata and one to hold the |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 46 | * actual data/parity. The reason for this is to not confuse |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 47 | * ti->len and give more flexibility in altering size and |
| 48 | * characteristics. |
| 49 | * |
| 50 | * While it is possible for this device to be associated |
| 51 | * with a different physical device than the data_dev, it |
| 52 | * is intended for it to be the same. |
| 53 | * |--------- Physical Device ---------| |
| 54 | * |- meta_dev -|------ data_dev ------| |
| 55 | */ |
| 56 | struct dm_dev *meta_dev; |
| 57 | struct dm_dev *data_dev; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 58 | struct md_rdev rdev; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /* |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 62 | * Bits for establishing rs->ctr_flags |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 63 | * |
| 64 | * 1 = no flag value |
| 65 | * 2 = flag with value |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 66 | */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 67 | #define __CTR_FLAG_SYNC 0 /* 1 */ /* Not with raid0! */ |
| 68 | #define __CTR_FLAG_NOSYNC 1 /* 1 */ /* Not with raid0! */ |
| 69 | #define __CTR_FLAG_REBUILD 2 /* 2 */ /* Not with raid0! */ |
| 70 | #define __CTR_FLAG_DAEMON_SLEEP 3 /* 2 */ /* Not with raid0! */ |
| 71 | #define __CTR_FLAG_MIN_RECOVERY_RATE 4 /* 2 */ /* Not with raid0! */ |
| 72 | #define __CTR_FLAG_MAX_RECOVERY_RATE 5 /* 2 */ /* Not with raid0! */ |
| 73 | #define __CTR_FLAG_MAX_WRITE_BEHIND 6 /* 2 */ /* Only with raid1! */ |
| 74 | #define __CTR_FLAG_WRITE_MOSTLY 7 /* 2 */ /* Only with raid1! */ |
| 75 | #define __CTR_FLAG_STRIPE_CACHE 8 /* 2 */ /* Only with raid4/5/6! */ |
| 76 | #define __CTR_FLAG_REGION_SIZE 9 /* 2 */ /* Not with raid0! */ |
| 77 | #define __CTR_FLAG_RAID10_COPIES 10 /* 2 */ /* Only with raid10 */ |
| 78 | #define __CTR_FLAG_RAID10_FORMAT 11 /* 2 */ /* Only with raid10 */ |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 79 | /* New for v1.9.0 */ |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 80 | #define __CTR_FLAG_DELTA_DISKS 12 /* 2 */ /* Only with reshapable raid1/4/5/6/10! */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 81 | #define __CTR_FLAG_DATA_OFFSET 13 /* 2 */ /* Only with reshapable raid4/5/6/10! */ |
| 82 | #define __CTR_FLAG_RAID10_USE_NEAR_SETS 14 /* 2 */ /* Only with raid10! */ |
| 83 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 84 | /* New for v1.10.0 */ |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 85 | #define __CTR_FLAG_JOURNAL_DEV 15 /* 2 */ /* Only with raid4/5/6 (journal device)! */ |
| 86 | |
| 87 | /* New for v1.11.1 */ |
| 88 | #define __CTR_FLAG_JOURNAL_MODE 16 /* 2 */ /* Only with raid4/5/6 (journal mode)! */ |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 89 | |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 90 | /* |
| 91 | * Flags for rs->ctr_flags field. |
| 92 | */ |
| 93 | #define CTR_FLAG_SYNC (1 << __CTR_FLAG_SYNC) |
| 94 | #define CTR_FLAG_NOSYNC (1 << __CTR_FLAG_NOSYNC) |
| 95 | #define CTR_FLAG_REBUILD (1 << __CTR_FLAG_REBUILD) |
| 96 | #define CTR_FLAG_DAEMON_SLEEP (1 << __CTR_FLAG_DAEMON_SLEEP) |
| 97 | #define CTR_FLAG_MIN_RECOVERY_RATE (1 << __CTR_FLAG_MIN_RECOVERY_RATE) |
| 98 | #define CTR_FLAG_MAX_RECOVERY_RATE (1 << __CTR_FLAG_MAX_RECOVERY_RATE) |
| 99 | #define CTR_FLAG_MAX_WRITE_BEHIND (1 << __CTR_FLAG_MAX_WRITE_BEHIND) |
| 100 | #define CTR_FLAG_WRITE_MOSTLY (1 << __CTR_FLAG_WRITE_MOSTLY) |
| 101 | #define CTR_FLAG_STRIPE_CACHE (1 << __CTR_FLAG_STRIPE_CACHE) |
| 102 | #define CTR_FLAG_REGION_SIZE (1 << __CTR_FLAG_REGION_SIZE) |
| 103 | #define CTR_FLAG_RAID10_COPIES (1 << __CTR_FLAG_RAID10_COPIES) |
| 104 | #define CTR_FLAG_RAID10_FORMAT (1 << __CTR_FLAG_RAID10_FORMAT) |
| 105 | #define CTR_FLAG_DELTA_DISKS (1 << __CTR_FLAG_DELTA_DISKS) |
| 106 | #define CTR_FLAG_DATA_OFFSET (1 << __CTR_FLAG_DATA_OFFSET) |
| 107 | #define CTR_FLAG_RAID10_USE_NEAR_SETS (1 << __CTR_FLAG_RAID10_USE_NEAR_SETS) |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 108 | #define CTR_FLAG_JOURNAL_DEV (1 << __CTR_FLAG_JOURNAL_DEV) |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 109 | #define CTR_FLAG_JOURNAL_MODE (1 << __CTR_FLAG_JOURNAL_MODE) |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 110 | |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 111 | /* |
| 112 | * Definitions of various constructor flags to |
| 113 | * be used in checks of valid / invalid flags |
| 114 | * per raid level. |
| 115 | */ |
| 116 | /* Define all any sync flags */ |
| 117 | #define CTR_FLAGS_ANY_SYNC (CTR_FLAG_SYNC | CTR_FLAG_NOSYNC) |
| 118 | |
| 119 | /* Define flags for options without argument (e.g. 'nosync') */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 120 | #define CTR_FLAG_OPTIONS_NO_ARGS (CTR_FLAGS_ANY_SYNC | \ |
| 121 | CTR_FLAG_RAID10_USE_NEAR_SETS) |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 122 | |
| 123 | /* Define flags for options with one argument (e.g. 'delta_disks +2') */ |
| 124 | #define CTR_FLAG_OPTIONS_ONE_ARG (CTR_FLAG_REBUILD | \ |
| 125 | CTR_FLAG_WRITE_MOSTLY | \ |
| 126 | CTR_FLAG_DAEMON_SLEEP | \ |
| 127 | CTR_FLAG_MIN_RECOVERY_RATE | \ |
| 128 | CTR_FLAG_MAX_RECOVERY_RATE | \ |
| 129 | CTR_FLAG_MAX_WRITE_BEHIND | \ |
| 130 | CTR_FLAG_STRIPE_CACHE | \ |
| 131 | CTR_FLAG_REGION_SIZE | \ |
| 132 | CTR_FLAG_RAID10_COPIES | \ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 133 | CTR_FLAG_RAID10_FORMAT | \ |
| 134 | CTR_FLAG_DELTA_DISKS | \ |
| 135 | CTR_FLAG_DATA_OFFSET) |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 136 | |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 137 | /* Valid options definitions per raid level... */ |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 138 | |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 139 | /* "raid0" does only accept data offset */ |
| 140 | #define RAID0_VALID_FLAGS (CTR_FLAG_DATA_OFFSET) |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 141 | |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 142 | /* "raid1" does not accept stripe cache, data offset, delta_disks or any raid10 options */ |
| 143 | #define RAID1_VALID_FLAGS (CTR_FLAGS_ANY_SYNC | \ |
| 144 | CTR_FLAG_REBUILD | \ |
| 145 | CTR_FLAG_WRITE_MOSTLY | \ |
| 146 | CTR_FLAG_DAEMON_SLEEP | \ |
| 147 | CTR_FLAG_MIN_RECOVERY_RATE | \ |
| 148 | CTR_FLAG_MAX_RECOVERY_RATE | \ |
| 149 | CTR_FLAG_MAX_WRITE_BEHIND | \ |
| 150 | CTR_FLAG_REGION_SIZE | \ |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 151 | CTR_FLAG_DELTA_DISKS | \ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 152 | CTR_FLAG_DATA_OFFSET) |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 153 | |
| 154 | /* "raid10" does not accept any raid1 or stripe cache options */ |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 155 | #define RAID10_VALID_FLAGS (CTR_FLAGS_ANY_SYNC | \ |
| 156 | CTR_FLAG_REBUILD | \ |
| 157 | CTR_FLAG_DAEMON_SLEEP | \ |
| 158 | CTR_FLAG_MIN_RECOVERY_RATE | \ |
| 159 | CTR_FLAG_MAX_RECOVERY_RATE | \ |
| 160 | CTR_FLAG_REGION_SIZE | \ |
| 161 | CTR_FLAG_RAID10_COPIES | \ |
| 162 | CTR_FLAG_RAID10_FORMAT | \ |
| 163 | CTR_FLAG_DELTA_DISKS | \ |
| 164 | CTR_FLAG_DATA_OFFSET | \ |
| 165 | CTR_FLAG_RAID10_USE_NEAR_SETS) |
| 166 | |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 167 | /* |
| 168 | * "raid4/5/6" do not accept any raid1 or raid10 specific options |
| 169 | * |
| 170 | * "raid6" does not accept "nosync", because it is not guaranteed |
| 171 | * that both parity and q-syndrome are being written properly with |
| 172 | * any writes |
| 173 | */ |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 174 | #define RAID45_VALID_FLAGS (CTR_FLAGS_ANY_SYNC | \ |
| 175 | CTR_FLAG_REBUILD | \ |
| 176 | CTR_FLAG_DAEMON_SLEEP | \ |
| 177 | CTR_FLAG_MIN_RECOVERY_RATE | \ |
| 178 | CTR_FLAG_MAX_RECOVERY_RATE | \ |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 179 | CTR_FLAG_STRIPE_CACHE | \ |
| 180 | CTR_FLAG_REGION_SIZE | \ |
| 181 | CTR_FLAG_DELTA_DISKS | \ |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 182 | CTR_FLAG_DATA_OFFSET | \ |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 183 | CTR_FLAG_JOURNAL_DEV | \ |
| 184 | CTR_FLAG_JOURNAL_MODE) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 185 | |
| 186 | #define RAID6_VALID_FLAGS (CTR_FLAG_SYNC | \ |
| 187 | CTR_FLAG_REBUILD | \ |
| 188 | CTR_FLAG_DAEMON_SLEEP | \ |
| 189 | CTR_FLAG_MIN_RECOVERY_RATE | \ |
| 190 | CTR_FLAG_MAX_RECOVERY_RATE | \ |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 191 | CTR_FLAG_STRIPE_CACHE | \ |
| 192 | CTR_FLAG_REGION_SIZE | \ |
| 193 | CTR_FLAG_DELTA_DISKS | \ |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 194 | CTR_FLAG_DATA_OFFSET | \ |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 195 | CTR_FLAG_JOURNAL_DEV | \ |
| 196 | CTR_FLAG_JOURNAL_MODE) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 197 | /* ...valid options definitions per raid level */ |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 198 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 199 | /* |
| 200 | * Flags for rs->runtime_flags field |
| 201 | * (RT_FLAG prefix meaning "runtime flag") |
| 202 | * |
| 203 | * These are all internal and used to define runtime state, |
| 204 | * e.g. to prevent another resume from preresume processing |
| 205 | * the raid set all over again. |
| 206 | */ |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 207 | #define RT_FLAG_RS_PRERESUMED 0 |
| 208 | #define RT_FLAG_RS_RESUMED 1 |
| 209 | #define RT_FLAG_RS_BITMAP_LOADED 2 |
| 210 | #define RT_FLAG_UPDATE_SBS 3 |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 211 | #define RT_FLAG_RESHAPE_RS 4 |
Heinz Mauelshagen | 0cf352e | 2017-07-13 17:34:24 +0200 | [diff] [blame] | 212 | #define RT_FLAG_RS_SUSPENDED 5 |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 213 | #define RT_FLAG_RS_IN_SYNC 6 |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 214 | #define RT_FLAG_RS_RESYNCING 7 |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 215 | |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 216 | /* Array elements of 64 bit needed for rebuild/failed disk bits */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 217 | #define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8) |
| 218 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 219 | /* |
| 220 | * raid set level, layout and chunk sectors backup/restore |
| 221 | */ |
| 222 | struct rs_layout { |
| 223 | int new_level; |
| 224 | int new_layout; |
| 225 | int new_chunk_sectors; |
| 226 | }; |
| 227 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 228 | struct raid_set { |
| 229 | struct dm_target *ti; |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 230 | struct list_head list; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 231 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 232 | uint32_t stripe_cache_entries; |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 233 | unsigned long ctr_flags; |
| 234 | unsigned long runtime_flags; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 235 | |
| 236 | uint64_t rebuild_disks[DISKS_ARRAY_ELEMS]; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 237 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 238 | int raid_disks; |
| 239 | int delta_disks; |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 240 | int data_offset; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 241 | int raid10_copies; |
Heinz Mauelshagen | 4257e08 | 2016-06-14 01:46:03 +0200 | [diff] [blame] | 242 | int requested_bitmap_chunk_sectors; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 243 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 244 | struct mddev md; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 245 | struct raid_type *raid_type; |
| 246 | struct dm_target_callbacks callbacks; |
| 247 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 248 | /* Optional raid4/5/6 journal device */ |
| 249 | struct journal_dev { |
| 250 | struct dm_dev *dev; |
| 251 | struct md_rdev rdev; |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 252 | int mode; |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 253 | } journal_dev; |
| 254 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 255 | struct raid_dev dev[0]; |
| 256 | }; |
| 257 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 258 | static void rs_config_backup(struct raid_set *rs, struct rs_layout *l) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 259 | { |
| 260 | struct mddev *mddev = &rs->md; |
| 261 | |
| 262 | l->new_level = mddev->new_level; |
| 263 | l->new_layout = mddev->new_layout; |
| 264 | l->new_chunk_sectors = mddev->new_chunk_sectors; |
| 265 | } |
| 266 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 267 | static void rs_config_restore(struct raid_set *rs, struct rs_layout *l) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 268 | { |
| 269 | struct mddev *mddev = &rs->md; |
| 270 | |
| 271 | mddev->new_level = l->new_level; |
| 272 | mddev->new_layout = l->new_layout; |
| 273 | mddev->new_chunk_sectors = l->new_chunk_sectors; |
| 274 | } |
| 275 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 276 | /* Find any raid_set in active slot for @rs on global list */ |
| 277 | static struct raid_set *rs_find_active(struct raid_set *rs) |
| 278 | { |
| 279 | struct raid_set *r; |
| 280 | struct mapped_device *md = dm_table_get_md(rs->ti->table); |
| 281 | |
| 282 | list_for_each_entry(r, &raid_sets, list) |
| 283 | if (r != rs && dm_table_get_md(r->ti->table) == md) |
| 284 | return r; |
| 285 | |
| 286 | return NULL; |
| 287 | } |
| 288 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 289 | /* raid10 algorithms (i.e. formats) */ |
| 290 | #define ALGORITHM_RAID10_DEFAULT 0 |
| 291 | #define ALGORITHM_RAID10_NEAR 1 |
| 292 | #define ALGORITHM_RAID10_OFFSET 2 |
| 293 | #define ALGORITHM_RAID10_FAR 3 |
| 294 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 295 | /* Supported raid types and properties. */ |
| 296 | static struct raid_type { |
| 297 | const char *name; /* RAID algorithm. */ |
| 298 | const char *descr; /* Descriptor text for logging. */ |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 299 | const unsigned int parity_devs; /* # of parity devices. */ |
| 300 | const unsigned int minimal_devs;/* minimal # of devices in set. */ |
| 301 | const unsigned int level; /* RAID level. */ |
| 302 | const unsigned int algorithm; /* RAID algorithm. */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 303 | } raid_types[] = { |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 304 | {"raid0", "raid0 (striping)", 0, 2, 0, 0 /* NONE */}, |
| 305 | {"raid1", "raid1 (mirroring)", 0, 2, 1, 0 /* NONE */}, |
| 306 | {"raid10_far", "raid10 far (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_FAR}, |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 307 | {"raid10_offset", "raid10 offset (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_OFFSET}, |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 308 | {"raid10_near", "raid10 near (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_NEAR}, |
| 309 | {"raid10", "raid10 (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_DEFAULT}, |
Heinz Mauelshagen | b052b07 | 2016-10-17 21:20:07 +0200 | [diff] [blame] | 310 | {"raid4", "raid4 (dedicated first parity disk)", 1, 2, 5, ALGORITHM_PARITY_0}, /* raid4 layout = raid5_0 */ |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 311 | {"raid5_n", "raid5 (dedicated last parity disk)", 1, 2, 5, ALGORITHM_PARITY_N}, |
| 312 | {"raid5_ls", "raid5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC}, |
| 313 | {"raid5_rs", "raid5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC}, |
| 314 | {"raid5_la", "raid5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC}, |
| 315 | {"raid5_ra", "raid5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC}, |
| 316 | {"raid6_zr", "raid6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART}, |
| 317 | {"raid6_nr", "raid6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART}, |
| 318 | {"raid6_nc", "raid6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE}, |
| 319 | {"raid6_n_6", "raid6 (dedicated parity/Q n/6)", 2, 4, 6, ALGORITHM_PARITY_N_6}, |
| 320 | {"raid6_ls_6", "raid6 (left symmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_LEFT_SYMMETRIC_6}, |
| 321 | {"raid6_rs_6", "raid6 (right symmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_RIGHT_SYMMETRIC_6}, |
| 322 | {"raid6_la_6", "raid6 (left asymmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_LEFT_ASYMMETRIC_6}, |
| 323 | {"raid6_ra_6", "raid6 (right asymmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_RIGHT_ASYMMETRIC_6} |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 326 | /* True, if @v is in inclusive range [@min, @max] */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 327 | static bool __within_range(long v, long min, long max) |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 328 | { |
| 329 | return v >= min && v <= max; |
| 330 | } |
| 331 | |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 332 | /* All table line arguments are defined here */ |
| 333 | static struct arg_name_flag { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 334 | const unsigned long flag; |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 335 | const char *name; |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 336 | } __arg_name_flags[] = { |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 337 | { CTR_FLAG_SYNC, "sync"}, |
| 338 | { CTR_FLAG_NOSYNC, "nosync"}, |
| 339 | { CTR_FLAG_REBUILD, "rebuild"}, |
| 340 | { CTR_FLAG_DAEMON_SLEEP, "daemon_sleep"}, |
| 341 | { CTR_FLAG_MIN_RECOVERY_RATE, "min_recovery_rate"}, |
| 342 | { CTR_FLAG_MAX_RECOVERY_RATE, "max_recovery_rate"}, |
| 343 | { CTR_FLAG_MAX_WRITE_BEHIND, "max_write_behind"}, |
Heinz Mauelshagen | 65359ee | 2016-06-24 21:32:25 +0200 | [diff] [blame] | 344 | { CTR_FLAG_WRITE_MOSTLY, "write_mostly"}, |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 345 | { CTR_FLAG_STRIPE_CACHE, "stripe_cache"}, |
| 346 | { CTR_FLAG_REGION_SIZE, "region_size"}, |
| 347 | { CTR_FLAG_RAID10_COPIES, "raid10_copies"}, |
| 348 | { CTR_FLAG_RAID10_FORMAT, "raid10_format"}, |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 349 | { CTR_FLAG_DATA_OFFSET, "data_offset"}, |
| 350 | { CTR_FLAG_DELTA_DISKS, "delta_disks"}, |
| 351 | { CTR_FLAG_RAID10_USE_NEAR_SETS, "raid10_use_near_sets"}, |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 352 | { CTR_FLAG_JOURNAL_DEV, "journal_dev" }, |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 353 | { CTR_FLAG_JOURNAL_MODE, "journal_mode" }, |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | /* Return argument name string for given @flag */ |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 357 | static const char *dm_raid_arg_name_by_flag(const uint32_t flag) |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 358 | { |
| 359 | if (hweight32(flag) == 1) { |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 360 | struct arg_name_flag *anf = __arg_name_flags + ARRAY_SIZE(__arg_name_flags); |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 361 | |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 362 | while (anf-- > __arg_name_flags) |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 363 | if (flag & anf->flag) |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 364 | return anf->name; |
| 365 | |
| 366 | } else |
| 367 | DMERR("%s called with more than one flag!", __func__); |
| 368 | |
| 369 | return NULL; |
| 370 | } |
| 371 | |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 372 | /* Define correlation of raid456 journal cache modes and dm-raid target line parameters */ |
| 373 | static struct { |
| 374 | const int mode; |
| 375 | const char *param; |
| 376 | } _raid456_journal_mode[] = { |
| 377 | { R5C_JOURNAL_MODE_WRITE_THROUGH , "writethrough" }, |
| 378 | { R5C_JOURNAL_MODE_WRITE_BACK , "writeback" } |
| 379 | }; |
| 380 | |
| 381 | /* Return MD raid4/5/6 journal mode for dm @journal_mode one */ |
| 382 | static int dm_raid_journal_mode_to_md(const char *mode) |
| 383 | { |
| 384 | int m = ARRAY_SIZE(_raid456_journal_mode); |
| 385 | |
| 386 | while (m--) |
| 387 | if (!strcasecmp(mode, _raid456_journal_mode[m].param)) |
| 388 | return _raid456_journal_mode[m].mode; |
| 389 | |
| 390 | return -EINVAL; |
| 391 | } |
| 392 | |
| 393 | /* Return dm-raid raid4/5/6 journal mode string for @mode */ |
| 394 | static const char *md_journal_mode_to_dm_raid(const int mode) |
| 395 | { |
| 396 | int m = ARRAY_SIZE(_raid456_journal_mode); |
| 397 | |
| 398 | while (m--) |
| 399 | if (mode == _raid456_journal_mode[m].mode) |
| 400 | return _raid456_journal_mode[m].param; |
| 401 | |
| 402 | return "unknown"; |
| 403 | } |
| 404 | |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 405 | /* |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 406 | * Bool helpers to test for various raid levels of a raid set. |
| 407 | * It's level as reported by the superblock rather than |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 408 | * the requested raid_type passed to the constructor. |
| 409 | */ |
| 410 | /* Return true, if raid set in @rs is raid0 */ |
| 411 | static bool rs_is_raid0(struct raid_set *rs) |
| 412 | { |
| 413 | return !rs->md.level; |
| 414 | } |
| 415 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 416 | /* Return true, if raid set in @rs is raid1 */ |
| 417 | static bool rs_is_raid1(struct raid_set *rs) |
| 418 | { |
| 419 | return rs->md.level == 1; |
| 420 | } |
| 421 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 422 | /* Return true, if raid set in @rs is raid10 */ |
| 423 | static bool rs_is_raid10(struct raid_set *rs) |
| 424 | { |
| 425 | return rs->md.level == 10; |
| 426 | } |
| 427 | |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 428 | /* Return true, if raid set in @rs is level 6 */ |
| 429 | static bool rs_is_raid6(struct raid_set *rs) |
| 430 | { |
| 431 | return rs->md.level == 6; |
| 432 | } |
| 433 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 434 | /* Return true, if raid set in @rs is level 4, 5 or 6 */ |
| 435 | static bool rs_is_raid456(struct raid_set *rs) |
| 436 | { |
| 437 | return __within_range(rs->md.level, 4, 6); |
| 438 | } |
| 439 | |
| 440 | /* Return true, if raid set in @rs is reshapable */ |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 441 | static bool __is_raid10_far(int layout); |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 442 | static bool rs_is_reshapable(struct raid_set *rs) |
| 443 | { |
| 444 | return rs_is_raid456(rs) || |
| 445 | (rs_is_raid10(rs) && !__is_raid10_far(rs->md.new_layout)); |
| 446 | } |
| 447 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 448 | /* Return true, if raid set in @rs is recovering */ |
| 449 | static bool rs_is_recovering(struct raid_set *rs) |
| 450 | { |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 451 | return rs->md.recovery_cp < rs->md.dev_sectors; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /* Return true, if raid set in @rs is reshaping */ |
| 455 | static bool rs_is_reshaping(struct raid_set *rs) |
| 456 | { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 457 | return rs->md.reshape_position != MaxSector; |
| 458 | } |
| 459 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 460 | /* |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 461 | * bool helpers to test for various raid levels of a raid type @rt |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 462 | */ |
| 463 | |
| 464 | /* Return true, if raid type in @rt is raid0 */ |
| 465 | static bool rt_is_raid0(struct raid_type *rt) |
| 466 | { |
| 467 | return !rt->level; |
| 468 | } |
| 469 | |
| 470 | /* Return true, if raid type in @rt is raid1 */ |
| 471 | static bool rt_is_raid1(struct raid_type *rt) |
| 472 | { |
| 473 | return rt->level == 1; |
| 474 | } |
| 475 | |
| 476 | /* Return true, if raid type in @rt is raid10 */ |
| 477 | static bool rt_is_raid10(struct raid_type *rt) |
| 478 | { |
| 479 | return rt->level == 10; |
| 480 | } |
| 481 | |
| 482 | /* Return true, if raid type in @rt is raid4/5 */ |
| 483 | static bool rt_is_raid45(struct raid_type *rt) |
| 484 | { |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 485 | return __within_range(rt->level, 4, 5); |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /* Return true, if raid type in @rt is raid6 */ |
| 489 | static bool rt_is_raid6(struct raid_type *rt) |
| 490 | { |
| 491 | return rt->level == 6; |
| 492 | } |
Heinz Mauelshagen | 676fa5a | 2016-05-19 18:49:29 +0200 | [diff] [blame] | 493 | |
| 494 | /* Return true, if raid type in @rt is raid4/5/6 */ |
| 495 | static bool rt_is_raid456(struct raid_type *rt) |
| 496 | { |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 497 | return __within_range(rt->level, 4, 6); |
Heinz Mauelshagen | 676fa5a | 2016-05-19 18:49:29 +0200 | [diff] [blame] | 498 | } |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 499 | /* END: raid level bools */ |
| 500 | |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 501 | /* Return valid ctr flags for the raid level of @rs */ |
| 502 | static unsigned long __valid_flags(struct raid_set *rs) |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 503 | { |
| 504 | if (rt_is_raid0(rs->raid_type)) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 505 | return RAID0_VALID_FLAGS; |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 506 | else if (rt_is_raid1(rs->raid_type)) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 507 | return RAID1_VALID_FLAGS; |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 508 | else if (rt_is_raid10(rs->raid_type)) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 509 | return RAID10_VALID_FLAGS; |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 510 | else if (rt_is_raid45(rs->raid_type)) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 511 | return RAID45_VALID_FLAGS; |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 512 | else if (rt_is_raid6(rs->raid_type)) |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 513 | return RAID6_VALID_FLAGS; |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 514 | |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 515 | return 0; |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 519 | * Check for valid flags set on @rs |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 520 | * |
| 521 | * Has to be called after parsing of the ctr flags! |
| 522 | */ |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 523 | static int rs_check_for_valid_flags(struct raid_set *rs) |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 524 | { |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 525 | if (rs->ctr_flags & ~__valid_flags(rs)) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 526 | rs->ti->error = "Invalid flags combination"; |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 527 | return -EINVAL; |
| 528 | } |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 533 | /* MD raid10 bit definitions and helpers */ |
| 534 | #define RAID10_OFFSET (1 << 16) /* stripes with data copies area adjacent on devices */ |
| 535 | #define RAID10_BROCKEN_USE_FAR_SETS (1 << 17) /* Broken in raid10.c: use sets instead of whole stripe rotation */ |
| 536 | #define RAID10_USE_FAR_SETS (1 << 18) /* Use sets instead of whole stripe rotation */ |
| 537 | #define RAID10_FAR_COPIES_SHIFT 8 /* raid10 # far copies shift (2nd byte of layout) */ |
| 538 | |
| 539 | /* Return md raid10 near copies for @layout */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 540 | static unsigned int __raid10_near_copies(int layout) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 541 | { |
| 542 | return layout & 0xFF; |
| 543 | } |
| 544 | |
| 545 | /* Return md raid10 far copies for @layout */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 546 | static unsigned int __raid10_far_copies(int layout) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 547 | { |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 548 | return __raid10_near_copies(layout >> RAID10_FAR_COPIES_SHIFT); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /* Return true if md raid10 offset for @layout */ |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 552 | static bool __is_raid10_offset(int layout) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 553 | { |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 554 | return !!(layout & RAID10_OFFSET); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* Return true if md raid10 near for @layout */ |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 558 | static bool __is_raid10_near(int layout) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 559 | { |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 560 | return !__is_raid10_offset(layout) && __raid10_near_copies(layout) > 1; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /* Return true if md raid10 far for @layout */ |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 564 | static bool __is_raid10_far(int layout) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 565 | { |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 566 | return !__is_raid10_offset(layout) && __raid10_far_copies(layout) > 1; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /* Return md raid10 layout string for @layout */ |
| 570 | static const char *raid10_md_layout_to_format(int layout) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 571 | { |
| 572 | /* |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 573 | * Bit 16 stands for "offset" |
| 574 | * (i.e. adjacent stripes hold copies) |
| 575 | * |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 576 | * Refer to MD's raid10.c for details |
| 577 | */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 578 | if (__is_raid10_offset(layout)) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 579 | return "offset"; |
| 580 | |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 581 | if (__raid10_near_copies(layout) > 1) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 582 | return "near"; |
| 583 | |
Heinz Mauelshagen | bbac1e0 | 2017-07-13 17:33:22 +0200 | [diff] [blame] | 584 | if (__raid10_far_copies(layout) > 1) |
| 585 | return "far"; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 586 | |
Heinz Mauelshagen | bbac1e0 | 2017-07-13 17:33:22 +0200 | [diff] [blame] | 587 | return "unknown"; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 588 | } |
| 589 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 590 | /* Return md raid10 algorithm for @name */ |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 591 | static const int raid10_name_to_format(const char *name) |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 592 | { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 593 | if (!strcasecmp(name, "near")) |
| 594 | return ALGORITHM_RAID10_NEAR; |
| 595 | else if (!strcasecmp(name, "offset")) |
| 596 | return ALGORITHM_RAID10_OFFSET; |
| 597 | else if (!strcasecmp(name, "far")) |
| 598 | return ALGORITHM_RAID10_FAR; |
| 599 | |
| 600 | return -EINVAL; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 601 | } |
| 602 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 603 | /* Return md raid10 copies for @layout */ |
| 604 | static unsigned int raid10_md_layout_to_copies(int layout) |
| 605 | { |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 606 | return max(__raid10_near_copies(layout), __raid10_far_copies(layout)); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /* Return md raid10 format id for @format string */ |
| 610 | static int raid10_format_to_md_layout(struct raid_set *rs, |
| 611 | unsigned int algorithm, |
| 612 | unsigned int copies) |
| 613 | { |
| 614 | unsigned int n = 1, f = 1, r = 0; |
| 615 | |
| 616 | /* |
| 617 | * MD resilienece flaw: |
| 618 | * |
| 619 | * enabling use_far_sets for far/offset formats causes copies |
| 620 | * to be colocated on the same devs together with their origins! |
| 621 | * |
| 622 | * -> disable it for now in the definition above |
| 623 | */ |
| 624 | if (algorithm == ALGORITHM_RAID10_DEFAULT || |
| 625 | algorithm == ALGORITHM_RAID10_NEAR) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 626 | n = copies; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 627 | |
| 628 | else if (algorithm == ALGORITHM_RAID10_OFFSET) { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 629 | f = copies; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 630 | r = RAID10_OFFSET; |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 631 | if (!test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 632 | r |= RAID10_USE_FAR_SETS; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 633 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 634 | } else if (algorithm == ALGORITHM_RAID10_FAR) { |
| 635 | f = copies; |
| 636 | r = !RAID10_OFFSET; |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 637 | if (!test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 638 | r |= RAID10_USE_FAR_SETS; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 639 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 640 | } else |
| 641 | return -EINVAL; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 642 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 643 | return r | (f << RAID10_FAR_COPIES_SHIFT) | n; |
| 644 | } |
| 645 | /* END: MD raid10 bit definitions and helpers */ |
| 646 | |
| 647 | /* Check for any of the raid10 algorithms */ |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 648 | static bool __got_raid10(struct raid_type *rtp, const int layout) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 649 | { |
| 650 | if (rtp->level == 10) { |
| 651 | switch (rtp->algorithm) { |
| 652 | case ALGORITHM_RAID10_DEFAULT: |
| 653 | case ALGORITHM_RAID10_NEAR: |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 654 | return __is_raid10_near(layout); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 655 | case ALGORITHM_RAID10_OFFSET: |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 656 | return __is_raid10_offset(layout); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 657 | case ALGORITHM_RAID10_FAR: |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 658 | return __is_raid10_far(layout); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 659 | default: |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | |
Heinz Mauelshagen | d7ccc2e | 2016-07-06 18:29:22 +0200 | [diff] [blame] | 664 | return false; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 665 | } |
| 666 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 667 | /* Return raid_type for @name */ |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 668 | static struct raid_type *get_raid_type(const char *name) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 669 | { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 670 | struct raid_type *rtp = raid_types + ARRAY_SIZE(raid_types); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 671 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 672 | while (rtp-- > raid_types) |
| 673 | if (!strcasecmp(rtp->name, name)) |
| 674 | return rtp; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 675 | |
| 676 | return NULL; |
| 677 | } |
| 678 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 679 | /* Return raid_type for @name based derived from @level and @layout */ |
| 680 | static struct raid_type *get_raid_type_by_ll(const int level, const int layout) |
| 681 | { |
| 682 | struct raid_type *rtp = raid_types + ARRAY_SIZE(raid_types); |
| 683 | |
| 684 | while (rtp-- > raid_types) { |
| 685 | /* RAID10 special checks based on @layout flags/properties */ |
| 686 | if (rtp->level == level && |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 687 | (__got_raid10(rtp, layout) || rtp->algorithm == layout)) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 688 | return rtp; |
| 689 | } |
| 690 | |
| 691 | return NULL; |
| 692 | } |
| 693 | |
Heinz Mauelshagen | 61e06e2 | 2017-12-02 01:03:51 +0100 | [diff] [blame] | 694 | /* Adjust rdev sectors */ |
| 695 | static void rs_set_rdev_sectors(struct raid_set *rs) |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 696 | { |
| 697 | struct mddev *mddev = &rs->md; |
Heinz Mauelshagen | fbe6365 | 2016-06-24 00:36:08 +0200 | [diff] [blame] | 698 | struct md_rdev *rdev; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 699 | |
Heinz Mauelshagen | fbe6365 | 2016-06-24 00:36:08 +0200 | [diff] [blame] | 700 | /* |
| 701 | * raid10 sets rdev->sector to the device size, which |
| 702 | * is unintended in case of out-of-place reshaping |
| 703 | */ |
| 704 | rdev_for_each(rdev, mddev) |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 705 | if (!test_bit(Journal, &rdev->flags)) |
| 706 | rdev->sectors = mddev->dev_sectors; |
Heinz Mauelshagen | 61e06e2 | 2017-12-02 01:03:51 +0100 | [diff] [blame] | 707 | } |
Heinz Mauelshagen | fbe6365 | 2016-06-24 00:36:08 +0200 | [diff] [blame] | 708 | |
Heinz Mauelshagen | 61e06e2 | 2017-12-02 01:03:51 +0100 | [diff] [blame] | 709 | /* |
| 710 | * Change bdev capacity of @rs in case of a disk add/remove reshape |
| 711 | */ |
| 712 | static void rs_set_capacity(struct raid_set *rs) |
| 713 | { |
| 714 | struct gendisk *gendisk = dm_disk(dm_table_get_md(rs->ti->table)); |
| 715 | |
| 716 | set_capacity(gendisk, rs->md.array_sectors); |
Heinz Mauelshagen | 0095dbc | 2016-06-24 00:10:12 +0200 | [diff] [blame] | 717 | revalidate_disk(gendisk); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /* |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 721 | * Set the mddev properties in @rs to the current |
| 722 | * ones retrieved from the freshest superblock |
| 723 | */ |
| 724 | static void rs_set_cur(struct raid_set *rs) |
| 725 | { |
| 726 | struct mddev *mddev = &rs->md; |
| 727 | |
| 728 | mddev->new_level = mddev->level; |
| 729 | mddev->new_layout = mddev->layout; |
| 730 | mddev->new_chunk_sectors = mddev->chunk_sectors; |
| 731 | } |
| 732 | |
| 733 | /* |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 734 | * Set the mddev properties in @rs to the new |
| 735 | * ones requested by the ctr |
| 736 | */ |
| 737 | static void rs_set_new(struct raid_set *rs) |
| 738 | { |
| 739 | struct mddev *mddev = &rs->md; |
| 740 | |
| 741 | mddev->level = mddev->new_level; |
| 742 | mddev->layout = mddev->new_layout; |
| 743 | mddev->chunk_sectors = mddev->new_chunk_sectors; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 744 | mddev->raid_disks = rs->raid_disks; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 745 | mddev->delta_disks = 0; |
| 746 | } |
| 747 | |
Mike Snitzer | bfcee0e | 2016-06-02 15:08:09 -0400 | [diff] [blame] | 748 | static struct raid_set *raid_set_alloc(struct dm_target *ti, struct raid_type *raid_type, |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 749 | unsigned int raid_devs) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 750 | { |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 751 | unsigned int i; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 752 | struct raid_set *rs; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 753 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 754 | if (raid_devs <= raid_type->parity_devs) { |
| 755 | ti->error = "Insufficient number of devices"; |
| 756 | return ERR_PTR(-EINVAL); |
| 757 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 758 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 759 | rs = kzalloc(sizeof(*rs) + raid_devs * sizeof(rs->dev[0]), GFP_KERNEL); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 760 | if (!rs) { |
| 761 | ti->error = "Cannot allocate raid context"; |
| 762 | return ERR_PTR(-ENOMEM); |
| 763 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 764 | |
| 765 | mddev_init(&rs->md); |
| 766 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 767 | INIT_LIST_HEAD(&rs->list); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 768 | rs->raid_disks = raid_devs; |
| 769 | rs->delta_disks = 0; |
| 770 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 771 | rs->ti = ti; |
| 772 | rs->raid_type = raid_type; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 773 | rs->stripe_cache_entries = 256; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 774 | rs->md.raid_disks = raid_devs; |
| 775 | rs->md.level = raid_type->level; |
| 776 | rs->md.new_level = rs->md.level; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 777 | rs->md.layout = raid_type->algorithm; |
| 778 | rs->md.new_layout = rs->md.layout; |
| 779 | rs->md.delta_disks = 0; |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 780 | rs->md.recovery_cp = MaxSector; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 781 | |
| 782 | for (i = 0; i < raid_devs; i++) |
| 783 | md_rdev_init(&rs->dev[i].rdev); |
| 784 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 785 | /* Add @rs to global list. */ |
| 786 | list_add(&rs->list, &raid_sets); |
| 787 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 788 | /* |
| 789 | * Remaining items to be initialized by further RAID params: |
| 790 | * rs->md.persistent |
| 791 | * rs->md.external |
| 792 | * rs->md.chunk_sectors |
| 793 | * rs->md.new_chunk_sectors |
Jonathan E Brassow | c039c33 | 2012-07-27 15:08:04 +0100 | [diff] [blame] | 794 | * rs->md.dev_sectors |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 795 | */ |
| 796 | |
| 797 | return rs; |
| 798 | } |
| 799 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 800 | /* Free all @rs allocations and remove it from global list. */ |
Mike Snitzer | bfcee0e | 2016-06-02 15:08:09 -0400 | [diff] [blame] | 801 | static void raid_set_free(struct raid_set *rs) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 802 | { |
| 803 | int i; |
| 804 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 805 | if (rs->journal_dev.dev) { |
| 806 | md_rdev_clear(&rs->journal_dev.rdev); |
| 807 | dm_put_device(rs->ti, rs->journal_dev.dev); |
| 808 | } |
| 809 | |
Heinz Mauelshagen | ffeeac7 | 2016-06-30 14:37:50 +0200 | [diff] [blame] | 810 | for (i = 0; i < rs->raid_disks; i++) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 811 | if (rs->dev[i].meta_dev) |
| 812 | dm_put_device(rs->ti, rs->dev[i].meta_dev); |
NeilBrown | 545c879 | 2012-05-22 13:54:30 +1000 | [diff] [blame] | 813 | md_rdev_clear(&rs->dev[i].rdev); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 814 | if (rs->dev[i].data_dev) |
| 815 | dm_put_device(rs->ti, rs->dev[i].data_dev); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 816 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 817 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 818 | list_del(&rs->list); |
| 819 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 820 | kfree(rs); |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | * For every device we have two words |
| 825 | * <meta_dev>: meta device name or '-' if missing |
| 826 | * <data_dev>: data device name or '-' if missing |
| 827 | * |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 828 | * The following are permitted: |
| 829 | * - - |
| 830 | * - <data_dev> |
| 831 | * <meta_dev> <data_dev> |
| 832 | * |
| 833 | * The following is not allowed: |
| 834 | * <meta_dev> - |
| 835 | * |
| 836 | * This code parses those words. If there is a failure, |
Mike Snitzer | bfcee0e | 2016-06-02 15:08:09 -0400 | [diff] [blame] | 837 | * the caller must use raid_set_free() to unwind the operations. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 838 | */ |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 839 | static int parse_dev_params(struct raid_set *rs, struct dm_arg_set *as) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 840 | { |
| 841 | int i; |
| 842 | int rebuild = 0; |
| 843 | int metadata_available = 0; |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 844 | int r = 0; |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 845 | const char *arg; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 846 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 847 | /* Put off the number of raid devices argument to get to dev pairs */ |
| 848 | arg = dm_shift_arg(as); |
| 849 | if (!arg) |
| 850 | return -EINVAL; |
| 851 | |
Heinz Mauelshagen | ffeeac7 | 2016-06-30 14:37:50 +0200 | [diff] [blame] | 852 | for (i = 0; i < rs->raid_disks; i++) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 853 | rs->dev[i].rdev.raid_disk = i; |
| 854 | |
| 855 | rs->dev[i].meta_dev = NULL; |
| 856 | rs->dev[i].data_dev = NULL; |
| 857 | |
| 858 | /* |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 859 | * There are no offsets initially. |
| 860 | * Out of place reshape will set them accordingly. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 861 | */ |
| 862 | rs->dev[i].rdev.data_offset = 0; |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 863 | rs->dev[i].rdev.new_data_offset = 0; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 864 | rs->dev[i].rdev.mddev = &rs->md; |
| 865 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 866 | arg = dm_shift_arg(as); |
| 867 | if (!arg) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | if (strcmp(arg, "-")) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 871 | r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), |
| 872 | &rs->dev[i].meta_dev); |
| 873 | if (r) { |
| 874 | rs->ti->error = "RAID metadata device lookup failure"; |
| 875 | return r; |
| 876 | } |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 877 | |
| 878 | rs->dev[i].rdev.sb_page = alloc_page(GFP_KERNEL); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 879 | if (!rs->dev[i].rdev.sb_page) { |
| 880 | rs->ti->error = "Failed to allocate superblock page"; |
| 881 | return -ENOMEM; |
| 882 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 885 | arg = dm_shift_arg(as); |
| 886 | if (!arg) |
| 887 | return -EINVAL; |
| 888 | |
| 889 | if (!strcmp(arg, "-")) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 890 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags) && |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 891 | (!rs->dev[i].rdev.recovery_offset)) { |
| 892 | rs->ti->error = "Drive designated for rebuild not specified"; |
| 893 | return -EINVAL; |
| 894 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 895 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 896 | if (rs->dev[i].meta_dev) { |
| 897 | rs->ti->error = "No data device supplied with metadata device"; |
| 898 | return -EINVAL; |
| 899 | } |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 900 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 901 | continue; |
| 902 | } |
| 903 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 904 | r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), |
| 905 | &rs->dev[i].data_dev); |
| 906 | if (r) { |
| 907 | rs->ti->error = "RAID device lookup failure"; |
| 908 | return r; |
| 909 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 910 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 911 | if (rs->dev[i].meta_dev) { |
| 912 | metadata_available = 1; |
| 913 | rs->dev[i].rdev.meta_bdev = rs->dev[i].meta_dev->bdev; |
| 914 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 915 | rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 916 | list_add_tail(&rs->dev[i].rdev.same_set, &rs->md.disks); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 917 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags)) |
| 918 | rebuild++; |
| 919 | } |
| 920 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 921 | if (rs->journal_dev.dev) |
| 922 | list_add_tail(&rs->journal_dev.rdev.same_set, &rs->md.disks); |
| 923 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 924 | if (metadata_available) { |
| 925 | rs->md.external = 0; |
| 926 | rs->md.persistent = 1; |
| 927 | rs->md.major_version = 2; |
| 928 | } else if (rebuild && !rs->md.recovery_cp) { |
| 929 | /* |
| 930 | * Without metadata, we will not be able to tell if the array |
| 931 | * is in-sync or not - we must assume it is not. Therefore, |
| 932 | * it is impossible to rebuild a drive. |
| 933 | * |
| 934 | * Even if there is metadata, the on-disk information may |
| 935 | * indicate that the array is not in-sync and it will then |
| 936 | * fail at that time. |
| 937 | * |
| 938 | * User could specify 'nosync' option if desperate. |
| 939 | */ |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 940 | rs->ti->error = "Unable to rebuild drive while array is not in-sync"; |
| 941 | return -EINVAL; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | /* |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 948 | * validate_region_size |
| 949 | * @rs |
| 950 | * @region_size: region size in sectors. If 0, pick a size (4MiB default). |
| 951 | * |
| 952 | * Set rs->md.bitmap_info.chunksize (which really refers to 'region size'). |
| 953 | * Ensure that (ti->len/region_size < 2^21) - required by MD bitmap. |
| 954 | * |
| 955 | * Returns: 0 on success, -EINVAL on failure. |
| 956 | */ |
| 957 | static int validate_region_size(struct raid_set *rs, unsigned long region_size) |
| 958 | { |
| 959 | unsigned long min_region_size = rs->ti->len / (1 << 21); |
| 960 | |
Heinz Mauelshagen | 9e7d936 | 2016-08-17 15:36:44 +0200 | [diff] [blame] | 961 | if (rs_is_raid0(rs)) |
| 962 | return 0; |
| 963 | |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 964 | if (!region_size) { |
| 965 | /* |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 966 | * Choose a reasonable default. All figures in sectors. |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 967 | */ |
| 968 | if (min_region_size > (1 << 13)) { |
Jonathan Brassow | 3a0f9aa | 2012-12-21 20:23:33 +0000 | [diff] [blame] | 969 | /* If not a power of 2, make it the next power of 2 */ |
Mikulas Patocka | 042745e | 2015-10-02 11:17:37 -0400 | [diff] [blame] | 970 | region_size = roundup_pow_of_two(min_region_size); |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 971 | DMINFO("Choosing default region size of %lu sectors", |
| 972 | region_size); |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 973 | } else { |
| 974 | DMINFO("Choosing default region size of 4MiB"); |
| 975 | region_size = 1 << 13; /* sectors */ |
| 976 | } |
| 977 | } else { |
| 978 | /* |
| 979 | * Validate user-supplied value. |
| 980 | */ |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 981 | if (region_size > rs->ti->len) { |
| 982 | rs->ti->error = "Supplied region size is too large"; |
| 983 | return -EINVAL; |
| 984 | } |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 985 | |
| 986 | if (region_size < min_region_size) { |
| 987 | DMERR("Supplied region_size (%lu sectors) below minimum (%lu)", |
| 988 | region_size, min_region_size); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 989 | rs->ti->error = "Supplied region size is too small"; |
| 990 | return -EINVAL; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 991 | } |
| 992 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 993 | if (!is_power_of_2(region_size)) { |
| 994 | rs->ti->error = "Region size is not a power of 2"; |
| 995 | return -EINVAL; |
| 996 | } |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 997 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 998 | if (region_size < rs->md.chunk_sectors) { |
| 999 | rs->ti->error = "Region size is smaller than the chunk size"; |
| 1000 | return -EINVAL; |
| 1001 | } |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | * Convert sectors to bytes. |
| 1006 | */ |
Heinz Mauelshagen | 89d3d9a | 2016-07-19 13:16:24 +0200 | [diff] [blame] | 1007 | rs->md.bitmap_info.chunksize = to_bytes(region_size); |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | /* |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1013 | * validate_raid_redundancy |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1014 | * @rs |
| 1015 | * |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1016 | * Determine if there are enough devices in the array that haven't |
| 1017 | * failed (or are being rebuilt) to form a usable array. |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1018 | * |
| 1019 | * Returns: 0 on success, -EINVAL on failure. |
| 1020 | */ |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1021 | static int validate_raid_redundancy(struct raid_set *rs) |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1022 | { |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 1023 | unsigned int i, rebuild_cnt = 0; |
| 1024 | unsigned int rebuilds_per_group = 0, copies; |
| 1025 | unsigned int group_size, last_group_start; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1026 | |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1027 | for (i = 0; i < rs->md.raid_disks; i++) |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1028 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags) || |
| 1029 | !rs->dev[i].rdev.sb_page) |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1030 | rebuild_cnt++; |
| 1031 | |
Heinz Mauelshagen | 53bf538 | 2017-12-13 17:13:17 +0100 | [diff] [blame] | 1032 | switch (rs->md.level) { |
Heinz Mauelshagen | 9e7d936 | 2016-08-17 15:36:44 +0200 | [diff] [blame] | 1033 | case 0: |
| 1034 | break; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1035 | case 1: |
| 1036 | if (rebuild_cnt >= rs->md.raid_disks) |
| 1037 | goto too_many; |
| 1038 | break; |
| 1039 | case 4: |
| 1040 | case 5: |
| 1041 | case 6: |
| 1042 | if (rebuild_cnt > rs->raid_type->parity_devs) |
| 1043 | goto too_many; |
| 1044 | break; |
| 1045 | case 10: |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1046 | copies = raid10_md_layout_to_copies(rs->md.new_layout); |
Heinz Mauelshagen | 53bf538 | 2017-12-13 17:13:17 +0100 | [diff] [blame] | 1047 | if (copies < 2) { |
| 1048 | DMERR("Bogus raid10 data copies < 2!"); |
| 1049 | return -EINVAL; |
| 1050 | } |
| 1051 | |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 1052 | if (rebuild_cnt < copies) |
| 1053 | break; |
| 1054 | |
| 1055 | /* |
| 1056 | * It is possible to have a higher rebuild count for RAID10, |
| 1057 | * as long as the failed devices occur in different mirror |
| 1058 | * groups (i.e. different stripes). |
| 1059 | * |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 1060 | * When checking "near" format, make sure no adjacent devices |
| 1061 | * have failed beyond what can be handled. In addition to the |
| 1062 | * simple case where the number of devices is a multiple of the |
| 1063 | * number of copies, we must also handle cases where the number |
| 1064 | * of devices is not a multiple of the number of copies. |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1065 | * E.g. dev1 dev2 dev3 dev4 dev5 |
| 1066 | * A A B B C |
| 1067 | * C D D E E |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 1068 | */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1069 | if (__is_raid10_near(rs->md.new_layout)) { |
Heinz Mauelshagen | ffeeac7 | 2016-06-30 14:37:50 +0200 | [diff] [blame] | 1070 | for (i = 0; i < rs->md.raid_disks; i++) { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1071 | if (!(i % copies)) |
| 1072 | rebuilds_per_group = 0; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1073 | if ((!rs->dev[i].rdev.sb_page || |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1074 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) && |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1075 | (++rebuilds_per_group >= copies)) |
| 1076 | goto too_many; |
| 1077 | } |
| 1078 | break; |
| 1079 | } |
| 1080 | |
| 1081 | /* |
| 1082 | * When checking "far" and "offset" formats, we need to ensure |
| 1083 | * that the device that holds its copy is not also dead or |
| 1084 | * being rebuilt. (Note that "far" and "offset" formats only |
| 1085 | * support two copies right now. These formats also only ever |
| 1086 | * use the 'use_far_sets' variant.) |
| 1087 | * |
| 1088 | * This check is somewhat complicated by the need to account |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1089 | * for arrays that are not a multiple of (far) copies. This |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1090 | * results in the need to treat the last (potentially larger) |
| 1091 | * set differently. |
| 1092 | */ |
| 1093 | group_size = (rs->md.raid_disks / copies); |
| 1094 | last_group_start = (rs->md.raid_disks / group_size) - 1; |
| 1095 | last_group_start *= group_size; |
| 1096 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 1097 | if (!(i % copies) && !(i > last_group_start)) |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1098 | rebuilds_per_group = 0; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1099 | if ((!rs->dev[i].rdev.sb_page || |
| 1100 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) && |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 1101 | (++rebuilds_per_group >= copies)) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1102 | goto too_many; |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 1103 | } |
| 1104 | break; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1105 | default: |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1106 | if (rebuild_cnt) |
| 1107 | return -EINVAL; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | return 0; |
| 1111 | |
| 1112 | too_many: |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 1113 | return -EINVAL; |
| 1114 | } |
| 1115 | |
| 1116 | /* |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1117 | * Possible arguments are... |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1118 | * <chunk_size> [optional_args] |
| 1119 | * |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1120 | * Argument definitions |
| 1121 | * <chunk_size> The number of sectors per disk that |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1122 | * will form the "stripe" |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1123 | * [[no]sync] Force or prevent recovery of the |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1124 | * entire array |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1125 | * [rebuild <idx>] Rebuild the drive indicated by the index |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1126 | * [daemon_sleep <ms>] Time between bitmap daemon work to |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1127 | * clear bits |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1128 | * [min_recovery_rate <kB/sec/disk>] Throttle RAID initialization |
| 1129 | * [max_recovery_rate <kB/sec/disk>] Throttle RAID initialization |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1130 | * [write_mostly <idx>] Indicate a write mostly drive via index |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1131 | * [max_write_behind <sectors>] See '-write-behind=' (man mdadm) |
| 1132 | * [stripe_cache <sectors>] Stripe cache size for higher RAIDs |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1133 | * [region_size <sectors>] Defines granularity of bitmap |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1134 | * [journal_dev <dev>] raid4/5/6 journaling deviice |
| 1135 | * (i.e. write hole closing log) |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1136 | * |
| 1137 | * RAID10-only options: |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1138 | * [raid10_copies <# copies>] Number of copies. (Default: 2) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1139 | * [raid10_format <near|far|offset>] Layout algorithm. (Default: near) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1140 | */ |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 1141 | static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 1142 | unsigned int num_raid_params) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1143 | { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1144 | int value, raid10_format = ALGORITHM_RAID10_DEFAULT; |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 1145 | unsigned int raid10_copies = 2; |
| 1146 | unsigned int i, write_mostly = 0; |
| 1147 | unsigned int region_size = 0; |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1148 | sector_t max_io_len; |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 1149 | const char *arg, *key; |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1150 | struct raid_dev *rd; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1151 | struct raid_type *rt = rs->raid_type; |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 1152 | |
| 1153 | arg = dm_shift_arg(as); |
| 1154 | num_raid_params--; /* Account for chunk_size argument */ |
| 1155 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1156 | if (kstrtoint(arg, 10, &value) < 0) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1157 | rs->ti->error = "Bad numerical argument given for chunk_size"; |
| 1158 | return -EINVAL; |
| 1159 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1160 | |
| 1161 | /* |
| 1162 | * First, parse the in-order required arguments |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1163 | * "chunk_size" is the only argument of this type. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1164 | */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1165 | if (rt_is_raid1(rt)) { |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1166 | if (value) |
| 1167 | DMERR("Ignoring chunk size parameter for RAID 1"); |
| 1168 | value = 0; |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1169 | } else if (!is_power_of_2(value)) { |
| 1170 | rs->ti->error = "Chunk size must be a power of 2"; |
| 1171 | return -EINVAL; |
| 1172 | } else if (value < 8) { |
| 1173 | rs->ti->error = "Chunk size value is too small"; |
| 1174 | return -EINVAL; |
| 1175 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1176 | |
| 1177 | rs->md.new_chunk_sectors = rs->md.chunk_sectors = value; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1178 | |
| 1179 | /* |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1180 | * We set each individual device as In_sync with a completed |
| 1181 | * 'recovery_offset'. If there has been a device failure or |
| 1182 | * replacement then one of the following cases applies: |
| 1183 | * |
| 1184 | * 1) User specifies 'rebuild'. |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1185 | * - Device is reset when param is read. |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1186 | * 2) A new device is supplied. |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1187 | * - No matching superblock found, resets device. |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1188 | * 3) Device failure was transient and returns on reload. |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1189 | * - Failure noticed, resets device for bitmap replay. |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1190 | * 4) Device hadn't completed recovery after previous failure. |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1191 | * - Superblock is read and overrides recovery_offset. |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1192 | * |
| 1193 | * What is found in the superblocks of the devices is always |
| 1194 | * authoritative, unless 'rebuild' or '[no]sync' was specified. |
| 1195 | */ |
Heinz Mauelshagen | ffeeac7 | 2016-06-30 14:37:50 +0200 | [diff] [blame] | 1196 | for (i = 0; i < rs->raid_disks; i++) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1197 | set_bit(In_sync, &rs->dev[i].rdev.flags); |
| 1198 | rs->dev[i].rdev.recovery_offset = MaxSector; |
| 1199 | } |
| 1200 | |
| 1201 | /* |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1202 | * Second, parse the unordered optional arguments |
| 1203 | */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1204 | for (i = 0; i < num_raid_params; i++) { |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1205 | key = dm_shift_arg(as); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1206 | if (!key) { |
| 1207 | rs->ti->error = "Not enough raid parameters given"; |
| 1208 | return -EINVAL; |
| 1209 | } |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 1210 | |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1211 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_NOSYNC))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1212 | if (test_and_set_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1213 | rs->ti->error = "Only one 'nosync' argument allowed"; |
| 1214 | return -EINVAL; |
| 1215 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1216 | continue; |
| 1217 | } |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1218 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_SYNC))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1219 | if (test_and_set_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1220 | rs->ti->error = "Only one 'sync' argument allowed"; |
| 1221 | return -EINVAL; |
| 1222 | } |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1223 | continue; |
| 1224 | } |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1225 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_RAID10_USE_NEAR_SETS))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1226 | if (test_and_set_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1227 | rs->ti->error = "Only one 'raid10_use_new_sets' argument allowed"; |
| 1228 | return -EINVAL; |
| 1229 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1230 | continue; |
| 1231 | } |
| 1232 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 1233 | arg = dm_shift_arg(as); |
| 1234 | i++; /* Account for the argument pairs */ |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1235 | if (!arg) { |
| 1236 | rs->ti->error = "Wrong number of raid parameters given"; |
| 1237 | return -EINVAL; |
| 1238 | } |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1239 | |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1240 | /* |
| 1241 | * Parameters that take a string value are checked here. |
| 1242 | */ |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1243 | /* "raid10_format {near|offset|far} */ |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1244 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_RAID10_FORMAT))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1245 | if (test_and_set_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1246 | rs->ti->error = "Only one 'raid10_format' argument pair allowed"; |
| 1247 | return -EINVAL; |
| 1248 | } |
| 1249 | if (!rt_is_raid10(rt)) { |
| 1250 | rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type"; |
| 1251 | return -EINVAL; |
| 1252 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1253 | raid10_format = raid10_name_to_format(arg); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1254 | if (raid10_format < 0) { |
| 1255 | rs->ti->error = "Invalid 'raid10_format' value given"; |
| 1256 | return raid10_format; |
| 1257 | } |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1258 | continue; |
| 1259 | } |
| 1260 | |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 1261 | /* "journal_dev <dev>" */ |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1262 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_JOURNAL_DEV))) { |
| 1263 | int r; |
| 1264 | struct md_rdev *jdev; |
| 1265 | |
| 1266 | if (test_and_set_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { |
| 1267 | rs->ti->error = "Only one raid4/5/6 set journaling device allowed"; |
| 1268 | return -EINVAL; |
| 1269 | } |
| 1270 | if (!rt_is_raid456(rt)) { |
| 1271 | rs->ti->error = "'journal_dev' is an invalid parameter for this RAID type"; |
| 1272 | return -EINVAL; |
| 1273 | } |
| 1274 | r = dm_get_device(rs->ti, arg, dm_table_get_mode(rs->ti->table), |
| 1275 | &rs->journal_dev.dev); |
| 1276 | if (r) { |
| 1277 | rs->ti->error = "raid4/5/6 journal device lookup failure"; |
| 1278 | return r; |
| 1279 | } |
| 1280 | jdev = &rs->journal_dev.rdev; |
| 1281 | md_rdev_init(jdev); |
| 1282 | jdev->mddev = &rs->md; |
| 1283 | jdev->bdev = rs->journal_dev.dev->bdev; |
| 1284 | jdev->sectors = to_sector(i_size_read(jdev->bdev->bd_inode)); |
| 1285 | if (jdev->sectors < MIN_RAID456_JOURNAL_SPACE) { |
| 1286 | rs->ti->error = "No space for raid4/5/6 journal"; |
| 1287 | return -ENOSPC; |
| 1288 | } |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 1289 | rs->journal_dev.mode = R5C_JOURNAL_MODE_WRITE_THROUGH; |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1290 | set_bit(Journal, &jdev->flags); |
| 1291 | continue; |
| 1292 | } |
| 1293 | |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 1294 | /* "journal_mode <mode>" ("journal_dev" mandatory!) */ |
| 1295 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_JOURNAL_MODE))) { |
| 1296 | int r; |
| 1297 | |
| 1298 | if (!test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { |
| 1299 | rs->ti->error = "raid4/5/6 'journal_mode' is invalid without 'journal_dev'"; |
| 1300 | return -EINVAL; |
| 1301 | } |
| 1302 | if (test_and_set_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { |
| 1303 | rs->ti->error = "Only one raid4/5/6 'journal_mode' argument allowed"; |
| 1304 | return -EINVAL; |
| 1305 | } |
| 1306 | r = dm_raid_journal_mode_to_md(arg); |
| 1307 | if (r < 0) { |
| 1308 | rs->ti->error = "Invalid 'journal_mode' argument"; |
| 1309 | return r; |
| 1310 | } |
| 1311 | rs->journal_dev.mode = r; |
| 1312 | continue; |
| 1313 | } |
| 1314 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1315 | /* |
| 1316 | * Parameters with number values from here on. |
| 1317 | */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1318 | if (kstrtoint(arg, 10, &value) < 0) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1319 | rs->ti->error = "Bad numerical argument given in raid params"; |
| 1320 | return -EINVAL; |
| 1321 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1322 | |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1323 | if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_REBUILD))) { |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1324 | /* |
| 1325 | * "rebuild" is being passed in by userspace to provide |
| 1326 | * indexes of replaced devices and to set up additional |
| 1327 | * devices on raid level takeover. |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 1328 | */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1329 | if (!__within_range(value, 0, rs->raid_disks - 1)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1330 | rs->ti->error = "Invalid rebuild index given"; |
| 1331 | return -EINVAL; |
| 1332 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1333 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1334 | if (test_and_set_bit(value, (void *) rs->rebuild_disks)) { |
| 1335 | rs->ti->error = "rebuild for this index already given"; |
| 1336 | return -EINVAL; |
| 1337 | } |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1338 | |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1339 | rd = rs->dev + value; |
| 1340 | clear_bit(In_sync, &rd->rdev.flags); |
| 1341 | clear_bit(Faulty, &rd->rdev.flags); |
| 1342 | rd->rdev.recovery_offset = 0; |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1343 | set_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags); |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1344 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_WRITE_MOSTLY))) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1345 | if (!rt_is_raid1(rt)) { |
| 1346 | rs->ti->error = "write_mostly option is only valid for RAID1"; |
| 1347 | return -EINVAL; |
| 1348 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1349 | |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1350 | if (!__within_range(value, 0, rs->md.raid_disks - 1)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1351 | rs->ti->error = "Invalid write_mostly index given"; |
| 1352 | return -EINVAL; |
| 1353 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1354 | |
Heinz Mauelshagen | 5fa146b | 2016-06-15 18:50:18 +0200 | [diff] [blame] | 1355 | write_mostly++; |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1356 | set_bit(WriteMostly, &rs->dev[value].rdev.flags); |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1357 | set_bit(__CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags); |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1358 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_MAX_WRITE_BEHIND))) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1359 | if (!rt_is_raid1(rt)) { |
| 1360 | rs->ti->error = "max_write_behind option is only valid for RAID1"; |
| 1361 | return -EINVAL; |
| 1362 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1363 | |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1364 | if (test_and_set_bit(__CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1365 | rs->ti->error = "Only one max_write_behind argument pair allowed"; |
| 1366 | return -EINVAL; |
| 1367 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1368 | |
| 1369 | /* |
| 1370 | * In device-mapper, we specify things in sectors, but |
| 1371 | * MD records this value in kB |
| 1372 | */ |
| 1373 | value /= 2; |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1374 | if (value > COUNTER_MAX) { |
| 1375 | rs->ti->error = "Max write-behind limit out of range"; |
| 1376 | return -EINVAL; |
| 1377 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1378 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1379 | rs->md.bitmap_info.max_write_behind = value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1380 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_DAEMON_SLEEP))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1381 | if (test_and_set_bit(__CTR_FLAG_DAEMON_SLEEP, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1382 | rs->ti->error = "Only one daemon_sleep argument pair allowed"; |
| 1383 | return -EINVAL; |
| 1384 | } |
| 1385 | if (!value || (value > MAX_SCHEDULE_TIMEOUT)) { |
| 1386 | rs->ti->error = "daemon sleep period out of range"; |
| 1387 | return -EINVAL; |
| 1388 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1389 | rs->md.bitmap_info.daemon_sleep = value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1390 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_DATA_OFFSET))) { |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1391 | /* Userspace passes new data_offset after having extended the the data image LV */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1392 | if (test_and_set_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1393 | rs->ti->error = "Only one data_offset argument pair allowed"; |
| 1394 | return -EINVAL; |
| 1395 | } |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1396 | /* Ensure sensible data offset */ |
Heinz Mauelshagen | 75dd3b9 | 2016-06-15 22:27:08 +0200 | [diff] [blame] | 1397 | if (value < 0 || |
| 1398 | (value && (value < MIN_FREE_RESHAPE_SPACE || value % to_sector(PAGE_SIZE)))) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1399 | rs->ti->error = "Bogus data_offset value"; |
| 1400 | return -EINVAL; |
| 1401 | } |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1402 | rs->data_offset = value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1403 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_DELTA_DISKS))) { |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1404 | /* Define the +/-# of disks to add to/remove from the given raid set */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1405 | if (test_and_set_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1406 | rs->ti->error = "Only one delta_disks argument pair allowed"; |
| 1407 | return -EINVAL; |
| 1408 | } |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1409 | /* Ensure MAX_RAID_DEVICES and raid type minimal_devs! */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1410 | if (!__within_range(abs(value), 1, MAX_RAID_DEVICES - rt->minimal_devs)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1411 | rs->ti->error = "Too many delta_disk requested"; |
| 1412 | return -EINVAL; |
| 1413 | } |
Heinz Mauelshagen | 4763e54 | 2016-05-19 18:49:31 +0200 | [diff] [blame] | 1414 | |
| 1415 | rs->delta_disks = value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1416 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_STRIPE_CACHE))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1417 | if (test_and_set_bit(__CTR_FLAG_STRIPE_CACHE, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1418 | rs->ti->error = "Only one stripe_cache argument pair allowed"; |
| 1419 | return -EINVAL; |
| 1420 | } |
| 1421 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1422 | if (!rt_is_raid456(rt)) { |
| 1423 | rs->ti->error = "Inappropriate argument: stripe_cache"; |
| 1424 | return -EINVAL; |
| 1425 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1426 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1427 | rs->stripe_cache_entries = value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1428 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_MIN_RECOVERY_RATE))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1429 | if (test_and_set_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1430 | rs->ti->error = "Only one min_recovery_rate argument pair allowed"; |
| 1431 | return -EINVAL; |
| 1432 | } |
| 1433 | if (value > INT_MAX) { |
| 1434 | rs->ti->error = "min_recovery_rate out of range"; |
| 1435 | return -EINVAL; |
| 1436 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1437 | rs->md.sync_speed_min = (int)value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1438 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_MAX_RECOVERY_RATE))) { |
Heinz Mauelshagen | f15f64d | 2016-07-27 23:34:01 +0200 | [diff] [blame] | 1439 | if (test_and_set_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1440 | rs->ti->error = "Only one max_recovery_rate argument pair allowed"; |
| 1441 | return -EINVAL; |
| 1442 | } |
| 1443 | if (value > INT_MAX) { |
| 1444 | rs->ti->error = "max_recovery_rate out of range"; |
| 1445 | return -EINVAL; |
| 1446 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1447 | rs->md.sync_speed_max = (int)value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1448 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_REGION_SIZE))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1449 | if (test_and_set_bit(__CTR_FLAG_REGION_SIZE, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1450 | rs->ti->error = "Only one region_size argument pair allowed"; |
| 1451 | return -EINVAL; |
| 1452 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1453 | |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1454 | region_size = value; |
Heinz Mauelshagen | 4257e08 | 2016-06-14 01:46:03 +0200 | [diff] [blame] | 1455 | rs->requested_bitmap_chunk_sectors = value; |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 1456 | } else if (!strcasecmp(key, dm_raid_arg_name_by_flag(CTR_FLAG_RAID10_COPIES))) { |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1457 | if (test_and_set_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1458 | rs->ti->error = "Only one raid10_copies argument pair allowed"; |
| 1459 | return -EINVAL; |
| 1460 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1461 | |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1462 | if (!__within_range(value, 2, rs->md.raid_disks)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1463 | rs->ti->error = "Bad value for 'raid10_copies'"; |
| 1464 | return -EINVAL; |
| 1465 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1466 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1467 | raid10_copies = value; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1468 | } else { |
| 1469 | DMERR("Unable to parse RAID parameter: %s", key); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1470 | rs->ti->error = "Unable to parse RAID parameter"; |
| 1471 | return -EINVAL; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
Heinz Mauelshagen | 0d851d1 | 2016-06-15 18:43:55 +0200 | [diff] [blame] | 1475 | if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) && |
| 1476 | test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { |
| 1477 | rs->ti->error = "sync and nosync are mutually exclusive"; |
| 1478 | return -EINVAL; |
| 1479 | } |
| 1480 | |
Heinz Mauelshagen | 37f10be | 2016-06-24 23:21:37 +0200 | [diff] [blame] | 1481 | if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && |
| 1482 | (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) || |
| 1483 | test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags))) { |
| 1484 | rs->ti->error = "sync/nosync and rebuild are mutually exclusive"; |
| 1485 | return -EINVAL; |
| 1486 | } |
| 1487 | |
Heinz Mauelshagen | 5fa146b | 2016-06-15 18:50:18 +0200 | [diff] [blame] | 1488 | if (write_mostly >= rs->md.raid_disks) { |
| 1489 | rs->ti->error = "Can't set all raid1 devices to write_mostly"; |
| 1490 | return -EINVAL; |
| 1491 | } |
| 1492 | |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1493 | if (validate_region_size(rs, region_size)) |
| 1494 | return -EINVAL; |
| 1495 | |
| 1496 | if (rs->md.chunk_sectors) |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1497 | max_io_len = rs->md.chunk_sectors; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1498 | else |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1499 | max_io_len = region_size; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1500 | |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1501 | if (dm_set_target_max_io_len(rs->ti, max_io_len)) |
| 1502 | return -EINVAL; |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1503 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1504 | if (rt_is_raid10(rt)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1505 | if (raid10_copies > rs->md.raid_disks) { |
| 1506 | rs->ti->error = "Not enough devices to satisfy specification"; |
| 1507 | return -EINVAL; |
| 1508 | } |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1509 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1510 | rs->md.new_layout = raid10_format_to_md_layout(rs, raid10_format, raid10_copies); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1511 | if (rs->md.new_layout < 0) { |
| 1512 | rs->ti->error = "Error getting raid10 format"; |
| 1513 | return rs->md.new_layout; |
| 1514 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1515 | |
| 1516 | rt = get_raid_type_by_ll(10, rs->md.new_layout); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1517 | if (!rt) { |
| 1518 | rs->ti->error = "Failed to recognize new raid10 layout"; |
| 1519 | return -EINVAL; |
| 1520 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1521 | |
| 1522 | if ((rt->algorithm == ALGORITHM_RAID10_DEFAULT || |
| 1523 | rt->algorithm == ALGORITHM_RAID10_NEAR) && |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 1524 | test_bit(__CTR_FLAG_RAID10_USE_NEAR_SETS, &rs->ctr_flags)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1525 | rs->ti->error = "RAID10 format 'near' and 'raid10_use_near_sets' are incompatible"; |
| 1526 | return -EINVAL; |
| 1527 | } |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1528 | } |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 1529 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1530 | rs->raid10_copies = raid10_copies; |
Jonathan E Brassow | c039c33 | 2012-07-27 15:08:04 +0100 | [diff] [blame] | 1531 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1532 | /* Assume there are no metadata devices until the drives are parsed */ |
| 1533 | rs->md.persistent = 0; |
| 1534 | rs->md.external = 1; |
| 1535 | |
Heinz Mauelshagen | f090279 | 2016-05-19 18:49:27 +0200 | [diff] [blame] | 1536 | /* Check, if any invalid ctr arguments have been passed in for the raid level */ |
Heinz Mauelshagen | a30cbc0 | 2016-06-09 16:42:16 +0200 | [diff] [blame] | 1537 | return rs_check_for_valid_flags(rs); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1540 | /* Set raid4/5/6 cache size */ |
| 1541 | static int rs_set_raid456_stripe_cache(struct raid_set *rs) |
| 1542 | { |
| 1543 | int r; |
| 1544 | struct r5conf *conf; |
| 1545 | struct mddev *mddev = &rs->md; |
| 1546 | uint32_t min_stripes = max(mddev->chunk_sectors, mddev->new_chunk_sectors) / 2; |
| 1547 | uint32_t nr_stripes = rs->stripe_cache_entries; |
| 1548 | |
| 1549 | if (!rt_is_raid456(rs->raid_type)) { |
| 1550 | rs->ti->error = "Inappropriate raid level; cannot change stripe_cache size"; |
| 1551 | return -EINVAL; |
| 1552 | } |
| 1553 | |
| 1554 | if (nr_stripes < min_stripes) { |
| 1555 | DMINFO("Adjusting requested %u stripe cache entries to %u to suit stripe size", |
| 1556 | nr_stripes, min_stripes); |
| 1557 | nr_stripes = min_stripes; |
| 1558 | } |
| 1559 | |
| 1560 | conf = mddev->private; |
| 1561 | if (!conf) { |
| 1562 | rs->ti->error = "Cannot change stripe_cache size on inactive RAID set"; |
| 1563 | return -EINVAL; |
| 1564 | } |
| 1565 | |
| 1566 | /* Try setting number of stripes in raid456 stripe cache */ |
| 1567 | if (conf->min_nr_stripes != nr_stripes) { |
| 1568 | r = raid5_set_cache_size(mddev, nr_stripes); |
| 1569 | if (r) { |
| 1570 | rs->ti->error = "Failed to set raid4/5/6 stripe cache size"; |
| 1571 | return r; |
| 1572 | } |
| 1573 | |
| 1574 | DMINFO("%u stripe cache entries", nr_stripes); |
| 1575 | } |
| 1576 | |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 1580 | /* Return # of data stripes as kept in mddev as of @rs (i.e. as of superblock) */ |
| 1581 | static unsigned int mddev_data_stripes(struct raid_set *rs) |
| 1582 | { |
| 1583 | return rs->md.raid_disks - rs->raid_type->parity_devs; |
| 1584 | } |
| 1585 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1586 | /* Return # of data stripes of @rs (i.e. as of ctr) */ |
| 1587 | static unsigned int rs_data_stripes(struct raid_set *rs) |
| 1588 | { |
| 1589 | return rs->raid_disks - rs->raid_type->parity_devs; |
| 1590 | } |
| 1591 | |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 1592 | /* |
| 1593 | * Retrieve rdev->sectors from any valid raid device of @rs |
| 1594 | * to allow userpace to pass in arbitray "- -" device tupples. |
| 1595 | */ |
| 1596 | static sector_t __rdev_sectors(struct raid_set *rs) |
| 1597 | { |
| 1598 | int i; |
| 1599 | |
| 1600 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 1601 | struct md_rdev *rdev = &rs->dev[i].rdev; |
| 1602 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1603 | if (!test_bit(Journal, &rdev->flags) && |
| 1604 | rdev->bdev && rdev->sectors) |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 1605 | return rdev->sectors; |
| 1606 | } |
| 1607 | |
Heinz Mauelshagen | 4d49f1b | 2017-06-30 15:45:58 +0200 | [diff] [blame] | 1608 | return 0; |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 1609 | } |
| 1610 | |
Heinz Mauelshagen | 188a212 | 2017-12-02 01:03:59 +0100 | [diff] [blame] | 1611 | /* Check that calculated dev_sectors fits all component devices. */ |
| 1612 | static int _check_data_dev_sectors(struct raid_set *rs) |
| 1613 | { |
| 1614 | sector_t ds = ~0; |
| 1615 | struct md_rdev *rdev; |
| 1616 | |
| 1617 | rdev_for_each(rdev, &rs->md) |
| 1618 | if (!test_bit(Journal, &rdev->flags) && rdev->bdev) { |
| 1619 | ds = min(ds, to_sector(i_size_read(rdev->bdev->bd_inode))); |
| 1620 | if (ds < rs->md.dev_sectors) { |
| 1621 | rs->ti->error = "Component device(s) too small"; |
| 1622 | return -EINVAL; |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | return 0; |
| 1627 | } |
| 1628 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1629 | /* Calculate the sectors per device and per array used for @rs */ |
| 1630 | static int rs_set_dev_and_array_sectors(struct raid_set *rs, bool use_mddev) |
| 1631 | { |
| 1632 | int delta_disks; |
| 1633 | unsigned int data_stripes; |
| 1634 | struct mddev *mddev = &rs->md; |
| 1635 | struct md_rdev *rdev; |
| 1636 | sector_t array_sectors = rs->ti->len, dev_sectors = rs->ti->len; |
| 1637 | |
| 1638 | if (use_mddev) { |
| 1639 | delta_disks = mddev->delta_disks; |
| 1640 | data_stripes = mddev_data_stripes(rs); |
| 1641 | } else { |
| 1642 | delta_disks = rs->delta_disks; |
| 1643 | data_stripes = rs_data_stripes(rs); |
| 1644 | } |
| 1645 | |
| 1646 | /* Special raid1 case w/o delta_disks support (yet) */ |
| 1647 | if (rt_is_raid1(rs->raid_type)) |
| 1648 | ; |
| 1649 | else if (rt_is_raid10(rs->raid_type)) { |
| 1650 | if (rs->raid10_copies < 2 || |
| 1651 | delta_disks < 0) { |
| 1652 | rs->ti->error = "Bogus raid10 data copies or delta disks"; |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 1653 | return -EINVAL; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | dev_sectors *= rs->raid10_copies; |
| 1657 | if (sector_div(dev_sectors, data_stripes)) |
| 1658 | goto bad; |
| 1659 | |
| 1660 | array_sectors = (data_stripes + delta_disks) * dev_sectors; |
| 1661 | if (sector_div(array_sectors, rs->raid10_copies)) |
| 1662 | goto bad; |
| 1663 | |
| 1664 | } else if (sector_div(dev_sectors, data_stripes)) |
| 1665 | goto bad; |
| 1666 | |
| 1667 | else |
| 1668 | /* Striped layouts */ |
| 1669 | array_sectors = (data_stripes + delta_disks) * dev_sectors; |
| 1670 | |
| 1671 | rdev_for_each(rdev, mddev) |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 1672 | if (!test_bit(Journal, &rdev->flags)) |
| 1673 | rdev->sectors = dev_sectors; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1674 | |
| 1675 | mddev->array_sectors = array_sectors; |
| 1676 | mddev->dev_sectors = dev_sectors; |
| 1677 | |
Heinz Mauelshagen | 188a212 | 2017-12-02 01:03:59 +0100 | [diff] [blame] | 1678 | return _check_data_dev_sectors(rs); |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1679 | bad: |
| 1680 | rs->ti->error = "Target length not divisible by number of data devices"; |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 1681 | return -EINVAL; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1682 | } |
| 1683 | |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 1684 | /* Setup recovery on @rs */ |
| 1685 | static void __rs_setup_recovery(struct raid_set *rs, sector_t dev_sectors) |
| 1686 | { |
| 1687 | /* raid0 does not recover */ |
| 1688 | if (rs_is_raid0(rs)) |
| 1689 | rs->md.recovery_cp = MaxSector; |
| 1690 | /* |
| 1691 | * A raid6 set has to be recovered either |
| 1692 | * completely or for the grown part to |
| 1693 | * ensure proper parity and Q-Syndrome |
| 1694 | */ |
| 1695 | else if (rs_is_raid6(rs)) |
| 1696 | rs->md.recovery_cp = dev_sectors; |
| 1697 | /* |
| 1698 | * Other raid set types may skip recovery |
| 1699 | * depending on the 'nosync' flag. |
| 1700 | */ |
| 1701 | else |
| 1702 | rs->md.recovery_cp = test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags) |
| 1703 | ? MaxSector : dev_sectors; |
| 1704 | } |
| 1705 | |
| 1706 | /* Setup recovery on @rs based on raid type, device size and 'nosync' flag */ |
| 1707 | static void rs_setup_recovery(struct raid_set *rs, sector_t dev_sectors) |
| 1708 | { |
| 1709 | if (!dev_sectors) |
| 1710 | /* New raid set or 'sync' flag provided */ |
| 1711 | __rs_setup_recovery(rs, 0); |
| 1712 | else if (dev_sectors == MaxSector) |
| 1713 | /* Prevent recovery */ |
| 1714 | __rs_setup_recovery(rs, MaxSector); |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 1715 | else if (__rdev_sectors(rs) < dev_sectors) |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 1716 | /* Grown raid set */ |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 1717 | __rs_setup_recovery(rs, __rdev_sectors(rs)); |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 1718 | else |
| 1719 | __rs_setup_recovery(rs, MaxSector); |
| 1720 | } |
| 1721 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1722 | static void do_table_event(struct work_struct *ws) |
| 1723 | { |
| 1724 | struct raid_set *rs = container_of(ws, struct raid_set, md.event_work); |
| 1725 | |
Heinz Mauelshagen | 9d9d939 | 2016-06-16 03:15:49 +0200 | [diff] [blame] | 1726 | smp_rmb(); /* Make sure we access most actual mddev properties */ |
Heinz Mauelshagen | 61e06e2 | 2017-12-02 01:03:51 +0100 | [diff] [blame] | 1727 | if (!rs_is_reshaping(rs)) { |
| 1728 | if (rs_is_raid10(rs)) |
| 1729 | rs_set_rdev_sectors(rs); |
Heinz Mauelshagen | 9d9d939 | 2016-06-16 03:15:49 +0200 | [diff] [blame] | 1730 | rs_set_capacity(rs); |
Heinz Mauelshagen | 61e06e2 | 2017-12-02 01:03:51 +0100 | [diff] [blame] | 1731 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1732 | dm_table_event(rs->ti->table); |
| 1733 | } |
| 1734 | |
| 1735 | static int raid_is_congested(struct dm_target_callbacks *cb, int bits) |
| 1736 | { |
| 1737 | struct raid_set *rs = container_of(cb, struct raid_set, callbacks); |
| 1738 | |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 1739 | return mddev_congested(&rs->md, bits); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1742 | /* |
| 1743 | * Make sure a valid takover (level switch) is being requested on @rs |
| 1744 | * |
| 1745 | * Conversions of raid sets from one MD personality to another |
| 1746 | * have to conform to restrictions which are enforced here. |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1747 | */ |
| 1748 | static int rs_check_takeover(struct raid_set *rs) |
| 1749 | { |
| 1750 | struct mddev *mddev = &rs->md; |
| 1751 | unsigned int near_copies; |
| 1752 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1753 | if (rs->md.degraded) { |
| 1754 | rs->ti->error = "Can't takeover degraded raid set"; |
| 1755 | return -EPERM; |
| 1756 | } |
| 1757 | |
| 1758 | if (rs_is_reshaping(rs)) { |
| 1759 | rs->ti->error = "Can't takeover reshaping raid set"; |
| 1760 | return -EPERM; |
| 1761 | } |
| 1762 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1763 | switch (mddev->level) { |
| 1764 | case 0: |
| 1765 | /* raid0 -> raid1/5 with one disk */ |
| 1766 | if ((mddev->new_level == 1 || mddev->new_level == 5) && |
| 1767 | mddev->raid_disks == 1) |
| 1768 | return 0; |
| 1769 | |
| 1770 | /* raid0 -> raid10 */ |
| 1771 | if (mddev->new_level == 10 && |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 1772 | !(rs->raid_disks % mddev->raid_disks)) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1773 | return 0; |
| 1774 | |
| 1775 | /* raid0 with multiple disks -> raid4/5/6 */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1776 | if (__within_range(mddev->new_level, 4, 6) && |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1777 | mddev->new_layout == ALGORITHM_PARITY_N && |
| 1778 | mddev->raid_disks > 1) |
| 1779 | return 0; |
| 1780 | |
| 1781 | break; |
| 1782 | |
| 1783 | case 10: |
| 1784 | /* Can't takeover raid10_offset! */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 1785 | if (__is_raid10_offset(mddev->layout)) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1786 | break; |
| 1787 | |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 1788 | near_copies = __raid10_near_copies(mddev->layout); |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1789 | |
| 1790 | /* raid10* -> raid0 */ |
| 1791 | if (mddev->new_level == 0) { |
| 1792 | /* Can takeover raid10_near with raid disks divisable by data copies! */ |
| 1793 | if (near_copies > 1 && |
| 1794 | !(mddev->raid_disks % near_copies)) { |
| 1795 | mddev->raid_disks /= near_copies; |
| 1796 | mddev->delta_disks = mddev->raid_disks; |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
| 1800 | /* Can takeover raid10_far */ |
| 1801 | if (near_copies == 1 && |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 1802 | __raid10_far_copies(mddev->layout) > 1) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1803 | return 0; |
| 1804 | |
| 1805 | break; |
| 1806 | } |
| 1807 | |
| 1808 | /* raid10_{near,far} -> raid1 */ |
| 1809 | if (mddev->new_level == 1 && |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 1810 | max(near_copies, __raid10_far_copies(mddev->layout)) == mddev->raid_disks) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1811 | return 0; |
| 1812 | |
| 1813 | /* raid10_{near,far} with 2 disks -> raid4/5 */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1814 | if (__within_range(mddev->new_level, 4, 5) && |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1815 | mddev->raid_disks == 2) |
| 1816 | return 0; |
| 1817 | break; |
| 1818 | |
| 1819 | case 1: |
| 1820 | /* raid1 with 2 disks -> raid4/5 */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1821 | if (__within_range(mddev->new_level, 4, 5) && |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1822 | mddev->raid_disks == 2) { |
| 1823 | mddev->degraded = 1; |
| 1824 | return 0; |
| 1825 | } |
| 1826 | |
| 1827 | /* raid1 -> raid0 */ |
| 1828 | if (mddev->new_level == 0 && |
| 1829 | mddev->raid_disks == 1) |
| 1830 | return 0; |
| 1831 | |
| 1832 | /* raid1 -> raid10 */ |
| 1833 | if (mddev->new_level == 10) |
| 1834 | return 0; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1835 | break; |
| 1836 | |
| 1837 | case 4: |
| 1838 | /* raid4 -> raid0 */ |
| 1839 | if (mddev->new_level == 0) |
| 1840 | return 0; |
| 1841 | |
| 1842 | /* raid4 -> raid1/5 with 2 disks */ |
| 1843 | if ((mddev->new_level == 1 || mddev->new_level == 5) && |
| 1844 | mddev->raid_disks == 2) |
| 1845 | return 0; |
| 1846 | |
| 1847 | /* raid4 -> raid5/6 with parity N */ |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1848 | if (__within_range(mddev->new_level, 5, 6) && |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1849 | mddev->layout == ALGORITHM_PARITY_N) |
| 1850 | return 0; |
| 1851 | break; |
| 1852 | |
| 1853 | case 5: |
| 1854 | /* raid5 with parity N -> raid0 */ |
| 1855 | if (mddev->new_level == 0 && |
| 1856 | mddev->layout == ALGORITHM_PARITY_N) |
| 1857 | return 0; |
| 1858 | |
| 1859 | /* raid5 with parity N -> raid4 */ |
| 1860 | if (mddev->new_level == 4 && |
| 1861 | mddev->layout == ALGORITHM_PARITY_N) |
| 1862 | return 0; |
| 1863 | |
| 1864 | /* raid5 with 2 disks -> raid1/4/10 */ |
| 1865 | if ((mddev->new_level == 1 || mddev->new_level == 4 || mddev->new_level == 10) && |
| 1866 | mddev->raid_disks == 2) |
| 1867 | return 0; |
| 1868 | |
Heinz Mauelshagen | 6ee0bae | 2016-06-15 22:29:09 +0200 | [diff] [blame] | 1869 | /* raid5_* -> raid6_*_6 with Q-Syndrome N (e.g. raid5_ra -> raid6_ra_6 */ |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1870 | if (mddev->new_level == 6 && |
| 1871 | ((mddev->layout == ALGORITHM_PARITY_N && mddev->new_layout == ALGORITHM_PARITY_N) || |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1872 | __within_range(mddev->new_layout, ALGORITHM_LEFT_ASYMMETRIC_6, ALGORITHM_RIGHT_SYMMETRIC_6))) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1873 | return 0; |
| 1874 | break; |
| 1875 | |
| 1876 | case 6: |
| 1877 | /* raid6 with parity N -> raid0 */ |
| 1878 | if (mddev->new_level == 0 && |
| 1879 | mddev->layout == ALGORITHM_PARITY_N) |
| 1880 | return 0; |
| 1881 | |
| 1882 | /* raid6 with parity N -> raid4 */ |
| 1883 | if (mddev->new_level == 4 && |
| 1884 | mddev->layout == ALGORITHM_PARITY_N) |
| 1885 | return 0; |
| 1886 | |
Heinz Mauelshagen | 6ee0bae | 2016-06-15 22:29:09 +0200 | [diff] [blame] | 1887 | /* raid6_*_n with Q-Syndrome N -> raid5_* */ |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1888 | if (mddev->new_level == 5 && |
| 1889 | ((mddev->layout == ALGORITHM_PARITY_N && mddev->new_layout == ALGORITHM_PARITY_N) || |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 1890 | __within_range(mddev->new_layout, ALGORITHM_LEFT_ASYMMETRIC, ALGORITHM_RIGHT_SYMMETRIC))) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1891 | return 0; |
| 1892 | |
| 1893 | default: |
| 1894 | break; |
| 1895 | } |
| 1896 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 1897 | rs->ti->error = "takeover not possible"; |
| 1898 | return -EINVAL; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | /* True if @rs requested to be taken over */ |
| 1902 | static bool rs_takeover_requested(struct raid_set *rs) |
| 1903 | { |
| 1904 | return rs->md.new_level != rs->md.level; |
| 1905 | } |
| 1906 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1907 | /* True if @rs is requested to reshape by ctr */ |
| 1908 | static bool rs_reshape_requested(struct raid_set *rs) |
| 1909 | { |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 1910 | bool change; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1911 | struct mddev *mddev = &rs->md; |
| 1912 | |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 1913 | if (rs_takeover_requested(rs)) |
| 1914 | return false; |
| 1915 | |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 1916 | if (rs_is_raid0(rs)) |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1917 | return false; |
| 1918 | |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 1919 | change = mddev->new_layout != mddev->layout || |
| 1920 | mddev->new_chunk_sectors != mddev->chunk_sectors || |
| 1921 | rs->delta_disks; |
| 1922 | |
| 1923 | /* Historical case to support raid1 reshape without delta disks */ |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 1924 | if (rs_is_raid1(rs)) { |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 1925 | if (rs->delta_disks) |
| 1926 | return !!rs->delta_disks; |
| 1927 | |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 1928 | return !change && |
| 1929 | mddev->raid_disks != rs->raid_disks; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 1930 | } |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 1931 | |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 1932 | if (rs_is_raid10(rs)) |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 1933 | return change && |
| 1934 | !__is_raid10_far(mddev->new_layout) && |
| 1935 | rs->delta_disks >= 0; |
| 1936 | |
| 1937 | return change; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1940 | /* Features */ |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 1941 | #define FEATURE_FLAG_SUPPORTS_V190 0x1 /* Supports extended superblock */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1942 | |
| 1943 | /* State flags for sb->flags */ |
| 1944 | #define SB_FLAG_RESHAPE_ACTIVE 0x1 |
| 1945 | #define SB_FLAG_RESHAPE_BACKWARDS 0x2 |
| 1946 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1947 | /* |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1948 | * This structure is never routinely used by userspace, unlike md superblocks. |
| 1949 | * Devices with this superblock should only ever be accessed via device-mapper. |
| 1950 | */ |
| 1951 | #define DM_RAID_MAGIC 0x64526D44 |
| 1952 | struct dm_raid_superblock { |
| 1953 | __le32 magic; /* "DmRd" */ |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 1954 | __le32 compat_features; /* Used to indicate compatible features (like 1.9.0 ondisk metadata extension) */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1955 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1956 | __le32 num_devices; /* Number of devices in this raid set. (Max 64) */ |
| 1957 | __le32 array_position; /* The position of this drive in the raid set */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1958 | |
| 1959 | __le64 events; /* Incremented by md when superblock updated */ |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 1960 | __le64 failed_devices; /* Pre 1.9.0 part of bit field of devices to */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1961 | /* indicate failures (see extension below) */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1962 | |
| 1963 | /* |
| 1964 | * This offset tracks the progress of the repair or replacement of |
| 1965 | * an individual drive. |
| 1966 | */ |
| 1967 | __le64 disk_recovery_offset; |
| 1968 | |
| 1969 | /* |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1970 | * This offset tracks the progress of the initial raid set |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1971 | * synchronisation/parity calculation. |
| 1972 | */ |
| 1973 | __le64 array_resync_offset; |
| 1974 | |
| 1975 | /* |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1976 | * raid characteristics |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1977 | */ |
| 1978 | __le32 level; |
| 1979 | __le32 layout; |
| 1980 | __le32 stripe_sectors; |
| 1981 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1982 | /******************************************************************** |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 1983 | * BELOW FOLLOW V1.9.0 EXTENSIONS TO THE PRISTINE SUPERBLOCK FORMAT!!! |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1984 | * |
Heinz Mauelshagen | c4d097d | 2017-06-23 17:27:01 +0200 | [diff] [blame] | 1985 | * FEATURE_FLAG_SUPPORTS_V190 in the compat_features member indicates that those exist |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 1986 | */ |
| 1987 | |
| 1988 | __le32 flags; /* Flags defining array states for reshaping */ |
| 1989 | |
| 1990 | /* |
| 1991 | * This offset tracks the progress of a raid |
| 1992 | * set reshape in order to be able to restart it |
| 1993 | */ |
| 1994 | __le64 reshape_position; |
| 1995 | |
| 1996 | /* |
| 1997 | * These define the properties of the array in case of an interrupted reshape |
| 1998 | */ |
| 1999 | __le32 new_level; |
| 2000 | __le32 new_layout; |
| 2001 | __le32 new_stripe_sectors; |
| 2002 | __le32 delta_disks; |
| 2003 | |
| 2004 | __le64 array_sectors; /* Array size in sectors */ |
| 2005 | |
| 2006 | /* |
| 2007 | * Sector offsets to data on devices (reshaping). |
| 2008 | * Needed to support out of place reshaping, thus |
| 2009 | * not writing over any stripes whilst converting |
| 2010 | * them from old to new layout |
| 2011 | */ |
| 2012 | __le64 data_offset; |
| 2013 | __le64 new_data_offset; |
| 2014 | |
| 2015 | __le64 sectors; /* Used device size in sectors */ |
| 2016 | |
| 2017 | /* |
| 2018 | * Additonal Bit field of devices indicating failures to support |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 2019 | * up to 256 devices with the 1.9.0 on-disk metadata format |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2020 | */ |
| 2021 | __le64 extended_failed_devices[DISKS_ARRAY_ELEMS - 1]; |
| 2022 | |
| 2023 | __le32 incompat_features; /* Used to indicate any incompatible features */ |
| 2024 | |
| 2025 | /* Always set rest up to logical block size to 0 when writing (see get_metadata_device() below). */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2026 | } __packed; |
| 2027 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2028 | /* |
| 2029 | * Check for reshape constraints on raid set @rs: |
| 2030 | * |
| 2031 | * - reshape function non-existent |
| 2032 | * - degraded set |
| 2033 | * - ongoing recovery |
| 2034 | * - ongoing reshape |
| 2035 | * |
| 2036 | * Returns 0 if none or -EPERM if given constraint |
| 2037 | * and error message reference in @errmsg |
| 2038 | */ |
| 2039 | static int rs_check_reshape(struct raid_set *rs) |
| 2040 | { |
| 2041 | struct mddev *mddev = &rs->md; |
| 2042 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2043 | if (!mddev->pers || !mddev->pers->check_reshape) |
| 2044 | rs->ti->error = "Reshape not supported"; |
| 2045 | else if (mddev->degraded) |
| 2046 | rs->ti->error = "Can't reshape degraded raid set"; |
| 2047 | else if (rs_is_recovering(rs)) |
| 2048 | rs->ti->error = "Convert request on recovering raid set prohibited"; |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 2049 | else if (rs_is_reshaping(rs)) |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2050 | rs->ti->error = "raid set already reshaping!"; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 2051 | else if (!(rs_is_raid1(rs) || rs_is_raid10(rs) || rs_is_raid456(rs))) |
| 2052 | rs->ti->error = "Reshaping only supported for raid1/4/5/6/10"; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2053 | else |
| 2054 | return 0; |
| 2055 | |
| 2056 | return -EPERM; |
| 2057 | } |
| 2058 | |
Heinz Mauelshagen | e256846 | 2017-01-14 03:53:10 +0100 | [diff] [blame] | 2059 | static int read_disk_sb(struct md_rdev *rdev, int size, bool force_reload) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2060 | { |
| 2061 | BUG_ON(!rdev->sb_page); |
| 2062 | |
Heinz Mauelshagen | e256846 | 2017-01-14 03:53:10 +0100 | [diff] [blame] | 2063 | if (rdev->sb_loaded && !force_reload) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2064 | return 0; |
| 2065 | |
Heinz Mauelshagen | e256846 | 2017-01-14 03:53:10 +0100 | [diff] [blame] | 2066 | rdev->sb_loaded = 0; |
| 2067 | |
Heinz Mauelshagen | 0a7b818 | 2016-06-15 18:45:56 +0200 | [diff] [blame] | 2068 | if (!sync_page_io(rdev, 0, size, rdev->sb_page, REQ_OP_READ, 0, true)) { |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 2069 | DMERR("Failed to read superblock of device at position %d", |
| 2070 | rdev->raid_disk); |
Jonathan Brassow | c32fb9e | 2012-05-22 13:55:31 +1000 | [diff] [blame] | 2071 | md_error(rdev->mddev, rdev); |
Heinz Mauelshagen | e256846 | 2017-01-14 03:53:10 +0100 | [diff] [blame] | 2072 | set_bit(Faulty, &rdev->flags); |
| 2073 | return -EIO; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | rdev->sb_loaded = 1; |
| 2077 | |
| 2078 | return 0; |
| 2079 | } |
| 2080 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2081 | static void sb_retrieve_failed_devices(struct dm_raid_superblock *sb, uint64_t *failed_devices) |
| 2082 | { |
| 2083 | failed_devices[0] = le64_to_cpu(sb->failed_devices); |
| 2084 | memset(failed_devices + 1, 0, sizeof(sb->extended_failed_devices)); |
| 2085 | |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2086 | if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2087 | int i = ARRAY_SIZE(sb->extended_failed_devices); |
| 2088 | |
| 2089 | while (i--) |
| 2090 | failed_devices[i+1] = le64_to_cpu(sb->extended_failed_devices[i]); |
| 2091 | } |
| 2092 | } |
| 2093 | |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2094 | static void sb_update_failed_devices(struct dm_raid_superblock *sb, uint64_t *failed_devices) |
| 2095 | { |
| 2096 | int i = ARRAY_SIZE(sb->extended_failed_devices); |
| 2097 | |
| 2098 | sb->failed_devices = cpu_to_le64(failed_devices[0]); |
| 2099 | while (i--) |
| 2100 | sb->extended_failed_devices[i] = cpu_to_le64(failed_devices[i+1]); |
| 2101 | } |
| 2102 | |
| 2103 | /* |
| 2104 | * Synchronize the superblock members with the raid set properties |
| 2105 | * |
| 2106 | * All superblock data is little endian. |
| 2107 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 2108 | static void super_sync(struct mddev *mddev, struct md_rdev *rdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2109 | { |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2110 | bool update_failed_devices = false; |
| 2111 | unsigned int i; |
| 2112 | uint64_t failed_devices[DISKS_ARRAY_ELEMS]; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2113 | struct dm_raid_superblock *sb; |
Jonathan Brassow | 81f382f | 2012-05-22 13:55:30 +1000 | [diff] [blame] | 2114 | struct raid_set *rs = container_of(mddev, struct raid_set, md); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2115 | |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2116 | /* No metadata device, no superblock */ |
| 2117 | if (!rdev->meta_bdev) |
| 2118 | return; |
| 2119 | |
| 2120 | BUG_ON(!rdev->sb_page); |
| 2121 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2122 | sb = page_address(rdev->sb_page); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2123 | |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2124 | sb_retrieve_failed_devices(sb, failed_devices); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2125 | |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2126 | for (i = 0; i < rs->raid_disks; i++) |
| 2127 | if (!rs->dev[i].data_dev || test_bit(Faulty, &rs->dev[i].rdev.flags)) { |
| 2128 | update_failed_devices = true; |
| 2129 | set_bit(i, (void *) failed_devices); |
| 2130 | } |
| 2131 | |
| 2132 | if (update_failed_devices) |
| 2133 | sb_update_failed_devices(sb, failed_devices); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2134 | |
| 2135 | sb->magic = cpu_to_le32(DM_RAID_MAGIC); |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 2136 | sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2137 | |
| 2138 | sb->num_devices = cpu_to_le32(mddev->raid_disks); |
| 2139 | sb->array_position = cpu_to_le32(rdev->raid_disk); |
| 2140 | |
| 2141 | sb->events = cpu_to_le64(mddev->events); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2142 | |
| 2143 | sb->disk_recovery_offset = cpu_to_le64(rdev->recovery_offset); |
| 2144 | sb->array_resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 2145 | |
| 2146 | sb->level = cpu_to_le32(mddev->level); |
| 2147 | sb->layout = cpu_to_le32(mddev->layout); |
| 2148 | sb->stripe_sectors = cpu_to_le32(mddev->chunk_sectors); |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2149 | |
Heinz Mauelshagen | c4d097d | 2017-06-23 17:27:01 +0200 | [diff] [blame] | 2150 | /******************************************************************** |
| 2151 | * BELOW FOLLOW V1.9.0 EXTENSIONS TO THE PRISTINE SUPERBLOCK FORMAT!!! |
| 2152 | * |
| 2153 | * FEATURE_FLAG_SUPPORTS_V190 in the compat_features member indicates that those exist |
| 2154 | */ |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2155 | sb->new_level = cpu_to_le32(mddev->new_level); |
| 2156 | sb->new_layout = cpu_to_le32(mddev->new_layout); |
| 2157 | sb->new_stripe_sectors = cpu_to_le32(mddev->new_chunk_sectors); |
| 2158 | |
| 2159 | sb->delta_disks = cpu_to_le32(mddev->delta_disks); |
| 2160 | |
| 2161 | smp_rmb(); /* Make sure we access most recent reshape position */ |
| 2162 | sb->reshape_position = cpu_to_le64(mddev->reshape_position); |
| 2163 | if (le64_to_cpu(sb->reshape_position) != MaxSector) { |
| 2164 | /* Flag ongoing reshape */ |
| 2165 | sb->flags |= cpu_to_le32(SB_FLAG_RESHAPE_ACTIVE); |
| 2166 | |
| 2167 | if (mddev->delta_disks < 0 || mddev->reshape_backwards) |
| 2168 | sb->flags |= cpu_to_le32(SB_FLAG_RESHAPE_BACKWARDS); |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2169 | } else { |
| 2170 | /* Clear reshape flags */ |
| 2171 | sb->flags &= ~(cpu_to_le32(SB_FLAG_RESHAPE_ACTIVE|SB_FLAG_RESHAPE_BACKWARDS)); |
| 2172 | } |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2173 | |
| 2174 | sb->array_sectors = cpu_to_le64(mddev->array_sectors); |
| 2175 | sb->data_offset = cpu_to_le64(rdev->data_offset); |
| 2176 | sb->new_data_offset = cpu_to_le64(rdev->new_data_offset); |
| 2177 | sb->sectors = cpu_to_le64(rdev->sectors); |
Heinz Mauelshagen | b2a4872 | 2016-08-03 17:47:04 +0200 | [diff] [blame] | 2178 | sb->incompat_features = cpu_to_le32(0); |
Heinz Mauelshagen | 7b34df7 | 2016-05-19 18:49:32 +0200 | [diff] [blame] | 2179 | |
| 2180 | /* Zero out the rest of the payload after the size of the superblock */ |
| 2181 | memset(sb + 1, 0, rdev->sb_size - sizeof(*sb)); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | /* |
| 2185 | * super_load |
| 2186 | * |
| 2187 | * This function creates a superblock if one is not found on the device |
| 2188 | * and will decide which superblock to use if there's a choice. |
| 2189 | * |
| 2190 | * Return: 1 if use rdev, 0 if use refdev, -Exxx otherwise |
| 2191 | */ |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 2192 | static int super_load(struct md_rdev *rdev, struct md_rdev *refdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2193 | { |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 2194 | int r; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2195 | struct dm_raid_superblock *sb; |
| 2196 | struct dm_raid_superblock *refsb; |
| 2197 | uint64_t events_sb, events_refsb; |
| 2198 | |
Heinz Mauelshagen | e256846 | 2017-01-14 03:53:10 +0100 | [diff] [blame] | 2199 | r = read_disk_sb(rdev, rdev->sb_size, false); |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 2200 | if (r) |
| 2201 | return r; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2202 | |
| 2203 | sb = page_address(rdev->sb_page); |
Jonathan E Brassow | 3aa3b2b | 2012-03-07 19:09:47 +0000 | [diff] [blame] | 2204 | |
| 2205 | /* |
| 2206 | * Two cases that we want to write new superblocks and rebuild: |
| 2207 | * 1) New device (no matching magic number) |
| 2208 | * 2) Device specified for rebuild (!In_sync w/ offset == 0) |
| 2209 | */ |
| 2210 | if ((sb->magic != cpu_to_le32(DM_RAID_MAGIC)) || |
| 2211 | (!test_bit(In_sync, &rdev->flags) && !rdev->recovery_offset)) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2212 | super_sync(rdev->mddev, rdev); |
| 2213 | |
| 2214 | set_bit(FirstUse, &rdev->flags); |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 2215 | sb->compat_features = cpu_to_le32(FEATURE_FLAG_SUPPORTS_V190); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2216 | |
| 2217 | /* Force writing of superblocks to disk */ |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 2218 | set_bit(MD_SB_CHANGE_DEVS, &rdev->mddev->sb_flags); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2219 | |
| 2220 | /* Any superblock is better than none, choose that if given */ |
| 2221 | return refdev ? 0 : 1; |
| 2222 | } |
| 2223 | |
| 2224 | if (!refdev) |
| 2225 | return 1; |
| 2226 | |
| 2227 | events_sb = le64_to_cpu(sb->events); |
| 2228 | |
| 2229 | refsb = page_address(refdev->sb_page); |
| 2230 | events_refsb = le64_to_cpu(refsb->events); |
| 2231 | |
| 2232 | return (events_sb > events_refsb) ? 1 : 0; |
| 2233 | } |
| 2234 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2235 | static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2236 | { |
| 2237 | int role; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2238 | unsigned int d; |
| 2239 | struct mddev *mddev = &rs->md; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2240 | uint64_t events_sb; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2241 | uint64_t failed_devices[DISKS_ARRAY_ELEMS]; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2242 | struct dm_raid_superblock *sb; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2243 | uint32_t new_devs = 0, rebuild_and_new = 0, rebuilds = 0; |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 2244 | struct md_rdev *r; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2245 | struct dm_raid_superblock *sb2; |
| 2246 | |
| 2247 | sb = page_address(rdev->sb_page); |
| 2248 | events_sb = le64_to_cpu(sb->events); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2249 | |
| 2250 | /* |
| 2251 | * Initialise to 1 if this is a new superblock. |
| 2252 | */ |
| 2253 | mddev->events = events_sb ? : 1; |
| 2254 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2255 | mddev->reshape_position = MaxSector; |
| 2256 | |
Heinz Mauelshagen | 453c2a8 | 2016-10-18 17:46:45 +0200 | [diff] [blame] | 2257 | mddev->raid_disks = le32_to_cpu(sb->num_devices); |
| 2258 | mddev->level = le32_to_cpu(sb->level); |
| 2259 | mddev->layout = le32_to_cpu(sb->layout); |
| 2260 | mddev->chunk_sectors = le32_to_cpu(sb->stripe_sectors); |
| 2261 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2262 | /* |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2263 | * Reshaping is supported, e.g. reshape_position is valid |
| 2264 | * in superblock and superblock content is authoritative. |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2265 | */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2266 | if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2267 | /* Superblock is authoritative wrt given raid set layout! */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2268 | mddev->new_level = le32_to_cpu(sb->new_level); |
| 2269 | mddev->new_layout = le32_to_cpu(sb->new_layout); |
| 2270 | mddev->new_chunk_sectors = le32_to_cpu(sb->new_stripe_sectors); |
| 2271 | mddev->delta_disks = le32_to_cpu(sb->delta_disks); |
| 2272 | mddev->array_sectors = le64_to_cpu(sb->array_sectors); |
| 2273 | |
| 2274 | /* raid was reshaping and got interrupted */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2275 | if (le32_to_cpu(sb->flags) & SB_FLAG_RESHAPE_ACTIVE) { |
| 2276 | if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2277 | DMERR("Reshape requested but raid set is still reshaping"); |
| 2278 | return -EINVAL; |
| 2279 | } |
| 2280 | |
| 2281 | if (mddev->delta_disks < 0 || |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2282 | (!mddev->delta_disks && (le32_to_cpu(sb->flags) & SB_FLAG_RESHAPE_BACKWARDS))) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2283 | mddev->reshape_backwards = 1; |
| 2284 | else |
| 2285 | mddev->reshape_backwards = 0; |
| 2286 | |
| 2287 | mddev->reshape_position = le64_to_cpu(sb->reshape_position); |
| 2288 | rs->raid_type = get_raid_type_by_ll(mddev->level, mddev->layout); |
| 2289 | } |
| 2290 | |
| 2291 | } else { |
| 2292 | /* |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 2293 | * No takeover/reshaping, because we don't have the extended v1.9.0 metadata |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2294 | */ |
Heinz Mauelshagen | 453c2a8 | 2016-10-18 17:46:45 +0200 | [diff] [blame] | 2295 | struct raid_type *rt_cur = get_raid_type_by_ll(mddev->level, mddev->layout); |
| 2296 | struct raid_type *rt_new = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2297 | |
Heinz Mauelshagen | 453c2a8 | 2016-10-18 17:46:45 +0200 | [diff] [blame] | 2298 | if (rs_takeover_requested(rs)) { |
| 2299 | if (rt_cur && rt_new) |
| 2300 | DMERR("Takeover raid sets from %s to %s not yet supported by metadata. (raid level change)", |
| 2301 | rt_cur->name, rt_new->name); |
| 2302 | else |
| 2303 | DMERR("Takeover raid sets not yet supported by metadata. (raid level change)"); |
| 2304 | return -EINVAL; |
| 2305 | } else if (rs_reshape_requested(rs)) { |
| 2306 | DMERR("Reshaping raid sets not yet supported by metadata. (raid layout change keeping level)"); |
| 2307 | if (mddev->layout != mddev->new_layout) { |
| 2308 | if (rt_cur && rt_new) |
| 2309 | DMERR(" current layout %s vs new layout %s", |
| 2310 | rt_cur->name, rt_new->name); |
| 2311 | else |
| 2312 | DMERR(" current layout 0x%X vs new layout 0x%X", |
| 2313 | le32_to_cpu(sb->layout), mddev->new_layout); |
| 2314 | } |
| 2315 | if (mddev->chunk_sectors != mddev->new_chunk_sectors) |
| 2316 | DMERR(" current stripe sectors %u vs new stripe sectors %u", |
| 2317 | mddev->chunk_sectors, mddev->new_chunk_sectors); |
| 2318 | if (rs->delta_disks) |
| 2319 | DMERR(" current %u disks vs new %u disks", |
| 2320 | mddev->raid_disks, mddev->raid_disks + rs->delta_disks); |
| 2321 | if (rs_is_raid10(rs)) { |
| 2322 | DMERR(" Old layout: %s w/ %u copies", |
| 2323 | raid10_md_layout_to_format(mddev->layout), |
| 2324 | raid10_md_layout_to_copies(mddev->layout)); |
| 2325 | DMERR(" New layout: %s w/ %u copies", |
| 2326 | raid10_md_layout_to_format(mddev->new_layout), |
| 2327 | raid10_md_layout_to_copies(mddev->new_layout)); |
| 2328 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2329 | return -EINVAL; |
| 2330 | } |
| 2331 | |
Heinz Mauelshagen | b052b07 | 2016-10-17 21:20:07 +0200 | [diff] [blame] | 2332 | DMINFO("Discovered old metadata format; upgrading to extended metadata format"); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2333 | } |
| 2334 | |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2335 | if (!test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2336 | mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset); |
| 2337 | |
| 2338 | /* |
| 2339 | * During load, we set FirstUse if a new superblock was written. |
| 2340 | * There are two reasons we might not have a superblock: |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2341 | * 1) The raid set is brand new - in which case, all of the |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 2342 | * devices must have their In_sync bit set. Also, |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2343 | * recovery_cp must be 0, unless forced. |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2344 | * 2) This is a new device being added to an old raid set |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2345 | * and the new device needs to be rebuilt - in which |
| 2346 | * case the In_sync bit will /not/ be set and |
| 2347 | * recovery_cp must be MaxSector. |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2348 | * 3) This is/are a new device(s) being added to an old |
| 2349 | * raid set during takeover to a higher raid level |
| 2350 | * to provide capacity for redundancy or during reshape |
| 2351 | * to add capacity to grow the raid set. |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2352 | */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2353 | d = 0; |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 2354 | rdev_for_each(r, mddev) { |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2355 | if (test_bit(Journal, &rdev->flags)) |
| 2356 | continue; |
| 2357 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2358 | if (test_bit(FirstUse, &r->flags)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2359 | new_devs++; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2360 | |
| 2361 | if (!test_bit(In_sync, &r->flags)) { |
| 2362 | DMINFO("Device %d specified for rebuild; clearing superblock", |
| 2363 | r->raid_disk); |
| 2364 | rebuilds++; |
| 2365 | |
| 2366 | if (test_bit(FirstUse, &r->flags)) |
| 2367 | rebuild_and_new++; |
| 2368 | } |
| 2369 | |
| 2370 | d++; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2371 | } |
| 2372 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2373 | if (new_devs == rs->raid_disks || !rebuilds) { |
| 2374 | /* Replace a broken device */ |
| 2375 | if (new_devs == 1 && !rs->delta_disks) |
| 2376 | ; |
| 2377 | if (new_devs == rs->raid_disks) { |
| 2378 | DMINFO("Superblocks created for new raid set"); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2379 | set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2380 | } else if (new_devs != rebuilds && |
| 2381 | new_devs != rs->delta_disks) { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2382 | DMERR("New device injected into existing raid set without " |
| 2383 | "'delta_disks' or 'rebuild' parameter specified"); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2384 | return -EINVAL; |
| 2385 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2386 | } else if (new_devs && new_devs != rebuilds) { |
| 2387 | DMERR("%u 'rebuild' devices cannot be injected into" |
| 2388 | " a raid set with %u other first-time devices", |
| 2389 | rebuilds, new_devs); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2390 | return -EINVAL; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2391 | } else if (rebuilds) { |
| 2392 | if (rebuild_and_new && rebuilds != rebuild_and_new) { |
| 2393 | DMERR("new device%s provided without 'rebuild'", |
| 2394 | new_devs > 1 ? "s" : ""); |
| 2395 | return -EINVAL; |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 2396 | } else if (!test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags) && rs_is_recovering(rs)) { |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2397 | DMERR("'rebuild' specified while raid set is not in-sync (recovery_cp=%llu)", |
| 2398 | (unsigned long long) mddev->recovery_cp); |
| 2399 | return -EINVAL; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2400 | } else if (rs_is_reshaping(rs)) { |
| 2401 | DMERR("'rebuild' specified while raid set is being reshaped (reshape_position=%llu)", |
| 2402 | (unsigned long long) mddev->reshape_position); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2403 | return -EINVAL; |
| 2404 | } |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /* |
| 2408 | * Now we set the Faulty bit for those devices that are |
| 2409 | * recorded in the superblock as failed. |
| 2410 | */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2411 | sb_retrieve_failed_devices(sb, failed_devices); |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 2412 | rdev_for_each(r, mddev) { |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2413 | if (test_bit(Journal, &rdev->flags) || |
| 2414 | !r->sb_page) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2415 | continue; |
| 2416 | sb2 = page_address(r->sb_page); |
| 2417 | sb2->failed_devices = 0; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2418 | memset(sb2->extended_failed_devices, 0, sizeof(sb2->extended_failed_devices)); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2419 | |
| 2420 | /* |
| 2421 | * Check for any device re-ordering. |
| 2422 | */ |
| 2423 | if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { |
| 2424 | role = le32_to_cpu(sb2->array_position); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2425 | if (role < 0) |
| 2426 | continue; |
| 2427 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2428 | if (role != r->raid_disk) { |
Heinz Mauelshagen | 453c2a8 | 2016-10-18 17:46:45 +0200 | [diff] [blame] | 2429 | if (rs_is_raid10(rs) && __is_raid10_near(mddev->layout)) { |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 2430 | if (mddev->raid_disks % __raid10_near_copies(mddev->layout) || |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 2431 | rs->raid_disks % rs->raid10_copies) { |
| 2432 | rs->ti->error = |
| 2433 | "Cannot change raid10 near set to odd # of devices!"; |
| 2434 | return -EINVAL; |
| 2435 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2436 | |
| 2437 | sb2->array_position = cpu_to_le32(r->raid_disk); |
| 2438 | |
| 2439 | } else if (!(rs_is_raid10(rs) && rt_is_raid0(rs->raid_type)) && |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 2440 | !(rs_is_raid0(rs) && rt_is_raid10(rs->raid_type)) && |
| 2441 | !rt_is_raid1(rs->raid_type)) { |
| 2442 | rs->ti->error = "Cannot change device positions in raid set"; |
| 2443 | return -EINVAL; |
| 2444 | } |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2445 | |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 2446 | DMINFO("raid device #%d now at position #%d", role, r->raid_disk); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | /* |
| 2450 | * Partial recovery is performed on |
| 2451 | * returning failed devices. |
| 2452 | */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2453 | if (test_bit(role, (void *) failed_devices)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2454 | set_bit(Faulty, &r->flags); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | return 0; |
| 2459 | } |
| 2460 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 2461 | static int super_validate(struct raid_set *rs, struct md_rdev *rdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2462 | { |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 2463 | struct mddev *mddev = &rs->md; |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2464 | struct dm_raid_superblock *sb; |
| 2465 | |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2466 | if (rs_is_raid0(rs) || !rdev->sb_page || rdev->raid_disk < 0) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2467 | return 0; |
| 2468 | |
| 2469 | sb = page_address(rdev->sb_page); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2470 | |
| 2471 | /* |
| 2472 | * If mddev->events is not set, we know we have not yet initialized |
| 2473 | * the array. |
| 2474 | */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2475 | if (!mddev->events && super_init_validation(rs, rdev)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2476 | return -EINVAL; |
| 2477 | |
Andy Whitcroft | 5c33677 | 2016-10-11 15:16:57 +0100 | [diff] [blame] | 2478 | if (le32_to_cpu(sb->compat_features) && |
| 2479 | le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) { |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 2480 | rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags"; |
| 2481 | return -EINVAL; |
| 2482 | } |
| 2483 | |
| 2484 | if (sb->incompat_features) { |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2485 | rs->ti->error = "Unable to assemble array: No incompatible feature flags supported yet"; |
Heinz Mauelshagen | 4c9971c | 2016-04-29 18:59:56 +0200 | [diff] [blame] | 2486 | return -EINVAL; |
| 2487 | } |
| 2488 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 2489 | /* Enable bitmap creation for RAID levels != 0 */ |
Heinz Mauelshagen | 676fa5a | 2016-05-19 18:49:29 +0200 | [diff] [blame] | 2490 | mddev->bitmap_info.offset = rt_is_raid0(rs->raid_type) ? 0 : to_sector(4096); |
Heinz Mauelshagen | 977f1a0 | 2017-01-14 03:53:11 +0100 | [diff] [blame] | 2491 | mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 2492 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2493 | if (!test_and_clear_bit(FirstUse, &rdev->flags)) { |
Heinz Mauelshagen | c4d097d | 2017-06-23 17:27:01 +0200 | [diff] [blame] | 2494 | /* |
| 2495 | * Retrieve rdev size stored in superblock to be prepared for shrink. |
| 2496 | * Check extended superblock members are present otherwise the size |
| 2497 | * will not be set! |
| 2498 | */ |
| 2499 | if (le32_to_cpu(sb->compat_features) & FEATURE_FLAG_SUPPORTS_V190) |
| 2500 | rdev->sectors = le64_to_cpu(sb->sectors); |
| 2501 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2502 | rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset); |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2503 | if (rdev->recovery_offset == MaxSector) |
| 2504 | set_bit(In_sync, &rdev->flags); |
| 2505 | /* |
| 2506 | * If no reshape in progress -> we're recovering single |
| 2507 | * disk(s) and have to set the device(s) to out-of-sync |
| 2508 | */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2509 | else if (!rs_is_reshaping(rs)) |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2510 | clear_bit(In_sync, &rdev->flags); /* Mandatory for recovery */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | /* |
| 2514 | * If a device comes back, set it as not In_sync and no longer faulty. |
| 2515 | */ |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2516 | if (test_and_clear_bit(Faulty, &rdev->flags)) { |
| 2517 | rdev->recovery_offset = 0; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2518 | clear_bit(In_sync, &rdev->flags); |
| 2519 | rdev->saved_raid_disk = rdev->raid_disk; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2520 | } |
| 2521 | |
Heinz Mauelshagen | 33e53f0 | 2016-05-19 18:49:30 +0200 | [diff] [blame] | 2522 | /* Reshape support -> restore repective data offsets */ |
| 2523 | rdev->data_offset = le64_to_cpu(sb->data_offset); |
| 2524 | rdev->new_data_offset = le64_to_cpu(sb->new_data_offset); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2525 | |
| 2526 | return 0; |
| 2527 | } |
| 2528 | |
| 2529 | /* |
| 2530 | * Analyse superblocks and select the freshest. |
| 2531 | */ |
| 2532 | static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs) |
| 2533 | { |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 2534 | int r; |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2535 | struct md_rdev *rdev, *freshest; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 2536 | struct mddev *mddev = &rs->md; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2537 | |
| 2538 | freshest = NULL; |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2539 | rdev_for_each(rdev, mddev) { |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2540 | if (test_bit(Journal, &rdev->flags)) |
| 2541 | continue; |
| 2542 | |
Heinz Mauelshagen | 2339784 | 2017-11-02 19:58:28 +0100 | [diff] [blame] | 2543 | if (!rdev->meta_bdev) |
| 2544 | continue; |
| 2545 | |
| 2546 | /* Set superblock offset/size for metadata device. */ |
| 2547 | rdev->sb_start = 0; |
| 2548 | rdev->sb_size = bdev_logical_block_size(rdev->meta_bdev); |
| 2549 | if (rdev->sb_size < sizeof(struct dm_raid_superblock) || rdev->sb_size > PAGE_SIZE) { |
| 2550 | DMERR("superblock size of a logical block is no longer valid"); |
| 2551 | return -EINVAL; |
| 2552 | } |
| 2553 | |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 2554 | /* |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 2555 | * Skipping super_load due to CTR_FLAG_SYNC will cause |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 2556 | * the array to undergo initialization again as |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 2557 | * though it were new. This is the intended effect |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 2558 | * of the "sync" directive. |
| 2559 | * |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2560 | * With reshaping capability added, we must ensure that |
| 2561 | * that the "sync" directive is disallowed during the reshape. |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 2562 | */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 2563 | if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 2564 | continue; |
| 2565 | |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 2566 | r = super_load(rdev, freshest); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2567 | |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 2568 | switch (r) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2569 | case 1: |
| 2570 | freshest = rdev; |
| 2571 | break; |
| 2572 | case 0: |
| 2573 | break; |
| 2574 | default: |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2575 | /* This is a failure to read the superblock from the metadata device. */ |
Heinz Mauelshagen | 9e7d936 | 2016-08-17 15:36:44 +0200 | [diff] [blame] | 2576 | /* |
| 2577 | * We have to keep any raid0 data/metadata device pairs or |
| 2578 | * the MD raid0 personality will fail to start the array. |
| 2579 | */ |
| 2580 | if (rs_is_raid0(rs)) |
| 2581 | continue; |
| 2582 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 2583 | /* |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2584 | * We keep the dm_devs to be able to emit the device tuple |
| 2585 | * properly on the table line in raid_status() (rather than |
| 2586 | * mistakenly acting as if '- -' got passed into the constructor). |
| 2587 | * |
| 2588 | * The rdev has to stay on the same_set list to allow for |
| 2589 | * the attempt to restore faulty devices on second resume. |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 2590 | */ |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 2591 | rdev->raid_disk = rdev->saved_raid_disk = -1; |
| 2592 | break; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
| 2596 | if (!freshest) |
| 2597 | return 0; |
| 2598 | |
| 2599 | /* |
| 2600 | * Validation of the freshest device provides the source of |
| 2601 | * validation for the remaining devices. |
| 2602 | */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2603 | rs->ti->error = "Unable to assemble array: Invalid superblocks"; |
| 2604 | if (super_validate(rs, freshest)) |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 2605 | return -EINVAL; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2606 | |
Heinz Mauelshagen | f4af3f8 | 2017-07-13 17:36:12 +0200 | [diff] [blame] | 2607 | if (validate_raid_redundancy(rs)) { |
| 2608 | rs->ti->error = "Insufficient redundancy to activate array"; |
| 2609 | return -EINVAL; |
| 2610 | } |
| 2611 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 2612 | rdev_for_each(rdev, mddev) |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2613 | if (!test_bit(Journal, &rdev->flags) && |
| 2614 | rdev != freshest && |
| 2615 | super_validate(rs, rdev)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2616 | return -EINVAL; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2617 | return 0; |
| 2618 | } |
| 2619 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 2620 | /* |
| 2621 | * Adjust data_offset and new_data_offset on all disk members of @rs |
| 2622 | * for out of place reshaping if requested by contructor |
| 2623 | * |
| 2624 | * We need free space at the beginning of each raid disk for forward |
| 2625 | * and at the end for backward reshapes which userspace has to provide |
| 2626 | * via remapping/reordering of space. |
| 2627 | */ |
| 2628 | static int rs_adjust_data_offsets(struct raid_set *rs) |
| 2629 | { |
| 2630 | sector_t data_offset = 0, new_data_offset = 0; |
| 2631 | struct md_rdev *rdev; |
| 2632 | |
| 2633 | /* Constructor did not request data offset change */ |
| 2634 | if (!test_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) { |
| 2635 | if (!rs_is_reshapable(rs)) |
| 2636 | goto out; |
| 2637 | |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
| 2641 | /* HM FIXME: get InSync raid_dev? */ |
| 2642 | rdev = &rs->dev[0].rdev; |
| 2643 | |
| 2644 | if (rs->delta_disks < 0) { |
| 2645 | /* |
| 2646 | * Removing disks (reshaping backwards): |
| 2647 | * |
| 2648 | * - before reshape: data is at offset 0 and free space |
| 2649 | * is at end of each component LV |
| 2650 | * |
| 2651 | * - after reshape: data is at offset rs->data_offset != 0 on each component LV |
| 2652 | */ |
| 2653 | data_offset = 0; |
| 2654 | new_data_offset = rs->data_offset; |
| 2655 | |
| 2656 | } else if (rs->delta_disks > 0) { |
| 2657 | /* |
| 2658 | * Adding disks (reshaping forwards): |
| 2659 | * |
| 2660 | * - before reshape: data is at offset rs->data_offset != 0 and |
| 2661 | * free space is at begin of each component LV |
| 2662 | * |
| 2663 | * - after reshape: data is at offset 0 on each component LV |
| 2664 | */ |
| 2665 | data_offset = rs->data_offset; |
| 2666 | new_data_offset = 0; |
| 2667 | |
| 2668 | } else { |
| 2669 | /* |
| 2670 | * User space passes in 0 for data offset after having removed reshape space |
| 2671 | * |
| 2672 | * - or - (data offset != 0) |
| 2673 | * |
| 2674 | * Changing RAID layout or chunk size -> toggle offsets |
| 2675 | * |
| 2676 | * - before reshape: data is at offset rs->data_offset 0 and |
| 2677 | * free space is at end of each component LV |
| 2678 | * -or- |
| 2679 | * data is at offset rs->data_offset != 0 and |
| 2680 | * free space is at begin of each component LV |
| 2681 | * |
Heinz Mauelshagen | 2527b56 | 2016-06-24 01:03:19 +0200 | [diff] [blame] | 2682 | * - after reshape: data is at offset 0 if it was at offset != 0 |
| 2683 | * or at offset != 0 if it was at offset 0 |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 2684 | * on each component LV |
| 2685 | * |
| 2686 | */ |
| 2687 | data_offset = rs->data_offset ? rdev->data_offset : 0; |
| 2688 | new_data_offset = data_offset ? 0 : rs->data_offset; |
| 2689 | set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); |
| 2690 | } |
| 2691 | |
| 2692 | /* |
| 2693 | * Make sure we got a minimum amount of free sectors per device |
| 2694 | */ |
| 2695 | if (rs->data_offset && |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2696 | to_sector(i_size_read(rdev->bdev->bd_inode)) - rs->md.dev_sectors < MIN_FREE_RESHAPE_SPACE) { |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 2697 | rs->ti->error = data_offset ? "No space for forward reshape" : |
| 2698 | "No space for backward reshape"; |
| 2699 | return -ENOSPC; |
| 2700 | } |
| 2701 | out: |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2702 | /* |
| 2703 | * Raise recovery_cp in case data_offset != 0 to |
| 2704 | * avoid false recovery positives in the constructor. |
| 2705 | */ |
| 2706 | if (rs->md.recovery_cp < rs->md.dev_sectors) |
| 2707 | rs->md.recovery_cp += rs->dev[0].rdev.data_offset; |
| 2708 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2709 | /* Adjust data offsets on all rdevs but on any raid4/5/6 journal device */ |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 2710 | rdev_for_each(rdev, &rs->md) { |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2711 | if (!test_bit(Journal, &rdev->flags)) { |
| 2712 | rdev->data_offset = data_offset; |
| 2713 | rdev->new_data_offset = new_data_offset; |
| 2714 | } |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | return 0; |
| 2718 | } |
| 2719 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2720 | /* Userpace reordered disks -> adjust raid_disk indexes in @rs */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 2721 | static void __reorder_raid_disk_indexes(struct raid_set *rs) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2722 | { |
| 2723 | int i = 0; |
| 2724 | struct md_rdev *rdev; |
| 2725 | |
| 2726 | rdev_for_each(rdev, &rs->md) { |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 2727 | if (!test_bit(Journal, &rdev->flags)) { |
| 2728 | rdev->raid_disk = i++; |
| 2729 | rdev->saved_raid_disk = rdev->new_raid_disk = -1; |
| 2730 | } |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | /* |
| 2735 | * Setup @rs for takeover by a different raid level |
| 2736 | */ |
| 2737 | static int rs_setup_takeover(struct raid_set *rs) |
| 2738 | { |
| 2739 | struct mddev *mddev = &rs->md; |
| 2740 | struct md_rdev *rdev; |
| 2741 | unsigned int d = mddev->raid_disks = rs->raid_disks; |
| 2742 | sector_t new_data_offset = rs->dev[0].rdev.data_offset ? 0 : rs->data_offset; |
| 2743 | |
| 2744 | if (rt_is_raid10(rs->raid_type)) { |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 2745 | if (rs_is_raid0(rs)) { |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2746 | /* Userpace reordered disks -> adjust raid_disk indexes */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 2747 | __reorder_raid_disk_indexes(rs); |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2748 | |
| 2749 | /* raid0 -> raid10_far layout */ |
| 2750 | mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_FAR, |
| 2751 | rs->raid10_copies); |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 2752 | } else if (rs_is_raid1(rs)) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2753 | /* raid1 -> raid10_near layout */ |
| 2754 | mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, |
| 2755 | rs->raid_disks); |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 2756 | else |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2757 | return -EINVAL; |
| 2758 | |
| 2759 | } |
| 2760 | |
| 2761 | clear_bit(MD_ARRAY_FIRST_USE, &mddev->flags); |
| 2762 | mddev->recovery_cp = MaxSector; |
| 2763 | |
| 2764 | while (d--) { |
| 2765 | rdev = &rs->dev[d].rdev; |
| 2766 | |
| 2767 | if (test_bit(d, (void *) rs->rebuild_disks)) { |
| 2768 | clear_bit(In_sync, &rdev->flags); |
| 2769 | clear_bit(Faulty, &rdev->flags); |
| 2770 | mddev->recovery_cp = rdev->recovery_offset = 0; |
| 2771 | /* Bitmap has to be created when we do an "up" takeover */ |
| 2772 | set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); |
| 2773 | } |
| 2774 | |
| 2775 | rdev->new_data_offset = new_data_offset; |
| 2776 | } |
| 2777 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2778 | return 0; |
| 2779 | } |
| 2780 | |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 2781 | /* Prepare @rs for reshape */ |
| 2782 | static int rs_prepare_reshape(struct raid_set *rs) |
| 2783 | { |
| 2784 | bool reshape; |
| 2785 | struct mddev *mddev = &rs->md; |
| 2786 | |
| 2787 | if (rs_is_raid10(rs)) { |
| 2788 | if (rs->raid_disks != mddev->raid_disks && |
| 2789 | __is_raid10_near(mddev->layout) && |
| 2790 | rs->raid10_copies && |
| 2791 | rs->raid10_copies != __raid10_near_copies(mddev->layout)) { |
| 2792 | /* |
| 2793 | * raid disk have to be multiple of data copies to allow this conversion, |
| 2794 | * |
| 2795 | * This is actually not a reshape it is a |
| 2796 | * rebuild of any additional mirrors per group |
| 2797 | */ |
| 2798 | if (rs->raid_disks % rs->raid10_copies) { |
| 2799 | rs->ti->error = "Can't reshape raid10 mirror groups"; |
| 2800 | return -EINVAL; |
| 2801 | } |
| 2802 | |
| 2803 | /* Userpace reordered disks to add/remove mirrors -> adjust raid_disk indexes */ |
| 2804 | __reorder_raid_disk_indexes(rs); |
| 2805 | mddev->layout = raid10_format_to_md_layout(rs, ALGORITHM_RAID10_NEAR, |
| 2806 | rs->raid10_copies); |
| 2807 | mddev->new_layout = mddev->layout; |
| 2808 | reshape = false; |
| 2809 | } else |
| 2810 | reshape = true; |
| 2811 | |
| 2812 | } else if (rs_is_raid456(rs)) |
| 2813 | reshape = true; |
| 2814 | |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 2815 | else if (rs_is_raid1(rs)) { |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 2816 | if (rs->delta_disks) { |
| 2817 | /* Process raid1 via delta_disks */ |
| 2818 | mddev->degraded = rs->delta_disks < 0 ? -rs->delta_disks : rs->delta_disks; |
| 2819 | reshape = true; |
| 2820 | } else { |
| 2821 | /* Process raid1 without delta_disks */ |
| 2822 | mddev->raid_disks = rs->raid_disks; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 2823 | reshape = false; |
| 2824 | } |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 2825 | } else { |
| 2826 | rs->ti->error = "Called with bogus raid type"; |
| 2827 | return -EINVAL; |
| 2828 | } |
| 2829 | |
| 2830 | if (reshape) { |
| 2831 | set_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags); |
| 2832 | set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 2833 | } else if (mddev->raid_disks < rs->raid_disks) |
| 2834 | /* Create new superblocks and bitmaps, if any new disks */ |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 2835 | set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 2836 | |
| 2837 | return 0; |
| 2838 | } |
| 2839 | |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2840 | /* Get reshape sectors from data_offsets or raid set */ |
| 2841 | static sector_t _get_reshape_sectors(struct raid_set *rs) |
| 2842 | { |
| 2843 | struct md_rdev *rdev; |
| 2844 | sector_t reshape_sectors = 0; |
| 2845 | |
| 2846 | rdev_for_each(rdev, &rs->md) |
| 2847 | if (!test_bit(Journal, &rdev->flags)) { |
| 2848 | reshape_sectors = (rdev->data_offset > rdev->new_data_offset) ? |
| 2849 | rdev->data_offset - rdev->new_data_offset : |
| 2850 | rdev->new_data_offset - rdev->data_offset; |
| 2851 | break; |
| 2852 | } |
| 2853 | |
| 2854 | return max(reshape_sectors, (sector_t) rs->data_offset); |
| 2855 | } |
| 2856 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 2857 | /* |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2858 | * |
| 2859 | * - change raid layout |
| 2860 | * - change chunk size |
| 2861 | * - add disks |
| 2862 | * - remove disks |
| 2863 | */ |
| 2864 | static int rs_setup_reshape(struct raid_set *rs) |
| 2865 | { |
| 2866 | int r = 0; |
| 2867 | unsigned int cur_raid_devs, d; |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2868 | sector_t reshape_sectors = _get_reshape_sectors(rs); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2869 | struct mddev *mddev = &rs->md; |
| 2870 | struct md_rdev *rdev; |
| 2871 | |
| 2872 | mddev->delta_disks = rs->delta_disks; |
| 2873 | cur_raid_devs = mddev->raid_disks; |
| 2874 | |
| 2875 | /* Ignore impossible layout change whilst adding/removing disks */ |
| 2876 | if (mddev->delta_disks && |
| 2877 | mddev->layout != mddev->new_layout) { |
| 2878 | DMINFO("Ignoring invalid layout change with delta_disks=%d", rs->delta_disks); |
| 2879 | mddev->new_layout = mddev->layout; |
| 2880 | } |
| 2881 | |
| 2882 | /* |
| 2883 | * Adjust array size: |
| 2884 | * |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2885 | * - in case of adding disk(s), array size has |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2886 | * to grow after the disk adding reshape, |
| 2887 | * which'll hapen in the event handler; |
| 2888 | * reshape will happen forward, so space has to |
| 2889 | * be available at the beginning of each disk |
| 2890 | * |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2891 | * - in case of removing disk(s), array size |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2892 | * has to shrink before starting the reshape, |
| 2893 | * which'll happen here; |
| 2894 | * reshape will happen backward, so space has to |
| 2895 | * be available at the end of each disk |
| 2896 | * |
| 2897 | * - data_offset and new_data_offset are |
Heinz Mauelshagen | ae3c6cf | 2016-06-15 22:27:40 +0200 | [diff] [blame] | 2898 | * adjusted for aforementioned out of place |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2899 | * reshaping based on userspace passing in |
| 2900 | * the "data_offset <sectors>" key/value |
Heinz Mauelshagen | ae3c6cf | 2016-06-15 22:27:40 +0200 | [diff] [blame] | 2901 | * pair via the constructor |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2902 | */ |
| 2903 | |
| 2904 | /* Add disk(s) */ |
| 2905 | if (rs->delta_disks > 0) { |
| 2906 | /* Prepare disks for check in raid4/5/6/10 {check|start}_reshape */ |
| 2907 | for (d = cur_raid_devs; d < rs->raid_disks; d++) { |
| 2908 | rdev = &rs->dev[d].rdev; |
| 2909 | clear_bit(In_sync, &rdev->flags); |
| 2910 | |
| 2911 | /* |
| 2912 | * save_raid_disk needs to be -1, or recovery_offset will be set to 0 |
| 2913 | * by md, which'll store that erroneously in the superblock on reshape |
| 2914 | */ |
| 2915 | rdev->saved_raid_disk = -1; |
| 2916 | rdev->raid_disk = d; |
| 2917 | |
| 2918 | rdev->sectors = mddev->dev_sectors; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 2919 | rdev->recovery_offset = rs_is_raid1(rs) ? 0 : MaxSector; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2920 | } |
| 2921 | |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2922 | mddev->reshape_backwards = 0; /* adding disk(s) -> forward reshape */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2923 | |
| 2924 | /* Remove disk(s) */ |
| 2925 | } else if (rs->delta_disks < 0) { |
| 2926 | r = rs_set_dev_and_array_sectors(rs, true); |
| 2927 | mddev->reshape_backwards = 1; /* removing disk(s) -> backward reshape */ |
| 2928 | |
| 2929 | /* Change layout and/or chunk size */ |
| 2930 | } else { |
| 2931 | /* |
| 2932 | * Reshape layout (e.g. raid5_ls -> raid5_n) and/or chunk size: |
| 2933 | * |
| 2934 | * keeping number of disks and do layout change -> |
| 2935 | * |
| 2936 | * toggle reshape_backward depending on data_offset: |
| 2937 | * |
| 2938 | * - free space upfront -> reshape forward |
| 2939 | * |
| 2940 | * - free space at the end -> reshape backward |
| 2941 | * |
| 2942 | * |
| 2943 | * This utilizes free reshape space avoiding the need |
| 2944 | * for userspace to move (parts of) LV segments in |
| 2945 | * case of layout/chunksize change (for disk |
| 2946 | * adding/removing reshape space has to be at |
| 2947 | * the proper address (see above with delta_disks): |
| 2948 | * |
| 2949 | * add disk(s) -> begin |
| 2950 | * remove disk(s)-> end |
| 2951 | */ |
| 2952 | mddev->reshape_backwards = rs->dev[0].rdev.data_offset ? 0 : 1; |
| 2953 | } |
| 2954 | |
Heinz Mauelshagen | 052b2b1 | 2017-12-02 01:03:49 +0100 | [diff] [blame] | 2955 | /* |
| 2956 | * Adjust device size for forward reshape |
| 2957 | * because md_finish_reshape() reduces it. |
| 2958 | */ |
| 2959 | if (!mddev->reshape_backwards) |
| 2960 | rdev_for_each(rdev, &rs->md) |
| 2961 | if (!test_bit(Journal, &rdev->flags)) |
| 2962 | rdev->sectors += reshape_sectors; |
| 2963 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 2964 | return r; |
| 2965 | } |
| 2966 | |
| 2967 | /* |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 2968 | * Enable/disable discard support on RAID set depending on |
| 2969 | * RAID level and discard properties of underlying RAID members. |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 2970 | */ |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2971 | static void configure_discard_support(struct raid_set *rs) |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 2972 | { |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 2973 | int i; |
| 2974 | bool raid456; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 2975 | struct dm_target *ti = rs->ti; |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 2976 | |
Christoph Hellwig | 48920ff | 2017-04-05 19:21:23 +0200 | [diff] [blame] | 2977 | /* |
| 2978 | * XXX: RAID level 4,5,6 require zeroing for safety. |
| 2979 | */ |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 2980 | raid456 = rs_is_raid456(rs); |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 2981 | |
Heinz Mauelshagen | ffeeac7 | 2016-06-30 14:37:50 +0200 | [diff] [blame] | 2982 | for (i = 0; i < rs->raid_disks; i++) { |
Heinz Mauelshagen | d20c4b0 | 2014-10-29 19:02:27 +0100 | [diff] [blame] | 2983 | struct request_queue *q; |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 2984 | |
Heinz Mauelshagen | d20c4b0 | 2014-10-29 19:02:27 +0100 | [diff] [blame] | 2985 | if (!rs->dev[i].rdev.bdev) |
| 2986 | continue; |
| 2987 | |
| 2988 | q = bdev_get_queue(rs->dev[i].rdev.bdev); |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 2989 | if (!q || !blk_queue_discard(q)) |
| 2990 | return; |
| 2991 | |
| 2992 | if (raid456) { |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 2993 | if (!devices_handle_discard_safely) { |
| 2994 | DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty."); |
| 2995 | DMERR("Set dm-raid.devices_handle_discard_safely=Y to override."); |
| 2996 | return; |
| 2997 | } |
| 2998 | } |
| 2999 | } |
| 3000 | |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 3001 | /* |
| 3002 | * RAID1 and RAID10 personalities require bio splitting, |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 3003 | * RAID0/4/5/6 don't and process large discard bios properly. |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 3004 | */ |
Heinz Mauelshagen | 552aa67 | 2017-12-13 17:13:21 +0100 | [diff] [blame] | 3005 | ti->split_discard_bios = !!(rs_is_raid1(rs) || rs_is_raid10(rs)); |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 3006 | ti->num_discard_bios = 1; |
| 3007 | } |
| 3008 | |
| 3009 | /* |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3010 | * Construct a RAID0/1/10/4/5/6 mapping: |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3011 | * Args: |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 3012 | * <raid_type> <#raid_params> <raid_params>{0,} \ |
| 3013 | * <#raid_devs> [<meta_dev1> <dev1>]{1,} |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3014 | * |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 3015 | * <raid_params> varies by <raid_type>. See 'parse_raid_params' for |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3016 | * details on possible <raid_params>. |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3017 | * |
| 3018 | * Userspace is free to initialize the metadata devices, hence the superblocks to |
| 3019 | * enforce recreation based on the passed in table parameters. |
| 3020 | * |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3021 | */ |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 3022 | static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3023 | { |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3024 | int r; |
Heinz Mauelshagen | 7501537 | 2017-12-02 01:03:50 +0100 | [diff] [blame] | 3025 | bool resize = false; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3026 | struct raid_type *rt; |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 3027 | unsigned int num_raid_params, num_raid_devs; |
Heinz Mauelshagen | 7501537 | 2017-12-02 01:03:50 +0100 | [diff] [blame] | 3028 | sector_t calculated_dev_sectors, rdev_sectors, reshape_sectors; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3029 | struct raid_set *rs = NULL; |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3030 | const char *arg; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3031 | struct rs_layout rs_layout; |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3032 | struct dm_arg_set as = { argc, argv }, as_nrd; |
| 3033 | struct dm_arg _args[] = { |
| 3034 | { 0, as.argc, "Cannot understand number of raid parameters" }, |
| 3035 | { 1, 254, "Cannot understand number of raid devices parameters" } |
| 3036 | }; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3037 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3038 | /* Must have <raid_type> */ |
| 3039 | arg = dm_shift_arg(&as); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 3040 | if (!arg) { |
| 3041 | ti->error = "No arguments"; |
| 3042 | return -EINVAL; |
| 3043 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3044 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3045 | rt = get_raid_type(arg); |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 3046 | if (!rt) { |
| 3047 | ti->error = "Unrecognised raid_type"; |
| 3048 | return -EINVAL; |
| 3049 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3050 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3051 | /* Must have <#raid_params> */ |
| 3052 | if (dm_read_arg_group(_args, &as, &num_raid_params, &ti->error)) |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 3053 | return -EINVAL; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3054 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3055 | /* number of raid device tupples <meta_dev data_dev> */ |
| 3056 | as_nrd = as; |
| 3057 | dm_consume_args(&as_nrd, num_raid_params); |
| 3058 | _args[1].max = (as_nrd.argc - 1) / 2; |
| 3059 | if (dm_read_arg(_args + 1, &as_nrd, &num_raid_devs, &ti->error)) |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 3060 | return -EINVAL; |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3061 | |
Mike Snitzer | bb91a63 | 2016-06-02 12:06:54 -0400 | [diff] [blame] | 3062 | if (!__within_range(num_raid_devs, 1, MAX_RAID_DEVICES)) { |
Mike Snitzer | bd83a4c | 2016-05-31 14:26:52 -0400 | [diff] [blame] | 3063 | ti->error = "Invalid number of supplied raid devices"; |
| 3064 | return -EINVAL; |
| 3065 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3066 | |
Mike Snitzer | bfcee0e | 2016-06-02 15:08:09 -0400 | [diff] [blame] | 3067 | rs = raid_set_alloc(ti, rt, num_raid_devs); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3068 | if (IS_ERR(rs)) |
| 3069 | return PTR_ERR(rs); |
| 3070 | |
Heinz Mauelshagen | 92c83d7 | 2016-05-19 18:49:25 +0200 | [diff] [blame] | 3071 | r = parse_raid_params(rs, &as, num_raid_params); |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3072 | if (r) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3073 | goto bad; |
| 3074 | |
Heinz Mauelshagen | 702108d | 2016-05-19 18:49:26 +0200 | [diff] [blame] | 3075 | r = parse_dev_params(rs, &as); |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3076 | if (r) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3077 | goto bad; |
| 3078 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 3079 | rs->md.sync_super = super_sync; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3080 | |
Heinz Mauelshagen | 2527b56 | 2016-06-24 01:03:19 +0200 | [diff] [blame] | 3081 | /* |
| 3082 | * Calculate ctr requested array and device sizes to allow |
| 3083 | * for superblock analysis needing device sizes defined. |
| 3084 | * |
| 3085 | * Any existing superblock will overwrite the array and device sizes |
| 3086 | */ |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 3087 | r = rs_set_dev_and_array_sectors(rs, false); |
| 3088 | if (r) |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3089 | goto bad; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 3090 | |
Heinz Mauelshagen | 50c4feb | 2017-01-14 03:53:08 +0100 | [diff] [blame] | 3091 | calculated_dev_sectors = rs->md.dev_sectors; |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 3092 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3093 | /* |
| 3094 | * Backup any new raid set level, layout, ... |
| 3095 | * requested to be able to compare to superblock |
| 3096 | * members for conversion decisions. |
| 3097 | */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3098 | rs_config_backup(rs, &rs_layout); |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3099 | |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3100 | r = analyse_superblocks(ti, rs); |
| 3101 | if (r) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 3102 | goto bad; |
| 3103 | |
Heinz Mauelshagen | 4d49f1b | 2017-06-30 15:45:58 +0200 | [diff] [blame] | 3104 | rdev_sectors = __rdev_sectors(rs); |
| 3105 | if (!rdev_sectors) { |
| 3106 | ti->error = "Invalid rdev size"; |
| 3107 | r = -EINVAL; |
| 3108 | goto bad; |
| 3109 | } |
| 3110 | |
Heinz Mauelshagen | 7501537 | 2017-12-02 01:03:50 +0100 | [diff] [blame] | 3111 | |
| 3112 | reshape_sectors = _get_reshape_sectors(rs); |
| 3113 | if (calculated_dev_sectors != rdev_sectors) |
| 3114 | resize = calculated_dev_sectors != (reshape_sectors ? rdev_sectors - reshape_sectors : rdev_sectors); |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 3115 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3116 | INIT_WORK(&rs->md.event_work, do_table_event); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3117 | ti->private = rs; |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 3118 | ti->num_flush_bios = 1; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3119 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3120 | /* Restore any requested new layout for conversion decision */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3121 | rs_config_restore(rs, &rs_layout); |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3122 | |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 3123 | /* |
| 3124 | * Now that we have any superblock metadata available, |
| 3125 | * check for new, recovering, reshaping, to be taken over, |
| 3126 | * to be reshaped or an existing, unchanged raid set to |
| 3127 | * run in sequence. |
| 3128 | */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3129 | if (test_bit(MD_ARRAY_FIRST_USE, &rs->md.flags)) { |
Heinz Mauelshagen | 2d92a3c | 2016-06-24 00:32:58 +0200 | [diff] [blame] | 3130 | /* A new raid6 set has to be recovered to ensure proper parity and Q-Syndrome */ |
| 3131 | if (rs_is_raid6(rs) && |
| 3132 | test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { |
| 3133 | ti->error = "'nosync' not allowed for new raid6 set"; |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3134 | r = -EINVAL; |
| 3135 | goto bad; |
Heinz Mauelshagen | 2d92a3c | 2016-06-24 00:32:58 +0200 | [diff] [blame] | 3136 | } |
| 3137 | rs_setup_recovery(rs, 0); |
Heinz Mauelshagen | 2a5556c | 2016-06-27 14:44:09 +0200 | [diff] [blame] | 3138 | set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); |
| 3139 | rs_set_new(rs); |
| 3140 | } else if (rs_is_recovering(rs)) { |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 3141 | /* A recovering raid set may be resized */ |
Heinz Mauelshagen | 2a5556c | 2016-06-27 14:44:09 +0200 | [diff] [blame] | 3142 | ; /* skip setup rs */ |
| 3143 | } else if (rs_is_reshaping(rs)) { |
| 3144 | /* Have to reject size change request during reshape */ |
| 3145 | if (resize) { |
| 3146 | ti->error = "Can't resize a reshaping raid set"; |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3147 | r = -EPERM; |
| 3148 | goto bad; |
Heinz Mauelshagen | 2d92a3c | 2016-06-24 00:32:58 +0200 | [diff] [blame] | 3149 | } |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 3150 | /* skip setup rs */ |
Heinz Mauelshagen | 2d92a3c | 2016-06-24 00:32:58 +0200 | [diff] [blame] | 3151 | } else if (rs_takeover_requested(rs)) { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3152 | if (rs_is_reshaping(rs)) { |
| 3153 | ti->error = "Can't takeover a reshaping raid set"; |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3154 | r = -EPERM; |
| 3155 | goto bad; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3156 | } |
| 3157 | |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3158 | /* We can't takeover a journaled raid4/5/6 */ |
| 3159 | if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { |
| 3160 | ti->error = "Can't takeover a journaled raid4/5/6 set"; |
| 3161 | r = -EPERM; |
| 3162 | goto bad; |
| 3163 | } |
| 3164 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3165 | /* |
Heinz Mauelshagen | 2527b56 | 2016-06-24 01:03:19 +0200 | [diff] [blame] | 3166 | * If a takeover is needed, userspace sets any additional |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 3167 | * devices to rebuild and we can check for a valid request here. |
| 3168 | * |
| 3169 | * If acceptible, set the level to the new requested |
Heinz Mauelshagen | 2a5556c | 2016-06-27 14:44:09 +0200 | [diff] [blame] | 3170 | * one, prohibit requesting recovery, allow the raid |
| 3171 | * set to run and store superblocks during resume. |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3172 | */ |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3173 | r = rs_check_takeover(rs); |
| 3174 | if (r) |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3175 | goto bad; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3176 | |
| 3177 | r = rs_setup_takeover(rs); |
| 3178 | if (r) |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3179 | goto bad; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3180 | |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 3181 | set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); |
Heinz Mauelshagen | 469b304 | 2016-06-29 18:13:58 +0200 | [diff] [blame] | 3182 | /* Takeover ain't recovery, so disable recovery */ |
Heinz Mauelshagen | 2a5556c | 2016-06-27 14:44:09 +0200 | [diff] [blame] | 3183 | rs_setup_recovery(rs, MaxSector); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3184 | rs_set_new(rs); |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 3185 | } else if (rs_reshape_requested(rs)) { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3186 | /* |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3187 | * No need to check for 'ongoing' takeover here, because takeover |
| 3188 | * is an instant operation as oposed to an ongoing reshape. |
| 3189 | */ |
| 3190 | |
| 3191 | /* We can't reshape a journaled raid4/5/6 */ |
| 3192 | if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) { |
| 3193 | ti->error = "Can't reshape a journaled raid4/5/6 set"; |
| 3194 | r = -EPERM; |
| 3195 | goto bad; |
| 3196 | } |
| 3197 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 3198 | /* Out-of-place space has to be available to allow for a reshape unless raid1! */ |
| 3199 | if (reshape_sectors || rs_is_raid1(rs)) { |
| 3200 | /* |
| 3201 | * We can only prepare for a reshape here, because the |
| 3202 | * raid set needs to run to provide the repective reshape |
| 3203 | * check functions via its MD personality instance. |
| 3204 | * |
| 3205 | * So do the reshape check after md_run() succeeded. |
| 3206 | */ |
| 3207 | r = rs_prepare_reshape(rs); |
| 3208 | if (r) |
| 3209 | return r; |
Heinz Mauelshagen | 6e20902 | 2016-06-14 15:23:13 -0400 | [diff] [blame] | 3210 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 3211 | /* Reshaping ain't recovery, so disable recovery */ |
| 3212 | rs_setup_recovery(rs, MaxSector); |
| 3213 | } |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3214 | rs_set_cur(rs); |
Heinz Mauelshagen | 2a5556c | 2016-06-27 14:44:09 +0200 | [diff] [blame] | 3215 | } else { |
| 3216 | /* May not set recovery when a device rebuild is requested */ |
Heinz Mauelshagen | 37f10be | 2016-06-24 23:21:37 +0200 | [diff] [blame] | 3217 | if (test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) { |
| 3218 | rs_setup_recovery(rs, MaxSector); |
| 3219 | set_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags); |
| 3220 | } else |
| 3221 | rs_setup_recovery(rs, test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) ? |
Heinz Mauelshagen | 2a5556c | 2016-06-27 14:44:09 +0200 | [diff] [blame] | 3222 | 0 : (resize ? calculated_dev_sectors : MaxSector)); |
| 3223 | rs_set_cur(rs); |
Heinz Mauelshagen | 4dff2f1 | 2016-06-24 00:21:09 +0200 | [diff] [blame] | 3224 | } |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3225 | |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 3226 | /* If constructor requested it, change data and new_data offsets */ |
| 3227 | r = rs_adjust_data_offsets(rs); |
| 3228 | if (r) |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3229 | goto bad; |
Heinz Mauelshagen | 40ba37e | 2016-06-13 17:55:13 +0200 | [diff] [blame] | 3230 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3231 | /* Start raid set read-only and assumed clean to change in raid_resume() */ |
| 3232 | rs->md.ro = 1; |
| 3233 | rs->md.in_sync = 1; |
| 3234 | set_bit(MD_RECOVERY_FROZEN, &rs->md.recovery); |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 3235 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 3236 | /* Has to be held on running the array */ |
| 3237 | mddev_lock_nointr(&rs->md); |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3238 | r = md_run(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3239 | rs->md.in_sync = 0; /* Assume already marked dirty */ |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3240 | if (r) { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3241 | ti->error = "Failed to run raid array"; |
| 3242 | mddev_unlock(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3243 | goto bad; |
| 3244 | } |
| 3245 | |
Song Liu | d5d885f | 2017-11-19 22:17:01 -0800 | [diff] [blame] | 3246 | r = md_start(&rs->md); |
| 3247 | |
| 3248 | if (r) { |
| 3249 | ti->error = "Failed to start raid array"; |
| 3250 | mddev_unlock(&rs->md); |
| 3251 | goto bad_md_start; |
| 3252 | } |
| 3253 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3254 | rs->callbacks.congested_fn = raid_is_congested; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3255 | dm_table_add_target_callbacks(ti->table, &rs->callbacks); |
| 3256 | |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3257 | /* If raid4/5/6 journal mode explictely requested (only possible with journal dev) -> set it */ |
| 3258 | if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) { |
| 3259 | r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode); |
| 3260 | if (r) { |
| 3261 | ti->error = "Failed to set raid4/5/6 journal mode"; |
| 3262 | mddev_unlock(&rs->md); |
| 3263 | goto bad_journal_mode_set; |
| 3264 | } |
| 3265 | } |
| 3266 | |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 3267 | mddev_suspend(&rs->md); |
Heinz Mauelshagen | 0cf352e | 2017-07-13 17:34:24 +0200 | [diff] [blame] | 3268 | set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3269 | |
| 3270 | /* Try to adjust the raid4/5/6 stripe cache size to the stripe size */ |
| 3271 | if (rs_is_raid456(rs)) { |
| 3272 | r = rs_set_raid456_stripe_cache(rs); |
| 3273 | if (r) |
| 3274 | goto bad_stripe_cache; |
| 3275 | } |
| 3276 | |
| 3277 | /* Now do an early reshape check */ |
| 3278 | if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) { |
| 3279 | r = rs_check_reshape(rs); |
| 3280 | if (r) |
Heinz Mauelshagen | b1956dc | 2016-06-24 21:49:26 +0200 | [diff] [blame] | 3281 | goto bad_check_reshape; |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3282 | |
| 3283 | /* Restore new, ctr requested layout to perform check */ |
| 3284 | rs_config_restore(rs, &rs_layout); |
| 3285 | |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3286 | if (rs->md.pers->start_reshape) { |
| 3287 | r = rs->md.pers->check_reshape(&rs->md); |
| 3288 | if (r) { |
| 3289 | ti->error = "Reshape check failed"; |
| 3290 | goto bad_check_reshape; |
| 3291 | } |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | |
Heinz Mauelshagen | 11e2968 | 2016-11-29 22:37:30 +0100 | [diff] [blame] | 3295 | /* Disable/enable discard support on raid set. */ |
| 3296 | configure_discard_support(rs); |
| 3297 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3298 | mddev_unlock(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3299 | return 0; |
| 3300 | |
Song Liu | d5d885f | 2017-11-19 22:17:01 -0800 | [diff] [blame] | 3301 | bad_md_start: |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3302 | bad_journal_mode_set: |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3303 | bad_stripe_cache: |
| 3304 | bad_check_reshape: |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 3305 | md_stop(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3306 | bad: |
Mike Snitzer | bfcee0e | 2016-06-02 15:08:09 -0400 | [diff] [blame] | 3307 | raid_set_free(rs); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3308 | |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3309 | return r; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | static void raid_dtr(struct dm_target *ti) |
| 3313 | { |
| 3314 | struct raid_set *rs = ti->private; |
| 3315 | |
| 3316 | list_del_init(&rs->callbacks.list); |
| 3317 | md_stop(&rs->md); |
Mike Snitzer | bfcee0e | 2016-06-02 15:08:09 -0400 | [diff] [blame] | 3318 | raid_set_free(rs); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 3321 | static int raid_map(struct dm_target *ti, struct bio *bio) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3322 | { |
| 3323 | struct raid_set *rs = ti->private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 3324 | struct mddev *mddev = &rs->md; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3325 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3326 | /* |
| 3327 | * If we're reshaping to add disk(s)), ti->len and |
| 3328 | * mddev->array_sectors will differ during the process |
| 3329 | * (ti->len > mddev->array_sectors), so we have to requeue |
| 3330 | * bios with addresses > mddev->array_sectors here or |
Heinz Mauelshagen | 2527b56 | 2016-06-24 01:03:19 +0200 | [diff] [blame] | 3331 | * there will occur accesses past EOD of the component |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3332 | * data images thus erroring the raid set. |
| 3333 | */ |
| 3334 | if (unlikely(bio_end_sector(bio) > mddev->array_sectors)) |
| 3335 | return DM_MAPIO_REQUEUE; |
| 3336 | |
Shaohua Li | c4d6a1b | 2017-09-21 10:29:22 -0700 | [diff] [blame] | 3337 | md_handle_request(mddev, bio); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3338 | |
| 3339 | return DM_MAPIO_SUBMITTED; |
| 3340 | } |
| 3341 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3342 | /* Return string describing the current sync action of @mddev */ |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3343 | static const char *decipher_sync_action(struct mddev *mddev, unsigned long recovery) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3344 | { |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3345 | if (test_bit(MD_RECOVERY_FROZEN, &recovery)) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3346 | return "frozen"; |
| 3347 | |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3348 | /* The MD sync thread can be done with io but still be running */ |
| 3349 | if (!test_bit(MD_RECOVERY_DONE, &recovery) && |
| 3350 | (test_bit(MD_RECOVERY_RUNNING, &recovery) || |
| 3351 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &recovery)))) { |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3352 | if (test_bit(MD_RECOVERY_RESHAPE, &recovery)) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3353 | return "reshape"; |
| 3354 | |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3355 | if (test_bit(MD_RECOVERY_SYNC, &recovery)) { |
| 3356 | if (!test_bit(MD_RECOVERY_REQUESTED, &recovery)) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3357 | return "resync"; |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3358 | else if (test_bit(MD_RECOVERY_CHECK, &recovery)) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3359 | return "check"; |
| 3360 | return "repair"; |
| 3361 | } |
| 3362 | |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3363 | if (test_bit(MD_RECOVERY_RECOVER, &recovery)) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3364 | return "recover"; |
| 3365 | } |
| 3366 | |
| 3367 | return "idle"; |
| 3368 | } |
| 3369 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3370 | /* |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3371 | * Return status string for @rdev |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3372 | * |
| 3373 | * Status characters: |
| 3374 | * |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3375 | * 'D' = Dead/Failed raid set component or raid4/5/6 journal device |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3376 | * 'a' = Alive but not in-sync raid set component _or_ alive raid4/5/6 'write_back' journal device |
| 3377 | * 'A' = Alive and in-sync raid set component _or_ alive raid4/5/6 'write_through' journal device |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3378 | * '-' = Non-existing device (i.e. uspace passed '- -' into the ctr) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3379 | */ |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3380 | static const char *__raid_dev_status(struct raid_set *rs, struct md_rdev *rdev) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3381 | { |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3382 | if (!rdev->bdev) |
| 3383 | return "-"; |
| 3384 | else if (test_bit(Faulty, &rdev->flags)) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3385 | return "D"; |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3386 | else if (test_bit(Journal, &rdev->flags)) |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3387 | return (rs->journal_dev.mode == R5C_JOURNAL_MODE_WRITE_THROUGH) ? "A" : "a"; |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3388 | else if (test_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags) || |
| 3389 | (!test_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags) && |
| 3390 | !test_bit(In_sync, &rdev->flags))) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3391 | return "a"; |
| 3392 | else |
| 3393 | return "A"; |
| 3394 | } |
| 3395 | |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3396 | /* Helper to return resync/reshape progress for @rs and runtime flags for raid set in sync / resynching */ |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3397 | static sector_t rs_get_progress(struct raid_set *rs, unsigned long recovery, |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3398 | sector_t resync_max_sectors) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3399 | { |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3400 | sector_t r; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3401 | struct mddev *mddev = &rs->md; |
| 3402 | |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3403 | clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3404 | clear_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3405 | |
| 3406 | if (rs_is_raid0(rs)) { |
| 3407 | r = resync_max_sectors; |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3408 | set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3409 | |
| 3410 | } else { |
Heinz Mauelshagen | 7c29744 | 2017-12-13 17:13:20 +0100 | [diff] [blame] | 3411 | if (test_bit(MD_RECOVERY_NEEDED, &recovery) || |
| 3412 | test_bit(MD_RECOVERY_RESHAPE, &recovery) || |
| 3413 | test_bit(MD_RECOVERY_RUNNING, &recovery)) |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3414 | r = mddev->curr_resync_completed; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3415 | else |
Jonathan Brassow | 41dcf19 | 2017-10-02 17:17:35 -0500 | [diff] [blame] | 3416 | r = mddev->recovery_cp; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3417 | |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3418 | if (r >= resync_max_sectors && |
| 3419 | (!test_bit(MD_RECOVERY_REQUESTED, &recovery) || |
| 3420 | (!test_bit(MD_RECOVERY_FROZEN, &recovery) && |
| 3421 | !test_bit(MD_RECOVERY_NEEDED, &recovery) && |
| 3422 | !test_bit(MD_RECOVERY_RUNNING, &recovery)))) { |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3423 | /* |
| 3424 | * Sync complete. |
| 3425 | */ |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3426 | /* In case we have finished recovering, the array is in sync. */ |
| 3427 | if (test_bit(MD_RECOVERY_RECOVER, &recovery)) |
| 3428 | set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); |
| 3429 | |
| 3430 | } else if (test_bit(MD_RECOVERY_RECOVER, &recovery)) { |
| 3431 | /* |
| 3432 | * In case we are recovering, the array is not in sync |
| 3433 | * and health chars should show the recovering legs. |
| 3434 | */ |
| 3435 | ; |
| 3436 | |
| 3437 | } else if (test_bit(MD_RECOVERY_SYNC, &recovery) && |
| 3438 | !test_bit(MD_RECOVERY_REQUESTED, &recovery)) { |
| 3439 | /* |
| 3440 | * If "resync" is occurring, the raid set |
| 3441 | * is or may be out of sync hence the health |
| 3442 | * characters shall be 'a'. |
| 3443 | */ |
| 3444 | set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); |
| 3445 | |
Heinz Mauelshagen | dc15b94 | 2017-12-13 17:13:19 +0100 | [diff] [blame] | 3446 | } else if (test_bit(MD_RECOVERY_RESHAPE, &recovery) && |
| 3447 | !test_bit(MD_RECOVERY_REQUESTED, &recovery)) { |
| 3448 | /* |
| 3449 | * If "reshape" is occurring, the raid set |
| 3450 | * is or may be out of sync hence the health |
| 3451 | * characters shall be 'a'. |
| 3452 | */ |
| 3453 | set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); |
| 3454 | |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3455 | } else if (test_bit(MD_RECOVERY_REQUESTED, &recovery)) { |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3456 | /* |
| 3457 | * If "check" or "repair" is occurring, the raid set has |
| 3458 | * undergone an initial sync and the health characters |
| 3459 | * should not be 'a' anymore. |
| 3460 | */ |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3461 | set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3462 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3463 | } else { |
| 3464 | struct md_rdev *rdev; |
| 3465 | |
| 3466 | /* |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3467 | * We are idle and recovery is needed, prevent 'A' chars race |
| 3468 | * caused by components still set to in-sync by constrcuctor. |
| 3469 | */ |
| 3470 | if (test_bit(MD_RECOVERY_NEEDED, &recovery)) |
| 3471 | set_bit(RT_FLAG_RS_RESYNCING, &rs->runtime_flags); |
| 3472 | |
| 3473 | /* |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3474 | * The raid set may be doing an initial sync, or it may |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 3475 | * be rebuilding individual components. If all the |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3476 | * devices are In_sync, then it is the raid set that is |
| 3477 | * being initialized. |
| 3478 | */ |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3479 | set_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3480 | rdev_for_each(rdev, mddev) |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3481 | if (!test_bit(Journal, &rdev->flags) && |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3482 | !test_bit(In_sync, &rdev->flags)) { |
| 3483 | clear_bit(RT_FLAG_RS_IN_SYNC, &rs->runtime_flags); |
| 3484 | break; |
| 3485 | } |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | |
Heinz Mauelshagen | 4102d9d | 2017-12-02 01:03:55 +0100 | [diff] [blame] | 3489 | return min(r, resync_max_sectors); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | /* Helper to return @dev name or "-" if !@dev */ |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 3493 | static const char *__get_dev_name(struct dm_dev *dev) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3494 | { |
| 3495 | return dev ? dev->name : "-"; |
| 3496 | } |
| 3497 | |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 3498 | static void raid_status(struct dm_target *ti, status_type_t type, |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3499 | unsigned int status_flags, char *result, unsigned int maxlen) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3500 | { |
| 3501 | struct raid_set *rs = ti->private; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3502 | struct mddev *mddev = &rs->md; |
| 3503 | struct r5conf *conf = mddev->private; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3504 | int i, max_nr_stripes = conf ? conf->max_nr_stripes : 0; |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3505 | unsigned long recovery; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3506 | unsigned int raid_param_cnt = 1; /* at least 1 for chunksize */ |
| 3507 | unsigned int sz = 0; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3508 | unsigned int rebuild_disks; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3509 | unsigned int write_mostly_params = 0; |
| 3510 | sector_t progress, resync_max_sectors, resync_mismatches; |
| 3511 | const char *sync_action; |
| 3512 | struct raid_type *rt; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3513 | |
| 3514 | switch (type) { |
| 3515 | case STATUSTYPE_INFO: |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3516 | /* *Should* always succeed */ |
| 3517 | rt = get_raid_type_by_ll(mddev->new_level, mddev->new_layout); |
| 3518 | if (!rt) |
| 3519 | return; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3520 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3521 | DMEMIT("%s %d ", rt->name, mddev->raid_disks); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3522 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3523 | /* Access most recent mddev properties for status output */ |
| 3524 | smp_rmb(); |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3525 | recovery = rs->md.recovery; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3526 | /* Get sensible max sectors even if raid set not yet started */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 3527 | resync_max_sectors = test_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags) ? |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3528 | mddev->resync_max_sectors : mddev->dev_sectors; |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3529 | progress = rs_get_progress(rs, recovery, resync_max_sectors); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3530 | resync_mismatches = (mddev->last_sync_action && !strcasecmp(mddev->last_sync_action, "check")) ? |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3531 | atomic64_read(&mddev->resync_mismatches) : 0; |
Heinz Mauelshagen | 6714351 | 2017-12-02 01:03:53 +0100 | [diff] [blame] | 3532 | sync_action = decipher_sync_action(&rs->md, recovery); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3533 | |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3534 | /* HM FIXME: do we want another state char for raid0? It shows 'D'/'A'/'-' now */ |
| 3535 | for (i = 0; i < rs->raid_disks; i++) |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3536 | DMEMIT(__raid_dev_status(rs, &rs->dev[i].rdev)); |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3537 | |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 3538 | /* |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3539 | * In-sync/Reshape ratio: |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 3540 | * The in-sync ratio shows the progress of: |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3541 | * - Initializing the raid set |
| 3542 | * - Rebuilding a subset of devices of the raid set |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 3543 | * The user can distinguish between the two by referring |
| 3544 | * to the status characters. |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3545 | * |
| 3546 | * The reshape ratio shows the progress of |
| 3547 | * changing the raid layout or the number of |
| 3548 | * disks of a raid set |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 3549 | */ |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3550 | DMEMIT(" %llu/%llu", (unsigned long long) progress, |
| 3551 | (unsigned long long) resync_max_sectors); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3552 | |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3553 | /* |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3554 | * v1.5.0+: |
| 3555 | * |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3556 | * Sync action: |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3557 | * See Documentation/device-mapper/dm-raid.txt for |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3558 | * information on each of these states. |
| 3559 | */ |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3560 | DMEMIT(" %s", sync_action); |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3561 | |
| 3562 | /* |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3563 | * v1.5.0+: |
| 3564 | * |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3565 | * resync_mismatches/mismatch_cnt |
| 3566 | * This field shows the number of discrepancies found when |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3567 | * performing a "check" of the raid set. |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3568 | */ |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3569 | DMEMIT(" %llu", (unsigned long long) resync_mismatches); |
| 3570 | |
| 3571 | /* |
Mike Snitzer | 9b6e542 | 2016-06-02 11:48:09 -0400 | [diff] [blame] | 3572 | * v1.9.0+: |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3573 | * |
| 3574 | * data_offset (needed for out of space reshaping) |
| 3575 | * This field shows the data offset into the data |
| 3576 | * image LV where the first stripes data starts. |
| 3577 | * |
| 3578 | * We keep data_offset equal on all raid disks of the set, |
| 3579 | * so retrieving it from the first raid disk is sufficient. |
| 3580 | */ |
| 3581 | DMEMIT(" %llu", (unsigned long long) rs->dev[0].rdev.data_offset); |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3582 | |
| 3583 | /* |
| 3584 | * v1.10.0+: |
| 3585 | */ |
| 3586 | DMEMIT(" %s", test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags) ? |
Heinz Mauelshagen | 242ea5a | 2017-12-02 01:03:54 +0100 | [diff] [blame] | 3587 | __raid_dev_status(rs, &rs->journal_dev.rdev) : "-"); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3588 | break; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3589 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3590 | case STATUSTYPE_TABLE: |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3591 | /* Report the table line string you would use to construct this raid set */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3592 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3593 | /* Calculate raid parameter count */ |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3594 | for (i = 0; i < rs->raid_disks; i++) |
| 3595 | if (test_bit(WriteMostly, &rs->dev[i].rdev.flags)) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3596 | write_mostly_params += 2; |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3597 | rebuild_disks = memweight(rs->rebuild_disks, DISKS_ARRAY_ELEMS * sizeof(*rs->rebuild_disks)); |
| 3598 | raid_param_cnt += rebuild_disks * 2 + |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3599 | write_mostly_params + |
| 3600 | hweight32(rs->ctr_flags & CTR_FLAG_OPTIONS_NO_ARGS) + |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3601 | hweight32(rs->ctr_flags & CTR_FLAG_OPTIONS_ONE_ARG) * 2 + |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3602 | (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags) ? 2 : 0) + |
| 3603 | (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags) ? 2 : 0); |
Heinz Mauelshagen | 4464e36 | 2017-03-18 01:39:12 +0100 | [diff] [blame] | 3604 | |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3605 | /* Emit table line */ |
Heinz Mauelshagen | 4464e36 | 2017-03-18 01:39:12 +0100 | [diff] [blame] | 3606 | /* This has to be in the documented order for userspace! */ |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3607 | DMEMIT("%s %u %u", rs->raid_type->name, raid_param_cnt, mddev->new_chunk_sectors); |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 3608 | if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags)) |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 3609 | DMEMIT(" %s", dm_raid_arg_name_by_flag(CTR_FLAG_SYNC)); |
Heinz Mauelshagen | 4464e36 | 2017-03-18 01:39:12 +0100 | [diff] [blame] | 3610 | if (test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) |
| 3611 | DMEMIT(" %s", dm_raid_arg_name_by_flag(CTR_FLAG_NOSYNC)); |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3612 | if (rebuild_disks) |
| 3613 | for (i = 0; i < rs->raid_disks; i++) |
| 3614 | if (test_bit(rs->dev[i].rdev.raid_disk, (void *) rs->rebuild_disks)) |
| 3615 | DMEMIT(" %s %u", dm_raid_arg_name_by_flag(CTR_FLAG_REBUILD), |
| 3616 | rs->dev[i].rdev.raid_disk); |
Heinz Mauelshagen | 4464e36 | 2017-03-18 01:39:12 +0100 | [diff] [blame] | 3617 | if (test_bit(__CTR_FLAG_DAEMON_SLEEP, &rs->ctr_flags)) |
| 3618 | DMEMIT(" %s %lu", dm_raid_arg_name_by_flag(CTR_FLAG_DAEMON_SLEEP), |
| 3619 | mddev->bitmap_info.daemon_sleep); |
| 3620 | if (test_bit(__CTR_FLAG_MIN_RECOVERY_RATE, &rs->ctr_flags)) |
| 3621 | DMEMIT(" %s %d", dm_raid_arg_name_by_flag(CTR_FLAG_MIN_RECOVERY_RATE), |
| 3622 | mddev->sync_speed_min); |
| 3623 | if (test_bit(__CTR_FLAG_MAX_RECOVERY_RATE, &rs->ctr_flags)) |
| 3624 | DMEMIT(" %s %d", dm_raid_arg_name_by_flag(CTR_FLAG_MAX_RECOVERY_RATE), |
| 3625 | mddev->sync_speed_max); |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3626 | if (write_mostly_params) |
| 3627 | for (i = 0; i < rs->raid_disks; i++) |
| 3628 | if (test_bit(WriteMostly, &rs->dev[i].rdev.flags)) |
| 3629 | DMEMIT(" %s %d", dm_raid_arg_name_by_flag(CTR_FLAG_WRITE_MOSTLY), |
| 3630 | rs->dev[i].rdev.raid_disk); |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 3631 | if (test_bit(__CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) |
Mike Snitzer | 3fa6cf3 | 2016-06-02 11:58:51 -0400 | [diff] [blame] | 3632 | DMEMIT(" %s %lu", dm_raid_arg_name_by_flag(CTR_FLAG_MAX_WRITE_BEHIND), |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3633 | mddev->bitmap_info.max_write_behind); |
Heinz Mauelshagen | 4464e36 | 2017-03-18 01:39:12 +0100 | [diff] [blame] | 3634 | if (test_bit(__CTR_FLAG_STRIPE_CACHE, &rs->ctr_flags)) |
| 3635 | DMEMIT(" %s %d", dm_raid_arg_name_by_flag(CTR_FLAG_STRIPE_CACHE), |
| 3636 | max_nr_stripes); |
| 3637 | if (test_bit(__CTR_FLAG_REGION_SIZE, &rs->ctr_flags)) |
| 3638 | DMEMIT(" %s %llu", dm_raid_arg_name_by_flag(CTR_FLAG_REGION_SIZE), |
| 3639 | (unsigned long long) to_sector(mddev->bitmap_info.chunksize)); |
| 3640 | if (test_bit(__CTR_FLAG_RAID10_COPIES, &rs->ctr_flags)) |
| 3641 | DMEMIT(" %s %d", dm_raid_arg_name_by_flag(CTR_FLAG_RAID10_COPIES), |
| 3642 | raid10_md_layout_to_copies(mddev->layout)); |
| 3643 | if (test_bit(__CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) |
| 3644 | DMEMIT(" %s %s", dm_raid_arg_name_by_flag(CTR_FLAG_RAID10_FORMAT), |
| 3645 | raid10_md_layout_to_format(mddev->layout)); |
| 3646 | if (test_bit(__CTR_FLAG_DELTA_DISKS, &rs->ctr_flags)) |
| 3647 | DMEMIT(" %s %d", dm_raid_arg_name_by_flag(CTR_FLAG_DELTA_DISKS), |
| 3648 | max(rs->delta_disks, mddev->delta_disks)); |
| 3649 | if (test_bit(__CTR_FLAG_DATA_OFFSET, &rs->ctr_flags)) |
| 3650 | DMEMIT(" %s %llu", dm_raid_arg_name_by_flag(CTR_FLAG_DATA_OFFSET), |
| 3651 | (unsigned long long) rs->data_offset); |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3652 | if (test_bit(__CTR_FLAG_JOURNAL_DEV, &rs->ctr_flags)) |
| 3653 | DMEMIT(" %s %s", dm_raid_arg_name_by_flag(CTR_FLAG_JOURNAL_DEV), |
| 3654 | __get_dev_name(rs->journal_dev.dev)); |
Heinz Mauelshagen | 6e53636 | 2017-03-22 17:44:38 +0100 | [diff] [blame] | 3655 | if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) |
| 3656 | DMEMIT(" %s %s", dm_raid_arg_name_by_flag(CTR_FLAG_JOURNAL_MODE), |
| 3657 | md_journal_mode_to_dm_raid(rs->journal_dev.mode)); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3658 | DMEMIT(" %d", rs->raid_disks); |
Heinz Mauelshagen | 7a7c330 | 2016-06-30 13:57:08 +0200 | [diff] [blame] | 3659 | for (i = 0; i < rs->raid_disks; i++) |
| 3660 | DMEMIT(" %s %s", __get_dev_name(rs->dev[i].meta_dev), |
| 3661 | __get_dev_name(rs->dev[i].data_dev)); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3662 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3663 | } |
| 3664 | |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 3665 | static int raid_message(struct dm_target *ti, unsigned int argc, char **argv) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3666 | { |
| 3667 | struct raid_set *rs = ti->private; |
| 3668 | struct mddev *mddev = &rs->md; |
| 3669 | |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3670 | if (!mddev->pers || !mddev->pers->sync_request) |
| 3671 | return -EINVAL; |
| 3672 | |
| 3673 | if (!strcasecmp(argv[0], "frozen")) |
| 3674 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3675 | else |
| 3676 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3677 | |
| 3678 | if (!strcasecmp(argv[0], "idle") || !strcasecmp(argv[0], "frozen")) { |
| 3679 | if (mddev->sync_thread) { |
| 3680 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 3681 | md_reap_sync_thread(mddev); |
| 3682 | } |
| 3683 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 3684 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
| 3685 | return -EBUSY; |
| 3686 | else if (!strcasecmp(argv[0], "resync")) |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3687 | ; /* MD_RECOVERY_NEEDED set below */ |
| 3688 | else if (!strcasecmp(argv[0], "recover")) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3689 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3690 | else { |
Mike Snitzer | ad47047 | 2017-02-28 11:55:16 -0500 | [diff] [blame] | 3691 | if (!strcasecmp(argv[0], "check")) { |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3692 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
Mike Snitzer | ad47047 | 2017-02-28 11:55:16 -0500 | [diff] [blame] | 3693 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3694 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 3695 | } else if (!strcasecmp(argv[0], "repair")) { |
Mike Snitzer | 105db59 | 2017-01-06 15:38:08 -0500 | [diff] [blame] | 3696 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 3697 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 3698 | } else |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3699 | return -EINVAL; |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3700 | } |
| 3701 | if (mddev->ro == 2) { |
| 3702 | /* A write to sync_action is enough to justify |
| 3703 | * canceling read-auto mode |
| 3704 | */ |
| 3705 | mddev->ro = 0; |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3706 | if (!mddev->suspended && mddev->sync_thread) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3707 | md_wakeup_thread(mddev->sync_thread); |
| 3708 | } |
| 3709 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 3710 | if (!mddev->suspended && mddev->thread) |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 3711 | md_wakeup_thread(mddev->thread); |
| 3712 | |
| 3713 | return 0; |
| 3714 | } |
| 3715 | |
| 3716 | static int raid_iterate_devices(struct dm_target *ti, |
| 3717 | iterate_devices_callout_fn fn, void *data) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3718 | { |
| 3719 | struct raid_set *rs = ti->private; |
Heinz Mauelshagen | 094f394 | 2016-07-19 14:03:51 +0200 | [diff] [blame] | 3720 | unsigned int i; |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3721 | int r = 0; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3722 | |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3723 | for (i = 0; !r && i < rs->md.raid_disks; i++) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3724 | if (rs->dev[i].data_dev) |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3725 | r = fn(ti, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3726 | rs->dev[i].data_dev, |
| 3727 | 0, /* No offset on data devs */ |
| 3728 | rs->md.dev_sectors, |
| 3729 | data); |
| 3730 | |
Heinz Mauelshagen | 73c6f23 | 2016-05-19 18:49:24 +0200 | [diff] [blame] | 3731 | return r; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits) |
| 3735 | { |
| 3736 | struct raid_set *rs = ti->private; |
Heinz Mauelshagen | 89d3d9a | 2016-07-19 13:16:24 +0200 | [diff] [blame] | 3737 | unsigned int chunk_size = to_bytes(rs->md.chunk_sectors); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3738 | |
| 3739 | blk_limits_io_min(limits, chunk_size); |
Heinz Mauelshagen | 89d3d9a | 2016-07-19 13:16:24 +0200 | [diff] [blame] | 3740 | blk_limits_io_opt(limits, chunk_size * mddev_data_stripes(rs)); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3743 | static void raid_postsuspend(struct dm_target *ti) |
| 3744 | { |
| 3745 | struct raid_set *rs = ti->private; |
| 3746 | |
NeilBrown | 4d5324f | 2017-10-19 12:17:16 +1100 | [diff] [blame] | 3747 | if (!test_and_set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { |
Heinz Mauelshagen | 1af2048 | 2017-12-02 01:03:48 +0100 | [diff] [blame] | 3748 | /* Writes have to be stopped before suspending to avoid deadlocks. */ |
| 3749 | if (!test_bit(MD_RECOVERY_FROZEN, &rs->md.recovery)) |
| 3750 | md_stop_writes(&rs->md); |
| 3751 | |
NeilBrown | 4d5324f | 2017-10-19 12:17:16 +1100 | [diff] [blame] | 3752 | mddev_lock_nointr(&rs->md); |
Heinz Mauelshagen | 31e10a4 | 2016-08-10 02:45:59 +0200 | [diff] [blame] | 3753 | mddev_suspend(&rs->md); |
NeilBrown | 4d5324f | 2017-10-19 12:17:16 +1100 | [diff] [blame] | 3754 | mddev_unlock(&rs->md); |
| 3755 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3758 | static void attempt_restore_of_faulty_devices(struct raid_set *rs) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3759 | { |
Jonathan Brassow | 9092c02 | 2013-05-02 14:19:24 -0500 | [diff] [blame] | 3760 | int i; |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3761 | uint64_t cleared_failed_devices[DISKS_ARRAY_ELEMS]; |
Jonathan Brassow | 9092c02 | 2013-05-02 14:19:24 -0500 | [diff] [blame] | 3762 | unsigned long flags; |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3763 | bool cleared = false; |
Jonathan Brassow | 9092c02 | 2013-05-02 14:19:24 -0500 | [diff] [blame] | 3764 | struct dm_raid_superblock *sb; |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3765 | struct mddev *mddev = &rs->md; |
Jonathan Brassow | 9092c02 | 2013-05-02 14:19:24 -0500 | [diff] [blame] | 3766 | struct md_rdev *r; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 3767 | |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3768 | /* RAID personalities have to provide hot add/remove methods or we need to bail out. */ |
| 3769 | if (!mddev->pers || !mddev->pers->hot_add_disk || !mddev->pers->hot_remove_disk) |
| 3770 | return; |
| 3771 | |
| 3772 | memset(cleared_failed_devices, 0, sizeof(cleared_failed_devices)); |
| 3773 | |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3774 | for (i = 0; i < mddev->raid_disks; i++) { |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3775 | r = &rs->dev[i].rdev; |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3776 | /* HM FIXME: enhance journal device recovery processing */ |
| 3777 | if (test_bit(Journal, &r->flags)) |
| 3778 | continue; |
| 3779 | |
Heinz Mauelshagen | e256846 | 2017-01-14 03:53:10 +0100 | [diff] [blame] | 3780 | if (test_bit(Faulty, &r->flags) && |
| 3781 | r->meta_bdev && !read_disk_sb(r, r->sb_size, true)) { |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3782 | DMINFO("Faulty %s device #%d has readable super block." |
| 3783 | " Attempting to revive it.", |
| 3784 | rs->raid_type->name, i); |
Jonathan Brassow | a4dc163 | 2013-05-08 18:00:54 -0500 | [diff] [blame] | 3785 | |
| 3786 | /* |
| 3787 | * Faulty bit may be set, but sometimes the array can |
| 3788 | * be suspended before the personalities can respond |
| 3789 | * by removing the device from the array (i.e. calling |
Mike Snitzer | 4315784 | 2016-05-30 13:03:37 -0400 | [diff] [blame] | 3790 | * 'hot_remove_disk'). If they haven't yet removed |
Jonathan Brassow | a4dc163 | 2013-05-08 18:00:54 -0500 | [diff] [blame] | 3791 | * the failed device, its 'raid_disk' number will be |
| 3792 | * '>= 0' - meaning we must call this function |
| 3793 | * ourselves. |
| 3794 | */ |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3795 | flags = r->flags; |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3796 | clear_bit(In_sync, &r->flags); /* Mandatory for hot remove. */ |
| 3797 | if (r->raid_disk >= 0) { |
| 3798 | if (mddev->pers->hot_remove_disk(mddev, r)) { |
| 3799 | /* Failed to revive this device, try next */ |
| 3800 | r->flags = flags; |
| 3801 | continue; |
| 3802 | } |
| 3803 | } else |
| 3804 | r->raid_disk = r->saved_raid_disk = i; |
| 3805 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3806 | clear_bit(Faulty, &r->flags); |
| 3807 | clear_bit(WriteErrorSeen, &r->flags); |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3808 | |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3809 | if (mddev->pers->hot_add_disk(mddev, r)) { |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3810 | /* Failed to revive this device, try next */ |
| 3811 | r->raid_disk = r->saved_raid_disk = -1; |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3812 | r->flags = flags; |
| 3813 | } else { |
Heinz Mauelshagen | c63ede3 | 2017-01-14 03:53:07 +0100 | [diff] [blame] | 3814 | clear_bit(In_sync, &r->flags); |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3815 | r->recovery_offset = 0; |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3816 | set_bit(i, (void *) cleared_failed_devices); |
| 3817 | cleared = true; |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3818 | } |
| 3819 | } |
| 3820 | } |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3821 | |
| 3822 | /* If any failed devices could be cleared, update all sbs failed_devices bits */ |
| 3823 | if (cleared) { |
| 3824 | uint64_t failed_devices[DISKS_ARRAY_ELEMS]; |
| 3825 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3826 | rdev_for_each(r, &rs->md) { |
Heinz Mauelshagen | 63c32ed | 2016-11-30 22:31:05 +0100 | [diff] [blame] | 3827 | if (test_bit(Journal, &r->flags)) |
| 3828 | continue; |
| 3829 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3830 | sb = page_address(r->sb_page); |
Heinz Mauelshagen | a3c06a3 | 2016-08-09 14:55:35 +0200 | [diff] [blame] | 3831 | sb_retrieve_failed_devices(sb, failed_devices); |
| 3832 | |
| 3833 | for (i = 0; i < DISKS_ARRAY_ELEMS; i++) |
| 3834 | failed_devices[i] &= ~cleared_failed_devices[i]; |
| 3835 | |
| 3836 | sb_update_failed_devices(sb, failed_devices); |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 3837 | } |
| 3838 | } |
| 3839 | } |
| 3840 | |
Mike Snitzer | e6ca5e1 | 2016-06-02 15:27:22 -0400 | [diff] [blame] | 3841 | static int __load_dirty_region_bitmap(struct raid_set *rs) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3842 | { |
| 3843 | int r = 0; |
| 3844 | |
| 3845 | /* Try loading the bitmap unless "raid0", which does not have one */ |
| 3846 | if (!rs_is_raid0(rs) && |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 3847 | !test_and_set_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags)) { |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3848 | r = bitmap_load(&rs->md); |
| 3849 | if (r) |
| 3850 | DMERR("Failed to load bitmap"); |
| 3851 | } |
| 3852 | |
| 3853 | return r; |
| 3854 | } |
| 3855 | |
Heinz Mauelshagen | 6e20902 | 2016-06-14 15:23:13 -0400 | [diff] [blame] | 3856 | /* Enforce updating all superblocks */ |
| 3857 | static void rs_update_sbs(struct raid_set *rs) |
| 3858 | { |
| 3859 | struct mddev *mddev = &rs->md; |
| 3860 | int ro = mddev->ro; |
| 3861 | |
Shaohua Li | 2953079 | 2016-12-08 15:48:19 -0800 | [diff] [blame] | 3862 | set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); |
Heinz Mauelshagen | 6e20902 | 2016-06-14 15:23:13 -0400 | [diff] [blame] | 3863 | mddev->ro = 0; |
| 3864 | md_update_sb(mddev, 1); |
| 3865 | mddev->ro = ro; |
| 3866 | } |
| 3867 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3868 | /* |
| 3869 | * Reshape changes raid algorithm of @rs to new one within personality |
| 3870 | * (e.g. raid6_zr -> raid6_nc), changes stripe size, adds/removes |
| 3871 | * disks from a raid set thus growing/shrinking it or resizes the set |
| 3872 | * |
| 3873 | * Call mddev_lock_nointr() before! |
| 3874 | */ |
| 3875 | static int rs_start_reshape(struct raid_set *rs) |
| 3876 | { |
| 3877 | int r; |
| 3878 | struct mddev *mddev = &rs->md; |
| 3879 | struct md_personality *pers = mddev->pers; |
| 3880 | |
| 3881 | r = rs_setup_reshape(rs); |
| 3882 | if (r) |
| 3883 | return r; |
| 3884 | |
| 3885 | /* Need to be resumed to be able to start reshape, recovery is frozen until raid_resume() though */ |
Heinz Mauelshagen | 0cf352e | 2017-07-13 17:34:24 +0200 | [diff] [blame] | 3886 | if (test_and_clear_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3887 | mddev_resume(mddev); |
| 3888 | |
| 3889 | /* |
| 3890 | * Check any reshape constraints enforced by the personalility |
| 3891 | * |
| 3892 | * May as well already kick the reshape off so that * pers->start_reshape() becomes optional. |
| 3893 | */ |
| 3894 | r = pers->check_reshape(mddev); |
| 3895 | if (r) { |
| 3896 | rs->ti->error = "pers->check_reshape() failed"; |
| 3897 | return r; |
| 3898 | } |
| 3899 | |
| 3900 | /* |
| 3901 | * Personality may not provide start reshape method in which |
| 3902 | * case check_reshape above has already covered everything |
| 3903 | */ |
| 3904 | if (pers->start_reshape) { |
| 3905 | r = pers->start_reshape(mddev); |
| 3906 | if (r) { |
| 3907 | rs->ti->error = "pers->start_reshape() failed"; |
| 3908 | return r; |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | /* Suspend because a resume will happen in raid_resume() */ |
Heinz Mauelshagen | 0cf352e | 2017-07-13 17:34:24 +0200 | [diff] [blame] | 3913 | set_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags); |
| 3914 | mddev_suspend(mddev); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3915 | |
Heinz Mauelshagen | 6e20902 | 2016-06-14 15:23:13 -0400 | [diff] [blame] | 3916 | /* |
| 3917 | * Now reshape got set up, update superblocks to |
| 3918 | * reflect the fact so that a table reload will |
| 3919 | * access proper superblock content in the ctr. |
| 3920 | */ |
| 3921 | rs_update_sbs(rs); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3922 | |
| 3923 | return 0; |
| 3924 | } |
| 3925 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3926 | static int raid_preresume(struct dm_target *ti) |
| 3927 | { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3928 | int r; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3929 | struct raid_set *rs = ti->private; |
| 3930 | struct mddev *mddev = &rs->md; |
| 3931 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 3932 | /* This is a resume after a suspend of the set -> it's already started. */ |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 3933 | if (test_and_set_bit(RT_FLAG_RS_PRERESUMED, &rs->runtime_flags)) |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3934 | return 0; |
| 3935 | |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 3936 | if (!test_bit(__CTR_FLAG_REBUILD, &rs->ctr_flags)) { |
| 3937 | struct raid_set *rs_active = rs_find_active(rs); |
| 3938 | |
| 3939 | if (rs_active) { |
| 3940 | /* |
| 3941 | * In case no rebuilds have been requested |
| 3942 | * and an active table slot exists, copy |
| 3943 | * current resynchonization completed and |
| 3944 | * reshape position pointers across from |
| 3945 | * suspended raid set in the active slot. |
| 3946 | * |
| 3947 | * This resumes the new mapping at current |
| 3948 | * offsets to continue recover/reshape without |
| 3949 | * necessarily redoing a raid set partially or |
| 3950 | * causing data corruption in case of a reshape. |
| 3951 | */ |
| 3952 | if (rs_active->md.curr_resync_completed != MaxSector) |
| 3953 | mddev->curr_resync_completed = rs_active->md.curr_resync_completed; |
| 3954 | if (rs_active->md.reshape_position != MaxSector) |
| 3955 | mddev->reshape_position = rs_active->md.reshape_position; |
| 3956 | } |
| 3957 | } |
| 3958 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3959 | /* |
| 3960 | * The superblocks need to be updated on disk if the |
Heinz Mauelshagen | 6e20902 | 2016-06-14 15:23:13 -0400 | [diff] [blame] | 3961 | * array is new or new devices got added (thus zeroed |
| 3962 | * out by userspace) or __load_dirty_region_bitmap |
| 3963 | * will overwrite them in core with old data or fail. |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3964 | */ |
Heinz Mauelshagen | 6e20902 | 2016-06-14 15:23:13 -0400 | [diff] [blame] | 3965 | if (test_bit(RT_FLAG_UPDATE_SBS, &rs->runtime_flags)) |
| 3966 | rs_update_sbs(rs); |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3967 | |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 3968 | /* Load the bitmap from disk unless raid0 */ |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3969 | r = __load_dirty_region_bitmap(rs); |
| 3970 | if (r) |
| 3971 | return r; |
| 3972 | |
Heinz Mauelshagen | 4257e08 | 2016-06-14 01:46:03 +0200 | [diff] [blame] | 3973 | /* Resize bitmap to adjust to changed region size (aka MD bitmap chunksize) */ |
Dmitry Bilunov | 7a0c5c5 | 2017-03-30 18:14:26 +0300 | [diff] [blame] | 3974 | if (test_bit(RT_FLAG_RS_BITMAP_LOADED, &rs->runtime_flags) && mddev->bitmap && |
Heinz Mauelshagen | 4257e08 | 2016-06-14 01:46:03 +0200 | [diff] [blame] | 3975 | mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)) { |
| 3976 | r = bitmap_resize(mddev->bitmap, mddev->dev_sectors, |
| 3977 | to_bytes(rs->requested_bitmap_chunk_sectors), 0); |
| 3978 | if (r) |
| 3979 | DMERR("Failed to resize bitmap"); |
| 3980 | } |
| 3981 | |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3982 | /* Check for any resize/reshape on @rs and adjust/initiate */ |
| 3983 | /* Be prepared for mddev_resume() in raid_resume() */ |
| 3984 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 3985 | if (mddev->recovery_cp && mddev->recovery_cp < MaxSector) { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3986 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 3987 | mddev->resync_min = mddev->recovery_cp; |
| 3988 | } |
| 3989 | |
Heinz Mauelshagen | 345a6cd | 2016-06-25 02:42:54 +0200 | [diff] [blame] | 3990 | /* Check for any reshape request unless new raid set */ |
Heinz Mauelshagen | d39f001 | 2017-12-02 01:03:52 +0100 | [diff] [blame] | 3991 | if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) { |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3992 | /* Initiate a reshape. */ |
Heinz Mauelshagen | 61e06e2 | 2017-12-02 01:03:51 +0100 | [diff] [blame] | 3993 | rs_set_rdev_sectors(rs); |
Heinz Mauelshagen | 9dbd1aa | 2016-06-13 17:55:14 +0200 | [diff] [blame] | 3994 | mddev_lock_nointr(mddev); |
| 3995 | r = rs_start_reshape(rs); |
| 3996 | mddev_unlock(mddev); |
| 3997 | if (r) |
| 3998 | DMWARN("Failed to check/start reshape, continuing without change"); |
| 3999 | r = 0; |
| 4000 | } |
| 4001 | |
| 4002 | return r; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 4003 | } |
| 4004 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 4005 | static void raid_resume(struct dm_target *ti) |
| 4006 | { |
| 4007 | struct raid_set *rs = ti->private; |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 4008 | struct mddev *mddev = &rs->md; |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 4009 | |
Mike Snitzer | 4286325 | 2016-06-02 12:27:46 -0400 | [diff] [blame] | 4010 | if (test_and_set_bit(RT_FLAG_RS_RESUMED, &rs->runtime_flags)) { |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 4011 | /* |
| 4012 | * A secondary resume while the device is active. |
| 4013 | * Take this opportunity to check whether any failed |
| 4014 | * devices are reachable again. |
| 4015 | */ |
| 4016 | attempt_restore_of_faulty_devices(rs); |
Jonathan Brassow | 47525e5 | 2012-05-22 13:55:29 +1000 | [diff] [blame] | 4017 | } |
Heinz Mauelshagen | 31e10a4 | 2016-08-10 02:45:59 +0200 | [diff] [blame] | 4018 | |
NeilBrown | 4d5324f | 2017-10-19 12:17:16 +1100 | [diff] [blame] | 4019 | if (test_and_clear_bit(RT_FLAG_RS_SUSPENDED, &rs->runtime_flags)) { |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 4020 | /* Only reduce raid set size before running a disk removing reshape. */ |
| 4021 | if (mddev->delta_disks < 0) |
| 4022 | rs_set_capacity(rs); |
| 4023 | |
NeilBrown | 4d5324f | 2017-10-19 12:17:16 +1100 | [diff] [blame] | 4024 | mddev_lock_nointr(mddev); |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 4025 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
Heinz Mauelshagen | 78a75d1 | 2017-12-02 01:03:56 +0100 | [diff] [blame] | 4026 | mddev->ro = 0; |
| 4027 | mddev->in_sync = 0; |
Heinz Mauelshagen | 31e10a4 | 2016-08-10 02:45:59 +0200 | [diff] [blame] | 4028 | mddev_resume(mddev); |
NeilBrown | 4d5324f | 2017-10-19 12:17:16 +1100 | [diff] [blame] | 4029 | mddev_unlock(mddev); |
| 4030 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | static struct target_type raid_target = { |
| 4034 | .name = "raid", |
Heinz Mauelshagen | 11e4723 | 2017-12-13 17:13:18 +0100 | [diff] [blame] | 4035 | .version = {1, 13, 2}, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4036 | .module = THIS_MODULE, |
| 4037 | .ctr = raid_ctr, |
| 4038 | .dtr = raid_dtr, |
| 4039 | .map = raid_map, |
| 4040 | .status = raid_status, |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 4041 | .message = raid_message, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4042 | .iterate_devices = raid_iterate_devices, |
| 4043 | .io_hints = raid_io_hints, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4044 | .postsuspend = raid_postsuspend, |
Heinz Mauelshagen | ecbfb9f | 2016-05-19 18:49:33 +0200 | [diff] [blame] | 4045 | .preresume = raid_preresume, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4046 | .resume = raid_resume, |
| 4047 | }; |
| 4048 | |
| 4049 | static int __init dm_raid_init(void) |
| 4050 | { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 4051 | DMINFO("Loading target version %u.%u.%u", |
| 4052 | raid_target.version[0], |
| 4053 | raid_target.version[1], |
| 4054 | raid_target.version[2]); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4055 | return dm_register_target(&raid_target); |
| 4056 | } |
| 4057 | |
| 4058 | static void __exit dm_raid_exit(void) |
| 4059 | { |
| 4060 | dm_unregister_target(&raid_target); |
| 4061 | } |
| 4062 | |
| 4063 | module_init(dm_raid_init); |
| 4064 | module_exit(dm_raid_exit); |
| 4065 | |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 4066 | module_param(devices_handle_discard_safely, bool, 0644); |
| 4067 | MODULE_PARM_DESC(devices_handle_discard_safely, |
| 4068 | "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions"); |
| 4069 | |
Mike Snitzer | ef9b85a | 2016-06-02 12:02:19 -0400 | [diff] [blame] | 4070 | MODULE_DESCRIPTION(DM_NAME " raid0/1/10/4/5/6 target"); |
| 4071 | MODULE_ALIAS("dm-raid0"); |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 4072 | MODULE_ALIAS("dm-raid1"); |
| 4073 | MODULE_ALIAS("dm-raid10"); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4074 | MODULE_ALIAS("dm-raid4"); |
| 4075 | MODULE_ALIAS("dm-raid5"); |
| 4076 | MODULE_ALIAS("dm-raid6"); |
| 4077 | MODULE_AUTHOR("Neil Brown <dm-devel@redhat.com>"); |
Heinz Mauelshagen | 3a1c1ef | 2016-05-19 18:49:34 +0200 | [diff] [blame] | 4078 | MODULE_AUTHOR("Heinz Mauelshagen <dm-devel@redhat.com>"); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 4079 | MODULE_LICENSE("GPL"); |