Changeset 2149 in MondoRescue for devel/mindi/lib
- Timestamp:
- Feb 16, 2009, 5:50:07 PM (16 years ago)
- Location:
- devel/mindi/lib/MondoRescue/Mindi
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
devel/mindi/lib/MondoRescue/Mindi/LVM.pm
r2142 r2149 1 1 #!/usr/bin/perl -w 2 2 # 3 # Mindi subroutines brought by the MondoRescue project3 # Mindi subroutines related to LVM brought by the MondoRescue project 4 4 # 5 5 # $Id$ … … 8 8 # Provided under the GPL v2 9 9 10 package M andoRescue::Mindi;10 package MondoRescue::Mindi::LVM; 11 11 12 12 use strict 'vars'; 13 13 use Data::Dumper; 14 14 use English; 15 use File::Basename;16 use File::Copy;17 use POSIX qw(strftime);18 15 use lib qw (lib); 19 16 use ProjectBuilder::Base; … … 28 25 29 26 our @ISA = qw(Exporter); 30 our @EXPORT = qw(mr_lvm_check );27 our @EXPORT = qw(mr_lvm_check mr_lvm_analyze mr_lvm_prepare); 31 28 32 29 =pod … … 48 45 This function checks the usage of LVM and gets the version used 49 46 It returns 2 parameters, the LVM version, and the lvm command to use if needed 47 If LVM version is null then no LVM Handling should be done. 50 48 51 49 =cut … … 53 51 sub mr_lvm_check { 54 52 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 54 my ($lvmds_t,$lvmproc_t,$lvmcmd_t,$lvmpath_t) = pb_conf_get("mr_lvmdiskscan","mr_lvmprocfile","mr_lvmcmd","mr_lvmpath"); 55 my $lvmds = $lvmds_t->{'mindi'}; 56 my $lvmproc = $lvmproc_t->{'mindi'}; 57 my $lvmcmd = $lvmcmd_t->{'mindi'}; 58 my $lvmpath = $lvmpath_t->{'mindi'}; 59 60 if (! -x $lvmproc) { 61 pb_log(1,"$lvmproc doesn't exist."); 62 return(0,undef); 63 } 61 64 62 65 # Check LVM volumes presence 63 66 open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc"); 64 67 while (<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 } 66 72 } 67 73 close(LVM); … … 96 102 if ($lvmver == 0) { 97 103 # 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"); 99 105 } 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 102 113 pb_log(1,"Found LVM version $lvmver"); 103 114 return ($lvmver,$lvmcmd); 115 116 } 117 118 =over 4 119 120 =item B<mr_lvm_analyze> 121 122 This function outputs in a file descriptor the LVM analysis done 123 It returns 1 parameters, the LVM version or 0 if no LVM 124 125 =cut 126 127 sub mr_lvm_analyze { 128 129 my $OUTPUT = shift; 130 131 my ($lvmver,$lvmcmd) = mr_lvm_check(); 132 return(0) if ($lvmver == 0); 133 134 print $OUTPUT "LVM:$lvmver"; 135 136 # Analyze the existing physical volumes 137 open(LVM,$lvmcmd."pvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."pvdisplay -c"); 138 while (<LVM>) { 139 print $OUTPUT "PV:$_"; 140 } 141 close(LVM); 142 143 # Analyze the existing volume groups 144 open(LVM,$lvmcmd."vgdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."vgdisplay -c"); 145 while (<LVM>) { 146 print $OUTPUT "VG:$_"; 147 } 148 close(LVM); 149 150 # Analyze the existing logical volumes 151 open(LVM,$lvmcmd."lvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."lvdisplay -c"); 152 while (<LVM>) { 153 print $OUTPUT "LV:$_"; 154 } 155 close(LVM); 156 return($lvmver); 157 } 158 159 160 =over 4 161 162 =item B<mr_lvm_prepare> 163 164 This function outputs in a file descriptor the LVM setup needed to restore LVM conf 165 It returns 1 parameters, the LVM version or 0 if no LVM 166 167 =cut 168 169 sub mr_lvm_prepare { 170 171 my $INPUT = shift; 172 my $OUTPUT = shift; 173 my $mrmult = shift; 174 175 my ($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 181 print $OUTPUT "# Desactivate Volume Groups\n"; 182 print $OUTPUT $lvmcmd."vgchange -an\n"; 183 print $OUTPUT "\n"; 184 185 my $firsttime = 0; 186 while (<$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 } 219 print $OUTPUT "\n"; 220 print $OUTPUT "# Scanning again Volume Groups\n"; 221 print $OUTPUT $lvmcmd."vgscan\n"; 222 print $OUTPUT "\n"; 104 223 105 224 }
Note:
See TracChangeset
for help on using the changeset viewer.