diff options
| -rw-r--r-- | installer/OpenSLX/OSExport/Engine.pm | 4 | ||||
| -rw-r--r-- | installer/OpenSLX/OSExport/ExportType/Base.pm | 44 | ||||
| -rw-r--r-- | installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm | 90 | ||||
| -rw-r--r-- | installer/OpenSLX/OSExport/ExportType/NFS.pm | 49 |
4 files changed, 137 insertions, 50 deletions
diff --git a/installer/OpenSLX/OSExport/Engine.pm b/installer/OpenSLX/OSExport/Engine.pm index c8768759..721bddf5 100644 --- a/installer/OpenSLX/OSExport/Engine.pm +++ b/installer/OpenSLX/OSExport/Engine.pm @@ -26,8 +26,8 @@ use vars qw(%supportedExportTypes %supportedDistros); %supportedExportTypes = ( 'nfs' => { module => 'NFS' }, -# 'nbd-squashfs' -# => { module => 'NBD_Squash' }, + 'nbd-squash' + => { module => 'NBD_Squash' }, ); %supportedDistros = ( diff --git a/installer/OpenSLX/OSExport/ExportType/Base.pm b/installer/OpenSLX/OSExport/ExportType/Base.pm index 6356ba94..7acda8b2 100644 --- a/installer/OpenSLX/OSExport/ExportType/Base.pm +++ b/installer/OpenSLX/OSExport/ExportType/Base.pm @@ -12,6 +12,9 @@ $VERSION = 1.01; # API-version . implementation-version use strict; use Carp; +use OpenSLX::Basics; +use OpenSLX::Utils; + ################################################################################ ### interface methods ################################################################################ @@ -32,6 +35,47 @@ sub exportVendorOS { } +################################################################################ +### implementation methods +################################################################################ +sub copyViaRsync +{ + my $self = shift; + my $source = shift; + my $target = shift; + + if (system("mkdir -p $target")) { + die _tr("unable to create directory '%s', giving up! (%s)\n", + $target, $!); + } + my $includeExcludeList = $self->determineIncludeExcludeList(); + vlog 1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList); + open(RSYNC, "| rsync -av --delete --exclude-from=- $source/ $target") + or die _tr("unable to start rsync for source '%s', giving up! (%s)", + $source, $!); + print RSYNC $includeExcludeList; + if (!close(RSYNC)) { + die _tr("unable to export to target '%s', giving up! (%s)", + $target, $!); + } +} + +sub determineIncludeExcludeList +{ + my $self = shift; + + # Rsync uses a first match strategy, so we mix the local specifications + # in front of the filterset given by the package (as the local filters + # should always overrule the vendor filters): + my $distroName = $self->{engine}->{'distro-name'}; + my $localFilterFile = "../lib/distro-info/$distroName/export-filter.local"; + my $includeExcludeList = slurpFile($localFilterFile, 1); + $includeExcludeList .= $self->{engine}->{distro}->{'export-filter'}; + $includeExcludeList =~ s[^\s+][]igms; + # remove any leading whitespace, as rsync doesn't like it + return $includeExcludeList; +} + 1; ################################################################################ diff --git a/installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm b/installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm new file mode 100644 index 00000000..e660ae04 --- /dev/null +++ b/installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm @@ -0,0 +1,90 @@ +# NBD_Squash.pm +# - provides NBD+Squashfs-specific overrides of the OpenSLX::OSExport::ExportType API. +# +# (c) 2006 - OpenSLX.com +# +# Oliver Tappe <ot@openslx.com> +# +package OpenSLX::OSExport::ExportType::NBD_Squash; + +use vars qw(@ISA $VERSION); +@ISA = ('OpenSLX::OSExport::ExportType::Base'); +$VERSION = 1.01; # API-version . implementation-version + +use strict; +use Carp; +use File::Basename; +use OpenSLX::Basics; +use OpenSLX::OSExport::ExportType::Base 1.01; + +################################################################################ +### interface methods +################################################################################ +sub new +{ + my $class = shift; + my $self = { + 'name' => 'NBD_Squash', + }; + return bless $self, $class; +} + +sub exportVendorOS +{ + my $self = shift; + my $source = shift; + my $target = shift; + + # TODO: once the include/exclude-patch by Vito has been applied + # to mksquashfs, the extra route via rsync isn't necessary anymore: + my $mksquashfsCanFilter = 0; + if ($mksquashfsCanFilter) { + # do filtering as part of mksquashfs (needs additional mapping of + # our internal (rsync-)filter format to regexes): + my $includeExcludeList = $self->determineIncludeExcludeList(); + vlog 1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList); + $self->createSquashFS($source, $target, $includeExcludeList); + } else { + # do filtering via an rsync copy: + vlog 0, _tr("taking detour via rsync..."); + my $tmpTarget = "${target}_###RSYNC_TMP###"; + $self->copyViaRsync($source, $tmpTarget); + $self->createSquashFS($tmpTarget, $target); +# system("rm -r $tmpTarget"); + } + $self->showNbdParams($target); +} + +################################################################################ +### implementation methods +################################################################################ + +sub createSquashFS +{ + my $self = shift; + my $source = shift; + my $target = shift; + my $includeExcludeList = shift; + + system("rm -rf $target"); + # mksquasfs isn't significantly faster if fs already exists, but it + # causes the filesystem to grow somewhat, so we remove it in order to + # get the smallest FS-file possible. + if (system("mksquashfs $source $target -info")) { + die _tr("unable to create squashfs for source '%s into target '%s', giving up! (%s)", + $source, $target, $!); + } +} + +sub showNbdParams +{ + my $self = shift; + my $target = shift; + + print (('#' x 80)."\n"); + print _tr("Please make sure you start a corresponding nbd-server:\n\t%s\n", + "nbd-server -r $self->{engine}->{'export-path'}"); + print (('#' x 80)."\n"); +} + +1; diff --git a/installer/OpenSLX/OSExport/ExportType/NFS.pm b/installer/OpenSLX/OSExport/ExportType/NFS.pm index ac85b9c8..cfa90ced 100644 --- a/installer/OpenSLX/OSExport/ExportType/NFS.pm +++ b/installer/OpenSLX/OSExport/ExportType/NFS.pm @@ -30,66 +30,19 @@ sub new return bless $self, $class; } -sub initialize -{ - my $self = shift; - my $engine = shift; - - $self->SUPER::initialize($engine); -} - sub exportVendorOS { my $self = shift; my $source = shift; my $target = shift; - $self->exportViaRsync($source, $target); + $self->copyViaRsync($source, $target); $self->addTargetToNfsExports($target); } ################################################################################ ### implementation methods ################################################################################ - -sub exportViaRsync -{ - my $self = shift; - my $source = shift; - my $target = shift; - - if (system("mkdir -p $target")) { - die _tr("unable to create directory '%s', giving up! (%s)\n", - $target, $!); - } - my $includeExcludeList = $self->determineIncludeExcludeList(); - vlog 1, _tr("using include-exclude-filter:\n%s\n", $includeExcludeList); - open(RSYNC, "| rsync -av --delete --exclude-from=- $source/ $target") - or die _tr("unable to start rsync for source '%s', giving up! (%s)", - $source, $!); - print RSYNC $includeExcludeList; - if (!close(RSYNC)) { - die _tr("unable to export to target '%s', giving up! (%s)", - $target, $!); - } -} - -sub determineIncludeExcludeList -{ - my $self = shift; - - # Rsync uses a first match strategy, so we mix the local specifications - # in front of the filterset given by the package (as the local filters - # should always overrule the vendor filters): - my $distroName = $self->{engine}->{'distro-name'}; - my $localFilterFile = "../lib/distro-info/$distroName/export-filter.local"; - my $includeExcludeList = slurpFile($localFilterFile, 1); - $includeExcludeList .= $self->{engine}->{distro}->{'export-filter'}; - $includeExcludeList =~ s[^\s+][]igms; - # remove any leading whitespace, as rsync doesn't like it - return $includeExcludeList; -} - sub addTargetToNfsExports { my $self = shift; |
