diff mbox series

[ndctl,v2,10/18] cxl/list: Record cxl objects in json objects

Message ID 167053493696.582963.9963151335296712050.stgit@dwillia2-xfh.jf.intel.com
State Accepted
Commit 78a6e63d20e030d46719e8fcb1b4a97b07932b6f
Headers show
Series cxl-cli test and usability updates | expand

Commit Message

Dan Williams Dec. 8, 2022, 9:28 p.m. UTC
In preparation for reusing 'cxl list' object selection in other utilities,
like 'cxl create-region', record the associated cxl object in the json
object. For example, enable 'cxl create-region -d decoderX.Y' to lookup the
memdevs that result from 'cxl list -M -d decoderX.Y'.

This sets up future design decisions for code that wants to walk the
topology. It can either open-code its own object walk, or get the json-c
representation of a query and use that. Unless the use case knows exactly
the object it wants it is likely more powerful to specify a
cxl_filter_walk() query and then walk the topology result.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 cxl/json.c |    9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Alison Schofield Dec. 9, 2022, 5:28 p.m. UTC | #1
On Thu, Dec 08, 2022 at 01:28:57PM -0800, Dan Williams wrote:
> In preparation for reusing 'cxl list' object selection in other utilities,
> like 'cxl create-region', record the associated cxl object in the json
> object. For example, enable 'cxl create-region -d decoderX.Y' to lookup the
> memdevs that result from 'cxl list -M -d decoderX.Y'.
> 
> This sets up future design decisions for code that wants to walk the
> topology. It can either open-code its own object walk, or get the json-c
> representation of a query and use that. Unless the use case knows exactly
> the object it wants it is likely more powerful to specify a
> cxl_filter_walk() query and then walk the topology result.

Reviewed-by: Alison Schofield <alison.schofield@intel.com>

> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  cxl/json.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/cxl/json.c b/cxl/json.c
> index 292e8428ccee..844bc089a4b7 100644
> --- a/cxl/json.c
> +++ b/cxl/json.c
> @@ -365,6 +365,8 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
>  		if (jobj)
>  			json_object_object_add(jdev, "partition_info", jobj);
>  	}
> +
> +	json_object_set_userdata(jdev, memdev, NULL);
>  	return jdev;
>  }
>  
> @@ -423,6 +425,7 @@ void util_cxl_dports_append_json(struct json_object *jport,
>  			json_object_object_add(jdport, "id", jobj);
>  
>  		json_object_array_add(jdports, jdport);
> +		json_object_set_userdata(jdport, dport, NULL);
>  	}
>  
>  	json_object_object_add(jport, "dports", jdports);
> @@ -446,6 +449,7 @@ struct json_object *util_cxl_bus_to_json(struct cxl_bus *bus,
>  	if (jobj)
>  		json_object_object_add(jbus, "provider", jobj);
>  
> +	json_object_set_userdata(jbus, bus, NULL);
>  	return jbus;
>  }
>  
> @@ -570,6 +574,7 @@ struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder,
>  					       jobj);
>  	}
>  
> +	json_object_set_userdata(jdecoder, decoder, NULL);
>  	return jdecoder;
>  }
>  
> @@ -628,6 +633,7 @@ void util_cxl_mappings_append_json(struct json_object *jregion,
>  			json_object_object_add(jmapping, "decoder", jobj);
>  
>  		json_object_array_add(jmappings, jmapping);
> +		json_object_set_userdata(jmapping, mapping, NULL);
>  	}
>  
>  	json_object_object_add(jregion, "mappings", jmappings);
> @@ -693,6 +699,7 @@ struct json_object *util_cxl_region_to_json(struct cxl_region *region,
>  
>  	util_cxl_mappings_append_json(jregion, region, flags);
>  
> +	json_object_set_userdata(jregion, region, NULL);
>  	return jregion;
>  }
>  
> @@ -765,6 +772,7 @@ void util_cxl_targets_append_json(struct json_object *jdecoder,
>  			json_object_object_add(jtarget, "id", jobj);
>  
>  		json_object_array_add(jtargets, jtarget);
> +		json_object_set_userdata(jtarget, target, NULL);
>  	}
>  
>  	json_object_object_add(jdecoder, "targets", jtargets);
> @@ -807,6 +815,7 @@ static struct json_object *__util_cxl_port_to_json(struct cxl_port *port,
>  			json_object_object_add(jport, "state", jobj);
>  	}
>  
> +	json_object_set_userdata(jport, port, NULL);
>  	return jport;
>  }
>  
>
diff mbox series

Patch

diff --git a/cxl/json.c b/cxl/json.c
index 292e8428ccee..844bc089a4b7 100644
--- a/cxl/json.c
+++ b/cxl/json.c
@@ -365,6 +365,8 @@  struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
 		if (jobj)
 			json_object_object_add(jdev, "partition_info", jobj);
 	}
+
+	json_object_set_userdata(jdev, memdev, NULL);
 	return jdev;
 }
 
@@ -423,6 +425,7 @@  void util_cxl_dports_append_json(struct json_object *jport,
 			json_object_object_add(jdport, "id", jobj);
 
 		json_object_array_add(jdports, jdport);
+		json_object_set_userdata(jdport, dport, NULL);
 	}
 
 	json_object_object_add(jport, "dports", jdports);
@@ -446,6 +449,7 @@  struct json_object *util_cxl_bus_to_json(struct cxl_bus *bus,
 	if (jobj)
 		json_object_object_add(jbus, "provider", jobj);
 
+	json_object_set_userdata(jbus, bus, NULL);
 	return jbus;
 }
 
@@ -570,6 +574,7 @@  struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder,
 					       jobj);
 	}
 
+	json_object_set_userdata(jdecoder, decoder, NULL);
 	return jdecoder;
 }
 
@@ -628,6 +633,7 @@  void util_cxl_mappings_append_json(struct json_object *jregion,
 			json_object_object_add(jmapping, "decoder", jobj);
 
 		json_object_array_add(jmappings, jmapping);
+		json_object_set_userdata(jmapping, mapping, NULL);
 	}
 
 	json_object_object_add(jregion, "mappings", jmappings);
@@ -693,6 +699,7 @@  struct json_object *util_cxl_region_to_json(struct cxl_region *region,
 
 	util_cxl_mappings_append_json(jregion, region, flags);
 
+	json_object_set_userdata(jregion, region, NULL);
 	return jregion;
 }
 
@@ -765,6 +772,7 @@  void util_cxl_targets_append_json(struct json_object *jdecoder,
 			json_object_object_add(jtarget, "id", jobj);
 
 		json_object_array_add(jtargets, jtarget);
+		json_object_set_userdata(jtarget, target, NULL);
 	}
 
 	json_object_object_add(jdecoder, "targets", jtargets);
@@ -807,6 +815,7 @@  static struct json_object *__util_cxl_port_to_json(struct cxl_port *port,
 			json_object_object_add(jport, "state", jobj);
 	}
 
+	json_object_set_userdata(jport, port, NULL);
 	return jport;
 }