From patchwork Tue Aug 1 13:49:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 9874661 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 8FD616038F for ; Tue, 1 Aug 2017 13:51:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DFC6286E0 for ; Tue, 1 Aug 2017 13:51:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72C7E286D5; Tue, 1 Aug 2017 13:51:31 +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 D849727F86 for ; Tue, 1 Aug 2017 13:51:29 +0000 (UTC) Received: from localhost ([::1]:42653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcXa4-0005ni-Oj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Aug 2017 09:51:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcXYx-0005hq-Vc for qemu-devel@nongnu.org; Tue, 01 Aug 2017 09:50:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dcXYw-0005JQ-Vw for qemu-devel@nongnu.org; Tue, 01 Aug 2017 09:50:20 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:48065) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dcXYu-00058L-83; Tue, 01 Aug 2017 09:50:16 -0400 Received: from mail.ntua.gr ([IPv6:2a02:587:8020:2800:cd94:9845:8007:a6e4]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v71DncxY012823 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 1 Aug 2017 16:49:38 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host [IPv6:2a02:587:8020:2800:cd94:9845:8007:a6e4] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Tue, 1 Aug 2017 16:49:06 +0300 Message-Id: <20170801134907.31253-3-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170801134907.31253-1-el13635@mail.ntua.gr> References: <20170801134907.31253-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 2/3] 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 , qemu-block , Stefan Hajnoczi 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 | 17 +++++++++++++++++ blockdev.c | 12 ++++++++++++ include/block/block_int.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/block.c b/block.c index 886a457ab0..9ebdba28b0 100644 --- a/block.c +++ b/block.c @@ -4947,3 +4947,20 @@ 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 non-implicit node down a bs chain. */ +BlockDriverState *bdrv_get_first_non_implicit(BlockDriverState *bs) +{ + if (!bs) { + return NULL; + } + + if (!bs->implicit) { + return bs; + } + + /* at this point bs is implicit and must have a child */ + assert(bs->file); + + return bdrv_get_first_non_implicit(bs->file->bs); +} diff --git a/blockdev.c b/blockdev.c index 23475abb72..d903a23786 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1664,6 +1664,9 @@ static void external_snapshot_prepare(BlkActionState *common, return; } + /* Skip implicit filter nodes */ + state->old_bs = bdrv_get_first_non_implicit(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); @@ -3095,6 +3098,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_non_implicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3209,6 +3215,9 @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, return NULL; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_non_implicit(bs); + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3484,6 +3493,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) return; } + /* Skip implicit filter nodes */ + bs = bdrv_get_first_non_implicit(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 d4f4ea7584..9eeae490f0 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -981,4 +981,6 @@ void bdrv_dec_in_flight(BlockDriverState *bs); void blockdev_close_all_bdrv_states(void); +BlockDriverState *bdrv_get_first_non_implicit(BlockDriverState *bs); + #endif /* BLOCK_INT_H */