| | 138 | =item B<mr_lvm_get_conf> |
|---|
| | 139 | |
|---|
| | 140 | This function returns 1 parameters, the LVM structure or undef if no LVM |
|---|
| | 141 | That LVM structure contains all the information related to the current LVM configuration |
|---|
| | 142 | |
|---|
| | 143 | =cut |
|---|
| | 144 | |
|---|
| | 145 | sub mr_lvm_get_conf { |
|---|
| | 146 | |
|---|
| | 147 | my $lvm = undef; |
|---|
| | 148 | |
|---|
| | 149 | my ($lvmver,$lvmcmd) = mr_lvm_check(); |
|---|
| | 150 | return(undef) if ((not defined $lvmver) || ($lvmver == 0)); |
|---|
| | 151 | |
|---|
| | 152 | # Analyze the existing physical volumes |
|---|
| | 153 | open(LVM,$lvmcmd."pvs --noheadings --nosuffix --units m --separator : -o pv_name,vg_name,pv_all,pv_fmt,pv_uuid,dev_size,pv_mda_free,pv_mda_size |") || mr_exit(-1,"Unable to execute ".$lvmcmd."pvs"); |
|---|
| | 154 | while (<LVM>) { |
|---|
| | 155 | s/^[\s]*//; |
|---|
| | 156 | |
|---|
| | 157 | my ($pv_name,$vg_name,$pe_start,$pv_size,$pv_free,$pv_used,$pv_attr,$pv_pe_count,$pv_pe_alloc_count,$pv_tags,$pv_mda_count,$pv_uuid,$dev_size,$pv_mda_free,$pv_mda_size) = split(/:/); |
|---|
| | 158 | |
|---|
| | 159 | =pod |
|---|
| | 160 | |
|---|
| | 161 | The LVM hash is indexed by VGs, provided by the vg_name attribute of the pvs command |
|---|
| | 162 | vg_name - Name of the volume group linked to this PV |
|---|
| | 163 | |
|---|
| | 164 | =cut |
|---|
| | 165 | |
|---|
| | 166 | $lvm->{$vg_name}->{'pvnum'}++; |
|---|
| | 167 | |
|---|
| | 168 | =pod |
|---|
| | 169 | |
|---|
| | 170 | The structure contains an array of PVs called pvs and starting at 1, containing the name of the PV as provided by the pv_name attribute of the pvs command |
|---|
| | 171 | pv_name - Name of the physical volume PV |
|---|
| | 172 | |
|---|
| | 173 | =cut |
|---|
| | 174 | |
|---|
| | 175 | # Array of PVs for that VG |
|---|
| | 176 | $lvm->{$vg_name}->{'pvs'}->[$lvm->{$vg_name}->{'pvnum'}] = $pv_name; |
|---|
| | 177 | |
|---|
| | 178 | =pod |
|---|
| | 179 | |
|---|
| | 180 | All the PV fields from the pvs command are gathered under their PV name (substructure) |
|---|
| | 181 | The following names are used: |
|---|
| | 182 | |
|---|
| | 183 | From pvs -o help |
|---|
| | 184 | pe_start - Offset to the start of data on the underlying device. |
|---|
| | 185 | pv_size - Size of PV in current units. |
|---|
| | 186 | pv_free - Total amount of unallocated space in current units. |
|---|
| | 187 | pv_used - Total amount of allocated space in current units. |
|---|
| | 188 | pv_attr - Various attributes - see man page. |
|---|
| | 189 | pv_pe_count - Total number of Physical Extents. |
|---|
| | 190 | pv_pe_alloc_count - Total number of allocated Physical Extents. |
|---|
| | 191 | pv_tags - Tags, if any. |
|---|
| | 192 | pv_mda_count - Number of metadata areas on this device. |
|---|
| | 193 | pv_fmt - Type of metadata. |
|---|
| | 194 | pv_uuid - Unique identifier. |
|---|
| | 195 | dev_size - Size of underlying device in current units. |
|---|
| | 196 | pv_mda_free - Free metadata area space on this device in current units. |
|---|
| | 197 | pv_mda_size - Size of smallest metadata area on this device in current units. |
|---|
| | 198 | |
|---|
| | 199 | =cut |
|---|
| | 200 | |
|---|
| | 201 | $lvm->{$vg_name}->{$pv_name}->{'pe_start'} = $pe_start; |
|---|
| | 202 | $lvm->{$vg_name}->{$pv_name}->{'pv_size'} = $pv_size; |
|---|
| | 203 | $lvm->{$vg_name}->{$pv_name}->{'pv_free'} = $pv_free; |
|---|
| | 204 | $lvm->{$vg_name}->{$pv_name}->{'pv_used'} = $pv_used; |
|---|
| | 205 | $lvm->{$vg_name}->{$pv_name}->{'pv_attr'} = $pv_attr; |
|---|
| | 206 | $lvm->{$vg_name}->{$pv_name}->{'pv_pe_count'} = $pv_pe_count; |
|---|
| | 207 | $lvm->{$vg_name}->{$pv_name}->{'pv_pe_alloc_count'} = $pv_pe_alloc_count; |
|---|
| | 208 | $lvm->{$vg_name}->{$pv_name}->{'pv_tags'} = $pv_tags; |
|---|
| | 209 | $lvm->{$vg_name}->{$pv_name}->{'pv_mda_count'} = $pv_mda_count; |
|---|
| | 210 | $lvm->{$vg_name}->{$pv_name}->{'pv_uuid'} = $pv_uuid; |
|---|
| | 211 | $lvm->{$vg_name}->{$pv_name}->{'dev_size'} = $dev_size; |
|---|
| | 212 | $lvm->{$vg_name}->{$pv_name}->{'pv_mda_free'} = $pv_mda_free; |
|---|
| | 213 | $lvm->{$vg_name}->{$pv_name}->{'pv_mda_size'} = $pv_mda_size; |
|---|
| | 214 | } |
|---|
| | 215 | close(LVM); |
|---|
| | 216 | |
|---|
| | 217 | # Analyze the existing volume groups |
|---|
| | 218 | #open(LVM,$lvmcmd."vgdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."vgdisplay -c"); |
|---|
| | 219 | open(LVM,$lvmcmd."vgs --noheadings --nosuffix --units m --separator : | -o vg_all") || mr_exit(-1,"Unable to execute ".$lvmcmd."vgs"); |
|---|
| | 220 | while (<LVM>) { |
|---|
| | 221 | |
|---|
| | 222 | =pod |
|---|
| | 223 | |
|---|
| | 224 | All the VG fields from the vgs command are gathered under the VG name |
|---|
| | 225 | The following names are used: |
|---|
| | 226 | |
|---|
| | 227 | From vgs -o help |
|---|
| | 228 | vg_fmt - Type of metadata. |
|---|
| | 229 | vg_uuid - Unique identifier. |
|---|
| | 230 | vg_attr - Various attributes - see man page. |
|---|
| | 231 | vg_size - Total size of VG in current units. |
|---|
| | 232 | vg_free - Total amount of free space in current units. |
|---|
| | 233 | vg_sysid - System ID indicating when and where it was created. |
|---|
| | 234 | vg_extent_size - Size of Physical Extents in current units. |
|---|
| | 235 | vg_extent_count - Total number of Physical Extents. |
|---|
| | 236 | vg_free_count - Total number of unallocated Physical Extents. |
|---|
| | 237 | max_lv - Maximum number of LVs allowed in VG or 0 if unlimited. |
|---|
| | 238 | max_pv - Maximum number of PVs allowed in VG or 0 if unlimited. |
|---|
| | 239 | pv_count - Number of PVs. |
|---|
| | 240 | lv_count - Number of LVs. |
|---|
| | 241 | snap_count - Number of snapshots. |
|---|
| | 242 | vg_seqno - Revision number of internal metadata. Incremented whenever it changes. |
|---|
| | 243 | vg_tags - Tags, if any. |
|---|
| | 244 | vg_mda_count - Number of metadata areas in use by this VG. |
|---|
| | 245 | vg_mda_free - Free metadata area space for this VG in current units. |
|---|
| | 246 | vg_mda_size - Size of smallest metadata area for this VG in current units. |
|---|
| | 247 | |
|---|
| | 248 | =cut |
|---|
| | 249 | s/^[\s]*//; |
|---|
| | 250 | my ($vg_fmt,$vg_uuid,$vg_name,$vg_attr,$vg_size,$vg_free,$vg_sysid,$vg_extend_size,$vg_extend_count,$vg_free_count,$max_lv,$max_pv,$pv_count,$lv_count,$snap_count,$vg_seqno,$vg_tags,$vg_mda_count,$vg_mda_free,$vg_mda_size) = split(/:/); |
|---|
| | 251 | $lvm->{$vg_name}->{'vg_fmt'} = $vg_fmt; |
|---|
| | 252 | $lvm->{$vg_name}->{'vg_uuid'} = $vg_uuid; |
|---|
| | 253 | $lvm->{$vg_name}->{'vg_attr'} = $vg_attr; |
|---|
| | 254 | $lvm->{$vg_name}->{'vg_size'} = $vg_size; |
|---|
| | 255 | $lvm->{$vg_name}->{'vg_free'} = $vg_free; |
|---|
| | 256 | $lvm->{$vg_name}->{'vg_sysid'} = $vg_sysid; |
|---|
| | 257 | $lvm->{$vg_name}->{'vg_extend_size'} = $vg_extend_size; |
|---|
| | 258 | $lvm->{$vg_name}->{'vg_extend_count'} = $vg_extend_count; |
|---|
| | 259 | $lvm->{$vg_name}->{'vg_free_count'} = $vg_free_count; |
|---|
| | 260 | $lvm->{$vg_name}->{'max_lv'} = $max_lv; |
|---|
| | 261 | $lvm->{$vg_name}->{'max_pv'} = $max_pv; |
|---|
| | 262 | $lvm->{$vg_name}->{'pv_count'} = $pv_count; |
|---|
| | 263 | $lvm->{$vg_name}->{'lv_count'} = $lv_count; |
|---|
| | 264 | $lvm->{$vg_name}->{'snap_count'} = $snap_count; |
|---|
| | 265 | $lvm->{$vg_name}->{'vg_seqno'} = $vg_seqno; |
|---|
| | 266 | $lvm->{$vg_name}->{'vg_tags'} = $vg_tags; |
|---|
| | 267 | $lvm->{$vg_name}->{'vg_mda_count'} = $vg_mda_count; |
|---|
| | 268 | $lvm->{$vg_name}->{'vg_mda_free'} = $vg_mda_free; |
|---|
| | 269 | $lvm->{$vg_name}->{'vg_mda_size'} = $vg_mda_size; |
|---|
| | 270 | } |
|---|
| | 271 | close(LVM); |
|---|
| | 272 | |
|---|
| | 273 | # Analyze the existing logical volumes |
|---|
| | 274 | #open(LVM,$lvmcmd."lvdisplay -c |") || mr_exit(-1,"Unable to execute ".$lvmcmd."lvdisplay -c"); |
|---|
| | 275 | open(LVM,$lvmcmd."lvs --noheadings --nosuffix --units m --separator : -o vg_name,lv_all|") || mr_exit(-1,"Unable to execute ".$lvmcmd."lvs"); |
|---|
| | 276 | while (<LVM>) { |
|---|
| | 277 | s/^[\s]*//; |
|---|
| | 278 | |
|---|
| | 279 | =pod |
|---|
| | 280 | |
|---|
| | 281 | The structure contains an array of LVs called lvs and starting at 1, containing the name of the PV as provided by the pv_name attribute of the pvs command |
|---|
| | 282 | pv_name - Name of the physical volume PV |
|---|
| | 283 | |
|---|
| | 284 | =cut |
|---|
| | 285 | |
|---|
| | 286 | # Array of PVs for that VG |
|---|
| | 287 | $lvm->{$vg_name}->{'pvs'}->[$lvm->{$vg_name}->{'pvnum'}] = $pv_name; |
|---|
| | 288 | |
|---|
| | 289 | =pod |
|---|
| | 290 | |
|---|
| | 291 | All the PV fields from the pvs command are gathered under their PV name (substructure) |
|---|
| | 292 | The following names are used: |
|---|
| | 293 | |
|---|
| | 294 | |
|---|
| | 295 | # From lvs -o help |
|---|
| | 296 | |
|---|
| | 297 | #vg_name - Name of the related volume group |
|---|
| | 298 | #lv_uuid - Unique identifier. |
|---|
| | 299 | #lv_name - Name. LVs created for internal use are enclosed in brackets. |
|---|
| | 300 | #lv_attr - Various attributes - see man page. |
|---|
| | 301 | #lv_major - Persistent major number or -1 if not persistent. |
|---|
| | 302 | #lv_minor - Persistent minor number or -1 if not persistent. |
|---|
| | 303 | #lv_read_ahead - Read ahead setting in current units. |
|---|
| | 304 | #lv_kernel_major - Currently assigned major number or -1 if LV is not active. |
|---|
| | 305 | #lv_kernel_minor - Currently assigned minor number or -1 if LV is not active. |
|---|
| | 306 | #lv_kernel_read_ahead - Currently-in-use read ahead setting in current units. |
|---|
| | 307 | #lv_size - Size of LV in current units. |
|---|
| | 308 | #seg_count - Number of segments in LV. |
|---|
| | 309 | #origin - For snapshots, the origin device of this LV. |
|---|
| | 310 | #origin_size - For snapshots, the size of the origin device of this LV. |
|---|
| | 311 | #snap_percent - For snapshots, the percentage full if LV is active. |
|---|
| | 312 | #copy_percent - For mirrors and pvmove, current percentage in-sync. |
|---|
| | 313 | #move_pv - For pvmove, Source PV of temporary LV created by pvmove. |
|---|
| | 314 | #convert_lv - For lvconvert, Name of temporary LV created by lvconvert. |
|---|
| | 315 | #lv_tags - Tags, if any. |
|---|
| | 316 | #mirror_log - For mirrors, the LV holding the synchronisation log. |
|---|
| | 317 | #modules - Kernel device-mapper modules required for this LV. |
|---|
| | 318 | |
|---|
| | 319 | =cut |
|---|
| | 320 | |
|---|
| | 321 | my ($vg_name,$lv_uuid,$lv_name,$lv_attr,$lv_major,$lv_minor,$lv_read_ahead,$lv_kernel_major,$lv_kernel_minor,$lv_kernel_read_ahead,$lv_size,$seg_count,$origin,$origin_size,$snap_percent,$copy_percent,$move_pv,$convert_lv,$lv_tags,$mirror_log,$modules) = split(/:/); |
|---|
| | 322 | # The LVM hash is indexed by VGs |
|---|
| | 323 | $lvm->{$vg_name}->{'lvnum'}++; |
|---|
| | 324 | # That array will start at 1 then |
|---|
| | 325 | # Array of LVs for that VG |
|---|
| | 326 | $lvm->{$vg_name}->{'lvs'}->[$lvm->{$vg_name}->{'lvnum'}] = $lv_name; |
|---|
| | 327 | # All LV fields gathered under the LV name |
|---|
| | 328 | $lvm->{$vg_name}->{$lv_name}->{'lv_uuid'} = $lv_uuid; |
|---|
| | 329 | $lvm->{$vg_name}->{$lv_name}->{'lv_attr'} = $lv_attr; |
|---|
| | 330 | $lvm->{$vg_name}->{$lv_name}->{'lv_major'} = $lv_major; |
|---|
| | 331 | $lvm->{$vg_name}->{$lv_name}->{'lv_minor'} = $lv_minor; |
|---|
| | 332 | $lvm->{$vg_name}->{$lv_name}->{'lv_read_ahead'} = $lv_read_ahead; |
|---|
| | 333 | $lvm->{$vg_name}->{$lv_name}->{'lv_kernel_major'} = $lv_kernel_major; |
|---|
| | 334 | $lvm->{$vg_name}->{$lv_name}->{'lv_kernel_minor'} = $lv_kernel_minor; |
|---|
| | 335 | $lvm->{$vg_name}->{$lv_name}->{'lv_kernel_read_ahead'} = $lv_kernel_read_ahead; |
|---|
| | 336 | $lvm->{$vg_name}->{$lv_name}->{'lv_size'} = $lv_size; |
|---|
| | 337 | $lvm->{$vg_name}->{$lv_name}->{'origin'} = $origin; |
|---|
| | 338 | $lvm->{$vg_name}->{$lv_name}->{'origin_size'} = $origin_size; |
|---|
| | 339 | $lvm->{$vg_name}->{$lv_name}->{'snap_percent'} = $snap_percent; |
|---|
| | 340 | $lvm->{$vg_name}->{$lv_name}->{'copy_percent'} = $copy_percent; |
|---|
| | 341 | $lvm->{$vg_name}->{$lv_name}->{'move_pv'} = $move_pv; |
|---|
| | 342 | $lvm->{$vg_name}->{$lv_name}->{'convert_lv'} = $convert_lv; |
|---|
| | 343 | $lvm->{$vg_name}->{$lv_name}->{'lv_tags'} = $lv_tags; |
|---|
| | 344 | $lvm->{$vg_name}->{$lv_name}->{'mirror_log'} = $mirror_log; |
|---|
| | 345 | $lvm->{$vg_name}->{$lv_name}->{'modules'} = $modules; |
|---|
| | 346 | } |
|---|
| | 347 | close(LVM); |
|---|
| | 348 | return($lvm); |
|---|
| | 349 | } |
|---|
| | 350 | |
|---|