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