Matthew Booth
2010-Apr-29 10:47 UTC
[Libguestfs] [PATCH 1/2] SSH: Check for complete transfer of disk images
--- lib/Sys/VirtV2V/Transfer/SSH.pm | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/lib/Sys/VirtV2V/Transfer/SSH.pm b/lib/Sys/VirtV2V/Transfer/SSH.pm index 3b08716..ac5a384 100644 --- a/lib/Sys/VirtV2V/Transfer/SSH.pm +++ b/lib/Sys/VirtV2V/Transfer/SSH.pm @@ -82,6 +82,7 @@ sub transfer my $vol = $target->create_volume($name, $size); $vol->open(); + my $written = 0; for (;;) { my $buffer; # Transfer in 8k chunks @@ -93,10 +94,16 @@ sub transfer last if ($in == 0); $vol->write($buffer); + $written += length($buffer); } $vol->close(); + die(user_message(__x("Didn't receive full volume. Received {received} ". + "of {total} bytes.", + received => $written, + total => $size))) unless ($written == $size); + waitpid($pid, 0) == $pid or die("error reaping child: $!"); # If the child returned an error, check for anything on its stderr if ($? != 0) { -- 1.6.6.1
Matthew Booth
2010-Apr-29 10:47 UTC
[Libguestfs] [PATCH 2/2] SSH: Don't mix buffered reads with sysread
SSH transfer contained a race due to use of buffered IO to read the initial size, followed by sysread() to read the data. If data was available for reading at the time the size was read, some of it would be consumed and buffered. It would subsequently not be available to sysread(), meaning it wasn't copied. Fix by using buffered IO consistently. --- lib/Sys/VirtV2V/Transfer/SSH.pm | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/Sys/VirtV2V/Transfer/SSH.pm b/lib/Sys/VirtV2V/Transfer/SSH.pm index ac5a384..0868b37 100644 --- a/lib/Sys/VirtV2V/Transfer/SSH.pm +++ b/lib/Sys/VirtV2V/Transfer/SSH.pm @@ -86,7 +86,7 @@ sub transfer for (;;) { my $buffer; # Transfer in 8k chunks - my $in = sysread($fh, $buffer, 8 * 1024); + my $in = read($fh, $buffer, 8 * 1024); die(user_message(__x("Error reading data from {path}: {error}", path => $path, error => $!))) if (!defined($in)); -- 1.6.6.1
Richard W.M. Jones
2010-Apr-29 20:43 UTC
[Libguestfs] [PATCH 1/2] SSH: Check for complete transfer of disk images
On Thu, Apr 29, 2010 at 11:47:48AM +0100, Matthew Booth wrote:> --- > lib/Sys/VirtV2V/Transfer/SSH.pm | 7 +++++++ > 1 files changed, 7 insertions(+), 0 deletions(-)ACK both. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Maybe Matching Threads
- [PATCH 1/2] Refactor guest and volume creation into Sys::VirtV2V::Target::LibVirt
- [PATCH] RHEV: Use dd and direct io to write to NFS
- [PATCH] Add SSH transfer method
- [PATCH] Remove v2v-snapshot
- [PATCH] Add LocalCopy transfer method to transfer local files to a target