/* retry the load if we might have raced against mdmon */
if (rv == 3) {
- struct mdstat_ent *mdstat = mdstat_by_component(fd2devnm(fd));
+ struct mdstat_ent *mdstat = NULL;
+ char *name = fd2kname(fd);
+
+ if (name)
+ mdstat = mdstat_by_component(name);
if (mdstat && mdmon_running(mdstat->devnm) && getpid() != mdmon_pid(mdstat->devnm)) {
for (retry = 0; retry < 3; retry++) {
return ret_val;
}
+#define COMPLETED_OK 0
+#define COMPLETED_NONE 1
+#define COMPLETED_DELAYED 2
+
+static int read_completed(int fd, unsigned long long *val)
+{
+ int ret;
+ char buf[50];
+
+ ret = sysfs_fd_get_str(fd, buf, 50);
+ if (ret < 0)
+ return ret;
+
+ ret = COMPLETED_OK;
+ if (strncmp(buf, "none", 4) == 0) {
+ ret = COMPLETED_NONE;
+ } else if (strncmp(buf, "delayed", 7) == 0) {
+ ret = COMPLETED_DELAYED;
+ } else {
+ char *ep;
+ *val = strtoull(buf, &ep, 0);
+ if (ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))
+ ret = -1;
+ }
+ return ret;
+}
+
/*******************************************************************************
* Function: wait_for_reshape_imsm
* Description: Function writes new sync_max value and waits until
int wait_for_reshape_imsm(struct mdinfo *sra, int ndata)
{
int fd = sysfs_get_fd(sra, NULL, "sync_completed");
+ int retry = 3;
unsigned long long completed;
/* to_complete : new sync_max position */
unsigned long long to_complete = sra->reshape_progress;
return 1;
}
- if (sysfs_fd_get_ll(fd, &completed) < 0) {
- dprintf("cannot read reshape_position (no reshape in progres)\n");
- close(fd);
- return 1;
- }
+ do {
+ if (sysfs_fd_get_ll(fd, &completed) < 0) {
+ if (!retry) {
+ dprintf("cannot read reshape_position (no reshape in progres)\n");
+ close(fd);
+ return 1;
+ }
+ usleep(30000);
+ } else
+ break;
+ } while (retry--);
if (completed > position_to_set) {
dprintf("wrong next position to set %llu (%llu)\n",
}
do {
+ int rc;
char action[20];
int timeout = 3000;
+
sysfs_wait(fd, &timeout);
if (sysfs_get_str(sra, NULL, "sync_action",
action, 20) > 0 &&
strncmp(action, "reshape", 7) != 0) {
+ if (strncmp(action, "idle", 4) == 0)
+ break;
close(fd);
return -1;
}
- if (sysfs_fd_get_ll(fd, &completed) < 0) {
+
+ rc = read_completed(fd, &completed);
+ if (rc < 0) {
dprintf("cannot read reshape_position (in loop)\n");
close(fd);
return 1;
- }
+ } else if (rc == COMPLETED_NONE)
+ break;
} while (completed < position_to_set);
+
close(fd);
return 0;
-
}
/*******************************************************************************