mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
qemu: Add handler for job state change event
Add support for handling the event either synchronously or asynchronously using the event thread. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b2d6ae674e
commit
cbf4e3af70
@ -14520,6 +14520,9 @@ qemuProcessEventFree(struct qemuProcessEvent *event)
|
|||||||
case QEMU_PROCESS_EVENT_MONITOR_EOF:
|
case QEMU_PROCESS_EVENT_MONITOR_EOF:
|
||||||
VIR_FREE(event->data);
|
VIR_FREE(event->data);
|
||||||
break;
|
break;
|
||||||
|
case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE:
|
||||||
|
virObjectUnref(event->data);
|
||||||
|
break;
|
||||||
case QEMU_PROCESS_EVENT_PR_DISCONNECT:
|
case QEMU_PROCESS_EVENT_PR_DISCONNECT:
|
||||||
case QEMU_PROCESS_EVENT_LAST:
|
case QEMU_PROCESS_EVENT_LAST:
|
||||||
break;
|
break;
|
||||||
|
@ -514,6 +514,7 @@ typedef enum {
|
|||||||
QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
|
QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
|
||||||
QEMU_PROCESS_EVENT_SERIAL_CHANGED,
|
QEMU_PROCESS_EVENT_SERIAL_CHANGED,
|
||||||
QEMU_PROCESS_EVENT_BLOCK_JOB,
|
QEMU_PROCESS_EVENT_BLOCK_JOB,
|
||||||
|
QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE,
|
||||||
QEMU_PROCESS_EVENT_MONITOR_EOF,
|
QEMU_PROCESS_EVENT_MONITOR_EOF,
|
||||||
QEMU_PROCESS_EVENT_PR_DISCONNECT,
|
QEMU_PROCESS_EVENT_PR_DISCONNECT,
|
||||||
QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED,
|
QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED,
|
||||||
|
@ -4717,6 +4717,26 @@ processBlockJobEvent(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
processJobStatusChangeEvent(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
qemuBlockJobDataPtr job)
|
||||||
|
{
|
||||||
|
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!virDomainObjIsActive(vm)) {
|
||||||
|
VIR_DEBUG("Domain is not running");
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
|
|
||||||
|
qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
|
||||||
|
|
||||||
|
endjob:
|
||||||
|
qemuDomainObjEndJob(driver, vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
processMonitorEOFEvent(virQEMUDriverPtr driver,
|
processMonitorEOFEvent(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
@ -4855,6 +4875,9 @@ static void qemuProcessEventHandler(void *data, void *opaque)
|
|||||||
processEvent->action,
|
processEvent->action,
|
||||||
processEvent->status);
|
processEvent->status);
|
||||||
break;
|
break;
|
||||||
|
case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE:
|
||||||
|
processJobStatusChangeEvent(driver, vm, processEvent->data);
|
||||||
|
break;
|
||||||
case QEMU_PROCESS_EVENT_MONITOR_EOF:
|
case QEMU_PROCESS_EVENT_MONITOR_EOF:
|
||||||
processMonitorEOFEvent(driver, vm);
|
processMonitorEOFEvent(driver, vm);
|
||||||
break;
|
break;
|
||||||
|
@ -990,6 +990,68 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuProcessHandleJobStatusChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
const char *jobname,
|
||||||
|
int status,
|
||||||
|
void *opaque)
|
||||||
|
{
|
||||||
|
virQEMUDriverPtr driver = opaque;
|
||||||
|
qemuDomainObjPrivatePtr priv;
|
||||||
|
struct qemuProcessEvent *processEvent = NULL;
|
||||||
|
qemuBlockJobDataPtr job = NULL;
|
||||||
|
int jobnewstate;
|
||||||
|
|
||||||
|
virObjectLock(vm);
|
||||||
|
priv = vm->privateData;
|
||||||
|
|
||||||
|
VIR_DEBUG("job '%s'(domain: %p,%s) state changed to '%s'(%d)",
|
||||||
|
jobname, vm, vm->def->name,
|
||||||
|
qemuMonitorJobStatusTypeToString(status), status);
|
||||||
|
|
||||||
|
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
|
||||||
|
VIR_DEBUG("job '%s' handled by old blockjob handler", jobname);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((jobnewstate = qemuBlockjobConvertMonitorStatus(status)) == QEMU_BLOCKJOB_STATE_LAST)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(job = virHashLookup(priv->blockjobs, jobname))) {
|
||||||
|
VIR_DEBUG("job '%s' not registered", jobname);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
job->newstate = jobnewstate;
|
||||||
|
|
||||||
|
if (job->synchronous) {
|
||||||
|
VIR_DEBUG("job '%s' handled synchronously", jobname);
|
||||||
|
virDomainObjBroadcast(vm);
|
||||||
|
} else {
|
||||||
|
VIR_DEBUG("job '%s' handled by event thread", jobname);
|
||||||
|
if (VIR_ALLOC(processEvent) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
processEvent->eventType = QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE;
|
||||||
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
processEvent->data = virObjectRef(job);
|
||||||
|
|
||||||
|
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
||||||
|
ignore_value(virObjectUnref(vm));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
processEvent = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
qemuProcessEventFree(processEvent);
|
||||||
|
virObjectUnlock(vm);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -1820,6 +1882,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
|
|||||||
.domainIOError = qemuProcessHandleIOError,
|
.domainIOError = qemuProcessHandleIOError,
|
||||||
.domainGraphics = qemuProcessHandleGraphics,
|
.domainGraphics = qemuProcessHandleGraphics,
|
||||||
.domainBlockJob = qemuProcessHandleBlockJob,
|
.domainBlockJob = qemuProcessHandleBlockJob,
|
||||||
|
.jobStatusChange = qemuProcessHandleJobStatusChange,
|
||||||
.domainTrayChange = qemuProcessHandleTrayChange,
|
.domainTrayChange = qemuProcessHandleTrayChange,
|
||||||
.domainPMWakeup = qemuProcessHandlePMWakeup,
|
.domainPMWakeup = qemuProcessHandlePMWakeup,
|
||||||
.domainPMSuspend = qemuProcessHandlePMSuspend,
|
.domainPMSuspend = qemuProcessHandlePMSuspend,
|
||||||
|
Loading…
Reference in New Issue
Block a user