Merge remote-tracking branch 'origin/devel'
[tools/build.git] / build-vm-xen
1 #
2 # XEN specific functions
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #
22 ################################################################
23
24 vm_verify_options_xen() {
25     vm_kernel=/boot/vmlinuz
26     vm_initrd=/boot/initrd
27     test -e /boot/vmlinuz-xen && vm_kernel=/boot/vmlinuz-xen
28     test -e /boot/initrd-xen && vm_initrd=/boot/initrd-xen
29     test -n "$VM_KERNEL" && vm_kernel="$VM_KERNEL"
30     test -n "$VM_INITRD" && vm_initrd="$VM_INITRD"
31 }
32
33 vm_startup_xen() {
34     XMCMD=xm
35     test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
36     XMROOT="file:$(readlink -f $VM_IMAGE)"
37     XMROOT=${XMROOT/#file:\/dev/phy:/dev}
38     XMROOT="disk=$XMROOT,hda1,w"
39     XMSWAP=
40     if test -n "$VM_SWAP" ; then
41         XMSWAP="file:$(readlink -f $VM_SWAP)"
42         XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
43         XMSWAP="disk=$XMSWAP,hda2,w"
44     fi
45     XENID="${VM_IMAGE%/root}"
46     XENID="${XENID%/tmpfs}"
47     XENID="${XENID##*/}"
48     XENID="${XENID#root_}"
49
50     if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
51        echo "Instance already exists, something really went wrong..."
52        echo "Please report to your server admin, there might be multiple services running for same domain"
53        cleanup_and_exit 3
54     fi
55     XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
56     
57     echo "kernel = \"$vm_kernel\""                                           >  $XEN_CONF_FILE
58     echo "ramdisk = \"$vm_initrd\""                                          >> $XEN_CONF_FILE
59     echo "memory = ${VM_MEMSIZE:-64}"                                        >> $XEN_CONF_FILE
60     test -n "$BUILD_JOBS" && echo "vcpus = $BUILD_JOBS"                      >> $XEN_CONF_FILE
61     echo "root = \"/dev/hda1 ro\""                                           >> $XEN_CONF_FILE
62     echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
63     echo "on_poweroff = \"destroy\""                                         >> $XEN_CONF_FILE
64     echo "on_reboot = \"destroy\""                                           >> $XEN_CONF_FILE
65     echo "on_crash = \"destroy\""                                            >> $XEN_CONF_FILE
66     if test "$XMCMD" = xm ; then
67         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=ttyS0"
68     else
69         XLDISK=
70         XLDISK="\"${XMROOT#disk=}\""
71         test -n "$XMSWAP" && XLDISK="$XLDISK, \"${XMSWAP#disk=}\""
72         set -- xl create -c $XEN_CONF_FILE name="\"build_$XENID\"" "disk=[ $XLDISK ]" extra=\""panic=1 quiet init="$vm_init_script" rd.driver.pre=binfmt_misc elevator=noop console=ttyS0"\"
73     fi
74     if test "$PERSONALITY" != 0 ; then
75         # have to switch back to PER_LINUX to make xm work
76         set -- linux64 "$@"
77     fi
78     echo "$@"
79     "$@" || cleanup_and_exit 3
80     rm -f "$XEN_CONF_FILE"
81 }
82
83 vm_kill_xen() {
84     XMCMD=xm
85     test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
86     XENID="${VM_IMAGE%/root}"
87     XENID="${XENID%/tmpfs}"
88     XENID="${XENID##*/}"
89     XENID="${XENID#root_}"
90     if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then 
91         if ! $XMCMD destroy "build_$XENID" ; then 
92             echo "could not kill xen build $XENID"
93             cleanup_and_exit 1
94         fi
95     fi
96 }
97
98 # XEN only
99 vm_purge_xen() {
100     # this should not be needed, but sometimes a xen instance gets lost
101     XMCMD=xm
102     test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
103     XENID="${VM_IMAGE%/root}"
104     XENID="${XENID%/tmpfs}"
105     XENID="${XENID##*/}"
106     XENID="${XENID#root_}"
107     $XMCMD destroy "build_$XENID" >/dev/null 2>&1
108 }
109
110 vm_fixup_xen() {
111     :
112 }
113
114 vm_attach_root_xen() {
115     :
116 }
117
118 vm_attach_swap_xen() {
119     :
120 }
121
122 vm_detach_root_xen() {
123     :
124 }
125
126 vm_detach_swap_xen() {
127     :
128 }
129
130 vm_cleanup_xen() {
131     :
132 }
133