@@ -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;
}
@@ -416,6 +418,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);
@@ -439,6 +442,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;
}
@@ -563,6 +567,7 @@ struct json_object *util_cxl_decoder_to_json(struct cxl_decoder *decoder,
jobj);
}
+ json_object_set_userdata(jdecoder, decoder, NULL);
return jdecoder;
}
@@ -621,6 +626,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);
@@ -686,6 +692,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;
}
@@ -751,6 +758,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);
@@ -785,6 +793,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;
}
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(+)