From patchwork Wed Mar 3 12:06:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 46796 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 20EFBB7CE8 for ; Wed, 3 Mar 2010 23:29:07 +1100 (EST) Received: from localhost ([127.0.0.1]:34338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmneT-0004Mb-17 for incoming@patchwork.ozlabs.org; Wed, 03 Mar 2010 07:26:09 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmnME-0000pm-GL for qemu-devel@nongnu.org; Wed, 03 Mar 2010 07:07:18 -0500 Received: from [199.232.76.173] (port=53682 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmnMD-0000pS-Vv for qemu-devel@nongnu.org; Wed, 03 Mar 2010 07:07:18 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NmnMB-0005JD-RS for qemu-devel@nongnu.org; Wed, 03 Mar 2010 07:07:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15037) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NmnMB-0005J3-FB for qemu-devel@nongnu.org; Wed, 03 Mar 2010 07:07:15 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o23C7EM7003862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 3 Mar 2010 07:07:14 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o23C71AB004209; Wed, 3 Mar 2010 07:07:13 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 3 Mar 2010 13:06:57 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, amit.shah@redhat.com Subject: [Qemu-devel] [PATCH 07/10] vmdk: make vmdk_snapshot_create return -errno 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 Signed-off-by: Juan Quintela --- block/vmdk.c | 79 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 58 insertions(+), 21 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 5b1d197..67a690e 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -187,6 +187,7 @@ static int vmdk_is_cid_valid(BlockDriverState *bs) static int vmdk_snapshot_create(const char *filename, const char *backing_file) { int snp_fd, p_fd; + int ret; uint32_t p_cid; char *p_name, *gd_buf, *rgd_buf; const char *real_filename, *temp_str; @@ -211,35 +212,49 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) snp_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644); if (snp_fd < 0) - return -1; + return -errno; p_fd = open(backing_file, O_RDONLY | O_BINARY | O_LARGEFILE); if (p_fd < 0) { close(snp_fd); - return -1; + return -errno; } /* read the header */ - if (lseek(p_fd, 0x0, SEEK_SET) == -1) + if (lseek(p_fd, 0x0, SEEK_SET) == -1) { + ret = -errno; goto fail; - if (read(p_fd, hdr, HEADER_SIZE) != HEADER_SIZE) + } + if (read(p_fd, hdr, HEADER_SIZE) != HEADER_SIZE) { + ret = -errno; goto fail; + } /* write the header */ - if (lseek(snp_fd, 0x0, SEEK_SET) == -1) + if (lseek(snp_fd, 0x0, SEEK_SET) == -1) { + ret = -errno; goto fail; - if (write(snp_fd, hdr, HEADER_SIZE) == -1) + } + if (write(snp_fd, hdr, HEADER_SIZE) == -1) { + ret = -errno; goto fail; + } memset(&header, 0, sizeof(header)); memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC - if (ftruncate(snp_fd, header.grain_offset << 9)) + if (ftruncate(snp_fd, header.grain_offset << 9)) { + ret = -errno; goto fail; + } /* the descriptor offset = 0x200 */ - if (lseek(p_fd, 0x200, SEEK_SET) == -1) + if (lseek(p_fd, 0x200, SEEK_SET) == -1) { + ret = -errno; goto fail; - if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE) + } + if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE) { + ret = -errno; goto fail; + } if ((p_name = strstr(p_desc,"CID")) != NULL) { p_name += sizeof("CID"); @@ -258,10 +273,14 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) (uint32_t)header.capacity, real_filename); /* write the descriptor */ - if (lseek(snp_fd, 0x200, SEEK_SET) == -1) + if (lseek(snp_fd, 0x200, SEEK_SET) == -1) { + ret = -errno; goto fail; - if (write(snp_fd, s_desc, strlen(s_desc)) == -1) + } + if (write(snp_fd, s_desc, strlen(s_desc)) == -1) { + ret = -errno; goto fail; + } gd_offset = header.gd_offset * SECTOR_SIZE; // offset of GD table rgd_offset = header.rgd_offset * SECTOR_SIZE; // offset of RGD table @@ -271,33 +290,51 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) * 512 GTE per GT, each GTE points to grain */ gt_size = (int64_t)header.num_gtes_per_gte * header.granularity * SECTOR_SIZE; - if (!gt_size) + if (!gt_size) { + ret = -EINVAL; goto fail; + } gde_entries = (uint32_t)(capacity / gt_size); // number of gde/rgde gd_size = gde_entries * sizeof(uint32_t); /* write RGD */ rgd_buf = qemu_malloc(gd_size); - if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) + if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) { + ret = -errno; goto fail_rgd; - if (read(p_fd, rgd_buf, gd_size) != gd_size) + } + if (read(p_fd, rgd_buf, gd_size) != gd_size) { + ret = -errno; goto fail_rgd; - if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1) + } + if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1) { + ret = -errno; goto fail_rgd; - if (write(snp_fd, rgd_buf, gd_size) == -1) + } + if (write(snp_fd, rgd_buf, gd_size) == -1) { + ret = -errno; goto fail_rgd; + } qemu_free(rgd_buf); /* write GD */ gd_buf = qemu_malloc(gd_size); - if (lseek(p_fd, gd_offset, SEEK_SET) == -1) + if (lseek(p_fd, gd_offset, SEEK_SET) == -1) { + ret = -errno; goto fail_gd; - if (read(p_fd, gd_buf, gd_size) != gd_size) + } + if (read(p_fd, gd_buf, gd_size) != gd_size) { + ret = -errno; goto fail_gd; - if (lseek(snp_fd, gd_offset, SEEK_SET) == -1) + } + if (lseek(snp_fd, gd_offset, SEEK_SET) == -1) { + ret = -errno; goto fail_gd; - if (write(snp_fd, gd_buf, gd_size) == -1) + } + if (write(snp_fd, gd_buf, gd_size) == -1) { + ret = -errno; goto fail_gd; + } qemu_free(gd_buf); close(p_fd); @@ -311,7 +348,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file) fail: close(p_fd); close(snp_fd); - return -1; + return ret; } static void vmdk_parent_close(BlockDriverState *bs)