qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Keil <jk@tools.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] qcow2: release refcount table clusters of the old table, after growing the refcount table
Date: Mon, 2 Apr 2007 12:42:23 +0200 (CEST)	[thread overview]
Message-ID: <200704021042.l32AgOi3024912@imap.tools.intra> (raw)

[-- Attachment #1: Type: TEXT/plain, Size: 937 bytes --]

Another patch for qcow2:  when the refcount table is grown, clusters for 
the new refcount table are allocated, but the clusters for the old
(now unused) refcount table are not released.

This isn't a big problem, it just wastes a few clusters.

But it results in error messages when block-qcow2.c is compiled with
DEBUG_ALLOC / DEBUG_ALLOC2 error checking, and a qcow2 image has ever
grown the refcount table:


    /* compare ref counts */
    for(i = 0; i < nb_clusters; i++) {
        refcount1 = get_refcount(bs, i);
        refcount2 = refcount_table[i];
        if (refcount1 != refcount2)
            printf("ERROR cluster %d refcount=%d reference=%d\n",
                   i, refcount1, refcount2);
    }


% qemu-img info sol11-b60.img
ERROR cluster 9 refcount=1 reference=0            <<<<<<<<<<<<<<<<<<<<<<<<<<<
image: sol11-b60.img
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 2.6G
cluster_size: 4096

[-- Attachment #2: qcow2-patch --]
[-- Type: TEXT/plain, Size: 1081 bytes --]

Index: block-qcow2.c
===================================================================
RCS file: /cvsroot/qemu/qemu/block-qcow2.c,v
retrieving revision 1.5
diff -u -B -r1.5 block-qcow2.c
--- block-qcow2.c	1 Apr 2007 19:01:40 -0000	1.5
+++ block-qcow2.c	2 Apr 2007 10:17:54 -0000
@@ -1886,6 +1894,8 @@
     int64_t table_offset;
     uint64_t data64;
     uint32_t data32;
+    int old_table_size;
+    int64_t old_table_offset;
 
     if (min_size <= s->refcount_table_size)
         return 0;
@@ -1931,11 +1941,14 @@
                     &data32, sizeof(data32)) != sizeof(data32))
         goto fail;
     qemu_free(s->refcount_table);
+    old_table_offset = s->refcount_table_offset;
+    old_table_size = s->refcount_table_size;
     s->refcount_table = new_table;
     s->refcount_table_size = new_table_size;
     s->refcount_table_offset = table_offset;
 
     update_refcount(bs, table_offset, new_table_size2, 1);
+    free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t));
     return 0;
  fail:
     free_clusters(bs, table_offset, new_table_size2);

                 reply	other threads:[~2007-04-02 10:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200704021042.l32AgOi3024912@imap.tools.intra \
    --to=jk@tools.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).