Skip to content
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

Merged
merged 18 commits into from
Jul 18, 2016
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ncm-afsclt: fix handling of size AUTOMATIC
Fixes #815.
  • Loading branch information
jouvin committed Jul 15, 2016
commit 4cb5a416bc3598fd13c8a84098c9545d5a07bfce
28 changes: 15 additions & 13 deletions ncm-afsclt/src/main/perl/afsclt.pm
Original file line number Diff line number Diff line change
@@ -106,9 +106,8 @@ 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+)$; ) {
my $afs_cacheinfo_fh = CAF::FileReader->new( $AFS_CACHEINFO, log => $self );
if ( "$afs_cacheinfo_fh" =~ m;^([^:]+):([^:]+):(\d+|AUTOMATIC)$; ) {
$file_afsmount = $1;
$file_cachemount = $2;
$file_cache = $3;
@@ -119,21 +118,24 @@ sub Configure_Cache {
}
$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;
unless ( $new_cache eq "AUTOMATIC" ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 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 ) {
# Force string interpolation of cache size as it can be AUTOMATIC
if ( "$new_cache" ne "$file_cache" ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this check, the AFS_CACHEINIFO is only updated is file_cache is modified, nit file_afsmount or file_cache_mount
i would always write the file, and with the close returns a change in content, do the block below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

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() ) {