From patchwork Fri Dec 1 23:25:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10088295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9BD8E6035E for ; Fri, 1 Dec 2017 23:34:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A7D32A7B3 for ; Fri, 1 Dec 2017 23:34:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F3602A7C7; Fri, 1 Dec 2017 23:34:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 398D02A7B3 for ; Fri, 1 Dec 2017 23:34:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3322C21A1098B; Fri, 1 Dec 2017 15:29:33 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A38EB21A10961 for ; Fri, 1 Dec 2017 15:29:31 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Dec 2017 15:33:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,347,1508828400"; d="scan'208";a="9508746" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga001.fm.intel.com with ESMTP; 01 Dec 2017 15:33:58 -0800 Subject: [ndctl PATCH 14/17] ndctl, smart: move smart temperature parsing to a library routine From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 01 Dec 2017 15:25:44 -0800 Message-ID: <151217074412.28402.914175135907454573.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <151217066885.28402.7962437173336388439.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151217066885.28402.7962437173336388439.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 8471dd8c4f89..01788f47fbd0 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -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; /** diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 6d9a04282c7d..2ace9420b158 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -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; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 0dfd373e7897..e9da20e57f32 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -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); diff --git a/ndctl/util/json-smart.c b/ndctl/util/json-smart.c index 7aabf4f3aebe..4020423bb8c8 100644 --- a/ndctl/util/json-smart.c +++ b/ndctl/util/json-smart.c @@ -18,19 +18,6 @@ #include #include -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)