Am 29.08.2014 um 10:33 hat Hu Tao geschrieben:
> This patch adds a new option preallocation for raw format, and implements
> full preallocation.
> 
> Signed-off-by: Hu Tao <hu...@cn.fujitsu.com>

v12 was better, it wasn't doing only metadata preallocation when you
told it to do full preallocation.

> +    if (prealloc == PREALLOC_MODE_FULL) {
> +        /* posix_fallocate() doesn't set errno. */
> +        result = -posix_fallocate(fd, 0, total_size);
> +        if (result != 0) {
> +            buf = g_malloc0(65536);
> +            int64_t num = 0, left = total_size;
> +
> +            while (left > 0) {
> +                num = MIN(left, 65536);
> +                result = write(fd, buf, num);
> +                if (result < 0) {
> +                    result = -errno;
> +                    error_setg_errno(errp, -result,
> +                                     "Could not write to the new file");
> +                    g_free(buf);
> +                    goto out_close;
> +                }
> +                left -= num;
> +            }
> +            fsync(fd);
> +            g_free(buf);
>          }

This is totally pointless. If the file system doesn't support fallocate,
posix_fallocate() will already try writing zeros.

Having code to write zeros in qemu only makes sense if you implement a
real full preallocation mode, which doesn't use fallocate even when it's
supported.

Please change the code to always write zeros for FULL, and either
reintroduce FALLOC or use METADATA for the fallocate (without a fallback
to zero writing code). In fact, for metadata preallocation we should
probably directly use fallocate(), which has no slow zero-write fallback
in the libc.

Kevin

Reply via email to