Also, the enqueuing of a new event now triggers virEventWorkerScanQueue()
Signed-off-by: Prerna Saxena <saxenap.ltc(a)gmail.com>
---
src/qemu/qemu_driver.c | 61 ++----------------------
src/qemu/qemu_process.c | 121 +++++++++++-------------------------------------
2 files changed, 29 insertions(+), 153 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9d495fb..881f253 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -138,8 +138,6 @@ VIR_LOG_INIT("qemu.qemu_driver");
#define QEMU_NB_BANDWIDTH_PARAM 7
-static void qemuProcessEventHandler(void *data, void *opaque);
-
static int qemuStateCleanup(void);
static int qemuDomainObjStart(virConnectPtr conn,
@@ -936,7 +934,9 @@ qemuStateInitialize(bool privileged,
qemuProcessReconnectAll(conn, qemu_driver);
- qemu_driver->workerPool = virThreadPoolNew(0, 1, 0, qemuProcessEventHandler,
qemu_driver);
+ qemu_driver->workerPool = virThreadPoolNew(0, 1, 0, virEventWorkerScanQueue,
+ qemu_driver);
+
if (!qemu_driver->workerPool)
goto error;
@@ -3645,61 +3645,6 @@ qemuDomainScreenshot(virDomainPtr dom,
}
-
-
-
-
-
-
-
-
-static void qemuProcessEventHandler(void *data, void *opaque)
-{
- struct qemuProcessEvent *processEvent = data;
- virDomainObjPtr vm = processEvent->vm;
- virQEMUDriverPtr driver = opaque;
-
- VIR_DEBUG("vm=%p, event=%d", vm, processEvent->eventType);
-
- virObjectLock(vm);
-
- switch (processEvent->eventType) {
- case QEMU_PROCESS_EVENT_WATCHDOG:
- processWatchdogEvent(driver, vm, processEvent->action);
- break;
- case QEMU_PROCESS_EVENT_GUESTPANIC:
- processGuestPanicEvent(driver, vm, processEvent->action,
- processEvent->data);
- break;
- case QEMU_PROCESS_EVENT_DEVICE_DELETED:
- processDeviceDeletedEvent(driver, vm, processEvent->data);
- break;
- case QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED:
- processNicRxFilterChangedEvent(driver, vm, processEvent->data);
- break;
- case QEMU_PROCESS_EVENT_SERIAL_CHANGED:
- processSerialChangedEvent(driver, vm, processEvent->data,
- processEvent->action);
- break;
- case QEMU_PROCESS_EVENT_BLOCK_JOB:
- processBlockJobEvent(driver, vm,
- processEvent->data,
- processEvent->action,
- processEvent->status);
- break;
- case QEMU_PROCESS_EVENT_MONITOR_EOF:
- processMonitorEOFEvent(driver, vm);
- break;
- case QEMU_PROCESS_EVENT_LAST:
- break;
- }
-
- virDomainConsumeVMEvents(vm, driver);
- virDomainObjEndAPI(&vm);
- VIR_FREE(processEvent);
-}
-
-
static int
qemuDomainSetVcpusAgent(virDomainObjPtr vm,
unsigned int nvcpus)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d2b5fe8..f9270e0 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -962,21 +962,11 @@ qemuProcessEventHandleWatchdog1(qemuEventPtr ev,
}
if (vm->def->watchdog->action == VIR_DOMAIN_WATCHDOG_ACTION_DUMP) {
- struct qemuProcessEvent *processEvent;
- if (VIR_ALLOC(processEvent) == 0) {
- processEvent->eventType = QEMU_PROCESS_EVENT_WATCHDOG;
- processEvent->action = VIR_DOMAIN_WATCHDOG_ACTION_DUMP;
- processEvent->vm = vm;
- /* Hold an extra reference because we can't allow 'vm' to be
- * deleted before handling watchdog event is finished.
- */
- virObjectRef(vm);
- if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
- if (!virObjectUnref(vm))
- vm = NULL;
- VIR_FREE(processEvent);
- }
- }
+ /* Hold an extra reference because we can't allow 'vm' to be
+ * deleted before handling watchdog event is finished.*/
+ virObjectRef(vm);
+ processWatchdogEvent(driver, vm, VIR_DOMAIN_WATCHDOG_ACTION_DUMP);
+ virObjectUnref(vm);
}
qemuDomainEventQueue(driver, watchdogEvent);
@@ -1068,12 +1058,10 @@ qemuProcessEventHandleBlockJob(qemuEventPtr ev,
void *opaque)
{
virQEMUDriverPtr driver = opaque;
- struct qemuProcessEvent *processEvent = NULL;
virDomainDiskDefPtr disk;
qemuDomainDiskPrivatePtr diskPriv;
- char *data = NULL;
virDomainObjPtr vm;
- const char *diskAlias;
+ char *diskAlias = NULL;
int type, status;
if (!ev)
@@ -1082,7 +1070,7 @@ qemuProcessEventHandleBlockJob(qemuEventPtr ev,
if (!ev->vm) {
VIR_WARN("Unable to locate VM, dropping Block Job event");
- goto cleanup;
+ goto error;
}
diskAlias = ev->evData.ev_blockJob.device;
@@ -1103,31 +1091,16 @@ qemuProcessEventHandleBlockJob(qemuEventPtr ev,
virDomainObjBroadcast(vm);
} else {
/* there is no waiting SYNC API, dispatch the update to a thread */
- if (VIR_ALLOC(processEvent) < 0)
- goto error;
-
- processEvent->eventType = QEMU_PROCESS_EVENT_BLOCK_JOB;
- if (VIR_STRDUP(data, diskAlias) < 0)
- goto error;
- processEvent->data = data;
- processEvent->vm = vm;
- processEvent->action = type;
- processEvent->status = status;
virObjectRef(vm);
- if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
- ignore_value(virObjectUnref(vm));
- goto error;
- }
+ processBlockJobEvent(driver, vm, diskAlias, type, status);
+ virObjectUnref(vm);
}
- cleanup:
+error:
+ if (diskAlias)
+ VIR_FREE(diskAlias);
return;
- error:
- if (processEvent)
- VIR_FREE(processEvent->data);
- VIR_FREE(processEvent);
- goto cleanup;
}
static void
@@ -1465,7 +1438,6 @@ qemuProcessEventHandleGuestPanic(qemuEventPtr ev,
void *opaque)
{
virQEMUDriverPtr driver = opaque;
- struct qemuProcessEvent *processEvent;
virDomainObjPtr vm;
qemuMonitorEventPanicInfoPtr info;
@@ -1479,22 +1451,12 @@ qemuProcessEventHandleGuestPanic(qemuEventPtr ev,
}
info = ev->evData.ev_panic.info;
- if (VIR_ALLOC(processEvent) < 0)
- goto exit;
-
- processEvent->eventType = QEMU_PROCESS_EVENT_GUESTPANIC;
- processEvent->action = vm->def->onCrash;
- processEvent->vm = vm;
- processEvent->data = info;
/* Hold an extra reference because we can't allow 'vm' to be
* deleted before handling guest panic event is finished.
*/
virObjectRef(vm);
- if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
- if (!virObjectUnref(vm))
- vm = NULL;
- VIR_FREE(processEvent);
- }
+ processGuestPanicEvent(driver, vm, vm->def->onCrash, info);
+ virObjectUnref(vm);
exit:
return;
@@ -1506,10 +1468,8 @@ qemuProcessEventHandleDeviceDeleted(qemuEventPtr ev,
void *opaque)
{
virQEMUDriverPtr driver = opaque;
- struct qemuProcessEvent *processEvent = NULL;
- char *data;
virDomainObjPtr vm;
- const char *devAlias;
+ char *devAlias = NULL;
if (!ev)
return;
@@ -1528,29 +1488,14 @@ qemuProcessEventHandleDeviceDeleted(qemuEventPtr ev,
QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_OK))
goto cleanup;
- if (VIR_ALLOC(processEvent) < 0)
- goto error;
-
- processEvent->eventType = QEMU_PROCESS_EVENT_DEVICE_DELETED;
- if (VIR_STRDUP(data, devAlias) < 0)
- goto error;
- processEvent->data = data;
- processEvent->vm = vm;
-
virObjectRef(vm);
- if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
- ignore_value(virObjectUnref(vm));
- goto error;
- }
+ processDeviceDeletedEvent(driver, vm, devAlias);
+ virObjectUnref(vm);
cleanup:
- VIR_FREE(ev->evData.ev_deviceDel.device);
+ if (ev->evData.ev_deviceDel.device)
+ VIR_FREE(ev->evData.ev_deviceDel.device);
return;
- error:
- if (processEvent)
- VIR_FREE(processEvent->data);
- VIR_FREE(processEvent);
- goto cleanup;
}
@@ -1744,8 +1689,6 @@ qemuProcessEventHandleSerialChanged(qemuEventPtr ev,
void *opaque)
{
virQEMUDriverPtr driver = opaque;
- struct qemuProcessEvent *processEvent = NULL;
- char *data;
virDomainObjPtr vm;
char *devAlias;
bool connected;
@@ -1764,30 +1707,14 @@ qemuProcessEventHandleSerialChanged(qemuEventPtr ev,
VIR_DEBUG("Serial port %s state changed to '%d' in domain %p %s",
devAlias, connected, vm, vm->def->name);
- if (VIR_ALLOC(processEvent) < 0)
- goto error;
-
- processEvent->eventType = QEMU_PROCESS_EVENT_SERIAL_CHANGED;
- if (VIR_STRDUP(data, devAlias) < 0)
- goto error;
- processEvent->data = data;
- processEvent->action = connected;
- processEvent->vm = vm;
virObjectRef(vm);
- if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
- ignore_value(virObjectUnref(vm));
- goto error;
- }
+ processSerialChangedEvent(driver, vm, devAlias, connected);
+ virObjectUnref(vm);
cleanup:
VIR_FREE(ev->evData.ev_serial.devAlias);
return;
- error:
- if (processEvent)
- VIR_FREE(processEvent->data);
- VIR_FREE(processEvent);
- goto cleanup;
}
@@ -1934,7 +1861,11 @@ qemuProcessEnqueueEvent(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
/* Bad code alert: Fix this lookup to scan table for correct index.
* Works for now since event table is sorted */
ev->handler = qemuEventFunctions[ev->ev_type].handler_func;
- return virEnqueueVMEvent(driver->ev_list, ev);
+ if (!virEnqueueVMEvent(driver->ev_list, ev)) {
+ /* Bad code alert #2: Use a better notification mechanism */
+ return virThreadPoolSendJob(driver->workerPool, 0, NULL);
+ }
+ return -1;
}
static qemuMonitorCallbacks monitorCallbacks = {
--
2.9.5