qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] block stream: close unused files and update ->backing_hd


From: Marcelo Tosatti
Subject: [Qemu-devel] block stream: close unused files and update ->backing_hd
Date: Wed, 21 Mar 2012 22:09:45 -0300
User-agent: Mutt/1.5.21 (2010-09-15)

Close the now unused images that were part of the previous backing file
chain and adjust ->backing_hd properly.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=801449

Signed-off-by: Marcelo Tosatti <address@hidden>

diff --git a/block/stream.c b/block/stream.c
index d1b3986..cbf041b 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -76,6 +76,29 @@ static int coroutine_fn stream_populate(BlockDriverState *bs,
     return bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, &qiov);
 }
 
+static void close_unused_images(BlockDriverState *top, BlockDriverState *base)
+{
+    BlockDriverState *intermediate;
+    intermediate = top->backing_hd;
+
+    while (intermediate) {
+        BlockDriverState *unused;
+
+        /* reached base */
+        if (intermediate == base) {
+            break;
+        }
+
+        unused = intermediate;
+        intermediate = intermediate->backing_hd;
+        unused->backing_hd = NULL;
+        bdrv_delete(unused);
+    }
+    top->backing_hd = base;
+
+    return;
+}
+
 /*
  * Given an image chain: [BASE] -> [INTER1] -> [INTER2] -> [TOP]
  *
@@ -221,6 +244,7 @@ retry:
             base_id = s->backing_file_id;
         }
         ret = bdrv_change_backing_file(bs, base_id, NULL);
+        close_unused_images(bs, base);
     }
 
     qemu_vfree(buf);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]