Matthew Booth
2010-Jun-01 11:00 UTC
[Libguestfs] [PATCH] RHEV: Pad disk sizes up to a multiple of 1024 bytes
Fixes RHBZ#585144 --- lib/Sys/VirtV2V/Target/RHEV.pm | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm index 9dd9013..6841afc 100644 --- a/lib/Sys/VirtV2V/Target/RHEV.pm +++ b/lib/Sys/VirtV2V/Target/RHEV.pm @@ -171,12 +171,16 @@ our %vols_by_path; sub _new { my $class = shift; - my ($mountdir, $domainuuid, $size) = @_; + my ($mountdir, $domainuuid, $insize) = @_; my $self = {}; bless($self, $class); - $self->{size} = $size; + $self->{insize} = $insize; + # RHEV needs disks to be a multiple of 512 in size. Additionally, SIZE in + # the disk meta file has units of kilobytes. To ensure everything matches up + # exactly, we will pad to to a 1024 byte boundary. + $self->{outsize} = ceil($insize/1024) * 1024; my $imageuuid = Sys::VirtV2V::Target::RHEV::UUIDHelper::get_uuid(); my $voluuid = Sys::VirtV2V::Target::RHEV::UUIDHelper::get_uuid(); @@ -206,7 +210,7 @@ sub _get_size { my $self = shift; - return $self->{size}; + return $self->{outsize}; } sub _get_imageuuid @@ -256,6 +260,7 @@ sub open my $self = shift; my $now = $self->{creation}; + $self->{written} = 0; $self->{writer} = Sys::VirtV2V::Target::RHEV::NFSHelper->new(sub { my $dir = $self->{dir}; @@ -283,7 +288,7 @@ sub open print $meta "LEGALITY=LEGAL\n"; print $meta "MTIME=$now\n"; print $meta "POOL_UUID=00000000-0000-0000-0000-000000000000\n"; - print $meta "SIZE=".ceil($self->{size}/1024)."\n"; + print $meta "SIZE=".($self->{outsize} / 1024)."\n"; print $meta "TYPE=SPARSE\n"; print $meta "DESCRIPTION=Exported by virt-v2v\n"; print $meta "EOF\n"; @@ -316,12 +321,25 @@ sub write # die() explicitly in case the above didn't die("Error writing to helper: $!"); } + + $self->{written} += length($data); } sub close { my $self = shift; + # Check we wrote the full file + die(user_message(__x("Didn't write full volume. Expected {expected} ". + "bytes, wrote {actual} bytes.", + expected => $self->{insize}, + actual => $self->{written}))) + unless ($self->{written} == $self->{insize}); + + # Pad the output up to outsize + my $pad = $self->{outsize} - $self->{insize}; + $self->write("\0" x $pad) if ($pad); + # Close the writer pipe, which will cause the child to exit close($self->{writer}->{tochild}) or die("Error closing tochild pipe"); @@ -330,6 +348,7 @@ sub close $self->{writer}->check_exit(); delete($self->{writer}); + delete($self->{written}); } package Sys::VirtV2V::Target::RHEV; -- 1.7.0.1
Richard W.M. Jones
2010-Jun-01 12:36 UTC
[Libguestfs] [PATCH] RHEV: Pad disk sizes up to a multiple of 1024 bytes
On Tue, Jun 01, 2010 at 12:00:28PM +0100, Matthew Booth wrote:> Fixes RHBZ#585144 > + # exactly, we will pad to to a 1024 byte boundary. > + $self->{outsize} = ceil($insize/1024) * 1024;Does this work on a 32 bit machine? Perl might try to promote these to floats. Anyway the fix looks good for 64 bit, so ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
Possibly Parallel Threads
- [PREVIEW ONLY] Refactor data transfer code
- [PATCH] RHEV: OVF must have the same name as the OS UUID
- [PATCH 1/2] Refactor guest and volume creation into Sys::VirtV2V::Target::LibVirt
- [PATCH] RHEV: Ensure DESTROY won't be called for uninitialized object
- [PATCH 1/3] Fix RHEV cleanup on unclean shutdown