From patchwork Wed Aug 9 14:02:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 9890697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79B8660384 for ; Wed, 9 Aug 2017 14:06:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5107628AAB for ; Wed, 9 Aug 2017 14:06:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45EEC28ABC; Wed, 9 Aug 2017 14:06:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 80CC428AAB for ; Wed, 9 Aug 2017 14:06:57 +0000 (UTC) Received: from localhost ([::1]:47695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfRdQ-0004gR-La for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Aug 2017 10:06:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfRaw-0003Xi-II for qemu-devel@nongnu.org; Wed, 09 Aug 2017 10:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfRap-0003ch-Vv for qemu-devel@nongnu.org; Wed, 09 Aug 2017 10:04:22 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:49068) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfRal-0003Vy-PN; Wed, 09 Aug 2017 10:04:12 -0400 Received: from mail.ntua.gr ([IPv6:2a02:587:8030:4e00:989e:98bf:1f16:f20b]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v79E3S3L083073 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 9 Aug 2017 17:03:28 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host [IPv6:2a02:587:8030:4e00:989e:98bf:1f16:f20b] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Wed, 9 Aug 2017 17:02:51 +0300 Message-Id: <20170809140256.25584-2-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170809140256.25584-1-el13635@mail.ntua.gr> References: <20170809140256.25584-1-el13635@mail.ntua.gr> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH v2 1/6] block: skip implicit nodes in snapshots, blockjobs 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: Kevin Wolf , Alberto Garcia , Stefan Hajnoczi , qemu-block Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implicit filter nodes added at the top of nodes can interfere with block jobs. This is not a problem when they are added by other jobs since adding another job will issue a QERR_DEVICE_IN_USE, but it can happen in the next commit which introduces an implicitly created throttle filter node below BlockBackend, which we want to be skipped during automatic operations on the graph since the user does not necessarily know about their existence. Signed-off-by: Manos Pitsidianakis --- block.c | 10 ++++++++++ block/qapi.c | 14 +++++--------- blockdev.c | 34 ++++++++++++++++++++++++++++++++++ include/block/block_int.h | 9 +++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 3615a6809e..e35d546c08 100644 --- a/block.c +++ b/block.c @@ -4945,3 +4945,13 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp); } + +/* Get first explicit node down a bs chain. */ +BlockDriverState *bdrv_get_first_explicit(BlockDriverState *bs) +{ + while (bs && bs->drv && bs->implicit) { + bs = child_bs(bs); + assert(bs); + } + return bs; +} diff --git a/block/qapi.c b/block/qapi.c index 7fa2437923..847b044d13 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -147,9 +147,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, /* Skip automatically inserted nodes that the user isn't aware of for * query-block (blk != NULL), but not for query-named-block-nodes */ - while (blk && bs0->drv && bs0->implicit) { - bs0 = backing_bs(bs0); - assert(bs0); + if (blk) { + bs0 = bdrv_get_first_explicit(bs0); } } @@ -336,9 +335,7 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, char *qdev; /* Skip automatically inserted nodes that the user isn't aware of */ - while (bs && bs->drv && bs->implicit) { - bs = backing_bs(bs); - } + bs = bdrv_get_first_explicit(bs); info->device = g_strdup(blk_name(blk)); info->type = g_strdup("unknown"); @@ -465,9 +462,8 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, /* Skip automatically inserted nodes that the user isn't aware of in * a BlockBackend-level command. Stay at the exact node for a node-level * command. */ - while (blk_level && bs->drv && bs->implicit) { - bs = backing_bs(bs); - assert(bs); + if (blk_level) { + bs = bdrv_get_first_explicit(bs); } if (bdrv_get_node_name(bs)[0]) { diff --git a/blockdev.c b/blockdev.c index 23475abb72..fc7b65c3f0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1300,6 +1300,10 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, if (!bs) { return NULL; } + + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -1508,6 +1512,9 @@ static void internal_snapshot_prepare(BlkActionState *common, return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + /* AioContext is released in .clean() */ state->aio_context = bdrv_get_aio_context(bs); aio_context_acquire(state->aio_context); @@ -1664,6 +1671,9 @@ static void external_snapshot_prepare(BlkActionState *common, return; } + /* Skip implicit filter nodes */ + state->old_bs = bdrv_get_first_explicit(state->old_bs); + /* Acquire AioContext now so any threads operating on old_bs stop */ state->aio_context = bdrv_get_aio_context(state->old_bs); aio_context_acquire(state->aio_context); @@ -1844,6 +1854,9 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + /* AioContext is released in .clean() */ state->aio_context = bdrv_get_aio_context(bs); aio_context_acquire(state->aio_context); @@ -1908,6 +1921,9 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp) return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + target = bdrv_lookup_bs(backup->target, backup->target, errp); if (!target) { return; @@ -2988,6 +3004,9 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3095,6 +3114,9 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device, return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3209,6 +3231,9 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, return NULL; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3484,6 +3509,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3638,6 +3666,9 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id, return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + target_bs = bdrv_lookup_bs(target, target, errp); if (!target_bs) { return; @@ -3786,6 +3817,9 @@ void qmp_change_backing_file(const char *device, return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_explicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); diff --git a/include/block/block_int.h b/include/block/block_int.h index 7571c0aaaf..8353b83e86 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -699,6 +699,13 @@ static inline BlockDriverState *backing_bs(BlockDriverState *bs) return bs->backing ? bs->backing->bs : NULL; } +static inline BlockDriverState *child_bs(BlockDriverState *bs) +{ + BdrvChild *child = QLIST_FIRST(&bs->children); + assert(child && !QLIST_NEXT(child, next)); + return child->bs; +} + /* Essential block drivers which must always be statically linked into qemu, and * which therefore can be accessed without using bdrv_find_format() */ @@ -980,4 +987,6 @@ void bdrv_dec_in_flight(BlockDriverState *bs); void blockdev_close_all_bdrv_states(void); +BlockDriverState *bdrv_get_first_explicit(BlockDriverState *bs); + #endif /* BLOCK_INT_H */