File build-vm-xen of Package build
#
# XEN specific functions
#
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
xen_set_xenid_xmcmd() {
XENID="${VM_ROOT%/root}"
XENID="${XENID%/tmpfs}"
XENID="${XENID##*/}"
XENID="${XENID#root_}"
XMCMD=xm
test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
}
vm_verify_options_xen() {
vm_kernel=/boot/vmlinuz
vm_initrd=/boot/initrd
test -e /boot/vmlinuz-xen && vm_kernel=/boot/vmlinuz-xen
test -e /boot/initrd-xen && vm_initrd=/boot/initrd-xen
test -n "$VM_KERNEL" && vm_kernel="$VM_KERNEL"
test -n "$VM_INITRD" && vm_initrd="$VM_INITRD"
if test ! -x /usr/sbin/xm -a -x /usr/sbin/xl ; then
VM_ROOTDEV=/dev/xvda
VM_SWAPDEV=/dev/xvdb
VM_CONSOLE=hvc0
else
VM_ROOTDEV=/dev/hda1
VM_SWAPDEV=/dev/hda2
VM_CONSOLE=ttyS0
fi
}
vm_startup_xen() {
xen_set_xenid_xmcmd
XMROOT="file:$(readlink -f $VM_ROOT)"
XMROOT=${XMROOT/#file:\/dev/phy:/dev}
XMROOT="disk=$XMROOT,${VM_ROOTDEV#/dev/},w"
XMSWAP=
if test -n "$VM_SWAP" ; then
XMSWAP="file:$(readlink -f $VM_SWAP)"
XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
XMSWAP="disk=$XMSWAP,${VM_SWAPDEV#/dev/},w"
fi
if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
echo "Instance already exists, something really went wrong..."
echo "Please report to your server admin, there might be multiple services running for same domain"
cleanup_and_exit 3
fi
XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
echo "memory = ${VM_MEMSIZE:-64}" >> $XEN_CONF_FILE
test -n "$BUILD_JOBS" && echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
echo "root = \"$VM_ROOTDEV ro\"" >> $XEN_CONF_FILE
echo "extra = \"init=/bin/bash console=$VM_CONSOLE panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
echo "on_poweroff = \"destroy\"" >> $XEN_CONF_FILE
echo "on_reboot = \"destroy\"" >> $XEN_CONF_FILE
echo "on_crash = \"destroy\"" >> $XEN_CONF_FILE
if test "$XMCMD" = xm ; then
set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="panic=1 quiet init="$vm_init_script" rd.driver.pre=binfmt_misc elevator=noop console=$VM_CONSOLE"
else
XLDISK=
XLDISK="\"${XMROOT#disk=}\""
test -n "$XMSWAP" && XLDISK="$XLDISK, \"${XMSWAP#disk=}\""
set -- xl create -c $XEN_CONF_FILE "$@" name="\"build_$XENID\"" "disk=[ $XLDISK ]" extra=\""$vm_linux_always_append init="$vm_init_script" rd.driver.pre=binfmt_misc $vm_linux_kernel_parameter console=$VM_CONSOLE"\"
fi
if test "$PERSONALITY" != 0 ; then
# have to switch back to PER_LINUX to make xm work
set -- linux64 "$@"
fi
echo "$@"
"$@" || cleanup_and_exit 3
rm -f "$XEN_CONF_FILE"
}
vm_kill_xen() {
xen_set_xenid_xmcmd
if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
if ! $XMCMD destroy "build_$XENID" ; then
cleanup_and_exit 1 "could not kill xen build $XENID"
fi
fi
}
# XEN only
vm_purge_xen() {
# this should not be needed, but sometimes a xen instance gets lost
xen_set_xenid_xmcmd
$XMCMD destroy "build_$XENID" >/dev/null 2>&1
}
vm_fixup_xen() {
:
}
vm_attach_root_xen() {
:
}
vm_attach_swap_xen() {
:
}
vm_detach_root_xen() {
:
}
vm_detach_swap_xen() {
:
}
vm_cleanup_xen() {
:
}
vm_sysrq_xen() {
:
}
vm_wipe_xen() {
:
}