aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2024-01-05 06:21:15 +0000
committerKyle Evans <kevans@FreeBSD.org>2024-01-22 17:18:58 +0000
commit3b01995df47a0184ecbb6777b88a3a0bd3c6797c (patch)
treee27e72cc6fa6ef538a84ea08164c5fdf97a93214
parent4bd568bd759bfd632425ee13e5e4e83b6a935525 (diff)
bhyveload: support guest rebooting from the loader
userboot has a EXIT_REBOOT code that it uses when the 'reboot' loader command is executed. Use that and longjmp back to reinit the VM entirely with a reboot request. This fixes the 'reboot' option in the loader menu to actually reboot rather than shutdown the VM. The JMP_* constants are introduced to keep track of why we're doing a longjmp, though they aren't currently used. We'll notably still do a complete reload of the interpreter to give the rebooted VM that new loader smell. It just seemed forward thinking to just keep track of the different setjmp points. While we're here, we don't actually need to keep the fd we passed to fdlopen(3), so let's avoid leaking it. Reviewed by: markj (cherry picked from commit 24cd5c26fe3ef7181e85467d9d55afbd76af5a2c)
-rw-r--r--usr.sbin/bhyveload/bhyveload.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c
index 16131dacecaa..4f16f58bfc9f 100644
--- a/usr.sbin/bhyveload/bhyveload.c
+++ b/usr.sbin/bhyveload/bhyveload.c
@@ -89,6 +89,16 @@
#define NDISKS 32
+/*
+ * Reason for our loader reload and reentry, though these aren't really used
+ * at the moment.
+ */
+enum {
+ /* 0 cannot be allocated; setjmp(3) return. */
+ JMP_SWAPLOADER = 0x01,
+ JMP_REBOOT,
+};
+
static struct termios term, oldterm;
static int disk_fd[NDISKS];
static int ndisks;
@@ -543,6 +553,8 @@ cb_exit(void *arg __unused, int v)
{
tcsetattr(consout_fd, TCSAFLUSH, &oldterm);
+ if (v == USERBOOT_EXIT_REBOOT)
+ longjmp(jb, JMP_REBOOT);
exit(v);
}
@@ -628,7 +640,7 @@ cb_swap_interpreter(void *arg __unused, const char *interp_req)
if (asprintf(&loader, "userboot_%s.so", interp_req) == -1)
err(EX_OSERR, "malloc");
- longjmp(jb, 1);
+ longjmp(jb, JMP_SWAPLOADER);
}
static struct loader_callbacks cb = {
@@ -769,6 +781,8 @@ loader_open(int bootfd)
loader_hdl = fdlopen(fd, RTLD_LOCAL);
if (!loader_hdl)
errx(EX_OSERR, "dlopen: %s", dlerror());
+ if (fd != explicit_loader_fd)
+ close(fd);
}
int