]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add script hook support to the LXC driver
authorDaniel Veillard <veillard@redhat.com>
Fri, 26 Mar 2010 15:02:05 +0000 (16:02 +0100)
committerDaniel Veillard <veillard@redhat.com>
Mon, 29 Mar 2010 16:21:26 +0000 (18:21 +0200)
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

src/lxc/lxc_driver.c

index 0650dc500a2a2c93d1fad5574f599183082fdee4..7ebc7ae9d1c29b381271a051147e8bbc23fba86d 100644 (file)
@@ -49,6 +49,7 @@
 #include "nodeinfo.h"
 #include "uuid.h"
 #include "stats_linux.h"
+#include "hooks.h"
 
 
 #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);
     }
 
+    /* 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);
     close(priv->monitor);
 
@@ -1130,6 +1141,22 @@ static int lxcControllerStart(lxc_driver_t *driver,
 
     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,
                 -1, &logfd, &logfd,
                 VIR_EXEC_NONE) < 0)