sysfs: detect disks that are in the process of being removed
When removing a disk there is a window where the 'slot' attribute of md/dev-$name will return -EBUSY to read attempts. When this happens look at the the 'block' link, if it is removed then we can be sure the device has been removed, versus some other error. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
parent
4065aa816a
commit
4795982e68
29
sysfs.c
29
sysfs.c
|
@ -238,14 +238,33 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
|
||||||
dev = malloc(sizeof(*dev));
|
dev = malloc(sizeof(*dev));
|
||||||
if (!dev)
|
if (!dev)
|
||||||
goto abort;
|
goto abort;
|
||||||
dev->next = sra->devs;
|
|
||||||
sra->devs = dev;
|
|
||||||
strcpy(dev->sys_name, de->d_name);
|
|
||||||
|
|
||||||
/* Always get slot, major, minor */
|
/* Always get slot, major, minor */
|
||||||
strcpy(dbase, "slot");
|
strcpy(dbase, "slot");
|
||||||
if (load_sys(fname, buf))
|
if (load_sys(fname, buf)) {
|
||||||
goto abort;
|
/* hmm... unable to read 'slot' maybe the device
|
||||||
|
* is going away?
|
||||||
|
*/
|
||||||
|
strcpy(dbase, "block");
|
||||||
|
if (readlink(fname, buf, sizeof(buf)) < 0 &&
|
||||||
|
errno != ENAMETOOLONG) {
|
||||||
|
/* ...yup device is gone */
|
||||||
|
free(dev);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
/* slot is unreadable but 'block' link
|
||||||
|
* still intact... something bad is happening
|
||||||
|
* so abort
|
||||||
|
*/
|
||||||
|
free(dev);
|
||||||
|
goto abort;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
dev->next = sra->devs;
|
||||||
|
sra->devs = dev;
|
||||||
|
|
||||||
|
strcpy(dev->sys_name, de->d_name);
|
||||||
dev->disk.raid_disk = strtoul(buf, &ep, 10);
|
dev->disk.raid_disk = strtoul(buf, &ep, 10);
|
||||||
if (*ep) dev->disk.raid_disk = -1;
|
if (*ep) dev->disk.raid_disk = -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue