From patchwork Fri Jul 1 15:52:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 9210121 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 145F660752 for ; Fri, 1 Jul 2016 16:01:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0327A28459 for ; Fri, 1 Jul 2016 16:01:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA37C2868D; Fri, 1 Jul 2016 16:01:04 +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 530F028459 for ; Fri, 1 Jul 2016 16:01:04 +0000 (UTC) Received: from localhost ([::1]:34139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ0sI-0000r1-Ic for patchwork-qemu-devel@patchwork.kernel.org; Fri, 01 Jul 2016 12:01:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ0kl-0000La-K4 for qemu-devel@nongnu.org; Fri, 01 Jul 2016 11:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJ0kf-0004jv-WA for qemu-devel@nongnu.org; Fri, 01 Jul 2016 11:53:14 -0400 Received: from smtp3.mundo-r.com ([212.51.32.191]:19237 helo=smtp4.mundo-r.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ0kf-0004jk-Oy; Fri, 01 Jul 2016 11:53:09 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2AlBQAhkXZX/5tjdVtTCh0BgyCBUqRkBgUBgRCRQYQKhhgCgTA7EQEBAQEBAQFlJ4RNAgQnUhA/EjwbGYg0AcRCAQEIJ4VggkeGZnSFDwWIF4VqcIofjkSJS4VfSI9BNCCCCByBT2uIdAEBAQ X-IPAS-Result: A2AlBQAhkXZX/5tjdVtTCh0BgyCBUqRkBgUBgRCRQYQKhhgCgTA7EQEBAQEBAQFlJ4RNAgQnUhA/EjwbGYg0AcRCAQEIJ4VggkeGZnSFDwWIF4VqcIofjkSJS4VfSI9BNCCCCByBT2uIdAEBAQ X-IronPort-AV: E=Sophos;i="5.26,557,1459807200"; d="scan'208";a="146521268" Received: from fanzine.igalia.com ([91.117.99.155]) by smtp4.mundo-r.com with ESMTP; 01 Jul 2016 17:52:29 +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 1bJ0k1-0003iA-4C; Fri, 01 Jul 2016 17:52:29 +0200 Received: from berto by perseus.local with local (Exim 4.87) (envelope-from ) id 1bJ0jl-0005PJ-6c; Fri, 01 Jul 2016 18:52:13 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 1 Jul 2016 18:52:02 +0300 Message-Id: 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 v3 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 --- blockdev.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3a104a0..8cedb60 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3704,42 +3704,31 @@ 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; *aio_context = NULL; - blk = blk_by_name(device); - if (!blk) { - goto notfound; + if (!id) { + error_setg(errp, "Unspecified job ID when looking for a block job"); + return NULL; } - *aio_context = blk_get_aio_context(blk); + 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(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)