From patchwork Thu Oct 1 13:13:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 525154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AB6EB14016A for ; Fri, 2 Oct 2015 02:23:04 +1000 (AEST) Received: from localhost ([::1]:52775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhgdK-0005ZL-Nw for incoming@patchwork.ozlabs.org; Thu, 01 Oct 2015 12:23:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhdgZ-0003i1-Et for qemu-devel@nongnu.org; Thu, 01 Oct 2015 09:14:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhdgY-0002b8-Gk for qemu-devel@nongnu.org; Thu, 01 Oct 2015 09:14:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhdgR-0002Yr-DV; Thu, 01 Oct 2015 09:14:03 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 029B024B; Thu, 1 Oct 2015 13:14:03 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-91.ams2.redhat.com [10.36.116.91]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t91DDbtf016338; Thu, 1 Oct 2015 09:14:00 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 1 Oct 2015 15:13:27 +0200 Message-Id: <1443705214-9304-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1443705214-9304-1-git-send-email-kwolf@redhat.com> References: <1443705214-9304-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 09/16] block: Split bdrv_move_feature_fields() 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 After bdrv_swap(), some fields must be moved back to their original BDS to compensate for the effects that a swap of the contents of the objects has while keeping the old addresses. Other fields must be moved back because they should logically be moved and must stay on top When replacing bdrv_swap() with operations changing the pointers in the parents, we only need the latter and must avoid swapping the former. Split the function accordingly. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block.c b/block.c index c4dcf81..f8e4631 100644 --- a/block.c +++ b/block.c @@ -1985,6 +1985,8 @@ static void bdrv_rebind(BlockDriverState *bs) } } +/* Fields that need to stay with the top-level BDS, no matter whether the + * address of the top-level BDS stays the same or not. */ static void bdrv_move_feature_fields(BlockDriverState *bs_dest, BlockDriverState *bs_src) { @@ -2020,7 +2022,13 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest, /* dirty bitmap */ bs_dest->dirty_bitmaps = bs_src->dirty_bitmaps; +} +/* Fields that only need to be swapped if the contents of BDSes is swapped + * rather than pointers being changed in the parents. */ +static void bdrv_move_reference_fields(BlockDriverState *bs_dest, + BlockDriverState *bs_src) +{ /* reference count */ bs_dest->refcnt = bs_src->refcnt; @@ -2091,6 +2099,10 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old) bdrv_move_feature_fields(bs_old, bs_new); bdrv_move_feature_fields(bs_new, &tmp); + bdrv_move_reference_fields(&tmp, bs_old); + bdrv_move_reference_fields(bs_old, bs_new); + bdrv_move_reference_fields(bs_new, &tmp); + /* bs_new must remain unattached */ assert(!bs_new->blk);