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:
NeilBrown 2011-11-01 13:30:41 +11:00
parent 81219e70f2
commit 2244d1a987
4 changed files with 26 additions and 91 deletions

View File

@ -47,11 +47,6 @@ static int Incremental_container(struct supertype *st, char *devname,
int verbose, int runstop, int autof,
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,
struct supertype *st, char *homehost, int require_homehost,
int autof, int freeze_reshape)
@ -213,7 +208,7 @@ int Incremental(char *devname, int verbose, int runstop,
st->ss->getinfo_super(st, &info, NULL);
/* 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)
goto out;
@ -591,79 +586,6 @@ out_unlock:
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,
int number, __u64 events, int verbose,
char *array_name)
@ -1460,7 +1382,7 @@ static int Incremental_container(struct supertype *st, char *devname,
return 0;
}
match = search_mdstat(st, &info, devname, verbose, &rv);
match = conf_match(st, &info, devname, verbose, &rv);
if (match == NULL && rv == 2)
return rv;

View File

@ -1019,11 +1019,12 @@ int conf_name_is_free(char *name)
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;
int verbose = 0;
char *devname = NULL;
array_list = conf_get_ident(NULL);
match = NULL;
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);
continue;
}
if (array_list->devices && devname &&
if (array_list->devices &&
!match_oneof(array_list->devices, devname)) {
if (verbose >= 2 && array_list->devname)
fprintf(stderr, Name
@ -1066,7 +1067,8 @@ struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st)
array_list->super_minor == UnSet) {
if (verbose >= 2 && array_list->devname)
fprintf(stderr, Name
": %s doesn't have any identifying information.\n",
": %s doesn't have any identifying"
" information.\n",
array_list->devname);
continue;
}
@ -1076,13 +1078,19 @@ struct mddev_ident *conf_match(struct mdinfo *info, struct supertype *st)
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);
": 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");
": multiple lines in mdadm.conf"
" match\n");
}
return NULL;
if (rvp)
*rvp = 2;
match = NULL;
break;
}
match = array_list;
}

View File

@ -431,7 +431,9 @@ void RebuildMap(void)
* 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;
if (match && match->devname && match->devname[0] == '/') {
path = match->devname;

View File

@ -1146,7 +1146,10 @@ extern char *conf_line(FILE *file);
extern char *conf_word(FILE *file, int allow_key);
extern int conf_name_is_free(char *name);
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 void free_line(char *line);