From 8475a6c9dd8ad9e6f079e1df6bb82e8170f12aa2 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 17 Jul 2008 20:12:56 +0000 Subject: * fixed bad bug that would cause removal of vendor-OS if the export was faked by bind-mounting to the vendor-OS. Now we simply give the same warning as when faking the export and skip the actuall removal. git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1933 95ad53e4-c205-0410-b2fa-d234c58c8868 --- installer/OpenSLX/OSExport/FileSystem/NFS.pm | 83 +++++++++++++++++----------- 1 file changed, 52 insertions(+), 31 deletions(-) (limited to 'installer/OpenSLX/OSExport/FileSystem/NFS.pm') diff --git a/installer/OpenSLX/OSExport/FileSystem/NFS.pm b/installer/OpenSLX/OSExport/FileSystem/NFS.pm index b114348d..e034b127 100644 --- a/installer/OpenSLX/OSExport/FileSystem/NFS.pm +++ b/installer/OpenSLX/OSExport/FileSystem/NFS.pm @@ -52,37 +52,12 @@ sub exportVendorOS my $source = shift; my $target = $self->{'export-path'}; - - # For development purposes, it is very desirable to be able to take a - # shortcut that avoids doing the actual copying of the folders (as that - # takes a considerable amount of time). - # In order to support this, we explicitly check if the OpenSLX NFS export - # root folder (/srv/openslx/export/nfs) is a bind-mount of the OpenSLX - # stage1 folder (/var/opt/openslx/stage1). - # If that is the case, we print a notice and skip the rsync step (which - # wouldn't work anyway, as source and target folder are the same). - my $stage1Root = dirname($source); - my $nfsRoot = dirname($target); - chomp(my $canonicalStage1Root = qx{readlink -f $stage1Root} || $stage1Root); - chomp(my $canonicalNFSRoot = qx{readlink -f $nfsRoot} || $nfsRoot); - my @mounts = slurpFile('/etc/mtab'); - for my $mount (@mounts) { - if ($mount =~ m{ - ^ - $canonicalStage1Root # mount source - \s+ - $canonicalNFSRoot # mount target - \s+ - none # filesystem for bind mounts is 'none' - \s+ - \S*\bbind\b\S* # look for bind mounts only - }gmsx) { - warn _tr( - "%s is a bind-mount to vendor-OS root - rsync step is skipped!", - $target - ); - return; - } + if ($self->_isTargetBindMounted($source, $target)) { + warn _tr( + "%s is a bind-mount to vendor-OS root - rsync step is skipped!", + $target + ); + return; } $self->_copyViaRsync($source, $target); @@ -94,7 +69,16 @@ sub purgeExport { my $self = shift; + my $source = $self->{'engine'}->{'vendor-os-path'}; my $target = $self->{'export-path'}; + if ($self->_isTargetBindMounted($source, $target)) { + warn _tr( + "%s is a bind-mount to vendor-OS root - removal step is skipped!", + $target + ); + return; + } + if (system("rm -r $target")) { vlog(0, _tr("unable to remove export '%s'!", $target)); return 0; @@ -214,4 +198,41 @@ sub _determineIncludeExcludeList return $includeExcludeList; } +sub _isTargetBindMounted +{ + my $self = shift; + my $source = shift; + my $target = shift; + + # For development purposes, it is very desirable to be able to take a + # shortcut that avoids doing the actual copying of the folders (as that + # takes a considerable amount of time). + # In order to support this, we explicitly check if the OpenSLX NFS export + # root folder (/srv/openslx/export/nfs) is a bind-mount of the OpenSLX + # stage1 folder (/var/opt/openslx/stage1). + # If that is the case, we print a notice and skip the rsync step (which + # wouldn't work anyway, as source and target folder are the same). + my $stage1Root = dirname($source); + my $nfsRoot = dirname($target); + chomp(my $canonicalStage1Root = qx{readlink -f $stage1Root} || $stage1Root); + chomp(my $canonicalNFSRoot = qx{readlink -f $nfsRoot} || $nfsRoot); + my @mounts = slurpFile('/etc/mtab'); + for my $mount (@mounts) { + if ($mount =~ m{ + ^ + $canonicalStage1Root # mount source + \s+ + $canonicalNFSRoot # mount target + \s+ + none # filesystem for bind mounts is 'none' + \s+ + \S*\bbind\b\S* # look for bind mounts only + }gmsx) { + return 1; + } + } + return 0; +} + + 1; -- cgit v1.2.3-55-g7522