Content-Type: multipart/mixed; boundary="===============8285304506331881271==" MIME-Version: 1.0 From: Jiang, Dave Subject: [Accel-config] Re: [PATCH v1 04/11] accel-config: Add mdev json support Date: Fri, 04 Dec 2020 23:54:57 +0000 Message-ID: <5159cd3fe52b4a9bb838ed1f7732964e@intel.com> In-Reply-To: 20201202193057.299615-5-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============8285304506331881271== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: ramesh.thomas(a)intel.com > Sent: Wednesday, December 2, 2020 12:31 PM > To: accel-config(a)lists.01.org > Cc: Thomas, Ramesh ; Luck, Tony > ; Jiang, Dave > Subject: [PATCH v1 04/11] accel-config: Add mdev json support > = > From: Ramesh Thomas > = > Load the mdevs stored in device contexts into json objects as array of md= ev > structures containing uuid and types > = > "list" command will list the mdevs structures under each device > = > Signed-off-by: Ramesh Thomas Reviewed-by: Dave Jiang > --- > 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 =3D 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 =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 --===============8285304506331881271==--