From patchwork Tue Mar 22 19:36:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8644801 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 97195C0553 for ; Tue, 22 Mar 2016 19:40:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5A1E20212 for ; Tue, 22 Mar 2016 19:40:03 +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 BFD9B20204 for ; Tue, 22 Mar 2016 19:40:02 +0000 (UTC) Received: from localhost ([::1]:39260 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiS9q-0006RD-5c for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Mar 2016 15:40:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiS6x-00011w-Vw for qemu-devel@nongnu.org; Tue, 22 Mar 2016 15:37:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiS6u-0003Fc-Oa for qemu-devel@nongnu.org; Tue, 22 Mar 2016 15:37:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiS6o-0003Dc-SZ; Tue, 22 Mar 2016 15:36:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 85BD07823F; Tue, 22 Mar 2016 19:36:54 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MJadsi002983; Tue, 22 Mar 2016 15:36:53 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 22 Mar 2016 20:36:37 +0100 Message-Id: <1458675397-24956-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1458675397-24956-1-git-send-email-kwolf@redhat.com> References: <1458675397-24956-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Subject: [Qemu-devel] [PATCH 9/9] block: Remove BlockDriverState.blk 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org 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. All checks that are currently in place to prevent the user from creating such setups. 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 | 8 -------- block/block-backend.c | 8 -------- block/mirror.c | 4 ++-- blockdev.c | 19 ++++++++----------- include/block/block_int.h | 2 -- tests/qemu-iotests/085.out | 6 +++--- 6 files changed, 13 insertions(+), 34 deletions(-) diff --git a/block.c b/block.c index eefbcf3..05f9ad4 100644 --- a/block.c +++ b/block.c @@ -2227,14 +2227,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; diff --git a/block/block-backend.c b/block/block-backend.c index b71b822..42f95a6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -190,7 +190,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; } @@ -453,12 +452,10 @@ bool bdrv_has_blk(BlockDriverState *bs) BdrvChild *child; QLIST_FOREACH(child, &bs->parents, next_parent) { if (child->role == &child_root) { - assert(bs->blk); return true; } } - assert(!bs->blk); return false; } @@ -518,8 +515,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); @@ -527,7 +522,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; } @@ -537,11 +531,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 b9a93fd..8b32271 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -450,7 +450,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; @@ -825,7 +825,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 c59cf3e..a658869 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1774,9 +1774,8 @@ static void external_snapshot_prepare(BlkActionState *common, return; } - if (state->new_bs->blk != NULL) { - error_setg(errp, "The snapshot is already in use by %s", - blk_name(state->new_bs->blk)); + if (bdrv_has_blk(state->new_bs)) { + error_setg(errp, "The snapshot is already in use"); return; } @@ -2492,9 +2491,8 @@ void qmp_x_blockdev_insert_medium(const char *device, const char *node_name, return; } - if (bs->blk) { - error_setg(errp, "Node '%s' is already in use by '%s'", node_name, - blk_name(bs->blk)); + if (bdrv_has_blk(bs)) { + error_setg(errp, "Node '%s' is already in use", node_name); return; } @@ -3439,7 +3437,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; } @@ -4023,15 +4021,14 @@ 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) { - error_setg(errp, "Node %s is in use by %s", - node_name, blk_name(blk)); + if (bdrv_has_blk(bs)) { + error_setg(errp, "Node %s is in use", node_name); return; } aio_context = bdrv_get_aio_context(bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 9358949..2bbca78 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -406,8 +406,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 diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out index 01c78d6..08e4bb7 100644 --- a/tests/qemu-iotests/085.out +++ b/tests/qemu-iotests/085.out @@ -68,9 +68,9 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/ === Invalid command - snapshot node used as active layer === -{"error": {"class": "GenericError", "desc": "The snapshot is already in use by virtio0"}} -{"error": {"class": "GenericError", "desc": "The snapshot is already in use by virtio0"}} -{"error": {"class": "GenericError", "desc": "The snapshot is already in use by virtio1"}} +{"error": {"class": "GenericError", "desc": "The snapshot is already in use"}} +{"error": {"class": "GenericError", "desc": "The snapshot is already in use"}} +{"error": {"class": "GenericError", "desc": "The snapshot is already in use"}} === Invalid command - snapshot node used as backing hd ===