]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
Avoid confusing with 'blocks' number.
[thirdparty/mdadm.git] / managemon.c
index 7e4924fe67977689afcebb6ae82c4ee571db173a..269d06ed58d8bfd2ac7183f8b5e564d6fd2f4ea4 100644 (file)
@@ -217,10 +217,16 @@ static void free_updates(struct metadata_update **update)
 {
        while (*update) {
                struct metadata_update *this = *update;
+               void **space_list = this->space_list;
 
                *update = this->next;
                free(this->buf);
                free(this->space);
+               while (space_list) {
+                       void *space = space_list;
+                       space_list = *space_list;
+                       free(space);
+               }
                free(this);
        }
 }
@@ -420,12 +426,12 @@ static void manage_member(struct mdstat_ent *mdstat,
         * We do not need to look for device state changes here, that
         * is dealt with by the monitor.
         *
-        * We just look for changes which suggest that a reshape is
-        * being requested.
-        * Unfortunately decreases in raid_disks don't show up in
-        * mdstat until the reshape completes FIXME.
+        * If a reshape is being requested, monitor will have noticed
+        * that sync_action changed and will have set check_reshape.
+        * We just need to see if new devices have appeared.  All metadata
+        * updates will already have been processed.
         *
-        * Actually, we also want to handle degraded arrays here by
+        * We also want to handle degraded arrays here by
         * trying to find and assign a spare.
         * We do that whenever the monitor tells us too.
         */
@@ -442,6 +448,18 @@ static void manage_member(struct mdstat_ent *mdstat,
        else
                frozen = 1; /* can't read metadata_version assume the worst */
 
+       if (mdstat->level) {
+               int level = map_name(pers, mdstat->level);
+               if (a->info.array.level != level && level >= 0) {
+                       struct active_array *newa = duplicate_aa(a);
+                       if (newa) {
+                               newa->info.array.level = level;
+                               replace_array(a->container, a, newa);
+                               a = newa;
+                       }
+               }
+       }
+
        if (a->check_degraded && !frozen) {
                struct metadata_update *updates = NULL;
                struct mdinfo *newdev = NULL;
@@ -488,6 +506,52 @@ static void manage_member(struct mdstat_ent *mdstat,
                }
                free_updates(&updates);
        }
+
+       if (a->check_reshape) {
+               /* mdadm might have added some devices to the array.
+                * We want to disk_init_and_add any such device to a
+                * duplicate_aa and replace a with that.
+                * mdstat doesn't have enough info so we sysfs_read
+                * and look for new stuff.
+                */
+               struct mdinfo *info, *d, *d2, *newd;
+               unsigned long long array_size;
+               struct active_array *newa = NULL;
+               a->check_reshape = 0;
+               info = sysfs_read(-1, mdstat->devnum,
+                                 GET_DEVS|GET_OFFSET|GET_SIZE|GET_STATE);
+               if (!info)
+                       goto out2;
+               for (d = info->devs; d; d = d->next) {
+                       if (d->disk.raid_disk < 0)
+                               continue;
+                       for (d2 = a->info.devs; d2; d2 = d2->next)
+                               if (d2->disk.raid_disk ==
+                                   d->disk.raid_disk)
+                                       break;
+                       if (d2)
+                               /* already have this one */
+                               continue;
+                       if (!newa) {
+                               newa = duplicate_aa(a);
+                               if (!newa)
+                                       break;
+                       }
+                       newd = malloc(sizeof(*newd));
+                       if (!newd)
+                               continue;
+                       disk_init_and_add(newd, d, newa);
+               }
+               if (sysfs_get_ll(info, NULL, "array_size", &array_size) == 0
+                   && a->info.custom_array_size > array_size) {
+                       sysfs_set_num(info, NULL, "array_size",
+                                     a->info.custom_array_size);
+               }
+       out2:
+               sysfs_free(info);
+               if (newa)
+                       replace_array(a->container, a, newa);
+       }
 }
 
 static int aa_ready(struct active_array *aa)
@@ -670,6 +734,7 @@ static void handle_message(struct supertype *container, struct metadata_update *
                mu->buf = msg->buf;
                msg->buf = NULL;
                mu->space = NULL;
+               mu->space_list = NULL;
                mu->next = NULL;
                if (container->ss->prepare_update)
                        container->ss->prepare_update(container, mu);