From patchwork Tue Nov 1 12:51:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9407337 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 5A63060585 for ; Tue, 1 Nov 2016 12:56:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BFFB294B3 for ; Tue, 1 Nov 2016 12:56:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DB8E2984A; Tue, 1 Nov 2016 12:56:30 +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 B3F9E294B3 for ; Tue, 1 Nov 2016 12:56:29 +0000 (UTC) Received: from localhost ([::1]:47679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1Yc8-00088i-W4 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Nov 2016 08:56:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1YXO-0004NY-Ib for qemu-devel@nongnu.org; Tue, 01 Nov 2016 08:51:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1YXN-0003m2-8r for qemu-devel@nongnu.org; Tue, 01 Nov 2016 08:51:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1YXK-0003kk-CP; Tue, 01 Nov 2016 08:51:30 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 994AD85376; Tue, 1 Nov 2016 12:51:29 +0000 (UTC) Received: from localhost (ovpn-112-28.phx2.redhat.com [10.3.112.28]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA1CpSik032456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 1 Nov 2016 08:51:29 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 1 Nov 2016 08:51:05 -0400 Message-Id: <1478004671-19154-9-git-send-email-jcody@redhat.com> In-Reply-To: <1478004671-19154-1-git-send-email-jcody@redhat.com> References: <1478004671-19154-1-git-send-email-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 01 Nov 2016 12:51:29 +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 v2 08/14] blockjobs: hide internal jobs from management API 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: peter.maydell@linaro.org, jcody@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: John Snow If jobs are not created directly by the user, do not allow them to be seen by the user/management utility. At the moment, 'internal' jobs are those that do not have an ID. As of this patch it is impossible to create such jobs. Signed-off-by: John Snow Message-id: 1477584421-1399-2-git-send-email-jsnow@redhat.com Signed-off-by: Jeff Cody --- blockdev.c | 17 +++++++++++++---- blockjob.c | 41 ++++++++++++++++++++++++++++++++++------- include/block/blockjob.h | 12 ++++++++++-- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/blockdev.c b/blockdev.c index ded1326..d57cb0c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3946,13 +3946,22 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp) BlockJob *job; for (job = block_job_next(NULL); job; job = block_job_next(job)) { - BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1); - AioContext *aio_context = blk_get_aio_context(job->blk); + BlockJobInfoList *elem; + AioContext *aio_context; + if (block_job_is_internal(job)) { + continue; + } + elem = g_new0(BlockJobInfoList, 1); + aio_context = blk_get_aio_context(job->blk); aio_context_acquire(aio_context); - elem->value = block_job_query(job); + elem->value = block_job_query(job, errp); aio_context_release(aio_context); - + if (!elem->value) { + g_free(elem); + qapi_free_BlockJobInfoList(head); + return NULL; + } *p_next = elem; p_next = &elem->next; } diff --git a/blockjob.c b/blockjob.c index 422851f..84d4f75 100644 --- a/blockjob.c +++ b/blockjob.c @@ -66,7 +66,7 @@ BlockJob *block_job_get(const char *id) BlockJob *job; QLIST_FOREACH(job, &block_jobs, job_list) { - if (!strcmp(id, job->id)) { + if (job->id && !strcmp(id, job->id)) { return job; } } @@ -188,6 +188,11 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, return job; } +bool block_job_is_internal(BlockJob *job) +{ + return (job->id == NULL); +} + void block_job_ref(BlockJob *job) { ++job->refcnt; @@ -330,6 +335,8 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp) void block_job_complete(BlockJob *job, Error **errp) { + /* Should not be reachable via external interface for internal jobs */ + assert(job->id); if (job->pause_count || job->cancelled || !job->driver->complete) { error_setg(errp, "The active block job '%s' cannot be completed", job->id); @@ -510,9 +517,15 @@ void block_job_yield(BlockJob *job) block_job_pause_point(job); } -BlockJobInfo *block_job_query(BlockJob *job) +BlockJobInfo *block_job_query(BlockJob *job, Error **errp) { - BlockJobInfo *info = g_new0(BlockJobInfo, 1); + BlockJobInfo *info; + + if (block_job_is_internal(job)) { + error_setg(errp, "Cannot query QEMU internal jobs"); + return NULL; + } + info = g_new0(BlockJobInfo, 1); info->type = g_strdup(BlockJobType_lookup[job->driver->job_type]); info->device = g_strdup(job->id); info->len = job->len; @@ -535,6 +548,10 @@ static void block_job_iostatus_set_err(BlockJob *job, int error) void block_job_event_cancelled(BlockJob *job) { + if (block_job_is_internal(job)) { + return; + } + qapi_event_send_block_job_cancelled(job->driver->job_type, job->id, job->len, @@ -545,6 +562,10 @@ void block_job_event_cancelled(BlockJob *job) void block_job_event_completed(BlockJob *job, const char *msg) { + if (block_job_is_internal(job)) { + return; + } + qapi_event_send_block_job_completed(job->driver->job_type, job->id, job->len, @@ -559,6 +580,10 @@ void block_job_event_ready(BlockJob *job) { job->ready = true; + if (block_job_is_internal(job)) { + return; + } + qapi_event_send_block_job_ready(job->driver->job_type, job->id, job->len, @@ -589,10 +614,12 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, default: abort(); } - qapi_event_send_block_job_error(job->id, - is_read ? IO_OPERATION_TYPE_READ : - IO_OPERATION_TYPE_WRITE, - action, &error_abort); + if (!block_job_is_internal(job)) { + qapi_event_send_block_job_error(job->id, + is_read ? IO_OPERATION_TYPE_READ : + IO_OPERATION_TYPE_WRITE, + action, &error_abort); + } if (action == BLOCK_ERROR_ACTION_STOP) { /* make the pause user visible, which will be resumed from QMP. */ job->user_paused = true; diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 4dfb16b..a1b7502 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -114,7 +114,7 @@ struct BlockJob { BlockBackend *blk; /** - * The ID of the block job. + * The ID of the block job. May be NULL for internal jobs. */ char *id; @@ -354,7 +354,7 @@ bool block_job_is_cancelled(BlockJob *job); * * Return information about a job. */ -BlockJobInfo *block_job_query(BlockJob *job); +BlockJobInfo *block_job_query(BlockJob *job, Error **errp); /** * block_job_pause_point: @@ -525,4 +525,12 @@ void block_job_txn_unref(BlockJobTxn *txn); */ void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job); +/** + * block_job_is_internal: + * @job: The job to determine if it is user-visible or not. + * + * Returns true if the job should not be visible to the management layer. + */ +bool block_job_is_internal(BlockJob *job); + #endif