static int Incremental_container(struct supertype *st, char *devname,
struct context *c, char *only);
-int Incremental(char *devname, struct context *c,
+int Incremental(struct mddev_dev *devlist, struct context *c,
struct supertype *st)
{
/* Add this device to an array, creating the array if necessary
struct mdinfo *sra = NULL, *d;
struct mddev_ident *match;
char chosen_name[1024];
+ char *md_devname;
int rv = 1;
struct map_ent *mp, *map = NULL;
int dfd = -1, mdfd = -1;
struct dev_policy *policy = NULL;
struct map_ent target_array;
int have_target;
+ char *devname = devlist->devname;
+ int journal_device_missing = 0;
struct createinfo *ci = conf_get_create_info();
if (must_be_container(dfd)) {
if (!st)
st = super_by_fd(dfd, NULL);
- if (st)
- st->ignore_hw_compat = 1;
if (st && st->ss->load_container)
rv = st->ss->load_container(st, dfd, NULL);
close(dfd);
if (!rv && st->ss->container_content) {
if (map_lock(&map))
- pr_err("failed to get "
- "exclusive lock on mapfile\n");
+ pr_err("failed to get exclusive lock on mapfile\n");
+ if (c->export)
+ printf("MD_DEVNAME=%s\n", devname);
rv = Incremental_container(st, devname, c, NULL);
map_unlock(&map);
return rv;
/* 1/ Check if device is permitted by mdadm.conf */
- if (!conf_test_dev(devname)) {
+ for (;devlist; devlist = devlist->next)
+ if (conf_test_dev(devlist->devname))
+ break;
+ if (!devlist) {
+ devlist = conf_get_devs();
+ for (;devlist; devlist = devlist->next) {
+ struct stat st2;
+ if (stat(devlist->devname, &st2) == 0 &&
+ (st2.st_mode & S_IFMT) == S_IFBLK &&
+ st2.st_rdev == stb.st_rdev)
+ break;
+ }
+ }
+ if (!devlist) {
if (c->verbose >= 0)
pr_err("%s not permitted by mdadm.conf.\n",
devname);
policy = disk_policy(&dinfo);
have_target = policy_check_path(&dinfo, &target_array);
- if (st == NULL && (st = guess_super(dfd)) == NULL) {
+ if (st == NULL && (st = guess_super_type(dfd, guess_array)) == NULL) {
if (c->verbose >= 0)
pr_err("no recognisable superblock on %s.\n",
devname);
rv = try_spare(devname, &dfd, policy,
have_target ? &target_array : NULL,
- st, c->verbose);
+ NULL, c->verbose);
goto out;
}
- st->ignore_hw_compat = 1;
+ st->ignore_hw_compat = 0;
+
if (st->ss->compare_super == NULL ||
- st->ss->load_super(st, dfd, NULL)) {
+ st->ss->load_super(st, dfd, c->verbose >= 0 ? devname : NULL)) {
if (c->verbose >= 0)
pr_err("no RAID superblock on %s.\n",
devname);
if (match && match->devname
&& strcasecmp(match->devname, "<ignore>") == 0) {
if (c->verbose >= 0)
- pr_err("array containing %s is explicitly"
- " ignored by mdadm.conf\n",
+ pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
devname);
goto out;
}
if (!match && !conf_test_metadata(st->ss->name, policy,
(trustworthy == LOCAL))) {
if (c->verbose >= 1)
- pr_err("%s has metadata type %s for which "
- "auto-assembly is disabled\n",
+ pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
devname, st->ss->name);
goto out;
}
/* 4/ Check if array exists.
*/
if (map_lock(&map))
- pr_err("failed to get exclusive lock on "
- "mapfile\n");
+ pr_err("failed to get exclusive lock on mapfile\n");
/* Now check we can get O_EXCL. If not, probably "mdadm -A" has
* taken over
*/
if (mdfd < 0) {
+ /* Skip the clustered ones. This should be started by
+ * clustering resource agents
+ */
+ if (info.array.state & (1 << MD_SB_CLUSTERED))
+ goto out;
+
/* Couldn't find an existing array, maybe make a new one */
mdfd = create_mddev(match ? match->devname : NULL,
name_to_use, c->autof, trustworthy, chosen_name);
* So reject it.
*/
ioctl(mdfd, STOP_ARRAY, NULL);
- pr_err("You have an old buggy kernel which cannot support\n"
- " --incremental reliably. Aborting.\n");
+ pr_err("You have an old buggy kernel which cannot support\n --incremental reliably. Aborting.\n");
rv = 2;
goto out_unlock;
}
st2 = dup_super(st);
if (st2->ss->load_super(st2, dfd2, NULL) ||
st->ss->compare_super(st, st2) != 0) {
- pr_err("metadata mismatch between %s and "
- "chosen array %s\n",
+ pr_err("metadata mismatch between %s and chosen array %s\n",
devname, chosen_name);
close(dfd2);
rv = 2;
/* add disk needs to know about containers */
if (st->ss->external)
sra->array.level = LEVEL_CONTAINER;
+
+ if (info.array.state & (1 << MD_SB_CLUSTERED))
+ info.disk.state |= (1 << MD_DISK_CLUSTER_ADD);
+
err = add_disk(mdfd, st, sra, &info);
if (err < 0 && errno == EBUSY) {
/* could be another device present with the same
info.array.working_disks ++;
}
+ if (strncmp(chosen_name, "/dev/md/", 8) == 0)
+ md_devname = chosen_name+8;
+ else
+ md_devname = chosen_name;
+ if (c->export) {
+ printf("MD_DEVICE=%s\n", fd2devnm(mdfd));
+ printf("MD_DEVNAME=%s\n", md_devname);
+ printf("MD_FOREIGN=%s\n", trustworthy == FOREIGN ? "yes" : "no");
+ }
/* 7/ Is there enough devices to possibly start the array? */
/* 7a/ if not, finish with success. */
char devnm[32];
/* Try to assemble within the container */
sysfs_uevent(sra, "change");
- if (c->verbose >= 0)
+ if (!c->export && c->verbose >= 0)
pr_err("container %s now has %d device%s\n",
chosen_name, info.array.working_disks,
info.array.working_disks == 1?"":"s");
sra = sysfs_read(mdfd, NULL, (GET_DEVS | GET_STATE |
GET_OFFSET | GET_SIZE));
active_disks = count_active(st, sra, mdfd, &avail, &info);
+
+ journal_device_missing = (info.journal_device_required) && (info.journal_clean == 0);
+
if (enough(info.array.level, info.array.raid_disks,
info.array.layout, info.array.state & 1,
avail) == 0) {
- if (c->verbose >= 0)
+ if (c->export) {
+ printf("MD_STARTED=no\n");
+ } else if (c->verbose >= 0)
pr_err("%s attached to %s, not enough to start (%d).\n",
devname, chosen_name, active_disks);
rv = 0;
/* + start the array (auto-readonly). */
if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
- if (c->verbose >= 0)
+ if (c->export) {
+ printf("MD_STARTED=already\n");
+ } else if (c->verbose >= 0)
pr_err("%s attached to %s which is already active.\n",
devname, chosen_name);
rv = 0;
}
map_unlock(&map);
- if (c->runstop > 0 || active_disks >= info.array.working_disks) {
+ if (c->runstop > 0 || (!journal_device_missing && active_disks >= info.array.working_disks)) {
struct mdinfo *dsk;
/* Let's try to start it */
+ if (journal_device_missing)
+ pr_err("Trying to run with missing journal device\n");
if (info.reshape_active && !(info.reshape_active & RESHAPE_NO_BACKUP)) {
pr_err("%s: This array is being reshaped and cannot be started\n",
chosen_name);
else
rv = sysfs_set_str(sra, NULL,
"array_state", "read-auto");
+ /* Array might be O_EXCL which will interfere with
+ * fsck and mount. So re-open without O_EXCL.
+ */
+ reopen_mddev(mdfd);
if (rv == 0) {
- if (c->verbose >= 0)
+ if (c->export) {
+ printf("MD_STARTED=yes\n");
+ } else if (c->verbose >= 0)
pr_err("%s attached to %s, which has been started.\n",
devname, chosen_name);
rv = 0;
rv = 1;
}
} else {
- if (c->verbose >= 0)
+ if (c->export) {
+ printf("MD_STARTED=unsafe\n");
+ } else if (journal_device_missing) {
+ pr_err("Journal device is missing, not safe to start yet.\n");
+ } else if (c->verbose >= 0)
pr_err("%s attached to %s, not enough to start safely.\n",
devname, chosen_name);
rv = 0;
close(dfd);
if (ok != 0)
continue;
+
info.array.raid_disks = raid_disks;
st->ss->getinfo_super(st, &info, devmap + raid_disks * devnum);
+ if (info.disk.raid_disk == MD_DISK_ROLE_JOURNAL)
+ bestinfo->journal_clean = 1;
if (!avail) {
raid_disks = info.array.raid_disks;
avail = xcalloc(raid_disks, 1);
replcnt++;
st->ss->free_super(st);
}
+
if (!avail)
return 0;
/* We need to reject any device that thinks the best device is
*/
if (map_lock(&map)) {
- pr_err("failed to get exclusive lock on "
- "mapfile\n");
+ pr_err("failed to get exclusive lock on mapfile\n");
return 1;
}
for (mp = map ; mp ; mp = mp->next) {
sra->text_version);
if (!st2) {
if (verbose > 1)
- pr_err("not adding %s to %s"
- " as metadata not recognised.\n",
+ pr_err("not adding %s to %s as metadata not recognised.\n",
devname, mp->path);
goto next;
}
if (domain_test(dl, pol, st2->ss->name) != 1) {
/* domain test fails */
if (verbose > 1)
- pr_err("not adding %s to %s as"
- " it is not in a compatible domain\n",
+ pr_err("not adding %s to %s as it is not in a compatible domain\n",
devname, mp->path);
goto next;
if (st2 == NULL ||
st2->ss->load_super(st2, fd, NULL) < 0)
goto next;
+ st2->ignore_hw_compat = 0;
if (!st) {
/* Check domain policy again, this time referring to metadata */
!policy_action_allows(pol, st?st->ss->name:NULL,
act_spare_same_slot)) {
if (verbose > 1)
- pr_err("%s is not bare, so not "
- "considering as a spare\n",
+ pr_err("%s is not bare, so not considering as a spare\n",
devname);
return 1;
}
struct supertype *st = super_by_fd(mdfd, NULL);
int ret = 0;
struct map_ent *map = NULL;
- if (st)
- st->ignore_hw_compat = 1;
+
if (st && st->ss->load_container)
ret = st->ss->load_container(st, mdfd, NULL);
close(mdfd);
- if (!ret && st->ss->container_content) {
+ if (!ret && st && st->ss->container_content) {
if (map_lock(&map))
pr_err("failed to get exclusive lock on mapfile\n");
ret = Incremental_container(st, me->path, c, only);
int sfd;
int ra_blocked = 0;
int ra_all = 0;
+ int result = 0;
st->ss->getinfo_super(st, &info, NULL);
info.container_enough > 0)
/* pass */;
else {
- if (c->verbose)
+ if (c->export) {
+ printf("MD_STARTED=no\n");
+ } else if (c->verbose)
pr_err("not enough devices to start the container\n");
return 0;
}
list = st->ss->container_content(st, NULL);
/* when nothing to activate - quit */
- if (list == NULL)
+ if (list == NULL) {
+ if (c->export) {
+ printf("MD_STARTED=nothing\n");
+ }
return 0;
+ }
for (ra = list ; ra ; ra = ra->next) {
int mdfd;
char chosen_name[1024];
if (match && match->devname &&
strcasecmp(match->devname, "<ignore>") == 0) {
if (c->verbose > 0)
- pr_err("array %s/%s is "
- "explicitly ignored by mdadm.conf\n",
+ pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
match->container, match->member);
continue;
}
}
assemble_container_content(st, mdfd, ra, c,
- chosen_name);
+ chosen_name, &result);
close(mdfd);
}
+ if (c->export && result) {
+ char sep = '=';
+ printf("MD_STARTED");
+ if (result & INCR_NO) {
+ printf("%cno", sep);
+ sep = ',';
+ }
+ if (result & INCR_UNSAFE) {
+ printf("%cunsafe", sep);
+ sep = ',';
+ }
+ if (result & INCR_ALREADY) {
+ printf("%calready", sep);
+ sep = ',';
+ }
+ if (result & INCR_YES) {
+ printf("%cyes", sep);
+ sep = ',';
+ }
+ printf("\n");
+ }
/* don't move spares to container with volume being activated
when all volumes are blocked */
char buf[32];
if (!id_path)
- dprintf(Name ": incremental removal without --path <id_path> "
- "lacks the possibility to re-add new device in this "
- "port\n");
+ dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
if (strchr(devname, '/')) {
- pr_err("incremental removal requires a "
- "kernel device name, not a file: %s\n", devname);
+ pr_err("incremental removal requires a kernel device name, not a file: %s\n", devname);
return 1;
}
ent = mdstat_by_component(devname);
if (!ent) {
if (verbose >= 0)
- pr_err("%s does not appear to be a component "
- "of any array\n", devname);
+ pr_err("%s does not appear to be a component of any array\n", devname);
return 1;
}
sysfs_init(&mdi, -1, ent->devnm);
- if (sysfs_get_str(&mdi, NULL, "array_state",
- buf, sizeof(buf)) > 0) {
- if (strncmp(buf, "active", 6) == 0 ||
- strncmp(buf, "clean", 5) == 0)
- sysfs_set_str(&mdi, NULL,
- "array_state", "read-auto");
+ mdfd = open_dev_excl(ent->devnm);
+ if (mdfd > 0) {
+ close(mdfd);
+ if (sysfs_get_str(&mdi, NULL, "array_state",
+ buf, sizeof(buf)) > 0) {
+ if (strncmp(buf, "active", 6) == 0 ||
+ strncmp(buf, "clean", 5) == 0)
+ sysfs_set_str(&mdi, NULL,
+ "array_state", "read-auto");
+ }
}
mdfd = open_dev(ent->devnm);
if (mdfd < 0) {
if (verbose >= 0)
- pr_err("Cannot open array %s!!\n", ent->dev);
+ pr_err("Cannot open array %s!!\n", ent->devnm);
free_mdstat(ent);
return 1;
}
struct mdstat_ent *mdstat = mdstat_read(0, 0);
struct mdstat_ent *memb;
for (memb = mdstat ; memb ; memb = memb->next)
- if (is_container_member(memb, ent->dev)) {
+ if (is_container_member(memb, ent->devnm)) {
int subfd = open_dev(memb->devnm);
if (subfd >= 0) {
rv |= Manage_subdevs(
- memb->dev, subfd,
+ memb->devnm, subfd,
&devlist, verbose, 0,
NULL, 0);
close(subfd);
}
free_mdstat(mdstat);
} else
- rv |= Manage_subdevs(ent->dev, mdfd, &devlist,
+ rv |= Manage_subdevs(ent->devnm, mdfd, &devlist,
verbose, 0, NULL, 0);
if (rv & 2) {
/* Failed due to EBUSY, try to stop the array.
*/
int devid = devnm2devid(ent->devnm);
run_udisks("--unmount", map_dev(major(devid),minor(devid), 0));
- rv = Manage_stop(ent->dev, mdfd, verbose, 1);
+ rv = Manage_stop(ent->devnm, mdfd, verbose, 1);
if (rv)
/* At least we can try to trigger a 'remove' */
sysfs_uevent(&mdi, "remove");
}
} else {
devlist.disposition = 'r';
- rv = Manage_subdevs(ent->dev, mdfd, &devlist,
+ rv = Manage_subdevs(ent->devnm, mdfd, &devlist,
verbose, 0, NULL, 0);
}
close(mdfd);