[et-mgmt-tools] [PATCH][virtinst] support for cloning a sparse file

Kazuki Mizushima mizushima.kazuk at jp.fujitsu.com
Thu May 24 11:15:28 UTC 2007


Hi, 

I made a patch that supported for copying a sparse file for 
reference in an opinion of Dan Berrange and investigating
cp.c source in fileutils. 

>> Now, I investigate sparse files copying.
> 
> There's no easy way to detect if a file is sparse - particularly in python.
> I think the best option is to detect sequences of zeros. eg, if you are
> reading the source file 4096  bytes at a time, check to see if that 4096
> set of bytes are all zeros. If they are, then seek() forward 4096 bytes
> instead of writing the set of zeros.

When copying a sparse file, I change read/write buffer to 4096 because it is 
4096 in cp.c. And I add the "--nonsparse" option as virt-install. Default 
behavior is creating a sparse. Basically when destination file/disk doesn't
exist, create a sparse file and do sparselly copying (means lseek when detecting
4096 sequences of zeros) to that sparse file. When destination file exists, do 
non-sparselly copying(means no lseek when detecting 4096 sequences of zeros)
to the existing file.

In the above-mentioned, as a result of measuring the performance of copying a 
sparse, I get the performance equivalent to the command of 'cp --sparse=always'.

A)used source file
# ls -als sparse.img
2788280 -rwxr-xr-x 1 root root 5368709121 2007-05-18 12:48 sparse.img

B)cp
# time -p cp sparse.img sparse_copy.img --sparse=always --verbose
`sparse.img' -> `sparse_copy.img'
real 190.71
user 1.50
sys 10.70
# ls -als sparse*
2788280 -rwxr-xr-x 1 root root 5368709121 2007-05-18 12:48 sparse.img
2612528 -rwxr-xr-x 1 root root 5368709121 2007-05-18 16:25 sparse_copy.img

C)virt-clone (sparse to sparse)
# time -p ./virt-clone -o PV_RH5GA_SPA -n PV_RH5GA_SPA_CLONE
-f /var/tmp/img/sparse_copy.img
Cloning from /var/tmp/sparse.img to /var/tmp/img/sparse_copy.img
Cloning domain...         100% |=========================| 5.0 GB    03:15
real 196.49
user 16.87
sys 13.68
# ls -als sparse*
2788280 -rwxr-xr-x 1 root root 5368709121 2007-05-18 12:48 sparse.img
2612536 -rwxr-xr-x 1 root root 5368709122 2007-05-24 09:31 sparse_copy.img

Signed-off-by: Kazuki Mizushima <mizushima.kazuk at jp.fujitsu.com>

Thanks,
Kazuki Mizushima
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CloneManager.py.sparse.patch
Type: application/octet-stream
Size: 2606 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/et-mgmt-tools/attachments/20070524/00444a1b/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: virt-clone.sparse.patch
Type: application/octet-stream
Size: 1516 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/et-mgmt-tools/attachments/20070524/00444a1b/attachment-0001.obj>


More information about the et-mgmt-tools mailing list