From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LNPF2-0001Uw-0z for qemu-devel@nongnu.org; Thu, 15 Jan 2009 05:14:24 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LNPF0-0001Tk-BZ for qemu-devel@nongnu.org; Thu, 15 Jan 2009 05:14:23 -0500 Received: from [199.232.76.173] (port=36191 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNPEz-0001Tb-T0 for qemu-devel@nongnu.org; Thu, 15 Jan 2009 05:14:21 -0500 Received: from mx2.redhat.com ([66.187.237.31]:60957) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LNPEz-0007oY-AK for qemu-devel@nongnu.org; Thu, 15 Jan 2009 05:14:21 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n0FAEKFx001014 for ; Thu, 15 Jan 2009 05:14:20 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n0FAEL18017057 for ; Thu, 15 Jan 2009 05:14:21 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n0FAEKqk025104 for ; Thu, 15 Jan 2009 05:14:20 -0500 Received: from dhcp-1-237.tlv.redhat.com (localhost [127.0.0.1]) by dhcp-1-237.tlv.redhat.com (Postfix) with ESMTP id BC55018D407 for ; Thu, 15 Jan 2009 12:12:47 +0200 (IST) From: Gleb Natapov Date: Thu, 15 Jan 2009 12:12:47 +0200 Message-ID: <20090115101247.13211.52893.stgit@dhcp-1-237.tlv.redhat.com> In-Reply-To: <20090115101241.13211.64596.stgit@dhcp-1-237.tlv.redhat.com> References: <20090115101241.13211.64596.stgit@dhcp-1-237.tlv.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v2 2/3] bdrv_write should not stop on partial write. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Should return real error instead. Signed-off-by: Gleb Natapov --- block.c | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 28d63d7..3250327 100644 --- a/block.c +++ b/block.c @@ -565,21 +565,22 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, if (bs->read_only) return -EACCES; if (drv->bdrv_pwrite) { - int ret, len; + int ret, len, count = 0; len = nb_sectors * 512; - ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len); - if (ret < 0) - return ret; - else if (ret != len) - return -EIO; - else { - bs->wr_bytes += (unsigned) len; - bs->wr_ops ++; - return 0; - } - } else { - return drv->bdrv_write(bs, sector_num, buf, nb_sectors); + do { + ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len - count); + if (ret < 0) { + printf("bdrv_write ret=%d\n", ret); + return ret; + } + count += ret; + buf += ret; + } while (count != len); + bs->wr_bytes += (unsigned) len; + bs->wr_ops ++; + return 0; } + return drv->bdrv_write(bs, sector_num, buf, nb_sectors); } static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,