+sub get_splitting_args_from_config {
+ my %params = @_;
+
+ use Data::Dumper;
+ my %splitting_args;
+
+ # if dle_splitting is false, then we don't split - easy.
+ if (defined $params{'dle_allow_split'} and !$params{'dle_allow_split'}) {
+ return ();
+ }
+
+ # utility for below
+ my $have_space = sub {
+ my ($dirname, $part_size) = @_;
+
+ use Carp;
+ my $fsusage = Amanda::Util::get_fs_usage($dirname);
+ confess "$dirname" if (!$fsusage);
+
+ my $avail = $fsusage->{'blocks'} * $fsusage->{'bavail'};
+ if ($avail < $part_size) {
+ Amanda::Debug::debug("disk cache has $avail bytes available on $dirname, but " .
+ "needs $part_size");
+ return 0;
+ } else {
+ return 1;
+ }
+ };
+
+ # first, handle the alternate spellings for part_size and part_cache_type
+ $params{'part_size'} = $params{'part_size_kb'} * 1024
+ if (defined $params{'part_size_kb'});
+
+ if (defined $params{'part_cache_type_enum'}) {
+ $params{'part_cache_type'} = 'none'
+ if ($params{'part_cache_type_enum'} == $PART_CACHE_TYPE_NONE);
+ $params{'part_cache_type'} = 'memory'
+ if ($params{'part_cache_type_enum'} == $PART_CACHE_TYPE_MEMORY);
+ $params{'part_cache_type'} = 'disk'
+ if ($params{'part_cache_type_enum'} == $PART_CACHE_TYPE_DISK);
+
+ $params{'part_cache_type'} = 'unknown'
+ unless defined $params{'part_cache_type'};
+ }
+
+ # if any of the dle_* parameters are set, use those to set the part_*
+ # parameters, which are emptied out first.
+ if (defined $params{'dle_tape_splitsize'} or
+ defined $params{'dle_split_diskbuffer'} or
+ defined $params{'dle_fallback_splitsize'}) {
+
+ $params{'part_size'} = $params{'dle_tape_splitsize'} || 0;
+ $params{'part_cache_type'} = 'none';
+ $params{'part_cache_dir'} = undef;
+ $params{'part_cache_max_size'} = undef;
+
+ # part cache type is memory unless we have a split_diskbuffer that fits the bill
+ if ($params{'part_size'}) {
+ $params{'part_cache_type'} = 'memory';
+ if (defined $params{'dle_split_diskbuffer'}
+ and -d $params{'dle_split_diskbuffer'}) {
+ if ($have_space->($params{'dle_split_diskbuffer'}, $params{'part_size'})) {
+ # disk cache checks out, so use it
+ $params{'part_cache_type'} = 'disk';
+ $params{'part_cache_dir'} = $params{'dle_split_diskbuffer'};
+ } else {
+ my $msg = "falling back to memory buffer for splitting: " .
+ "insufficient space in disk cache directory";
+ $splitting_args{'warning'} = $msg;
+ }
+ }
+ }
+
+ if ($params{'part_cache_type'} eq 'memory') {
+ # fall back to 10M if fallback size is not given
+ $params{'part_cache_max_size'} = $params{'dle_fallback_splitsize'} || 10*1024*1024;
+ }
+ } else {
+ my $ps = $params{'part_size'};
+ my $pcms = $params{'part_cache_max_size'};
+ $ps = $pcms if (!defined $ps or (defined $pcms and $pcms < $ps));
+
+ # fail back from 'disk' to 'none' if the disk isn't set up correctly
+ if (defined $params{'part_cache_type'} and
+ $params{'part_cache_type'} eq 'disk') {
+ my $warning;
+ if (!$params{'part_cache_dir'}) {
+ $warning = "no part-cache-dir specified; "
+ . "using part cache type 'none'";
+ } elsif (!-d $params{'part_cache_dir'}) {
+ $warning = "part-cache-dir '$params{part_cache_dir} "
+ . "does not exist; using part cache type 'none'";
+ } elsif (!$have_space->($params{'part_cache_dir'}, $ps)) {
+ $warning = "part-cache-dir '$params{part_cache_dir} "
+ . "has insufficient space; using part cache type 'none'";
+ }
+
+ if (defined $warning) {
+ $splitting_args{'warning'} = $warning;
+ $params{'part_cache_type'} = 'none';
+ delete $params{'part_cache_dir'};
+ }
+ }
+ }
+
+ $splitting_args{'part_size'} = $params{'part_size'}
+ if defined($params{'part_size'});
+ $splitting_args{'part_cache_type'} = $params{'part_cache_type'}
+ if defined($params{'part_cache_type'});
+ $splitting_args{'part_cache_dir'} = $params{'part_cache_dir'}
+ if defined($params{'part_cache_dir'});
+ $splitting_args{'part_cache_max_size'} = $params{'part_cache_max_size'}
+ if defined($params{'part_cache_max_size'});
+
+ return %splitting_args;
+}