- /* 3a/ if not, check for homehost match. If no match, reject. */
- if (!match) {
- if (homehost == NULL ||
- st->ss->match_home(st, homehost) == 0) {
- if (verbose >= 0)
- fprintf(stderr, Name
- ": not found in mdadm.conf and not identified by homehost.\n");
- return 2;
- }
- }
- /* 4/ Determine device number. */
- /* - If in mdadm.conf with std name, use that */
- /* - UUID in /var/run/mdadm.map use that */
- /* - If name is suggestive, use that. unless in use with */
- /* different uuid. */
- /* - Choose a free, high number. */
- /* - Use a partitioned device unless strong suggestion not to. */
- /* e.g. auto=md */
- 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. */
- int use_partitions = 1;
- char *np, *ep;
- char *nm, nbuf[1024];
- if ((autof&7) == 3 || (autof&7) == 5)
- use_partitions = 0;
- np = strchr(info.name, ':');
- if (np)
- np++;
- else
- np = info.name;
- devnum = strtoul(np, &ep, 10);
- if (ep > np && *ep == 0) {
- /* This is a number. Let check that it is unused. */
- if (mddev_busy(use_partitions ? (-1-devnum) : devnum))
- devnum = -1;
- } else
- devnum = -1;
-
- if (match)
- nm = match->devname;
- else {
- sprintf(nbuf, "/dev/md/%s", np);
- nm = nbuf;
- }
- if (stat(nm, &stb) == 0 &&
- S_ISBLK(stb.st_mode) &&
- major(stb.st_rdev) == (use_partitions ?
- get_mdp_major() : MD_MAJOR)) {
- if (use_partitions)
- devnum = minor(stb.st_rdev) >> MdpMinorShift;
- else
- devnum = minor(stb.st_rdev);
- if (mddev_busy(use_partitions ? (-1-devnum) : devnum))
- devnum = -1;
- }
-
- if (devnum < 0) {
- /* Haven't found anything yet, choose something free */
- devnum = find_free_devnum(use_partitions);
+ /* 3a/ if not, check for homehost match. If no match, continue
+ * but don't trust the 'name' in the array. Thus a 'random' minor
+ * number will be assigned, and the device name will be based
+ * on that. */
+ if (match)
+ trustworthy = LOCAL;
+ else if (homehost == NULL ||
+ st->ss->match_home(st, homehost) != 1)
+ trustworthy = FOREIGN;
+ name_to_use = strchr(info.name, ':');
+ if (name_to_use)
+ name_to_use++;
+ else
+ name_to_use = info.name;
+
+ /* There are three possible sources for 'autof': command line,
+ * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
+ * ARRAY takes precedence, then command line, then
+ * CREATE.
+ */
+ if (match && match->autof)
+ autof = match->autof;
+ if (autof == 0)
+ autof = ci->autof;