dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/sysfs-Parse-array_state-in-sysfs_read.patch

2c1b57
From 5e4ca8bb82e98400c9258cb3d7e4d030576f21df Mon Sep 17 00:00:00 2001
2c1b57
From: Jes Sorensen <jsorensen@fb.com>
2c1b57
Date: Wed, 19 Apr 2017 23:27:58 -0400
2c1b57
Subject: [RHEL7.5 PATCH 081/169] sysfs: Parse array_state in sysfs_read()
2c1b57
2c1b57
Rather than copying in the array_state string, parse it and use an
2c1b57
enum to indicate the state.
2c1b57
2c1b57
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2c1b57
---
2c1b57
 Manage.c |  2 +-
2c1b57
 maps.c   | 17 +++++++++++++++++
2c1b57
 mdadm.h  | 17 ++++++++++++++---
2c1b57
 sysfs.c  |  9 +++++----
2c1b57
 4 files changed, 37 insertions(+), 8 deletions(-)
2c1b57
2c1b57
diff --git a/Manage.c b/Manage.c
2c1b57
index bb84d28..8966e33 100644
2c1b57
--- a/Manage.c
2c1b57
+++ b/Manage.c
2c1b57
@@ -929,7 +929,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
2c1b57
 			return -1;
2c1b57
 		}
2c1b57
 
2c1b57
-		if (strncmp(mdp->sysfs_array_state, "readonly", 8) != 0) {
2c1b57
+		if (mdp->array_state != ARRAY_READONLY) {
2c1b57
 			sysfs_free(mdp);
2c1b57
 			pr_err("%s is not readonly, cannot add journal.\n", devname);
2c1b57
 			return -1;
2c1b57
diff --git a/maps.c b/maps.c
2c1b57
index d9ee7de..a8a4639 100644
2c1b57
--- a/maps.c
2c1b57
+++ b/maps.c
2c1b57
@@ -139,6 +139,23 @@ mapping_t consistency_policies[] = {
2c1b57
 	{ NULL, 0}
2c1b57
 };
2c1b57
 
2c1b57
+mapping_t sysfs_array_states[] = {
2c1b57
+	/*
2c1b57
+	 * Beware map_name() uses strcmp() so active-idle must come before
2c1b57
+	 * active, to be detected correctly.
2c1b57
+	 */
2c1b57
+	{ "active-idle", ARRAY_ACTIVE_IDLE },
2c1b57
+	{ "active", ARRAY_ACTIVE },
2c1b57
+	{ "clear", ARRAY_CLEAR },
2c1b57
+	{ "inactive", ARRAY_INACTIVE },
2c1b57
+	{ "suspended", ARRAY_SUSPENDED },
2c1b57
+	{ "readonly", ARRAY_READONLY },
2c1b57
+	{ "read-auto", ARRAY_READ_AUTO },
2c1b57
+	{ "clean", ARRAY_CLEAN },
2c1b57
+	{ "write-pending", ARRAY_WRITE_PENDING },
2c1b57
+	{ NULL, 0 }
2c1b57
+};
2c1b57
+
2c1b57
 char *map_num(mapping_t *map, int num)
2c1b57
 {
2c1b57
 	while (map->name) {
2c1b57
diff --git a/mdadm.h b/mdadm.h
2c1b57
index f1f643c..a379973 100644
2c1b57
--- a/mdadm.h
2c1b57
+++ b/mdadm.h
2c1b57
@@ -335,8 +335,18 @@ struct mdinfo {
2c1b57
 	int prev_state, curr_state, next_state;
2c1b57
 
2c1b57
 	/* info read from sysfs */
2c1b57
-	char		sysfs_array_state[20];
2c1b57
-
2c1b57
+	enum {
2c1b57
+		ARRAY_CLEAR,
2c1b57
+		ARRAY_INACTIVE,
2c1b57
+		ARRAY_SUSPENDED,
2c1b57
+		ARRAY_READONLY,
2c1b57
+		ARRAY_READ_AUTO,
2c1b57
+		ARRAY_CLEAN,
2c1b57
+		ARRAY_ACTIVE,
2c1b57
+		ARRAY_WRITE_PENDING,
2c1b57
+		ARRAY_ACTIVE_IDLE,
2c1b57
+		ARRAY_UNKNOWN_STATE,
2c1b57
+	} array_state;
2c1b57
 	struct md_bb bb;
2c1b57
 };
2c1b57
 
2c1b57
@@ -716,7 +726,8 @@ extern int restore_stripes(int *dest, unsigned long long *offsets,
2c1b57
 
2c1b57
 extern char *map_num(mapping_t *map, int num);
2c1b57
 extern int map_name(mapping_t *map, char *name);
2c1b57
-extern mapping_t r5layout[], r6layout[], pers[], modes[], faultylayout[], consistency_policies[];
2c1b57
+extern mapping_t r5layout[], r6layout[], pers[], modes[], faultylayout[];
2c1b57
+extern mapping_t consistency_policies[], sysfs_array_states[];
2c1b57
 
2c1b57
 extern char *map_dev_preferred(int major, int minor, int create,
2c1b57
 			       char *prefer);
2c1b57
diff --git a/sysfs.c b/sysfs.c
2c1b57
index 51deb23..c6df9b0 100644
2c1b57
--- a/sysfs.c
2c1b57
+++ b/sysfs.c
2c1b57
@@ -247,11 +247,12 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
2c1b57
 
2c1b57
 	if (options & GET_ARRAY_STATE) {
2c1b57
 		strcpy(base, "array_state");
2c1b57
-		if (load_sys(fname, sra->sysfs_array_state,
2c1b57
-			     sizeof(sra->sysfs_array_state)))
2c1b57
+		if (load_sys(fname, buf, sizeof(buf)))
2c1b57
 			goto abort;
2c1b57
-	} else
2c1b57
-		sra->sysfs_array_state[0] = 0;
2c1b57
+		sra->array_state = map_name(sysfs_array_states, buf);
2c1b57
+		if (sra->array_state == UnSet)
2c1b57
+			sra->array_state = ARRAY_UNKNOWN_STATE;
2c1b57
+	}
2c1b57
 
2c1b57
 	if (options & GET_CONSISTENCY_POLICY) {
2c1b57
 		strcpy(base, "consistency_policy");
2c1b57
-- 
2c1b57
2.7.4
2c1b57