[Accel-config] [PATCH v3 04/14] accel-config: Add mdev json support

ramesh.thomas at intel.com
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.