[OpenAFS-devel] CACHESIZE AUTOMATIC in afs.rc.linux

Harald Barth haba@pdc.kth.se
Wed, 28 Sep 2005 17:39:41 +0200 (MEST)


The awk test for "own cache partition" can be written better.

df's pretty printing can be hindered with -P (stupid default behaviour
wrapping long dev names even in output to pipe, but what can we do
against a stupid df?)

The whole thing can be written shorter without $LINE and such error prone stuff.

Yes, I think I want $6 and not $NF in awk script below. Falls to safe
side in case of error.

# TEST="awk and sh forever" 
# export TEST
# echo | awk '{print "'"$TEST"'"}'
...

Suggestion of patch below.

Harald.

-----------------------------------------------------------------------------------------------------------


# diff -u ./src/afsd/afs.rc.linux{.orig,}
--- ./src/afsd/afs.rc.linux.orig        2005-03-20 16:02:30.000000000 +0100
+++ ./src/afsd/afs.rc.linux     2005-09-28 17:22:27.565168744 +0200
@@ -215,22 +215,12 @@
 
 generate_cacheinfo() {
     if [ "$CACHESIZE" = "AUTOMATIC" ]; then
-       LINE=`df -k $CACHE | tail -1`
-       PART=`echo $LINE | awk '{ if ( ($NF != "/usr")  && ($NF != "/") ) print $NF; else print "NONE";}'`
-       if [ "$PART" = "NONE" ]; then
-           echo "$CACHE or /usr/vice is not a separate partition"
+       CACHESIZE=`df -Pk "$CACHE" | tail -n 1 | awk '{ if ($6 == "'"$CACHE"'") {printf "%d",int(($2*.8)/1000)*1000 } else {print "NONE"}}'`
+       if [ "$CACHESIZE" = "NONE" ]; then
+           echo "Cache partition $CACHE is not a separate partition"
            echo "you have to change the cachesize in $SYSCNF by hand"
            echo "AFS will be started with a VERY small cache of 8Mb."
            CACHESIZE=8000
-       else
-           # Check to see if df has pretty-printed for long dev (i.e. LVM)
-            FCHAR=`echo $LINE | cut -c 1`
-            if [ "$FCHAR" = "/" ]; then
-                PARTSIZE=`echo $LINE | awk '{print $2}'`
-            else
-                PARTSIZE=`echo $LINE | awk '{print $1}'`
-           fi
-           CACHESIZE=`echo $PARTSIZE | awk '{printf "%d",int(($1*.8)/1000)*1000}'`
        fi
     fi
     if [ "x$CACHESIZE" != "x" ]; then