/[fai]/branches/experimental/patches/setup-storage_resize2fs
ViewVC logotype

Contents of /branches/experimental/patches/setup-storage_resize2fs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5766 - (show annotations) (download)
Tue Apr 13 08:39:38 2010 UTC (3 years, 1 month ago) by mt
File size: 7981 byte(s)
run e2fsck before resize2fs
1 2010-04-06 Michael Tautschnig <mt@debian.org>
2
3 * setup-storage/{Volumes.pm,Sizes.pm}: eff_size is bytes. Always.
4 * setup-storage/Commands.pm: Prefer resize2fs over parted to resize logical
5 volumes. Future versions of parted will allow even more use of resize2fs.
6 Fix use of eff_size as bytes.
7 Index: trunk/lib/setup-storage/Commands.pm
8 ===================================================================
9 --- trunk.orig/lib/setup-storage/Commands.pm
10 +++ trunk/lib/setup-storage/Commands.pm
11 @@ -496,18 +496,38 @@
12 or die "Resized volume $vg/$lv does not exist\n";
13 warn "$vg/$lv will be resized\n";
14
15 - if ($lv_size->{eff_size} <
16 - $FAI::current_lvm_config{$vg}{volumes}{$lv}{size})
17 + use POSIX qw(floor);
18 +
19 + my $lvsize_mib = &FAI::convert_unit($lv_size->{eff_size} . "B");
20 + if ($lvsize_mib < $FAI::current_lvm_config{$vg}{volumes}{$lv}{size})
21 {
22 - &FAI::push_command( "parted -s /dev/$vg/$lv resize 1 0 " . $lv_size->{eff_size} . "B",
23 - "vg_enabled_$vg,$lv_rm_pre", "lv_shrink_$vg/$lv" );
24 - &FAI::push_command( "lvresize -L " . $lv_size->{eff_size} . " $vg/$lv",
25 + if (($FAI::configs{$config}{volumes}{$lv}{filesystem} =~
26 + /^ext[23]$/) && &FAI::in_path("resize2fs")) {
27 + my $block_count = POSIX::floor($lv_size->{eff_size} / 512);
28 + &FAI::push_command( "e2fsck -f /dev/$vg/$lv",
29 + "vg_enabled_$vg,$lv_rm_pre", "e2fsck_f_resize_$vg/$lv" );
30 + &FAI::push_command( "resize2fs /dev/$vg/$lv ${block_count}s",
31 + "e2fsck_f_resize_$vg/$lv", "lv_shrink_$vg/$lv" );
32 + } else {
33 + &FAI::push_command( "parted -s /dev/$vg/$lv resize 1 0 " . $lv_size->{eff_size} . "B",
34 + "vg_enabled_$vg,$lv_rm_pre", "lv_shrink_$vg/$lv" );
35 + }
36 + &FAI::push_command( "lvresize -L $lvsize_mib $vg/$lv",
37 "vg_enabled_$vg,$lv_rm_pre,lv_shrink_$vg/$lv", "lv_created_$vg/$lv" );
38 } else {
39 - &FAI::push_command( "lvresize -L " . $lv_size->{eff_size} . " $vg/$lv",
40 + &FAI::push_command( "lvresize -L $lvsize_mib $vg/$lv",
41 "vg_enabled_$vg,$lv_rm_pre", "lv_grow_$vg/$lv" );
42 - &FAI::push_command( "parted -s /dev/$vg/$lv resize 1 0 " . $lv_size->{eff_size} . "B",
43 - "vg_enabled_$vg,$lv_rm_pre,lv_grow_$vg/$lv", "exist_/dev/$vg/$lv" );
44 + if (($FAI::configs{$config}{volumes}{$lv}{filesystem} =~
45 + /^ext[23]$/) && &FAI::in_path("resize2fs")) {
46 + my $block_count = POSIX::floor($lv_size->{eff_size} / 512);
47 + &FAI::push_command( "e2fsck -f /dev/$vg/$lv ${block_count}s",
48 + "vg_enabled_$vg,$lv_rm_pre,lv_grow_$vg/$lv", "e2fsck_f_resize_$vg/$lv" );
49 + &FAI::push_command( "resize2fs /dev/$vg/$lv ${block_count}s",
50 + "e2fsck_f_resize_$vg/$lv", "exist_/dev/$vg/$lv" );
51 + } else {
52 + &FAI::push_command( "parted -s /dev/$vg/$lv resize 1 0 " . $lv_size->{eff_size} . "B",
53 + "vg_enabled_$vg,$lv_rm_pre,lv_grow_$vg/$lv", "exist_/dev/$vg/$lv" );
54 + }
55 }
56
57 next;
58 @@ -516,10 +536,10 @@
59 my ($create_options) = $FAI::configs{$config}{volumes}{$lv}{lvcreateopts};
60 # prevent warnings of uninitialized variables
61 $create_options = '' unless $create_options;
62 - print "/dev/$vg/$lv LV create_options: $create_options\n" if ($FAI::debug && $create_options);
63 + print "/dev/$vg/$lv LV create_options: $create_options\n" if ($FAI::debug && $create_options);
64 # create a new volume
65 &FAI::push_command( "lvcreate $create_options -n $lv -L " .
66 - $lv_size->{eff_size} . " $vg", "vg_enabled_$vg,$lv_rm_pre",
67 + &FAI::convert_unit($lv_size->{eff_size} . "B") . " $vg", "vg_enabled_$vg,$lv_rm_pre",
68 "exist_/dev/$vg/$lv" );
69
70 # create the filesystem on the volume
71 @@ -847,25 +867,42 @@
72 my $start = $part->{start_byte};
73 my $end = $part->{end_byte};
74
75 + # ntfs/ext2,3 partition can't be moved
76 + ($start == $FAI::current_config{$disk}{partitions}{$mapped_id}{begin_byte})
77 + or &FAI::internal_error(
78 + $FAI::current_config{$disk}{partitions}{$mapped_id}{filesystem}
79 + . " partition start supposed to move, which is not allowed") if
80 + ($FAI::current_config{$disk}{partitions}{$mapped_id}{filesystem} =~
81 + /^(ntfs|ext[23])$/);
82 +
83 # build an appropriate command
84 # ntfs requires specific care
85 if ($FAI::current_config{$disk}{partitions}{$mapped_id}{filesystem} eq
86 "ntfs") {
87 # check, whether ntfsresize is available
88 &FAI::in_path("ntfsresize") or die "ntfsresize not found in PATH\n";
89 - # ntfs partition can't be moved
90 - ($start == $FAI::current_config{$disk}{partitions}{$mapped_id}{begin_byte})
91 - or &FAI::internal_error("ntfs partition supposed to move");
92 - # ntfsresize requires device names
93 - my $eff_size = $part->{size}->{eff_size};
94
95 - &FAI::push_command( "yes | ntfsresize -s $eff_size " .
96 + &FAI::push_command( "yes | ntfsresize -s " . $part->{size}->{eff_size} .
97 &FAI::make_device_name($disk, $p), "rebuilt_" .
98 &FAI::make_device_name($disk, $p) . $deps, "ntfs_ready_for_rm_" .
99 &FAI::make_device_name($disk, $p) );
100 + # TODO this is just a hack, we would really need support for resize
101 + # without data resize in parted, which will be added in some parted
102 + # version > 2.1
103 &FAI::push_command( "parted -s $disk rm $p", "ntfs_ready_for_rm_" .
104 &FAI::make_device_name($disk, $p), "resized_" .
105 &FAI::make_device_name($disk, $p) );
106 + ## } elsif (($FAI::current_config{$disk}{partitions}{$mapped_id}{filesystem} =~
107 + ## /^ext[23]$/) && &FAI::in_path("resize2fs")) {
108 + ## TODO: BROKEN needs more checks, enlarge partition table before resize, just as
109 + ## NTFS case
110 + ## my $block_count = $part->{size}->{eff_size} / 512;
111 + ## &FAI::push_command( "e2fsck -f " . &FAI::make_device_name($disk, $p) .
112 + ## " ${block_count}s", "rebuilt_" . &FAI::make_device_name($disk, $p) . $deps,
113 + ## "e2fsck_f_resize_" . &FAI::make_device_name($disk, $p) );
114 + ## &FAI::push_command( "resize2fs " . &FAI::make_device_name($disk, $p) .
115 + ## " ${block_count}s", "e2fsck_f_resize_" . &FAI::make_device_name($disk, $p),
116 + ## "resized_" . &FAI::make_device_name($disk, $p) );
117 } else {
118 &FAI::push_command( "parted -s $disk resize $p ${start}B ${end}B",
119 "rebuilt_" . &FAI::make_device_name($disk, $p) . $deps, "resized_" .
120 Index: trunk/lib/setup-storage/Sizes.pm
121 ===================================================================
122 --- trunk.orig/lib/setup-storage/Sizes.pm
123 +++ trunk/lib/setup-storage/Sizes.pm
124 @@ -251,7 +251,7 @@
125 # the size is fixed
126 if ($start == $end) {
127 # write the size back to the configuration
128 - $lv_size->{eff_size} = $start;
129 + $lv_size->{eff_size} = $start * 1024.0 * 1024.0;
130 } else {
131
132 # add this volume to the redistribution list
133 @@ -281,7 +281,7 @@
134
135 # write the final size
136 $FAI::configs{$config}{volumes}{$lv}{size}{eff_size} =
137 - $start + (($end - $start) * $redist_factor);
138 + ($start + (($end - $start) * $redist_factor)) * 1024.0 * 1024.0;
139 }
140 }
141 }
142 Index: trunk/lib/setup-storage/Volumes.pm
143 ===================================================================
144 --- trunk.orig/lib/setup-storage/Volumes.pm
145 +++ trunk/lib/setup-storage/Volumes.pm
146 @@ -352,10 +352,10 @@
147 # store the vg size in MB
148 my %vg_info = get_volume_group_information($vg);
149 if (%vg_info) {
150 - $FAI::current_lvm_config{$vg}{size} = $vg_info{alloc_pe_size} .
151 - $vg_info{alloc_pe_size_unit};
152 + $FAI::current_lvm_config{$vg}{size} = &FAI::convert_unit(
153 + $vg_info{alloc_pe_size} . $vg_info{alloc_pe_size_unit});
154 } else {
155 - $FAI::current_lvm_config{$vg}{size} = "0M";
156 + $FAI::current_lvm_config{$vg}{size} = "0";
157 }
158
159 # store the logical volumes and their sizes

  ViewVC Help
Powered by ViewVC 1.1.5