From patchwork Wed Jan 20 14:03:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 43290 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 7AC77B7C7E for ; Thu, 21 Jan 2010 01:23:41 +1100 (EST) Received: from localhost ([127.0.0.1]:43903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXbT8-0007mT-7I for incoming@patchwork.ozlabs.org; Wed, 20 Jan 2010 09:23:38 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXbAQ-00076o-LJ for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXbAH-0006xK-EG for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:14 -0500 Received: from [199.232.76.173] (port=43299 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXbAH-0006wx-7J for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31688) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXbAG-0003Lr-HC for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:08 -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 o0KE47YO009290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Jan 2010 09:04:07 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0KE40Q2030534; Wed, 20 Jan 2010 09:04:06 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 20 Jan 2010 15:03:02 +0100 Message-Id: <1263996186-6623-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1263996186-6623-1-git-send-email-kwolf@redhat.com> References: <1263996186-6623-1-git-send-email-kwolf@redhat.com> 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: Kevin Wolf Subject: [Qemu-devel] [PATCH v2 05/10] block: Return original error codes in bdrv_pread/write 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 Don't assume -EIO but return the real error. Signed-off-by: Kevin Wolf --- block.c | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index 115e591..a4c4953 100644 --- a/block.c +++ b/block.c @@ -717,6 +717,7 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset, uint8_t tmp_buf[BDRV_SECTOR_SIZE]; int len, nb_sectors, count; int64_t sector_num; + int ret; count = count1; /* first read to align to sector start */ @@ -725,8 +726,8 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset, len = count; sector_num = offset >> BDRV_SECTOR_BITS; if (len > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(buf, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), len); count -= len; if (count == 0) @@ -738,8 +739,8 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset, /* read the sectors "in place" */ nb_sectors = count >> BDRV_SECTOR_BITS; if (nb_sectors > 0) { - if (bdrv_read(bs, sector_num, buf, nb_sectors) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, buf, nb_sectors)) < 0) + return ret; sector_num += nb_sectors; len = nb_sectors << BDRV_SECTOR_BITS; buf += len; @@ -748,8 +749,8 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset, /* add data from the last sector */ if (count > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(buf, tmp_buf, count); } return count1; @@ -761,6 +762,7 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, uint8_t tmp_buf[BDRV_SECTOR_SIZE]; int len, nb_sectors, count; int64_t sector_num; + int ret; count = count1; /* first write to align to sector start */ @@ -769,11 +771,11 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, len = count; sector_num = offset >> BDRV_SECTOR_BITS; if (len > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), buf, len); - if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0) + return ret; count -= len; if (count == 0) return count1; @@ -784,8 +786,8 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, /* write the sectors "in place" */ nb_sectors = count >> BDRV_SECTOR_BITS; if (nb_sectors > 0) { - if (bdrv_write(bs, sector_num, buf, nb_sectors) < 0) - return -EIO; + if ((ret = bdrv_write(bs, sector_num, buf, nb_sectors)) < 0) + return ret; sector_num += nb_sectors; len = nb_sectors << BDRV_SECTOR_BITS; buf += len; @@ -794,11 +796,11 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, /* add data from the last sector */ if (count > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(tmp_buf, buf, count); - if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0) + return ret; } return count1; }