Skip to contentSkip to conversation

ndctl, inject-error: error out for a non-existent namespace

PATCH Superseded Vishal Verma 2 participants 5 messages Feb 8, 2018 – Feb 9, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/4 ndctl, inject-error: error out for a non-existent namespace

When an invalid namespace was specified, inject-error would simply walk through a loop trying to matching namespace, and at the end, exit out silently. This could make it look as though the operation had been successful, when in reality, nothing had been done.

Fix to print a message, and exit with an ENXIO when this happens.

---
 ndctl/inject-error.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ndctl/inject-error.c +2 -1
index 9b9d821..efa9f92 100644
@@ -338,7 +338,8 @@ static int do_inject(const char *namespace, struct ndctl_ctx *ctx)
 		}
 	}
 
-	return 0;
+	error("%s: no such namespace\n", namespace);
+	return rc;
 }
 
 int cmd_inject_error(int argc, const char **argv, void *ctx)
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author maintainer
#1 lore raw

PATCH 2/4 ndctl: add ndctl_encode_smart_temperature()

This provides for encoding of a human-readable temperature value into the format expected by the smart command

---
 ndctl/lib/libndctl.c   | 16 ++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  1 +
 3 files changed, 18 insertions(+)
ndctl/lib/libndctl.c +16 -0
index 4119a2e..ed5a65b 100644
@@ -87,6 +87,22 @@ NDCTL_EXPORT double ndctl_decode_smart_temperature(unsigned int temp)
 	return t;
 }
 
+NDCTL_EXPORT unsigned int ndctl_encode_smart_temperature(double temp)
+{
+	bool negative = false;
+	unsigned int t;
+
+	if  (temp < 0) {
+		negative = true;
+		temp *= -1;
+	}
+	t = temp;
+	t *= 16;
+	if (negative)
+		t |= (1 << 15);
+	return t;
+}
+
 struct ndctl_ctx;
 
 /**
ndctl/lib/libndctl.sym +1 -0
index c160847..e7f9675 100644
@@ -322,6 +322,7 @@ global:
 	ndctl_cmd_smart_threshold_set_ctrl_temperature;
 	ndctl_cmd_smart_threshold_set_spares;
 	ndctl_decode_smart_temperature;
+	ndctl_encode_smart_temperature;
 	ndctl_dimm_cmd_new_smart_inject;
 	ndctl_cmd_smart_inject_media_temperature;
 	ndctl_cmd_smart_inject_spares;
ndctl/libndctl.h +1 -0
index bd33d39..6091ff3 100644
@@ -76,6 +76,7 @@ size_t ndctl_min_namespace_size(void);
 size_t ndctl_sizeof_namespace_index(void);
 size_t ndctl_sizeof_namespace_label(void);
 double ndctl_decode_smart_temperature(unsigned int temp);
+unsigned int ndctl_encode_smart_temperature(double temp);
 
 struct ndctl_ctx;
 struct ndctl_ctx *ndctl_ref(struct ndctl_ctx *ctx);
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author maintainer
#2 lore raw

PATCH 3/4 ndctl: add a new command - inject-smart

In reply to Vishal Verma

Add an inject-smart command to ndctl to allow injection of smart fields, and setting of smart thresholds. If a field is injected that breaches the threshold, or sets a fatal flag, or if a new threshold is set that causes the same effect, generate an acpi health even notification.

---
 Documentation/ndctl/ndctl-inject-smart.txt |  90 +++++++
 builtin.h                                  |   1 +
 ndctl/Makefile.am                          |   3 +-
 ndctl/inject-smart.c                       | 365 +++++++++++++++++++++++++++++
 ndctl/ndctl.c                              |   1 +
 5 files changed, 459 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ndctl/ndctl-inject-smart.txt
 create mode 100644 ndctl/inject-smart.c
Documentation/ndctl/ndctl-inject-smart.txt new file +90 -0
new file mode 100644
index 0000000..da20afe
@@ -0,0 +1,90 @@
+ndctl-inject-smart(1)
+=====================
+
+NAME
+----
+ndctl-inject-smart - perform smart threshold/injection operations on a DIMM
+
+SYNOPSIS
+--------
+[verse]
+'ndctl inject-smart' <dimm> [<options>]
+
+DESCRIPTION
+-----------
+A generic DIMM device object, named /dev/nmemX, is registered for each
+memory device indicated in the ACPI NFIT table, or other platform NVDIMM
+resource discovery mechanism.
+
+ndctl-inject-smart can be used to set smart thresholds, and inject smart errors.
+
+EXAMPLES
+--------
+
+Set smart controller temperature and spares threshold for DIMM-0 to 32C, and 8
+[verse]
+ndctl inject-smart --set-threshold --ctrl-temperature=32 --spares=8 nmem0
+
+Inject the fatal health status flag for DIMM-0
+[verse]
+ndctl inject-smart --inject --fatal nmem0
+
+
+OPTIONS
+-------
+-b::
+--bus=::
+	Enforce that the operation only be carried on devices that are
+	attached to the given bus. Where 'bus' can be a provider name or a bus
+	id number.
+
+-s::
+--set-threshold::
+	Set a smart threshold. Provide one or more of the smart fields and
+	values to set them to.
+
+-i::
+--inject::
+	Inject a smart status. This can be a boolean flag or a field with a
+	certain value. Multiple fields may be specified in a single command.
+
+-A::
+--alarm-control=::
+	Smart field for alarm control flags.
+
+-M::
+--media-temperature=::
+	Smart field for media temperature.
+
+-C::
+--ctrl-temperature=::
+	Smart field for controller temperature.
+
+-S::
+--spares=::
+	Smart field for spares.
+
+-F::
+--fatal=::
+	Smart fatal status. Only usable with --inject.
+
+-U::
+--unsafe-shutdown=::
+	Smart unsafe shutdown status. Only usable with --inject.
+
+-v::
+--verbose::
+	Emit debug messages for the error injection process
+
+include::human-option.txt[]
+
+COPYRIGHT
+---------
+Copyright (c) 2018, Intel Corporation. License GPLv2: GNU GPL
+version 2 <http://gnu.org/licenses/gpl.html>.  This is free software:
+you are free to change and redistribute it.  There is NO WARRANTY, to
+the extent permitted by law.
+
+SEE ALSO
+--------
+linkndctl:ndctl-list[1],
builtin.h +1 -0
index 1f423dc..b24fc99 100644
@@ -44,4 +44,5 @@ int cmd_test(int argc, const char **argv, void *ctx);
 int cmd_bat(int argc, const char **argv, void *ctx);
 #endif
 int cmd_update_firmware(int argc, const char **argv, void *ctx);
+int cmd_inject_smart(int argc, const char **argv, void *ctx);
 #endif /* _NDCTL_BUILTIN_H_ */
ndctl/Makefile.am +2 -1
index 5cd8678..2054c1a 100644
@@ -14,7 +14,8 @@ ndctl_SOURCES = ndctl.c \
 		../util/json.c \
 		util/json-smart.c \
 		inject-error.c \
-		update.c
+		update.c \
+		inject-smart.c
 
 if ENABLE_DESTRUCTIVE
 ndctl_SOURCES += ../test/blk_namespaces.c \
ndctl/inject-smart.c new file +365 -0

365 lines not on this page · raw message

ndctl/ndctl.c +1 -0
index a0e5153..d3c6db1 100644
@@ -85,6 +85,7 @@ static struct cmd_struct commands[] = {
 	{ "check-labels", cmd_check_labels },
 	{ "inject-error", cmd_inject_error },
 	{ "update-firmware", cmd_update_firmware },
+	{ "inject-smart", cmd_inject_smart },
 	{ "list", cmd_list },
 	{ "help", cmd_help },
 	#ifdef ENABLE_TEST
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#3 lore raw

Re: [ndctl PATCH 3/4] ndctl: add a new command - inject-smart

Quoted 43 lines · Vishal Verma

Add an inject-smart command to ndctl to allow injection of smart fields, and setting of smart thresholds. If a field is injected that breaches the threshold, or sets a fatal flag, or if a new threshold is set that causes the same effect, generate an acpi health even notification.

---
 Documentation/ndctl/ndctl-inject-smart.txt |  90 +++++++
 builtin.h                                  |   1 +
 ndctl/Makefile.am                          |   3 +-
 ndctl/inject-smart.c                       | 365 +++++++++++++++++++++++++++++
 ndctl/ndctl.c                              |   1 +
 5 files changed, 459 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ndctl/ndctl-inject-smart.txt
 create mode 100644 ndctl/inject-smart.c
Documentation/ndctl/ndctl-inject-smart.txt new file +20 -0
new file mode 100644
index 0000000..da20afe
@@ -0,0 +1,90 @@
+ndctl-inject-smart(1)
+=====================
+
+NAME
+----
+ndctl-inject-smart - perform smart threshold/injection operations on a DIMM
+
+SYNOPSIS
+--------
+[verse]
+'ndctl inject-smart' <dimm> [<options>]
+
+DESCRIPTION
+-----------
+A generic DIMM device object, named /dev/nmemX, is registered for each
+memory device indicated in the ACPI NFIT table, or other platform NVDIMM
+resource discovery mechanism.
+
+ndctl-inject-smart can be used to set smart thresholds, and inject smart errors.
+

Documentation/ndctl/ndctl-inject-smart.txt line 30

Quoted 10 lines
Documentation/ndctl/ndctl-inject-smart.txt new file +10 -0
+EXAMPLES
+--------
+
+Set smart controller temperature and spares threshold for DIMM-0 to 32C, and 8
+[verse]
+ndctl inject-smart --set-threshold --ctrl-temperature=32 --spares=8 nmem0
+
+Inject the fatal health status flag for DIMM-0
+[verse]
+ndctl inject-smart --inject --fatal nmem0

I'd like to tweak this a bit to eliminate what appears to be a "sub-command of a sub-command" calling convention. Either we need separate commands for threshold setting and value injection, not my first choice, *or* have explicit <set> and <set threshold> options with the attribute included in the option directly. Where a <set> operation is an injectable (writable) attribute and <set threshold> is of course a threshold. We'd then end up with an option stream like:

--controller-temperature=<temp>
--controller-temperature-alarm
--no-controller-temperature-alarm
--controller-temperature-threshold=<temp>
--media-temperature=<temp>
--media-temperature-alarm
--no-media-temperature-alarm
--media-temperature-threshold=temp
--health={fatal,nominal}
--unsafe-shutdown-event

What this also might imply, for a future change, is the capability to list the supported injections (perhaps annotate the output of ndctl list -DH??). For example, "controller-temperature" injection should be an option for completeness, but it will fail on Intel DIMMs that only define a media temperature injection mechanism.

With this change you can inject, set alarms, and set thresholds all in one command.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#4 lore raw

PATCH 4/4 ndctl, bash-completion: Add bash completion for inject-smart

In reply to Vishal Verma

This adds bash completion for the enw ndctl inject-smart command. non-option arguments are completed with dimms, and new options requiring data are marked as such.

---
 contrib/ndctl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/ndctl +4 -1
index eeda1c4..9a14383 100755
@@ -91,7 +91,7 @@ __ndctlcomp()
 
 	COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
 	for cword in "${COMPREPLY[@]}"; do
-		if [[ "$cword" == @(--bus|--region|--type|--mode|--size|--dimm|--reconfig|--uuid|--name|--sector-size|--map|--namespace|--input|--output|--label-version|--align|--block|--count|--firmware) ]]; then
+		if [[ "$cword" == @(--bus|--region|--type|--mode|--size|--dimm|--reconfig|--uuid|--name|--sector-size|--map|--namespace|--input|--output|--label-version|--align|--block|--count|--firmware|--alarm-control|--media-temperature|--ctrl-temperature|--spares) ]]; then
 			COMPREPLY[$i]="${cword}="
 		else
 			COMPREPLY[$i]="${cword} "
@@ -262,6 +262,9 @@ __ndctl_comp_non_option_args()
 	inject-error)
 		opts="$(__ndctl_get_ns -i)"
 		;;
+	inject-smart)
+		opts="$(__ndctl_get_dimms -i)"
+		;;
 	*)
 		return
 		;;
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm