Use 'mdinfo' instead of special 'sysdev' structure.
authorNeil Brown <neilb@suse.de>
Fri, 14 Dec 2007 09:14:57 +0000 (20:14 +1100)
committerNeil Brown <neilb@suse.de>
Fri, 14 Dec 2007 09:14:57 +0000 (20:14 +1100)
there is needless duplicatiion between mdinfo and sysdev, so discard
the latter.

Create.c
Grow.c
Incremental.c
mdadm.h
sysfs.c

index 6cf509a..b7a3f7d 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -70,11 +70,11 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        int rv;
        int bitmap_fd;
        unsigned long long bitmapsize;
+       struct mdinfo info;
 
-       mdu_array_info_t array;
        int major_num = BITMAP_MAJOR_HI;
 
-       memset(&array, 0, sizeof(array));
+       memset(&info, 0, sizeof(info));
 
        vers = md_get_version(mdfd);
        if (vers < 9000) {
@@ -193,8 +193,8 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        }
 
        /* now look at the subdevs */
-       array.active_disks = 0;
-       array.working_disks = 0;
+       info.array.active_disks = 0;
+       info.array.working_disks = 0;
        dnum = 0;
        for (dv=devlist; dv; dv=dv->next, dnum++) {
                char *dname = dv->devname;
@@ -206,9 +206,9 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                        missing_disks ++;
                        continue;
                }
-               array.working_disks++;
+               info.array.working_disks++;
                if (dnum < raiddisks)
-                       array.active_disks++;
+                       info.array.active_disks++;
                fd = open(dname, O_RDONLY|O_EXCL, 0);
                if (fd <0 ) {
                        fprintf(stderr, Name ": Cannot open %s: %s\n",
@@ -334,7 +334,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                case 5:
                        insert_point = raiddisks-1;
                        sparedisks++;
-                       array.active_disks--;
+                       info.array.active_disks--;
                        missing_disks++;
                        break;
                default:
@@ -350,16 +350,16 @@ int Create(struct supertype *st, char *mddev, int mdfd,
 
        /* Ok, lets try some ioctls */
 
-       array.level = level;
-       array.size = size;
-       array.raid_disks = raiddisks;
+       info.array.level = level;
+       info.array.size = size;
+       info.array.raid_disks = raiddisks;
        /* The kernel should *know* what md_minor we are dealing
         * with, but it chooses to trust me instead. Sigh
         */
-       array.md_minor = 0;
+       info.array.md_minor = 0;
        if (fstat(mdfd, &stb)==0)
-               array.md_minor = minor(stb.st_rdev);
-       array.not_persistent = 0;
+               info.array.md_minor = minor(stb.st_rdev);
+       info.array.not_persistent = 0;
        /*** FIX: Need to do something about RAID-6 here ***/
        if ( ( (level == 4 || level == 5) &&
               (insert_point < raiddisks || first_missing < raiddisks) )
@@ -368,9 +368,9 @@ int Create(struct supertype *st, char *mddev, int mdfd,
             ||
             assume_clean
                )
-               array.state = 1; /* clean, but one+ drive will be missing */
+               info.array.state = 1; /* clean, but one+ drive will be missing*/
        else
-               array.state = 0; /* not clean, but no errors */
+               info.array.state = 0; /* not clean, but no errors */
 
        if (level == 10) {
                /* for raid10, the bitmap size is the capacity of the array,
@@ -402,12 +402,13 @@ int Create(struct supertype *st, char *mddev, int mdfd,
         * So for now, we assume that all raid and spare
         * devices will be given.
         */
-       array.spare_disks=sparedisks;
-       array.failed_disks=missing_disks;
-       array.nr_disks = array.working_disks + array.failed_disks;
-       array.layout = layout;
-       array.chunk_size = chunk*1024;
-       array.major_version = st->ss->major;
+       info.array.spare_disks=sparedisks;
+       info.array.failed_disks=missing_disks;
+       info.array.nr_disks = info.array.working_disks
+               + info.array.failed_disks;
+       info.array.layout = layout;
+       info.array.chunk_size = chunk*1024;
+       info.array.major_version = st->ss->major;
 
        if (name == NULL || *name == 0) {
                /* base name on mddev */
@@ -433,7 +434,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                                name += 2;
                }
        }
-       if (!st->ss->init_super(st, &array, size, name, homehost, uuid))
+       if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid))
                return 1;
 
        if (bitmap_file && vers < 9003) {
@@ -506,26 +507,25 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                     dv=(dv->next)?(dv->next):moved_disk, dnum++) {
                        int fd;
                        struct stat stb;
-                       mdu_disk_info_t disk;
 
-                       disk.number = dnum;
+                       info.disk.number = dnum;
                        if (dnum == insert_point) {
                                moved_disk = dv;
                        }
-                       disk.raid_disk = disk.number;
-                       if (disk.raid_disk < raiddisks)
-                               disk.state = (1<<MD_DISK_ACTIVE) |
+                       info.disk.raid_disk = info.disk.number;
+                       if (info.disk.raid_disk < raiddisks)
+                               info.disk.state = (1<<MD_DISK_ACTIVE) |
                                                (1<<MD_DISK_SYNC);
                        else
-                               disk.state = 0;
+                               info.disk.state = 0;
                        if (dv->writemostly)
-                               disk.state |= (1<<MD_DISK_WRITEMOSTLY);
+                               info.disk.state |= (1<<MD_DISK_WRITEMOSTLY);
 
                        if (dnum == insert_point ||
                            strcasecmp(dv->devname, "missing")==0) {
-                               disk.major = 0;
-                               disk.minor = 0;
-                               disk.state = (1<<MD_DISK_FAULTY);
+                               info.disk.major = 0;
+                               info.disk.minor = 0;
+                               info.disk.state = (1<<MD_DISK_FAULTY);
                        } else {
                                fd = open(dv->devname, O_RDONLY|O_EXCL, 0);
                                if (fd < 0) {
@@ -534,23 +534,23 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                                        return 1;
                                }
                                fstat(fd, &stb);
-                               disk.major = major(stb.st_rdev);
-                               disk.minor = minor(stb.st_rdev);
+                               info.disk.major = major(stb.st_rdev);
+                               info.disk.minor = minor(stb.st_rdev);
                                remove_partitions(fd);
                                close(fd);
                        }
                        switch(pass){
                        case 1:
-                               st->ss->add_to_super(st, &disk);
+                               st->ss->add_to_super(st, &info.disk);
                                break;
                        case 2:
-                               if (disk.state == 1) break;
+                               if (info.disk.state == 1) break;
                                Kill(dv->devname, 0, 1); /* Just be sure it is clean */
                                Kill(dv->devname, 0, 1); /* and again, there could be two superblocks */
-                               st->ss->write_init_super(st, &disk,
+                               st->ss->write_init_super(st, &info.disk,
                                                         dv->devname);
 
-                               if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
+                               if (ioctl(mdfd, ADD_NEW_DISK, &info.disk)) {
                                        fprintf(stderr, Name ": ADD_NEW_DISK for %s failed: %s\n",
                                                dv->devname, strerror(errno));
                                        st->ss->free_super(st);
diff --git a/Grow.c b/Grow.c
index 3c22741..c02ff80 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -436,7 +436,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
        int err;
 
        struct sysarray *sra;
-       struct sysdev *sd;
+       struct mdinfo *sd;
 
        if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) {
                fprintf(stderr, Name ": %s is not an active md array - aborting\n",
@@ -650,22 +650,25 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                        fdlist[d] = -1;
                d = array.raid_disks;
                for (sd = sra->devs; sd; sd=sd->next) {
-                       if (sd->state & (1<<MD_DISK_FAULTY))
+                       if (sd->disk.state & (1<<MD_DISK_FAULTY))
                                continue;
-                       if (sd->state & (1<<MD_DISK_SYNC)) {
-                               char *dn = map_dev(sd->major, sd->minor, 1);
-                               fdlist[sd->role] = dev_open(dn, O_RDONLY);
-                               offsets[sd->role] = sd->offset;
-                               if (fdlist[sd->role] < 0) {
+                       if (sd->disk.state & (1<<MD_DISK_SYNC)) {
+                               char *dn = map_dev(sd->disk.major,
+                                                  sd->disk.minor, 1);
+                               fdlist[sd->disk.raid_disk]
+                                       = dev_open(dn, O_RDONLY);
+                               offsets[sd->disk.raid_disk] = sd->data_offset;
+                               if (fdlist[sd->disk.raid_disk] < 0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
                                                devname, dn?dn:"-unknown-");
                                        goto abort;
                                }
                        } else {
                                /* spare */
-                               char *dn = map_dev(sd->major, sd->minor, 1);
+                               char *dn = map_dev(sd->disk.major,
+                                                  sd->disk.minor, 1);
                                fdlist[d] = dev_open(dn, O_RDWR);
-                               offsets[d] = sd->offset;
+                               offsets[d] = sd->data_offset;
                                if (fdlist[d]<0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
                                                devname, dn?dn:"-unknown");
index d3ab72f..df5314d 100644 (file)
@@ -306,7 +306,7 @@ int Incremental(char *devname, int verbose, int runstop,
                        return 2;
                }
                sra = sysfs_read(mdfd, devnum, GET_DEVS);
-               if (!sra || !sra->devs || sra->devs->role >= 0) {
+               if (!sra || !sra->devs || sra->devs->disk.raid_disk >= 0) {
                        /* It really should be 'none' - must be old buggy
                         * kernel, and mdadm -I may not be able to complete.
                         * So reject it.
@@ -343,7 +343,8 @@ int Incremental(char *devname, int verbose, int runstop,
                        close(mdfd);
                        return 1;
                }
-               sprintf(dn, "%d:%d", sra->devs->major, sra->devs->minor);
+               sprintf(dn, "%d:%d", sra->devs->disk.major,
+                       sra->devs->disk.minor);
                dfd2 = dev_open(dn, O_RDONLY);
                st2 = dup_super(st);
                if (st2->ss->load_super(st2, dfd2, NULL)) {
@@ -483,7 +484,7 @@ static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
        /* Find a device attached to this array with a disk.number of number
         * and events less than the passed events, and remove the device.
         */
-       struct sysdev *d;
+       struct mdinfo *d;
        mdu_array_info_t ra;
 
        if (ioctl(mdfd, GET_ARRAY_INFO, &ra) == 0)
@@ -494,7 +495,7 @@ static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
                char dn[10];
                int dfd;
                struct mdinfo info;
-               sprintf(dn, "%d:%d", d->major, d->minor);
+               sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
                dfd = dev_open(dn, O_RDONLY);
                if (dfd < 0)
                        continue;
@@ -510,13 +511,13 @@ static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
                    info.events >= events)
                        continue;
 
-               if (d->role > -1)
+               if (d->disk.raid_disk > -1)
                        sysfs_set_str(sra, d, "slot", "none");
                if (sysfs_set_str(sra, d, "state", "remove") == 0)
                        if (verbose >= 0)
                                fprintf(stderr, Name
                                        ": removing old device %s from %s\n",
-                                       d->name+4, array_name);
+                                       d->sys_name+4, array_name);
        }
 }
 
@@ -524,7 +525,7 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
                        struct mdinfo *bestinfo)
 {
        /* count how many devices in sra think they are active */
-       struct sysdev *d;
+       struct mdinfo *d;
        int cnt = 0, cnt1 = 0;
        __u64 max_events = 0;
        struct sysarray *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
@@ -536,7 +537,7 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
                int ok;
                struct mdinfo info;
 
-               sprintf(dn, "%d:%d", d->major, d->minor);
+               sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
                dfd = dev_open(dn, O_RDONLY);
                if (dfd < 0)
                        continue;
@@ -595,7 +596,7 @@ void RebuildMap(void)
 
        for (md = mdstat ; md ; md = md->next) {
                struct sysarray *sra = sysfs_read(-1, md->devnum, GET_DEVS);
-               struct sysdev *sd;
+               struct mdinfo *sd;
 
                for (sd = sra->devs ; sd ; sd = sd->next) {
                        char dn[30];
@@ -605,7 +606,7 @@ void RebuildMap(void)
                        char *path;
                        struct mdinfo info;
 
-                       sprintf(dn, "%d:%d", sd->major, sd->minor);
+                       sprintf(dn, "%d:%d", sd->disk.major, sd->disk.minor);
                        dfd = dev_open(dn, O_RDONLY);
                        if (dfd < 0)
                                continue;
diff --git a/mdadm.h b/mdadm.h
index a001e9f..483a072 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -131,6 +131,10 @@ struct mdinfo {
        int                     reshape_active;
        unsigned long long      reshape_progress;
        int                     new_level, delta_disks, new_layout, new_chunk;
+       int                     errors;
+
+       char            sys_name[20];
+       struct mdinfo *next;
 };
 
 struct createinfo {
@@ -268,19 +272,9 @@ extern void map_free(struct map_ent *map);
 extern void map_add(struct map_ent **melp,
                    int devnum, int major, int minor, int uuid[4], char *path);
 
-/* Data structure for holding info read from sysfs */
-struct sysdev {
-       char    name[20];
-       int     role;
-       int     major, minor;
-       unsigned long long offset, size;
-       int     state;
-       int     errors;
-       struct sysdev *next;
-};
 struct sysarray {
        char    name[20];
-       struct sysdev *devs;
+       struct mdinfo *devs;
        int     chunk;
        unsigned long long component_size;
        int     layout;
@@ -310,11 +304,11 @@ struct sysarray {
  */
 extern void sysfs_free(struct sysarray *sra);
 extern struct sysarray *sysfs_read(int fd, int devnum, unsigned long options);
-extern int sysfs_set_str(struct sysarray *sra, struct sysdev *dev,
+extern int sysfs_set_str(struct sysarray *sra, struct mdinfo *dev,
                         char *name, char *val);
-extern int sysfs_set_num(struct sysarray *sra, struct sysdev *dev,
+extern int sysfs_set_num(struct sysarray *sra, struct mdinfo *dev,
                         char *name, unsigned long long val);
-extern int sysfs_get_ll(struct sysarray *sra, struct sysdev *dev,
+extern int sysfs_get_ll(struct sysarray *sra, struct mdinfo *dev,
                        char *name, unsigned long long *val);
 
 
diff --git a/sysfs.c b/sysfs.c
index 1dbc680..970d211 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -47,7 +47,7 @@ void sysfs_free(struct sysarray *sra)
        if (!sra)
                return;
        while (sra->devs) {
-               struct sysdev *d = sra->devs;
+               struct mdinfo *d = sra->devs;
                sra->devs = d->next;
                free(d);
        }
@@ -66,7 +66,7 @@ struct sysarray *sysfs_read(int fd, int devnum, unsigned long options)
        char *base;
        char *dbase;
        struct sysarray *sra;
-       struct sysdev *dev;
+       struct mdinfo *dev;
        DIR *dir;
        struct dirent *de;
 
@@ -169,42 +169,42 @@ struct sysarray *sysfs_read(int fd, int devnum, unsigned long options)
                        goto abort;
                dev->next = sra->devs;
                sra->devs = dev;
-               strcpy(dev->name, de->d_name);
+               strcpy(dev->sys_name, de->d_name);
 
                /* Always get slot, major, minor */
                strcpy(dbase, "slot");
                if (load_sys(fname, buf))
                        goto abort;
-               dev->role = strtoul(buf, &ep, 10);
-               if (*ep) dev->role = -1;
+               dev->disk.raid_disk = strtoul(buf, &ep, 10);
+               if (*ep) dev->disk.raid_disk = -1;
 
                strcpy(dbase, "block/dev");
                if (load_sys(fname, buf))
                        goto abort;
-               sscanf(buf, "%d:%d", &dev->major, &dev->minor);
+               sscanf(buf, "%d:%d", &dev->disk.major, &dev->disk.minor);
 
                if (options & GET_OFFSET) {
                        strcpy(dbase, "offset");
                        if (load_sys(fname, buf))
                                goto abort;
-                       dev->offset = strtoull(buf, NULL, 0);
+                       dev->data_offset = strtoull(buf, NULL, 0);
                }
                if (options & GET_SIZE) {
                        strcpy(dbase, "size");
                        if (load_sys(fname, buf))
                                goto abort;
-                       dev->size = strtoull(buf, NULL, 0);
+                       dev->component_size = strtoull(buf, NULL, 0);
                }
                if (options & GET_STATE) {
-                       dev->state = 0;
+                       dev->disk.state = 0;
                        strcpy(dbase, "state");
                        if (load_sys(fname, buf))
                                goto abort;
                        if (strstr(buf, "in_sync"))
-                               dev->state |= (1<<MD_DISK_SYNC);
+                               dev->disk.state |= (1<<MD_DISK_SYNC);
                        if (strstr(buf, "faulty"))
-                               dev->state |= (1<<MD_DISK_FAULTY);
-                       if (dev->state == 0)
+                               dev->disk.state |= (1<<MD_DISK_FAULTY);
+                       if (dev->disk.state == 0)
                                sra->spares++;
                }
                if (options & GET_ERROR) {
@@ -251,14 +251,14 @@ unsigned long long get_component_size(int fd)
        return strtoull(fname, NULL, 10) * 2;
 }
 
-int sysfs_set_str(struct sysarray *sra, struct sysdev *dev,
+int sysfs_set_str(struct sysarray *sra, struct mdinfo *dev,
                  char *name, char *val)
 {
        char fname[50];
        int n;
        int fd;
        sprintf(fname, "/sys/block/%s/md/%s/%s",
-               sra->name, dev?dev->name:"", name);
+               sra->name, dev?dev->sys_name:"", name);
        fd = open(fname, O_WRONLY);
        if (fd < 0)
                return -1;
@@ -269,7 +269,7 @@ int sysfs_set_str(struct sysarray *sra, struct sysdev *dev,
        return 0;
 }
 
-int sysfs_set_num(struct sysarray *sra, struct sysdev *dev,
+int sysfs_set_num(struct sysarray *sra, struct mdinfo *dev,
                  char *name, unsigned long long val)
 {
        char valstr[50];
@@ -277,7 +277,7 @@ int sysfs_set_num(struct sysarray *sra, struct sysdev *dev,
        return sysfs_set_str(sra, dev, name, valstr);
 }
 
-int sysfs_get_ll(struct sysarray *sra, struct sysdev *dev,
+int sysfs_get_ll(struct sysarray *sra, struct mdinfo *dev,
                       char *name, unsigned long long *val)
 {
        char fname[50];
@@ -286,7 +286,7 @@ int sysfs_get_ll(struct sysarray *sra, struct sysdev *dev,
        int fd;
        char *ep;
        sprintf(fname, "/sys/block/%s/md/%s/%s",
-               sra->name, dev?dev->name:"", name);
+               sra->name, dev?dev->sys_name:"", name);
        fd = open(fname, O_RDONLY);
        if (fd < 0)
                return -1;