[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [RFC 2/7] qemu: add guest init event callback to do the initialize work for guest



Signed-off-by: Chen Fan <chen fan fnst cn fujitsu com>
---
 src/qemu/qemu_domain.h  |  7 +++++++
 src/qemu/qemu_driver.c  | 32 ++++++++++++++++++++++++++++++++
 src/qemu/qemu_process.c | 22 ++++++++++++++++++++++
 3 files changed, 61 insertions(+)

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 3225abb..19f4b27 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -136,6 +136,8 @@ struct qemuDomainJobObj {
 typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
                                           virDomainObjPtr vm);
 
+typedef void (*qemuDomainInitCallback)(virDomainObjPtr vm);
+
 typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate;
 typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
 struct _qemuDomainObjPrivate {
@@ -185,6 +187,10 @@ struct _qemuDomainObjPrivate {
     size_t ncleanupCallbacks;
     size_t ncleanupCallbacks_max;
 
+    qemuDomainInitCallback *initCallbacks;
+    size_t nInitCallbacks;
+    size_t nInitCallbacks_max;
+
     virCgroupPtr cgroup;
 
     virCond unplugFinished; /* signals that unpluggingDevice was unplugged */
@@ -205,6 +211,7 @@ typedef enum {
     QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED,
     QEMU_PROCESS_EVENT_SERIAL_CHANGED,
     QEMU_PROCESS_EVENT_BLOCK_JOB,
+    QEMU_PROCESS_EVENT_GUESTINIT,
 
     QEMU_PROCESS_EVENT_LAST
 } qemuProcessEventType;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f37b95d..7368145 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4073,6 +4073,35 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
 
 
 static void
+processGuestInitEvent(virQEMUDriverPtr driver,
+                      virDomainObjPtr vm)
+{
+    qemuDomainObjPrivatePtr priv;
+    int i;
+
+    VIR_DEBUG("init guest from domain %p %s",
+              vm, vm->def->name);
+
+    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+        return;
+
+    if (!virDomainObjIsActive(vm)) {
+        VIR_DEBUG("Domain is not running");
+        goto endjob;
+    }
+
+    priv = vm->privateData;
+
+    for (i = 0; i < priv->nInitCallbacks; i++) {
+        if (priv->initCallbacks[i])
+            priv->initCallbacks[i](vm);
+    }
+
+ endjob:
+    qemuDomainObjEndJob(driver, vm);
+}
+
+static void
 processDeviceDeletedEvent(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
                           char *devAlias)
@@ -4627,6 +4656,9 @@ static void qemuProcessEventHandler(void *data, void *opaque)
                              processEvent->action,
                              processEvent->status);
         break;
+    case QEMU_PROCESS_EVENT_GUESTINIT:
+        processGuestInitEvent(driver, vm);
+        break;
     case QEMU_PROCESS_EVENT_LAST:
         break;
     }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e6fc53a..fcc0566 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -197,7 +197,29 @@ static void qemuProcessHandleAgentDestroy(qemuAgentPtr agent,
 static void qemuProcessHandleAgentInit(qemuAgentPtr agent ATTRIBUTE_UNUSED,
                                        virDomainObjPtr vm)
 {
+    struct qemuProcessEvent *processEvent = NULL;
+    virQEMUDriverPtr driver = qemu_driver;
+
+    virObjectLock(vm);
+
     VIR_DEBUG("Received init from agent on %p '%s'", vm, vm->def->name);
+
+    if (VIR_ALLOC(processEvent) < 0)
+        goto cleanup;
+
+    processEvent->eventType = QEMU_PROCESS_EVENT_GUESTINIT;
+    processEvent->vm = vm;
+
+    virObjectRef(vm);
+    if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
+        if (!virObjectUnref(vm))
+            vm = NULL;
+        VIR_FREE(processEvent);
+    }
+
+ cleanup:
+    if (vm)
+        virObjectUnlock(vm);
 }
 
 static qemuAgentCallbacks agentCallbacks = {
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]