aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-11-17 15:54:31 +0000
committerKeir Fraser <keir.fraser@citrix.com>2008-11-17 15:54:31 +0000
commit336c6833737db68e90a4239f5f357a9eb3d860fa (patch)
treee33ba74042d212c0d7fa5b0ca4790d7c41dc9067 /tools
parentb332f3477769d83d1b5c0813639531c258f3c661 (diff)
downloadxen-336c6833737db68e90a4239f5f357a9eb3d860fa.tar.gz
xen-336c6833737db68e90a4239f5f357a9eb3d860fa.tar.bz2
xen-336c6833737db68e90a4239f5f357a9eb3d860fa.zip
tools: use sysfs interface to balloon driver if present
The pvops dom0 kernel does not expose the balloon driver via /proc/xen, so use the sysfs interface. Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/python/xen/xend/osdep.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tools/python/xen/xend/osdep.py b/tools/python/xen/xend/osdep.py
index a026c85277..6636797b44 100644
--- a/tools/python/xen/xend/osdep.py
+++ b/tools/python/xen/xend/osdep.py
@@ -38,7 +38,10 @@ _vif_script = {
"SunOS": "vif-vnic"
}
-def _linux_balloon_stat(label):
+PROC_XEN_BALLOON = '/proc/xen/balloon'
+SYSFS_XEN_MEMORY = '/sys/devices/system/xen_memory/xen_memory0'
+
+def _linux_balloon_stat_proc(label):
"""Returns the value for the named label, or None if an error occurs."""
xend2linux_labels = { 'current' : 'Current allocation',
@@ -47,7 +50,6 @@ def _linux_balloon_stat(label):
'high-balloon' : 'High-mem balloon',
'limit' : 'Xen hard limit' }
- PROC_XEN_BALLOON = '/proc/xen/balloon'
f = file(PROC_XEN_BALLOON, 'r')
try:
for line in f:
@@ -62,6 +64,29 @@ def _linux_balloon_stat(label):
finally:
f.close()
+def _linux_balloon_stat_sysfs(label):
+ sysfiles = { 'target' : 'target_kb',
+ 'current' : 'info/current_kb',
+ 'low-balloon' : 'info/low_kb',
+ 'high-balloon' : 'info/high_kb',
+ 'limit' : 'info/hard_limit_kb' }
+
+ name = os.path.join(SYSFS_XEN_MEMORY, sysfiles[label])
+ f = file(name, 'r')
+
+ val = f.read().strip()
+ if val.isdigit():
+ return int(val)
+ return None
+
+def _linux_balloon_stat(label):
+ if os.access(PROC_XEN_BALLOON, os.F_OK):
+ return _linux_balloon_stat_proc(label)
+ elif os.access(SYSFS_XEN_MEMORY, os.F_OK):
+ return _linux_balloon_stat_sysfs(label)
+
+ return None
+
def _solaris_balloon_stat(label):
"""Returns the value for the named label, or None if an error occurs."""