1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-14 12:58:33 +03:00

Rewrite allocation tracking when cloning volumes

Instead of storing the remaining bytes, store the position of the first
unallocated byte. This will allow changing the amount of bytes copied
by virStorageBackendCopyToFD without changing the safezero call.

No functional impact.
This commit is contained in:
Ján Tomko 2015-07-03 12:47:02 +02:00
parent 04d5fb2e0a
commit e30297b096

View File

@ -399,7 +399,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
{ {
bool need_alloc = true; bool need_alloc = true;
int ret = 0; int ret = 0;
unsigned long long remain; unsigned long long pos = 0;
/* Seek to the final size, so the capacity is available upfront /* Seek to the final size, so the capacity is available upfront
* for progress reporting */ * for progress reporting */
@ -433,9 +433,9 @@ createRawFile(int fd, virStorageVolDefPtr vol,
} }
#endif #endif
remain = vol->target.allocation;
if (inputvol) { if (inputvol) {
unsigned long long remain = vol->target.allocation;
/* allow zero blocks to be skipped if we've requested sparse /* allow zero blocks to be skipped if we've requested sparse
* allocation (allocation < capacity) or we have already * allocation (allocation < capacity) or we have already
* been able to allocate the required space. */ * been able to allocate the required space. */
@ -446,10 +446,12 @@ createRawFile(int fd, virStorageVolDefPtr vol,
want_sparse, reflink_copy); want_sparse, reflink_copy);
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
pos = vol->target.allocation - remain;
} }
if (remain && need_alloc) { if (need_alloc) {
if (safezero(fd, vol->target.allocation - remain, remain) < 0) { if (safezero(fd, pos, vol->target.allocation - pos) < 0) {
ret = -errno; ret = -errno;
virReportSystemError(errno, _("cannot fill file '%s'"), virReportSystemError(errno, _("cannot fill file '%s'"),
vol->target.path); vol->target.path);