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 <hu...@cn.fujitsu.com> > --- > 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