@@ -74,6 +74,19 @@ NDCTL_EXPORT size_t ndctl_sizeof_namespace_label(void)
return offsetof(struct namespace_label, type_guid);
}
+NDCTL_EXPORT double ndctl_decode_smart_temperature(unsigned int temp)
+{
+ bool negative = !!(temp & (1 << 15));
+ double t;
+
+ temp &= ~(1 << 15);
+ t = temp;
+ t /= 16;
+ if (negative)
+ t *= -1;
+ return t;
+}
+
struct ndctl_ctx;
/**
@@ -321,4 +321,5 @@ global:
ndctl_cmd_smart_threshold_set_media_temperature;
ndctl_cmd_smart_threshold_set_ctrl_temperature;
ndctl_cmd_smart_threshold_set_spares;
+ ndctl_decode_smart_temperature;
} LIBNDCTL_13;
@@ -74,6 +74,7 @@ extern "C" {
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);
struct ndctl_ctx;
struct ndctl_ctx *ndctl_ref(struct ndctl_ctx *ctx);
@@ -18,19 +18,6 @@
#include <ccan/array_size/array_size.h>
#include <ndctl.h>
-static double parse_smart_temperature(unsigned int temp)
-{
- bool negative = !!(temp & (1 << 15));
- double t;
-
- temp &= ~(1 << 15);
- t = temp;
- t /= 16;
- if (negative)
- t *= -1;
- return t;
-}
-
static void smart_threshold_to_json(struct ndctl_dimm *dimm,
struct json_object *jhealth)
{
@@ -53,7 +40,7 @@ static void smart_threshold_to_json(struct ndctl_dimm *dimm,
double t;
temp = ndctl_cmd_smart_threshold_get_temperature(cmd);
- t = parse_smart_temperature(temp);
+ t = ndctl_decode_smart_temperature(temp);
jobj = json_object_new_double(t);
if (jobj)
json_object_object_add(jhealth,
@@ -115,7 +102,7 @@ struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm)
if (flags & ND_SMART_TEMP_VALID) {
unsigned int temp = ndctl_cmd_smart_get_temperature(cmd);
- double t = parse_smart_temperature(temp);
+ double t = ndctl_decode_smart_temperature(temp);
jobj = json_object_new_double(t);
if (jobj)
Similar to the 'ndctl list' command, consumers of the smart apis need to be able to convert the encoded smart temperature to a number. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- ndctl/lib/libndctl.c | 13 +++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + ndctl/util/json-smart.c | 17 ++--------------- 4 files changed, 17 insertions(+), 15 deletions(-)