vm: replace vnode v_pages with a v_pagecache_list list_t
[unleashed.git] / usr / src / cmd / xvm / ipagent / ipagent.ksh
blob4b85637b5b3160c8ae9d39ff81e8187075b3f1c7
1 #!/bin/ksh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 # xVM PV domU IP address reporting agent. Reports IP address back to dom0.
30 interval=$1
32 xs_ipaddr_path="guest/ipv4/0/address"
33 xs_link_path="guest/ipv4/default-link"
34 link=""
37 # Look for a valid-seeming address for the given link. Return 0 on success.
39 link_to_addr()
41 tmp=`netstat -I $1 -in -f inet | awk '{print $4}' | grep -v Address`;
42 if [ -z "$tmp" ] || [ "$tmp" = "0.0.0.0" ];
43 then
44 addr="(none)";
45 return 1;
48 addr=$tmp;
49 return 0;
52 default_link()
55 # Look in the store for a cached link name.
57 link=`/usr/lib/xen/bin/xenstore-read $xs_link_path 2>/dev/null`
58 if [ -z "$link" ] || [ "$link" = "(none)" ]
59 then
61 # If it's not there, try to determine what it is
62 # and add it to the store.
63 determine_default_link
68 # Determine the default link name and update xenstore with the details.
70 determine_default_link()
72 link="(none)";
74 # Choose the first up, non-loopback interface with a valid-looking
75 # IP address.
77 dladm show-link -p -o link,state | while IFS=: read LINKNAME STATE;
79 if [ "$STATE" = "up" ];
80 then
81 link_to_addr "$LINKNAME"
82 if [ $? -eq 0 ]; then link=$LINKNAME; break; fi
85 done
87 /usr/lib/xen/bin/xenstore-write $xs_link_path $link
90 while true; do
93 # Determine the default link in use by this domU.
95 default_link;
98 # If the link still has a valid-looking IP address, notify dom0 of its
99 # address.
101 link_to_addr $link
102 if [ $? -ne 0 ]
103 then
105 # An address could not be determined for the currently cached
106 # default link so determine it again in case it has changed.
107 # We'll still sleep this iteration to rate-limit dladm calls.
109 determine_default_link;
112 /usr/lib/xen/bin/xenstore-write $xs_ipaddr_path $addr
114 sleep $interval
115 done