ia64/xen-unstable

changeset 8211:b20641d24272

Set hostname in DHCP config from the guest name, and if more than one interface
is specified, from guest-2, guest-3 etc. Have the DHCP server send the
hostname to the guest.

Added a lock around DHCP config file frobbing, to avoid racing creation vs
deletion.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Sat Dec 03 12:21:27 2005 +0000 (2005-12-03)
parents 5e617fd48504
children 4146dbea47e1
files tools/examples/vif-nat
line diff
     1.1 --- a/tools/examples/vif-nat	Sat Dec 03 00:51:36 2005 +0000
     1.2 +++ b/tools/examples/vif-nat	Sat Dec 03 12:21:27 2005 +0000
     1.3 @@ -42,14 +42,15 @@ then
     1.4  fi
     1.5  
     1.6  
     1.7 +domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
     1.8 +vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
     1.9 +vifid=$(( $vifid + 1 ))
    1.10 +
    1.11 +
    1.12  ip_from_dom()
    1.13  {
    1.14 -  local domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
    1.15 -  local vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
    1.16 -
    1.17    local domid1=$(( $domid / 256 ))
    1.18    local domid2=$(( $domid % 256 ))
    1.19 -  vifid=$(( $vifid + 1 ))
    1.20  
    1.21    echo "10.$domid1.$domid2.$vifid/16"
    1.22  }
    1.23 @@ -92,10 +93,17 @@ netmask=$(dotted_quad $intmask)
    1.24  network=$(dotted_quad $(( $vif_int & $intmask )) )
    1.25  
    1.26  
    1.27 +hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----')
    1.28 +if [ "$vifid" != "1" ]
    1.29 +then
    1.30 +  hostname="$hostname-$vifid"
    1.31 +fi
    1.32 +
    1.33 +
    1.34  dhcp_remove_entry()
    1.35  {
    1.36    local tmpfile=$(mktemp)
    1.37 -  grep -v "host Xen-${vif/./-}" "$dhcpd_conf_file" >"$tmpfile"
    1.38 +  grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
    1.39    if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
    1.40    then
    1.41      rm "$tmpfile"
    1.42 @@ -107,18 +115,21 @@ dhcp_remove_entry()
    1.43  
    1.44  dhcp_up()
    1.45  {
    1.46 +  claim_lock "vif-nat-dhcp"
    1.47    dhcp_remove_entry
    1.48    mac=$(xenstore_read "$XENBUS_PATH/mac")
    1.49    echo >>"$dhcpd_conf_file" \
    1.50 -"host Xen-${vif/./-} { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; }"
    1.51 -
    1.52 -  "$dhcpd_init_file" restart
    1.53 +"host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }"
    1.54 +  release_lock "vif-nat-dhcp"
    1.55 +  "$dhcpd_init_file" restart || true
    1.56  }
    1.57  
    1.58  
    1.59  dhcp_down()
    1.60  {
    1.61 +  claim_lock "vif-nat-dhcp"
    1.62    dhcp_remove_entry
    1.63 +  release_lock "vif-nat-dhcp"
    1.64    "$dhcpd_init_file" restart || true # We need to ignore failure because
    1.65                                       # ISC dhcpd 3 borks if there is nothing
    1.66                                       # for it to do, which is the case if