WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Set hostname in DHCP config from the guest name, and if

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Set hostname in DHCP config from the guest name, and if more than one interface
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 03 Dec 2005 13:36:07 +0000
Delivery-date: Sat, 03 Dec 2005 13:36:17 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID b20641d242723923de40030a63771770b04702d3
# Parent  5e617fd4850427ac4ac235969b36d78935103f19
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@xxxxxxxxxxxxx>

diff -r 5e617fd48504 -r b20641d24272 tools/examples/vif-nat
--- a/tools/examples/vif-nat    Sat Dec  3 00:51:36 2005
+++ b/tools/examples/vif-nat    Sat Dec  3 12:21:27 2005
@@ -42,14 +42,15 @@
 fi
 
 
+domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
+vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
+vifid=$(( $vifid + 1 ))
+
+
 ip_from_dom()
 {
-  local domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
-  local vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
-
   local domid1=$(( $domid / 256 ))
   local domid2=$(( $domid % 256 ))
-  vifid=$(( $vifid + 1 ))
 
   echo "10.$domid1.$domid2.$vifid/16"
 }
@@ -92,10 +93,17 @@
 network=$(dotted_quad $(( $vif_int & $intmask )) )
 
 
+hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----')
+if [ "$vifid" != "1" ]
+then
+  hostname="$hostname-$vifid"
+fi
+
+
 dhcp_remove_entry()
 {
   local tmpfile=$(mktemp)
-  grep -v "host Xen-${vif/./-}" "$dhcpd_conf_file" >"$tmpfile"
+  grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
   if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
   then
     rm "$tmpfile"
@@ -107,18 +115,21 @@
 
 dhcp_up()
 {
+  claim_lock "vif-nat-dhcp"
   dhcp_remove_entry
   mac=$(xenstore_read "$XENBUS_PATH/mac")
   echo >>"$dhcpd_conf_file" \
-"host Xen-${vif/./-} { hardware ethernet $mac; fixed-address $vif_ip; option 
routers $router_ip; }"
-
-  "$dhcpd_init_file" restart
+"host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option 
routers $router_ip; option host-name \"$hostname\"; }"
+  release_lock "vif-nat-dhcp"
+  "$dhcpd_init_file" restart || true
 }
 
 
 dhcp_down()
 {
+  claim_lock "vif-nat-dhcp"
   dhcp_remove_entry
+  release_lock "vif-nat-dhcp"
   "$dhcpd_init_file" restart || true # We need to ignore failure because
                                      # ISC dhcpd 3 borks if there is nothing
                                      # for it to do, which is the case if

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Set hostname in DHCP config from the guest name, and if more than one interface, Xen patchbot -unstable <=