From 9f1fd6c2237ec22a62b7ca4d824a2895fdf08c66 Mon Sep 17 00:00:00 2001 From: daniceexi Date: Sun, 3 Nov 2013 09:36:55 -0500 Subject: [PATCH] code drop for xeon phi (mic) support phase 2. 1. Support mpss 3.1; 2. Support to install software in .filelist, rpm and simple format; 3. Support the hcp software to be installed in .filelist format by genimage command; 4. Support the nfs mount setting for mic node (base on litefile table); 5. Support Internal bridge setting for mic host --- xCAT-server/lib/xcat/plugins/ipmi.pm | 2 +- xCAT-server/lib/xcat/plugins/mic.pm | 197 ++++++++++++++---- xCAT-server/sbin/configmic | 215 ++++++++++++-------- xCAT-server/sbin/flashmic | 14 +- xCAT-server/share/xcat/netboot/mic/genimage | 182 ++++++++++++++++- 5 files changed, 483 insertions(+), 127 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index cd62f9800..7b1886562 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -6540,7 +6540,7 @@ sub scan { my $output = xCAT::Utils->runxcmd({ command => ['xdsh'], node => $nodes, - arg => ['/opt/intel/mic/bin/micinfo', '-listDevices'] }, $subreq, 0, 1); + arg => ['micinfo', '-listDevices'] }, $subreq, 0, 1); # parse the output from 'xdsh micinfo -listDevices' my %host2mic; diff --git a/xCAT-server/lib/xcat/plugins/mic.pm b/xCAT-server/lib/xcat/plugins/mic.pm index 3c64260db..45ce72c51 100644 --- a/xCAT-server/lib/xcat/plugins/mic.pm +++ b/xCAT-server/lib/xcat/plugins/mic.pm @@ -307,7 +307,7 @@ sub rinv { my @hosts = (keys %$host2mic); my $output = xCAT::Utils->runxcmd({ command => ['xdsh'], node => \@hosts, - arg => ["/opt/intel/mic/bin/micinfo"]}, $subreq, 0, 1); + arg => ["/usr/bin/micinfo"]}, $subreq, 0, 1); # classify all the output with the host name my %outofhost; @@ -379,6 +379,27 @@ sub copytar { 'f=s' => \$file); } + # get the + my ($mpssver, $targetos, $targetosver); + my $tarfilename = basename ($file); + if ($tarfilename =~ /mpss-([\d\.-]+)-(rhel|suse)-([\d\.-]+)\.tar/) { + $mpssver = $1; + $targetos = $2; + $targetosver = $3; + } elsif ($tarfilename =~ /mpss/) { + if ($osname =~ /mpss-([\d\.-]+)-(rhel|suse)-([\d\.-]+)/) { + $mpssver = $1; + $targetos = $2; + $targetosver = $3; + } else { + xCAT::MsgUtils->message("E", {error=>["The flag -n needs be specified to identify the version of mpss and target os. The value format for -n must be mpss-[mpss_versoin]-[rhel/suse]-[os_version]."], errorcode=>["1"]}, $callback); + return; + } + } else { + # not for Xeon Phi + return; + } + my $installroot = "/install"; my @entries = xCAT::TableUtils->get_site_attribute("installdir"); my $t_entry = $entries[0]; @@ -386,35 +407,40 @@ sub copytar { $installroot = $t_entry; } - my $tmpdir = "/tmp/mictmp"; - my $destdir = "$installroot/$osname"; - rmtree ($tmpdir); - mkpath ($tmpdir); + my $destdir = "$installroot/mpss$mpssver"; mkpath ($destdir); + # creae the default dirs in the mpss image dir + mkpath ("$destdir/common"); + mkpath ("$destdir/overlay/package"); + mkpath ("$destdir/overlay/rpm"); + `/bin/touch "$destdir/common.filelist"`; + # extract the files from the mpss tar file - my $cmd = "tar xvf $file -C $tmpdir"; - my @output = xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC != 0) { - xCAT::MsgUtils->message("E", {error=>["Error when run [$cmd], @output"], errorcode=>["1"]}, $callback); - return 1; - } + #my $cmd = "tar xvf $file -C $tmpdir"; + #my @output = xCAT::Utils->runcmd($cmd, -1); + #if ($::RUNCMD_RC != 0) { + # xCAT::MsgUtils->message("E", {error=>["Error when run [$cmd], @output"], errorcode=>["1"]}, $callback); + # return 1; + #} # get the rpm packages intel-mic-gpl and intel-mic-flash which include the files for root file system, flash ... - my @micgpl = <$tmpdir/*/intel-mic-gpl*>; - my @micflash = <$tmpdir/*/intel-mic-flash*>; - unless (-r $micgpl[0] && -r $micflash[0]) { - xCAT::MsgUtils->message("E", {error=>["Error: Cannot get the rpm files intel-mic-gpl or intel-mic-flash from the tar file."], errorcode=>["1"]}, $callback); - return 1; - } + #my @micgpl = <$tmpdir/*/intel-mic-gpl*>; + #my @micflash = <$tmpdir/*/intel-mic-flash*>; + #unless (-r $micgpl[0] && -r $micflash[0]) { + # xCAT::MsgUtils->message("E", {error=>["Error: Cannot get the rpm files intel-mic-gpl or intel-mic-flash from the tar file."], errorcode=>["1"]}, $callback); + # return 1; + #} # extract the files from rpm packages - $cmd = "cd $destdir; rpm2cpio $micgpl[0] | cpio -idum; rpm2cpio $micflash[0] | cpio -idum"; - @output = xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC != 0) { - xCAT::MsgUtils->message("E", {error=>["Error when run [$cmd], @output"], errorcode=>["1"]}, $callback); - return 1; - } + #$cmd = "cd $destdir; rpm2cpio $micgpl[0] | cpio -idum; rpm2cpio $micflash[0] | cpio -idum"; + #@output = xCAT::Utils->runcmd($cmd, -1); + #if ($::RUNCMD_RC != 0) { + # xCAT::MsgUtils->message("E", {error=>["Error when run [$cmd], @output"], errorcode=>["1"]}, $callback); + # return 1; + #} + + # generate the image objects my $oitab = xCAT::Table->new('osimage'); @@ -426,14 +452,22 @@ sub copytar { my %values; $values{'imagetype'} = "linux"; $values{'provmethod'} = "netboot"; - $values{'rootfstype'} = "ramdisk"; $values{'description'} = "Linux for Intel mic"; $values{'osname'} = "Linux"; - $values{'osvers'} = "mic"; + $values{'osvers'} = "mic$mpssver"; $values{'osarch'} = "x86_64"; $values{'profile'} = "compute"; - my $imagename = "$osname-netboot-compute"; + # set the osdistroname attr which will be used to get the repo path for the rpm install in osimage + my $osver; + if ($targetos =~ /rhel/) { + $osver = "rhels".$targetosver; + } elsif ($targetos =~ /suse/) { + $osver = "sles".$targetosver; + } + $values{'osdistroname'} = $osver."-x86_64"; + + my $imagename = "mpss$mpssver-$osver-compute"; $oitab->setAttribs({'imagename' => $imagename}, \%values); my $litab = xCAT::Table->new('linuximage'); @@ -441,13 +475,15 @@ sub copytar { xCAT::MsgUtils->message("E", {error=>["Error: Cannot open table linuximage."], errorcode=>["1"]}, $callback); return 1; } + + my $otherpkgdir = "$installroot/post/otherpkgs/mic$mpssver/x86_64"; # set a default package list my $pkglist = "$::XCATROOT/share/xcat/netboot/mic/compute.pkglist"; - $litab->setAttribs({'imagename' => $imagename}, {'pkgdir' => $destdir, 'pkglist' => $pkglist}); + $litab->setAttribs({'imagename' => $imagename}, {'pkgdir' => $destdir, 'pkglist' => $pkglist, 'otherpkgdir' => $otherpkgdir}); xCAT::MsgUtils->message("I", {data=>["The image $imagename has been created."]}, $callback); - rmtree ($tmpdir); + #rmtree ($tmpdir); } # get the console configuration for rcons: @@ -627,7 +663,7 @@ sub nodeset { my $nthash = $nttab->getNodesAttribs($nodes,['provmethod']); foreach my $node (@$nodes) { unless (defined ($nthash->{$node}->[0]->{'provmethod'})) { - xCAT::MsgUtils->message("E", {error=>["The provmethod for the node $node must be set by [nodeset osimage=] or set in the provmethod attribute of the node."], errorcode=>["1"]}, $callback); + xCAT::MsgUtils->message("E", {error=>["The must be specified in [nodeset osimage=] or it must be set in the provmethod attribute before running nodeset command."], errorcode=>["1"]}, $callback); return; } } @@ -660,6 +696,22 @@ sub nodeset { $osimage{$_->{'imagename'}} = $_->{'pkgdir'}; } + # get the bridge configuration from nics table + my $nicstab = xCAT::Table->new("nics"); + unless ($nicstab) { + xCAT::MsgUtils->message("E", {error=>["Cannot open the nics table."], errorcode=>["1"]}, $callback); + return; + } + + # get mic mount entries from litefile table + my $lftab = xCAT::Table->new("litefile"); + unless ($lftab) { + xCAT::MsgUtils->message("E", {error=>["Cannot open the litefile table."], errorcode=>["1"]}, $callback); + return; + } + my @lfentall = $lftab->getAttribs({'image'=>'ALL'}, 'file', 'options'); + + # get the tftp dir and create the path for mic configuration my $tftpdir = "/tftpboot"; my @entries = xCAT::TableUtils->get_site_attribute("$tftpdir"); @@ -677,6 +729,8 @@ sub nodeset { #overlay=ol1 my %imghash; # cache of osimage information my @hosts = (keys %$host2mic); + # get the bridge configuration from nics table, use host as key + my $nicshash = $nicstab->getNodesAttribs(\@hosts, ['nicips', 'nictypes']); foreach my $host (@hosts) { my @cfgfile; push @cfgfile, "#XCAT MIC CONFIGURATION FILE#"; @@ -696,7 +750,7 @@ sub nodeset { # and make sure the osimage which set to the mic shold be same for all the mics on one host if ($osimg) { if ($osimg ne $nthash->{$micname}->[0]->{'provmethod'}) { - xCAT::MsgUtils->message("E", {error=>["The provmethod for the nodes in the same host should be same."], errorcode=>["1"]}, $callback); + xCAT::MsgUtils->message("E", {error=>["The provmethod for the mic nodes which located in the same host should be same."], errorcode=>["1"]}, $callback); return; } } else { @@ -721,6 +775,24 @@ sub nodeset { return; } + # get the bridge configuration + my ($brgip, $brgtype); + if (defined ($nicshash->{$host}) && defined ($nicshash->{$host}->[0]->{'nicips'})) { + foreach (split(/,/, $nicshash->{$host}->[0]->{'nicips'})) { + if (/$micbrg!(.+)/) { + $brgip = $1; + } + } + push @cfgfile, "brgip=$brgip"; + + foreach (split(/,/, $nicshash->{$host}->[0]->{'nictypes'})) { + if (/$micbrg!(.+)/) { + $brgtype = $1; + } + } + push @cfgfile, "brgtype=$brgtype"; + } + # generate the mic specific entry in the configuration file my $micattrs = "$micid:ip=$micip|br=$micbrg|name=$micname"; if (defined ($michash->{$micname}->[0]->{'onboot'})) { @@ -735,17 +807,61 @@ sub nodeset { push @cfgfile, "imgpath=$osimage{$osimg}"; # get all the overlay entries for the osimage and do the cache for image - # search all the dir in the overlay dir execpt the system dir (system dir includes the files + # search all the dir in the /install//overlay dir, the dir tree in 'overlay' should be following: + # |--mnt + # | `--system (files for system boot) + # | |--common.filelist + # | `--common + # | `--overlay + # | `--overlay + # | `--rpm + # | `--simple + # | |--simple.cfg (the file must be multiple lines of 'a->b' format; 'a' is dir name in simple/, 'b' is the path on mic for 'a' + # | `--package + # | |--the base file for fs + # | `--opt/mic + # | |--yy.filelist + # | `--yy + # | |--xx.filelist + # | `--xx + #the system dir (system dir includes the files # which generated by genimage command, and will be copied to mic osimage separated) + if (! -d "$osimage{$osimg}/system") { + xCAT::MsgUtils->message("E", {error=>["Missed system directory in $osimage{$osimg}. Did you miss to run genimage command?"], errorcode=>["1"]}, $callback); + return; + } if (defined ($imghash{$osimg}{'ollist'})) { push @cfgfile, "overlay=$imghash{$osimg}{'ollist'}"; } else { - my @overlays = <$osimage{$osimg}/opt/intel/mic/filesystem/overlay/*>; + my @items = <$osimage{$osimg}/overlay/*>; my $ollist; # overlay list - foreach my $obj (@overlays) { + foreach my $obj (@items) { my $objname = basename($obj); - if (-d $obj && $objname ne "system") { - $ollist .= ",$objname"; + if (-d $obj) { + if ($objname eq "rpm") { + $ollist .= ",rpm:$objname"; + } elsif ($objname eq "simple") { + if (-f "$osimage{$osimg}/overlay/simple/simple.cfg") { + open (SIMPLE, "<$osimage{$osimg}/overlay/simple/simple.cfg"); + while () { + if (/(.+)->(.+)/) { + $ollist .= ",simple:$_"; + } + } + } + } elsif ($objname eq "package") { + my @pfl = <$osimage{$osimg}/overlay/package/opt/mic/*.filelist>; + foreach my $filelist (@pfl) { + $filelist = basename($filelist); + if ($filelist =~ /(.+)\.filelist/) { + $ollist .= ",pfilelist:$1"; + } + } + } + } else { + if ($objname =~ /(.+)\.filelist/) { + $ollist .= ",filelist:$1"; + } } } $ollist =~ s/^,//; @@ -754,6 +870,16 @@ sub nodeset { push @cfgfile, "overlay=$ollist"; } + # generate the nfs mount entries for mic node + my @lfentimg = $lftab->getAttribs({'image'=>$osimg}, 'file', 'options'); + foreach my $ent (@lfentall, @lfentimg) { + if (defined ($ent->{'options'}) && $ent->{'options'} eq "micmount") { + if (defined ($ent->{'file'})) { + push @cfgfile, "micmount=$ent->{file}"; + } + } + } + if (open (CFG, ">$tftpdir/xcat/miccfg/miccfg.$host")) { foreach (@cfgfile) { print CFG $_."\n"; @@ -763,6 +889,7 @@ sub nodeset { xCAT::MsgUtils->message("E", {error=>["Cannot open the file $tftpdir/xcat/miccfg/miccfg.$host to write."], errorcode=>["1"]}, $callback); return; } + } # run the cmd on the host to configure the mic diff --git a/xCAT-server/sbin/configmic b/xCAT-server/sbin/configmic index 7eb4d10f3..659c87ace 100755 --- a/xCAT-server/sbin/configmic +++ b/xCAT-server/sbin/configmic @@ -20,7 +20,7 @@ $| = 1; my $tmppath = "/tmp/mictmp"; my $logpath = "/var/log/xcat/"; my $logfile = "$logpath/configmic.log"; -my $micmnt = "/opt/intel/mic/mnt"; +my $micmnt = "/var/mpss/mnt"; mkpath $tmppath; mkpath $micmnt; @@ -92,6 +92,9 @@ my %miccfg; my $miclist; my $overlay; my $ospath; +my $brgname; +my $brgip; +my $brgtype; while () { if (/(\d+):(.*)/) { my $deviceid = $1; @@ -99,13 +102,24 @@ while () { foreach (@params) { my ($n, $v) = split (/=/, $_); $miccfg{$deviceid}{$n} = $v; + if ($n eq 'br') { + $brgname = $v; + } } } elsif (/^miclist=(.*)/) { $miclist = $1; } elsif (/^overlay=(.*)/) { $overlay = $1; } elsif (/^imgpath=(.*)/) { - $ospath= $1; + $ospath = $1; + } elsif (/^brgip=(.*)/) { + $brgip = $1; + } elsif (/^brgtype=(.*)/) { + $brgtype = $1; + } elsif (/^micmount=(.+)/) { + if ($1 =~ /(.+):(.+)/) { + $miccfg{'micmount'}{$1} = $2; + } } } close (CFGFILE); @@ -113,8 +127,8 @@ close (CFGFILE); $miclist =~ s/,/ /g; # add the mount entry for mounting of root fs from master to /etc/fstab -# e.g. mount $master:/install/mpss3 /opt/intel/mic/mnt -$cmd = "grep $master:$ospath $micmnt /etc/fstab "; +# e.g. mount $master:/install/mpss3 /var/mpss/mnt +$cmd = "grep \'$master:$ospath \' $micmnt /etc/fstab "; ($rc, $output) = runsyscmd ($cmd); if ($rc) { # not found the exact mount entry @@ -140,9 +154,33 @@ if ($rc) { runsyscmd ($cmd); } +# the dir structure in mount opint 'mnt' +# |--mnt +# | `--system (files for system boot) +# | |--common.filelist +# | `--common +# | `--overlay +# | `--overlay +# | `--rpm +# | `--simple +# | |--simple.cfg (the file must be multiple lines of 'a->b' format; 'a' is dir name in simple/, 'b' is the path on mic for 'a' +# | `--package +# | |--the base file for fs +# | `--opt/mic +# | |--yy.filelist +# | `--yy +# | |--xx.filelist +# | `--xx + # make sure the remote files are accessable -unless (-r "$micmnt/opt/intel/mic/filesystem/base.filelist") { - outputmsg("Error: cannot access the $micmnt/opt/intel/mic/filesystem/base.filelist\n", 8); +unless (-r "$micmnt/common.filelist") { + outputmsg("Error: cannot access the $micmnt/common.filelist\n", 8); +} + +# initialize mic card if it has not been +if (! -f "/etc/mpss/default.conf") { + $cmd = "micctrl --initdefaults"; + runsyscmd ($cmd, "Error: failed to initiate the mic configuration file.\n", 200) } # start to configure the mic @@ -162,12 +200,12 @@ while ($i > 0) { $i--; } -# remove the mic configuration file -unlink ("/etc/sysconfig/mic/default.conf"); +# remove the mic configuration files and source files for ramfs, them will be recreated base on setting +unlink ("/etc/mpss/default.conf"); foreach my $mic (split (/ /, $miclist)) { - unlink ("/etc/sysconfig/mic/$mic.conf"); - unlink ("/opt/intel/mic/filesystem/$mic.filelist"); - rmtree ("/opt/intel/mic/filesystem/$mic"); + unlink ("/etc/mpss/$mic.conf"); + unlink ("/var/mpss/$mic.filelist"); + rmtree ("/var/mpss/$mic"); } # reset the configuration to default @@ -175,34 +213,79 @@ $cmd = "micctrl --initdefaults $miclist"; runsyscmd ($cmd, "Error: failed to initiate the mic devices.\n", 200); # configure the base dir -$cmd = "micctrl --basedir=/opt/intel/mic/mnt/opt/intel/mic/filesystem/base --list=/opt/intel/mic/mnt/opt/intel/mic/filesystem/base.filelist $miclist"; -runsyscmd ($cmd, "Error: failed to change the base dir for mic file system..\n", 101); +#$cmd = "micctrl --basedir=/opt/intel/mic/mnt/opt/intel/mic/filesystem/base --list=/opt/intel/mic/mnt/opt/intel/mic/filesystem/base.filelist $miclist"; +#runsyscmd ($cmd, "Error: failed to change the base dir for mic file system..\n", 101); # configure the commondir -$cmd = "micctrl --commondir=/opt/intel/mic/mnt/opt/intel/mic/filesystem/common --list=/opt/intel/mic/mnt/opt/intel/mic/filesystem/common.filelist $miclist"; -runsyscmd ($cmd, "Error: failed to change the common dir for mic file system.\n", 102); +$cmd = "micctrl --commondir=$micmnt/common --list=$micmnt/common.filelist $miclist"; +runsyscmd ($cmd, "Error: failed to set the common dir for mic file system.\n", 102); -# configure the overlay +# configure the overlay file system my @ols = split (/,/, $overlay); foreach (@ols) { - $cmd = "micctrl --overlay=filelist --state=on --source=/opt/intel/mic/mnt/opt/intel/mic/filesystem/overlay/$_ --target=/opt/intel/mic/mnt/opt/intel/mic/filesystem/overlay/$_.filelist $miclist"; - runsyscmd ($cmd, "Error: failed to change the overlay dir for mic file system.\n", 103); + if (/^filelist:(.+)/) { + $cmd = "micctrl --overlay=Filelist --source=$micmnt/overlay/$1/ --target=$micmnt/overlay/$1.filelist --state=on $miclist"; + } elsif (/^pfilelist:(.+)/) { + $cmd = "micctrl --overlay=Filelist --source=$micmnt/overlay/package/ --target=$micmnt/overlay/package/opt/mic/$1.filelist --state=on $miclist"; + } elsif (/^rpm:(.+)/) { + $cmd = "micctrl --overlay=RPM --source=$micmnt/overlay/rpm/ --state=on $miclist"; + } elsif (/^simple:(.+)->(.+)/) { + $cmd = "micctrl --overlay=Simple --source=$micmnt/overlay/simple/$1 --target=$2 --state=on $miclist"; + } + + runsyscmd ($cmd, "Error: failed to set the overlay dir for mic file system.\n", 103); +} + +# configure bridge for mic +my ($netbit, $brc, $mtu); +if ($brgtype && $brgtype =~ /Internal/i) { + $cmd = "micctrl --addbridge=$brgname --type=Internal --ip=$brgip"; + runsyscmd ($cmd, "Error: failed to add bridge for mic.\n", 111); +} else { + # for External bridge, it must has been set up correctly + # get the ip of the bridge + $cmd = "ip -4 addr show"; + ($rc, $output) = runsyscmd ($cmd); + $cmd = "ip -4 route show"; + my ($rc2, $output2) = runsyscmd ($cmd); + foreach (@$output) { + if (/inet\s+([\d\.]+)\/(\d+)\s+brd\s+([\d\.]+) scope global $brgname/) { + $brgip = $1; + $netbit = $2; + $brc = $3; + last; + } elsif (/\d+:\s+$brgname:.*mtu\s+(\d+)/) { + $mtu = $1; + } + } + + unless ($brgip && $netbit && $brc) { + outputmsg("Error: failed to get ip for the bridge $brgname.\n", 110); + } + + # add the bridge to mic configuration + # since the micctrl --addbridge= --type=external --ip= --netbits=8 does not + # work with '--netbis=8', the bridge configuration has been done by changing cfg file directly. + #$cmd = "echo \"Bridge $brg External $brip $netbit $mtu\" >> /etc/sysconfig/mic/default.conf"; + #runsyscmd ($cmd); + $cmd = "micctrl --addbridge=$brgname --type=external --ip=$brgip --netbits=$netbit --mtu=$mtu"; + runsyscmd ($cmd, "Error: failed to add bridge for mic.\n", 111); } # do the mic specific configuration -$cmd = "ip -4 addr show"; -($rc, $output) = runsyscmd ($cmd); -$cmd = "ip -4 route show"; -my ($rc2, $output2) = runsyscmd ($cmd); foreach my $micid (keys %miccfg) { + if ($micid !~ /^\d*$/) { + # not mic specific, return + next; + } my $micname = $miccfg{$micid}{'name'}; # set the boot device to be staticramfs so that the osimage don't need to generated for every boot - $cmd = "micctrl --rootdev=StaticRamFS --target=/opt/intel/mic/filesystem/$micname.image mic$micid"; - runsyscmd ($cmd, "Error: failed to set root image for mic.\n", 104); + #$cmd = "micctrl --rootdev=StaticRamFS --target=/opt/intel/mic/filesystem/$micname.image mic$micid"; + #runsyscmd ($cmd, "Error: failed to set root image for mic.\n", 104); # set the linux kernel location - $cmd = "micctrl --osimage=$micmnt/lib/firmware/mic/uos.img mic$micid"; - runsyscmd ($cmd, "Error: failed to linux kernle location for mic.\n", 105); + #$cmd = "micctrl --osimage=$micmnt/lib/firmware/mic/uos.img mic$micid"; + #runsyscmd ($cmd, "Error: failed to linux kernle location for mic.\n", 105); # set the autoboot if ($miccfg{$micid}{'onboot'} =~ /no/i) { @@ -213,79 +296,47 @@ foreach my $micid (keys %miccfg) { runsyscmd ($cmd, "Error: failed to set the autoboot for mic.\n", 106); # set the hostname - $cmd = "sed \"s/Hostname .*/Hostname \"$micname\"/\" /etc/sysconfig/mic/mic$micid.conf > $tmppath/mic$micid.conf"; + $cmd = "sed \"s/Hostname .*/Hostname \"$micname\"/\" /etc/mpss/mic$micid.conf > $tmppath/mic$micid.conf"; runsyscmd ($cmd, "Error: failed to set hostname for mic.\n", 107); - copy ("$tmppath/mic$micid.conf", "/etc/sysconfig/mic/mic$micid.conf"); + copy ("$tmppath/mic$micid.conf", "/etc/mpss/mic$micid.conf"); # configure the Verbose log if ($miccfg{$micid}{'vlog'} =~ /yes/i) { - $cmd = "sed \"s/VerboseLogging .*/VerboseLogging \"Enabled\"/\" /etc/sysconfig/mic/mic$micid.conf > $tmppath/mic$micid.conf"; + $cmd = "sed \"s/VerboseLogging .*/VerboseLogging \"Enabled\"/\" /etc/mpss/mic$micid.conf > $tmppath/mic$micid.conf"; runsyscmd ($cmd, "Error: failed to set Verbose log for mic.\n", 108); - copy ("$tmppath/mic$micid.conf", "/etc/sysconfig/mic/mic$micid.conf"); + copy ("$tmppath/mic$micid.conf", "/etc/mpss/mic$micid.conf"); } - # configure the bridge and ip for the mic - # get the ip of the bridge - my $brg = $miccfg{$micid}{br}; - my ($brip, $netbit, $brc, $mtu); - foreach (@$output) { - if (/inet\s+([\d\.]+)\/(\d+)\s+brd\s+([\d\.]+) scope global $brg/) { - $brip = $1; - $netbit = $2; - $brc = $3; - last; - } elsif (/\d+:\s+$brg:.*mtu\s+(\d+)/) { - $mtu = $1; - } - } - - unless ($brip && $netbit && $brc) { - outputmsg("Error: failed to get ip for the bridge $brg.\n", 110); - } - - # add the bridge to mic configuration - # since the micctrl --addbridge= --type=external --ip= --netbits=8 does not - # work with '--netbis=8', the bridge configuration has been done by changing cfg file directly. - $cmd = "echo \"Bridge $brg External $brip $netbit $mtu\" >> /etc/sysconfig/mic/default.conf"; - runsyscmd ($cmd); - - # configre network for each mic - $cmd = "micctrl --network=static --bridge=".$brg." --ip=".$miccfg{$micid}{ip}." mic$micid"; + # configure network for each mic + $cmd = "micctrl --network=static --bridge=".$miccfg{$micid}{br}." --ip=".$miccfg{$micid}{ip}." mic$micid"; runsyscmd ($cmd, "Error: failed to generate IP configuration for mic.\n", 104); + # configure nfs mount for each mic + foreach my $msrc (keys %{$miccfg{'micmount'}}) { + $cmd = "micctrl --addnfs=$brgip:/$msrc --dir=$miccfg{micmount}{$msrc} mic$micid"; + runsyscmd ($cmd, "Error: failed to add nfs mount for mic.\n", 104); + } + # take the configuration to effect $cmd = "micctrl --resetconfig mic$micid"; runsyscmd ($cmd, "Error: failed to spread the configuration.\n", 201); - # get the gateway of the bridge - my $netmask = 2**$netbit - 1 << (32 - $netbit); - my $brnet = unpack("N", inet_aton($brip)); - $brnet &= $netmask; - $brnet = inet_ntoa(pack("N", $brnet)); - my $brgw; - foreach (@$output2) { - if (/$brnet\/$netbit\s+dev\s+$brg.*src\s+([\d\.]+)/) { - $brgw = $1; - last; - } - } - - # configure the mic interface to the real interface cfg file instead of mic cfg file - # this also because the defect of intel tool so that we have to do it separated - my @ifcfg = ("IPADDR=$miccfg{$micid}{ip}\n", "GATEWAY=$brgw\n", "PREFIX=$netbit\n"); - unless (open (IFCFG, ">/opt/intel/mic/filesystem/mic$micid/etc/sysconfig/network/ifcfg-mic0")) { - outputmsg ("Error: cannot open ifcfg-mic$micid\n", 111); - } - print IFCFG @ifcfg; - close (IFCFG); + # back up the /etc/passwd and /etc/shadow which generated by 'micctrl --initdefaults' + system ("/bin/cp -rf /var/mpss/mic$micid/etc/passwd /tmp/mictmp/passwd"); + system ("/bin/cp -rf /var/mpss/mic$micid/etc/shadow /tmp/mictmp/shadow"); # copy the system files which generated by genimage to the micdir # e.g. /etc/hosts /etc/passwd ... - my $src = "$micmnt/opt/intel/mic/filesystem/overlay/system/*"; - my $dst = "/opt/intel/mic/filesystem/mic$micid"; + my $src = "$micmnt/system/*"; + my $dst = "/var/mpss/mic$micid"; + $cmd = "/bin/cp -rf $src $dst"; runsyscmd ($cmd, "Error: failed to copy the overlay dir.\n", 300); + # append /etc/passwd and /etc/shadow which generated by 'micctrl --initdefaults' + system ("/bin/grep micuser /tmp/mictmp/passwd >> /var/mpss/mic$micid/etc/passwd"); + system ("/bin/grep micuser /tmp/mictmp/shadow >> /var/mpss/mic$micid/etc/shadow"); + # generate the static root file system in ramdisk format $cmd = "micctrl --updateramfs mic$micid"; runsyscmd ($cmd, "Error: failed to generate the static ramfs.\n", 301); @@ -308,6 +359,10 @@ while ($i > 0) { # notice nodeset command, the configuratoin has been done foreach my $micid (keys %miccfg) { + if ($micid !~ /^\d*$/) { + # not mic specific, return + next; + } outputmsg ("MICMSG:$miccfg{$micid}{'name'}: Done\n"); } diff --git a/xCAT-server/sbin/flashmic b/xCAT-server/sbin/flashmic index daee9256b..108af6c7e 100755 --- a/xCAT-server/sbin/flashmic +++ b/xCAT-server/sbin/flashmic @@ -20,8 +20,12 @@ $| = 1; my $tmppath = "/tmp/mictmp"; my $logpath = "/var/log/xcat/"; my $logfile = "$logpath/flash.log"; -my $micmnt = "/opt/intel/mic/mnt"; -my $flashpath = "$micmnt/opt/intel/mic/flash"; +my $micmnt = "/var/mpss/mnt"; +my $flashpath = "$micmnt/usr/share/mpss/flash"; + +if (! -d "$flashpath") { + $flashpath = "/usr/share/mpss/flash"; +} mkpath $tmppath; mkpath $micmnt; @@ -110,8 +114,8 @@ close (CFGFILE); $miclist =~ s/,/ /g; # add the mount entry for mounting of root fs from master to /etc/fstab -# e.g. mount $master:/install/mpss3 /opt/intel/mic/mnt -$cmd = "grep $master:$ospath $micmnt /etc/fstab "; +# e.g. mount $master:/install/mpss3 /var/mpss/mnt +$cmd = "grep \'$master:$ospath \' $micmnt /etc/fstab "; ($rc, $output) = runsyscmd ($cmd); if ($rc) { # not found the exact mount entry @@ -155,7 +159,7 @@ foreach my $micid (keys %miccfg) { $micidlist =~ s/^,//; # do the flash -$cmd = "/opt/intel/mic/bin/micflash -update $flashpath -device $micidlist"; +$cmd = "micflash -update $flashpath -device $micidlist"; ($rc, $output) = runsyscmd ($cmd); # generate the output messages diff --git a/xCAT-server/share/xcat/netboot/mic/genimage b/xCAT-server/share/xcat/netboot/mic/genimage index ae7e93758..3be6eb295 100755 --- a/xCAT-server/share/xcat/netboot/mic/genimage +++ b/xCAT-server/share/xcat/netboot/mic/genimage @@ -14,19 +14,193 @@ use strict; use File::Path; use File::Basename; use File::Copy; +use File::Find; use Getopt::Long; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); +use FindBin; +use lib "$FindBin::Bin/../imgutils"; +use imgutils; +use xCAT::Table; + + +my $arch; +my $profile; +my $osver; my $pkglist; my $srcdir; +my $otherpkglist; +my $rootimg_dir; +my $srcdir_otherpkgs; +my $tempfile; GetOptions( + 'a=s' => \$arch, + 'p=s' => \$profile, + 'o=s' => \$osver, 'pkglist=s' => \$pkglist, 'srcdir=s' => \$srcdir, + 'otherpkglist=s' => \$otherpkglist, + 'otherpkgdir=s' => \$srcdir_otherpkgs, + 'tempfile=s' =>\$tempfile, ); -my $fsdir = "$srcdir/opt/intel/mic/filesystem"; -my $systemdir = "$fsdir/overlay/system"; +$rootimg_dir = "$srcdir/overlay/package/"; +my @yumdirs; +my $imagename; +if (@ARGV > 0) { + $imagename=$ARGV[0]; +} +unless ($imagename) { + print "Error: osimage name needs be specified.\n"; + exit 1; +} + +sub isyumdir { + if ($File::Find::name =~ /\/repodata$/) { + my $location = $File::Find::name; + $location =~ s/\/repodata$//; + push @yumdirs,$location; + } +} + +if ($otherpkglist) { + + # get the distroname + my $oitab = xCAT::Table->new('osimage'); + unless ($oitab) { + print "Error: Cannot open table osimage.\n"; + return 1; + } + # generate the yum configuration file + + my $aiddistro; + my $oient = $oitab->getAttribs({'imagename'=>$imagename}, 'osdistroname'); + if ($oient && $oient->{'osdistroname'}) { + $aiddistro = $oient->{'osdistroname'}; + } + + my $distrotab = xCAT::Table->new('osdistro'); + unless ($distrotab) { + print "Error: Cannot open table osdistro.\n"; + return 1; + } + my $aiddistrodir; + my $distroent = $distrotab->getAttribs({'osdistroname'=>$aiddistro}, 'dirpaths'); + if ($distroent && $distroent->{'dirpaths'}) { + $aiddistrodir = $distroent->{'dirpaths'} + } + + my @pkgdirs = split(",", $aiddistrodir); + foreach my $dir (@pkgdirs) { + find(\&isyumdir, <$dir/>); + if (!grep /$dir/, @yumdirs) { + print "The repository for $dir should be created before running the genimge. Try to run [createrepo $dir].\n"; + } + } + + my $yumconfig; + open($yumconfig,">","/tmp/genimage.$$.yum.conf"); + my $repnum=0; + foreach $srcdir (@yumdirs) { + print $yumconfig "[$aiddistro-$repnum]\nname=$aiddistro-$repnum\nbaseurl=file://$srcdir\ngpgpcheck=0\n\n"; + $repnum += 1; + } + $repnum-=1; + close($yumconfig); + mkpath "$rootimg_dir/etc"; + + my %extra_hash = imgutils::get_package_names($otherpkglist); + my %extrapkgnames; + + my %repohash; + if (keys(%extra_hash) > 0) { + open($yumconfig,">>","/tmp/genimage.$$.yum.conf"); + my $index=1; + my $pass; + foreach $pass (sort {$a <=> $b} (keys(%extra_hash))) { + foreach (keys(%{$extra_hash{$pass}})) { + if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;} + print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs/$_\ngpgpcheck=0\n\n"; + $repohash{$pass}{$index} = 1; + $index++; + my $pa=$extra_hash{$pass}{$_}; + $extrapkgnames{$pass} .= " " . join(' ', @$pa); + } + } + close($yumconfig); + $index--; + my $yumcmd_base = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* "; + foreach (0..$repnum) { + $yumcmd_base .= "--enablerepo=$aiddistro-$_ "; + } + + foreach $pass (sort {$a <=> $b} (keys(%extra_hash))) { + my $yumcmd = $yumcmd_base; + foreach my $repo_index ( keys %{$repohash{$pass}} ) { + $yumcmd .= "--enablerepo=otherpkgs$repo_index "; + } + + system("$yumcmd clean all"); + + my $envlist; + if(exists($extra_hash{$pass}{ENVLIST})){ + $envlist = join(' ', @{$extra_hash{$pass}{ENVLIST}}); + } + # remove the packages that are specified in the otherpkgs.list files with leading '-' + my $yumcmd_remove= "$yumcmd erase "; + if (exists ($extra_hash{$pass}{'PRE_REMOVE'})) { + my $pa=$extra_hash{$pass}{'PRE_REMOVE'}; + my $rm_packges= join(' ', @$pa); + if ($rm_packges) { + print "$envlist $yumcmd_remove $rm_packges\n"; + my $rc = system("$envlist $yumcmd_remove $rm_packges"); + if ($rc) { + print "yum invocation failed\n"; + exit 1; + } + } + } + + # install extra packages + $yumcmd .= "install "; + # append extra pkg names to yum command + if ($extrapkgnames{$pass}) { + $yumcmd .= " $extrapkgnames{$pass} "; + $yumcmd =~ s/ $/\n/; + + print "$envlist $yumcmd\n"; + my $rc = system("$envlist $yumcmd"); + if ($rc) { + print "yum invocation failed\n"; + exit 1; + } + } else { + print "No Packages marked for install\n"; + } + + # remove the packages that are specified in the otherpkgs.list files with leading '--' + if (exists ($extra_hash{$pass}{'POST_REMOVE'})) { + my $pa=$extra_hash{$pass}{'POST_REMOVE'}; + my $rm_packges= join(' ', @$pa); + if ($rm_packges) { + print "$envlist $yumcmd_remove $rm_packges\n"; + my $rc = system("$envlist $yumcmd_remove $rm_packges"); + if ($rc) { + print "yum invocation failed\n"; + exit 1; + } + } + } + } + } +} + + + + +my $fsdir = "$srcdir/"; +my $systemdir = "$fsdir/system"; mkpath ($systemdir); # this is the file list which includes the files which should be copied @@ -57,15 +231,11 @@ foreach my $file (@sysfilelist) { copy ($file, "$systemdir/$file"); } -#Change the /bin/bash to /bin/sh in the /etc/passwd since base file system of mic only has sh. -my $cmd = "sed \"s/\\/bin\\/bash/\\/bin\\/sh/\" $systemdir/etc/passwd > /tmp/passwd.mic; mv /tmp/passwd.mic $systemdir/etc/passwd;"; -system ($cmd); # Create emtpy common dir and common.filelist for later using mkpath ("$fsdir/common"); system ("touch $fsdir/common.filelist"); - print "Genimage for mic has been done.\n"; 1;