From patchwork Thu Oct 7 20:25:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 67104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E3DFBB6F07 for ; Fri, 8 Oct 2010 07:41:03 +1100 (EST) Received: from localhost ([127.0.0.1]:42457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3xGt-0007KV-VB for incoming@patchwork.ozlabs.org; Thu, 07 Oct 2010 16:41:00 -0400 Received: from [140.186.70.92] (port=40577 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3x1j-0002Ut-63 for qemu-devel@nongnu.org; Thu, 07 Oct 2010 16:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3x1Z-0000ET-S3 for qemu-devel@nongnu.org; Thu, 07 Oct 2010 16:25:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60187) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3x1Z-0000D7-Le for qemu-devel@nongnu.org; Thu, 07 Oct 2010 16:25:09 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o97KP775007631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Oct 2010 16:25:07 -0400 Received: from blackpad.lan.raisama.net (ovpn-113-100.phx2.redhat.com [10.3.113.100]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o97KP6fI018449; Thu, 7 Oct 2010 16:25:07 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id C2DC517FA9C; Thu, 7 Oct 2010 17:25:05 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 7 Oct 2010 17:25:05 -0300 Message-Id: <1286483105-9768-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1286483105-9768-1-git-send-email-ehabkost@redhat.com> References: <1286483105-9768-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH 2/2] check for close() errors on qcow2_create() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors when closing the file we just created should not be ignored. I/O errors may happen and "qemu-img create" should fail in those cases. If we are already exiting due to an error, we will still return the original error number, though. Signed-off-by: Eduardo Habkost --- block/qcow2.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index c5fb28e..d3a056b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -882,7 +882,7 @@ static int qcow_create2(const char *filename, int64_t total_size, uint64_t old_ref_clusters; QCowCreateState s1, *s = &s1; QCowExtension ext_bf = {0, 0}; - int ret; + int ret, cret; memset(s, 0, sizeof(*s)); @@ -1055,7 +1055,9 @@ exit: qemu_free(s->refcount_block); exit_close: - close(fd); + cret = close(fd); + if (ret == 0 && cret < 0) + ret = -errno; /* Preallocate metadata */ if (ret == 0 && prealloc) {