Manage/stop: guard against 'completed' being too large.

A race can allow 'completed' to read as 2^63-1, which takes
a long time to count up to.
So guard against that possibility.

Signed-off-by: NeilBrown <neilb@suse.com>
This commit is contained in:
NeilBrown 2015-07-06 13:33:20 +10:00
parent d3f6cf4f9b
commit 30ddba7de5
1 changed files with 5 additions and 1 deletions

View File

@ -400,6 +400,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
delay = 3000;
scfd = sysfs_open(mdi->sys_name, NULL, "sync_completed");
while (scfd >= 0 && delay > 0 && old_sync_max > 0) {
unsigned long long max_completed;
sysfs_get_ll(mdi, NULL, "reshape_position", &curr);
sysfs_fd_get_str(scfd, buf, sizeof(buf));
if (strncmp(buf, "none", 4) == 0) {
@ -413,7 +414,10 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
break;
}
if (sysfs_fd_get_ll(scfd, &completed) == 0 &&
if (sysfs_fd_get_two(scfd, &completed,
&max_completed) == 2 &&
/* 'completed' sometimes reads as max-uulong */
completed < max_completed &&
(completed > sync_max ||
(completed == sync_max && curr != position))) {
while (completed > sync_max) {