Skip to contentSkip to conversation

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

PATCH In review Vishal Verma 2 participants 5 messages Feb 9, 2018

Subsystems (2)
lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH v2 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 v2 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 v2 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 | 102 +++++++
 builtin.h                                  |   1 +
 ndctl/Makefile.am                          |   3 +-
 ndctl/inject-smart.c                       | 436 +++++++++++++++++++++++++++++
 ndctl/ndctl.c                              |   1 +
 5 files changed, 542 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ndctl/ndctl-inject-smart.txt
 create mode 100644 ndctl/inject-smart.c

v2: Change inject-smart semantics to avoid sub-commands like --inject and --set. Instead allow injection and threshold setting all in one command by making each a distinct option. (Dan)

Documentation/ndctl/ndctl-inject-smart.txt new file +102 -0
new file mode 100644
index 0000000..212bca0
@@ -0,0 +1,102 @@
+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
+attributes.
+
+EXAMPLES
+--------
+
+Set smart controller temperature and spares threshold for DIMM-0 to 32C, spares
+threshold to 8, and enable the spares alarm.
+[verse]
+ndctl inject-smart --ctrl-temperature-threshold=32 --spares-threshold=8 --spares-alarm nmem0
+
+Inject a media temperature value of 52 and fatal health status flag for DIMM-0
+[verse]
+ndctl inject-smart --media-temperature=52 --health=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.
+
+-m::
+--media-temperature=::
+	Inject <value> for the media temperature smart attribute.
+
+-M::
+--media-temperature-threshold=::
+	Set <value> for the smart media temperature threshold.
+
+--media-temperature-alarm=::
+	Enable or disable the smart media temperature alarm. Options are
+	'on' or 'off'.
+
+-c::
+--ctrl-temperature=::
+	Inject <value> for the controller temperature smart attribute.
+
+-C::
+--ctrl-temperature-threshold=::
+	Set <value> for the smart controller temperature threshold.
+
+--ctrl-temperature-alarm=::
+	Enable or disable the smart controller temperature alarm. Options are
+	'on' or 'off'.
+
+-s::
+--spares=::
+	Inject <value> for the spares smart attribute.
+
+-S::
+--spares-threshold=::
+	Set <value> for the smart spares threshold.
+
+--spares-alarm=::
+	Enable or disable the smart spares alarm. Options are 'on' or 'off'.
+
+-H::
+--health=::
+	Smart attribute for health status. Provide either 'fatal' or 'nominal'
+	to set the state of the attribute.
+
+-U::
+--unsafe-shutdown=::
+	Set the flag to spoof an unsafe shutdown on the next power down.
+
+-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 +436 -0

436 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 v2 3/4] ndctl: add a new command - inject-smart

Quoted 106 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 | 102 +++++++
 builtin.h                                  |   1 +
 ndctl/Makefile.am                          |   3 +-
 ndctl/inject-smart.c                       | 436 +++++++++++++++++++++++++++++
 ndctl/ndctl.c                              |   1 +
 5 files changed, 542 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ndctl/ndctl-inject-smart.txt
 create mode 100644 ndctl/inject-smart.c

v2: Change inject-smart semantics to avoid sub-commands like --inject and --set. Instead allow injection and threshold setting all in one command by making each a distinct option. (Dan)

Documentation/ndctl/ndctl-inject-smart.txt new file +79 -0
new file mode 100644
index 0000000..212bca0
@@ -0,0 +1,102 @@
+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
+attributes.
+
+EXAMPLES
+--------
+
+Set smart controller temperature and spares threshold for DIMM-0 to 32C, spares
+threshold to 8, and enable the spares alarm.
+[verse]
+ndctl inject-smart --ctrl-temperature-threshold=32 --spares-threshold=8 --spares-alarm nmem0
+
+Inject a media temperature value of 52 and fatal health status flag for DIMM-0
+[verse]
+ndctl inject-smart --media-temperature=52 --health=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.
+
+-m::
+--media-temperature=::
+       Inject <value> for the media temperature smart attribute.
+
+-M::
+--media-temperature-threshold=::
+       Set <value> for the smart media temperature threshold.
+
+--media-temperature-alarm=::
+       Enable or disable the smart media temperature alarm. Options are
+       'on' or 'off'.
+
+-c::
+--ctrl-temperature=::
+       Inject <value> for the controller temperature smart attribute.
+
+-C::
+--ctrl-temperature-threshold=::
+       Set <value> for the smart controller temperature threshold.
+
+--ctrl-temperature-alarm=::
+       Enable or disable the smart controller temperature alarm. Options are
+       'on' or 'off'.
+
+-s::
+--spares=::
+       Inject <value> for the spares smart attribute.
+
+-S::
+--spares-threshold=::
+       Set <value> for the smart spares threshold.
+
+--spares-alarm=::
+       Enable or disable the smart spares alarm. Options are 'on' or 'off'.
+
+-H::
+--health=::

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

Quoted 10 lines
Documentation/ndctl/ndctl-inject-smart.txt new file +10 -0
+       Smart attribute for health status. Provide either 'fatal' or 'nominal'
+       to set the state of the attribute.
+
+-U::
+--unsafe-shutdown=::
+       Set the flag to spoof an unsafe shutdown on the next power down.
+
+-v::
+--verbose::
+       Emit debug messages for the error injection process

Nice, and I like your short option choices too.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#4 lore raw

PATCH v2 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 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
contrib/ndctl +11 -1
index eeda1c4..89e0252 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|--media-temperature|--ctrl-temperature|--spares|--media-temperature-threshold|--ctrl-temperature-threshold|--spares-threshold|--media-temperature-alarm|--ctrl-temperature-alarm|--spares-alarm) ]]; then
 			COMPREPLY[$i]="${cword}="
 		else
 			COMPREPLY[$i]="${cword} "
@@ -210,6 +210,13 @@ __ndctl_comp_options()
 		--label-version)
 			opts="1.1 1.2"
 			;;
+		--media-temperature-alarm)
+			;&
+		--ctrl-temperature-alarm)
+			;&
+		--spares-alarm)
+			opts="on off"
+			;;
 		*)
 			return
 			;;
@@ -262,6 +269,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