]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
sysfs_read: return devices in same order as in filesystem.
authorNeilBrown <neilb@suse.de>
Wed, 19 Jun 2013 00:33:47 +0000 (10:33 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 19 Jun 2013 00:33:47 +0000 (10:33 +1000)
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>
sysfs.c

diff --git a/sysfs.c b/sysfs.c
index 6bc28651fd4f8f81c582eb4d5e98b4de80cdc90a..cb25a413a1dfc28926b05fad8e8db08dd601e51f 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -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");