]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
incremental_container: preserve 'in_sync' flag when adding to existing array.
authorNeilBrown <neilb@suse.de>
Tue, 14 Apr 2009 00:19:02 +0000 (10:19 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 14 Apr 2009 00:19:02 +0000 (10:19 +1000)
When building container members with -IR, we need to ensure that
devices added to an active array preserve the 'in_sync' status so they
don't needlessly get rebuilt.

So allow sysfs_add_disk to do this (only works in kernels since
2.6.30) and pass the relevant flag down.

Signed-off-by: NeilBrown <neilb@suse.de>
Assemble.c
Manage.c
managemon.c
mdadm.h
sysfs.c
util.c

index 73d6ee231d9f466a99b2330bad7c8d7b3b393ce5..4cf5405890ea35306d8940691f97e60064bab0a1 100644 (file)
@@ -1228,7 +1228,7 @@ int assemble_container_content(struct supertype *st, int mdfd,
                sysfs_free(sra);
 
        for (dev = content->devs; dev; dev = dev->next)
-               if (sysfs_add_disk(content, dev) == 0)
+               if (sysfs_add_disk(content, dev, 1) == 0)
                        working++;
                else if (errno == EEXIST)
                        preexist++;
index 7afd89b7ce7b56c81aa6871ed8c149961cf02382..1f38fa54db91217af138eb528a448393eb26104a 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -702,7 +702,7 @@ int Manage_subdevs(char *devname, int fd,
                                tst->ss->getinfo_super(tst, &new_mdi);
                                new_mdi.disk.major = disc.major;
                                new_mdi.disk.minor = disc.minor;
-                               if (sysfs_add_disk(sra, &new_mdi) != 0) {
+                               if (sysfs_add_disk(sra, &new_mdi, 0) != 0) {
                                        fprintf(stderr, Name ": add new device to external metadata"
                                                " failed for %s\n", dv->devname);
                                        close(container_fd);
index e02c77ea964ef8fa6746ec05f06dc3835f312eb2..3835c995cfa8803ac135a005581ef0a6feb32d73 100644 (file)
@@ -395,7 +395,7 @@ static void manage_member(struct mdstat_ent *mdstat,
                         * and open files for each newdev */
                        for (d = newdev; d ; d = d->next) {
                                struct mdinfo *newd;
-                               if (sysfs_add_disk(&newa->info, d) < 0)
+                               if (sysfs_add_disk(&newa->info, d, 0) < 0)
                                        continue;
                                newd = malloc(sizeof(*newd));
                                *newd = *d;
diff --git a/mdadm.h b/mdadm.h
index 83a7944b58d13dade07035319bb9761ea08a8fee..357dc43313d93e52525d5609edcb72ac40a53740 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -373,7 +373,8 @@ extern int sysfs_get_str(struct mdinfo *sra, struct mdinfo *dev,
                         char *name, char *val, int size);
 extern int sysfs_set_safemode(struct mdinfo *sra, unsigned long ms);
 extern int sysfs_set_array(struct mdinfo *info, int vers);
-extern int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd);
+extern int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd,
+                         int in_sync);
 extern int sysfs_disk_to_scsi_id(int fd, __u32 *id);
 extern int sysfs_unique_holder(int devnum, long rdev);
 extern int load_sys(char *path, char *buf);
diff --git a/sysfs.c b/sysfs.c
index d4a1e495d5256a0abeef19d1256bb83d069dd922..711dce13e876d4befb41f0092c79422878776806 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -530,7 +530,7 @@ int sysfs_set_array(struct mdinfo *info, int vers)
        return rv;
 }
 
-int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd)
+int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int in_sync)
 {
        char dv[100];
        char nm[100];
@@ -556,8 +556,12 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd)
        rv = sysfs_set_num(sra, sd, "offset", sd->data_offset);
        rv |= sysfs_set_num(sra, sd, "size", (sd->component_size+1) / 2);
        if (sra->array.level != LEVEL_CONTAINER) {
+               if (in_sync)
+                       /* This can correctly fail if array isn't started,
+                        * yet, so just ignore status for now.
+                        */
+                       sysfs_set_str(sra, sd, "state", "in_sync");
                rv |= sysfs_set_num(sra, sd, "slot", sd->disk.raid_disk);
-//             rv |= sysfs_set_str(sra, sd, "state", "in_sync");
        }
        return rv;
 }
diff --git a/util.c b/util.c
index 02fc46339742c6058ae099d729f94728c20982f2..35bb91bb0d0b51c7a7541f8cba49197d14b87080 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1092,7 +1092,8 @@ int add_disk(int mdfd, struct supertype *st,
        int rv;
 #ifndef MDASSEMBLE
        if (st->ss->external) {
-               rv = sysfs_add_disk(sra, info);
+               rv = sysfs_add_disk(sra, info,
+                                   info->disk.state & (1<<MD_DISK_SYNC));
                if (! rv) {
                        struct mdinfo *sd2;
                        for (sd2 = sra->devs; sd2; sd2=sd2->next)