Change the interface of loading drivers from rpm package. If no netdrivers attribute specifiec, no driver will be added. If you'd like to add all drivers from rpm packages, using allupdate as key word in netdrivers attribute.

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14022 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
daniceexi 2012-10-16 05:58:29 +00:00
parent 38ce4c7423
commit 5ffbcb5fba
4 changed files with 188 additions and 108 deletions

View File

@ -899,7 +899,7 @@ sub mkinstall
if (!$linuximagetab) {
$linuximagetab=xCAT::Table->new('linuximage', -create=>1);
}
(my $ref1) = $linuximagetab->getAttribs({imagename => $imagename}, 'template', 'pkgdir', 'pkglist', 'partitionfile');
(my $ref1) = $linuximagetab->getAttribs({imagename => $imagename}, 'template', 'pkgdir', 'pkglist', 'partitionfile', 'driverupdatesrc', 'netdrivers');
if ($ref1) {
if ($ref1->{'template'}) {
$img_hash{$imagename}->{template}=$ref1->{'template'};
@ -910,9 +910,9 @@ sub mkinstall
if ($ref1->{'pkglist'}) {
$img_hash{$imagename}->{pkglist}=$ref1->{'pkglist'};
}
if ($ref1->{'partitionfile'}) {
$img_hash{$imagename}->{partitionfile} = $ref1->{'partitionfile'};
}
if ($ref1->{'partitionfile'}) {
$img_hash{$imagename}->{partitionfile} = $ref1->{'partitionfile'};
}
if ($ref1->{'driverupdatesrc'}) {
$img_hash{$imagename}->{driverupdatesrc}=$ref1->{'driverupdatesrc'};
}
@ -1691,6 +1691,7 @@ sub insert_dd {
my @dd_list;
my @rpm_list;
my @driver_list;
my $Injectalldriver;
my @rpm_drivers;
@ -1717,6 +1718,10 @@ sub insert_dd {
}
foreach (split /,/,$drivers) {
if (/^allupdate$/) {
$Injectalldriver = 1;
next;
}
unless (/\.ko$/) {
s/$/.ko/;
}
@ -1726,8 +1731,8 @@ sub insert_dd {
chomp(@dd_list);
chomp(@rpm_list);
unless (@dd_list || @rpm_list ) {
return undef;
unless (@dd_list || (@rpm_list && ($Injectalldriver || @driver_list))) {
return ();
}
# Create the tmp dir for dd hack
@ -1737,7 +1742,7 @@ sub insert_dd {
# dracut + drvier rpm
# !dracut + driver rpm
# !dracut + driver disk
if (!<$install_dir/$os/$arch/Packages/dracut*> || @rpm_list) {
if (!<$install_dir/$os/$arch/Packages/dracut*> || (@rpm_list && ($Injectalldriver || @driver_list))) {
mkpath "$dd_dir/initrd_img"; # The dir for the new initrd
# unzip the initrd image
@ -1747,7 +1752,7 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not gunzip the initial initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
# Extract the files from original initrd
@ -1757,10 +1762,10 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not extract files from the initial initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
if (@rpm_list) {
if (@rpm_list && ($Injectalldriver || @driver_list)) {
# Extract the files from rpm to the tmp dir
mkpath "$dd_dir/rpm";
foreach my $rpm (@rpm_list) {
@ -1790,7 +1795,7 @@ sub insert_dd {
# For dracut mode, only copy the drivers from rpm packages to the /lib/modules/<kernel>
# The driver disk will be handled that append the whole disk to the orignial initrd
if (@rpm_list) {
if (@rpm_list && ($Injectalldriver || @driver_list)) {
# Copy the firmware to the rootimage
if (-d "$dd_dir/rpm/lib/firmware") {
if (! -d "$dd_dir/initrd_img/lib") {
@ -1878,7 +1883,7 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not gunzip modules.cgz from the initial initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
my @modinfo = ();
@ -1892,7 +1897,7 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not mount the driver update disk.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
$cmd = "cd $dd_dir/dd_modules; gunzip -c $dd_dir/mnt/modules.cgz | cpio -id";
@ -1903,7 +1908,7 @@ sub insert_dd {
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not gunzip the modules.cgz from the driver update disk.";
xCAT::MsgUtils->message("E", $rsp, $callback);
system("umount -f $dd_dir/mnt");
return undef;
return ();
}
# Copy all the driver files out
@ -1967,7 +1972,7 @@ sub insert_dd {
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not unmount the driver update disk.";
xCAT::MsgUtils->message("E", $rsp, $callback);
system("umount -f $dd_dir/mnt");
return undef;
return ();
}
# Clean the env
@ -1978,7 +1983,7 @@ sub insert_dd {
}
# Merge the drviers from rpm packages to the initrd
if (@rpm_list) {
if (@rpm_list && ($Injectalldriver || @driver_list)) {
# Copy the firmware to the rootimage
if (-d "$dd_dir/rpm/lib/firmware") {
if (! -d "$dd_dir/initrd_img/lib") {
@ -2034,7 +2039,7 @@ sub insert_dd {
}
}
}
} else {
} elsif ($Injectalldriver) {
# copy all the drviers to the initrd
if (-d "$dd_dir/rpm/lib/modules/$kernelver") {
find(\&get_all_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
@ -2148,7 +2153,7 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked modules.cgz.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
} # End of non dracut
@ -2159,7 +2164,7 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd.";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
copy ("$dd_dir/initrd.img", $img);
@ -2175,7 +2180,7 @@ sub insert_dd {
my $rsp;
push @{$rsp->{data}}, "Merging multiple driver disks requires createrepo and mkisofs utilities";
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
return ();
}
mkpath("$dd_dir/newddimg");
mkpath("$dd_dir/tmpddmnt");
@ -2223,7 +2228,7 @@ sub insert_dd {
}
if (@driver_list) {
push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages.";
} elsif (@rpm_list) {
} elsif (@rpm_list && ($Injectalldriver || @driver_list)) {
push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list)).".";
}
xCAT::MsgUtils->message("I", $rsp, $callback);

View File

@ -634,8 +634,8 @@ sub mkinstall
my %doneimgs;
require xCAT::Template; #only used here, load so memory can be COWed
# Define a variable for driver update list
my @dd_drivers;
# Define a variable for driver update list
my @dd_drivers;
foreach $node (@nodes)
{
my $os;
@ -1395,6 +1395,7 @@ sub insert_dd () {
my @dd_list;
my @rpm_list;
my @driver_list;
my $Injectalldriver;
my @rpm_drivers;
@ -1421,6 +1422,10 @@ sub insert_dd () {
}
foreach (split /,/,$drivers) {
if (/^allupdate$/) {
$Injectalldriver = 1;
next;
}
unless (/\.ko$/) {
s/$/.ko/;
}
@ -1430,8 +1435,8 @@ sub insert_dd () {
chomp(@dd_list);
chomp(@rpm_list);
unless (@dd_list || @rpm_list ) {
return undef;
unless (@dd_list || (@rpm_list && ($Injectalldriver || @driver_list))) {
return ();
}
# Create the tmp dir for dd hack
@ -1443,7 +1448,7 @@ sub insert_dd () {
# Unzip the original initrd
# This only needs to be done for ppc or handling the driver rpm
# For the driver disk against x86, append the driver disk to initrd directly
if ($arch =~/ppc/ || @rpm_list) {
if ($arch =~/ppc/ || (@rpm_list && ($Injectalldriver || @driver_list))) {
if ($arch =~ /ppc/) {
$cmd = "gunzip --quiet -c $pkgdir/1/suseboot/initrd64 > $dd_dir/initrd";
} elsif ($arch =~ /x86/) {
@ -1468,7 +1473,7 @@ sub insert_dd () {
}
# Start to load the drivers from rpm packages
if (@rpm_list) {
if (@rpm_list && ($Injectalldriver || @driver_list)) {
# Extract the files from rpm to the tmp dir
mkpath "$dd_dir/rpm";
foreach my $rpm (@rpm_list) {
@ -1531,7 +1536,7 @@ sub insert_dd () {
}
}
}
} else {
} elsif ($Injectalldriver) {
# copy all the drviers to the initrd
if (-d "$dd_dir/rpm/lib/modules/$kernelver") {
$cmd = "cp -rf $dd_dir/rpm/lib/modules/$kernelver $dd_dir/initrd_img/lib/modules/";
@ -1587,7 +1592,7 @@ sub insert_dd () {
$cmd = "gzip -f $dd_dir/initrd";
xCAT::Utils->runcmd($cmd, -1);
if ($arch =~/ppc/ || @rpm_list) {
if ($arch =~/ppc/ || (@rpm_list && ($Injectalldriver || @driver_list))) {
if ($arch =~/ppc/) {
# make sure the src kernel existed
$cmd = "gunzip -c $pkgdir/1/suseboot/linux64.gz > $dd_dir/kernel";
@ -1626,7 +1631,7 @@ sub insert_dd () {
}
if (@driver_list) {
push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages.";
} elsif (@rpm_list) {
} elsif (@rpm_list && ($Injectalldriver || @driver_list)) {
push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list)).".";
}
xCAT::MsgUtils->message("I", $rsp, $callback);

View File

@ -157,10 +157,24 @@ unless ($osver and $profile) {
my @ndrivers;
if ($netdriver) {
foreach (split /,/,$netdriver) {
if (/^allupdate$/) {
next;
}
unless (/\.ko$/) {
s/$/.ko/;
}
next if (/^$/);
push @ndrivers, $_;
}
if ( ($updates{'netdrivers'} ne $netdriver) and ($tempfile) ) {
$updates{'netdrivers'} = $netdriver;
}
} else {
}
# Use the default list if not specified
unless (@ndrivers) {
if ($arch eq 'x86' or $arch eq 'x86_64') {
@ndrivers = qw/tg3 bnx2 bnx2x e1000 e1000e igb mlx_en virtio_net/;
} elsif ($arch eq 'ppc64') {
@ -169,13 +183,6 @@ if ($netdriver) {
@ndrivers = qw/qdio ccwgroup/;
}
}
foreach (split /,/,$netdriver) {
unless (/\.ko$/) {
s/$/.ko/;
}
next if (/^$/);
push @ndrivers, $_;
}
foreach (@ndrivers) {
unless (/\.ko$/) {
@ -440,8 +447,13 @@ foreach my $dd (@dd_drivers) {
unless (grep { $_ eq $dd} @ndrivers) {
push @new_order, $dd;
}
print "Added driver $dd from driver update disk or driver rpm.\n";
print "Added driver $dd from driver update disk or driver rpm\n";
}
foreach my $driver (@ndrivers) {
print "Added driver $driver from root image\n";
}
if (@new_order) {
@ndrivers = (@new_order, @ndrivers);
}
@ -1561,6 +1573,7 @@ sub load_dd ()
my @rpm_list;
my @driver_list;
my $Injectalldriver;
my @rpm_drivers;
# Parse the parameters to the the source of Driver update disk and Driver rpm, and driver list as well
@ -1585,6 +1598,10 @@ sub load_dd ()
}
foreach (split /,/,$netdriver) {
if (/^allupdate$/) {
$Injectalldriver = 1;
next;
}
unless (/\.ko$/) {
s/$/.ko/;
}
@ -1595,7 +1612,7 @@ sub load_dd ()
chomp(@dd_list);
chomp(@rpm_list);
unless (@dd_list || @rpm_list ) {
unless (@dd_list || (@rpm_list && ($Injectalldriver || @driver_list))) {
return ();
}
@ -1679,54 +1696,72 @@ sub load_dd ()
}
# Loading the drivers from rpm packages
if (@rpm_list) {
if (@rpm_list) {
# Extract the files from rpm to the tmp dir
mkpath "$dd_dir/rpm";
foreach my $rpm (@rpm_list) {
if (-r $rpm) {
if (system ("cd $dd_dir/rpm; rpm2cpio $rpm | cpio -idum")) {
print "Error: Cannot extract the files from the rpm $rpm.\n";
}
} else {
print "Error: Cannot read the rpm $rpm.\n";
if (@rpm_list && ($Injectalldriver || @driver_list)) {
# Extract the files from rpm to the tmp dir
mkpath "$dd_dir/rpm";
foreach my $rpm (@rpm_list) {
if (-r $rpm) {
if (system ("cd $dd_dir/rpm; rpm2cpio $rpm | cpio -idum")) {
print "Error: Cannot extract the files from the rpm $rpm.\n";
}
}
# Copy the firmware to the rootimage
if (-d "$dd_dir/rpm/lib/firmware") {
system ("cp -rf $dd_dir/rpm/lib/firmware $rootimg_dir/lib");
}
# Copy the drivers to the rootimage
if (-d "$dd_dir/rpm/lib/modules/$kernelver") {
if (@driver_list) {
foreach my $driver (@driver_list) {
$driver_name = $driver;
$real_path = "";
find(\&get_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
if ($real_path && $real_path =~ m!$dd_dir/rpm(/lib/modules/$kernelver/.*?)[^\/]*$!) {
if (! -d "$rootimg_dir$1") {
mkpath "$rootimg_dir$1";
}
system ("cp -rf $real_path $rootimg_dir$1");
push @rpm_drivers, $driver;
} else {
print "Error: cannot find the driver $driver from the driver rpms\n";
}
}
} else {
# copy all the drviers to the rootimage
system ("cp -rf $dd_dir/rpm/lib/modules/$kernelver $rootimg_dir/lib/modules/");
find(\&get_all_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
foreach (@all_real_path) {
if (basename($_) =~ /\.ko$/) {
push @rpm_drivers, basename($_);
}
}
}
} else {
print "Warning: cannot find the kernel $kernelver from drvier rpms\n";
print "Error: Cannot read the rpm $rpm.\n";
}
}
# Copy the firmware to the rootimage
if (-d "$dd_dir/rpm/lib/firmware") {
system ("cp -rf $dd_dir/rpm/lib/firmware $rootimg_dir/lib");
}
# Copy the drivers to the rootimage
if (-d "$dd_dir/rpm/lib/modules/$kernelver") {
if (@driver_list) {
foreach my $driver (@driver_list) {
$driver_name = $driver;
$real_path = "";
find(\&get_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
if ($real_path && $real_path =~ m!$dd_dir/rpm(/lib/modules/$kernelver/.*?)[^\/]*$!) {
# remove the old one if existing
@all_real_path = ();
find(\&get_all_path, <$rootimg_dir/lib/modules/$kernelver/*>);
foreach (@all_real_path) {
if (-r $_) {
unlink ($_);
}
}
if (! -d "$rootimg_dir$1") {
mkpath "$rootimg_dir$1";
}
system ("cp -rf $real_path $rootimg_dir$1");
push @rpm_drivers, $driver;
} else {
print "Error: cannot find the driver $driver from the driver rpms\n";
}
}
} elsif ($Injectalldriver) {
# copy all the drviers to the rootimage
find(\&get_all_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
my @all_drivers = @all_real_path;
foreach my $new_driver (@all_drivers) {
if (basename($new_driver) =~ /\.ko$/) {
# remove the old one if existing
$driver_name = basename($new_driver);
@all_real_path = ();
find(\&get_all_path, <$rootimg_dir/lib/modules/$kernelver/*>);
foreach my $old_driver (@all_real_path) {
if (-r $old_driver) {
unlink ($old_driver);
}
}
push @rpm_drivers, basename($new_driver);
}
}
system ("cp -rf $dd_dir/rpm/lib/modules/$kernelver $rootimg_dir/lib/modules/");
}
} else {
print "Warning: cannot find the kernel $kernelver from drvier rpms\n";
}
push @dd_drivers, @rpm_drivers;
}

View File

@ -149,10 +149,29 @@ unless ($osver and $profile) {
my @ndrivers;
if ($netdriver) {
foreach (split /,/,$netdriver) {
if (/^allupdate$/) {
next;
}
unless (/\.ko$/) {
s/$/.ko/;
}
next if (/^$/);
# Do not include qeth module here
# This module is included later on
unless ( $_ =~ m/qeth/i ) {
push @ndrivers, $_;
}
}
if ( ($updates{'netdrivers'} ne $netdriver) and $tempfile ) {
$updates{'netdrivers'} = $netdriver;
}
} else {
}
# Use the default list if not specified
unless (@ndrivers) {
if ($arch eq 'x86' or $arch eq 'x86_64') {
@ndrivers = qw/tg3 bnx2 bnx2x e1000 e1000e igb mlx_en be2net/;
} elsif ($arch eq 'ppc64') {
@ -162,20 +181,6 @@ if ($netdriver) {
}
}
foreach (split /,/,$netdriver) {
unless (/\.ko$/) {
s/$/.ko/;
}
next if (/^$/);
# Do not include qeth module here
# This module is included later on
unless ( $_ =~ m/qeth/i ) {
push @ndrivers, $_;
}
}
foreach (@ndrivers) {
unless (/\.ko$/) {
s/$/.ko/;
@ -712,8 +717,13 @@ foreach my $dd (@dd_drivers) {
unless (grep { $_ eq $dd} @ndrivers) {
push @new_order, $dd;
}
print "Added driver $dd from driver update disk or driver rpm.\n";
print "Added driver $dd from driver update disk or driver rpm\n";
}
foreach my $driver (@ndrivers) {
print "Added driver $driver from root image\n";
}
if (@new_order) {
@ndrivers = (@new_order, @ndrivers);
}
@ -1590,7 +1600,8 @@ sub load_dd()
my @dd_list;
my @rpm_list;
my @driver_list;
my $Injectalldriver;
my @rpm_drivers;
# Parse the parameters to the the source of Driver update disk and Driver rpm, and driver list as well
@ -1615,6 +1626,10 @@ sub load_dd()
}
foreach (split /,/,$netdriver) {
if (/^allupdate$/) {
$Injectalldriver = 1;
next;
}
unless (/\.ko$/) {
s/$/.ko/;
}
@ -1624,7 +1639,7 @@ sub load_dd()
chomp(@dd_list);
chomp(@rpm_list);
unless (@dd_list || @rpm_list ) {
unless (@dd_list || (@rpm_list && ($Injectalldriver || @driver_list))) {
return ();
}
@ -1757,7 +1772,7 @@ sub load_dd()
}
# Loading the drivers from rpm packages
if (@rpm_list) {
if (@rpm_list && ($Injectalldriver || @driver_list)) {
# Extract the files from rpm to the tmp dir
mkpath "$dd_dir/rpm";
foreach my $rpm (@rpm_list) {
@ -1782,6 +1797,15 @@ sub load_dd()
$real_path = "";
find(\&get_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
if ($real_path && $real_path =~ m!$dd_dir/rpm(/lib/modules/$kernelver/.*?)[^\/]*$!) {
# remove the old one if existing
@all_real_path = ();
find(\&get_all_path, <$rootimg_dir/lib/modules/$kernelver/*>);
foreach (@all_real_path) {
if (-r $_) {
unlink ($_);
}
}
if (! -d "$rootimg_dir$1") {
mkpath "$rootimg_dir$1";
}
@ -1791,15 +1815,26 @@ sub load_dd()
print "Error: cannot find the driver $driver from the driver rpms\n";
}
}
} else {
} elsif ($Injectalldriver) {
# copy all the drviers to the rootimage
system ("cp -rf $dd_dir/rpm/lib/modules/$kernelver $rootimg_dir/lib/modules/");
find(\&get_all_path, <$dd_dir/rpm/lib/modules/$kernelver/*>);
foreach (@all_real_path) {
if (basename($_) =~ /\.ko$/) {
push @rpm_drivers, basename($_);
my @all_drivers = @all_real_path;
foreach my $new_driver (@all_drivers) {
if (basename($new_driver) =~ /\.ko$/) {
# remove the old one if existing
$driver_name = basename($new_driver);
@all_real_path = ();
find(\&get_all_path, <$rootimg_dir/lib/modules/$kernelver/*>);
foreach my $old_driver (@all_real_path) {
if (-r $old_driver) {
unlink ($old_driver);
}
}
push @rpm_drivers, basename($new_driver);
}
}
system ("cp -rf $dd_dir/rpm/lib/modules/$kernelver $rootimg_dir/lib/modules/");
}
} else {
print "Warning: cannot find the kernel $kernelver from drvier rpms\n";