ia64/xen-unstable

changeset 18801:17911073a90a

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>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Nov 17 15:54:31 2008 +0000 (2008-11-17)
parents 2188ed106885
children 7dd722064128
files tools/python/xen/xend/osdep.py
line diff
     1.1 --- a/tools/python/xen/xend/osdep.py	Fri Nov 14 14:33:25 2008 +0000
     1.2 +++ b/tools/python/xen/xend/osdep.py	Mon Nov 17 15:54:31 2008 +0000
     1.3 @@ -38,7 +38,10 @@ import os
     1.4      "SunOS": "vif-vnic"
     1.5  }
     1.6  
     1.7 -def _linux_balloon_stat(label):
     1.8 +PROC_XEN_BALLOON = '/proc/xen/balloon'
     1.9 +SYSFS_XEN_MEMORY = '/sys/devices/system/xen_memory/xen_memory0'
    1.10 +
    1.11 +def _linux_balloon_stat_proc(label):
    1.12      """Returns the value for the named label, or None if an error occurs."""
    1.13  
    1.14      xend2linux_labels = { 'current'      : 'Current allocation',
    1.15 @@ -47,7 +50,6 @@ def _linux_balloon_stat(label):
    1.16                            'high-balloon' : 'High-mem balloon',
    1.17                            'limit'        : 'Xen hard limit' }
    1.18  
    1.19 -    PROC_XEN_BALLOON = '/proc/xen/balloon'
    1.20      f = file(PROC_XEN_BALLOON, 'r')
    1.21      try:
    1.22          for line in f:
    1.23 @@ -62,6 +64,29 @@ def _linux_balloon_stat(label):
    1.24      finally:
    1.25          f.close()
    1.26  
    1.27 +def _linux_balloon_stat_sysfs(label):
    1.28 +    sysfiles = { 'target'       : 'target_kb',
    1.29 +                 'current'      : 'info/current_kb',
    1.30 +                 'low-balloon'  : 'info/low_kb',
    1.31 +                 'high-balloon' : 'info/high_kb',
    1.32 +                 'limit'        : 'info/hard_limit_kb' }
    1.33 +
    1.34 +    name = os.path.join(SYSFS_XEN_MEMORY, sysfiles[label])
    1.35 +    f = file(name, 'r')
    1.36 +
    1.37 +    val = f.read().strip()
    1.38 +    if val.isdigit():
    1.39 +        return int(val)
    1.40 +    return None
    1.41 +
    1.42 +def _linux_balloon_stat(label):
    1.43 +	if os.access(PROC_XEN_BALLOON, os.F_OK):
    1.44 +		return _linux_balloon_stat_proc(label)
    1.45 +	elif os.access(SYSFS_XEN_MEMORY, os.F_OK):
    1.46 +		return _linux_balloon_stat_sysfs(label)
    1.47 +
    1.48 +	return None
    1.49 +
    1.50  def _solaris_balloon_stat(label):
    1.51      """Returns the value for the named label, or None if an error occurs."""
    1.52