anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0135-cxl-add-memdev-partition-information-to-cxl-list.patch

e0018b
From 033b94ad7346a82504cffba3d87650b60945c1eb Mon Sep 17 00:00:00 2001
e0018b
From: Alison Schofield <alison.schofield@intel.com>
e0018b
Date: Tue, 22 Feb 2022 11:56:06 -0800
e0018b
Subject: [PATCH 135/217] cxl: add memdev partition information to cxl-list
e0018b
e0018b
The CXL PMEM provisioning model depends upon the values reported in
e0018b
both the CXL IDENTIFY and GET_PARTITION_INFO mailbox commands when
e0018b
changing the partitioning between volatile and persistent capacity.
e0018b
e0018b
Add an option to the 'cxl list' command to display partition information.
e0018b
e0018b
Include the partitioning related fields from the IDENTIFY command:
e0018b
total, volatile_only, persistent_only, and partition_alignment sizes.
e0018b
When the partition_alignment size is greater than zero, indicating
e0018b
partitionable capacity, include the active and next size fields of
e0018b
GET_PARTITION_INFO.
e0018b
e0018b
Example:
e0018b
    "partition_info":{
e0018b
      "total_size":273535729664,
e0018b
      "volatile_only_size":0,
e0018b
      "persistent_only_size":0,
e0018b
      "partition_alignment_size":268435456
e0018b
      "active_volatile_size":273535729664,
e0018b
      "active_persistent_size":0,
e0018b
      "next_volatile_size":0,
e0018b
      "next_persistent_size":0,
e0018b
    }
e0018b
e0018b
Link: https://lore.kernel.org/r/70cc57379d2c49692036b1daa158a122aa19c126.1645558189.git.alison.schofield@intel.com
e0018b
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 Documentation/cxl/cxl-list.txt |  23 +++++++
e0018b
 cxl/filter.c                   |   2 +
e0018b
 cxl/filter.h                   |   1 +
e0018b
 cxl/json.c                     | 120 +++++++++++++++++++++++++++++++++
e0018b
 cxl/list.c                     |   2 +
e0018b
 util/json.h                    |   1 +
e0018b
 6 files changed, 149 insertions(+)
e0018b
e0018b
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
e0018b
index 90e6d9f..f6aba0c 100644
e0018b
--- a/Documentation/cxl/cxl-list.txt
e0018b
+++ b/Documentation/cxl/cxl-list.txt
e0018b
@@ -196,6 +196,29 @@ OPTIONS
e0018b
   }
e0018b
 ]
e0018b
 ----
e0018b
+-I::
e0018b
+--partition::
e0018b
+	Include partition information in the memdev listing. Example listing:
e0018b
+----
e0018b
+# cxl list -m mem0 -I
e0018b
+[
e0018b
+  {
e0018b
+    "memdev":"mem0",
e0018b
+    "pmem_size":0,
e0018b
+    "ram_size":273535729664,
e0018b
+    "partition_info":{
e0018b
+      "total_size":273535729664,
e0018b
+      "volatile_only_size":0,
e0018b
+      "persistent_only_size":0,
e0018b
+      "partition_alignment_size":268435456
e0018b
+      "active_volatile_size":273535729664,
e0018b
+      "active_persistent_size":0,
e0018b
+      "next_volatile_size":0,
e0018b
+      "next_persistent_size":0,
e0018b
+    }
e0018b
+  }
e0018b
+]
e0018b
+----
e0018b
 
e0018b
 -B::
e0018b
 --buses::
e0018b
diff --git a/cxl/filter.c b/cxl/filter.c
e0018b
index 925bf3a..b339642 100644
e0018b
--- a/cxl/filter.c
e0018b
+++ b/cxl/filter.c
e0018b
@@ -581,6 +581,8 @@ static unsigned long params_to_flags(struct cxl_filter_params *param)
e0018b
 		flags |= UTIL_JSON_HEALTH;
e0018b
 	if (param->targets)
e0018b
 		flags |= UTIL_JSON_TARGETS;
e0018b
+	if (param->partition)
e0018b
+		flags |= UTIL_JSON_PARTITION;
e0018b
 	return flags;
e0018b
 }
e0018b
 
e0018b
diff --git a/cxl/filter.h b/cxl/filter.h
e0018b
index 5deabb3..697b777 100644
e0018b
--- a/cxl/filter.h
e0018b
+++ b/cxl/filter.h
e0018b
@@ -23,6 +23,7 @@ struct cxl_filter_params {
e0018b
 	bool idle;
e0018b
 	bool human;
e0018b
 	bool health;
e0018b
+	bool partition;
e0018b
 	struct log_ctx ctx;
e0018b
 };
e0018b
 
e0018b
diff --git a/cxl/json.c b/cxl/json.c
e0018b
index f3b536e..fdc6f73 100644
e0018b
--- a/cxl/json.c
e0018b
+++ b/cxl/json.c
e0018b
@@ -185,6 +185,121 @@ err_jobj:
e0018b
 	return NULL;
e0018b
 }
e0018b
 
e0018b
+/*
e0018b
+ * Present complete view of memdev partition by presenting fields from
e0018b
+ * both GET_PARTITION_INFO and IDENTIFY mailbox commands.
e0018b
+ */
e0018b
+static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *memdev,
e0018b
+		unsigned long flags)
e0018b
+{
e0018b
+	struct json_object *jobj = NULL;
e0018b
+	struct json_object *jpart;
e0018b
+	unsigned long long cap;
e0018b
+	struct cxl_cmd *cmd;
e0018b
+	int rc;
e0018b
+
e0018b
+	jpart = json_object_new_object();
e0018b
+	if (!jpart)
e0018b
+		return NULL;
e0018b
+	if (!memdev)
e0018b
+		goto err_jobj;
e0018b
+
e0018b
+	/* Retrieve partition info in the IDENTIFY mbox cmd */
e0018b
+	cmd = cxl_cmd_new_identify(memdev);
e0018b
+	if (!cmd)
e0018b
+		goto err_jobj;
e0018b
+
e0018b
+	rc = cxl_cmd_submit(cmd);
e0018b
+	if (rc < 0)
e0018b
+		goto err_identify;
e0018b
+	rc = cxl_cmd_get_mbox_status(cmd);
e0018b
+	if (rc != 0)
e0018b
+		goto err_identify;
e0018b
+
e0018b
+	cap = cxl_cmd_identify_get_total_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart, "total_size", jobj);
e0018b
+	}
e0018b
+	cap = cxl_cmd_identify_get_volatile_only_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart,
e0018b
+					"volatile_only_size", jobj);
e0018b
+	}
e0018b
+	cap = cxl_cmd_identify_get_persistent_only_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart,
e0018b
+					"persistent_only_size", jobj);
e0018b
+	}
e0018b
+	cap = cxl_cmd_identify_get_partition_align(cmd);
e0018b
+	jobj = util_json_object_size(cap, flags);
e0018b
+	if (jobj)
e0018b
+		json_object_object_add(jpart, "partition_alignment_size", jobj);
e0018b
+
e0018b
+	cxl_cmd_unref(cmd);
e0018b
+
e0018b
+	/* Return now if there is no partition info to get. */
e0018b
+	if (!cap)
e0018b
+		return jpart;
e0018b
+
e0018b
+	/* Retrieve partition info in GET_PARTITION_INFO mbox cmd */
e0018b
+	cmd = cxl_cmd_new_get_partition(memdev);
e0018b
+	if (!cmd)
e0018b
+		return jpart;
e0018b
+
e0018b
+	rc = cxl_cmd_submit(cmd);
e0018b
+	if (rc < 0)
e0018b
+		goto err_get;
e0018b
+	rc = cxl_cmd_get_mbox_status(cmd);
e0018b
+	if (rc != 0)
e0018b
+		goto err_get;
e0018b
+
e0018b
+	cap = cxl_cmd_partition_get_active_volatile_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart,
e0018b
+					"active_volatile_size", jobj);
e0018b
+	}
e0018b
+	cap = cxl_cmd_partition_get_active_persistent_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart,
e0018b
+					"active_persistent_size", jobj);
e0018b
+	}
e0018b
+	cap = cxl_cmd_partition_get_next_volatile_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart,
e0018b
+					"next_volatile_size", jobj);
e0018b
+	}
e0018b
+	cap = cxl_cmd_partition_get_next_persistent_size(cmd);
e0018b
+	if (cap != ULLONG_MAX) {
e0018b
+		jobj = util_json_object_size(cap, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jpart,
e0018b
+					"next_persistent_size", jobj);
e0018b
+	}
e0018b
+
e0018b
+err_get:
e0018b
+	cxl_cmd_unref(cmd);
e0018b
+	return jpart;
e0018b
+
e0018b
+err_identify:
e0018b
+	cxl_cmd_unref(cmd);
e0018b
+
e0018b
+err_jobj:
e0018b
+	json_object_put(jpart);
e0018b
+	return NULL;
e0018b
+}
e0018b
+
e0018b
 struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
e0018b
 		unsigned long flags)
e0018b
 {
e0018b
@@ -239,6 +354,11 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
e0018b
 			json_object_object_add(jdev, "state", jobj);
e0018b
 	}
e0018b
 
e0018b
+	if (flags & UTIL_JSON_PARTITION) {
e0018b
+		jobj = util_cxl_memdev_partition_to_json(memdev, flags);
e0018b
+		if (jobj)
e0018b
+			json_object_object_add(jdev, "partition_info", jobj);
e0018b
+	}
e0018b
 	return jdev;
e0018b
 }
e0018b
 
e0018b
diff --git a/cxl/list.c b/cxl/list.c
e0018b
index de96ff9..1e9d441 100644
e0018b
--- a/cxl/list.c
e0018b
+++ b/cxl/list.c
e0018b
@@ -48,6 +48,8 @@ static const struct option options[] = {
e0018b
 		    "use human friendly number formats "),
e0018b
 	OPT_BOOLEAN('H', "health", &param.health,
e0018b
 		    "include memory device health information "),
e0018b
+	OPT_BOOLEAN('I', "partition", &param.partition,
e0018b
+		    "include memory device partition information "),
e0018b
 #ifdef ENABLE_DEBUG
e0018b
 	OPT_BOOLEAN(0, "debug", &debug, "debug list walk"),
e0018b
 #endif
e0018b
diff --git a/util/json.h b/util/json.h
e0018b
index e026df1..73bb9f0 100644
e0018b
--- a/util/json.h
e0018b
+++ b/util/json.h
e0018b
@@ -19,6 +19,7 @@ enum util_json_flags {
e0018b
 	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
e0018b
 	UTIL_JSON_HEALTH	= (1 << 10),
e0018b
 	UTIL_JSON_TARGETS	= (1 << 11),
e0018b
+	UTIL_JSON_PARTITION	= (1 << 12),
e0018b
 };
e0018b
 
e0018b
 void util_display_json_array(FILE *f_out, struct json_object *jarray,
e0018b
-- 
e0018b
2.27.0
e0018b