qmp: add query-block-jobs
Add query-block-jobs, which shows the progress of ongoing block device operations. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Acked-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
370521a1d6
commit
fb5458cd10
33
blockdev.c
33
blockdev.c
@ -1006,3 +1006,36 @@ void qmp_block_job_cancel(const char *device, Error **errp)
|
|||||||
trace_qmp_block_job_cancel(job);
|
trace_qmp_block_job_cancel(job);
|
||||||
block_job_cancel(job);
|
block_job_cancel(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
BlockJobInfoList **prev = opaque;
|
||||||
|
BlockJob *job = bs->job;
|
||||||
|
|
||||||
|
if (job) {
|
||||||
|
BlockJobInfoList *elem;
|
||||||
|
BlockJobInfo *info = g_new(BlockJobInfo, 1);
|
||||||
|
*info = (BlockJobInfo){
|
||||||
|
.type = g_strdup(job->job_type->job_type),
|
||||||
|
.device = g_strdup(bdrv_get_device_name(bs)),
|
||||||
|
.len = job->len,
|
||||||
|
.offset = job->offset,
|
||||||
|
.speed = job->speed,
|
||||||
|
};
|
||||||
|
|
||||||
|
elem = g_new0(BlockJobInfoList, 1);
|
||||||
|
elem->value = info;
|
||||||
|
|
||||||
|
(*prev)->next = elem;
|
||||||
|
*prev = elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockJobInfoList *qmp_query_block_jobs(Error **errp)
|
||||||
|
{
|
||||||
|
/* Dummy is a fake list element for holding the head pointer */
|
||||||
|
BlockJobInfoList dummy = {};
|
||||||
|
BlockJobInfoList *prev = &dummy;
|
||||||
|
bdrv_iterate(do_qmp_query_block_jobs_one, &prev);
|
||||||
|
return dummy.next;
|
||||||
|
}
|
||||||
|
36
hmp.c
36
hmp.c
@ -509,6 +509,42 @@ void hmp_info_pci(Monitor *mon)
|
|||||||
qapi_free_PciInfoList(info_list);
|
qapi_free_PciInfoList(info_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hmp_info_block_jobs(Monitor *mon)
|
||||||
|
{
|
||||||
|
BlockJobInfoList *list;
|
||||||
|
Error *err = NULL;
|
||||||
|
|
||||||
|
list = qmp_query_block_jobs(&err);
|
||||||
|
assert(!err);
|
||||||
|
|
||||||
|
if (!list) {
|
||||||
|
monitor_printf(mon, "No active jobs\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (list) {
|
||||||
|
if (strcmp(list->value->type, "stream") == 0) {
|
||||||
|
monitor_printf(mon, "Streaming device %s: Completed %" PRId64
|
||||||
|
" of %" PRId64 " bytes, speed limit %" PRId64
|
||||||
|
" bytes/s\n",
|
||||||
|
list->value->device,
|
||||||
|
list->value->offset,
|
||||||
|
list->value->len,
|
||||||
|
list->value->speed);
|
||||||
|
} else {
|
||||||
|
monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
|
||||||
|
" of %" PRId64 " bytes, speed limit %" PRId64
|
||||||
|
" bytes/s\n",
|
||||||
|
list->value->type,
|
||||||
|
list->value->device,
|
||||||
|
list->value->offset,
|
||||||
|
list->value->len,
|
||||||
|
list->value->speed);
|
||||||
|
}
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void hmp_quit(Monitor *mon, const QDict *qdict)
|
void hmp_quit(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
monitor_suspend(mon);
|
monitor_suspend(mon);
|
||||||
|
1
hmp.h
1
hmp.h
@ -32,6 +32,7 @@ void hmp_info_vnc(Monitor *mon);
|
|||||||
void hmp_info_spice(Monitor *mon);
|
void hmp_info_spice(Monitor *mon);
|
||||||
void hmp_info_balloon(Monitor *mon);
|
void hmp_info_balloon(Monitor *mon);
|
||||||
void hmp_info_pci(Monitor *mon);
|
void hmp_info_pci(Monitor *mon);
|
||||||
|
void hmp_info_block_jobs(Monitor *mon);
|
||||||
void hmp_quit(Monitor *mon, const QDict *qdict);
|
void hmp_quit(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_stop(Monitor *mon, const QDict *qdict);
|
void hmp_stop(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_system_reset(Monitor *mon, const QDict *qdict);
|
void hmp_system_reset(Monitor *mon, const QDict *qdict);
|
||||||
|
@ -2317,6 +2317,13 @@ static mon_cmd_t info_cmds[] = {
|
|||||||
.help = "show block device statistics",
|
.help = "show block device statistics",
|
||||||
.mhandler.info = hmp_info_blockstats,
|
.mhandler.info = hmp_info_blockstats,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "block-jobs",
|
||||||
|
.args_type = "",
|
||||||
|
.params = "",
|
||||||
|
.help = "show progress of ongoing block device operations",
|
||||||
|
.mhandler.info = hmp_info_block_jobs,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "registers",
|
.name = "registers",
|
||||||
.args_type = "",
|
.args_type = "",
|
||||||
|
@ -844,6 +844,38 @@
|
|||||||
##
|
##
|
||||||
{ 'command': 'query-pci', 'returns': ['PciInfo'] }
|
{ 'command': 'query-pci', 'returns': ['PciInfo'] }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @BlockJobInfo:
|
||||||
|
#
|
||||||
|
# Information about a long-running block device operation.
|
||||||
|
#
|
||||||
|
# @type: the job type ('stream' for image streaming)
|
||||||
|
#
|
||||||
|
# @device: the block device name
|
||||||
|
#
|
||||||
|
# @len: the maximum progress value
|
||||||
|
#
|
||||||
|
# @offset: the current progress value
|
||||||
|
#
|
||||||
|
# @speed: the rate limit, bytes per second
|
||||||
|
#
|
||||||
|
# Since: 1.1
|
||||||
|
##
|
||||||
|
{ 'type': 'BlockJobInfo',
|
||||||
|
'data': {'type': 'str', 'device': 'str', 'len': 'int',
|
||||||
|
'offset': 'int', 'speed': 'int'} }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @query-block-jobs:
|
||||||
|
#
|
||||||
|
# Return information about long-running block device operations.
|
||||||
|
#
|
||||||
|
# Returns: a list of @BlockJobInfo for each active block job
|
||||||
|
#
|
||||||
|
# Since: 1.1
|
||||||
|
##
|
||||||
|
{ 'command': 'query-block-jobs', 'returns': ['BlockJobInfo'] }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @quit:
|
# @quit:
|
||||||
#
|
#
|
||||||
|
@ -2013,6 +2013,12 @@ EQMP
|
|||||||
.mhandler.cmd_new = qmp_marshal_input_query_balloon,
|
.mhandler.cmd_new = qmp_marshal_input_query_balloon,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
.name = "query-block-jobs",
|
||||||
|
.args_type = "",
|
||||||
|
.mhandler.cmd_new = qmp_marshal_input_query_block_jobs,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
.name = "qom-list",
|
.name = "qom-list",
|
||||||
.args_type = "path:s",
|
.args_type = "path:s",
|
||||||
|
Loading…
Reference in New Issue
Block a user