All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Roger Pau Monne <roger.pau@citrix.com>
Cc: xen-devel@lists.xenproject.org,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Wei Liu <wei.liu2@citrix.com>
Subject: Re: [PATCH RFC 5/5] libxl/FreeBSD: add support for disk hotplug scripts
Date: Wed, 17 Jun 2015 14:23:38 +0100	[thread overview]
Message-ID: <1434547418.13744.380.camel@citrix.com> (raw)
In-Reply-To: <1432286338-56077-6-git-send-email-roger.pau@citrix.com>

On Fri, 2015-05-22 at 11:18 +0200, Roger Pau Monne wrote:
> Allow FreeBSD to execute hotplug scripts when attaching disk devices.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

This looks rather similar to the code for Linux, is there any chance
they could be combined into one or more common hotplugger running
things?

> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> ---
>  tools/libxl/libxl_freebsd.c | 114 ++++++++++++++++++++++++++++++++------------
>  1 file changed, 83 insertions(+), 31 deletions(-)
> 
> diff --git a/tools/libxl/libxl_freebsd.c b/tools/libxl/libxl_freebsd.c
> index 47c3391..5ff3388 100644
> --- a/tools/libxl/libxl_freebsd.c
> +++ b/tools/libxl/libxl_freebsd.c
> @@ -59,14 +59,36 @@ static int libxl__hotplug_env_nic(libxl__gc *gc, libxl__device *dev, char ***env
>      return 0;
>  }
>  
> -static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, char ***args,
> -                              libxl__device_action action)
> +static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev,
> +                              char ***args, char ***env,
> +                              libxl__device_action action,
> +                              int num_exec)
>  {
> +    libxl_nic_type nictype;
>      char *be_path = libxl__device_backend_path(gc, dev);
>      char *script;
> -    int nr = 0, rc = 0, arraysize = 4;
> +    int nr = 0, rc;
>  
> -    assert(dev->backend_kind == LIBXL__DEVICE_KIND_VIF);
> +    rc = libxl__nic_type(gc, dev, &nictype);
> +    if (rc) {
> +        LOG(ERROR, "error when fetching nic type");
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +
> +    /*
> +     * For PV domains only one pass is needed (because there's no emulated
> +     * interface). For HVM domains two passes are needed in order to add
> +     * both the PV and the tap interfaces to the bridge.
> +     */
> +    if (nictype == LIBXL_NIC_TYPE_VIF && num_exec != 0) {
> +        rc = 0;
> +        goto out;
> +    }
> +
> +    rc = libxl__hotplug_env_nic(gc, dev, env, num_exec);
> +    if (rc)
> +        goto out;
>  
>      script = libxl__xs_read(gc, XBT_NULL,
>                              GCSPRINTF("%s/%s", be_path, "script"));
> @@ -76,53 +98,83 @@ static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev, char ***args,
>          goto out;
>      }
>  
> +    const int arraysize = 4;
>      GCNEW_ARRAY(*args, arraysize);
>      (*args)[nr++] = script;
>      (*args)[nr++] = be_path;
> -    (*args)[nr++] = GCSPRINTF("%s", action == LIBXL__DEVICE_ACTION_ADD ?
> -                                    "add" : "remove");
> +    (*args)[nr++] = (char *) libxl__device_action_to_string(action);
>      (*args)[nr++] = NULL;
>      assert(nr == arraysize);
>  
> +    rc = 1;
> +
>  out:
>      return rc;
>  }
>  
> +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;
> +
> +    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;
> +    }
> +
> +    const int arraysize = 4;
> +    GCNEW_ARRAY(*args, arraysize);
> +    (*args)[nr++] = script;
> +    (*args)[nr++] = be_path;
> +    (*args)[nr++] = (char *) libxl__device_action_to_string(action);
> +    (*args)[nr++] = NULL;
> +    assert(nr == arraysize);
> +
> +    rc = 1;
> +
> +error:
> +    return rc;
> +}
> +
>  int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
>                                     char ***args, char ***env,
>                                     libxl__device_action action,
>                                     int num_exec)
>  {
> -    libxl_nic_type nictype;
>      int rc;
>  
> -    if (dev->backend_kind != LIBXL__DEVICE_KIND_VIF || num_exec == 2)
> -        return 0;
> -
> -    rc = libxl__nic_type(gc, dev, &nictype);
> -    if (rc) {
> -        LOG(ERROR, "error when fetching nic type");
> -        rc = ERROR_FAIL;
> -        goto out;
> -    }
> -
> -    /*
> -     * For PV domains only one pass is needed (because there's no emulated
> -     * interface). For HVM domains two passes are needed in order to add
> -     * both the PV and the tap interfaces to the bridge.
> -     */
> -    if (nictype == LIBXL_NIC_TYPE_VIF && num_exec != 0) {
> +    switch (dev->backend_kind) {
> +    case LIBXL__DEVICE_KIND_VBD:
> +        if (num_exec != 0) {
> +            rc = 0;
> +            goto out;
> +        }
> +        rc = libxl__hotplug_disk(gc, dev, args, env, action);
> +        break;
> +    case LIBXL__DEVICE_KIND_VIF:
> +        /*
> +         * If domain has a stubdom we don't have to execute hotplug scripts
> +         * for emulated interfaces
> +         */
> +        if ((num_exec > 1) ||
> +            (libxl_get_stubdom_id(CTX, dev->domid) && num_exec)) {
> +            rc = 0;
> +            goto out;
> +        }
> +        rc = libxl__hotplug_nic(gc, dev, args, env, action, num_exec);
> +        break;
> +    default:
> +        /* No need to execute any hotplug scripts */
>          rc = 0;
> -        goto out;
> +        break;
>      }
>  
> -    rc = libxl__hotplug_env_nic(gc, dev, env, num_exec);
> -    if (rc)
> -        goto out;
> -
> -    rc = libxl__hotplug_nic(gc, dev, args, action);
> -    if (!rc) rc = 1;
> -
>  out:
>      return rc;
>  }



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2015-06-17 13:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  9:18 [PATCH RFC 0/5] tools/FreeBSD: enable disk hotplug scripts Roger Pau Monne
2015-05-22  9:18 ` [PATCH RFC 1/5] libxl: only write physical-device on Linux and NetBSD Roger Pau Monne
2015-05-22  9:18 ` [PATCH RFC 2/5] blkif: document new blkback path xenstore node Roger Pau Monne
2015-06-01 13:24   ` Wei Liu
2015-06-02 15:22     ` Roger Pau Monné
2015-06-02 16:57       ` Wei Liu
2015-06-17 13:22     ` Ian Campbell
2015-05-22  9:18 ` [PATCH RFC 3/5] libxl/FreeBSD: write blkback "path" node Roger Pau Monne
2015-05-22  9:18 ` [PATCH RFC 4/5] hotplug/FreeBSD: add block hotplug script Roger Pau Monne
2015-05-22  9:18 ` [PATCH RFC 5/5] libxl/FreeBSD: add support for disk hotplug scripts Roger Pau Monne
2015-06-17 13:23   ` Ian Campbell [this message]
2015-06-17 14:57     ` Roger Pau Monné

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434547418.13744.380.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.