From patchwork Tue Jul 5 14:28:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9214353 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 D34FD6048F for ; Tue, 5 Jul 2016 14:35:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C49AA20453 for ; Tue, 5 Jul 2016 14:35:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B90DC24B48; Tue, 5 Jul 2016 14:35:28 +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 63EB020453 for ; Tue, 5 Jul 2016 14:35:28 +0000 (UTC) Received: from localhost ([::1]:55448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKRRf-000217-GH for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Jul 2016 10:35:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKRMU-0005DL-ES for qemu-devel@nongnu.org; Tue, 05 Jul 2016 10:30:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKRMR-0004A6-Hr for qemu-devel@nongnu.org; Tue, 05 Jul 2016 10:30:05 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:57707 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKRMR-000456-AK; Tue, 05 Jul 2016 10:30:03 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2DZBQAbw3tX/5tjdVtSCh0BgyCBUqRfBQGBEJFBhAaGGAKBMjsRAQEBAQEBAWUnhE0CBCdSED8SPBsZiDQBulcBAQgnhV+CSIZldIUPBYgahWpwih+OR4lLhV9Ij0I0IIIIHIFPa4h5AQEB X-IPAS-Result: A2DZBQAbw3tX/5tjdVtSCh0BgyCBUqRfBQGBEJFBhAaGGAKBMjsRAQEBAQEBAWUnhE0CBCdSED8SPBsZiDQBulcBAQgnhV+CSIZldIUPBYgahWpwih+OR4lLhV9Ij0I0IIIIHIFPa4h5AQEB X-IronPort-AV: E=Sophos;i="5.26,580,1459807200"; d="scan'208";a="81596919" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 05 Jul 2016 16:29:23 +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 1bKRLm-00017b-JQ; Tue, 05 Jul 2016 16:29:22 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bKRLU-0003Z1-RH; Tue, 05 Jul 2016 17:29:04 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 5 Jul 2016 17:28:55 +0300 Message-Id: <4d6fc28a98f25df6ed98257de40bc7d01fde7e25.1467727577.git.berto@igalia.com> X-Mailer: git-send-email 2.8.1 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 v4 04/11] block: Use block_job_get() in find_block_job() 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, Jeff Cody , Max Reitz , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP find_block_job() looks for a block backend with a specified name, checks whether it has a block job and acquires its AioContext. We want to identify jobs by their ID and not by the block backend they're attached to, so this patch ignores the backends altogether and gets the job directly. Apart from making the code simpler, this will allow us to find block jobs once they start having user-specified IDs. To ensure backward compatibility we keep ERROR_CLASS_DEVICE_NOT_ACTIVE as the error class if the job doesn't exist. In subsequent patches we'll also need to keep the device name as the default job ID if the user doesn't specify a different one. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Kevin Wolf --- blockdev.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3a104a0..f19f3b7 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3704,42 +3704,28 @@ void qmp_blockdev_mirror(const char *device, const char *target, aio_context_release(aio_context); } -/* Get the block job for a given device name and acquire its AioContext */ -static BlockJob *find_block_job(const char *device, AioContext **aio_context, +/* Get a block job using its ID and acquire its AioContext */ +static BlockJob *find_block_job(const char *id, AioContext **aio_context, Error **errp) { - BlockBackend *blk; - BlockDriverState *bs; + BlockJob *job; + + assert(id != NULL); *aio_context = NULL; - blk = blk_by_name(device); - if (!blk) { - goto notfound; + job = block_job_get(id); + + if (!job) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE, + "Block job '%s' not found", id); + return NULL; } - *aio_context = blk_get_aio_context(blk); + *aio_context = blk_get_aio_context(job->blk); aio_context_acquire(*aio_context); - if (!blk_is_available(blk)) { - goto notfound; - } - bs = blk_bs(blk); - - if (!bs->job) { - goto notfound; - } - - return bs->job; - -notfound: - error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE, - "No active block job on device '%s'", device); - if (*aio_context) { - aio_context_release(*aio_context); - *aio_context = NULL; - } - return NULL; + return job; } void qmp_block_job_set_speed(const char *device, int64_t speed, Error **errp)