ia64/xen-unstable

changeset 19209:67d9d2a4b988

xendomains: clean up output formatting

Show errors in the way they are coming from xm command only (no usage
is printed now). Watchdog_wm() has been changed for not showing dots
in the process of shutting down domains and if an error occurs it
prints target domain, operation (save/restore/migrate etc.) and reason
of failure in more user-friendly way.

Signed-off-by: Michal Novotny <minovotn@redhat.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Feb 13 09:32:02 2009 +0000 (2009-02-13)
parents e6f1c66874d5
children 766b3763ad1b
files tools/hotplug/Linux/init.d/xendomains
line diff
     1.1 --- a/tools/hotplug/Linux/init.d/xendomains	Fri Feb 13 09:29:52 2009 +0000
     1.2 +++ b/tools/hotplug/Linux/init.d/xendomains	Fri Feb 13 09:32:02 2009 +0000
     1.3 @@ -213,7 +213,7 @@ is_running()
     1.4  start() 
     1.5  {
     1.6      if [ -f $LOCKFILE ]; then 
     1.7 -	echo -n "xendomains already running (lockfile exists)"
     1.8 +	echo -e "xendomains already running (lockfile exists)"
     1.9  	return; 
    1.10      fi
    1.11  
    1.12 @@ -230,10 +230,12 @@ start()
    1.13                  HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
    1.14                  if [ $HEADER = "LinuxGuestRecord" ]; then
    1.15                      echo -n " ${dom##*/}"
    1.16 -                    xm restore $dom
    1.17 +                    XMR=`xm restore $dom 2>&1 1>/dev/null`
    1.18 +                    #xm restore $dom
    1.19                      if [ $? -ne 0 ]; then
    1.20 +                	echo -e "\nAn error occured while restoring domain ${dom##*/}:\n$XMR"
    1.21                          rc_failed $?
    1.22 -                        echo -n '!'
    1.23 +                        echo -e '!'
    1.24                      else
    1.25                          # mv $dom ${dom%/*}/.${dom##*/}
    1.26                          rm $dom
    1.27 @@ -241,7 +243,7 @@ start()
    1.28                  fi
    1.29              fi
    1.30          done
    1.31 -	echo .
    1.32 +	echo -e
    1.33      fi
    1.34  
    1.35      if contains_something "$XENDOMAINS_AUTO"
    1.36 @@ -264,16 +266,17 @@ start()
    1.37  	    if [ $? -eq 0 ] || is_running $dom; then
    1.38  		echo -n "(skip)"
    1.39  	    else
    1.40 -		xm create --quiet --defconfig $dom
    1.41 -		if [ $? -ne 0 ]; then
    1.42 +		XMC=`xm create --quiet --defconfig $dom`
    1.43 +            	if [ $? -ne 0 ]; then
    1.44 +                    echo -e "\nAn error occured while creating domain ${dom##*/}: $XMC\n"
    1.45  		    rc_failed $?
    1.46 -		    echo -n '!'
    1.47 +		    echo -e '!'
    1.48  		else
    1.49  		    usleep $XENDOMAINS_CREATE_USLEEP
    1.50  		fi
    1.51  	    fi
    1.52  	done
    1.53 -    fi	
    1.54 +    fi
    1.55  }
    1.56  
    1.57  all_zombies()
    1.58 @@ -293,18 +296,21 @@ all_zombies()
    1.59  # if it has not exited by that time kill it, so the init script will
    1.60  # succeed within a finite amount of time; if $2 is nonnull, it will
    1.61  # kill the command as well as soon as no domain (except for zombies)
    1.62 -# are left (used for shutdown --all).
    1.63 +# are left (used for shutdown --all). Third parameter, if any, suppresses
    1.64 +# output of dots per working state (formatting issues)
    1.65  watchdog_xm()
    1.66  {
    1.67      if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
    1.68  	exit
    1.69      fi
    1.70 +
    1.71      usleep 20000
    1.72      for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
    1.73  	# exit if xm save/migrate/shutdown is finished
    1.74  	PSAX=`ps axlw | grep "xm $1" | grep -v grep`
    1.75  	if test -z "$PSAX"; then exit; fi
    1.76 -	echo -n "."; sleep 1
    1.77 +	if ! test -n "$3"; then echo -n '.'; fi
    1.78 +	sleep 1
    1.79  	# go to kill immediately if there's only zombies left
    1.80  	if all_zombies && test -n "$2"; then break; fi
    1.81      done
    1.82 @@ -312,10 +318,14 @@ watchdog_xm()
    1.83      read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
    1.84      # kill xm $1
    1.85      kill $PSPID >/dev/null 2>&1
    1.86 +    
    1.87 +    echo -e .
    1.88  }
    1.89  
    1.90  stop()
    1.91  {
    1.92 +    exec 3>&2 2> /dev/null
    1.93 +    
    1.94      # Collect list of domains to shut down
    1.95      if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
    1.96  	rdnames
    1.97 @@ -333,7 +343,7 @@ stop()
    1.98  		    # nothing
    1.99  		    ;;
   1.100  		(*)
   1.101 -		    echo -n '(skip)'
   1.102 +		    echo -e '(skip)'
   1.103  		    continue
   1.104  		    ;;
   1.105  	    esac
   1.106 @@ -345,8 +355,9 @@ stop()
   1.107  	if test -n "$XENDOMAINS_SYSRQ"; then
   1.108  	    for sysrq in $XENDOMAINS_SYSRQ; do
   1.109  		echo -n "(SR-$sysrq)"
   1.110 -		xm sysrq $id $sysrq
   1.111 +		XMR=`xm sysrq $id $sysrq 2>&1 1>/dev/null`
   1.112  		if test $? -ne 0; then
   1.113 +                    echo -e "\nAn error occured while doing sysrq on domain:\n$XMR\n"
   1.114  		    rc_failed $?
   1.115  		    echo -n '!'
   1.116  		fi
   1.117 @@ -362,13 +373,18 @@ stop()
   1.118  	    echo -n "(migr)"
   1.119  	    watchdog_xm migrate &
   1.120  	    WDOG_PID=$!
   1.121 -	    xm migrate $id $XENDOMAINS_MIGRATE
   1.122 +	    XMR=`xm migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
   1.123  	    if test $? -ne 0; then
   1.124 +                echo -e "\nAn error occured while migrating domain:\n$XMR\n"
   1.125  		rc_failed $?
   1.126 -		echo -n '!'
   1.127 +		echo -e '!'
   1.128 +
   1.129  		kill $WDOG_PID >/dev/null 2>&1
   1.130  	    else
   1.131  		kill $WDOG_PID >/dev/null 2>&1
   1.132 +		
   1.133 +		echo -e .
   1.134 +		usleep 1000
   1.135  		continue
   1.136  	    fi
   1.137  	fi
   1.138 @@ -377,13 +393,16 @@ stop()
   1.139  	    watchdog_xm save &
   1.140  	    WDOG_PID=$!
   1.141  	    mkdir -p "$XENDOMAINS_SAVE"
   1.142 -	    xm save $id $XENDOMAINS_SAVE/$name
   1.143 +	    XMR=`xm save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
   1.144  	    if test $? -ne 0; then
   1.145 +                echo -e "\nAn error occured while saving domain:\n$XMR\n"
   1.146  		rc_failed $?
   1.147 -		echo -n '!'
   1.148 +		echo -e '!'
   1.149  		kill $WDOG_PID >/dev/null 2>&1
   1.150  	    else
   1.151  		kill $WDOG_PID >/dev/null 2>&1
   1.152 +		echo -e .
   1.153 +		usleep 1000
   1.154  		continue
   1.155  	    fi
   1.156  	fi
   1.157 @@ -392,10 +411,11 @@ stop()
   1.158  	    echo -n "(shut)"
   1.159  	    watchdog_xm shutdown &
   1.160  	    WDOG_PID=$!
   1.161 -	    xm shutdown $id $XENDOMAINS_SHUTDOWN
   1.162 +	    XMR=`xm shutdown $id $XENDOMAINS_SHUTDOWN 2>&1 1>/dev/null`
   1.163  	    if test $? -ne 0; then
   1.164 +                echo -e "\nAn error occured while shutting down domain:\n$XMR\n"
   1.165  		rc_failed $?
   1.166 -		echo -n '!'
   1.167 +		echo -e '!'
   1.168  	    fi
   1.169  	    kill $WDOG_PID >/dev/null 2>&1
   1.170  	fi
   1.171 @@ -408,18 +428,21 @@ stop()
   1.172      if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
   1.173  	# XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait"
   1.174  	echo -n " SHUTDOWN_ALL "
   1.175 -	watchdog_xm shutdown 1 &
   1.176 +	watchdog_xm shutdown 1 false &
   1.177  	WDOG_PID=$!
   1.178 -	xm shutdown $XENDOMAINS_SHUTDOWN_ALL
   1.179 +	XMR=`xm shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
   1.180  	if test $? -ne 0; then
   1.181 +            echo -e "\nAn error occured while shutting down all domains: $XMR\n"
   1.182  	    rc_failed $?
   1.183 -	    echo -n '!'
   1.184 +	    echo -e '!'
   1.185  	fi
   1.186  	kill $WDOG_PID >/dev/null 2>&1
   1.187      fi
   1.188  
   1.189      # Unconditionally delete lock file
   1.190      rm -f $LOCKFILE
   1.191 +    
   1.192 +    exec 2>&3
   1.193  }
   1.194  
   1.195  check_domain_up()