Ryan Harper
2009-Nov-16 19:21 UTC
[Ovirt-devel] [PATCH] Add support for vendor hooks during ovirt-early start()
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" + } esac done + if [ -n "${vendor_script}" ]; then + . ${vendor_script} + vendor_pre_hook + 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 + 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
Darryl L. Pierce
2009-Nov-16 20:50 UTC
[Ovirt-devel] [PATCH] Add support for vendor hooks during ovirt-early start()
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 > + fiHere, 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 > + fiSame 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>
Perry Myers
2009-Nov-16 20:55 UTC
[Ovirt-devel] [PATCH] Add support for vendor hooks during ovirt-early start()
On 11/16/2009 02:21 PM, 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.If you're using edit-livecd to embed a vendor specific script in the oVirt ISO image, why wouldn't you just change the init process to call that script instead of using a kernel cmdline parameter like this? i.e. edit-livecd to add a new init script called vendor-foo to /etc/init.d, then chkconfig that script on. Now during startup the script will automatically execute. I suppose maybe some information about the use case that is driving this request might help to explain. Perry
Alan Pevec
2009-Nov-17 14:15 UTC
[Ovirt-devel] [PATCH] Add support for vendor hooks during ovirt-early start()
> > The ovirt-early script uses the standard ip= and ipv6= kernel command line > > options to bring up autoconfigured network interfaces. The interface to > > bring up can be specified using the standard BOOTIF= kernel cmdline arg. > > So what you're talking about should work fine, as both ip= and ipv6= both > > support dhcp as an argument. > Sure, except AFAICT, this won't bring up networking until after we've > attempted to mount /config ... which is of course too late if we're > using an iscsi "local" disk.right, ovirt-early is only parsing ip parameters, they're used for the firstboot configuration in stand-alone mode. But let me try to understand the use-case here: is this PXE boot of the node image with /config on iSCSI ? B/c with iSCSI root networking must be brought up even earlier in initrd, right? In any case, for boot parameters we should reuse or make compatible with Dracut parameters http://sourceforge.net/apps/trac/dracut/wiki/commandline> Oddly enough, we pxe from our 1g nics, but want to bond the 10g > nics... > I'd prefer specifying input for creating a bond, or bonds...I guess bonding should be added to Dracut as well, let's propose it there. Dracut has bridge parameter which could be extended: http://sourceforge.net/apps/trac/dracut/wiki/commandline#Bridging> BONDIF=bond0,bond1 > bond0_MACS=$primary_mac,$secondary_mac > bond0_OPTIONS="mode=6 miimon=100 use_carrier=1" > bond0_PROTO="dhcp" > bond0_ONBOOT="yes" > bond1_MACS=$primary_mac,$secondary_mac > bond1_OPTIONS="mode=6 miimon=100 use_carrier=1" > > We'd also need bridging parameters so we can configure a bridge with > the > bond port... > BRIDGEIF=brbond0> > >> ... But regardless, it is probably worth creating an easy to use interface > > >> for vendors to add their own init scripts in without needing to duplicate > > >> code, and trampling on ovirt-early. Perhaps an > > >> /etc/insert-your-vendor-script-here.d directory that ovirt-early and > > >> ovirt-post reads and executes functions from? That would provide an easy > > >> way to drop in custom functionality and would also not require a new > > >> kernel cmdline param. Thoughts? > > > > > > That does seem cleaner; though I do still like having a way to choose > > > which set of vendor scripts to run via kernel parameter. We'd like to > > > have a single iso image that we could support different types of startups.There's already similar hooks folder /etc/ovirt-config-boot.d/ (scripts there are executed after upgrade). What about /etc/ovirt-early.d/ where vendor could put pre-* and post-* scripts and parameter would then select one or more scripts to execute: ovirt_early=*) i=${i#ovirt_early=} ovirt_early=$(echo $i|tr ",:;" " ") ;; EARLY_DIR=/etc/ovirt-early.d for hook in $ovirt_early; do pre="$EARLY_DIR/pre-$hook" if [ -e "$pre" ]; then . "$pre" fi done ... for hook in $ovirt_early; do post="$EARLY_DIR/post-$hook" if [ -e "$post" ]; then . "$post" fi done