From patchwork Fri Jul 8 17:21:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9221531 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 3A0666044F for ; Fri, 8 Jul 2016 17:27:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26F2F27F60 for ; Fri, 8 Jul 2016 17:27:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BFB627F85; Fri, 8 Jul 2016 17:27:19 +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 91FEF27F60 for ; Fri, 8 Jul 2016 17:27:18 +0000 (UTC) Received: from localhost ([::1]:46940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLZYb-000743-KJ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 08 Jul 2016 13:27:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLZTa-00019E-IJ for qemu-devel@nongnu.org; Fri, 08 Jul 2016 13:22:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bLZTV-0008Kq-DZ for qemu-devel@nongnu.org; Fri, 08 Jul 2016 13:22:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42756) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLZTM-0008I3-Kl; Fri, 08 Jul 2016 13:21:52 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CB09C04B31B; Fri, 8 Jul 2016 17:21:52 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u68HLk2q006858; Fri, 8 Jul 2016 13:21:51 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 8 Jul 2016 19:21:16 +0200 Message-Id: <1467998504-15744-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1467998504-15744-1-git-send-email-kwolf@redhat.com> References: <1467998504-15744-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 08 Jul 2016 17:21:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/32] 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia 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 Signed-off-by: Kevin Wolf --- blockdev.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/blockdev.c b/blockdev.c index 0f8065c..e649521 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; - *aio_context = NULL; + assert(id != NULL); - blk = blk_by_name(device); - if (!blk) { - goto notfound; - } - - *aio_context = blk_get_aio_context(blk); - aio_context_acquire(*aio_context); + *aio_context = NULL; - if (!blk_is_available(blk)) { - goto notfound; - } - bs = blk_bs(blk); + job = block_job_get(id); - if (!bs->job) { - goto notfound; + if (!job) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE, + "Block job '%s' not found", id); + return NULL; } - return bs->job; + *aio_context = blk_get_aio_context(job->blk); + aio_context_acquire(*aio_context); -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)