Changeset 2149 in MondoRescue for devel/mindi/lib/MondoRescue/Mindi


Ignore:
Timestamp:
Feb 16, 2009, 5:50:07 PM (15 years ago)
Author:
Bruno Cornec
Message:

Begining f devl branch coding nd preliminary organisation

Location:
devel/mindi/lib/MondoRescue/Mindi
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • devel/mindi/lib/MondoRescue/Mindi/LVM.pm

    r2142 r2149  
    11#!/usr/bin/perl -w
    22#
    3 # Mindi subroutines brought by the MondoRescue project
     3# Mindi subroutines related to LVM brought by the MondoRescue project
    44#
    55# $Id$
     
    88# Provided under the GPL v2
    99
    10 package MandoRescue::Mindi;
     10package MondoRescue::Mindi::LVM;
    1111
    1212use strict 'vars';
    1313use Data::Dumper;
    1414use English;
    15 use File::Basename;
    16 use File::Copy;
    17 use POSIX qw(strftime);
    1815use lib qw (lib);
    1916use ProjectBuilder::Base;
     
    2825
    2926our @ISA = qw(Exporter);
    30 our @EXPORT = qw(mr_lvm_check);
     27our @EXPORT = qw(mr_lvm_check mr_lvm_analyze mr_lvm_prepare);
    3128
    3229=pod
     
    4845This function checks the usage of LVM and gets the version used
    4946It returns 2 parameters, the LVM version, and the lvm command to use if needed
     47If LVM version is null then no LVM Handling should be done.
    5048
    5149=cut
     
    5351sub mr_lvm_check {
    5452
    55 # Get them from a conf file instead
    56 my $lvmds = "/usr/sbin/lvmdiskscan";
    57 my $lvmproc = "/proc/lvm/global";
    58 my $lvmcmd = "/usr/sbin/lvm";
    59 
    60 mr_exit(1,"$lvmproc doesn't exist.") if (! -x $lvmproc) ;
     53# Get params from the conf file
     54my ($lvmds_t,$lvmproc_t,$lvmcmd_t,$lvmpath_t) = pb_conf_get("mr_lvmdiskscan","mr_lvmprocfile","mr_lvmcmd","mr_lvmpath");
     55my $lvmds = $lvmds_t->{'mindi'};
     56my $lvmproc = $lvmproc_t->{'mindi'};
     57my $lvmcmd = $lvmcmd_t->{'mindi'};
     58my $lvmpath = $lvmpath_t->{'mindi'};
     59
     60if (! -x $lvmproc) {
     61    pb_log(1,"$lvmproc doesn't exist.");
     62    return(0,undef);
     63    }
    6164
    6265# Check LVM volumes presence
    6366open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc");
    6467while (<LVM>) {
    65     mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);
     68    if (/0 VGs 0 PVs 0 LVs/) {
     69        pb_log(1,"No LVM volumes found in $lvmproc");
     70        return(0,undef);
     71    }
    6672}
    6773close(LVM);
     
    96102if ($lvmver == 0) {
    97103    # Still not found
    98     mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmcmd version");
     104    mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmcmd");
    99105} elsif ($lvmver == 1) {
    100     $lvmcmd = "";
    101 }
     106    $lvmcmd = "$lvmpath";
     107} elsif ($lvmver == 2) {
     108    $lvmcmd .= " ";
     109} else {
     110    pb_log(0,"Unknown LVM version $lvmver");
     111}
     112# Here $lvmcmd contains a full path name
    102113pb_log(1,"Found LVM version $lvmver");
    103114return ($lvmver,$lvmcmd);
     115
     116}
     117
     118=over 4
     119
     120=item B<mr_lvm_analyze>
     121
     122This function outputs in a file descriptor the LVM analysis done
     123It returns 1 parameters, the LVM version or 0 if no LVM
     124
     125=cut
     126
     127sub mr_lvm_analyze {
     128
     129my $OUTPUT = shift;
     130
     131my ($lvmver,$lvmcmd) = mr_lvm_check();
     132return(0) if ($lvmver == 0);
     133
     134print $OUTPUT "LVM:$lvmver";
     135
     136# Analyze the existing physical volumes
     137open(LVM,$lvmcmd."pvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."pvdisplay -c");
     138while (<LVM>) {
     139        print $OUTPUT "PV:$_";
     140}
     141close(LVM);
     142
     143# Analyze the existing volume groups
     144open(LVM,$lvmcmd."vgdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."vgdisplay -c");
     145while (<LVM>) {
     146        print $OUTPUT "VG:$_";
     147}
     148close(LVM);
     149
     150# Analyze the existing logical volumes
     151open(LVM,$lvmcmd."lvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."lvdisplay -c");
     152while (<LVM>) {
     153        print $OUTPUT "LV:$_";
     154}
     155close(LVM);
     156return($lvmver);
     157}
     158
     159
     160=over 4
     161
     162=item B<mr_lvm_prepare>
     163
     164This function outputs in a file descriptor the LVM setup needed to restore LVM conf
     165It returns 1 parameters, the LVM version or 0 if no LVM
     166
     167=cut
     168
     169sub mr_lvm_prepare {
     170
     171my $INPUT = shift;
     172my $OUTPUT = shift;
     173my $mrmult = shift;
     174
     175my ($lvmver,$lvmcmd) = mr_lvm_check();
     176
     177# Generate the startup scrit needed to restore LVM conf
     178# from what is given on input
     179# Multiply by the multiplier given in input or 1 of none
     180
     181print $OUTPUT "# Desactivate Volume Groups\n";
     182print $OUTPUT $lvmcmd."vgchange -an\n";
     183print $OUTPUT "\n";
     184
     185my $firsttime = 0;
     186while (<$INPUT>) {
     187    if (/^PV:/) {
     188        my ($tag,$pvname,$vgname,$pvsize,$ipvn,$pvstat,$pvna,$lvnum,$pesize,$petot,$pefree,$pelloc) = split(/:/);
     189        print $OUTPUT "# Creating Physical Volumes $pvname\n";
     190        print $OUTPUT $lvmcmd."pvcreate -ff -y -s ".$pesize*$mrmult." $pvname\n";
     191        print $OUTPUT "\n";
     192    } elsif (/^VG:/) {
     193        my ($tag,$vgname,$vgaccess,$vgstat,$vgnum,$lvmaxnum,$lvnum,$ocalvinvg,$lvmaxsize,$pvmaxnum,$cnumpv,$anumpv,$vgsize,$pesize,$penum,$pealloc,$pefree,$uuid) = split(/:/);
     194        if ($lvmver < 2) {
     195            print $OUTPUT "# Removing device first as LVM v1 doesn't do it\n";
     196            print $OUTPUT "rm -Rf /dev/$vgname\n";
     197        }
     198        $lvmaxnum = 255 if ($lvmaxnum > 256);
     199        $pvmaxnum = 255 if ($pvmaxnum > 256);
     200        print $OUTPUT "# Create Volume Group $vgname\n";
     201        # Pb sur pesize unite ?
     202        print $OUTPUT $lvmcmd."vgcreate $vgname -p $pvmaxnum -s $pesize -l $lvmaxnum\n";
     203        print $OUTPUT "\n";
     204    } elsif (/^LV:/) {
     205        if ($firsttime eq 0) {
     206            print $OUTPUT "\n";
     207            print $OUTPUT "# Activate All Volume Groups\n";
     208            print $OUTPUT $lvmcmd."vgchange -ay\n";
     209            print $OUTPUT "\n";
     210            $firsttime = 1;
     211        }
     212        my ($tag,$lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$readahead,$major,$minor) = split(/:/);
     213        print $OUTPUT "# Create Logical Volume $lvname\n";
     214        print $OUTPUT $lvmcmd."lvcreate -n $lvname -L ".$lvsize*$mrmult." -r $readahead $vgname\n";
     215        #[ "$stripes" ]    && output="$output -i $stripes"
     216        #[ "$stripesize" ] && output="$output -I $stripesize"
     217    }
     218}
     219print $OUTPUT "\n";
     220print $OUTPUT "# Scanning again Volume Groups\n";
     221print $OUTPUT $lvmcmd."vgscan\n";
     222print $OUTPUT "\n";
    104223
    105224}
Note: See TracChangeset for help on using the changeset viewer.