From: Jeff Cody <jcody@redhat.com>
To: qemu-block@nongnu.org
Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL v2 09/14] blockjobs: Allow creating internal jobs
Date: Tue, 1 Nov 2016 08:51:06 -0400 [thread overview]
Message-ID: <1478004671-19154-10-git-send-email-jcody@redhat.com> (raw)
In-Reply-To: <1478004671-19154-1-git-send-email-jcody@redhat.com>
From: John Snow <jsnow@redhat.com>
Add the ability to create jobs without an ID.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Message-id: 1477584421-1399-3-git-send-email-jsnow@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
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 44c7ff3..3877d93 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -612,7 +612,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 a5e17f6..0740a41 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -234,7 +234,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 82a9529..e9fba9b 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -967,7 +967,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 b8ab89a..09ce9ef 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -230,7 +230,7 @@ void stream_start(const char *job_id, BlockDriverState *bs,
int orig_bs_flags;
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 84d4f75..c286fc3 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -121,7 +121,7 @@ void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs)
}
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;
@@ -133,7 +133,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");
@@ -141,14 +141,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 a1b7502..d0d9333 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -210,6 +210,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.
@@ -252,7 +257,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);
--
2.7.4
next prev parent reply other threads:[~2016-11-01 12:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-01 12:50 [Qemu-devel] [PULL v2 00/14] Block patches for 2.8 Jeff Cody
2016-11-01 12:50 ` [Qemu-devel] [PULL v2 01/14] qapi: add release designator to gluster logfile option Jeff Cody
2016-11-01 12:50 ` [Qemu-devel] [PULL v2 02/14] rbd: make the code more readable Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 03/14] block: add gluster ifdef guard checks for SEEK_DATA/SEEK_HOLE support Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 04/14] block/gluster: memory usage: use one glfs instance per volume Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 05/14] block: Turn on "unmap" in active commit Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 06/14] block/gluster: improve defense over string to int conversion Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 07/14] block/gluster: fix port type in the QAPI options list Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 08/14] blockjobs: hide internal jobs from management API Jeff Cody
2016-11-01 12:51 ` Jeff Cody [this message]
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 10/14] Replication/Blockjobs: Create replication jobs as internal Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 11/14] blockjob: centralize QMP event emissions Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 12/14] Blockjobs: Internalize user_pause logic Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 13/14] blockjobs: split interface into public/private, Part 1 Jeff Cody
2016-11-01 12:51 ` [Qemu-devel] [PULL v2 14/14] blockjobs: fix documentation Jeff Cody
2016-11-01 13:12 ` [Qemu-devel] [PULL v2 00/14] Block patches for 2.8 no-reply
2016-11-01 15:15 ` Peter Maydell
2016-11-02 17:03 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-11-02 18:11 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478004671-19154-10-git-send-email-jcody@redhat.com \
--to=jcody@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).