From 587c0ed12ad249533a55bccd467295187254d7bf Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 4 Dec 2018 17:57:23 +0100 Subject: [PATCH] qemu: monitor: Implement support for 'JOB_STATUS_CHANGE' event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This new event is a superset of the BLOCK_JOB* events and also covers jobs which don't bind to a VM disk. In this patch the monitor part is implemented. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_monitor.c | 13 +++++++++++++ src/qemu/qemu_monitor.h | 9 +++++++++ src/qemu/qemu_monitor_json.c | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 70e864fa67..433fe7e60e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1503,6 +1503,19 @@ qemuMonitorEmitBlockJob(qemuMonitorPtr mon, } +int +qemuMonitorEmitJobStatusChange(qemuMonitorPtr mon, + const char *jobname, + qemuMonitorJobStatus status) +{ + int ret = -1; + VIR_DEBUG("mon=%p", mon); + + QEMU_MONITOR_CALLBACK(mon, ret, jobStatusChange, mon->vm, jobname, status); + return ret; +} + + int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon, unsigned long long actual) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 3e9bb4a289..fa8f8a6e47 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -230,6 +230,11 @@ typedef int (*qemuMonitorDomainBlockJobCallback)(qemuMonitorPtr mon, int status, const char *error, void *opaque); +typedef int (*qemuMonitorDomainJobStatusChangeCallback)(qemuMonitorPtr mon, + virDomainObjPtr vm, + const char *jobname, + int status, + void *opaque); typedef int (*qemuMonitorDomainTrayChangeCallback)(qemuMonitorPtr mon, virDomainObjPtr vm, const char *devAlias, @@ -357,6 +362,7 @@ struct _qemuMonitorCallbacks { qemuMonitorDomainIOErrorCallback domainIOError; qemuMonitorDomainGraphicsCallback domainGraphics; qemuMonitorDomainBlockJobCallback domainBlockJob; + qemuMonitorDomainJobStatusChangeCallback jobStatusChange; qemuMonitorDomainTrayChangeCallback domainTrayChange; qemuMonitorDomainPMWakeupCallback domainPMWakeup; qemuMonitorDomainPMSuspendCallback domainPMSuspend; @@ -467,6 +473,9 @@ int qemuMonitorEmitBlockJob(qemuMonitorPtr mon, int type, int status, const char *error); +int qemuMonitorEmitJobStatusChange(qemuMonitorPtr mon, + const char *jobname, + qemuMonitorJobStatus status); int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon, unsigned long long actual); int qemuMonitorEmitPMSuspendDisk(qemuMonitorPtr mon); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a1cb553109..73eb0f77cb 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -100,6 +100,7 @@ static void qemuMonitorJSONHandlePMSuspend(qemuMonitorPtr mon, virJSONValuePtr d static void qemuMonitorJSONHandleBlockJobCompleted(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleBlockJobCanceled(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleBlockJobReady(qemuMonitorPtr mon, virJSONValuePtr data); +static void qemuMonitorJSONHandleJobStatusChange(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleBalloonChange(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandlePMSuspendDisk(qemuMonitorPtr mon, virJSONValuePtr data); static void qemuMonitorJSONHandleGuestPanic(qemuMonitorPtr mon, virJSONValuePtr data); @@ -132,6 +133,7 @@ static qemuEventHandler eventHandlers[] = { { "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange, }, { "DUMP_COMPLETED", qemuMonitorJSONHandleDumpCompleted, }, { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, }, + { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, }, { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, }, { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, }, { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, }, @@ -1172,6 +1174,30 @@ qemuMonitorJSONHandleBlockJobImpl(qemuMonitorPtr mon, qemuMonitorEmitBlockJob(mon, device, type, event, error); } + +static void +qemuMonitorJSONHandleJobStatusChange(qemuMonitorPtr mon, + virJSONValuePtr data) +{ + const char *jobname = virJSONValueObjectGetString(data, "id"); + const char *statusstr = virJSONValueObjectGetString(data, "status"); + int status; + + if (!jobname) { + VIR_WARN("missing job name in JOB_STATUS_CHANGE event"); + return; + } + + if ((status = qemuMonitorJobStatusTypeFromString(statusstr)) < 0) { + VIR_WARN("unknown job status '%s' for job '%s' in JOB_STATUS_CHANGE event", + statusstr, jobname); + return; + } + + qemuMonitorEmitJobStatusChange(mon, jobname, status); +} + + static void qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon, virJSONValuePtr data)