mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Add script hook support to the LXC driver
Right now this implements only 2 basic hooks: - before the lxc control process is being launched - after the lxc control process is terminated the XML description of the domain is passed to the hook script stdin /etc/libvirt/hook/lxc * src/lxc/lxc_driver.c: implement synchronous script hooks for LXC at domain startup and end
This commit is contained in:
parent
668150fc3d
commit
86415b2d26
@ -49,6 +49,7 @@
|
|||||||
#include "nodeinfo.h"
|
#include "nodeinfo.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "stats_linux.h"
|
#include "stats_linux.h"
|
||||||
|
#include "hooks.h"
|
||||||
|
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
@ -722,6 +723,16 @@ static int lxcVmCleanup(lxc_driver_t *driver,
|
|||||||
DEBUG("container exited with rc: %d", rc);
|
DEBUG("container exited with rc: %d", rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* now that we know it's stopped call the hook if present */
|
||||||
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
|
char *xml = virDomainDefFormat(vm->def, 0);
|
||||||
|
|
||||||
|
/* we can't stop the operation even if the script raised an error */
|
||||||
|
virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
|
VIR_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END, NULL, xml);
|
||||||
|
VIR_FREE(xml);
|
||||||
|
}
|
||||||
|
|
||||||
virEventRemoveHandle(priv->monitorWatch);
|
virEventRemoveHandle(priv->monitorWatch);
|
||||||
close(priv->monitor);
|
close(priv->monitor);
|
||||||
|
|
||||||
@ -1130,6 +1141,22 @@ static int lxcControllerStart(lxc_driver_t *driver,
|
|||||||
|
|
||||||
FD_SET(appPty, &keepfd);
|
FD_SET(appPty, &keepfd);
|
||||||
|
|
||||||
|
/* now that we know it is about to start call the hook if present */
|
||||||
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
|
char *xml = virDomainDefFormat(vm->def, 0);
|
||||||
|
int hookret;
|
||||||
|
|
||||||
|
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
|
VIR_HOOK_LXC_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;
|
||||||
|
}
|
||||||
|
|
||||||
if (virExec(largv, lenv, &keepfd, &child,
|
if (virExec(largv, lenv, &keepfd, &child,
|
||||||
-1, &logfd, &logfd,
|
-1, &logfd, &logfd,
|
||||||
VIR_EXEC_NONE) < 0)
|
VIR_EXEC_NONE) < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user