From patchwork Wed Oct 19 16:48:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9384889 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 5890E607D0 for ; Wed, 19 Oct 2016 16:51:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AA3828C36 for ; Wed, 19 Oct 2016 16:51:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FB5328D8F; Wed, 19 Oct 2016 16:51:25 +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 9CF7228C36 for ; Wed, 19 Oct 2016 16:51:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 903E11A1E6B; Wed, 19 Oct 2016 09:51:23 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 C83881A1E9B for ; Wed, 19 Oct 2016 09:51:22 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 19 Oct 2016 09:51:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,367,1473145200"; d="scan'208";a="21736047" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by orsmga004.jf.intel.com with ESMTP; 19 Oct 2016 09:51:22 -0700 Subject: [ndctl PATCH 6/8] ndctl: provide a read_labels() helper From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 19 Oct 2016 09:48:20 -0700 Message-ID: <147689570053.11015.1779678039898343821.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <147689566876.11015.13898062253087685236.stgit@dwillia2-desk3.amr.corp.intel.com> References: <147689566876.11015.13898062253087685236.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.21 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 In preparation for adding an 'init-labels' command, factor out the common portion of reading the label space from a dimm. Signed-off-by: Dan Williams --- ndctl/builtin-dimm.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/ndctl/builtin-dimm.c b/ndctl/builtin-dimm.c index 6d0c343a29e3..34ad1d9b47e7 100644 --- a/ndctl/builtin-dimm.c +++ b/ndctl/builtin-dimm.c @@ -284,46 +284,62 @@ static int dump_bin(FILE *f_out, struct ndctl_cmd *cmd_read, ssize_t size) return 0; } -static int action_read(struct ndctl_dimm *dimm, struct action_context *actx) +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; - ssize_t size; int rc; rc = ndctl_bus_wait_probe(bus); if (rc < 0) - return rc; + return NULL; cmd_size = ndctl_dimm_cmd_new_cfg_size(dimm); if (!cmd_size) - return -ENOTTY; + 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) { - rc = -ENOTTY; + if (!cmd_read) goto out_size; - } rc = ndctl_cmd_submit(cmd_read); if (rc || ndctl_cmd_get_firmware_status(cmd_read)) goto out_read; - size = ndctl_cmd_cfg_size_get_size(cmd_size); + 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_read(struct ndctl_dimm *dimm, struct action_context *actx) +{ + struct ndctl_cmd *cmd_read; + ssize_t size; + int rc = 0; + + cmd_read = read_labels(dimm); + if (!cmd_read) + return -ENXIO; + + size = ndctl_cmd_cfg_read_get_size(cmd_read); if (actx->jdimms) { struct json_object *jdimm = dump_json(dimm, cmd_read, size); - if (!jdimm) - return -ENOMEM; - json_object_array_add(actx->jdimms, jdimm); + + if (jdimm) + json_object_array_add(actx->jdimms, jdimm); + else + rc = -ENOMEM; } else rc = dump_bin(actx->f_out, cmd_read, size); - out_read: ndctl_cmd_unref(cmd_read); - out_size: - ndctl_cmd_unref(cmd_size); return rc; }