qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] raw-posix: Handle errors in raw_create


From: Stefan Weil
Subject: Re: [Qemu-devel] [PATCH] raw-posix: Handle errors in raw_create
Date: Wed, 15 Jul 2009 18:45:26 +0200
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707)

Christoph Hellwig schrieb:
> On Sat, Jul 11, 2009 at 04:43:37PM +0200, Stefan Weil wrote:
>> In qemu-iotests, some large images are created using qemu-img.
>>
>> Without checks for errors, qemu-img will just create an
>> empty image, and later read / write tests will fail.
>>
>> With the patch, failures during image creation are detected
>> and reported.
>
> Yeah, we should handle the failures and your patch looks correct in
> that respect. But returning close error codes is in general
> not very useful. There's not much we can do about them, in they
> might override the more useful ftruncate error code.
>
> So I'd rather do something like the following:
>
> if (fd < 0) {
> return -errno;
> }
>
> if (ftruncate(fd, total_size * 512) != 0) {
> result = -errno;
> }
>
> close(fd);
> return result;

A useful ftruncate error code won't be overwritten by a close error
in most cases because it's not very likely to get both errors together.
For the rare case where ftruncate and close both fail and set different
errno values, I'd accept to get the error code from close.

Here is an extract from the man page of close:

Not checking the return value of close() is a common  but  nevertheless
serious  programming error. ...
Not checking the return value when closing the file may lead to silent
loss of data. ...

The patch works: on disks with less than 128 MB free space
qemu-iotests will give better diagnostics, because qemu-img
won't silently create an image of length 0.

Regards,
Stefan





reply via email to

[Prev in Thread] Current Thread [Next in Thread]