[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v3 03/11] libxl: add generic function to get and free device list



Thanks, I will fix it.

On Thu, Jun 29, 2017 at 8:36 PM, Wei Liu <wei.liu2@xxxxxxxxxx> wrote:
> On Tue, Jun 27, 2017 at 01:03:19PM +0300, Oleksandr Grytsov wrote:
>> From: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
>>
>> Add libxl__device_list, libxl__device_list_free.
>> Device list is created from libxl xen store entries.
>> In order to fill libxl device structure from xen store,
>> the device handling framework extended with from_xenstore callback.
>> On this callback libxl_device shall be filled with data from
>> be xen store directory.
>>
>> Signed-off-by: Oleksandr Grytsov <oleksandr_grytsov@xxxxxxxx>
>> ---
>>  tools/libxl/libxl_device.c   | 76 
>> ++++++++++++++++++++++++++++++++++++++++++++
>>  tools/libxl/libxl_internal.h |  8 +++++
>>  tools/libxl/libxl_vdispl.c   | 17 ++++++++--
>>  3 files changed, 98 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
>> index 00356af..8bcfa2b 100644
>> --- a/tools/libxl/libxl_device.c
>> +++ b/tools/libxl/libxl_device.c
>> @@ -1793,6 +1793,82 @@ out:
>>      return AO_CREATE_FAIL(rc);
>>  }
>>
>> +void* libxl__device_list(const struct libxl_device_type *dt,
>> +                         libxl_ctx *ctx, uint32_t domid, int *num)
>
> void *libxl_...
>
>> +{
>> +    GC_INIT(ctx);
>> +
>> +    void *r = NULL;
>> +    void *list = NULL;
>> +    void *item = NULL;
>> +    char *libxl_path;
>> +    char *be_path;
>> +    char** dir = NULL;
>
> char **dir
>
>> +    unsigned int ndirs = 0;
>> +    int rc;
>> +
>> +    *num = 0;
>> +
>> +    libxl_path = GCSPRINTF("%s/device/%s",
>> +                           libxl__xs_libxl_path(gc, domid), dt->type);
>> +
>> +    dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs);
>> +
>> +    if (dir && ndirs) {
>> +        list = malloc(dt->dev_elem_size * ndirs);
>> +        void *end = (uint8_t*)list + ndirs * dt->dev_elem_size;
>
> (uint8_t *)
>
>> +        item = list;
>> +
>> +        while(item < end) {
>> +            be_path = libxl__xs_read(gc, XBT_NULL,
>> +                                     GCSPRINTF("%s/%s/backend",
>> +                                     libxl_path, *dir));
>> +
>> +            dt->init(item);
>> +
>> +            if (dt->from_xenstore)
>> +            {
>
> Move { to previous line.
>
>> +                rc = dt->from_xenstore(gc, be_path, atoi(*dir), item);
>> +                if (rc) goto out;
>> +            }
>> +
>> +            item = (uint8_t*)item + dt->dev_elem_size;
>> +            ++dir;
>> +        }
>> +    }
>> +
>> +    *num = ndirs;
>> +    r = list;
>> +    list = NULL;
>> +
>> +out:
>> +
>> +    if (list) {
>> +        *num = 0;
>> +        while(item >= list) {
>
> Space after while.
>
>> +            item = (uint8_t*)item - dt->dev_elem_size;
>> +            dt->dispose(item);
>> +        }
>> +        free(list);
>> +    }
>> +
>> +    GC_FREE;
>> +
>> +    return r;
>> +}
>> +
>> +void libxl__device_list_free(const struct libxl_device_type *dt,
>> +                             void *list, int num)
>> +{
>> +    int i;
>> +
>> +    for (i = 0; i < num; i++) {
>> +        dt->dispose((uint8_t*)list + i * dt->dev_elem_size);
>> +    }
>> +
>
> No need to have {}.



-- 
Best Regards,
Oleksandr Grytsov.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.