All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: vishal.l.verma@intel.com
Cc: Alison Schofield <alison.schofield@intel.com>,
	nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: [ndctl PATCH 06/11] cxl/memdev: Fix json for multi-device partitioning
Date: Tue, 12 Jul 2022 12:07:58 -0700	[thread overview]
Message-ID: <165765287829.435671.4715059086458230262.stgit@dwillia2-xfh> (raw)
In-Reply-To: <165765284365.435671.13173937566404931163.stgit@dwillia2-xfh>

In the case when someone partitions several devices at once, collect all
the affected memdevs into a json array.

With the move to use util_display_json_array() that also requires a set of
flags to be specifiied. Apply the UTIL_JSON_HUMAN flag for all interactive
command result output to bring this command in line with other tools.

Cc: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 cxl/memdev.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/cxl/memdev.c b/cxl/memdev.c
index 91d914db5af6..9fcd8ae5724b 100644
--- a/cxl/memdev.c
+++ b/cxl/memdev.c
@@ -19,6 +19,7 @@
 struct action_context {
 	FILE *f_out;
 	FILE *f_in;
+	struct json_object *jdevs;
 };
 
 static struct parameters {
@@ -339,12 +340,13 @@ out:
 }
 
 static int action_setpartition(struct cxl_memdev *memdev,
-		struct action_context *actx)
+			       struct action_context *actx)
 {
 	const char *devname = cxl_memdev_get_devname(memdev);
 	enum cxl_setpart_type type = CXL_SETPART_PMEM;
 	unsigned long long size = ULLONG_MAX;
 	struct json_object *jmemdev;
+	unsigned long flags;
 	struct cxl_cmd *cmd;
 	int rc;
 
@@ -396,10 +398,12 @@ out_err:
 	if (rc)
 		log_err(&ml, "%s error: %s\n", devname, strerror(-rc));
 
-	jmemdev = util_cxl_memdev_to_json(memdev, UTIL_JSON_PARTITION);
-	if (jmemdev)
-		printf("%s\n", json_object_to_json_string_ext(jmemdev,
-		       JSON_C_TO_STRING_PRETTY));
+	flags = UTIL_JSON_PARTITION;
+	if (actx->f_out == stdout && isatty(1))
+		flags |= UTIL_JSON_HUMAN;
+	jmemdev = util_cxl_memdev_to_json(memdev, flags);
+	if (actx->jdevs && jmemdev)
+		json_object_array_add(actx->jdevs, jmemdev);
 
 	return rc;
 }
@@ -446,6 +450,9 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
 		err++;
 	}
 
+	if (action == action_setpartition)
+		actx.jdevs = json_object_new_array();
+
 	if (err == argc) {
 		usage_with_options(u, options);
 		return -EINVAL;
@@ -528,6 +535,15 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
 	if (actx.f_in != stdin)
 		fclose(actx.f_in);
 
+	if (actx.jdevs) {
+		unsigned long flags = 0;
+
+		if (actx.f_out == stdout && isatty(1))
+			flags |= UTIL_JSON_HUMAN;
+		util_display_json_array(actx.f_out, actx.jdevs, flags);
+	}
+
+
  out_close_fout:
 	if (actx.f_out != stdout)
 		fclose(actx.f_out);


  parent reply	other threads:[~2022-07-12 19:08 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 19:07 [ndctl PATCH 00/11] cxl: Region provisioning foundation Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 01/11] cxl/list: Reformat option list Dan Williams
2022-07-13 19:04   ` [PATCH 1/11] " Davidlohr Bueso
2022-07-12 19:07 ` [ndctl PATCH 02/11] cxl/list: Emit endpoint decoders filtered by memdev Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 03/11] cxl/list: Hide 0s in disabled decoder listings Dan Williams
2022-07-13 19:16   ` [PATCH 3/11] " Davidlohr Bueso
2022-07-12 19:07 ` [ndctl PATCH 04/11] cxl/list: Add DPA span to endpoint " Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 05/11] cxl/lib: Maintain decoders in id order Dan Williams
2022-07-13 14:44   ` Ira Weiny
2022-07-13 16:23     ` Dan Williams
2022-07-13 19:45   ` [PATCH 5/11] " Davidlohr Bueso
2022-07-13 23:14     ` Dan Williams
2022-07-12 19:07 ` Dan Williams [this message]
2022-07-12 19:08 ` [ndctl PATCH 07/11] cxl/list: Emit 'mode' for endpoint decoder objects Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 08/11] cxl/set-partition: Accept 'ram' as an alias for 'volatile' Dan Williams
2022-07-13 19:06   ` [PATCH 8/11] " Davidlohr Bueso
2022-07-12 19:08 ` [ndctl PATCH 09/11] cxl/memdev: Add {reserve,free}-dpa commands Dan Williams
2022-07-13  8:04   ` Verma, Vishal L
2022-07-13 15:22     ` Dan Williams
2022-07-13 15:44       ` Verma, Vishal L
2022-07-13 16:55         ` Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 10/11] cxl/test: Update CXL memory parameters Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 11/11] cxl/test: Checkout region setup/teardown Dan Williams
2022-07-13  7:47   ` Verma, Vishal L
2022-07-13 14:47     ` Dan Williams
2022-07-13 15:15       ` Verma, Vishal L
2022-07-13 16:53         ` 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=165765287829.435671.4715059086458230262.stgit@dwillia2-xfh \
    --to=dan.j.williams@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /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.