From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SAWao-0006dA-GP for qemu-devel@nongnu.org; Wed, 21 Mar 2012 21:13:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SAWam-0000IK-Mo for qemu-devel@nongnu.org; Wed, 21 Mar 2012 21:13:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SAWam-0000I1-Ef for qemu-devel@nongnu.org; Wed, 21 Mar 2012 21:13:28 -0400 Date: Wed, 21 Mar 2012 22:09:45 -0300 From: Marcelo Tosatti Message-ID: <20120322010945.GA7674@amt.cnet> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] block stream: close unused files and update ->backing_hd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , Kevin Wolf Cc: qemu-devel@nongnu.org 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 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);