From aeae30cc5b1a9038602944122c4c0f30fb54db86 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Thu, 25 Feb 2010 14:52:57 +0000 Subject: [PATCH] -two new optins: bind and bind,perssistent is added for the statelite mode support git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5296 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/statelite.pm | 55 +++++++++++++++---- .../netboot/add-on/statelite/rc.statelite | 37 ++++++++++++- 2 files changed, 79 insertions(+), 13 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/statelite.pm b/xCAT-server/lib/xcat/plugins/statelite.pm index 285fb2b6c..0e5357478 100644 --- a/xCAT-server/lib/xcat/plugins/statelite.pm +++ b/xCAT-server/lib/xcat/plugins/statelite.pm @@ -189,22 +189,35 @@ sub process_request { return; } - # all I care about are the files, not the characteristics at this point: + # this line is TOO OLD: all I care about are the files, not the characteristics at this point: + # We need to consider the characteristics of the file if the option is "bind,persistent" or "bind" my @files; + my @bindedFiles; foreach my $line (@synclist){ foreach (@{$line}){ - my $f = (split(/\s+/, $_))[2]; - if($f =~ /^\//){ - push @files, $f; - }else{ - # make sure each file begins with "/" - $callback->({error=>["$f in litefile does not begin with absolute path! Need a '/' in the beginning"],errorcode=>[1]}); - return; - } + my @entry = split(/\s+/, $_); + my $f = $entry[2]; + if($entry[1] =~ m/bind/) { + if($f =~ /^\//) { + push @bindedFiles, $f; + }else { + # make sure each file begins with "/" + $callback->({error=>["$f in litefile does not begin with absolute path! Need a '/' in the beginning"],errorcode=>[1]}); + return; + } + } else { + if($f =~ /^\//){ + push @files, $f; + }else{ + # make sure each file begins with "/" + $callback->({error=>["$f in litefile does not begin with absolute path! Need a '/' in the beginning"],errorcode=>[1]}); + return; + } + } } } - liteMe($rootimg_dir,\@files, $callback); + liteMe($rootimg_dir,\@files, \@bindedFiles, $callback); @@ -216,6 +229,10 @@ sub liteMe { # Arg 1: root image dir: /install/netboot/centos5.3/x86_64/compute/rootimg my $rootimg_dir = shift; my $files = shift; + my $bindedFiles = shift; + use Data::Dumper; + print Dumper($files); + print Dumper($bindedFiles); # Arg 2: callback ref to make comments... my $callback = shift; unless(-d $rootimg_dir){ @@ -227,6 +244,24 @@ sub liteMe { mkpath("$rootimg_dir/$statedir/tmpfs"); # now make a place for all the files. + # this loop uses "mount --bind" to mount files instead of creating symbolic links for + # each of the files in the @$bindedFiles sync list; + # 1. copy original contents if they exist to .default directory + foreach my $f (@$bindedFiles) { + print Dumper($f); + # copy the file to /.defaults + my $rif = $rootimg_dir . $f; + my $d = dirname($f); + + if( !(-e "$rootimg_dir/.default$d") ) { + $verbose && $callback->({info=>["mkdir -p $rootimg_dir/.default$d"]}); + system("mkdir -p $rootimg_dir/.default$d"); + } + + # copy the file in place. + $verbose && $callback->({info=>["cp -a $rif $rootimg_dir/.default$d"]}); + system("cp -a $rif $rootimg_dir/.default$d"); + } # this loop creates symbolic links for each of the files in the sync list. # 1. copy original contents if they exist to .default directory diff --git a/xCAT-server/share/xcat/netboot/add-on/statelite/rc.statelite b/xCAT-server/share/xcat/netboot/add-on/statelite/rc.statelite index cb5268706..05cb7f4dc 100755 --- a/xCAT-server/share/xcat/netboot/add-on/statelite/rc.statelite +++ b/xCAT-server/share/xcat/netboot/add-on/statelite/rc.statelite @@ -145,8 +145,13 @@ ProcessType () { case "${3}" in tmpfs,rw) - cp -a ${1} ${TMPFS}${2} - echo "cp -a ${1} ${TMPFS}${2}" >>$LOG + if [ -d ${TMPFS}${2} ]; then + cp -a ${1}* ${TMPFS}${2} + echo "cp -a ${1}* ${TMPFS}${2}" >>$LOG + else + cp -a ${1} ${TMPFS}${2} + echo "cp -a ${1} ${TMPFS}${2}" >>$LOG + fi # the link will already be in place on the image, so nothing else to do! #mount -n --bind ${TMPFS}${2} ${1} ;; @@ -154,8 +159,34 @@ ProcessType () { # cons go in tmpfs cat ${1} >>${TMPFS}${2} echo "cat ${1} >>${TMPFS}${2}" >>$LOG - ;; + bind) + ORIG=`echo ${2} | sed -e 's/\/$//'` + TARGET=`echo ${1}` + + echo "mount --bind /${TARGET} /sysroot/${ORIG}" >>$LOG + mount --bind ${TARGET} /sysroot/${ORIG}>>$LOG 2>&1 + ;; + bind,persistent) + if [ ! -d ${PERSISTENT}`dirname ${2}` ] + then + mkdir -p ${PERSISTENT}`dirname ${2}` + echo "mkdir -p ${PERSISTENT}`dirname ${2}`" >>$LOG + fi + + # if the file doesn't exist, then copy it over to persistent + if [ ! -e ${PERSISTENT}${2} ] + then + echo "cp -a ${1} ${PERSISTENT}${2}" >>$LOG + cp -a ${1} ${PERSISTENT}${2} 2>&1 >>$LOG + fi + + ORIG=`echo ${2} | sed -e 's/\/$//'` + TARGET=`echo ${PERSISTENT}${2}` + + echo "mount --bind ${TARGET} /sysroot/${ORIG}" >>$LOG + mount --bind ${TARGET} /sysroot/${ORIG}>>$LOG 2>&1 + ;; persistent*) # everything from root image points to tmpfs # so have tmpfs point to persistent