Date: Wed, 25 Jul 2018 04:33:56 +0000 (UTC) From: Marcelo Araujo <araujo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r336704 - stable/11/usr.sbin/bhyve Message-ID: <201807250433.w6P4Xuew010652@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: araujo Date: Wed Jul 25 04:33:56 2018 New Revision: 336704 URL: https://svnweb.freebsd.org/changeset/base/336704 Log: MFC r336188: Improve bhyve exit(3) error code. The bhyve(8) exit status indicates how the VM was terminated: 0 rebooted 1 powered off 2 halted 3 triple fault The problem is when we have wrappers around bhyve that parses the exit error code and gets an exit(1) for an error but interprets it as "powered off". So to mitigate this issue and makes it less error prone for third part applications, I have added a new exit code 4 that is "exited due to an error". For now the bhyve(8) exit status are: 0 rebooted 1 powered off 2 halted 3 triple fault 4 exited due to an error Reviewed by: @jhb Sponsored by: iXsystems Inc. Differential Revision: https://reviews.freebsd.org/D16161 Modified: stable/11/usr.sbin/bhyve/bhyve.8 stable/11/usr.sbin/bhyve/bhyverun.c stable/11/usr.sbin/bhyve/dbgport.c stable/11/usr.sbin/bhyve/fwctl.c stable/11/usr.sbin/bhyve/mevent_test.c stable/11/usr.sbin/bhyve/pci_e82545.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/bhyve/bhyve.8 ============================================================================== --- stable/11/usr.sbin/bhyve/bhyve.8 Wed Jul 25 04:06:09 2018 (r336703) +++ stable/11/usr.sbin/bhyve/bhyve.8 Wed Jul 25 04:33:56 2018 (r336704) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 2, 2017 +.Dd Jul 11, 2018 .Dt BHYVE 8 .Os .Sh NAME @@ -428,6 +428,8 @@ powered off halted .It 3 triple fault +.It 4 +exited due to an error .El .Sh EXAMPLES If not using a boot ROM, the guest operating system must have been loaded with Modified: stable/11/usr.sbin/bhyve/bhyverun.c ============================================================================== --- stable/11/usr.sbin/bhyve/bhyverun.c Wed Jul 25 04:06:09 2018 (r336703) +++ stable/11/usr.sbin/bhyve/bhyverun.c Wed Jul 25 04:33:56 2018 (r336704) @@ -338,7 +338,7 @@ fbsdrun_deletecpu(struct vmctx *ctx, int vcpu) if (!CPU_ISSET(vcpu, &cpumask)) { fprintf(stderr, "Attempting to delete unknown cpu %d\n", vcpu); - exit(1); + exit(4); } CPU_CLR_ATOMIC(vcpu, &cpumask); @@ -672,7 +672,7 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t startrip if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) { fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n", exitcode); - exit(1); + exit(4); } rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu); @@ -683,7 +683,7 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t startrip case VMEXIT_ABORT: abort(); default: - exit(1); + exit(4); } } fprintf(stderr, "vm_run error %d, errno %d\n", error, errno); @@ -715,7 +715,7 @@ fbsdrun_set_capabilities(struct vmctx *ctx, int cpu) err = vm_get_capability(ctx, cpu, VM_CAP_HALT_EXIT, &tmp); if (err < 0) { fprintf(stderr, "VM exit on HLT not supported\n"); - exit(1); + exit(4); } vm_set_capability(ctx, cpu, VM_CAP_HALT_EXIT, 1); if (cpu == BSP) @@ -730,7 +730,7 @@ fbsdrun_set_capabilities(struct vmctx *ctx, int cpu) if (err < 0) { fprintf(stderr, "SMP mux requested, no pause support\n"); - exit(1); + exit(4); } vm_set_capability(ctx, cpu, VM_CAP_PAUSE_EXIT, 1); if (cpu == BSP) @@ -744,7 +744,7 @@ fbsdrun_set_capabilities(struct vmctx *ctx, int cpu) if (err) { fprintf(stderr, "Unable to set x2apic state (%d)\n", err); - exit(1); + exit(4); } vm_set_capability(ctx, cpu, VM_CAP_ENABLE_INVPCID, 1); @@ -780,7 +780,7 @@ do_open(const char *vmname) } } else { perror("vm_create"); - exit(1); + exit(4); } } else { if (!romboot) { @@ -789,14 +789,14 @@ do_open(const char *vmname) * bootrom must be configured to boot it. */ fprintf(stderr, "virtual machine cannot be booted\n"); - exit(1); + exit(4); } } ctx = vm_open(vmname); if (ctx == NULL) { perror("vm_open"); - exit(1); + exit(4); } #ifndef WITHOUT_CAPSICUM @@ -818,7 +818,7 @@ do_open(const char *vmname) error = vm_reinit(ctx); if (error) { perror("vm_reinit"); - exit(1); + exit(4); } } return (ctx); @@ -879,7 +879,7 @@ main(int argc, char *argv[]) break; case 's': if (pci_parse_slot(optarg) != 0) - exit(1); + exit(4); else break; case 'S': @@ -950,7 +950,7 @@ main(int argc, char *argv[]) if (guest_ncpus > max_vcpus) { fprintf(stderr, "%d vCPUs requested but only %d available\n", guest_ncpus, max_vcpus); - exit(1); + exit(4); } fbsdrun_set_capabilities(ctx, BSP); @@ -959,13 +959,13 @@ main(int argc, char *argv[]) err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); if (err) { fprintf(stderr, "Unable to setup memory (%d)\n", errno); - exit(1); + exit(4); } error = init_msr(); if (error) { fprintf(stderr, "init_msr error %d", error); - exit(1); + exit(4); } init_mem(); @@ -980,8 +980,10 @@ main(int argc, char *argv[]) /* * Exit if a device emulation finds an error in it's initilization */ - if (init_pci(ctx) != 0) - exit(1); + if (init_pci(ctx) != 0) { + perror("device emulation initialization error"); + exit(4); + } if (gdb_port != 0) init_dbgport(gdb_port); @@ -993,7 +995,7 @@ main(int argc, char *argv[]) if (vm_set_capability(ctx, BSP, VM_CAP_UNRESTRICTED_GUEST, 1)) { fprintf(stderr, "ROM boot failed: unrestricted guest " "capability not available\n"); - exit(1); + exit(4); } error = vcpu_reset(ctx, BSP); assert(error == 0); @@ -1007,8 +1009,10 @@ main(int argc, char *argv[]) */ if (mptgen) { error = mptable_build(ctx, guest_ncpus); - if (error) - exit(1); + if (error) { + perror("error to build the guest tables"); + exit(4); + } } error = smbios_build(ctx); @@ -1047,5 +1051,5 @@ main(int argc, char *argv[]) */ mevent_dispatch(); - exit(1); + exit(4); } Modified: stable/11/usr.sbin/bhyve/dbgport.c ============================================================================== --- stable/11/usr.sbin/bhyve/dbgport.c Wed Jul 25 04:06:09 2018 (r336703) +++ stable/11/usr.sbin/bhyve/dbgport.c Wed Jul 25 04:33:56 2018 (r336704) @@ -139,8 +139,8 @@ init_dbgport(int sport) conn_fd = -1; if ((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("socket"); - exit(1); + perror("cannot create socket"); + exit(4); } sin.sin_len = sizeof(sin); @@ -151,18 +151,18 @@ init_dbgport(int sport) reuse = 1; if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { - perror("setsockopt"); - exit(1); + perror("cannot set socket options"); + exit(4); } if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - perror("bind"); - exit(1); + perror("cannot bind socket"); + exit(4); } if (listen(listen_fd, 1) < 0) { - perror("listen"); - exit(1); + perror("cannot listen socket"); + exit(4); } #ifndef WITHOUT_CAPSICUM Modified: stable/11/usr.sbin/bhyve/fwctl.c ============================================================================== --- stable/11/usr.sbin/bhyve/fwctl.c Wed Jul 25 04:06:09 2018 (r336703) +++ stable/11/usr.sbin/bhyve/fwctl.c Wed Jul 25 04:33:56 2018 (r336704) @@ -375,7 +375,7 @@ fwctl_request(uint32_t value) /* Verify size */ if (value < 12) { printf("msg size error"); - exit(1); + exit(4); } rinfo.req_size = value; rinfo.req_count = 1; Modified: stable/11/usr.sbin/bhyve/mevent_test.c ============================================================================== --- stable/11/usr.sbin/bhyve/mevent_test.c Wed Jul 25 04:06:09 2018 (r336703) +++ stable/11/usr.sbin/bhyve/mevent_test.c Wed Jul 25 04:33:56 2018 (r336704) @@ -143,7 +143,7 @@ echoer(void *param) mev = mevent_add(fd, EVF_READ, echoer_callback, &sync); if (mev == NULL) { printf("Could not allocate echoer event\n"); - exit(1); + exit(4); } while (!pthread_cond_wait(&sync.e_cond, &sync.e_mt)) { @@ -200,8 +200,8 @@ acceptor(void *param) static int first; if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("socket"); - exit(1); + perror("cannot create socket"); + exit(4); } sin.sin_len = sizeof(sin); @@ -210,13 +210,13 @@ acceptor(void *param) sin.sin_port = htons(TEST_PORT); if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - perror("bind"); - exit(1); + perror("cannot bind socket"); + exit(4); } if (listen(s, 1) < 0) { - perror("listen"); - exit(1); + perror("cannot listen socket"); + exit(4); } (void) mevent_add(s, EVF_READ, acceptor_callback, NULL); Modified: stable/11/usr.sbin/bhyve/pci_e82545.c ============================================================================== --- stable/11/usr.sbin/bhyve/pci_e82545.c Wed Jul 25 04:06:09 2018 (r336703) +++ stable/11/usr.sbin/bhyve/pci_e82545.c Wed Jul 25 04:33:56 2018 (r336704) @@ -2224,7 +2224,7 @@ e82545_open_tap(struct e82545_softc *sc, char *opts) sc->esc_tapfd = open(tbuf, O_RDWR); if (sc->esc_tapfd == -1) { DPRINTF("unable to open tap device %s\n", opts); - exit(1); + exit(4); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807250433.w6P4Xuew010652>