From 1ad2902bf63bf9c53cdc79c7aa76fd8ffbc5ff9c Mon Sep 17 00:00:00 2001 From: probe Date: Tue, 1 Sep 1992 19:49:14 +0000 Subject: [PATCH] Added a couple functions: afs_vname, afs_partinfo These abstractions were added as they were required by multiple procedures. --- incremental/afs_utils.pl | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/incremental/afs_utils.pl b/incremental/afs_utils.pl index 1c97ecd1..0e1399e1 100644 --- a/incremental/afs_utils.pl +++ b/incremental/afs_utils.pl @@ -23,6 +23,21 @@ $LOCK_UN=8; "UROP", "urop", ); +# Function: afs_vname +# Returns the canonical volume name for (locker,type,cell) +sub afs_vname +{ + local($name,$type,$cell) = @_; + + $vtype = eval "\$vtypes_$cell{$type}"; + return "" unless $vtype; + + $vname = $vtype . "." . $name; + $vname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters + return $vname; +} + + # File format: # cell server partition total used alloc @@ -57,7 +72,8 @@ sub afs_unlock close(SRV); } -# Find server/partition for allocation. +# Function: afs_find +# Finds server/partition for allocation. # # Best fit algorithm used: # max[ (2*free space) - (unused quota) ] @@ -65,31 +81,36 @@ sub afs_unlock # # Note: This routine does not actually adjust the quota; the caller # should use afs_quota_adj(); - sub afs_find { local($cell,$type,$quota) = @_; - local($j); + local($i, $j, $vos, $a); local(@max) = ''; &afs_lock; chop(@afs_data); - for (@afs_data) { - local ($a, $asrv, $apart, $t, $total, $used, $alloc) = split(/\s+/,$_); + for $i ($[ .. $#afs_data) { + ($a, $asrv, $apart, $t, $total, $used, $alloc) = + split(/\s+/, $afs_data[$i]); next if ($a ne $cell || !$total || $type !~ /$t/); $alloc = $used if ($alloc < $used); $j = 2*$total - $used - $alloc; - @max = ($asrv,$apart,$j) if (! @max || $j > $max[2]); + if (! @max || $j > $max[2]) { + ($total, $used) = &afs_partinfo($asrv, $apart, $cell); + next if ($?); + $afs_data[$i]=join(' ',$cell,$asrv,$apart,$t,$total,$used,$alloc); + @max = ($asrv,$apart,$j); + } } &afs_unlock; return(@max); } -# -# Quota adjustments -# + +# Function: afs_quota_adj +# Adjusts the quota allocation for a given server/partition sub afs_quota_adj { local($cell,$asrv,$apart,$adj) = @_; @@ -110,3 +131,20 @@ sub afs_quota_adj &afs_unlock; return($found); } + + +sub afs_partinfo +{ + local($as, $ap, $c) = @_; + local(@vos, $total, $used); + + open(VOS,"$vos partinfo $as $ap -cell $c -noauth|"); + chop(@vos = ); + close(VOS); + return "" if ($?); + + @vos = split(/\s+/,$vos[0]); + $total = pop(@vos); + $used = $total-$vos[5]; + return ($total,$used); +} -- 2.45.1