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