ia64/xen-unstable

annotate tools/python/xen/xend/osdep.py @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 23f9857f642f
children
rev   line source
kfraser@11855 1 #!/usr/bin/env python
kfraser@11855 2 #
kfraser@11855 3 # This library is free software; you can redistribute it and/or
kfraser@11855 4 # modify it under the terms of version 2.1 of the GNU Lesser General Public
kfraser@11855 5 # License as published by the Free Software Foundation.
kfraser@11855 6 #
kfraser@11855 7 # This library is distributed in the hope that it will be useful,
kfraser@11855 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
kfraser@11855 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kfraser@11855 10 # Lesser General Public License for more details.
kfraser@11855 11 #
kfraser@11855 12 # You should have received a copy of the GNU Lesser General Public
kfraser@11855 13 # License along with this library; if not, write to the Free Software
kfraser@11855 14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
kfraser@11855 15 #
kfraser@11855 16
kfraser@11855 17 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
kfraser@11855 18 # Use is subject to license terms.
kfraser@11855 19
kfraser@11855 20 import os
keir@19326 21 import commands
kfraser@11855 22
kfraser@11860 23 _xend_autorestart = {
keir@16430 24 "NetBSD": True,
kfraser@11860 25 "Linux": True,
kfraser@11860 26 "SunOS": False,
kfraser@11860 27 }
kfraser@11860 28
john@13486 29 _vif_script = {
john@13486 30 "SunOS": "vif-vnic"
john@13486 31 }
john@13486 32
keir@18801 33 PROC_XEN_BALLOON = '/proc/xen/balloon'
keir@18801 34 SYSFS_XEN_MEMORY = '/sys/devices/system/xen_memory/xen_memory0'
keir@18801 35
keir@18801 36 def _linux_balloon_stat_proc(label):
keir@14686 37 """Returns the value for the named label, or None if an error occurs."""
keir@14686 38
keir@18129 39 xend2linux_labels = { 'current' : 'Current allocation',
keir@18129 40 'target' : 'Requested target',
keir@18129 41 'low-balloon' : 'Low-mem balloon',
keir@18129 42 'high-balloon' : 'High-mem balloon',
keir@18129 43 'limit' : 'Xen hard limit' }
keir@18129 44
keir@14686 45 f = file(PROC_XEN_BALLOON, 'r')
keir@14686 46 try:
keir@14686 47 for line in f:
keir@14686 48 keyvalue = line.split(':')
keir@18129 49 if keyvalue[0] == xend2linux_labels[label]:
keir@14686 50 values = keyvalue[1].split()
keir@14686 51 if values[0].isdigit():
keir@14686 52 return int(values[0])
keir@14686 53 else:
keir@14686 54 return None
keir@14686 55 return None
keir@14686 56 finally:
keir@14686 57 f.close()
keir@14686 58
keir@18801 59 def _linux_balloon_stat_sysfs(label):
keir@18801 60 sysfiles = { 'target' : 'target_kb',
keir@18801 61 'current' : 'info/current_kb',
keir@18801 62 'low-balloon' : 'info/low_kb',
keir@18801 63 'high-balloon' : 'info/high_kb',
keir@18801 64 'limit' : 'info/hard_limit_kb' }
keir@18801 65
keir@18801 66 name = os.path.join(SYSFS_XEN_MEMORY, sysfiles[label])
keir@18801 67 f = file(name, 'r')
keir@18801 68
keir@18801 69 val = f.read().strip()
keir@18801 70 if val.isdigit():
keir@18801 71 return int(val)
keir@18801 72 return None
keir@18801 73
keir@18801 74 def _linux_balloon_stat(label):
keir@18801 75 if os.access(PROC_XEN_BALLOON, os.F_OK):
keir@18801 76 return _linux_balloon_stat_proc(label)
keir@18801 77 elif os.access(SYSFS_XEN_MEMORY, os.F_OK):
keir@18801 78 return _linux_balloon_stat_sysfs(label)
keir@18801 79
keir@18801 80 return None
keir@18801 81
keir@14686 82 def _solaris_balloon_stat(label):
keir@14686 83 """Returns the value for the named label, or None if an error occurs."""
keir@14686 84
keir@14686 85 import fcntl
keir@14686 86 import array
keir@14686 87 DEV_XEN_BALLOON = '/dev/xen/balloon'
keir@15360 88 BLN_IOCTL_CURRENT = 0x42410001
keir@15360 89 BLN_IOCTL_TARGET = 0x42410002
keir@15360 90 BLN_IOCTL_LOW = 0x42410003
keir@15360 91 BLN_IOCTL_HIGH = 0x42410004
keir@15360 92 BLN_IOCTL_LIMIT = 0x42410005
keir@18129 93 label_to_ioctl = { 'current' : BLN_IOCTL_CURRENT,
keir@18129 94 'target' : BLN_IOCTL_TARGET,
keir@18129 95 'low-balloon' : BLN_IOCTL_LOW,
keir@18129 96 'high-balloon' : BLN_IOCTL_HIGH,
keir@18129 97 'limit' : BLN_IOCTL_LIMIT }
keir@14686 98
keir@14686 99 f = file(DEV_XEN_BALLOON, 'r')
keir@14686 100 try:
keir@14686 101 values = array.array('L', [0])
keir@14686 102 if fcntl.ioctl(f.fileno(), label_to_ioctl[label], values, 1) == 0:
keir@14686 103 return values[0]
keir@14686 104 else:
keir@14686 105 return None
keir@14686 106 finally:
keir@14686 107 f.close()
keir@14686 108
keir@14686 109 _balloon_stat = {
keir@14686 110 "SunOS": _solaris_balloon_stat
keir@14686 111 }
keir@14686 112
keir@18107 113 def _linux_get_cpuinfo():
keir@18107 114 cpuinfo = {}
keir@18107 115 f = file('/proc/cpuinfo', 'r')
keir@18107 116 try:
keir@18107 117 p = -1
keir@18107 118 d = {}
keir@18107 119 for line in f:
keir@18107 120 keyvalue = line.split(':')
keir@18107 121 if len(keyvalue) != 2:
keir@18107 122 continue
keir@18107 123 key = keyvalue[0].strip()
keir@18107 124 val = keyvalue[1].strip()
keir@18107 125 if key == 'processor':
keir@18107 126 if p != -1:
keir@18107 127 cpuinfo[p] = d
keir@18107 128 p = int(val)
keir@18107 129 d = {}
keir@18107 130 else:
keir@18107 131 d[key] = val
keir@18107 132 cpuinfo[p] = d
keir@18107 133 return cpuinfo
keir@18107 134 finally:
keir@18107 135 f.close()
keir@18107 136
keir@19326 137 def _solaris_get_cpuinfo():
keir@19326 138 cpuinfo = {}
keir@19326 139
keir@19326 140 # call kstat to extrace specific cpu_info output
keir@19326 141 cmd = "/usr/bin/kstat -p -c misc -m cpu_info"
keir@19326 142 kstatoutput = commands.getoutput (cmd)
keir@19326 143
keir@19326 144 # walk each line
keir@19326 145 for kstatline in kstatoutput.split('\n'):
keir@19326 146
keir@19326 147 # split the line on
keir@19326 148 # module:cpu #:module#:name value
keir@19326 149 (module, cpunum, combo, namevalue) = kstatline.split (":")
keir@19326 150
keir@19326 151 # check to see if this cpunum is already a key. If not,
keir@19326 152 # initialize an empty hash table
keir@19326 153 if not cpuinfo.has_key (int(cpunum)):
keir@19326 154 cpuinfo[int(cpunum)] = {}
keir@19326 155
keir@19326 156 # split the namevalue output on whitespace
keir@19326 157 data = namevalue.split()
keir@19326 158
keir@19326 159 # the key will be data[0]
keir@19326 160 key = data[0]
keir@19326 161
keir@19326 162 # check the length of the data list. If it's larger than
keir@19326 163 # 2, join the rest of the list together with a space.
keir@19326 164 # Otherwise, value is just data[1]
keir@19326 165 if len (data) > 2:
keir@19326 166 value = ' '.join (data[1:])
keir@19326 167 else:
keir@19326 168 value = data[1]
keir@19326 169
keir@19326 170 # add this key/value pair to the cpuhash
keir@19326 171 cpuinfo[int(cpunum)][key] = value
keir@19326 172
keir@19326 173 # Translate Solaris tokens into what Xend expects
keir@19326 174 for key in cpuinfo.keys():
keir@19326 175 cpuinfo[key]["flags"] = ""
keir@19326 176 cpuinfo[key]["model name"] = cpuinfo[key]["brand"]
keir@19326 177 cpuinfo[key]["cpu MHz"] = cpuinfo[key]["clock_MHz"]
keir@19326 178
keir@19326 179 # return the hash table
keir@19326 180 return cpuinfo
keir@19326 181
keir@18107 182 _get_cpuinfo = {
keir@19326 183 "SunOS": _solaris_get_cpuinfo
keir@18107 184 }
keir@18107 185
keir@19333 186 def _default_prefork(name):
keir@19333 187 pass
keir@19333 188
keir@19333 189 def _default_postfork(ct, abandon=False):
keir@19333 190 pass
keir@19333 191
keir@19333 192 # call this for long-running processes that should survive a xend
keir@19333 193 # restart
keir@19333 194 def _solaris_prefork(name):
keir@19333 195 from xen.lowlevel import process
keir@19333 196 return process.activate(name)
keir@19333 197
keir@19333 198 def _solaris_postfork(ct, abandon=False):
keir@19333 199 from xen.lowlevel import process
keir@19333 200 process.clear(ct)
keir@19333 201 if abandon:
keir@19333 202 process.abandon_latest()
keir@19333 203
keir@19333 204 _get_prefork = {
keir@19333 205 "SunOS": _solaris_prefork
keir@19333 206 }
keir@19333 207
keir@19333 208 _get_postfork = {
keir@19333 209 "SunOS": _solaris_postfork
keir@19333 210 }
keir@19333 211
kfraser@11860 212 def _get(var, default=None):
kfraser@11860 213 return var.get(os.uname()[0], default)
kfraser@11860 214
kfraser@11860 215 xend_autorestart = _get(_xend_autorestart)
john@13486 216 vif_script = _get(_vif_script, "vif-bridge")
keir@14686 217 lookup_balloon_stat = _get(_balloon_stat, _linux_balloon_stat)
keir@18107 218 get_cpuinfo = _get(_get_cpuinfo, _linux_get_cpuinfo)
keir@19333 219 prefork = _get(_get_prefork, _default_prefork)
keir@19333 220 postfork = _get(_get_postfork, _default_postfork)