[Ovirt-devel] [PATCH] Add support for vendor hooks during ovirt-early start()

Darryl L. Pierce dpierce at redhat.com
Mon Nov 16 20:50:13 UTC 2009


On Mon, Nov 16, 2009 at 01:21:45PM -0600, Ryan Harper wrote:
> Add a kernel parameter, vendor= which takes a path to a script
> embedded in the image.  If this script is executable, we will then
> source it during ovirt-early start() after command line processing
> and before mounting of /config.  We also call a post hook at the end of
> ovirt-early start().
> 
> Also include a sample vendor script.
>
> Signed-off-by: Ryan Harper <ryanh at us.ibm.com>
> ---
>  scripts/ovirt-early         |   25 ++++++++++++++++++++++++-
>  scripts/ovirt-vendor.sample |   35 +++++++++++++++++++++++++++++++++++
>  2 files changed, 59 insertions(+), 1 deletions(-)
>  create mode 100644 scripts/ovirt-vendor.sample
> 
> diff --git a/scripts/ovirt-early b/scripts/ovirt-early
> index cdd4afd..7683948 100755
> --- a/scripts/ovirt-early
> +++ b/scripts/ovirt-early
> @@ -369,9 +369,27 @@ start() {
>              console=*)
>              bootparams="$bootparams $i"
>              ;;
> +            vendor=*)
> +            i=${i#vendor=}
> +            # path to vendor script:
> +            # has 2 stages:
> +            #   vendor_pre_hook()
> +            #   vendor_post_host()
> +            # pre_hook runs after cmdline processing but before the rest of ovirt-early
> +            # post_hook runs at the end of ovirt-early start()
> +            [ -x "${i}" ] && {
> +                vendor_script="$i"
> +                log "Found vendor script: ${vendor_script}";
> +                bootparams="$bootparams $i"
> +            }

If there would only be one such vendor script, then perhaps a different
way to go would be to use a well-known script name and, if such exists,
source and execute that, rather than specifying it in the kernel 
commandline? Then an optional kernel argument, "novendor", could be used
to ignore that script if it exists. That way the default behavior would
be to execute the script if it's found.

>          esac
>      done
>  
> +    if [ -n "${vendor_script}" ]; then
> +        . ${vendor_script}
> +        vendor_pre_hook
> +    fi

Here, and also in the call to vendor_post_hook, the script should
probably check that the function being called exist.

+    if [ -n "${vendor_script}" ]; then
+        . ${vendor_script}
+        if type vendor_pre_hook > /dev/null 2>&1; then
+            vendor_pre_hook
+        fi
+    fi

> +
>      if [ -z "$ip_netmask" ]; then
>          ip_netmask=$netmask
>      fi
> @@ -379,7 +397,8 @@ start() {
>          ip_gateway=$gateway
>      fi
>      # save boot parameters as defaults for ovirt-config-*
> -    params="bootif init vol_boot_size vol_swap_size vol_root_size vol_config_size vol_logging_size vol_data_size local_boot standalone overcommit ip_address ip_netmask ip_gateway ipv6 dns ntp vlan ssh_pwauth syslog_server syslog_port collectd_server collectd_port bootparams hostname firstboot"
> +    # and allow vendor prehook set params to be saved
> +    params="${params} bootif init vol_boot_size vol_swap_size vol_root_size vol_config_size vol_logging_size vol_data_size local_boot standalone overcommit ip_address ip_netmask ip_gateway ipv6 dns ntp vlan ssh_pwauth syslog_server syslog_port collectd_server collectd_port bootparams hostname firstboot"
>      # mount /config unless firstboot is forced
>      if [ "$firstboot" != "1" ]; then
>          mount_config
> @@ -434,6 +453,10 @@ start() {
>          fi
>      fi
>  
> +    if [ -n "${vendor_script}" ]; then
> +        vendor_post_hook
> +    fi

Same here with the method call, checking if it exists first:

+    if [ -n "${vendor_script}" ]; then
+        if type vendor_post_host > /dev/null 2>&1; then
+            vendor_post_hook
+        fi
+    fi

> +
>      return 0
>  }
>  
> diff --git a/scripts/ovirt-vendor.sample b/scripts/ovirt-vendor.sample
> new file mode 100644
> index 0000000..7a57ddd
> --- /dev/null
> +++ b/scripts/ovirt-vendor.sample
> @@ -0,0 +1,35 @@
> +#!/bin/bash
> +
> +# This is a sample vendor script
> +#
> +# We need to provide two hook functions:
> +# - vendor_pre_hook()
> +# - vendor_post_hook()
> +#
> +# pre_hook is called after command line processing in ovirt-early, before
> +# /config is mounted
> +#
> +# post_hook is called at the very end of ovirt-early start()
> +#
> +
> +# as an example, lets look for a new kernel parameter and save it
> +function vendor_pre_hook()
> +{
> +    log "Entering vendor pre hook";
> +    for i in $(cat /proc/cmdline); do
> +        case $i in
> +            vendor=*)
> +            bootparams="$bootparams $i"
> +            ;;
> +        esac
> +    done
> +    params="${params} vendor";
> +    log "Exiting vendor pre hook";
> +}
> +
> +function vendor_post_hook()
> +{
> +    log "Entering vendor post hook";
> +
> +    log "Exiting vendor post hook";
> +}
> -- 
> 1.6.2.5
> 
> 
> -- 
> Ryan Harper
> Software Engineer; Linux Technology Center
> IBM Corp., Austin, Tx
> ryanh at us.ibm.com
> 
> _______________________________________________
> Ovirt-devel mailing list
> Ovirt-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/ovirt-devel

-- 
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20091116/a059e7bb/attachment.sig>


More information about the ovirt-devel mailing list