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

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