All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 6/8] ndctl: provide a read_labels() helper
Date: Wed, 19 Oct 2016 09:48:20 -0700	[thread overview]
Message-ID: <147689570053.11015.1779678039898343821.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <147689566876.11015.13898062253087685236.stgit@dwillia2-desk3.amr.corp.intel.com>

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 <dan.j.williams@intel.com>
---
 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;
 }

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  parent reply	other threads:[~2016-10-19 16:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-19 16:47 [ndctl PATCH 0/8] dimm label space initialization support Dan Williams
2016-10-19 16:47 ` [Qemu-devel] " Dan Williams
2016-10-19 16:47 ` [ndctl PATCH 1/8] libndctl: fix error returns for unsigned apis Dan Williams
2016-10-19 16:47 ` [ndctl PATCH 2/8] ndctl: consolidate label commands into a single file Dan Williams
2016-10-19 16:48 ` [ndctl PATCH 3/8] ndctl: glob support for label commands Dan Williams
2016-10-19 16:48 ` [ndctl PATCH 4/8] ndctl: merge {enable, disable}-dimm with " Dan Williams
2016-10-19 16:48 ` [ndctl PATCH 5/8] libndctl: add ndctl_cmd_cfg_read_get_size() Dan Williams
2016-10-19 16:48 ` Dan Williams [this message]
2016-10-19 16:48 ` [ndctl PATCH 7/8] ndctl: init-labels command Dan Williams
2016-10-19 16:48   ` [Qemu-devel] " Dan Williams
2016-10-19 16:48 ` [ndctl PATCH 8/8] ndctl: check-labels command Dan Williams
2016-10-19 18:42 ` [ndctl PATCH 0/8] dimm label space initialization support Eric Blake
2016-10-19 18:42   ` [Qemu-devel] " Eric Blake
     [not found]   ` <6ceb7075-71fc-b725-8a1c-a7d8c727770e-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-10-19 19:41     ` Dan Williams
2016-10-19 19:41       ` Dan Williams
     [not found]       ` <CAPcyv4gbRE-ALJM6EHv6fM3Kq02HeZFMLF5T63J5qaJmHWvQCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-10-19 21:29         ` Dan Williams
2016-10-19 21:29           ` Dan Williams
2016-10-19 23:46           ` Eric Blake
2016-10-19 23:46             ` [Qemu-devel] " Eric Blake
     [not found]             ` <708947f5-dfdc-d6c9-4523-7436959119f3-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-10-19 23:56               ` Dan Williams
2016-10-19 23:56                 ` Dan Williams
2016-10-20 19:32 ` Vishal Verma
2016-10-20 19:32   ` [Qemu-devel] " Vishal Verma
2016-10-20 20:06   ` Dan Williams
2016-10-20 20:06     ` [Qemu-devel] " Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=147689570053.11015.1779678039898343821.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.