提交 fe5d2f4a 编写于 作者: J Jonathan Brassow 提交者: NeilBrown

DM RAID: Add support for MD's RAID10 "far" and "offset" algorithms

DM RAID:  Add support for MD's RAID10 "far" and "offset" algorithms

Until now, dm-raid.c only supported the "near" algorthm of MD's RAID10
implementation.  This patch adds support for the "far" and "offset"
algorithms, but only with the improved redundancy that is brought with
the introduction of the 'use_far_sets' bit, which shifts copied stripes
according to smaller sets vs the entire array.  That is, the 17th bit
of the 'layout' variable that defines the RAID10 implementation will
always be set.   (More information on how the 'layout' variable selects
the RAID10 algorithm can be found in the opening comments of
drivers/md/raid10.c.)
Signed-off-by: NJonathan Brassow <jbrassow@redhat.com>
Signed-off-by: NNeilBrown <neilb@suse.de>
上级 9a3152ab
...@@ -30,6 +30,7 @@ The target is named "raid" and it accepts the following parameters: ...@@ -30,6 +30,7 @@ The target is named "raid" and it accepts the following parameters:
raid10 Various RAID10 inspired algorithms chosen by additional params raid10 Various RAID10 inspired algorithms chosen by additional params
- RAID10: Striped Mirrors (aka 'Striping on top of mirrors') - RAID10: Striped Mirrors (aka 'Striping on top of mirrors')
- RAID1E: Integrated Adjacent Stripe Mirroring - RAID1E: Integrated Adjacent Stripe Mirroring
- RAID1E: Integrated Offset Stripe Mirroring
- and other similar RAID10 variants - and other similar RAID10 variants
Reference: Chapter 4 of Reference: Chapter 4 of
...@@ -64,15 +65,15 @@ The target is named "raid" and it accepts the following parameters: ...@@ -64,15 +65,15 @@ The target is named "raid" and it accepts the following parameters:
synchronisation state for each region. synchronisation state for each region.
[raid10_copies <# copies>] [raid10_copies <# copies>]
[raid10_format near] [raid10_format <near|far|offset>]
These two options are used to alter the default layout of These two options are used to alter the default layout of
a RAID10 configuration. The number of copies is can be a RAID10 configuration. The number of copies is can be
specified, but the default is 2. There are other variations specified, but the default is 2. There are also three
to how the copies are laid down - the default and only current variations to how the copies are laid down - the default
option is "near". Near copies are what most people think of is "near". Near copies are what most people think of with
with respect to mirroring. If these options are left respect to mirroring. If these options are left unspecified,
unspecified, or 'raid10_copies 2' and/or 'raid10_format near' or 'raid10_copies 2' and/or 'raid10_format near' are given,
are given, then the layouts for 2, 3 and 4 devices are: then the layouts for 2, 3 and 4 devices are:
2 drives 3 drives 4 drives 2 drives 3 drives 4 drives
-------- ---------- -------------- -------- ---------- --------------
A1 A1 A1 A1 A2 A1 A1 A2 A2 A1 A1 A1 A1 A2 A1 A1 A2 A2
...@@ -85,6 +86,33 @@ The target is named "raid" and it accepts the following parameters: ...@@ -85,6 +86,33 @@ The target is named "raid" and it accepts the following parameters:
3-device layout is what might be called a 'RAID1E - Integrated 3-device layout is what might be called a 'RAID1E - Integrated
Adjacent Stripe Mirroring'. Adjacent Stripe Mirroring'.
If 'raid10_copies 2' and 'raid10_format far', then the layouts
for 2, 3 and 4 devices are:
2 drives 3 drives 4 drives
-------- -------------- --------------------
A1 A2 A1 A2 A3 A1 A2 A3 A4
A3 A4 A4 A5 A6 A5 A6 A7 A8
A5 A6 A7 A8 A9 A9 A10 A11 A12
.. .. .. .. .. .. .. .. ..
A2 A1 A3 A1 A2 A2 A1 A4 A3
A4 A3 A6 A4 A5 A6 A5 A8 A7
A6 A5 A9 A7 A8 A10 A9 A12 A11
.. .. .. .. .. .. .. .. ..
If 'raid10_copies 2' and 'raid10_format offset', then the
layouts for 2, 3 and 4 devices are:
2 drives 3 drives 4 drives
-------- ------------ -----------------
A1 A2 A1 A2 A3 A1 A2 A3 A4
A2 A1 A3 A1 A2 A2 A1 A4 A3
A3 A4 A4 A5 A6 A5 A6 A7 A8
A4 A3 A6 A4 A5 A6 A5 A8 A7
A5 A6 A7 A8 A9 A9 A10 A11 A12
A6 A5 A9 A7 A8 A10 A9 A12 A11
.. .. .. .. .. .. .. .. ..
Here we see layouts closely akin to 'RAID1E - Integrated
Offset Stripe Mirroring'.
<#raid_devs>: The number of devices composing the array. <#raid_devs>: The number of devices composing the array.
Each device consists of two entries. The first is the device Each device consists of two entries. The first is the device
containing the metadata (if any); the second is the one containing the containing the metadata (if any); the second is the one containing the
...@@ -142,3 +170,5 @@ Version History ...@@ -142,3 +170,5 @@ Version History
1.3.0 Added support for RAID 10 1.3.0 Added support for RAID 10
1.3.1 Allow device replacement/rebuild for RAID 10 1.3.1 Allow device replacement/rebuild for RAID 10
1.3.2 Fix/improve redundancy checking for RAID10 1.3.2 Fix/improve redundancy checking for RAID10
1.4.0 Non-functional change. Removes arg from mapping function.
1.4.1 Add RAID10 "far" and "offset" algorithm support.
...@@ -91,15 +91,44 @@ static struct raid_type { ...@@ -91,15 +91,44 @@ static struct raid_type {
{"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE} {"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE}
}; };
static char *raid10_md_layout_to_format(int layout)
{
/*
* Bit 16 and 17 stand for "offset" and "use_far_sets"
* Refer to MD's raid10.c for details
*/
if ((layout & 0x10000) && (layout & 0x20000))
return "offset";
if ((layout & 0xFF) > 1)
return "near";
return "far";
}
static unsigned raid10_md_layout_to_copies(int layout) static unsigned raid10_md_layout_to_copies(int layout)
{ {
if ((layout & 0xFF) > 1)
return layout & 0xFF; return layout & 0xFF;
return (layout >> 8) & 0xFF;
} }
static int raid10_format_to_md_layout(char *format, unsigned copies) static int raid10_format_to_md_layout(char *format, unsigned copies)
{ {
/* 1 "far" copy, and 'copies' "near" copies */ unsigned n = 1, f = 1;
return (1 << 8) | (copies & 0xFF);
if (!strcmp("near", format))
n = copies;
else
f = copies;
if (!strcmp("offset", format))
return 0x30000 | (f << 8) | n;
if (!strcmp("far", format))
return 0x20000 | (f << 8) | n;
return (f << 8) | n;
} }
static struct raid_type *get_raid_type(char *name) static struct raid_type *get_raid_type(char *name)
...@@ -352,6 +381,7 @@ static int validate_raid_redundancy(struct raid_set *rs) ...@@ -352,6 +381,7 @@ static int validate_raid_redundancy(struct raid_set *rs)
{ {
unsigned i, rebuild_cnt = 0; unsigned i, rebuild_cnt = 0;
unsigned rebuilds_per_group, copies, d; unsigned rebuilds_per_group, copies, d;
unsigned group_size, last_group_start;
for (i = 0; i < rs->md.raid_disks; i++) for (i = 0; i < rs->md.raid_disks; i++)
if (!test_bit(In_sync, &rs->dev[i].rdev.flags) || if (!test_bit(In_sync, &rs->dev[i].rdev.flags) ||
...@@ -379,9 +409,6 @@ static int validate_raid_redundancy(struct raid_set *rs) ...@@ -379,9 +409,6 @@ static int validate_raid_redundancy(struct raid_set *rs)
* as long as the failed devices occur in different mirror * as long as the failed devices occur in different mirror
* groups (i.e. different stripes). * groups (i.e. different stripes).
* *
* Right now, we only allow for "near" copies. When other
* formats are added, we will have to check those too.
*
* When checking "near" format, make sure no adjacent devices * When checking "near" format, make sure no adjacent devices
* have failed beyond what can be handled. In addition to the * have failed beyond what can be handled. In addition to the
* simple case where the number of devices is a multiple of the * simple case where the number of devices is a multiple of the
...@@ -391,6 +418,7 @@ static int validate_raid_redundancy(struct raid_set *rs) ...@@ -391,6 +418,7 @@ static int validate_raid_redundancy(struct raid_set *rs)
* A A B B C * A A B B C
* C D D E E * C D D E E
*/ */
if (!strcmp("near", raid10_md_layout_to_format(rs->md.layout))) {
for (i = 0; i < rs->md.raid_disks * copies; i++) { for (i = 0; i < rs->md.raid_disks * copies; i++) {
if (!(i % copies)) if (!(i % copies))
rebuilds_per_group = 0; rebuilds_per_group = 0;
...@@ -401,6 +429,32 @@ static int validate_raid_redundancy(struct raid_set *rs) ...@@ -401,6 +429,32 @@ static int validate_raid_redundancy(struct raid_set *rs)
goto too_many; goto too_many;
} }
break; break;
}
/*
* When checking "far" and "offset" formats, we need to ensure
* that the device that holds its copy is not also dead or
* being rebuilt. (Note that "far" and "offset" formats only
* support two copies right now. These formats also only ever
* use the 'use_far_sets' variant.)
*
* This check is somewhat complicated by the need to account
* for arrays that are not a multiple of (far) copies. This
* results in the need to treat the last (potentially larger)
* set differently.
*/
group_size = (rs->md.raid_disks / copies);
last_group_start = (rs->md.raid_disks / group_size) - 1;
last_group_start *= group_size;
for (i = 0; i < rs->md.raid_disks; i++) {
if (!(i % copies) && !(i > last_group_start))
rebuilds_per_group = 0;
if ((!rs->dev[i].rdev.sb_page ||
!test_bit(In_sync, &rs->dev[i].rdev.flags)) &&
(++rebuilds_per_group >= copies))
goto too_many;
}
break;
default: default:
if (rebuild_cnt) if (rebuild_cnt)
return -EINVAL; return -EINVAL;
...@@ -433,7 +487,7 @@ static int validate_raid_redundancy(struct raid_set *rs) ...@@ -433,7 +487,7 @@ static int validate_raid_redundancy(struct raid_set *rs)
* *
* RAID10-only options: * RAID10-only options:
* [raid10_copies <# copies>] Number of copies. (Default: 2) * [raid10_copies <# copies>] Number of copies. (Default: 2)
* [raid10_format <near>] Layout algorithm. (Default: near) * [raid10_format <near|far|offset>] Layout algorithm. (Default: near)
*/ */
static int parse_raid_params(struct raid_set *rs, char **argv, static int parse_raid_params(struct raid_set *rs, char **argv,
unsigned num_raid_params) unsigned num_raid_params)
...@@ -520,7 +574,9 @@ static int parse_raid_params(struct raid_set *rs, char **argv, ...@@ -520,7 +574,9 @@ static int parse_raid_params(struct raid_set *rs, char **argv,
rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type"; rs->ti->error = "'raid10_format' is an invalid parameter for this RAID type";
return -EINVAL; return -EINVAL;
} }
if (strcmp("near", argv[i])) { if (strcmp("near", argv[i]) &&
strcmp("far", argv[i]) &&
strcmp("offset", argv[i])) {
rs->ti->error = "Invalid 'raid10_format' value given"; rs->ti->error = "Invalid 'raid10_format' value given";
return -EINVAL; return -EINVAL;
} }
...@@ -644,6 +700,15 @@ static int parse_raid_params(struct raid_set *rs, char **argv, ...@@ -644,6 +700,15 @@ static int parse_raid_params(struct raid_set *rs, char **argv,
return -EINVAL; return -EINVAL;
} }
/*
* If the format is not "near", we only support
* two copies at the moment.
*/
if (strcmp("near", raid10_format) && (raid10_copies > 2)) {
rs->ti->error = "Too many copies for given RAID10 format.";
return -EINVAL;
}
/* (Len * #mirrors) / #devices */ /* (Len * #mirrors) / #devices */
sectors_per_dev = rs->ti->len * raid10_copies; sectors_per_dev = rs->ti->len * raid10_copies;
sector_div(sectors_per_dev, rs->md.raid_disks); sector_div(sectors_per_dev, rs->md.raid_disks);
...@@ -854,17 +919,30 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) ...@@ -854,17 +919,30 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev)
/* /*
* Reshaping is not currently allowed * Reshaping is not currently allowed
*/ */
if ((le32_to_cpu(sb->level) != mddev->level) || if (le32_to_cpu(sb->level) != mddev->level) {
(le32_to_cpu(sb->layout) != mddev->layout) || DMERR("Reshaping arrays not yet supported. (RAID level change)");
(le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors)) { return -EINVAL;
DMERR("Reshaping arrays not yet supported."); }
if (le32_to_cpu(sb->layout) != mddev->layout) {
DMERR("Reshaping arrays not yet supported. (RAID layout change)");
DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout);
DMERR(" Old layout: %s w/ %d copies",
raid10_md_layout_to_format(le32_to_cpu(sb->layout)),
raid10_md_layout_to_copies(le32_to_cpu(sb->layout)));
DMERR(" New layout: %s w/ %d copies",
raid10_md_layout_to_format(mddev->layout),
raid10_md_layout_to_copies(mddev->layout));
return -EINVAL;
}
if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) {
DMERR("Reshaping arrays not yet supported. (stripe sectors change)");
return -EINVAL; return -EINVAL;
} }
/* We can only change the number of devices in RAID1 right now */ /* We can only change the number of devices in RAID1 right now */
if ((rs->raid_type->level != 1) && if ((rs->raid_type->level != 1) &&
(le32_to_cpu(sb->num_devices) != mddev->raid_disks)) { (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) {
DMERR("Reshaping arrays not yet supported."); DMERR("Reshaping arrays not yet supported. (device count change)");
return -EINVAL; return -EINVAL;
} }
...@@ -1329,7 +1407,8 @@ static int raid_status(struct dm_target *ti, status_type_t type, ...@@ -1329,7 +1407,8 @@ static int raid_status(struct dm_target *ti, status_type_t type,
raid10_md_layout_to_copies(rs->md.layout)); raid10_md_layout_to_copies(rs->md.layout));
if (rs->print_flags & DMPF_RAID10_FORMAT) if (rs->print_flags & DMPF_RAID10_FORMAT)
DMEMIT(" raid10_format near"); DMEMIT(" raid10_format %s",
raid10_md_layout_to_format(rs->md.layout));
DMEMIT(" %d", rs->md.raid_disks); DMEMIT(" %d", rs->md.raid_disks);
for (i = 0; i < rs->md.raid_disks; i++) { for (i = 0; i < rs->md.raid_disks; i++) {
...@@ -1420,6 +1499,10 @@ static struct target_type raid_target = { ...@@ -1420,6 +1499,10 @@ static struct target_type raid_target = {
static int __init dm_raid_init(void) static int __init dm_raid_init(void)
{ {
DMINFO("Loading target version %u.%u.%u",
raid_target.version[0],
raid_target.version[1],
raid_target.version[2]);
return dm_register_target(&raid_target); return dm_register_target(&raid_target);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册