-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ncm-afsclt: fix handling of size AUTOMATIC #816
Changes from all commits
4cb5a41
56af89a
7c72faa
845fa03
f508894
d5f71bc
fb49435
5be2b85
c8cb6a4
209704a
79d39f2
c7fae1d
a546dd8
31e8126
5c15bd3
086142f
f9ce48f
f831796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,9 @@ | |
<name>Alan Fitton</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
<developer> | ||
<name>Michel Jouvin</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,55 +25,60 @@ Readonly my $THESECELLS => '/usr/vice/etc/TheseCells'; | |
Readonly my $AFSD_ARGS => '/etc/afsd.args'; | ||
Readonly my $PREFIX => '/software/components/afsclt'; | ||
|
||
Readonly my $AFS_MOUNTPOINT_DEF => '/afs'; | ||
|
||
|
||
sub Configure { | ||
my ( $self, $config ) = @_; | ||
$self->Configure_Cell($config); | ||
$self->Configure_TheseCells($config); | ||
$self->Configure_Cache($config); | ||
$self->Configure_CellServDB($config); | ||
$self->Configure_Afsd_Args($config); | ||
|
||
my $afsclt_config = $config->getElement($PREFIX)->getTree(); | ||
|
||
$self->Configure_Cell($afsclt_config); | ||
$self->Configure_TheseCells($afsclt_config); | ||
$self->Configure_Cache($afsclt_config); | ||
$self->Configure_CellServDB($afsclt_config); | ||
$self->Configure_Afsd_Args($afsclt_config); | ||
} | ||
|
||
sub Configure_Cell { | ||
my ( $self, $config ) = @_; | ||
unless ( $config->elementExists("$PREFIX/thiscell") ) { | ||
$self->error("Cannot get $PREFIX/thiscell (required in profile)"); | ||
unless ( defined($config->{thiscell}) ) { | ||
$self->error("$PREFIX/thiscell missing in the configuration"); | ||
return 1; | ||
} | ||
|
||
my $afscell = $config->getValue("$PREFIX/thiscell"); | ||
my $thiscell_fh = CAF::FileWriter->new( $THISCELL, log => $self ); | ||
print $thiscell_fh "$afscell\n"; | ||
print $thiscell_fh "$config->{thiscell}\n"; | ||
|
||
if ( $thiscell_fh->close() ) { | ||
$self->info("Updated thiscell to $afscell"); | ||
$self->info("Updated thiscell to $config->{thiscell}"); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
sub Configure_TheseCells { | ||
my ( $self, $config ) = @_; | ||
|
||
if ( $config->elementExists("$PREFIX/thesecells") ) { | ||
my $cells = $config->getElement("$PREFIX/thesecells")->getTree(); | ||
if ( defined($config->{thesecells}) ) { | ||
my $thesecells_fh = CAF::FileWriter->new( $THESECELLS, log => $self ); | ||
print $thesecells_fh join ( " ", @$cells ) . "\n"; | ||
print $thesecells_fh join ( " ", @{$config->{thesecells}} ) . "\n"; | ||
if ( $thesecells_fh->close() ) { | ||
$self->info("Configured cell list for authentication $THESECELLS"); | ||
} | ||
} | ||
elsif ( -f $THESECELLS ) { | ||
} elsif ( -f $THESECELLS ) { | ||
if ($NoAction) { | ||
$self->info("Would remove $THESECELLS"); | ||
} | ||
else { | ||
} else { | ||
if ( unlink($THESECELLS) ) { | ||
$self->info("Removed cell list for authentication $THESECELLS"); | ||
} | ||
else { | ||
} else { | ||
$self->error("Could not remove $THESECELLS: $!"); | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
sub Configure_Cache { | ||
|
@@ -85,14 +90,25 @@ sub Configure_Cache { | |
my $new_cache = 0; # in 1k blocks. | ||
my $file_afsmount = ''; | ||
|
||
if ( $config->elementExists("$PREFIX/cachesize") ) { | ||
$new_cache = $config->getValue("$PREFIX/cachesize"); #new cache size | ||
} | ||
else { | ||
$self->info("Cannot get CDB $PREFIX/cachesize - not setting cache size"); | ||
if ( defined($config->{cachesize}) ) { | ||
$new_cache = $config->{cachesize} | ||
} else { | ||
$self->info("$PREFIX/cachesize undefined: not setting cache size"); | ||
return 1; | ||
} | ||
|
||
if ( defined($config->{cachemount}) ) { | ||
$file_cachemount = $config->{cachemount}; # mount point for AFS cache partition | ||
} else { | ||
$self->debug(1, "No explicit cache mount point defined in the configuration: will use currently defined one, if any"); | ||
} | ||
|
||
if ( defined($config->{afs_mount}) ) { | ||
$file_afsmount = $config->{afs_mount}; # AFS mount point | ||
} else { | ||
$self->debug(1, "No explicit AFS mount point defined in the configuration"); | ||
} | ||
|
||
my $proc = CAF::Process->new( [ "fs", "getcacheparms" ], log => $self, keeps_state => 1 ); | ||
my $output = $proc->output(); | ||
if ( !( $? >> 8 ) && $output =~ /AFS using \d+ of the cache's available (\d+) (\w+) byte blocks/ ) { | ||
|
@@ -106,39 +122,45 @@ sub Configure_Cache { | |
$self->warn("Cannot determine current AFS cache size, changing only config file"); | ||
} | ||
|
||
my $afs_cacheinfo_fh = CAF::FileEditor->new( $AFS_CACHEINFO, log => $self ); # TODO use FileReader | ||
$afs_cacheinfo_fh->cancel(); | ||
if ( "$afs_cacheinfo_fh" =~ m;^([^:]+):([^:]+):(\d+)$; ) { | ||
$file_afsmount = $1; | ||
$file_cachemount = $2; | ||
my $afs_cacheinfo_fh = CAF::FileReader->new( $AFS_CACHEINFO, log => $self ); | ||
$self->debug(2, "$AFS_CACHEINFO current contents: >>>$afs_cacheinfo_fh<<<"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only in else block? (and in that case, maybe in the error message) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, I realized that my mod was wrong because if was no longer possible to override value in |
||
if ( "$afs_cacheinfo_fh" =~ m;^([^:]+):([^:]+):(\d+|AUTOMATIC)$; ) { | ||
$file_afsmount = $1 if $file_afsmount eq ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these cannot be emtpy, since the regex have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure to understand... You probably misread... The point is that you use the value from the file only if it is not defined in the configuration (in which case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, i misread. |
||
$file_cachemount = $2 if $file_cachemount eq ""; | ||
$file_cache = $3; | ||
} | ||
else { | ||
} elsif ( "$afs_cacheinfo_fh" ne "" ) { | ||
$self->error("Cannot parse stored AFS cache mount or size from $AFS_CACHEINFO"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the unparseable content in the message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it adds anything... It is enough to look at fhe |
||
return 1; | ||
} else { | ||
$self->debug(1, "No existing cacheinfo file found"); | ||
} | ||
$afs_cacheinfo_fh->close(); | ||
|
||
# sanity check - don't allow cachesize bigger than 95% of a partition size | ||
$proc = CAF::Process->new( [ "df", "-k", $file_cachemount ], log => $self, keeps_state => 1 ); | ||
foreach my $line ( split ( "\n", $proc->output() ) ) { | ||
if ($line =~ m{^.*?\s+(\d+)\s+\d+\s+\d+\s+\d+%\s+(.*)}) { | ||
my $disk_cachesize = $1; | ||
my $mount = $2; | ||
if ( $mount eq $file_cachemount && $new_cache > 0.95 * $disk_cachesize ) { | ||
$self->error("Cache size ($disk_cachesize) on $mount cannot exceed 95% of its partition size. Not changing."); | ||
return 1; | ||
if ( $new_cache ne "AUTOMATIC" ) { | ||
# sanity check - don't allow cachesize bigger than 95% of a partition size | ||
$proc = CAF::Process->new( [ "df", "-k", $file_cachemount ], log => $self, keeps_state => 1 ); | ||
foreach my $line ( split ( "\n", $proc->output() ) ) { | ||
if ($line =~ m{^.*?\s+(\d+)\s+\d+\s+\d+\s+\d+%\s+(.*)}) { | ||
my $disk_cachesize = $1; | ||
my $mount = $2; | ||
if ( $mount eq $file_cachemount && $new_cache > 0.95 * $disk_cachesize ) { | ||
$self->error("Cache size ($disk_cachesize) on $mount cannot exceed 95% of its partition size. Not changing."); | ||
return 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
# adjust stored cache size (gets overwritten on restart for OpenAFS-1.4) | ||
if ( $new_cache != $file_cache ) { | ||
my $afs_cacheinfo_fh = CAF::FileWriter->new( $AFS_CACHEINFO, log => $self ); | ||
print $afs_cacheinfo_fh "$file_afsmount:$file_cachemount:$new_cache\n"; | ||
if ( $afs_cacheinfo_fh->close() ) { | ||
$self->info("Changed AFS cache config file $AFS_CACHEINFO: $file_cachemount $run_cache -> $new_cache (1K blocks)"); | ||
} | ||
# Adjust cacheinfo file if needed. | ||
# Force string interpolation of cache size as it can be AUTOMATIC | ||
if ( $file_afsmount eq "" ) { | ||
$self->debug(1, "AFS mount point not defined: using default ($AFS_MOUNTPOINT_DEF)"); | ||
$file_afsmount = $AFS_MOUNTPOINT_DEF; | ||
} | ||
my $afs_cacheinfo_fh = CAF::FileWriter->new( $AFS_CACHEINFO, log => $self ); | ||
print $afs_cacheinfo_fh "$file_afsmount:$file_cachemount:$new_cache\n"; | ||
if ( $afs_cacheinfo_fh->close() ) { | ||
$self->info("Changed AFS cache config ($AFS_CACHEINFO). New cache size (1K blocks): $new_cache (current: $run_cache)"); | ||
} | ||
|
||
# adjust online (in-kernel) value | ||
|
@@ -152,22 +174,22 @@ sub Configure_Cache { | |
$self->info("Changed running AFS cache $run_cache -> $new_cache (1K blocks)"); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
sub Configure_CellServDB { | ||
my ( $self, $config ) = @_; | ||
my $master_cellservdb; | ||
if ( $config->elementExists("$PREFIX/cellservdb") ) { | ||
$master_cellservdb = $config->getValue("$PREFIX/cellservdb"); | ||
if ( defined($config->{cellservdb}) ) { | ||
$master_cellservdb = $config->{cellservdb}; | ||
if ( $master_cellservdb =~ m/^\/\w/i ) { # non-URI -> file | ||
$master_cellservdb = "file://" . $master_cellservdb; | ||
} | ||
elsif ( $master_cellservdb !~ m/^(ftp|http|file)/i ) { # known URIs | ||
$self->error("Don't know how to handle URI: $master_cellservdb, giving up"); | ||
} elsif ( $master_cellservdb !~ m/^(ftp|http|file)/i ) { # known URIs | ||
$self->error("Unsupported protocol to access master CellServDB ($master_cellservdb), giving up"); | ||
return 1; | ||
} | ||
} | ||
else { | ||
} else { | ||
return 0; | ||
} | ||
|
||
|
@@ -183,9 +205,8 @@ sub Configure_CellServDB { | |
if ($cellservdb_fh->close()) { | ||
$self->info("Updated CellServDB"); | ||
} | ||
$self->update_afs_cells(); | ||
|
||
return 1; | ||
return $self->update_afs_cells(); | ||
} | ||
|
||
# update the list of known AFS cells and run "fs newcell" when needed | ||
|
@@ -201,8 +222,7 @@ sub update_afs_cells ( $$ ) { | |
if ($line =~ /^>(.\S+)/) { | ||
$cell = $1; | ||
$ipaddrs{$cell} = []; | ||
} | ||
elsif ($line =~ /^(\S+)\s+\#\s*\S+/) { | ||
} elsif ($line =~ /^(\S+)\s+\#\s*\S+/) { | ||
# new entry | ||
push ( @{ $ipaddrs{$cell} }, $1 ); | ||
} | ||
|
@@ -262,21 +282,24 @@ sub update_afs_cells ( $$ ) { | |
else { | ||
$self->info("Nothing to do for AFS cell information"); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
sub Configure_Afsd_Args { | ||
my ( $self, $config ) = @_; | ||
|
||
if ( $config->elementExists("$PREFIX/afsd_args") ) { | ||
my $args = $config->getElement("$PREFIX/afsd_args")->getTree(); | ||
if ( defined($config->{afsd_args}) ) { | ||
my $fh = CAF::FileWriter->new( $AFSD_ARGS, log => $self, backup => ".old" ); | ||
foreach my $key (sort keys %$args) { | ||
print $fh "$key:" . $args->{$key} . "\n"; | ||
foreach my $key (sort keys %{$config->{afsd_args}}) { | ||
print $fh "$key:$config->{afsd_args}->{$key}\n"; | ||
} | ||
if ( $fh->close() ) { | ||
$self->info("Updated afsd.args"); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
1; #required for Perl modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this is a retrograde step for readability. I now need to locate this type defined in some other file before I can understand how to populate this mandatory field, which has no default. legacy_yes_or_no_string would be more intuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree... I was thinking the same thing when doing the modification suggested by @stdweird ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open an issue to change. This is work done in quattor/template-library-core#111 and #749; but renaming the type should be very trivial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. quattor/template-library-core#118.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it would be better to make the effort to change the type to boolean instead of renaming the legacy type.