Commit 33e53f06 authored by Heinz Mauelshagen's avatar Heinz Mauelshagen Committed by Mike Snitzer

dm raid: introduce extended superblock and new raid types to support takeover/reshaping

Add new members to the dm-raid superblock and new raid types to support
takeover/reshape.

Add all necessary members needed to support takeover and reshape in one
go -- aiming to limit the amount of changes to the superblock layout.

This is a larger patch due to the new superblock members, their related
flags, validation of both and involved API additions/changes:

 - add additional members to keep track of:
   - state about forward/backward reshaping
   - reshape position
   - new level, layout, stripe size and delta disks
   - data offset to current and new data for out-of-place reshapes
   - failed devices bitfield extensions to keep track of max raid devices

 - adjust super_validate() to cope with new superblock members

 - adjust super_init_validation() to cope with new superblock members

 - add definitions for ctr flags supporting delta disks etc.

 - add new raid types (raid6_n_6 etc.)

 - add new raid10 supporting function API (_is_raid10_*())

 - adjust to changed raid10 supporting function API
Signed-off-by: default avatarHeinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 676fa5ad
...@@ -63,6 +63,10 @@ struct raid_dev { ...@@ -63,6 +63,10 @@ struct raid_dev {
#define CTR_FLAG_REGION_SIZE 0x200 /* 2 */ /* Not with raid0! */ #define CTR_FLAG_REGION_SIZE 0x200 /* 2 */ /* Not with raid0! */
#define CTR_FLAG_RAID10_COPIES 0x400 /* 2 */ /* Only with raid10 */ #define CTR_FLAG_RAID10_COPIES 0x400 /* 2 */ /* Only with raid10 */
#define CTR_FLAG_RAID10_FORMAT 0x800 /* 2 */ /* Only with raid10 */ #define CTR_FLAG_RAID10_FORMAT 0x800 /* 2 */ /* Only with raid10 */
/* New for v1.8.0 */
#define CTR_FLAG_DELTA_DISKS 0x1000 /* 2 */ /* Only with reshapable raid4/5/6/10! */
#define CTR_FLAG_DATA_OFFSET 0x2000 /* 2 */ /* Only with reshapable raid4/5/6/10! */
#define CTR_FLAG_RAID10_USE_NEAR_SETS 0x4000 /* 2 */ /* Only with raid10! */
/* /*
* Definitions of various constructor flags to * Definitions of various constructor flags to
...@@ -73,7 +77,8 @@ struct raid_dev { ...@@ -73,7 +77,8 @@ struct raid_dev {
#define CTR_FLAGS_ANY_SYNC (CTR_FLAG_SYNC | CTR_FLAG_NOSYNC) #define CTR_FLAGS_ANY_SYNC (CTR_FLAG_SYNC | CTR_FLAG_NOSYNC)
/* Define flags for options without argument (e.g. 'nosync') */ /* Define flags for options without argument (e.g. 'nosync') */
#define CTR_FLAG_OPTIONS_NO_ARGS CTR_FLAGS_ANY_SYNC #define CTR_FLAG_OPTIONS_NO_ARGS (CTR_FLAGS_ANY_SYNC | \
CTR_FLAG_RAID10_USE_NEAR_SETS)
/* Define flags for options with one argument (e.g. 'delta_disks +2') */ /* Define flags for options with one argument (e.g. 'delta_disks +2') */
#define CTR_FLAG_OPTIONS_ONE_ARG (CTR_FLAG_REBUILD | \ #define CTR_FLAG_OPTIONS_ONE_ARG (CTR_FLAG_REBUILD | \
...@@ -85,7 +90,9 @@ struct raid_dev { ...@@ -85,7 +90,9 @@ struct raid_dev {
CTR_FLAG_STRIPE_CACHE | \ CTR_FLAG_STRIPE_CACHE | \
CTR_FLAG_REGION_SIZE | \ CTR_FLAG_REGION_SIZE | \
CTR_FLAG_RAID10_COPIES | \ CTR_FLAG_RAID10_COPIES | \
CTR_FLAG_RAID10_FORMAT) CTR_FLAG_RAID10_FORMAT | \
CTR_FLAG_DELTA_DISKS | \
CTR_FLAG_DATA_OFFSET)
/* All ctr optional arguments */ /* All ctr optional arguments */
#define ALL_CTR_FLAGS (CTR_FLAG_OPTIONS_NO_ARGS | \ #define ALL_CTR_FLAGS (CTR_FLAG_OPTIONS_NO_ARGS | \
...@@ -99,7 +106,9 @@ struct raid_dev { ...@@ -99,7 +106,9 @@ struct raid_dev {
/* "raid1" does not accept stripe cache or any raid10 options */ /* "raid1" does not accept stripe cache or any raid10 options */
#define RAID1_INVALID_FLAGS (CTR_FLAG_STRIPE_CACHE | \ #define RAID1_INVALID_FLAGS (CTR_FLAG_STRIPE_CACHE | \
CTR_FLAG_RAID10_COPIES | \ CTR_FLAG_RAID10_COPIES | \
CTR_FLAG_RAID10_FORMAT) CTR_FLAG_RAID10_FORMAT | \
CTR_FLAG_DELTA_DISKS | \
CTR_FLAG_DATA_OFFSET)
/* "raid10" does not accept any raid1 or stripe cache options */ /* "raid10" does not accept any raid1 or stripe cache options */
#define RAID10_INVALID_FLAGS (CTR_FLAG_WRITE_MOSTLY | \ #define RAID10_INVALID_FLAGS (CTR_FLAG_WRITE_MOSTLY | \
...@@ -115,16 +124,24 @@ struct raid_dev { ...@@ -115,16 +124,24 @@ struct raid_dev {
#define RAID45_INVALID_FLAGS (CTR_FLAG_WRITE_MOSTLY | \ #define RAID45_INVALID_FLAGS (CTR_FLAG_WRITE_MOSTLY | \
CTR_FLAG_MAX_WRITE_BEHIND | \ CTR_FLAG_MAX_WRITE_BEHIND | \
CTR_FLAG_RAID10_FORMAT | \ CTR_FLAG_RAID10_FORMAT | \
CTR_FLAG_RAID10_COPIES) CTR_FLAG_RAID10_COPIES | \
CTR_FLAG_RAID10_USE_NEAR_SETS)
#define RAID6_INVALID_FLAGS (CTR_FLAG_NOSYNC | RAID45_INVALID_FLAGS) #define RAID6_INVALID_FLAGS (CTR_FLAG_NOSYNC | RAID45_INVALID_FLAGS)
/* ...invalid options definitions per raid level */ /* ...invalid options definitions per raid level */
/* Array elements of 64 bit needed for rebuild/write_mostly bits */
#define DISKS_ARRAY_ELEMS ((MAX_RAID_DEVICES + (sizeof(uint64_t) * 8 - 1)) / sizeof(uint64_t) / 8)
struct raid_set { struct raid_set {
struct dm_target *ti; struct dm_target *ti;
uint32_t bitmap_loaded; uint32_t bitmap_loaded;
uint32_t ctr_flags; uint32_t ctr_flags;
int raid_disks;
int delta_disks;
int raid10_copies;
struct mddev md; struct mddev md;
struct raid_type *raid_type; struct raid_type *raid_type;
struct dm_target_callbacks callbacks; struct dm_target_callbacks callbacks;
...@@ -132,6 +149,12 @@ struct raid_set { ...@@ -132,6 +149,12 @@ struct raid_set {
struct raid_dev dev[0]; struct raid_dev dev[0];
}; };
/* raid10 algorithms (i.e. formats) */
#define ALGORITHM_RAID10_DEFAULT 0
#define ALGORITHM_RAID10_NEAR 1
#define ALGORITHM_RAID10_OFFSET 2
#define ALGORITHM_RAID10_FAR 3
/* Supported raid types and properties. */ /* Supported raid types and properties. */
static struct raid_type { static struct raid_type {
const char *name; /* RAID algorithm. */ const char *name; /* RAID algorithm. */
...@@ -141,17 +164,26 @@ static struct raid_type { ...@@ -141,17 +164,26 @@ static struct raid_type {
const unsigned level; /* RAID level. */ const unsigned level; /* RAID level. */
const unsigned algorithm; /* RAID algorithm. */ const unsigned algorithm; /* RAID algorithm. */
} raid_types[] = { } raid_types[] = {
{"raid0", "RAID0 (striping)", 0, 2, 0, 0 /* NONE */}, {"raid0", "raid0 (striping)", 0, 2, 0, 0 /* NONE */},
{"raid1", "RAID1 (mirroring)", 0, 2, 1, 0 /* NONE */}, {"raid1", "raid1 (mirroring)", 0, 2, 1, 0 /* NONE */},
{"raid10", "RAID10 (striped mirrors)", 0, 2, 10, UINT_MAX /* Varies */}, {"raid10_far", "raid10 far (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_FAR},
{"raid4", "RAID4 (dedicated parity disk)", 1, 2, 5, ALGORITHM_PARITY_0}, {"raid10_offset", "raid10 offset (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_OFFSET},
{"raid5_la", "RAID5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC}, {"raid10_near", "raid10 near (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_NEAR},
{"raid5_ra", "RAID5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC}, {"raid10", "raid10 (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_DEFAULT},
{"raid5_ls", "RAID5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC}, {"raid4", "raid4 (dedicated last parity disk)", 1, 2, 4, ALGORITHM_PARITY_N}, /* raid4 layout = raid5_n */
{"raid5_rs", "RAID5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC}, {"raid5_n", "raid5 (dedicated last parity disk)", 1, 2, 5, ALGORITHM_PARITY_N},
{"raid6_zr", "RAID6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART}, {"raid5_ls", "raid5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC},
{"raid6_nr", "RAID6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART}, {"raid5_rs", "raid5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC},
{"raid6_nc", "RAID6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE} {"raid5_la", "raid5 (left asymmetric)", 1, 2, 5, ALGORITHM_LEFT_ASYMMETRIC},
{"raid5_ra", "raid5 (right asymmetric)", 1, 2, 5, ALGORITHM_RIGHT_ASYMMETRIC},
{"raid6_zr", "raid6 (zero restart)", 2, 4, 6, ALGORITHM_ROTATING_ZERO_RESTART},
{"raid6_nr", "raid6 (N restart)", 2, 4, 6, ALGORITHM_ROTATING_N_RESTART},
{"raid6_nc", "raid6 (N continue)", 2, 4, 6, ALGORITHM_ROTATING_N_CONTINUE},
{"raid6_n_6", "raid6 (dedicated parity/Q n/6)", 2, 4, 6, ALGORITHM_PARITY_N_6},
{"raid6_ls_6", "raid6 (left symmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_LEFT_SYMMETRIC_6},
{"raid6_rs_6", "raid6 (right symmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_RIGHT_SYMMETRIC_6},
{"raid6_la_6", "raid6 (left asymmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_LEFT_ASYMMETRIC_6},
{"raid6_ra_6", "raid6 (right asymmetric dedicated Q 6)", 2, 4, 6, ALGORITHM_RIGHT_ASYMMETRIC_6}
}; };
/* True, if @v is in inclusive range [@min, @max] */ /* True, if @v is in inclusive range [@min, @max] */
...@@ -227,6 +259,23 @@ static const char *_argname_by_flag(const uint32_t flag) ...@@ -227,6 +259,23 @@ static const char *_argname_by_flag(const uint32_t flag)
return NULL; return NULL;
} }
/*
* bool helpers to test for various raid levels of a raid set,
* is. it's level as reported by the superblock rather than
* the requested raid_type passed to the constructor.
*/
/* Return true, if raid set in @rs is raid0 */
static bool rs_is_raid0(struct raid_set *rs)
{
return !rs->md.level;
}
/* Return true, if raid set in @rs is raid10 */
static bool rs_is_raid10(struct raid_set *rs)
{
return rs->md.level == 10;
}
/* /*
* bool helpers to test for various raid levels of a raid type * bool helpers to test for various raid levels of a raid type
*/ */
...@@ -314,57 +363,184 @@ static int rs_check_for_invalid_flags(struct raid_set *rs) ...@@ -314,57 +363,184 @@ static int rs_check_for_invalid_flags(struct raid_set *rs)
return 0; return 0;
} }
static char *raid10_md_layout_to_format(int layout)
/* MD raid10 bit definitions and helpers */
#define RAID10_OFFSET (1 << 16) /* stripes with data copies area adjacent on devices */
#define RAID10_BROCKEN_USE_FAR_SETS (1 << 17) /* Broken in raid10.c: use sets instead of whole stripe rotation */
#define RAID10_USE_FAR_SETS (1 << 18) /* Use sets instead of whole stripe rotation */
#define RAID10_FAR_COPIES_SHIFT 8 /* raid10 # far copies shift (2nd byte of layout) */
/* Return md raid10 near copies for @layout */
static unsigned int _raid10_near_copies(int layout)
{
return layout & 0xFF;
}
/* Return md raid10 far copies for @layout */
static unsigned int _raid10_far_copies(int layout)
{
return _raid10_near_copies(layout >> RAID10_FAR_COPIES_SHIFT);
}
/* Return true if md raid10 offset for @layout */
static unsigned int _is_raid10_offset(int layout)
{
return layout & RAID10_OFFSET;
}
/* Return true if md raid10 near for @layout */
static unsigned int _is_raid10_near(int layout)
{
return !_is_raid10_offset(layout) && _raid10_near_copies(layout) > 1;
}
/* Return true if md raid10 far for @layout */
static unsigned int _is_raid10_far(int layout)
{
return !_is_raid10_offset(layout) && _raid10_far_copies(layout) > 1;
}
/* Return md raid10 layout string for @layout */
static const char *raid10_md_layout_to_format(int layout)
{ {
/* /*
* Bit 16 and 17 stand for "offset" and "use_far_sets" * Bit 16 stands for "offset"
* (i.e. adjacent stripes hold copies)
*
* Refer to MD's raid10.c for details * Refer to MD's raid10.c for details
*/ */
if ((layout & 0x10000) && (layout & 0x20000)) if (_is_raid10_offset(layout))
return "offset"; return "offset";
if ((layout & 0xFF) > 1) if (_raid10_near_copies(layout) > 1)
return "near"; return "near";
WARN_ON(_raid10_far_copies(layout) < 2);
return "far"; return "far";
} }
static unsigned raid10_md_layout_to_copies(int layout) /* Return md raid10 algorithm for @name */
static const int raid10_name_to_format(const char *name)
{ {
if ((layout & 0xFF) > 1) if (!strcasecmp(name, "near"))
return layout & 0xFF; return ALGORITHM_RAID10_NEAR;
return (layout >> 8) & 0xFF; else if (!strcasecmp(name, "offset"))
return ALGORITHM_RAID10_OFFSET;
else if (!strcasecmp(name, "far"))
return ALGORITHM_RAID10_FAR;
return -EINVAL;
} }
static int raid10_format_to_md_layout(char *format, unsigned copies)
/* Return md raid10 copies for @layout */
static unsigned int raid10_md_layout_to_copies(int layout)
{ {
unsigned n = 1, f = 1; return _raid10_near_copies(layout) > 1 ?
_raid10_near_copies(layout) : _raid10_far_copies(layout);
}
/* Return md raid10 format id for @format string */
static int raid10_format_to_md_layout(struct raid_set *rs,
unsigned int algorithm,
unsigned int copies)
{
unsigned int n = 1, f = 1, r = 0;
if (!strcasecmp("near", format)) /*
* MD resilienece flaw:
*
* enabling use_far_sets for far/offset formats causes copies
* to be colocated on the same devs together with their origins!
*
* -> disable it for now in the definition above
*/
if (algorithm == ALGORITHM_RAID10_DEFAULT ||
algorithm == ALGORITHM_RAID10_NEAR)
n = copies; n = copies;
else
else if (algorithm == ALGORITHM_RAID10_OFFSET) {
f = copies; f = copies;
r = RAID10_OFFSET;
if (!_test_flag(CTR_FLAG_RAID10_USE_NEAR_SETS, rs->ctr_flags))
r |= RAID10_USE_FAR_SETS;
if (!strcasecmp("offset", format)) } else if (algorithm == ALGORITHM_RAID10_FAR) {
return 0x30000 | (f << 8) | n; f = copies;
r = !RAID10_OFFSET;
if (!_test_flag(CTR_FLAG_RAID10_USE_NEAR_SETS, rs->ctr_flags))
r |= RAID10_USE_FAR_SETS;
if (!strcasecmp("far", format)) } else
return 0x20000 | (f << 8) | n; return -EINVAL;
return (f << 8) | n; return r | (f << RAID10_FAR_COPIES_SHIFT) | n;
} }
/* END: MD raid10 bit definitions and helpers */
/* Check for any of the raid10 algorithms */
static int _got_raid10(struct raid_type *rtp, const int layout)
{
if (rtp->level == 10) {
switch (rtp->algorithm) {
case ALGORITHM_RAID10_DEFAULT:
case ALGORITHM_RAID10_NEAR:
return _is_raid10_near(layout);
case ALGORITHM_RAID10_OFFSET:
return _is_raid10_offset(layout);
case ALGORITHM_RAID10_FAR:
return _is_raid10_far(layout);
default:
break;
}
}
return 0;
}
/* Return raid_type for @name */
static struct raid_type *get_raid_type(const char *name) static struct raid_type *get_raid_type(const char *name)
{ {
int i; struct raid_type *rtp = raid_types + ARRAY_SIZE(raid_types);
while (rtp-- > raid_types)
if (!strcasecmp(rtp->name, name))
return rtp;
return NULL;
}
/* Return raid_type for @name based derived from @level and @layout */
static struct raid_type *get_raid_type_by_ll(const int level, const int layout)
{
struct raid_type *rtp = raid_types + ARRAY_SIZE(raid_types);
for (i = 0; i < ARRAY_SIZE(raid_types); i++) while (rtp-- > raid_types) {
if (!strcmp(raid_types[i].name, name)) /* RAID10 special checks based on @layout flags/properties */
return &raid_types[i]; if (rtp->level == level &&
(_got_raid10(rtp, layout) || rtp->algorithm == layout))
return rtp;
}
return NULL; return NULL;
} }
/*
* Set the mddev properties in @rs to the new
* ones requested by the ctr
*/
static void rs_set_new(struct raid_set *rs)
{
struct mddev *mddev = &rs->md;
mddev->level = mddev->new_level;
mddev->layout = mddev->new_layout;
mddev->chunk_sectors = mddev->new_chunk_sectors;
mddev->delta_disks = 0;
}
static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *raid_type, unsigned raid_devs) static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *raid_type, unsigned raid_devs)
{ {
unsigned i; unsigned i;
...@@ -379,6 +555,9 @@ static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *ra ...@@ -379,6 +555,9 @@ static struct raid_set *context_alloc(struct dm_target *ti, struct raid_type *ra
mddev_init(&rs->md); mddev_init(&rs->md);
rs->raid_disks = raid_devs;
rs->delta_disks = 0;
rs->ti = ti; rs->ti = ti;
rs->raid_type = raid_type; rs->raid_type = raid_type;
rs->md.raid_disks = raid_devs; rs->md.raid_disks = raid_devs;
...@@ -710,7 +889,7 @@ static int validate_raid_redundancy(struct raid_set *rs) ...@@ -710,7 +889,7 @@ static int validate_raid_redundancy(struct raid_set *rs)
static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
unsigned num_raid_params) unsigned num_raid_params)
{ {
char *raid10_format = "near"; int raid10_format = ALGORITHM_RAID10_DEFAULT;
unsigned raid10_copies = 2; unsigned raid10_copies = 2;
unsigned i; unsigned i;
unsigned value, region_size = 0; unsigned value, region_size = 0;
...@@ -718,6 +897,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -718,6 +897,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
sector_t max_io_len; sector_t max_io_len;
const char *arg, *key; const char *arg, *key;
struct raid_dev *rd; struct raid_dev *rd;
struct raid_type *rt = rs->raid_type;
arg = dm_shift_arg(as); arg = dm_shift_arg(as);
num_raid_params--; /* Account for chunk_size argument */ num_raid_params--; /* Account for chunk_size argument */
...@@ -729,7 +909,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -729,7 +909,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
* First, parse the in-order required arguments * First, parse the in-order required arguments
* "chunk_size" is the only argument of this type. * "chunk_size" is the only argument of this type.
*/ */
if (rt_is_raid1(rs->raid_type)) { if (rt_is_raid1(rt)) {
if (value) if (value)
DMERR("Ignoring chunk size parameter for RAID 1"); DMERR("Ignoring chunk size parameter for RAID 1");
value = 0; value = 0;
...@@ -794,14 +974,11 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -794,14 +974,11 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_RAID10_FORMAT))) { if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_RAID10_FORMAT))) {
if (_test_and_set_flag(CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags)) if (_test_and_set_flag(CTR_FLAG_RAID10_FORMAT, &rs->ctr_flags))
return ti_error_einval(rs->ti, "Only one raid10_format argument pair allowed"); return ti_error_einval(rs->ti, "Only one raid10_format argument pair allowed");
if (!rt_is_raid10(rs->raid_type)) if (!rt_is_raid10(rt))
return ti_error_einval(rs->ti, "'raid10_format' is an invalid parameter for this RAID type"); return ti_error_einval(rs->ti, "'raid10_format' is an invalid parameter for this RAID type");
if (strcmp("near", arg) && raid10_format = raid10_name_to_format(arg);
strcmp("far", arg) && if (raid10_format < 0)
strcmp("offset", arg)) return ti_error_ret(rs->ti, "Invalid 'raid10_format' value given", raid10_format);
return ti_error_einval(rs->ti, "Invalid 'raid10_format' value given");
raid10_format = (char *) arg;
continue; continue;
} }
...@@ -823,7 +1000,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -823,7 +1000,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
rd->rdev.recovery_offset = 0; rd->rdev.recovery_offset = 0;
_set_flag(CTR_FLAG_REBUILD, &rs->ctr_flags); _set_flag(CTR_FLAG_REBUILD, &rs->ctr_flags);
} else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_WRITE_MOSTLY))) { } else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_WRITE_MOSTLY))) {
if (!rt_is_raid1(rs->raid_type)) if (!rt_is_raid1(rt))
return ti_error_einval(rs->ti, "write_mostly option is only valid for RAID1"); return ti_error_einval(rs->ti, "write_mostly option is only valid for RAID1");
if (!_in_range(value, 0, rs->md.raid_disks - 1)) if (!_in_range(value, 0, rs->md.raid_disks - 1))
...@@ -832,7 +1009,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -832,7 +1009,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
set_bit(WriteMostly, &rs->dev[value].rdev.flags); set_bit(WriteMostly, &rs->dev[value].rdev.flags);
_set_flag(CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags); _set_flag(CTR_FLAG_WRITE_MOSTLY, &rs->ctr_flags);
} else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_MAX_WRITE_BEHIND))) { } else if (!strcasecmp(key, _argname_by_flag(CTR_FLAG_MAX_WRITE_BEHIND))) {
if (!rt_is_raid1(rs->raid_type)) if (!rt_is_raid1(rt))
return ti_error_einval(rs->ti, "max_write_behind option is only valid for RAID1"); return ti_error_einval(rs->ti, "max_write_behind option is only valid for RAID1");
if (_test_and_set_flag(CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags)) if (_test_and_set_flag(CTR_FLAG_MAX_WRITE_BEHIND, &rs->ctr_flags))
...@@ -862,7 +1039,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -862,7 +1039,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
*/ */
value /= 2; value /= 2;
if (!rt_is_raid456(rs->raid_type)) if (!rt_is_raid456(rt))
return ti_error_einval(rs->ti, "Inappropriate argument: stripe_cache"); return ti_error_einval(rs->ti, "Inappropriate argument: stripe_cache");
if (raid5_set_cache_size(&rs->md, (int)value)) if (raid5_set_cache_size(&rs->md, (int)value))
return ti_error_einval(rs->ti, "Bad stripe_cache size"); return ti_error_einval(rs->ti, "Bad stripe_cache size");
...@@ -909,29 +1086,35 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, ...@@ -909,29 +1086,35 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
if (dm_set_target_max_io_len(rs->ti, max_io_len)) if (dm_set_target_max_io_len(rs->ti, max_io_len))
return -EINVAL; return -EINVAL;
if (rt_is_raid10(rs->raid_type)) { if (rt_is_raid10(rt)) {
if (raid10_copies > rs->md.raid_disks) if (raid10_copies > rs->md.raid_disks)
return ti_error_einval(rs->ti, "Not enough devices to satisfy specification"); return ti_error_einval(rs->ti, "Not enough devices to satisfy specification");
/* rs->md.new_layout = raid10_format_to_md_layout(rs, raid10_format, raid10_copies);
* If the format is not "near", we only support if (rs->md.new_layout < 0)
* two copies at the moment. return ti_error_ret(rs->ti, "Error getting raid10 format", rs->md.new_layout);
*/
if (strcmp("near", raid10_format) && (raid10_copies > 2)) rt = get_raid_type_by_ll(10, rs->md.new_layout);
return ti_error_einval(rs->ti, "Too many copies for given RAID10 format."); if (!rt)
return ti_error_einval(rs->ti, "Failed to recognize new raid10 layout");
if ((rt->algorithm == ALGORITHM_RAID10_DEFAULT ||
rt->algorithm == ALGORITHM_RAID10_NEAR) &&
_test_flag(CTR_FLAG_RAID10_USE_NEAR_SETS, rs->ctr_flags))
return ti_error_einval(rs->ti, "RAID10 format \"near\" and \"raid10_use_near_sets\" are incompatible");
/* (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);
rs->md.layout = raid10_format_to_md_layout(raid10_format, rs->md.layout = raid10_format_to_md_layout(rs, raid10_format, raid10_copies);
raid10_copies);
rs->md.new_layout = rs->md.layout; rs->md.new_layout = rs->md.layout;
} else if (!rt_is_raid1(rs->raid_type) && } else if (!rt_is_raid1(rt) &&
sector_div(sectors_per_dev, sector_div(sectors_per_dev,
(rs->md.raid_disks - rs->raid_type->parity_devs))) (rs->md.raid_disks - rt->parity_devs)))
return ti_error_einval(rs->ti, "Target length not divisible by number of data devices"); return ti_error_einval(rs->ti, "Target length not divisible by number of data devices");
rs->raid10_copies = raid10_copies;
rs->md.dev_sectors = sectors_per_dev; rs->md.dev_sectors = sectors_per_dev;
/* Assume there are no metadata devices until the drives are parsed */ /* Assume there are no metadata devices until the drives are parsed */
...@@ -956,6 +1139,13 @@ static int raid_is_congested(struct dm_target_callbacks *cb, int bits) ...@@ -956,6 +1139,13 @@ static int raid_is_congested(struct dm_target_callbacks *cb, int bits)
return mddev_congested(&rs->md, bits); return mddev_congested(&rs->md, bits);
} }
/* Features */
#define FEATURE_FLAG_SUPPORTS_RESHAPE 0x1
/* State flags for sb->flags */
#define SB_FLAG_RESHAPE_ACTIVE 0x1
#define SB_FLAG_RESHAPE_BACKWARDS 0x2
/* /*
* This structure is never routinely used by userspace, unlike md superblocks. * This structure is never routinely used by userspace, unlike md superblocks.
* Devices with this superblock should only ever be accessed via device-mapper. * Devices with this superblock should only ever be accessed via device-mapper.
...@@ -963,13 +1153,14 @@ static int raid_is_congested(struct dm_target_callbacks *cb, int bits) ...@@ -963,13 +1153,14 @@ static int raid_is_congested(struct dm_target_callbacks *cb, int bits)
#define DM_RAID_MAGIC 0x64526D44 #define DM_RAID_MAGIC 0x64526D44
struct dm_raid_superblock { struct dm_raid_superblock {
__le32 magic; /* "DmRd" */ __le32 magic; /* "DmRd" */
__le32 features; /* Used to indicate possible future changes */ __le32 compat_features; /* Used to indicate compatible features (like 1.8.0 ondisk metadata extension) */
__le32 num_devices; /* Number of devices in this array. (Max 64) */ __le32 num_devices; /* Number of devices in this raid set. (Max 64) */
__le32 array_position; /* The position of this drive in the array */ __le32 array_position; /* The position of this drive in the raid set */
__le64 events; /* Incremented by md when superblock updated */ __le64 events; /* Incremented by md when superblock updated */
__le64 failed_devices; /* Bit field of devices to indicate failures */ __le64 failed_devices; /* Pre 1.8.0 part of bit field of devices to */
/* indicate failures (see extension below) */
/* /*
* This offset tracks the progress of the repair or replacement of * This offset tracks the progress of the repair or replacement of
...@@ -978,19 +1169,62 @@ struct dm_raid_superblock { ...@@ -978,19 +1169,62 @@ struct dm_raid_superblock {
__le64 disk_recovery_offset; __le64 disk_recovery_offset;
/* /*
* This offset tracks the progress of the initial array * This offset tracks the progress of the initial raid set
* synchronisation/parity calculation. * synchronisation/parity calculation.
*/ */
__le64 array_resync_offset; __le64 array_resync_offset;
/* /*
* RAID characteristics * raid characteristics
*/ */
__le32 level; __le32 level;
__le32 layout; __le32 layout;
__le32 stripe_sectors; __le32 stripe_sectors;
/* Remainder of a logical block is zero-filled when writing (see super_sync()). */ /********************************************************************
* BELOW FOLLOW V1.8.0 EXTENSIONS TO THE PRISTINE SUPERBLOCK FORMAT!!!
*
* FEATURE_FLAG_SUPPORTS_RESHAPE in the features member indicates that those exist
*/
__le32 flags; /* Flags defining array states for reshaping */
/*
* This offset tracks the progress of a raid
* set reshape in order to be able to restart it
*/
__le64 reshape_position;
/*
* These define the properties of the array in case of an interrupted reshape
*/
__le32 new_level;
__le32 new_layout;
__le32 new_stripe_sectors;
__le32 delta_disks;
__le64 array_sectors; /* Array size in sectors */
/*
* Sector offsets to data on devices (reshaping).
* Needed to support out of place reshaping, thus
* not writing over any stripes whilst converting
* them from old to new layout
*/
__le64 data_offset;
__le64 new_data_offset;
__le64 sectors; /* Used device size in sectors */
/*
* Additonal Bit field of devices indicating failures to support
* up to 256 devices with the 1.8.0 on-disk metadata format
*/
__le64 extended_failed_devices[DISKS_ARRAY_ELEMS - 1];
__le32 incompat_features; /* Used to indicate any incompatible features */
/* Always set rest up to logical block size to 0 when writing (see get_metadata_device() below). */
} __packed; } __packed;
static int read_disk_sb(struct md_rdev *rdev, int size) static int read_disk_sb(struct md_rdev *rdev, int size)
...@@ -1012,6 +1246,19 @@ static int read_disk_sb(struct md_rdev *rdev, int size) ...@@ -1012,6 +1246,19 @@ static int read_disk_sb(struct md_rdev *rdev, int size)
return 0; return 0;
} }
static void sb_retrieve_failed_devices(struct dm_raid_superblock *sb, uint64_t *failed_devices)
{
failed_devices[0] = le64_to_cpu(sb->failed_devices);
memset(failed_devices + 1, 0, sizeof(sb->extended_failed_devices));
if (_test_flag(FEATURE_FLAG_SUPPORTS_RESHAPE, le32_to_cpu(sb->compat_features))) {
int i = ARRAY_SIZE(sb->extended_failed_devices);
while (i--)
failed_devices[i+1] = le64_to_cpu(sb->extended_failed_devices[i]);
}
}
static void super_sync(struct mddev *mddev, struct md_rdev *rdev) static void super_sync(struct mddev *mddev, struct md_rdev *rdev)
{ {
int i; int i;
...@@ -1030,7 +1277,7 @@ static void super_sync(struct mddev *mddev, struct md_rdev *rdev) ...@@ -1030,7 +1277,7 @@ static void super_sync(struct mddev *mddev, struct md_rdev *rdev)
memset(sb + 1, 0, rdev->sb_size - sizeof(*sb)); memset(sb + 1, 0, rdev->sb_size - sizeof(*sb));
sb->magic = cpu_to_le32(DM_RAID_MAGIC); sb->magic = cpu_to_le32(DM_RAID_MAGIC);
sb->features = cpu_to_le32(0); /* No features yet */ sb->compat_features = cpu_to_le32(0); /* No features yet */
sb->num_devices = cpu_to_le32(mddev->raid_disks); sb->num_devices = cpu_to_le32(mddev->raid_disks);
sb->array_position = cpu_to_le32(rdev->raid_disk); sb->array_position = cpu_to_le32(rdev->raid_disk);
...@@ -1103,36 +1350,71 @@ static int super_load(struct md_rdev *rdev, struct md_rdev *refdev) ...@@ -1103,36 +1350,71 @@ static int super_load(struct md_rdev *rdev, struct md_rdev *refdev)
return (events_sb > events_refsb) ? 1 : 0; return (events_sb > events_refsb) ? 1 : 0;
} }
static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
{ {
int role; int role;
struct raid_set *rs = container_of(mddev, struct raid_set, md); unsigned int d;
struct mddev *mddev = &rs->md;
uint64_t events_sb; uint64_t events_sb;
uint64_t failed_devices; uint64_t failed_devices[DISKS_ARRAY_ELEMS];
struct dm_raid_superblock *sb; struct dm_raid_superblock *sb;
uint32_t new_devs = 0; uint32_t new_devs = 0, rebuild_and_new = 0, rebuilds = 0;
uint32_t rebuilds = 0;
struct md_rdev *r; struct md_rdev *r;
struct dm_raid_superblock *sb2; struct dm_raid_superblock *sb2;
sb = page_address(rdev->sb_page); sb = page_address(rdev->sb_page);
events_sb = le64_to_cpu(sb->events); events_sb = le64_to_cpu(sb->events);
failed_devices = le64_to_cpu(sb->failed_devices);
/* /*
* Initialise to 1 if this is a new superblock. * Initialise to 1 if this is a new superblock.
*/ */
mddev->events = events_sb ? : 1; mddev->events = events_sb ? : 1;
mddev->reshape_position = MaxSector;
/* /*
* Reshaping is not currently allowed * Reshaping is supported, e.g. reshape_position is valid
* in superblock and superblock content is authoritative.
*/
if (_test_flag(FEATURE_FLAG_SUPPORTS_RESHAPE, le32_to_cpu(sb->compat_features))) {
/* Superblock is authoritative wrt given raid set layout! */
mddev->raid_disks = le32_to_cpu(sb->num_devices);
mddev->level = le32_to_cpu(sb->level);
mddev->layout = le32_to_cpu(sb->layout);
mddev->chunk_sectors = le32_to_cpu(sb->stripe_sectors);
mddev->new_level = le32_to_cpu(sb->new_level);
mddev->new_layout = le32_to_cpu(sb->new_layout);
mddev->new_chunk_sectors = le32_to_cpu(sb->new_stripe_sectors);
mddev->delta_disks = le32_to_cpu(sb->delta_disks);
mddev->array_sectors = le64_to_cpu(sb->array_sectors);
/* raid was reshaping and got interrupted */
if (_test_flag(SB_FLAG_RESHAPE_ACTIVE, le32_to_cpu(sb->flags))) {
if (_test_flag(CTR_FLAG_DELTA_DISKS, rs->ctr_flags)) {
DMERR("Reshape requested but raid set is still reshaping");
return -EINVAL;
}
if (mddev->delta_disks < 0 ||
(!mddev->delta_disks && _test_flag(SB_FLAG_RESHAPE_BACKWARDS, le32_to_cpu(sb->flags))))
mddev->reshape_backwards = 1;
else
mddev->reshape_backwards = 0;
mddev->reshape_position = le64_to_cpu(sb->reshape_position);
rs->raid_type = get_raid_type_by_ll(mddev->level, mddev->layout);
}
} else {
/*
* Reshaping is not allowed, because we don't have the appropriate metadata
*/ */
if (le32_to_cpu(sb->level) != mddev->level) { if (le32_to_cpu(sb->level) != mddev->level) {
DMERR("Reshaping arrays not yet supported. (RAID level change)"); DMERR("Reshaping/takeover raid sets not yet supported. (raid level/stripes/size change)");
return -EINVAL; return -EINVAL;
} }
if (le32_to_cpu(sb->layout) != mddev->layout) { if (le32_to_cpu(sb->layout) != mddev->layout) {
DMERR("Reshaping arrays not yet supported. (RAID layout change)"); DMERR("Reshaping raid sets not yet supported. (raid layout change)");
DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout); DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout);
DMERR(" Old layout: %s w/ %d copies", DMERR(" Old layout: %s w/ %d copies",
raid10_md_layout_to_format(le32_to_cpu(sb->layout)), raid10_md_layout_to_format(le32_to_cpu(sb->layout)),
...@@ -1143,79 +1425,121 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) ...@@ -1143,79 +1425,121 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev)
return -EINVAL; return -EINVAL;
} }
if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) { if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) {
DMERR("Reshaping arrays not yet supported. (stripe sectors change)"); DMERR("Reshaping raid sets 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 with old (i.e. pre 1.0.7) metadata */
if (!rt_is_raid1(rs->raid_type) && if (!rt_is_raid1(rs->raid_type) &&
(le32_to_cpu(sb->num_devices) != mddev->raid_disks)) { (le32_to_cpu(sb->num_devices) != mddev->raid_disks)) {
DMERR("Reshaping arrays not yet supported. (device count change)"); DMERR("Reshaping raid sets not yet supported. (device count change from %u to %u)",
sb->num_devices, mddev->raid_disks);
return -EINVAL; return -EINVAL;
} }
if (!(_test_flags(CTR_FLAGS_ANY_SYNC, rs->ctr_flags))) /* Table line is checked vs. authoritative superblock */
rs_set_new(rs);
}
if (!_test_flag(CTR_FLAG_NOSYNC, rs->ctr_flags))
mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset); mddev->recovery_cp = le64_to_cpu(sb->array_resync_offset);
/* /*
* During load, we set FirstUse if a new superblock was written. * During load, we set FirstUse if a new superblock was written.
* There are two reasons we might not have a superblock: * There are two reasons we might not have a superblock:
* 1) The array is brand new - in which case, all of the * 1) The raid set is brand new - in which case, all of the
* devices must have their In_sync bit set. Also, * devices must have their In_sync bit set. Also,
* recovery_cp must be 0, unless forced. * recovery_cp must be 0, unless forced.
* 2) This is a new device being added to an old array * 2) This is a new device being added to an old raid set
* and the new device needs to be rebuilt - in which * and the new device needs to be rebuilt - in which
* case the In_sync bit will /not/ be set and * case the In_sync bit will /not/ be set and
* recovery_cp must be MaxSector. * recovery_cp must be MaxSector.
*/ */
d = 0;
rdev_for_each(r, mddev) { rdev_for_each(r, mddev) {
if (test_bit(FirstUse, &r->flags))
new_devs++;
if (!test_bit(In_sync, &r->flags)) { if (!test_bit(In_sync, &r->flags)) {
DMINFO("Device %d specified for rebuild: " DMINFO("Device %d specified for rebuild; clearing superblock",
"Clearing superblock", r->raid_disk); r->raid_disk);
rebuilds++; rebuilds++;
} else if (test_bit(FirstUse, &r->flags))
new_devs++; if (test_bit(FirstUse, &r->flags))
rebuild_and_new++;
}
d++;
} }
if (!rebuilds) { if (new_devs == rs->raid_disks || !rebuilds) {
if (new_devs == mddev->raid_disks) { /* Replace a broken device */
DMINFO("Superblocks created for new array"); if (new_devs == 1 && !rs->delta_disks)
;
if (new_devs == rs->raid_disks) {
DMINFO("Superblocks created for new raid set");
set_bit(MD_ARRAY_FIRST_USE, &mddev->flags); set_bit(MD_ARRAY_FIRST_USE, &mddev->flags);
} else if (new_devs) { mddev->recovery_cp = 0;
DMERR("New device injected " } else if (new_devs && new_devs != rs->raid_disks && !rebuilds) {
"into existing array without 'rebuild' " DMERR("New device injected into existing raid set without "
"parameter specified"); "'delta_disks' or 'rebuild' parameter specified");
return -EINVAL; return -EINVAL;
} }
} else if (new_devs) { } else if (new_devs && new_devs != rebuilds) {
DMERR("'rebuild' devices cannot be " DMERR("%u 'rebuild' devices cannot be injected into"
"injected into an array with other first-time devices"); " a raid set with %u other first-time devices",
rebuilds, new_devs);
return -EINVAL;
} else if (rebuilds) {
if (rebuild_and_new && rebuilds != rebuild_and_new) {
DMERR("new device%s provided without 'rebuild'",
new_devs > 1 ? "s" : "");
return -EINVAL; return -EINVAL;
} else if (mddev->recovery_cp != MaxSector) { } else if (mddev->recovery_cp != MaxSector) {
DMERR("'rebuild' specified while array is not in-sync"); DMERR("'rebuild' specified while raid set is not in-sync (recovery_cp=%llu)",
(unsigned long long) mddev->recovery_cp);
return -EINVAL;
} else if (mddev->reshape_position != MaxSector) {
DMERR("'rebuild' specified while raid set is being reshaped");
return -EINVAL; return -EINVAL;
} }
}
/* /*
* Now we set the Faulty bit for those devices that are * Now we set the Faulty bit for those devices that are
* recorded in the superblock as failed. * recorded in the superblock as failed.
*/ */
sb_retrieve_failed_devices(sb, failed_devices);
rdev_for_each(r, mddev) { rdev_for_each(r, mddev) {
if (!r->sb_page) if (!r->sb_page)
continue; continue;
sb2 = page_address(r->sb_page); sb2 = page_address(r->sb_page);
sb2->failed_devices = 0; sb2->failed_devices = 0;
memset(sb2->extended_failed_devices, 0, sizeof(sb2->extended_failed_devices));
/* /*
* Check for any device re-ordering. * Check for any device re-ordering.
*/ */
if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) {
role = le32_to_cpu(sb2->array_position); role = le32_to_cpu(sb2->array_position);
if (role < 0)
continue;
if (role != r->raid_disk) { if (role != r->raid_disk) {
if (!rt_is_raid1(rs->raid_type)) if (_is_raid10_near(mddev->layout)) {
return ti_error_einval(rs->ti, "Cannot change device " if (mddev->raid_disks % _raid10_near_copies(mddev->layout) ||
"positions in RAID array"); rs->raid_disks % rs->raid10_copies)
DMINFO("RAID1 device #%d now at position #%d", return ti_error_einval(rs->ti, "Cannot change raid10 near "
"set to odd # of devices!");
sb2->array_position = cpu_to_le32(r->raid_disk);
} else if (!(rs_is_raid10(rs) && rt_is_raid0(rs->raid_type)) &&
!(rs_is_raid0(rs) && rt_is_raid10(rs->raid_type)) &&
!rt_is_raid1(rs->raid_type))
return ti_error_einval(rs->ti, "Cannot change device positions in raid set");
DMINFO("raid device #%d now at position #%d",
role, r->raid_disk); role, r->raid_disk);
} }
...@@ -1223,7 +1547,7 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) ...@@ -1223,7 +1547,7 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev)
* Partial recovery is performed on * Partial recovery is performed on
* returning failed devices. * returning failed devices.
*/ */
if (failed_devices & (1 << role)) if (test_bit(role, (void *) failed_devices))
set_bit(Faulty, &r->flags); set_bit(Faulty, &r->flags);
} }
} }
...@@ -1234,16 +1558,21 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev) ...@@ -1234,16 +1558,21 @@ static int super_init_validation(struct mddev *mddev, struct md_rdev *rdev)
static int super_validate(struct raid_set *rs, struct md_rdev *rdev) static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
{ {
struct mddev *mddev = &rs->md; struct mddev *mddev = &rs->md;
struct dm_raid_superblock *sb = page_address(rdev->sb_page); struct dm_raid_superblock *sb;
if (!rdev->sb_page)
return 0;
sb = page_address(rdev->sb_page);
/* /*
* If mddev->events is not set, we know we have not yet initialized * If mddev->events is not set, we know we have not yet initialized
* the array. * the array.
*/ */
if (!mddev->events && super_init_validation(mddev, rdev)) if (!mddev->events && super_init_validation(rs, rdev))
return -EINVAL; return -EINVAL;
if (le32_to_cpu(sb->features)) { if (sb->compat_features || sb->incompat_features) {
rs->ti->error = "Unable to assemble array: No feature flags supported yet"; rs->ti->error = "Unable to assemble array: No feature flags supported yet";
return -EINVAL; return -EINVAL;
} }
...@@ -1252,23 +1581,32 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev) ...@@ -1252,23 +1581,32 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
mddev->bitmap_info.offset = rt_is_raid0(rs->raid_type) ? 0 : to_sector(4096); mddev->bitmap_info.offset = rt_is_raid0(rs->raid_type) ? 0 : to_sector(4096);
rdev->mddev->bitmap_info.default_offset = mddev->bitmap_info.offset; rdev->mddev->bitmap_info.default_offset = mddev->bitmap_info.offset;
if (!test_bit(FirstUse, &rdev->flags)) { if (!test_and_clear_bit(FirstUse, &rdev->flags)) {
/* Retrieve device size stored in superblock to be prepared for shrink */
rdev->sectors = le64_to_cpu(sb->sectors);
rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset); rdev->recovery_offset = le64_to_cpu(sb->disk_recovery_offset);
if (rdev->recovery_offset != MaxSector) if (rdev->recovery_offset == MaxSector)
clear_bit(In_sync, &rdev->flags); set_bit(In_sync, &rdev->flags);
/*
* If no reshape in progress -> we're recovering single
* disk(s) and have to set the device(s) to out-of-sync
*/
else if (rs->md.reshape_position == MaxSector)
clear_bit(In_sync, &rdev->flags); /* Mandatory for recovery */
} }
/* /*
* If a device comes back, set it as not In_sync and no longer faulty. * If a device comes back, set it as not In_sync and no longer faulty.
*/ */
if (test_bit(Faulty, &rdev->flags)) { if (test_and_clear_bit(Faulty, &rdev->flags)) {
clear_bit(Faulty, &rdev->flags); rdev->recovery_offset = 0;
clear_bit(In_sync, &rdev->flags); clear_bit(In_sync, &rdev->flags);
rdev->saved_raid_disk = rdev->raid_disk; rdev->saved_raid_disk = rdev->raid_disk;
rdev->recovery_offset = 0;
} }
clear_bit(FirstUse, &rdev->flags); /* Reshape support -> restore repective data offsets */
rdev->data_offset = le64_to_cpu(sb->data_offset);
rdev->new_data_offset = le64_to_cpu(sb->new_data_offset);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment