static int count_active(struct supertype *st, struct mdinfo *sra,
int mdfd, char **availp,
- struct mdinfo *info, int *journal_device_missing);
+ struct mdinfo *info);
static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
int number, __u64 events, int verbose,
char *array_name);
/* 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
sysfs_free(sra);
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);
+ 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) {
close(mdfd);
if (policy)
dev_policy_free(policy);
- if (sra)
- sysfs_free(sra);
+ sysfs_free(sra);
return rv;
out_unlock:
map_unlock(&map);
* without thinking more */
for (d = sra->devs; d ; d = d->next) {
- char dn[10];
+ char dn[24]; // 2*11 bytes for ints (including sign) + colon + null byte
int dfd;
struct mdinfo info;
sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
static int count_active(struct supertype *st, struct mdinfo *sra,
int mdfd, char **availp,
- struct mdinfo *bestinfo,
- int *journal_device_missing)
+ struct mdinfo *bestinfo)
{
/* count how many devices in sra think they are active */
struct mdinfo *d;
int devnum;
int b, i;
int raid_disks = 0;
- int require_journal_dev = 0;
- int has_journal_dev = 0;
if (!sra)
return 0;
if (ok != 0)
continue;
- if (st->ss->require_journal) {
- require_journal_dev = st->ss->require_journal(st);
- if (require_journal_dev == 2) {
- pr_err("BUG: Superblock not loaded in Incremental.c:count_active\n");
- return 0;
- }
- }
-
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)
- has_journal_dev = 1;
+ bestinfo->journal_clean = 1;
if (!avail) {
raid_disks = info.array.raid_disks;
avail = xcalloc(raid_disks, 1);
st->ss->free_super(st);
}
- if (require_journal_dev && !has_journal_dev)
- *journal_device_missing = 1;
-
if (!avail)
return 0;
/* We need to reject any device that thinks the best device is
sizeof(target->uuid)) == 0 &&
sra->array.failed_disks > 0) {
/* This is our target!! */
- if (chosen)
- sysfs_free(chosen);
+ sysfs_free(chosen);
chosen = sra;
sra = NULL;
/* skip to end so we don't check any more */
sra = NULL;
}
next:
- if (sra)
- sysfs_free(sra);
+ sysfs_free(sra);
if (st != st2)
free(st2);
if (dl)
int mdfd = open_dev(chosen->sys_name);
if (mdfd >= 0) {
struct mddev_dev devlist;
- char devname[20];
+ char chosen_devname[24]; // 2*11 for int (including signs) + colon + null
devlist.next = NULL;
devlist.used = 0;
devlist.writemostly = 0;
- devlist.devname = devname;
- sprintf(devname, "%d:%d", major(stb.st_rdev),
+ devlist.devname = chosen_devname;
+ sprintf(chosen_devname, "%d:%d", major(stb.st_rdev),
minor(stb.st_rdev));
devlist.disposition = 'a';
close(dfd);