NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2011 Neil Brown |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 3 | * Copyright (C) 2010-2015 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 | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 20 | #define MAX_RAID_DEVICES 253 /* raid4/5/6 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 | */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [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 |
| 33 | * actual data/parity. The reason for this is to not confuse |
| 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 | /* |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 49 | * Flags for rs->ctr_flags field. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 50 | */ |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 51 | #define CTR_FLAG_SYNC 0x1 |
| 52 | #define CTR_FLAG_NOSYNC 0x2 |
| 53 | #define CTR_FLAG_REBUILD 0x4 |
| 54 | #define CTR_FLAG_DAEMON_SLEEP 0x8 |
| 55 | #define CTR_FLAG_MIN_RECOVERY_RATE 0x10 |
| 56 | #define CTR_FLAG_MAX_RECOVERY_RATE 0x20 |
| 57 | #define CTR_FLAG_MAX_WRITE_BEHIND 0x40 |
| 58 | #define CTR_FLAG_STRIPE_CACHE 0x80 |
| 59 | #define CTR_FLAG_REGION_SIZE 0x100 |
| 60 | #define CTR_FLAG_RAID10_COPIES 0x200 |
| 61 | #define CTR_FLAG_RAID10_FORMAT 0x400 |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 62 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 63 | struct raid_set { |
| 64 | struct dm_target *ti; |
| 65 | |
Jonathan Brassow | 34f8ac6d | 2012-01-27 14:53:53 -0600 | [diff] [blame] | 66 | uint32_t bitmap_loaded; |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 67 | uint32_t ctr_flags; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 68 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 69 | struct mddev md; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 70 | struct raid_type *raid_type; |
| 71 | struct dm_target_callbacks callbacks; |
| 72 | |
| 73 | struct raid_dev dev[0]; |
| 74 | }; |
| 75 | |
| 76 | /* Supported raid types and properties. */ |
| 77 | static struct raid_type { |
| 78 | const char *name; /* RAID algorithm. */ |
| 79 | const char *descr; /* Descriptor text for logging. */ |
| 80 | const unsigned parity_devs; /* # of parity devices. */ |
| 81 | const unsigned minimal_devs; /* minimal # of devices in set. */ |
| 82 | const unsigned level; /* RAID level. */ |
| 83 | const unsigned algorithm; /* RAID algorithm. */ |
| 84 | } raid_types[] = { |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 85 | {"raid0", "RAID0 (striping)", 0, 2, 0, 0 /* NONE */}, |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 86 | {"raid1", "RAID1 (mirroring)", 0, 2, 1, 0 /* NONE */}, |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 87 | {"raid10", "RAID10 (striped mirrors)", 0, 2, 10, UINT_MAX /* Varies */}, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 88 | {"raid4", "RAID4 (dedicated parity disk)", 1, 2, 5, ALGORITHM_PARITY_0}, |
| 89 | {"raid5_la", "RAID5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC}, |
| 90 | {"raid5_ra", "RAID5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC}, |
| 91 | {"raid5_ls", "RAID5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC}, |
| 92 | {"raid5_rs", "RAID5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC}, |
| 93 | {"raid6_zr", "RAID6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART}, |
| 94 | {"raid6_nr", "RAID6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART}, |
| 95 | {"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE} |
| 96 | }; |
| 97 | |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 98 | static char *raid10_md_layout_to_format(int layout) |
| 99 | { |
| 100 | /* |
| 101 | * Bit 16 and 17 stand for "offset" and "use_far_sets" |
| 102 | * Refer to MD's raid10.c for details |
| 103 | */ |
| 104 | if ((layout & 0x10000) && (layout & 0x20000)) |
| 105 | return "offset"; |
| 106 | |
| 107 | if ((layout & 0xFF) > 1) |
| 108 | return "near"; |
| 109 | |
| 110 | return "far"; |
| 111 | } |
| 112 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 113 | static unsigned raid10_md_layout_to_copies(int layout) |
| 114 | { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 115 | if ((layout & 0xFF) > 1) |
| 116 | return layout & 0xFF; |
| 117 | return (layout >> 8) & 0xFF; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static int raid10_format_to_md_layout(char *format, unsigned copies) |
| 121 | { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 122 | unsigned n = 1, f = 1; |
| 123 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 124 | if (!strcasecmp("near", format)) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 125 | n = copies; |
| 126 | else |
| 127 | f = copies; |
| 128 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 129 | if (!strcasecmp("offset", format)) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 130 | return 0x30000 | (f << 8) | n; |
| 131 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 132 | if (!strcasecmp("far", format)) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 133 | return 0x20000 | (f << 8) | n; |
| 134 | |
| 135 | return (f << 8) | n; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 136 | } |
| 137 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 138 | static struct raid_type *get_raid_type(char *name) |
| 139 | { |
| 140 | int i; |
| 141 | |
| 142 | for (i = 0; i < ARRAY_SIZE(raid_types); i++) |
| 143 | if (!strcmp(raid_types[i].name, name)) |
| 144 | return &raid_types[i]; |
| 145 | |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *raid_type, unsigned raid_devs) |
| 150 | { |
| 151 | unsigned i; |
| 152 | struct raid_set *rs; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 153 | |
| 154 | if (raid_devs <= raid_type->parity_devs) { |
| 155 | ti->error = "Insufficient number of devices"; |
| 156 | return ERR_PTR(-EINVAL); |
| 157 | } |
| 158 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 159 | rs = kzalloc(sizeof(*rs) + raid_devs * sizeof(rs->dev[0]), GFP_KERNEL); |
| 160 | if (!rs) { |
| 161 | ti->error = "Cannot allocate raid context"; |
| 162 | return ERR_PTR(-ENOMEM); |
| 163 | } |
| 164 | |
| 165 | mddev_init(&rs->md); |
| 166 | |
| 167 | rs->ti = ti; |
| 168 | rs->raid_type = raid_type; |
| 169 | rs->md.raid_disks = raid_devs; |
| 170 | rs->md.level = raid_type->level; |
| 171 | rs->md.new_level = rs->md.level; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 172 | rs->md.layout = raid_type->algorithm; |
| 173 | rs->md.new_layout = rs->md.layout; |
| 174 | rs->md.delta_disks = 0; |
| 175 | rs->md.recovery_cp = 0; |
| 176 | |
| 177 | for (i = 0; i < raid_devs; i++) |
| 178 | md_rdev_init(&rs->dev[i].rdev); |
| 179 | |
| 180 | /* |
| 181 | * Remaining items to be initialized by further RAID params: |
| 182 | * rs->md.persistent |
| 183 | * rs->md.external |
| 184 | * rs->md.chunk_sectors |
| 185 | * rs->md.new_chunk_sectors |
Jonathan E Brassow | c039c33 | 2012-07-27 15:08:04 +0100 | [diff] [blame] | 186 | * rs->md.dev_sectors |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 187 | */ |
| 188 | |
| 189 | return rs; |
| 190 | } |
| 191 | |
| 192 | static void context_free(struct raid_set *rs) |
| 193 | { |
| 194 | int i; |
| 195 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 196 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 197 | if (rs->dev[i].meta_dev) |
| 198 | dm_put_device(rs->ti, rs->dev[i].meta_dev); |
NeilBrown | 545c879 | 2012-05-22 13:54:30 +1000 | [diff] [blame] | 199 | md_rdev_clear(&rs->dev[i].rdev); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 200 | if (rs->dev[i].data_dev) |
| 201 | dm_put_device(rs->ti, rs->dev[i].data_dev); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 202 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 203 | |
| 204 | kfree(rs); |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * For every device we have two words |
| 209 | * <meta_dev>: meta device name or '-' if missing |
| 210 | * <data_dev>: data device name or '-' if missing |
| 211 | * |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 212 | * The following are permitted: |
| 213 | * - - |
| 214 | * - <data_dev> |
| 215 | * <meta_dev> <data_dev> |
| 216 | * |
| 217 | * The following is not allowed: |
| 218 | * <meta_dev> - |
| 219 | * |
| 220 | * This code parses those words. If there is a failure, |
| 221 | * the caller must use context_free to unwind the operations. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 222 | */ |
| 223 | static int dev_parms(struct raid_set *rs, char **argv) |
| 224 | { |
| 225 | int i; |
| 226 | int rebuild = 0; |
| 227 | int metadata_available = 0; |
| 228 | int ret = 0; |
| 229 | |
| 230 | for (i = 0; i < rs->md.raid_disks; i++, argv += 2) { |
| 231 | rs->dev[i].rdev.raid_disk = i; |
| 232 | |
| 233 | rs->dev[i].meta_dev = NULL; |
| 234 | rs->dev[i].data_dev = NULL; |
| 235 | |
| 236 | /* |
| 237 | * There are no offsets, since there is a separate device |
| 238 | * for data and metadata. |
| 239 | */ |
| 240 | rs->dev[i].rdev.data_offset = 0; |
| 241 | rs->dev[i].rdev.mddev = &rs->md; |
| 242 | |
| 243 | if (strcmp(argv[0], "-")) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 244 | ret = dm_get_device(rs->ti, argv[0], |
| 245 | dm_table_get_mode(rs->ti->table), |
| 246 | &rs->dev[i].meta_dev); |
| 247 | rs->ti->error = "RAID metadata device lookup failure"; |
| 248 | if (ret) |
| 249 | return ret; |
| 250 | |
| 251 | rs->dev[i].rdev.sb_page = alloc_page(GFP_KERNEL); |
| 252 | if (!rs->dev[i].rdev.sb_page) |
| 253 | return -ENOMEM; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | if (!strcmp(argv[1], "-")) { |
| 257 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags) && |
| 258 | (!rs->dev[i].rdev.recovery_offset)) { |
| 259 | rs->ti->error = "Drive designated for rebuild not specified"; |
| 260 | return -EINVAL; |
| 261 | } |
| 262 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 263 | rs->ti->error = "No data device supplied with metadata device"; |
| 264 | if (rs->dev[i].meta_dev) |
| 265 | return -EINVAL; |
| 266 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 267 | continue; |
| 268 | } |
| 269 | |
| 270 | ret = dm_get_device(rs->ti, argv[1], |
| 271 | dm_table_get_mode(rs->ti->table), |
| 272 | &rs->dev[i].data_dev); |
| 273 | if (ret) { |
| 274 | rs->ti->error = "RAID device lookup failure"; |
| 275 | return ret; |
| 276 | } |
| 277 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 278 | if (rs->dev[i].meta_dev) { |
| 279 | metadata_available = 1; |
| 280 | rs->dev[i].rdev.meta_bdev = rs->dev[i].meta_dev->bdev; |
| 281 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 282 | rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev; |
| 283 | list_add(&rs->dev[i].rdev.same_set, &rs->md.disks); |
| 284 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags)) |
| 285 | rebuild++; |
| 286 | } |
| 287 | |
| 288 | if (metadata_available) { |
| 289 | rs->md.external = 0; |
| 290 | rs->md.persistent = 1; |
| 291 | rs->md.major_version = 2; |
| 292 | } else if (rebuild && !rs->md.recovery_cp) { |
| 293 | /* |
| 294 | * Without metadata, we will not be able to tell if the array |
| 295 | * is in-sync or not - we must assume it is not. Therefore, |
| 296 | * it is impossible to rebuild a drive. |
| 297 | * |
| 298 | * Even if there is metadata, the on-disk information may |
| 299 | * indicate that the array is not in-sync and it will then |
| 300 | * fail at that time. |
| 301 | * |
| 302 | * User could specify 'nosync' option if desperate. |
| 303 | */ |
| 304 | DMERR("Unable to rebuild drive while array is not in-sync"); |
| 305 | rs->ti->error = "RAID device lookup failure"; |
| 306 | return -EINVAL; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /* |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 313 | * validate_region_size |
| 314 | * @rs |
| 315 | * @region_size: region size in sectors. If 0, pick a size (4MiB default). |
| 316 | * |
| 317 | * Set rs->md.bitmap_info.chunksize (which really refers to 'region size'). |
| 318 | * Ensure that (ti->len/region_size < 2^21) - required by MD bitmap. |
| 319 | * |
| 320 | * Returns: 0 on success, -EINVAL on failure. |
| 321 | */ |
| 322 | static int validate_region_size(struct raid_set *rs, unsigned long region_size) |
| 323 | { |
| 324 | unsigned long min_region_size = rs->ti->len / (1 << 21); |
| 325 | |
| 326 | if (!region_size) { |
| 327 | /* |
| 328 | * Choose a reasonable default. All figures in sectors. |
| 329 | */ |
| 330 | if (min_region_size > (1 << 13)) { |
Jonathan Brassow | 3a0f9aa | 2012-12-21 20:23:33 +0000 | [diff] [blame] | 331 | /* If not a power of 2, make it the next power of 2 */ |
| 332 | if (min_region_size & (min_region_size - 1)) |
| 333 | region_size = 1 << fls(region_size); |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 334 | DMINFO("Choosing default region size of %lu sectors", |
| 335 | region_size); |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 336 | } else { |
| 337 | DMINFO("Choosing default region size of 4MiB"); |
| 338 | region_size = 1 << 13; /* sectors */ |
| 339 | } |
| 340 | } else { |
| 341 | /* |
| 342 | * Validate user-supplied value. |
| 343 | */ |
| 344 | if (region_size > rs->ti->len) { |
| 345 | rs->ti->error = "Supplied region size is too large"; |
| 346 | return -EINVAL; |
| 347 | } |
| 348 | |
| 349 | if (region_size < min_region_size) { |
| 350 | DMERR("Supplied region_size (%lu sectors) below minimum (%lu)", |
| 351 | region_size, min_region_size); |
| 352 | rs->ti->error = "Supplied region size is too small"; |
| 353 | return -EINVAL; |
| 354 | } |
| 355 | |
| 356 | if (!is_power_of_2(region_size)) { |
| 357 | rs->ti->error = "Region size is not a power of 2"; |
| 358 | return -EINVAL; |
| 359 | } |
| 360 | |
| 361 | if (region_size < rs->md.chunk_sectors) { |
| 362 | rs->ti->error = "Region size is smaller than the chunk size"; |
| 363 | return -EINVAL; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * Convert sectors to bytes. |
| 369 | */ |
| 370 | rs->md.bitmap_info.chunksize = (region_size << 9); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | /* |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 376 | * validate_raid_redundancy |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 377 | * @rs |
| 378 | * |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 379 | * Determine if there are enough devices in the array that haven't |
| 380 | * failed (or are being rebuilt) to form a usable array. |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 381 | * |
| 382 | * Returns: 0 on success, -EINVAL on failure. |
| 383 | */ |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 384 | static int validate_raid_redundancy(struct raid_set *rs) |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 385 | { |
| 386 | unsigned i, rebuild_cnt = 0; |
NeilBrown | 3f6bbd3 | 2013-05-09 10:27:49 +1000 | [diff] [blame] | 387 | unsigned rebuilds_per_group = 0, copies, d; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 388 | unsigned group_size, last_group_start; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 389 | |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 390 | for (i = 0; i < rs->md.raid_disks; i++) |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 391 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags) || |
| 392 | !rs->dev[i].rdev.sb_page) |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 393 | rebuild_cnt++; |
| 394 | |
| 395 | switch (rs->raid_type->level) { |
| 396 | case 1: |
| 397 | if (rebuild_cnt >= rs->md.raid_disks) |
| 398 | goto too_many; |
| 399 | break; |
| 400 | case 4: |
| 401 | case 5: |
| 402 | case 6: |
| 403 | if (rebuild_cnt > rs->raid_type->parity_devs) |
| 404 | goto too_many; |
| 405 | break; |
| 406 | case 10: |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 407 | copies = raid10_md_layout_to_copies(rs->md.layout); |
| 408 | if (rebuild_cnt < copies) |
| 409 | break; |
| 410 | |
| 411 | /* |
| 412 | * It is possible to have a higher rebuild count for RAID10, |
| 413 | * as long as the failed devices occur in different mirror |
| 414 | * groups (i.e. different stripes). |
| 415 | * |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 416 | * When checking "near" format, make sure no adjacent devices |
| 417 | * have failed beyond what can be handled. In addition to the |
| 418 | * simple case where the number of devices is a multiple of the |
| 419 | * number of copies, we must also handle cases where the number |
| 420 | * of devices is not a multiple of the number of copies. |
| 421 | * E.g. dev1 dev2 dev3 dev4 dev5 |
| 422 | * A A B B C |
| 423 | * C D D E E |
| 424 | */ |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 425 | if (!strcmp("near", raid10_md_layout_to_format(rs->md.layout))) { |
| 426 | for (i = 0; i < rs->md.raid_disks * copies; i++) { |
| 427 | if (!(i % copies)) |
| 428 | rebuilds_per_group = 0; |
| 429 | d = i % rs->md.raid_disks; |
| 430 | if ((!rs->dev[d].rdev.sb_page || |
| 431 | !test_bit(In_sync, &rs->dev[d].rdev.flags)) && |
| 432 | (++rebuilds_per_group >= copies)) |
| 433 | goto too_many; |
| 434 | } |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | /* |
| 439 | * When checking "far" and "offset" formats, we need to ensure |
| 440 | * that the device that holds its copy is not also dead or |
| 441 | * being rebuilt. (Note that "far" and "offset" formats only |
| 442 | * support two copies right now. These formats also only ever |
| 443 | * use the 'use_far_sets' variant.) |
| 444 | * |
| 445 | * This check is somewhat complicated by the need to account |
| 446 | * for arrays that are not a multiple of (far) copies. This |
| 447 | * results in the need to treat the last (potentially larger) |
| 448 | * set differently. |
| 449 | */ |
| 450 | group_size = (rs->md.raid_disks / copies); |
| 451 | last_group_start = (rs->md.raid_disks / group_size) - 1; |
| 452 | last_group_start *= group_size; |
| 453 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 454 | if (!(i % copies) && !(i > last_group_start)) |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 455 | rebuilds_per_group = 0; |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 456 | if ((!rs->dev[i].rdev.sb_page || |
| 457 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) && |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 458 | (++rebuilds_per_group >= copies)) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 459 | goto too_many; |
Jonathan Brassow | 4ec1e36 | 2012-10-11 13:40:24 +1100 | [diff] [blame] | 460 | } |
| 461 | break; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 462 | default: |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 463 | if (rebuild_cnt) |
| 464 | return -EINVAL; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | |
| 469 | too_many: |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 470 | return -EINVAL; |
| 471 | } |
| 472 | |
| 473 | /* |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 474 | * Possible arguments are... |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 475 | * <chunk_size> [optional_args] |
| 476 | * |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 477 | * Argument definitions |
| 478 | * <chunk_size> The number of sectors per disk that |
| 479 | * will form the "stripe" |
| 480 | * [[no]sync] Force or prevent recovery of the |
| 481 | * entire array |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 482 | * [rebuild <idx>] Rebuild the drive indicated by the index |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 483 | * [daemon_sleep <ms>] Time between bitmap daemon work to |
| 484 | * clear bits |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 485 | * [min_recovery_rate <kB/sec/disk>] Throttle RAID initialization |
| 486 | * [max_recovery_rate <kB/sec/disk>] Throttle RAID initialization |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 487 | * [write_mostly <idx>] Indicate a write mostly drive via index |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 488 | * [max_write_behind <sectors>] See '-write-behind=' (man mdadm) |
| 489 | * [stripe_cache <sectors>] Stripe cache size for higher RAIDs |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 490 | * [region_size <sectors>] Defines granularity of bitmap |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 491 | * |
| 492 | * RAID10-only options: |
| 493 | * [raid10_copies <# copies>] Number of copies. (Default: 2) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 494 | * [raid10_format <near|far|offset>] Layout algorithm. (Default: near) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 495 | */ |
| 496 | static int parse_raid_params(struct raid_set *rs, char **argv, |
| 497 | unsigned num_raid_params) |
| 498 | { |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 499 | char *raid10_format = "near"; |
| 500 | unsigned raid10_copies = 2; |
Jonathan Brassow | eb64912 | 2012-10-11 13:40:09 +1100 | [diff] [blame] | 501 | unsigned i; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 502 | unsigned long value, region_size = 0; |
Jonathan E Brassow | c039c33 | 2012-07-27 15:08:04 +0100 | [diff] [blame] | 503 | sector_t sectors_per_dev = rs->ti->len; |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 504 | sector_t max_io_len; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 505 | char *key; |
| 506 | |
| 507 | /* |
| 508 | * First, parse the in-order required arguments |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 509 | * "chunk_size" is the only argument of this type. |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 510 | */ |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 511 | if ((kstrtoul(argv[0], 10, &value) < 0)) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 512 | rs->ti->error = "Bad chunk size"; |
| 513 | return -EINVAL; |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 514 | } else if (rs->raid_type->level == 1) { |
| 515 | if (value) |
| 516 | DMERR("Ignoring chunk size parameter for RAID 1"); |
| 517 | value = 0; |
| 518 | } else if (!is_power_of_2(value)) { |
| 519 | rs->ti->error = "Chunk size must be a power of 2"; |
| 520 | return -EINVAL; |
| 521 | } else if (value < 8) { |
| 522 | rs->ti->error = "Chunk size value is too small"; |
| 523 | return -EINVAL; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | rs->md.new_chunk_sectors = rs->md.chunk_sectors = value; |
| 527 | argv++; |
| 528 | num_raid_params--; |
| 529 | |
| 530 | /* |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 531 | * We set each individual device as In_sync with a completed |
| 532 | * 'recovery_offset'. If there has been a device failure or |
| 533 | * replacement then one of the following cases applies: |
| 534 | * |
| 535 | * 1) User specifies 'rebuild'. |
| 536 | * - Device is reset when param is read. |
| 537 | * 2) A new device is supplied. |
| 538 | * - No matching superblock found, resets device. |
| 539 | * 3) Device failure was transient and returns on reload. |
| 540 | * - Failure noticed, resets device for bitmap replay. |
| 541 | * 4) Device hadn't completed recovery after previous failure. |
| 542 | * - Superblock is read and overrides recovery_offset. |
| 543 | * |
| 544 | * What is found in the superblocks of the devices is always |
| 545 | * authoritative, unless 'rebuild' or '[no]sync' was specified. |
| 546 | */ |
| 547 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 548 | set_bit(In_sync, &rs->dev[i].rdev.flags); |
| 549 | rs->dev[i].rdev.recovery_offset = MaxSector; |
| 550 | } |
| 551 | |
| 552 | /* |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 553 | * Second, parse the unordered optional arguments |
| 554 | */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 555 | for (i = 0; i < num_raid_params; i++) { |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 556 | if (!strcasecmp(argv[i], "nosync")) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 557 | rs->md.recovery_cp = MaxSector; |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 558 | rs->ctr_flags |= CTR_FLAG_NOSYNC; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 559 | continue; |
| 560 | } |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 561 | if (!strcasecmp(argv[i], "sync")) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 562 | rs->md.recovery_cp = 0; |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 563 | rs->ctr_flags |= CTR_FLAG_SYNC; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 564 | continue; |
| 565 | } |
| 566 | |
| 567 | /* The rest of the optional arguments come in key/value pairs */ |
| 568 | if ((i + 1) >= num_raid_params) { |
| 569 | rs->ti->error = "Wrong number of raid parameters given"; |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | |
| 573 | key = argv[i++]; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 574 | |
| 575 | /* Parameters that take a string value are checked here. */ |
| 576 | if (!strcasecmp(key, "raid10_format")) { |
| 577 | if (rs->raid_type->level != 10) { |
| 578 | rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type"; |
| 579 | return -EINVAL; |
| 580 | } |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 581 | if (strcmp("near", argv[i]) && |
| 582 | strcmp("far", argv[i]) && |
| 583 | strcmp("offset", argv[i])) { |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 584 | rs->ti->error = "Invalid 'raid10_format' value given"; |
| 585 | return -EINVAL; |
| 586 | } |
| 587 | raid10_format = argv[i]; |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 588 | rs->ctr_flags |= CTR_FLAG_RAID10_FORMAT; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 589 | continue; |
| 590 | } |
| 591 | |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 592 | if (kstrtoul(argv[i], 10, &value) < 0) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 593 | rs->ti->error = "Bad numerical argument given in raid params"; |
| 594 | return -EINVAL; |
| 595 | } |
| 596 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 597 | /* Parameters that take a numeric value are checked here */ |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 598 | if (!strcasecmp(key, "rebuild")) { |
Jonathan Brassow | 7386199 | 2012-10-11 13:40:36 +1100 | [diff] [blame] | 599 | if (value >= rs->md.raid_disks) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 600 | rs->ti->error = "Invalid rebuild index given"; |
| 601 | return -EINVAL; |
| 602 | } |
| 603 | clear_bit(In_sync, &rs->dev[value].rdev.flags); |
| 604 | rs->dev[value].rdev.recovery_offset = 0; |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 605 | rs->ctr_flags |= CTR_FLAG_REBUILD; |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 606 | } else if (!strcasecmp(key, "write_mostly")) { |
| 607 | if (rs->raid_type->level != 1) { |
| 608 | rs->ti->error = "write_mostly option is only valid for RAID1"; |
| 609 | return -EINVAL; |
| 610 | } |
Jonthan Brassow | 8232480 | 2011-09-25 23:26:19 +0100 | [diff] [blame] | 611 | if (value >= rs->md.raid_disks) { |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 612 | rs->ti->error = "Invalid write_mostly drive index given"; |
| 613 | return -EINVAL; |
| 614 | } |
| 615 | set_bit(WriteMostly, &rs->dev[value].rdev.flags); |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 616 | } else if (!strcasecmp(key, "max_write_behind")) { |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 617 | if (rs->raid_type->level != 1) { |
| 618 | rs->ti->error = "max_write_behind option is only valid for RAID1"; |
| 619 | return -EINVAL; |
| 620 | } |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 621 | rs->ctr_flags |= CTR_FLAG_MAX_WRITE_BEHIND; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 622 | |
| 623 | /* |
| 624 | * In device-mapper, we specify things in sectors, but |
| 625 | * MD records this value in kB |
| 626 | */ |
| 627 | value /= 2; |
| 628 | if (value > COUNTER_MAX) { |
| 629 | rs->ti->error = "Max write-behind limit out of range"; |
| 630 | return -EINVAL; |
| 631 | } |
| 632 | rs->md.bitmap_info.max_write_behind = value; |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 633 | } else if (!strcasecmp(key, "daemon_sleep")) { |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 634 | rs->ctr_flags |= CTR_FLAG_DAEMON_SLEEP; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 635 | if (!value || (value > MAX_SCHEDULE_TIMEOUT)) { |
| 636 | rs->ti->error = "daemon sleep period out of range"; |
| 637 | return -EINVAL; |
| 638 | } |
| 639 | rs->md.bitmap_info.daemon_sleep = value; |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 640 | } else if (!strcasecmp(key, "stripe_cache")) { |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 641 | rs->ctr_flags |= CTR_FLAG_STRIPE_CACHE; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 642 | |
| 643 | /* |
| 644 | * In device-mapper, we specify things in sectors, but |
| 645 | * MD records this value in kB |
| 646 | */ |
| 647 | value /= 2; |
| 648 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 649 | if ((rs->raid_type->level != 5) && |
| 650 | (rs->raid_type->level != 6)) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 651 | rs->ti->error = "Inappropriate argument: stripe_cache"; |
| 652 | return -EINVAL; |
| 653 | } |
| 654 | if (raid5_set_cache_size(&rs->md, (int)value)) { |
| 655 | rs->ti->error = "Bad stripe_cache size"; |
| 656 | return -EINVAL; |
| 657 | } |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 658 | } else if (!strcasecmp(key, "min_recovery_rate")) { |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 659 | rs->ctr_flags |= CTR_FLAG_MIN_RECOVERY_RATE; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 660 | if (value > INT_MAX) { |
| 661 | rs->ti->error = "min_recovery_rate out of range"; |
| 662 | return -EINVAL; |
| 663 | } |
| 664 | rs->md.sync_speed_min = (int)value; |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 665 | } else if (!strcasecmp(key, "max_recovery_rate")) { |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 666 | rs->ctr_flags |= CTR_FLAG_MAX_RECOVERY_RATE; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 667 | if (value > INT_MAX) { |
| 668 | rs->ti->error = "max_recovery_rate out of range"; |
| 669 | return -EINVAL; |
| 670 | } |
| 671 | rs->md.sync_speed_max = (int)value; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 672 | } else if (!strcasecmp(key, "region_size")) { |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 673 | rs->ctr_flags |= CTR_FLAG_REGION_SIZE; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 674 | region_size = value; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 675 | } else if (!strcasecmp(key, "raid10_copies") && |
| 676 | (rs->raid_type->level == 10)) { |
| 677 | if ((value < 2) || (value > 0xFF)) { |
| 678 | rs->ti->error = "Bad value for 'raid10_copies'"; |
| 679 | return -EINVAL; |
| 680 | } |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 681 | rs->ctr_flags |= CTR_FLAG_RAID10_COPIES; |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 682 | raid10_copies = value; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 683 | } else { |
| 684 | DMERR("Unable to parse RAID parameter: %s", key); |
| 685 | rs->ti->error = "Unable to parse RAID parameters"; |
| 686 | return -EINVAL; |
| 687 | } |
| 688 | } |
| 689 | |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 690 | if (validate_region_size(rs, region_size)) |
| 691 | return -EINVAL; |
| 692 | |
| 693 | if (rs->md.chunk_sectors) |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 694 | max_io_len = rs->md.chunk_sectors; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 695 | else |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 696 | max_io_len = region_size; |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 697 | |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 698 | if (dm_set_target_max_io_len(rs->ti, max_io_len)) |
| 699 | return -EINVAL; |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 700 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 701 | if (rs->raid_type->level == 10) { |
| 702 | if (raid10_copies > rs->md.raid_disks) { |
| 703 | rs->ti->error = "Not enough devices to satisfy specification"; |
| 704 | return -EINVAL; |
| 705 | } |
| 706 | |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 707 | /* |
| 708 | * If the format is not "near", we only support |
| 709 | * two copies at the moment. |
| 710 | */ |
| 711 | if (strcmp("near", raid10_format) && (raid10_copies > 2)) { |
| 712 | rs->ti->error = "Too many copies for given RAID10 format."; |
| 713 | return -EINVAL; |
| 714 | } |
| 715 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 716 | /* (Len * #mirrors) / #devices */ |
| 717 | sectors_per_dev = rs->ti->len * raid10_copies; |
| 718 | sector_div(sectors_per_dev, rs->md.raid_disks); |
| 719 | |
| 720 | rs->md.layout = raid10_format_to_md_layout(raid10_format, |
| 721 | raid10_copies); |
| 722 | rs->md.new_layout = rs->md.layout; |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 723 | } else if ((!rs->raid_type->level || rs->raid_type->level > 1) && |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 724 | sector_div(sectors_per_dev, |
| 725 | (rs->md.raid_disks - rs->raid_type->parity_devs))) { |
Jonathan E Brassow | c039c33 | 2012-07-27 15:08:04 +0100 | [diff] [blame] | 726 | rs->ti->error = "Target length not divisible by number of data devices"; |
| 727 | return -EINVAL; |
| 728 | } |
| 729 | rs->md.dev_sectors = sectors_per_dev; |
| 730 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 731 | /* Assume there are no metadata devices until the drives are parsed */ |
| 732 | rs->md.persistent = 0; |
| 733 | rs->md.external = 1; |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static void do_table_event(struct work_struct *ws) |
| 739 | { |
| 740 | struct raid_set *rs = container_of(ws, struct raid_set, md.event_work); |
| 741 | |
| 742 | dm_table_event(rs->ti->table); |
| 743 | } |
| 744 | |
| 745 | static int raid_is_congested(struct dm_target_callbacks *cb, int bits) |
| 746 | { |
| 747 | struct raid_set *rs = container_of(cb, struct raid_set, callbacks); |
| 748 | |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 749 | return mddev_congested(&rs->md, bits); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 750 | } |
| 751 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 752 | /* |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 753 | * This structure is never routinely used by userspace, unlike md superblocks. |
| 754 | * Devices with this superblock should only ever be accessed via device-mapper. |
| 755 | */ |
| 756 | #define DM_RAID_MAGIC 0x64526D44 |
| 757 | struct dm_raid_superblock { |
| 758 | __le32 magic; /* "DmRd" */ |
| 759 | __le32 features; /* Used to indicate possible future changes */ |
| 760 | |
| 761 | __le32 num_devices; /* Number of devices in this array. (Max 64) */ |
| 762 | __le32 array_position; /* The position of this drive in the array */ |
| 763 | |
| 764 | __le64 events; /* Incremented by md when superblock updated */ |
| 765 | __le64 failed_devices; /* Bit field of devices to indicate failures */ |
| 766 | |
| 767 | /* |
| 768 | * This offset tracks the progress of the repair or replacement of |
| 769 | * an individual drive. |
| 770 | */ |
| 771 | __le64 disk_recovery_offset; |
| 772 | |
| 773 | /* |
| 774 | * This offset tracks the progress of the initial array |
| 775 | * synchronisation/parity calculation. |
| 776 | */ |
| 777 | __le64 array_resync_offset; |
| 778 | |
| 779 | /* |
| 780 | * RAID characteristics |
| 781 | */ |
| 782 | __le32 level; |
| 783 | __le32 layout; |
| 784 | __le32 stripe_sectors; |
| 785 | |
Heinz Mauelshagen | 40d43c4 | 2014-10-17 13:38:50 +0200 | [diff] [blame] | 786 | /* Remainder of a logical block is zero-filled when writing (see super_sync()). */ |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 787 | } __packed; |
| 788 | |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 789 | static int read_disk_sb(struct md_rdev *rdev, int size) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 790 | { |
| 791 | BUG_ON(!rdev->sb_page); |
| 792 | |
| 793 | if (rdev->sb_loaded) |
| 794 | return 0; |
| 795 | |
| 796 | if (!sync_page_io(rdev, 0, size, rdev->sb_page, READ, 1)) { |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 797 | DMERR("Failed to read superblock of device at position %d", |
| 798 | rdev->raid_disk); |
Jonathan Brassow | c32fb9e | 2012-05-22 13:55:31 +1000 | [diff] [blame] | 799 | md_error(rdev->mddev, rdev); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 800 | return -EINVAL; |
| 801 | } |
| 802 | |
| 803 | rdev->sb_loaded = 1; |
| 804 | |
| 805 | return 0; |
| 806 | } |
| 807 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 808 | static void super_sync(struct mddev *mddev, struct md_rdev *rdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 809 | { |
Jonathan Brassow | 81f382f | 2012-05-22 13:55:30 +1000 | [diff] [blame] | 810 | int i; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 811 | uint64_t failed_devices; |
| 812 | struct dm_raid_superblock *sb; |
Jonathan Brassow | 81f382f | 2012-05-22 13:55:30 +1000 | [diff] [blame] | 813 | struct raid_set *rs = container_of(mddev, struct raid_set, md); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 814 | |
| 815 | sb = page_address(rdev->sb_page); |
| 816 | failed_devices = le64_to_cpu(sb->failed_devices); |
| 817 | |
Jonathan Brassow | 81f382f | 2012-05-22 13:55:30 +1000 | [diff] [blame] | 818 | for (i = 0; i < mddev->raid_disks; i++) |
| 819 | if (!rs->dev[i].data_dev || |
| 820 | test_bit(Faulty, &(rs->dev[i].rdev.flags))) |
| 821 | failed_devices |= (1ULL << i); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 822 | |
Heinz Mauelshagen | 40d43c4 | 2014-10-17 13:38:50 +0200 | [diff] [blame] | 823 | memset(sb + 1, 0, rdev->sb_size - sizeof(*sb)); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 824 | |
| 825 | sb->magic = cpu_to_le32(DM_RAID_MAGIC); |
| 826 | sb->features = cpu_to_le32(0); /* No features yet */ |
| 827 | |
| 828 | sb->num_devices = cpu_to_le32(mddev->raid_disks); |
| 829 | sb->array_position = cpu_to_le32(rdev->raid_disk); |
| 830 | |
| 831 | sb->events = cpu_to_le64(mddev->events); |
| 832 | sb->failed_devices = cpu_to_le64(failed_devices); |
| 833 | |
| 834 | sb->disk_recovery_offset = cpu_to_le64(rdev->recovery_offset); |
| 835 | sb->array_resync_offset = cpu_to_le64(mddev->recovery_cp); |
| 836 | |
| 837 | sb->level = cpu_to_le32(mddev->level); |
| 838 | sb->layout = cpu_to_le32(mddev->layout); |
| 839 | sb->stripe_sectors = cpu_to_le32(mddev->chunk_sectors); |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * super_load |
| 844 | * |
| 845 | * This function creates a superblock if one is not found on the device |
| 846 | * and will decide which superblock to use if there's a choice. |
| 847 | * |
| 848 | * Return: 1 if use rdev, 0 if use refdev, -Exxx otherwise |
| 849 | */ |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 850 | static int super_load(struct md_rdev *rdev, struct md_rdev *refdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 851 | { |
| 852 | int ret; |
| 853 | struct dm_raid_superblock *sb; |
| 854 | struct dm_raid_superblock *refsb; |
| 855 | uint64_t events_sb, events_refsb; |
| 856 | |
| 857 | rdev->sb_start = 0; |
Heinz Mauelshagen | 40d43c4 | 2014-10-17 13:38:50 +0200 | [diff] [blame] | 858 | rdev->sb_size = bdev_logical_block_size(rdev->meta_bdev); |
| 859 | if (rdev->sb_size < sizeof(*sb) || rdev->sb_size > PAGE_SIZE) { |
| 860 | DMERR("superblock size of a logical block is no longer valid"); |
| 861 | return -EINVAL; |
| 862 | } |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 863 | |
| 864 | ret = read_disk_sb(rdev, rdev->sb_size); |
| 865 | if (ret) |
| 866 | return ret; |
| 867 | |
| 868 | sb = page_address(rdev->sb_page); |
Jonathan E Brassow | 3aa3b2b | 2012-03-07 19:09:47 +0000 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * Two cases that we want to write new superblocks and rebuild: |
| 872 | * 1) New device (no matching magic number) |
| 873 | * 2) Device specified for rebuild (!In_sync w/ offset == 0) |
| 874 | */ |
| 875 | if ((sb->magic != cpu_to_le32(DM_RAID_MAGIC)) || |
| 876 | (!test_bit(In_sync, &rdev->flags) && !rdev->recovery_offset)) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 877 | super_sync(rdev->mddev, rdev); |
| 878 | |
| 879 | set_bit(FirstUse, &rdev->flags); |
| 880 | |
| 881 | /* Force writing of superblocks to disk */ |
| 882 | set_bit(MD_CHANGE_DEVS, &rdev->mddev->flags); |
| 883 | |
| 884 | /* Any superblock is better than none, choose that if given */ |
| 885 | return refdev ? 0 : 1; |
| 886 | } |
| 887 | |
| 888 | if (!refdev) |
| 889 | return 1; |
| 890 | |
| 891 | events_sb = le64_to_cpu(sb->events); |
| 892 | |
| 893 | refsb = page_address(refdev->sb_page); |
| 894 | events_refsb = le64_to_cpu(refsb->events); |
| 895 | |
| 896 | return (events_sb > events_refsb) ? 1 : 0; |
| 897 | } |
| 898 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 899 | static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 900 | { |
| 901 | int role; |
| 902 | struct raid_set *rs = container_of(mddev, struct raid_set, md); |
| 903 | uint64_t events_sb; |
| 904 | uint64_t failed_devices; |
| 905 | struct dm_raid_superblock *sb; |
| 906 | uint32_t new_devs = 0; |
| 907 | uint32_t rebuilds = 0; |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 908 | struct md_rdev *r; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 909 | struct dm_raid_superblock *sb2; |
| 910 | |
| 911 | sb = page_address(rdev->sb_page); |
| 912 | events_sb = le64_to_cpu(sb->events); |
| 913 | failed_devices = le64_to_cpu(sb->failed_devices); |
| 914 | |
| 915 | /* |
| 916 | * Initialise to 1 if this is a new superblock. |
| 917 | */ |
| 918 | mddev->events = events_sb ? : 1; |
| 919 | |
| 920 | /* |
| 921 | * Reshaping is not currently allowed |
| 922 | */ |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 923 | if (le32_to_cpu(sb->level) != mddev->level) { |
| 924 | DMERR("Reshaping arrays not yet supported. (RAID level change)"); |
| 925 | return -EINVAL; |
| 926 | } |
| 927 | if (le32_to_cpu(sb->layout) != mddev->layout) { |
| 928 | DMERR("Reshaping arrays not yet supported. (RAID layout change)"); |
| 929 | DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout); |
| 930 | DMERR(" Old layout: %s w/ %d copies", |
| 931 | raid10_md_layout_to_format(le32_to_cpu(sb->layout)), |
| 932 | raid10_md_layout_to_copies(le32_to_cpu(sb->layout))); |
| 933 | DMERR(" New layout: %s w/ %d copies", |
| 934 | raid10_md_layout_to_format(mddev->layout), |
| 935 | raid10_md_layout_to_copies(mddev->layout)); |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) { |
| 939 | DMERR("Reshaping arrays not yet supported. (stripe sectors change)"); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 940 | return -EINVAL; |
| 941 | } |
| 942 | |
| 943 | /* We can only change the number of devices in RAID1 right now */ |
| 944 | if ((rs->raid_type->level != 1) && |
| 945 | (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 946 | DMERR("Reshaping arrays not yet supported. (device count change)"); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 947 | return -EINVAL; |
| 948 | } |
| 949 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 950 | if (!(rs->ctr_flags & (CTR_FLAG_SYNC | CTR_FLAG_NOSYNC))) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 951 | mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset); |
| 952 | |
| 953 | /* |
| 954 | * During load, we set FirstUse if a new superblock was written. |
| 955 | * There are two reasons we might not have a superblock: |
| 956 | * 1) The array is brand new - in which case, all of the |
| 957 | * devices must have their In_sync bit set. Also, |
| 958 | * recovery_cp must be 0, unless forced. |
| 959 | * 2) This is a new device being added to an old array |
| 960 | * and the new device needs to be rebuilt - in which |
| 961 | * case the In_sync bit will /not/ be set and |
| 962 | * recovery_cp must be MaxSector. |
| 963 | */ |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 964 | rdev_for_each(r, mddev) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 965 | if (!test_bit(In_sync, &r->flags)) { |
Jonathan E Brassow | 3aa3b2b | 2012-03-07 19:09:47 +0000 | [diff] [blame] | 966 | DMINFO("Device %d specified for rebuild: " |
| 967 | "Clearing superblock", r->raid_disk); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 968 | rebuilds++; |
| 969 | } else if (test_bit(FirstUse, &r->flags)) |
| 970 | new_devs++; |
| 971 | } |
| 972 | |
| 973 | if (!rebuilds) { |
| 974 | if (new_devs == mddev->raid_disks) { |
| 975 | DMINFO("Superblocks created for new array"); |
| 976 | set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); |
| 977 | } else if (new_devs) { |
| 978 | DMERR("New device injected " |
| 979 | "into existing array without 'rebuild' " |
| 980 | "parameter specified"); |
| 981 | return -EINVAL; |
| 982 | } |
| 983 | } else if (new_devs) { |
| 984 | DMERR("'rebuild' devices cannot be " |
| 985 | "injected into an array with other first-time devices"); |
| 986 | return -EINVAL; |
| 987 | } else if (mddev->recovery_cp != MaxSector) { |
| 988 | DMERR("'rebuild' specified while array is not in-sync"); |
| 989 | return -EINVAL; |
| 990 | } |
| 991 | |
| 992 | /* |
| 993 | * Now we set the Faulty bit for those devices that are |
| 994 | * recorded in the superblock as failed. |
| 995 | */ |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 996 | rdev_for_each(r, mddev) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 997 | if (!r->sb_page) |
| 998 | continue; |
| 999 | sb2 = page_address(r->sb_page); |
| 1000 | sb2->failed_devices = 0; |
| 1001 | |
| 1002 | /* |
| 1003 | * Check for any device re-ordering. |
| 1004 | */ |
| 1005 | if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { |
| 1006 | role = le32_to_cpu(sb2->array_position); |
| 1007 | if (role != r->raid_disk) { |
| 1008 | if (rs->raid_type->level != 1) { |
| 1009 | rs->ti->error = "Cannot change device " |
| 1010 | "positions in RAID array"; |
| 1011 | return -EINVAL; |
| 1012 | } |
| 1013 | DMINFO("RAID1 device #%d now at position #%d", |
| 1014 | role, r->raid_disk); |
| 1015 | } |
| 1016 | |
| 1017 | /* |
| 1018 | * Partial recovery is performed on |
| 1019 | * returning failed devices. |
| 1020 | */ |
| 1021 | if (failed_devices & (1 << role)) |
| 1022 | set_bit(Faulty, &r->flags); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1029 | static int super_validate(struct raid_set *rs, struct md_rdev *rdev) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1030 | { |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1031 | struct mddev *mddev = &rs->md; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1032 | struct dm_raid_superblock *sb = page_address(rdev->sb_page); |
| 1033 | |
| 1034 | /* |
| 1035 | * If mddev->events is not set, we know we have not yet initialized |
| 1036 | * the array. |
| 1037 | */ |
| 1038 | if (!mddev->events && super_init_validation(mddev, rdev)) |
| 1039 | return -EINVAL; |
| 1040 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1041 | /* Enable bitmap creation for RAID levels != 0 */ |
| 1042 | mddev->bitmap_info.offset = (rs->raid_type->level) ? to_sector(4096) : 0; |
| 1043 | rdev->mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; |
| 1044 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1045 | if (!test_bit(FirstUse, &rdev->flags)) { |
| 1046 | rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset); |
| 1047 | if (rdev->recovery_offset != MaxSector) |
| 1048 | clear_bit(In_sync, &rdev->flags); |
| 1049 | } |
| 1050 | |
| 1051 | /* |
| 1052 | * If a device comes back, set it as not In_sync and no longer faulty. |
| 1053 | */ |
| 1054 | if (test_bit(Faulty, &rdev->flags)) { |
| 1055 | clear_bit(Faulty, &rdev->flags); |
| 1056 | clear_bit(In_sync, &rdev->flags); |
| 1057 | rdev->saved_raid_disk = rdev->raid_disk; |
| 1058 | rdev->recovery_offset = 0; |
| 1059 | } |
| 1060 | |
| 1061 | clear_bit(FirstUse, &rdev->flags); |
| 1062 | |
| 1063 | return 0; |
| 1064 | } |
| 1065 | |
| 1066 | /* |
| 1067 | * Analyse superblocks and select the freshest. |
| 1068 | */ |
| 1069 | static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs) |
| 1070 | { |
| 1071 | int ret; |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1072 | struct raid_dev *dev; |
Jonathan Brassow | a9ad852 | 2012-04-24 10:23:13 +1000 | [diff] [blame] | 1073 | struct md_rdev *rdev, *tmp, *freshest; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1074 | struct mddev *mddev = &rs->md; |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1075 | |
| 1076 | freshest = NULL; |
Jonathan Brassow | a9ad852 | 2012-04-24 10:23:13 +1000 | [diff] [blame] | 1077 | rdev_for_each_safe(rdev, tmp, mddev) { |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 1078 | /* |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1079 | * Skipping super_load due to CTR_FLAG_SYNC will cause |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 1080 | * the array to undergo initialization again as |
| 1081 | * though it were new. This is the intended effect |
| 1082 | * of the "sync" directive. |
| 1083 | * |
| 1084 | * When reshaping capability is added, we must ensure |
| 1085 | * that the "sync" directive is disallowed during the |
| 1086 | * reshape. |
| 1087 | */ |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1088 | rdev->sectors = to_sector(i_size_read(rdev->bdev->bd_inode)); |
| 1089 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1090 | if (rs->ctr_flags & CTR_FLAG_SYNC) |
Jonathan Brassow | 761becf | 2012-10-11 13:42:19 +1100 | [diff] [blame] | 1091 | continue; |
| 1092 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1093 | if (!rdev->meta_bdev) |
| 1094 | continue; |
| 1095 | |
| 1096 | ret = super_load(rdev, freshest); |
| 1097 | |
| 1098 | switch (ret) { |
| 1099 | case 1: |
| 1100 | freshest = rdev; |
| 1101 | break; |
| 1102 | case 0: |
| 1103 | break; |
| 1104 | default: |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1105 | dev = container_of(rdev, struct raid_dev, rdev); |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1106 | if (dev->meta_dev) |
| 1107 | dm_put_device(ti, dev->meta_dev); |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1108 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1109 | dev->meta_dev = NULL; |
| 1110 | rdev->meta_bdev = NULL; |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1111 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1112 | if (rdev->sb_page) |
| 1113 | put_page(rdev->sb_page); |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1114 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1115 | rdev->sb_page = NULL; |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1116 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1117 | rdev->sb_loaded = 0; |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1118 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1119 | /* |
| 1120 | * We might be able to salvage the data device |
| 1121 | * even though the meta device has failed. For |
| 1122 | * now, we behave as though '- -' had been |
| 1123 | * set for this device in the table. |
| 1124 | */ |
| 1125 | if (dev->data_dev) |
| 1126 | dm_put_device(ti, dev->data_dev); |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1127 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1128 | dev->data_dev = NULL; |
| 1129 | rdev->bdev = NULL; |
Jonathan E Brassow | 0447568 | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1130 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1131 | list_del(&rdev->same_set); |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | if (!freshest) |
| 1136 | return 0; |
| 1137 | |
Jonathan Brassow | 55ebbb5 | 2013-01-22 21:42:18 -0600 | [diff] [blame] | 1138 | if (validate_raid_redundancy(rs)) { |
| 1139 | rs->ti->error = "Insufficient redundancy to activate array"; |
| 1140 | return -EINVAL; |
| 1141 | } |
| 1142 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1143 | /* |
| 1144 | * Validation of the freshest device provides the source of |
| 1145 | * validation for the remaining devices. |
| 1146 | */ |
| 1147 | ti->error = "Unable to assemble array: Invalid superblocks"; |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1148 | if (super_validate(rs, freshest)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1149 | return -EINVAL; |
| 1150 | |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 1151 | rdev_for_each(rdev, mddev) |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1152 | if ((rdev != freshest) && super_validate(rs, rdev)) |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1153 | return -EINVAL; |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | /* |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1159 | * Enable/disable discard support on RAID set depending on |
| 1160 | * RAID level and discard properties of underlying RAID members. |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 1161 | */ |
| 1162 | static void configure_discard_support(struct dm_target *ti, struct raid_set *rs) |
| 1163 | { |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1164 | int i; |
| 1165 | bool raid456; |
| 1166 | |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 1167 | /* Assume discards not supported until after checks below. */ |
| 1168 | ti->discards_supported = false; |
| 1169 | |
| 1170 | /* RAID level 4,5,6 require discard_zeroes_data for data integrity! */ |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1171 | 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] | 1172 | |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1173 | for (i = 0; i < rs->md.raid_disks; i++) { |
Heinz Mauelshagen | d20c4b0 | 2014-10-29 19:02:27 +0100 | [diff] [blame] | 1174 | struct request_queue *q; |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1175 | |
Heinz Mauelshagen | d20c4b0 | 2014-10-29 19:02:27 +0100 | [diff] [blame] | 1176 | if (!rs->dev[i].rdev.bdev) |
| 1177 | continue; |
| 1178 | |
| 1179 | q = bdev_get_queue(rs->dev[i].rdev.bdev); |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1180 | if (!q || !blk_queue_discard(q)) |
| 1181 | return; |
| 1182 | |
| 1183 | if (raid456) { |
| 1184 | if (!q->limits.discard_zeroes_data) |
| 1185 | return; |
| 1186 | if (!devices_handle_discard_safely) { |
| 1187 | DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty."); |
| 1188 | DMERR("Set dm-raid.devices_handle_discard_safely=Y to override."); |
| 1189 | return; |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | /* All RAID members properly support discards */ |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 1195 | ti->discards_supported = true; |
| 1196 | |
| 1197 | /* |
| 1198 | * RAID1 and RAID10 personalities require bio splitting, |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1199 | * RAID0/4/5/6 don't and process large discard bios properly. |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 1200 | */ |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1201 | ti->split_discard_bios = !!(rs->md.level == 1 || rs->md.level == 10); |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 1202 | ti->num_discard_bios = 1; |
| 1203 | } |
| 1204 | |
| 1205 | /* |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1206 | * Construct a RAID4/5/6 mapping: |
| 1207 | * Args: |
| 1208 | * <raid_type> <#raid_params> <raid_params> \ |
| 1209 | * <#raid_devs> { <meta_dev1> <dev1> .. <meta_devN> <devN> } |
| 1210 | * |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1211 | * <raid_params> varies by <raid_type>. See 'parse_raid_params' for |
| 1212 | * details on possible <raid_params>. |
| 1213 | */ |
| 1214 | static int raid_ctr(struct dm_target *ti, unsigned argc, char **argv) |
| 1215 | { |
| 1216 | int ret; |
| 1217 | struct raid_type *rt; |
| 1218 | unsigned long num_raid_params, num_raid_devs; |
| 1219 | struct raid_set *rs = NULL; |
| 1220 | |
| 1221 | /* Must have at least <raid_type> <#raid_params> */ |
| 1222 | if (argc < 2) { |
| 1223 | ti->error = "Too few arguments"; |
| 1224 | return -EINVAL; |
| 1225 | } |
| 1226 | |
| 1227 | /* raid type */ |
| 1228 | rt = get_raid_type(argv[0]); |
| 1229 | if (!rt) { |
| 1230 | ti->error = "Unrecognised raid_type"; |
| 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | argc--; |
| 1234 | argv++; |
| 1235 | |
| 1236 | /* number of RAID parameters */ |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 1237 | if (kstrtoul(argv[0], 10, &num_raid_params) < 0) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1238 | ti->error = "Cannot understand number of RAID parameters"; |
| 1239 | return -EINVAL; |
| 1240 | } |
| 1241 | argc--; |
| 1242 | argv++; |
| 1243 | |
| 1244 | /* Skip over RAID params for now and find out # of devices */ |
Dan Carpenter | 3ca5a21 | 2014-05-29 11:23:23 +0300 | [diff] [blame] | 1245 | if (num_raid_params >= argc) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1246 | ti->error = "Arguments do not agree with counts given"; |
| 1247 | return -EINVAL; |
| 1248 | } |
| 1249 | |
Jingoo Han | b29bebd | 2013-06-01 16:15:16 +0900 | [diff] [blame] | 1250 | if ((kstrtoul(argv[num_raid_params], 10, &num_raid_devs) < 0) || |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1251 | (num_raid_devs > MAX_RAID_DEVICES)) { |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1252 | ti->error = "Cannot understand number of raid devices"; |
| 1253 | return -EINVAL; |
| 1254 | } |
| 1255 | |
Dan Carpenter | 3ca5a21 | 2014-05-29 11:23:23 +0300 | [diff] [blame] | 1256 | argc -= num_raid_params + 1; /* +1: we already have num_raid_devs */ |
| 1257 | if (argc != (num_raid_devs * 2)) { |
| 1258 | ti->error = "Supplied RAID devices does not match the count given"; |
| 1259 | return -EINVAL; |
| 1260 | } |
| 1261 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1262 | rs = context_alloc(ti, rt, (unsigned)num_raid_devs); |
| 1263 | if (IS_ERR(rs)) |
| 1264 | return PTR_ERR(rs); |
| 1265 | |
| 1266 | ret = parse_raid_params(rs, argv, (unsigned)num_raid_params); |
| 1267 | if (ret) |
| 1268 | goto bad; |
| 1269 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1270 | argv += num_raid_params + 1; |
| 1271 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1272 | ret = dev_parms(rs, argv); |
| 1273 | if (ret) |
| 1274 | goto bad; |
| 1275 | |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1276 | rs->md.sync_super = super_sync; |
| 1277 | ret = analyse_superblocks(ti, rs); |
| 1278 | if (ret) |
| 1279 | goto bad; |
| 1280 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1281 | INIT_WORK(&rs->md.event_work, do_table_event); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1282 | ti->private = rs; |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 1283 | ti->num_flush_bios = 1; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1284 | |
Heinz Mauelshagen | 75b8e04 | 2014-09-24 17:47:18 +0200 | [diff] [blame] | 1285 | /* |
| 1286 | * Disable/enable discard support on RAID set. |
| 1287 | */ |
| 1288 | configure_discard_support(ti, rs); |
| 1289 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1290 | /* Has to be held on running the array */ |
| 1291 | mddev_lock_nointr(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1292 | ret = md_run(&rs->md); |
| 1293 | rs->md.in_sync = 0; /* Assume already marked dirty */ |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1294 | mddev_unlock(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1295 | |
| 1296 | if (ret) { |
| 1297 | ti->error = "Fail to run raid array"; |
| 1298 | goto bad; |
| 1299 | } |
| 1300 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1301 | if (ti->len != rs->md.array_sectors) { |
| 1302 | ti->error = "Array size does not match requested target length"; |
| 1303 | ret = -EINVAL; |
| 1304 | goto size_mismatch; |
| 1305 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1306 | rs->callbacks.congested_fn = raid_is_congested; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1307 | dm_table_add_target_callbacks(ti->table, &rs->callbacks); |
| 1308 | |
Jonathan Brassow | 3273727 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1309 | mddev_suspend(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1310 | return 0; |
| 1311 | |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1312 | size_mismatch: |
| 1313 | md_stop(&rs->md); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1314 | bad: |
| 1315 | context_free(rs); |
| 1316 | |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
| 1320 | static void raid_dtr(struct dm_target *ti) |
| 1321 | { |
| 1322 | struct raid_set *rs = ti->private; |
| 1323 | |
| 1324 | list_del_init(&rs->callbacks.list); |
| 1325 | md_stop(&rs->md); |
| 1326 | context_free(rs); |
| 1327 | } |
| 1328 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1329 | static int raid_map(struct dm_target *ti, struct bio *bio) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1330 | { |
| 1331 | struct raid_set *rs = ti->private; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 1332 | struct mddev *mddev = &rs->md; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1333 | |
| 1334 | mddev->pers->make_request(mddev, bio); |
| 1335 | |
| 1336 | return DM_MAPIO_SUBMITTED; |
| 1337 | } |
| 1338 | |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 1339 | static const char *decipher_sync_action(struct mddev *mddev) |
| 1340 | { |
| 1341 | if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) |
| 1342 | return "frozen"; |
| 1343 | |
| 1344 | if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 1345 | (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) { |
| 1346 | if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery)) |
| 1347 | return "reshape"; |
| 1348 | |
| 1349 | if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { |
| 1350 | if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) |
| 1351 | return "resync"; |
| 1352 | else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)) |
| 1353 | return "check"; |
| 1354 | return "repair"; |
| 1355 | } |
| 1356 | |
| 1357 | if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery)) |
| 1358 | return "recover"; |
| 1359 | } |
| 1360 | |
| 1361 | return "idle"; |
| 1362 | } |
| 1363 | |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 1364 | static void raid_status(struct dm_target *ti, status_type_t type, |
| 1365 | unsigned status_flags, char *result, unsigned maxlen) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1366 | { |
| 1367 | struct raid_set *rs = ti->private; |
| 1368 | unsigned raid_param_cnt = 1; /* at least 1 for chunksize */ |
| 1369 | unsigned sz = 0; |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 1370 | int i, array_in_sync = 0; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1371 | sector_t sync; |
| 1372 | |
| 1373 | switch (type) { |
| 1374 | case STATUSTYPE_INFO: |
| 1375 | DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks); |
| 1376 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1377 | if (rs->raid_type->level) { |
| 1378 | if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery)) |
| 1379 | sync = rs->md.curr_resync_completed; |
| 1380 | else |
| 1381 | sync = rs->md.recovery_cp; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1382 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1383 | if (sync >= rs->md.resync_max_sectors) { |
| 1384 | /* |
| 1385 | * Sync complete. |
| 1386 | */ |
| 1387 | array_in_sync = 1; |
| 1388 | sync = rs->md.resync_max_sectors; |
| 1389 | } else if (test_bit(MD_RECOVERY_REQUESTED, &rs->md.recovery)) { |
| 1390 | /* |
| 1391 | * If "check" or "repair" is occurring, the array has |
| 1392 | * undergone and initial sync and the health characters |
| 1393 | * should not be 'a' anymore. |
| 1394 | */ |
| 1395 | array_in_sync = 1; |
| 1396 | } else { |
| 1397 | /* |
| 1398 | * The array may be doing an initial sync, or it may |
| 1399 | * be rebuilding individual components. If all the |
| 1400 | * devices are In_sync, then it is the array that is |
| 1401 | * being initialized. |
| 1402 | */ |
| 1403 | for (i = 0; i < rs->md.raid_disks; i++) |
| 1404 | if (!test_bit(In_sync, &rs->dev[i].rdev.flags)) |
| 1405 | array_in_sync = 1; |
| 1406 | } |
| 1407 | } else { |
| 1408 | /* RAID0 */ |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 1409 | array_in_sync = 1; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1410 | sync = rs->md.resync_max_sectors; |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 1411 | } |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 1412 | |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 1413 | /* |
| 1414 | * Status characters: |
| 1415 | * 'D' = Dead/Failed device |
| 1416 | * 'a' = Alive but not in-sync |
| 1417 | * 'A' = Alive and in-sync |
| 1418 | */ |
| 1419 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 1420 | if (test_bit(Faulty, &rs->dev[i].rdev.flags)) |
| 1421 | DMEMIT("D"); |
| 1422 | else if (!array_in_sync || |
| 1423 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) |
| 1424 | DMEMIT("a"); |
| 1425 | else |
| 1426 | DMEMIT("A"); |
| 1427 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1428 | |
Jonathan E Brassow | 2e727c3 | 2011-10-31 20:21:26 +0000 | [diff] [blame] | 1429 | /* |
| 1430 | * In-sync ratio: |
| 1431 | * The in-sync ratio shows the progress of: |
| 1432 | * - Initializing the array |
| 1433 | * - Rebuilding a subset of devices of the array |
| 1434 | * The user can distinguish between the two by referring |
| 1435 | * to the status characters. |
| 1436 | */ |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1437 | DMEMIT(" %llu/%llu", |
| 1438 | (unsigned long long) sync, |
| 1439 | (unsigned long long) rs->md.resync_max_sectors); |
| 1440 | |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 1441 | /* |
| 1442 | * Sync action: |
| 1443 | * See Documentation/device-mapper/dm-raid.c for |
| 1444 | * information on each of these states. |
| 1445 | */ |
| 1446 | DMEMIT(" %s", decipher_sync_action(&rs->md)); |
| 1447 | |
| 1448 | /* |
| 1449 | * resync_mismatches/mismatch_cnt |
| 1450 | * This field shows the number of discrepancies found when |
| 1451 | * performing a "check" of the array. |
| 1452 | */ |
| 1453 | DMEMIT(" %llu", |
Jonathan Brassow | c4a3955 | 2013-06-25 01:23:59 -0500 | [diff] [blame] | 1454 | (strcmp(rs->md.last_sync_action, "check")) ? 0 : |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 1455 | (unsigned long long) |
| 1456 | atomic64_read(&rs->md.resync_mismatches)); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1457 | break; |
| 1458 | case STATUSTYPE_TABLE: |
| 1459 | /* The string you would use to construct this array */ |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1460 | for (i = 0; i < rs->md.raid_disks; i++) { |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1461 | if ((rs->ctr_flags & CTR_FLAG_REBUILD) && |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1462 | rs->dev[i].data_dev && |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1463 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1464 | raid_param_cnt += 2; /* for rebuilds */ |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1465 | if (rs->dev[i].data_dev && |
| 1466 | test_bit(WriteMostly, &rs->dev[i].rdev.flags)) |
| 1467 | raid_param_cnt += 2; |
| 1468 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1469 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1470 | raid_param_cnt += (hweight32(rs->ctr_flags & ~CTR_FLAG_REBUILD) * 2); |
| 1471 | if (rs->ctr_flags & (CTR_FLAG_SYNC | CTR_FLAG_NOSYNC)) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1472 | raid_param_cnt--; |
| 1473 | |
| 1474 | DMEMIT("%s %u %u", rs->raid_type->name, |
| 1475 | raid_param_cnt, rs->md.chunk_sectors); |
| 1476 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1477 | if ((rs->ctr_flags & CTR_FLAG_SYNC) && |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1478 | (rs->md.recovery_cp == MaxSector)) |
| 1479 | DMEMIT(" sync"); |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1480 | if (rs->ctr_flags & CTR_FLAG_NOSYNC) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1481 | DMEMIT(" nosync"); |
| 1482 | |
| 1483 | for (i = 0; i < rs->md.raid_disks; i++) |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1484 | if ((rs->ctr_flags & CTR_FLAG_REBUILD) && |
Jonathan Brassow | 13c8758 | 2011-08-02 12:32:03 +0100 | [diff] [blame] | 1485 | rs->dev[i].data_dev && |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1486 | !test_bit(In_sync, &rs->dev[i].rdev.flags)) |
| 1487 | DMEMIT(" rebuild %u", i); |
| 1488 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1489 | if (rs->ctr_flags & CTR_FLAG_DAEMON_SLEEP) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1490 | DMEMIT(" daemon_sleep %lu", |
| 1491 | rs->md.bitmap_info.daemon_sleep); |
| 1492 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1493 | if (rs->ctr_flags & CTR_FLAG_MIN_RECOVERY_RATE) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1494 | DMEMIT(" min_recovery_rate %d", rs->md.sync_speed_min); |
| 1495 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1496 | if (rs->ctr_flags & CTR_FLAG_MAX_RECOVERY_RATE) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1497 | DMEMIT(" max_recovery_rate %d", rs->md.sync_speed_max); |
| 1498 | |
Jonathan Brassow | 46bed2b | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1499 | for (i = 0; i < rs->md.raid_disks; i++) |
| 1500 | if (rs->dev[i].data_dev && |
| 1501 | test_bit(WriteMostly, &rs->dev[i].rdev.flags)) |
| 1502 | DMEMIT(" write_mostly %u", i); |
| 1503 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1504 | if (rs->ctr_flags & CTR_FLAG_MAX_WRITE_BEHIND) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1505 | DMEMIT(" max_write_behind %lu", |
| 1506 | rs->md.bitmap_info.max_write_behind); |
| 1507 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1508 | if (rs->ctr_flags & CTR_FLAG_STRIPE_CACHE) { |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1509 | struct r5conf *conf = rs->md.private; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1510 | |
| 1511 | /* convert from kiB to sectors */ |
| 1512 | DMEMIT(" stripe_cache %d", |
| 1513 | conf ? conf->max_nr_stripes * 2 : 0); |
| 1514 | } |
| 1515 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1516 | if (rs->ctr_flags & CTR_FLAG_REGION_SIZE) |
Jonathan Brassow | c108456 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1517 | DMEMIT(" region_size %lu", |
| 1518 | rs->md.bitmap_info.chunksize >> 9); |
| 1519 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1520 | if (rs->ctr_flags & CTR_FLAG_RAID10_COPIES) |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1521 | DMEMIT(" raid10_copies %u", |
| 1522 | raid10_md_layout_to_copies(rs->md.layout)); |
| 1523 | |
Heinz Mauelshagen | c76d53f | 2015-04-29 14:03:00 +0200 | [diff] [blame] | 1524 | if (rs->ctr_flags & CTR_FLAG_RAID10_FORMAT) |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1525 | DMEMIT(" raid10_format %s", |
| 1526 | raid10_md_layout_to_format(rs->md.layout)); |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1527 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1528 | DMEMIT(" %d", rs->md.raid_disks); |
| 1529 | for (i = 0; i < rs->md.raid_disks; i++) { |
Jonathan Brassow | b12d437 | 2011-08-02 12:32:07 +0100 | [diff] [blame] | 1530 | if (rs->dev[i].meta_dev) |
| 1531 | DMEMIT(" %s", rs->dev[i].meta_dev->name); |
| 1532 | else |
| 1533 | DMEMIT(" -"); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1534 | |
| 1535 | if (rs->dev[i].data_dev) |
| 1536 | DMEMIT(" %s", rs->dev[i].data_dev->name); |
| 1537 | else |
| 1538 | DMEMIT(" -"); |
| 1539 | } |
| 1540 | } |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 1543 | static int raid_message(struct dm_target *ti, unsigned argc, char **argv) |
| 1544 | { |
| 1545 | struct raid_set *rs = ti->private; |
| 1546 | struct mddev *mddev = &rs->md; |
| 1547 | |
| 1548 | if (!strcasecmp(argv[0], "reshape")) { |
| 1549 | DMERR("Reshape not supported."); |
| 1550 | return -EINVAL; |
| 1551 | } |
| 1552 | |
| 1553 | if (!mddev->pers || !mddev->pers->sync_request) |
| 1554 | return -EINVAL; |
| 1555 | |
| 1556 | if (!strcasecmp(argv[0], "frozen")) |
| 1557 | set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 1558 | else |
| 1559 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
| 1560 | |
| 1561 | if (!strcasecmp(argv[0], "idle") || !strcasecmp(argv[0], "frozen")) { |
| 1562 | if (mddev->sync_thread) { |
| 1563 | set_bit(MD_RECOVERY_INTR, &mddev->recovery); |
| 1564 | md_reap_sync_thread(mddev); |
| 1565 | } |
| 1566 | } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) || |
| 1567 | test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) |
| 1568 | return -EBUSY; |
| 1569 | else if (!strcasecmp(argv[0], "resync")) |
| 1570 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 1571 | else if (!strcasecmp(argv[0], "recover")) { |
| 1572 | set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); |
| 1573 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 1574 | } else { |
| 1575 | if (!strcasecmp(argv[0], "check")) |
| 1576 | set_bit(MD_RECOVERY_CHECK, &mddev->recovery); |
| 1577 | else if (!!strcasecmp(argv[0], "repair")) |
| 1578 | return -EINVAL; |
| 1579 | set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery); |
| 1580 | set_bit(MD_RECOVERY_SYNC, &mddev->recovery); |
| 1581 | } |
| 1582 | if (mddev->ro == 2) { |
| 1583 | /* A write to sync_action is enough to justify |
| 1584 | * canceling read-auto mode |
| 1585 | */ |
| 1586 | mddev->ro = 0; |
| 1587 | if (!mddev->suspended) |
| 1588 | md_wakeup_thread(mddev->sync_thread); |
| 1589 | } |
| 1590 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 1591 | if (!mddev->suspended) |
| 1592 | md_wakeup_thread(mddev->thread); |
| 1593 | |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
| 1597 | static int raid_iterate_devices(struct dm_target *ti, |
| 1598 | iterate_devices_callout_fn fn, void *data) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1599 | { |
| 1600 | struct raid_set *rs = ti->private; |
| 1601 | unsigned i; |
| 1602 | int ret = 0; |
| 1603 | |
| 1604 | for (i = 0; !ret && i < rs->md.raid_disks; i++) |
| 1605 | if (rs->dev[i].data_dev) |
| 1606 | ret = fn(ti, |
| 1607 | rs->dev[i].data_dev, |
| 1608 | 0, /* No offset on data devs */ |
| 1609 | rs->md.dev_sectors, |
| 1610 | data); |
| 1611 | |
| 1612 | return ret; |
| 1613 | } |
| 1614 | |
| 1615 | static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits) |
| 1616 | { |
| 1617 | struct raid_set *rs = ti->private; |
| 1618 | unsigned chunk_size = rs->md.chunk_sectors << 9; |
NeilBrown | d1688a6 | 2011-10-11 16:49:52 +1100 | [diff] [blame] | 1619 | struct r5conf *conf = rs->md.private; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1620 | |
| 1621 | blk_limits_io_min(limits, chunk_size); |
| 1622 | blk_limits_io_opt(limits, chunk_size * (conf->raid_disks - conf->max_degraded)); |
| 1623 | } |
| 1624 | |
| 1625 | static void raid_presuspend(struct dm_target *ti) |
| 1626 | { |
| 1627 | struct raid_set *rs = ti->private; |
| 1628 | |
| 1629 | md_stop_writes(&rs->md); |
| 1630 | } |
| 1631 | |
| 1632 | static void raid_postsuspend(struct dm_target *ti) |
| 1633 | { |
| 1634 | struct raid_set *rs = ti->private; |
| 1635 | |
| 1636 | mddev_suspend(&rs->md); |
| 1637 | } |
| 1638 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 1639 | static void attempt_restore_of_faulty_devices(struct raid_set *rs) |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1640 | { |
Jonathan Brassow | 9092c02 | 2013-05-02 14:19:24 -0500 | [diff] [blame] | 1641 | int i; |
| 1642 | uint64_t failed_devices, cleared_failed_devices = 0; |
| 1643 | unsigned long flags; |
| 1644 | struct dm_raid_superblock *sb; |
Jonathan Brassow | 9092c02 | 2013-05-02 14:19:24 -0500 | [diff] [blame] | 1645 | struct md_rdev *r; |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1646 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 1647 | for (i = 0; i < rs->md.raid_disks; i++) { |
| 1648 | r = &rs->dev[i].rdev; |
| 1649 | if (test_bit(Faulty, &r->flags) && r->sb_page && |
| 1650 | sync_page_io(r, 0, r->sb_size, r->sb_page, READ, 1)) { |
| 1651 | DMINFO("Faulty %s device #%d has readable super block." |
| 1652 | " Attempting to revive it.", |
| 1653 | rs->raid_type->name, i); |
Jonathan Brassow | a4dc163 | 2013-05-08 18:00:54 -0500 | [diff] [blame] | 1654 | |
| 1655 | /* |
| 1656 | * Faulty bit may be set, but sometimes the array can |
| 1657 | * be suspended before the personalities can respond |
| 1658 | * by removing the device from the array (i.e. calling |
| 1659 | * 'hot_remove_disk'). If they haven't yet removed |
| 1660 | * the failed device, its 'raid_disk' number will be |
| 1661 | * '>= 0' - meaning we must call this function |
| 1662 | * ourselves. |
| 1663 | */ |
| 1664 | if ((r->raid_disk >= 0) && |
| 1665 | (r->mddev->pers->hot_remove_disk(r->mddev, r) != 0)) |
| 1666 | /* Failed to revive this device, try next */ |
| 1667 | continue; |
| 1668 | |
Jonathan Brassow | f381e71 | 2013-05-08 17:57:13 -0500 | [diff] [blame] | 1669 | r->raid_disk = i; |
| 1670 | r->saved_raid_disk = i; |
| 1671 | flags = r->flags; |
| 1672 | clear_bit(Faulty, &r->flags); |
| 1673 | clear_bit(WriteErrorSeen, &r->flags); |
| 1674 | clear_bit(In_sync, &r->flags); |
| 1675 | if (r->mddev->pers->hot_add_disk(r->mddev, r)) { |
| 1676 | r->raid_disk = -1; |
| 1677 | r->saved_raid_disk = -1; |
| 1678 | r->flags = flags; |
| 1679 | } else { |
| 1680 | r->recovery_offset = 0; |
| 1681 | cleared_failed_devices |= 1 << i; |
| 1682 | } |
| 1683 | } |
| 1684 | } |
| 1685 | if (cleared_failed_devices) { |
| 1686 | rdev_for_each(r, &rs->md) { |
| 1687 | sb = page_address(r->sb_page); |
| 1688 | failed_devices = le64_to_cpu(sb->failed_devices); |
| 1689 | failed_devices &= ~cleared_failed_devices; |
| 1690 | sb->failed_devices = cpu_to_le64(failed_devices); |
| 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | static void raid_resume(struct dm_target *ti) |
| 1696 | { |
| 1697 | struct raid_set *rs = ti->private; |
| 1698 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1699 | if (rs->raid_type->level) { |
| 1700 | set_bit(MD_CHANGE_DEVS, &rs->md.flags); |
| 1701 | |
| 1702 | if (!rs->bitmap_loaded) { |
| 1703 | bitmap_load(&rs->md); |
| 1704 | rs->bitmap_loaded = 1; |
| 1705 | } else { |
| 1706 | /* |
| 1707 | * A secondary resume while the device is active. |
| 1708 | * Take this opportunity to check whether any failed |
| 1709 | * devices are reachable again. |
| 1710 | */ |
| 1711 | attempt_restore_of_faulty_devices(rs); |
| 1712 | } |
| 1713 | |
| 1714 | clear_bit(MD_RECOVERY_FROZEN, &rs->md.recovery); |
Jonathan Brassow | 47525e5 | 2012-05-22 13:55:29 +1000 | [diff] [blame] | 1715 | } |
Jonathan Brassow | 34f8ac6d | 2012-01-27 14:53:53 -0600 | [diff] [blame] | 1716 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1717 | mddev_resume(&rs->md); |
| 1718 | } |
| 1719 | |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1720 | static int raid_merge(struct dm_target *ti, struct bvec_merge_data *bvm, |
| 1721 | struct bio_vec *biovec, int max_size) |
| 1722 | { |
| 1723 | struct raid_set *rs = ti->private; |
| 1724 | struct md_personality *pers = rs->md.pers; |
| 1725 | |
| 1726 | if (pers && pers->mergeable_bvec) |
| 1727 | return min(max_size, pers->mergeable_bvec(&rs->md, bvm, biovec)); |
| 1728 | |
| 1729 | /* |
| 1730 | * In case we can't request the personality because |
| 1731 | * the raid set is not running yet |
| 1732 | * |
| 1733 | * -> return safe minimum |
| 1734 | */ |
| 1735 | return rs->md.chunk_sectors; |
| 1736 | } |
| 1737 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1738 | static struct target_type raid_target = { |
| 1739 | .name = "raid", |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1740 | .version = {1, 7, 0}, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1741 | .module = THIS_MODULE, |
| 1742 | .ctr = raid_ctr, |
| 1743 | .dtr = raid_dtr, |
| 1744 | .map = raid_map, |
| 1745 | .status = raid_status, |
Jonathan Brassow | be83651 | 2013-04-24 11:42:43 +1000 | [diff] [blame] | 1746 | .message = raid_message, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1747 | .iterate_devices = raid_iterate_devices, |
| 1748 | .io_hints = raid_io_hints, |
| 1749 | .presuspend = raid_presuspend, |
| 1750 | .postsuspend = raid_postsuspend, |
| 1751 | .resume = raid_resume, |
Heinz Mauelshagen | 0cf4503 | 2015-04-29 14:03:04 +0200 | [diff] [blame] | 1752 | .merge = raid_merge, |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1753 | }; |
| 1754 | |
| 1755 | static int __init dm_raid_init(void) |
| 1756 | { |
Jonathan Brassow | fe5d2f4 | 2013-02-21 13:28:10 +1100 | [diff] [blame] | 1757 | DMINFO("Loading target version %u.%u.%u", |
| 1758 | raid_target.version[0], |
| 1759 | raid_target.version[1], |
| 1760 | raid_target.version[2]); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1761 | return dm_register_target(&raid_target); |
| 1762 | } |
| 1763 | |
| 1764 | static void __exit dm_raid_exit(void) |
| 1765 | { |
| 1766 | dm_unregister_target(&raid_target); |
| 1767 | } |
| 1768 | |
| 1769 | module_init(dm_raid_init); |
| 1770 | module_exit(dm_raid_exit); |
| 1771 | |
Heinz Mauelshagen | 48cf06b | 2014-09-24 17:47:19 +0200 | [diff] [blame] | 1772 | module_param(devices_handle_discard_safely, bool, 0644); |
| 1773 | MODULE_PARM_DESC(devices_handle_discard_safely, |
| 1774 | "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions"); |
| 1775 | |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1776 | MODULE_DESCRIPTION(DM_NAME " raid4/5/6 target"); |
Jonathan Brassow | 63f33b8d | 2012-07-31 21:44:26 -0500 | [diff] [blame] | 1777 | MODULE_ALIAS("dm-raid1"); |
| 1778 | MODULE_ALIAS("dm-raid10"); |
NeilBrown | 9d09e66 | 2011-01-13 20:00:02 +0000 | [diff] [blame] | 1779 | MODULE_ALIAS("dm-raid4"); |
| 1780 | MODULE_ALIAS("dm-raid5"); |
| 1781 | MODULE_ALIAS("dm-raid6"); |
| 1782 | MODULE_AUTHOR("Neil Brown <dm-devel@redhat.com>"); |
| 1783 | MODULE_LICENSE("GPL"); |