qemuProcessStart is so big that any nontrivial code should be moved to dedicated functions to make the code easier to read and maintain. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_process.c | 80 ++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 009c729..112e561 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4232,6 +4232,29 @@ qemuProcessEndJob(virQEMUDriverPtr driver, } +static int +qemuProcessStartHook(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virHookQemuOpType op, + virHookSubopType subop) +{ + char *xml; + int ret; + + if (!virHookPresent(VIR_HOOK_DRIVER_QEMU)) + return 0; + + if (!(xml = qemuDomainDefFormatXML(driver, vm->def, 0))) + return -1; + + ret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, op, subop, + NULL, xml, NULL); + VIR_FREE(xml); + + return ret; +} + + int qemuProcessStart(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -4327,21 +4350,10 @@ int qemuProcessStart(virConnectPtr conn, driver->inhibitCallback(true, driver->inhibitOpaque); /* Run an early hook to set-up missing devices */ - if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { - char *xml = qemuDomainDefFormatXML(driver, vm->def, 0); - int hookret; - - hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, - VIR_HOOK_QEMU_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN, - NULL, xml, NULL); - VIR_FREE(xml); - - /* - * If the script raised an error abort the launch - */ - if (hookret < 0) - goto error; - } + if (qemuProcessStartHook(driver, vm, + VIR_HOOK_QEMU_OP_PREPARE, + VIR_HOOK_SUBOP_BEGIN) < 0) + goto error; VIR_DEBUG("Determining emulator version"); virObjectUnref(priv->qemuCaps); @@ -4644,21 +4656,10 @@ int qemuProcessStart(virConnectPtr conn, VIR_FREE(tmppath); /* now that we know it is about to start call the hook if present */ - if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { - char *xml = qemuDomainDefFormatXML(driver, 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, NULL); - VIR_FREE(xml); - - /* - * If the script raised an error abort the launch - */ - if (hookret < 0) - goto error; - } + if (qemuProcessStartHook(driver, vm, + VIR_HOOK_QEMU_OP_START, + VIR_HOOK_SUBOP_BEGIN) < 0) + goto error; qemuLogOperation(vm, "starting up", logfile, cmd); @@ -4968,21 +4969,10 @@ int qemuProcessStart(virConnectPtr conn, goto error; /* finally we can call the 'started' hook script if any */ - if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { - char *xml = qemuDomainDefFormatXML(driver, vm->def, 0); - int hookret; - - hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, - VIR_HOOK_QEMU_OP_STARTED, VIR_HOOK_SUBOP_BEGIN, - NULL, xml, NULL); - VIR_FREE(xml); - - /* - * If the script raised an error abort the launch - */ - if (hookret < 0) - goto error; - } + if (qemuProcessStartHook(driver, vm, + VIR_HOOK_QEMU_OP_STARTED, + VIR_HOOK_SUBOP_BEGIN) < 0) + goto error; /* Keep watching qemu log for errors during incoming migration, otherwise * unset reporting errors from qemu log. */ -- 2.6.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list