Hooks may now be used as filters. --- daemon/libvirtd.c | 6 +++--- src/lxc/lxc_driver.c | 6 ++++-- src/qemu/qemu_process.c | 12 ++++++++---- src/util/hooks.c | 22 ++++++++++++++++++---- src/util/hooks.h | 2 +- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index b1b542b..52e80fa 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -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); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index d77afcc..d9cbd9e 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -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); /* diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 41218de..36e5ce6 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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); } diff --git a/src/util/hooks.c b/src/util/hooks.c index 110a94b..8c16a3a 100644 --- a/src/util/hooks.c +++ b/src/util/hooks.c @@ -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) { diff --git a/src/util/hooks.h b/src/util/hooks.h index fd7411c..a53ac2c 100644 --- a/src/util/hooks.h +++ b/src/util/hooks.h @@ -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__ */ -- 1.7.8.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list