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

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