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

Re: [Xen-devel] [PATCH 6 of 9 v2] libxl: execute hotplug scripts directly from libxl



2011/11/18 Ian Campbell <Ian.Campbell@xxxxxxxxxx>:
> On Fri, 2011-11-18 at 11:59 +0000, Roger Pau Monne wrote:
>> # HG changeset patch
>> # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
>> # Date 1317386335 -7200
>> # Node ID 1d81d1c4c851c0b07696373304801df56a221e90
>> # Parent Â4ad998fddb16a299cb230ea23ba944d84adbd2bf
>> libxl: execute hotplug scripts directly from libxl.
>>
>> Added the necessary handlers to execute hotplug scripts when necessary
>> from libxl. Split NetBSD and Linux hotplug calls into two separate
>> files, because parameters for hotplug scripts are different. Linux
>> has empty functions, since the calling of hotplug scripts is still
>> done using udev.
>>
>> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
>>
>> diff -r 4ad998fddb16 -r 1d81d1c4c851 tools/libxl/Makefile
>> --- a/tools/libxl/Makefile   ÂFri Nov 18 11:29:14 2011 +0100
>> +++ b/tools/libxl/Makefile   ÂFri Sep 30 14:38:55 2011 +0200
>> @@ -34,8 +34,10 @@ LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpu
>
> Should be:
>
>> Âifeq ($(CONFIG_NetBSD),y)
>> ÂLIBXL_OBJS-y += libxl_phybackend.o
>> +LIBXL_OBJS-y += hotplug_netbsd.o
> Â elsif ($(CONFIG_Linux),y)
>> ÂLIBXL_OBJS-y += libxl_nophybackend.o
>> +LIBXL_OBJS-y += hotplug_linux.o
> Â else
> Â $(error A message of some sort)
>> Âendif

Done, I've moved PHY backend selection and hotplug specific functions
to libxl_netbsd.c and libxl_linux.c, and added an error message in
case someone tries to use a different OS.

>> diff -r 4ad998fddb16 -r 1d81d1c4c851 tools/libxl/libxl_device.c
>> --- a/tools/libxl/libxl_device.c    ÂFri Nov 18 11:29:14 2011 +0100
>> +++ b/tools/libxl/libxl_device.c    ÂFri Sep 30 14:38:55 2011 +0200
>> @@ -68,6 +68,24 @@ int libxl__parse_backend_path(libxl__gc
>> Â Â Âreturn libxl__device_kind_from_string(strkind, &dev->backend_kind);
>> Â}
>>
>> +int libxl__device_execute_hotplug(libxl__gc *gc, libxl__device *dev)
>
> No need for a add/remove type parameter?

Although you could pass this kind of parameter, the action to perform
is based on the state of the device in the corresponding xenstore
entry. State 2 means that the device should be connected, state 6
means the device should be disconnected.

>> +{
>> + Â Âint rc = 0;
>> +
>> + Â Âswitch(dev->kind) {
>> + Â Âcase LIBXL__DEVICE_KIND_VIF:
>> + Â Â Â Ârc = libxl__nic_hotplug(gc, dev);
>> + Â Â Â Âbreak;
>> + Â Âcase LIBXL__DEVICE_KIND_VBD:
>> + Â Â Â Ârc = libxl__disk_hotplug(gc, dev);
>> + Â Â Â Âbreak;
>> + Â Âdefault:
>> + Â Â Â Âbreak;
>> + Â Â}
>> +
>> + Â Âreturn rc;
>> +}
>> +
>> Âint libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â char **bents, char **fents)
>> Â{
>> @@ -449,6 +467,7 @@ int libxl__device_remove(libxl__gc *gc,
>> Â Â Âif (!state)
>> Â Â Â Â Âgoto out;
>> Â Â Âif (atoi(state) != 4) {
>> + Â Â Â Âlibxl__device_execute_hotplug(gc, dev);
>> Â Â Â Â Âlibxl__device_destroy_tapdisk(gc, be_path);
>> Â Â Â Â Âxs_rm(ctx->xsh, XBT_NULL, be_path);
>> Â Â Â Â Âgoto out;
>> @@ -492,6 +511,12 @@ int libxl__device_destroy(libxl__gc *gc,
>> Â Â Âchar *be_path = libxl__device_backend_path(gc, dev);
>> Â Â Âchar *fe_path = libxl__device_frontend_path(gc, dev);
>>
>> + Â Â/*
>> + Â Â * Run hotplug scripts, which will probably not be able to
>> + Â Â * execute successfully since the device may still be plugged
>
> What does this mean? If we don't expect it to work why are we calling
> them?

If you call the libxl_domain_destroy function with force == 1, the
destroy process doesn't wait for devices to be disconnected, but we
might as well try to execute hotplug scripts, since we don't know the
actual state of the device. If we are lucky, the device might be
disconnected (state == 6), and we should be able to execute hotplug
scripts successfully.

>> + Â Â */
>> + Â Âlibxl__device_execute_hotplug(gc, dev);
>> +
>> Â Â Âxs_rm(ctx->xsh, XBT_NULL, be_path);
>> Â Â Âxs_rm(ctx->xsh, XBT_NULL, fe_path);
>>
>> diff -r 4ad998fddb16 -r 1d81d1c4c851 tools/libxl/libxl_internal.h
>> --- a/tools/libxl/libxl_internal.h   ÂFri Nov 18 11:29:14 2011 +0100
>> +++ b/tools/libxl/libxl_internal.h   ÂFri Sep 30 14:38:55 2011 +0200
>> @@ -287,6 +287,34 @@ _hidden int libxl__wait_for_device_state
>> Â */
>> Â_hidden int libxl__try_phy_backend(mode_t st_mode);
>>
>> +/* hotplug functions */
>> +/*
>> + * libxl__device_execute_hotplug - generic function to execute hotplug 
>> scripts
>> + * gc: allocation pool
>> + * dev: reference to the device that executes the hotplug scripts
>> + *
>> + * Returns 0 on success, and < 0 on error.
>> + */
>> +_hidden int libxl__device_execute_hotplug(libxl__gc *gc, libxl__device 
>> *dev);
>> +
>> +/*
>> + * libxl__disk_hotplug - execute hotplug script for a disk type device
>> + * gc: allocation pool
>> + * dev: reference to the disk device
>> + *
>> + * Returns 0 on success, and < 0 on error.
>> + */
>> +_hidden int libxl__disk_hotplug(libxl__gc *gc, libxl__device *dev);
>> +
>> +/*
>> + * libxl__nic_hotplug - execute hotplug script for a nic type device
>> + * gc: allocation pool
>> + * dev: reference to the nic device
>> + *
>> + * Returns 0 on success, and < 0 on error.
>> + */
>> +_hidden int libxl__nic_hotplug(libxl__gc *gc, libxl__device *dev);
>> +
>> Â/* from libxl_pci */
>>
>> Â_hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, 
>> libxl_device_pci *pcidev, int starting);
>>
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@xxxxxxxxxxxxxxxxxxx
>> http://lists.xensource.com/xen-devel
>
>
>

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

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