ia64/xen-unstable

changeset 14686:fbe52b559161

xend: Implement auto-ballooning for Solaris.

/proc/xen/balloon is Linux-specific. Implement a Solaris backend
too. Also fix the FMRI for xend.

Signed-off-by: Ryan Scott <ryan.scott@sun.com>
author Keir Fraser <keir@xensource.com>
date Sat Mar 31 14:05:57 2007 +0100 (2007-03-31)
parents 7b77b47a49d1
children 3a0b808d917a
files tools/python/xen/lowlevel/scf/scf.c tools/python/xen/xend/balloon.py tools/python/xen/xend/osdep.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/scf/scf.c	Sat Mar 31 14:03:17 2007 +0100
     1.2 +++ b/tools/python/xen/lowlevel/scf/scf.c	Sat Mar 31 14:05:57 2007 +0100
     1.3 @@ -26,7 +26,7 @@
     1.4  #include <libscf.h>
     1.5  #include <stdio.h>
     1.6  
     1.7 -#define	XEND_FMRI "svc:/system/xen/xend:default"
     1.8 +#define	XEND_FMRI "svc:/system/xctl/xend:default"
     1.9  #define	XEND_PG "config"
    1.10  
    1.11  static PyObject *scf_exc;
     2.1 --- a/tools/python/xen/xend/balloon.py	Sat Mar 31 14:03:17 2007 +0100
     2.2 +++ b/tools/python/xen/xend/balloon.py	Sat Mar 31 14:05:57 2007 +0100
     2.3 @@ -25,9 +25,7 @@ import XendDomain
     2.4  import XendOptions
     2.5  from XendLogging import log
     2.6  from XendError import VmError
     2.7 -
     2.8 -
     2.9 -PROC_XEN_BALLOON = '/proc/xen/balloon'
    2.10 +import osdep
    2.11  
    2.12  RETRY_LIMIT = 20
    2.13  RETRY_LIMIT_INCR = 5
    2.14 @@ -51,19 +49,7 @@ def _get_proc_balloon(label):
    2.15      """Returns the value for the named label.  Returns None if the label was
    2.16         not found or the value was non-numeric."""
    2.17  
    2.18 -    f = file(PROC_XEN_BALLOON, 'r')
    2.19 -    try:
    2.20 -        for line in f:
    2.21 -            keyvalue = line.split(':')
    2.22 -            if keyvalue[0] == label:
    2.23 -                values = keyvalue[1].split()
    2.24 -                if values[0].isdigit():
    2.25 -                    return int(values[0])
    2.26 -                else:
    2.27 -                    return None
    2.28 -        return None
    2.29 -    finally:
    2.30 -        f.close()
    2.31 +    return osdep.lookup_balloon_stat(label)
    2.32  
    2.33  def get_dom0_current_alloc():
    2.34      """Returns the current memory allocation (in KiB) of dom0."""
     3.1 --- a/tools/python/xen/xend/osdep.py	Sat Mar 31 14:03:17 2007 +0100
     3.2 +++ b/tools/python/xen/xend/osdep.py	Sat Mar 31 14:05:57 2007 +0100
     3.3 @@ -41,6 +41,55 @@ import os
     3.4      "SunOS": "vif-vnic"
     3.5  }
     3.6  
     3.7 +def _linux_balloon_stat(label):
     3.8 +    """Returns the value for the named label, or None if an error occurs."""
     3.9 +
    3.10 +    PROC_XEN_BALLOON = '/proc/xen/balloon'
    3.11 +    f = file(PROC_XEN_BALLOON, 'r')
    3.12 +    try:
    3.13 +        for line in f:
    3.14 +            keyvalue = line.split(':')
    3.15 +            if keyvalue[0] == label:
    3.16 +                values = keyvalue[1].split()
    3.17 +                if values[0].isdigit():
    3.18 +                    return int(values[0])
    3.19 +                else:
    3.20 +                    return None
    3.21 +        return None
    3.22 +    finally:
    3.23 +        f.close()
    3.24 +
    3.25 +def _solaris_balloon_stat(label):
    3.26 +    """Returns the value for the named label, or None if an error occurs."""
    3.27 +
    3.28 +    import fcntl
    3.29 +    import array
    3.30 +    DEV_XEN_BALLOON = '/dev/xen/balloon'
    3.31 +    BLN_IOCTL_CURRENT = 0x4201
    3.32 +    BLN_IOCTL_TARGET = 0x4202
    3.33 +    BLN_IOCTL_LOW = 0x4203
    3.34 +    BLN_IOCTL_HIGH = 0x4204
    3.35 +    BLN_IOCTL_LIMIT = 0x4205
    3.36 +    label_to_ioctl = {	'Current allocation'	: BLN_IOCTL_CURRENT,
    3.37 +			'Requested target'	: BLN_IOCTL_TARGET,
    3.38 +			'Low-mem balloon'	: BLN_IOCTL_LOW,
    3.39 +			'High-mem balloon'	: BLN_IOCTL_HIGH,
    3.40 +			'Xen hard limit'	: BLN_IOCTL_LIMIT }
    3.41 +
    3.42 +    f = file(DEV_XEN_BALLOON, 'r')
    3.43 +    try:
    3.44 +        values = array.array('L', [0])
    3.45 +        if fcntl.ioctl(f.fileno(), label_to_ioctl[label], values, 1) == 0:
    3.46 +            return values[0]
    3.47 +        else:
    3.48 +            return None
    3.49 +    finally:
    3.50 +        f.close()
    3.51 +
    3.52 +_balloon_stat = {
    3.53 +    "SunOS": _solaris_balloon_stat
    3.54 +}
    3.55 +
    3.56  def _get(var, default=None):
    3.57      return var.get(os.uname()[0], default)
    3.58  
    3.59 @@ -49,3 +98,4 @@ xend_autorestart = _get(_xend_autorestar
    3.60  pygrub_path = _get(_pygrub_path, "/usr/bin/pygrub")
    3.61  netback_type = _get(_netback_type, "netfront")
    3.62  vif_script = _get(_vif_script, "vif-bridge")
    3.63 +lookup_balloon_stat = _get(_balloon_stat, _linux_balloon_stat)