[Pkg-xen-devel] [PATCH 8/9] debian/scripts: Optimize runtime scripts

Hans van Kranenburg hans at knorrie.org
Tue Dec 1 23:03:50 GMT 2020


Hi,

On 9/21/20 6:28 AM, Elliott Mitchell wrote:
> Fewer fork()s and execve()s quickly add up to significant savings.  I'm
> concerned Debian is slowly headed towards recreating SunOS^WSolaris
> 5.7^W2.7^W7 and the layers and layers of scripts which killed
> performance.
> 
> As these runtime scripts are heavily used, avoid all uses of external
> programs by them.

I like this, thanks for taking the time to work on this.

In 'normal life' I try to avoid using shell scripting for everything
that is not really trivial, so I'm not a fluent reader/writer of it, and
it's a bit harder to process and review.

So, I will need to find some time to fiddle around with this, and figure
out which new things you just caused me to learn about by figuring out
what's going on in this change. And that's not a bad thing. :)

> Signed-off-by: Elliott Mitchell <ehem+debian at m5p.com>
> ---
>  debian/scripts/xen-utils-wrapper | 43 +++++++++++++++++++++++++++++---
>  debian/scripts/xen-version       |  6 +++--
>  2 files changed, 43 insertions(+), 6 deletions(-)
> 
> diff --git a/debian/scripts/xen-utils-wrapper b/debian/scripts/xen-utils-wrapper
> index 4d27a62d33..6247fd0b29 100755
> --- a/debian/scripts/xen-utils-wrapper
> +++ b/debian/scripts/xen-utils-wrapper
> @@ -1,6 +1,41 @@
> -#!/bin/sh -e
> +#!/bin/sh
>  
> -COMMAND="$(basename $0)"
> -DIR=$(/usr/lib/xen-common/bin/xen-dir)
> +# This portion is fast-path, avoid external programs, NOTE: NOT -e HERE!
> +
> +COMMAND="${0##*/}"
> +
> +DIR=/sys/hypervisor/version
> +# these return non-zero if hypervisor is absent, this is detected below
> +read major 2> /dev/null < $DIR/major
> +read minor 2> /dev/null < $DIR/minor
> +VERSION="$major.$minor"
> +
> +DIR="/usr/lib/xen-$VERSION/bin"
> +
> +[ -x "$DIR/$COMMAND" ] && exec "$DIR/$COMMAND" "$@"
> +
> +
> +# Certainly didn't work, now report failures, slower-path
> +set -e
> +
> +error() {
> +	err="$1"
> +	shift
> +	echo "ERROR: " "$@" >&2
> +	exit $err
> +}
> +
> +[ -e "/sys/hypervisor/type" ] || error 1 "Can't find hypervisor information in sysfs!"
> +
> +read type < /sys/hypervisor/type
> +if [ "$type" != xen ]; then
> +	[ -n "$type" ] || error 1 "Can't read hypervisor type from sysfs!"
> +	error 1 "Hypervisor is not xen but '$type'!"
> +fi
> +
> +if [ ! -d "/usr/lib/xen-$VERSION" ]; then
> +	error 127 "Can't find version $VERSION of xen utils (maybe xen-utils-$VERSION was already removed before rebooting out of Xen $VERSION), bailing out!"
> +fi
> +
> +error 127 "Unable to execute $DIR/$COMMAND"
>  
> -exec "$DIR/bin/$COMMAND" "$@"
> diff --git a/debian/scripts/xen-version b/debian/scripts/xen-version
> index 492070a43b..5c42ad7351 100755
> --- a/debian/scripts/xen-version
> +++ b/debian/scripts/xen-version
> @@ -6,10 +6,12 @@ error() {
>  }
>  
>  if [ -e "/sys/hypervisor/type" ]; then
> -    type="$(cat /sys/hypervisor/type)"
> +    read type < /sys/hypervisor/type
>      if [ "$type" = xen ]; then
>          DIR=/sys/hypervisor/version
> -        VERSION="$(cat $DIR/major).$(cat $DIR/minor)"
> +        read major < $DIR/major
> +        read minor < $DIR/minor
> +        VERSION="$major.$minor"
>      elif [ -z "$type" ]; then
>          error "Can't read hypervisor type from sysfs!"
>      else
> 

Thanks,
Hans



More information about the Pkg-xen-devel mailing list