]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
imsm: fix activate_spare off-by-one
[thirdparty/mdadm.git] / managemon.c
index 5f0a61b5ce106f56d44404ae08b7347f29a1a36f..f9d545d46fbac9142c06f1ea540896a78980e01d 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * mdmon - monitor external metadata arrays
  *
- * Copyright (C) 2007-2008 Neil Brown <neilb@suse.de>
- * Copyright (C) 2007-2008 Intel Corporation
+ * Copyright (C) 2007-2009 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2007-2009 Intel Corporation
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -241,7 +241,9 @@ static void add_disk_to_container(struct supertype *st, struct mdinfo *sd)
 {
        int dfd;
        char nm[20];
+       struct supertype *st2;
        struct metadata_update *update = NULL;
+       struct mdinfo info;
        mdu_disk_info_t dk = {
                .number = -1,
                .major = sd->disk.major,
@@ -261,6 +263,25 @@ static void add_disk_to_container(struct supertype *st, struct mdinfo *sd)
        if (dfd < 0)
                return;
 
+       /* Check the metadata and see if it is already part of this
+        * array
+        */
+       st2 = dup_super(st);
+       if (st2->ss->load_super(st2, dfd, NULL) == 0) {
+               st2->ss->getinfo_super(st, &info);
+               if (st->ss->compare_super(st, st2) == 0 &&
+                   info.disk.raid_disk >= 0) {
+                       /* Looks like a good member of array.
+                        * Just accept it.
+                        * mdadm will incorporate any parts into
+                        * active arrays.
+                        */
+                       st2->ss->free_super(st2);
+                       return;
+               }
+       }
+       st2->ss->free_super(st2);
+
        st->update_tail = &update;
        st->ss->add_to_super(st, &dk, dfd, NULL);
        st->ss->write_init_super(st);
@@ -374,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;