-Add -f flag to xcatd to keep in foreground

-Fix xcatd subprocesses to not overwrite their own parent fd when spawning more subprocesses
-Add hierarchy function to fedora plugin


git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@331 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-01-27 17:37:24 +00:00
parent f68aa9065d
commit 254432e82d
2 changed files with 54 additions and 11 deletions

View File

@ -24,6 +24,44 @@ sub handled_commands {
}
}
sub preprocess_request {
my $req = shift;
my $callback = shift;
if ($req->{command}->[0] eq 'copycd') { #don't farm out copycd
return [$req];
}
my %localnodehash;
my %dispatchhash;
my $nrtab = xCAT::Table->new('noderes');
foreach my $node (@{$req->{node}}) {
my $nodeserver;
my $tent = $nrtab->getNodeAttribs($node,['tftpserver']);
if ($tent) { $nodeserver = $tent->{tftpserver} }
unless ($tent and $tent->{tftpserver}) {
$tent = $nrtab->getNodeAttribs($node,['servicenode']);
if ($tent) { $nodeserver = $tent->{servicenode} }
}
if ($nodeserver) {
$dispatchhash{$nodeserver}->{$node} = 1;
} else {
$localnodehash{$node} = 1;
}
}
my @requests;
my $reqc = {%$req};
$reqc->{node} = [ keys %localnodehash ];
if (scalar(@{$reqc->{node}})) { push @requests,$reqc }
foreach my $dtarg (keys %dispatchhash) { #iterate dispatch targets
my $reqcopy = {%$req}; #deep copy
$reqcopy->{'_xcatdest'} = $dtarg;
$reqcopy->{node} = [ keys %{$dispatchhash{$dtarg}}];
push @requests,$reqcopy;
}
return \@requests;
}
sub process_request {
my $request = shift;
my $callback = shift;
@ -53,7 +91,6 @@ sub mknetboot {
my $installroot;
if ($sitetab) {
(my $ref) = $sitetab->getAttribs({key=>installdir},value);
print Dumper($ref);
if ($ref and $ref->{value}) {
$installroot = $ref->{value};
}
@ -268,7 +305,6 @@ sub copycd {
my $sitetab = xCAT::Table->new('site');
if ($sitetab) {
(my $ref) = $sitetab->getAttribs({key=>installdir},value);
print Dumper($ref);
if ($ref and $ref->{value}) {
$installroot = $ref->{value};
}

View File

@ -40,8 +40,10 @@ use Storable qw(dclone);
use POSIX qw(WNOHANG setsid);
use strict;
my $pidfile;
my $foreground;
GetOptions(
'pidfile|p=s' => \$pidfile
'pidfile|p=s' => \$pidfile,
'foreground|f' => \$foreground
);
my $quit = 0;
@ -321,7 +323,9 @@ sub scan_plugins {
}
}
scan_plugins;
daemonize;
unless ($foreground) {
daemonize;
}
$SIG{CHLD} = sub { while (waitpid(-1,WNOHANG) > 0) {} };
$SIG{TERM} = $SIG{INT} = sub { printf("Asked to quit...\n"); $quit++ };
@ -518,11 +522,12 @@ sub plugin_command {
require $plugins_dir."/".$modname.".pm";
$children++;
my $pfd; #will be referenced for inter-process messaging.
my $parfd; #not causing a problem that I discern yet, but theoretically
my $child;
if ($sock) { #If $sock not passed in, don't fork..
socketpair($pfd, $parent_fd,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die "socketpair: $!";
socketpair($pfd, $parfd,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die "socketpair: $!";
#pipe($pfd,$cfd);
$parent_fd->autoflush(1);
$parfd->autoflush(1);
$pfd->autoflush(1);
$child = xCAT::Utils->xfork;
} else {
@ -530,6 +535,7 @@ sub plugin_command {
}
unless (defined $child) { die "Fork failed"; }
if ($child == 0) {
$parent_fd = $parfd;
my $oldprogname=$$progname;
$$progname=$oldprogname.": $modname instance";
if ($sock) { close $pfd; }
@ -546,7 +552,7 @@ sub plugin_command {
exit(0);
}
} else {
close $parent_fd;
close $parfd;
$check_fds->add($pfd);
}
}
@ -583,7 +589,7 @@ sub dispatch_callback {
sub relay_dispatch {
my $fds = shift;
my @ready_ins = $fds->can_read(0);
my @ready_ins = $fds->can_read(0.2);
foreach my $rin (@ready_ins) {
my $data;
if ($data = <$rin>) {
@ -626,13 +632,13 @@ sub dispatch_request {
my $childrn=0;
$SIG{CHLD} = sub {while (waitpid(-1, WNOHANG) > 0) { $childrn--; } };
#TODO: calls to dispatch must be parallelized
foreach (@{$reqs}) {
my $pfd;
my $parfd; #use a private variable so it won't trounce itself recursively
my $child;
delete $_->{noderange};
socketpair($pfd, $dispatch_parentfd,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die "socketpair: $!";
$dispatch_parentfd->autoflush(1);
socketpair($pfd, $parfd,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die "socketpair: $!";
$parfd->autoflush(1);
$pfd->autoflush(1);
$child = xCAT::Utils->xfork;
if ($child) {
@ -643,6 +649,7 @@ sub dispatch_request {
unless (defined $child) {
$dispatch_cb->({error=>['Fork failure dispatching request'],errorcode=>[1]});
}
$dispatch_parentfd = $parfd;
if ($_->{'_xcatdest'} and thishostisnot($_->{'_xcatdest'})) {
$ENV{XCATHOST} = ( $_->{'_xcatdest'} =~ /:/ ? $_->{'_xcatdest'} : $_->{'_xcatdest'}.":3001" );
eval {