Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Fedora/Linux Management Tools (http://www.linux-archive.org/fedora-linux-management-tools/)
-   -   Fix sparse file size off-by-one error (http://www.linux-archive.org/fedora-linux-management-tools/204554-fix-sparse-file-size-off-one-error.html)

12-03-2008 01:24 AM

Fix sparse file size off-by-one error
 
# HG changeset patch
# User john.levon@sun.com
# 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@sun.com>

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')
os.close(fd)
else:
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')
if progresscb:
progresscb.update(self.size)

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

"Daniel P. Berrange" 12-03-2008 08:35 AM

Fix sparse file size off-by-one error
 
On Tue, Dec 02, 2008 at 06:24:50PM -0800, john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # 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@sun.com>
>
> 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@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

12-04-2008 02:29 AM

Fix sparse file size off-by-one error
 
# HG changeset patch
# User john.levon@sun.com
# Date 1228360958 28800
# Node ID d8591178ebfca87835c7c5181cd96fde303444c9
# Parent a16f24e020cec71d5d61661a2a85e7e241ffe0be
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@sun.com>

diff --git a/virtinst/CloneManager.py b/virtinst/CloneManager.py
--- a/virtinst/CloneManager.py
+++ b/virtinst/CloneManager.py
@@ -557,8 +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.write(fd, 'x00')
+ os.ftruncate(fd, dst_siz)
os.close(fd)
else:
design.clone_bs = 1024*1024*10
diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
--- a/virtinst/VirtualDisk.py
+++ b/virtinst/VirtualDisk.py
@@ -488,8 +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.write(fd, 'x00')
+ os.ftruncate(fd, size_bytes)
if progresscb:
progresscb.update(self.size)
else:

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

"Daniel P. Berrange" 12-04-2008 11:00 AM

Fix sparse file size off-by-one error
 
On Wed, Dec 03, 2008 at 07:29:02PM -0800, john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228360958 28800
> # Node ID d8591178ebfca87835c7c5181cd96fde303444c9
> # Parent a16f24e020cec71d5d61661a2a85e7e241ffe0be
> 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.

ACK

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@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

Cole Robinson 12-07-2008 03:21 AM

Fix sparse file size off-by-one error
 
john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228360958 28800
> # Node ID d8591178ebfca87835c7c5181cd96fde303444c9
> # Parent a16f24e020cec71d5d61661a2a85e7e241ffe0be
> 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@sun.com>
>
>

Thanks, Applied:

http://hg.et.redhat.com/virt/applications/virtinst--devel?cs=ed58873b537c

- Cole

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


All times are GMT. The time now is 07:03 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.