From patchwork Mon Oct 31 19:22:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9406317 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 5C24460585 for ; Mon, 31 Oct 2016 19:31:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F21728DB5 for ; Mon, 31 Oct 2016 19:31:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4258A28E1B; Mon, 31 Oct 2016 19:31: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 B6C7128DB5 for ; Mon, 31 Oct 2016 19:31:27 +0000 (UTC) Received: from localhost ([::1]:38171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1IIp-0004XN-11 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Oct 2016 15:31:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1IB6-0005g3-7y for qemu-devel@nongnu.org; Mon, 31 Oct 2016 15:23:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1IB4-0005OZ-W0 for qemu-devel@nongnu.org; Mon, 31 Oct 2016 15:23:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1IAz-0005KT-3E; Mon, 31 Oct 2016 15:23:21 -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 6771C85541; Mon, 31 Oct 2016 19:23:20 +0000 (UTC) Received: from localhost (ovpn-112-28.phx2.redhat.com [10.3.112.28]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9VJNI5T021411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 31 Oct 2016 15:23:19 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Mon, 31 Oct 2016 15:22:56 -0400 Message-Id: <1477941781-4108-10-git-send-email-jcody@redhat.com> In-Reply-To: <1477941781-4108-1-git-send-email-jcody@redhat.com> References: <1477941781-4108-1-git-send-email-jcody@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.28]); Mon, 31 Oct 2016 19:23:20 +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 09/14] blockjobs: Allow creating internal jobs 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 Add the ability to create jobs without an ID. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Jeff Cody Message-id: 1477584421-1399-3-git-send-email-jsnow@redhat.com Signed-off-by: Jeff Cody --- block/backup.c | 2 +- block/commit.c | 2 +- block/mirror.c | 3 ++- block/stream.c | 2 +- blockjob.c | 25 ++++++++++++++++--------- include/block/blockjob.h | 7 ++++++- tests/test-blockjob-txn.c | 3 ++- tests/test-blockjob.c | 2 +- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/block/backup.c b/block/backup.c index 81d4042..4bec27e 100644 --- a/block/backup.c +++ b/block/backup.c @@ -615,7 +615,7 @@ void backup_start(const char *job_id, BlockDriverState *bs, } job = block_job_create(job_id, &backup_job_driver, bs, speed, - cb, opaque, errp); + BLOCK_JOB_DEFAULT, cb, opaque, errp); if (!job) { goto error; } diff --git a/block/commit.c b/block/commit.c index 499ecca..1a25f8b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -233,7 +233,7 @@ void commit_start(const char *job_id, BlockDriverState *bs, } s = block_job_create(job_id, &commit_job_driver, bs, speed, - cb, opaque, errp); + BLOCK_JOB_DEFAULT, cb, opaque, errp); if (!s) { return; } diff --git a/block/mirror.c b/block/mirror.c index 80be93e..62721db 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -968,7 +968,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs, buf_size = DEFAULT_MIRROR_BUF_SIZE; } - s = block_job_create(job_id, driver, bs, speed, cb, opaque, errp); + s = block_job_create(job_id, driver, bs, speed, + BLOCK_JOB_DEFAULT, cb, opaque, errp); if (!s) { return; } diff --git a/block/stream.c b/block/stream.c index 3187481..eeb6f52 100644 --- a/block/stream.c +++ b/block/stream.c @@ -222,7 +222,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, StreamBlockJob *s; s = block_job_create(job_id, &stream_job_driver, bs, speed, - cb, opaque, errp); + BLOCK_JOB_DEFAULT, cb, opaque, errp); if (!s) { return; } diff --git a/blockjob.c b/blockjob.c index 38f69a0..15a1474 100644 --- a/blockjob.c +++ b/blockjob.c @@ -114,7 +114,7 @@ static void block_job_detach_aio_context(void *opaque) } void *block_job_create(const char *job_id, const BlockJobDriver *driver, - BlockDriverState *bs, int64_t speed, + BlockDriverState *bs, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp) { BlockBackend *blk; @@ -126,7 +126,7 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, return NULL; } - if (job_id == NULL) { + if (job_id == NULL && !(flags & BLOCK_JOB_INTERNAL)) { job_id = bdrv_get_device_name(bs); if (!*job_id) { error_setg(errp, "An explicit job ID is required for this node"); @@ -134,14 +134,21 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, } } - if (!id_wellformed(job_id)) { - error_setg(errp, "Invalid job ID '%s'", job_id); - return NULL; - } + if (job_id) { + if (flags & BLOCK_JOB_INTERNAL) { + error_setg(errp, "Cannot specify job ID for internal block job"); + return NULL; + } - if (block_job_get(job_id)) { - error_setg(errp, "Job ID '%s' already in use", job_id); - return NULL; + if (!id_wellformed(job_id)) { + error_setg(errp, "Invalid job ID '%s'", job_id); + return NULL; + } + + if (block_job_get(job_id)) { + error_setg(errp, "Job ID '%s' already in use", job_id); + return NULL; + } } blk = blk_new(); diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 2f60aff..69d3f24 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -207,6 +207,11 @@ struct BlockJob { QLIST_ENTRY(BlockJob) txn_list; }; +typedef enum BlockJobCreateFlags { + BLOCK_JOB_DEFAULT = 0x00, + BLOCK_JOB_INTERNAL = 0x01, +} BlockJobCreateFlags; + /** * block_job_next: * @job: A block job, or %NULL. @@ -249,7 +254,7 @@ BlockJob *block_job_get(const char *id); * called from a wrapper that is specific to the job type. */ void *block_job_create(const char *job_id, const BlockJobDriver *driver, - BlockDriverState *bs, int64_t speed, + BlockDriverState *bs, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp); /** diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index d049cba..b79e0c6 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -98,7 +98,8 @@ static BlockJob *test_block_job_start(unsigned int iterations, bs = bdrv_new(); snprintf(job_id, sizeof(job_id), "job%u", counter++); s = block_job_create(job_id, &test_block_job_driver, bs, 0, - test_block_job_cb, data, &error_abort); + BLOCK_JOB_DEFAULT, test_block_job_cb, + data, &error_abort); s->iterations = iterations; s->use_timer = use_timer; s->rc = rc; diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 5b0e934..18bf850 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -31,7 +31,7 @@ static BlockJob *do_test_id(BlockBackend *blk, const char *id, Error *errp = NULL; job = block_job_create(id, &test_block_job_driver, blk_bs(blk), 0, - block_job_cb, NULL, &errp); + BLOCK_JOB_DEFAULT, block_job_cb, NULL, &errp); if (should_succeed) { g_assert_null(errp); g_assert_nonnull(job);