sysfs_read: return devices in same order as in filesystem.

When we read devices from sysfs (../md/dev-*), store them in the same
order that they appear.  That makes more sense when exposed to a
human (as the next patch will).

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2013-06-19 10:33:47 +10:00
parent 2161adce8f
commit 64e103fe19
1 changed files with 7 additions and 4 deletions

11
sysfs.c
View File

@ -96,7 +96,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
char *base;
char *dbase;
struct mdinfo *sra;
struct mdinfo *dev;
struct mdinfo *dev, **devp;
DIR *dir = NULL;
struct dirent *de;
@ -235,6 +235,8 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
goto abort;
sra->array.spare_disks = 0;
devp = &sra->devs;
sra->devs = NULL;
while ((de = readdir(dir)) != NULL) {
char *ep;
if (de->d_ino == 0 ||
@ -266,7 +268,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
free(dev);
goto abort;
}
}
strcpy(dev->sys_name, de->d_name);
dev->disk.raid_disk = strtoul(buf, &ep, 10);
@ -292,8 +294,9 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
}
/* finally add this disk to the array */
dev->next = sra->devs;
sra->devs = dev;
*devp = dev;
devp = & dev->next;
dev->next = NULL;
if (options & GET_OFFSET) {
strcpy(dbase, "offset");