mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
qemu: add two hook script events "prepare" and "release"
Fix for bug https://bugzilla.redhat.com/show_bug.cgi?id=618970 The "prepare" hook is called very early in the VM statup process before device labeling, so that it can allocate ressources not managed by libvirt, such as DRBD, or for instance create missing bridges and vlan interfaces. * src/util/hooks.c src/util/hooks.h: add definitions for new hooks VIR_HOOK_QEMU_OP_PREPARE and VIR_HOOK_QEMU_OP_RELEASE * src/qemu/qemu_process.c: use them in qemuProcessStart and qemuProcessStop()
This commit is contained in:
parent
23674616b9
commit
3415eeb53e
@ -1927,6 +1927,22 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
|
||||
vm->def->id = driver->nextvmid++;
|
||||
|
||||
/* Run a early hook to set-up missing devices */
|
||||
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_PREPARE, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
|
||||
VIR_FREE(xml);
|
||||
|
||||
/*
|
||||
* If the script raised an error abort the launch
|
||||
*/
|
||||
if (hookret < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Must be run before security labelling */
|
||||
VIR_DEBUG0("Preparing host devices");
|
||||
if (qemuPrepareHostDevices(driver, vm->def) < 0)
|
||||
@ -2419,6 +2435,16 @@ retry:
|
||||
VIR_FREE(priv->vcpupids);
|
||||
priv->nvcpupids = 0;
|
||||
|
||||
/* The "release" hook cleans up additional ressources */
|
||||
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_RELEASE, VIR_HOOK_SUBOP_END, NULL, xml);
|
||||
VIR_FREE(xml);
|
||||
}
|
||||
|
||||
if (vm->newDef) {
|
||||
virDomainDefFree(vm->def);
|
||||
vm->def = vm->newDef;
|
||||
|
@ -71,7 +71,9 @@ VIR_ENUM_IMPL(virHookSubop, VIR_HOOK_SUBOP_LAST,
|
||||
|
||||
VIR_ENUM_IMPL(virHookQemuOp, VIR_HOOK_QEMU_OP_LAST,
|
||||
"start",
|
||||
"stopped")
|
||||
"stopped",
|
||||
"prepare",
|
||||
"release")
|
||||
|
||||
VIR_ENUM_IMPL(virHookLxcOp, VIR_HOOK_LXC_OP_LAST,
|
||||
"start",
|
||||
|
@ -54,6 +54,8 @@ enum virHookSubopType {
|
||||
enum virHookQemuOpType {
|
||||
VIR_HOOK_QEMU_OP_START, /* domain is about to start */
|
||||
VIR_HOOK_QEMU_OP_STOPPED, /* domain has stopped */
|
||||
VIR_HOOK_QEMU_OP_PREPARE, /* domain startup initiated */
|
||||
VIR_HOOK_QEMU_OP_RELEASE, /* domain destruction is over */
|
||||
|
||||
VIR_HOOK_QEMU_OP_LAST,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user