[libvirt] [PATCH] safezero: fall back to writing zeroes even when resizing
Michal Privoznik
mprivozn at redhat.com
Fri Jan 9 13:16:15 UTC 2015
On 07.01.2015 16:49, Ján Tomko wrote:
> Remove the resize flag and use the same code path for all callers.
> This flag was added by commit 18f0316 to allow virStorageFileResize
> use 'safezero' while preserving the behavior.
>
> Explicitly return -2 when a fallback to a different method should
> be done, to make the code path more obvious.
>
> Fail immediately when ftruncate fails in the mmap method,
> as we did before commit 18f0316.
> ---
> src/locking/lock_driver_sanlock.c | 4 ++--
> src/storage/storage_backend.c | 2 +-
> src/util/virfile.c | 34 ++++++++++++----------------------
> src/util/virfile.h | 2 +-
> src/util/virstoragefile.c | 13 ++++---------
> 5 files changed, 20 insertions(+), 35 deletions(-)
>
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index a2bf008..5f56005 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> -int safezero(int fd, off_t offset, off_t len, bool resize)
> +int safezero(int fd, off_t offset, off_t len)
> {
> int ret;
>
> - /* posix_fallocate returns 0 on success or error number on failure,
> - * but errno is not set so use that to our advantage since we set
> - * errno to the returned value if we make the call. If we don't make
> - * the call because it doesn't exist, then errno won't change and
> - * we can try other methods.
> - */
> - errno = 0;
> ret = safezero_posix_fallocate(fd, offset, len);
> - if (ret == 0 || errno != 0)
> + if (ret != -2)
> return ret;
>
> - if (resize)
> - return safezero_sys_fallocate(fd, offset, len);
> -
> - if (safezero_mmap(fd, offset, len) == 0)
> + if (safezero_sys_fallocate(fd, offset, len) == 0)
> return 0;
Aha! So we are sticking with best effort here. If libvirt was built with
SYS_fallocate defined, but is running under a kernel without the
syscall, we want to try other methods too. Makes sense.
> +
> + ret = safezero_mmap(fd, offset, len);
> + if (ret != -2)
> + return ret;
> return safezero_slow(fd, offset, len);
> }
>
ACK
Michal
More information about the libvir-list
mailing list