execute hotplug scripts from libxl
v4 cover execute hotplug scripts from libxl
This series have been splitted in several patches, to make them easier to review. Also the amount of changes introduced is quite important, since apart from all the hotplug necessary functions and modifications, libxl_domain_destroy has been converted to an async op. This was necessary in order to have async operations during device removal.
Also, as an important change, disk and nics are added at different points for HVM and device model based guests, since we need the disk in order to start Qemu, but the nic hotplug scripts should be called at a later point, when Qemu has created the corresponding tap device.
Patches 1-4 from the previous series are already commited, so they are removed from v4.
Pending:
[PATCH v3 01/10] libxl: change libxl__ao_device_remove to [PATCH v3 02/10] libxl: move device model creation prototypes [PATCH v3 03/10] libxl: convert libxl_domain_destroy to an async op [PATCH v3 04/10] libxl: convert libxl_device_disk_add to an asyn op [PATCH v3 05/10] libxl: convert libxl_device_nic_add to an async [PATCH v3 06/10] libxl: add option to choose who executes hotplug [PATCH v3 07/10] libxl: set nic type to VIF by default [PATCH v3 08/10] libxl: call hotplug scripts for disk devices from [PATCH v3 09/10] libxl: call hotplug scripts for nic devices from [PATCH v3 10/10] libxl: use libxl__xs_path_cleanup on device_destroy
Changes since v3:
* Fixed Python bindings.
* Fixed a mess in macro declaration DEFINE_DEVICE_REMOVE.
* Updated to upstream.
Changes since v2:
* Fixed IanJ comments.
Changes since v1:
* Removed all the unecessary code motion and code cleanup
* Split "convert libxl_domain_destroy to an async op" into two separate patches.
PATCH v4 1/10 libxl: change libxl__ao_device_remove to libxl__ao_device
Introduce a new structure to track state of device backends, that will be used in following patches on this series.
This structure if used for both device creation and device destruction and removes libxl__ao_device_remove.
Changes since v2:
* Remove unnecessary comments in libxl__ao_device.
* Change libxl__device_cb to device_addrm_aocomplete.
* Rename aorm parameter in device_addrm_aocomplete to aodev.
* Use a macro to define {nic,disk,vkb,vfb}_{remove,destroy} functions.
* Rename libxl__init_ao_device to libxl__prepare_ao_device and add a comment explaining why we need to set active to 1.
* Replace al uses of aorm with aodev.
--- tools/libxl/libxl.c | 211 ++++++++++++++---------------------------- tools/libxl/libxl.h | 15 ++- tools/libxl/libxl_device.c | 113 +++++++++++++++-------- tools/libxl/libxl_internal.h | 49 +++++++++-- 4 files changed, 197 insertions(+), 191 deletions(-)
tools/libxl/libxl.c +69 -142
@@ -1317,6 +1317,26 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)/******************************************************************************/ +/* generic callback for devices that only need to set ao_complete */ +static void device_addrm_aocomplete (libxl__egc *egc,libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); + +if (aodev->rc) { +LOGE (ERROR ,"unable to %s %s with id %u" , + aodev->action ==DEVICE_CONNECT ?"add" :"remove" , +libxl__device_kind_to_string (aodev->dev->kind), + aodev->dev->devid); + goto out; + } + +out: +libxl__ao_complete (egc, ao, aodev->rc); +return ; +} + +/******************************************************************************/ +int libxl__device_disk_setdefault (libxl__gc *gc,libxl_device_disk *disk) {int rc;
@@ -1486,42 +1506,6 @@ out:return rc; } -int libxl_device_disk_remove (libxl_ctx *ctx,uint32_t domid, -libxl_device_disk *disk, -const libxl_asyncop_how *ao_how) -{ -AO_CREATE (ctx, domid, ao_how); -libxl__device device; -int rc; - - rc =libxl__device_from_disk (gc, domid, disk, &device); -if (rc !=0 ) goto out; - - rc =libxl__initiate_device_remove (egc, ao, &device); -if (rc) goto out; - -return AO_INPROGRESS ; - -out: -return AO_ABORT (rc); -} - -int libxl_device_disk_destroy (libxl_ctx *ctx,uint32_t domid, -libxl_device_disk *disk) -{ -GC_INIT (ctx); -libxl__device device; -int rc; - - rc =libxl__device_from_disk (gc, domid, disk, &device); -if (rc !=0 ) goto out; - - rc =libxl__device_destroy (gc, &device); -out: -GC_FREE ; -return rc; -} -static void libxl__device_disk_from_xs_be (libxl__gc *gc,const char *be_path,libxl_device_disk *disk)
@@ -1964,42 +1948,6 @@ out:return rc; } -int libxl_device_nic_remove (libxl_ctx *ctx,uint32_t domid, -libxl_device_nic *nic, -const libxl_asyncop_how *ao_how) -{ -AO_CREATE (ctx, domid, ao_how); -libxl__device device; -int rc; - - rc =libxl__device_from_nic (gc, domid, nic, &device); -if (rc !=0 ) goto out; - - rc =libxl__initiate_device_remove (egc, ao, &device); -if (rc) goto out; - -return AO_INPROGRESS ; - -out: -return AO_ABORT (rc); -} - -int libxl_device_nic_destroy (libxl_ctx *ctx,uint32_t domid, -libxl_device_nic *nic) -{ -GC_INIT (ctx); -libxl__device device; -int rc; - - rc =libxl__device_from_nic (gc, domid, nic, &device); -if (rc !=0 ) goto out; - - rc =libxl__device_destroy (gc, &device); -out: -GC_FREE ; -return rc; -} -static void libxl__device_nic_from_xs_be (libxl__gc *gc,const char *be_path,libxl_device_nic *nic)
@@ -2326,42 +2274,6 @@ out:return rc; } -int libxl_device_vkb_remove (libxl_ctx *ctx,uint32_t domid, -libxl_device_vkb *vkb, -const libxl_asyncop_how *ao_how) -{ -AO_CREATE (ctx, domid, ao_how); -libxl__device device; -int rc; - - rc =libxl__device_from_vkb (gc, domid, vkb, &device); -if (rc !=0 ) goto out; - - rc =libxl__initiate_device_remove (egc, ao, &device); -if (rc) goto out; - -return AO_INPROGRESS ; - -out: -return AO_ABORT (rc); -} - -int libxl_device_vkb_destroy (libxl_ctx *ctx,uint32_t domid, -libxl_device_vkb *vkb) -{ -GC_INIT (ctx); -libxl__device device; -int rc; - - rc =libxl__device_from_vkb (gc, domid, vkb, &device); -if (rc !=0 ) goto out; - - rc =libxl__device_destroy (gc, &device); -out: -GC_FREE ; -return rc; -} -/******************************************************************************/ int libxl__device_vfb_setdefault (libxl__gc *gc,libxl_device_vfb *vfb)
@@ -2459,41 +2371,56 @@ out:return rc; } -int libxl_device_vfb_remove (libxl_ctx *ctx,uint32_t domid, -libxl_device_vfb *vfb, -const libxl_asyncop_how *ao_how) -{ -AO_CREATE (ctx, domid, ao_how); -libxl__device device; -int rc; - - rc =libxl__device_from_vfb (gc, domid, vfb, &device); -if (rc !=0 ) goto out; - - rc =libxl__initiate_device_remove (egc, ao, &device); -if (rc) goto out; - -return AO_INPROGRESS ; - -out: -return AO_ABORT (rc); -} - -int libxl_device_vfb_destroy (libxl_ctx *ctx,uint32_t domid, -libxl_device_vfb *vfb) -{ -GC_INIT (ctx); -libxl__device device; -int rc; - - rc =libxl__device_from_vfb (gc, domid, vfb, &device); -if (rc !=0 ) goto out; +/******************************************************************************/ - rc =libxl__device_destroy (gc, &device); -out: -GC_FREE ; -return rc; -} +/* Macro for defining device remove/destroy functions in a compact way */ +#define DEFINE_DEVICE_REMOVE (type, 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(aodev, ao, NULL); \ + aodev->action = DEVICE_DISCONNECT; \ + aodev->dev = device; \ + aodev->callback = device_addrm_aocomplete; \ + aodev->force = f; \ + libxl__initiate_device_remove(egc, aodev); \ + \ + out: \ + if (rc) return AO_ABORT(rc); \ + return AO_INPROGRESS; \ + } + +/* 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) + +#undef DEFINE_DEVICE_REMOVE/******************************************************************************/
tools/libxl/libxl.h +11 -4
@@ -674,7 +674,8 @@ int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,libxl_device_disk *disk, const libxl_asyncop_how *ao_how);int libxl_device_disk_destroy (libxl_ctx *ctx,uint32_t domid, -libxl_device_disk *disk); +libxl_device_disk *disk, +const libxl_asyncop_how *ao_how);libxl_device_disk *libxl_device_disk_list (libxl_ctx *ctx,uint32_t domid,int *num); int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
@@ -698,7 +699,9 @@ int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);int libxl_device_nic_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic,const libxl_asyncop_how *ao_how); -int libxl_device_nic_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic); +int libxl_device_nic_destroy (libxl_ctx *ctx,uint32_t domid, +libxl_device_nic *nic, +const libxl_asyncop_how *ao_how);libxl_device_nic *libxl_device_nic_list (libxl_ctx *ctx,uint32_t domid,int *num); int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
@@ -709,14 +712,18 @@ int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);int libxl_device_vkb_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_vkb *vkb,const libxl_asyncop_how *ao_how); -int libxl_device_vkb_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_vkb *vkb); +int libxl_device_vkb_destroy (libxl_ctx *ctx,uint32_t domid, +libxl_device_vkb *vkb, +const libxl_asyncop_how *ao_how);/* Framebuffer */ int libxl_device_vfb_add (libxl_ctx *ctx,uint32_t domid,libxl_device_vfb *vfb);int libxl_device_vfb_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_vfb *vfb,const libxl_asyncop_how *ao_how); -int libxl_device_vfb_destroy (libxl_ctx *ctx,uint32_t domid,libxl_device_vfb *vfb); +int libxl_device_vfb_destroy (libxl_ctx *ctx,uint32_t domid, +libxl_device_vfb *vfb, +const libxl_asyncop_how *ao_how);/* PCI Passthrough */ int libxl_device_pci_add (libxl_ctx *ctx,uint32_t domid,libxl_device_pci *pcidev);
tools/libxl/libxl_device.c +75 -38
162 lines not on this page · raw message
tools/libxl/libxl_internal.h +42 -7
61 lines not on this page · raw message
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 01/10] libxl: change libxl__ao_device_remove to libxl__ao_device
Roger Pau Monne writes ("[PATCH v4 01/10] libxl: change libxl__ao_device_remove to libxl__ao_device"):
Quoted 5 lines
Introduce a new structure to track state of device backends, that will be used in following patches on this series.
This structure if used for both device creation and device destruction and removes
libxl__ao_device_remove.
...
Quoted 4 lines
tools/libxl/libxl.c +0
-0
...
tools/libxl/libxl.c out: · line 2377
Quoted 2 lines
tools/libxl/libxl.c +2
-0+/* Macro for defining device remove/destroy functions in a compact way */ +#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \
Looks reasonable to me.
tools/libxl/libxl.c out: · line 2408
Quoted 5 lines
tools/libxl/libxl.c +5
-0+/* Define all remove/destroy functions and undef the macro */ + +/* disk */ +DEFINE_DEVICE_REMOVE(disk, remove, 0) +DEFINE_DEVICE_REMOVE (disk, destroy,1 )
I'm not sure what purpose the comment serves but I don't really object to it :-).
Quoted 4 lines
tools/libxl/libxl_internal.h +0
-0
...
tools/libxl/libxl_internal.h _hidden const char *libxl__device_nic_devname(libxl__gc * · line 1827
Quoted 8 lines
tools/libxl/libxl_internal.h +7
-0@@ -830,13 +830,6 @@ _hidden const char *libxl__device_nic_devname(libxl__gc * +/* This functions sets the necessary libxl__ao_device struct values to use +* safely inside functions. It marks the operation as "active" +* since we need to be sure that all device status structs are set +* to active before start queueing events, or we might call +* ao_complete before all devices had finished */ +_hidden void libxl__prepare_ao_device(libxl__ao_device *aodev, libxl__ao *ao, +libxl__ao_device **base);
You need to clearly explain what the constraints are on the order of calling _prepare and _initiate_..._remove.
Questions whose answers should be clear from your text include:
- is it legal to call _initiate_ without having previously called _prepare ?
- is it legal to call _prepare and then simply throw away the aodev ?
- is it legal to call _prepare multiple times ? (If the answer to the previous question is `yes' then it must be, I think.)
Quoted 6 lines
tools/libxl/libxl_internal.h +2
-2@@ -436,34 +441,35 @@ out: -int libxl__initiate_device_remove (libxl__egc *egc,libxl__ao *ao, -libxl__device *dev) +void libxl__initiate_device_remove (libxl__egc *egc, +libxl__ao_device *aodev) {
...
tools/libxl/libxl_internal.h
Quoted 6 lines
tools/libxl/libxl_internal.h +6
-0+retry_transaction: + t =xs_transaction_start (ctx->xsh); +if (aodev->force) +libxl__xs_path_cleanup (gc, t, +libxl__device_frontend_path (gc, aodev->dev)); + state =libxl__xs_read (gc, t, state_path);
Didn't I previously comment adversely on having this check here ?
Ah yes, I commented on the corresponding code in add (v2 08/15):
[...], I think all of this is done for you by libxl__ev_devstate_wait. You don't need to pre-check the state path at all.
And:
Do you really need to do the xenstore state read here ? Surely libxl__ev_devstate_wait will do it for you.
tools/libxl/libxl_internal.h
Quoted 9 lines
tools/libxl/libxl_internal.h +9
-0+/* Some devices (vkbd) fail to disconnect properly, +* but we shouldn't alarm the user if it's during +* domain destruction. +*/ +if (rc && aodev->action ==DEVICE_CONNECT ) { +LOG (ERROR ,"unable to connect device with path %s" , +libxl__device_backend_path (gc, aodev->dev)); + goto out; + }else if (rc) {
Missing space after `if'.
tools/libxl/libxl_internal.h
Quoted 4 lines
tools/libxl/libxl_internal.h +4
-0+LOG (DEBUG ,"unable to disconnect device with path %s" , +libxl__device_backend_path (gc, aodev->dev)); + goto out; + }
Last time I wrote:
Perhaps we should have a separate flag which controls error reporting so that a user-requested graceful device disconnect gets full error logging ?
Did you miss the fact that email suggesting the macro for generating the device remove functions also had these other comments in ?
Thanks,
Ian.
Re: [PATCH v4 01/10] libxl: change libxl__ao_device_remove to libxl__ao_device
Quoted 43 lines · Ian Jackson
Roger Pau Monne writes ("[PATCH v4 01/10] libxl: change
libxl__ao_device_removetolibxl__ao_device"):Quoted 5 lines
Introduce a new structure to track state of device backends, that will be used in following patches on this series.
This structure if used for both device creation and device destruction and removes
libxl__ao_device_remove....
Quoted 4 lines
tools/libxl/libxl.c +0
-0...
tools/libxl/libxl.c out: · line 2377
Quoted 2 lines
tools/libxl/libxl.c +2
-0+/* Macro for defining device remove/destroy functions in a compact way */ +#define DEFINE_DEVICE_REMOVE (type, removedestroy, f) \Looks reasonable to me.
tools/libxl/libxl.c out: · line 2408
Quoted 5 lines
tools/libxl/libxl.c +5
-0+/* Define all remove/destroy functions and undef the macro */ + +/* disk */ +DEFINE_DEVICE_REMOVE(disk, remove, 0) +DEFINE_DEVICE_REMOVE (disk, destroy,1 )I'm not sure what purpose the comment serves but I don't really object to it :-).
Quoted 4 lines
tools/libxl/libxl_internal.h +0
-0...
tools/libxl/libxl_internal.h _hidden const char *libxl__device_nic_devname(libxl__gc * · line 1827
Quoted 8 lines
tools/libxl/libxl_internal.h +7
-0@@ -830,13 +830,6 @@ _hidden const char *libxl__device_nic_devname(libxl__gc * +/* This functions sets the necessary libxl__ao_device struct values to use +* safely inside functions. It marks the operation as "active" +* since we need to be sure that all device status structs are set +* to active before start queueing events, or we might call +* ao_complete before all devices had finished */ +_hidden void libxl__prepare_ao_device(libxl__ao_device *aodev, libxl__ao *ao, +libxl__ao_device **base);You need to clearly explain what the constraints are on the order of calling
_prepareand _initiate_..._remove.
Quoted 7 lines
Questions whose answers should be clear from your text include:
- is it legal to call _initiate_ without having previously called_prepare?
- is it legal to call_prepareand then simply throw away the aodev ?
- is it legal to call_preparemultiple times ? (If the answer to the previous question is `yes' then it must be, I think.)
I've added a more detailed comment about _prepare.
Quoted 18 lines
Quoted 6 lines
tools/libxl/libxl_internal.h +2
-2@@ -436,34 +441,35 @@ out: -int libxl__initiate_device_remove (libxl__egc *egc,libxl__ao *ao, -libxl__device *dev) +void libxl__initiate_device_remove (libxl__egc *egc, +libxl__ao_device *aodev) {...
tools/libxl/libxl_internal.h
Quoted 6 lines
tools/libxl/libxl_internal.h +6
-0+retry_transaction: + t =xs_transaction_start (ctx->xsh); +if (aodev->force) +libxl__xs_path_cleanup (gc, t, +libxl__device_frontend_path (gc, aodev->dev)); + state =libxl__xs_read (gc, t, state_path);Didn't I previously comment adversely on having this check here ?
Ah yes, I commented on the corresponding code in add (v2 08/15):
Quoted 8 lines
[...], I think all of this is done for you by
libxl__ev_devstate_wait. You don't need to pre-check the state path at all.And:
Do you really need to do the xenstore state read here ? Surely
libxl__ev_devstate_waitwill do it for you.
Done.
Quoted 11 lines
tools/libxl/libxl_internal.h
Quoted 9 lines
tools/libxl/libxl_internal.h +9
-0+/* Some devices (vkbd) fail to disconnect properly, +* but we shouldn't alarm the user if it's during +* domain destruction. +*/ +if (rc&& aodev->action ==DEVICE_CONNECT ) { +LOG (ERROR ,"unable to connect device with path %s" , +libxl__device_backend_path (gc, aodev->dev)); + goto out; + }else if (rc) {Missing space after `if'.
Done.
Quoted 5 lines
tools/libxl/libxl_internal.h
Quoted 4 lines
tools/libxl/libxl_internal.h +4
-0+LOG (DEBUG ,"unable to disconnect device with path %s" , +libxl__device_backend_path (gc, aodev->dev)); + goto out; + }
Quoted 8 lines
Last time I wrote:
Perhaps we should have a separate flag which controls error reporting so that a user-requested graceful device disconnect gets full error logging ?
Did you miss the fact that email suggesting the macro for generating the device remove functions also had these other comments in ?
I've replied to this email, the response is here:
http://marc.info/?l=xen-devel&m=133770109429587&w=2
I would like to leave this for future work, since the error checking we have now is not better that what I'm proposing here.
Re: [PATCH v4 01/10] libxl: change libxl__ao_device_remove to libxl__ao_device
Roger Pau Monne writes ("Re: [PATCH v4 01/10] libxl: change libxl__ao_device_remove to libxl__ao_device"):
Quoted 2 lines
Quoted 1 line · Ian Jackson
Questions whose answers should be clear from your text include:
...
Quoted 1 line
I've added a more detailed comment about
_prepare.
Thanks.
Quoted 6 lines
Quoted 2 lines
Did you miss the fact that email suggesting the macro for generating the device remove functions also had these other comments in ?
I've replied to this email, the response is here:
Sorry, I seem to have dropped that mail. My fault.
Quoted 2 lines
I would like to leave this for future work, since the error checking we have now is not better that what I'm proposing here.
OK.
Ian.
PATCH v4 2/10 libxl: move device model creation prototypes
In reply to Roger Pau MonneMove prototypes regarding device model creation, since they will depend on domain destruction in future patches.
This patch is pure code motion.
--- tools/libxl/libxl_internal.h | 75 ++++++++++++++++++++--------------------- 1 files changed, 37 insertions(+), 38 deletions(-)
tools/libxl/libxl_internal.h +37 -38
@@ -1070,44 +1070,6 @@ static inline int libxl__spawn_inuse(libxl__spawn_state *ss) _hidden int libxl__spawn_record_pid(libxl__gc*, libxl__spawn_state*,pid_t innerchild); -/*----- device model creation -----*/ - -/* First layer; wraps libxl__spawn_spawn. */ - -typedef struct libxl__dm_spawn_state libxl__dm_spawn_state ; - -typedef void libxl__dm_spawn_cb (libxl__egc *egc,libxl__dm_spawn_state *, -int rc/* if !0, error was logged */ ); - -struct libxl__dm_spawn_state { -/* mixed - spawn.ao must be initialised by user; rest is private: */ -libxl__spawn_state spawn; -/* filled in by user, must remain valid: */ -uint32_t guest_domid;/* domain being served */ -libxl_domain_config *guest_config; -libxl__domain_build_state *build_state;/* relates to guest_domid */ -libxl__dm_spawn_cb *callback; -}; - -_hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*); - -/* Stubdom device models. */ - -typedef struct { -/* Mixed - user must fill in public parts EXCEPT callback, -* which may be undefined on entry. (See above for details) */ -libxl__dm_spawn_state dm;/* the stub domain device model */ -/* filled in by user, must remain valid: */ -libxl__dm_spawn_cb *callback;/* called as callback(,&sdss->dm,) */ -/* private to libxl__spawn_stub_dm: */ -libxl_domain_config dm_config; -libxl__domain_build_state dm_state; -libxl__dm_spawn_state pvqemu; -}libxl__stub_dm_spawn_state ; - -_hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*); - -/* * libxl__wait_for_offspring - Wait for child state * gc: allocation pool
@@ -1849,6 +1811,43 @@ struct libxl__ao_device { _hidden void libxl__initiate_device_remove(libxl__egc *egc,libxl__ao_device *aodev); +/*----- device model creation -----*/ + +/* First layer; wraps libxl__spawn_spawn. */ + +typedef struct libxl__dm_spawn_state libxl__dm_spawn_state ; + +typedef void libxl__dm_spawn_cb (libxl__egc *egc,libxl__dm_spawn_state *, +int rc/* if !0, error was logged */ ); + +struct libxl__dm_spawn_state { +/* mixed - spawn.ao must be initialised by user; rest is private: */ +libxl__spawn_state spawn; +/* filled in by user, must remain valid: */ +uint32_t guest_domid;/* domain being served */ +libxl_domain_config *guest_config; +libxl__domain_build_state *build_state;/* relates to guest_domid */ +libxl__dm_spawn_cb *callback; +}; + +_hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*); + +/* Stubdom device models. */ + +typedef struct { +/* Mixed - user must fill in public parts EXCEPT callback, +* which may be undefined on entry. (See above for details) */ +libxl__dm_spawn_state dm;/* the stub domain device model */ +/* filled in by user, must remain valid: */ +libxl__dm_spawn_cb *callback;/* called as callback(,&sdss->dm,) */ +/* private to libxl__spawn_stub_dm: */ +libxl_domain_config dm_config; +libxl__domain_build_state dm_state; +libxl__dm_spawn_state pvqemu; +}libxl__stub_dm_spawn_state ; + +_hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*); +/*----- Domain creation -----*/ typedef struct libxl__domain_create_state libxl__domain_create_state ;
Signature · 1 line
1.7.7.5 (Apple Git-26)
PATCH v4 3/10 libxl: convert libxl_domain_destroy to an async op
In reply to Roger Pau MonneThis change introduces some new structures, and breaks the mutual dependency that libxl_domain_destroy and libxl__destroy_device_model had. This is done by checking if the domid passed to libxl_domain_destroy has a stubdom, and then having the bulk of the destroy machinery in a separate function (libxl__destroy_domid) that doesn't check for stubdom presence, since we check for it in the upper level function. The reason behind this change is the need to use structures for ao operations, and it was impossible to have two different self-referencing structs.
All uses of libxl_domain_destroy have been changed, and either replaced by the new libxl_domain_destroy ao function or by the internal libxl__domain_destroy that can be used inside an already running ao.
Changes since v3:
* Fixed python bindings.
Changes since v2:
* Remove printfs.
* Replace aorm with aodev.
* Define an auxiliary libxl__ao_device *aodev to avoid using the long
expression: drs->aorm[numdev]...
* Added a common callback for both domain and stubdomain destruction that checks if both domains are finished and handles errors correctly.
* Change libxl__ao_device_check_last logic a bit and add a comment describing how does it work.
* Fixed spelling mistakes.
* Use a do-while for xs transaction in device_remove_callback.
--- tools/libxl/libxl.c | 167 +++++++++++++++++++++++++++++++++++-- tools/libxl/libxl.h | 3 +- tools/libxl/libxl_create.c | 29 ++++++- tools/libxl/libxl_device.c | 149 +++++++++++++++++++++++++++++---- tools/libxl/libxl_dm.c | 85 ++++++++++--------- tools/libxl/libxl_internal.h | 95 +++++++++++++++++++++- tools/libxl/xl_cmdimpl.c | 12 ++-- tools/python/xen/lowlevel/xl/xl.c | 2 +- 8 files changed, 465 insertions(+), 77 deletions(-)
tools/libxl/libxl.c +160 -7
@@ -1112,11 +1112,133 @@ void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) {GC_FREE ; } -int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid) +/* Callbacks for libxl_domain_destroy */ + +static void domain_destroy_cb (libxl__egc *egc,libxl__domain_destroy_state *dds, +int rc); + +int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid, +const libxl_asyncop_how *ao_how) { -GC_INIT (ctx); +AO_CREATE (ctx, domid, ao_how); +libxl__domain_destroy_state *dds; + +GCNEW (dds); + dds->ao = ao; + dds->domid = domid; + dds->callback = domain_destroy_cb; +libxl__domain_destroy (egc, dds); + +return AO_INPROGRESS ; +} + +static void domain_destroy_cb (libxl__egc *egc,libxl__domain_destroy_state *dds, +int rc) +{ +STATE_AO_GC (dds->ao); + +if (rc) +LOG (ERROR ,"destruction of domain %u failed" , dds->domid); + +libxl__ao_complete (egc, ao, rc); +} + +/* Callbacks for libxl__domain_destroy */ + +static void stubdom_callback (libxl__egc *egc,libxl__destroy_domid_state *dis, +int rc); + +static void domain_callback (libxl__egc *egc,libxl__destroy_domid_state *dis, +int rc); + +static void destroy_finish_check (libxl__egc *egc, +libxl__domain_destroy_state *dds); + +void libxl__domain_destroy (libxl__egc *egc,libxl__domain_destroy_state *dds) +{ +STATE_AO_GC (dds->ao); +uint32_t stubdomid =libxl_get_stubdom_id (CTX , dds->domid); + +if (stubdomid) { + dds->stubdom.ao = ao; + dds->stubdom.domid = stubdomid; + dds->stubdom.callback = stubdom_callback; + dds->stubdom.force =1 ; +libxl__destroy_domid (egc, &dds->stubdom); + }else { + dds->stubdom_finished =1 ; + } + + dds->domain.ao = ao; + dds->domain.domid = dds->domid; + dds->domain.callback = domain_callback; + dds->domain.force =1 ; +libxl__destroy_domid (egc, &dds->domain); +} + +static void stubdom_callback (libxl__egc *egc,libxl__destroy_domid_state *dis, +int rc) +{ +STATE_AO_GC (dis->ao); +libxl__domain_destroy_state *dds =CONTAINER_OF (dis, *dds, stubdom); +const char *savefile; + +if (rc) { +LOG (ERROR ,"unable to destroy stubdom with domid %u" , dis->domid); + dds->rc = rc; + } + + dds->stubdom_finished =1 ; + savefile =libxl__device_model_savefile (gc, dis->domid); + rc =unlink (savefile); +/* +* On suspend libxl__domain_save_device_model will have already +* unlinked the save file. +*/ +if (rc && errno ==ENOENT ) rc =0 ; +if (rc) { +LOGEV (ERROR , errno,"failed to remove device-model savefile %s" , + savefile); + } + +destroy_finish_check (egc, dds); +} + +static void domain_callback (libxl__egc *egc,libxl__destroy_domid_state *dis, +int rc) +{ +STATE_AO_GC (dis->ao); +libxl__domain_destroy_state *dds =CONTAINER_OF (dis, *dds, domain); + +if (rc) { +LOG (ERROR ,"unable to destroy guest with domid %u" , dis->domid); + dds->rc = rc; + } + + dds->domain_finished =1 ; +destroy_finish_check (egc, dds); +} + +static void destroy_finish_check (libxl__egc *egc, +libxl__domain_destroy_state *dds) +{ +if (!(dds->domain_finished && dds->stubdom_finished)) +return ; + + dds->callback (egc, dds, dds->rc); +} + +/* Callbacks for libxl__destroy_domid */ +static void devices_destroy_cb (libxl__egc *egc, +libxl__devices_remove_state *drs, +int rc); + +void libxl__destroy_domid (libxl__egc *egc,libxl__destroy_domid_state *dis) +{ +STATE_AO_GC (dis->ao); +libxl_ctx *ctx =CTX ; +uint32_t domid = dis->domid;char *dom_path; -char *vm_path;char *pid;int rc, dm_present;
@@ -1127,7 +1249,7 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)case ERROR_INVAL :LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"non-existant domain %d" , domid);default : -return rc; + goto out; }switch (libxl__domain_type (gc, domid)) {
@@ -1160,7 +1282,37 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)libxl__qmp_cleanup (gc, domid); } -if (libxl__devices_destroy (gc, domid) <0 ) + dis->drs.ao = ao; + dis->drs.domid = domid; + dis->drs.callback = devices_destroy_cb; + dis->drs.force = dis->force; +libxl__devices_destroy (egc, &dis->drs); +return ; + +out: +assert (rc); + dis->callback (egc, dis, rc); +return ; +} + +static void devices_destroy_cb (libxl__egc *egc, +libxl__devices_remove_state *drs, +int rc) +{ +STATE_AO_GC (drs->ao); +libxl__destroy_domid_state *dis =CONTAINER_OF (drs, *dis, drs); +libxl_ctx *ctx =CTX ; +uint32_t domid = dis->domid; +char *dom_path; +char *vm_path; + + dom_path =libxl__xs_get_dompath (gc, domid); +if (!dom_path) { + rc =ERROR_FAIL ; + goto out; + } + +if (rc <0 )LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"libxl__devices_destroy failed for %d" , domid);
@@ -1183,9 +1335,10 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid) goto out; } rc =0 ; + out: -GC_FREE ; -return rc; + dis->callback (egc, dis, rc); +return ; }int libxl_console_exec (libxl_ctx *ctx,uint32_t domid,int cons_num,libxl_console_type type)
tools/libxl/libxl.h +2 -1
@@ -537,7 +537,8 @@ int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid,int suspend_cancel);int libxl_domain_shutdown (libxl_ctx *ctx,uint32_t domid);int libxl_domain_reboot (libxl_ctx *ctx,uint32_t domid); -int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid); +int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid, +const libxl_asyncop_how *ao_how);int libxl_domain_preserve (libxl_ctx *ctx,uint32_t domid,libxl_domain_create_info *info,const char *name_suffix,libxl_uuid new_uuid);/* get max. number of cpus supported by hypervisor */
tools/libxl/libxl_create.c +25 -4
@@ -584,6 +584,12 @@ static void domcreate_complete(libxl__egc *egc,libxl__domain_create_state *dcs, int rc); +/* If creation is not successful, this callback will be executed +* when domain destruction is finished */ +static void domcreate_destruction_cb (libxl__egc *egc, +libxl__domain_destroy_state *dds, +int rc); +static void initiate_domain_create (libxl__egc *egc,libxl__domain_create_state *dcs) {
@@ -848,16 +854,31 @@ static void domcreate_complete(libxl__egc *egc,if (rc) {if (dcs->guest_domid) { -int rc2 =libxl_domain_destroy (CTX , dcs->guest_domid); -if (rc2) -LOG (ERROR ,"unable to destroy domain %d following" -" failed creation" , dcs->guest_domid); + dcs->dds.ao = ao; + dcs->dds.domid = dcs->guest_domid; + dcs->dds.callback = domcreate_destruction_cb; +libxl__domain_destroy (egc, &dcs->dds); +return ; } dcs->guest_domid =-1 ; } dcs->callback (egc, dcs, rc, dcs->guest_domid); } +static void domcreate_destruction_cb (libxl__egc *egc, +libxl__domain_destroy_state *dds, +int rc) +{ +STATE_AO_GC (dds->ao); +libxl__domain_create_state *dcs =CONTAINER_OF (dds, *dcs, dds); + +if (rc) +LOG (ERROR ,"unable to destroy domain %u following failed creation" , + dds->domid); + + dcs->callback (egc, dcs,ERROR_FAIL , dcs->guest_domid); +} +/*----- application-facing domain creation interface -----*/ typedef struct {
tools/libxl/libxl_device.c +134 -15
197 lines not on this page · raw message
tools/libxl/libxl_dm.c +43 -42
109 lines not on this page · raw message
tools/libxl/libxl_internal.h +94 -1
125 lines not on this page · raw message
tools/libxl/xl_cmdimpl.c +6 -6
@@ -1388,7 +1388,7 @@ static int handle_domain_death(libxl_ctx *ctx, uint32_t domid,/* fall-through */ case LIBXL_ACTION_ON_SHUTDOWN_DESTROY :LOG ("Domain %d needs to be cleaned up: destroying the domain" , domid); -libxl_domain_destroy (ctx, domid); +libxl_domain_destroy (ctx, domid,0 );break ;case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY :
@@ -1976,7 +1976,7 @@ start: error_out:release_lock ();if (libxl_domid_valid_guest (domid)) -libxl_domain_destroy (ctx, domid); +libxl_domain_destroy (ctx, domid,0 ); out:if (logfile !=2 )
@@ -2542,7 +2542,7 @@ static void destroy_domain(const char *p)fprintf (stderr,"Cannot destroy privileged domain 0.\n\n" );exit (-1 ); } - rc =libxl_domain_destroy (ctx, domid); + rc =libxl_domain_destroy (ctx, domid,0 );if (rc) {fprintf (stderr,"destroy failed (rc=%d)\n" ,rc);exit (-1 ); } }
@@ -2816,7 +2816,7 @@ static int save_domain(const char *p, const char *filename, int checkpoint,if (checkpoint)libxl_domain_resume (ctx, domid,1 );else -libxl_domain_destroy (ctx, domid); +libxl_domain_destroy (ctx, domid,0 );exit (0 ); }
@@ -3077,7 +3077,7 @@ static void migrate_domain(const char *domain_spec, const char *rune, }fprintf (stderr,"migration sender: Target reports successful startup.\n" ); -libxl_domain_destroy (ctx, domid);/* bang! */ +libxl_domain_destroy (ctx, domid,0 );/* bang! */ fprintf (stderr,"Migration successful.\n" );exit (0 );
@@ -3230,7 +3230,7 @@ static void migrate_receive(int debug, int daemonize, int monitor,if (rc) {fprintf (stderr,"migration target: Failure, destroying our copy.\n" ); - rc2 =libxl_domain_destroy (ctx, domid); + rc2 =libxl_domain_destroy (ctx, domid,0 );if (rc2) {fprintf (stderr,"migration target: Failed to destroy our copy" " (code %d).\n" , rc2);
tools/python/xen/lowlevel/xl/xl.c +1 -1
@@ -447,7 +447,7 @@ static PyObject *pyxl_domain_destroy(XlObject *self, PyObject *args)int domid;if ( !PyArg_ParseTuple (args,"i" , &domid) )return NULL ; -if (libxl_domain_destroy (self->ctx, domid) ) { +if (libxl_domain_destroy (self->ctx, domid,0 ) ) {PyErr_SetString (xl_error_obj,"cannot destroy domain" );return NULL ; }
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 03/10] libxl: convert libxl_domain_destroy to an async op
Roger Pau Monne writes ("[PATCH v4 03/10] libxl: convert libxl_domain_destroy to an async op"):
Quoted 9 lines
This change introduces some new structures, and breaks the mutual dependency that
libxl_domain_destroyandlibxl__destroy_device_modelhad. This is done by checking if the domid passed tolibxl_domain_destroyhas a stubdom, and then having the bulk of the destroy machinery in a separate function (libxl__destroy_domid) that doesn't check for stubdom presence, since we check for it in the upper level function. The reason behind this change is the need to use structures for ao operations, and it was impossible to have two different self-referencing structs.
Thanks. I have a series of largely cosmetic comments which it would be nice if you felt like addressing, but:
Quoted 4 lines
tools/libxl/libxl_internal.h +0
-0
...
Quoted 7 lines
+/* Check if there are devices that have pending events in the array
+ * pointed to by the "list" parameter. Return values can be:
+ * < 0: All done, but error(s) found.
+ * 0: All done
+ * > 0: Not all done
+ * The passedlibxl__ao_devicestruct in "device" is marked as finished.
+ */
Good.
Quoted 4 lines
+/*
+ * Entry point for domain destruction
+ * This function checks for stubdom presence and then calls
+ *libxl__destroy_domidon the passed domain and it's stubdom if found.
"its" not "it's"
Quoted 5 lines
tools/libxl/libxl.c +0
-0
tools/libxl/libxl.c void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) { · line 1166
Quoted 10 lines
tools/libxl/libxl.c +10
-0+void libxl__domain_destroy (libxl__egc *egc,libxl__domain_destroy_state *dds) +{ +STATE_AO_GC (dds->ao); +uint32_t stubdomid =libxl_get_stubdom_id (CTX , dds->domid); + +if (stubdomid) { + dds->stubdom.ao = ao; + dds->stubdom.domid = stubdomid; + dds->stubdom.callback = stubdom_callback; + dds->stubdom.force =1 ;
This variable seems never to be set to anything but 1. We aren't going to have libxl_domain_remove or indeed libxl__remove_domid, are we ?
Perhaps the domain destroy functions should lose the force flag and instead simply always pass 1 into the device remove functions.
tools/libxl/libxl.c void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) { · line 1181
Quoted 3 lines
tools/libxl/libxl.c +3
-0+static void stubdom_callback (libxl__egc *egc,libxl__destroy_domid_state *dis, +int rc) +{
Can this function please have destroy' in its name somewhere ? libxl.c contains code for doing other things than destruction. The same goes for domain_callback'.
tools/libxl/libxl.c void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) { · line 1193
Quoted 12 lines
tools/libxl/libxl.c +12
-0+STATE_AO_GC (dis->ao); +libxl__domain_destroy_state *dds =CONTAINER_OF (dis, *dds, stubdom); +const char *savefile; + +if (rc) { +LOG (ERROR ,"unable to destroy stubdom with domid %u" , dis->domid); + dds->rc = rc; + } + + dds->stubdom_finished =1 ; + savefile =libxl__device_model_savefile (gc, dis->domid); + rc =unlink (savefile);
Please use `rc' only for libxl error codes. This is a system call return value.
tools/libxl/libxl.c void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) { · line 1202
Quoted 9 lines
tools/libxl/libxl.c +9
-0+/* +* On suspend libxl__domain_save_device_model will have already +* unlinked the save file. +*/ +if (rc && errno ==ENOENT ) rc =0 ; +if (rc) { +LOGEV (ERROR , errno,"failed to remove device-model savefile %s" , + savefile); + }
This is one possible reason why the savefile might not exist. To be honest I'm not really convinced this warrants an explanation. Domain destruction inherently wants to be idempotent.
And, why not use libxl__remove_file which already contains the relevant logic including a log message. ?
Quoted 5 lines
tools/libxl/libxl_device.c +0
-0@@ -58,6 +58,48 @@ int libxl__parse_backend_path(libxl__gc *gc,
...
tools/libxl/libxl_device.c int libxl__parse_backend_path(libxl__gc *gc, · line 69
Quoted 6 lines
tools/libxl/libxl_device.c +6
-0+unsigned int num_kinds, num_devs; +char **kinds =NULL , **devs =NULL ; +int i, j, rc =0 ; +libxl__device dev; +libxl__device_kind kind; +int numdevs =0 ;
Having two variables num_devs' and numdevs' seems unnecessarily opaque :-). Perhaps the one from libxl__xs_directory should be called `num_dev_xsentries' or something.
Quoted 1 line
tools/libxl/libxl_device.c +0
-0@@ -367,6 +409,23 @@ void libxl__prepare_ao_device(libxl__ao_device *aodev, libxl__ao *ao,
...
tools/libxl/libxl_device.c void libxl__prepare_ao_device(libxl__ao_device *aodev, libxl__ao *ao, · line 420
Quoted 9 lines
tools/libxl/libxl_device.c +9
-0+int libxl__ao_device_check_last (libxl__gc *gc,libxl__ao_device *device, +libxl__ao_device *list,int num) +{ +int i, pending =0 , error =0 ; + + device->active =0 ; +for (i =0 ; i < num; i++) { +if (list[i].active) + pending++;
Why not return +1' ? That would do away with the variable pending'.
tools/libxl/libxl_device.c void libxl__prepare_ao_device(libxl__ao_device *aodev, libxl__ao *ao, · line 426
Quoted 6 lines
tools/libxl/libxl_device.c +6
-0+ +if (list[i].rc) + error = list[i].rc; + } + +return pending ==0 ? error :1 ;
And it would simplify this to `return error;'.
Quoted 6 lines
tools/libxl/libxl_device.c +5
-1-int libxl__devices_destroy (libxl__gc *gc,uint32_t domid) +/* Callback for device destruction */ + +static void device_remove_callback (libxl__egc *egc,libxl__ao_device *aodev); + +void libxl__devices_destroy (libxl__egc *egc,libxl__devices_remove_state *drs)
...
tools/libxl/libxl_device.c int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) · line 464
Quoted 4 lines
tools/libxl/libxl_device.c +4
-0+if (drs->num_devices <0 ) { +LOG (ERROR ,"unable to get number of devices for domain %u" , drs->domid); + rc =ERROR_FAIL ; + goto out;
A minor point but this should be `rc = drs->num_devices' surely ? A minor point since it can currently only fail with ERROR_FAIL but at some point we might want to invent more error codes and then they should propagate nicely.
Quoted 7 lines
tools/libxl/libxl_device.c +1
-1@@ -426,17 +510,19 @@ int libxl__devices_destroy(libxl__gc *gc, uint32_t domid)/* console 0 frontend directory is not under /local/domain/<domid>/device */ path =libxl__sprintf (gc,"/local/domain/%d/console/backend" , domid); path =libxl__xs_read (gc,XBT_NULL , path); +GCNEW (dev); if (path && strcmp(path, "") && -libxl__parse_backend_path (gc, path, &dev) ==0 ) {
tools/libxl/libxl_device.c int libxl__devices_destroy(libxl__gc *gc, uint32_t domid) · line 520
Quoted 10 lines
tools/libxl/libxl_device.c +5
-4- dev.domid = domid; - dev.kind =LIBXL__DEVICE_KIND_CONSOLE ; - dev.devid =0 ; + libxl__parse_backend_path(gc, path, dev) == 0) { + dev->domid = domid; + dev->kind =LIBXL__DEVICE_KIND_CONSOLE ; + dev->devid =0 ; -libxl__device_destroy (gc, &dev); +libxl__device_destroy (gc, dev);
This is quite confusing, because libxl__device_destroy sounds like it should be a synchronous version of libxl__initiate_device_destroy or to put it another way an internal version of something called libxl_device_destroy (which doesn't exist); of course such a function couldn't exist either.
Perhaps libxl__device_destroy should be renamed somehow (perhaps in another pre-patch).
Or perhaps there should be a comment to note that (currently) consoles can be simply synchronously destroyed in xenstore.
Quoted 1 line
tools/libxl/libxl_device.c +0
-0@@ -549,6 +635,39 @@ static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev)
...
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 653
Quoted 6 lines
tools/libxl/libxl_device.c +6
-0+do { + t =xs_transaction_start (CTX ->xsh); +libxl__xs_path_cleanup (gc, t, fe_path); +libxl__xs_path_cleanup (gc, t, be_path); + rc = !xs_transaction_end (CTX ->xsh, t,0 ); + }while (rc && errno ==EAGAIN );
Again, can we reserve `rc' for libxl error codes ?
Quoted 1 line
tools/libxl/libxl_device.c +0
-0@@ -1090,48 +1114,25 @@ int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid)
...
tools/libxl/libxl_device.c
Quoted 9 lines
tools/libxl/libxl_device.c +9
-0+if (!pid || !atoi (pid)) { +LOG (ERROR ,"could not find device-model's pid for dom %u" , domid); + ret =ERROR_FAIL ; + goto out; + } + ret =kill (atoi (pid),SIGHUP ); +if (ret <0 && errno ==ESRCH ) { +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Device Model already exited" ); + ret =0 ;
Of course if this happens we have risked sending SIGHUP to an innocent process. It would be nice to arrange for that not to happen but I don't think we currently have a way to prevent it.
Quoted 1 line
+ LIBXL__LOG_ERRNO(ctx,
LIBXL__LOG_ERROR, "failed to kill Device Model [%d]",
Would you care to use LOG(ERROR, ...) ? You might want to use LOG for the other cases too.
Thanks,
Ian.
PATCH v4 4/10 libxl: convert libxl_device_disk_add to an asyn op
In reply to Roger Pau MonneThis patch converts libxl_device_disk_add to an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.
As usual, libxl_device_disk_add callers have been modified, and the internal function libxl__device_disk_add has been used if the call was inside an already running ao.
Changes since v2:
* Remove state read from libxl__initiate_device_add
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl.c | 50 ++++++++++++++++++++++++++-------- tools/libxl/libxl.h | 4 ++- tools/libxl/libxl_create.c | 41 ++++++++++++++++++++++------ tools/libxl/libxl_device.c | 48 +++++++++++++++++++++++++++++++++ tools/libxl/libxl_dm.c | 61 +++++++++++++++++++++++++++++++---------- tools/libxl/libxl_internal.h | 26 ++++++++++++++++++ tools/libxl/xl_cmdimpl.c | 2 +- 8 files changed, 195 insertions(+), 39 deletions(-)
tools/libxl/Makefile +1 -1
@@ -13,7 +13,7 @@ XLUMINOR = 0 CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \ -Wno-declaration-after-statement -Wformat-nonliteral -CFLAGS += -I. -fPIC +CFLAGS += -I. -fPIC -O0 ifeq ($(CONFIG_Linux),y) LIBUUID_LIBS += -luuid
tools/libxl/libxl.c +38 -12
105 lines not on this page · raw message
tools/libxl/libxl.h +3 -1
@@ -670,7 +670,9 @@ void libxl_vminfo_list_free(libxl_vminfo *list, int nr);*/ /* Disks */ -int libxl_device_disk_add (libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk); +int libxl_device_disk_add (libxl_ctx *ctx,uint32_t domid, +libxl_device_disk *disk, +const libxl_asyncop_how *ao_how);int libxl_device_disk_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk,const libxl_asyncop_how *ao_how);
tools/libxl/libxl_create.c +32 -9
60 lines not on this page · raw message
tools/libxl/libxl_device.c +48 -0
60 lines not on this page · raw message
tools/libxl/libxl_dm.c +46 -15
107 lines not on this page · raw message
tools/libxl/libxl_internal.h +26 -0
@@ -70,6 +70,7 @@#include "_libxl_types_internal.h" #include "_libxl_types_internal_json.h" +#define LIBXL_INIT_TIMEOUT 10#define LIBXL_DESTROY_TIMEOUT 10#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10#define LIBXL_XENCONSOLE_LIMIT 1048576
@@ -1812,6 +1813,19 @@ struct libxl__ao_device {void *base; }; +/* Internal AO operation to connect a disk device */ +_hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid, +libxl_device_disk *disk, +libxl__ao_device *aodev); + +/* Arranges that dev will be added to the guest, and the +* hotplug scripts will be executed (if necessary). When +* this is done (or an error happens), the callback in +* aodev->callback will be called. +*/ +_hidden void libxl__initiate_device_add(libxl__egc*, libxl__ao_device *aodev); + +/* Arranges that dev will be removed to the guest, and the * hotplug scripts will be executed (if necessary). When * this is done (or an error happens), the callback in
@@ -1901,6 +1915,12 @@ _hidden void libxl__destroy_domid(libxl__egc *egc, _hidden void libxl__devices_destroy(libxl__egc *egc,libxl__devices_remove_state *drs); +/* Helper function to add a bunch of disks */ +void libxl__add_disks (libxl__egc *egc,libxl__ao *ao,uint32_t domid, +libxl_domain_config *d_config, +libxl__ao_device **devices, +libxl__device_callback callback); +/*----- device model creation -----*/ /* First layer; wraps libxl__spawn_spawn. */
@@ -1935,6 +1955,9 @@ typedef struct {libxl__domain_build_state dm_state;libxl__dm_spawn_state pvqemu;libxl__destroy_domid_state dis; +/* used to store the state of devices being connected */ +libxl__ao_device *devices; +int num_devices; } libxl__stub_dm_spawn_state; _hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*);
@@ -1963,6 +1986,9 @@ struct libxl__domain_create_state {* for the non-stubdom device model. */ /* necessary if the domain creation failed and we have to destroy it */ libxl__domain_destroy_state dds; +/* used to store the state of devices being connected */ +libxl__ao_device *devices; +int num_devices; };
tools/libxl/xl_cmdimpl.c +1 -1
@@ -5334,7 +5334,7 @@ int main_blockattach(int argc, char **argv)return 0 ; } -if (libxl_device_disk_add (ctx, fe_domid, &disk)) { +if (libxl_device_disk_add (ctx, fe_domid, &disk,0 )) {fprintf (stderr,"libxl_device_disk_add failed.\n" ); }return 0 ;
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 04/10] libxl: convert libxl_device_disk_add to an asyn op
Roger Pau Monne writes ("[PATCH v4 04/10] libxl: convert libxl_device_disk_add to an asyn op"):
Subject line needs to say async' not asyn'.
Quoted 9 lines
This patch converts
libxl_device_disk_addto an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.As usual,
libxl_device_disk_addcallers have been modified, and the internal functionlibxl__device_disk_addhas been used if the call was inside an already running ao.
This looks good to me. I have some very minor comments.
...
Quoted 12 lines
tools/libxl/libxl_internal.h +11
-0+/* Internal AO operation to connect a disk device */ +_hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid, +libxl_device_disk *disk, +libxl__ao_device *aodev); + +/* Arranges that dev will be added to the guest, and the +* hotplug scripts will be executed (if necessary). When +* this is done (or an error happens), the callback in +* aodev->callback will be called. +*/ +_hidden void libxl__initiate_device_add(libxl__egc*, libxl__ao_device *aodev);
Quoted 1 line
From the comments I'm a bit confused by the relationship between
these. I guess libxl__device_disk_add is called by libxl__initiate_device_add and not vice versa, and that only libxl__initiate_device_add is allowed to call libxl__device_disk_add. Is that true ? If so it would be nice to say so.
tools/libxl/libxl_internal.h _hidden void libxl__destroy_domid(libxl__egc *egc, · line 1923
Quoted 6 lines
tools/libxl/libxl_internal.h +6
-0+/* Helper function to add a bunch of disks */ +void libxl__add_disks (libxl__egc *egc,libxl__ao *ao,uint32_t domid, +libxl_domain_config *d_config, +libxl__ao_device **devices, +libxl__device_callback callback); +
This comment should make it clear that the callback will be called _once for each device_, and that that callback is therefore responsible for using libxl__ao_device_check_last.
Doesn't this define `callback' as a parameter of function type? Is that legal in C89/C99 ?
tools/libxl/Makefile XLUMINOR = 0 · line 16
Quoted 10 lines
tools/libxl/Makefile +1
-1@@ -13,7 +13,7 @@ XLUMINOR = 0 CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \ -Wno-declaration-after-statement -Wformat-nonliteral -CFLAGS += -I. -fPIC +CFLAGS += -I. -fPIC -O0
Stray hunk I think.
tools/libxl/Makefile int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) · line 1886
Quoted 6 lines
tools/libxl/Makefile +1
-1@@ -1859,11 +1883,13 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) ret = 0; libxl_device_disk_remove(ctx, domid, disks + i, 0); - libxl_device_disk_add(ctx, domid, disk); + /* fixme-ao */
We need to fix this in the API, at least by making libxl_cdrom_insert take an ao_how at some point. But not in this patch, indeed.
Quoted 7 lines
tools/libxl/Makefile +7
-0+void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, + libxl_domain_config *d_config, + libxl__ao_device **devices, + libxl__device_callback callback) +{ + AO_GC; + GCNEW_ARRAY(*devices, d_config->num_disks);
tools/libxl/Makefile int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
Quoted 10 lines
tools/libxl/Makefile +10
-0+ libxl__ao_device *aodev = *devices; + int i; + + for (i = 0; i < d_config->num_disks; i++) { + libxl__prepare_ao_device(&aodev[i], ao, devices); + aodev[i].callback = callback; + libxl__device_disk_add(egc, domid, &d_config->disks[i], + &aodev[i]); + } +}
If libxl__device_disk_add ever becomes capable of reentrantly calling the completion callback, this will go wrong because the others haven't been prepared yet. Perhaps this should be in two loops ?
Ian.
Re: [PATCH v4 04/10] libxl: convert libxl_device_disk_add to an asyn op
Quoted 11 lines · Ian Jackson
Review int libxl_cdrom_insert(libxl_ctx *ctx,
Quoted 2 lines
(quoted diff) +0
-0@@ -1859,11 +1883,13 @@ int libxl_cdrom_insert(libxl_ctx *ctx,
uint32_tdomid,libxl_device_disk*disk)tools/libxl/libxl.c int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) · line 1886
Quoted 5 lines
tools/libxl/libxl.c +1
-1ret =0 ;libxl_device_disk_remove (ctx, domid, disks + i,0 ); -libxl_device_disk_add (ctx, domid, disk); +/* fixme-ao */ We need to fix this in the API, at least by making
libxl_cdrom_inserttake anao_howat some point. But not in this patch, indeed.
In yesterday's TODO I said:
* libxl_cdrom_insert. Should be easy once disk_{add,remove} done. Nobody is looking at this? This is basically a helper function and its functionality can be implemented in terms of the libxl_disk_* interfaces. We could therefore consider marking this function as substandard and subject to change in the future. We could also consider simply moving it into xl as a helper function and revisting for 4.3.
I'm quite interested in thoughts on that ;-)
Ian.
PATCH v4 5/10 libxl: convert libxl_device_nic_add to an async operation
In reply to Roger Pau MonneThis patch converts libxl_device_nic_add to an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.
Calls to libxl_device_nic_add have also been moved to occur after the device model has been launched, so when hotplug scripts are called from this functions the interfaces already exists.
As usual, libxl_device_nic_add callers have been modified, and the internal function libxl__device_disk_add has been used if the call was inside an already running ao.
--- tools/libxl/libxl.c | 39 ++++++++++++++++++----- tools/libxl/libxl.h | 3 +- tools/libxl/libxl_create.c | 70 +++++++++++++++++++++++++++++++++++++----- tools/libxl/libxl_device.c | 18 +++++++++++ tools/libxl/libxl_dm.c | 54 ++++++++++++++++++++++++++++++-- tools/libxl/libxl_internal.h | 11 ++++++ tools/libxl/xl_cmdimpl.c | 2 +- 7 files changed, 176 insertions(+), 21 deletions(-)
tools/libxl/libxl.c +31 -8
@@ -2026,12 +2026,27 @@ static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,return 0 ; } -int libxl_device_nic_add (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic) +int libxl_device_nic_add (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic, +const libxl_asyncop_how *ao_how) { -GC_INIT (ctx); +AO_CREATE (ctx, domid, ao_how); +libxl__ao_device *device; + +GCNEW (device); +libxl__prepare_ao_device (device, ao,NULL ); + device->callback = device_addrm_aocomplete; +libxl__device_nic_add (egc, domid, nic, device); + +return AO_INPROGRESS ; +} + +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;flexarray_t *back; -libxl__device device; +libxl__device *device;char *dompath, **l;unsigned int nb, rc;
@@ -2062,7 +2077,8 @@ int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic) } } - rc =libxl__device_from_nic (gc, domid, nic, &device); +GCNEW (device); + rc =libxl__device_from_nic (gc, domid, nic, device);if ( rc !=0 ) goto out_free;flexarray_append (back,"frontend-id" );
@@ -2103,6 +2119,9 @@ int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic)flexarray_append (back,libxl__strdup (gc, nic->bridge));flexarray_append (back,"handle" );flexarray_append (back,libxl__sprintf (gc,"%d" , nic->devid)); +flexarray_append (back,"type" ); +flexarray_append (back,libxl__strdup (gc, +libxl_nic_type_to_string (nic->nictype)));flexarray_append (front,"backend-id" );flexarray_append (front,libxl__sprintf (gc,"%d" , nic->backend_domid));
@@ -2113,18 +2132,22 @@ int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic)flexarray_append (front,"mac" );flexarray_append (front,libxl__sprintf (gc,LIBXL_MAC_FMT ,LIBXL_MAC_BYTES (nic->mac))); -libxl__device_generic_add (gc, &device, +libxl__device_generic_add (gc, device,libxl__xs_kvs_of_flexarray (gc, back, back->count),libxl__xs_kvs_of_flexarray (gc, front, front->count)); -/* FIXME: wait for plug */ + aodev->dev = device; + aodev->action =DEVICE_CONNECT ; +libxl__initiate_device_add (egc, aodev); + rc =0 ; out_free:flexarray_free (back);flexarray_free (front); out: -GC_FREE ; -return rc; + aodev->rc = rc; +if (rc) aodev->callback (egc, aodev); +return ; } static void libxl__device_nic_from_xs_be(libxl__gc *gc,
tools/libxl/libxl.h +2 -1
@@ -698,7 +698,8 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);int libxl_device_disk_local_detach (libxl_ctx *ctx,libxl_device_disk *disk);/* Network Interfaces */ -int libxl_device_nic_add (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic); +int libxl_device_nic_add (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic, +const libxl_asyncop_how *ao_how);int libxl_device_nic_remove (libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic,const libxl_asyncop_how *ao_how);
tools/libxl/libxl_create.c +62 -8
94 lines not on this page · raw message
tools/libxl/libxl_device.c +18 -0
@@ -444,6 +444,24 @@ void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, } } +void libxl__add_nics (libxl__egc *egc,libxl__ao *ao,uint32_t domid, +libxl_domain_config *d_config, +libxl__ao_device **devices, +libxl__device_callback callback) +{ +AO_GC ; +GCNEW_ARRAY (*devices, d_config->num_vifs); +libxl__ao_device *aodev = *devices; +int i; + +for (i =0 ; i < d_config->num_vifs; i++) { +libxl__prepare_ao_device (&aodev[i], ao, devices); + aodev[i].callback = callback; +libxl__device_nic_add (egc, domid, &d_config->vifs[i], + &aodev[i]); + } +} +int libxl__device_destroy (libxl__gc *gc,libxl__device *dev) {libxl_ctx *ctx =libxl__gc_owner (gc);
tools/libxl/libxl_dm.c +51 -3
75 lines not on this page · raw message
tools/libxl/libxl_internal.h +11 -0
@@ -1818,6 +1818,11 @@ _hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid, libxl_device_disk *disk, libxl__ao_device *aodev); +/* Internal 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); +/* Arranges that dev will be added to the guest, and the * hotplug scripts will be executed (if necessary). When * this is done (or an error happens), the callback in
@@ -1921,6 +1926,12 @@ void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid,libxl__ao_device **devices, libxl__device_callback callback); +/* Helper function to add a bunch of disks */ +void libxl__add_nics (libxl__egc *egc,libxl__ao *ao,uint32_t domid, +libxl_domain_config *d_config, +libxl__ao_device **devices, +libxl__device_callback callback); +/*----- device model creation -----*/ /* First layer; wraps libxl__spawn_spawn. */
tools/libxl/xl_cmdimpl.c +1 -1
@@ -5223,7 +5223,7 @@ int main_networkattach(int argc, char **argv)return 0 ; } -if (libxl_device_nic_add (ctx, domid, &nic)) { +if (libxl_device_nic_add (ctx, domid, &nic,0 )) {fprintf (stderr,"libxl_device_nic_add failed.\n" );return 1 ; }
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 05/10] libxl: convert libxl_device_nic_add to an async operation
Roger Pau Monne writes ("[PATCH v4 05/10] libxl: convert libxl_device_nic_add to an async operation"):
Quoted 5 lines
This patch converts
libxl_device_nic_addto an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.
Thanks. I'm afraid this is still tripping my repetition detector. See below.
Quoted 15 lines
tools/libxl/libxl_device.c +7
-0@@ -444,6 +444,24 @@ void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, } } +void libxl__add_nics (libxl__egc *egc,libxl__ao *ao,uint32_t domid, +libxl_domain_config *d_config, +libxl__ao_device **devices, +libxl__device_callback callback) +{ +AO_GC ; +GCNEW_ARRAY (*devices, d_config->num_vifs);
tools/libxl/libxl_device.c void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, · line 463
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+libxl__ao_device *aodev = *devices; +int i; + +for (i =0 ; i < d_config->num_vifs; i++) { +libxl__prepare_ao_device (&aodev[i], ao, devices); + aodev[i].callback = callback; +libxl__device_nic_add (egc, domid, &d_config->vifs[i], + &aodev[i]); + } +}
The same comment applies as before about libxl__add_disks and the two loops.
But, this is another copy of libxl__add_disks. Perhaps you want a macro to generate these functions ?
In general this patch seems to contain an awful lot of very similar code to the previous one. Eg domcreate_nic_connected is practically identical to domcreate_disk_connected. And domcreate_attach_nick is practically identical to domcreate_attach_disk.
Another option would be to make the types of libxl__device_FOO_add compatible (by replacing the actual config parameter with const void*) and then pass them as function pointers.
Or you could even have a table
{ offsetof(disks, libxl_domain_config), sizeof(libxl_device_disk),
libxl__device_disk_add },
{ offsetof(vifs, libxl_domain_config), sizeof(libxl_device_vif),
libxl__device_nic_add },
...
which your domain creation logic could iterate over. That way you would do away with domcreate_FOO_connected and you'd end up with
static void domcreate_device_connected(libxl__egc *egc,
libxl__ao_device *aodev)
{
tableentry = devicekindstable[dcs->currentdevicekind];
rc = libxl__ao_device_check_last(gc, aodev, dcs->devices,
dcs->num_devices);
if (rc > 0) return;
if (rc) {
LOGE(ERROR, "error connecting devices");
goto error_out;
}
dcs->currentdevicekind++;
if (!devicekindstable[dcs->currentdevicekind].add_function) {
domcreate_complete(egc, dcs, rc);
} else {
domcreate_attach_devices(egc, dcs);
}or something like it.
Or something. Anyway, can you try to find a way to avoid me having to review lots of nearly-identical code ?
Thanks,
Ian.
Re: [PATCH v4 05/10] libxl: convert libxl_device_nic_add to an async operation
Quoted 40 lines · Ian Jackson
Roger Pau Monne writes ("[PATCH v4 05/10] libxl: convert
libxl_device_nic_addto an async operation"):Quoted 5 lines
This patch converts
libxl_device_nic_addto an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.Thanks. I'm afraid this is still tripping my repetition detector. See below.
Quoted 15 lines
tools/libxl/libxl_device.c +7
-0@@ -444,6 +444,24 @@ void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, } } +void libxl__add_nics (libxl__egc *egc,libxl__ao *ao,uint32_t domid, +libxl_domain_config *d_config, +libxl__ao_device **devices, +libxl__device_callback callback) +{ +AO_GC ; +GCNEW_ARRAY (*devices, d_config->num_vifs);tools/libxl/libxl_device.c void libxl__add_disks(libxl__egc *egc, libxl__ao *ao, uint32_t domid, · line 463
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+libxl__ao_device *aodev = *devices; +int i; + +for (i =0 ; i< d_config->num_vifs; i++) { +libxl__prepare_ao_device (&aodev[i], ao, devices); + aodev[i].callback = callback; +libxl__device_nic_add (egc, domid,&d_config->vifs[i], +&aodev[i]); + } +}The same comment applies as before about
libxl__add_disksand the two loops.
Quoted 2 lines
But, this is another copy of
libxl__add_disks. Perhaps you want a macro to generate these functions ?
Yes, a macro would be ok I think.
Quoted 42 lines
In general this patch seems to contain an awful lot of very similar code to the previous one. Eg
domcreate_nic_connectedis practically identical todomcreate_disk_connected. Anddomcreate_attach_nickis practically identical todomcreate_attach_disk.Another option would be to make the types of
libxl__device_FOO_addcompatible (by replacing the actual config parameter with const void*) and then pass them as function pointers.Or you could even have a table
{offsetof(disks, libxl_domain_config),sizeof(libxl_device_disk),
libxl__device_disk_add},
{offsetof(vifs, libxl_domain_config),sizeof(libxl_device_vif),
libxl__device_nic_add},
...
which your domain creation logic could iterate over. That way you would do away withdomcreate_FOO_connectedand you'd end up withstatic void domcreate_device_connected(libxl__egc *egc, libxl__ao_device *aodev) { tableentry = devicekindstable[dcs->currentdevicekind]; rc = libxl__ao_device_check_last(gc, aodev, dcs->devices, dcs->num_devices); if (rc> 0) return; if (rc) { LOGE(ERROR, "error connecting devices"); goto error_out; } dcs->currentdevicekind++; if (!devicekindstable[dcs->currentdevicekind].add_function) { domcreate_complete(egc, dcs, rc); } else { domcreate_attach_devices(egc, dcs); }
Quoted 1 line
or something like it.
We can really iterate over this to add the devices, since we might need to launch the device model between connecting the disks and connecting the nics, I will try to find a nicer way to do this, I will try to come up with some macros to define this in a nicer way.
Quoted 6 lines
Or something. Anyway, can you try to find a way to avoid me having to review lots of nearly-identical code ?
Thanks,
Ian.
Re: [PATCH v4 05/10] libxl: convert libxl_device_nic_add to an async operation
Roger Pau Monne writes ("Re: [PATCH v4 05/10] libxl: convert libxl_device_nic_add to an async operation"):
Quoted 2 lines
Quoted 1 line · Ian Jackson
Or you could even have a table
...
Quoted 5 lines
We can really iterate over this to add the devices, since we might need to launch the device model between connecting the disks and connecting the nics, I will try to find a nicer way to do this, I will try to come up with some macros to define this in a nicer way.
I guess you mean `we can't really'. OK, thanks. Let me know if you need any help/suggestions.
Ian.
PATCH v4 6/10 libxl: add option to choose who executes hotplug scripts
In reply to Roger Pau MonneAdd and option to xl.conf file to decide if hotplug scripts are executed from the toolstack (xl) or from udev as it used to be in the past.
This option is only introduced in this patch, but it has no effect since the code to call hotplug scripts from libxl is introduced in a latter patch.
This choice will be saved in "libxl/disable_udev", as specified in the DISABLE_UDEV_PATH constant.
Changes since v2:
* Change atoi(...) to !!atoi(...) to prevent returning negative values from xenstore (which will be handled as errors).
* Check for errors on the return value of libxl__hotplug_settings.
Changes since v1:
* Used an auxiliary function to check for the current setting.
--- docs/man/xl.conf.pod.5 | 8 ++++++++ tools/examples/xl.conf | 5 +++++ tools/libxl/libxl_create.c | 36 +++++++++++++++++++++++++++++++++++- tools/libxl/libxl_internal.c | 19 +++++++++++++++++++ tools/libxl/libxl_internal.h | 3 +++ tools/libxl/libxl_types.idl | 1 + tools/libxl/xl.c | 4 ++++ tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 1 + 9 files changed, 77 insertions(+), 1 deletions(-)
docs/man/xl.conf.pod.5 +8 -0
@@ -55,6 +55,14 @@ default. Default: C<1> +=item B<run_hotplug_scripts=BOOLEAN> + +If disabled hotplug scripts will be called from udev, as it used to +be in the previous releases. With the default option, hotplug scripts +will be launched by xl directly. + +Default: C<1> + =item B<lockfile="PATH"> Sets the path to the lock file used by xl to serialise certain
tools/examples/xl.conf +5 -0
@@ -12,3 +12,8 @@ # default output format used by "xl list -l" #output_format="json" + +# default option to run hotplug scripts from xl +# if disabled the old behaviour will be used, and hotplug scripts will be +# launched by udev. +#run_hotplug_scripts=1
tools/libxl/libxl_create.c +35 -1
@@ -398,7 +398,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid) {libxl_ctx *ctx =libxl__gc_owner (gc); -int flags, ret, rc; +int flags, ret, rc, nb_vm;char *uuid_string;char *dom_path, *vm_path, *libxl_path;struct xs_permissions roperm[2 ];
@@ -519,6 +519,40 @@ retry_transaction:libxl__sprintf (gc,"%s/hvmloader/generation-id-address" , dom_path), rwperm, ARRAY_SIZE(rwperm)); +if (libxl_list_vm (ctx, &nb_vm) <0 ) { +LOG (ERROR ,"cannot get number of running guests" ); + rc =ERROR_FAIL ; + goto out; + } + +int hotplug_setting =libxl__hotplug_settings (gc, t); +if (hotplug_setting <0 ) { +LOG (ERROR ,"unable to get current hotplug scripts execution setting" ); + rc =ERROR_FAIL ; + goto out; + } +if (libxl_defbool_val (info->run_hotplug_scripts) != hotplug_setting && + (nb_vm -1 )) { +LOG (ERROR ,"cannot change hotplug execution option once set, " +"please shutdown all guests before changing it" ); + rc =ERROR_FAIL ; + goto out; + } + +if (libxl_defbool_val (info->run_hotplug_scripts)) { + rc =libxl__xs_write (gc, t,DISABLE_UDEV_PATH ,"1" ); +if (rc) { +LOGE (ERROR ,"unable to write %s = 1" ,DISABLE_UDEV_PATH ); + goto out; + } + }else { + rc =xs_rm (ctx->xsh, t,DISABLE_UDEV_PATH ); +if (rc) { +LOGE (ERROR ,"unable to delete %s" ,DISABLE_UDEV_PATH ); + goto out; + } + } +xs_write (ctx->xsh, t,libxl__sprintf (gc,"%s/uuid" , vm_path), uuid_string,strlen (uuid_string));xs_write (ctx->xsh, t,libxl__sprintf (gc,"%s/name" , vm_path), info->name,strlen (info->name));
tools/libxl/libxl_internal.c +19 -0
@@ -346,6 +346,25 @@ libxl_device_model_version libxl__device_model_version_running(libxl__gc *gc,return value; } +int libxl__hotplug_settings (libxl__gc *gc,xs_transaction_t t) +{ +int rc =0 ; +char *val; + + val =libxl__xs_read (gc, t,DISABLE_UDEV_PATH ); +if (!val && errno !=ENOENT ) { +LOGE (ERROR ,"cannot read %s from xenstore" ,DISABLE_UDEV_PATH ); + rc =ERROR_FAIL ; + goto out; + } +if (!val) val ="0" ; + + rc = !!atoi (val); + +out: +return rc; +} +/* * Local variables: * mode: C
tools/libxl/libxl_internal.h +3 -0
@@ -86,6 +86,7 @@#define STUBDOM_CONSOLE_SERIAL 3#define STUBDOM_SPECIAL_CONSOLES 3#define TAP_DEVICE_SUFFIX "-emu" +#define DISABLE_UDEV_PATH "libxl/disable_udev"#define ARRAY_SIZE (a) (sizeof(a) / sizeof(a[0]))
@@ -1393,6 +1394,8 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s); _hidden libxl_device_model_versionlibxl__device_model_version_running (libxl__gc *gc,uint32_t domid); +/* Check how executes hotplug script currently */ +int libxl__hotplug_settings (libxl__gc *gc,xs_transaction_t t);/* * Calling context and GC for event-generating functions:
tools/libxl/libxl_types.idl +1 -0
@@ -220,6 +220,7 @@ libxl_domain_create_info = Struct("domain_create_info",[ ("xsdata", libxl_key_value_list), ("platformdata", libxl_key_value_list), ("poolid", uint32), + ("run_hotplug_scripts",libxl_defbool), ], dir=DIR_IN) MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
tools/libxl/xl.c +4 -0
@@ -38,6 +38,7 @@ xentoollog_logger_stdiostream *logger;int dryrun_only;int force_execution;int autoballoon =1 ; +libxl_defbool run_hotplug_scripts;char *lockfile;char *default_vifscript =NULL ;char *default_bridge =NULL ;
@@ -69,6 +70,9 @@ static void parse_global_config(const char *configfile,if (!xlu_cfg_get_long (config,"autoballoon" , &l,0 )) autoballoon = l; +libxl_defbool_setdefault (&run_hotplug_scripts, true); +xlu_cfg_get_defbool (config,"run_hotplug_scripts" , &run_hotplug_scripts,0 ); +if (!xlu_cfg_get_string (config,"lockfile" , &buf,0 )) lockfile =strdup (buf);else {
tools/libxl/xl.h +1 -0
@@ -113,6 +113,7 @@ void postfork(void);/* global options */ extern int autoballoon; +extern libxl_defbool run_hotplug_scripts;extern int dryrun_only;extern char *lockfile;extern char *default_vifscript;
tools/libxl/xl_cmdimpl.c +1 -0
@@ -593,6 +593,7 @@ static void parse_config_data(const char *config_source, } } + c_info->run_hotplug_scripts = run_hotplug_scripts; c_info->type =LIBXL_DOMAIN_TYPE_PV ;if (!xlu_cfg_get_string (config,"builder" , &buf,0 ) && !strncmp (buf,"hvm" ,strlen (buf)))
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 06/10] libxl: add option to choose who executes hotplug scripts
Roger Pau Monne writes ("[PATCH v4 06/10] libxl: add option to choose who executes hotplug scripts"):
Quoted 3 lines
Add and option to xl.conf file to decide if hotplug scripts are executed from the toolstack (xl) or from udev as it used to be in the past.
Thanks.
PATCH v4 7/10 libxl: set nic type to VIF by default
In reply to Roger Pau MonneSet the default value for nic interfaces to VIF, since it used to be IOEMU, even for PV guests.
--- tools/libxl/libxl.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +1 -1
@@ -2008,7 +2008,7 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) libxl__xen_script_dir_path()) < 0 )return ERROR_FAIL ;if (!nic->nictype) - nic->nictype =LIBXL_NIC_TYPE_IOEMU ; + nic->nictype =LIBXL_NIC_TYPE_VIF ;return 0 ; }
Signature · 1 line
1.7.7.5 (Apple Git-26)
PATCH v4 8/10 libxl: call hotplug scripts for disk devices from libxl
In reply to Roger Pau MonneSince most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for disk devices, that should be called when the device is added or removed from a guest.
We will chain the launch of the disk hotplug scripts after the device_backend_callback callback, or directly from libxl__initiate_device_{add,remove} if the device is already in the desired state.
Changes since v2:
* Added array size check with assert.
* Added NetBSD code (so compilation is not broken).
* Removed a check for null in device_hotplug_timeout_cb.
Changes since v1:
* Moved all the event related code that was inside libxl_linux.c into libxl_device.c, so the flow of the device addition/removal event is all in the same file.
--- tools/hotplug/Linux/xen-backend.rules | 6 +- tools/hotplug/Linux/xen-hotplug-common.sh | 6 ++ tools/libxl/libxl.c | 10 +++ tools/libxl/libxl_device.c | 121 ++++++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 20 +++++ tools/libxl/libxl_linux.c | 98 +++++++++++++++++++++++ tools/libxl/libxl_netbsd.c | 9 ++ 7 files changed, 266 insertions(+), 4 deletions(-)
tools/hotplug/Linux/xen-backend.rules +3 -3
@@ -1,11 +1,11 @@ -SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}" -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" +SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}" +SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif" SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif" SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" -SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" +SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" KERNEL=="evtchn", NAME="xen/%k" SUBSYSTEM=="xen", KERNEL=="blktap[0-9]*", NAME="xen/%k", MODE="0600" SUBSYSTEM=="blktap2", KERNEL=="blktap[0-9]*", NAME="xen/blktap-2/%k", MODE="0600"
tools/hotplug/Linux/xen-hotplug-common.sh +6 -0
@@ -15,6 +15,12 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# Hack to prevent the execution of hotplug scripts from udev if the domain +# has been launched from libxl +if [ -n "${UDEV_CALL}" ] && \ + xenstore-read "libxl/disable_udev" >/dev/null 2>&1; then + exit 0 +fi dir=$(dirname "$0") . "$dir/hotplugpath.sh"
tools/libxl/libxl.c +10 -0
@@ -1607,6 +1607,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,flexarray_append (back,"params" );flexarray_append (back, dev); +flexarray_append (back,"script" ); +flexarray_append (back,GCSPRINTF ("%s/%s" , +libxl__xen_script_dir_path (), +"block" )); +assert (device->backend_kind ==LIBXL__DEVICE_KIND_VBD );break ;case LIBXL_DISK_BACKEND_TAP :
@@ -1622,6 +1627,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,libxl__device_disk_string_of_format (disk->format), disk->pdev_path)); +flexarray_append (back,"script" ); +flexarray_append (back,GCSPRINTF ("%s/%s" , +libxl__xen_script_dir_path (), +"blktap" )); +/* now create a phy device to export the device to the guest */ goto do_backend_phy;case LIBXL_DISK_BACKEND_QDISK :
tools/libxl/libxl_device.c +120 -1
145 lines not on this page · raw message
tools/libxl/libxl_internal.h +20 -0
@@ -72,6 +72,7 @@#define LIBXL_INIT_TIMEOUT 10#define LIBXL_DESTROY_TIMEOUT 10 +#define LIBXL_HOTPLUG_TIMEOUT 10#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10#define LIBXL_XENCONSOLE_LIMIT 1048576#define LIBXL_XENCONSOLE_PROTOCOL "vt100"
@@ -1814,6 +1815,11 @@ struct libxl__ao_device {int rc;libxl__ev_devstate ds;void *base; +/* device hotplug execution */ +pid_t pid; +char *what; +libxl__ev_time ev; +libxl__ev_child child; };/* Internal AO operation to connect a disk device */
@@ -1842,6 +1848,20 @@ _hidden void libxl__initiate_device_add(libxl__egc*, libxl__ao_device *aodev); _hidden void libxl__initiate_device_remove(libxl__egc *egc,libxl__ao_device *aodev); +/* +* libxl__get_hotplug_script_info returns the args and env that should +* be passed to the hotplug script for the requested device. +* +* Since a device might not need to execute any hotplug script, this function +* can return the following values: +* < 0: Error +* 0: No need to execute hotplug script +* 1: Execute hotplug script +*/ +_hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev, +char ***args,char ***env, +libxl__device_action action); +/*----- Domain destruction -----*/ /* Domain destruction has been split into two functions:
tools/libxl/libxl_linux.c +98 -0
101 lines not on this page · raw message
tools/libxl/libxl_netbsd.c +9 -0
@@ -24,3 +24,12 @@ int libxl__try_phy_backend(mode_t st_mode)return 0 ; } + +/* Hotplug scripts caller functions */ + +int libxl__get_hotplug_script_info (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +return 0 ; +}
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 08/10] libxl: call hotplug scripts for disk devices from libxl
Quoted 139 lines · Roger Pau Monne
Since most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for disk devices, that should be called when the device is added or removed from a guest.
We will chain the launch of the disk hotplug scripts after the
device_backend_callbackcallback, or directly from libxl__initiate_device_{add,remove} if the device is already in the desired state.Changes since v2:
* Added array size check with assert.
* Added NetBSD code (so compilation is not broken).
* Removed a check for null in
device_hotplug_timeout_cb.Changes since v1:
* Moved all the event related code that was inside
libxl_linux.cintolibxl_device.c, so the flow of the device addition/removal event is all in the same file.Cc Ian Jackson<[email protected]>Signed-off-by Roger Pau Monne<[email protected]>--- tools/hotplug/Linux/xen-backend.rules | 6 +- tools/hotplug/Linux/xen-hotplug-common.sh | 6 ++ tools/libxl/libxl.c | 10 +++ tools/libxl/libxl_device.c | 121 ++++++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 20 +++++ tools/libxl/libxl_linux.c | 98 +++++++++++++++++++++++ tools/libxl/libxl_netbsd.c | 9 ++ 7 files changed, 266 insertions(+), 4 deletions(-)tools/hotplug/Linux/xen-backend.rules +3
-3@@ -1,11 +1,11 @@ -SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}" -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" +SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}" +SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif" SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif" SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" -SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" +SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" KERNEL=="evtchn", NAME="xen/%k" SUBSYSTEM=="xen", KERNEL=="blktap[0-9]*", NAME="xen/%k", MODE="0600" SUBSYSTEM=="blktap2", KERNEL=="blktap[0-9]*", NAME="xen/blktap-2/%k", MODE="0600"tools/hotplug/Linux/xen-hotplug-common.sh +6
-0@@ -15,6 +15,12 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# Hack to prevent the execution of hotplug scripts from udev if the domain +# has been launched from libxl +if [ -n "${UDEV_CALL}" ]&& \ + xenstore-read "libxl/disable_udev">/dev/null 2>&1; then + exit 0 +fi dir=$(dirname "$0") . "$dir/hotplugpath.sh"tools/libxl/libxl.c +10
-0@@ -1607,6 +1607,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,flexarray_append (back,"params" );flexarray_append (back, dev); +flexarray_append (back,"script" ); +flexarray_append (back,GCSPRINTF ("%s/%s" , +libxl__xen_script_dir_path (), +"block" )); +assert (device->backend_kind ==LIBXL__DEVICE_KIND_VBD );break ;case LIBXL_DISK_BACKEND_TAP :@@ -1622,6 +1627,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,libxl__device_disk_string_of_format (disk->format), disk->pdev_path)); +flexarray_append (back,"script" ); +flexarray_append (back,GCSPRINTF ("%s/%s" , +libxl__xen_script_dir_path (), +"blktap" )); +/* now create a phy device to export the device to the guest */ goto do_backend_phy;case LIBXL_DISK_BACKEND_QDISK :tools/libxl/libxl_device.c +12
-1@@ -569,6 +569,14 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,static void device_backend_cleanup (libxl__gc *gc,libxl__ao_device *aodev); +static void device_hotplug (libxl__egc *egc,libxl__ao_device *aodev); + +static void device_hotplug_fork_cb (libxl__egc *egc,libxl__ev_child *child, +pid_t pid,int status); + +static void device_hotplug_timeout_cb (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs); +void libxl__initiate_device_add (libxl__egc *egc,libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao);@@ -657,7 +665,7 @@ retry_transaction: out_ok:if (t)xs_transaction_end (ctx->xsh, t,0 ); - aodev->callback (egc, aodev); +device_hotplug (egc, aodev);return ; }@@ -689,6 +697,9 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, goto out; } +device_hotplug (egc, aodev); +return ; + out: aodev->rc = rc; aodev->callback (egc, aodev);
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 719
Quoted 8 lines
tools/libxl/libxl_device.c +5
-0@@ -701,6 +712,114 @@ static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev)libxl__ev_devstate_cancel (gc,&aodev->ds); } +static void device_hotplug (libxl__egc *egc,libxl__ao_device *aodev) +{ +STATE_AO_GC (aodev->ao); +char *be_path =libxl__device_backend_path (gc, aodev->dev); +char **args, **env;
These should we initialised to NULL.
char **args = NULL, **env = NULL;
Quoted 278 lines
tools/libxl/libxl_device.c +103
-0+int rc =0 ; +int hotplug; + +/* Check if we have to execute hotplug scripts for this device +* and return the necessary args/env vars for execution */ + hotplug =libxl__get_hotplug_script_info (gc, aodev->dev,&args,&env, + aodev->action); +switch (hotplug) { +case 0 : +/* no hotplug script to execute */ + goto out; +case 1 : +/* execute hotplug script */ +break ; +default : +/* everything else is an error */ +LOG (ERROR ,"unable to get args/env to execute hotplug script for " +"device %s" ,libxl__device_backend_path (gc, aodev->dev)); + rc =ERROR_FAIL ; + goto out; + } + +/* Set hotplug timeout */ +libxl__ev_time_init (&aodev->ev); + rc =libxl__ev_time_register_rel (gc,&aodev->ev, device_hotplug_timeout_cb, +LIBXL_HOTPLUG_TIMEOUT *1000 ); +if (rc) { +LOG (ERROR ,"unable to register timeout for hotplug device %s" , be_path); + goto out; + } + + aodev->what =GCSPRINTF ("%s %s" , args[0 ], args[1 ]); +LOG (DEBUG ,"calling hotplug script: %s %s" , args[0 ], args[1 ]); +libxl__ev_child_init (&aodev->child); + +/* fork and execute hotplug script */ + aodev->pid =libxl__ev_child_fork (gc,&aodev->child, + device_hotplug_fork_cb); +if (aodev->pid ==-1 ) { +LOG (ERROR ,"unable to fork" ); + rc =ERROR_FAIL ; + goto out; + } + +if (!aodev->pid) { +/* child */ +libxl__exec (gc,-1 ,-1 ,-1 , args[0 ], args, env); +/* notreached */ +abort (); + } + +if (!libxl__ev_child_inuse (&aodev->child)) { +/* hotplug launch failed */ +LOG (ERROR ,"unable to launch hotplug script for device %s" , be_path); + rc =ERROR_FAIL ; + goto out; + } + +return ; + +out: +libxl__ev_time_deregister (gc,&aodev->ev); + aodev->rc = rc; + aodev->callback (egc, aodev); +return ; +} + +static void device_hotplug_fork_cb (libxl__egc *egc,libxl__ev_child *child, +pid_t pid,int status) +{ +libxl__ao_device *aodev =CONTAINER_OF (child, *aodev, child); +STATE_AO_GC (aodev->ao); + +libxl__ev_time_deregister (gc,&aodev->ev); + +if (status) { +libxl_report_child_exitstatus (CTX , aodev->rc ?LIBXL__LOG_ERROR + :LIBXL__LOG_WARNING , + aodev->what, pid, status); + aodev->rc =ERROR_FAIL ; + } + aodev->callback (egc, aodev); +} + +static void device_hotplug_timeout_cb (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs) +{ +libxl__ao_device *aodev =CONTAINER_OF (ev, *aodev, ev); +STATE_AO_GC (aodev->ao); + +if (libxl__ev_child_inuse (&aodev->child)) { +if (kill (aodev->pid,SIGKILL )) { +LOGEV (ERROR , errno,"unable to kill hotplug script %s [%ld]" , + aodev->what, (unsigned long )aodev->pid); + goto out; + } + } + +out: +libxl__ev_time_deregister (gc,&aodev->ev); +return ; +} +static void device_remove_callback (libxl__egc *egc,libxl__ao_device *aodev) {STATE_AO_GC (aodev->ao);tools/libxl/libxl_internal.h +20
-0@@ -72,6 +72,7 @@#define LIBXL_INIT_TIMEOUT 10#define LIBXL_DESTROY_TIMEOUT 10 +#define LIBXL_HOTPLUG_TIMEOUT 10#define LIBXL_DEVICE_MODEL_START_TIMEOUT 10#define LIBXL_XENCONSOLE_LIMIT 1048576#define LIBXL_XENCONSOLE_PROTOCOL "vt100"@@ -1814,6 +1815,11 @@ struct libxl__ao_device {int rc;libxl__ev_devstate ds;void *base; +/* device hotplug execution */ +pid_t pid; +char *what; +libxl__ev_time ev; +libxl__ev_child child; };/* Internal AO operation to connect a disk device */ @@ -1842,6 +1848,20 @@ _hidden void libxl__initiate_device_add(libxl__egc*, libxl__ao_device *aodev); _hidden void libxl__initiate_device_remove(libxl__egc *egc,libxl__ao_device *aodev); +/* +* libxl__get_hotplug_script_info returns the args and env that should +* be passed to the hotplug script for the requested device. +* +* Since a device might not need to execute any hotplug script, this function +* can return the following values: +*< 0: Error +* 0: No need to execute hotplug script +* 1: Execute hotplug script +*/ +_hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev, +char ***args,char ***env, +libxl__device_action action); +/*----- Domain destruction -----*/ /* Domain destruction has been split into two functions: tools/libxl/libxl_linux.c +98
-0@@ -25,3 +25,101 @@ int libxl__try_phy_backend(mode_t st_mode)return 1 ; } + +/* Hotplug scripts helpers */ + +static char **get_hotplug_env (libxl__gc *gc,libxl__device *dev) +{ +char *be_path =libxl__device_backend_path (gc, dev); +char *script; +const char *type =libxl__device_kind_to_string (dev->backend_kind); +char **env; +int nr =0 , arraysize =9 ; + + script =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path,"script" )); +if (!script) { +LOGEV (ERROR , errno,"unable to read script from %s" , be_path); +return NULL ; + } + +GCNEW_ARRAY (env, arraysize); + env[nr++] ="script" ; + env[nr++] = script; + env[nr++] ="XENBUS_TYPE" ; + env[nr++] =libxl__strdup (gc, type); + env[nr++] ="XENBUS_PATH" ; + env[nr++] =GCSPRINTF ("backend/%s/%u/%d" , type, dev->domid, dev->devid); + env[nr++] ="XENBUS_BASE_PATH" ; + env[nr++] ="backend" ; + env[nr++] =NULL ; +assert (nr == arraysize); + +return env; +} + +/* Hotplug scripts caller functions */ + +static int libxl__hotplug_disk (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +char *be_path =libxl__device_backend_path (gc, dev); +char *script; +int nr =0 , rc =0 , arraysize =3 ; + + script =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path,"script" )); +if (!script) { +LOGEV (ERROR , errno,"unable to read script from %s" , be_path); + rc =ERROR_FAIL ; + goto error; + } + + *env =get_hotplug_env (gc, dev); +if (!*env) { + rc =ERROR_FAIL ; + goto error; + } + +GCNEW_ARRAY (*args, arraysize); + (*args)[nr++] = script; + (*args)[nr++] = action ==DEVICE_CONNECT ?"add" :"remove" ; + (*args)[nr++] =NULL ; +assert (nr == arraysize); + + rc =0 ; + +error: +return rc; +} + +int libxl__get_hotplug_script_info (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +char *disable_udev =libxl__xs_read (gc,XBT_NULL ,DISABLE_UDEV_PATH ); +int rc; + +/* Check if we have to run hotplug scripts */ +if (!disable_udev) { + rc =0 ; + goto out; + } + +switch (dev->backend_kind) { +case LIBXL__DEVICE_KIND_VBD : + rc =libxl__hotplug_disk (gc, dev, args, env, action); +if (!rc) rc =1 ; +break ; +default : +/* If no need to execute any hotplug scripts, +* call the callback manually +*/ + rc =0 ; +break ; + } + +out: +return rc; +}tools/libxl/libxl_netbsd.c +9
-1@@ -24,3 +24,12 @@ int libxl__try_phy_backend(mode_t st_mode)return 0 ; } + +/* Hotplug scripts caller functions */ + +int libxl__get_hotplug_script_info (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +return 0 ; +} --1.7.7.5 (Apple Git-26)
Re: [PATCH v4 08/10] libxl: call hotplug scripts for disk devices from libxl
In reply to Roger Pau MonneRoger Pau Monne writes ("[PATCH v4 08/10] libxl: call hotplug scripts for disk devices from libxl"):
Quoted 4 lines
Since most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for disk devices, that should be called when the device is added or removed from a guest.
Thanks.
Quoted 2 lines
tools/libxl/libxl_device.c +2
-0+static void device_hotplug (libxl__egc *egc,libxl__ao_device *aodev) +{
...
Quoted 5 lines
tools/libxl/libxl_device.c +5
-0+/* Check if we have to execute hotplug scripts for this device +* and return the necessary args/env vars for execution */ + hotplug =libxl__get_hotplug_script_info (gc, aodev->dev, &args, &env, + aodev->action); +switch (hotplug) {
...
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 738
Quoted 5 lines
tools/libxl/libxl_device.c +5
-0+default : +/* everything else is an error */ +LOG (ERROR ,"unable to get args/env to execute hotplug script for " +"device %s" ,libxl__device_backend_path (gc, aodev->dev)); + rc =ERROR_FAIL ;
Again, `rc = hotplug' perhaps ?
Quoted 12 lines
tools/libxl/libxl_device.c +12
-0+/* fork and execute hotplug script */ + aodev->pid =libxl__ev_child_fork (gc, &aodev->child, + device_hotplug_fork_cb); +if (aodev->pid ==-1 ) { +LOG (ERROR ,"unable to fork" ); + rc =ERROR_FAIL ; + goto out; + } + +if (!aodev->pid) { +/* child */ +libxl__exec (gc,-1 ,-1 ,-1 , args[0 ], args, env);
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 776
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+/* notreached */ +abort (); + } + +if (!libxl__ev_child_inuse (&aodev->child)) { +/* hotplug launch failed */ +LOG (ERROR ,"unable to launch hotplug script for device %s" , be_path); + rc =ERROR_FAIL ; + goto out; + }
This isn't right. After a successful libxl__ev_child_fork, the child structure is definitely in use. So an assert would be appropriate but really this last stanza can just be removed.
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 785
Quoted 8 lines
tools/libxl/libxl_device.c +8
-0+return ; + +out: +libxl__ev_time_deregister (gc, &aodev->ev); + aodev->rc = rc; + aodev->callback (egc, aodev); +return ; +}
Shouldn't something set aodev->state to FINISHED in this error path ?
It might be better to have a helper function to call when declaring the aodev finished. That helper function would also do the _ev_time_deregister, and assert !libxl__ev_child_inuse.
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 788
Quoted 2 lines
tools/libxl/libxl_device.c +2
-0+static void device_hotplug_fork_cb (libxl__egc *egc,libxl__ev_child *child, +pid_t pid,int status)
This shouldn't be called fork_cb'. It's a callback that happens when the child dies, not when it forks. I wouldn't call it death_cb' or `child_cb' or something.
Quoted 7 lines
tools/libxl/libxl_device.c +7
-0+static void device_hotplug_timeout_cb (libxl__egc *egc,libxl__ev_time *ev, +const struct timeval *requested_abs) +{ +libxl__ao_device *aodev =CONTAINER_OF (ev, *aodev, ev); +STATE_AO_GC (aodev->ao); + +if (libxl__ev_child_inuse (&aodev->child)) {
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 820
Quoted 10 lines
tools/libxl/libxl_device.c +10
-0+if (kill (aodev->pid,SIGKILL )) { +LOGEV (ERROR , errno,"unable to kill hotplug script %s [%ld]" , + aodev->what, (unsigned long )aodev->pid); + goto out; + } + } + +out: +libxl__ev_time_deregister (gc, &aodev->ev); +return ;
You could profitably move that deregistration to the top of the function. That would save the goto.
Also libxl__ev_child_inuse should always be true here, surely ? After all we shouldn't have a timeout running unless we also have the child. So yo should assert libxl__ev_child_inuse.
Quoted 4 lines
tools/libxl/libxl_internal.h +0
-0
...
tools/libxl/libxl_internal.h struct libxl__ao_device { · line 1822
Quoted 5 lines
tools/libxl/libxl_internal.h +5
-0+/* device hotplug execution */ +pid_t pid; +char *what; +libxl__ev_time ev; +libxl__ev_child child;
Is the pid inside child not sufficient ?
Quoted 13 lines
tools/libxl/libxl_linux.c +5
-0@@ -25,3 +25,101 @@ int libxl__try_phy_backend(mode_t st_mode)return 1 ; } + +/* Hotplug scripts helpers */ + +static char **get_hotplug_env (libxl__gc *gc,libxl__device *dev) +{
...
Quoted 1 line
+ int nr = 0, arraysize = 9;
A nit, but here we see memetic leakage from the tyranny of
-Wdeclaration-after-statement. Surely the definition of arraysize
would be better placed:
tools/libxl/libxl_linux.c int libxl__try_phy_backend(mode_t st_mode) · line 45
Quoted 7 lines
tools/libxl/libxl_linux.c +7
-0+ script =libxl__xs_read (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path,"script" )); +if (!script) { +LOGEV (ERROR , errno,"unable to read script from %s" , be_path); +return NULL ; + } +
Here:
const int arraysize = 9;
Quoted 20 lines
tools/libxl/libxl_linux.c +11
-0+GCNEW_ARRAY (env, arraysize); + env[nr++] ="script" ; + env[nr++] = script; + env[nr++] ="XENBUS_TYPE" ; + env[nr++] =libxl__strdup (gc, type); + env[nr++] ="XENBUS_PATH" ; + env[nr++] =GCSPRINTF ("backend/%s/%u/%d" , type, dev->domid, dev->devid); + env[nr++] ="XENBUS_BASE_PATH" ; + env[nr++] ="backend" ; + env[nr++] =NULL ; +assert (nr == arraysize);tools/libxl/libxl_netbsd.c +0
-0@@ -24,3 +24,12 @@ int libxl__try_phy_backend(mode_t st_mode)return 0 ; }
tools/libxl/libxl_netbsd.c int libxl__try_phy_backend(mode_t st_mode) · line 35
Quoted 10 lines
tools/libxl/libxl_netbsd.c +9
-0+ +/* Hotplug scripts caller functions */ + +int libxl__get_hotplug_script_info (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action) +{ +return 0 ; +}
That last complaint from diff should be fixed :-).
Ian.
Re: [PATCH v4 08/10] libxl: call hotplug scripts for disk devices from libxl
Quoted 11 lines · Ian Jackson
tools/libxl/libxl_device.c static void device_backend_cleanup(libxl__gc *gc, libxl__ao_device *aodev) · line 785
Quoted 8 lines
tools/libxl/libxl_device.c +8
-0+return ; + +out: +libxl__ev_time_deregister (gc,&aodev->ev); + aodev->rc = rc; + aodev->callback (egc, aodev); +return ; +}Shouldn't something set
aodev->stateto FINISHED in this error path ?
Quoted 3 lines
It might be better to have a helper function to call when declaring the aodev finished. That helper function would also do the
_ev_time_deregister, and assert !libxl__ev_child_inuse.
Setting the aodev to finished is always done in libxl__ao_device_check_last, which should be called by the user.
Quoted 6 lines
Quoted 5 lines
tools/libxl/libxl_internal.h +0
-0...
Quoted 7 lines
tools/libxl/libxl_internal.h struct libxl__ao_device { · line 1822
Quoted 5 lines
tools/libxl/libxl_internal.h +5
-0+/* device hotplug execution */ +pid_t pid; +char *what; +libxl__ev_time ev; +libxl__ev_child child;Is the pid inside child not sufficient ?
Probably, I just wasn't sure if the user of libxl__ev_child was allowed to pick values inside the struct, now I saw the comment :)
PATCH v4 9/10 libxl: call hotplug scripts for nic devices from libxl
In reply to Roger Pau MonneSince most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for nic devices, that should be called when the device is added or removed from a guest.
Changes since v2:
* Change libxl__nic_type to return the value in a parameter passed by the caller.
* Rename vif_execute to num_exec, to represent the number of times hotplug scripts have been called for that device.
Changes since v1:
* Move event code to libxl_device.c (as in previous patch).
--- tools/hotplug/Linux/xen-backend.rules | 6 +- tools/libxl/libxl_device.c | 46 ++++++++++++++++- tools/libxl/libxl_internal.h | 6 ++- tools/libxl/libxl_linux.c | 92 +++++++++++++++++++++++++++++++- 4 files changed, 142 insertions(+), 8 deletions(-)
tools/hotplug/Linux/xen-backend.rules +3 -3
@@ -2,8 +2,8 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scr SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ENV{UDEV_CALL}="1", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ENV{UDEV_CALL}="1", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif" SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" KERNEL=="evtchn", NAME="xen/%k"
@@ -13,4 +13,4 @@ KERNEL=="blktap-control", NAME="xen/blktap-2/control", MODE="0600" KERNEL=="gntdev", NAME="xen/%k", MODE="0600" KERNEL=="pci_iomul", NAME="xen/%k", MODE="0600" KERNEL=="tapdev[a-z]*", NAME="xen/blktap-2/tapdev%m", MODE="0600" -SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap" +SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
tools/libxl/libxl_device.c +45 -1
71 lines not on this page · raw message
tools/libxl/libxl_internal.h +5 -1
@@ -803,6 +803,8 @@ _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path, libxl__device *dev); _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +_hidden int libxl__nic_type(libxl__gc *gc, libxl__device *dev, +libxl_nic_type *nictype);/* * For each aggregate type which can be used as an input we provide:
@@ -1818,6 +1820,7 @@ struct libxl__ao_device {/* device hotplug execution */ pid_t pid;char *what; +int num_exec;libxl__ev_time ev;libxl__ev_child child; };
@@ -1860,7 +1863,8 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,*/ _hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,char ***args,char ***env, -libxl__device_action action); +libxl__device_action action, +int num_exec);/*----- Domain destruction -----*/
tools/libxl/libxl_linux.c +89 -3
123 lines not on this page · raw message
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 09/10] libxl: call hotplug scripts for nic devices from libxl
Roger Pau Monne writes ("[PATCH v4 09/10] libxl: call hotplug scripts for nic devices from libxl"):
Quoted 5 lines
Since most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for nic devices, that should be called when the device is added or removed from a guest.
Quoted 7 lines
Changes since v2:
* Change
libxl__nic_typeto return the value in a parameter passed by the caller.* Rename
vif_executetonum_exec, to represent the number of times hotplug scripts have been called for that device.
This observation needs to be reworked into a suitable form and placed as a comment here in the code:
Quoted 4 lines
tools/libxl/libxl_internal.h +0
-0
...
tools/libxl/libxl_internal.h _hidden void libxl__initiate_device_remove(libxl__egc *egc, · line 1867
Quoted 7 lines
tools/libxl/libxl_internal.h +2
-1@@ -1860,7 +1863,8 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,*/ _hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,char ***args,char ***env, -libxl__device_action action); +libxl__device_action action, +int num_exec);
And the semantics need to be clearly explained. In particular, this is an interface that is supposed to be implemented by multiple providers for different platforms.
I _think_ what is happening is that `num_exec' is always 0 for everything but vifs. For vifs libxl__get_hotplug_script_info is always called with num_exec==0 for the actual PV vif (Xen PV interface) but may also be called with num_exec==1 for the ioemu device, but I may be wrong.
Quoted 5 lines
tools/libxl/libxl_linux.c +0
-0@@ -34,7 +34,8 @@ static char **get_hotplug_env(libxl__gc *gc, libxl__device *dev)
...
Quoted 3 lines
tools/libxl/libxl_linux.c +3
-0+static int libxl__hotplug_nic (libxl__gc *gc,libxl__device *dev, +char ***args,char ***env, +libxl__device_action action,int num_exec)
...
tools/libxl/libxl_linux.c static char **get_hotplug_env(libxl__gc *gc, libxl__device *dev) · line 121
Quoted 3 lines
tools/libxl/libxl_linux.c +3
-0+switch (nictype) { +case LIBXL_NIC_TYPE_IOEMU : +if (num_exec ==0 ) goto execute_vif;
Urgh! This is a pretty nasty use of goto.
Thanks,
Ian.
PATCH v4 10/10 libxl: use libxl__xs_path_cleanup on device_destroy
In reply to Roger Pau MonneSince the hotplug script that was in charge of cleaning the backend is no longer launched, we need to clean the backend by ourselves, so use libxl__xs_path_cleanup instead of xs_rm.
Changes sinve v2:
* Changed the goto construction to a do-while loop.
--- tools/libxl/libxl_device.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-)
tools/libxl/libxl_device.c +14 -4
@@ -487,16 +487,26 @@ void libxl__add_nics(libxl__egc *egc, libxl__ao *ao, uint32_t domid,int libxl__device_destroy (libxl__gc *gc,libxl__device *dev) { -libxl_ctx *ctx =libxl__gc_owner (gc);char *be_path =libxl__device_backend_path (gc, dev);char *fe_path =libxl__device_frontend_path (gc, dev); +xs_transaction_t t =0 ; +int rc =0 ; -xs_rm (ctx->xsh,XBT_NULL , be_path); -xs_rm (ctx->xsh,XBT_NULL , fe_path); +do { + t =xs_transaction_start (CTX ->xsh); +libxl__xs_path_cleanup (gc, t, fe_path); +libxl__xs_path_cleanup (gc, t, be_path); + rc = !xs_transaction_end (CTX ->xsh, t,0 ); + }while (rc && errno ==EAGAIN ); +if (rc) { +LOGE (ERROR ,"unable to finish transaction" ); + goto out; + }libxl__device_destroy_tapdisk (gc, be_path); -return 0 ; +out: +return rc; }/* Callback for device destruction */
Signature · 1 line
1.7.7.5 (Apple Git-26)
Re: [PATCH v4 10/10] libxl: use libxl__xs_path_cleanup on device_destroy
Roger Pau Monne writes ("[PATCH v4 10/10] libxl: use libxl__xs_path_cleanup on device_destroy"):
Quoted 3 lines
Since the hotplug script that was in charge of cleaning the backend is no longer launched, we need to clean the backend by ourselves, so use
libxl__xs_path_cleanupinstead ofxs_rm.
But see my comments earlier about wanting to give this function a different name.
Thanks,
Ian.