[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 4/4] libxl: move DEFINE_DEVICE* macros to libxl_internal.h
In order to be able to have all functions related to a device type in a single source file move the macros used to generate device type specific functions to libxl_internal.h. Rename the macros as they are no longer local to a source file. While at it hide device remove and device destroy in one macro as those are always used in pairs. Move usage of the macros to the appropriate source files. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> --- tools/libxl/libxl.c | 143 +++++++++---------------------------------- tools/libxl/libxl_device.c | 36 ----------- tools/libxl/libxl_internal.h | 106 +++++++++++++++++++++----------- tools/libxl/libxl_pvusb.c | 25 +++++--- 4 files changed, 115 insertions(+), 195 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index b3deef0..68b77b9 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1980,7 +1980,7 @@ out: /******************************************************************************/ /* generic callback for devices that only need to set ao_complete */ -static void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev) +void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); @@ -2055,9 +2055,9 @@ static int libxl__device_from_vtpm(libxl__gc *gc, uint32_t domid, return 0; } -void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, - libxl_device_vtpm *vtpm, - libxl__ao_device *aodev) +static void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, + libxl_device_vtpm *vtpm, + libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); flexarray_t *front; @@ -2629,8 +2629,9 @@ out: return; } -void libxl__device_disk_add(libxl__egc *egc, uint32_t domid, - libxl_device_disk *disk, libxl__ao_device *aodev) +static void libxl__device_disk_add(libxl__egc *egc, uint32_t domid, + libxl_device_disk *disk, + libxl__ao_device *aodev) { device_disk_add(egc, domid, disk, aodev, NULL, NULL); } @@ -3432,8 +3433,9 @@ static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, return 0; } -void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, - libxl_device_nic *nic, libxl__ao_device *aodev) +static void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, + libxl_device_nic *nic, + libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); flexarray_t *front; @@ -4298,136 +4300,49 @@ out: /******************************************************************************/ -/* Macro for defining device remove/destroy functions in a compact way */ /* The following functions are defined: + * libxl_device_disk_add + * libxl__add_disks * libxl_device_disk_remove * libxl_device_disk_destroy + * libxl_device_nic_add + * libxl__add_nics * libxl_device_nic_remove * libxl_device_nic_destroy + * libxl_device_vtpm_add + * libxl__add_vtpms * libxl_device_vtpm_remove * libxl_device_vtpm_destroy * libxl_device_vkb_remove * libxl_device_vkb_destroy * libxl_device_vfb_remove * libxl_device_vfb_destroy - * libxl_device_usbctrl_remove - * libxl_device_usbctrl_destroy */ -#define DEFINE_DEVICE_REMOVE_EXT(type, remtype, removedestroy, f) \ - int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ - uint32_t domid, libxl_device_##type *type, \ - const libxl_asyncop_how *ao_how) \ - { \ - AO_CREATE(ctx, domid, ao_how); \ - libxl__device *device; \ - libxl__ao_device *aodev; \ - int rc; \ - \ - GCNEW(device); \ - rc = libxl__device_from_##type(gc, domid, type, device); \ - if (rc != 0) goto out; \ - \ - GCNEW(aodev); \ - libxl__prepare_ao_device(ao, aodev); \ - aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ - aodev->dev = device; \ - aodev->callback = device_addrm_aocomplete; \ - aodev->force = f; \ - libxl__initiate_device_##remtype##_remove(egc, aodev); \ - \ - out: \ - if (rc) return AO_CREATE_FAIL(rc); \ - return AO_INPROGRESS; \ - } - -#define DEFINE_DEVICE_REMOVE(type, removedestroy, f) \ - DEFINE_DEVICE_REMOVE_EXT(type, generic, removedestroy, f) - -#define DEFINE_DEVICE_REMOVE_CUSTOM(type, removedestroy, f) \ - DEFINE_DEVICE_REMOVE_EXT(type, type, removedestroy, f) - -/* Define all remove/destroy functions and undef the macro */ - -/* disk */ -DEFINE_DEVICE_REMOVE(disk, remove, 0) -DEFINE_DEVICE_REMOVE(disk, destroy, 1) - -/* nic */ -DEFINE_DEVICE_REMOVE(nic, remove, 0) -DEFINE_DEVICE_REMOVE(nic, destroy, 1) - -/* vkb */ -DEFINE_DEVICE_REMOVE(vkb, remove, 0) -DEFINE_DEVICE_REMOVE(vkb, destroy, 1) - -/* vfb */ - -DEFINE_DEVICE_REMOVE(vfb, remove, 0) -DEFINE_DEVICE_REMOVE(vfb, destroy, 1) - -/* vtpm */ -DEFINE_DEVICE_REMOVE(vtpm, remove, 0) -DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) - -/* usbctrl */ -DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, remove, 0) -DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl, destroy, 1) /* channel/console hotunplug is not implemented. There are 2 possibilities: * 1. add support for secondary consoles to xenconsoled * 2. dynamically add/remove qemu chardevs via qmp messages. */ -#undef DEFINE_DEVICE_REMOVE -#undef DEFINE_DEVICE_REMOVE_CUSTOM -#undef DEFINE_DEVICE_REMOVE_EXT - -/******************************************************************************/ - -/* Macro for defining device addition functions in a compact way */ -/* The following functions are defined: - * libxl_device_disk_add - * libxl_device_nic_add - * libxl_device_vtpm_add - * libxl_device_usbctrl_add - * libxl_device_usbdev_add - */ - -#define DEFINE_DEVICE_ADD(type) \ - int libxl_device_##type##_add(libxl_ctx *ctx, \ - uint32_t domid, libxl_device_##type *type, \ - const libxl_asyncop_how *ao_how) \ - { \ - AO_CREATE(ctx, domid, ao_how); \ - libxl__ao_device *aodev; \ - \ - GCNEW(aodev); \ - libxl__prepare_ao_device(ao, aodev); \ - aodev->action = LIBXL__DEVICE_ACTION_ADD; \ - aodev->callback = device_addrm_aocomplete; \ - aodev->update_json = true; \ - libxl__device_##type##_add(egc, domid, type, aodev); \ - \ - return AO_INPROGRESS; \ - } - -/* Define alladd functions and undef the macro */ - /* disk */ -DEFINE_DEVICE_ADD(disk) +LIBXL_DEFINE_DEVICE_ADD(disk) +LIBXL_DEFINE_DEVICES_ADD(disk) +LIBXL_DEFINE_DEVICE_REMOVE(disk) /* nic */ -DEFINE_DEVICE_ADD(nic) +LIBXL_DEFINE_DEVICE_ADD(nic) +LIBXL_DEFINE_DEVICES_ADD(nic) +LIBXL_DEFINE_DEVICE_REMOVE(nic) /* vtpm */ -DEFINE_DEVICE_ADD(vtpm) +LIBXL_DEFINE_DEVICE_ADD(vtpm) +static LIBXL_DEFINE_DEVICES_ADD(vtpm) +LIBXL_DEFINE_DEVICE_REMOVE(vtpm) -/* usbctrl */ -DEFINE_DEVICE_ADD(usbctrl) +/* vkb */ +LIBXL_DEFINE_DEVICE_REMOVE(vkb) -/* usb */ -DEFINE_DEVICE_ADD(usbdev) - -#undef DEFINE_DEVICE_ADD +/* vfb */ +LIBXL_DEFINE_DEVICE_REMOVE(vfb) /******************************************************************************/ diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 4717027..200bfad 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -677,42 +677,6 @@ void libxl__multidev_prepared(libxl__egc *egc, /******************************************************************************/ -/* Macro for defining the functions that will add a bunch of disks when - * inside an async op with multidev. - * This macro is added to prevent repetition of code. - * - * The following functions are defined: - * libxl__add_disks - * libxl__add_nics - * libxl__add_vtpms - * libxl__add_usbctrls - * libxl__add_usbs - */ - -#define DEFINE_DEVICES_ADD(type) \ - void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \ - libxl_domain_config *d_config, \ - libxl__multidev *multidev) \ - { \ - AO_GC; \ - int i; \ - for (i = 0; i < d_config->num_##type##s; i++) { \ - libxl__ao_device *aodev = libxl__multidev_prepare(multidev); \ - libxl__device_##type##_add(egc, domid, &d_config->type##s[i], \ - aodev); \ - } \ - } - -DEFINE_DEVICES_ADD(disk) -DEFINE_DEVICES_ADD(nic) -DEFINE_DEVICES_ADD(vtpm) -DEFINE_DEVICES_ADD(usbctrl) -DEFINE_DEVICES_ADD(usbdev) - -#undef DEFINE_DEVICES_ADD - -/******************************************************************************/ - int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) { const char *be_path = libxl__device_backend_path(gc, dev); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 79ce392..00b1f0c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2379,6 +2379,9 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*); */ _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev); +/* generic callback for devices that only need to set ao_complete */ +_hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev); + struct libxl__ao_device { /* filled in by user */ libxl__ao *ao; @@ -2621,26 +2624,6 @@ struct libxl__multidev { * xenstore entry afterwards. We have both JSON and xenstore entry, * it's a valid state. */ -_hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid, - libxl_device_disk *disk, - libxl__ao_device *aodev); - -/* AO operation to connect a nic device */ -_hidden void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, - libxl_device_nic *nic, - libxl__ao_device *aodev); - -_hidden void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, - libxl_device_vtpm *vtpm, - libxl__ao_device *aodev); - -_hidden void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, - libxl_device_usbctrl *usbctrl, - libxl__ao_device *aodev); - -_hidden void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, - libxl_device_usbdev *usbdev, - libxl__ao_device *aodev); /* Internal function to connect a vkb device */ _hidden int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid, @@ -2674,10 +2657,6 @@ _hidden void libxl__wait_device_connection(libxl__egc*, _hidden void libxl__initiate_device_generic_remove(libxl__egc *egc, libxl__ao_device *aodev); -_hidden int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, - libxl_device_usbctrl *usbctrl, - libxl__device *device); - _hidden void libxl__initiate_device_usbctrl_remove(libxl__egc *egc, libxl__ao_device *aodev); @@ -3390,6 +3369,73 @@ _hidden void libxl__bootloader_init(libxl__bootloader_state *bl); _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st); /*----- Generic Device Handling -----*/ +#define LIBXL_DEFINE_DEVICE_ADD(type) \ + int libxl_device_##type##_add(libxl_ctx *ctx, \ + uint32_t domid, libxl_device_##type *type, \ + const libxl_asyncop_how *ao_how) \ + { \ + AO_CREATE(ctx, domid, ao_how); \ + libxl__ao_device *aodev; \ + \ + GCNEW(aodev); \ + libxl__prepare_ao_device(ao, aodev); \ + aodev->action = LIBXL__DEVICE_ACTION_ADD; \ + aodev->callback = device_addrm_aocomplete; \ + aodev->update_json = true; \ + libxl__device_##type##_add(egc, domid, type, aodev); \ + \ + return AO_INPROGRESS; \ + } + +#define LIBXL_DEFINE_DEVICES_ADD(type) \ + void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \ + libxl_domain_config *d_config, \ + libxl__multidev *multidev) \ + { \ + AO_GC; \ + int i; \ + for (i = 0; i < d_config->num_##type##s; i++) { \ + libxl__ao_device *aodev = libxl__multidev_prepare(multidev); \ + libxl__device_##type##_add(egc, domid, &d_config->type##s[i], \ + aodev); \ + } \ + } + +#define LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, remtype, removedestroy, f) \ + int libxl_device_##type##_##removedestroy(libxl_ctx *ctx, \ + uint32_t domid, libxl_device_##type *type, \ + const libxl_asyncop_how *ao_how) \ + { \ + AO_CREATE(ctx, domid, ao_how); \ + libxl__device *device; \ + libxl__ao_device *aodev; \ + int rc; \ + \ + GCNEW(device); \ + rc = libxl__device_from_##type(gc, domid, type, device); \ + if (rc != 0) goto out; \ + \ + GCNEW(aodev); \ + libxl__prepare_ao_device(ao, aodev); \ + aodev->action = LIBXL__DEVICE_ACTION_REMOVE; \ + aodev->dev = device; \ + aodev->callback = device_addrm_aocomplete; \ + aodev->force = f; \ + libxl__initiate_device_##remtype##_remove(egc, aodev); \ + \ + out: \ + if (rc) return AO_CREATE_FAIL(rc); \ + return AO_INPROGRESS; \ + } + +#define LIBXL_DEFINE_DEVICE_REMOVE(type) \ + LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, remove, 0) \ + LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, generic, destroy, 1) + +#define LIBXL_DEFINE_DEVICE_REMOVE_CUSTOM(type) \ + LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, type, remove, 0) \ + LIBXL_DEFINE_DEVICE_REMOVE_EXT(type, type, destroy, 1) + struct libxl_device_type { char *type; int num_offset; /* Offset of # of devices in libxl_domain_config */ @@ -3508,18 +3554,6 @@ _hidden void libxl__add_nics(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev); -_hidden void libxl__add_vtpms(libxl__egc *egc, libxl__ao *ao, uint32_t domid, - libxl_domain_config *d_config, - libxl__multidev *multidev); - -_hidden void libxl__add_usbctrls(libxl__egc *egc, libxl__ao *ao, - uint32_t domid, libxl_domain_config *d_config, - libxl__multidev *multidev); - -_hidden void libxl__add_usbdevs(libxl__egc *egc, libxl__ao *ao, - uint32_t domid, libxl_domain_config *d_config, - libxl__multidev *multidev); - /*----- device model creation -----*/ /* First layer; wraps libxl__spawn_spawn. */ diff --git a/tools/libxl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c index 5edd206..41ea6bc 100644 --- a/tools/libxl/libxl_pvusb.c +++ b/tools/libxl/libxl_pvusb.c @@ -69,9 +69,9 @@ out: return rc; } -int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, - libxl_device_usbctrl *usbctrl, - libxl__device *device) +static int libxl__device_from_usbctrl(libxl__gc *gc, uint32_t domid, + libxl_device_usbctrl *usbctrl, + libxl__device *device) { device->backend_devid = usbctrl->devid; device->backend_domid = usbctrl->backend_domid; @@ -218,9 +218,9 @@ static char *pvusb_get_device_type(libxl_usbctrl_type type) * Before calling this function, aodev should be properly filled: * aodev->ao, aodev->callback, aodev->update_json, ... */ -void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, - libxl_device_usbctrl *usbctrl, - libxl__ao_device *aodev) +static void libxl__device_usbctrl_add(libxl__egc *egc, uint32_t domid, + libxl_device_usbctrl *usbctrl, + libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); libxl__device *device; @@ -263,6 +263,10 @@ out: return; } +LIBXL_DEFINE_DEVICE_ADD(usbctrl) +static LIBXL_DEFINE_DEVICES_ADD(usbctrl) +LIBXL_DEFINE_DEVICE_REMOVE_CUSTOM(usbctrl) + static int libxl__device_usbdev_list_for_usbctrl(libxl__gc *gc, uint32_t domid, libxl_devid usbctrl, libxl_device_usbdev **usbdevs, @@ -1423,9 +1427,9 @@ out: * Before calling this function, aodev should be properly filled: * aodev->ao, aodev->callback, aodev->update_json, ... */ -void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, - libxl_device_usbdev *usbdev, - libxl__ao_device *aodev) +static void libxl__device_usbdev_add(libxl__egc *egc, uint32_t domid, + libxl_device_usbdev *usbdev, + libxl__ao_device *aodev) { STATE_AO_GC(aodev->ao); int rc; @@ -1491,6 +1495,9 @@ out: return; } +LIBXL_DEFINE_DEVICE_ADD(usbdev) +static LIBXL_DEFINE_DEVICES_ADD(usbdev) + static int do_usbdev_remove(libxl__gc *gc, uint32_t domid, libxl_device_usbdev *usbdev) { -- 2.6.6 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |