From patchwork Fri Oct 14 13:08:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9376805 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 0DE906022E for ; Fri, 14 Oct 2016 13:12:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F34F92A687 for ; Fri, 14 Oct 2016 13:12:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7F8C2A690; Fri, 14 Oct 2016 13:12:07 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 B82BD2A687 for ; Fri, 14 Oct 2016 13:12:06 +0000 (UTC) Received: from localhost ([::1]:47221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2HN-0008BK-OR for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Oct 2016 09:12:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2FN-0006gd-W9 for qemu-devel@nongnu.org; Fri, 14 Oct 2016 09:10:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bv2FK-0007CL-E6 for qemu-devel@nongnu.org; Fri, 14 Oct 2016 09:10:01 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:33004 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv2FK-00073X-5z; Fri, 14 Oct 2016 09:09:58 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BDAgCE2ABY/5tjdVtcHQYMgz0BAQEBAR2BU400lV4BAQEBAQEFAYEXAY97gjGCD4IIhiICgg44FAECAQEBAQEBAV4nhGICBCdSED8SPBsZiFYBwwUBMYVyglCMdgWPM4pTkACJaYYMSZAvHjZEBgiCehyBVm+INQEBAQ X-IPAS-Result: A2BDAgCE2ABY/5tjdVtcHQYMgz0BAQEBAR2BU400lV4BAQEBAQEFAYEXAY97gjGCD4IIhiICgg44FAECAQEBAQEBAV4nhGICBCdSED8SPBsZiFYBwwUBMYVyglCMdgWPM4pTkACJaYYMSZAvHjZEBgiCehyBVm+INQEBAQ X-IronPort-AV: E=Sophos;i="5.31,493,1473112800"; d="scan'208";a="118727408" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 14 Oct 2016 15:08:59 +0200 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim) id 1bv2EM-0004Qq-1f; Fri, 14 Oct 2016 15:08:58 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bv2E1-0006kH-Qo; Fri, 14 Oct 2016 16:08:37 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 14 Oct 2016 16:08:15 +0300 Message-Id: X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.51.32.191 Subject: [Qemu-devel] [PATCH v11 03/19] block: Add block_job_add_bdrv() 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@nongnu.org, Markus Armbruster , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When a block job is created on a certain BlockDriverState, operations are blocked there while the job exists. However, some block jobs may involve additional BDSs, which must be blocked separately when the job is created and unblocked manually afterwards. This patch adds block_job_add_bdrv(), that simplifies this process by keeping a list of BDSs that are involved in the specified block job. Signed-off-by: Alberto Garcia --- blockjob.c | 17 +++++++++++++++-- include/block/blockjob.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/blockjob.c b/blockjob.c index 43fecbe..c67c46d 100644 --- a/blockjob.c +++ b/blockjob.c @@ -117,6 +117,13 @@ static void block_job_detach_aio_context(void *opaque) block_job_unref(job); } +void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs) +{ + job->nodes = g_slist_prepend(job->nodes, bs); + bdrv_ref(bs); + bdrv_op_block_all(bs, job->blocker); +} + void *block_job_create(const char *job_id, const BlockJobDriver *driver, BlockDriverState *bs, int64_t speed, BlockCompletionFunc *cb, void *opaque, Error **errp) @@ -154,7 +161,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, job = g_malloc0(driver->instance_size); error_setg(&job->blocker, "block device is in use by block job: %s", BlockJobType_lookup[driver->job_type]); - bdrv_op_block_all(bs, job->blocker); + block_job_add_bdrv(job, bs); bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); job->driver = driver; @@ -193,9 +200,15 @@ void block_job_ref(BlockJob *job) void block_job_unref(BlockJob *job) { if (--job->refcnt == 0) { + GSList *l; BlockDriverState *bs = blk_bs(job->blk); bs->job = NULL; - bdrv_op_unblock_all(bs, job->blocker); + for (l = job->nodes; l; l = l->next) { + bs = l->data; + bdrv_op_unblock_all(bs, job->blocker); + bdrv_unref(bs); + } + g_slist_free(job->nodes); blk_remove_aio_context_notifier(job->blk, block_job_attached_aio_context, block_job_detach_aio_context, job); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 4ddb4ae..bab91b1 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -181,6 +181,9 @@ struct BlockJob { /** Block other operations when block job is running */ Error *blocker; + /** BlockDriverStates that are involved in this block job */ + GSList *nodes; + /** The opaque value that is passed to the completion function. */ void *opaque; @@ -246,6 +249,17 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, BlockCompletionFunc *cb, void *opaque, Error **errp); /** + * block_job_add_bdrv: + * @job: A block job + * @bs: A BlockDriverState that is involved in @job + * + * Add @bs to the list of BlockDriverState that are involved in + * @job. This means that all operations will be blocked on @bs while + * @job exists. + */ +void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs); + +/** * block_job_sleep_ns: * @job: The job that calls the function. * @clock: The clock to sleep on.