Re: [PATCH] Fix sparse file size off-by-one error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 02, 2008 at 06:24:50PM -0800, john.levon@xxxxxxx wrote:
> # HG changeset patch
> # User john.levon@xxxxxxx
> # Date 1228271065 28800
> # Node ID ca3207be8b5da3d6f4f9f5432dfa819cfab173c8
> # Parent  31aef21ff81fc33675c09ed0e03e152b963f5042
> Fix sparse file size off-by-one error
> 
> The Solaris loopback driver (lofi) requires files be a multiple of
> 512-bytes in size. Sparse files created via lseek(f, size, 0) are
> 1 byte larger than what is being requested.
> 
> Signed-off-by: John Danielson <john.danielson@xxxxxxx>
> 
> diff --git a/virtinst/CloneManager.py b/virtinst/CloneManager.py
> --- a/virtinst/CloneManager.py
> +++ b/virtinst/CloneManager.py
> @@ -557,7 +557,7 @@ def _do_duplicate(design):
>                  design.clone_bs = 4096
>                  sparse_copy_mode = True
>                  fd = os.open(dst_dev, os.O_WRONLY | os.O_CREAT)
> -                os.lseek(fd, dst_siz, 0)
> +                os.lseek(fd, dst_siz - 1, 0)
>                  os.write(fd, '\x00')

Perhaps we should just avoid the extra 1 byte write here, by switching
to ftruncate, eg

                    fd = os.open(dst_dev, os.O_WRONLY | os.O_CREAT)
                    os.ftruncate(fd, dst_siz, 0)
                    os.close(fd)

> diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
> --- a/virtinst/VirtualDisk.py
> +++ b/virtinst/VirtualDisk.py
> @@ -488,7 +488,7 @@ class VirtualDisk(VirtualDevice):
>                  try:
>                      fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
>                      if self.sparse:
> -                        os.lseek(fd, size_bytes, 0)
> +                        os.lseek(fd, size_bytes -1, 0)
>                          os.write(fd, '\x00')

Likewise here 


Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux