anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0126-libndctl-intel-Indicate-supported-smart-inject-types.patch

e0018b
From edcd9b7e10b3b33a9660e412a2db1beab30936d3 Mon Sep 17 00:00:00 2001
e0018b
From: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Date: Tue, 25 Jan 2022 02:07:35 +0530
e0018b
Subject: [PATCH 126/217] libndctl, intel: Indicate supported smart-inject
e0018b
 types
e0018b
e0018b
Presently the inject-smart code assumes support for injecting all
e0018b
smart-errors namely media-temperature, controller-temperature,
e0018b
spares-remaining, fatal-health and unsafe-shutdown. This assumption
e0018b
may break in case of other non-Intel NVDIMM types namely PAPR NVDIMMs
e0018b
which presently only have support for injecting unsafe-shutdown and
e0018b
fatal health events.
e0018b
e0018b
Trying to inject-smart errors on PAPR NVDIMMs causes problems as
e0018b
smart_inject() prematurely exits when trying to inject
e0018b
media-temperature smart-error errors out.
e0018b
e0018b
To fix this issue the patch proposes extending the definition of
e0018b
dimm_op 'smart_inject_supported' to return bitmap of flags indicating
e0018b
the type of smart-error injections supported by an NVDIMM. These types
e0018b
are indicated by the newly introduced defines ND_SMART_INJECT_* . A
e0018b
dimm-ops provide can return an bitmap composed of these flags back
e0018b
from its implementation of 'smart_inject_supported' to indicate to
e0018b
dimm_inject_smart() which type of smart-error injection it
e0018b
supports. In case of an error the dimm-op is still expected to return
e0018b
a negative error code back to the caller.
e0018b
e0018b
The patch updates intel_dimm_smart_inject_supported() to return a
e0018b
bitmap composed of all ND_SMART_INJECT_* flags to indicate support for
e0018b
all smart-error types.
e0018b
e0018b
Finally the patch also updates smart_inject() to test for specific
e0018b
ND_START_INJECT_* flags before sending a smart-inject command via
e0018b
dimm-provider.
e0018b
e0018b
Link: https://lore.kernel.org/r/20220124203735.1490186-1-vaibhav@linux.ibm.com
e0018b
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
e0018b
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 ndctl/inject-smart.c | 31 ++++++++++++++++++++++++-------
e0018b
 ndctl/lib/intel.c    |  7 ++++++-
e0018b
 ndctl/libndctl.h     |  8 ++++++++
e0018b
 3 files changed, 38 insertions(+), 8 deletions(-)
e0018b
e0018b
diff --git a/ndctl/inject-smart.c b/ndctl/inject-smart.c
e0018b
index 2b9d7e8..bd8c01e 100644
e0018b
--- a/ndctl/inject-smart.c
e0018b
+++ b/ndctl/inject-smart.c
e0018b
@@ -395,18 +395,26 @@ out:
e0018b
 	} \
e0018b
 }
e0018b
 
e0018b
-static int smart_inject(struct ndctl_dimm *dimm)
e0018b
+static int smart_inject(struct ndctl_dimm *dimm, unsigned int inject_types)
e0018b
 {
e0018b
 	const char *name = ndctl_dimm_get_devname(dimm);
e0018b
 	struct ndctl_cmd *si_cmd = NULL;
e0018b
 	int rc = -EOPNOTSUPP;
e0018b
 
e0018b
-	send_inject_val(media_temperature)
e0018b
-	send_inject_val(ctrl_temperature)
e0018b
-	send_inject_val(spares)
e0018b
-	send_inject_bool(fatal)
e0018b
-	send_inject_bool(unsafe_shutdown)
e0018b
+	if (inject_types & ND_SMART_INJECT_MEDIA_TEMPERATURE)
e0018b
+		send_inject_val(media_temperature);
e0018b
 
e0018b
+	if (inject_types & ND_SMART_INJECT_CTRL_TEMPERATURE)
e0018b
+		send_inject_val(ctrl_temperature);
e0018b
+
e0018b
+	if (inject_types & ND_SMART_INJECT_SPARES_REMAINING)
e0018b
+		send_inject_val(spares);
e0018b
+
e0018b
+	if (inject_types & ND_SMART_INJECT_HEALTH_STATE)
e0018b
+		send_inject_bool(fatal);
e0018b
+
e0018b
+	if (inject_types & ND_SMART_INJECT_UNCLEAN_SHUTDOWN)
e0018b
+		send_inject_bool(unsafe_shutdown);
e0018b
 out:
e0018b
 	ndctl_cmd_unref(si_cmd);
e0018b
 	return rc;
e0018b
@@ -417,6 +425,7 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
e0018b
 	struct json_object *jhealth;
e0018b
 	struct json_object *jdimms;
e0018b
 	struct json_object *jdimm;
e0018b
+	unsigned int supported_types;
e0018b
 	int rc;
e0018b
 
e0018b
 	rc = ndctl_dimm_smart_inject_supported(dimm);
e0018b
@@ -433,6 +442,14 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
e0018b
 		error("%s: smart injection not supported by either platform firmware or the kernel.",
e0018b
 			ndctl_dimm_get_devname(dimm));
e0018b
 		return rc;
e0018b
+	default:
e0018b
+		if (rc < 0) {
e0018b
+			error("%s: Unknown error %d while checking for smart injection support",
e0018b
+			      ndctl_dimm_get_devname(dimm), rc);
e0018b
+			return rc;
e0018b
+		}
e0018b
+		supported_types = rc;
e0018b
+		break;
e0018b
 	}
e0018b
 
e0018b
 	if (sctx.op_mask & (1 << OP_SET)) {
e0018b
@@ -441,7 +458,7 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
e0018b
 			goto out;
e0018b
 	}
e0018b
 	if (sctx.op_mask & (1 << OP_INJECT)) {
e0018b
-		rc = smart_inject(dimm);
e0018b
+		rc = smart_inject(dimm, supported_types);
e0018b
 		if (rc)
e0018b
 			goto out;
e0018b
 	}
e0018b
diff --git a/ndctl/lib/intel.c b/ndctl/lib/intel.c
e0018b
index a3df26e..1314854 100644
e0018b
--- a/ndctl/lib/intel.c
e0018b
+++ b/ndctl/lib/intel.c
e0018b
@@ -455,7 +455,12 @@ static int intel_dimm_smart_inject_supported(struct ndctl_dimm *dimm)
e0018b
 		return -EIO;
e0018b
 	}
e0018b
 
e0018b
-	return 0;
e0018b
+	/* Indicate all smart injection types are supported */
e0018b
+	return ND_SMART_INJECT_SPARES_REMAINING |
e0018b
+		ND_SMART_INJECT_MEDIA_TEMPERATURE |
e0018b
+		ND_SMART_INJECT_CTRL_TEMPERATURE |
e0018b
+		ND_SMART_INJECT_HEALTH_STATE |
e0018b
+		ND_SMART_INJECT_UNCLEAN_SHUTDOWN;
e0018b
 }
e0018b
 
e0018b
 static const char *intel_cmd_desc(int fn)
e0018b
diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h
e0018b
index b59026c..4d5cdbf 100644
e0018b
--- a/ndctl/libndctl.h
e0018b
+++ b/ndctl/libndctl.h
e0018b
@@ -69,6 +69,13 @@ extern "C" {
e0018b
 #define ND_EVENT_HEALTH_STATE		(1 << 3)
e0018b
 #define ND_EVENT_UNCLEAN_SHUTDOWN	(1 << 4)
e0018b
 
e0018b
+/* Flags indicating support for various smart injection types */
e0018b
+#define ND_SMART_INJECT_SPARES_REMAINING	(1 << 0)
e0018b
+#define ND_SMART_INJECT_MEDIA_TEMPERATURE	(1 << 1)
e0018b
+#define ND_SMART_INJECT_CTRL_TEMPERATURE	(1 << 2)
e0018b
+#define ND_SMART_INJECT_HEALTH_STATE		(1 << 3)
e0018b
+#define ND_SMART_INJECT_UNCLEAN_SHUTDOWN	(1 << 4)
e0018b
+
e0018b
 size_t ndctl_min_namespace_size(void);
e0018b
 size_t ndctl_sizeof_namespace_index(void);
e0018b
 size_t ndctl_sizeof_namespace_label(void);
e0018b
@@ -311,6 +318,7 @@ int ndctl_cmd_smart_inject_spares(struct ndctl_cmd *cmd, bool enable,
e0018b
 		unsigned int spares);
e0018b
 int ndctl_cmd_smart_inject_fatal(struct ndctl_cmd *cmd, bool enable);
e0018b
 int ndctl_cmd_smart_inject_unsafe_shutdown(struct ndctl_cmd *cmd, bool enable);
e0018b
+/* Returns a bitmap of ND_SMART_INJECT_* supported */
e0018b
 int ndctl_dimm_smart_inject_supported(struct ndctl_dimm *dimm);
e0018b
 
e0018b
 struct ndctl_cmd *ndctl_dimm_cmd_new_vendor_specific(struct ndctl_dimm *dimm,
e0018b
-- 
e0018b
2.27.0
e0018b