Skip to content

Commit 61a3a5a

Browse files
foxmoxkevmw
authored andcommitted
blockjob: introduce block-job-change QMP command
which will allow changing job-type-specific options after job creation. In the JobVerbTable, the same allow bits as for set-speed are used, because set-speed can be considered an existing change command. Signed-off-by: Fiona Ebner <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Message-ID: <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Reviewed-by: Eric Blake <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 073458d commit 61a3a5a

File tree

7 files changed

+82
-1
lines changed

7 files changed

+82
-1
lines changed

blockdev.c

+14
Original file line numberDiff line numberDiff line change
@@ -3392,6 +3392,20 @@ void qmp_block_job_dismiss(const char *id, Error **errp)
33923392
job_dismiss_locked(&job, errp);
33933393
}
33943394

3395+
void qmp_block_job_change(BlockJobChangeOptions *opts, Error **errp)
3396+
{
3397+
BlockJob *job;
3398+
3399+
JOB_LOCK_GUARD();
3400+
job = find_block_job_locked(opts->id, errp);
3401+
3402+
if (!job) {
3403+
return;
3404+
}
3405+
3406+
block_job_change_locked(job, opts, errp);
3407+
}
3408+
33953409
void qmp_change_backing_file(const char *device,
33963410
const char *image_node_name,
33973411
const char *backing_file,

blockjob.c

+20
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ static bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
330330
return block_job_set_speed_locked(job, speed, errp);
331331
}
332332

333+
void block_job_change_locked(BlockJob *job, BlockJobChangeOptions *opts,
334+
Error **errp)
335+
{
336+
const BlockJobDriver *drv = block_job_driver(job);
337+
338+
GLOBAL_STATE_CODE();
339+
340+
if (job_apply_verb_locked(&job->job, JOB_VERB_CHANGE, errp)) {
341+
return;
342+
}
343+
344+
if (drv->change) {
345+
job_unlock();
346+
drv->change(job, opts, errp);
347+
job_lock();
348+
} else {
349+
error_setg(errp, "Job type does not support change");
350+
}
351+
}
352+
333353
void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n)
334354
{
335355
IO_CODE();

include/block/blockjob.h

+11
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs);
172172
*/
173173
bool block_job_set_speed_locked(BlockJob *job, int64_t speed, Error **errp);
174174

175+
/**
176+
* block_job_change_locked:
177+
* @job: The job to change.
178+
* @opts: The new options.
179+
* @errp: Error object.
180+
*
181+
* Change the job according to opts.
182+
*/
183+
void block_job_change_locked(BlockJob *job, BlockJobChangeOptions *opts,
184+
Error **errp);
185+
175186
/**
176187
* block_job_query_locked:
177188
* @job: The job to get information about.

include/block/blockjob_int.h

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ struct BlockJobDriver {
6767
void (*attached_aio_context)(BlockJob *job, AioContext *new_context);
6868

6969
void (*set_speed)(BlockJob *job, int64_t speed);
70+
71+
/*
72+
* Change the @job's options according to @opts.
73+
*
74+
* Note that this can already be called before the job coroutine is running.
75+
*/
76+
void (*change)(BlockJob *job, BlockJobChangeOptions *opts, Error **errp);
7077
};
7178

7279
/*

job.c

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ bool JobVerbTable[JOB_VERB__MAX][JOB_STATUS__MAX] = {
8080
[JOB_VERB_COMPLETE] = {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
8181
[JOB_VERB_FINALIZE] = {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
8282
[JOB_VERB_DISMISS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
83+
[JOB_VERB_CHANGE] = {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
8384
};
8485

8586
/* Transactional group of jobs */

qapi/block-core.json

+26
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,32 @@
30443044
{ 'command': 'block-job-finalize', 'data': { 'id': 'str' },
30453045
'allow-preconfig': true }
30463046

3047+
##
3048+
# @BlockJobChangeOptions:
3049+
#
3050+
# Block job options that can be changed after job creation.
3051+
#
3052+
# @id: The job identifier
3053+
#
3054+
# @type: The job type
3055+
#
3056+
# Since 8.2
3057+
##
3058+
{ 'union': 'BlockJobChangeOptions',
3059+
'base': { 'id': 'str', 'type': 'JobType' },
3060+
'discriminator': 'type',
3061+
'data': {} }
3062+
3063+
##
3064+
# @block-job-change:
3065+
#
3066+
# Change the block job's options.
3067+
#
3068+
# Since: 8.2
3069+
##
3070+
{ 'command': 'block-job-change',
3071+
'data': 'BlockJobChangeOptions', 'boxed': true }
3072+
30473073
##
30483074
# @BlockdevDiscardOptions:
30493075
#

qapi/job.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@
105105
#
106106
# @finalize: see @job-finalize
107107
#
108+
# @change: see @block-job-change (since 8.2)
109+
#
108110
# Since: 2.12
109111
##
110112
{ 'enum': 'JobVerb',
111113
'data': ['cancel', 'pause', 'resume', 'set-speed', 'complete', 'dismiss',
112-
'finalize' ] }
114+
'finalize', 'change' ] }
113115

114116
##
115117
# @JOB_STATUS_CHANGE:

0 commit comments

Comments
 (0)