diff --git a/perl-xCAT/xCAT/Common.pm b/perl-xCAT/xCAT/Common.pm index ff722e079..34df42054 100644 --- a/perl-xCAT/xCAT/Common.pm +++ b/perl-xCAT/xCAT/Common.pm @@ -8,6 +8,7 @@ use File::stat; use File::Copy; use xCAT::Usage; use Thread qw/yield/; +use Storabe qw/store_fd fd_retrieve/; BEGIN { @@ -29,19 +30,18 @@ sub forward_data { my $rfh; my $rc = @ready_fds; foreach $rfh (@ready_fds) { - my $data; - if ($data = <$rfh>) { - while ($data !~ /ENDOFFREEZE6sK4ci/) { - $data .= <$rfh>; - } + my $responses; + eval { + $responses = fd_retrieve($rfh); + }; + if ($@ and $@ =~ /^Magic number checking on storable file/) { #this most likely means we ran over the end of available input + $fds->remove($rfh); + close($rfh); + } else { eval { print $rfh "ACK\n"; }; #Ignore ack loss due to child giving up and exiting, we don't actually explicitly care about the acks - my $responses=thaw($data); foreach (@$responses) { $callback->($_); } - } else { - $fds->remove($rfh); - close($rfh); } } yield(); #Try to avoid useless iterations as much as possible @@ -62,8 +62,7 @@ sub send_data { foreach(@_) { my %output; if (ref($_) eq HASH) { - print $out freeze([$_]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([$_],$out); yield(); waitforack($out); next; @@ -97,8 +96,7 @@ sub send_data { } else { $output{node}->[0]->{data}->[0]->{contents}->[0]=$text; } - print $out freeze([\%output]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%output],$out); yield(); waitforack($out); } diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index bf31071e1..5fb734d11 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -36,7 +36,7 @@ package xCAT::Table; use xCAT::MsgUtils; use Sys::Syslog; -use Storable qw/freeze thaw/; +use Storable qw/freeze thaw store_fd fd_retrieve/; use IO::Socket; #use Data::Dumper; use POSIX qw/WNOHANG/; @@ -92,8 +92,6 @@ sub dbc_call { sub dbc_submit { my $request = shift; $request->{'wantarray'} = wantarray(); - my $data = freeze($request); - $data.= "\nENDOFFREEZEQFVyo4Cj6Q0v\n"; my $clisock; my $tries=300; while($tries and !($clisock = IO::Socket::UNIX->new(Peer => $dbsockpath, Type => SOCK_STREAM, Timeout => 120) ) ) { @@ -105,22 +103,20 @@ sub dbc_submit { use Carp qw/cluck/; cluck(); } - print $clisock $data; - $data=""; + store_fd($request,$clisock); + #print $clisock $data; + my $data=""; my $lastline=""; - while (read($clisock,$lastline,32768)) { #$lastline ne "ENDOFFREEZEQFVyo4Cj6Q0j\n" and $lastline ne "*XCATBUGDETECTED*76e9b54341\n") { #index($lastline,"ENDOFFREEZEQFVyo4Cj6Q0j") < 0) { -# $lastline = <$clisock>; - $data .= $lastline; - } + my $retdata = fd_retrieve($clisock); close($clisock); - if ($lastline =~ m/\*XCATBUGDETECTED\*76e9b54341\n\z/) { #if it was an error + if (ref $retdata eq "SCALAR") { #bug detected #in the midst of the operation, die like it used to die my $err; - $data =~ /\*XCATBUGDETECTED\*:(.*):\*XCATBUGDETECTED\*/s; + $$retdata =~ /\*XCATBUGDETECTED\*:(.*):\*XCATBUGDETECTED\*/s; $err = $1; die $err; } - my @returndata = @{thaw($data)}; + my @returndata = @{$retdata}; if (wantarray) { return @returndata; } else { @@ -201,8 +197,7 @@ sub init_dbworker { xCAT::MsgUtils->message("S","xcatd: possible BUG encountered by xCAT DB worker ".$err); if ($currcon) { eval { #avoid hang by allowin client to die too - print $currcon "*XCATBUGDETECTED*:$err:*XCATBUGDETECTED*\n"; - print $currcon "*XCATBUGDETECTED*76e9b54341\n"; + store_fd("*XCATBUGDETECTED*:$err:*XCATBUGDETECTED*\n",$currcon); $clientset->remove($currcon); close($currcon); }; @@ -230,13 +225,14 @@ sub handle_dbc_conn { my $client = shift; my $clientset = shift; my $data; - if ($data = <$client>) { - my $lastline; - while ($lastline ne "ENDOFFREEZEQFVyo4Cj6Q0v\n") { #$data !~ /ENDOFFREEZEQFVyo4Cj6Q0v/) { - $lastline = <$client>; - $data .= $lastline; - } - my $request = thaw($data); + my $request; + eval { + $request = fd_retrieve($client); + }; + if ($@ and $@ =~ /^Magic number checking on storable file/) { #this most likely means we ran over the end of available input + $clientset->remove($client); + close($client); + } elsif ($request) { my $response; my @returndata; if ($request->{'wantarray'}) { @@ -244,12 +240,7 @@ sub handle_dbc_conn { } else { @returndata = (scalar(handle_dbc_request($request))); } - $response = freeze(\@returndata); - # $response .= "\nENDOFFREEZEQFVyo4Cj6Q0j\n"; - print $client $response; - $clientset->remove($client); - close($client); - } else { #Connection terminated, clean up + store_fd(\@returndata,$client); $clientset->remove($client); close($client); } diff --git a/xCAT-server/lib/xcat/plugins/blade.pm b/xCAT-server/lib/xcat/plugins/blade.pm index 0a7e7ba4f..d42efd9c1 100644 --- a/xCAT-server/lib/xcat/plugins/blade.pm +++ b/xCAT-server/lib/xcat/plugins/blade.pm @@ -38,7 +38,7 @@ use XML::Simple; $XML::Simple::PREFERRED_PARSER='XML::Parser'; #use Data::Dumper; use POSIX "WNOHANG"; -use Storable qw(freeze thaw); +use Storable qw(freeze thaw store_fd fd_retrieve); use IO::Select; use IO::Handle; use Time::HiRes qw(gettimeofday sleep); @@ -5354,18 +5354,18 @@ sub forward_data { my $rc = @ready_fds; foreach $rfh (@ready_fds) { my $data; - if ($data = <$rfh>) { - while ($data !~ /ENDOFFREEZE6sK4ci/) { - $data .= <$rfh>; - } + my $responses; + eval { + $responses = fd_retrieve($rfh); + }; + if ($@ and $@ =~ /^Magic number checking on storable file/) { #this most likely means we ran over the end of available input + $fds->remove($rfh); + close($rfh); + } else { eval { print $rfh "ACK\n"; }; #Ignore ack loss due to child giving up and exiting, we don't actually explicitly care about the acks - my $responses=thaw($data); foreach (@$responses) { $callback->($_); } - } else { - $fds->remove($rfh); - close($rfh); } } yield; #Try to avoid useless iterations as much as possible @@ -5397,8 +5397,7 @@ sub dompa { error=>["Unable to perform http login to $mpa"], errorcode=>['3'] }]); - print $out freeze([\%outh]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%outh],$out); yield; waitforack($out); %outh=(); @@ -5432,8 +5431,7 @@ sub dompa { foreach (@output) { (my $tag, my $text)=split /:/,$_,2; push (@{$outh{node}->[0]->{data}},{desc=>[$tag],contents=>[$text]}); - print $out freeze([\%outh]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%outh],$out); yield; waitforack($out); %outh=(); @@ -5497,8 +5495,7 @@ sub dompa { # $output{node}->[0]->{data}->[0]->{contents}->[0]=$text; #} - print $out freeze([\%output]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%output],$out); yield; waitforack($out); } @@ -5548,8 +5545,7 @@ sub dompa { foreach (keys %{$mpahash{$mpa}->{nodes}}) { push (@{$err{node}},{name=>[$_],error=>["Cannot communicate with $mpa"],errorcode=>[1]}); } - print $out freeze([\%err]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%err],$out); yield; waitforack($out); return 1,"General error establishing SNMP communication"; @@ -5681,8 +5677,7 @@ sub dompa { $output{node}->[0]->{data}->[0]->{contents}->[0]=$text; } } - print $out freeze([\%output]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%output],$out); yield; waitforack($out); } diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 393848ebd..fe8e2972b 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -50,7 +50,7 @@ use XML::Simple; $XML::Simple::PREFERRED_PARSER='XML::Parser'; use Data::Dumper; use POSIX "WNOHANG"; -use Storable qw(freeze thaw); +use Storable qw(freeze thaw store_fd fd_retrieve); use IO::Select; use IO::Handle; use Time::HiRes qw(gettimeofday sleep); @@ -2857,12 +2857,15 @@ sub forward_data { my $rc = @ready_fds; foreach $rfh (@ready_fds) { my $data; - if ($data = <$rfh>) { - while ($data !~ /ENDOFFREEZE6sK4ci/) { - $data .= <$rfh>; - } + my $responses; + eval { + $responses = fd_retrieve($rfh); + }; + if ($@ and $@ =~ /^Magic number checking on storable file/) { #this most likely means we ran over the end of available input + $fds->remove($rfh); + close($rfh); + } else { eval { print $rfh "ACK\n"; }; #ignore failures to send inter-process ack - my $responses=thaw($data); foreach (@$responses) { #save the nodes that has errors and the ones that has no-op for use by the node status monitoring my $no_op=0; @@ -2885,9 +2888,6 @@ sub forward_data { $callback->($_); } } else { - $fds->remove($rfh); - close($rfh); - } } yield(); #Try to avoid useless iterations as much as possible return $rc; @@ -2926,8 +2926,7 @@ sub dohyp { foreach (keys %{$hyphash{$hyp}->{nodes}}) { push (@{$err{node}},{name=>[$_],error=>["Cannot communicate via libvirt to $hyp"],errorcode=>[1]}); } - print $out freeze([\%err]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%err],$out); yield(); waitforack($out); %err=(node=>[]); @@ -2935,8 +2934,7 @@ sub dohyp { foreach (keys %{$hyphash{$hyp}->{nodes}}) { push (@{$err{node}},{name=>[$_],error=>["Forcibly relocating VM from $hyp"],errorcode=>[1]}); } - print $out freeze([\%err]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%err],$out); } else { return 1,"General error establishing libvirt communication"; } @@ -2947,8 +2945,7 @@ sub dohyp { foreach(@output) { my %output; if (ref($_)) { - print $out freeze([$_]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([$_],$out); yield(); waitforack($out); next; @@ -2973,8 +2970,7 @@ sub dohyp { } else { $output{node}->[0]->{error} = $text; } - print $out freeze([\%output]); - print $out "\nENDOFFREEZE6sK4ci\n"; + store_fd([\%output],$out); yield(); waitforack($out); }