libxl: add PV display device driver interface
cover libxl: add PV display device driver interface
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions: LIBXL_DEFINE_DEVICE_COMMIT, LIBXL_DEFINE_DEVICE_LIST_GET, LIBXL_DEFINE_DEVICE_GETINFO etc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.
Thanks.
[1] http://marc.info/?l=xen-devel&m=149000029128972&w=2
[2] http://marc.info/?l=xen-devel&m=145372933919792&w=2
Oleksandr Grytsov (2):
libxl: add PV display device driver interface
xl: add PV display device commands
tools/libxl/Makefile | 2 +- tools/libxl/libxl.h | 21 ++++ tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_internal.h | 228 +++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 22 +++- tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.h | 4 + tools/libxl/libxl_vdispl.c | 137 +++++++++++++++++++++ tools/xl/Makefile | 1 + tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 16 +++ tools/xl/xl_parse.c | 44 ++++++- tools/xl/xl_parse.h | 2 +- tools/xl/xl_vdispl.c | 162 +++++++++++++++++++++++++ 14 files changed, 639 insertions(+), 5 deletions(-) create mode 100644 tools/libxl/libxl_vdispl.c create mode 100644 tools/xl/xl_vdispl.c
Signature · 6 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/2 libxl: add PV display device driver interface
From: Oleksandr Grytsov <[email protected]>
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.h | 21 ++++ tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_internal.h | 228 +++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 22 +++- tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.h | 4 + tools/libxl/libxl_vdispl.c | 137 +++++++++++++++++++++ 8 files changed, 413 insertions(+), 3 deletions(-) create mode 100644 tools/libxl/libxl_vdispl.c
tools/libxl/Makefile +1 -1
@@ -138,7 +138,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \ libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \ libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \ - libxl_domain.o \ + libxl_domain.o libxl_vdispl.o \ $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl.h +21 -0
@@ -1833,6 +1833,27 @@ libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *nint libxl_device_vtpm_getinfo (libxl_ctx *ctx,uint32_t domid,libxl_device_vtpm *vtpm,libxl_vtpminfo *vtpminfo); +/* Virtual displays */ +int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *displ, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdispl_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *vdispl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdispl_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdispl *vdispl, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +libxl_device_vdispl *libxl_device_vdispl_list (libxl_ctx *ctx,uint32_t domid, +int *num); +void libxl_device_vdispl_list_free (libxl_device_vdispl * list,int num); +int libxl_device_vdispl_getinfo (libxl_ctx *ctx,uint32_t domid, +libxl_device_vdispl *vdispl, +libxl_vdisplinfo *vdisplinfo); +/* Keyboard */ int libxl_device_vkb_add (libxl_ctx *ctx,uint32_t domid,libxl_device_vkb *vkb,const libxl_asyncop_how *ao_how)
tools/libxl/libxl_create.c +1 -0
@@ -1445,6 +1445,7 @@ const struct libxl_device_type *device_type_tbl[] = { &libxl__usbdev_devtype, &libxl__pcidev_devtype, &libxl__dtdev_devtype, + &libxl__vdispl_devtype, NULL };
tools/libxl/libxl_internal.h +228 -0
240 lines not on this page · raw message
tools/libxl/libxl_types.idl +20 -2
@@ -690,7 +690,14 @@ libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domname", string), ("devid", libxl_devid), ("uuid", libxl_uuid), -]) + ]) + +libxl_device_vdispl = Struct("device_vdispl", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("be_alloc", bool), + ]) libxl_device_channel = Struct("device_channel", [ ("backend_domid", libxl_domid),
@@ -702,7 +709,7 @@ libxl_device_channel = Struct("device_channel", [ ("pty", None), ("socket", Struct(None, [("path", string)])), ])), -]) + ]) libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info),
@@ -716,6 +723,7 @@ libxl_domain_config = Struct("domain_config", [ ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), + ("vdispls", Array(libxl_device_vdispl, "num_vdispls")), # a channel manifests as a console with a name, # see docs/misc/channels.txt ("channels", Array(libxl_device_channel, "num_channels")),
@@ -812,6 +820,16 @@ libxl_physinfo = Struct("physinfo", [ ("cap_hvm_directio", bool), ], dir=DIR_OUT) +libxl_vdisplinfo = Struct("vdisplinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ("be_alloc", bool), + ], dir=DIR_OUT) + # NUMA node characteristics: size and free are how much memory it has, and how # much of it is free, respectively. dists is an array of distances from this # node to each other node.
tools/libxl/libxl_types_internal.idl +1 -0
@@ -25,6 +25,7 @@ libxl__device_kind = Enumeration("device_kind", [ (8, "VTPM"), (9, "VUSB"), (10, "QUSB"), + (11, "VDISPL") ]) libxl__console_backend = Enumeration("console_backend", [
tools/libxl/libxl_utils.h +4 -0
@@ -78,6 +78,10 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_vtpm *vtpm);int libxl_devid_to_device_usbctrl (libxl_ctx *ctx,uint32_t domid,int devid,libxl_device_usbctrl *usbctrl); + +int libxl_devid_to_device_vdispl (libxl_ctx *ctx,uint32_t domid, +int devid,libxl_device_vdispl *vdispl); +int libxl_ctrlport_to_device_usbdev (libxl_ctx *ctx,uint32_t domid,int ctrl,int port,libxl_device_usbdev *usbdev);
tools/libxl/libxl_vdispl.c new file +137 -0
137 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 xl: add PV display device commands
In reply to Oleksandr GrytsovFrom: Oleksandr Grytsov <[email protected]>
--- tools/xl/Makefile | 1 + tools/xl/xl.h | 3 + tools/xl/xl_cmdtable.c | 16 +++++ tools/xl/xl_parse.c | 44 +++++++++++++- tools/xl/xl_parse.h | 2 +- tools/xl/xl_vdispl.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 tools/xl/xl_vdispl.c
tools/xl/Makefile +1 -0
@@ -21,6 +21,7 @@ XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o XL_OBJS += xl_psr.o xl_info.o xl_console.o xl_misc.o XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o +XL_OBJS += xl_vdispl.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
tools/xl/xl.h +3 -0
@@ -165,6 +165,9 @@ int main_blockdetach(int argc, char **argv);int main_vtpmattach (int argc,char **argv);int main_vtpmlist (int argc,char **argv);int main_vtpmdetach (int argc,char **argv); +int main_vdisplattach (int argc,char **argv); +int main_vdispllist (int argc,char **argv); +int main_vdispldetach (int argc,char **argv);int main_usbctrl_attach (int argc,char **argv);int main_usbctrl_detach (int argc,char **argv);int main_usbdev_attach (int argc,char **argv);
tools/xl/xl_cmdtable.c +16 -0
@@ -372,6 +372,22 @@ struct cmd_spec cmd_table[] = {"Destroy a domain's virtual TPM device" ,"<Domain> <DevId|uuid>" , }, + { "vdispl-attach", + &main_vdisplattach,1 ,1 , +"Create a new virtual display device" , +"<Domain> [devId=<Device>] [backend=<BackDomain>] [beAlloc=<BackAlloc>]" , +" BackAlloc - set to 1 to allow backend allocated display buffers" + }, + { "vdispl-list", + &main_vdispllist,0 ,0 , +"List virtual display devices for a domain" , +"<Domain(s)>" , + }, + { "vdispl-detach", + &main_vdispldetach,0 ,1 , +"Destroy a domain's virtual display device" , +"<Domain> <DevId>" , + }, { "uptime", &main_uptime,0 ,0 , "Print uptime for all/some domains",
tools/xl/xl_parse.c +43 -1
62 lines not on this page · raw message
tools/xl/xl_parse.h +1 -1
@@ -33,7 +33,7 @@ int parse_usbctrl_config(libxl_device_usbctrl *usbctrl, char *token);int parse_usbdev_config (libxl_device_usbdev *usbdev,char *token);int parse_cpurange (const char *cpu,libxl_bitmap *cpumap);int parse_nic_config (libxl_device_nic *nic,XLU_Config **config,char *token); - +int parse_vdispl_config (libxl_device_vdispl *vdispl,char *token);int match_option_size (const char *prefix,size_t len,char *arg,char **argopt);
tools/xl/xl_vdispl.c new file +162 -0
162 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines · Oleksandr Grytsov
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.
Did you look into the device type framework I introduced with commit 74e857c6c7f9 and some followups? Maybe it is possible to expand this framework by adding more callbacks to struct libxl_device_type and have some common function(s) in libxl_device.c?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Juergen,
I've checked the mentioned commits. And I don't see how it can be done. The duplication I see it is in libxl_device_type.add and libxl_device_type.list functions
for different PV devices. These functions have a lot of common code which I've tried
to move to macros in my patches.
2017-03-23 12:21 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 23 lines · Oleksandr Grytsov
Quoted 8 lines
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.Did you look into the device type framework I introduced with commit
74e857c6c7f9and some followups? Maybe it is possible to expand this framework by adding more callbacks to structlibxl_device_typeand have some common function(s) inlibxl_device.c?Juergen
Signature · 7 lines
Best Regards, Oleksandr Grytsov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines · On 23/03/17 12:32, al1img . wrote:
Hi Juergen,
I've checked the mentioned commits. And I don't see how it can be done. The duplication I see it is in libxl_device_type.add and libxl_device_type.list functions
for different PV devices. These functions have a lot of common code which I've tried
to move to macros in my patches.
Okay, here an example for replacement of LIBXL_DEFINE_DEVICE_LIST_FREE()
void libxl_device_list_free(struct libxl_device_type *dt,
void *list, int nr)
{
int i;
for (i = 0; i < nr; i++)
dt->dispose(list + i * dt->dev_elem_size);
free(list);
}BTW: exactly this pattern is to be found at the very end of libxl_retrieve_domain_configuration().
The others should be doable, too.
Juergen
Quoted 28 lines
2017-03-23 12:21 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 23 lines · Oleksandr Grytsov
Quoted 8 lines
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.Did you look into the device type framework I introduced with commit
74e857c6c7f9and some followups? Maybe it is possible to expand this framework by adding more callbacks to structlibxl_device_typeand have some common function(s) inlibxl_device.c?Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
This example is clear. But still wrapper macro is required to make it visible for libxen client (xl):
#define LIBXL_DEFINE_DEVICE_LIST_FREE(type)
void libxl_device_##type##_list_free(libxl_device_##type* list, int nr)
{
libxl__device_list_free(libxl__##type##_devtype, list, nr);
}Also where should this function (libxl__device_list_free) be located? libxl_device.c?
Another case is getting this list:
From one side each device should have its own implementation, from other side for PV devices
there is common part like getting devId and backend domId and unique part like getting
device specific parameters (uuid for vtpm). In this case I can do following:
Implement void *libxl__device_list(struct libxl_device_type *dt, libxl_ctx *ctx, uint32_t domid, int *num)
where I will get devId and backend domId. Then add get_params callback to libxl_device_type to get device specific
parameters:
void *libxl__device_pv_list(struct libxl_device_type *dt, libxl_ctx *ctx, uint32_t domid, int *num)
{
...
if (dt->get_patams) {
dt->get_params(...);
}
}And vtpm get list may look like:
libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *num)
{
return libxl__device_list(&libxl__vtpm_devtype, ctx, domid, num);
}DEFINE_DEVICE_TYPE_STRUCT(vtpm,
.update_config = libxl_device_vtpm_update_config .get_params = libxl_device_vtpm_get_params
);
Correct?
2017-03-23 14:08 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 59 lines · On 23/03/17 12:32, al1img . wrote:
Quoted 8 lines
Hi Juergen,
I've checked the mentioned commits. And I don't see how it can be done. The duplication I see it is in libxl_device_type.add and libxl_device_type.list functions
for different PV devices. These functions have a lot of common code which I've tried
to move to macros in my patches.Okay, here an example for replacement of
LIBXL_DEFINE_DEVICE_LIST_FREE()void libxl_device_list_free(struct
libxl_device_type*dt,
void *list, int nr){ int i; for (i = 0; i < nr; i++) dt->dispose(list + i * dt->dev_elem_size); free(list); }BTW: exactly this pattern is to be found at the very end of
libxl_retrieve_domain_configuration().The others should be doable, too.
Juergen
Quoted 28 lines
2017-03-23 12:21 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 23 lines · Oleksandr Grytsov
Quoted 8 lines
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.Did you look into the device type framework I introduced with commit
74e857c6c7f9and some followups? Maybe it is possible to expand this framework by adding more callbacks to structlibxl_device_typeand have some common function(s) inlibxl_device.c?Juergen
Signature · 7 lines
Best Regards, Oleksandr Grytsov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines · On 23/03/17 15:23, al1img . wrote:
This example is clear. But still wrapper macro is required to make it visible for libxen client (xl):
#define LIBXL_DEFINE_DEVICE_LIST_FREE(type) void libxl_device_##type##_list_free(libxl_device_##type* list, int nr) { libxl__device_list_free(libxl__##type##_devtype, list, nr); }
Either this or we could switch to a more generic way avoiding the need to add multiple very similar functions to libxl:
#define LIBXL_DEVTYPE_VTPM "vtpm"
int libxl_device_list_free(const char *type, void *list, int nr)
{
int i;
for (i = 0; device_type_tbl[i]; i++) {
if (!strcmp(type, device_type_tbl[i]->type)) {
libxl__device_list_free(device_type_tbl[i], list, nr);
return 0;
}
}
return ERROR_INVAL;
}and let xl call it via libxl_device_list_free(LIBXL_DEVTYPE_VTPM, ...)
This is subject to an Ack from the tools maintainers, of course.
Quoted 3 lines
Also where should this function (
libxl__device_list_free) be located?libxl_device.c?
I think so.
Quoted 32 lines
Another case is getting this list:
From one side each device should have its own implementation, from other side for PV devices
there is common part like getting devId and backend domId and unique part like getting
device specific parameters (uuid for vtpm). In this case I can do following:Implement void *libxl__device_list(struct
libxl_device_type*dt,libxl_ctx*ctx,uint32_tdomid, int *num)
where I will get devId and backend domId. Then addget_paramscallback tolibxl_device_typeto get device specific
parameters:void *libxl__device_pv_list(struct
libxl_device_type*dt,libxl_ctx*ctx,uint32_tdomid, int *num){ ... if (dt->get_patams) { dt->get_params(...); } }And vtpm get list may look like:
libxl_device_vtpm*libxl_device_vtpm_list(libxl_ctx *ctx,uint32_tdomid, int *num){ return libxl__device_list(&libxl__vtpm_devtype, ctx, domid, num); }
Quoted 6 lines
DEFINE_DEVICE_TYPE_STRUCT(vtpm,
.update_config =libxl_device_vtpm_update_config.get_params =libxl_device_vtpm_get_params
);Correct?
Right. Possibly using the same trick as above.
BTW: Please don't top-post.
Juergen
Quoted 65 lines
2017-03-23 14:08 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 59 lines · On 23/03/17 12:32, al1img . wrote:
Quoted 8 lines
Hi Juergen,
I've checked the mentioned commits. And I don't see how it can be done. The duplication I see it is in libxl_device_type.add and libxl_device_type.list functions
for different PV devices. These functions have a lot of common code which I've tried
to move to macros in my patches.Okay, here an example for replacement of
LIBXL_DEFINE_DEVICE_LIST_FREE()void libxl_device_list_free(struct
libxl_device_type*dt,
void *list, int nr){ int i; for (i = 0; i < nr; i++) dt->dispose(list + i * dt->dev_elem_size); free(list); }BTW: exactly this pattern is to be found at the very end of
libxl_retrieve_domain_configuration().The others should be doable, too.
Juergen
Quoted 28 lines
2017-03-23 12:21 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 23 lines · Oleksandr Grytsov
Quoted 8 lines
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.Did you look into the device type framework I introduced with commit
74e857c6c7f9and some followups? Maybe it is possible to expand this framework by adding more callbacks to structlibxl_device_typeand have some common function(s) inlibxl_device.c?Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 75 lines · Juergen Gross
Quoted 8 lines · On 23/03/17 15:23, al1img . wrote:
This example is clear. But still wrapper macro is required to make it visible for libxen client (xl):
#define LIBXL_DEFINE_DEVICE_LIST_FREE(type) void libxl_device_##type##_list_free(libxl_device_##type* list, int nr) { libxl__device_list_free(libxl__##type##_devtype, list, nr); }Either this or we could switch to a more generic way avoiding the need to add multiple very similar functions to libxl:
#define
LIBXL_DEVTYPE_VTPM"vtpm"int
libxl_device_list_free(const char *type, void *list, int nr){ int i; for (i = 0; device_type_tbl[i]; i++) { if (!strcmp(type, device_type_tbl[i]->type)) { libxl__device_list_free(device_type_tbl[i], list, nr); return 0; } } return ERROR_INVAL; }and let xl call it via
libxl_device_list_free(LIBXL_DEVTYPE_VTPM, ...)This is subject to an Ack from the tools maintainers, of course.
Quoted 3 lines
Also where should this function (
libxl__device_list_free) be located?libxl_device.c?I think so.
Quoted 37 lines
Another case is getting this list:
From one side each device should have its own implementation, from other side for PV devices
there is common part like getting devId and backend domId and unique part like getting
device specific parameters (uuid for vtpm). In this case I can do following:Implement void *libxl__device_list(struct
libxl_device_type*dt,libxl_ctx*ctx,uint32_tdomid, int *num)
where I will get devId and backend domId. Then addget_paramscallback tolibxl_device_typeto get device specific
parameters:void *libxl__device_pv_list(struct
libxl_device_type*dt,libxl_ctx*ctx,uint32_tdomid, int *num){ ... if (dt->get_patams) { dt->get_params(...); } }And vtpm get list may look like:
libxl_device_vtpm*libxl_device_vtpm_list(libxl_ctx *ctx,uint32_tdomid, int *num){ return libxl__device_list(&libxl__vtpm_devtype, ctx, domid, num); }DEFINE_DEVICE_TYPE_STRUCT(vtpm,
.update_config =libxl_device_vtpm_update_config.get_params =libxl_device_vtpm_get_params
);
Quoted 75 lines
Quoted 1 line
Correct?
Right. Possibly using the same trick as above.
BTW: Please don't top-post.
Juergen
Quoted 65 lines
2017-03-23 14:08 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 59 lines · On 23/03/17 12:32, al1img . wrote:
Quoted 8 lines
Hi Juergen,
I've checked the mentioned commits. And I don't see how it can be done. The duplication I see it is in libxl_device_type.add and libxl_device_type.list functions
for different PV devices. These functions have a lot of common code which I've tried
to move to macros in my patches.Okay, here an example for replacement of
LIBXL_DEFINE_DEVICE_LIST_FREE()void libxl_device_list_free(struct
libxl_device_type*dt,
void *list, int nr){ int i; for (i = 0; i < nr; i++) dt->dispose(list + i * dt->dev_elem_size); free(list); }BTW: exactly this pattern is to be found at the very end of
libxl_retrieve_domain_configuration().The others should be doable, too.
Juergen
Quoted 28 lines
2017-03-23 12:21 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 23 lines · Oleksandr Grytsov
Quoted 8 lines
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.Did you look into the device type framework I introduced with commit
74e857c6c7f9and some followups? Maybe it is possible to expand this framework by adding more callbacks to structlibxl_device_typeand have some common function(s) inlibxl_device.c?Juergen
For me the drawback of more generic way is to cast device_type to void* and back which
may be used by client in improper way.
Thanks.
Signature · 7 lines
Best Regards, Oleksandr Grytsov. _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 152 lines · On 23.03.17 17:55, al1img . wrote:
Quoted 75 lines · Juergen Gross
Quoted 8 lines · On 23/03/17 15:23, al1img . wrote:
This example is clear. But still wrapper macro is required to make it visible for libxen client (xl):
#define LIBXL_DEFINE_DEVICE_LIST_FREE(type) void libxl_device_##type##_list_free(libxl_device_##type* list, int nr) { libxl__device_list_free(libxl__##type##_devtype, list, nr); }Either this or we could switch to a more generic way avoiding the need to add multiple very similar functions to libxl:
#define
LIBXL_DEVTYPE_VTPM"vtpm"int
libxl_device_list_free(const char *type, void *list, int nr){ int i; for (i = 0; device_type_tbl[i]; i++) { if (!strcmp(type, device_type_tbl[i]->type)) { libxl__device_list_free(device_type_tbl[i], list, nr); return 0; } } return ERROR_INVAL; }and let xl call it via
libxl_device_list_free(LIBXL_DEVTYPE_VTPM, ...)This is subject to an Ack from the tools maintainers, of course.
Quoted 3 lines
Also where should this function (
libxl__device_list_free) be located?libxl_device.c?I think so.
Quoted 37 lines
Another case is getting this list:
From one side each device should have its own implementation, from
other side for PV devices
there is common part like getting devId and backend domId and unique part like getting
device specific parameters (uuid for vtpm). In this case I can do following:Implement void *libxl__device_list(struct
libxl_device_type*dt,libxl_ctx*ctx,uint32_tdomid, int *num)
where I will get devId and backend domId. Then addget_paramscallback tolibxl_device_typeto get device specific
parameters:void *libxl__device_pv_list(struct
libxl_device_type*dt,libxl_ctx*ctx,uint32_tdomid, int *num){ ... if (dt->get_patams) { dt->get_params(...); } }And vtpm get list may look like:
libxl_device_vtpm*libxl_device_vtpm_list(libxl_ctx *ctx,uint32_tdomid, int *num){ return libxl__device_list(&libxl__vtpm_devtype, ctx, domid, num); }DEFINE_DEVICE_TYPE_STRUCT(vtpm,
.update_config =libxl_device_vtpm_update_config.get_params =libxl_device_vtpm_get_params
);Quoted 75 lines
Quoted 1 line
Correct?
Right. Possibly using the same trick as above.
BTW: Please don't top-post.
Juergen
Quoted 65 lines
2017-03-23 14:08 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 59 lines · On 23/03/17 12:32, al1img . wrote:
Quoted 8 lines
Hi Juergen,
I've checked the mentioned commits. And I don't see how it can be done. The duplication I see it is in libxl_device_type.add and libxl_device_type.list functions
for different PV devices. These functions have a lot of common code which I've tried
to move to macros in my patches.Okay, here an example for replacement of
LIBXL_DEFINE_DEVICE_LIST_FREE()void libxl_device_list_free(struct
libxl_device_type*dt,
void *list, int nr){ int i; for (i = 0; i < nr; i++) dt->dispose(list + i * dt->dev_elem_size); free(list); }BTW: exactly this pattern is to be found at the very end of
libxl_retrieve_domain_configuration().The others should be doable, too.
Juergen
Quoted 28 lines
2017-03-23 12:21 GMT+02:00 Juergen Gross <[email protected]>:
Quoted 23 lines · Oleksandr Grytsov
Quoted 8 lines
From: Oleksandr Grytsov <[email protected]>
Hi all,
We are working on series of PV drivers (display, sound, input etc.) and would like to add their support to libxl and xl. These patches add PV display device. PV display is based on [1] protocol.
Quoted 7 lines
During implementation I see a lot of code duplication. This problem was mentioned in [2]. One of the solutions was to implement common parts in IDL and make them autogenerated. On my side, to minimize the copy/pasting I've moved common parts into macro functions:
LIBXL_DEFINE_DEVICE_COMMIT,LIBXL_DEFINE_DEVICE_LIST_GET,LIBXL_DEFINE_DEVICE_GETINFOetc. Existing PV devices implementations can be reworked to use these macros as well. Any other proposals to avoid the duplications are welcome.Did you look into the device type framework I introduced with commit
74e857c6c7f9and some followups? Maybe it is possible to expand this framework by adding more callbacks to structlibxl_device_typeand have some common function(s) inlibxl_device.c?Juergen
Quoted 6 lines
For me the drawback of more generic way is to cast
device_typeto void* and back which
may be used by client in improper way.Thanks.
To summarize:
There are two ways to rework the patches:
1. Keep interface between xl an libxl as is and put duplicated code into libxl_device_type specific functions.
2. Change interface to call libxl_device_type specific functions directly from xl:
libxl_device_vtpm *vtpms;
vtpms = (libxl_device_vtpm*)libxl_device_list_get(LIBXL_DEVTYPE_VTPM, ...);
...
libxl__device_list_free(LIBXL_DEVTYPE_VTPM, vtpms, nr);
But I need feedback from maintainers.
Adding maintainers to CC.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 14 lines · Oleksandr Grytsov
To summarize:
There are two ways to rework the patches:
1. Keep interface between xl an libxl as is and put duplicated code into
libxl_device_typespecific functions.2. Change interface to call
libxl_device_typespecific functions directly from xl:
libxl_device_vtpm*vtpms;vtpms = (libxl_device_vtpm*)libxl_device_list_get(LIBXL_DEVTYPE_VTPM, ...);
Quoted 7 lines
...
libxl__device_list_free(LIBXL_DEVTYPE_VTPM, vtpms, nr);But I need feedback from maintainers.
Adding maintainers to CC.
I'm leaning towards #1 because we get type-safety that way.
Ian?
Wei.
Quoted 1 line
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel