From patchwork Wed Apr 27 13:20:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8957371 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E4F3CBF29F for ; Wed, 27 Apr 2016 13:25:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F26C201E4 for ; Wed, 27 Apr 2016 13:25:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B185520253 for ; Wed, 27 Apr 2016 13:25:27 +0000 (UTC) Received: from localhost ([::1]:43101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avPT5-0005j4-1s for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Apr 2016 09:25:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avPOj-0005sA-9k for qemu-devel@nongnu.org; Wed, 27 Apr 2016 09:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avPOe-00010e-QN for qemu-devel@nongnu.org; Wed, 27 Apr 2016 09:20:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avPOb-0000yw-IF; Wed, 27 Apr 2016 09:20:49 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39250310F; Wed, 27 Apr 2016 13:20:49 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RDKXxI012383; Wed, 27 Apr 2016 09:20:47 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 27 Apr 2016 15:20:31 +0200 Message-Id: <1461763231-17598-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1461763231-17598-1-git-send-email-kwolf@redhat.com> References: <1461763231-17598-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 9/9] block: Remove BlockDriverState.blk X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch removes the remaining users of bs->blk, which will allow us to have multiple BBs on top of a single BDS. In the meantime, all checks that are currently in place to prevent the user from creating such setups can be switched to bdrv_has_blk() instead of accessing BDS.blk. Future patches can allow them and e.g. enable users to mirror to a block device that already has a BlockBackend on it. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 10 +--------- block/block-backend.c | 8 -------- block/mirror.c | 4 ++-- blockdev.c | 16 ++++++++-------- include/block/block_int.h | 3 +-- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index 117bef7..cf813ef 100644 --- a/block.c +++ b/block.c @@ -2228,14 +2228,6 @@ static void change_parent_backing_link(BlockDriverState *from, { BdrvChild *c, *next; - if (from->blk) { - /* FIXME We bypass blk_set_bs(), so we need to make these updates - * manually. The root problem is not in this change function, but the - * existence of BlockDriverState.blk. */ - to->blk = from->blk; - from->blk = NULL; - } - QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { assert(c->role != &child_backing); c->bs = to; @@ -2877,7 +2869,7 @@ const char *bdrv_get_node_name(const BlockDriverState *bs) return bs->node_name; } -static const char *bdrv_get_parent_name(const BlockDriverState *bs) +const char *bdrv_get_parent_name(const BlockDriverState *bs) { BdrvChild *c; const char *name; diff --git a/block/block-backend.c b/block/block-backend.c index a355590..ffcd44a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -152,7 +152,6 @@ BlockBackend *blk_new_with_bs(Error **errp) bs = bdrv_new_root(); blk->root = bdrv_root_attach_child(bs, "root", &child_root); blk->root->opaque = blk; - bs->blk = blk; return blk; } @@ -422,12 +421,10 @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs) BdrvChild *child; QLIST_FOREACH(child, &bs->parents, next_parent) { if (child->role == &child_root) { - assert(bs->blk); return child->opaque; } } - assert(!bs->blk); return NULL; } @@ -495,8 +492,6 @@ BlockBackend *blk_by_public(BlockBackendPublic *public) */ void blk_remove_bs(BlockBackend *blk) { - assert(blk->root->bs->blk == blk); - notifier_list_notify(&blk->remove_bs_notifiers, blk); if (blk->public.throttle_state) { throttle_timers_detach_aio_context(&blk->public.throttle_timers); @@ -504,7 +499,6 @@ void blk_remove_bs(BlockBackend *blk) blk_update_root_state(blk); - blk->root->bs->blk = NULL; bdrv_root_unref_child(blk->root); blk->root = NULL; } @@ -514,11 +508,9 @@ void blk_remove_bs(BlockBackend *blk) */ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) { - assert(!blk->root && !bs->blk); bdrv_ref(bs); blk->root = bdrv_root_attach_child(bs, "root", &child_root); blk->root->opaque = blk; - bs->blk = blk; notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { diff --git a/block/mirror.c b/block/mirror.c index 71d7a4e..b9986d8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -468,7 +468,7 @@ static void mirror_exit(BlockJob *job, void *opaque) /* This was checked in mirror_start_job(), but meanwhile one of the * nodes could have been newly attached to a BlockBackend. */ - if (to_replace->blk && s->target->blk) { + if (bdrv_has_blk(to_replace) && bdrv_has_blk(s->target)) { error_report("block job: Can't create node with two BlockBackends"); data->ret = -EINVAL; goto out; @@ -831,7 +831,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, } else { replaced_bs = bs; } - if (replaced_bs->blk && target->blk) { + if (bdrv_has_blk(replaced_bs) && bdrv_has_blk(target)) { error_setg(errp, "Can't create node with two BlockBackends"); return; } diff --git a/blockdev.c b/blockdev.c index 445a213..e667b8c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1776,9 +1776,9 @@ static void external_snapshot_prepare(BlkActionState *common, return; } - if (state->new_bs->blk != NULL) { + if (bdrv_has_blk(state->new_bs)) { error_setg(errp, "The snapshot is already in use by %s", - blk_name(state->new_bs->blk)); + bdrv_get_parent_name(state->new_bs)); return; } @@ -2494,9 +2494,9 @@ void qmp_x_blockdev_insert_medium(const char *device, const char *node_name, return; } - if (bs->blk) { + if (bdrv_has_blk(bs)) { error_setg(errp, "Node '%s' is already in use by '%s'", node_name, - blk_name(bs->blk)); + bdrv_get_parent_name(bs)); return; } @@ -3441,7 +3441,7 @@ static void blockdev_mirror_common(BlockDriverState *bs, if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_MIRROR_TARGET, errp)) { return; } - if (target->blk) { + if (bdrv_has_blk(target)) { error_setg(errp, "Cannot mirror to an attached block device"); return; } @@ -4030,15 +4030,15 @@ void qmp_x_blockdev_del(bool has_id, const char *id, bs = blk_bs(blk); aio_context = blk_get_aio_context(blk); } else { + blk = NULL; bs = bdrv_find_node(node_name); if (!bs) { error_setg(errp, "Cannot find node %s", node_name); return; } - blk = bs->blk; - if (blk) { + if (bdrv_has_blk(bs)) { error_setg(errp, "Node %s is in use by %s", - node_name, blk_name(blk)); + node_name, bdrv_get_parent_name(bs)); return; } aio_context = bdrv_get_aio_context(bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index f4a0941..647e9b3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -407,8 +407,6 @@ struct BlockDriverState { BlockDriver *drv; /* NULL means no media */ void *opaque; - BlockBackend *blk; /* owning backend, if any */ - AioContext *aio_context; /* event loop used for fd handlers, timers, etc */ /* long-running tasks intended to always use the same AioContext as this * BDS may register themselves in this list to be notified of changes @@ -708,6 +706,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const BdrvChildRole *child_role); void bdrv_root_unref_child(BdrvChild *child); +const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load); bool blk_dev_has_removable_media(BlockBackend *blk); bool blk_dev_has_tray(BlockBackend *blk);