Content-Type: multipart/mixed; boundary="===============0528236990852326111==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v3 04/14] accel-config: Add mdev json support Date: Sat, 05 Dec 2020 15:20:16 -0500 Message-ID: <20201205202025.315186-5-ramesh.thomas@intel.com> In-Reply-To: 20201205202025.315186-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============0528236990852326111== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas 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 --- 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_d= evice *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 =3D 0; + struct json_object *json_mdev; = if (!jdevice) return NULL; @@ -339,6 +345,38 @@ struct json_object *util_device_to_json(struct accfg_d= evice *device, goto err; json_object_object_add(jdevice, "clients", jobj); = + jobj =3D 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 =3D json_object_new_string(uuid_string); + if (!json_uuid) + break; + mdev_type =3D accfg_mdev_basenames[accfg_mdev_get_type(mdev)]; + json_mtype =3D json_object_new_string(mdev_type); + if (!json_mtype) { + json_object_put(json_uuid); + break; + } + json_mdev =3D 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 --===============0528236990852326111==--