[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v8 3/4] raw-posix: Add full image preallocation
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v8 3/4] raw-posix: Add full image preallocation option |
Date: |
Wed, 23 Apr 2014 06:53:49 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 04/09/2014 01:12 AM, Hu Tao wrote:
> This patch adds a new option preallocation for raw format, and implements
> full preallocation.
>
> Signed-off-by: Hu Tao <address@hidden>
> ---
> block/raw-posix.c | 61
> ++++++++++++++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 54 insertions(+), 7 deletions(-)
>
> + if (prealloc == PREALLOC_MODE_METADATA) {
> + /* posix_fallocate() doesn't set errno. */
> + result = -posix_fallocate(fd, 0, total_size);
> + if (result != 0) {
> + error_setg_errno(errp, -result,
> + "Could not preallocate data for the new file");
> }
> - if (qemu_close(fd) != 0) {
> - result = -errno;
> - error_setg_errno(errp, -result, "Could not close the new file");
> + } else if (prealloc == PREALLOC_MODE_FULL) {
> + char *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);
> + }
> +out_close:
> + if (qemu_close(fd) != 0) {
> + result = -errno;
This overwrites any earlier failure with the failure of close, which may
less informative. I think you want to use 'if (!result) { result =
-errno; }' rather than blindly losing information.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v8 0/4] qemu-img: add preallocation=full, Hu Tao, 2014/04/09
- [Qemu-devel] [PATCH v8 1/4] qapi: introduce PreallocMode and a new PreallocMode full., Hu Tao, 2014/04/09
- [Qemu-devel] [PATCH v8 3/4] raw-posix: Add full image preallocation option, Hu Tao, 2014/04/09
- Re: [Qemu-devel] [PATCH v8 3/4] raw-posix: Add full image preallocation option,
Eric Blake <=
- [Qemu-devel] [PATCH v8 2/4] raw, qcow2: don't convert file size to sector size, Hu Tao, 2014/04/09
- [Qemu-devel] [PATCH v8 4/4] qcow2: Add full image preallocation option, Hu Tao, 2014/04/09
- Re: [Qemu-devel] [PATCH v8 0/4] qemu-img: add preallocation=full, Hu Tao, 2014/04/23