mirror of https://gitee.com/openkylin/libvirt.git
bhyve: add hooks
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
This commit is contained in:
parent
67fc00aa4e
commit
51451662f6
|
@ -37,6 +37,7 @@
|
|||
#include "bhyve_process.h"
|
||||
#include "datatypes.h"
|
||||
#include "virerror.h"
|
||||
#include "virhook.h"
|
||||
#include "virlog.h"
|
||||
#include "virfile.h"
|
||||
#include "viralloc.h"
|
||||
|
@ -91,6 +92,24 @@ virBhyveFormatDevMapFile(const char *vm_name, char **fn_out)
|
|||
*fn_out = g_strdup_printf("%s/grub_bhyve-%s-device.map", BHYVE_STATE_DIR, vm_name);
|
||||
}
|
||||
|
||||
static int
|
||||
bhyveProcessStartHook(virDomainObjPtr vm, virHookBhyveOpType op)
|
||||
{
|
||||
if (!virHookPresent(VIR_HOOK_DRIVER_BHYVE))
|
||||
return 0;
|
||||
|
||||
return virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
|
||||
VIR_HOOK_SUBOP_BEGIN, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
bhyveProcessStopHook(virDomainObjPtr vm, virHookBhyveOpType op)
|
||||
{
|
||||
if (virHookPresent(VIR_HOOK_DRIVER_BHYVE))
|
||||
virHookCall(VIR_HOOK_DRIVER_BHYVE, vm->def->name, op,
|
||||
VIR_HOOK_SUBOP_END, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
virBhyveProcessStart(virConnectPtr conn,
|
||||
virDomainObjPtr vm,
|
||||
|
@ -135,6 +154,10 @@ virBhyveProcessStart(virConnectPtr conn,
|
|||
if (bhyveDomainAssignAddresses(vm->def, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Run an early hook to setup missing devices. */
|
||||
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_PREPARE) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Call bhyve to start the VM */
|
||||
if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, vm->def, false)))
|
||||
goto cleanup;
|
||||
|
@ -176,6 +199,9 @@ virBhyveProcessStart(virConnectPtr conn,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_START) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Now we can start the domain */
|
||||
VIR_DEBUG("Starting domain '%s'", vm->def->name);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
|
@ -200,6 +226,9 @@ virBhyveProcessStart(virConnectPtr conn,
|
|||
BHYVE_STATE_DIR) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (bhyveProcessStartHook(vm, VIR_HOOK_BHYVE_OP_STARTED) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
|
@ -263,6 +292,8 @@ virBhyveProcessStop(bhyveConnPtr driver,
|
|||
if ((priv != NULL) && (priv->mon != NULL))
|
||||
bhyveMonitorClose(priv->mon);
|
||||
|
||||
bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_STOPPED);
|
||||
|
||||
/* Cleanup network interfaces */
|
||||
bhyveNetCleanup(vm);
|
||||
|
||||
|
@ -284,6 +315,8 @@ virBhyveProcessStop(bhyveConnPtr driver,
|
|||
vm->pid = -1;
|
||||
vm->def->id = -1;
|
||||
|
||||
bhyveProcessStopHook(vm, VIR_HOOK_BHYVE_OP_RELEASE);
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ VIR_ENUM_DECL(virHookQemuOp);
|
|||
VIR_ENUM_DECL(virHookLxcOp);
|
||||
VIR_ENUM_DECL(virHookNetworkOp);
|
||||
VIR_ENUM_DECL(virHookLibxlOp);
|
||||
VIR_ENUM_DECL(virHookBhyveOp);
|
||||
|
||||
VIR_ENUM_IMPL(virHookDriver,
|
||||
VIR_HOOK_DRIVER_LAST,
|
||||
|
@ -55,6 +56,7 @@ VIR_ENUM_IMPL(virHookDriver,
|
|||
"lxc",
|
||||
"network",
|
||||
"libxl",
|
||||
"bhyve",
|
||||
);
|
||||
|
||||
VIR_ENUM_IMPL(virHookDaemonOp,
|
||||
|
@ -115,6 +117,15 @@ VIR_ENUM_IMPL(virHookLibxlOp,
|
|||
"reconnect",
|
||||
);
|
||||
|
||||
VIR_ENUM_IMPL(virHookBhyveOp,
|
||||
VIR_HOOK_BHYVE_OP_LAST,
|
||||
"start",
|
||||
"stopped",
|
||||
"prepare",
|
||||
"release",
|
||||
"started",
|
||||
);
|
||||
|
||||
static int virHooksFound = -1;
|
||||
|
||||
/**
|
||||
|
@ -283,6 +294,10 @@ virHookCall(int driver,
|
|||
break;
|
||||
case VIR_HOOK_DRIVER_NETWORK:
|
||||
opstr = virHookNetworkOpTypeToString(op);
|
||||
break;
|
||||
case VIR_HOOK_DRIVER_BHYVE:
|
||||
opstr = virHookBhyveOpTypeToString(op);
|
||||
break;
|
||||
}
|
||||
if (opstr == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef enum {
|
|||
VIR_HOOK_DRIVER_LXC, /* LXC domains related events */
|
||||
VIR_HOOK_DRIVER_NETWORK, /* network related events */
|
||||
VIR_HOOK_DRIVER_LIBXL, /* Xen libxl domains related events */
|
||||
VIR_HOOK_DRIVER_BHYVE, /* Bhyve domains related events */
|
||||
|
||||
VIR_HOOK_DRIVER_LAST,
|
||||
} virHookDriverType;
|
||||
|
@ -97,6 +98,16 @@ typedef enum {
|
|||
VIR_HOOK_LIBXL_OP_LAST,
|
||||
} virHookLibxlOpType;
|
||||
|
||||
typedef enum {
|
||||
VIR_HOOK_BHYVE_OP_START, /* domain is about to start */
|
||||
VIR_HOOK_BHYVE_OP_STOPPED, /* domain has stopped */
|
||||
VIR_HOOK_BHYVE_OP_PREPARE, /* domain startup initiated */
|
||||
VIR_HOOK_BHYVE_OP_RELEASE, /* domain destruction is over */
|
||||
VIR_HOOK_BHYVE_OP_STARTED, /* domain has started */
|
||||
|
||||
VIR_HOOK_BHYVE_OP_LAST,
|
||||
} virHookBhyveOpType;
|
||||
|
||||
int virHookInitialize(void);
|
||||
|
||||
int virHookPresent(int driver);
|
||||
|
|
Loading…
Reference in New Issue