Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > aadbe78a25743146bb784eee19f007c5 > files > 37

kvm-83-164.el5_5.9.src.rpm

From 3e27913d4d7c47342844a330d888d0e4f105ece6 Mon Sep 17 00:00:00 2001
From: aliguori <aliguori>
Date: Thu, 15 Jan 2009 20:43:39 +0000
Subject: [PATCH 36/54] bdrv_write should not stop on partial write (Gleb Natapov)

Should return real error instead.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
RH-Upstream-status: applied(qemu), pending(maint/2.6.29)
---
 qemu/block.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/qemu/block.c b/qemu/block.c
index 8627884..a4b3b2c 100644
--- a/qemu/block.c
+++ b/qemu/block.c
@@ -630,21 +630,22 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
     if (bdrv_wr_badreq_sectors(bs, sector_num, nb_sectors))
         return -EDOM;
     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,
-- 
1.6.1