|
|
e0018b |
From 8ed95d22504d7b2b258d1800878e32c162badf8c Mon Sep 17 00:00:00 2001
|
|
|
e0018b |
From: Dan Williams <dan.j.williams@intel.com>
|
|
|
e0018b |
Date: Thu, 14 Jul 2022 10:02:27 -0700
|
|
|
e0018b |
Subject: [PATCH 181/217] cxl/memdev: Fix json for multi-device partitioning
|
|
|
e0018b |
|
|
|
e0018b |
In the case when someone partitions several devices at once, collect all
|
|
|
e0018b |
the affected memdevs into a json array.
|
|
|
e0018b |
|
|
|
e0018b |
With the move to use util_display_json_array() that also requires a set of
|
|
|
e0018b |
flags to be specifiied. Apply the UTIL_JSON_HUMAN flag for all interactive
|
|
|
e0018b |
command result output to bring this command in line with other tools.
|
|
|
e0018b |
|
|
|
e0018b |
Link: https://lore.kernel.org/r/165781814737.1555691.889129128205037941.stgit@dwillia2-xfh.jf.intel.com
|
|
|
e0018b |
Cc: Alison Schofield <alison.schofield@intel.com>
|
|
|
e0018b |
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
|
|
|
e0018b |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
e0018b |
---
|
|
|
e0018b |
cxl/memdev.c | 26 +++++++++++++++++++++-----
|
|
|
e0018b |
1 file changed, 21 insertions(+), 5 deletions(-)
|
|
|
e0018b |
|
|
|
e0018b |
diff --git a/cxl/memdev.c b/cxl/memdev.c
|
|
|
e0018b |
index 91d914d..9fcd8ae 100644
|
|
|
e0018b |
--- a/cxl/memdev.c
|
|
|
e0018b |
+++ b/cxl/memdev.c
|
|
|
e0018b |
@@ -19,6 +19,7 @@
|
|
|
e0018b |
struct action_context {
|
|
|
e0018b |
FILE *f_out;
|
|
|
e0018b |
FILE *f_in;
|
|
|
e0018b |
+ struct json_object *jdevs;
|
|
|
e0018b |
};
|
|
|
e0018b |
|
|
|
e0018b |
static struct parameters {
|
|
|
e0018b |
@@ -339,12 +340,13 @@ out:
|
|
|
e0018b |
}
|
|
|
e0018b |
|
|
|
e0018b |
static int action_setpartition(struct cxl_memdev *memdev,
|
|
|
e0018b |
- struct action_context *actx)
|
|
|
e0018b |
+ struct action_context *actx)
|
|
|
e0018b |
{
|
|
|
e0018b |
const char *devname = cxl_memdev_get_devname(memdev);
|
|
|
e0018b |
enum cxl_setpart_type type = CXL_SETPART_PMEM;
|
|
|
e0018b |
unsigned long long size = ULLONG_MAX;
|
|
|
e0018b |
struct json_object *jmemdev;
|
|
|
e0018b |
+ unsigned long flags;
|
|
|
e0018b |
struct cxl_cmd *cmd;
|
|
|
e0018b |
int rc;
|
|
|
e0018b |
|
|
|
e0018b |
@@ -396,10 +398,12 @@ out_err:
|
|
|
e0018b |
if (rc)
|
|
|
e0018b |
log_err(&ml, "%s error: %s\n", devname, strerror(-rc));
|
|
|
e0018b |
|
|
|
e0018b |
- jmemdev = util_cxl_memdev_to_json(memdev, UTIL_JSON_PARTITION);
|
|
|
e0018b |
- if (jmemdev)
|
|
|
e0018b |
- printf("%s\n", json_object_to_json_string_ext(jmemdev,
|
|
|
e0018b |
- JSON_C_TO_STRING_PRETTY));
|
|
|
e0018b |
+ flags = UTIL_JSON_PARTITION;
|
|
|
e0018b |
+ if (actx->f_out == stdout && isatty(1))
|
|
|
e0018b |
+ flags |= UTIL_JSON_HUMAN;
|
|
|
e0018b |
+ jmemdev = util_cxl_memdev_to_json(memdev, flags);
|
|
|
e0018b |
+ if (actx->jdevs && jmemdev)
|
|
|
e0018b |
+ json_object_array_add(actx->jdevs, jmemdev);
|
|
|
e0018b |
|
|
|
e0018b |
return rc;
|
|
|
e0018b |
}
|
|
|
e0018b |
@@ -446,6 +450,9 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
|
|
|
e0018b |
err++;
|
|
|
e0018b |
}
|
|
|
e0018b |
|
|
|
e0018b |
+ if (action == action_setpartition)
|
|
|
e0018b |
+ actx.jdevs = json_object_new_array();
|
|
|
e0018b |
+
|
|
|
e0018b |
if (err == argc) {
|
|
|
e0018b |
usage_with_options(u, options);
|
|
|
e0018b |
return -EINVAL;
|
|
|
e0018b |
@@ -528,6 +535,15 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx,
|
|
|
e0018b |
if (actx.f_in != stdin)
|
|
|
e0018b |
fclose(actx.f_in);
|
|
|
e0018b |
|
|
|
e0018b |
+ if (actx.jdevs) {
|
|
|
e0018b |
+ unsigned long flags = 0;
|
|
|
e0018b |
+
|
|
|
e0018b |
+ if (actx.f_out == stdout && isatty(1))
|
|
|
e0018b |
+ flags |= UTIL_JSON_HUMAN;
|
|
|
e0018b |
+ util_display_json_array(actx.f_out, actx.jdevs, flags);
|
|
|
e0018b |
+ }
|
|
|
e0018b |
+
|
|
|
e0018b |
+
|
|
|
e0018b |
out_close_fout:
|
|
|
e0018b |
if (actx.f_out != stdout)
|
|
|
e0018b |
fclose(actx.f_out);
|
|
|
e0018b |
--
|
|
|
e0018b |
2.27.0
|
|
|
e0018b |
|