mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
hooks: Add support for capturing hook output
Hooks may now be used as filters.
This commit is contained in:
parent
c0f722240d
commit
8ab785783f
@ -1148,7 +1148,7 @@ static void daemonReloadHandler(virNetServerPtr srv ATTRIBUTE_UNUSED,
|
||||
{
|
||||
VIR_INFO("Reloading configuration on SIGHUP");
|
||||
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-",
|
||||
VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL);
|
||||
VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL, NULL);
|
||||
if (virStateReload() < 0)
|
||||
VIR_WARN("Error while reloading drivers");
|
||||
}
|
||||
@ -1571,7 +1571,7 @@ int main(int argc, char **argv) {
|
||||
* an error ?
|
||||
*/
|
||||
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_START,
|
||||
0, "start", NULL);
|
||||
0, "start", NULL, NULL);
|
||||
|
||||
if (daemonSetupNetworking(srv, config,
|
||||
sock_file, sock_file_ro,
|
||||
@ -1604,7 +1604,7 @@ int main(int argc, char **argv) {
|
||||
ret = 0;
|
||||
|
||||
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_SHUTDOWN,
|
||||
0, "shutdown", NULL);
|
||||
0, "shutdown", NULL, NULL);
|
||||
|
||||
cleanup:
|
||||
virNetServerProgramFree(remoteProgram);
|
||||
|
@ -1115,7 +1115,8 @@ static void lxcVmCleanup(lxc_driver_t *driver,
|
||||
|
||||
/* 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_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END,
|
||||
NULL, xml, NULL);
|
||||
VIR_FREE(xml);
|
||||
}
|
||||
|
||||
@ -1632,7 +1633,8 @@ lxcBuildControllerCmd(lxc_driver_t *driver,
|
||||
int hookret;
|
||||
|
||||
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||
VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
|
||||
VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN,
|
||||
NULL, xml, NULL);
|
||||
VIR_FREE(xml);
|
||||
|
||||
/*
|
||||
|
@ -3120,7 +3120,8 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
int hookret;
|
||||
|
||||
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
|
||||
VIR_HOOK_QEMU_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
|
||||
VIR_HOOK_QEMU_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN,
|
||||
NULL, xml, NULL);
|
||||
VIR_FREE(xml);
|
||||
|
||||
/*
|
||||
@ -3305,7 +3306,8 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
int hookret;
|
||||
|
||||
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
|
||||
VIR_HOOK_QEMU_OP_START, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
|
||||
VIR_HOOK_QEMU_OP_START, VIR_HOOK_SUBOP_BEGIN,
|
||||
NULL, xml, NULL);
|
||||
VIR_FREE(xml);
|
||||
|
||||
/*
|
||||
@ -3726,7 +3728,8 @@ void qemuProcessStop(struct qemud_driver *driver,
|
||||
|
||||
/* 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_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END,
|
||||
NULL, xml, NULL);
|
||||
VIR_FREE(xml);
|
||||
}
|
||||
|
||||
@ -3819,7 +3822,8 @@ retry:
|
||||
|
||||
/* 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_HOOK_QEMU_OP_RELEASE, VIR_HOOK_SUBOP_END,
|
||||
NULL, xml, NULL);
|
||||
VIR_FREE(xml);
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ virHookPresent(int driver) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* virHookCall:
|
||||
* @driver: the driver number (from virHookDriver enum)
|
||||
* @id: an id for the object '-' if non available for example on daemon hooks
|
||||
@ -181,17 +181,26 @@ virHookPresent(int driver) {
|
||||
* @sub_op: a sub_operation, currently unused
|
||||
* @extra: optional string information
|
||||
* @input: extra input given to the script on stdin
|
||||
* @output: optional address of variable to store malloced result buffer
|
||||
*
|
||||
* Implement a hook call, where the external script for the driver is
|
||||
* called with the given information. This is a synchronous call, we wait for
|
||||
* execution completion
|
||||
* execution completion. If @output is non-NULL, *output is guaranteed to be
|
||||
* allocated after successful virHookCall, and is best-effort allocated after
|
||||
* failed virHookCall; the caller is responsible for freeing *output.
|
||||
*
|
||||
* Returns: 0 if the execution succeeded, 1 if the script was not found or
|
||||
* invalid parameters, and -1 if script returned an error
|
||||
*/
|
||||
int
|
||||
virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
|
||||
const char *input) {
|
||||
virHookCall(int driver,
|
||||
const char *id,
|
||||
int op,
|
||||
int sub_op,
|
||||
const char *extra,
|
||||
const char *input,
|
||||
char **output)
|
||||
{
|
||||
int ret;
|
||||
int exitstatus;
|
||||
char *path;
|
||||
@ -200,6 +209,9 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
|
||||
const char *opstr;
|
||||
const char *subopstr;
|
||||
|
||||
if (output)
|
||||
*output = NULL;
|
||||
|
||||
if ((driver < VIR_HOOK_DRIVER_DAEMON) ||
|
||||
(driver >= VIR_HOOK_DRIVER_LAST))
|
||||
return(1);
|
||||
@ -257,6 +269,8 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
|
||||
|
||||
if (input)
|
||||
virCommandSetInputBuffer(cmd, input);
|
||||
if (output)
|
||||
virCommandSetOutputBuffer(cmd, output);
|
||||
|
||||
ret = virCommandRun(cmd, &exitstatus);
|
||||
if (ret == 0 && exitstatus != 0) {
|
||||
|
@ -72,6 +72,6 @@ int virHookInitialize(void);
|
||||
int virHookPresent(int driver);
|
||||
|
||||
int virHookCall(int driver, const char *id, int op, int sub_op,
|
||||
const char *extra, const char *input);
|
||||
const char *extra, const char *input, char **output);
|
||||
|
||||
#endif /* __VIR_HOOKS_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user