/* If this is an externally-managed array, we need to modify the
* metadata_version so that mdmon doesn't undo our change.
*/
- mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
+ mdi = sysfs_read(fd, NULL, GET_LEVEL|GET_VERSION);
if (mdi &&
mdi->array.major_version == -1 &&
is_subarray(mdi->text_version)) {
#ifndef MDASSEMBLE
-static void remove_devices(int devnum, char *path)
+static void remove_devices(char *devnm, char *path)
{
/*
* Remove names at 'path' - possibly with
* partition suffixes - which link to the 'standard'
- * name for devnum. These were probably created
+ * name for devnm. These were probably created
* by mdadm when the array was assembled.
*/
char base[40];
if (!path)
return;
- if (devnum >= 0)
- sprintf(base, "/dev/md%d", devnum);
- else
- sprintf(base, "/dev/md_d%d", -1-devnum);
+ sprintf(base, "/dev/%s", devnm);
be = base + strlen(base);
path2 = xmalloc(strlen(path)+20);
pr_err("started %s\n", devname);
} else if (runstop < 0){
struct map_ent *map = NULL;
- struct stat stb;
struct mdinfo *mdi;
- int devnum;
+ char devnm[32];
+ char container[32];
int err;
int count;
/* If this is an mdmon managed array, just write 'inactive'
* to the array state and let mdmon clear up.
*/
- devnum = fd2devnum(fd);
+ strcpy(devnm, fd2devnm(fd));
/* Get EXCL access first. If this fails, then attempting
* to stop is probably a bad idea.
*/
+ mdi = sysfs_read(fd, NULL, GET_LEVEL|GET_VERSION);
+ if (mdi && is_subarray(mdi->text_version)) {
+ char *sl;
+ strncpy(container, mdi->text_version+1, sizeof(container));
+ container[sizeof(container)-1] = 0;
+ sl = strchr(container, '/');
+ if (sl)
+ *sl = 0;
+ } else
+ container[0] = 0;
close(fd);
- fd = open(devname, O_RDONLY|O_EXCL);
- if (fd < 0 || fd2devnum(fd) != devnum) {
+ count = 5;
+ while (((fd = ((devnm[0] == '/')
+ ?open(devname, O_RDONLY|O_EXCL)
+ :open_dev_flags(devnm, O_RDONLY|O_EXCL))) < 0
+ || strcmp(fd2devnm(fd), devnm) != 0)
+ && container[0]
+ && mdmon_running(container)
+ && count) {
+ if (fd >= 0)
+ close(fd);
+ flush_mdmon(container);
+ count--;
+ }
+ if (fd < 0 || strcmp(fd2devnm(fd), devnm) != 0) {
if (fd >= 0)
close(fd);
if (verbose >= 0)
devname);
return 1;
}
- mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION);
if (mdi &&
mdi->array.level > 0 &&
is_subarray(mdi->text_version)) {
/* Give monitor a chance to act */
ping_monitor(mdi->text_version);
- fd = open_dev_excl(devnum);
+ fd = open_dev_excl(devnm);
if (fd < 0) {
if (verbose >= 0)
pr_err("failed to completely stop %s"
for (m = mds; m; m = m->next)
if (m->metadata_version &&
strncmp(m->metadata_version, "external:", 9)==0 &&
- is_subarray(m->metadata_version+9) &&
- devname2devnum(m->metadata_version+10) == devnum) {
+ metadata_container_matches(m->metadata_version+9,
+ devnm)) {
if (verbose >= 0)
pr_err("Cannot stop container %s: "
"member %s still active\n",
if (mdi)
sysfs_uevent(mdi, "change");
- if (devnum != NoMdDev &&
- (stat("/dev/.udev", &stb) != 0 ||
- check_env("MDADM_NO_UDEV"))) {
- struct map_ent *mp = map_by_devnum(&map, devnum);
- remove_devices(devnum, mp ? mp->path : NULL);
+ if (devnm[0] && use_udev()) {
+ struct map_ent *mp = map_by_devnm(&map, devnm);
+ remove_devices(devnm, mp ? mp->path : NULL);
}
if (verbose >= 0)
pr_err("stopped %s\n", devname);
map_lock(&map);
- map_remove(&map, devnum);
+ map_remove(&map, devnm);
map_unlock(&map);
out:
if (mdi)
return rv;
}
+static struct mddev_dev *add_one(struct mddev_dev *dv, char *name, char disp)
+{
+ struct mddev_dev *new;
+ new = xmalloc(sizeof(*new));
+ memset(new, 0, sizeof(*new));
+ new->devname = xstrdup(name);
+ new->disposition = disp;
+ new->next = dv->next;
+ dv->next = new;
+ return new;
+}
+
static void add_faulty(struct mddev_dev *dv, int fd, char disp)
{
mdu_array_info_t array;
remaining_disks = array.nr_disks;
for (i = 0; i < MAX_DISKS && remaining_disks > 0; i++) {
- struct mddev_dev *new;
char buf[40];
disk.number = i;
if (ioctl(fd, GET_DISK_INFO, &disk) != 0)
if ((disk.state & 1) == 0) /* not faulty */
continue;
sprintf(buf, "%d:%d", disk.major, disk.minor);
- new = xmalloc(sizeof(*new));
- new->devname = xstrdup(buf);
- new->disposition = disp;
- new->next = dv->next;
- dv->next = new;
- dv = new;
+ dv = add_one(dv, buf, disp);
}
}
remaining_disks = array.nr_disks;
for (i = 0; i < MAX_DISKS && remaining_disks > 0; i++) {
- struct mddev_dev *new;
char buf[40];
int sfd;
disk.number = i;
if (errno != ENXIO)
/* Probably not detached */
continue;
- new = xmalloc(sizeof(*new));
- new->devname = xstrdup(buf);
- new->disposition = disp;
- new->next = dv->next;
- dv->next = new;
- dv = new;
+ dv = add_one(dv, buf, disp);
+ }
+}
+
+static void add_set(struct mddev_dev *dv, int fd, char set_char)
+{
+ mdu_array_info_t array;
+ mdu_disk_info_t disk;
+ int remaining_disks;
+ int copies, set;
+ int i;
+
+ if (ioctl(fd, GET_ARRAY_INFO, &array) != 0)
+ return;
+ if (array.level != 10)
+ return;
+ copies = ((array.layout & 0xff) *
+ ((array.layout >> 8) & 0xff));
+ if (array.raid_disks % copies)
+ return;
+
+ remaining_disks = array.nr_disks;
+ for (i = 0; i < MAX_DISKS && remaining_disks > 0; i++) {
+ char buf[40];
+ disk.number = i;
+ if (ioctl(fd, GET_DISK_INFO, &disk) != 0)
+ continue;
+ if (disk.major == 0 && disk.minor == 0)
+ continue;
+ remaining_disks--;
+ set = disk.raid_disk % copies;
+ if (set_char != set + 'A')
+ continue;
+ sprintf(buf, "%d:%d", disk.major, disk.minor);
+ dv = add_one(dv, buf, dv->disposition);
}
}
struct mdinfo new_mdi;
struct mdinfo *sra;
int container_fd;
- int devnum = fd2devnum(fd);
+ char devnm[32];
int dfd;
- container_fd = open_dev_excl(devnum);
+ strcpy(devnm, fd2devnm(fd));
+
+ container_fd = open_dev_excl(devnm);
if (container_fd < 0) {
pr_err("add failed for %s:"
" could not get exclusive access to container\n",
Kill(dv->devname, NULL, 0, -1, 0);
dfd = dev_open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
- if (mdmon_running(tst->container_dev))
+ if (mdmon_running(tst->container_devnm))
tst->update_tail = &tst->updates;
if (tst->ss->add_to_super(tst, &disc, dfd,
dv->devname, INVALID_SECTORS)) {
else
tst->ss->sync_metadata(tst);
- sra = sysfs_read(container_fd, -1, 0);
+ sra = sysfs_read(container_fd, NULL, 0);
if (!sra) {
pr_err("add failed for %s: sysfs_read failed\n",
dv->devname);
sysfs_free(sra);
return -1;
}
- ping_monitor_by_id(devnum);
+ ping_monitor(devnm);
sysfs_free(sra);
close(container_fd);
} else {
* get an O_EXCL open on the container
*/
int ret;
- int dnum = fd2devnum(fd);
- lfd = open_dev_excl(dnum);
+ char devnm[32];
+ strcpy(devnm, fd2devnm(fd));
+ lfd = open_dev_excl(devnm);
if (lfd < 0) {
pr_err("Cannot get exclusive access "
" to container - odd\n");
if (rdev == 0)
ret = -1;
else
- ret = sysfs_unique_holder(dnum, rdev);
+ ret = sysfs_unique_holder(devnm, rdev);
if (ret == 0) {
pr_err("%s is not a member, cannot remove.\n",
dv->devname);
if (err && errno == ENODEV) {
/* Old kernels rejected this if no personality
* is registered */
- struct mdinfo *sra = sysfs_read(fd, 0, GET_DEVS);
+ struct mdinfo *sra = sysfs_read(fd, NULL, GET_DEVS);
struct mdinfo *dv = NULL;
if (sra)
dv = sra->devs;
* 'add' event before reconciling this 'remove'
* event.
*/
- char *name = devnum2devname(fd2devnum(fd));
+ char *devnm = fd2devnm(fd);
- if (!name) {
+ if (!devnm) {
pr_err("unable to get container name\n");
return -1;
}
- ping_manager(name);
- free(name);
+ ping_manager(devnm);
}
if (lfd >= 0)
close(lfd);
/* Need to find the device in sysfs and add 'want_replacement' to the
* status.
*/
- mdi = sysfs_read(fd, -1, GET_DEVS);
+ mdi = sysfs_read(fd, NULL, GET_DEVS);
if (!mdi || !mdi->devs) {
pr_err("Cannot find status of %s to enable replacement - strange\n",
devname);
{
struct mdinfo *mdi, *di;
/* try to set 'slot' for 'rdev' in 'fd' to 'dv->used' */
- mdi = sysfs_read(fd, -1, GET_DEVS|GET_STATE);
+ mdi = sysfs_read(fd, NULL, GET_DEVS|GET_STATE);
if (!mdi || !mdi->devs) {
pr_err("Cannot find status of %s to enable replacement - strange\n",
devname);
* it must be unpaired, and is an error.
* 'M' - this is created by a 'missing' target. It is a slight
* variant on 'A'
+ * 'F' - Another variant of 'A', where the device was faulty
+ * so must be removed from the array first.
*
* For 'f' and 'r', the device can also be a kernel-internal
* name such as 'sdb'.
int count = 0; /* number of actions taken */
struct mdinfo info;
int frozen = 0;
+ int busy = 0;
if (ioctl(fd, GET_ARRAY_INFO, &array)) {
pr_err("Cannot get array info for %s\n",
devname);
goto abort;
}
- sysfs_init(&info, fd, 0);
+ sysfs_init(&info, fd, NULL);
/* array.size is only 32 bits and may be truncated.
* So read from sysfs if possible, and record number of sectors
if (strcmp(dv->devname, "failed") == 0 ||
strcmp(dv->devname, "faulty") == 0) {
- if (dv->disposition != 'r') {
+ if (dv->disposition != 'A'
+ && dv->disposition != 'r') {
pr_err("%s only meaningful "
- "with -r, not -%c\n",
+ "with -r or --re-add, not -%c\n",
dv->devname, dv->disposition);
goto abort;
}
- add_faulty(dv, fd, 'r');
+ add_faulty(dv, fd, (dv->disposition == 'A'
+ ? 'F' : 'r'));
continue;
}
if (strcmp(dv->devname, "detached") == 0) {
continue;
}
+ if (strncmp(dv->devname, "set-", 4) == 0 &&
+ strlen(dv->devname) == 5) {
+ int copies;
+
+ if (dv->disposition != 'r' &&
+ dv->disposition != 'f') {
+ pr_err("'%s' only meaningful with -r or -f\n",
+ dv->devname);
+ goto abort;
+ }
+ if (array.level != 10) {
+ pr_err("'%s' only meaningful with RAID10 arrays\n",
+ dv->devname);
+ goto abort;
+ }
+ copies = ((array.layout & 0xff) *
+ ((array.layout >> 8) & 0xff));
+ if (array.raid_disks % copies != 0 ||
+ dv->devname[4] < 'A' ||
+ dv->devname[4] >= 'A' + copies ||
+ copies > 26) {
+ pr_err("'%s' not meaningful with this array\n",
+ dv->devname);
+ goto abort;
+ }
+ add_set(dv, fd, dv->devname[4]);
+ continue;
+ }
+
if (strchr(dv->devname, '/') == NULL &&
strchr(dv->devname, ':') == NULL &&
strlen(dv->devname) < 50) {
}
sprintf(dname, "dev-%s", dv->devname);
- sysfd = sysfs_open(fd2devnum(fd), dname, "block/dev");
+ sysfd = sysfs_open(fd2devnm(fd), dname, "block/dev");
if (sysfd >= 0) {
char dn[20];
int mj,mn;
sysfd = -1;
}
if (!found) {
- sysfd = sysfs_open(fd2devnum(fd), dname, "state");
+ sysfd = sysfs_open(fd2devnm(fd), dname, "state");
if (sysfd < 0) {
pr_err("%s does not appear "
"to be a component of %s\n",
goto abort;
case 'a':
case 'A':
- case 'M':
+ case 'M': /* --re-add missing */
+ case 'F': /* --re-add faulty */
/* add the device */
if (subarray) {
pr_err("Cannot add disks to a"
" operation on the parent container\n");
goto abort;
}
+ if (dv->disposition == 'F')
+ /* Need to remove first */
+ ioctl(fd, HOT_REMOVE_DISK,
+ (unsigned long)stb.st_rdev);
/* Make sure it isn't in use (in 2.6 or later) */
tfd = dev_open(dv->devname, O_RDONLY|O_EXCL);
if (tfd >= 0) {
if ((sysfd >= 0 && write(sysfd, "faulty", 6) != 6) ||
(sysfd < 0 && ioctl(fd, SET_DISK_FAULTY,
(unsigned long) stb.st_rdev))) {
+ if (errno == EBUSY)
+ busy = 1;
pr_err("set device faulty failed for %s: %s\n",
dv->devname, strerror(errno));
if (sysfd >= 0)
abort:
if (frozen > 0)
sysfs_set_str(&info, NULL, "sync_action","idle");
- return 1;
+ return !test && busy ? 2 : 1;
}
int autodetect(void)
goto free_super;
}
- if (mdmon_running(st->devnum))
+ if (mdmon_running(st->devnm))
st->update_tail = &st->updates;
rv = st->ss->update_subarray(st, subarray, update, ident);