X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Fvserver.functions;h=6bb9058defb7435a19774c1ebad6536c80dca516;hb=75385100bedf6d457e88bc2bb942a6f0771b0e06;hp=73558eedee4d3c3e1d1f1ab4bbafbcf01b9bd44f;hpb=da726e51c48ee9c70352bca04b3b5ee0867e5c4f;p=util-vserver.git diff --git a/util-vserver/scripts/vserver.functions b/util-vserver/scripts/vserver.functions index 73558ee..6bb9058 100644 --- a/util-vserver/scripts/vserver.functions +++ b/util-vserver/scripts/vserver.functions @@ -77,13 +77,16 @@ function _generateChbindOptions local vdir="$1" local i local bcast= + local nid= test -n "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$vdir" local f=$vdir/interfaces/bcast getFileValue bcast "$f" + + getFileValue nid "$vdir/ncontext" "$vdir/context" - CHBIND_OPTS=( $SILENT_OPT ${bcast:+--bcast "$bcast"} ) + CHBIND_OPTS=( $SILENT_OPT ${nid:+--nid "$nid"} ${bcast:+--bcast "$bcast"} ) for i in "${INTERFACES[@]}"; do CHBIND_OPTS=( "${CHBIND_OPTS[@]}" --ip "$i" ) @@ -140,7 +143,7 @@ function _generateCCapabilityOptions test -e "$f" || return 0 while read cap; do case x"$cap" in - (x|x\#) ;; + (x|x\#*) ;; (*) OPTS_VATTRIBUTE=( "${OPTS_VATTRIBUTE[@]}" --ccap "$cap" );; esac done <"$f" @@ -155,7 +158,7 @@ function _generateBCapabilityOptions test -e "$f" || return 0 while read cap; do case x"$cap" in - (x|x\#) ;; + (x|x\#*) ;; (*) OPTS_VATTRIBUTE=( "${OPTS_VATTRIBUTE[@]}" --bcap "$cap" );; esac done <"$f" @@ -176,7 +179,7 @@ function _generateCapabilityOptions while read cap; do case x"$cap" in - (x|x\#) ;; + (x|x\#*) ;; (!CAP_SYSCHROOT) CAP_OPTS=( "${CAP_OPTS[@]}" --cap "$cap" ) CAPCHROOT_OPTS=( "${CAPCHROOT_OPTS[@]}" --nochroot ) @@ -294,8 +297,7 @@ function _generateInitOptions ;; (x) ;; - (*) echo "Unknown init-style '$INITSTYLE'; aborting" >&2; - exit 1;; + (*) panic "Unknown init-style '$INITSTYLE'; aborting";; esac if test x"$INITSTYLE" != xrescue; then @@ -328,7 +330,7 @@ function _generateFlagOptions test ! -e "$vdir"/flags || \ while read flag; do case x"$flag" in - (x|x\#) ;; + (x|x\#*) ;; (xnamespace) ;; (xfakeinit) _IS_FAKEINIT=1 @@ -377,7 +379,7 @@ function _generateChcontextOptions OPTS_VCONTEXT_CREATE=( $SILENT_OPT \ ${ctx:+--xid "$ctx"} ) ## put '--secure' at front so that it can be overridden - OPTS_VATTRIBUTE=( --secure "${OPTS_VATTRIBUTE[@]}" ) + OPTS_VATTRIBUTE=( --secure --flag default "${OPTS_VATTRIBUTE[@]}" ) } function _generateScheduleOptions @@ -455,6 +457,29 @@ function _generateMac eval $1=$(printf "f0:ff:%02x:%02x:%02x:%02x" $[ (~($2>>8)) & 0xff ] $[ ($2 & 0xff) ] $[ ($3>>8) & 0xff ] $[ $3 & 0xff ]) } +function _getVLANInfo +{ + case "$1" in + (vlan????) + panic "\ +creation of VLAN_PLUS_VID devices is not supported; please create them +before starting the vserver and use the 'nodev' flag then" + echo "$1 vlan ${1##vlan} VLAN_PLUS_VID" + ;; + (vlan*) + panic "\ +creation of VLAN_PLUS_VID_NO_PAD devices is not supported; please +create them before starting the vserver and use the 'nodev' flag then" + echo "$1 vlan ${1##vlan} VLAN_PLUS_VID_N0_PAD" + ;; + (*.????) echo "$1 ${1%%.*} ${1##*.} DEV_PLUS_VID";; + (*.*) echo "$1 ${1%%.*} ${1##*.} DEV_PLUS_VID_NO_PAD";; + (*) return 1 + esac + + return 0 +} + ## Usage: _processSingleInterface function _processSingleInterface { @@ -497,19 +522,16 @@ function _processSingleInterface ## LEGACY ALERT test ! -e "$iface"/only_ip || break - case "$dev" in - (*.*) - test -d /proc/net/vlan || { - echo -e $"VLAN device-name used, but vlan subsystem not enabled.\nTry to execute 'modprobe 8021q' before starting the vservers" >&2 - return 1 - } - test -f /proc/net/vlan || { - _addInterfaceCmd VCONFIG ${dev/./ } - _addInterfaceCmd IP_ADDR 127.0.0.1/8 broadcast 127.255.255.255 dev "$dev" - _addInterfaceCmd IP_LINK "$dev" $up - } - ;; - esac + local vlan_info + if vlan_info=$(_getVLANInfo "$dev"); then + test -d /proc/net/vlan || { + echo -e $"VLAN device-name used, but vlan subsystem not enabled.\nTry to execute 'modprobe 8021q' before starting the vservers" >&2 + return 1 + } + test -f /proc/net/vlan -o -e "$iface"/novlandev || { + _addInterfaceCmd VCONFIG $vlan_info + } + fi if ! test -e "$iface"/indirect; then _addInterfaceCmd IP_ADDR "$ip${prefix:+/$prefix}" broadcast ${bcast:-+} ${name:+label "$dev:$name"} dev "$dev" @@ -569,8 +591,9 @@ function enableInterfaces shift 2 $_MODPROBE ${name:+-o "$name"} "$mod" "$@" ;; - NAMEIF) $_NAMEIF "$@";; - VCONFIG) $_VCONFIG add "$@";; + NAMEIF) $_NAMEIF "$@";; + VCONFIG) $_VCONFIG set_name_type "$4" >/dev/null + $_VCONFIG add "$2" "$3" >/dev/null;; IP_ADDR) $_IP addr add "$@";; IP_ADDR_FLUSH) $_IP addr flush "$@";; IP_LINK) $_IP link set "$@";; @@ -605,7 +628,7 @@ function disableInterfaces IPTABLES) ;; ## TODO MODPROBE) $_RMMOD "${2:-$1}";; NAMEIF) ;; - VCONFIG) $_VCONFIG rem "$@";; + VCONFIG) $_VCONFIG rem "$2.$3" >/dev/null;; IP_ADDR) $_IP addr del "$@";; IP_ADDR_FLUSH) ;; IP_LINK) ;; ## Ignore the link-down command for now @@ -787,23 +810,36 @@ function initWait if $_VSERVER_INFO - FEATURE vwait; then local _is_tmpdir _is_tmpdir=$($_MKTEMPDIR /tmp/vwaitstat.XXXXXX) - - $_NOHUP $_VWAIT --timeout "$VSHELPER_SYNC_TIMEOUT" \ - --terminate --status-fd 3 "$2" \ - >>$_is_tmpdir/out 2>$_is_tmpdir/err 3>$_is_tmpdir/fifo & + ( + $_VWAIT --timeout "$VSHELPER_SYNC_TIMEOUT" \ + --status-fd 3 "$2" \ + >>$_is_tmpdir/out 2>$_is_tmpdir/err 3>$_is_tmpdir/fifo + rc=$? + + if test "$rc" -ne 0 -a "$rc" -ne 1; then + $_VPS axf | $_EGREP -e "^[^ \t]+[ \t]+$S_CONTEXT[ \t]+" >&4 + killContext "$S_CONTEXT" 9 + fi + + exit $rc + ) 4>$_is_tmpdir/procs & + echo "$!" >$_is_tmpdir/pid eval "$3"=$_is_tmpdir - fi + fi +## Usage: _waitForVWait function _waitForVWait { + wait "$3" || : + declare -a status - wait "$2" || : - getFileArray status "$1" + declare -r procs=$(cat $4) + + getFileArray status "$2" set -- ${status[0]} case "$1" in @@ -817,10 +853,21 @@ A timeout occured while waiting for the vserver to finish and it was killed by sending a SIGKILL signal. Please investigate the reasons and/or increase the timeout in apps/vshelper/sync-timeout." ;; - (TIMEOUT|\?\?\?|*) warning $"\ + + (TIMEOUT) warning $"\ +A timeout occured while waiting for the vserver to finish and it will +be killed by sending a SIGKILL signal. The following process list +might be useful for finding out the reason of this behavior: + +---------------------------------------------------------------------- +${procs:+$procs +}----------------------------------------------------------------------" + ;; + + (\?\?\?|*) warning $"\ internal error: 'vwait' exited with an unexpected status '$1'; I will try to continue but be prepared for unexpected events." - ;; + ;; esac return 0 @@ -835,7 +882,7 @@ function waitForSync local vwait_pid=$4 if test -d "$vwait_statdir"; then - _waitForVWait "$vwait_statdir/fifo" "$( <$vwait_statdir/pid )" + _waitForVWait "$cfgdir" "$vwait_statdir/fifo" "$( <$vwait_statdir/pid )" "$vwait_statdir/procs" elif test -n "$_NEED_VSHELPER_SYNC"; then $_VSHELPER_SYNC "$fifo" "$VSHELPER_SYNC_TIMEOUT" || \ warning $"\ @@ -919,7 +966,7 @@ WARNING: The 'only_ip' flag for interface '$iface' is deprecated; use 'nodev' instead of" fi done - + find "$cfgdir" -type f -exec "$_CHECK_UNIXFILE" '{}' ';' vshelper.doSanityCheck @@ -933,3 +980,92 @@ WARNING: The 'only_ip' flag for interface '$iface' is deprecated; use procfs-security. Please read the FAQ for more details http://www.linux-vserver.org/index.php?page=Linux-Vserver+FAQ" } + + +function _setSingleDiskLimit +{ + local vdir=$1 + local dlimit=$2 + local space_used= + local space_total= + local inodes_used= + local inodes_total= + local reserved= + local directory= + local ctx= + + getFileValue ctx "$vdir/context" + getFileValue directory "$dlimit/directory" || return 0 + getFileValue space_total "$dlimit/space_total" || return 0 + getFileValue inodes_total "$dlimit/inodes_total" || return 0 + getFileValue reserved "$dlimit/reserved" || return 0 + + local cachename=`echo "$ctx$directory" | $_SED 's!/!_!g'` + + test -e "$vdir/cache/$cachename" && . "$vdir/cache/$cachename" + # Remove the cache so if the machine goes down unexpectedly, we won't have a stale cache + $_RM -f "$vdir/cache/$cachename" + + if test -z "$inodes_used" -o -z "$space_used"; then + space_used=` $_VDU --xid $ctx --space --script "$directory"` + inodes_used=`$_VDU --xid $ctx --inodes --script "$directory"` + fi + + $_VDLIMIT --xid $ctx \ + --set space_used=$space_used \ + --set space_total=$space_total \ + --set inodes_used=$inodes_used \ + --set inodes_total=$inodes_total \ + --set reserved=$reserved \ + "$directory" +} + + +function setDiskLimits +{ + local vdir=$1 + local dlimit + + # Disk Limits without a static context are useless + test -e "$vdir"/context || return 0 + + for dlimit in "$vdir/dlimits/"*; do + test -d "$dlimit" || continue + test ! -e "$dlimit/disabled" || continue + + _setSingleDiskLimit "$vdir" "$dlimit" + done +} + + +function _saveSingleDiskLimit +{ + local vdir=$1 + local dlimit=$2 + local ctx= + local directory= + + getFileValue ctx "$vdir/context" + getFileValue directory "$dlimit/directory" || return 0 + + local cachename=`echo "$ctx$directory" | $_SED 's!/!_!g'` + + $_VDLIMIT --xid $ctx "$directory" | \ + $_GREP '_used=' > "$vdir/cache/$cachename" +} + + +function saveDiskLimits +{ + local vdir=$1 + local dlimit + + test -e "$vdir"/context || return 0 + + for dlimit in "$vdir/dlimits/"*; do + test -d "$dlimit" || continue + test ! -e "$dlimit/disabled" || continue + + _saveSingleDiskLimit "$vdir" "$dlimit" + done +}