From patchwork Fri May 30 15:35:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 354234 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 704341400D6 for ; Sat, 31 May 2014 01:38:10 +1000 (EST) Received: from localhost ([::1]:54953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqOsi-0006mW-Cn for incoming@patchwork.ozlabs.org; Fri, 30 May 2014 11:38:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqOqG-0001UA-QV for qemu-devel@nongnu.org; Fri, 30 May 2014 11:35:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqOq9-0004ih-5M for qemu-devel@nongnu.org; Fri, 30 May 2014 11:35:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqOq8-0004iV-Fx for qemu-devel@nongnu.org; Fri, 30 May 2014 11:35:28 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4UFZQML021751 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 May 2014 11:35:26 -0400 Received: from localhost (ovpn-112-54.phx2.redhat.com [10.3.112.54]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4UFZOHx014617 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 30 May 2014 11:35:25 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Fri, 30 May 2014 11:35:05 -0400 Message-Id: <8c52711b0fc55e2bb44b3cb2d8a7043079e456c6.1401463410.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, benoit.canet@irqsave.net, pkrempa@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [v3 03/12] block: Add overlay BDS pointer into the BlockDriverState struct 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 Now that node-names can reference an individual BlockDriverState without needing to navigate downwards from the 'device' level, in order to find the top-most image (active layer) we need a pointer to the overlay of a BDS. This will allow QMP commands to reference an image solely by its node-name, without also needing to pass in the corresponding 'device' string. This also adds a helper function to set the overlay pointer that is, for now, trivial. But since we recently moved away from open coding bs->backing_hd assignment, we should probably also refrain from setting bs->overlay directly. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- block.c | 14 ++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 1 + 3 files changed, 16 insertions(+) diff --git a/block.c b/block.c index cf4b296..588046e 100644 --- a/block.c +++ b/block.c @@ -1108,12 +1108,22 @@ fail: return ret; } +void bdrv_set_overlay(BlockDriverState *bs, BlockDriverState *overlay) +{ + if (bs) { + bs->overlay = overlay; + } +} + void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd) { if (bs->backing_hd) { assert(bs->backing_blocker); bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker); + if (!backing_hd) { + bdrv_set_overlay(bs->backing_hd, NULL); + } } else if (backing_hd) { error_setg(&bs->backing_blocker, "device is used as backing hd of '%s'", @@ -1126,6 +1136,8 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd) bs->backing_blocker = NULL; goto out; } + bdrv_set_overlay(backing_hd, bs); + bs->open_flags &= ~BDRV_O_NO_BACKING; pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filename); pstrcpy(bs->backing_format, sizeof(bs->backing_format), @@ -2085,6 +2097,8 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) /* The contents of 'tmp' will become bs_top, as we are * swapping bs_new and bs_top contents. */ bdrv_set_backing_hd(bs_top, bs_new); + /* make sure that bs_new->backing_hd->overlay points to bs_new */ + bdrv_set_overlay(bs_new->backing_hd, bs_new); } static void bdrv_delete(BlockDriverState *bs) diff --git a/include/block/block.h b/include/block/block.h index 4dc68be..dff5403 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -217,6 +217,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char *filename, QDict *options, const char *bdref_key, int flags, bool allow_none, Error **errp); void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd); +void bdrv_set_overlay(BlockDriverState *bs, BlockDriverState *overlay); int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp); void bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp); int bdrv_open(BlockDriverState **pbs, const char *filename, diff --git a/include/block/block_int.h b/include/block/block_int.h index f2e753f..c0fe90b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -303,6 +303,7 @@ struct BlockDriverState { char backing_format[16]; /* if non-zero and backing_file exists */ BlockDriverState *backing_hd; + BlockDriverState *overlay; BlockDriverState *file; NotifierList close_notifiers;