From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH v2 02/26] ndctl/dimm: Add --human support to read-labels
Date: Sat, 27 Jul 2019 14:39:31 -0700 [thread overview]
Message-ID: <156426357173.531577.2988157861473659679.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com>
Allow for easier comparisons between 'read-labels' output and list.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Documentation/ndctl/ndctl-read-labels.txt | 7 +++++++
ndctl/dimm.c | 20 ++++++++++++--------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/Documentation/ndctl/ndctl-read-labels.txt b/Documentation/ndctl/ndctl-read-labels.txt
index 0127e15f0721..756713ee12d7 100644
--- a/Documentation/ndctl/ndctl-read-labels.txt
+++ b/Documentation/ndctl/ndctl-read-labels.txt
@@ -27,6 +27,13 @@ include::labels-options.txt[]
parse the label data into json assuming the 'NVDIMM Namespace
Specification' format.
+-u::
+--human::
+ enable json output and convert number formats to human readable
+ strings, for example show the size in terms of "KB", "MB", "GB", etc
+ instead of a signed 64-bit numbers per the JSON interchange
+ format (implies --json).
+
include::../copyright.txt[]
SEE ALSO
diff --git a/ndctl/dimm.c b/ndctl/dimm.c
index 8946dc74fe41..5f05a75f00eb 100644
--- a/ndctl/dimm.c
+++ b/ndctl/dimm.c
@@ -51,6 +51,7 @@ static struct parameters {
bool overwrite;
bool zero_key;
bool master_pass;
+ bool human;
bool force;
bool json;
bool verbose;
@@ -80,7 +81,7 @@ static int action_zero(struct ndctl_dimm *dimm, struct action_context *actx)
}
static struct json_object *dump_label_json(struct ndctl_dimm *dimm,
- struct ndctl_cmd *cmd_read, ssize_t size)
+ struct ndctl_cmd *cmd_read, ssize_t size, unsigned long flags)
{
struct json_object *jarray = json_object_new_array();
struct json_object *jlabel = NULL;
@@ -141,12 +142,13 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,
break;
json_object_object_add(jlabel, "nlabel", jobj);
- jobj = json_object_new_int64(le64_to_cpu(nslabel.flags));
+ jobj = util_json_object_hex(le32_to_cpu(nslabel.flags), flags);
if (!jobj)
break;
json_object_object_add(jlabel, "flags", jobj);
- jobj = json_object_new_int64(le64_to_cpu(nslabel.isetcookie));
+ jobj = util_json_object_hex(le64_to_cpu(nslabel.isetcookie),
+ flags);
if (!jobj)
break;
json_object_object_add(jlabel, "isetcookie", jobj);
@@ -156,12 +158,12 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm,
break;
json_object_object_add(jlabel, "lbasize", jobj);
- jobj = json_object_new_int64(le64_to_cpu(nslabel.dpa));
+ jobj = util_json_object_hex(le64_to_cpu(nslabel.dpa), flags);
if (!jobj)
break;
json_object_object_add(jlabel, "dpa", jobj);
- jobj = json_object_new_int64(le64_to_cpu(nslabel.rawsize));
+ jobj = util_json_object_size(le64_to_cpu(nslabel.rawsize), flags);
if (!jobj)
break;
json_object_object_add(jlabel, "rawsize", jobj);
@@ -266,6 +268,7 @@ static struct json_object *dump_index_json(struct ndctl_cmd *cmd_read, ssize_t s
static struct json_object *dump_json(struct ndctl_dimm *dimm,
struct ndctl_cmd *cmd_read, ssize_t size)
{
+ unsigned long flags = param.human ? UTIL_JSON_HUMAN : 0;
struct json_object *jdimm = json_object_new_object();
struct json_object *jlabel, *jobj, *jindex;
@@ -274,7 +277,7 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm,
jindex = dump_index_json(cmd_read, size);
if (!jindex)
goto err_jindex;
- jlabel = dump_label_json(dimm, cmd_read, size);
+ jlabel = dump_label_json(dimm, cmd_read, size, flags);
if (!jlabel)
goto err_jlabel;
@@ -1046,7 +1049,8 @@ OPT_BOOLEAN('v',"verbose", ¶m.verbose, "turn on debug")
#define READ_OPTIONS() \
OPT_STRING('o', "output", ¶m.outfile, "output-file", \
"filename to write label area contents"), \
-OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json")
+OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json"), \
+OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats (implies --json)")
#define WRITE_OPTIONS() \
OPT_STRING('i', "input", ¶m.infile, "input-file", \
@@ -1156,7 +1160,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx,
return -EINVAL;
}
- if (param.json) {
+ if (param.json || param.human) {
actx.jdimms = json_object_new_array();
if (!actx.jdimms)
return -ENOMEM;
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next prev parent reply other threads:[~2019-07-27 21:56 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-27 21:39 [ndctl PATCH v2 00/26] Improvements for namespace creation/interrogation Dan Williams
2019-07-27 21:39 ` [ndctl PATCH v2 01/26] ndctl/dimm: Add 'flags' field to read-labels output Dan Williams
2019-08-02 18:01 ` Verma, Vishal L
2019-08-02 18:19 ` Dan Williams
2019-07-27 21:39 ` Dan Williams [this message]
2019-07-27 21:39 ` [ndctl PATCH v2 03/26] ndctl/build: Drop -Wpointer-arith Dan Williams
2019-07-27 21:39 ` [ndctl PATCH v2 04/26] ndctl/namespace: Add read-infoblock command Dan Williams
2019-07-27 21:39 ` [ndctl PATCH v2 05/26] ndctl/test: Update dax-dev to handle multiple e820 ranges Dan Williams
2019-07-27 21:39 ` [ndctl PATCH v2 06/26] ndctl/test: Make dax.sh more robust vs small namespaces Dan Williams
2019-07-27 21:39 ` [ndctl PATCH v2 07/26] ndctl/namespace: Always zero info-blocks Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 08/26] ndctl/dimm: Support small label reads/writes Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 09/26] ndctl/dimm: Minimize data-transfer for init-labels Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 10/26] ndctl/dimm: Add offset and size options to {read, write, zero}-labels Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 11/26] ndctl/dimm: Limit read-labels with --index option Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 12/26] ndctl/namespace: Minimize label data transfer for autolabel Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 13/26] ndctl/namespace: Disable autorecovery of create-namespace failures Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 14/26] ndctl/namespace: Handle 'create-namespace' in label-less mode Dan Williams
2019-08-21 12:56 ` Michal Suchánek
2019-08-21 18:03 ` Verma, Vishal L
2019-08-21 18:19 ` Michal Suchánek
2019-07-27 21:40 ` [ndctl PATCH v2 15/26] ndctl/dimm: Fix init-labels success reporting Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 16/26] ndctl/test: Fix device-dax bus-model detection Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 17/26] ndctl/test: Checkout device-mapper + dax operation Dan Williams
2019-07-27 21:40 ` [ndctl PATCH v2 18/26] ndctl/test: Exercise sub-section sized namespace creation/deletion Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 19/26] ndctl/namespace: Kill off the legacy mode names Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 20/26] ndctl/namespace: Introduce mode-to-name and name-to-mode helpers Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 21/26] ndctl/namespace: Validate namespace size within validate_namespace_options() Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 22/26] ndctl/namespace: Clarify 16M minimum size requirement Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 23/26] ndctl/namespace: Report ENOSPC when regions are full Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 24/26] ndctl/test: Regression test 'failed to track' Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 25/26] ndctl/namespace: Continue region search on 'missing seed' event Dan Williams
2019-07-27 21:41 ` [ndctl PATCH v2 26/26] ndctl/monitor: Allow monitor to be manually moved to the background 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=156426357173.531577.2988157861473659679.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).