summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
51006d8)
If we aren't sure that the array belongs to 'this' host, use the
uuid to choose a name to avoid any conflict.
struct mdinfo info;
char *avail;
int nextspare = 0;
struct mdinfo info;
char *avail;
int nextspare = 0;
memset(&info, 0, sizeof(info));
memset(&info, 0, sizeof(info));
if (mdfd < 0) {
if (tst == NULL || tst->sb == NULL)
continue;
if (mdfd < 0) {
if (tst == NULL || tst->sb == NULL)
continue;
- if (update == NULL &&
- tst->ss->match_home(tst, homehost)==0) {
+ switch(tst->ss->match_home(tst, homehost))
+ {
+ case 1: /* happy with match. */
+ break;
+ case -1: /* cannot match */
+ uuid_for_name = 1;
+ break;
+ case 0: /* Doesn't match */
+ if (update)
+ /* We are changing the name*/
+ break;
if ((inargv && verbose >= 0) || verbose > 0)
if ((inargv && verbose >= 0) || verbose > 0)
- fprintf(stderr, Name ": %s is not built for host %s.\n",
+ fprintf(stderr, Name ": %s is not built for "
+ "host %s - using UUID for "
+ "device name.\n",
/* Auto-assemble, and this is not a usable host */
/* if update != NULL, we are updating the host
* name... */
/* Auto-assemble, and this is not a usable host */
/* if update != NULL, we are updating the host
* name... */
+ uuid_for_name = 1;
+ break;
}
}
/* If we are this far, then we are nearly commited to this device.
}
}
/* If we are this far, then we are nearly commited to this device.
*/
mdu_array_info_t inf;
char *c;
*/
mdu_array_info_t inf;
char *c;
if (!st || !st->sb) {
return 2;
}
st->ss->getinfo_super(st, &info);
if (!st || !st->sb) {
return 2;
}
st->ss->getinfo_super(st, &info);
- c = strchr(info.name, ':');
- if (c) c++; else c= info.name;
+ if (uuid_for_name)
+ c = fname_from_uuid(st, &info, nbuf);
+ else {
+ c = strchr(info.name, ':');
+ if (c) c++; else c= info.name;
+ }
if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6))
/* /dev/md/d0 style for partitionable */
asprintf(&mddev, "/dev/md/d%s", c);
if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6))
/* /dev/md/d0 style for partitionable */
asprintf(&mddev, "/dev/md/d%s", c);
int dfd, mdfd;
char *avail;
int active_disks;
int dfd, mdfd;
char *avail;
int active_disks;
+ int uuid_for_name = 0;
+ char *name_to_use;
+ char nbuf[64];
struct createinfo *ci = conf_get_create_info();
struct createinfo *ci = conf_get_create_info();
/* 3a/ if not, check for homehost match. If no match, reject. */
if (!match) {
if (homehost == NULL ||
/* 3a/ if not, check for homehost match. If no match, reject. */
if (!match) {
if (homehost == NULL ||
- st->ss->match_home(st, homehost) != 1) {
- if (verbose >= 0)
- fprintf(stderr, Name
- ": not found in mdadm.conf and not identified by homehost.\n");
- return 2;
- }
+ st->ss->match_home(st, homehost) != 1)
+ uuid_for_name = 1;
}
/* 4/ Determine device number. */
/* - If in mdadm.conf with std name, use that */
}
/* 4/ Determine device number. */
/* - If in mdadm.conf with std name, use that */
/* - Choose a free, high number. */
/* - Use a partitioned device unless strong suggestion not to. */
/* e.g. auto=md */
/* - Choose a free, high number. */
/* - Use a partitioned device unless strong suggestion not to. */
/* e.g. auto=md */
+ mp = map_by_uuid(&map, info.uuid);
+
+ if (uuid_for_name && ! mp) {
+ name_to_use = fname_from_uuid(st, &info, nbuf);
+ if (verbose >= 0)
+ fprintf(stderr, Name
+ ": not found in mdadm.conf and not identified by homehost"
+ " - using uuid based name\n");
+ } else
+ name_to_use = info.name;
+
if (match && is_standard(match->devname, &devnum))
/* We have devnum now */;
if (match && is_standard(match->devname, &devnum))
/* We have devnum now */;
- else if ((mp = map_by_uuid(&map, info.uuid)) != NULL)
devnum = mp->devnum;
else {
/* Have to guess a bit. */
devnum = mp->devnum;
else {
/* Have to guess a bit. */
use_partitions = 0;
if (st->ss->external)
use_partitions = 0;
use_partitions = 0;
if (st->ss->external)
use_partitions = 0;
- np = strchr(info.name, ':');
+ np = strchr(name_to_use, ':');
devnum = strtoul(np, &ep, 10);
if (ep > np && *ep == 0) {
/* This is a number. Let check that it is unused. */
devnum = strtoul(np, &ep, 10);
if (ep > np && *ep == 0) {
/* This is a number. Let check that it is unused. */
} else
devnum = use_partitions ? (-1-devnum) : devnum;
}
} else
devnum = use_partitions ? (-1-devnum) : devnum;
}
- mdfd = open_mddev_devnum(match ? match->devname : NULL,
+
+ mdfd = open_mddev_devnum(match ? match->devname : mp ? mp->path : NULL,
chosen_name, autof >> 3);
if (mdfd < 0) {
fprintf(stderr, Name ": failed to open %s: %s.\n",
chosen_name, autof >> 3);
if (mdfd < 0) {
fprintf(stderr, Name ": failed to open %s: %s.\n",
char *n;
int working = 0, preexist = 0;
struct map_ent *mp, *map = NULL;
char *n;
int working = 0, preexist = 0;
struct map_ent *mp, *map = NULL;
+ char nbuf[64];
+ char *name_to_use;
if ((autof&7) == 3 || (autof&7) == 5)
usepart = 0;
mp = map_by_uuid(&map, ra->uuid);
if ((autof&7) == 3 || (autof&7) == 5)
usepart = 0;
mp = map_by_uuid(&map, ra->uuid);
+
+ name_to_use = ra->name;
+ if (! name_to_use ||
+ ! *name_to_use ||
+ (*devname != '/' || strncmp("UUID-", strrchr(devname,'/')+1,5) == 0)
+ )
+ name_to_use = fname_from_uuid(st, ra, nbuf);
+
if (mp)
devnum = mp->devnum;
else {
if (mp)
devnum = mp->devnum;
else {
if (*n == 'd')
n++;
if (*n && devnum < 0) {
devnum = strtoul(n, &n, 10);
if (devnum >= 0 && (*n == 0 || *n == ' ')) {
/* Use this devnum */
if (*n == 'd')
n++;
if (*n && devnum < 0) {
devnum = strtoul(n, &n, 10);
if (devnum >= 0 && (*n == 0 || *n == ' ')) {
/* Use this devnum */
- usepart = (ra->name[0] == 'd');
+ usepart = (name_to_use[0] == 'd');
if (mddev_busy(usepart ? (-1-devnum) : devnum))
devnum = -1;
} else
if (mddev_busy(usepart ? (-1-devnum) : devnum))
devnum = -1;
} else
+ char *nm = name_to_use;
char nbuf[1024];
struct stat stb;
if (strchr(nm, ':'))
char nbuf[1024];
struct stat stb;
if (strchr(nm, ':'))
else
devnum = find_free_devnum(usepart);
}
else
devnum = find_free_devnum(usepart);
}
- mdfd = open_mddev_devnum(mp ? mp->path : NULL, devnum, ra->name,
+ mdfd = open_mddev_devnum(mp ? mp->path : NULL, devnum, name_to_use,
chosen_name, autof>>3);
if (mdfd < 0) {
chosen_name, autof>>3);
if (mdfd < 0) {
sysfs_set_safemode(ra, ra->safe_mode_delay);
if (verbose >= 0) {
fprintf(stderr, Name
sysfs_set_safemode(ra, ra->safe_mode_delay);
if (verbose >= 0) {
fprintf(stderr, Name
- "Started %s with %d devices",
+ ": Started %s with %d devices",
chosen_name, working + preexist);
if (preexist)
fprintf(stderr, " (%d new)", working);
chosen_name, working + preexist);
if (preexist)
fprintf(stderr, " (%d new)", working);
} else
if (verbose >= 0)
fprintf(stderr, Name
} else
if (verbose >= 0)
fprintf(stderr, Name
- "%s assembled with %d devices but "
+ ": %s assembled with %d devices but "
"not started\n",
chosen_name, working);
close(mdfd);
"not started\n",
chosen_name, working);
close(mdfd);
extern void uuid_from_super(int uuid[4], mdp_super_t *super);
extern int same_uuid(int a[4], int b[4], int swapuuid);
extern void copy_uuid(void *a, int b[4], int swapuuid);
extern void uuid_from_super(int uuid[4], mdp_super_t *super);
extern int same_uuid(int a[4], int b[4], int swapuuid);
extern void copy_uuid(void *a, int b[4], int swapuuid);
+extern char *fname_from_uuid(struct supertype *st,
+ struct mdinfo *info, char *buf);
extern unsigned long calc_csum(void *super, int bytes);
extern int enough(int level, int raid_disks, int layout, int clean,
char *avail, int avail_disks);
extern unsigned long calc_csum(void *super, int bytes);
extern int enough(int level, int raid_disks, int layout, int clean,
char *avail, int avail_disks);
+char *fname_from_uuid(struct supertype *st, struct mdinfo *info, char *buf)
+{
+ int i;
+ char uuid[16];
+ char *c = buf;
+ strcpy(c, "UUID-");
+ c += strlen(c);
+ copy_uuid(uuid, info->uuid, st->ss->swapuuid);
+ for (i=0; i<16; i++) {
+ if (i && (i&3)==0) {
+ strcpy(c, "-");
+ c++;
+ }
+ sprintf(c,"%02x", (unsigned char)uuid[i]);
+ c+= 2;
+ }
+ return buf;
+}
+
#ifndef MDASSEMBLE
int check_ext2(int fd, char *name)
{
#ifndef MDASSEMBLE
int check_ext2(int fd, char *name)
{