Changeset 2771

Show
Ignore:
Timestamp:
08/24/08 22:12:08 (3 months ago)
Author:
dhozac
Message:

cgroup support.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doc/configuration.xml

    r2740 r2771  
    305305        <description>The default /etc/resolv.conf file.</description> 
    306306      </data> 
     307    </collection> 
     308 
     309    <collection name="cgroup" use="optional" since="0.30.216" id="global-cgroup"> 
     310      <description> 
     311This directory contains cgroup settings which should be applied to all guests. 
     312See your kernel documentation for what settings are valid with your 
     313configuration. 
     314      </description> 
     315      <scalar name="mnt"> 
     316        <description> 
     317The directory to mount the cgroup hierarchy at. The default is /dev/cgroup. 
     318        </description> 
     319      </scalar> 
     320      <scalar name="subsys"> 
     321        <description> 
     322Comma-separated list of subsystems to enable on the cgroup mount point. 
     323The default is "all". 
     324        </description> 
     325      </scalar> 
     326      <list name="inherit"> 
     327        <description> 
     328Some subsystems start out with clean slates, making it impossible to use the 
     329cgroup before certain things have been set. This is true for e.g. the cpuset 
     330subsystem. This file contains a list of filenames which should be explicitly 
     331inherited from the parent (root) cgroup, if not overridden elsewhere. 
     332The default is cpuset.cpus and cpuset.mems. 
     333        </description> 
     334      </list> 
     335      <scalar name="name" id="global-cgroup-name"> 
     336        <description> 
     337If this file exists, all guests will be put in one cgroup named after the 
     338contents of this file. The default is to put each guest in a cgroup named the 
     339same thing as the guest. 
     340        </description> 
     341      </scalar> 
    307342    </collection> 
    308343  </collection> 
     
    16201655      </scalar> 
    16211656    </collection> 
     1657 
     1658    <collection name="cgroup" use="optional" since="0.30.216" id="guest-cgroup"> 
     1659      <description> 
     1660This directory contains cgroup settings to be applied to this guest. 
     1661See your kernel documentation for what settings are valid with your 
     1662configuration. 
     1663      </description> 
     1664      <scalar name="name"> 
     1665        <description> 
     1666If this file exists, the guest will be put in a cgroup named after the 
     1667contents of this file. The default is to name the cgroup the same thing as the 
     1668guest, unless 
     1669<optionref ref="global-cgroup-name">.defaults/cgroup/name</optionref> says 
     1670otherwise. 
     1671        </description> 
     1672      </scalar> 
     1673    </collection> 
     1674    <scalar name="nocgroup" since="0.30.216"> 
     1675      <description> 
     1676If this file exists, 
     1677<optionref ref="global-cgroup">.defaults/cgroup</optionref> will be ignored 
     1678for this guest. 
     1679      </description> 
     1680    </scalar> 
    16221681  </collection> 
    16231682  </database> 
  • trunk/scripts/vserver.functions

    r2744 r2771  
    7171 
    7272SILENT_OPT= 
     73 
     74CGROUP_MNT=/dev/cgroup 
     75CGROUP_SUBSYS=all 
     76declare -a CGROUP_INHERIT=( cpuset.cpus cpuset.mems ) 
    7377 
    7478: ${VSERVER_NAME:=$(basename "$VSERVER_DIR")} 
     
    832836    _generateMemctrlOptions     "$1" 
    833837    _generateSpaceOptions       "$1" 
     838    _generateCgroupOptions 
    834839 
    835840    if test -n "$_IS_FAKEINIT"; then 
     
    13961401    done 
    13971402} 
     1403 
     1404function hasCgroup 
     1405{ 
     1406    $_GREP -q "cgroup" /proc/filesystems 
     1407} 
     1408 
     1409function _generateCgroupOptions 
     1410{ 
     1411    local file 
     1412 
     1413    hasCgroup || return 0 
     1414 
     1415    findFile file "$__CONFDIR/.defaults/cgroup/mnt" "" 
     1416    if test -n "$file"; then 
     1417        read CGROUP_MNT < "$file" 
     1418    fi 
     1419    findFile file "$__CONFDIR/.defaults/cgroup/subsys" "" 
     1420    if test -n "$file"; then 
     1421        read CGROUP_SUBSYS < "$file" 
     1422    fi 
     1423    findFile file "$__CONFDIR/.defaults/cgroup/inherit" "" 
     1424    if test -n "$file"; then 
     1425        _readFileToArray CGROUP_INHERIT "$file" "" 
     1426    fi 
     1427 
     1428    return 0 
     1429} 
     1430 
     1431function useCgroup 
     1432{ 
     1433    hasCgroup || return 1 
     1434    test -d "$CGROUP_MNT" || return 1 
     1435    test -d "$1/cgroup" -o \ 
     1436        \( -d "$__CONFDIR/.defaults/cgroup" -a \ 
     1437           ! -e "$1/nocgroup" \) 
     1438} 
     1439 
     1440function _handleCgroup 
     1441{ 
     1442    local action="$1" 
     1443    local vdir="$2" 
     1444    local dir 
     1445    local name 
     1446    local i 
     1447    local parent 
     1448 
     1449    useCgroup "$vdir" || return 0 
     1450 
     1451    findDir dir "$vdir/cgroup" "$__CONFDIR/.defaults/cgroup" "" 
     1452    test -d "$dir" || return 0 
     1453 
     1454    if test -r "$dir"/name; then 
     1455        read name < "$dir"/name 
     1456    else 
     1457        read name < "$vdir"/name 
     1458    fi 
     1459 
     1460    if test "$action" = "attach"; then 
     1461        if mkdir "$CGROUP_MNT/$name" 2>/dev/null; then 
     1462            parent="$CGROUP_MNT/$name" 
     1463            parent="${parent%/*}" 
     1464            for i in "${CGROUP_INHERIT[@]}"; do 
     1465                test -f "$parent/$i" || continue 
     1466                cat "$parent/$i" > "$CGROUP_MNT/$name/$i" 
     1467            done 
     1468 
     1469            shopt -s nullglob 
     1470            for i in "$dir"/*; do 
     1471                cat "$i" > "$CGROUP_MNT/$name/${i##*/}" 
     1472            done 
     1473        fi 
     1474        echo "$$" > "$CGROUP_MNT/$name/tasks" 
     1475    elif test "$action" = "destroy"; then 
     1476        rmdir "$CGROUP_MNT/$name" 2>/dev/null || : 
     1477    fi 
     1478 
     1479    return 0 
     1480} 
     1481 
     1482function attachToCgroup 
     1483{ 
     1484    _handleCgroup attach "$@" 
     1485} 
     1486 
     1487function destroyCgroup 
     1488{ 
     1489    _handleCgroup destroy "$@" 
     1490} 
  • trunk/scripts/vserver.start

    r2736 r2771  
    122122prepareInit      "$VSERVER_DIR" 
    123123addtoCPUSET      "$VSERVER_DIR" 
     124attachToCgroup   "$VSERVER_DIR" 
    124125 
    125126handleDeviceMap --set "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap" 
  • trunk/scripts/vserver.stop

    r2736 r2771  
    127127execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" postpost-stop 
    128128removeCPUSET      "$VSERVER_DIR" 
     129destroyCgroup     "$VSERVER_DIR" 
  • trunk/sysv/util-vserver

    r2749 r2771  
    5353} 
    5454 
     55function mount_cgroup() 
     56{ 
     57    _generateCgroupOptions 
     58    test -n "$CGROUP_MNT" || return 0 
     59    $_MKDIR -p "$CGROUP_MNT" 
     60    $_MOUNT -t cgroup -o "$CGROUP_SUBSYS" vserver "$CGROUP_MNT" 
     61} 
     62 
    5563function start() 
    5664{ 
     
    6573    handleDeviceMap --set 0 "$__CONFDIR/.defaults/apps/vdevmap" 
    6674    _endResult $? 
     75    if hasCgroup; then 
     76        _beginResult $"Mounting cgroup-hierarchy" 
     77        mount_cgroup 
     78        _endResult $? 
     79    fi 
    6780    test "$retval" -ne 0 || touch "$lockfile" 
    6881    return $retval