From c3621c0a5fe2344681388cf0439bdf978736d2a6 Mon Sep 17 00:00:00 2001 From: Marcin Labun Date: Mon, 22 Nov 2010 20:58:07 +1100 Subject: [PATCH] Monitor: link containers with subarrays in statelist Each containers has list of its subarrays. Each subarray has back link to its parent container. Signed-off-by: Marcin Labun Signed-off-by: Anna Czarnowska Signed-off-by: NeilBrown --- Monitor.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Monitor.c b/Monitor.c index 54f26b1..be8d590 100644 --- 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) {