From patchwork Tue Aug 29 20:01:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9928215 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 427D5603B4 for ; Tue, 29 Aug 2017 20:09:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34999285DA for ; Tue, 29 Aug 2017 20:09:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29880286BC; Tue, 29 Aug 2017 20:09:22 +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 6C19C285E5 for ; Tue, 29 Aug 2017 20:09:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 19EC321D1E2F4; Tue, 29 Aug 2017 13:05:42 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 3F74721CE748D for ; Tue, 29 Aug 2017 13:05:41 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2017 13:08:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,445,1498546800"; d="scan'208";a="145325384" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga005.fm.intel.com with ESMTP; 29 Aug 2017 13:08:21 -0700 Subject: [ndctl PATCH 5/7] ndctl: refactor read_labels() helper into a library call From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 29 Aug 2017 13:01:57 -0700 Message-ID: <150403691762.8240.16085152850679077792.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <150403689024.8240.10207637569759874850.stgit@dwillia2-desk3.amr.corp.intel.com> References: <150403689024.8240.10207637569759874850.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 As a pre-requisite to making an "init labels" library call, refactor label reading into a generic helper call. Signed-off-by: Dan Williams --- ndctl/dimm.c | 40 ++---------------------------- ndctl/lib/dimm.c | 64 ++++++++++++++++++++++++++++++------------------ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h.in | 1 + 4 files changed, 45 insertions(+), 61 deletions(-) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 4a39189297a6..ca7b833db182 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -358,40 +358,6 @@ static int rw_bin(FILE *f, struct ndctl_cmd *cmd, ssize_t size, int rw) return 0; } -static struct ndctl_cmd *read_labels(struct ndctl_dimm *dimm) -{ - struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); - struct ndctl_cmd *cmd_size, *cmd_read; - int rc; - - rc = ndctl_bus_wait_probe(bus); - if (rc < 0) - return NULL; - - cmd_size = ndctl_dimm_cmd_new_cfg_size(dimm); - if (!cmd_size) - return NULL; - rc = ndctl_cmd_submit(cmd_size); - if (rc || ndctl_cmd_get_firmware_status(cmd_size)) - goto out_size; - - cmd_read = ndctl_dimm_cmd_new_cfg_read(cmd_size); - if (!cmd_read) - goto out_size; - rc = ndctl_cmd_submit(cmd_read); - if (rc || ndctl_cmd_get_firmware_status(cmd_read)) - goto out_read; - - ndctl_cmd_unref(cmd_size); - return cmd_read; - - out_read: - ndctl_cmd_unref(cmd_read); - out_size: - ndctl_cmd_unref(cmd_size); - return NULL; -} - static int action_write(struct ndctl_dimm *dimm, struct action_context *actx) { struct ndctl_cmd *cmd_read, *cmd_write; @@ -403,7 +369,7 @@ static int action_write(struct ndctl_dimm *dimm, struct action_context *actx) return -EBUSY; } - cmd_read = read_labels(dimm); + cmd_read = ndctl_dimm_read_labels(dimm); if (!cmd_read) return -ENXIO; @@ -441,7 +407,7 @@ static int action_read(struct ndctl_dimm *dimm, struct action_context *actx) ssize_t size; int rc = 0; - cmd_read = read_labels(dimm); + cmd_read = ndctl_dimm_read_labels(dimm); if (!cmd_read) return -ENXIO; @@ -794,7 +760,7 @@ static int __action_init(struct ndctl_dimm *dimm, int version, int chk_only) int rc = 0, i; ssize_t size; - cmd_read = read_labels(dimm); + cmd_read = ndctl_dimm_read_labels(dimm); if (!cmd_read) return -ENXIO; diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c index 1c613a470099..f7696af04ba2 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -15,38 +15,56 @@ #include #include "private.h" +NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) +{ + struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); + struct ndctl_cmd *cmd_size, *cmd_read; + int rc; + + rc = ndctl_bus_wait_probe(bus); + if (rc < 0) + return NULL; + + cmd_size = ndctl_dimm_cmd_new_cfg_size(dimm); + if (!cmd_size) + return NULL; + rc = ndctl_cmd_submit(cmd_size); + if (rc || ndctl_cmd_get_firmware_status(cmd_size)) + goto out_size; + + cmd_read = ndctl_dimm_cmd_new_cfg_read(cmd_size); + if (!cmd_read) + goto out_size; + rc = ndctl_cmd_submit(cmd_read); + if (rc || ndctl_cmd_get_firmware_status(cmd_read)) + goto out_read; + + ndctl_cmd_unref(cmd_size); + return cmd_read; + + out_read: + ndctl_cmd_unref(cmd_read); + out_size: + ndctl_cmd_unref(cmd_size); + return NULL; +} + NDCTL_EXPORT int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm) { - struct ndctl_cmd *cmd_size, *cmd_read, *cmd_write; struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); - struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); + struct ndctl_cmd *cmd_read, *cmd_write; int rc; - rc = ndctl_bus_wait_probe(bus); - if (rc < 0) - return rc; + cmd_read = ndctl_dimm_read_labels(dimm); + if (!cmd_read) + return -ENXIO; if (ndctl_dimm_is_active(dimm)) { dbg(ctx, "%s: regions active, abort label write\n", ndctl_dimm_get_devname(dimm)); - return -EBUSY; - } - - cmd_size = ndctl_dimm_cmd_new_cfg_size(dimm); - if (!cmd_size) - return -ENOTTY; - rc = ndctl_cmd_submit(cmd_size); - if (rc || ndctl_cmd_get_firmware_status(cmd_size)) - goto out_size; - - cmd_read = ndctl_dimm_cmd_new_cfg_read(cmd_size); - if (!cmd_read) { - rc = -ENOTTY; - goto out_size; - } - rc = ndctl_cmd_submit(cmd_read); - if (rc || ndctl_cmd_get_firmware_status(cmd_read)) + rc = -EBUSY; goto out_read; + } cmd_write = ndctl_dimm_cmd_new_cfg_write(cmd_read); if (!cmd_write) { @@ -77,8 +95,6 @@ NDCTL_EXPORT int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm) ndctl_cmd_unref(cmd_write); out_read: ndctl_cmd_unref(cmd_read); - out_size: - ndctl_cmd_unref(cmd_size); return rc; } diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index b8ac65f2917f..95c6e400124d 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -113,6 +113,7 @@ global: ndctl_cmd_smart_threshold_get_temperature; ndctl_cmd_smart_threshold_get_spares; ndctl_dimm_zero_labels; + ndctl_dimm_read_labels; ndctl_dimm_get_available_labels; ndctl_region_get_first; ndctl_region_get_next; diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in index 855d883c3380..9be380b8a735 100644 --- a/ndctl/libndctl.h.in +++ b/ndctl/libndctl.h.in @@ -358,6 +358,7 @@ struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_size(struct ndctl_dimm *dimm); struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_read(struct ndctl_cmd *cfg_size); struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_write(struct ndctl_cmd *cfg_read); int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm); +struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm); unsigned long ndctl_dimm_get_available_labels(struct ndctl_dimm *dimm); unsigned int ndctl_cmd_cfg_size_get_size(struct ndctl_cmd *cfg_size); ssize_t ndctl_cmd_cfg_read_get_data(struct ndctl_cmd *cfg_read, void *buf,