Matthew Booth
2010-Apr-06 14:04 UTC
[Libguestfs] [PATCH] LocalCopy: Use blockdev to get the size of block devices
LocalCopy was previously only using stat to determine the size of a source disk. If that source disk was a block device it would return 4k. Amongst other problems, this resulted in disks which would not import into RHEV. --- lib/Sys/VirtV2V/Transfer/LocalCopy.pm | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-) diff --git a/lib/Sys/VirtV2V/Transfer/LocalCopy.pm b/lib/Sys/VirtV2V/Transfer/LocalCopy.pm index 814bf4a..093e78f 100644 --- a/lib/Sys/VirtV2V/Transfer/LocalCopy.pm +++ b/lib/Sys/VirtV2V/Transfer/LocalCopy.pm @@ -17,6 +17,7 @@ package Sys::VirtV2V::Transfer::LocalCopy; +use POSIX; use File::Spec; use File::stat; @@ -79,7 +80,36 @@ sub transfer path => $path, error => $!))); - my $vol = $target->create_volume($name, $st->size); + my $size; + + # If it's a block device, use the output of blockdev command + if (S_ISBLK($st->mode)) { + my $blockdev; + open($blockdev, '-|', 'blockdev', '--getsize64', $path) + or die("Unable to execute blockdev: $!"); + + while (<$blockdev>) { + if (defined($size)) { + my $error = "blockdev returned multiple output lines:\n$size\n"; + $error .= $_; + while(<$blockdev>) { + $error .= $_; + } + die($error); + } + chomp; + $size = $_; + } + + close($blockdev) or die("blockdev returned an error: $size"); + } + + # Otherwise use the size of the file directly + else { + $size = $st->size; + } + + my $vol = $target->create_volume($name, $size); $vol->open(); for (;;) { -- 1.6.6.1
Richard W.M. Jones
2010-Apr-06 14:20 UTC
[Libguestfs] [PATCH] LocalCopy: Use blockdev to get the size of block devices
On Tue, Apr 06, 2010 at 03:04:00PM +0100, Matthew Booth wrote:> LocalCopy was previously only using stat to determine the size of a source disk. > If that source disk was a block device it would return 4k.Yeah, that was never going to work :-) Patch looks good, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Maybe Matching Threads
- [PATCH] Add LocalCopy transfer method to transfer local files to a target
- [PREVIEW ONLY] Refactor data transfer code
- [PATCH] Correctly detect the size of a block device over SSH
- [PATCH] Add SSH transfer method
- [PATCH 1/2] Refactor guest and volume creation into Sys::VirtV2V::Target::LibVirt