linux-cxl.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH] cxl/list: Handle GET_PARTITION_INFO command as optional
@ 2022-02-22 18:23 alison.schofield
  2022-02-22 18:48 ` Verma, Vishal L
  0 siblings, 1 reply; 2+ messages in thread
From: alison.schofield @ 2022-02-22 18:23 UTC (permalink / raw)
  To: Ben Widawsky, Dan Williams, Ira Weiny, Vishal Verma
  Cc: Alison Schofield, nvdimm, linux-cxl

From: Alison Schofield <alison.schofield@intel.com>

CXL specifies GET_PARTITION_INFO mailbox command as optional. A device
may not support the command when it has no partitionable space.

Flip the order in which the command cxl-list retrieves the partition
info so that the fields reported by the IDENTIFY mailbox command are
always reported, and then the fields reported by the GET_PARTITION_INFO
mailbox command are optionally reported.

Fixes: 7581aba52da0 ("cxl: add memdev partition information to cxl-list")
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---

Vishal, I wasn't sure whether to rev the original patchset or post as a
fix. Let me know.


 cxl/json.c | 97 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 52 insertions(+), 45 deletions(-)

diff --git a/cxl/json.c b/cxl/json.c
index 69671b3e7fe9..fdc6f73a86c1 100644
--- a/cxl/json.c
+++ b/cxl/json.c
@@ -204,48 +204,6 @@ static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *
 	if (!memdev)
 		goto err_jobj;
 
-	/* Retrieve partition info in GET_PARTITION_INFO mbox cmd */
-	cmd = cxl_cmd_new_get_partition(memdev);
-	if (!cmd)
-		goto err_jobj;
-
-	rc = cxl_cmd_submit(cmd);
-	if (rc < 0)
-		goto err_cmd;
-	rc = cxl_cmd_get_mbox_status(cmd);
-	if (rc != 0)
-		goto err_cmd;
-
-	cap = cxl_cmd_partition_get_active_volatile_size(cmd);
-	if (cap != ULLONG_MAX) {
-		jobj = util_json_object_size(cap, flags);
-		if (jobj)
-			json_object_object_add(jpart,
-					"active_volatile_size", jobj);
-	}
-	cap = cxl_cmd_partition_get_active_persistent_size(cmd);
-	if (cap != ULLONG_MAX) {
-		jobj = util_json_object_size(cap, flags);
-		if (jobj)
-			json_object_object_add(jpart,
-					"active_persistent_size", jobj);
-	}
-	cap = cxl_cmd_partition_get_next_volatile_size(cmd);
-	if (cap != ULLONG_MAX) {
-		jobj = util_json_object_size(cap, flags);
-		if (jobj)
-			json_object_object_add(jpart,
-					"next_volatile_size", jobj);
-	}
-	cap = cxl_cmd_partition_get_next_persistent_size(cmd);
-	if (cap != ULLONG_MAX) {
-		jobj = util_json_object_size(cap, flags);
-		if (jobj)
-			json_object_object_add(jpart,
-					"next_persistent_size", jobj);
-	}
-	cxl_cmd_unref(cmd);
-
 	/* Retrieve partition info in the IDENTIFY mbox cmd */
 	cmd = cxl_cmd_new_identify(memdev);
 	if (!cmd)
@@ -253,10 +211,10 @@ static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *
 
 	rc = cxl_cmd_submit(cmd);
 	if (rc < 0)
-		goto err_cmd;
+		goto err_identify;
 	rc = cxl_cmd_get_mbox_status(cmd);
 	if (rc != 0)
-		goto err_cmd;
+		goto err_identify;
 
 	cap = cxl_cmd_identify_get_total_size(cmd);
 	if (cap != ULLONG_MAX) {
@@ -284,10 +242,59 @@ static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *
 		json_object_object_add(jpart, "partition_alignment_size", jobj);
 
 	cxl_cmd_unref(cmd);
+
+	/* Return now if there is no partition info to get. */
+	if (!cap)
+		return jpart;
+
+	/* Retrieve partition info in GET_PARTITION_INFO mbox cmd */
+	cmd = cxl_cmd_new_get_partition(memdev);
+	if (!cmd)
+		return jpart;
+
+	rc = cxl_cmd_submit(cmd);
+	if (rc < 0)
+		goto err_get;
+	rc = cxl_cmd_get_mbox_status(cmd);
+	if (rc != 0)
+		goto err_get;
+
+	cap = cxl_cmd_partition_get_active_volatile_size(cmd);
+	if (cap != ULLONG_MAX) {
+		jobj = util_json_object_size(cap, flags);
+		if (jobj)
+			json_object_object_add(jpart,
+					"active_volatile_size", jobj);
+	}
+	cap = cxl_cmd_partition_get_active_persistent_size(cmd);
+	if (cap != ULLONG_MAX) {
+		jobj = util_json_object_size(cap, flags);
+		if (jobj)
+			json_object_object_add(jpart,
+					"active_persistent_size", jobj);
+	}
+	cap = cxl_cmd_partition_get_next_volatile_size(cmd);
+	if (cap != ULLONG_MAX) {
+		jobj = util_json_object_size(cap, flags);
+		if (jobj)
+			json_object_object_add(jpart,
+					"next_volatile_size", jobj);
+	}
+	cap = cxl_cmd_partition_get_next_persistent_size(cmd);
+	if (cap != ULLONG_MAX) {
+		jobj = util_json_object_size(cap, flags);
+		if (jobj)
+			json_object_object_add(jpart,
+					"next_persistent_size", jobj);
+	}
+
+err_get:
+	cxl_cmd_unref(cmd);
 	return jpart;
 
-err_cmd:
+err_identify:
 	cxl_cmd_unref(cmd);
+
 err_jobj:
 	json_object_put(jpart);
 	return NULL;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [ndctl PATCH] cxl/list: Handle GET_PARTITION_INFO command as optional
  2022-02-22 18:23 [ndctl PATCH] cxl/list: Handle GET_PARTITION_INFO command as optional alison.schofield
@ 2022-02-22 18:48 ` Verma, Vishal L
  0 siblings, 0 replies; 2+ messages in thread
From: Verma, Vishal L @ 2022-02-22 18:48 UTC (permalink / raw)
  To: Williams, Dan J, Schofield, Alison, Widawsky, Ben, Weiny, Ira
  Cc: linux-cxl, nvdimm

On Tue, 2022-02-22 at 10:23 -0800, alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> CXL specifies GET_PARTITION_INFO mailbox command as optional. A device
> may not support the command when it has no partitionable space.
> 
> Flip the order in which the command cxl-list retrieves the partition
> info so that the fields reported by the IDENTIFY mailbox command are
> always reported, and then the fields reported by the GET_PARTITION_INFO
> mailbox command are optionally reported.
> 
> Fixes: 7581aba52da0 ("cxl: add memdev partition information to cxl-list")
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
> 
> Vishal, I wasn't sure whether to rev the original patchset or post as a
> fix. Let me know.

Hey Alison,

I hadn't pulled in the original patchset to pending yet, so rev'ing it
would be better. The Fixes line above doesn't point to anything stable
either - generally, that should only ever point to commits that have
appeared in 'master' or 'pending'. Any other branch is free to rebase
at will.

> 
> 
>  cxl/json.c | 97 +++++++++++++++++++++++++++++-------------------------
>  1 file changed, 52 insertions(+), 45 deletions(-)
> 
> diff --git a/cxl/json.c b/cxl/json.c
> index 69671b3e7fe9..fdc6f73a86c1 100644
> --- a/cxl/json.c
> +++ b/cxl/json.c
> @@ -204,48 +204,6 @@ static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *
>  	if (!memdev)
>  		goto err_jobj;
>  
> -	/* Retrieve partition info in GET_PARTITION_INFO mbox cmd */
> -	cmd = cxl_cmd_new_get_partition(memdev);
> -	if (!cmd)
> -		goto err_jobj;
> -
> -	rc = cxl_cmd_submit(cmd);
> -	if (rc < 0)
> -		goto err_cmd;
> -	rc = cxl_cmd_get_mbox_status(cmd);
> -	if (rc != 0)
> -		goto err_cmd;
> -
> -	cap = cxl_cmd_partition_get_active_volatile_size(cmd);
> -	if (cap != ULLONG_MAX) {
> -		jobj = util_json_object_size(cap, flags);
> -		if (jobj)
> -			json_object_object_add(jpart,
> -					"active_volatile_size", jobj);
> -	}
> -	cap = cxl_cmd_partition_get_active_persistent_size(cmd);
> -	if (cap != ULLONG_MAX) {
> -		jobj = util_json_object_size(cap, flags);
> -		if (jobj)
> -			json_object_object_add(jpart,
> -					"active_persistent_size", jobj);
> -	}
> -	cap = cxl_cmd_partition_get_next_volatile_size(cmd);
> -	if (cap != ULLONG_MAX) {
> -		jobj = util_json_object_size(cap, flags);
> -		if (jobj)
> -			json_object_object_add(jpart,
> -					"next_volatile_size", jobj);
> -	}
> -	cap = cxl_cmd_partition_get_next_persistent_size(cmd);
> -	if (cap != ULLONG_MAX) {
> -		jobj = util_json_object_size(cap, flags);
> -		if (jobj)
> -			json_object_object_add(jpart,
> -					"next_persistent_size", jobj);
> -	}
> -	cxl_cmd_unref(cmd);
> -
>  	/* Retrieve partition info in the IDENTIFY mbox cmd */
>  	cmd = cxl_cmd_new_identify(memdev);
>  	if (!cmd)
> @@ -253,10 +211,10 @@ static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *
>  
>  	rc = cxl_cmd_submit(cmd);
>  	if (rc < 0)
> -		goto err_cmd;
> +		goto err_identify;
>  	rc = cxl_cmd_get_mbox_status(cmd);
>  	if (rc != 0)
> -		goto err_cmd;
> +		goto err_identify;
>  
>  	cap = cxl_cmd_identify_get_total_size(cmd);
>  	if (cap != ULLONG_MAX) {
> @@ -284,10 +242,59 @@ static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *
>  		json_object_object_add(jpart, "partition_alignment_size", jobj);
>  
>  	cxl_cmd_unref(cmd);
> +
> +	/* Return now if there is no partition info to get. */
> +	if (!cap)
> +		return jpart;
> +
> +	/* Retrieve partition info in GET_PARTITION_INFO mbox cmd */
> +	cmd = cxl_cmd_new_get_partition(memdev);
> +	if (!cmd)
> +		return jpart;
> +
> +	rc = cxl_cmd_submit(cmd);
> +	if (rc < 0)
> +		goto err_get;
> +	rc = cxl_cmd_get_mbox_status(cmd);
> +	if (rc != 0)
> +		goto err_get;
> +
> +	cap = cxl_cmd_partition_get_active_volatile_size(cmd);
> +	if (cap != ULLONG_MAX) {
> +		jobj = util_json_object_size(cap, flags);
> +		if (jobj)
> +			json_object_object_add(jpart,
> +					"active_volatile_size", jobj);
> +	}
> +	cap = cxl_cmd_partition_get_active_persistent_size(cmd);
> +	if (cap != ULLONG_MAX) {
> +		jobj = util_json_object_size(cap, flags);
> +		if (jobj)
> +			json_object_object_add(jpart,
> +					"active_persistent_size", jobj);
> +	}
> +	cap = cxl_cmd_partition_get_next_volatile_size(cmd);
> +	if (cap != ULLONG_MAX) {
> +		jobj = util_json_object_size(cap, flags);
> +		if (jobj)
> +			json_object_object_add(jpart,
> +					"next_volatile_size", jobj);
> +	}
> +	cap = cxl_cmd_partition_get_next_persistent_size(cmd);
> +	if (cap != ULLONG_MAX) {
> +		jobj = util_json_object_size(cap, flags);
> +		if (jobj)
> +			json_object_object_add(jpart,
> +					"next_persistent_size", jobj);
> +	}
> +
> +err_get:
> +	cxl_cmd_unref(cmd);
>  	return jpart;
>  
> -err_cmd:
> +err_identify:
>  	cxl_cmd_unref(cmd);
> +
>  err_jobj:
>  	json_object_put(jpart);
>  	return NULL;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-22 18:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 18:23 [ndctl PATCH] cxl/list: Handle GET_PARTITION_INFO command as optional alison.schofield
2022-02-22 18:48 ` Verma, Vishal L

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).