]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Monitor: link containers with subarrays in statelist
authorMarcin Labun <marcin.labun@intel.com>
Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:07 +0000 (20:58 +1100)
Each containers has list of its subarrays. Each subarray
has back link to its parent container.

Signed-off-by: Marcin Labun <marcin.labun@intel.com>
Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Monitor.c

index 54f26b19d66ef595504931ca9d902293752fec49..be8d5904d6addf7f51a3b554c640750ea7fdbb1a 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -50,6 +50,11 @@ struct state {
                         * For others, NoMdDev
                         */
        struct supertype *metadata;
+       struct state *subarray;/* for a container it is a link to first subarray
+                               * for a subarray it is a link to next subarray
+                               * in the same container */
+       struct state *parent;  /* for a subarray it is a link to its container
+                               */
        struct state *next;
 };
 
@@ -67,6 +72,7 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state *statelist,
 static void try_spare_migration(struct state *statelist,
                                char *mailaddr, char *mailfrom,
                                char *alert_cmd, int dosyslog);
+static void link_containers_with_subarrays(struct state *list);
 
 int Monitor(struct mddev_dev *devlist,
            char *mailaddr, char *alert_cmd,
@@ -680,6 +686,8 @@ static void try_spare_migration(struct state *statelist,
                                char *alert_cmd, int dosyslog)
 {
        struct state *st;
+
+       link_containers_with_subarrays(statelist);
        for (st = statelist; st; st=st->next)
                if (st->active < st->raid &&
                    st->spare == 0 &&
@@ -735,6 +743,34 @@ static void try_spare_migration(struct state *statelist,
                                }
                }
 }
+
+/* search the statelist to connect external
+ * metadata subarrays with their containers
+ * We always completely rebuild the tree from scratch as
+ * that is safest considering the possibility of entries
+ * disappearing or changing.
+ */
+static void link_containers_with_subarrays(struct state *list)
+{
+       struct state *st;
+       struct state *cont;
+       for (st = list; st; st = st->next) {
+               st->parent = NULL;
+               st->subarray = NULL;
+       }
+       for (st = list; st; st = st->next)
+               if (st->parent_dev != NoMdDev)
+                       for (cont = list; cont; cont = cont->next)
+                               if (!cont->err &&
+                                   cont->parent_dev == NoMdDev &&
+                                   cont->devnum == st->parent_dev) {
+                                       st->parent = cont;
+                                       st->subarray = cont->subarray;
+                                       cont->subarray = st;
+                                       break;
+                               }
+}
+
 /* Not really Monitor but ... */
 int Wait(char *dev)
 {