|
| 1 | +#!/usr/bin/perl -w |
| 2 | +# libguestfs |
| 3 | +# Copyright (C) 2018 Red Hat Inc. |
| 4 | +# |
| 5 | +# This program is free software; you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation; either version 2 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with this program; if not, write to the Free Software |
| 17 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + |
| 19 | +# From painful experience we know that changes to the kernel can |
| 20 | +# suddenly change the maximum number of disks we can add to the |
| 21 | +# appliance. This script uses a simple binary search to find the |
| 22 | +# current maximum. |
| 23 | +# |
| 24 | +# To test different kernels you may want to do: |
| 25 | +# rm -rf /var/tmp/.guestfs-* |
| 26 | +# export SUPERMIN_KERNEL=/boot/vmlinuz-... |
| 27 | +# export SUPERMIN_MODULES=/lib/modules/... |
| 28 | +# ./max-disks.pl |
| 29 | +# |
| 30 | +# See also: |
| 31 | +# https://bugzilla.redhat.com/show_bug.cgi?id=1478201#c4 |
| 32 | + |
| 33 | +use strict; |
| 34 | +use Sys::Guestfs; |
| 35 | + |
| 36 | +$| = 1; |
| 37 | + |
| 38 | +my $low = 1; |
| 39 | +my $high = 2048; # Will never test higher than this. |
| 40 | +my $mid = 1024; |
| 41 | + |
| 42 | +# Get the kernel under test. |
| 43 | +my $g = Sys::Guestfs->new (); |
| 44 | +$g->launch (); |
| 45 | +my %kernel = $g->utsname; |
| 46 | +$g->close (); |
| 47 | + |
| 48 | +sub test_mid |
| 49 | +{ |
| 50 | + my ($ret, %k); |
| 51 | + |
| 52 | + eval { |
| 53 | + my $g = Sys::Guestfs->new (); |
| 54 | + for (my $i = 0; $i < $mid; ++$i) { |
| 55 | + $g->add_drive_scratch (1024*1024); |
| 56 | + } |
| 57 | + $g->launch (); |
| 58 | + %k = $g->utsname; |
| 59 | + $g->shutdown (); |
| 60 | + }; |
| 61 | + if ($@) { |
| 62 | + printf ("%d => bad\n", $mid); |
| 63 | + $ret = 0; |
| 64 | + } |
| 65 | + else { |
| 66 | + printf ("%d => good\n", $mid); |
| 67 | + $ret = 1; |
| 68 | + } |
| 69 | + |
| 70 | + die "kernel version changed during test!\n" |
| 71 | + if exists $k{uts_release} && $k{uts_release} ne $kernel{uts_release}; |
| 72 | + |
| 73 | + return $ret; |
| 74 | +} |
| 75 | + |
| 76 | +for (;;) { |
| 77 | + if (test_mid ()) { |
| 78 | + # good, so try higher |
| 79 | + $low = $mid; |
| 80 | + } |
| 81 | + else { |
| 82 | + # bad, so try lower |
| 83 | + $high = $mid; |
| 84 | + } |
| 85 | + $mid = int (($high+$low) / 2); |
| 86 | + if ($mid == $high || $mid == $low) { |
| 87 | + printf("kernel: %s %s (%s)\n", |
| 88 | + $kernel{uts_sysname}, $kernel{uts_release}, |
| 89 | + $kernel{uts_machine}); |
| 90 | + # +1 because of the appliance disk. |
| 91 | + printf ("max disks = %d\n", $mid+1); |
| 92 | + exit 0; |
| 93 | + } |
| 94 | +} |
0 commit comments