Blame SOURCES/0009-RH-attempt-to-get-ANA-info-via-sysfs-first.patch

68b27c
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
68b27c
From: Benjamin Marzinski <bmarzins@redhat.com>
68b27c
Date: Thu, 11 Apr 2019 13:25:42 -0500
68b27c
Subject: [PATCH] RH: attempt to get ANA info via sysfs first
68b27c
68b27c
When the ANA prioritizer is run, first see if the "ana_state" sysfs file
68b27c
exists, and if it does, try to read the state from there. If that fails,
68b27c
fallback to using an ioctl.
68b27c
68b27c
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
68b27c
---
68b27c
 libmultipath/prioritizers/ana.c | 31 +++++++++++++++++++++++++++++--
68b27c
 1 file changed, 29 insertions(+), 2 deletions(-)
68b27c
68b27c
diff --git a/libmultipath/prioritizers/ana.c b/libmultipath/prioritizers/ana.c
68b27c
index b5c7873d..e139360c 100644
68b27c
--- a/libmultipath/prioritizers/ana.c
68b27c
+++ b/libmultipath/prioritizers/ana.c
68b27c
@@ -24,6 +24,7 @@
68b27c
 #include "prio.h"
68b27c
 #include "util.h"
68b27c
 #include "structs.h"
68b27c
+#include "sysfs.h"
68b27c
 
68b27c
 enum {
68b27c
 	ANA_ERR_GETCTRL_FAILED		= 1,
68b27c
@@ -36,6 +37,7 @@ enum {
68b27c
 	ANA_ERR_GETNS_FAILED,
68b27c
 	ANA_ERR_NO_MEMORY,
68b27c
 	ANA_ERR_NO_INFORMATION,
68b27c
+	ANA_ERR_INVALID_STATE,
68b27c
 };
68b27c
 
68b27c
 static const char *ana_errmsg[] = {
68b27c
@@ -49,6 +51,7 @@ static const char *ana_errmsg[] = {
68b27c
 	[ANA_ERR_GETNS_FAILED]		= "couldn't get namespace info",
68b27c
 	[ANA_ERR_NO_MEMORY]		= "out of memory",
68b27c
 	[ANA_ERR_NO_INFORMATION]	= "invalid fd",
68b27c
+	[ANA_ERR_INVALID_STATE]		= "invalid state",
68b27c
 };
68b27c
 
68b27c
 static const char *anas_string[] = {
68b27c
@@ -107,6 +110,27 @@ static int get_ana_state(__u32 nsid, __u32 anagrpid, void *ana_log,
68b27c
 	return -ANA_ERR_GETANAS_NOTFOUND;
68b27c
 }
68b27c
 
68b27c
+static int get_ana_info_sysfs(struct path *pp)
68b27c
+{
68b27c
+	char state[32];
68b27c
+
68b27c
+	if (!pp->udev || sysfs_attr_get_value(pp->udev, "ana_state", state,
68b27c
+					      sizeof(state)) <= 0)
68b27c
+		return -ANA_ERR_NO_INFORMATION;
68b27c
+
68b27c
+	if (strcmp(state, "optimized") == 0)
68b27c
+		return NVME_ANA_OPTIMIZED;
68b27c
+	if (strcmp(state, "non-optimized") == 0)
68b27c
+		return NVME_ANA_NONOPTIMIZED;
68b27c
+	if (strcmp(state, "inaccessible") == 0)
68b27c
+		return NVME_ANA_INACCESSIBLE;
68b27c
+	if (strcmp(state, "persistent-loss") == 0)
68b27c
+		return NVME_ANA_PERSISTENT_LOSS;
68b27c
+	if (strcmp(state, "change") == 0)
68b27c
+		return NVME_ANA_CHANGE;
68b27c
+	return -ANA_ERR_INVALID_STATE;
68b27c
+}
68b27c
+
68b27c
 static int get_ana_info(struct path * pp)
68b27c
 {
68b27c
 	int	rc;
68b27c
@@ -210,8 +234,11 @@ int getprio(struct path *pp, __attribute__((unused)) char *args,
68b27c
 
68b27c
 	if (pp->fd < 0)
68b27c
 		rc = -ANA_ERR_NO_INFORMATION;
68b27c
-	else
68b27c
-		rc = get_ana_info(pp);
68b27c
+	else {
68b27c
+		rc = get_ana_info_sysfs(pp);
68b27c
+		if (rc < 0)
68b27c
+			rc = get_ana_info(pp);
68b27c
+	}
68b27c
 
68b27c
 	switch (rc) {
68b27c
 	case NVME_ANA_OPTIMIZED: