Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 640

kvm-83-270.el5_11.src.rpm

From 1986a345f46a699afcf3c7aa5d49210a11c25082 Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Thu, 21 Jan 2010 14:03:07 -0200
Subject: [PATCH 09/10] qcow2: Don't ignore update_refcount return value

RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1264082588-10273-10-git-send-email-kwolf@redhat.com>
Patchwork-id: 6518
O-Subject: [RHEL-5.5 KVM PATCH 09/10] qcow2: Don't ignore update_refcount return
	value
Bugzilla: 537077
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Gleb Natapov <gleb@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>

Bugzilla: 537077
Upstream status: Submitted

update_refcount can return errors that need to be handled by the callers.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu/block-qcow2.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/block-qcow2.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
index b974de3..20cb9e5 100644
--- a/qemu/block-qcow2.c
+++ b/qemu/block-qcow2.c
@@ -2039,9 +2039,15 @@ static int update_snapshot_refcount(BlockDriverState *bs,
                     if (offset & QCOW_OFLAG_COMPRESSED) {
                         nb_csectors = ((offset >> s->csize_shift) &
                                        s->csize_mask) + 1;
-                        if (addend != 0)
-                            update_refcount(bs, (offset & s->cluster_offset_mask) & ~511,
-                                            nb_csectors * 512, addend);
+                        if (addend != 0) {
+                            int ret;
+                            ret = update_refcount(bs,
+                                (offset & s->cluster_offset_mask) & ~511,
+                                nb_csectors * 512, addend);
+                            if (ret < 0) {
+                                goto fail;
+                            }
+                        }
                         /* compressed clusters are never modified */
                         refcount = 2;
                     } else {
@@ -2574,9 +2580,13 @@ retry:
 static int64_t alloc_clusters(BlockDriverState *bs, int64_t size)
 {
     int64_t offset;
+    int ret;
 
     offset = alloc_clusters_noref(bs, size);
-    update_refcount(bs, offset, size, 1);
+    ret = update_refcount(bs, offset, size, 1);
+    if (ret < 0) {
+        return ret;
+    }
     return offset;
 }
 
@@ -2623,7 +2633,13 @@ static int64_t alloc_bytes(BlockDriverState *bs, int size)
 static void free_clusters(BlockDriverState *bs,
                           int64_t offset, int64_t size)
 {
-    update_refcount(bs, offset, size, -1);
+    int ret;
+
+    ret = update_refcount(bs, offset, size, -1);
+    if (ret < 0) {
+        fprintf(stderr, "qcow2: free_clusters failed: %s\n", strerror(-ret));
+        abort();
+    }
 }
 
 static int grow_refcount_table(BlockDriverState *bs, int min_size)
-- 
1.6.3.rc4.29.g8146