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:
Dan Williams 2008-09-15 20:58:43 -07:00
parent 4065aa816a
commit 4795982e68
1 changed files with 24 additions and 5 deletions

29
sysfs.c
View File

@ -238,14 +238,33 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
dev = malloc(sizeof(*dev));
if (!dev)
goto abort;
dev->next = sra->devs;
sra->devs = dev;
strcpy(dev->sys_name, de->d_name);
/* Always get slot, major, minor */
strcpy(dbase, "slot");
if (load_sys(fname, buf))
goto abort;
if (load_sys(fname, buf)) {
/* 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);
if (*ep) dev->disk.raid_disk = -1;