From 1dd534f9534eeda713ba543170ba954e56a95c07 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 26 Aug 2007 21:30:50 +0000 Subject: [PATCH] Add support for the lback address in the configuration. Add --silent to vtag so it'll complain if run manually on a kernel without the necessary support. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2599 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- doc/configuration.xml | 8 ++++---- scripts/chbind | 10 ++++++++-- scripts/chcontext | 4 ++-- scripts/pkgmgmt | 12 ++++++------ scripts/vserver-build.fai | 2 +- scripts/vserver.functions | 25 +++++++++++++++---------- scripts/vserver.start | 6 +++--- scripts/vserver.stop | 4 ++-- scripts/vserver.suexec | 12 +++++++----- scripts/vsomething | 5 +++-- src/vtag.c | 18 +++++++++++++++--- 11 files changed, 66 insertions(+), 40 deletions(-) diff --git a/doc/configuration.xml b/doc/configuration.xml index 7367b9d..2890a49 100644 --- a/doc/configuration.xml +++ b/doc/configuration.xml @@ -1221,7 +1221,10 @@ The name of the current vserver. - The default broadcast address. + The guest's broadcast address. + + + The guest's loopback address. The default network device. See iface/dev for more information. @@ -1265,9 +1268,6 @@ numbers like '00' are good names for these directories. The IP address which will be assigned to this interface. - - The broadcast address. - The network device. When this is specified, the IP address will be assigned and removed when starting and stopping the guest. diff --git a/scripts/chbind b/scripts/chbind index 03836d8..2524644 100755 --- a/scripts/chbind +++ b/scripts/chbind @@ -29,7 +29,8 @@ function showHelp() { echo \ $"Usage: $1 [--silent] [--nid ] [--ip [/]] - [--bcast ] [--] * + [--lback ] [--bcast ] + [--] * --silent Do not print the addresses assigned. @@ -37,6 +38,8 @@ $"Usage: $1 [--silent] [--nid ] [--ip [/]] Network context id to use. --ip [/] IP address to bind to. +--lback + Loopback address for the network context. --bcast Broadcast address for the network context. @@ -57,7 +60,7 @@ the GNU General Public License. This program has absolutely no warranty." exit $1 } -tmp=$(getopt -o + --long ncap:,nid:,ip:,bcast:,disconnect,flag:,secure,silent,help,version -n "$0" -- "$@") || exit 1 +tmp=$(getopt -o + --long ncap:,nid:,ip:,bcast:,lback:,disconnect,flag:,secure,silent,help,version -n "$0" -- "$@") || exit 1 eval set -- "$tmp" OPT_CAPS=() @@ -67,6 +70,7 @@ OPT_FLAGS=() OPT_SECURE= OPT_SILENT= OPT_BCAST= +OPT_LBACK= OPT_IPS=() while true; do @@ -81,6 +85,7 @@ while true; do --silent) OPT_SILENT=1;; --ip) OPT_IPS=( "${OPT_IPS[@]}" --ip "$2" ); shift;; --bcast) OPT_BCAST=$2; shift;; + --lback) OPT_LBACK=$2; shift;; --) shift; break;; *) echo $"chbind: internal error; arg=='$1'" >&2; exit 1;; esac @@ -113,6 +118,7 @@ chain_cmd=( "${chain_cmd[@]}" $_NADDRESS --add ${OPT_SILENT:+--silent} ${OPT_BCAST:+--bcast "$OPT_BCAST"} + ${OPT_LBACK:+--lback "$OPT_LBACK"} "${OPT_IPS[@]}" ) migrate_cmd=( $_NCONTEXT diff --git a/scripts/chcontext b/scripts/chcontext index 39087c2..60df5fe 100755 --- a/scripts/chcontext +++ b/scripts/chcontext @@ -134,7 +134,7 @@ while true; do shift done -create_cmd=( ${OPT_CTX:+$_VTAG --create --tag "$OPT_CTX" --silentexist --} +create_cmd=( ${OPT_CTX:+$_VTAG --create --tag "$OPT_CTX" --silentexist --silent --} $_VCONTEXT --create --silentexist ${OPT_SILENT:+--silent} ${OPT_CTX:+--xid "$OPT_CTX"} ) @@ -173,6 +173,6 @@ else rc=254 fi -test "$rc" -ne 254 || exec "$_VTAG" --migrate --tag "$OPT_CTX" -- \ +test "$rc" -ne 254 || exec "$_VTAG" --migrate --tag "$OPT_CTX" --silent -- \ "${migrate_cmd[@]}" --xid "$OPT_CTX" --migrate -- "$@" exit $rc diff --git a/scripts/pkgmgmt b/scripts/pkgmgmt index 8a6e44e..d38c192 100755 --- a/scripts/pkgmgmt +++ b/scripts/pkgmgmt @@ -160,9 +160,9 @@ function _mountFilesystems() } test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$1" - _mountFilesystemsInternal "$cfgdir"/fstab || return 1 - _mountFilesystemsInternal "$cfgdir"/fstab.local || return 1 - _mountFilesystemsInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" || return 1 + _mountFilesystemsInternal "$cfgdir"/fstab || return 1 + _mountFilesystemsInternal "$cfgdir"/fstab.local || return 1 + _mountFilesystemsInternal "$cfgdir"/fstab.remote "${CHBIND_CMD[@]}" || return 1 } function _umountFilesystems() @@ -177,9 +177,9 @@ function _umountFilesystems() test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$1" pushd "$vdir/" >/dev/null || return 1 - _umountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" || is_ok= - _umountVserverInternal "$cfgdir"/fstab.local || is_ok= - _umountVserverInternal "$cfgdir"/fstab || is_ok= + _umountVserverInternal "$cfgdir"/fstab.remote "${CHBIND_CMD[@]}" || is_ok= + _umountVserverInternal "$cfgdir"/fstab.local || is_ok= + _umountVserverInternal "$cfgdir"/fstab || is_ok= popd >/dev/null || return 1 test -n "$is_ok" diff --git a/scripts/vserver-build.fai b/scripts/vserver-build.fai index b59951c..6e2333f 100644 --- a/scripts/vserver-build.fai +++ b/scripts/vserver-build.fai @@ -156,7 +156,7 @@ $_SECURE_MOUNT -n -o ro --bind "$FAI_DIR" /mnt/fai $_SECURE_MOUNT -n -t proc proc /mnt/proc cd /mnt -$_CHBIND "${CHBIND_OPTS[@]}" \ +"${CHBIND_CMD[@]}" \ $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \ $_VUNAME --xid self --set -t nodename="${SETUP_HOSTNAME:-fai-build}" \ -t context="$SETUP_CONFDIR" -- \ diff --git a/scripts/vserver.functions b/scripts/vserver.functions index 546cc6a..78d37e8 100644 --- a/scripts/vserver.functions +++ b/scripts/vserver.functions @@ -20,7 +20,7 @@ # $VSERVER_NAME ... name of vserver declare -a NICE_CMD=() -declare -a CHBIND_OPTS=() +declare -a CHBIND_CMD=() declare -a CAP_OPTS=() declare -a CHCONTEXT_INIT_OPTS=() declare -a CHCONTEXT_FLAG_OPTS=() @@ -96,23 +96,28 @@ function _generateChbindOptions local vdir="$1" local i local bcast= + local lback= local nid= test -n "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$vdir" - local f=$vdir/interfaces/bcast + local f="$vdir"/interfaces/bcast getFileValue bcast "$f" + f="$vdir"/interfaces/lback + getFileValue lback "$f" getFileValue nid "$vdir/ncontext" "$vdir/context" - CHBIND_OPTS=( $SILENT_OPT --secure ${nid:+--nid "$nid"} ${bcast:+--bcast "$bcast"} ) + CHBIND_CMD=( $_CHBIND $SILENT_OPT --secure ${nid:+--nid "$nid"} + ${bcast:+--bcast "$bcast"} ${lback:+--lback "$lback"} + ) for i in "${INTERFACES[@]}"; do - CHBIND_OPTS=( "${CHBIND_OPTS[@]}" --ip "$i" ) + CHBIND_CMD=( "${CHBIND_CMD[@]}" --ip "$i" ) done - _readFileToArray "$vdir"/nflags CHBIND_OPTS --flag - _readFileToArray "$vdir"/ncapabilities CHBIND_OPTS --ncap + _readFileToArray "$vdir"/nflags CHBIND_CMD --flag + _readFileToArray "$vdir"/ncapabilities CHBIND_CMD --ncap _HAVE_CHBIND_OPTIONS=1 } @@ -836,7 +841,7 @@ function mountVserver _mountVserverInternal "$cfgdir"/fstab _mountVserverInternal "$cfgdir"/fstab.local - _mountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" + _mountVserverInternal "$cfgdir"/fstab.remote "${CHBIND_CMD[@]}" isNamespaceCleanup "$cfgdir" && \ _namespaceCleanup "$cfgdir" @@ -879,9 +884,9 @@ function umountVserver test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" pushd "$vdir/" >/dev/null || return 1 - _umountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" || is_ok= - _umountVserverInternal "$cfgdir"/fstab.local || is_ok= - _umountVserverInternal "$cfgdir"/fstab || is_ok= + _umountVserverInternal "$cfgdir"/fstab.remote "${CHBIND_CMD[@]}" || is_ok= + _umountVserverInternal "$cfgdir"/fstab.local || is_ok= + _umountVserverInternal "$cfgdir"/fstab || is_ok= popd >/dev/null || return 1 test -n "$is_ok" diff --git a/scripts/vserver.start b/scripts/vserver.start index 63b02a9..a9b95c2 100644 --- a/scripts/vserver.start +++ b/scripts/vserver.start @@ -130,9 +130,9 @@ pushd "$VSERVER_DIR"/vdir/ >/dev/null is_configured=1 if $_VSERVER_INFO - FEATURE migrate; then ${NICE_CMD[@]} \ - $_CHBIND "${CHBIND_OPTS[@]}" -- \ + "${CHBIND_CMD[@]}" \ $_EXEC_ULIMIT "$VSERVER_DIR"/ulimits \ - $_VTAG --create "${OPTS_VTAG_CREATE[@]}" -- \ + $_VTAG --create "${OPTS_VTAG_CREATE[@]}" --silent -- \ $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \ ${OPTION_STRACE:+$_STRACE -fF -o /tmp/vserver-start.$$} \ ${USE_VNAMESPACE:+$_VNAMESPACE --set -- } \ @@ -156,7 +156,7 @@ else fi ${NICE_CMD[@]} \ - $_CHBIND "${CHBIND_OPTS[@]}" \ + "${CHBIND_CMD[@]}" \ $_EXEC_ULIMIT "$VSERVER_DIR/ulimits" \ $_CHCONTEXT_COMPAT "${CHCONTEXT_OPTS[@]}" "${CHCONTEXT_INIT_OPTS[@]}" \ $_SAVE_CTXINFO "$VSERVER_DIR" \ diff --git a/scripts/vserver.stop b/scripts/vserver.stop index cdbb139..5591307 100644 --- a/scripts/vserver.stop +++ b/scripts/vserver.stop @@ -71,8 +71,8 @@ if test -n "$_IS_FAKEINIT" && \ fi elif $_VSERVER_INFO - FEATURE migrate; then "${NICE_CMD[@]}" \ - "$_CHBIND" "${CHBIND_OPTS[@]}" \ - "$_VTAG" --migrate "${OPTS_VTAG_MIGRATE[@]}" -- \ + "${CHBIND_CMD[@]}" \ + "$_VTAG" --migrate "${OPTS_VTAG_MIGRATE[@]}" --silent -- \ $_VCONTEXT $SILENT_OPT --migrate --chroot --xid "$S_CONTEXT" -- \ "${INITCMD_STOP[@]}" || fail=1 else diff --git a/scripts/vserver.suexec b/scripts/vserver.suexec index 8b19f53..f249df3 100644 --- a/scripts/vserver.suexec +++ b/scripts/vserver.suexec @@ -34,18 +34,20 @@ test -z "$OPTION_NONAMESPACE" || USE_VNAMESPACE= if $_VSERVER_INFO - FEATURE migrate; then if test -z "$is_stopped"; then exec \ - $_CHBIND "${CHBIND_OPTS[@]}" \ + "${NICE_CMD[@]}" \ + "${CHBIND_CMD[@]}" \ $_EXEC_ULIMIT "$VSERVER_DIR/ulimits" \ ${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT" -- } \ - $_VTAG --migrate "${OPTS_VTAG_ENTER[@]}" -- \ + $_VTAG --migrate "${OPTS_VTAG_ENTER[@]}" --silent -- \ $_VCONTEXT $SILENT_OPT --migrate --chroot \ --xid "$S_CONTEXT" --uid "$user" "${OPTS_VCONTEXT_ENTER[@]}" -- \ "$@" else exec \ - $_CHBIND "${CHBIND_OPTS[@]}" \ + "${NICE_CMD[@]}" \ + "${CHBIND_CMD[@]}" \ $_EXEC_ULIMIT "$VSERVER_DIR/ulimits" \ - $_VTAG --migrate "${OPTS_VTAG_ENTER[@]}" -- \ + $_VTAG --create "${OPTS_VTAG_CREATE[@]}" --silent -- \ $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \ $_VUNAME --xid self --dir "$VSERVER_DIR"/uts --missingok -- \ $_VUNAME --xid self --set -t context="$VSERVER_DIR" -- \ @@ -55,7 +57,7 @@ if $_VSERVER_INFO - FEATURE migrate; then else exec \ "${NICE_CMD[@]}" \ - "$_CHBIND" "${CHBIND_OPTS[@]}" \ + "${CHBIND_CMD[@]}" \ "$_EXEC_ULIMIT" "$VSERVER_DIR/ulimits" \ ${USE_VNAMESPACE:+$_VNAMESPACE --enter "$S_CONTEXT" --} \ $_CHCONTEXT_COMPAT "${CHCONTEXT_OPTS[@]}" -- \ diff --git a/scripts/vsomething b/scripts/vsomething index 734f0b6..3ae3762 100755 --- a/scripts/vsomething +++ b/scripts/vsomething @@ -107,9 +107,10 @@ for i in "${vservers[@]}"; do $_VSERVER "$i" exec "$cmd" "$@" else _setVserverDir "$i" + # subshell so we don't have to clean up ( _generateChbindOptions "$VSERVER_DIR" - $_VSERVER "$i" status &> /dev/null && \ - CHBIND_CMD=( "$_CHBIND" "${CHBIND_OPTS[@]}" -- ) + $_VSERVER "$i" status &> /dev/null || \ + CHBIND_CMD=() callInNamespace "$i" \ "$_VNAMESPACE" --new -- \ "${CHBIND_CMD[@]}" \ diff --git a/src/vtag.c b/src/vtag.c index 3aa6cc4..edf9766 100644 --- a/src/vtag.c +++ b/src/vtag.c @@ -38,6 +38,7 @@ #define CMD_CREATE 0x4001 #define CMD_MIGRATE 0x4002 #define CMD_SILENTEXIST 0x4003 +#define CMD_SILENT 0x4004 struct option const @@ -47,6 +48,7 @@ CMDLINE_OPTIONS[] = { { "tag", required_argument, 0, CMD_TAG }, { "create", no_argument, 0, CMD_CREATE }, { "migrate", no_argument, 0, CMD_MIGRATE }, + { "silent", no_argument, 0, CMD_SILENT }, { "silentexist", no_argument, 0, CMD_SILENTEXIST }, { 0,0,0,0 }, }; @@ -72,6 +74,8 @@ showHelp(int fd, char const *cmd, int res) " can be:\n" " --silentexist ... be silent when context exists already; useful\n" " for '--create' only\n" + " --silent ... if the feature is not supported, just execute\n" + " \n" "\n" "'vtag --create' exits with code 254 iff the context exists already.\n" "\n" @@ -96,8 +100,15 @@ doit(struct Arguments const *args, char *argv[]) { tag_t tag; - if (!vc_isSupported(vcFEATURE_PPTAG)) - goto exec; + if (!vc_isSupported(vcFEATURE_PPTAG)) { + if (args->verbosity >= 1) { + errno = ENOSYS; + perror(ENSC_WRAPPERS_PREFIX); + return wrapper_exit_code; + } + else + goto exec; + } if (args->do_create) { tag = vc_tag_create(args->tag); @@ -139,7 +150,7 @@ int main (int argc, char *argv[]) while (1) { int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); if (c==-1) break; - + switch (c) { case CMD_HELP : showHelp(1, argv[0], 0); case CMD_VERSION : showVersion(); @@ -147,6 +158,7 @@ int main (int argc, char *argv[]) case CMD_MIGRATE : args.do_migrate = true; break; case CMD_SILENTEXIST : args.is_silentexist = true; break; case CMD_TAG : args.tag = Evc_tagopt2tag(optarg,true); break; + case CMD_SILENT : args.verbosity--; break; default : WRITE_MSG(2, "Try '"); -- 1.8.1.5