All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] qcow2: add update refcount table realization for update_refcount
@ 2014-09-01 10:52 Jun Li
  2014-09-01 11:11 ` Benoît Canet
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Jun Li @ 2014-09-01 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, famz, juli, Jun Li, stefanha

When every item of refcount block is NULL, free refcount block and reset the
corresponding item of refcount table with NULL.

Signed-off-by: Jun Li <address@hidden>
---

The v2 do following change to modify some potential issue.

             +------- Here should start from "0".
             |
    for (k = 0; k < refcount_block_entries; k++) {
        if (refcount_block[k] != cpu_to_be16(0)) {
        ...                |                 |
        }                  |                 |
    }                      |                 +---- Using "0" is more safe.
                           |
                           +-------- This should be "k" not "++k".
---
 block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 43665b8..63f36e6 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
         if (refcount == 0 && s->discard_passthrough[type]) {
             update_refcount_discard(bs, cluster_offset, s->cluster_size);
         }
+
+        /* When refcount block is NULL, update refcount table */
+        if (block_index == 0) {
+            int k = block_index;
+            int refcount_block_entries = s->cluster_size / sizeof(uint16_t);
+            for (k = 0; k < refcount_block_entries; k++) {
+                if (refcount_block[k] != cpu_to_be16(0)) {
+                    break;
+                }
+            }
+
+            if (k == refcount_block_entries) {
+                qemu_vfree(refcount_block);
+                /* update refcount table */
+                unsigned int refcount_table_index;
+                uint64_t data64 = cpu_to_be64(0);
+                refcount_table_index = cluster_index >> (s->cluster_bits -
+                                       REFCOUNT_SHIFT);
+                ret = bdrv_pwrite_sync(bs->file,
+                                       s->refcount_table_offset +
+                                       refcount_table_index *
+                                       sizeof(uint64_t),
+                                       &data64, sizeof(data64));
+                if (ret < 0) {
+                    goto fail;
+                }
+
+                s->refcount_table[refcount_table_index] = data64;
+
+            }
+        }
     }
 
     ret = 0;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-09-22  1:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-01 10:52 [Qemu-devel] [PATCH v2] qcow2: add update refcount table realization for update_refcount Jun Li
2014-09-01 11:11 ` Benoît Canet
2014-09-01 16:04   ` Jun Li
2014-09-02 13:38     ` Benoît Canet
2014-09-02 17:12 ` Greg Kurz
2014-09-22  1:45   ` jun muzi
2014-09-05 10:21 ` Kevin Wolf
2014-09-09  2:52   ` Jun Li
2014-09-09  8:21     ` Kevin Wolf
2014-09-09 14:04       ` Jun Li
2014-09-05 15:33 ` Stefan Hajnoczi
2014-09-13 15:53   ` Jun Li
2014-09-15  9:27     ` Stefan Hajnoczi
2014-09-05 15:34 ` Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.