diff options
author | Mateusz Kusiak <mateusz.kusiak@intel.com> | 2024-04-29 15:07:14 +0200 |
---|---|---|
committer | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2024-05-07 01:49:37 +0200 |
commit | 0acda7053df653022e46fa3b7caf1f4d4ba31a66 (patch) | |
tree | 7dc918ba2396735afa81b6f9df4490b9fc0df195 /Grow.c | |
parent | mdadm: pass struct context for external reshapes (diff) | |
download | mdadm-0acda7053df653022e46fa3b7caf1f4d4ba31a66.tar.xz mdadm-0acda7053df653022e46fa3b7caf1f4d4ba31a66.zip |
mdadm: use struct context in reshape_super()
reshape_super() takes too many arguments. Change passing params in
favor of single struct.
Add devname pointer and change direction members to struct shape
and use it for reshape_super().
Create reshape_array_size() and reshape_array_non_size() to handle
reshape_super() calls.
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Diffstat (limited to 'Grow.c')
-rw-r--r-- | Grow.c | 93 |
1 files changed, 68 insertions, 25 deletions
@@ -862,9 +862,7 @@ static void wait_reshape(struct mdinfo *sra) close(fd); } -static int reshape_super(struct supertype *st, unsigned long long size, - int level, int layout, int chunksize, int raid_disks, - int delta_disks, char *dev, int direction, struct context *c) +static int reshape_super(struct supertype *st, struct shape *shape, struct context *c) { /* nothing extra to check in the native case */ if (!st->ss->external) @@ -875,8 +873,65 @@ static int reshape_super(struct supertype *st, unsigned long long size, return 1; } - return st->ss->reshape_super(st, size, level, layout, chunksize, raid_disks, - delta_disks, dev, direction, c); + return st->ss->reshape_super(st, shape, c); +} + +/** + * reshape_super_size() - Reshape array, size only. + * + * @st: supertype. + * @devname: device name. + * @size: component size. + * @dir metadata changes direction + * Returns: 0 on success, 1 otherwise. + * + * This function is solely used to change size of the volume. + * Setting size is not valid for container. + * Size is only change that can be rolled back, thus the @dir param. + */ +static int reshape_super_size(struct supertype *st, char *devname, + unsigned long long size, change_dir_t direction, + struct context *c) +{ + struct shape shape = {0}; + + shape.level = UnSet; + shape.layout = UnSet; + shape.delta_disks = UnSet; + shape.dev = devname; + shape.size = size; + shape.direction = direction; + + return reshape_super(st, &shape, c); +} + +/** + * reshape_super_non_size() - Reshape array, non size changes. + * + * @st: supertype. + * @devname: device name. + * @info: superblock info. + * Returns: 0 on success, 1 otherwise. + * + * This function is used for any external array changes but size. + * It handles both volumes and containers. + * For changes other than size, rollback is not possible. + */ +static int reshape_super_non_size(struct supertype *st, char *devname, + struct mdinfo *info, struct context *c) +{ + struct shape shape = {0}; + /* Size already set to zero, not updating size */ + shape.level = info->new_level; + shape.layout = info->new_layout; + shape.chunk = info->new_chunk; + shape.raiddisks = info->array.raid_disks; + shape.delta_disks = info->delta_disks; + shape.dev = devname; + /* Rollback not possible for non size changes */ + shape.direction = APPLY_METADATA_CHANGES; + + return reshape_super(st, &shape, c); } static void sync_metadata(struct supertype *st) @@ -1979,9 +2034,8 @@ int Grow_reshape(char *devname, int fd, } /* ========= set size =============== */ - if (s->size > 0 && - (s->size == MAX_SIZE || s->size != (unsigned)array.size)) { - unsigned long long orig_size = get_component_size(fd)/2; + if (s->size > 0 && (s->size == MAX_SIZE || s->size != (unsigned)array.size)) { + unsigned long long orig_size = get_component_size(fd) / 2; unsigned long long min_csize; struct mdinfo *mdi; int raid0_takeover = 0; @@ -2001,8 +2055,7 @@ int Grow_reshape(char *devname, int fd, goto release; } - if (reshape_super(st, s->size, UnSet, UnSet, 0, 0, UnSet, - devname, APPLY_METADATA_CHANGES, c)) { + if (reshape_super_size(st, devname, s->size, APPLY_METADATA_CHANGES, c)) { rv = 1; goto release; } @@ -2120,8 +2173,8 @@ size_change_error: int err = errno; /* restore metadata */ - if (reshape_super(st, orig_size, UnSet, UnSet, 0, 0, UnSet, - devname, ROLLBACK_METADATA_CHANGES, c) == 0) + if (reshape_super_size(st, devname, orig_size, + ROLLBACK_METADATA_CHANGES, c) == 0) sync_metadata(st); pr_err("Cannot set device size for %s: %s\n", devname, strerror(err)); @@ -2351,11 +2404,7 @@ size_change_error: /* Impose these changes on a single array. First * check that the metadata is OK with the change. */ - - if (reshape_super(st, 0, info.new_level, - info.new_layout, info.new_chunk, - info.array.raid_disks, info.delta_disks, - devname, APPLY_METADATA_CHANGES, c)) { + if (reshape_super_non_size(st, devname, &info, c)) { rv = 1; goto release; } @@ -3668,14 +3717,8 @@ int reshape_container(char *container, char *devname, int rv = restart; char last_devnm[32] = ""; - /* component_size is not meaningful for a container, - * so pass '0' meaning 'no change' - */ - if (!restart && - reshape_super(st, 0, info->new_level, - info->new_layout, info->new_chunk, - info->array.raid_disks, info->delta_disks, - devname, APPLY_METADATA_CHANGES, c)) { + /* component_size is not meaningful for a container */ + if (!restart && reshape_super_non_size(st, devname, info, c)) { unfreeze(st); return 1; } |