All of lore.kernel.org
 help / color / mirror / Atom feed
* [Accel-config] [PATCH v2 04/12] accel-config: Add mdev json support
@ 2020-12-05  5:38 ramesh.thomas
  0 siblings, 0 replies; only message in thread
From: ramesh.thomas @ 2020-12-05  5:38 UTC (permalink / raw)
  To: accel-config

[-- Attachment #1: Type: text/plain, Size: 2041 bytes --]

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Load the mdevs stored in device contexts into json objects as array of
mdev structures containing uuid and types

"list" command will list the mdevs structures under each device

Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 util/json.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/util/json.c b/util/json.c
index 6f4b4d1..8ff89d0 100644
--- a/util/json.c
+++ b/util/json.c
@@ -153,6 +153,12 @@ struct json_object *util_device_to_json(struct accfg_device *device,
 	unsigned long ulong_val;
 	unsigned long long ullong_val;
 	bool new_bool;
+	struct accfg_device_mdev *mdev;
+	struct json_object *json_uuid;
+	struct json_object *json_mtype;
+	char uuid_string[UUID_STR_LEN];
+	int mdev_found = 0;
+	struct json_object *json_mdev;
 
 	if (!jdevice)
 		return NULL;
@@ -339,6 +345,38 @@ struct json_object *util_device_to_json(struct accfg_device *device,
 		goto err;
 	json_object_object_add(jdevice, "clients", jobj);
 
+	jobj = json_object_new_array();
+	accfg_device_mdev_foreach(device, mdev) {
+		uuid_t uuid;
+		const char *mdev_type;
+
+		accfg_mdev_get_uuid(mdev, uuid);
+		uuid_unparse(uuid, uuid_string);
+		json_uuid = json_object_new_string(uuid_string);
+		if (!json_uuid)
+			break;
+		mdev_type = accfg_mdev_basenames[accfg_mdev_get_type(mdev)];
+		json_mtype = json_object_new_string(mdev_type);
+		if (!json_mtype) {
+			json_object_put(json_uuid);
+			break;
+		}
+		json_mdev = json_object_new_object();
+		if (!json_mdev) {
+			json_object_put(json_uuid);
+			json_object_put(json_mtype);
+			break;
+		}
+		json_object_object_add(json_mdev, "uuid", json_uuid);
+		json_object_object_add(json_mdev, "type", json_mtype);
+		json_object_array_add(jobj, json_mdev);
+		mdev_found++;
+	}
+	if (mdev_found)
+		json_object_object_add(jdevice, "mdevs", jobj);
+	else
+		json_object_put(jobj);
+
 	free(error);
 	return jdevice;
 err:
-- 
2.26.2

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-05  5:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-05  5:38 [Accel-config] [PATCH v2 04/12] accel-config: Add mdev json support ramesh.thomas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.