xen-drbd
changeset 51:d3198c10cc10
minifix
author | root@linux10 |
---|---|
date | Fri Oct 10 18:35:48 2008 +0000 (2008-10-10) |
parents | 151c7ef48ded |
children | 21f21fa8f106 |
files | INSTALL network-bridge-for-xen-drbd xen-drbd-install.py |
line diff
1.1 --- a/INSTALL Wed Oct 01 00:39:01 2008 +0300 1.2 +++ b/INSTALL Fri Oct 10 18:35:48 2008 +0000 1.3 @@ -20,6 +20,7 @@ 1.4 chmod +x ${ROOT}/etc/init.d/xen-drbd 1.5 1.6 cp xen-scripts-network-xen-drbd $ROOT/etc/xen/scripts/network-xen-drbd 1.7 +cp network-bridge-for-xen-drbd $ROOT/etc/xen/scripts/network-bridge-for-xen-drbd 1.8 chmod +x /etc/xen/scripts/network-xen-drbd 1.9 1.10 cp default-xen-drbd ${ROOT}/etc/default/xen-drbd
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/network-bridge-for-xen-drbd Fri Oct 10 18:35:48 2008 +0000 2.3 @@ -0,0 +1,313 @@ 2.4 +#!/bin/bash 2.5 +#============================================================================ 2.6 +# Default Xen network start/stop script. 2.7 +# Xend calls a network script when it starts. 2.8 +# The script name to use is defined in /etc/xen/xend-config.sxp 2.9 +# in the network-script field. 2.10 +# 2.11 +# This script creates a bridge (default xenbr${vifnum}), adds a device 2.12 +# (default eth${vifnum}) to it, copies the IP addresses from the device 2.13 +# to the bridge and adjusts the routes accordingly. 2.14 +# 2.15 +# If all goes well, this should ensure that networking stays up. 2.16 +# However, some configurations are upset by this, especially 2.17 +# NFS roots. If the bridged setup does not meet your needs, 2.18 +# configure a different script, for example using routing instead. 2.19 +# 2.20 +# Usage: 2.21 +# 2.22 +# network-bridge (start|stop|status) {VAR=VAL}* 2.23 +# 2.24 +# Vars: 2.25 +# 2.26 +# vifnum Virtual device number to use (default 0). Numbers >=8 2.27 +# require the netback driver to have nloopbacks set to a 2.28 +# higher value than its default of 8. 2.29 +# bridge The bridge to use (default xenbr${vifnum}). 2.30 +# netdev The interface to add to the bridge (default eth${vifnum}). 2.31 +# antispoof Whether to use iptables to prevent spoofing (default no). 2.32 +# 2.33 +# Internal Vars: 2.34 +# pdev="p${netdev}" 2.35 +# vdev="veth${vifnum}" 2.36 +# vif0="vif0.${vifnum}" 2.37 +# 2.38 +# start: 2.39 +# Creates the bridge 2.40 +# Copies the IP and MAC addresses from netdev to vdev 2.41 +# Renames netdev to be pdev 2.42 +# Renames vdev to be netdev 2.43 +# Enslaves pdev, vdev to bridge 2.44 +# 2.45 +# stop: 2.46 +# Removes netdev from the bridge 2.47 +# Transfers addresses, routes from netdev to pdev 2.48 +# Renames netdev to vdev 2.49 +# Renames pdev to netdev 2.50 +# Deletes bridge 2.51 +# 2.52 +# status: 2.53 +# Print addresses, interfaces, routes 2.54 +# 2.55 +#============================================================================ 2.56 + 2.57 + 2.58 +dir=$(dirname "$0") 2.59 +. "$dir/xen-script-common.sh" 2.60 +. "$dir/xen-network-common.sh" 2.61 + 2.62 +findCommand "$@" 2.63 +evalVariables "$@" 2.64 + 2.65 +modprobe netloop > /dev/null 2>&1 || true 2.66 + 2.67 +vifnum=${vifnum:-$(ip route list | awk '/^default / { print $NF }' | sed 's/^[^0-9]*//')} 2.68 +vifnum=${vifnum:-0} 2.69 +bridge=${bridge:-xenbr${vifnum}} 2.70 +netdev=${netdev:-eth${vifnum}} 2.71 +antispoof=${antispoof:-no} 2.72 + 2.73 +pdev="p${netdev}" 2.74 +vdev="veth${vifnum}" 2.75 +vif0="vif0.${vifnum}" 2.76 + 2.77 +get_ip_info() { 2.78 + addr_pfx=`ip addr show dev $1 | egrep '^ *inet' | sed -e 's/ *inet //' -e 's/ .*//'` 2.79 + gateway=`ip route show dev $1 | fgrep default | sed 's/default via //'` 2.80 +} 2.81 + 2.82 +do_ifup() { 2.83 + if ! ifup $1 ; then 2.84 + if [ ${addr_pfx} ] ; then 2.85 + # use the info from get_ip_info() 2.86 + ip addr flush $1 2.87 + ip addr add ${addr_pfx} dev $1 2.88 + ip link set dev $1 up 2.89 + [ ${gateway} ] && ip route add default via ${gateway} 2.90 + fi 2.91 + fi 2.92 +} 2.93 + 2.94 +# Usage: transfer_addrs src dst 2.95 +# Copy all IP addresses (including aliases) from device $src to device $dst. 2.96 +transfer_addrs () { 2.97 + local src=$1 2.98 + local dst=$2 2.99 + # Don't bother if $dst already has IP addresses. 2.100 + if ip addr show dev ${dst} | egrep -q '^ *inet ' ; then 2.101 + return 2.102 + fi 2.103 + # Address lines start with 'inet' and have the device in them. 2.104 + # Replace 'inet' with 'ip addr add' and change the device name $src 2.105 + # to 'dev $src'. 2.106 + ip addr show dev ${src} | egrep '^ *inet ' | sed -e " 2.107 +s/inet/ip addr add/ 2.108 +s@\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/[0-9]\+\)@\1@ 2.109 +s/${src}/dev ${dst}/ 2.110 +" | sh -e 2.111 + # Remove automatic routes on destination device 2.112 + ip route list | sed -ne " 2.113 +/dev ${dst}\( \|$\)/ { 2.114 + s/^/ip route del / 2.115 + p 2.116 +}" | sh -e 2.117 +} 2.118 + 2.119 +# Usage: transfer_routes src dst 2.120 +# Get all IP routes to device $src, delete them, and 2.121 +# add the same routes to device $dst. 2.122 +# The original routes have to be deleted, otherwise adding them 2.123 +# for $dst fails (duplicate routes). 2.124 +transfer_routes () { 2.125 + local src=$1 2.126 + local dst=$2 2.127 + # List all routes and grep the ones with $src in. 2.128 + # Stick 'ip route del' on the front to delete. 2.129 + # Change $src to $dst and use 'ip route add' to add. 2.130 + ip route list | sed -ne " 2.131 +/dev ${src}\( \|$\)/ { 2.132 + h 2.133 + s/^/ip route del / 2.134 + P 2.135 + g 2.136 + s/${src}/${dst}/ 2.137 + s/^/ip route add / 2.138 + P 2.139 + d 2.140 +}" | sh -e 2.141 +} 2.142 + 2.143 + 2.144 +## 2.145 +# link_exists interface 2.146 +# 2.147 +# Returns 0 if the interface named exists (whether up or down), 1 otherwise. 2.148 +# 2.149 +link_exists() 2.150 +{ 2.151 + if ip link show "$1" >/dev/null 2>/dev/null 2.152 + then 2.153 + return 0 2.154 + else 2.155 + return 1 2.156 + fi 2.157 +} 2.158 + 2.159 +# Set the default forwarding policy for $dev to drop. 2.160 +# Allow forwarding to the bridge. 2.161 +antispoofing () { 2.162 + iptables -P FORWARD DROP 2.163 + iptables -F FORWARD 2.164 + iptables -A FORWARD -m physdev --physdev-in ${pdev} -j ACCEPT 2.165 + iptables -A FORWARD -m physdev --physdev-in ${vif0} -j ACCEPT 2.166 +} 2.167 + 2.168 +# Usage: show_status dev bridge 2.169 +# Print ifconfig and routes. 2.170 +show_status () { 2.171 + local dev=$1 2.172 + local bridge=$2 2.173 + 2.174 + echo '============================================================' 2.175 + ip addr show ${dev} 2.176 + ip addr show ${bridge} 2.177 + echo ' ' 2.178 + brctl show ${bridge} 2.179 + echo ' ' 2.180 + ip route list 2.181 + echo ' ' 2.182 + route -n 2.183 + echo '============================================================' 2.184 +} 2.185 + 2.186 +op_start () { 2.187 + if [ "${bridge}" = "null" ] ; then 2.188 + return 2.189 + fi 2.190 + 2.191 + if ! link_exists "$vdev"; then 2.192 + if link_exists "$pdev"; then 2.193 + # The device is already up. 2.194 + return 2.195 + else 2.196 + echo " 2.197 +Link $vdev is missing. 2.198 +This may be because you have reached the limit of the number of interfaces 2.199 +that the loopback driver supports. If the loopback driver is a module, you 2.200 +may raise this limit by passing it as a parameter (nloopbacks=<N>); if the 2.201 +driver is compiled statically into the kernel, then you may set the parameter 2.202 +using loopback.nloopbacks=<N> on the domain 0 kernel command line. 2.203 +" >&2 2.204 + exit 1 2.205 + fi 2.206 + fi 2.207 + 2.208 + create_bridge ${bridge} 2.209 + 2.210 + if link_exists "$vdev"; then 2.211 + mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` 2.212 + preiftransfer ${netdev} 2.213 + transfer_addrs ${netdev} ${vdev} 2.214 + if ! ifdown ${netdev}; then 2.215 + # If ifdown fails, remember the IP details. 2.216 + get_ip_info ${netdev} 2.217 + ip link set ${netdev} down 2.218 + ip addr flush ${netdev} 2.219 + fi 2.220 + ip link set ${netdev} name ${pdev} 2.221 + ip link set ${vdev} name ${netdev} 2.222 + 2.223 + setup_bridge_port ${pdev} 2.224 + setup_bridge_port ${vif0} 2.225 + ip link set ${netdev} addr ${mac} arp on 2.226 + 2.227 + ip link set ${bridge} up 2.228 + add_to_bridge ${bridge} ${vif0} 2.229 + add_to_bridge2 ${bridge} ${pdev} 2.230 + do_ifup ${netdev} 2.231 + else 2.232 + # old style without ${vdev} 2.233 + transfer_addrs ${netdev} ${bridge} 2.234 + transfer_routes ${netdev} ${bridge} 2.235 + fi 2.236 + 2.237 + if [ ${antispoof} = 'yes' ] ; then 2.238 + antispoofing 2.239 + fi 2.240 +} 2.241 + 2.242 +op_stop () { 2.243 + if [ "${bridge}" = "null" ]; then 2.244 + return 2.245 + fi 2.246 + if ! link_exists "$bridge"; then 2.247 + return 2.248 + fi 2.249 + 2.250 + if link_exists "$pdev"; then 2.251 + ip link set dev ${vif0} down 2.252 + mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` 2.253 + transfer_addrs ${netdev} ${pdev} 2.254 + if ! ifdown ${netdev}; then 2.255 + get_ip_info ${netdev} 2.256 + fi 2.257 + ip link set ${netdev} down arp off 2.258 + ip link set ${netdev} addr fe:ff:ff:ff:ff:ff 2.259 + ip link set ${pdev} down 2.260 + ip addr flush ${netdev} 2.261 + ip link set ${pdev} addr ${mac} arp on 2.262 + 2.263 + brctl delif ${bridge} ${pdev} 2.264 + brctl delif ${bridge} ${vif0} 2.265 + ip link set ${bridge} down 2.266 + 2.267 + ip link set ${netdev} name ${vdev} 2.268 + ip link set ${pdev} name ${netdev} 2.269 + do_ifup ${netdev} 2.270 + else 2.271 + transfer_routes ${bridge} ${netdev} 2.272 + ip link set ${bridge} down 2.273 + fi 2.274 + brctl delbr ${bridge} 2.275 +} 2.276 + 2.277 +# adds $dev to $bridge but waits for $dev to be in running state first 2.278 +add_to_bridge2() { 2.279 + local bridge=$1 2.280 + local dev=$2 2.281 + local maxtries=10 2.282 + 2.283 + echo -n "Waiting for ${dev} to negotiate link." 2.284 + ip link set ${dev} up 2.285 + for i in `seq ${maxtries}` ; do 2.286 + if ifconfig ${dev} | grep -q RUNNING ; then 2.287 + break 2.288 + else 2.289 + echo -n '.' 2.290 + sleep 1 2.291 + fi 2.292 + done 2.293 + 2.294 + if [ ${i} -eq ${maxtries} ] ; then echo '(link isnt in running state)' ; fi 2.295 + 2.296 + add_to_bridge ${bridge} ${dev} 2.297 +} 2.298 + 2.299 +case "$command" in 2.300 + start) 2.301 + op_start 2.302 + ;; 2.303 + 2.304 + stop) 2.305 + op_stop 2.306 + ;; 2.307 + 2.308 + status) 2.309 + show_status ${netdev} ${bridge} 2.310 + ;; 2.311 + 2.312 + *) 2.313 + echo "Unknown command: $command" >&2 2.314 + echo 'Valid commands are: start, stop, status' >&2 2.315 + exit 1 2.316 +esac
3.1 --- a/xen-drbd-install.py Wed Oct 01 00:39:01 2008 +0300 3.2 +++ b/xen-drbd-install.py Fri Oct 10 18:35:48 2008 +0000 3.3 @@ -161,7 +161,7 @@ 3.4 print "drbdadm up all" 3.5 for dom in domains: 3.6 for disk in disk_table[dom]: 3.7 - print "drbdsetup %s primary -o" % disk.split(':')[0] 3.8 + print "drbdsetup /dev/%s primary -o" % disk.split(':')[0] 3.9 3.10 3.11 def make_links(): 3.12 @@ -271,8 +271,8 @@ 3.13 network %s.0 3.14 broadcast %s.255 3.15 gateway %s 3.16 + dns-search %s 3.17 dns-nameservers %s 3.18 - dns-search %s 3.19 INTERFACES 3.20 """ % (dom,ip_address_table[dom],ip_network, ip_network, ip_gateway, domain_name, ip_nameserver) 3.21