Sophie

Sophie

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

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

From cb3dac50ad622885684087db1a56e4d2735e240c Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Wed, 9 Sep 2009 15:57:43 -0300
Subject: [PATCH 5/5] update_refcount: Write complete sectors

Message-id: <1250675987-18401-6-git-send-email-kwolf@redhat.com>
RH-Author: Kevin Wolf <kwolf@redhat.com>
Patchwork-id: 3274
O-Subject: [RHEL 5.5 PATCH 5/5] update_refcount: Write complete sectors
Bugzilla: 518169
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Gleb Natapov <gleb@redhat.com>
RH-Acked-by: Andrea Arcangeli <aarcange@redhat.com>

When updating the refcount blocks in update_refcount(), write complete sectors
instead of updating single entries.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 qemu/block-qcow2.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

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

diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
index 50561f1..37a73e0 100644
--- a/qemu/block-qcow2.c
+++ b/qemu/block-qcow2.c
@@ -2628,6 +2628,27 @@ static int update_cluster_refcount(BlockDriverState *bs,
     return get_refcount(bs, cluster_index);
 }
 
+#define REFCOUNTS_PER_SECTOR (512 >> REFCOUNT_SHIFT)
+static int write_refcount_block_entries(BDRVQcowState *s,
+    int64_t refcount_block_offset, int first_index, int last_index)
+{
+    size_t size;
+
+    first_index &= ~(REFCOUNTS_PER_SECTOR - 1);
+    last_index = (last_index + REFCOUNTS_PER_SECTOR)
+        & ~(REFCOUNTS_PER_SECTOR - 1);
+
+    size = (last_index - first_index) << REFCOUNT_SHIFT;
+    if (bdrv_pwrite(s->hd,
+        refcount_block_offset + (first_index << REFCOUNT_SHIFT),
+        &s->refcount_block_cache[first_index], size) != size)
+    {
+        return -EIO;
+    }
+
+    return 0;
+}
+
 /* XXX: cache several refcount block clusters ? */
 static int update_refcount(BlockDriverState *bs,
                             int64_t offset, int64_t length,
@@ -2657,10 +2678,9 @@ static int update_refcount(BlockDriverState *bs,
         old_table_index = table_index;
         table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);
         if ((old_table_index >= 0) && (table_index != old_table_index)) {
-            size_t size = (last_index - first_index + 1) << REFCOUNT_SHIFT;
-            if (bdrv_pwrite(s->hd,
-                refcount_block_offset + (first_index << REFCOUNT_SHIFT),
-                &s->refcount_block_cache[first_index], size) != size)
+
+            if (write_refcount_block_entries(s, refcount_block_offset,
+                first_index, last_index) < 0)
             {
                 return -EIO;
             }
@@ -2697,10 +2717,8 @@ static int update_refcount(BlockDriverState *bs,
 
     /* Write last changed block to disk */
     if (refcount_block_offset != 0) {
-        size_t size = (last_index - first_index + 1) << REFCOUNT_SHIFT;
-        if (bdrv_pwrite(s->hd,
-            refcount_block_offset + (first_index << REFCOUNT_SHIFT),
-            &s->refcount_block_cache[first_index], size) != size)
+        if (write_refcount_block_entries(s, refcount_block_offset,
+            first_index, last_index) < 0)
         {
             return -EIO;
         }
-- 
1.6.3.rc4.29.g8146