diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3df0398801db80b56a469e6af7a7c53550c127a2..b738be86e3e74dcc06bc8652efc6706dba195658 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -84,6 +84,7 @@ #include "cpu/cpu.h" #include "macvtap.h" #include "nwfilter/nwfilter_gentech_driver.h" +#include "hooks.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -3100,6 +3101,22 @@ static int qemudStartVMDaemon(virConnectPtr conn, &tapfds, &ntapfds, migrateFrom) < 0) goto cleanup; + /* now that we know it is about to start call the hook if present */ + if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { + char *xml = virDomainDefFormat(vm->def, 0); + int hookret; + + hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, + VIR_HOOK_QEMU_OP_START, VIR_HOOK_SUBOP_BEGIN, NULL, xml); + VIR_FREE(xml); + + /* + * If the script raised an error abort the launch + */ + if (hookret < 0) + goto cleanup; + } + tmp = progenv; while (*tmp) { if (safewrite(logfile, *tmp, strlen(*tmp)) < 0) @@ -3324,6 +3341,16 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver, /* shut it off for sure */ virKillProcess(vm->pid, SIGKILL); + /* now that we know it's stopped call the hook if present */ + if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { + char *xml = virDomainDefFormat(vm->def, 0); + + /* we can't stop the operation even if the script raised an error */ + virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, + VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END, NULL, xml); + VIR_FREE(xml); + } + /* Reset Security Labels */ if (driver->securityDriver && driver->securityDriver->domainRestoreSecurityAllLabel)