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

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