mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 09:14:57 +00:00
qemu: process: Extract code for submitting event handling to separate thread
The submission of the event to the helper thread has a verbose cleanup path which was duplicated in all the event handlers. Simplify it by extracting the code into a helper named 'qemuProcessEventSubmit' and reuse it where appropriate. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
59ba742cbc
commit
e286a62941
@ -280,6 +280,33 @@ qemuConnectAgent(virQEMUDriver *driver, virDomainObj *vm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuProcessEventSubmit:
|
||||||
|
* @driver: QEMU driver object
|
||||||
|
* @event: pointer to the variable holding the event processing data (stolen and cleared)
|
||||||
|
*
|
||||||
|
* Submits @event to be processed by the asynchronous event handling thread.
|
||||||
|
* In case when submission of the handling fails @event is properly freed and
|
||||||
|
* cleared. If (*event)->vm is non-NULL the domain object is uref'd before freeing
|
||||||
|
* @event.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
qemuProcessEventSubmit(virQEMUDriver *driver,
|
||||||
|
struct qemuProcessEvent **event)
|
||||||
|
{
|
||||||
|
if (!*event)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (virThreadPoolSendJob(driver->workerPool, 0, *event) < 0) {
|
||||||
|
if ((*event)->vm)
|
||||||
|
virObjectUnref((*event)->vm);
|
||||||
|
qemuProcessEventFree(*event);
|
||||||
|
}
|
||||||
|
|
||||||
|
*event = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a callback registered with a qemuMonitor *instance,
|
* This is a callback registered with a qemuMonitor *instance,
|
||||||
* and to be invoked when the monitor console hits an end of file
|
* and to be invoked when the monitor console hits an end of file
|
||||||
@ -310,11 +337,7 @@ qemuProcessHandleMonitorEOF(qemuMonitor *mon,
|
|||||||
processEvent->eventType = QEMU_PROCESS_EVENT_MONITOR_EOF;
|
processEvent->eventType = QEMU_PROCESS_EVENT_MONITOR_EOF;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We don't want this EOF handler to be called over and over while the
|
/* We don't want this EOF handler to be called over and over while the
|
||||||
* thread is waiting for a job.
|
* thread is waiting for a job.
|
||||||
@ -833,10 +856,8 @@ qemuProcessHandleWatchdog(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
* deleted before handling watchdog event is finished.
|
* deleted before handling watchdog event is finished.
|
||||||
*/
|
*/
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
|
||||||
virObjectUnref(vm);
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
@ -925,7 +946,6 @@ qemuProcessHandleBlockJob(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
{
|
{
|
||||||
qemuDomainObjPrivate *priv;
|
qemuDomainObjPrivate *priv;
|
||||||
virQEMUDriver *driver = opaque;
|
virQEMUDriver *driver = opaque;
|
||||||
struct qemuProcessEvent *processEvent = NULL;
|
|
||||||
virDomainDiskDef *disk;
|
virDomainDiskDef *disk;
|
||||||
g_autoptr(qemuBlockJobData) job = NULL;
|
g_autoptr(qemuBlockJobData) job = NULL;
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
@ -954,7 +974,7 @@ qemuProcessHandleBlockJob(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
virDomainObjBroadcast(vm);
|
virDomainObjBroadcast(vm);
|
||||||
} else {
|
} else {
|
||||||
/* there is no waiting SYNC API, dispatch the update to a thread */
|
/* there is no waiting SYNC API, dispatch the update to a thread */
|
||||||
processEvent = g_new0(struct qemuProcessEvent, 1);
|
struct qemuProcessEvent *processEvent = g_new0(struct qemuProcessEvent, 1);
|
||||||
|
|
||||||
processEvent->eventType = QEMU_PROCESS_EVENT_BLOCK_JOB;
|
processEvent->eventType = QEMU_PROCESS_EVENT_BLOCK_JOB;
|
||||||
data = g_strdup(diskAlias);
|
data = g_strdup(diskAlias);
|
||||||
@ -963,16 +983,10 @@ qemuProcessHandleBlockJob(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->action = type;
|
processEvent->action = type;
|
||||||
processEvent->status = status;
|
processEvent->status = status;
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
processEvent = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,7 +1000,6 @@ qemuProcessHandleJobStatusChange(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
{
|
{
|
||||||
virQEMUDriver *driver = opaque;
|
virQEMUDriver *driver = opaque;
|
||||||
qemuDomainObjPrivate *priv;
|
qemuDomainObjPrivate *priv;
|
||||||
struct qemuProcessEvent *processEvent = NULL;
|
|
||||||
qemuBlockJobData *job = NULL;
|
qemuBlockJobData *job = NULL;
|
||||||
int jobnewstate;
|
int jobnewstate;
|
||||||
|
|
||||||
@ -1016,23 +1029,18 @@ qemuProcessHandleJobStatusChange(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
VIR_DEBUG("job '%s' handled synchronously", jobname);
|
VIR_DEBUG("job '%s' handled synchronously", jobname);
|
||||||
virDomainObjBroadcast(vm);
|
virDomainObjBroadcast(vm);
|
||||||
} else {
|
} else {
|
||||||
|
struct qemuProcessEvent *processEvent = g_new0(struct qemuProcessEvent, 1);
|
||||||
|
|
||||||
VIR_DEBUG("job '%s' handled by event thread", jobname);
|
VIR_DEBUG("job '%s' handled by event thread", jobname);
|
||||||
processEvent = g_new0(struct qemuProcessEvent, 1);
|
|
||||||
|
|
||||||
processEvent->eventType = QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE;
|
processEvent->eventType = QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
processEvent->data = virObjectRef(job);
|
processEvent->data = virObjectRef(job);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
processEvent = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1288,10 +1296,7 @@ qemuProcessHandleGuestPanic(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
*/
|
*/
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
}
|
}
|
||||||
@ -1323,17 +1328,10 @@ qemuProcessHandleDeviceDeleted(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->data = data;
|
processEvent->data = data;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
return;
|
|
||||||
error:
|
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1503,17 +1501,9 @@ qemuProcessHandleNicRxFilterChanged(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->data = data;
|
processEvent->data = data;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
return;
|
|
||||||
error:
|
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1541,17 +1531,9 @@ qemuProcessHandleSerialChanged(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->action = connected;
|
processEvent->action = connected;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
return;
|
|
||||||
error:
|
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1740,11 +1722,7 @@ qemuProcessHandlePRManagerStatusChanged(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->eventType = QEMU_PROCESS_EVENT_PR_DISCONNECT;
|
processEvent->eventType = QEMU_PROCESS_EVENT_PR_DISCONNECT;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
virObjectUnref(vm);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
@ -1783,10 +1761,7 @@ qemuProcessHandleRdmaGidStatusChanged(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
processEvent->data = g_steal_pointer(&info);
|
processEvent->data = g_steal_pointer(&info);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
virObjectUnref(vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
}
|
}
|
||||||
@ -1806,10 +1781,7 @@ qemuProcessHandleGuestCrashloaded(qemuMonitor *mon G_GNUC_UNUSED,
|
|||||||
processEvent->eventType = QEMU_PROCESS_EVENT_GUEST_CRASHLOADED;
|
processEvent->eventType = QEMU_PROCESS_EVENT_GUEST_CRASHLOADED;
|
||||||
processEvent->vm = virObjectRef(vm);
|
processEvent->vm = virObjectRef(vm);
|
||||||
|
|
||||||
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
|
qemuProcessEventSubmit(driver, &processEvent);
|
||||||
virObjectUnref(vm);
|
|
||||||
qemuProcessEventFree(processEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user