]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - managemon.c
ddf: implement remove_from_super
[thirdparty/mdadm.git] / managemon.c
index 9cb8049971f4168828d3da202176f168a7705c74..15b6e692efcbcf78a54afc9708db5d528ba742b6 100644 (file)
@@ -320,16 +320,15 @@ static void remove_disk_from_container(struct supertype *st, struct mdinfo *sd)
                .raid_disk = -1,
                .state = 0,
        };
-       /* nothing to do if super type handler does not support
-        * remove disk primitive
-        */
-       if (!st->ss->remove_from_super)
-               return;
        dprintf("%s: remove %d:%d from container\n",
                __func__, sd->disk.major, sd->disk.minor);
 
        st->update_tail = &update;
        st->ss->remove_from_super(st, &dk);
+       /* FIXME this write_init_super shouldn't be here.
+        * We have it after add_to_super to write to new device,
+        * but with 'remove' we don't ant to write to that device!
+        */
        st->ss->write_init_super(st);
        queue_metadata_update(update);
        st->update_tail = NULL;
@@ -448,6 +447,24 @@ static void manage_member(struct mdstat_ent *mdstat,
        else
                frozen = 1; /* can't read metadata_version assume the worst */
 
+       /* If sync_action is not 'idle' then don't try recovery now */
+       if (!frozen
+           && sysfs_get_str(&a->info, NULL, "sync_action", buf, sizeof(buf)) > 0
+           && strncmp(buf, "idle", 4) != 0)
+               frozen = 1;
+
+       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;
@@ -531,9 +548,9 @@ static void manage_member(struct mdstat_ent *mdstat,
                        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) {
+                   && a->info.custom_array_size > array_size*2) {
                        sysfs_set_num(info, NULL, "array_size",
-                                     a->info.custom_array_size);
+                                     a->info.custom_array_size/2);
                }
        out2:
                sysfs_free(info);
@@ -578,6 +595,7 @@ static void manage_new(struct mdstat_ent *mdstat,
        char *inst;
        int i;
        int failed = 0;
+       char buf[40];
 
        /* check if array is ready to be monitored */
        if (!mdstat->active)
@@ -639,6 +657,29 @@ static void manage_new(struct mdstat_ent *mdstat,
        dprintf("%s: inst: %d action: %d state: %d\n", __func__, atoi(inst),
                new->action_fd, new->info.state_fd);
 
+       /* reshape_position is set by mdadm in sysfs
+        * read this information for new arrays only (empty victim)
+        */
+       if ((victim == NULL) &&
+           (sysfs_get_str(mdi, NULL, "sync_action", buf, 40) > 0) &&
+           (strncmp(buf, "reshape", 7) == 0)) {
+               if (sysfs_get_ll(mdi, NULL, "reshape_position",
+                       &new->last_checkpoint) != 0)
+                       new->last_checkpoint = 0;
+               else {
+                       int data_disks = mdi->array.raid_disks;
+                       if (mdi->array.level == 4 || mdi->array.level == 5)
+                               data_disks--;
+                       if (mdi->array.level == 6)
+                               data_disks -= 2;
+
+                       new->last_checkpoint /= data_disks;
+               }
+               dprintf("mdmon: New monitored array is under reshape.\n"
+                       "       Last checkpoint is: %llu\n",
+                       new->last_checkpoint);
+       }
+
        sysfs_free(mdi);
 
        /* if everything checks out tell the metadata handler we want to