2 * Copyright (C) 2010-2011 Neil Brown
3 * Copyright (C) 2010-2014 Red Hat, Inc. All rights reserved.
5 * This file is released under the GPL.
8 #include <linux/slab.h>
9 #include <linux/module.h>
17 #include <linux/device-mapper.h>
19 #define DM_MSG_PREFIX "raid"
21 static bool devices_handle_discard_safely = false;
24 * The following flags are used by dm-raid.c to set up the array state.
25 * They must be cleared before md_run is called.
27 #define FirstUse 10 /* rdev flag */
31 * Two DM devices, one to hold metadata and one to hold the
32 * actual data/parity. The reason for this is to not confuse
33 * ti->len and give more flexibility in altering size and
36 * While it is possible for this device to be associated
37 * with a different physical device than the data_dev, it
38 * is intended for it to be the same.
39 * |--------- Physical Device ---------|
40 * |- meta_dev -|------ data_dev ------|
42 struct dm_dev *meta_dev;
43 struct dm_dev *data_dev;
48 * Flags for rs->print_flags field.
51 #define DMPF_NOSYNC 0x2
52 #define DMPF_REBUILD 0x4
53 #define DMPF_DAEMON_SLEEP 0x8
54 #define DMPF_MIN_RECOVERY_RATE 0x10
55 #define DMPF_MAX_RECOVERY_RATE 0x20
56 #define DMPF_MAX_WRITE_BEHIND 0x40
57 #define DMPF_STRIPE_CACHE 0x80
58 #define DMPF_REGION_SIZE 0x100
59 #define DMPF_RAID10_COPIES 0x200
60 #define DMPF_RAID10_FORMAT 0x400
65 uint32_t bitmap_loaded;
69 struct raid_type *raid_type;
70 struct dm_target_callbacks callbacks;
72 struct raid_dev dev[0];
75 /* Supported raid types and properties. */
76 static struct raid_type {
77 const char *name; /* RAID algorithm. */
78 const char *descr; /* Descriptor text for logging. */
79 const unsigned parity_devs; /* # of parity devices. */
80 const unsigned minimal_devs; /* minimal # of devices in set. */
81 const unsigned level; /* RAID level. */
82 const unsigned algorithm; /* RAID algorithm. */
84 {"raid1", "RAID1 (mirroring)", 0, 2, 1, 0 /* NONE */},
85 {"raid10", "RAID10 (striped mirrors)", 0, 2, 10, UINT_MAX /* Varies */},
86 {"raid4", "RAID4 (dedicated parity disk)", 1, 2, 5, ALGORITHM_PARITY_0},
87 {"raid5_la", "RAID5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC},
88 {"raid5_ra", "RAID5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC},
89 {"raid5_ls", "RAID5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC},
90 {"raid5_rs", "RAID5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC},
91 {"raid6_zr", "RAID6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART},
92 {"raid6_nr", "RAID6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART},
93 {"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE}
96 static char *raid10_md_layout_to_format(int layout)
99 * Bit 16 and 17 stand for "offset" and "use_far_sets"
100 * Refer to MD's raid10.c for details
102 if ((layout & 0x10000) && (layout & 0x20000))
105 if ((layout & 0xFF) > 1)
111 static unsigned raid10_md_layout_to_copies(int layout)
113 if ((layout & 0xFF) > 1)
114 return layout & 0xFF;
115 return (layout >> 8) & 0xFF;
118 static int raid10_format_to_md_layout(char *format, unsigned copies)
120 unsigned n = 1, f = 1;
122 if (!strcmp("near", format))
127 if (!strcmp("offset", format))
128 return 0x30000 | (f << 8) | n;
130 if (!strcmp("far", format))
131 return 0x20000 | (f << 8) | n;
136 static struct raid_type *get_raid_type(char *name)
140 for (i = 0; i < ARRAY_SIZE(raid_types); i++)
141 if (!strcmp(raid_types[i].name, name))
142 return &raid_types[i];
147 static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *raid_type, unsigned raid_devs)
152 if (raid_devs <= raid_type->parity_devs) {
153 ti->error = "Insufficient number of devices";
154 return ERR_PTR(-EINVAL);
157 rs = kzalloc(sizeof(*rs) + raid_devs * sizeof(rs->dev[0]), GFP_KERNEL);
159 ti->error = "Cannot allocate raid context";
160 return ERR_PTR(-ENOMEM);
166 rs->raid_type = raid_type;
167 rs->md.raid_disks = raid_devs;
168 rs->md.level = raid_type->level;
169 rs->md.new_level = rs->md.level;
170 rs->md.layout = raid_type->algorithm;
171 rs->md.new_layout = rs->md.layout;
172 rs->md.delta_disks = 0;
173 rs->md.recovery_cp = 0;
175 for (i = 0; i < raid_devs; i++)
176 md_rdev_init(&rs->dev[i].rdev);
179 * Remaining items to be initialized by further RAID params:
182 * rs->md.chunk_sectors
183 * rs->md.new_chunk_sectors
190 static void context_free(struct raid_set *rs)
194 for (i = 0; i < rs->md.raid_disks; i++) {
195 if (rs->dev[i].meta_dev)
196 dm_put_device(rs->ti, rs->dev[i].meta_dev);
197 md_rdev_clear(&rs->dev[i].rdev);
198 if (rs->dev[i].data_dev)
199 dm_put_device(rs->ti, rs->dev[i].data_dev);
206 * For every device we have two words
207 * <meta_dev>: meta device name or '-' if missing
208 * <data_dev>: data device name or '-' if missing
210 * The following are permitted:
213 * <meta_dev> <data_dev>
215 * The following is not allowed:
218 * This code parses those words. If there is a failure,
219 * the caller must use context_free to unwind the operations.
221 static int dev_parms(struct raid_set *rs, char **argv)
225 int metadata_available = 0;
228 for (i = 0; i < rs->md.raid_disks; i++, argv += 2) {
229 rs->dev[i].rdev.raid_disk = i;
231 rs->dev[i].meta_dev = NULL;
232 rs->dev[i].data_dev = NULL;
235 * There are no offsets, since there is a separate device
236 * for data and metadata.
238 rs->dev[i].rdev.data_offset = 0;
239 rs->dev[i].rdev.mddev = &rs->md;
241 if (strcmp(argv[0], "-")) {
242 ret = dm_get_device(rs->ti, argv[0],
243 dm_table_get_mode(rs->ti->table),
244 &rs->dev[i].meta_dev);
245 rs->ti->error = "RAID metadata device lookup failure";
249 rs->dev[i].rdev.sb_page = alloc_page(GFP_KERNEL);
250 if (!rs->dev[i].rdev.sb_page)
254 if (!strcmp(argv[1], "-")) {
255 if (!test_bit(In_sync, &rs->dev[i].rdev.flags) &&
256 (!rs->dev[i].rdev.recovery_offset)) {
257 rs->ti->error = "Drive designated for rebuild not specified";
261 rs->ti->error = "No data device supplied with metadata device";
262 if (rs->dev[i].meta_dev)
268 ret = dm_get_device(rs->ti, argv[1],
269 dm_table_get_mode(rs->ti->table),
270 &rs->dev[i].data_dev);
272 rs->ti->error = "RAID device lookup failure";
276 if (rs->dev[i].meta_dev) {
277 metadata_available = 1;
278 rs->dev[i].rdev.meta_bdev = rs->dev[i].meta_dev->bdev;
280 rs->dev[i].rdev.bdev = rs->dev[i].data_dev->bdev;
281 list_add(&rs->dev[i].rdev.same_set, &rs->md.disks);
282 if (!test_bit(In_sync, &rs->dev[i].rdev.flags))
286 if (metadata_available) {
288 rs->md.persistent = 1;
289 rs->md.major_version = 2;
290 } else if (rebuild && !rs->md.recovery_cp) {
292 * Without metadata, we will not be able to tell if the array
293 * is in-sync or not - we must assume it is not. Therefore,
294 * it is impossible to rebuild a drive.
296 * Even if there is metadata, the on-disk information may
297 * indicate that the array is not in-sync and it will then
300 * User could specify 'nosync' option if desperate.
302 DMERR("Unable to rebuild drive while array is not in-sync");
303 rs->ti->error = "RAID device lookup failure";
311 * validate_region_size
313 * @region_size: region size in sectors. If 0, pick a size (4MiB default).
315 * Set rs->md.bitmap_info.chunksize (which really refers to 'region size').
316 * Ensure that (ti->len/region_size < 2^21) - required by MD bitmap.
318 * Returns: 0 on success, -EINVAL on failure.
320 static int validate_region_size(struct raid_set *rs, unsigned long region_size)
322 unsigned long min_region_size = rs->ti->len / (1 << 21);
326 * Choose a reasonable default. All figures in sectors.
328 if (min_region_size > (1 << 13)) {
329 /* If not a power of 2, make it the next power of 2 */
330 if (min_region_size & (min_region_size - 1))
331 region_size = 1 << fls(region_size);
332 DMINFO("Choosing default region size of %lu sectors",
335 DMINFO("Choosing default region size of 4MiB");
336 region_size = 1 << 13; /* sectors */
340 * Validate user-supplied value.
342 if (region_size > rs->ti->len) {
343 rs->ti->error = "Supplied region size is too large";
347 if (region_size < min_region_size) {
348 DMERR("Supplied region_size (%lu sectors) below minimum (%lu)",
349 region_size, min_region_size);
350 rs->ti->error = "Supplied region size is too small";
354 if (!is_power_of_2(region_size)) {
355 rs->ti->error = "Region size is not a power of 2";
359 if (region_size < rs->md.chunk_sectors) {
360 rs->ti->error = "Region size is smaller than the chunk size";
366 * Convert sectors to bytes.
368 rs->md.bitmap_info.chunksize = (region_size << 9);
374 * validate_raid_redundancy
377 * Determine if there are enough devices in the array that haven't
378 * failed (or are being rebuilt) to form a usable array.
380 * Returns: 0 on success, -EINVAL on failure.
382 static int validate_raid_redundancy(struct raid_set *rs)
384 unsigned i, rebuild_cnt = 0;
385 unsigned rebuilds_per_group = 0, copies, d;
386 unsigned group_size, last_group_start;
388 for (i = 0; i < rs->md.raid_disks; i++)
389 if (!test_bit(In_sync, &rs->dev[i].rdev.flags) ||
390 !rs->dev[i].rdev.sb_page)
393 switch (rs->raid_type->level) {
395 if (rebuild_cnt >= rs->md.raid_disks)
401 if (rebuild_cnt > rs->raid_type->parity_devs)
405 copies = raid10_md_layout_to_copies(rs->md.layout);
406 if (rebuild_cnt < copies)
410 * It is possible to have a higher rebuild count for RAID10,
411 * as long as the failed devices occur in different mirror
412 * groups (i.e. different stripes).
414 * When checking "near" format, make sure no adjacent devices
415 * have failed beyond what can be handled. In addition to the
416 * simple case where the number of devices is a multiple of the
417 * number of copies, we must also handle cases where the number
418 * of devices is not a multiple of the number of copies.
419 * E.g. dev1 dev2 dev3 dev4 dev5
423 if (!strcmp("near", raid10_md_layout_to_format(rs->md.layout))) {
424 for (i = 0; i < rs->md.raid_disks * copies; i++) {
426 rebuilds_per_group = 0;
427 d = i % rs->md.raid_disks;
428 if ((!rs->dev[d].rdev.sb_page ||
429 !test_bit(In_sync, &rs->dev[d].rdev.flags)) &&
430 (++rebuilds_per_group >= copies))
437 * When checking "far" and "offset" formats, we need to ensure
438 * that the device that holds its copy is not also dead or
439 * being rebuilt. (Note that "far" and "offset" formats only
440 * support two copies right now. These formats also only ever
441 * use the 'use_far_sets' variant.)
443 * This check is somewhat complicated by the need to account
444 * for arrays that are not a multiple of (far) copies. This
445 * results in the need to treat the last (potentially larger)
448 group_size = (rs->md.raid_disks / copies);
449 last_group_start = (rs->md.raid_disks / group_size) - 1;
450 last_group_start *= group_size;
451 for (i = 0; i < rs->md.raid_disks; i++) {
452 if (!(i % copies) && !(i > last_group_start))
453 rebuilds_per_group = 0;
454 if ((!rs->dev[i].rdev.sb_page ||
455 !test_bit(In_sync, &rs->dev[i].rdev.flags)) &&
456 (++rebuilds_per_group >= copies))
472 * Possible arguments are...
473 * <chunk_size> [optional_args]
475 * Argument definitions
476 * <chunk_size> The number of sectors per disk that
477 * will form the "stripe"
478 * [[no]sync] Force or prevent recovery of the
480 * [devices_handle_discard_safely] Allow discards on RAID4/5/6; useful if RAID
481 * member device(s) properly support TRIM/UNMAP
482 * [rebuild <idx>] Rebuild the drive indicated by the index
483 * [daemon_sleep <ms>] Time between bitmap daemon work to
485 * [min_recovery_rate <kB/sec/disk>] Throttle RAID initialization
486 * [max_recovery_rate <kB/sec/disk>] Throttle RAID initialization
487 * [write_mostly <idx>] Indicate a write mostly drive via index
488 * [max_write_behind <sectors>] See '-write-behind=' (man mdadm)
489 * [stripe_cache <sectors>] Stripe cache size for higher RAIDs
490 * [region_size <sectors>] Defines granularity of bitmap
492 * RAID10-only options:
493 * [raid10_copies <# copies>] Number of copies. (Default: 2)
494 * [raid10_format <near|far|offset>] Layout algorithm. (Default: near)
496 static int parse_raid_params(struct raid_set *rs, char **argv,
497 unsigned num_raid_params)
499 char *raid10_format = "near";
500 unsigned raid10_copies = 2;
502 unsigned long value, region_size = 0;
503 sector_t sectors_per_dev = rs->ti->len;
508 * First, parse the in-order required arguments
509 * "chunk_size" is the only argument of this type.
511 if ((kstrtoul(argv[0], 10, &value) < 0)) {
512 rs->ti->error = "Bad chunk size";
514 } else if (rs->raid_type->level == 1) {
516 DMERR("Ignoring chunk size parameter for RAID 1");
518 } else if (!is_power_of_2(value)) {
519 rs->ti->error = "Chunk size must be a power of 2";
521 } else if (value < 8) {
522 rs->ti->error = "Chunk size value is too small";
526 rs->md.new_chunk_sectors = rs->md.chunk_sectors = value;
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:
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.
544 * What is found in the superblocks of the devices is always
545 * authoritative, unless 'rebuild' or '[no]sync' was specified.
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;
553 * Second, parse the unordered optional arguments
555 for (i = 0; i < num_raid_params; i++) {
556 if (!strcasecmp(argv[i], "nosync")) {
557 rs->md.recovery_cp = MaxSector;
558 rs->print_flags |= DMPF_NOSYNC;
561 if (!strcasecmp(argv[i], "sync")) {
562 rs->md.recovery_cp = 0;
563 rs->print_flags |= DMPF_SYNC;
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";
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";
581 if (strcmp("near", argv[i]) &&
582 strcmp("far", argv[i]) &&
583 strcmp("offset", argv[i])) {
584 rs->ti->error = "Invalid 'raid10_format' value given";
587 raid10_format = argv[i];
588 rs->print_flags |= DMPF_RAID10_FORMAT;
592 if (kstrtoul(argv[i], 10, &value) < 0) {
593 rs->ti->error = "Bad numerical argument given in raid params";
597 /* Parameters that take a numeric value are checked here */
598 if (!strcasecmp(key, "rebuild")) {
599 if (value >= rs->md.raid_disks) {
600 rs->ti->error = "Invalid rebuild index given";
603 clear_bit(In_sync, &rs->dev[value].rdev.flags);
604 rs->dev[value].rdev.recovery_offset = 0;
605 rs->print_flags |= DMPF_REBUILD;
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";
611 if (value >= rs->md.raid_disks) {
612 rs->ti->error = "Invalid write_mostly drive index given";
615 set_bit(WriteMostly, &rs->dev[value].rdev.flags);
616 } else if (!strcasecmp(key, "max_write_behind")) {
617 if (rs->raid_type->level != 1) {
618 rs->ti->error = "max_write_behind option is only valid for RAID1";
621 rs->print_flags |= DMPF_MAX_WRITE_BEHIND;
624 * In device-mapper, we specify things in sectors, but
625 * MD records this value in kB
628 if (value > COUNTER_MAX) {
629 rs->ti->error = "Max write-behind limit out of range";
632 rs->md.bitmap_info.max_write_behind = value;
633 } else if (!strcasecmp(key, "daemon_sleep")) {
634 rs->print_flags |= DMPF_DAEMON_SLEEP;
635 if (!value || (value > MAX_SCHEDULE_TIMEOUT)) {
636 rs->ti->error = "daemon sleep period out of range";
639 rs->md.bitmap_info.daemon_sleep = value;
640 } else if (!strcasecmp(key, "stripe_cache")) {
641 rs->print_flags |= DMPF_STRIPE_CACHE;
644 * In device-mapper, we specify things in sectors, but
645 * MD records this value in kB
649 if ((rs->raid_type->level != 5) &&
650 (rs->raid_type->level != 6)) {
651 rs->ti->error = "Inappropriate argument: stripe_cache";
654 if (raid5_set_cache_size(&rs->md, (int)value)) {
655 rs->ti->error = "Bad stripe_cache size";
658 } else if (!strcasecmp(key, "min_recovery_rate")) {
659 rs->print_flags |= DMPF_MIN_RECOVERY_RATE;
660 if (value > INT_MAX) {
661 rs->ti->error = "min_recovery_rate out of range";
664 rs->md.sync_speed_min = (int)value;
665 } else if (!strcasecmp(key, "max_recovery_rate")) {
666 rs->print_flags |= DMPF_MAX_RECOVERY_RATE;
667 if (value > INT_MAX) {
668 rs->ti->error = "max_recovery_rate out of range";
671 rs->md.sync_speed_max = (int)value;
672 } else if (!strcasecmp(key, "region_size")) {
673 rs->print_flags |= DMPF_REGION_SIZE;
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'";
681 rs->print_flags |= DMPF_RAID10_COPIES;
682 raid10_copies = value;
684 DMERR("Unable to parse RAID parameter: %s", key);
685 rs->ti->error = "Unable to parse RAID parameters";
690 if (validate_region_size(rs, region_size))
693 if (rs->md.chunk_sectors)
694 max_io_len = rs->md.chunk_sectors;
696 max_io_len = region_size;
698 if (dm_set_target_max_io_len(rs->ti, max_io_len))
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";
708 * If the format is not "near", we only support
709 * two copies at the moment.
711 if (strcmp("near", raid10_format) && (raid10_copies > 2)) {
712 rs->ti->error = "Too many copies for given RAID10 format.";
716 /* (Len * #mirrors) / #devices */
717 sectors_per_dev = rs->ti->len * raid10_copies;
718 sector_div(sectors_per_dev, rs->md.raid_disks);
720 rs->md.layout = raid10_format_to_md_layout(raid10_format,
722 rs->md.new_layout = rs->md.layout;
723 } else if ((rs->raid_type->level > 1) &&
724 sector_div(sectors_per_dev,
725 (rs->md.raid_disks - rs->raid_type->parity_devs))) {
726 rs->ti->error = "Target length not divisible by number of data devices";
729 rs->md.dev_sectors = sectors_per_dev;
731 /* Assume there are no metadata devices until the drives are parsed */
732 rs->md.persistent = 0;
738 static void do_table_event(struct work_struct *ws)
740 struct raid_set *rs = container_of(ws, struct raid_set, md.event_work);
742 dm_table_event(rs->ti->table);
745 static int raid_is_congested(struct dm_target_callbacks *cb, int bits)
747 struct raid_set *rs = container_of(cb, struct raid_set, callbacks);
749 if (rs->raid_type->level == 1)
750 return md_raid1_congested(&rs->md, bits);
752 if (rs->raid_type->level == 10)
753 return md_raid10_congested(&rs->md, bits);
755 return md_raid5_congested(&rs->md, bits);
759 * This structure is never routinely used by userspace, unlike md superblocks.
760 * Devices with this superblock should only ever be accessed via device-mapper.
762 #define DM_RAID_MAGIC 0x64526D44
763 struct dm_raid_superblock {
764 __le32 magic; /* "DmRd" */
765 __le32 features; /* Used to indicate possible future changes */
767 __le32 num_devices; /* Number of devices in this array. (Max 64) */
768 __le32 array_position; /* The position of this drive in the array */
770 __le64 events; /* Incremented by md when superblock updated */
771 __le64 failed_devices; /* Bit field of devices to indicate failures */
774 * This offset tracks the progress of the repair or replacement of
775 * an individual drive.
777 __le64 disk_recovery_offset;
780 * This offset tracks the progress of the initial array
781 * synchronisation/parity calculation.
783 __le64 array_resync_offset;
786 * RAID characteristics
790 __le32 stripe_sectors;
792 __u8 pad[452]; /* Round struct to 512 bytes. */
793 /* Always set to 0 when writing. */
796 static int read_disk_sb(struct md_rdev *rdev, int size)
798 BUG_ON(!rdev->sb_page);
803 if (!sync_page_io(rdev, 0, size, rdev->sb_page, READ, 1)) {
804 DMERR("Failed to read superblock of device at position %d",
806 md_error(rdev->mddev, rdev);
815 static void super_sync(struct mddev *mddev, struct md_rdev *rdev)
818 uint64_t failed_devices;
819 struct dm_raid_superblock *sb;
820 struct raid_set *rs = container_of(mddev, struct raid_set, md);
822 sb = page_address(rdev->sb_page);
823 failed_devices = le64_to_cpu(sb->failed_devices);
825 for (i = 0; i < mddev->raid_disks; i++)
826 if (!rs->dev[i].data_dev ||
827 test_bit(Faulty, &(rs->dev[i].rdev.flags)))
828 failed_devices |= (1ULL << i);
830 memset(sb, 0, sizeof(*sb));
832 sb->magic = cpu_to_le32(DM_RAID_MAGIC);
833 sb->features = cpu_to_le32(0); /* No features yet */
835 sb->num_devices = cpu_to_le32(mddev->raid_disks);
836 sb->array_position = cpu_to_le32(rdev->raid_disk);
838 sb->events = cpu_to_le64(mddev->events);
839 sb->failed_devices = cpu_to_le64(failed_devices);
841 sb->disk_recovery_offset = cpu_to_le64(rdev->recovery_offset);
842 sb->array_resync_offset = cpu_to_le64(mddev->recovery_cp);
844 sb->level = cpu_to_le32(mddev->level);
845 sb->layout = cpu_to_le32(mddev->layout);
846 sb->stripe_sectors = cpu_to_le32(mddev->chunk_sectors);
852 * This function creates a superblock if one is not found on the device
853 * and will decide which superblock to use if there's a choice.
855 * Return: 1 if use rdev, 0 if use refdev, -Exxx otherwise
857 static int super_load(struct md_rdev *rdev, struct md_rdev *refdev)
860 struct dm_raid_superblock *sb;
861 struct dm_raid_superblock *refsb;
862 uint64_t events_sb, events_refsb;
865 rdev->sb_size = sizeof(*sb);
867 ret = read_disk_sb(rdev, rdev->sb_size);
871 sb = page_address(rdev->sb_page);
874 * Two cases that we want to write new superblocks and rebuild:
875 * 1) New device (no matching magic number)
876 * 2) Device specified for rebuild (!In_sync w/ offset == 0)
878 if ((sb->magic != cpu_to_le32(DM_RAID_MAGIC)) ||
879 (!test_bit(In_sync, &rdev->flags) && !rdev->recovery_offset)) {
880 super_sync(rdev->mddev, rdev);
882 set_bit(FirstUse, &rdev->flags);
884 /* Force writing of superblocks to disk */
885 set_bit(MD_CHANGE_DEVS, &rdev->mddev->flags);
887 /* Any superblock is better than none, choose that if given */
888 return refdev ? 0 : 1;
894 events_sb = le64_to_cpu(sb->events);
896 refsb = page_address(refdev->sb_page);
897 events_refsb = le64_to_cpu(refsb->events);
899 return (events_sb > events_refsb) ? 1 : 0;
902 static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev)
905 struct raid_set *rs = container_of(mddev, struct raid_set, md);
907 uint64_t failed_devices;
908 struct dm_raid_superblock *sb;
909 uint32_t new_devs = 0;
910 uint32_t rebuilds = 0;
912 struct dm_raid_superblock *sb2;
914 sb = page_address(rdev->sb_page);
915 events_sb = le64_to_cpu(sb->events);
916 failed_devices = le64_to_cpu(sb->failed_devices);
919 * Initialise to 1 if this is a new superblock.
921 mddev->events = events_sb ? : 1;
924 * Reshaping is not currently allowed
926 if (le32_to_cpu(sb->level) != mddev->level) {
927 DMERR("Reshaping arrays not yet supported. (RAID level change)");
930 if (le32_to_cpu(sb->layout) != mddev->layout) {
931 DMERR("Reshaping arrays not yet supported. (RAID layout change)");
932 DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout);
933 DMERR(" Old layout: %s w/ %d copies",
934 raid10_md_layout_to_format(le32_to_cpu(sb->layout)),
935 raid10_md_layout_to_copies(le32_to_cpu(sb->layout)));
936 DMERR(" New layout: %s w/ %d copies",
937 raid10_md_layout_to_format(mddev->layout),
938 raid10_md_layout_to_copies(mddev->layout));
941 if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) {
942 DMERR("Reshaping arrays not yet supported. (stripe sectors change)");
946 /* We can only change the number of devices in RAID1 right now */
947 if ((rs->raid_type->level != 1) &&
948 (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) {
949 DMERR("Reshaping arrays not yet supported. (device count change)");
953 if (!(rs->print_flags & (DMPF_SYNC | DMPF_NOSYNC)))
954 mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset);
957 * During load, we set FirstUse if a new superblock was written.
958 * There are two reasons we might not have a superblock:
959 * 1) The array is brand new - in which case, all of the
960 * devices must have their In_sync bit set. Also,
961 * recovery_cp must be 0, unless forced.
962 * 2) This is a new device being added to an old array
963 * and the new device needs to be rebuilt - in which
964 * case the In_sync bit will /not/ be set and
965 * recovery_cp must be MaxSector.
967 rdev_for_each(r, mddev) {
968 if (!test_bit(In_sync, &r->flags)) {
969 DMINFO("Device %d specified for rebuild: "
970 "Clearing superblock", r->raid_disk);
972 } else if (test_bit(FirstUse, &r->flags))
977 if (new_devs == mddev->raid_disks) {
978 DMINFO("Superblocks created for new array");
979 set_bit(MD_ARRAY_FIRST_USE, &mddev->flags);
980 } else if (new_devs) {
981 DMERR("New device injected "
982 "into existing array without 'rebuild' "
983 "parameter specified");
986 } else if (new_devs) {
987 DMERR("'rebuild' devices cannot be "
988 "injected into an array with other first-time devices");
990 } else if (mddev->recovery_cp != MaxSector) {
991 DMERR("'rebuild' specified while array is not in-sync");
996 * Now we set the Faulty bit for those devices that are
997 * recorded in the superblock as failed.
999 rdev_for_each(r, mddev) {
1002 sb2 = page_address(r->sb_page);
1003 sb2->failed_devices = 0;
1006 * Check for any device re-ordering.
1008 if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) {
1009 role = le32_to_cpu(sb2->array_position);
1010 if (role != r->raid_disk) {
1011 if (rs->raid_type->level != 1) {
1012 rs->ti->error = "Cannot change device "
1013 "positions in RAID array";
1016 DMINFO("RAID1 device #%d now at position #%d",
1017 role, r->raid_disk);
1021 * Partial recovery is performed on
1022 * returning failed devices.
1024 if (failed_devices & (1 << role))
1025 set_bit(Faulty, &r->flags);
1032 static int super_validate(struct mddev *mddev, struct md_rdev *rdev)
1034 struct dm_raid_superblock *sb = page_address(rdev->sb_page);
1037 * If mddev->events is not set, we know we have not yet initialized
1040 if (!mddev->events && super_init_validation(mddev, rdev))
1043 mddev->bitmap_info.offset = 4096 >> 9; /* Enable bitmap creation */
1044 rdev->mddev->bitmap_info.default_offset = 4096 >> 9;
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);
1052 * If a device comes back, set it as not In_sync and no longer faulty.
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;
1061 clear_bit(FirstUse, &rdev->flags);
1067 * Analyse superblocks and select the freshest.
1069 static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs)
1072 struct raid_dev *dev;
1073 struct md_rdev *rdev, *tmp, *freshest;
1074 struct mddev *mddev = &rs->md;
1077 rdev_for_each_safe(rdev, tmp, mddev) {
1079 * Skipping super_load due to DMPF_SYNC will cause
1080 * the array to undergo initialization again as
1081 * though it were new. This is the intended effect
1082 * of the "sync" directive.
1084 * When reshaping capability is added, we must ensure
1085 * that the "sync" directive is disallowed during the
1088 if (rs->print_flags & DMPF_SYNC)
1091 if (!rdev->meta_bdev)
1094 ret = super_load(rdev, freshest);
1103 dev = container_of(rdev, struct raid_dev, rdev);
1105 dm_put_device(ti, dev->meta_dev);
1107 dev->meta_dev = NULL;
1108 rdev->meta_bdev = NULL;
1111 put_page(rdev->sb_page);
1113 rdev->sb_page = NULL;
1115 rdev->sb_loaded = 0;
1118 * We might be able to salvage the data device
1119 * even though the meta device has failed. For
1120 * now, we behave as though '- -' had been
1121 * set for this device in the table.
1124 dm_put_device(ti, dev->data_dev);
1126 dev->data_dev = NULL;
1129 list_del(&rdev->same_set);
1136 if (validate_raid_redundancy(rs)) {
1137 rs->ti->error = "Insufficient redundancy to activate array";
1142 * Validation of the freshest device provides the source of
1143 * validation for the remaining devices.
1145 ti->error = "Unable to assemble array: Invalid superblocks";
1146 if (super_validate(mddev, freshest))
1149 rdev_for_each(rdev, mddev)
1150 if ((rdev != freshest) && super_validate(mddev, rdev))
1157 * Enable/disable discard support on RAID set depending on
1158 * RAID level and discard properties of underlying RAID members.
1160 static void configure_discard_support(struct dm_target *ti, struct raid_set *rs)
1165 /* Assume discards not supported until after checks below. */
1166 ti->discards_supported = false;
1168 /* RAID level 4,5,6 require discard_zeroes_data for data integrity! */
1169 raid456 = (rs->md.level == 4 || rs->md.level == 5 || rs->md.level == 6);
1171 for (i = 0; i < rs->md.raid_disks; i++) {
1172 struct request_queue *q = bdev_get_queue(rs->dev[i].rdev.bdev);
1174 if (!q || !blk_queue_discard(q))
1178 if (!q->limits.discard_zeroes_data)
1180 if (!devices_handle_discard_safely) {
1181 DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty.");
1182 DMERR("Set dm-raid.devices_handle_discard_safely=Y to override.");
1188 /* All RAID members properly support discards */
1189 ti->discards_supported = true;
1192 * RAID1 and RAID10 personalities require bio splitting,
1193 * RAID0/4/5/6 don't and process large discard bios properly.
1195 ti->split_discard_bios = !!(rs->md.level == 1 || rs->md.level == 10);
1196 ti->num_discard_bios = 1;
1200 * Construct a RAID4/5/6 mapping:
1202 * <raid_type> <#raid_params> <raid_params> \
1203 * <#raid_devs> { <meta_dev1> <dev1> .. <meta_devN> <devN> }
1205 * <raid_params> varies by <raid_type>. See 'parse_raid_params' for
1206 * details on possible <raid_params>.
1208 static int raid_ctr(struct dm_target *ti, unsigned argc, char **argv)
1211 struct raid_type *rt;
1212 unsigned long num_raid_params, num_raid_devs;
1213 struct raid_set *rs = NULL;
1215 /* Must have at least <raid_type> <#raid_params> */
1217 ti->error = "Too few arguments";
1222 rt = get_raid_type(argv[0]);
1224 ti->error = "Unrecognised raid_type";
1230 /* number of RAID parameters */
1231 if (kstrtoul(argv[0], 10, &num_raid_params) < 0) {
1232 ti->error = "Cannot understand number of RAID parameters";
1238 /* Skip over RAID params for now and find out # of devices */
1239 if (num_raid_params + 1 > argc) {
1240 ti->error = "Arguments do not agree with counts given";
1244 if ((kstrtoul(argv[num_raid_params], 10, &num_raid_devs) < 0) ||
1245 (num_raid_devs >= INT_MAX)) {
1246 ti->error = "Cannot understand number of raid devices";
1250 rs = context_alloc(ti, rt, (unsigned)num_raid_devs);
1254 ret = parse_raid_params(rs, argv, (unsigned)num_raid_params);
1260 argc -= num_raid_params + 1; /* +1: we already have num_raid_devs */
1261 argv += num_raid_params + 1;
1263 if (argc != (num_raid_devs * 2)) {
1264 ti->error = "Supplied RAID devices does not match the count given";
1268 ret = dev_parms(rs, argv);
1272 rs->md.sync_super = super_sync;
1273 ret = analyse_superblocks(ti, rs);
1277 INIT_WORK(&rs->md.event_work, do_table_event);
1279 ti->num_flush_bios = 1;
1282 * Disable/enable discard support on RAID set.
1284 configure_discard_support(ti, rs);
1286 mutex_lock(&rs->md.reconfig_mutex);
1287 ret = md_run(&rs->md);
1288 rs->md.in_sync = 0; /* Assume already marked dirty */
1289 mutex_unlock(&rs->md.reconfig_mutex);
1292 ti->error = "Fail to run raid array";
1296 if (ti->len != rs->md.array_sectors) {
1297 ti->error = "Array size does not match requested target length";
1301 rs->callbacks.congested_fn = raid_is_congested;
1302 dm_table_add_target_callbacks(ti->table, &rs->callbacks);
1304 mddev_suspend(&rs->md);
1315 static void raid_dtr(struct dm_target *ti)
1317 struct raid_set *rs = ti->private;
1319 list_del_init(&rs->callbacks.list);
1324 static int raid_map(struct dm_target *ti, struct bio *bio)
1326 struct raid_set *rs = ti->private;
1327 struct mddev *mddev = &rs->md;
1329 mddev->pers->make_request(mddev, bio);
1331 return DM_MAPIO_SUBMITTED;
1334 static const char *decipher_sync_action(struct mddev *mddev)
1336 if (test_bit(MD_RECOVERY_FROZEN, &mddev->recovery))
1339 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
1340 (!mddev->ro && test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))) {
1341 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery))
1344 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
1345 if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
1347 else if (test_bit(MD_RECOVERY_CHECK, &mddev->recovery))
1352 if (test_bit(MD_RECOVERY_RECOVER, &mddev->recovery))
1359 static void raid_status(struct dm_target *ti, status_type_t type,
1360 unsigned status_flags, char *result, unsigned maxlen)
1362 struct raid_set *rs = ti->private;
1363 unsigned raid_param_cnt = 1; /* at least 1 for chunksize */
1365 int i, array_in_sync = 0;
1369 case STATUSTYPE_INFO:
1370 DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks);
1372 if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery))
1373 sync = rs->md.curr_resync_completed;
1375 sync = rs->md.recovery_cp;
1377 if (sync >= rs->md.resync_max_sectors) {
1382 sync = rs->md.resync_max_sectors;
1383 } else if (test_bit(MD_RECOVERY_REQUESTED, &rs->md.recovery)) {
1385 * If "check" or "repair" is occurring, the array has
1386 * undergone and initial sync and the health characters
1387 * should not be 'a' anymore.
1392 * The array may be doing an initial sync, or it may
1393 * be rebuilding individual components. If all the
1394 * devices are In_sync, then it is the array that is
1395 * being initialized.
1397 for (i = 0; i < rs->md.raid_disks; i++)
1398 if (!test_bit(In_sync, &rs->dev[i].rdev.flags))
1403 * Status characters:
1404 * 'D' = Dead/Failed device
1405 * 'a' = Alive but not in-sync
1406 * 'A' = Alive and in-sync
1408 for (i = 0; i < rs->md.raid_disks; i++) {
1409 if (test_bit(Faulty, &rs->dev[i].rdev.flags))
1411 else if (!array_in_sync ||
1412 !test_bit(In_sync, &rs->dev[i].rdev.flags))
1420 * The in-sync ratio shows the progress of:
1421 * - Initializing the array
1422 * - Rebuilding a subset of devices of the array
1423 * The user can distinguish between the two by referring
1424 * to the status characters.
1426 DMEMIT(" %llu/%llu",
1427 (unsigned long long) sync,
1428 (unsigned long long) rs->md.resync_max_sectors);
1432 * See Documentation/device-mapper/dm-raid.c for
1433 * information on each of these states.
1435 DMEMIT(" %s", decipher_sync_action(&rs->md));
1438 * resync_mismatches/mismatch_cnt
1439 * This field shows the number of discrepancies found when
1440 * performing a "check" of the array.
1443 (strcmp(rs->md.last_sync_action, "check")) ? 0 :
1444 (unsigned long long)
1445 atomic64_read(&rs->md.resync_mismatches));
1447 case STATUSTYPE_TABLE:
1448 /* The string you would use to construct this array */
1449 for (i = 0; i < rs->md.raid_disks; i++) {
1450 if ((rs->print_flags & DMPF_REBUILD) &&
1451 rs->dev[i].data_dev &&
1452 !test_bit(In_sync, &rs->dev[i].rdev.flags))
1453 raid_param_cnt += 2; /* for rebuilds */
1454 if (rs->dev[i].data_dev &&
1455 test_bit(WriteMostly, &rs->dev[i].rdev.flags))
1456 raid_param_cnt += 2;
1459 raid_param_cnt += (hweight32(rs->print_flags & ~DMPF_REBUILD) * 2);
1460 if (rs->print_flags & (DMPF_SYNC | DMPF_NOSYNC))
1463 DMEMIT("%s %u %u", rs->raid_type->name,
1464 raid_param_cnt, rs->md.chunk_sectors);
1466 if ((rs->print_flags & DMPF_SYNC) &&
1467 (rs->md.recovery_cp == MaxSector))
1469 if (rs->print_flags & DMPF_NOSYNC)
1472 for (i = 0; i < rs->md.raid_disks; i++)
1473 if ((rs->print_flags & DMPF_REBUILD) &&
1474 rs->dev[i].data_dev &&
1475 !test_bit(In_sync, &rs->dev[i].rdev.flags))
1476 DMEMIT(" rebuild %u", i);
1478 if (rs->print_flags & DMPF_DAEMON_SLEEP)
1479 DMEMIT(" daemon_sleep %lu",
1480 rs->md.bitmap_info.daemon_sleep);
1482 if (rs->print_flags & DMPF_MIN_RECOVERY_RATE)
1483 DMEMIT(" min_recovery_rate %d", rs->md.sync_speed_min);
1485 if (rs->print_flags & DMPF_MAX_RECOVERY_RATE)
1486 DMEMIT(" max_recovery_rate %d", rs->md.sync_speed_max);
1488 for (i = 0; i < rs->md.raid_disks; i++)
1489 if (rs->dev[i].data_dev &&
1490 test_bit(WriteMostly, &rs->dev[i].rdev.flags))
1491 DMEMIT(" write_mostly %u", i);
1493 if (rs->print_flags & DMPF_MAX_WRITE_BEHIND)
1494 DMEMIT(" max_write_behind %lu",
1495 rs->md.bitmap_info.max_write_behind);
1497 if (rs->print_flags & DMPF_STRIPE_CACHE) {
1498 struct r5conf *conf = rs->md.private;
1500 /* convert from kiB to sectors */
1501 DMEMIT(" stripe_cache %d",
1502 conf ? conf->max_nr_stripes * 2 : 0);
1505 if (rs->print_flags & DMPF_REGION_SIZE)
1506 DMEMIT(" region_size %lu",
1507 rs->md.bitmap_info.chunksize >> 9);
1509 if (rs->print_flags & DMPF_RAID10_COPIES)
1510 DMEMIT(" raid10_copies %u",
1511 raid10_md_layout_to_copies(rs->md.layout));
1513 if (rs->print_flags & DMPF_RAID10_FORMAT)
1514 DMEMIT(" raid10_format %s",
1515 raid10_md_layout_to_format(rs->md.layout));
1517 DMEMIT(" %d", rs->md.raid_disks);
1518 for (i = 0; i < rs->md.raid_disks; i++) {
1519 if (rs->dev[i].meta_dev)
1520 DMEMIT(" %s", rs->dev[i].meta_dev->name);
1524 if (rs->dev[i].data_dev)
1525 DMEMIT(" %s", rs->dev[i].data_dev->name);
1532 static int raid_message(struct dm_target *ti, unsigned argc, char **argv)
1534 struct raid_set *rs = ti->private;
1535 struct mddev *mddev = &rs->md;
1537 if (!strcasecmp(argv[0], "reshape")) {
1538 DMERR("Reshape not supported.");
1542 if (!mddev->pers || !mddev->pers->sync_request)
1545 if (!strcasecmp(argv[0], "frozen"))
1546 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
1548 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
1550 if (!strcasecmp(argv[0], "idle") || !strcasecmp(argv[0], "frozen")) {
1551 if (mddev->sync_thread) {
1552 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
1553 md_reap_sync_thread(mddev);
1555 } else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
1556 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
1558 else if (!strcasecmp(argv[0], "resync"))
1559 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
1560 else if (!strcasecmp(argv[0], "recover")) {
1561 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
1562 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
1564 if (!strcasecmp(argv[0], "check"))
1565 set_bit(MD_RECOVERY_CHECK, &mddev->recovery);
1566 else if (!!strcasecmp(argv[0], "repair"))
1568 set_bit(MD_RECOVERY_REQUESTED, &mddev->recovery);
1569 set_bit(MD_RECOVERY_SYNC, &mddev->recovery);
1571 if (mddev->ro == 2) {
1572 /* A write to sync_action is enough to justify
1573 * canceling read-auto mode
1576 if (!mddev->suspended)
1577 md_wakeup_thread(mddev->sync_thread);
1579 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
1580 if (!mddev->suspended)
1581 md_wakeup_thread(mddev->thread);
1586 static int raid_iterate_devices(struct dm_target *ti,
1587 iterate_devices_callout_fn fn, void *data)
1589 struct raid_set *rs = ti->private;
1593 for (i = 0; !ret && i < rs->md.raid_disks; i++)
1594 if (rs->dev[i].data_dev)
1596 rs->dev[i].data_dev,
1597 0, /* No offset on data devs */
1604 static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits)
1606 struct raid_set *rs = ti->private;
1607 unsigned chunk_size = rs->md.chunk_sectors << 9;
1608 struct r5conf *conf = rs->md.private;
1610 blk_limits_io_min(limits, chunk_size);
1611 blk_limits_io_opt(limits, chunk_size * (conf->raid_disks - conf->max_degraded));
1614 static void raid_presuspend(struct dm_target *ti)
1616 struct raid_set *rs = ti->private;
1618 md_stop_writes(&rs->md);
1621 static void raid_postsuspend(struct dm_target *ti)
1623 struct raid_set *rs = ti->private;
1625 mddev_suspend(&rs->md);
1628 static void attempt_restore_of_faulty_devices(struct raid_set *rs)
1631 uint64_t failed_devices, cleared_failed_devices = 0;
1632 unsigned long flags;
1633 struct dm_raid_superblock *sb;
1636 for (i = 0; i < rs->md.raid_disks; i++) {
1637 r = &rs->dev[i].rdev;
1638 if (test_bit(Faulty, &r->flags) && r->sb_page &&
1639 sync_page_io(r, 0, r->sb_size, r->sb_page, READ, 1)) {
1640 DMINFO("Faulty %s device #%d has readable super block."
1641 " Attempting to revive it.",
1642 rs->raid_type->name, i);
1645 * Faulty bit may be set, but sometimes the array can
1646 * be suspended before the personalities can respond
1647 * by removing the device from the array (i.e. calling
1648 * 'hot_remove_disk'). If they haven't yet removed
1649 * the failed device, its 'raid_disk' number will be
1650 * '>= 0' - meaning we must call this function
1653 if ((r->raid_disk >= 0) &&
1654 (r->mddev->pers->hot_remove_disk(r->mddev, r) != 0))
1655 /* Failed to revive this device, try next */
1659 r->saved_raid_disk = i;
1661 clear_bit(Faulty, &r->flags);
1662 clear_bit(WriteErrorSeen, &r->flags);
1663 clear_bit(In_sync, &r->flags);
1664 if (r->mddev->pers->hot_add_disk(r->mddev, r)) {
1666 r->saved_raid_disk = -1;
1669 r->recovery_offset = 0;
1670 cleared_failed_devices |= 1 << i;
1674 if (cleared_failed_devices) {
1675 rdev_for_each(r, &rs->md) {
1676 sb = page_address(r->sb_page);
1677 failed_devices = le64_to_cpu(sb->failed_devices);
1678 failed_devices &= ~cleared_failed_devices;
1679 sb->failed_devices = cpu_to_le64(failed_devices);
1684 static void raid_resume(struct dm_target *ti)
1686 struct raid_set *rs = ti->private;
1688 set_bit(MD_CHANGE_DEVS, &rs->md.flags);
1689 if (!rs->bitmap_loaded) {
1690 bitmap_load(&rs->md);
1691 rs->bitmap_loaded = 1;
1694 * A secondary resume while the device is active.
1695 * Take this opportunity to check whether any failed
1696 * devices are reachable again.
1698 attempt_restore_of_faulty_devices(rs);
1701 clear_bit(MD_RECOVERY_FROZEN, &rs->md.recovery);
1702 mddev_resume(&rs->md);
1705 static struct target_type raid_target = {
1707 .version = {1, 6, 0},
1708 .module = THIS_MODULE,
1712 .status = raid_status,
1713 .message = raid_message,
1714 .iterate_devices = raid_iterate_devices,
1715 .io_hints = raid_io_hints,
1716 .presuspend = raid_presuspend,
1717 .postsuspend = raid_postsuspend,
1718 .resume = raid_resume,
1721 static int __init dm_raid_init(void)
1723 DMINFO("Loading target version %u.%u.%u",
1724 raid_target.version[0],
1725 raid_target.version[1],
1726 raid_target.version[2]);
1727 return dm_register_target(&raid_target);
1730 static void __exit dm_raid_exit(void)
1732 dm_unregister_target(&raid_target);
1735 module_init(dm_raid_init);
1736 module_exit(dm_raid_exit);
1738 module_param(devices_handle_discard_safely, bool, 0644);
1739 MODULE_PARM_DESC(devices_handle_discard_safely,
1740 "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions");
1742 MODULE_DESCRIPTION(DM_NAME " raid4/5/6 target");
1743 MODULE_ALIAS("dm-raid1");
1744 MODULE_ALIAS("dm-raid10");
1745 MODULE_ALIAS("dm-raid4");
1746 MODULE_ALIAS("dm-raid5");
1747 MODULE_ALIAS("dm-raid6");
1748 MODULE_AUTHOR("Neil Brown <dm-devel@redhat.com>");
1749 MODULE_LICENSE("GPL");