From: Joao Martins <joao.m.martins@oracle.com>
To: linux-nvdimm@lists.01.org
Cc: Joao Martins <joao.m.martins@oracle.com>
Subject: [PATCH daxctl v2 2/5] daxctl: include mappings when listing
Date: Fri, 18 Dec 2020 02:14:35 +0000 [thread overview]
Message-ID: <20201218021438.8926-3-joao.m.martins@oracle.com> (raw)
In-Reply-To: <20201218021438.8926-1-joao.m.martins@oracle.com>
Iterate over the device mappings and print @page_offset,
@start, @end and a computed size, but only if user
passes -M|--mappings to daxctl list as the output can
get verbose with a lot of mapping entries.
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
Documentation/daxctl/daxctl-list.txt | 4 +++
daxctl/list.c | 4 +++
util/json.c | 57 +++++++++++++++++++++++++++++++++++-
util/json.h | 4 +++
4 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/Documentation/daxctl/daxctl-list.txt b/Documentation/daxctl/daxctl-list.txt
index cb82c3cc6fb2..5a6a98e73849 100644
--- a/Documentation/daxctl/daxctl-list.txt
+++ b/Documentation/daxctl/daxctl-list.txt
@@ -67,6 +67,10 @@ OPTIONS
--devices::
Include device-dax instance info in the listing (default)
+-M::
+--mappings::
+ Include device-dax instance mappings info in the listing
+
-R::
--regions::
Include region info in the listing
diff --git a/daxctl/list.c b/daxctl/list.c
index 6c6251b4de37..6860a460e4c0 100644
--- a/daxctl/list.c
+++ b/daxctl/list.c
@@ -25,6 +25,7 @@
static struct {
bool devs;
bool regions;
+ bool mappings;
bool idle;
bool human;
} list;
@@ -35,6 +36,8 @@ static unsigned long listopts_to_flags(void)
if (list.devs)
flags |= UTIL_JSON_DAX_DEVS;
+ if (list.mappings)
+ flags |= UTIL_JSON_DAX_MAPPINGS;
if (list.idle)
flags |= UTIL_JSON_IDLE;
if (list.human)
@@ -70,6 +73,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx)
"filter by dax device instance name"),
OPT_BOOLEAN('D', "devices", &list.devs, "include dax device info"),
OPT_BOOLEAN('R', "regions", &list.regions, "include dax region info"),
+ OPT_BOOLEAN('M', "mappings", &list.mappings, "include dax mappings info"),
OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
OPT_BOOLEAN('u', "human", &list.human,
"use human friendly number formats "),
diff --git a/util/json.c b/util/json.c
index 357dff20d6be..dcc927294e4f 100644
--- a/util/json.c
+++ b/util/json.c
@@ -454,7 +454,8 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,
{
struct daxctl_memory *mem = daxctl_dev_get_memory(dev);
const char *devname = daxctl_dev_get_devname(dev);
- struct json_object *jdev, *jobj;
+ struct json_object *jdev, *jobj, *jmappings = NULL;
+ struct daxctl_mapping *mapping = NULL;
int node, movable, align;
jdev = json_object_new_object();
@@ -508,6 +509,25 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,
json_object_object_add(jdev, "state", jobj);
}
+ if (!(flags & UTIL_JSON_DAX_MAPPINGS))
+ return jdev;
+
+ daxctl_mapping_foreach(dev, mapping) {
+ struct json_object *jmapping;
+
+ if (!jmappings) {
+ jmappings = json_object_new_array();
+ if (!jmappings)
+ continue;
+
+ json_object_object_add(jdev, "mappings", jmappings);
+ }
+
+ jmapping = util_daxctl_mapping_to_json(mapping, flags);
+ if (!jmapping)
+ continue;
+ json_object_array_add(jmappings, jmapping);
+ }
return jdev;
}
@@ -1357,6 +1377,41 @@ struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping,
return NULL;
}
+struct json_object *util_daxctl_mapping_to_json(struct daxctl_mapping *mapping,
+ unsigned long flags)
+{
+ struct json_object *jmapping = json_object_new_object();
+ struct json_object *jobj;
+
+ if (!jmapping)
+ return NULL;
+
+ jobj = util_json_object_hex(daxctl_mapping_get_offset(mapping), flags);
+ if (!jobj)
+ goto err;
+ json_object_object_add(jmapping, "page_offset", jobj);
+
+ jobj = util_json_object_hex(daxctl_mapping_get_start(mapping), flags);
+ if (!jobj)
+ goto err;
+ json_object_object_add(jmapping, "start", jobj);
+
+ jobj = util_json_object_hex(daxctl_mapping_get_end(mapping), flags);
+ if (!jobj)
+ goto err;
+ json_object_object_add(jmapping, "end", jobj);
+
+ jobj = util_json_object_size(daxctl_mapping_get_size(mapping), flags);
+ if (!jobj)
+ goto err;
+ json_object_object_add(jmapping, "size", jobj);
+
+ return jmapping;
+ err:
+ json_object_put(jmapping);
+ return NULL;
+}
+
struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
unsigned long flags)
{
diff --git a/util/json.h b/util/json.h
index 39a33789bac9..e26875a5ecd8 100644
--- a/util/json.h
+++ b/util/json.h
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <ndctl/libndctl.h>
+#include <daxctl/libdaxctl.h>
#include <ccan/short_types/short_types.h>
enum util_json_flags {
@@ -27,6 +28,7 @@ enum util_json_flags {
UTIL_JSON_CAPABILITIES = (1 << 6),
UTIL_JSON_CONFIGURED = (1 << 7),
UTIL_JSON_FIRMWARE = (1 << 8),
+ UTIL_JSON_DAX_MAPPINGS = (1 << 9),
};
struct json_object;
@@ -38,6 +40,8 @@ struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm,
unsigned long flags);
struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping,
unsigned long flags);
+struct json_object *util_daxctl_mapping_to_json(struct daxctl_mapping *mapping,
+ unsigned long flags);
struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
unsigned long flags);
struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
--
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2020-12-18 2:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 2:14 [PATCH daxctl v2 0/5] daxctl: range mapping allocation Joao Martins
2020-12-18 2:14 ` [PATCH daxctl v2 1/5] libdaxctl: add mapping iterator APIs Joao Martins
2020-12-18 2:14 ` Joao Martins [this message]
2020-12-18 2:14 ` [PATCH daxctl v2 3/5] libdaxctl: add daxctl_dev_set_mapping() Joao Martins
2020-12-18 2:14 ` [PATCH daxctl v2 4/5] daxctl: allow creating devices from input json Joao Martins
2020-12-18 2:14 ` [PATCH daxctl v2 5/5] daxctl/test: add a test for daxctl-create with input file Joao Martins
2020-12-19 8:21 ` [PATCH daxctl v2 0/5] daxctl: range mapping allocation Verma, Vishal L
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=20201218021438.8926-3-joao.m.martins@oracle.com \
--to=joao.m.martins@oracle.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