From 906688785c433b9c6c17e6f1d39dbcc3026397a4 Mon Sep 17 00:00:00 2001 From: jjhua Date: Thu, 13 Dec 2012 05:27:24 +0000 Subject: [PATCH] make the improvment of the performance on xdsh with -e git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14638 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/DSHCLI.pm | 19 +++++--- perl-xCAT/xCAT/DSHCore.pm | 93 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/DSHCLI.pm b/perl-xCAT/xCAT/DSHCLI.pm index a37eecbc5..a315e13d1 100644 --- a/perl-xCAT/xCAT/DSHCLI.pm +++ b/perl-xCAT/xCAT/DSHCLI.pm @@ -1017,6 +1017,7 @@ sub fork_fanout_dsh { my $user_target = shift @$targets_waiting; my $target_properties = $$resolved_targets{$user_target}; + my @commands; my $localShell = ($$options{'syntax'} eq 'csh') ? '/bin/csh' : '/bin/sh'; my @dsh_command = ($localShell, '-c'); @@ -1151,9 +1152,10 @@ sub fork_fanout_dsh "TRACE:Environment: Exporting File.@env_rcp_command "; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); # copy the Env Variable input file to the nodes - my @env_rcp_process = - xCAT::DSHCore->fork_no_output($user_target, @env_rcp_command); - waitpid($env_rcp_process[0], undef); + #my @env_rcp_process = + # xCAT::DSHCore->fork_no_output($user_target, @env_rcp_command); + #waitpid($env_rcp_process[0], undef); + push @commands, \@env_rcp_command; } my $tmp_cmd_file; if ($$options{'execute'}) @@ -1200,9 +1202,10 @@ sub fork_fanout_dsh $rsp->{data}->[0] = "TRACE:Execute: Exporting File:@exe_rcp_command"; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); - my @exe_rcp_process = - xCAT::DSHCore->fork_no_output($user_target, @exe_rcp_command); - waitpid($exe_rcp_process[0], undef); + #my @exe_rcp_process = + # xCAT::DSHCore->fork_no_output($user_target, @exe_rcp_command); + #waitpid($exe_rcp_process[0], undef); + push @commands, \@exe_rcp_command; } else @@ -1241,7 +1244,9 @@ sub fork_fanout_dsh # input -E file #print "Command=@dsh_command\n"; - @process_info = xCAT::DSHCore->fork_output($user_target, @dsh_command); + #@process_info = xCAT::DSHCore->fork_output($user_target, @dsh_command); + push (@commands, \@dsh_command); #print Dumper(\@commands); + @process_info = xCAT::DSHCore->fork_output_for_commands($user_target, @commands); if ($process_info[0] == -2) { my $rsp = {}; diff --git a/perl-xCAT/xCAT/DSHCore.pm b/perl-xCAT/xCAT/DSHCore.pm index 96c05fd37..5cd4df743 100644 --- a/perl-xCAT/xCAT/DSHCore.pm +++ b/perl-xCAT/xCAT/DSHCore.pm @@ -159,6 +159,99 @@ no strict; use strict; } + +#--------------------------------------------------------------------------- + +=head3 + fork_output_for_commands + + Forks a process for the given command array and returns the process + ID for the forked process and references to all I/O pipes for STDOUT + and STDERR. In the child process, it will invoke the xCAT::DSHCore->fork_no_output() + for the first command which is a no-output command and waitpid(). And then execute + the left commands in the child process. + + Arguments: + $fork_id - unique identifer to use for tracking the forked process + @command - command and parameter array to execute in the forkec process + + Returns: + $pid - process identifer for the forked process + + Globals: + None + + Error: + None + + Example: + $pid = xCAT::DSHCore->fork_output_for_commands('hostname1PID', @command_array); + + Comments: + +=cut + +#--------------------------------------------------------------------------- + + +sub fork_output_for_commands +{ + my ($class, $fork_id, @commands) = @_; +no strict; + my $pid; + my %pipes = (); + + my $rout_fh = "rout_$fork_id"; + my $rerr_fh = "rerr_$fork_id"; + my $wout_fh = "wout_$fork_id"; + my $werr_fh = "werr_$fork_id"; + + (pipe($rout_fh, $wout_fh) == -1) && return (-1, undef); + (pipe($rerr_fh, $werr_fh) == -1) && return (-2, undef); + + if ($pid = fork) + { + close($wout_fh); + close($werr_fh); + } + + elsif (defined $pid) + { + close($rout_fh); + close($rerr_fh); + + !(open(STDOUT, ">&$wout_fh")) && return (-5, undef); + !(open(STDERR, ">&$werr_fh")) && return (-6, undef); + + select(STDOUT); + $| = 1; + select(STDERR); + $| = 1; + + my $command0 = $commands[0]; + my @exe_command0_process = xCAT::DSHCore->fork_no_output($fork_id, @$command0); + waitpid($exe_command0_process[0], undef); + + my $t_command = $commands[1]; + my @command = @$t_command; + if (!(exec {$command[0]} @command)) + { + return (-4, undef); + } + + } + else + { + return (-3, undef); + } + + return ($pid, *$rout_fh, *$rerr_fh, *$wout_fh, *$werr_fh); +use strict; +} + + + + #--------------------------------------------------------------------------- =head3