cd9d161
From 2139ef7f75ff63904fac6b451c8a89e4b0c72448 Mon Sep 17 00:00:00 2001
cd9d161
From: Kevin Wolf <kwolf@redhat.com>
cd9d161
Date: Wed, 26 Oct 2011 12:25:25 +0200
cd9d161
Subject: [PATCH] vmdk: Improve error handling
cd9d161
MIME-Version: 1.0
cd9d161
Content-Type: text/plain; charset=UTF-8
cd9d161
Content-Transfer-Encoding: 8bit
cd9d161
cd9d161
Return the right error values in some more places.
cd9d161
cd9d161
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
cd9d161
(cherry picked from commit 99f1835d9bc744f98370254600530e66f32e6d81)
cd9d161
cd9d161
Signed-off-by: Bruce Rogers <brogers@suse.com>
cd9d161
Signed-off-by: Andreas Färber <afaerber@suse.de>
cd9d161
---
cd9d161
 block/vmdk.c | 21 +++++++++++++++------
cd9d161
 1 file changed, 15 insertions(+), 6 deletions(-)
cd9d161
cd9d161
diff --git a/block/vmdk.c b/block/vmdk.c
cd9d161
index b5caa40..8284747 100644
cd9d161
--- a/block/vmdk.c
cd9d161
+++ b/block/vmdk.c
cd9d161
@@ -181,8 +181,10 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
cd9d161
     const char *p_name, *cid_str;
cd9d161
     size_t cid_str_size;
cd9d161
     BDRVVmdkState *s = bs->opaque;
cd9d161
+    int ret;
cd9d161
 
cd9d161
-    if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
cd9d161
+    ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE);
cd9d161
+    if (ret < 0) {
cd9d161
         return 0;
cd9d161
     }
cd9d161
 
cd9d161
@@ -208,10 +210,12 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
cd9d161
     char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
cd9d161
     char *p_name, *tmp_str;
cd9d161
     BDRVVmdkState *s = bs->opaque;
cd9d161
+    int ret;
cd9d161
 
cd9d161
     memset(desc, 0, sizeof(desc));
cd9d161
-    if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
cd9d161
-        return -EIO;
cd9d161
+    ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE);
cd9d161
+    if (ret < 0) {
cd9d161
+        return ret;
cd9d161
     }
cd9d161
 
cd9d161
     tmp_str = strstr(desc, "parentCID");
cd9d161
@@ -223,9 +227,11 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
cd9d161
         pstrcat(desc, sizeof(desc), tmp_desc);
cd9d161
     }
cd9d161
 
cd9d161
-    if (bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE) < 0) {
cd9d161
-        return -EIO;
cd9d161
+    ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE);
cd9d161
+    if (ret < 0) {
cd9d161
+        return ret;
cd9d161
     }
cd9d161
+
cd9d161
     return 0;
cd9d161
 }
cd9d161
 
cd9d161
@@ -906,7 +912,10 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
cd9d161
         /* update CID on the first write every time the virtual disk is
cd9d161
          * opened */
cd9d161
         if (!s->cid_updated) {
cd9d161
-            vmdk_write_cid(bs, time(NULL));
cd9d161
+            ret = vmdk_write_cid(bs, time(NULL));
cd9d161
+            if (ret < 0) {
cd9d161
+                return ret;
cd9d161
+            }
cd9d161
             s->cid_updated = true;
cd9d161
         }
cd9d161
     }
cd9d161
-- 
cd9d161
1.7.11.2
cd9d161