Changeset 543


Ignore:
Timestamp:
12/15/2011 16:59:40 (5 months ago)
Author:
ccowart
Message:

WIP: Fixing race condition.

Overall design change:

  • Commit modules in _reverse_ order
  • Keep a list of "committed" files and don't re-commit if we encounter the same filesystem path in a later module

I need some help reviewing this change, especially as it relates to the
install operation; I'm not convinced the implementation is complete yet.

See #120.

Location:
branches/confman-1.9
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/confman-1.9/confaudit.in

    r483 r543  
    109109tmproot=$(conf_tmp_dir) 
    110110live_root="${LIVE_ROOT}" 
     111statefile=$(conf_tmp_file) 
    111112 
    112113# Override LIVE_ROOT to commit into our temporary directory. 
     
    116117for layer in $(conf_get_recipe) ; do 
    117118    echo "Rolling on $layer..." 
    118     conf_rollout $layer || conf_cleanExit 
     119    conf_rollout $layer $statefile || conf_cleanExit 
    119120done 
    120121for file in $SINGULARITIES ; do 
  • branches/confman-1.9/confman.in

    r502 r543  
    189189 
    190190function commit { 
    191     local msg status modules module symlink abswork files 
     191    local msg status modules module symlink abswork files statefile 
    192192    local nocommit=true 
    193193    local opt OPTIND OPTARG 
     
    212212    abswork=$(conf_abswork) 
    213213     
    214     for module in $(conf_get_recipe); do 
     214    for module in $(conf_get_reverse_recipe); do 
    215215        modules=${modules:+${modules} }${module} 
    216216        for symlink in $(find ${WORK_PATH}/${module} \ 
     
    236236    echo "Commit operation started" >&2 
    237237    $nocommit || conf_commit_file $msg $files || return $? 
    238     for layer in $(conf_get_recipe) ; do 
     238    statefile=$(conf_tmp_file) 
     239    for layer in $(conf_get_reverse_recipe) ; do 
    239240        echo "Rolling on $layer..." 
    240         conf_rollout $layer || return $? 
     241        conf_rollout $layer $statefile || return $? 
    241242    done 
    242243    for file in $SINGULARITIES ; do 
     
    259260    local opt OPTIND OPTARG 
    260261    local module 
     262    local statefile 
    261263 
    262264    while getopts ":m:F:" opt ; do 
     
    292294    $nocommit || conf_commit_file "$msg" "$files" || return $? 
    293295     
    294     for layer in $(conf_get_recipe) ; do 
     296    for layer in $(conf_get_reverse_recipe) ; do 
    295297        for file in "$@"; do 
    296298            module=$(conf_wfile_module $file) 
    297299            if conf_wfile_is_singularity $file; then 
    298                 conf_install $layer "${file%-$module}-${layer}" 
     300                conf_install $layer $statefile "${file%-$module}-${layer}" 
    299301            else 
    300                 conf_install $layer "$file" 
     302                conf_install $layer $statefile "$file" 
    301303            fi 
    302304        done 
     
    761763    local checkpoint=$2 
    762764    local clock=$3 
    763     local wcopy_lock system_lock 
     765    local wcopy_lock system_lock statefile 
    764766 
    765767    if [ -z "$2" ] ; then 
     
    771773        echo "Rolling $module back to $checkpoint $clock" >&2 
    772774        conf_rollback $module $checkpoint $clock || conf_cleanExit 
    773         for layer in $(conf_get_recipe) ; do 
     775        statefile=$(conf_tmp_file) 
     776        for layer in $(conf_get_reverse_recipe) ; do 
    774777            echo "Rolling on $layer..." 
    775             conf_rollout $layer || conf_cleanExit 
     778            conf_rollout $layer $statefile || conf_cleanExit 
    776779        done 
    777780 
     
    925928        local tmproot=$(conf_tmp_dir) 
    926929        local live_root="${LIVE_ROOT}" 
     930        local statefile 
    927931 
    928932        # Override LIVE_ROOT to commit into our tmporary directory. 
     
    932936 
    933937        echo "Audit operation started" >&2 
    934         for layer in $(conf_get_recipe) ; do 
     938        for layer in $(conf_get_reverse_recipe) ; do 
    935939            echo "Rolling on $layer..." 
    936             conf_rollout $layer || return $? 
     940            conf_rollout $layer $statefile || return $? 
    937941        done >/dev/null 
    938942        for file in $SINGULARITIES ; do 
  • branches/confman-1.9/confmanlib.sh.in

    r516 r543  
    414414} 
    415415 
     416# Test to see if the pathname has been added to a statefile yet 
     417function conf_beenthere { 
     418    local statefile="$1" 
     419    local pathname="$2" 
     420    fgrep -q "$pathname" "$statefile" 
     421} 
     422 
     423# Record this file in the given statefile 
     424function conf_gothere { 
     425    local statefile="$1" 
     426    local pathname="$2" 
     427    echo "$pathname" >> $statefile 
     428} 
     429 
    416430# Roll out the specified module, optionally at the specified checkpoint 
    417 # eg:   conf_rollout MODULE [checkpoint] 
     431# A statefile is a place to record the files that have been rolled out to 
     432# prevent a lower-priority module from installing a committed file. 
     433# eg:   conf_rollout MODULE STATEFILE [checkpoint] 
    418434function conf_rollout { 
    419435        local module="$1" 
    420         if [ -z $2 ] ; then 
     436    local statefile="$2" 
     437        if [ -z $3 ] ; then 
    421438                local moduledir="${WORK_PATH}/$module" 
    422439        else  
     
    436453                local livedir=`echo $directory | ${sed_cmd} -e "s:$moduledir::"` 
    437454                livedir="${LIVE_ROOT}${livedir}" 
    438                 local owner=`conf_get_prop ${directory} owner` 
    439                 local group=`conf_get_prop ${directory} group` 
    440                 local mode=`conf_get_prop ${directory} mode` 
    441                 local opts="-d -o $owner -g $group -m $mode" 
    442                 local cmd="$SUDO $install_cmd $opts $livedir" 
    443                 echo $cmd 
    444                 $cmd 
    445         done 
     455        if ! conf_beenthere $statefile "$livedir" ; then 
     456                    local owner=`conf_get_prop ${directory} owner` 
     457                    local group=`conf_get_prop ${directory} group` 
     458                    local mode=`conf_get_prop ${directory} mode` 
     459                    local opts="-d -o $owner -g $group -m $mode" 
     460                    local cmd="$SUDO $install_cmd $opts $livedir" 
     461                    echo $cmd 
     462            conf_gothere $statefile "$livedir" 
     463                    $cmd 
     464        fi 
     465        done     
    446466        for file in `find -L $moduledir -type f | grep -v "\.svn"` ; do 
    447467                local livefile=`echo "$file" | ${sed_cmd} -e "s:$moduledir::"` 
     
    450470                local mode=`conf_get_prop ${file} mode` 
    451471        local symlink="`conf_get_prop ${file} symlink`" 
    452         file=`$readlink_cmd -m $file` 
    453         if [ -n "$symlink" ]; then 
    454             local cmd="$SUDO ln -snf $symlink ${LIVE_ROOT}$livefile" 
    455             echo $cmd 
    456             $cmd 
    457         else 
    458                     local opts="-o $owner -g $group -m $mode" 
    459                     local cmd="$SUDO $install_cmd $opts $file ${LIVE_ROOT}$livefile" 
     472        livefile="${LIVE_ROOT}${livefile}" 
     473        if ! conf_beenthere $statefile "$livefile" ; then 
     474            file=`$readlink_cmd -m $file` 
     475            if [ -n "$symlink" ]; then 
     476                local cmd="$SUDO ln -snf $symlink $livefile" 
     477            else 
     478                        local opts="-o $owner -g $group -m $mode" 
     479                        local cmd="$SUDO $install_cmd $opts $file $livefile" 
     480            fi 
    460481                    echo $cmd 
     482            conf_gothere $statefile "$livefile" 
    461483                    $cmd 
    462484        fi 
     
    539561    ABS_WORK=$(${readlink_cmd} -m "$WORK_PATH") 
    540562        local module="$1" 
    541     local file="$2" 
     563    local statefile="$2" 
     564    local file="$3" 
    542565    shift 2 
    543566    local livefile 
     
    553576    livefile="/${file#*/}" 
    554577    file="${ABS_WORK}/${module}${livefile}" 
     578    livefile="${LIVE_ROOT}${livefile}" 
    555579 
    556580        # See if it even exists 
    557581    if [ ! -e "$file" ] ; then 
    558582        conf_debug "$file" does not appear to exist 
    559         conf_install $module "$@" 
     583        conf_install $module $statefile "$@" 
    560584        return 1 
    561585    fi 
     
    574598     
    575599    if [ -n "$symlink" ] ; then 
    576         local cmd="$SUDO ln -snf $symlink ${LIVE_ROOT}$livefile" 
    577     else 
    578             local cmd="$SUDO $install_cmd $opts $file ${LIVE_ROOT}$livefile" 
    579     fi 
    580  
    581         ${NFS_HACK:-false} && chmod o+rx ${ABS_WORK} 
    582         echo $cmd 
    583         $cmd || failures=true 
    584         ${NFS_HACK:-false} && chmod o-rx ${ABS_WORK} 
     600        local cmd="$SUDO ln -snf $symlink $livefile" 
     601    else 
     602            local cmd="$SUDO $install_cmd $opts $file $livefile" 
     603    fi 
     604 
     605    if ! conf_beenthere $statefile "$livefile" ; then 
     606            ${NFS_HACK:-false} && chmod o+rx ${ABS_WORK} 
     607            echo $cmd 
     608        conf_gothere $statefile "$lifefile" 
     609            $cmd || failures=true 
     610            ${NFS_HACK:-false} && chmod o-rx ${ABS_WORK} 
     611    fi 
    585612 
    586613    if [ -d "$file" ] ; then 
    587614        conf_debug "conf_install encountered a directory. Recursing." 
    588         conf_install $module $(find "$file" \ 
     615        conf_install $module $statefile $(find "$file" \ 
    589616            -mindepth 1 -maxdepth 1 -not -name '.svn') || failures=true 
    590617    fi 
    591618    conf_debug "conf_install recursing" 
    592         conf_install $module "$@" || failures=true 
     619        conf_install $module $statefile "$@" || failures=true 
    593620    conf_debug "conf_install returning" 
    594621    if $failures ; then  
     
    10131040} 
    10141041 
     1042# Gets a reversed copy of the recipe 
     1043function conf_get_reverse_recipe { 
     1044    local fwd_recipe=$(conf_get_recipe "$@") 
     1045    local rev_recipe 
     1046    for module in $fwd_recipe ; do 
     1047        rev_recipe="$module $rev_recipe" 
     1048    done 
     1049    echo $rev_recipe 
     1050} 
     1051 
    10151052# Spits the recipe, modules separated by whitespace, out on stdout 
    10161053function conf_get_recipe { 
  • branches/confman-1.9/confsync.in

    r486 r543  
    116116sys_revision=`conf_sysrev` 
    117117last_action=$(conf_lastact) 
     118statefile=$(conf_tmp_file) 
    118119 
    119120if [ "x$last_action" = "xinstall" ] && [ $tar_revision -lt $sys_revision ] 
     
    139140for layer in $(conf_get_recipe) ; do 
    140141    echo "Rolling on $layer..." 
    141     conf_rollout $layer || conf_cleanExit 
     142    conf_rollout $layer $statefile || conf_cleanExit 
    142143done 
    143144for file in $SINGULARITIES ; do 
Note: See TracChangeset for help on using the changeset viewer.