]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
imsm: FIX: wait_for_reshape_imsm() cleanup
authorAdam Kwolek <adam.kwolek@intel.com>
Thu, 9 Jun 2011 03:00:55 +0000 (13:00 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 9 Jun 2011 03:00:55 +0000 (13:00 +1000)
This function needs to be corrected.
It should check sysfs operations status and it should not interpret
0 reshape position special meaning.

Unused input parameter is removed also.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
super-intel.c

index 06831c3e08a0a0835f5b103156fc946c359f6737..4b94e9d7810be28efbaca007e3d19d691fa91b18 100644 (file)
@@ -8559,39 +8559,50 @@ exit_imsm_reshape_super:
  *             reshape process reach new position
  * Parameters:
  *     sra             : general array info
- *     to_complete     : new sync_max position
  *     ndata           : number of disks in new array's layout
  * Returns:
  *      0 : success,
  *      1 : there is no reshape in progress,
  *     -1 : fail
  ******************************************************************************/
-int wait_for_reshape_imsm(struct mdinfo *sra, unsigned long long to_complete,
-                         int ndata)
+int wait_for_reshape_imsm(struct mdinfo *sra, int ndata)
 {
        int fd = sysfs_get_fd(sra, NULL, "reshape_position");
        unsigned long long completed;
+       /* to_complete : new sync_max position */
+       unsigned long long to_complete = sra->reshape_progress;
+       unsigned long long position_to_set = to_complete / ndata;
 
        struct timeval timeout;
 
-       if (fd < 0)
+       if (fd < 0) {
+               dprintf("imsm: wait_for_reshape_imsm() "
+                       "cannot open reshape_position\n");
                return 1;
+       }
 
-       sysfs_fd_get_ll(fd, &completed);
+       if (sysfs_fd_get_ll(fd, &completed) < 0) {
+               dprintf("imsm: wait_for_reshape_imsm() "
+                       "cannot read reshape_position (no reshape in progres)\n");
+               close(fd);
+               return 0;
+       }
 
-       if (to_complete == 0) {/* reshape till the end of array */
-               sysfs_set_str(sra, NULL, "sync_max", "max");
-               to_complete = MaxSector;
-       } else {
-               if (completed > to_complete) {
-                       close(fd);
-                       return -1;
-               }
-               if (sysfs_set_num(sra, NULL, "sync_max",
-                                 to_complete / ndata) != 0) {
-                       close(fd);
-                       return -1;
-               }
+       if (completed > to_complete) {
+               dprintf("imsm: wait_for_reshape_imsm() "
+                       "wrong next position to set %llu (%llu)\n",
+                       to_complete, completed);
+               close(fd);
+               return -1;
+       }
+       dprintf("Position set: %llu\n", position_to_set);
+       if (sysfs_set_num(sra, NULL, "sync_max",
+                         position_to_set) != 0) {
+               dprintf("imsm: wait_for_reshape_imsm() "
+                       "cannot set reshape position to %llu\n",
+                       position_to_set);
+               close(fd);
+               return -1;
        }
 
        /* FIXME should not need a timeout at all */
@@ -8604,6 +8615,8 @@ int wait_for_reshape_imsm(struct mdinfo *sra, unsigned long long to_complete,
                FD_SET(fd, &rfds);
                select(fd+1, NULL, NULL, &rfds, &timeout);
                if (sysfs_fd_get_ll(fd, &completed) < 0) {
+                       dprintf("imsm: wait_for_reshape_imsm() "
+                               "cannot read reshape_position (in loop)\n");
                        close(fd);
                        return 1;
                }
@@ -8853,15 +8866,14 @@ static int imsm_manage_reshape(
                next_step = next_step + sra->reshape_progress;
                sysfs_set_num(sra, NULL, "suspend_lo", sra->reshape_progress);
                sysfs_set_num(sra, NULL, "suspend_hi", next_step);
+               sra->reshape_progress = next_step;
 
                /* wait until reshape finish */
-               if (wait_for_reshape_imsm(sra, next_step, ndata) < 0) {
+               if (wait_for_reshape_imsm(sra, ndata) < 0) {
                        dprintf("wait_for_reshape_imsm returned error!\n");
                        goto abort;
                }
 
-               sra->reshape_progress = next_step;
-
                if (save_checkpoint_imsm(st, sra, UNIT_SRC_NORMAL) == 1) {
                        /* ignore error == 2, this can mean end of reshape here
                         */