| 51 |
|
|
| 52 |
my ($rstr, $size) = @_; |
my ($rstr, $size) = @_; |
| 53 |
# convert size to Bytes |
# convert size to Bytes |
| 54 |
my $size_b = &FAI::convert_unit($size); |
my $size_b = &FAI::convert_unit($size) * 1024.0 * 1024.0; |
| 55 |
# check the format of the string |
# check the format of the string |
| 56 |
($rstr =~ /^(\d+%?)-(\d+%?)$/) or &FAI::internal_error("Invalid range"); |
($rstr =~ /^(\d+(\.\d+)?%?)-(\d+(\.\d+)?%?)$/) or &FAI::internal_error("Invalid range"); |
| 57 |
my ($start, $end) = ($1, $2); |
my ($start, $end) = ($1, $3); |
| 58 |
# start may be given in percents of the size |
# start may be given in percents of the size |
| 59 |
if ($start =~ /^(\d+)%$/) { |
if ($start =~ /^(\d+(\.\d+)?)%$/) { |
| 60 |
# rewrite it to bytes |
# rewrite it to bytes |
| 61 |
$start = POSIX::floor($size_b * $1 / 100); |
$start = POSIX::floor($size_b * $1 / 100); |
| 62 |
} else { |
} else { |
| 65 |
} |
} |
| 66 |
|
|
| 67 |
# end may be given in percents of the size |
# end may be given in percents of the size |
| 68 |
if ( $end =~ /^(\d+)%$/ ) { |
if ( $end =~ /^(\d+(\.\d+)?)%$/ ) { |
| 69 |
# rewrite it to bytes |
# rewrite it to bytes |
| 70 |
$end = POSIX::ceil($size_b * $1 / 100); |
$end = POSIX::ceil($size_b * $1 / 100); |
| 71 |
} else { |
} else { |
| 95 |
# try the entire disk first; we then use the data from the current |
# try the entire disk first; we then use the data from the current |
| 96 |
# configuration; this matches in fact for than the allowable strings, but |
# configuration; this matches in fact for than the allowable strings, but |
| 97 |
# this should be caught later on |
# this should be caught later on |
| 98 |
if ($dev =~ /^\/dev\/[sh]d[a-z]$/) { |
if ($dev =~ m{^/dev/(i2o/hd[a-t]|cciss/c\dd\d|ida/c\dd\d|rd/c\dd\d|ataraid/d\d|sd[a-t]|hd[a-t])$}) { |
| 99 |
defined ($FAI::current_config{$dev}{end_byte}) |
defined ($FAI::current_config{$dev}{end_byte}) |
| 100 |
or die "$dev is not a valid block device\n"; |
or die "$dev is not a valid block device\n"; |
| 101 |
|
|
| 105 |
} |
} |
| 106 |
|
|
| 107 |
# try a partition |
# try a partition |
| 108 |
elsif ($dev =~ /^(\/dev\/[sh]d[a-z])(\d+)$/) { |
elsif ($dev =~ m{^(/dev/(i2o/hd[a-t]|cciss/c\dd\d|ida/c\dd\d|rd/c\dd\d|ataraid/d\d|sd[a-t]|hd[a-t]))p?(\d+)$}) { |
| 109 |
|
|
| 110 |
# the size is configured, return it |
# the size is configured, return it |
| 111 |
defined ($FAI::configs{"PHY_$1"}{partitions}{$2}{size}{eff_size}) |
defined ($FAI::configs{"PHY_$1"}{partitions}{$3}{size}{eff_size}) |
| 112 |
and return $FAI::configs{"PHY_$1"}{partitions}{$2}{size}{eff_size} / |
and return $FAI::configs{"PHY_$1"}{partitions}{$3}{size}{eff_size} / |
| 113 |
(1024 * 1024); |
(1024 * 1024); |
| 114 |
|
|
| 115 |
# the size is known from the current configuration on disk, return it |
# the size is known from the current configuration on disk, return it |
| 116 |
defined ($FAI::current_config{$1}{partitions}{$2}{count_byte}) |
defined ($FAI::current_config{$1}{partitions}{$3}{count_byte}) |
| 117 |
and return $FAI::current_config{$1}{partitions}{$2}{count_byte} / |
and return $FAI::current_config{$1}{partitions}{$3}{count_byte} / |
| 118 |
(1024 * 1024); |
(1024 * 1024); |
| 119 |
|
|
| 120 |
# the size is not known (yet?) |
# the size is not known (yet?) |
| 168 |
|
|
| 169 |
# otherwise we are clueless |
# otherwise we are clueless |
| 170 |
else { |
else { |
| 171 |
die "Cannot determine size of $dev\n"; |
die "Cannot determine size of $dev - scheme unknown\n"; |
| 172 |
} |
} |
| 173 |
} |
} |
| 174 |
|
|
| 215 |
# get the effective sizes (in Bytes) from the range |
# get the effective sizes (in Bytes) from the range |
| 216 |
my ($start, $end) = &FAI::make_range($lv_size->{range}, "${vg_size}MB"); |
my ($start, $end) = &FAI::make_range($lv_size->{range}, "${vg_size}MB"); |
| 217 |
# make them MB |
# make them MB |
| 218 |
$start *= 1024.0 * 1024.0; |
$start /= 1024.0 * 1024.0; |
| 219 |
$end *= 1024.0 * 1024.0; |
$end /= 1024.0 * 1024.0; |
| 220 |
|
|
| 221 |
# increase the used space |
# increase the used space |
| 222 |
$min_space += $start; |
$min_space += $start; |
| 252 |
my ($start, $end) = |
my ($start, $end) = |
| 253 |
&FAI::make_range($FAI::configs{$config}{volumes}{$lv}{size}{range}, "${vg_size}MB"); |
&FAI::make_range($FAI::configs{$config}{volumes}{$lv}{size}{range}, "${vg_size}MB"); |
| 254 |
# make them MB |
# make them MB |
| 255 |
$start *= 1024.0 * 1024.0; |
$start /= 1024.0 * 1024.0; |
| 256 |
$end *= 1024.0 * 1024.0; |
$end /= 1024.0 * 1024.0; |
| 257 |
|
|
| 258 |
# write the final size |
# write the final size |
| 259 |
$FAI::configs{$config}{volumes}{$lv}{size}{eff_size} = |
$FAI::configs{$config}{volumes}{$lv}{size}{eff_size} = |
| 369 |
$part->{size}->{eff_size} = 0; |
$part->{size}->{eff_size} = 0; |
| 370 |
$part->{start_byte} = -1; |
$part->{start_byte} = -1; |
| 371 |
|
|
| 372 |
foreach my $p (sort keys %{ $FAI::configs{$config}{partitions} }) { |
foreach my $p (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} }) { |
| 373 |
next if ($p < 5); |
next if ($p < 5); |
| 374 |
|
|
| 375 |
$part->{start_byte} = $FAI::configs{$config}{partitions}{$p}{start_byte} - |
$part->{start_byte} = $FAI::configs{$config}{partitions}{$p}{start_byte} - |
| 407 |
# reference to the current partition |
# reference to the current partition |
| 408 |
my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id}; |
my $part = (\%FAI::configs)->{$config}->{partitions}->{$part_id}; |
| 409 |
|
|
| 410 |
my ($start, $end) = &FAI::make_range($part->{size}->{range}, $current_disk->{size}); |
my ($start, $end) = &FAI::make_range($part->{size}->{range}, |
| 411 |
|
$current_disk->{size} . "B"); |
| 412 |
|
|
| 413 |
# check, whether the size is fixed |
# check, whether the size is fixed |
| 414 |
if ($end != $start) { |
if ($end != $start) { |
| 415 |
|
|
| 416 |
# the end of the current range (may be the end of the disk or some |
# the end of the current range (may be the end of the disk or some |
| 417 |
# preserved partition |
# preserved partition or an ntfs volume to be resized) |
| 418 |
my $end_of_range = -1; |
my $end_of_range = -1; |
| 419 |
|
|
| 420 |
# minimum space required by all partitions, i.e., the lower ends of the |
# minimum space required by all partitions, i.e., the lower ends of the |
| 430 |
foreach my $p (@{$worklist}) { |
foreach my $p (@{$worklist}) { |
| 431 |
|
|
| 432 |
# we have found the delimiter |
# we have found the delimiter |
| 433 |
if ($FAI::configs{$config}{partitions}{$p}{size}{preserve}) { |
if ($FAI::configs{$config}{partitions}{$p}{size}{preserve} || |
| 434 |
|
($FAI::configs{$config}{partitions}{$p}{size}{resize} && |
| 435 |
|
($current_disk->{partitions}->{$p}->{filesystem} eq "ntfs"))) { |
| 436 |
$end_of_range = $current_disk->{partitions}->{$p}->{begin_byte}; |
$end_of_range = $current_disk->{partitions}->{$p}->{begin_byte}; |
| 437 |
|
|
| 438 |
# logical partitions require the space for the EPBR to be left |
# logical partitions require the space for the EPBR to be left |
| 447 |
next; |
next; |
| 448 |
} else { |
} else { |
| 449 |
my ($min_size, $max_size) = &FAI::make_range( |
my ($min_size, $max_size) = &FAI::make_range( |
| 450 |
$FAI::configs{$config}{partitions}{$p}{size}{range}, $current_disk->{size}); |
$FAI::configs{$config}{partitions}{$p}{size}{range}, |
| 451 |
|
$current_disk->{size} . "B"); |
| 452 |
|
|
| 453 |
# logical partitions require the space for the EPBR to be left |
# logical partitions require the space for the EPBR to be left |
| 454 |
# out |
# out |
| 502 |
$current_disk->{sector_size}; |
$current_disk->{sector_size}; |
| 503 |
} |
} |
| 504 |
|
|
| 505 |
# partition starts at where we currently are |
# partition starts at where we currently are, or remains fixed in case of |
| 506 |
|
# resized ntfs |
| 507 |
|
if ($FAI::configs{$config}{partitions}{$part_id}{size}{resize} && |
| 508 |
|
($current_disk->{partitions}->{$part_id}->{filesystem} eq "ntfs")) { |
| 509 |
|
($next_start <= $current_disk->{partitions}->{$part_id}->{begin_byte}) |
| 510 |
|
or die "Cannot preserve start byte of ntfs volume on partition $part_id, space before it is too small\n"; |
| 511 |
|
$next_start = $current_disk->{partitions}->{$part_id}->{begin_byte}; |
| 512 |
|
} |
| 513 |
$FAI::configs{$config}{partitions}{$part_id}{start_byte} = |
$FAI::configs{$config}{partitions}{$part_id}{start_byte} = |
| 514 |
$next_start; |
$next_start; |
| 515 |
|
|
| 570 |
# nothing to be done, if this is a configuration for a virtual disk |
# nothing to be done, if this is a configuration for a virtual disk |
| 571 |
next if $FAI::configs{$config}{virtual}; |
next if $FAI::configs{$config}{virtual}; |
| 572 |
my $disk = $1; # the device name of the disk |
my $disk = $1; # the device name of the disk |
| 573 |
|
# test, whether $disk is a block special device |
| 574 |
|
(-b $disk) or die "$disk is not a valid device name\n"; |
| 575 |
# reference to the current disk config |
# reference to the current disk config |
| 576 |
my $current_disk = $FAI::current_config{$disk}; |
my $current_disk = $FAI::current_config{$disk}; |
| 577 |
|
|
| 585 |
my $current_extended = -1; |
my $current_extended = -1; |
| 586 |
|
|
| 587 |
# find the first existing extended partition |
# find the first existing extended partition |
| 588 |
foreach my $part_id (sort keys %{ $current_disk->{partitions} }) { |
foreach my $part_id (sort { $a <=> $b } keys %{ $current_disk->{partitions} }) { |
| 589 |
if ($current_disk->{partitions}->{$part_id}->{is_extended}) { |
if ($current_disk->{partitions}->{$part_id}->{is_extended}) { |
| 590 |
$current_extended = $part_id; |
$current_extended = $part_id; |
| 591 |
last; |
last; |
| 620 |
} |
} |
| 621 |
|
|
| 622 |
# the list of partitions that we need to find start and end bytes for |
# the list of partitions that we need to find start and end bytes for |
| 623 |
my @worklist = (sort keys %{ $FAI::configs{$config}{partitions} }); |
my @worklist = (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} }); |
| 624 |
|
|
| 625 |
while (scalar (@worklist)) |
while (scalar (@worklist)) |
| 626 |
{ |
{ |
| 682 |
(defined ($FAI::configs{$config}{partitions}{$_}{start_byte}) |
(defined ($FAI::configs{$config}{partitions}{$_}{start_byte}) |
| 683 |
&& defined ($FAI::configs{$config}{partitions}{$_}{end_byte})) |
&& defined ($FAI::configs{$config}{partitions}{$_}{end_byte})) |
| 684 |
or &FAI::internal_error("start or end of partition $_ not set") |
or &FAI::internal_error("start or end of partition $_ not set") |
| 685 |
foreach (sort keys %{ $FAI::configs{$config}{partitions} }); |
foreach (sort { $a <=> $b } keys %{ $FAI::configs{$config}{partitions} }); |
| 686 |
} |
} |
| 687 |
} |
} |
| 688 |
|
|