From 78a77be447311f092e92c19b0371379f533c4ec5 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 16 Feb 2008 17:18:42 +0000 Subject: Refactored call-out to plugins when making the initramfs: * The code for setting up the plugin in the initramfs has been moved into the plugin base, as this makes it possible for any plugin to override it (should the need ever arise). * The plugin scripts themselves are now being copied into the initramfs, instead of being part of the config-TGZ - they are static scripts, so there's no need to make them part of the config. Only the actual settings of each plugin are part of the config-TGZ now. * Cleaned up most accesses from plugins to private data of the makeInitRamFS- engine. I have tested with these changes with Ubuntu and Debian, and splashy still works for both, so it should be ok. git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1551 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/slxconfig-demuxer | 26 ++----- initramfs/OpenSLX/MakeInitRamFS/Engine.pm | 80 ++++++++++++---------- os-plugins/OpenSLX/OSPlugin/Base.pm | 73 ++++++++++++++++++-- .../plugins/example/OpenSLX/OSPlugin/example.pm | 4 +- os-plugins/plugins/theme/OpenSLX/OSPlugin/theme.pm | 14 ++-- .../plugins/vmware/OpenSLX/OSPlugin/vmware.pm | 8 +-- 6 files changed, 130 insertions(+), 75 deletions(-) diff --git a/config-db/slxconfig-demuxer b/config-db/slxconfig-demuxer index 5ae29150..091c8c8b 100755 --- a/config-db/slxconfig-demuxer +++ b/config-db/slxconfig-demuxer @@ -522,7 +522,7 @@ sub makeInitRamFS 'export-name' => $info->{export}->{name}, 'export-uri' => $info->{'export-uri'}, 'initramfs' => "$pxeVendorOSPath/$info->{'initramfs-name'}", - 'kernel-params' => $info->{kernel_params} || '', + 'kernel-params' => [ split ' ', ($info->{kernel_params} || '') ], 'kernel-version' => $kernelFile =~ m[-(.+)$] ? $1 : '', 'plugins' => $info->{'active-plugins'}, 'root-path' @@ -530,9 +530,9 @@ sub makeInitRamFS 'slx-version' => $slxVersion, 'system-name' => $info->{name}, }; + # TODO: make debug-level an explicit attribute, it's used in many places! - my $kernelParams = $info->{kernel_params} || ''; - if ($kernelParams =~ m{debug(?:=(\d+))?}) { + if ($info->{kernel_params} =~ m{debug(?:=(\d+))?}) { my $debugLevel = defined $1 ? $1 : '1'; $params->{'debug-level'} = $debugLevel; } @@ -541,7 +541,7 @@ sub makeInitRamFS $makeInitRamFSEngine->execute($option{dryRun}); # copy back kernel-params, as they might have been changed (by plugins) - $info->{kernel_params} = $makeInitRamFSEngine->{'kernel-params'}; + $info->{kernel_params} = join ' ', $makeInitRamFSEngine->kernelParams(); return; } @@ -656,8 +656,6 @@ sub writePluginConfigurationsForSystem my $buildPath = shift || confess 'need to pass in build-path!'; my $pluginConfPath = "$buildPath/initramfs/plugin-conf"; - my $pluginInitdPath = "$buildPath/initramfs/plugin-init.d"; - my $initHooksPath = "$buildPath/initramfs/init-hooks"; my $attrs = $info->{attrs} || {}; @@ -672,7 +670,7 @@ sub writePluginConfigurationsForSystem next if $option{dryRun}; - mkpath([ $pluginConfPath, $pluginInitdPath, $initHooksPath]); + mkpath([ $pluginConfPath ]); vlog(2, _tr("writing configuration file for plugin '%s'", $pluginName)); # write plugin configuration to a file: @@ -691,20 +689,6 @@ sub writePluginConfigurationsForSystem vlog(0, $content); vlog(0, "--- END OF $fileName --- "); } - - # copy runlevel script to be used in stage3: - my $precedence - = sprintf('%02d', $attrs->{"${pluginName}::precedence"}); - my $pluginFolder - = "$openslxConfig{'base-path'}/lib/plugins/$pluginName"; - my $scriptName = "$pluginFolder/XX_${pluginName}.sh"; - my $targetName = "$pluginInitdPath/${precedence}_${pluginName}.sh"; - if (slxsystem("cp $scriptName $targetName && chmod a+x $targetName")) { - die _tr( - "unable to copy runlevel script '%s' to '%s'! (%s)", - $scriptName, $targetName, $! - ); - } } $info->{'active-plugins'} = \@activePlugins; my $activePluginStr = @activePlugins ? join ',', @activePlugins : ''; diff --git a/initramfs/OpenSLX/MakeInitRamFS/Engine.pm b/initramfs/OpenSLX/MakeInitRamFS/Engine.pm index bd30d15f..577cb168 100644 --- a/initramfs/OpenSLX/MakeInitRamFS/Engine.pm +++ b/initramfs/OpenSLX/MakeInitRamFS/Engine.pm @@ -93,6 +93,41 @@ sub execute return; } +sub haveKernelParam +{ + my $self = shift; + my $param = shift; + + return ref $param eq 'Regexp' + ? grep { $_ =~ $param } @{ $self->{'kernel-params'} } + : grep { $_ eq $param } @{ $self->{'kernel-params'} }; +} + +sub addKernelParams +{ + my $self = shift; + + push @{ $self->{'kernel-params'} }, @_; + + return; +} + +sub kernelParams +{ + my $self = shift; + + return @{ $self->{'kernel-params'} }; +} + +sub addKernelModules +{ + my $self = shift; + + push @{ $self->{'suggested-kernel-modules'} }, @_; + + return; +} + ################################################################################ ### implementation methods ################################################################################ @@ -128,7 +163,7 @@ sub _collectCMDs $self->_copyDebugTools(); } - $self->_handlePlugins(); + $self->_calloutToPlugins(); $self->{distro}->applyChanges($self); @@ -446,10 +481,10 @@ sub _copyRequiredLayeredFSTools my $self = shift; my @tools; - if ($self->{'kernel-params'} =~ m{\bunionfs\b}) { + if ($self->haveKernelParam('unionfs')) { push @tools, 'unionctl'; } - if ($self->{'kernel-params'} =~ m{\bcowloop\b}) { + if ($self->haveKernelParam('cowloop')) { push @tools, 'cowdev'; } foreach my $tool (@tools) { @@ -695,45 +730,18 @@ sub _writeSlxSystemConf return; } -sub _handlePlugins +sub _calloutToPlugins { my $self = shift; - my $pluginSrcPath = "$openslxConfig{'base-path'}/lib/plugins"; - my $buildPath = $self->{'build-path'}; + my $pluginInitdPath = "$self->{'build-path'}/etc/plugin-init.d"; + my $initHooksPath = "$self->{'build-path'}/etc/init-hooks"; + $self->addCMD("mkdir -p $pluginInitdPath $initHooksPath"); + foreach my $pluginName (@{$self->{'plugins'}}) { - if (-d "$pluginSrcPath/$pluginName/init-hooks") { - my $hookSrcPath = "$pluginSrcPath/$pluginName/init-hooks"; - $self->addCMD("cp -r $hookSrcPath/* $buildPath/etc/init-hooks/"); - } my $plugin = OpenSLX::OSPlugin::Roster->getPlugin($pluginName); next if !$plugin; - - my @suggestedKernelParams - = $plugin->suggestAdditionalKernelParams($self->{'kernel-params'}); - if (@suggestedKernelParams) { - my $paramsList = join ' ', @suggestedKernelParams; - vlog( - 2, - "plugin $pluginName suggests these kernel params: $paramsList" - ); - $self->{'kernel-params'} - .= ($self->{'kernel-params'} ? ' ' : '') . $paramsList; - } - - my @suggestedModules = $plugin->suggestAdditionalKernelModules($self); - if (@suggestedModules) { - vlog( - 2, - "plugin $pluginName suggests these kernel modules: " - . join(',', @suggestedModules) - ); - push @{ $self->{'suggested-kernel-modules'} }, @suggestedModules; - } - - $plugin->copyRequiredFilesIntoInitramfs( - $self->{'build-path'}, $self->{attrs}, $self - ); + $plugin->setupPluginInInitramfs($self->{attrs}, $self); } return; } diff --git a/os-plugins/OpenSLX/OSPlugin/Base.pm b/os-plugins/OpenSLX/OSPlugin/Base.pm index 51990912..c1945c95 100644 --- a/os-plugins/OpenSLX/OSPlugin/Base.pm +++ b/os-plugins/OpenSLX/OSPlugin/Base.pm @@ -146,11 +146,10 @@ sub postRemovalPhase sub suggestAdditionalKernelParams { # called by config-demuxer in order to give the plugin a chance to add # any kernel params it requires. - # In order to do so, the plugin should analyse the contents of the - # given string ('kernel-params') and return a list of additional params - # that it would like to see added. - my $self = shift; - my $kernelParams = shift; + # In order to do so, the plugin should return a list of additional kernel + # params that it would like to see added. + my $self = shift; + my $makeInitRamFSEngine = shift; return; } @@ -171,7 +170,8 @@ sub copyRequiredFilesIntoInitramfs # all required files from the vendor-OS into the initramfs. # N.B.: Only files that are indeed required by the initramfs should be # copied here, i.e. files that are needed *before* the root-fs - # has been mounted! + # has been mounted. + # All other files should be taken from the root-fs instead! my $self = shift; my $targetPath = shift; my $attrs = shift; @@ -179,3 +179,64 @@ sub copyRequiredFilesIntoInitramfs return; } + +sub setupPluginInInitramfs +{ # called by config-demuxer in order to let the plugin setup all the files + # it requires in the initramfs. + # Normally, you don't need to override this method in your own plugin, + # as it is usually enough to override suggestAdditionalKernelParams(), + # suggestAdditionalKernelModules() and maybe copyRequiredFilesIntoInitramfs(). + my $self = shift; + my $attrs = shift; + my $makeInitRamFSEngine = shift; + + my $pluginName = $self->{name}; + my $pluginSrcPath = "$openslxConfig{'base-path'}/lib/plugins"; + my $buildPath = $makeInitRamFSEngine->{'build-path'}; + my $pluginInitdPath = "$buildPath/etc/plugin-init.d"; + my $initHooksPath = "$buildPath/etc/init-hooks"; + + # copy runlevel script + my $precedence + = sprintf('%02d', $attrs->{"${pluginName}::precedence"}); + my $scriptName = "$pluginSrcPath/$pluginName/XX_${pluginName}.sh"; + my $targetName = "$pluginInitdPath/${precedence}_${pluginName}.sh"; + if (-e $scriptName) { + $makeInitRamFSEngine->addCMD("cp $scriptName $targetName"); + $makeInitRamFSEngine->addCMD("chmod a+x $targetName"); + } + + # copy init hook scripts, if any + if (-d "$pluginSrcPath/$pluginName/init-hooks") { + my $hookSrcPath = "$pluginSrcPath/$pluginName/init-hooks"; + $makeInitRamFSEngine->addCMD( + "cp -r $hookSrcPath/* $buildPath/etc/init-hooks/" + ); + } + + # invoke hook methods to suggest additional kernel params ... + my @suggestedParams + = $self->suggestAdditionalKernelParams($makeInitRamFSEngine); + if (@suggestedParams) { + my $params = join ' ', @suggestedParams; + vlog(1, "plugin $pluginName suggests these kernel params: $params"); + $makeInitRamFSEngine->addKernelParams(@suggestedParams); + } + + # ... and kernel modules + my @suggestedModules + = $self->suggestAdditionalKernelModules($makeInitRamFSEngine); + if (@suggestedModules) { + my $modules = join(',', @suggestedModules); + vlog(1, "plugin $pluginName suggests these kernel modules: $modules"); + $makeInitRamFSEngine->addKernelModules(@suggestedModules); + } + + # invoke hook method to copy any further files that are required in stage3 + # before the root-fs has been mounted + $self->copyRequiredFilesIntoInitramfs( + $buildPath, $attrs, $makeInitRamFSEngine + ); + + return 1; +} diff --git a/os-plugins/plugins/example/OpenSLX/OSPlugin/example.pm b/os-plugins/plugins/example/OpenSLX/OSPlugin/example.pm index 787991c3..252e8ae7 100644 --- a/os-plugins/plugins/example/OpenSLX/OSPlugin/example.pm +++ b/os-plugins/plugins/example/OpenSLX/OSPlugin/example.pm @@ -30,7 +30,9 @@ sub new { my $class = shift; - my $self = {}; + my $self = { + name => 'example', + }; return bless $self, $class; } diff --git a/os-plugins/plugins/theme/OpenSLX/OSPlugin/theme.pm b/os-plugins/plugins/theme/OpenSLX/OSPlugin/theme.pm index c2897eec..4bd83c69 100644 --- a/os-plugins/plugins/theme/OpenSLX/OSPlugin/theme.pm +++ b/os-plugins/plugins/theme/OpenSLX/OSPlugin/theme.pm @@ -29,7 +29,9 @@ sub new { my $class = shift; - my $self = {}; + my $self = { + name => 'theme', + }; return bless $self, $class; } @@ -113,20 +115,18 @@ sub getAttrInfo sub suggestAdditionalKernelParams { - my $self = shift; - my $kernelParams = shift; + my $self = shift; + my $makeInitRamFSEngine = shift; my @suggestedParams; # add vga=0x317 unless explicit vga-mode is already set - if ($kernelParams !~ m{\bvga=}) { - vlog(1, "theme-plugin: adding kernel-param vga=0x317"); + if (!$makeInitRamFSEngine->haveKernelParam(qr{\bvga=})) { push @suggestedParams, 'vga=0x317'; } # add quiet, if not already set - if ($kernelParams !~ m{\bquiet\b}) { - vlog(1, "theme-plugin: adding kernel-param quiet"); + if (!$makeInitRamFSEngine->haveKernelParam('quiet')) { push @suggestedParams, 'quiet'; } diff --git a/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm b/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm index b466dd17..d3d5375a 100644 --- a/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm +++ b/os-plugins/plugins/vmware/OpenSLX/OSPlugin/vmware.pm @@ -25,7 +25,9 @@ sub new { my $class = shift; - my $self = {}; + my $self = { + name => 'vmware', + }; return bless $self, $class; } @@ -83,9 +85,7 @@ sub suggestAdditionalKernelModules my $makeInitRamFSEngine = shift; # simply suggest these and see where we go from there (what is vmblock?) - my @suggestedModules = qw( vmmon vmnet vmblock ); - - return @suggestedModules; + return qw( vmmon vmnet vmblock ); } 1; -- cgit v1.2.3-55-g7522