Debian Codegraph @

build-vm-xen

raw
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 xen_set_xenid_xmcmd() {
25 XENID="${VM_ROOT%/root}"
26 XENID="${XENID%/tmpfs}"
27 XENID="${XENID##*/}"
28 XENID="${XENID#root_}"
29 XMCMD=xm
30 test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
31 }
32
33 vm_verify_options_xen() {
34 vm_kernel=/boot/vmlinuz
35 vm_initrd=/boot/initrd
36 test -e /boot/vmlinuz-xen && vm_kernel=/boot/vmlinuz-xen
37 test -e /boot/initrd-xen && vm_initrd=/boot/initrd-xen
38 test -n "$VM_KERNEL" && vm_kernel="$VM_KERNEL"
39 test -n "$VM_INITRD" && vm_initrd="$VM_INITRD"
40 if test ! -x /usr/sbin/xm -a -x /usr/sbin/xl ; then
41 VM_ROOTDEV=/dev/xvda
42 VM_SWAPDEV=/dev/xvdb
43 VM_CONSOLE=hvc0
44 else
45 VM_ROOTDEV=/dev/hda1
46 VM_SWAPDEV=/dev/hda2
47 VM_CONSOLE=ttyS0
48 fi
49 }
50
51 vm_startup_xen() {
52 xen_set_xenid_xmcmd
53 XMROOT="file:$(readlink -f $VM_ROOT)"
54 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
55 XMROOT="disk=$XMROOT,${VM_ROOTDEV#/dev/},w"
56 XMSWAP=
57 if test -n "$VM_SWAP" ; then
58 XMSWAP="file:$(readlink -f $VM_SWAP)"
59 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
60 XMSWAP="disk=$XMSWAP,${VM_SWAPDEV#/dev/},w"
61 fi
62
63 if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
64 echo "Instance already exists, something really went wrong..."
65 echo "Please report to your server admin, there might be multiple services running for same domain"
66 cleanup_and_exit 3
67 fi
68 XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
69
70 echo "kernel = \"$vm_kernel\"" > $XEN_CONF_FILE
71 echo "ramdisk = \"$vm_initrd\"" >> $XEN_CONF_FILE
72 echo "memory = ${VM_MEMSIZE:-64}" >> $XEN_CONF_FILE
73 test -n "$BUILD_JOBS" && echo "vcpus = $BUILD_JOBS" >> $XEN_CONF_FILE
74 echo "root = \"$VM_ROOTDEV ro\"" >> $XEN_CONF_FILE
75 echo "extra = \"init=/bin/bash console=$VM_CONSOLE panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
76 echo "on_poweroff = \"destroy\"" >> $XEN_CONF_FILE
77 echo "on_reboot = \"destroy\"" >> $XEN_CONF_FILE
78 echo "on_crash = \"destroy\"" >> $XEN_CONF_FILE
79 if test "$XMCMD" = xm ; then
80 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"
81 else
82 XLDISK=
83 XLDISK="\"${XMROOT#disk=}\""
84 test -n "$XMSWAP" && XLDISK="$XLDISK, \"${XMSWAP#disk=}\""
85 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 $vm_linux_kernel_parameter elevator=noop console=$VM_CONSOLE"\"
86 fi
87 if test "$PERSONALITY" != 0 ; then
88 # have to switch back to PER_LINUX to make xm work
89 set -- linux64 "$@"
90 fi
91 echo "$@"
92 "$@" || cleanup_and_exit 3
93 rm -f "$XEN_CONF_FILE"
94 }
95
96 vm_kill_xen() {
97 xen_set_xenid_xmcmd
98 if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
99 if ! $XMCMD destroy "build_$XENID" ; then
100 cleanup_and_exit 1 "could not kill xen build $XENID"
101 fi
102 fi
103 }
104
105 # XEN only
106 vm_purge_xen() {
107 # this should not be needed, but sometimes a xen instance gets lost
108 xen_set_xenid_xmcmd
109 $XMCMD destroy "build_$XENID" >/dev/null 2>&1
110 }
111
112 vm_fixup_xen() {
113 :
114 }
115
116 vm_attach_root_xen() {
117 :
118 }
119
120 vm_attach_swap_xen() {
121 :
122 }
123
124 vm_detach_root_xen() {
125 :
126 }
127
128 vm_detach_swap_xen() {
129 :
130 }
131
132 vm_cleanup_xen() {
133 :
134 }
135
136 vm_sysrq_xen() {
137 :
138 }
139
140 vm_wipe_xen() {
141 :
142 }
143