Changeset 3249 for branches/3.2


Ignore:
Timestamp:
Feb 27, 2014, 3:48:19 AM (6 years ago)
Author:
bruno
Message:
  • create function mr_kernel_get_modules in MondoRescue::Kernel.pm from code previously in get-modules.pl which now just calls it
Location:
branches/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/lib/MondoRescue/Kernel.pm

    r3219 r3249  
    1212use strict 'vars';
    1313use Data::Dumper;
     14use POSIX "uname";
    1415use lib qw (lib);
    1516use ProjectBuilder::Base;
     
    2627
    2728our @ISA = qw(Exporter);
    28 our @EXPORT = qw(mr_kernel_get_version);
     29our @EXPORT = qw(mr_kernel_get_version mr_kernel_get_modules);
    2930
    3031=pod
     
    5556$kernelver = "unknown";
    5657
    57 ($os,$ver,$kernelver,$rest) = split(/ /,$mr_os->{'files'}->{'proc_version'}) if ($mr_os->{'os'} eq "linux");
     58my ($sysname, $nodename, $release, $version, $machine ) = uname();
     59$kernelver = $release if (defined $release);
    5860
    5961return($kernelver);
     62}
     63
     64
     65=item B<mr_kernel_get_modules>
     66
     67Tis function takes as input the kernel version to examined (can be undef in which case the running kernel is used) and a list of modules names to examined as well (can be undef in which case all modules ar taken)
     68This function returns back the modules path as a first argument and the list of relative modules path for the modules names passed.
     69
     70Example:
     71mr_kernel_get_modules("3.8.13.4-desktop-1.mga3","ext3") returns
     72("/lib/modules/3.8.13.4-desktop-1.mga3", "kernel/fs/ext3/ext3.ko.xz","kernel/fs/jbd/jbd.ko.xz")
     73
     74=cut
     75
     76sub mr_kernel_get_modules {
     77
     78my $ver = $_;
     79$ver = mr_kernel_get_version() if (not defined ($ver));
     80my @allmodules = @_;
     81
     82my $module = "";
     83my %modlist;
     84my $void = "";
     85my @allmodpaths;
     86my $modulepath = "";
     87
     88# If no module names list passed as parameter, the work on all modules of the system
     89if (not defined $allmodules[0]) {
     90    open(LSMOD, "/sbin/lsmod |") or die "Unable to launch lsmod";
     91    while (<LSMOD>) {
     92        next if (/^Module/);
     93        ($module, $void) = split(/ /);
     94        push @allmodules,$module;
     95    }
     96    close(LSMOD);
     97}
     98
     99open(DEPMOD, "/sbin/depmod -n $ver |") or die "Unable to launch depmod";
     100while (<DEPMOD>) {
     101    ($module, $void) = split(/:/);
     102    last if ($module =~ /^#/);
     103    chomp($void);
     104    $modlist{$module} = $void;
     105    pb_log(2,"Depmod on $module gives $void\n");
     106}
     107close(DEPMOD);
     108
     109#print Dumper(%modlist)."\n";
     110
     111my $lib;
     112my $modulep;
     113my $kernelv;
     114my $modpath;
     115
     116foreach my $m (@allmodules) {
     117    pb_log(1,"Analyzing $m\n");
     118    open(MODINFO, "/sbin/modinfo -n -k $ver $m 2>/dev/null |") or die "Unable to launch modinfo";
     119    $module = <MODINFO>;
     120    close(MODINFO);
     121    if ((not defined $module) || ($module =~ '^$')) {
     122        pb_log(1,"WARNING: No modinfo for module $m\n");
     123        next;
     124    }
     125    chomp($module);
     126    ($void,$lib,$modulep,$kernelv,$modpath) = split(/\//,$module,5);
     127    next if (not defined $modpath);
     128    pb_log(2,"modpath: $modpath\n");
     129    push @allmodpaths,$modpath,split(/ /,$modlist{$modpath});
     130}
     131$modulepath = "/$lib/$modulep/$kernelv";
     132pb_log(1,"modules path: $modulepath\n");
     133pb_log(1,"all modpaths: ".join(' ',@allmodpaths)."\n");
     134return($modulepath,@allmodpaths);
    60135}
    61136
  • branches/3.2/mindi/get-modules.pl

    r3213 r3249  
    44use POSIX "uname";
    55use Data::Dumper;
     6use ProjectBuilder::Base;
     7use MondoRescue::Kernel;
    68
    7 my ($sysname, $nodename, $release, $version, $machine ) = uname();
    8 my $ver = "";
    9 my $module = "";
    10 my %modlist;
    11 my $void = "";
    12 my $allmodules = "";
     9my $ver = undef;
    1310
    14 
    15 if (not (defined $ARGV[0])) {
    16         $ver = $release;
    17 } else {
    18         $ver = $ARGV[0];
     11if ((defined $ARGV[0]) && ($ARGV[0] eq "-v")) {
     12    #$pbverbose = 1;
     13    shift;
    1914}
    20 open(LSMOD, "/sbin/lsmod |") or die "Unable to launch lsmod";
    21 open(DEPMOD, "/sbin/depmod -n $ver |") or die "Unable to launch depmod";
    22 
    23 while (<DEPMOD>) {
    24     ($module, $modlist{$module}) = split(/:/);
    25     chomp($modlist{$module});
    26     last if ($module =~ /^#/);
    27     #print "Analyzing $module\n";
     15if ((defined $ARGV[0]) && ($ARGV[0] eq "-k")) {
     16    shift;
     17    $ver = $ARGV[0];
     18    shift;
    2819}
    29 print Dumper(%modlist)."\n";
    30 while (<LSMOD>) {
    31     next if (/^Module/);
    32     ($module, $void) = split(/ /);
    33     #print "Analyzing $module\n";
    34     $module = `/sbin/modinfo -n $module`;
    35     chomp($module);
    36     my ($void,$lib,$modulep,$kernelv,$modpath) = split(/\//,$module,5);
    37     print "modpath: $modpath\n";
    38     $allmodules .= $modlist{$modpath};
    39 }
    40 close(LSMOD);
    41 close(DEPMOD);
    42 $allmodules =~ s/\n/ /g;
    43 $allmodules =~ s/  */ /g;
    44 $allmodules =~ s/ [0-9A-z\/]*\// /g;
    45 $allmodules =~ s/\.ko.xz//g;
    46 print "all modules: $allmodules\n";
     20my ($modulepath,@allmodpaths) = mr_kernel_get_modules($ver,@ARGV);
     21print "modules path: $modulepath\n";
     22print "all modpaths: ".join(' ',@allmodpaths)."\n";
Note: See TracChangeset for help on using the changeset viewer.