summaryrefslogtreecommitdiffstats
path: root/installer/OpenSLX/OSExport/ExportType/NBD_Squash.pm
blob: 41bb9bb978b97d7c990480041361ae963a6be6b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright (c) 2006, 2007 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# NBD_Squash.pm
#	- provides NBD+Squashfs-specific overrides of the OpenSLX::OSExport::ExportType API.
# -----------------------------------------------------------------------------
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;