- Fix a few issues with the new code to determine when a device gets to

keep its name and when it doesn't
This commit is contained in:
Doug Ledford 2009-03-21 01:25:02 +00:00
parent a261cbe6b4
commit 1c823de16c
2 changed files with 138 additions and 27 deletions

View File

@ -1,6 +1,21 @@
--- mdadm-3.0-devel3/Incremental.c.foreign 2009-03-20 17:11:01.000000000 -0400 --- mdadm-3.0-devel3/Incremental.c.foreign 2009-03-20 17:49:20.000000000 -0400
+++ mdadm-3.0-devel3/Incremental.c 2009-03-20 17:11:39.000000000 -0400 +++ mdadm-3.0-devel3/Incremental.c 2009-03-20 21:19:50.000000000 -0400
@@ -48,8 +48,10 @@ int Incremental(char *devname, int verbo @@ -29,12 +29,14 @@
*/
#include "mdadm.h"
+#include <ctype.h>
static int count_active(struct supertype *st, int mdfd, char **availp,
struct mdinfo *info);
static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
int number, __u64 events, int verbose,
char *array_name);
+static int compare_array_name(char *conf_name, char *sb_name);
int Incremental(char *devname, int verbose, int runstop,
struct supertype *st, char *homehost, int autof)
@@ -48,8 +50,10 @@ int Incremental(char *devname, int verbo
* 2/ Find metadata, reject if none appropriate (check * 2/ Find metadata, reject if none appropriate (check
* version/name from args) * version/name from args)
* 3/ Check if there is a match in mdadm.conf * 3/ Check if there is a match in mdadm.conf
@ -13,7 +28,7 @@
* 4/ Determine device number. * 4/ Determine device number.
* - If in mdadm.conf with std name, use that * - If in mdadm.conf with std name, use that
* - UUID in /dev/md/mdadm.map use that * - UUID in /dev/md/mdadm.map use that
@@ -78,7 +80,7 @@ int Incremental(char *devname, int verbo @@ -78,7 +82,7 @@ int Incremental(char *devname, int verbo
*/ */
struct stat stb; struct stat stb;
struct mdinfo info; struct mdinfo info;
@ -22,8 +37,15 @@
char chosen_name[1024]; char chosen_name[1024];
int rv; int rv;
struct map_ent *mp, *map = NULL; struct map_ent *mp, *map = NULL;
@@ -150,24 +152,37 @@ int Incremental(char *devname, int verbo @@ -148,26 +152,42 @@ int Incremental(char *devname, int verbo
st->ss->getinfo_super(st, &info);
/* 3/ Check if there is a match in mdadm.conf */
+ name_to_use = strchr(info.name, ':');
+ if (name_to_use)
+ name_to_use++;
+ else
+ name_to_use = info.name;
array_list = conf_get_ident(NULL); array_list = conf_get_ident(NULL);
match = NULL; match = NULL;
+ match_uuid = NULL; + match_uuid = NULL;
@ -45,15 +67,13 @@
array_list->devname); array_list->devname);
- continue; - continue;
- } - }
+ /* If we match name now and the entry has a uuid, it *must* + /* If we match name, save it off separately so we can tell if
+ * match. If we match name, but the entry *doesn't* have + * we matched uuid, name, or both, and if both, if they were
+ * a uuid set, save it off separately so we can tell if we
+ * matched uuid, name, or both, and if both, if they were
+ * the same entry */ + * the same entry */
if (array_list->name[0] && if (array_list->name[0] &&
- strcasecmp(array_list->name, info.name) != 0) { - strcasecmp(array_list->name, info.name) != 0) {
- if (verbose >= 2 && array_list->devname) - if (verbose >= 2 && array_list->devname)
+ strcasecmp(array_list->name, info.name) == 0) + compare_array_name(array_list->name, info.name))
+ match_name = array_list; + match_name = array_list;
+ else if (array_list->name[0] && verbose >= 2 && + else if (array_list->name[0] && verbose >= 2 &&
+ array_list->devname) + array_list->devname)
@ -67,7 +87,7 @@
if (array_list->devices && 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)
@@ -197,7 +212,13 @@ int Incremental(char *devname, int verbo @@ -197,7 +217,13 @@ int Incremental(char *devname, int verbo
/* FIXME, should I check raid_disks and level too?? */ /* FIXME, should I check raid_disks and level too?? */
if (match) { if (match) {
@ -82,7 +102,7 @@
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 - cannot decide which to use.\n",
@@ -205,23 +226,54 @@ int Incremental(char *devname, int verbo @@ -205,23 +231,52 @@ int Incremental(char *devname, int verbo
else else
fprintf(stderr, Name fprintf(stderr, Name
": multiple lines in mdadm.conf match\n"); ": multiple lines in mdadm.conf match\n");
@ -102,29 +122,27 @@
+ * likely foreign match. I dropped the homehost test entirely because + * likely foreign match. I dropped the homehost test entirely because
+ * it didn't seem to add any value whatsoever above and beyond what + * it didn't seem to add any value whatsoever above and beyond what
+ * these tests can do. */ + * these tests can do. */
+ if (match_uuid == match_name) + if (match && match_uuid == match_name) {
+ /* found in conf, both name and uuid match */ + /* found in conf, both name and uuid match */
trustworthy = LOCAL; trustworthy = LOCAL;
- else if (homehost == NULL || - else if (homehost == NULL ||
- st->ss->match_home(st, homehost) != 1) - st->ss->match_home(st, homehost) != 1)
+ else if (match_uuid && match_name) - trustworthy = FOREIGN;
+ /* found both a name and a uuid match, but not on the same
+ * entry, so use a random name and assume UUID match was
+ * correct but has a bad name just in case the one that
+ * would match the matching name shows up with both a
+ * matching name and a matching UUID */
trustworthy = FOREIGN;
- else - else
- trustworthy = LOCAL; + } else if (match_uuid && match_name) {
+ else if (!match_uuid && match_name) { + /* found both a name and a uuid match, but not on the same
+ * entry, so prefer the uuid match (done above) */
trustworthy = LOCAL;
+ } else if (!match_uuid && match_name) {
+ /* no uuid match, but name match */ + /* no uuid match, but name match */
+ if (match_name->uuid_set) + if (match_name->uuid_set) {
+ /* oops, name that matched had a uuid, it just wasn't + /* oops, name that matched had a uuid, it just wasn't
+ * right, assume there is a local device with both + * right, assume there is a local device with both
+ * a matching name and uuid, so this needs a random + * a matching name and uuid, so this needs a random
+ * name */ + * name */
+ trustworthy = FOREIGN; + trustworthy = FOREIGN;
+ else + match = NULL;
+ } else
+ /* matched name, and the matching entry in conf file + /* matched name, and the matching entry in conf file
+ * didn't include a uuid, and this uuid never showed + * didn't include a uuid, and this uuid never showed
+ * up anywhere else in the conf file, so consider it + * up anywhere else in the conf file, so consider it
@ -147,8 +165,66 @@
/* There are three possible sources for 'autof': command line, /* There are three possible sources for 'autof': command line,
* ARRAY line in mdadm.conf, or CREATE line in mdadm.conf. * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
@@ -240,11 +295,6 @@ int Incremental(char *devname, int verbo
return Incremental_container(st, devname, verbose, runstop,
autof, trustworthy);
}
- name_to_use = strchr(info.name, ':');
- if (name_to_use)
- name_to_use++;
- else
- name_to_use = info.name;
if ((!name_to_use || name_to_use[0] == 0) &&
info.array.level == LEVEL_CONTAINER &&
@@ -797,3 +847,45 @@ int Incremental_container(struct superty
map_unlock(&map);
return 0;
}
+
+static int compare_array_name(char *conf_name, char *sb_name)
+{
+ char *cptr, *sptr;
+ int conf_num = -1;
+
+ /* usage of the name variable in the superblock comes in several
+ * flavors:
+ * A) full md pathname (/dev/md0)
+ * B) just the md name (md0)
+ * C) just the md number (0)
+ * D) all of the above, but with hostname: prefixed to it
+ *
+ * Depending on which of those variants we have, we need to alter
+ * how we attempt to match the array name in the mdadm.conf file
+ * which is always a full pathname. We don't match on hostname:
+ * though, so eliminate it from the equation.
+ */
+
+ if ((sptr = strchr(sb_name, ':')) == NULL)
+ sptr = sb_name;
+ else
+ sptr++;
+
+ /* Do we have a full pathname in the superblock name field? */
+ if (strchr(sptr, '/'))
+ return !strcasecmp(conf_name, sptr);
+ /* If not, is it just a number or an md device name? */
+ else if (isdigit(sptr[0])) {
+ cptr = conf_name + strlen(conf_name);
+ while (cptr > conf_name && isdigit(cptr[-1]))
+ cptr--;
+ if (cptr[0])
+ conf_num = strtoul(cptr, NULL, 10);
+ return conf_num == strtoul(sptr, NULL, 10);
+ } /* fall through else, it's a device name but not a full path */
+
+ cptr = strcasestr(conf_name, sptr);
+ if (cptr)
+ return !strcasecmp(cptr, sptr);
+ return 0;
+}
--- mdadm-3.0-devel3/mdadm.h.foreign 2009-03-10 01:39:41.000000000 -0400 --- mdadm-3.0-devel3/mdadm.h.foreign 2009-03-10 01:39:41.000000000 -0400
+++ mdadm-3.0-devel3/mdadm.h 2009-03-20 17:11:01.000000000 -0400 +++ mdadm-3.0-devel3/mdadm.h 2009-03-20 17:49:20.000000000 -0400
@@ -785,6 +785,7 @@ extern mddev_dev_t conf_get_devs(void); @@ -785,6 +785,7 @@ extern mddev_dev_t conf_get_devs(void);
extern int conf_test_dev(char *devname); extern int conf_test_dev(char *devname);
extern struct createinfo *conf_get_create_info(void); extern struct createinfo *conf_get_create_info(void);
@ -157,8 +233,39 @@
extern char *conf_get_mailaddr(void); extern char *conf_get_mailaddr(void);
extern char *conf_get_mailfrom(void); extern char *conf_get_mailfrom(void);
extern char *conf_get_program(void); extern char *conf_get_program(void);
--- mdadm-3.0-devel3/mdopen.c.foreign 2009-03-20 19:02:38.000000000 -0400
+++ mdadm-3.0-devel3/mdopen.c 2009-03-20 19:02:43.000000000 -0400
@@ -159,7 +159,6 @@ int create_mddev(char *dev, char *name,
strcpy(chosen, "/dev/md/");
cname = chosen + strlen(chosen);
-
if (dev) {
if (strncmp(dev, "/dev/md/", 8) == 0) {
@@ -240,12 +239,14 @@ int create_mddev(char *dev, char *name,
if (num < 0 && trustworthy == LOCAL && name) {
/* if name is numeric, use that for num
* if it is not already in use */
- char *ep;
- num = strtoul(name, &ep, 10);
- if (ep == name || *ep)
- num = -1;
- else if (mddev_busy(use_mdp ? (-1-num) : num))
- num = -1;
+ char *e = name + strlen(name);
+ while (e > name && isdigit(e[-1]))
+ e--;
+ if (e[0]) {
+ num = strtoul(e, NULL, 10);
+ if (mddev_busy(use_mdp ? (-1-num) : num))
+ num = -1;
+ }
}
if (num < 0) {
--- mdadm-3.0-devel3/config.c.foreign 2009-03-10 01:39:41.000000000 -0400 --- mdadm-3.0-devel3/config.c.foreign 2009-03-10 01:39:41.000000000 -0400
+++ mdadm-3.0-devel3/config.c 2009-03-20 17:11:01.000000000 -0400 +++ mdadm-3.0-devel3/config.c 2009-03-20 17:49:20.000000000 -0400
@@ -637,7 +637,7 @@ void homehostline(char *line) @@ -637,7 +637,7 @@ void homehostline(char *line)
} }
} }

View File

@ -1,7 +1,7 @@
Summary: The mdadm program controls Linux md devices (software RAID arrays) Summary: The mdadm program controls Linux md devices (software RAID arrays)
Name: mdadm Name: mdadm
Version: 3.0 Version: 3.0
Release: 0.devel3.4%{?dist} Release: 0.devel3.5%{?dist}
Source: http://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-%{version}-devel3.tar.bz2 Source: http://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-%{version}-devel3.tar.bz2
Source1: mdmonitor.init Source1: mdmonitor.init
Source2: raid-check Source2: raid-check
@ -87,6 +87,10 @@ fi
%attr(0700,root,root) %dir /var/run/mdadm %attr(0700,root,root) %dir /var/run/mdadm
%changelog %changelog
* Fri Mar 20 2009 Doug Ledford <dledford@redhat.com> - 3.0-0.devel3.5
- Fix a few issues with the new code to determine when a device gets to
keep its name and when it doesn't
* Fri Mar 20 2009 Doug Ledford <dledford@redhat.com> - 3.0-0.devel3.4 * Fri Mar 20 2009 Doug Ledford <dledford@redhat.com> - 3.0-0.devel3.4
- Change the perms on the udev rules file, it doesn't need to be +x - Change the perms on the udev rules file, it doesn't need to be +x