From patchwork Mon Jan 7 07:28:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V2,02/10] block: add function deappend() Date: Sun, 06 Jan 2013 21:28:00 -0000 From: Wayne Xia X-Patchwork-Id: 209873 Message-Id: <1357543689-11415-3-git-send-email-xiawenc@linux.vnet.ibm.com> To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, Wenchao Xia , lcapitulino@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com This function should revert the append operation. Signed-off-by: Wenchao Xia --- block.c | 21 +++++++++++++++++++++ include/block/block.h | 1 + 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 09208c2..48ddf64 100644 --- a/block.c +++ b/block.c @@ -1376,6 +1376,27 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) bs_new->drv ? bs_new->drv->format_name : ""); } +/* + * Remove bs contents which is at the top of an image chain while + * the chain is live. After bdrv_append(bs_new, bs_top) called, + * bs_top keeps as the top of the chain but bs_new become the 2nd + * top one, so call bdrv_deappend(bs_new, bs_top) to cancel the change. + * As a result, bs_top still keeps the top position but bs_new is + * is discarded. + * + * This will modify the BlockDriverState fields, and swap contents + * between bs_old and bs_top. Both bs_old and bs_top are modified. + * + * bs_old and bs_top should be the pairs which have been used in + * bdrv_append(). + * + * This function does not delete any image files. + */ +void bdrv_deappend(BlockDriverState *bs_old, BlockDriverState *bs_top) +{ + bdrv_swap(bs_old, bs_top); +} + void bdrv_delete(BlockDriverState *bs) { assert(!bs->dev); diff --git a/include/block/block.h b/include/block/block.h index a49fd71..ae6a5ae 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -130,6 +130,7 @@ BlockDriverState *bdrv_new(const char *device_name); void bdrv_make_anon(BlockDriverState *bs); void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old); void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top); +void bdrv_deappend(BlockDriverState *bs_old, BlockDriverState *bs_top); void bdrv_delete(BlockDriverState *bs); int bdrv_parse_cache_flags(const char *mode, int *flags); int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);