dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/mdadm-3.4-imsm-properly-handle-values-of-sync_completed.patch

7bdf8f
From 0febb20c458a488460eadade74a6c283aadaf96a Mon Sep 17 00:00:00 2001
7bdf8f
From: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
7bdf8f
Date: Thu, 16 Jun 2016 11:31:37 +0200
7bdf8f
Subject: [PATCH 2/2] imsm: properly handle values of sync_completed
7bdf8f
7bdf8f
The sync_completed can be set to such values:
7bdf8f
- two numbers of processed sectors and total during synchronization,
7bdf8f
separated with '/';
7bdf8f
- 'none' if synchronization process is stopped;
7bdf8f
- 'delayed' if synchronization process is delayed.
7bdf8f
Handle value of sync_completed not only as numbers but
7bdf8f
also check for 'none' and 'delayed'.
7bdf8f
7bdf8f
Signed-off-by: Alexey Obitotskiy <aleksey.obitotskiy@intel.com>
7bdf8f
Reviewed-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
7bdf8f
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
7bdf8f
---
7bdf8f
 super-intel.c | 36 ++++++++++++++++++++++++++++++++++--
7bdf8f
 1 file changed, 34 insertions(+), 2 deletions(-)
7bdf8f
7bdf8f
diff --git a/super-intel.c b/super-intel.c
7bdf8f
index 7950bef..92817e9 100644
7bdf8f
--- a/super-intel.c
7bdf8f
+++ b/super-intel.c
7bdf8f
@@ -10363,6 +10363,33 @@ exit_imsm_reshape_super:
7bdf8f
 	return ret_val;
7bdf8f
 }
7bdf8f
 
7bdf8f
+#define COMPLETED_OK		0
7bdf8f
+#define COMPLETED_NONE		1
7bdf8f
+#define COMPLETED_DELAYED	2
7bdf8f
+
7bdf8f
+static int read_completed(int fd, unsigned long long *val)
7bdf8f
+{
7bdf8f
+	int ret;
7bdf8f
+	char buf[50];
7bdf8f
+
7bdf8f
+	ret = sysfs_fd_get_str(fd, buf, 50);
7bdf8f
+	if (ret < 0)
7bdf8f
+		return ret;
7bdf8f
+
7bdf8f
+	ret = COMPLETED_OK;
7bdf8f
+	if (strncmp(buf, "none", 4) == 0) {
7bdf8f
+		ret = COMPLETED_NONE;
7bdf8f
+	} else if (strncmp(buf, "delayed", 7) == 0) {
7bdf8f
+		ret = COMPLETED_DELAYED;
7bdf8f
+	} else {
7bdf8f
+		char *ep;
7bdf8f
+		*val = strtoull(buf, &ep, 0);
7bdf8f
+		if (ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))
7bdf8f
+			ret = -1;
7bdf8f
+	}
7bdf8f
+	return ret;
7bdf8f
+}
7bdf8f
+
7bdf8f
 /*******************************************************************************
7bdf8f
  * Function:	wait_for_reshape_imsm
7bdf8f
  * Description:	Function writes new sync_max value and waits until
7bdf8f
@@ -10417,8 +10444,10 @@ int wait_for_reshape_imsm(struct mdinfo *sra, int ndata)
7bdf8f
 	}
7bdf8f
 
7bdf8f
 	do {
7bdf8f
+		int rc;
7bdf8f
 		char action[20];
7bdf8f
 		int timeout = 3000;
7bdf8f
+
7bdf8f
 		sysfs_wait(fd, &timeout);
7bdf8f
 		if (sysfs_get_str(sra, NULL, "sync_action",
7bdf8f
 				  action, 20) > 0 &&
7bdf8f
@@ -10428,11 +10457,14 @@ int wait_for_reshape_imsm(struct mdinfo *sra, int ndata)
7bdf8f
 			close(fd);
7bdf8f
 			return -1;
7bdf8f
 		}
7bdf8f
-		if (sysfs_fd_get_ll(fd, &completed) < 0) {
7bdf8f
+
7bdf8f
+		rc = read_completed(fd, &completed);
7bdf8f
+		if (rc < 0) {
7bdf8f
 			dprintf("cannot read reshape_position (in loop)\n");
7bdf8f
 			close(fd);
7bdf8f
 			return 1;
7bdf8f
-		}
7bdf8f
+		} else if (rc == COMPLETED_NONE)
7bdf8f
+			break;
7bdf8f
 	} while (completed < position_to_set);
7bdf8f
 
7bdf8f
 	close(fd);
7bdf8f
-- 
7bdf8f
2.5.5
7bdf8f