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

Re: [Xen-devel] [PATCH 13 of 29 RFC] libxl: add hotplug script calls for Linux



2012/2/7 Shriram Rajagopalan <rshriram@xxxxxxxxx>:
> On Thu, Feb 2, 2012 at 5:26 AM, Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
> wrote:
>>
>> # HG changeset patch
>> # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
>> # Date 1328177591 -3600
>> # Node ID 98a4f01033786a2fc15b4130897c35f64a676e40
>> # Parent Â6c2690921fba580dd7dd836da3be484dee049be0
>> libxl: add hotplug script calls for Linux
>>
>> This patchs adds the necessary logic to call hotplug scripts directly
>> from libxl. Linux hotplug scritps read most parameters from the caller
>> environment (since udev set this parameters automatically). In this
>> implementation we fake udev parameters, so no changes are needed to
>> the scripts itself.
>>
>> Currently, the following scripts are called:
>>
>> Â* block: used when disk backend is PHY.
>>
>> Â* blktap: used when disk backend is TAP.
>>
>
> Sorry if this is a bit dense, but you have been through the code
> already ;)
> Is there an option to call other scripts other than block/blktap ?

libxl has some preliminary support for setting custom hotplug scripts
for hard drives in configuration files (just like you do for nic
interfaces), this is currently disabled but could be enabled in future
releases.

> For e.g., if I were to add a backend type DRBD/FOOBAR,
> and wish to call script "block-<drbd|foobar>, how do you suggest I
> proceed ?

Well, I see several approaches here, right now we call Linux hotplug
scripts adding the necessary env variables, since udev used to set
those variables automatically, and we will continue to do it that way
until xend is removed. I think it's most suitable to pass those
parameters as arguments to the script, but this as I said before is a
long term goal.

> Â Start my way from defining new disk backend types and just add
> hotplug handlers for these block-* devices and finally expose them as
> phy devices to libxl ?

That's really up to you, but if you want to pass them as PHY devices,
you should modify the libxl__try_phy_backend function inside
libxl_linux.c and libxl_netbsd.c. If you want this changes to be added
to upstream it might be best to define your own backend type,
overloading the PHY type it's not clearer, and PHY should only be used
for physical partitions (again, since I don't know your specific
implementation, I cannot be sure of the most suitable way to tackle
this problem).

>
> shriram
>
>>
>> Â* vif-*: used when adding a network interface and can be manually set
>> Â by the user.
>>
>> udev rules descrive more device types, currently the following scripts
>> are NOT executed from libxl because I wasn't able to find any support
>> for this device types in libxl:
>>
>> Â* vtpm
>>
>> Â* vif2
>>
>> Â* vscsi
>>
>> Â* vif-setup with devices of type tap*
>>
>> This patch just adds the necessary code, but hotplug scripts are NOT
>> called from libxl yet, following patches will disable udev rules and
>> use this calls instead.
>>
>> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
>>
>> diff -r 6c2690921fba -r 98a4f0103378 tools/libxl/libxl_linux.c
>> --- a/tools/libxl/libxl_linux.c Thu Feb 02 11:10:24 2012 +0100
>> +++ b/tools/libxl/libxl_linux.c Thu Feb 02 11:13:11 2012 +0100
>> @@ -26,10 +26,172 @@ int libxl__try_phy_backend(mode_t st_mod
>> Â Â return 1;
>> Â}
>>
>> +/* Hotplug scripts helpers */
>> +#if 0
>> +static char **get_hotplug_env(libxl__gc *gc, libxl__device *dev)
>> +{
>> + Â Âlibxl_ctx *ctx = libxl__gc_owner(gc);
>> + Â Âchar *be_path = libxl__device_backend_path(gc, dev);
>> + Â Âflexarray_t *f_env;
>> + Â Âint nr = 0;
>> +
>> + Â Âf_env = flexarray_make(11, 1);
>> + Â Âif (!f_env) {
>> + Â Â Â ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR,
>> + Â Â Â Â Â Â Â Â Â "unable to create environment array");
>> + Â Â Â Âreturn NULL;
>> + Â Â}
>> +
>> + Â Âflexarray_set(f_env, nr++, "script");
>> + Â Âflexarray_set(f_env, nr++, libxl__xs_read(gc, XBT_NULL,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__sprintf(gc, "%s/%s",
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbe_path,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"script")));
>> + Â Âflexarray_set(f_env, nr++, "XENBUS_TYPE");
>> + Â Âflexarray_set(f_env, nr++, (char *)
>> + Â Â Â Â Â Â Â Â Âlibxl__device_kind_to_string(dev->backend_kind));
>> + Â Âflexarray_set(f_env, nr++, "XENBUS_PATH");
>> + Â Âflexarray_set(f_env, nr++,
>> + Â Â Â Â Â Â Â Â Âlibxl__sprintf(gc, "backend/%s/%u/%d",
>> + Â Â Â Â Â Â Â Â Âlibxl__device_kind_to_string(dev->backend_kind),
>> + Â Â Â Â Â Â Â Â Âdev->domid, dev->devid));
>> + Â Âflexarray_set(f_env, nr++, "XENBUS_BASE_PATH");
>> + Â Âflexarray_set(f_env, nr++, "backend");
>> + Â Âif (dev->backend_kind == LIBXL__DEVICE_KIND_VIF) {
>> + Â Â Â Âflexarray_set(f_env, nr++, "vif");
>> + Â Â Â Âflexarray_set(f_env, nr++,
>> + Â Â Â Â Â Â Â Â Â Â Âlibxl__sprintf(gc, "%s%u.%d",
>> + Â Â Â Â Â Â Â Â Â Â Âlibxl__device_kind_to_string(dev->backend_kind),
>> + Â Â Â Â Â Â Â Â Â Â Âdev->domid, dev->devid));
>> + Â Â}
>> + Â Âflexarray_set(f_env, nr++, NULL);
>> +
>> + Â Âreturn (char **) flexarray_contents(f_env);
>> +}
>> +
>> Â/* Hotplug scripts caller functions */
>>
>> +static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev,
>> + Â Â Â Â Â Â Â Â Â Â Â libxl__hotplug_action action)
>> +{
>> + Â Âlibxl_ctx *ctx = libxl__gc_owner(gc);
>> + Â Âchar *be_path = libxl__device_backend_path(gc, dev);
>> + Â Âchar *script, *what;
>> + Â Âchar **args, **env;
>> + Â Âint status, nr = 0;
>> + Â Âint rc = -1;
>> + Â Âflexarray_t *f_args;
>> +
>> + Â Âscript = libxl__xs_read(gc, XBT_NULL,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âlibxl__sprintf(gc, "%s/%s", be_path,
>> "script"));
>> + Â Âif (!script) {
>> + Â Â Â ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to read script from
>> %s",
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbe_path);
>> + Â Â Â Âreturn -1;
>> + Â Â}
>> +
>> + Â Âenv = get_hotplug_env(gc, dev);
>> + Â Âif (!env)
>> + Â Â Â Âreturn -1;
>> +
>> + Â Âf_args = flexarray_make(4, 1);
>> + Â Âif (!f_args) {
>> + Â Â Â ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to create arguments
>> array");
>> + Â Â Â Âreturn -1;
>> + Â Â}
>> +
>> + Â Âflexarray_set(f_args, nr++, script);
>> + Â Âflexarray_set(f_args, nr++, action == CONNECT ? "online" :
>> "offline");
>> + Â Âflexarray_set(f_args, nr++, "type_if=vif");
>> + Â Âflexarray_set(f_args, nr++, NULL);
>> +
>> + Â Âargs = (char **) flexarray_contents(f_args);
>> + Â Âwhat = libxl__sprintf(gc, "%s %s", args[0],
>> + Â Â Â Â Â Â Â Â Â Â Â Â Âaction == CONNECT ? "connect" : "disconnect");
>> + Â ÂLIBXL__LOG(ctx, LIBXL__LOG_DEBUG,
>> + Â Â Â Â Â Â Â "Calling hotplug script: %s %s %s",
>> + Â Â Â Â Â Â Â args[0], args[1], args[2]);
>> + Â Âstatus = libxl__forkexec(gc, -1, -1, -1, args[0], args, env, what);
>> + Â Âif (status) {
>> + Â Â Â Ârc = -1;
>> + Â Â Â Âgoto out;
>> + Â Â}
>> + Â Ârc = 0;
>> +
>> +out:
>> + Â Âfree(env);
>> + Â Âfree(args);
>> + Â Âreturn rc;
>> +}
>> +
>> +static int libxl__hotplug_disk(libxl__gc *gc, libxl__device *dev,
>> + Â Â Â Â Â Â Â Â Â Â Â libxl__hotplug_action action)
>> +{
>> + Â Âlibxl_ctx *ctx = libxl__gc_owner(gc);
>> + Â Âchar *be_path = libxl__device_backend_path(gc, dev);
>> + Â Âchar *script, *what;
>> + Â Âchar **args, **env;
>> + Â Âint status, nr = 0;
>> + Â Âint rc = -1;
>> + Â Âflexarray_t *f_args;
>> +
>> + Â Âscript = libxl__xs_read(gc, XBT_NULL,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âlibxl__sprintf(gc, "%s/%s", be_path,
>> "script"));
>> + Â Âif (!script) {
>> + Â Â Â ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to read script from
>> %s",
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbe_path);
>> + Â Â Â Âreturn -1;
>> + Â Â}
>> +
>> + Â Âenv = get_hotplug_env(gc, dev);
>> + Â Âif (!env)
>> + Â Â Â Âreturn -1;
>> +
>> + Â Âf_args = flexarray_make(3, 1);
>> + Â Âif (!f_args) {
>> + Â Â Â ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to create arguments
>> array");
>> + Â Â Â Âreturn -1;
>> + Â Â}
>> +
>> + Â Âflexarray_set(f_args, nr++, script);
>> + Â Âflexarray_set(f_args, nr++, action == CONNECT ? "add" : "remove");
>> + Â Âflexarray_set(f_args, nr++, NULL);
>> +
>> + Â Âargs = (char **) flexarray_contents(f_args);
>> + Â Âwhat = libxl__sprintf(gc, "%s %s", args[0],
>> + Â Â Â Â Â Â Â Â Â Â Â Â Âaction == CONNECT ? "connect" : "disconnect");
>> + Â ÂLIBXL__LOG(ctx, LIBXL__LOG_DEBUG,
>> + Â Â Â Â Â Â Â "Calling hotplug script: %s %s",
>> + Â Â Â Â Â Â Â args[0], args[1]);
>> + Â Âstatus = libxl__forkexec(gc, -1, -1, -1, args[0], args, env, what);
>> + Â Âif (status) {
>> + Â Â Â Ârc = -1;
>> + Â Â Â Âgoto out;
>> + Â Â}
>> + Â Ârc = 0;
>> +
>> +out:
>> + Â Âfree(env);
>> + Â Âfree(args);
>> + Â Âreturn rc;
>> +}
>> +#endif /* 0 */
>> Âint libxl__device_hotplug(libxl__gc *gc, libxl__device *dev,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â libxl__hotplug_action action)
>> Â{
>> - Â Âreturn 0;
>> + Â Âint rc = 0;
>> +#if 0
>> + Â Âswitch (dev->backend_kind) {
>> + Â Âcase LIBXL__DEVICE_KIND_VIF:
>> + Â Â Â Ârc = libxl__hotplug_nic(gc, dev, action);
>> + Â Â Â Âbreak;
>> + Â Âcase LIBXL__DEVICE_KIND_VBD:
>> + Â Â Â Ârc = libxl__hotplug_disk(gc, dev, action);
>> + Â Â Â Âbreak;
>> + Â Âdefault:
>> + Â Â Â Ârc = 0;
>> + Â Â Â Âbreak;
>> + Â Â}
>> +#endif /* 0 */
>> + Â Âreturn rc;
>> Â}
>>
>> _______________________________________________
>> 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®.