* [Qemu-devel] [PATCH v2] block stream: close unused files and update ->backing_hd
@ 2012-03-27 0:22 Marcelo Tosatti
2012-03-27 7:13 ` Stefan Hajnoczi
0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Tosatti @ 2012-03-27 0:22 UTC (permalink / raw)
To: Stefan Hajnoczi, Kevin Wolf; +Cc: qemu-devel
Close the now unused images that were part of the previous backing file
chain and adjust ->backing_hd, backing_filename and backing_format
properly.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=801449
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
diff --git a/block/stream.c b/block/stream.c
index d1b3986..5880288 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -76,6 +76,39 @@ 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,
+ const char *base_id)
+{
+ 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;
+
+ pstrcpy(top->backing_file, sizeof(top->backing_file), "");
+ pstrcpy(top->backing_format, sizeof(top->backing_format), "");
+ if (base_id) {
+ pstrcpy(top->backing_file, sizeof(top->backing_file), base_id);
+ if (base->drv) {
+ pstrcpy(top->backing_format, sizeof(top->backing_format),
+ base->drv->format_name);
+ }
+ }
+
+}
+
/*
* Given an image chain: [BASE] -> [INTER1] -> [INTER2] -> [TOP]
*
@@ -221,6 +254,7 @@ retry:
base_id = s->backing_file_id;
}
ret = bdrv_change_backing_file(bs, base_id, NULL);
+ close_unused_images(bs, base, base_id);
}
qemu_vfree(buf);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] block stream: close unused files and update ->backing_hd
2012-03-27 0:22 [Qemu-devel] [PATCH v2] block stream: close unused files and update ->backing_hd Marcelo Tosatti
@ 2012-03-27 7:13 ` Stefan Hajnoczi
2012-04-05 13:12 ` Kevin Wolf
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2012-03-27 7:13 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: Kevin Wolf, qemu-devel
On Mon, Mar 26, 2012 at 09:22:10PM -0300, Marcelo Tosatti wrote:
>
> Close the now unused images that were part of the previous backing file
> chain and adjust ->backing_hd, backing_filename and backing_format
> properly.
>
> Fixes https://bugzilla.redhat.com/show_bug.cgi?id=801449
>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] block stream: close unused files and update ->backing_hd
2012-03-27 7:13 ` Stefan Hajnoczi
@ 2012-04-05 13:12 ` Kevin Wolf
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Wolf @ 2012-04-05 13:12 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Marcelo Tosatti, qemu-devel
Am 27.03.2012 09:13, schrieb Stefan Hajnoczi:
> On Mon, Mar 26, 2012 at 09:22:10PM -0300, Marcelo Tosatti wrote:
>>
>> Close the now unused images that were part of the previous backing file
>> chain and adjust ->backing_hd, backing_filename and backing_format
>> properly.
>>
>> Fixes https://bugzilla.redhat.com/show_bug.cgi?id=801449
>>
>> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>
> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-05 13:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-27 0:22 [Qemu-devel] [PATCH v2] block stream: close unused files and update ->backing_hd Marcelo Tosatti
2012-03-27 7:13 ` Stefan Hajnoczi
2012-04-05 13:12 ` Kevin Wolf
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).