Skip to content

Commit be13265

Browse files
committed
resize/test-virt-resize.pl: Parameterize the size of each partition
Currently the partitions created during this test are 512MB (1024*1024 sectors). Just make this into a parameter within the code. Refactoring, no change to the test.
1 parent a69e20a commit be13265

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

resize/test-virt-resize.pl

+11-5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363

6464
$| = 1;
6565

66+
# The size of each partition, in MB and sectors.
67+
my $part_size_mb = 512;
68+
my $part_size_sectors = 1024 * 1024 * $part_size_mb / 512;
69+
70+
# Create the handle.
6671
my $g = Sys::Guestfs->new ();
6772
my $backend = $g->get_backend ();
6873

@@ -106,6 +111,7 @@
106111
print "seed: $seed\n";
107112
print "partition type: $part_type\n";
108113
print "nr partitions: $nr_parts\n";
114+
print "partition size: ${part_size_mb}M ($part_size_sectors sectors)\n";
109115
print "expand: $expand\n";
110116
print "no extra part: $no_extra_partition\n";
111117
print "source format: $source_format\n";
@@ -150,7 +156,7 @@
150156
# Size of the source disk. It's always roughly nr_parts * size of
151157
# each partition + a bit extra. For btrfs we have to choose a large
152158
# partition size.
153-
my $source_size = (10 + $nr_parts * 512) * 1024 * 1024;
159+
my $source_size = (10 + $nr_parts * $part_size_mb) * 1024 * 1024;
154160

155161
# Create the source disk.
156162
my $source_file = "test-virt-resize-source.img";
@@ -214,15 +220,15 @@
214220

215221
if ($part_type eq "gpt") {
216222
for (my $i = 1; $i <= $nr_parts; ++$i) {
217-
my $end = $start + 1024*1024 - 1;
223+
my $end = $start + $part_size_sectors - 1;
218224
$g->part_add ("/dev/sda", "primary", $start, $end);
219225
$start = $end+1;
220226
}
221227
} else {
222228
# MBR is nuts ...
223229
for ($i = 1; $i <= $nr_parts; ++$i) {
224230
if ($i <= 3) {
225-
my $end = $start + 1024*1024 - 1;
231+
my $end = $start + $part_size_sectors - 1;
226232
$g->part_add ("/dev/sda", "primary", $start, $end);
227233
$start = $end+1;
228234
}
@@ -237,7 +243,7 @@
237243
# confusing thing about them is we have to take into
238244
# account the sector that contains the linked list of
239245
# logical partitions, hence -2/+2 below.
240-
my $end = $start + 1024*1024 - 2;
246+
my $end = $start + $part_size_sectors - 2;
241247
$g->part_add ("/dev/sda", "logical", $start, $end);
242248
$start = $end+2;
243249
}
@@ -298,7 +304,7 @@
298304
$target_size += 260;
299305
}
300306
} else {
301-
$target_size += 512; # remain at original size
307+
$target_size += $part_size_mb; # remain at original size
302308
}
303309
}
304310
$target_size += 10;

0 commit comments

Comments
 (0)