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

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