You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
280 lines
9.7 KiB
280 lines
9.7 KiB
2 years ago
|
From f2e8393bd7223c419aaa33c45feeb5c75440b986 Mon Sep 17 00:00:00 2001
|
||
|
From: Mateusz Kusiak <mateusz.kusiak@intel.com>
|
||
|
Date: Mon, 2 Jan 2023 09:35:23 +0100
|
||
|
Subject: [PATCH 75/83] Manage&Incremental: code refactor, string to enum
|
||
|
|
||
|
Prepare Manage and Incremental for later changing context->update to enum.
|
||
|
Change update from string to enum in multiple functions and pass enum
|
||
|
where already possible.
|
||
|
|
||
|
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
|
||
|
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
|
||
|
---
|
||
|
Grow.c | 8 ++++----
|
||
|
Incremental.c | 8 ++++----
|
||
|
Manage.c | 35 +++++++++++++++++------------------
|
||
|
mdadm.c | 23 ++++++++++++++++++-----
|
||
|
mdadm.h | 4 ++--
|
||
|
5 files changed, 45 insertions(+), 33 deletions(-)
|
||
|
|
||
|
diff --git a/Grow.c b/Grow.c
|
||
|
index 82d5d2ea..8f5cf07d 100644
|
||
|
--- a/Grow.c
|
||
|
+++ b/Grow.c
|
||
|
@@ -605,12 +605,12 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
|
||
|
}
|
||
|
|
||
|
if (subarray) {
|
||
|
- char *update;
|
||
|
+ enum update_opt update;
|
||
|
|
||
|
if (s->consistency_policy == CONSISTENCY_POLICY_PPL)
|
||
|
- update = "ppl";
|
||
|
+ update = UOPT_PPL;
|
||
|
else
|
||
|
- update = "no-ppl";
|
||
|
+ update = UOPT_NO_PPL;
|
||
|
|
||
|
sprintf(container_dev, "/dev/%s", st->container_devnm);
|
||
|
|
||
|
@@ -3243,7 +3243,7 @@ static int reshape_array(char *container, int fd, char *devname,
|
||
|
* level and frozen, we can safely add them.
|
||
|
*/
|
||
|
if (devlist) {
|
||
|
- if (Manage_subdevs(devname, fd, devlist, verbose, 0, NULL, 0))
|
||
|
+ if (Manage_subdevs(devname, fd, devlist, verbose, 0, UOPT_UNDEFINED, 0))
|
||
|
goto release;
|
||
|
}
|
||
|
|
||
|
diff --git a/Incremental.c b/Incremental.c
|
||
|
index 5a5f4c4c..ff3548c0 100644
|
||
|
--- a/Incremental.c
|
||
|
+++ b/Incremental.c
|
||
|
@@ -1025,7 +1025,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
|
||
|
close(dfd);
|
||
|
*dfdp = -1;
|
||
|
rv = Manage_subdevs(chosen->sys_name, mdfd, &devlist,
|
||
|
- -1, 0, NULL, 0);
|
||
|
+ -1, 0, UOPT_UNDEFINED, 0);
|
||
|
close(mdfd);
|
||
|
}
|
||
|
if (verbose > 0) {
|
||
|
@@ -1666,7 +1666,7 @@ static void remove_from_member_array(struct mdstat_ent *memb,
|
||
|
|
||
|
if (subfd >= 0) {
|
||
|
rv = Manage_subdevs(memb->devnm, subfd, devlist, verbose,
|
||
|
- 0, NULL, 0);
|
||
|
+ 0, UOPT_UNDEFINED, 0);
|
||
|
if (rv & 2) {
|
||
|
if (sysfs_init(&mmdi, -1, memb->devnm))
|
||
|
pr_err("unable to initialize sysfs for: %s\n",
|
||
|
@@ -1758,7 +1758,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
|
||
|
free_mdstat(mdstat);
|
||
|
} else {
|
||
|
rv |= Manage_subdevs(ent->devnm, mdfd, &devlist,
|
||
|
- verbose, 0, NULL, 0);
|
||
|
+ verbose, 0, UOPT_UNDEFINED, 0);
|
||
|
if (rv & 2) {
|
||
|
/* Failed due to EBUSY, try to stop the array.
|
||
|
* Give udisks a chance to unmount it first.
|
||
|
@@ -1770,7 +1770,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
|
||
|
|
||
|
devlist.disposition = 'r';
|
||
|
rv = Manage_subdevs(ent->devnm, mdfd, &devlist,
|
||
|
- verbose, 0, NULL, 0);
|
||
|
+ verbose, 0, UOPT_UNDEFINED, 0);
|
||
|
end:
|
||
|
close(mdfd);
|
||
|
free_mdstat(ent);
|
||
|
diff --git a/Manage.c b/Manage.c
|
||
|
index 87b8aa0c..594e3d2c 100644
|
||
|
--- a/Manage.c
|
||
|
+++ b/Manage.c
|
||
|
@@ -598,14 +598,12 @@ static void add_set(struct mddev_dev *dv, int fd, char set_char)
|
||
|
|
||
|
int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,
|
||
|
struct supertype *dev_st, struct supertype *tst,
|
||
|
- unsigned long rdev,
|
||
|
- char *update, char *devname, int verbose,
|
||
|
- mdu_array_info_t *array)
|
||
|
+ unsigned long rdev, enum update_opt update,
|
||
|
+ char *devname, int verbose, mdu_array_info_t *array)
|
||
|
{
|
||
|
struct mdinfo mdi;
|
||
|
int duuid[4];
|
||
|
int ouuid[4];
|
||
|
- enum update_opt update_enum = map_name(update_options, update);
|
||
|
|
||
|
dev_st->ss->getinfo_super(dev_st, &mdi, NULL);
|
||
|
dev_st->ss->uuid_from_super(dev_st, ouuid);
|
||
|
@@ -683,7 +681,7 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,
|
||
|
devname, verbose, 0, NULL);
|
||
|
if (update)
|
||
|
rv = dev_st->ss->update_super(
|
||
|
- dev_st, NULL, update_enum,
|
||
|
+ dev_st, NULL, update,
|
||
|
devname, verbose, 0, NULL);
|
||
|
if (rv == 0)
|
||
|
rv = dev_st->ss->store_super(dev_st, tfd);
|
||
|
@@ -715,8 +713,8 @@ skip_re_add:
|
||
|
int Manage_add(int fd, int tfd, struct mddev_dev *dv,
|
||
|
struct supertype *tst, mdu_array_info_t *array,
|
||
|
int force, int verbose, char *devname,
|
||
|
- char *update, unsigned long rdev, unsigned long long array_size,
|
||
|
- int raid_slot)
|
||
|
+ enum update_opt update, unsigned long rdev,
|
||
|
+ unsigned long long array_size, int raid_slot)
|
||
|
{
|
||
|
unsigned long long ldsize;
|
||
|
struct supertype *dev_st;
|
||
|
@@ -1332,7 +1330,7 @@ bool is_remove_safe(mdu_array_info_t *array, const int fd, char *devname, const
|
||
|
|
||
|
int Manage_subdevs(char *devname, int fd,
|
||
|
struct mddev_dev *devlist, int verbose, int test,
|
||
|
- char *update, int force)
|
||
|
+ enum update_opt update, int force)
|
||
|
{
|
||
|
/* Do something to each dev.
|
||
|
* devmode can be
|
||
|
@@ -1727,12 +1725,13 @@ int autodetect(void)
|
||
|
return rv;
|
||
|
}
|
||
|
|
||
|
-int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident *ident, int verbose)
|
||
|
+int Update_subarray(char *dev, char *subarray, enum update_opt update,
|
||
|
+ struct mddev_ident *ident, int verbose)
|
||
|
{
|
||
|
struct supertype supertype, *st = &supertype;
|
||
|
int fd, rv = 2;
|
||
|
struct mdinfo *info = NULL;
|
||
|
- enum update_opt update_enum = map_name(update_options, update);
|
||
|
+ char *update_verb = map_num(update_options, update);
|
||
|
|
||
|
memset(st, 0, sizeof(*st));
|
||
|
|
||
|
@@ -1750,7 +1749,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
|
||
|
if (is_subarray_active(subarray, st->devnm)) {
|
||
|
if (verbose >= 0)
|
||
|
pr_err("Subarray %s in %s is active, cannot update %s\n",
|
||
|
- subarray, dev, update);
|
||
|
+ subarray, dev, update_verb);
|
||
|
goto free_super;
|
||
|
}
|
||
|
|
||
|
@@ -1759,23 +1758,23 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
|
||
|
|
||
|
info = st->ss->container_content(st, subarray);
|
||
|
|
||
|
- if (strncmp(update, "ppl", 3) == 0 && !is_level456(info->array.level)) {
|
||
|
+ if (update == UOPT_PPL && !is_level456(info->array.level)) {
|
||
|
pr_err("RWH policy ppl is supported only for raid4, raid5 and raid6.\n");
|
||
|
goto free_super;
|
||
|
}
|
||
|
|
||
|
- rv = st->ss->update_subarray(st, subarray, update_enum, ident);
|
||
|
+ rv = st->ss->update_subarray(st, subarray, update, ident);
|
||
|
|
||
|
if (rv) {
|
||
|
if (verbose >= 0)
|
||
|
pr_err("Failed to update %s of subarray-%s in %s\n",
|
||
|
- update, subarray, dev);
|
||
|
+ update_verb, subarray, dev);
|
||
|
} else if (st->update_tail)
|
||
|
flush_metadata_updates(st);
|
||
|
else
|
||
|
st->ss->sync_metadata(st);
|
||
|
|
||
|
- if (rv == 0 && strcmp(update, "name") == 0 && verbose >= 0)
|
||
|
+ if (rv == 0 && update == UOPT_NAME && verbose >= 0)
|
||
|
pr_err("Updated subarray-%s name from %s, UUIDs may have changed\n",
|
||
|
subarray, dev);
|
||
|
|
||
|
@@ -1816,10 +1815,10 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid)
|
||
|
sprintf(devname, "%d:%d", major(devid), minor(devid));
|
||
|
|
||
|
devlist.disposition = 'r';
|
||
|
- if (Manage_subdevs(from_devname, fd2, &devlist, -1, 0, NULL, 0) == 0) {
|
||
|
+ if (Manage_subdevs(from_devname, fd2, &devlist, -1, 0, UOPT_UNDEFINED, 0) == 0) {
|
||
|
devlist.disposition = 'a';
|
||
|
if (Manage_subdevs(to_devname, fd1, &devlist, -1, 0,
|
||
|
- NULL, 0) == 0) {
|
||
|
+ UOPT_UNDEFINED, 0) == 0) {
|
||
|
/* make sure manager is aware of changes */
|
||
|
ping_manager(to_devname);
|
||
|
ping_manager(from_devname);
|
||
|
@@ -1829,7 +1828,7 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid)
|
||
|
}
|
||
|
else
|
||
|
Manage_subdevs(from_devname, fd2, &devlist,
|
||
|
- -1, 0, NULL, 0);
|
||
|
+ -1, 0, UOPT_UNDEFINED, 0);
|
||
|
}
|
||
|
close(fd1);
|
||
|
close(fd2);
|
||
|
diff --git a/mdadm.c b/mdadm.c
|
||
|
index f5f505fe..d06e2820 100644
|
||
|
--- a/mdadm.c
|
||
|
+++ b/mdadm.c
|
||
|
@@ -1402,10 +1402,22 @@ int main(int argc, char *argv[])
|
||
|
/* readonly, add/remove, readwrite, runstop */
|
||
|
if (c.readonly > 0)
|
||
|
rv = Manage_ro(devlist->devname, mdfd, c.readonly);
|
||
|
- if (!rv && devs_found>1)
|
||
|
- rv = Manage_subdevs(devlist->devname, mdfd,
|
||
|
- devlist->next, c.verbose, c.test,
|
||
|
- c.update, c.force);
|
||
|
+ if (!rv && devs_found > 1) {
|
||
|
+ /*
|
||
|
+ * This is temporary and will be removed in next patches
|
||
|
+ * Null c.update will cause segfault
|
||
|
+ */
|
||
|
+ if (c.update)
|
||
|
+ rv = Manage_subdevs(devlist->devname, mdfd,
|
||
|
+ devlist->next, c.verbose, c.test,
|
||
|
+ map_name(update_options, c.update),
|
||
|
+ c.force);
|
||
|
+ else
|
||
|
+ rv = Manage_subdevs(devlist->devname, mdfd,
|
||
|
+ devlist->next, c.verbose, c.test,
|
||
|
+ UOPT_UNDEFINED,
|
||
|
+ c.force);
|
||
|
+ }
|
||
|
if (!rv && c.readonly < 0)
|
||
|
rv = Manage_ro(devlist->devname, mdfd, c.readonly);
|
||
|
if (!rv && c.runstop > 0)
|
||
|
@@ -1931,7 +1943,8 @@ static int misc_list(struct mddev_dev *devlist,
|
||
|
continue;
|
||
|
}
|
||
|
rv |= Update_subarray(dv->devname, c->subarray,
|
||
|
- c->update, ident, c->verbose);
|
||
|
+ map_name(update_options, c->update),
|
||
|
+ ident, c->verbose);
|
||
|
continue;
|
||
|
case Dump:
|
||
|
rv |= Dump_metadata(dv->devname, dump_directory, c, ss);
|
||
|
diff --git a/mdadm.h b/mdadm.h
|
||
|
index 5dc94390..924f4b63 100644
|
||
|
--- a/mdadm.h
|
||
|
+++ b/mdadm.h
|
||
|
@@ -1478,7 +1478,7 @@ extern int Manage_stop(char *devname, int fd, int quiet,
|
||
|
int will_retry);
|
||
|
extern int Manage_subdevs(char *devname, int fd,
|
||
|
struct mddev_dev *devlist, int verbose, int test,
|
||
|
- char *update, int force);
|
||
|
+ enum update_opt update, int force);
|
||
|
extern int autodetect(void);
|
||
|
extern int Grow_Add_device(char *devname, int fd, char *newdev);
|
||
|
extern int Grow_addbitmap(char *devname, int fd,
|
||
|
@@ -1532,7 +1532,7 @@ extern int Monitor(struct mddev_dev *devlist,
|
||
|
|
||
|
extern int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl);
|
||
|
extern int Kill_subarray(char *dev, char *subarray, int verbose);
|
||
|
-extern int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident *ident, int quiet);
|
||
|
+extern int Update_subarray(char *dev, char *subarray, enum update_opt update, struct mddev_ident *ident, int quiet);
|
||
|
extern int Wait(char *dev);
|
||
|
extern int WaitClean(char *dev, int verbose);
|
||
|
extern int SetAction(char *dev, char *action);
|
||
|
--
|
||
|
2.38.1
|
||
|
|