Lines 1-16
Link Here
|
1 |
--- src/sbin/xe-update-guest-attrs.orig 2014-07-07 15:45:10.000000000 +0200 |
1 |
--- src/sbin/xe-update-guest-attrs.orig 2024-09-03 15:39:43.133537000 -0400 |
2 |
+++ src/sbin/xe-update-guest-attrs 2015-01-30 10:24:05.000000000 +0100 |
2 |
+++ src/sbin/xe-update-guest-attrs 2024-09-03 15:42:09.862675000 -0400 |
3 |
@@ -173,10 +173,10 @@ |
3 |
@@ -39,7 +39,7 @@ XENSTORE=${XENSTORE:-/usr/local/bin/xenstore} |
4 |
xenstore_write_cached "control/feature-balloon" "1" |
4 |
|
|
|
5 |
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/sbin |
6 |
XENSTORE=${XENSTORE:-/usr/local/bin/xenstore} |
7 |
- |
8 |
+CACHEROOT="/var/cache/xenstore" |
9 |
XENSTORE_UPDATED=0 |
10 |
|
11 |
# parse command line opts |
12 |
@@ -54,7 +54,7 @@ xenstore_write_cached() { |
13 |
|
14 |
xenstore_write_cached() { |
15 |
key="$1" newval="$2" |
16 |
- cache=/var/cache/xenstore/$key |
17 |
+ cache=${CACHEROOT}/$key |
18 |
if [ -f $cache ] ; then |
19 |
# cache exists |
20 |
oldval=$(cat "$cache") |
21 |
@@ -82,13 +82,13 @@ domid=$(/usr/local/bin/xenstore-read "domid") |
22 |
|
23 |
# If we detect a domain change then delete our cache and force a refresh |
24 |
domid=$(/usr/local/bin/xenstore-read "domid") |
25 |
-cache=/var/cache/xenstore/unique-domain-id |
26 |
+cache=${CACHEROOT}/unique-domain-id |
27 |
newval=$(/usr/local/bin/xenstore-read "/local/domain/${domid}/unique-domain-id") |
28 |
if [ -e $cache ]; then |
29 |
oldval=$(cat "$cache") |
30 |
if [ "$oldval" != "$newval" ]; then |
31 |
# domain changed |
32 |
- rm -rf /var/cache/xenstore |
33 |
+ rm -rf xenstore |
34 |
fi |
35 |
fi |
36 |
mkdir -p $(dirname "$cache") |
37 |
@@ -96,7 +96,7 @@ xenstore_rm_cached() { |
38 |
|
39 |
xenstore_rm_cached() { |
40 |
key="$1" |
41 |
- cache=/var/cache/xenstore/$key |
42 |
+ cache=${CACHEROOT}/$key |
43 |
if [ ! -e $cache ] ; then |
44 |
return 1 |
45 |
fi |
46 |
@@ -109,21 +109,46 @@ xenstore_rm_cached() { |
47 |
return 1 |
48 |
} |
49 |
|
50 |
+# read cache, using xen-style integers (e.g., "0", "1") |
51 |
+# return bsd names like xn0 |
52 |
xenstore_list_interfaces_cached() { |
53 |
- topdir=/var/cache/xenstore/attr |
54 |
+ topdir=${CACHEROOT}/attr |
55 |
if [ -d $topdir ] ; then |
56 |
cd $topdir |
57 |
- for dir in * ; do |
58 |
- [ -f $dir/ip ] && echo $dir |
59 |
+ # if a file named like vif/0/ipv4/0 exists, then xn0 is a valid interface |
60 |
+ # sort -u to get only unique interfaces |
61 |
+ iflist=$(ls vif/*/ipv?/* | cut -d / -f 2 | sort -u | xargs echo) |
62 |
+ for n in $iflist |
63 |
+ do |
64 |
+ echo "xn${n}" |
65 |
done |
66 |
fi |
67 |
} |
68 |
|
69 |
+# XAPI expects things like attr/vif/0/ipv4/0 = 172.30.0.2 |
70 |
+# So this tries to map BSD names like xn0 to attr/vif/0 |
71 |
xe_ip_if() { |
72 |
-interfaces=$(/sbin/ifconfig -u | grep ': flags=' | grep xn | cut -d ':' -f1) |
73 |
-for if in $interfaces ; do |
74 |
- echo $(echo $if | sed 's/xn/eth/g') "|" $(/sbin/ifconfig $if | grep 'inet ' | cut -d ' ' -f2) |
75 |
-done |
76 |
+ interfaces=$(/sbin/ifconfig -u | grep ': flags=' | grep xn | cut -d ':' -f1) |
77 |
+ n=0 |
78 |
+ for ifacename in $interfaces ; do |
79 |
+ v4ips=$(/sbin/ifconfig $ifacename | grep 'inet ' | cut -d ' ' -f2) |
80 |
+ # FreeBSD reports some IPv6 addrs like fe80:1234::abcd%xn0, the `cut` strips that off |
81 |
+ v6ips=$(/sbin/ifconfig $ifacename | grep 'inet6 ' | cut -d ' ' -f2 | cut -d % -f 1 ) |
82 |
+ i=0 |
83 |
+ for v4ip in $v4ips |
84 |
+ do |
85 |
+ echo "vif/$n/ipv4/$i | $v4ip" |
86 |
+ i=$(($i+1)) |
87 |
+ done |
88 |
+ |
89 |
+ i=0 |
90 |
+ for v6ip in $v6ips |
91 |
+ do |
92 |
+ echo "vif/$n/ipv6/$i | $v6ip" |
93 |
+ i=$(($i+1)) |
94 |
+ done |
95 |
+ n=$(($n+1)) |
96 |
+ done |
97 |
} |
98 |
|
99 |
if [ $MEMORY_MODE -eq 1 ] ; then |
100 |
@@ -140,22 +165,33 @@ fi |
101 |
xenstore_write_cached "data/meminfo_free" "$memavail" |
102 |
fi |
103 |
|
104 |
+# xe_ip_if | while read linea |
105 |
+# do |
106 |
+# if=$(echo $linea | cut -d '|' -f1 | sed 's/ //g') |
107 |
+# inet=$(echo $linea | cut -d '|' -f2 | sed 's/^ //') |
108 |
+# xenstore_write_cached "attr/${if}/ip" "${inet}" |
109 |
+# done |
110 |
+ |
111 |
+# This breaks apart a string like "vif/0/ipv4/0 | 172.16.0.8" into 2 arguments for |
112 |
+# xenstore_write_cached |
113 |
xe_ip_if | while read linea |
114 |
do |
115 |
- if=$(echo $linea | cut -d '|' -f1 | sed 's/ //g') |
116 |
- inet=$(echo $linea | cut -d '|' -f2 | sed 's/^ //') |
117 |
- xenstore_write_cached "attr/${if}/ip" "${inet}" |
118 |
+ if=$(echo $linea | cut -d '|' -f1 | tr -d ' ' ) |
119 |
+ inet=$(echo $linea | cut -d '|' -f2 | tr -d ' ' ) |
120 |
+ xenstore_write_cached "attr/${if}" "${inet}" |
121 |
done |
122 |
|
123 |
# remove any interfaces that have been unplugged or downed |
124 |
-for at in $(xenstore_list_interfaces_cached) ; do |
125 |
+for xn in $(xenstore_list_interfaces_cached) ; do |
126 |
link=1 |
127 |
- xn=$(echo $at | sed 's/eth/xn/') |
128 |
- iface=$(/sbin/ifconfig $xn | grep UP | cut -d ':' -f1) |
129 |
+ iface=$(/sbin/ifconfig $xn | grep "UP," | cut -d ':' -f1) |
130 |
[ "${iface}" = "${xn}" ] && link=0 |
131 |
|
132 |
if [ "$link" -gt "0" ] ; then |
133 |
- xenstore_rm_cached "attr/${at}" |
134 |
+ # bsd-named interface is gone, remove attr from xenstore |
135 |
+ vifnum=$(echo $xn | sed 's/xn//g') |
136 |
+ echo "removing vif $vifnum" |
137 |
+ xenstore_rm_cached "attr/vif/${vifnum}" |
138 |
fi |
139 |
done |
140 |
|
141 |
@@ -174,9 +210,9 @@ xenstore_write_cached "attr/PVAddons/MajorVersion" "6" |
5 |
|
142 |
|
6 |
# build time addons |
143 |
# build time addons |
7 |
-xenstore_write_cached "attr/PVAddons/MajorVersion" "6" |
144 |
xenstore_write_cached "attr/PVAddons/MajorVersion" "6" |
8 |
-xenstore_write_cached "attr/PVAddons/MinorVersion" "0" |
145 |
-xenstore_write_cached "attr/PVAddons/MinorVersion" "0" |
9 |
-xenstore_write_cached "attr/PVAddons/MicroVersion" "2" |
146 |
-xenstore_write_cached "attr/PVAddons/MicroVersion" "2" |
10 |
-xenstore_write_cached "attr/PVAddons/BuildVersion" "54078" |
147 |
-xenstore_write_cached "attr/PVAddons/BuildVersion" "54078" |
11 |
+xenstore_write_cached "attr/PVAddons/MajorVersion" "6" |
|
|
12 |
+xenstore_write_cached "attr/PVAddons/MinorVersion" "2" |
148 |
+xenstore_write_cached "attr/PVAddons/MinorVersion" "2" |
13 |
+xenstore_write_cached "attr/PVAddons/MicroVersion" "0" |
149 |
+xenstore_write_cached "attr/PVAddons/MicroVersion" "1" |
14 |
+xenstore_write_cached "attr/PVAddons/BuildVersion" "76888" |
150 |
+xenstore_write_cached "attr/PVAddons/BuildVersion" "76888" |
15 |
xenstore_write_cached "attr/PVAddons/Installed" "1" |
151 |
xenstore_write_cached "attr/PVAddons/Installed" "1" |
16 |
|
152 |
|
17 |
- |
|
|