Remove duplicated code: search_mdstat and conf_match
search_mdstat and conf_match are almost identical. Put all the functionality in conf_match, and remove search_mdstat. Reported-by: Jes.Sorensen@redhat.com Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
81219e70f2
commit
2244d1a987
|
@ -47,11 +47,6 @@ static int Incremental_container(struct supertype *st, char *devname,
|
||||||
int verbose, int runstop, int autof,
|
int verbose, int runstop, int autof,
|
||||||
int freeze_reshape);
|
int freeze_reshape);
|
||||||
|
|
||||||
static struct mddev_ident *search_mdstat(struct supertype *st,
|
|
||||||
struct mdinfo *info,
|
|
||||||
char *devname,
|
|
||||||
int verbose, int *rvp);
|
|
||||||
|
|
||||||
int Incremental(char *devname, int verbose, int runstop,
|
int Incremental(char *devname, int verbose, int runstop,
|
||||||
struct supertype *st, char *homehost, int require_homehost,
|
struct supertype *st, char *homehost, int require_homehost,
|
||||||
int autof, int freeze_reshape)
|
int autof, int freeze_reshape)
|
||||||
|
@ -213,7 +208,7 @@ int Incremental(char *devname, int verbose, int runstop,
|
||||||
st->ss->getinfo_super(st, &info, NULL);
|
st->ss->getinfo_super(st, &info, NULL);
|
||||||
|
|
||||||
/* 3/ Check if there is a match in mdadm.conf */
|
/* 3/ Check if there is a match in mdadm.conf */
|
||||||
match = search_mdstat(st, &info, devname, verbose, &rv);
|
match = conf_match(st, &info, devname, verbose, &rv);
|
||||||
if (!match && rv == 2)
|
if (!match && rv == 2)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -591,79 +586,6 @@ out_unlock:
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct mddev_ident *search_mdstat(struct supertype *st,
|
|
||||||
struct mdinfo *info,
|
|
||||||
char *devname,
|
|
||||||
int verbose, int *rvp)
|
|
||||||
{
|
|
||||||
struct mddev_ident *array_list, *match;
|
|
||||||
array_list = conf_get_ident(NULL);
|
|
||||||
match = NULL;
|
|
||||||
for (; array_list; array_list = array_list->next) {
|
|
||||||
if (array_list->uuid_set &&
|
|
||||||
same_uuid(array_list->uuid, info->uuid, st->ss->swapuuid)
|
|
||||||
== 0) {
|
|
||||||
if (verbose >= 2 && array_list->devname)
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": UUID differs from %s.\n",
|
|
||||||
array_list->devname);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (array_list->name[0] &&
|
|
||||||
strcasecmp(array_list->name, info->name) != 0) {
|
|
||||||
if (verbose >= 2 && array_list->devname)
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": Name differs from %s.\n",
|
|
||||||
array_list->devname);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (array_list->devices &&
|
|
||||||
!match_oneof(array_list->devices, devname)) {
|
|
||||||
if (verbose >= 2 && array_list->devname)
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": Not a listed device for %s.\n",
|
|
||||||
array_list->devname);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (array_list->super_minor != UnSet &&
|
|
||||||
array_list->super_minor != info->array.md_minor) {
|
|
||||||
if (verbose >= 2 && array_list->devname)
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": Different super-minor to %s.\n",
|
|
||||||
array_list->devname);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!array_list->uuid_set &&
|
|
||||||
!array_list->name[0] &&
|
|
||||||
!array_list->devices &&
|
|
||||||
array_list->super_minor == UnSet) {
|
|
||||||
if (verbose >= 2 && array_list->devname)
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": %s doesn't have any identifying information.\n",
|
|
||||||
array_list->devname);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* FIXME, should I check raid_disks and level too?? */
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
if (verbose >= 0) {
|
|
||||||
if (match->devname && array_list->devname)
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": we match both %s and %s - cannot decide which to use.\n",
|
|
||||||
match->devname, array_list->devname);
|
|
||||||
else
|
|
||||||
fprintf(stderr, Name
|
|
||||||
": multiple lines in mdadm.conf match\n");
|
|
||||||
}
|
|
||||||
*rvp = 2;
|
|
||||||
match = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
match = array_list;
|
|
||||||
}
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
|
static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
|
||||||
int number, __u64 events, int verbose,
|
int number, __u64 events, int verbose,
|
||||||
char *array_name)
|
char *array_name)
|
||||||
|
@ -1460,7 +1382,7 @@ static int Incremental_container(struct supertype *st, char *devname,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
match = search_mdstat(st, &info, devname, verbose, &rv);
|
match = conf_match(st, &info, devname, verbose, &rv);
|
||||||
if (match == NULL && rv == 2)
|
if (match == NULL && rv == 2)
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
|
|
26
config.c
26
config.c
|
@ -1019,11 +1019,12 @@ int conf_name_is_free(char *name)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st)
|
struct mddev_ident *conf_match(struct supertype *st,
|
||||||
|
struct mdinfo *info,
|
||||||
|
char *devname,
|
||||||
|
int verbose, int *rvp)
|
||||||
{
|
{
|
||||||
struct mddev_ident *array_list, *match;
|
struct mddev_ident *array_list, *match;
|
||||||
int verbose = 0;
|
|
||||||
char *devname = NULL;
|
|
||||||
array_list = conf_get_ident(NULL);
|
array_list = conf_get_ident(NULL);
|
||||||
match = NULL;
|
match = NULL;
|
||||||
for (; array_list; array_list = array_list->next) {
|
for (; array_list; array_list = array_list->next) {
|
||||||
|
@ -1044,7 +1045,7 @@ struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st)
|
||||||
array_list->devname);
|
array_list->devname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (array_list->devices && devname &&
|
if (array_list->devices &&
|
||||||
!match_oneof(array_list->devices, devname)) {
|
!match_oneof(array_list->devices, devname)) {
|
||||||
if (verbose >= 2 && array_list->devname)
|
if (verbose >= 2 && array_list->devname)
|
||||||
fprintf(stderr, Name
|
fprintf(stderr, Name
|
||||||
|
@ -1066,7 +1067,8 @@ struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st)
|
||||||
array_list->super_minor == UnSet) {
|
array_list->super_minor == UnSet) {
|
||||||
if (verbose >= 2 && array_list->devname)
|
if (verbose >= 2 && array_list->devname)
|
||||||
fprintf(stderr, Name
|
fprintf(stderr, Name
|
||||||
": %s doesn't have any identifying information.\n",
|
": %s doesn't have any identifying"
|
||||||
|
" information.\n",
|
||||||
array_list->devname);
|
array_list->devname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1076,13 +1078,19 @@ struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st)
|
||||||
if (verbose >= 0) {
|
if (verbose >= 0) {
|
||||||
if (match->devname && array_list->devname)
|
if (match->devname && array_list->devname)
|
||||||
fprintf(stderr, Name
|
fprintf(stderr, Name
|
||||||
": we match both %s and %s - cannot decide which to use.\n",
|
": we match both %s and %s - "
|
||||||
match->devname, array_list->devname);
|
"cannot decide which to use.\n",
|
||||||
|
match->devname,
|
||||||
|
array_list->devname);
|
||||||
else
|
else
|
||||||
fprintf(stderr, Name
|
fprintf(stderr, Name
|
||||||
": multiple lines in mdadm.conf match\n");
|
": multiple lines in mdadm.conf"
|
||||||
|
" match\n");
|
||||||
}
|
}
|
||||||
return NULL;
|
if (rvp)
|
||||||
|
*rvp = 2;
|
||||||
|
match = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
match = array_list;
|
match = array_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,7 +431,9 @@ void RebuildMap(void)
|
||||||
* find a unique name based on metadata name.
|
* find a unique name based on metadata name.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct mddev_ident *match = conf_match(info, st);
|
struct mddev_ident *match = conf_match(st, info,
|
||||||
|
NULL, 0,
|
||||||
|
NULL);
|
||||||
struct stat stb;
|
struct stat stb;
|
||||||
if (match && match->devname && match->devname[0] == '/') {
|
if (match && match->devname && match->devname[0] == '/') {
|
||||||
path = match->devname;
|
path = match->devname;
|
||||||
|
|
5
mdadm.h
5
mdadm.h
|
@ -1146,7 +1146,10 @@ extern char *conf_line(FILE *file);
|
||||||
extern char *conf_word(FILE *file, int allow_key);
|
extern char *conf_word(FILE *file, int allow_key);
|
||||||
extern int conf_name_is_free(char *name);
|
extern int conf_name_is_free(char *name);
|
||||||
extern int devname_matches(char *name, char *match);
|
extern int devname_matches(char *name, char *match);
|
||||||
extern struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st);
|
extern struct mddev_ident *conf_match(struct supertype *st,
|
||||||
|
struct mdinfo *info,
|
||||||
|
char *devname,
|
||||||
|
int verbose, int *rvp);
|
||||||
extern int experimental(void);
|
extern int experimental(void);
|
||||||
|
|
||||||
extern void free_line(char *line);
|
extern void free_line(char *line);
|
||||||
|
|
Loading…
Reference in New Issue