Skip to content

Commit f81e0b4

Browse files
jnsnowcodyprime
authored andcommitted
blockjobs: Allow creating internal jobs
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>
1 parent 559b935 commit f81e0b4

File tree

8 files changed

+30
-16
lines changed

8 files changed

+30
-16
lines changed

block/backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ void backup_start(const char *job_id, BlockDriverState *bs,
612612
}
613613

614614
job = block_job_create(job_id, &backup_job_driver, bs, speed,
615-
cb, opaque, errp);
615+
BLOCK_JOB_DEFAULT, cb, opaque, errp);
616616
if (!job) {
617617
goto error;
618618
}

block/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void commit_start(const char *job_id, BlockDriverState *bs,
234234
}
235235

236236
s = block_job_create(job_id, &commit_job_driver, bs, speed,
237-
cb, opaque, errp);
237+
BLOCK_JOB_DEFAULT, cb, opaque, errp);
238238
if (!s) {
239239
return;
240240
}

block/mirror.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
967967
buf_size = DEFAULT_MIRROR_BUF_SIZE;
968968
}
969969

970-
s = block_job_create(job_id, driver, bs, speed, cb, opaque, errp);
970+
s = block_job_create(job_id, driver, bs, speed,
971+
BLOCK_JOB_DEFAULT, cb, opaque, errp);
971972
if (!s) {
972973
return;
973974
}

block/stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void stream_start(const char *job_id, BlockDriverState *bs,
230230
int orig_bs_flags;
231231

232232
s = block_job_create(job_id, &stream_job_driver, bs, speed,
233-
cb, opaque, errp);
233+
BLOCK_JOB_DEFAULT, cb, opaque, errp);
234234
if (!s) {
235235
return;
236236
}

blockjob.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void block_job_add_bdrv(BlockJob *job, BlockDriverState *bs)
121121
}
122122

123123
void *block_job_create(const char *job_id, const BlockJobDriver *driver,
124-
BlockDriverState *bs, int64_t speed,
124+
BlockDriverState *bs, int64_t speed, int flags,
125125
BlockCompletionFunc *cb, void *opaque, Error **errp)
126126
{
127127
BlockBackend *blk;
@@ -133,22 +133,29 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
133133
return NULL;
134134
}
135135

136-
if (job_id == NULL) {
136+
if (job_id == NULL && !(flags & BLOCK_JOB_INTERNAL)) {
137137
job_id = bdrv_get_device_name(bs);
138138
if (!*job_id) {
139139
error_setg(errp, "An explicit job ID is required for this node");
140140
return NULL;
141141
}
142142
}
143143

144-
if (!id_wellformed(job_id)) {
145-
error_setg(errp, "Invalid job ID '%s'", job_id);
146-
return NULL;
147-
}
144+
if (job_id) {
145+
if (flags & BLOCK_JOB_INTERNAL) {
146+
error_setg(errp, "Cannot specify job ID for internal block job");
147+
return NULL;
148+
}
148149

149-
if (block_job_get(job_id)) {
150-
error_setg(errp, "Job ID '%s' already in use", job_id);
151-
return NULL;
150+
if (!id_wellformed(job_id)) {
151+
error_setg(errp, "Invalid job ID '%s'", job_id);
152+
return NULL;
153+
}
154+
155+
if (block_job_get(job_id)) {
156+
error_setg(errp, "Job ID '%s' already in use", job_id);
157+
return NULL;
158+
}
152159
}
153160

154161
blk = blk_new();

include/block/blockjob.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ struct BlockJob {
210210
QLIST_ENTRY(BlockJob) txn_list;
211211
};
212212

213+
typedef enum BlockJobCreateFlags {
214+
BLOCK_JOB_DEFAULT = 0x00,
215+
BLOCK_JOB_INTERNAL = 0x01,
216+
} BlockJobCreateFlags;
217+
213218
/**
214219
* block_job_next:
215220
* @job: A block job, or %NULL.
@@ -252,7 +257,7 @@ BlockJob *block_job_get(const char *id);
252257
* called from a wrapper that is specific to the job type.
253258
*/
254259
void *block_job_create(const char *job_id, const BlockJobDriver *driver,
255-
BlockDriverState *bs, int64_t speed,
260+
BlockDriverState *bs, int64_t speed, int flags,
256261
BlockCompletionFunc *cb, void *opaque, Error **errp);
257262

258263
/**

tests/test-blockjob-txn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ static BlockJob *test_block_job_start(unsigned int iterations,
9898
bs = bdrv_new();
9999
snprintf(job_id, sizeof(job_id), "job%u", counter++);
100100
s = block_job_create(job_id, &test_block_job_driver, bs, 0,
101-
test_block_job_cb, data, &error_abort);
101+
BLOCK_JOB_DEFAULT, test_block_job_cb,
102+
data, &error_abort);
102103
s->iterations = iterations;
103104
s->use_timer = use_timer;
104105
s->rc = rc;

tests/test-blockjob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static BlockJob *do_test_id(BlockBackend *blk, const char *id,
3131
Error *errp = NULL;
3232

3333
job = block_job_create(id, &test_block_job_driver, blk_bs(blk), 0,
34-
block_job_cb, NULL, &errp);
34+
BLOCK_JOB_DEFAULT, block_job_cb, NULL, &errp);
3535
if (should_succeed) {
3636
g_assert_null(errp);
3737
g_assert_nonnull(job);

0 commit comments

Comments
 (0)