Ignore:
Timestamp:
Aug 30, 2015, 2:33:49 AM (4 years ago)
Author:
bruno
Message:
  • Adds a mr-device-mounted binary to MondoRescue? (replaces the code of the C function is_this_device_mounted) and the corresponding perl function (mr_device_mounted) to handle cases where a mounted device has a different name than the one seen on mount (e.g. /dev/rhel/root and /dev/mapper/rhel-root)
  • Adds perl function mr_file_copy_and_erase_hash to empty the hash generated in mr_file_read_all_link and thus avoid filling the hash it generates, which is useful for a recursive function, but not when called multiple times from another perl script. To be improved later on.
  • Adapt build procedure to the new binary (tested on Mageia 5 and RHEL7)
Location:
branches/3.2/MondoRescue
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/Makefile.PL

    r3265 r3447  
    1818    EXE_FILES    => [ qw( bin/mr-analyze-lvm
    1919                bin/mr-check-lvm
     20                bin/mr-device-mounted
    2021                bin/mr-process-ldd
    2122                bin/mr-read-all-link
  • branches/3.2/MondoRescue/lib/MondoRescue/Disk.pm

    r3432 r3447  
    1313use ProjectBuilder::Base;
    1414use English;
     15use MondoRescue::File;
    1516
    1617# Inherit from the "Exporter" module which handles exporting functions.
     
    2223
    2324our @ISA = qw(Exporter);
    24 our @EXPORT = qw(mr_disk_type);
     25our @EXPORT = qw(mr_disk_type mr_device_mounted);
    2526
    2627=pod
     
    6667
    6768
     69=item B<mr_device_mounted>
     70
     71This function returns the mount point if a device is mounted and undef if not.
     72
     73=cut
     74
     75sub mr_device_mounted {
     76
     77my $device = shift;
     78
     79return(1) if ((not defined $device) || ($device =~ "^/sys|^/proc"));
     80
     81my $h = mr_file_read_all_link($device);
     82# Preserve that hash locally before earsing it to reuse another one
     83my $h2 = mr_file_copy_and_erase_hash($h);
     84
     85foreach my $f (keys %$h2) {
     86    pb_log(2,"Working on device $f\n");
     87    # TODO: get them from a conf file - FreeBSD needs swapinfo for swap request
     88    foreach my $dev ("mount","cat /proc/swaps") {
     89        # Look for the device in the command result
     90        open(MOUNT,"$dev|") || die "Unable to execute the $dev command";
     91        while (<MOUNT>) {
     92            my ($mntp,$void) = split('\s',$_,2);
     93            $h = mr_file_read_all_link($mntp);
     94            foreach my $m (keys %$h) {
     95                pb_log(2,"== Working on mounted device $m\n");
     96                if ($m eq $f) {
     97                    # Find the mountpoint and return it
     98                    my ($void1,$mountpoint,$void2) = split('\s',$void);
     99                    pb_log(2,"*** Found $m on $mountpoint\n") if (defined $mountpoint);
     100                    return($mountpoint);
     101                }
     102            }
     103            my $h3 = mr_file_copy_and_erase_hash($h);
     104        }
     105        close(MOUNT);
     106    }
     107}
     108
     109# Not found
     110return(undef);
     111}
  • branches/3.2/MondoRescue/lib/MondoRescue/File.pm

    r3262 r3447  
    2626
    2727our @ISA = qw(Exporter);
    28 our @EXPORT = qw(mr_file_read_all_link mr_file_process_ldd mr_file_normalize);
     28our @EXPORT = qw(mr_file_read_all_link mr_file_process_ldd mr_file_normalize mr_file_copy_and_erase_hash);
    2929
    3030=pod
     
    8585=over 4
    8686
     87=item B<mr_file_erase_hash>
     88
     89This function erases all elements in the hash passed in parameter (such as the one created in mr_file_read_all_link)
     90Takes as param the hash to delete and returns a new fresh one
     91
     92=cut
     93
     94sub mr_file_copy_and_erase_hash {
     95
     96my $files = shift;
     97my %h;
     98
     99foreach my $i (keys %$files) {
     100    $h{$i} = $files->{$i};
     101    delete $files->{$i};
     102}
     103return(\%h);
     104}
     105
     106=over 4
     107
    87108=item B<mr_file_read_all_link>
    88109
    89110This function returns all the links found for a given file passed as parameter
    90111Example: mr_file_read_all_link(/lib64) returns (/lib64,/usr/lib64) on a system having a link from /lib64 to /usr/lib64
    91 The return value is a hash of all input files pointing to hash of links
     112The return value is a hash of all input files pointing to the hash of their links
     113That hash needs to be cleaned up after usage
    92114
    93115=cut
     
    96118
    97119# TODO: Can be parallelized
     120# use "our" to keep info between recursive calls
    98121our $files;
     122
    99123
    100124foreach my $f (@_) {
Note: See TracChangeset for help on using the changeset viewer.