From patchwork Mon Jan 7 07:28:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 209873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D16582C007E for ; Mon, 7 Jan 2013 18:54:20 +1100 (EST) Received: from localhost ([::1]:35554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts7Ak-0005CR-Qj for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 02:31:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts79x-0003P5-Fm for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ts79w-0005RW-Dh for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:13 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:36308) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ts79v-0005R3-R0 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 02:30:12 -0500 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 7 Jan 2013 17:25:23 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 7 Jan 2013 17:25:21 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 74166357804D for ; Mon, 7 Jan 2013 18:30:06 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r077ITdW57475200 for ; Mon, 7 Jan 2013 18:18:29 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r077U5Zc021536 for ; Mon, 7 Jan 2013 18:30:05 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.237]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r077Rp6W018491; Mon, 7 Jan 2013 18:30:03 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 7 Jan 2013 15:28:00 +0800 Message-Id: <1357543689-11415-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1357543689-11415-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13010707-6102-0000-0000-000002CFFC4E X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.145 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 Subject: [Qemu-devel] [PATCH V2 02/10] block: add function deappend() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);