libxl: extend device type framework
cover libxl: extend device type framework
Extend the device type framework in libxl to cover more functions in a generic way. This allows to have all functionality of a specific device type in just one source file instead of spreading it via multiple files and have functions to deal with multiple device types in a similar way.
Some patches of this series can be regarded as RFC, as having e.g. all nic related functions in one file is a matter of taste. I haven't marked the patches as RFC as they are completely tested and I believe the result is an improvement over current status.
Juergen Gross (6):
libxl: add "merge" function to generic device type support
libxl: add "pv device mode needed" support to device type framework
libxl: move library pvusb specific code into libxl_pvusb.c
libxl: split libxl vtpm code into one source
libxl: add config update callback to device type framework
libxl: move common nic stuff into one source
tools/libxl/Makefile | 1 + tools/libxl/libxl.c | 930 ++++++------------------------------------- tools/libxl/libxl_create.c | 35 +- tools/libxl/libxl_dm.c | 31 +- tools/libxl/libxl_internal.c | 21 +- tools/libxl/libxl_internal.h | 77 ++-- tools/libxl/libxl_nic.c | 554 ++++++++++++++++++++++++++ tools/libxl/libxl_pci.c | 8 +- tools/libxl/libxl_pvusb.c | 42 +- tools/libxl/libxl_utils.c | 96 ----- tools/libxl/libxl_vtpm.c | 380 ++++++++++++++++++ 11 files changed, 1192 insertions(+), 983 deletions(-) create mode 100644 tools/libxl/libxl_nic.c create mode 100644 tools/libxl/libxl_vtpm.c
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/6 libxl: add "merge" function to generic device type support
Instead of using a macro generating the code to merge xenstore and json configuration data, use the generic device type support for this purpose.
This requires to add some accessor functions to the framework and a structure for disks (as disks are added separately they didn't need such a structure up to now).
--- tools/libxl/libxl.c | 181 ++++++++++++++++++++++++------------------- tools/libxl/libxl_create.c | 18 +++-- tools/libxl/libxl_internal.h | 52 +++++++++++-- tools/libxl/libxl_pci.c | 8 +- tools/libxl/libxl_pvusb.c | 12 +++ 5 files changed, 181 insertions(+), 90 deletions(-)
tools/libxl/libxl.c +103 -78
@@ -7371,93 +7371,68 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,* entry retrieved from xenstore while "dst" points to the entry * retrieve from JSON. */ -#define MERGE(type, ptr, compare, merge) \ - do { \ - libxl_device_##type *p = NULL; \ - int i, j, num; \ - \ - p = libxl_device_##type##_list(CTX, domid, &num); \ - if (p == NULL) { \ - LOG(DEBUG, \ - "no %s from xenstore for domain %d", \ - #type, domid); \ - } \ - \ - for (i = 0; i < d_config->num_##ptr; i++) { \ - libxl_device_##type *q = &d_config->ptr[i]; \ - for (j = 0; j < num; j++) { \ - if (compare(&p[j], q)) \ - break; \ - } \ - \ - if (j < num) { /* found in xenstore */ \ - libxl_device_##type *dst, *src; \ - dst = q; \ - src = &p[j]; \ - merge; \ - } else {/* not found in xenstore */ \ -LOG (WARN , \ -"Device present in JSON but not in xenstore, ignored" ); \ - \ - libxl_device_##type##_dispose(q); \ - \ - for (j = i; j < d_config->num_##ptr - 1; j++) \ - memcpy(&d_config->ptr[j], &d_config->ptr[j+1], \ - sizeof(libxl_device_##type)); \ - \ - d_config->ptr = \ - libxl__realloc(NOGC, d_config->ptr, \ - sizeof(libxl_device_##type) * \ - (d_config->num_##ptr - 1)); \ - \ -/* rewind counters */ \ - d_config->num_##ptr--; \ - i--; \ - } \ - } \ - \ - for (i = 0; i < num; i++) \ - libxl_device_##type##_dispose(&p[i]); \ - free(p); \ - } while (0); + { +const struct libxl_device_type *dt; +int idx; -MERGE (nic, nics,COMPARE_DEVID , {}); +for (idx =0 ;; idx++) { +void *p =NULL ; +void **devs; +int i, j, num; +int *num_dev; -MERGE (vtpm, vtpms,COMPARE_DEVID , {}); + dt = device_type_tbl[idx]; +if (!dt) +break ; -MERGE (pci, pcidevs,COMPARE_PCI , {}); +if (!dt->list || !dt->compare) +continue ; -MERGE (usbctrl, usbctrls,COMPARE_USBCTRL , {}); + num_dev =libxl__device_type_get_num (dt, d_config); + p = dt->list (CTX , domid, &num); +if (p ==NULL ) { +LOG (DEBUG ,"no %s from xenstore for domain %d" , + dt->type, domid); + } + devs =libxl__device_type_get_ptr (dt, d_config); + +for (i =0 ; i < *num_dev; i++) { +void *q; + + q =libxl__device_type_get_elem (dt, d_config, i); +for (j =0 ; j < num; j++) { +if (dt->compare (p + dt->dev_elem_size * j, q)) +break ; + } + +if (j < num) {/* found in xenstore */ +if (dt->merge) + dt->merge (ctx, p + dt->dev_elem_size * j, q); + }else {/* not found in xenstore */ +LOG (WARN , +"Device present in JSON but not in xenstore, ignored" ); + + dt->dispose (q); + +for (j = i; j < *num_dev -1 ; j++) +memcpy (libxl__device_type_get_elem (dt, d_config, j), +libxl__device_type_get_elem (dt, d_config, j+1 ), + dt->dev_elem_size); -MERGE (usbdev, usbdevs,COMPARE_USB , {}); +/* rewind counters */ + (*num_dev)--; + i--; -/* Take care of removable device. We maintain invariant in the -* insert / remove operation so that: -* 1. if xenstore is "empty" while JSON is not, the result -* is "empty" -* 2. if xenstore has a different media than JSON, use the -* one in JSON -* 3. if xenstore and JSON have the same media, well, you -* know the answer :-) -* -* Currently there is only one removable device -- CDROM. -* Look for libxl_cdrom_insert for reference. -*/ -MERGE (disk, disks,COMPARE_DISK , { -if (src->removable) { -if (!src->pdev_path || *src->pdev_path =='\0' ) { -/* 1, no media in drive */ -free (dst->pdev_path); - dst->pdev_path =libxl__strdup (NOGC ,"" ); - dst->format =LIBXL_DISK_FORMAT_EMPTY ; - }else { -/* 2 and 3, use JSON, no need to touch anything */ - ; + *devs =libxl__realloc (NOGC , *devs, + dt->dev_elem_size * *num_dev); } } - }); -#undef MERGE +for (i =0 ; i < num; i++) + dt->dispose (p + dt->dev_elem_size * i); +free (p); + } + } out:if (lock)libxl__unlock_domain_userdata (lock);
@@ -7466,6 +7441,56 @@ out:return rc; } +static int libxl_device_disk_compare (libxl_device_disk *d1, +libxl_device_disk *d2) +{ +return COMPARE_DISK (d1, d2); +} + +/* Take care of removable device. We maintain invariant in the +* insert / remove operation so that: +* 1. if xenstore is "empty" while JSON is not, the result +* is "empty" +* 2. if xenstore has a different media than JSON, use the +* one in JSON +* 3. if xenstore and JSON have the same media, well, you +* know the answer :-) +* +* Currently there is only one removable device -- CDROM. +* Look for libxl_cdrom_insert for reference. +*/ +static void libxl_device_disk_merge (libxl_ctx *ctx,void *d1,void *d2) +{ +GC_INIT (ctx); +libxl_device_disk *src = d1; +libxl_device_disk *dst = d2; + +if (src->removable) { +if (!src->pdev_path || *src->pdev_path =='\0' ) { +/* 1, no media in drive */ +free (dst->pdev_path); + dst->pdev_path =libxl__strdup (NOGC ,"" ); + dst->format =LIBXL_DISK_FORMAT_EMPTY ; + }else { +/* 2 and 3, use JSON, no need to touch anything */ + ; + } + } +} + +static int libxl_device_nic_compare (libxl_device_nic *d1, +libxl_device_nic *d2) +{ +return COMPARE_DEVID (d1, d2); +} + +static int libxl_device_vtpm_compare (libxl_device_vtpm *d1, +libxl_device_vtpm *d2) +{ +return COMPARE_DEVID (d1, d2); +} + +DEFINE_DEVICE_TYPE_STRUCT(disk, .merge = libxl_device_disk_merge);DEFINE_DEVICE_TYPE_STRUCT (nic);DEFINE_DEVICE_TYPE_STRUCT (vtpm);
tools/libxl/libxl_create.c +13 -5
@@ -1420,15 +1420,19 @@ out: aodev->callback (egc, aodev); } +#define libxl_device_dtdev_list NULL +#define libxl_device_dtdev_compare NULLstatic DEFINE_DEVICE_TYPE_STRUCT (dtdev); -static const struct libxl_device_type *device_type_tbl[] = { +const struct libxl_device_type *device_type_tbl[] = { + &libxl__disk_devtype, &libxl__nic_devtype, &libxl__vtpm_devtype, &libxl__usbctrl_devtype, &libxl__usbdev_devtype, &libxl__pcidev_devtype, &libxl__dtdev_devtype, +NULL }; static void domcreate_attach_devices(libxl__egc *egc,
@@ -1448,9 +1452,9 @@ static void domcreate_attach_devices(libxl__egc *egc, } dcs->device_type_idx++; -if (dcs->device_type_idx <ARRAY_SIZE (device_type_tbl)) { - dt = device_type_tbl[dcs->device_type_idx]; -if (*(int *)((void *)d_config + dt->num_offset) >0 ) { + dt = device_type_tbl[dcs->device_type_idx]; +if (dt) { +if (*libxl__device_type_get_num (dt, d_config) >0 ) {/* Attach devices */ libxl__multidev_begin (ao, &dcs->multidev); dcs->multidev.callback = domcreate_attach_devices;
@@ -1497,7 +1501,11 @@ static void domcreate_devmodel_started(libxl__egc *egc, } } - dcs->device_type_idx =-1 ; +/* +* Setting dcs->device_type_idx to 0 will skip disks, those have been +* already added. +*/ + dcs->device_type_idx =0 ;domcreate_attach_devices (egc, &dcs->multidev,0 );return ;
tools/libxl/libxl_internal.h +46 -6
69 lines not on this page · raw message
tools/libxl/libxl_pci.c +7 -1
@@ -1698,7 +1698,13 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,return 0 ; } -DEFINE_DEVICE_TYPE_STRUCT (pcidev); +static int libxl_device_pci_compare (libxl_device_pci *d1, +libxl_device_pci *d2) +{ +return COMPARE_PCI (d1, d2); +} + +DEFINE_DEVICE_TYPE_STRUCT_X (pcidev, pci);/* * Local variables:
tools/libxl/libxl_pvusb.c +12 -0
@@ -1675,6 +1675,18 @@ out:return rc; } +static int libxl_device_usbctrl_compare (libxl_device_usbctrl *d1, +libxl_device_usbctrl *d2) +{ +return COMPARE_USBCTRL (d1, d2); +} + +static int libxl_device_usbdev_compare (libxl_device_usbdev *d1, +libxl_device_usbdev *d2) +{ +return COMPARE_USB (d1, d2); +} +DEFINE_DEVICE_TYPE_STRUCT (usbctrl);DEFINE_DEVICE_TYPE_STRUCT (usbdev);
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 1/6] libxl: add "merge" function to generic device type support
Quoted 9 lines · Juergen Gross
Instead of using a macro generating the code to merge xenstore and json configuration data, use the generic device type support for this purpose.
This requires to add some accessor functions to the framework and a structure for disks (as disks are added separately they didn't need such a structure up to now).
Signed-off-by Juergen Gross <[email protected]>
I definitely think this is a good idea.
The code looks good to me:
I didn't do a line-by-line review though because most code looks very mechanical. I'm confident that we can sort out issues should they arise.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/6] libxl: add "merge" function to generic device type support
In reply to Juergen Grosstools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7373
Quoted 12 lines · Juergen Gross
Instead of using a macro generating the code to merge xenstore and json configuration data, use the generic device type support for this purpose.
This requires to add some accessor functions to the framework and a structure for disks (as disks are added separately they didn't need such a structure up to now).+++
b/tools/libxl/libxl.ctools/libxl/libxl.c +2
-0@@ -7371,93 +7371,68 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, +if (!dt->list || !dt->compare) +continue ;
This makes libxl_device_<type>_compare optional ...
tools/libxl/libxl_internal.h _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st); · line 3466
Quoted 12 lines
tools/libxl/libxl_internal.h +12
-0+#define DEFINE_DEVICE_TYPE_STRUCT_X (name, sname, ...) \ + const struct libxl_device_type libxl__ ## name ## _devtype = { \ + .type = #sname, \ + .ptr_offset = offsetof(libxl_domain_config, name ## s), \ + .num_offset = offsetof(libxl_domain_config, num_ ## name ## s), \ + .dev_elem_size = sizeof(libxl_device_ ## sname), \ + .add = libxl__add_ ## name ## s, \ + .list = (void *(*)(libxl_ctx *, uint32_t, int *)) \ + libxl_device_ ## sname ## _list, \ + .dispose = (void (*)(void *))libxl_device_ ## sname ## _dispose, \ + .compare = (int (*)(void *, void *)) \ + libxl_device_ ## sname ## _compare, \
... and this makes libxl_device_<type>_compare mandatory.
Which one is correct?
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/6] libxl: add "merge" function to generic device type support
Quoted 9 lines · Olaf Hering
Quoted 6 lines · Juergen Gross
Instead of using a macro generating the code to merge xenstore and json configuration data, use the generic device type support for this purpose.
This requires to add some accessor functions to the framework and a structure for disks (as disks are added separately they didn't need such a structure up to now).
Quoted 8 lines
tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7373
Quoted 5 lines
+++
b/tools/libxl/libxl.ctools/libxl/libxl.c +2
-0@@ -7371,93 +7371,68 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, +if (!dt->list || !dt->compare) +continue ;This makes libxl_device_<type>_compare optional ...
Actually this makes both list and compare optional.
I would say both should be mandatory -- why would you have a device type that can't be listed or compared?
Juergen?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/6] libxl: add "merge" function to generic device type support
Quoted 17 lines · Wei Liu
Quoted 16 lines · Olaf Hering
Quoted 12 lines · Juergen Gross
Instead of using a macro generating the code to merge xenstore and json configuration data, use the generic device type support for this purpose.
This requires to add some accessor functions to the framework and a structure for disks (as disks are added separately they didn't need such a structure up to now).+++
b/tools/libxl/libxl.ctools/libxl/libxl.c +2
-0@@ -7371,93 +7371,68 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, +if (!dt->list || !dt->compare) +continue ;
Quoted 8 lines
Quoted 1 line
This makes libxl_device_<type>_compare optional ...
Actually this makes both list and compare optional.
I would say both should be mandatory -- why would you have a device type that can't be listed or compared?
Juergen?
I think above lines predate the introduction ofDEFINE_DEVICE_TYPE_STRUCT_X().
They can probably be removed.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 2/6 libxl: add "pv device mode needed" support to device type framework
In reply to Juergen GrossAdd another callback to the device type framework in order to aid decision whether a pv domain needs a device model.
--- tools/libxl/libxl.c | 14 +++++++++++++- tools/libxl/libxl_create.c | 8 ++------ tools/libxl/libxl_dm.c | 31 +++++++++++++++++-------------- tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_pvusb.c | 12 +++++++++++- 5 files changed, 45 insertions(+), 22 deletions(-)
tools/libxl/libxl.c +13 -1
@@ -7478,6 +7478,14 @@ static void libxl_device_disk_merge(libxl_ctx *ctx, void *d1, void *d2) } } +static int libxl_device_disk_dm_needed (void *e,unsigned domid) +{ +libxl_device_disk *elem = e; + +return elem->backend ==LIBXL_DISK_BACKEND_QDISK && + elem->backend_domid == domid; +} +static int libxl_device_nic_compare (libxl_device_nic *d1,libxl_device_nic *d2) {
@@ -7490,7 +7498,11 @@ static int libxl_device_vtpm_compare(libxl_device_vtpm *d1,return COMPARE_DEVID (d1, d2); } -DEFINE_DEVICE_TYPE_STRUCT(disk, .merge = libxl_device_disk_merge); +DEFINE_DEVICE_TYPE_STRUCT(disk, + .merge = libxl_device_disk_merge, + .dm_needed = libxl_device_disk_dm_needed, + .skip_attach =1 +);DEFINE_DEVICE_TYPE_STRUCT (nic);DEFINE_DEVICE_TYPE_STRUCT (vtpm);
tools/libxl/libxl_create.c +2 -6
@@ -1454,7 +1454,7 @@ static void domcreate_attach_devices(libxl__egc *egc, dcs->device_type_idx++; dt = device_type_tbl[dcs->device_type_idx];if (dt) { -if (*libxl__device_type_get_num (dt, d_config) >0 ) { +if (*libxl__device_type_get_num (dt, d_config) >0 && !dt->skip_attach) {/* Attach devices */ libxl__multidev_begin (ao, &dcs->multidev); dcs->multidev.callback = domcreate_attach_devices;
@@ -1501,11 +1501,7 @@ static void domcreate_devmodel_started(libxl__egc *egc, } } -/* -* Setting dcs->device_type_idx to 0 will skip disks, those have been -* already added. -*/ - dcs->device_type_idx =0 ; + dcs->device_type_idx =-1 ;domcreate_attach_devices (egc, &dcs->multidev,0 );return ;
tools/libxl/libxl_dm.c +17 -14
@@ -2348,8 +2348,9 @@ int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)/* Return 0 if no dm needed, 1 if needed and <0 if error. */ int libxl__need_xenpv_qemu (libxl__gc *gc,libxl_domain_config *d_config) { -int i, ret; +int idx, i, ret, num;uint32_t domid; +const struct libxl_device_type *dt; ret =libxl__get_domid (gc, &domid);if (ret) {
@@ -2362,11 +2363,21 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config) goto out; } -for (i =0 ; i < d_config->num_disks; i++) { -if (d_config->disks[i].backend ==LIBXL_DISK_BACKEND_QDISK && - d_config->disks[i].backend_domid == domid) { - ret =1 ; - goto out; +for (idx =0 ;; idx++) { + dt = device_type_tbl[idx]; +if (!dt) +break ; + + num = *libxl__device_type_get_num (dt, d_config); +if (!dt->dm_needed || !num) +continue ; + +for (i =0 ; i < num; i++) { +if (dt->dm_needed (libxl__device_type_get_elem (dt, d_config, i), + domid)) { + ret =1 ; + goto out; + } } }
@@ -2380,14 +2391,6 @@ int libxl__need_xenpv_qemu(libxl__gc *gc, libxl_domain_config *d_config) } } -for (i =0 ; i < d_config->num_usbctrls; i++) { -if (d_config->usbctrls[i].type ==LIBXL_USBCTRL_TYPE_QUSB && - d_config->usbctrls[i].backend_domid == domid) { - ret =1 ; - goto out; - } - } - out:return ret; }
tools/libxl/libxl_internal.h +2 -0
@@ -3441,6 +3441,7 @@ _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st);struct libxl_device_type {char *type; +int skip_attach;/* Skip entry in domcreate_attach_devices() if 1 */ int ptr_offset;/* Offset of device array ptr in libxl_domain_config */ int num_offset;/* Offset of # of devices in libxl_domain_config */ int dev_elem_size;/* Size of one device element in array */
@@ -3450,6 +3451,7 @@ struct libxl_device_type {void (*dispose)(void *);int (*compare)(void *,void *);void (*merge)(libxl_ctx *,void *,void *); +int (*dm_needed)(void *,unsigned ); };#define DEFINE_DEVICE_TYPE_STRUCT_X (name, sname, ...) \
tools/libxl/libxl_pvusb.c +11 -1
@@ -1681,13 +1681,23 @@ static int libxl_device_usbctrl_compare(libxl_device_usbctrl *d1,return COMPARE_USBCTRL (d1, d2); } +static int libxl_device_usbctrl_dm_needed (void *e,unsigned domid) +{ +libxl_device_usbctrl *elem = e; + +return elem->type ==LIBXL_USBCTRL_TYPE_QUSB && + elem->backend_domid == domid; +} +static int libxl_device_usbdev_compare (libxl_device_usbdev *d1,libxl_device_usbdev *d2) {return COMPARE_USB (d1, d2); } -DEFINE_DEVICE_TYPE_STRUCT (usbctrl); +DEFINE_DEVICE_TYPE_STRUCT(usbctrl, + .dm_needed = libxl_device_usbctrl_dm_needed +);DEFINE_DEVICE_TYPE_STRUCT (usbdev);/*
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/6] libxl: add "pv device mode needed" support to device type framework
Quoted 4 lines · Juergen Gross
Add another callback to the device type framework in order to aid decision whether a pv domain needs a device model.
Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 3/6 libxl: move library pvusb specific code into libxl_pvusb.c
In reply to Juergen GrossOutside libxl_pvusb.c only libxl_util.c still contains some pvusb code.
Move it to libxl_pvusb.c.
--- tools/libxl/libxl_pvusb.c | 18 ++++++++++++++++++ tools/libxl/libxl_utils.c | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-)
tools/libxl/libxl_pvusb.c +18 -0
@@ -1695,6 +1695,24 @@ static int libxl_device_usbdev_compare(libxl_device_usbdev *d1,return COMPARE_USB (d1, d2); } +void libxl_device_usbctrl_list_free (libxl_device_usbctrl *list,int nr) +{ +int i; + +for (i =0 ; i < nr; i++) +libxl_device_usbctrl_dispose (&list[i]); +free (list); +} + +void libxl_device_usbdev_list_free (libxl_device_usbdev *list,int nr) +{ +int i; + +for (i =0 ; i < nr; i++) +libxl_device_usbdev_dispose (&list[i]); +free (list); +} + DEFINE_DEVICE_TYPE_STRUCT(usbctrl, .dm_needed = libxl_device_usbctrl_dm_needed );
tools/libxl/libxl_utils.c +0 -18
@@ -1310,24 +1310,6 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len)return ret; } -void libxl_device_usbctrl_list_free (libxl_device_usbctrl *list,int nr) -{ -int i; - -for (i =0 ; i < nr; i++) -libxl_device_usbctrl_dispose (&list[i]); -free (list); -} - -void libxl_device_usbdev_list_free (libxl_device_usbdev *list,int nr) -{ -int i; - -for (i =0 ; i < nr; i++) -libxl_device_usbdev_dispose (&list[i]); -free (list); -} -/* * Local variables: * mode: C
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 3/6] libxl: move library pvusb specific code into libxl_pvusb.c
Quoted 5 lines · Juergen Gross
Outside
libxl_pvusb.conlylibxl_util.cstill contains some pvusb code.Move it to
libxl_pvusb.c.Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/6 libxl: split libxl vtpm code into one source
In reply to Juergen GrossPut all vtpm related stuff of libxl into a dedicated source file.
--- tools/libxl/Makefile | 1 + tools/libxl/libxl.c | 302 ----------------------------------- tools/libxl/libxl_internal.h | 1 - tools/libxl/libxl_utils.c | 43 ----- tools/libxl/libxl_vtpm.c | 366 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 367 insertions(+), 346 deletions(-) create mode 100644 tools/libxl/libxl_vtpm.c
tools/libxl/Makefile +1 -0
@@ -115,6 +115,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ libxl_qmp.o libxl_event.o libxl_fork.o \ libxl_dom_suspend.o libxl_dom_save.o libxl_pvusb.o \ + libxl_vtpm.o \ $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl.c +0 -302
332 lines not on this page · raw message
tools/libxl/libxl_internal.h +0 -1
@@ -1221,7 +1221,6 @@ _hidden int libxl__device_disk_setdefault(libxl__gc *gc, uint32_t domid); _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,uint32_t domid,bool hotplug); -_hidden int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm); _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb); _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb); _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
tools/libxl/libxl_utils.c +0 -43
55 lines not on this page · raw message
tools/libxl/libxl_vtpm.c new file +366 -0
366 lines not on this page · raw message
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 4/6] libxl: split libxl vtpm code into one source
Quoted 3 lines · Juergen Gross
Put all vtpm related stuff of libxl into a dedicated source file.
Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 5/6 libxl: add config update callback to device type framework
In reply to Juergen GrossSome device types require a configuration update after resume of domain. Add a callback for this purpose.
--- tools/libxl/libxl.c | 17 ++++++++++++++++- tools/libxl/libxl_internal.c | 21 ++++++++++++++------- tools/libxl/libxl_internal.h | 17 +---------------- tools/libxl/libxl_vtpm.c | 16 +++++++++++++++- 4 files changed, 46 insertions(+), 25 deletions(-)
tools/libxl/libxl.c +16 -1
@@ -3147,6 +3147,14 @@ static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,return 0 ; } +static void libxl__update_config_nic (libxl__gc *gc,libxl_device_nic *dst, +const libxl_device_nic *src) +{ + dst->devid = src->devid; + dst->nictype = src->nictype; +libxl_mac_copy (CTX , &dst->mac, &src->mac); +} +static void libxl__device_nic_add (libxl__egc *egc,uint32_t domid,libxl_device_nic *nic,libxl__ao_device *aodev)
@@ -7197,12 +7205,19 @@ static int libxl_device_nic_compare(libxl_device_nic *d1,return COMPARE_DEVID (d1, d2); } +static void libxl_device_nic_update_config (libxl__gc *gc,void *d,void *s) +{ +libxl__update_config_nic (gc, d, s); +} + DEFINE_DEVICE_TYPE_STRUCT(disk, .merge = libxl_device_disk_merge, .dm_needed = libxl_device_disk_dm_needed, .skip_attach =1 ); -DEFINE_DEVICE_TYPE_STRUCT (nic); +DEFINE_DEVICE_TYPE_STRUCT(nic, + .update_config = libxl_device_nic_update_config +);/* * Local variables:
tools/libxl/libxl_internal.c +14 -7
@@ -537,15 +537,22 @@ void libxl__update_domain_configuration(libxl__gc *gc,libxl_domain_config *dst, const libxl_domain_config *src) { - int i; + int i, idx, num; +const struct libxl_device_type *dt; -/* update network interface information */ -for (i =0 ; i < src->num_nics; i++) -libxl__update_config_nic (gc, &dst->nics[i], &src->nics[i]); +for (idx =0 ;; idx++) { + dt = device_type_tbl[idx]; +if (!dt) +break ; -/* update vtpm information */ -for (i =0 ; i < src->num_vtpms; i++) -libxl__update_config_vtpm (gc, &dst->vtpms[i], &src->vtpms[i]); + num = *libxl__device_type_get_num (dt, src); +if (!dt->update_config || !num) +continue ; + +for (i =0 ; i < num; i++) + dt->update_config (gc,libxl__device_type_get_elem (dt, dst, i), +libxl__device_type_get_elem (dt, src, i)); + }/* update guest UUID */ libxl_uuid_copy (CTX , &dst->c_info.uuid, &src->c_info.uuid);
tools/libxl/libxl_internal.h +1 -16
@@ -3451,6 +3451,7 @@ struct libxl_device_type {int (*compare)(void *,void *);void (*merge)(libxl_ctx *,void *,void *);int (*dm_needed)(void *,unsigned ); +void (*update_config)(libxl__gc *,void *,void *); };#define DEFINE_DEVICE_TYPE_STRUCT_X (name, sname, ...) \
@@ -4192,22 +4193,6 @@ int libxl__set_domain_configuration(libxl__gc *gc, uint32_t domid,void libxl__update_domain_configuration (libxl__gc *gc,libxl_domain_config *dst,const libxl_domain_config *src); -static inline void libxl__update_config_nic (libxl__gc *gc, -libxl_device_nic *dst, -const libxl_device_nic *src) -{ - dst->devid = src->devid; - dst->nictype = src->nictype; -libxl_mac_copy (CTX , &dst->mac, &src->mac); -} - -static inline void libxl__update_config_vtpm (libxl__gc *gc, -libxl_device_vtpm *dst, -libxl_device_vtpm *src) -{ - dst->devid = src->devid; -libxl_uuid_copy (CTX , &dst->uuid, &src->uuid); -}/* Target memory in xenstore is different from what user has * asked for. The difference is video_memkb + (possible) fudge.
tools/libxl/libxl_vtpm.c +15 -1
@@ -41,6 +41,13 @@ static int libxl__device_from_vtpm(libxl__gc *gc, uint32_t domid,return 0 ; } +static void libxl__update_config_vtpm (libxl__gc *gc,libxl_device_vtpm *dst, +libxl_device_vtpm *src) +{ + dst->devid = src->devid; +libxl_uuid_copy (CTX , &dst->uuid, &src->uuid); +} +static void libxl__device_vtpm_add (libxl__egc *egc,uint32_t domid,libxl_device_vtpm *vtpm,libxl__ao_device *aodev)
@@ -350,11 +357,18 @@ void libxl_device_vtpm_list_free(libxl_device_vtpm* list, int nr)free (list); } +static void libxl_device_vtpm_update_config (libxl__gc *gc,void *d,void *s) +{ +libxl__update_config_vtpm (gc, d, s); +} + LIBXL_DEFINE_DEVICE_ADD(vtpm) static LIBXL_DEFINE_DEVICES_ADD(vtpm) LIBXL_DEFINE_DEVICE_REMOVE(vtpm) -DEFINE_DEVICE_TYPE_STRUCT(vtpm); +DEFINE_DEVICE_TYPE_STRUCT(vtpm, + .update_config = libxl_device_vtpm_update_config +);/* * Local variables:
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 5/6] libxl: add config update callback to device type framework
Quoted 4 lines · Juergen Gross
Some device types require a configuration update after resume of domain. Add a callback for this purpose.
Signed-off-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 6/6 libxl: move common nic stuff into one source
In reply to Juergen GrossPut all nic related stuff of libxl form common files into a dedicated source file.
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 474 +----------------------------------- tools/libxl/libxl_create.c | 23 +- tools/libxl/libxl_internal.h | 5 +- tools/libxl/libxl_nic.c | 554 +++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_utils.c | 35 --- 6 files changed, 573 insertions(+), 520 deletions(-) create mode 100644 tools/libxl/libxl_nic.c
tools/libxl/Makefile +1 -1
@@ -115,7 +115,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_save_callout.o _libxl_save_msgs_callout.o \ libxl_qmp.o libxl_event.o libxl_fork.o \ libxl_dom_suspend.o libxl_dom_save.o libxl_pvusb.o \ - libxl_vtpm.o \ + libxl_vtpm.o libxl_nic.o \ $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl.c +11 -463
519 lines not on this page · raw message
tools/libxl/libxl_create.c +3 -20
@@ -772,7 +772,6 @@ static void initiate_domain_create(libxl__egc *egc,libxl_ctx *ctx =libxl__gc_owner (gc);uint32_t domid;int i, ret; -size_t last_devid =-1 ;bool pod_enabled = false;/* convenience aliases */
@@ -932,25 +931,9 @@ static void initiate_domain_create(libxl__egc *egc,* Make two runs over configured NICs in order to avoid duplicate IDs * in case the caller partially assigned IDs. */ -for (i =0 ; i < d_config->num_nics; i++) { -/* We have to init the nic here, because we still haven't -* called libxl_device_nic_add when domcreate_launch_dm gets called, -* but qemu needs the nic information to be complete. -*/ - ret =libxl__device_nic_setdefault (gc, &d_config->nics[i], domid, - false); -if (ret) { -LOG (ERROR ,"Unable to set nic defaults for nic %d" , i); - goto error_out; - } - -if (d_config->nics[i].devid > last_devid) - last_devid = d_config->nics[i].devid; - } -for (i =0 ; i < d_config->num_nics; i++) { -if (d_config->nics[i].devid <0 ) - d_config->nics[i].devid = ++last_devid; - } + ret =libxl__device_nic_set_devids (gc, d_config, domid); +if (ret) + goto error_out;if (restore_fd >=0 || dcs->domid_soft_reset !=INVALID_DOMID ) {LOG (DEBUG ,"restoring, not running bootloader" );
tools/libxl/libxl_internal.h +4 -1
@@ -1288,7 +1288,6 @@ bool libxl__xswait_inuse(const libxl__xswait_state *ss);int libxl__xswait_start (libxl__gc *,libxl__xswait_state *); -/* * libxl__ev_devstate - waits a given time for a device to * reach a given state. Follows the libxl_ev_* conventions.
@@ -3679,6 +3678,10 @@ struct libxl__domain_create_state {libxl__multidev multidev; }; +_hidden int libxl__device_nic_set_devids(libxl__gc *gc, +libxl_domain_config *d_config, +uint32_t domid); +/*----- Domain suspend (save) functions -----*/ /* calls dss->callback when done */
tools/libxl/libxl_nic.c new file +554 -0
554 lines not on this page · raw message
tools/libxl/libxl_utils.c +0 -35
@@ -598,41 +598,6 @@ int libxl_pipe(libxl_ctx *ctx, int pipes[2])return ret; } -int libxl_mac_to_device_nic (libxl_ctx *ctx,uint32_t domid, -const char *mac,libxl_device_nic *nic) -{ -libxl_device_nic *nics; -int nb, rc, i; -libxl_mac mac_n; - - rc =libxl__parse_mac (mac, mac_n); -if (rc) -return rc; - - nics =libxl_device_nic_list (ctx, domid, &nb); -if (!nics) -return ERROR_FAIL ; - -memset (nic,0 ,sizeof (libxl_device_nic)); - - rc =ERROR_INVAL ; -for (i =0 ; i < nb; ++i) { -if (!libxl__compare_macs (&mac_n, &nics[i].mac)) { - *nic = nics[i]; - rc =0 ; - i++;/* Do not dispose this NIC on exit path */ -break ; - } -libxl_device_nic_dispose (&nics[i]); - } - -for (; i<nb; i++) -libxl_device_nic_dispose (&nics[i]); - -free (nics); -return rc; -} -int libxl_bitmap_alloc (libxl_ctx *ctx,libxl_bitmap *bitmap,int n_bits) {GC_INIT (ctx);
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 6/6] libxl: move common nic stuff into one source
Quoted 4 lines · Juergen Gross
Put all nic related stuff of libxl form common files into a dedicated source file.
Signed-off-by Juergen Gross <[email protected]>
Assuming this is pure code motion:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 18 lines · Juergen Gross
Extend the device type framework in libxl to cover more functions in a generic way. This allows to have all functionality of a specific device type in just one source file instead of spreading it via multiple files and have functions to deal with multiple device types in a similar way.
Some patches of this series can be regarded as RFC, as having e.g. all nic related functions in one file is a matter of taste. I haven't marked the patches as RFC as they are completely tested and I believe the result is an improvement over current status.
Juergen Gross (6):
libxl: add "merge" function to generic device type support
libxl: add "pv device mode needed" support to device type framework
libxl: move library pvusb specific code intolibxl_pvusb.c
libxl: split libxl vtpm code into one source
libxl: add config update callback to device type framework
libxl: move common nic stuff into one source
Quoted 15 lines
tools/libxl/Makefile | 1 + tools/libxl/libxl.c | 930 ++++++------------------------------------- tools/libxl/libxl_create.c | 35 +- tools/libxl/libxl_dm.c | 31 +- tools/libxl/libxl_internal.c | 21 +- tools/libxl/libxl_internal.h | 77 ++-- tools/libxl/libxl_nic.c | 554 ++++++++++++++++++++++++++ tools/libxl/libxl_pci.c | 8 +- tools/libxl/libxl_pvusb.c | 42 +- tools/libxl/libxl_utils.c | 96 ----- tools/libxl/libxl_vtpm.c | 380 ++++++++++++++++++ 11 files changed, 1192 insertions(+), 983 deletions(-) create mode 100644 tools/libxl/libxl_nic.c create mode 100644 tools/libxl/libxl_vtpm.c
Any comments on this series?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Series pushed to staging.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel