* array was possibly started early and our best bet is
* to add this anyway.
* Also if action policy is re-add or better we allow
- * re-add
+ * re-add.
+ * This doesn't apply to containers as the 'non-spare'
+ * flag has a different meaning. The test has to happen
+ * at the device level there
*/
- if ((info.disk.state & (1<<MD_DISK_SYNC)) != 0
+ if (!st->ss->external
+ && (info.disk.state & (1<<MD_DISK_SYNC)) != 0
&& ! policy_action_allows(policy, st->ss->name,
act_re_add)
&& runstop < 1) {
- int active = 0;
-
- if (st->ss->external) {
- char *devname = devnum2devname(fd2devnum(mdfd));
-
- active = devname && is_container_active(devname);
- free(devname);
- } else if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0)
- active = 1;
- if (active) {
+ if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
fprintf(stderr, Name
": not adding %s to active array (without --run) %s\n",
devname, chosen_name);
/* 7/ Is there enough devices to possibly start the array? */
/* 7a/ if not, finish with success. */
if (info.array.level == LEVEL_CONTAINER) {
- char *devname = NULL;
+ int devnum = devnum; /* defined and used iff ->external */
/* Try to assemble within the container */
map_unlock(&map);
sysfs_uevent(&info, "change");
chosen_name, info.array.working_disks);
wait_for(chosen_name, mdfd);
if (st->ss->external)
- devname = devnum2devname(fd2devnum(mdfd));
+ devnum = fd2devnum(mdfd);
close(mdfd);
sysfs_free(sra);
rv = Incremental(chosen_name, verbose, runstop,
rv = 0;
/* after spare is added, ping monitor for external metadata
* so that it can eg. try to rebuild degraded array */
- if (st->ss->external) {
- ping_monitor(devname);
- free(devname);
- }
+ if (st->ss->external)
+ ping_monitor_by_id(devnum);
return rv;
}
struct domainlist *dl = NULL;
struct mdinfo *sra;
unsigned long long devsize;
- unsigned long long component_size;
+ unsigned long long component_size = 0;
if (is_subarray(mp->metadata))
continue;
}
dl = domain_from_array(sra, st2->ss->name);
- if (!domain_test(dl, pol, st2->ss->name)) {
+ if (domain_test(dl, pol, st2->ss->name) != 1) {
/* domain test fails */
if (verbose > 1)
fprintf(stderr, Name ": not adding %s to %s as"
DIR *dir;
struct dirent *de;
char *chosen = NULL;
- unsigned long long chosen_size;
+ unsigned long long chosen_size = 0;
struct supertype *chosen_st = NULL;
int fd;
pol2 = path_policy(de->d_name, type_disk);
domain_merge(&domlist, pol2, st ? st->ss->name : NULL);
- if (domain_test(domlist, pol, st ? st->ss->name : NULL) == 0)
+ if (domain_test(domlist, pol, st ? st->ss->name : NULL) != 1)
/* new device is incompatible with this device. */
goto next;
domain_free(domlist);
domlist = NULL;
- asprintf(&devname, "/dev/disk/by-path/%s", de->d_name);
+ if (asprintf(&devname, "/dev/disk/by-path/%s", de->d_name) != 1) {
+ devname = NULL;
+ goto next;
+ }
fd = open(devname, O_RDONLY);
if (fd < 0)
goto next;
if (!st) {
/* Check domain policy again, this time referring to metadata */
domain_merge(&domlist, pol2, st2->ss->name);
- if (domain_test(domlist, pol, st2->ss->name) == 0)
+ if (domain_test(domlist, pol, st2->ss->name) != 1)
/* Incompatible devices for this metadata type */
goto next;
if (!policy_action_allows(pol, st2->ss->name, act_spare))
if (list->array.state & (1<<MD_SB_BBM_ERRORS)) {
fprintf(stderr, Name ": BBM log found in metadata. "
"Cannot activate array(s).\n");
- list = NULL;
+ /* free container data and exit */
+ sysfs_free(list);
+ return 2;
}
for (ra = list ; ra ; ra = ra->next) {
}
assemble_container_content(st, mdfd, ra, runstop,
- chosen_name, verbose);
+ chosen_name, verbose, NULL);
+ close(mdfd);
}
/* Now move all suitable spares from spare container */