Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
volume: Be more careful with create=False
Recently we started to use create=False when converting images to block storage. This was needed as a workaround for qemu-img bug that is now fixed. Then we found that qemu-img preallocation is inefficient and cause trouble with legacy NFS storage, and now we preallocate images with out fallocate helper. These changes revealed the fact that we always create the target image when running qemuimg.convert(). This does not make sense for our use case, so we switch to create=False for all cases. Unfortunately, this does not work. We have 2 cases that require create=True: 1. Raw sparse images when the file system does not support punching holes. When qemu-img convert is trying to punch holes in unallocated areas it falls back to writing zeroes, which is very slow, and fully allocates sparse images. 2. qcow2 with compat=0.10 when volume does not have a parent. Since this older qcow2 format does not support zero clusters, qemu-img fall back to writing zeroes which is very slow and allocates the entire image. When qemu-img convert creates a new image, it knows that the image is zeroed so it can skip unallocated areas. Here are few examples showing the problem cases: Coping sparse image to NFS 3 $ truncate -s 10g /var/tmp/src.raw $ truncate -s 10g dst.raw $ time qemu-img convert -f raw -O raw -t none -T none -n /var/tmp/src.raw dst.raw real 0m50.684s user 0m0.034s sys 0m0.711s $ du -sh dst.raw 10G dst.raw The image became fully allocated and the operation was very slow. If we use create=True: $ time qemu-img convert -f raw -O raw -t none -T none /var/tmp/src.raw dst.raw real 0m0.222s user 0m0.005s sys 0m0.003s $ du -sh dst.raw 4.0K dst.raw More correct and 250 times faster. Copying image to qcow2 compat=0.10: $ qemu-img create -f qcow2 -o compat=0.10 dst.qcow2 10g $ time qemu-img convert -f raw -O qcow2 -t none -T none -n /var/tmp/src.raw dst.qcow2 real 0m58.734s user 0m0.049s sys 0m0.673s # du -sh dst.qcow2 11G dst.qcow2 Again the image was fully allocated, slowly. If we use create=True: $ time qemu-img convert -f raw -O qcow2 -t none -T none /var/tmp/src.raw dst.qcow2 real 0m0.224s user 0m0.003s sys 0m0.006s $ du -sh dst.qcow2 196K dst.qcow2 The creation logic is needed in the 3 callers of qemuimg.convert(), and is mostly about the volume properties. Add Volume.requires_create() method returning True if using the volume as target image in qemuimg.convert() requires create=True. The issue with qcow2 compat=0.10 format is fixed upstream. Once qemu-5.1.0 is available we can remove this check and handle only raw sparse images. Change-Id: Ia456006262376d2cc6174a7849133b77b2322a4a Bug-Url: https://bugzilla.redhat.com/1850267 Related-To: https://bugzilla.redhat.com/1858632 Signed-off-by: Nir Soffer <nsoffer@redhat.com>
- Loading branch information
Showing
5 changed files
with
69 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters