From: Stefan Weil <weil@mail.berlios.de>
To: Christoph Hellwig <hch@lst.de>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] raw-posix: Handle errors in raw_create
Date: Wed, 15 Jul 2009 18:45:26 +0200 [thread overview]
Message-ID: <4A5E07A6.2050405@mail.berlios.de> (raw)
In-Reply-To: <20090714213235.GC7580@lst.de>
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
prev parent reply other threads:[~2009-07-15 16:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-11 14:43 [Qemu-devel] [PATCH] raw-posix: Handle errors in raw_create Stefan Weil
2009-07-14 21:32 ` Christoph Hellwig
2009-07-15 16:45 ` Stefan Weil [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A5E07A6.2050405@mail.berlios.de \
--to=weil@mail.berlios.de \
--cc=hch@lst.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).