From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MR7br-0007Ik-7H for qemu-devel@nongnu.org; Wed, 15 Jul 2009 12:45:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MR7bm-0007Fz-5W for qemu-devel@nongnu.org; Wed, 15 Jul 2009 12:45:34 -0400 Received: from [199.232.76.173] (port=47671 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MR7bl-0007Fw-W3 for qemu-devel@nongnu.org; Wed, 15 Jul 2009 12:45:30 -0400 Received: from moutng.kundenserver.de ([212.227.17.9]:64843) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MR7bl-0006Iv-De for qemu-devel@nongnu.org; Wed, 15 Jul 2009 12:45:29 -0400 Message-ID: <4A5E07A6.2050405@mail.berlios.de> Date: Wed, 15 Jul 2009 18:45:26 +0200 From: Stefan Weil MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] raw-posix: Handle errors in raw_create References: <1247323417-17395-1-git-send-email-weil@mail.berlios.de> <20090714213235.GC7580@lst.de> In-Reply-To: <20090714213235.GC7580@lst.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christoph Hellwig Cc: QEMU Developers 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