From 07a3904f8220fbc4d12d85fb45bc44eeefc3d6ae Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Thu, 19 Oct 2006 15:09:47 +0000 Subject: [PATCH] Improve namespace cleanup to make sure some required directories stick around, and add some configuration options to exclude further paths. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2357 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- doc/configuration.xml | 14 ++++++++++++++ scripts/vserver.functions | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/doc/configuration.xml b/doc/configuration.xml index ed75590..1c34a85 100644 --- a/doc/configuration.xml +++ b/doc/configuration.xml @@ -45,6 +45,12 @@ there. + + +List of paths to skip during namespace cleanup. + + + Path of the vserver run reverse directory. This directory contains @@ -381,6 +387,14 @@ Enable namespace cleanup for the current vserver. + + +List of paths to skip during namespace cleanup. This overrides the +global namespace-cleanup-skip +file. + + + [experimental; name is subject of possible change] Contains the diff --git a/scripts/vserver.functions b/scripts/vserver.functions index 2c02276..cd0cccd 100644 --- a/scripts/vserver.functions +++ b/scripts/vserver.functions @@ -805,7 +805,7 @@ function mountVserver _mountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" isNamespaceCleanup "$cfgdir" && \ - _namespaceCleanup + _namespaceCleanup "$cfgdir" isAvoidNamespace "$cfgdir" || \ $_SECURE_MOUNT --rbind -n "$vdir" "/" @@ -1161,26 +1161,39 @@ function saveDiskLimits function _namespaceCleanup { - local root=$(readlink -f "$vdir") - local tmp="$root" + local vdir="$1" + local root=$($_VSERVER_INFO "$1" VDIR 1) local -a list - while [ "$tmp" ]; do - list=( "${list[@]}" "$tmp" ) - tmp="${tmp%/*}" + local -a skip + local tmp + + getFileArray skip "$vdir"/namespace-cleanup-skip \ + "$__CONFDIR"/.defaults/namespace-cleanup-skip || : + + # these are things that have to be accessible post-cleanup + for tmp in "$root" "$__SBINDIR" "$__PKGLIBDIR" "$vdir" \ + "$__PKGSTATEDIR" "${skip[@]}"; do + while test -n "$tmp"; do + list=( "${list[@]}" "$tmp" ) + tmp="${tmp%/*}" + done done + local -a list_umount while read dev path opts; do - [ "$path" ] || continue - for i in "$root" /dev /proc; do - [ "${path#$i}" != "$path" ] && continue 2 - done - for i in "${list[@]}" /; do - [ "$path" = "$i" ] && continue 2 - done - list_umount=( "${list_umount[@]}" "$path" ) + test -n "$path" || continue + for i in "$root" /dev /proc; do + test "${path#$i}" != "$path" && continue 2 + done + for i in "${list[@]}" /; do + test "$path" = "$i" && continue 2 + done + # unmount them in reverse order so mounts further down the tree get unmounted first + list_umount=( "$path" "${list_umount[@]}" ) done < /proc/mounts + # separate loop to avoid races while reading /proc/mounts for i in "${list_umount[@]}"; do - umount -l -n "$i" + $_UMOUNT -l -n "$i" done } -- 1.8.1.5