diff options
author | bapt <bapt@FreeBSD.org> | 2015-06-20 00:58:46 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-06-20 00:58:46 +0000 |
commit | bb8dfd5e7e9ae9f11af6d8bc1e6993e7490d8530 (patch) | |
tree | fc0773ee0b0110256bf52c4846f02ccaec2c6e6d /usr.sbin | |
parent | dfe0a3d0ebe1a9f827bcae5ac6c246fa0b50e817 (diff) | |
parent | b7b105f7f3482125c0a0cd3901ba022144b964b1 (diff) | |
download | FreeBSD-src-bb8dfd5e7e9ae9f11af6d8bc1e6993e7490d8530.zip FreeBSD-src-bb8dfd5e7e9ae9f11af6d8bc1e6993e7490d8530.tar.gz |
Merge from head @274131
Diffstat (limited to 'usr.sbin')
45 files changed, 723 insertions, 138 deletions
diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index 70b7041..5a923e0 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -14,6 +14,7 @@ SRCS= \ acpi.c \ bhyverun.c \ block_if.c \ + bootrom.c \ consport.c \ dbgport.c \ inout.c \ diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index ee0f2ca..c5de82a 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -32,7 +32,7 @@ .Nd "run a guest operating system inside a virtual machine" .Sh SYNOPSIS .Nm -.Op Fl abehuwxACHPWY +.Op Fl abehuwxACHPSWY .Op Fl c Ar numcpus .Op Fl g Ar gdbport .Op Fl l Ar lpcdev Ns Op , Ns Ar conf @@ -99,10 +99,12 @@ Yield the virtual CPU thread when a HLT instruction is detected. If this option is not specified, virtual CPUs will use 100% of a host CPU. .It Fl l Ar lpcdev Ns Op , Ns Ar conf Allow devices behind the LPC PCI-ISA bridge to be configured. -The only supported devices are the TTY-class devices, -.Li com1 +The only supported devices are the TTY-class devices +.Ar com1 and -.Li com2 . +.Ar com2 +and the boot ROM device +.Ar bootrom . .It Fl m Ar size Ns Op Ar K|k|M|m|G|g|T|t Guest physical memory size in bytes. This must be the same size that was given to @@ -165,8 +167,8 @@ AHCI controller attached to a SATA hard-drive. .It Li uart PCI 16550 serial device. .It Li lpc -LPC PCI-ISA bridge with COM1 and COM2 16550 serial ports. The LPC bridge -emulation can only be configured on bus 0. +LPC PCI-ISA bridge with COM1 and COM2 16550 serial ports and a boot ROM. +The LPC bridge emulation can only be configured on bus 0. .El .It Op Ar conf This optional parameter describes the backend for device emulations. @@ -224,6 +226,14 @@ the bhyve process. Use the host TTY device for serial port I/O. .El .Pp +Boot ROM device: +.Bl -tag -width 10n +.It Pa romfile +Map +.Ar romfile +in the guest address space reserved for boot firmware. +.El +.Pp Pass-through devices: .Bl -tag -width 10n .It Ns Ar slot Ns / Ns Ar bus Ns / Ns Ar function @@ -235,11 +245,17 @@ and numbers. .El .Pp +Guest memory must be wired using the +.Fl S +option when a pass-through device is configured. +.Pp The host device must have been reserved at boot-time using the .Va pptdev loader variable as described in .Xr vmm 4 . .El +.It Fl S +Wire guest memory. .It Fl u RTC keeps UTC time. .It Fl U Ar uuid diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index ee0f106..cfb3fe4 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include <pthread.h> #include <pthread_np.h> #include <sysexits.h> +#include <stdbool.h> #include <machine/vmm.h> #include <vmmapi.h> @@ -122,7 +123,7 @@ usage(int code) { fprintf(stderr, - "Usage: %s [-abehuwxACHPWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n" + "Usage: %s [-abehuwxACHPSWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n" " %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n" " -a: local apic is in xAPIC mode (deprecated)\n" " -A: create ACPI tables\n" @@ -137,6 +138,7 @@ usage(int code) " -p: pin 'vcpu' to 'hostcpu'\n" " -P: vmexit from the guest on pause\n" " -s: <slot,driver,configinfo> PCI slot config\n" + " -S: guest memory cannot be swapped\n" " -u: RTC keeps UTC time\n" " -U: uuid\n" " -w: ignore unimplemented MSRs\n" @@ -700,26 +702,82 @@ fbsdrun_set_capabilities(struct vmctx *ctx, int cpu) vm_set_capability(ctx, cpu, VM_CAP_ENABLE_INVPCID, 1); } +static struct vmctx * +do_open(const char *vmname) +{ + struct vmctx *ctx; + int error; + bool reinit, romboot; + + reinit = romboot = false; + + if (lpc_bootrom()) + romboot = true; + + error = vm_create(vmname); + if (error) { + if (errno == EEXIST) { + if (romboot) { + reinit = true; + } else { + /* + * The virtual machine has been setup by the + * userspace bootloader. + */ + } + } else { + perror("vm_create"); + exit(1); + } + } else { + if (!romboot) { + /* + * If the virtual machine was just created then a + * bootrom must be configured to boot it. + */ + fprintf(stderr, "virtual machine cannot be booted\n"); + exit(1); + } + } + + ctx = vm_open(vmname); + if (ctx == NULL) { + perror("vm_open"); + exit(1); + } + + if (reinit) { + error = vm_reinit(ctx); + if (error) { + perror("vm_reinit"); + exit(1); + } + } + return (ctx); +} + int main(int argc, char *argv[]) { int c, error, gdb_port, err, bvmcons; - int dump_guest_memory, max_vcpus, mptgen; + int max_vcpus, mptgen, memflags; int rtc_localtime; struct vmctx *ctx; uint64_t rip; size_t memsize; + char *optstr; bvmcons = 0; - dump_guest_memory = 0; progname = basename(argv[0]); gdb_port = 0; guest_ncpus = 1; memsize = 256 * MB; mptgen = 1; rtc_localtime = 1; + memflags = 0; - while ((c = getopt(argc, argv, "abehuwxACHIPWYp:g:c:s:m:l:U:")) != -1) { + optstr = "abehuwxACHIPSWYp:g:c:s:m:l:U:"; + while ((c = getopt(argc, argv, optstr)) != -1) { switch (c) { case 'a': x2apic_mode = 0; @@ -740,7 +798,7 @@ main(int argc, char *argv[]) guest_ncpus = atoi(optarg); break; case 'C': - dump_guest_memory = 1; + memflags |= VM_MEM_F_INCORE; break; case 'g': gdb_port = atoi(optarg); @@ -756,6 +814,9 @@ main(int argc, char *argv[]) exit(1); else break; + case 'S': + memflags |= VM_MEM_F_WIRED; + break; case 'm': error = vm_parse_memsize(optarg, &memsize); if (error) @@ -810,12 +871,7 @@ main(int argc, char *argv[]) usage(1); vmname = argv[0]; - - ctx = vm_open(vmname); - if (ctx == NULL) { - perror("vm_open"); - exit(1); - } + ctx = do_open(vmname); if (guest_ncpus < 1) { fprintf(stderr, "Invalid guest vCPUs (%d)\n", guest_ncpus); @@ -831,11 +887,10 @@ main(int argc, char *argv[]) fbsdrun_set_capabilities(ctx, BSP); - if (dump_guest_memory) - vm_set_memflags(ctx, VM_MEM_F_INCORE); + vm_set_memflags(ctx, memflags); err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); if (err) { - fprintf(stderr, "Unable to setup memory (%d)\n", err); + fprintf(stderr, "Unable to setup memory (%d)\n", errno); exit(1); } @@ -865,6 +920,16 @@ main(int argc, char *argv[]) if (bvmcons) init_bvmcons(); + if (lpc_bootrom()) { + if (vm_set_capability(ctx, BSP, VM_CAP_UNRESTRICTED_GUEST, 1)) { + fprintf(stderr, "ROM boot failed: unrestricted guest " + "capability not available\n"); + exit(1); + } + error = vcpu_reset(ctx, BSP); + assert(error == 0); + } + error = vm_get_register(ctx, BSP, VM_REG_GUEST_RIP, &rip); assert(error == 0); diff --git a/usr.sbin/bhyve/bootrom.c b/usr.sbin/bhyve/bootrom.c new file mode 100644 index 0000000..5e4e0e9 --- /dev/null +++ b/usr.sbin/bhyve/bootrom.c @@ -0,0 +1,111 @@ +/*- + * Copyright (c) 2015 Neel Natu <neel@freebsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/param.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> + +#include <machine/vmm.h> + +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdbool.h> + +#include <vmmapi.h> +#include "bhyverun.h" +#include "bootrom.h" + +#define MAX_BOOTROM_SIZE (16 * 1024 * 1024) /* 16 MB */ + +int +bootrom_init(struct vmctx *ctx, const char *romfile) +{ + struct stat sbuf; + vm_paddr_t gpa; + ssize_t rlen; + char *ptr; + int fd, i, rv, prot; + + rv = -1; + fd = open(romfile, O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Error opening bootrom \"%s\": %s\n", + romfile, strerror(errno)); + goto done; + } + + if (fstat(fd, &sbuf) < 0) { + fprintf(stderr, "Could not fstat bootrom file \"%s\": %s\n", + romfile, strerror(errno)); + goto done; + } + + /* + * Limit bootrom size to 16MB so it doesn't encroach into reserved + * MMIO space (e.g. APIC, HPET, MSI). + */ + if (sbuf.st_size > MAX_BOOTROM_SIZE || sbuf.st_size < PAGE_SIZE) { + fprintf(stderr, "Invalid bootrom size %ld\n", sbuf.st_size); + goto done; + } + + if (sbuf.st_size & PAGE_MASK) { + fprintf(stderr, "Bootrom size %ld is not a multiple of the " + "page size\n", sbuf.st_size); + goto done; + } + + ptr = vm_create_devmem(ctx, VM_BOOTROM, "bootrom", sbuf.st_size); + if (ptr == MAP_FAILED) + goto done; + + /* Map the bootrom into the guest address space */ + prot = PROT_READ | PROT_EXEC; + gpa = (1ULL << 32) - sbuf.st_size; + if (vm_mmap_memseg(ctx, gpa, VM_BOOTROM, 0, sbuf.st_size, prot) != 0) + goto done; + + /* Read 'romfile' into the guest address space */ + for (i = 0; i < sbuf.st_size / PAGE_SIZE; i++) { + rlen = read(fd, ptr + i * PAGE_SIZE, PAGE_SIZE); + if (rlen != PAGE_SIZE) { + fprintf(stderr, "Incomplete read of page %d of bootrom " + "file %s: %ld bytes\n", i, romfile, rlen); + goto done; + } + } + rv = 0; +done: + if (fd >= 0) + close(fd); + return (rv); +} diff --git a/usr.sbin/bhyve/bootrom.h b/usr.sbin/bhyve/bootrom.h new file mode 100644 index 0000000..af150d3 --- /dev/null +++ b/usr.sbin/bhyve/bootrom.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2015 Neel Natu <neel@freebsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _BOOTROM_H_ +#define _BOOTROM_H_ + +#include <stdbool.h> + +struct vmctx; + +int bootrom_init(struct vmctx *ctx, const char *romfile); + +#endif diff --git a/usr.sbin/bhyve/pci_lpc.c b/usr.sbin/bhyve/pci_lpc.c index e98b141..2203a00 100644 --- a/usr.sbin/bhyve/pci_lpc.c +++ b/usr.sbin/bhyve/pci_lpc.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include <vmmapi.h> #include "acpi.h" +#include "bootrom.h" #include "inout.h" #include "pci_emul.h" #include "pci_irq.h" @@ -62,6 +63,8 @@ SYSRES_IO(NMISC_PORT, 1); static struct pci_devinst *lpc_bridge; +static const char *romfile; + #define LPC_UART_NUM 2 static struct lpc_uart_softc { struct uart_softc *uart_softc; @@ -76,7 +79,7 @@ static const char *lpc_uart_names[LPC_UART_NUM] = { "COM1", "COM2" }; /* * LPC device configuration is in the following form: * <lpc_device_name>[,<options>] - * For e.g. "com1,stdio" + * For e.g. "com1,stdio" or "bootrom,/var/romfile" */ int lpc_device_parse(const char *opts) @@ -88,6 +91,11 @@ lpc_device_parse(const char *opts) str = cpy = strdup(opts); lpcdev = strsep(&str, ","); if (lpcdev != NULL) { + if (strcasecmp(lpcdev, "bootrom") == 0) { + romfile = str; + error = 0; + goto done; + } for (unit = 0; unit < LPC_UART_NUM; unit++) { if (strcasecmp(lpcdev, lpc_uart_names[unit]) == 0) { lpc_uart_softc[unit].opts = str; @@ -104,6 +112,13 @@ done: return (error); } +const char * +lpc_bootrom(void) +{ + + return (romfile); +} + static void lpc_uart_intr_assert(void *arg) { @@ -156,13 +171,19 @@ lpc_uart_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, } static int -lpc_init(void) +lpc_init(struct vmctx *ctx) { struct lpc_uart_softc *sc; struct inout_port iop; const char *name; int unit, error; + if (romfile != NULL) { + error = bootrom_init(ctx, romfile); + if (error) + return (error); + } + /* COM1 and COM2 */ for (unit = 0; unit < LPC_UART_NUM; unit++) { sc = &lpc_uart_softc[unit]; @@ -379,7 +400,7 @@ pci_lpc_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) return (-1); } - if (lpc_init() != 0) + if (lpc_init(ctx) != 0) return (-1); /* initialize config space */ diff --git a/usr.sbin/bhyve/pci_lpc.h b/usr.sbin/bhyve/pci_lpc.h index 55a5865..431f5cf 100644 --- a/usr.sbin/bhyve/pci_lpc.h +++ b/usr.sbin/bhyve/pci_lpc.h @@ -68,5 +68,6 @@ struct lpc_sysres { int lpc_device_parse(const char *opt); char *lpc_pirq_name(int pin); void lpc_pirq_routed(void); +const char *lpc_bootrom(void); #endif diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 04d68c4..5b52b05 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -548,12 +548,18 @@ done: static int passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { - int bus, slot, func, error; + int bus, slot, func, error, memflags; struct passthru_softc *sc; sc = NULL; error = 1; + memflags = vm_get_memflags(ctx); + if (!(memflags & VM_MEM_F_WIRED)) { + fprintf(stderr, "passthru requires guest memory to be wired\n"); + goto done; + } + if (pcifd < 0) { pcifd = open(_PATH_DEVPCI, O_RDWR, 0); if (pcifd < 0) diff --git a/usr.sbin/bhyvectl/Makefile b/usr.sbin/bhyvectl/Makefile index 5c088a3..c48ca6e 100644 --- a/usr.sbin/bhyvectl/Makefile +++ b/usr.sbin/bhyvectl/Makefile @@ -8,7 +8,7 @@ PACKAGE= bhyve MAN= -LIBADD= vmmapi +LIBADD= vmmapi util WARNS?= 3 diff --git a/usr.sbin/bhyvectl/bhyvectl.c b/usr.sbin/bhyvectl/bhyvectl.c index 7d3017f..51bade1 100644 --- a/usr.sbin/bhyvectl/bhyvectl.c +++ b/usr.sbin/bhyvectl/bhyvectl.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include <sys/sysctl.h> #include <sys/errno.h> #include <sys/mman.h> +#include <sys/cpuset.h> #include <stdio.h> #include <stdlib.h> @@ -47,10 +48,12 @@ __FBSDID("$FreeBSD$"); #include <getopt.h> #include <time.h> #include <assert.h> +#include <libutil.h> #include <machine/cpufunc.h> -#include <machine/vmm.h> #include <machine/specialreg.h> +#include <machine/vmm.h> +#include <machine/vmm_dev.h> #include <vmmapi.h> #include "amd/vmcb.h" @@ -236,7 +239,7 @@ static int get_stats, getcap, setcap, capval, get_gpa_pmap; static int inject_nmi, assert_lapic_lvt; static int force_reset, force_poweroff; static const char *capname; -static int create, destroy, get_lowmem, get_highmem; +static int create, destroy, get_memmap, get_memseg; static int get_intinfo; static int get_active_cpus, get_suspended_cpus; static uint64_t memsize; @@ -1320,8 +1323,8 @@ setup_options(bool cpu_intel) { "get-desc-gdtr", NO_ARG, &get_desc_gdtr, 1 }, { "set-desc-idtr", NO_ARG, &set_desc_idtr, 1 }, { "get-desc-idtr", NO_ARG, &get_desc_idtr, 1 }, - { "get-lowmem", NO_ARG, &get_lowmem, 1 }, - { "get-highmem",NO_ARG, &get_highmem, 1 }, + { "get-memmap", NO_ARG, &get_memmap, 1 }, + { "get-memseg", NO_ARG, &get_memseg, 1 }, { "get-efer", NO_ARG, &get_efer, 1 }, { "get-cr0", NO_ARG, &get_cr0, 1 }, { "get-cr3", NO_ARG, &get_cr3, 1 }, @@ -1520,18 +1523,92 @@ mon_str(int idx) return ("UNK"); } +static int +show_memmap(struct vmctx *ctx) +{ + char name[SPECNAMELEN + 1], numbuf[8]; + vm_ooffset_t segoff; + vm_paddr_t gpa; + size_t maplen, seglen; + int error, flags, prot, segid, delim; + + printf("Address Length Segment Offset "); + printf("Prot Flags\n"); + + gpa = 0; + while (1) { + error = vm_mmap_getnext(ctx, &gpa, &segid, &segoff, &maplen, + &prot, &flags); + if (error) + return (errno == ENOENT ? 0 : error); + + error = vm_get_memseg(ctx, segid, &seglen, name, sizeof(name)); + if (error) + return (error); + + printf("%-12lX", gpa); + humanize_number(numbuf, sizeof(numbuf), maplen, "B", + HN_AUTOSCALE, HN_NOSPACE); + printf("%-12s", numbuf); + + printf("%-12s", name[0] ? name : "sysmem"); + printf("%-12lX", segoff); + printf("%c%c%c ", prot & PROT_READ ? 'R' : '-', + prot & PROT_WRITE ? 'W' : '-', + prot & PROT_EXEC ? 'X' : '-'); + + delim = '\0'; + if (flags & VM_MEMMAP_F_WIRED) { + printf("%cwired", delim); + delim = '/'; + } + if (flags & VM_MEMMAP_F_IOMMU) { + printf("%ciommu", delim); + delim = '/'; + } + printf("\n"); + + gpa += maplen; + } +} + +static int +show_memseg(struct vmctx *ctx) +{ + char name[SPECNAMELEN + 1], numbuf[8]; + size_t seglen; + int error, segid; + + printf("ID Length Name\n"); + + segid = 0; + while (1) { + error = vm_get_memseg(ctx, segid, &seglen, name, sizeof(name)); + if (error) + return (errno == EINVAL ? 0 : error); + + if (seglen) { + printf("%-4d", segid); + humanize_number(numbuf, sizeof(numbuf), seglen, "B", + HN_AUTOSCALE, HN_NOSPACE); + printf("%-12s", numbuf); + printf("%s", name[0] ? name : "sysmem"); + printf("\n"); + } + segid++; + } +} + int main(int argc, char *argv[]) { char *vmname; int error, ch, vcpu, ptenum; - vm_paddr_t gpa, gpa_pmap; - size_t len; + vm_paddr_t gpa_pmap; struct vm_exit vmexit; uint64_t rax, cr0, cr3, cr4, dr7, rsp, rip, rflags, efer, pat; uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2]; struct vmctx *ctx; - int wired; cpuset_t cpus; bool cpu_intel; uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; @@ -1703,7 +1780,7 @@ main(int argc, char *argv[]) } if (!error && memsize) - error = vm_setup_memory(ctx, memsize, VM_MMAP_NONE); + error = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); if (!error && set_efer) error = vm_set_register(ctx, vcpu, VM_REG_GUEST_EFER, efer); @@ -1838,21 +1915,11 @@ main(int argc, char *argv[]) error = vm_lapic_local_irq(ctx, vcpu, assert_lapic_lvt); } - if (!error && (get_lowmem || get_all)) { - gpa = 0; - error = vm_get_memory_seg(ctx, gpa, &len, &wired); - if (error == 0) - printf("lowmem\t\t0x%016lx/%ld%s\n", gpa, len, - wired ? " wired" : ""); - } + if (!error && (get_memseg || get_all)) + error = show_memseg(ctx); - if (!error && (get_highmem || get_all)) { - gpa = 4 * GB; - error = vm_get_memory_seg(ctx, gpa, &len, &wired); - if (error == 0) - printf("highmem\t\t0x%016lx/%ld%s\n", gpa, len, - wired ? " wired" : ""); - } + if (!error && (get_memmap || get_all)) + error = show_memmap(ctx); if (!error) error = get_all_registers(ctx, vcpu); diff --git a/usr.sbin/bhyveload/bhyveload.8 b/usr.sbin/bhyveload/bhyveload.8 index c168832..fc9c8e1 100644 --- a/usr.sbin/bhyveload/bhyveload.8 +++ b/usr.sbin/bhyveload/bhyveload.8 @@ -35,6 +35,7 @@ guest inside a bhyve virtual machine .Sh SYNOPSIS .Nm +.Op Fl S .Op Fl c Ar cons-dev .Op Fl d Ar disk-path .Op Fl e Ar name=value @@ -111,8 +112,10 @@ respectively. The default value of .Ar mem-size is 256M. -.El +.It Fl S +Wire guest memory. .Sh EXAMPLES +.El To create a virtual machine named .Ar freebsd-vm that boots off the ISO image diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c index 8ebf116..8178bb2 100644 --- a/usr.sbin/bhyveload/bhyveload.c +++ b/usr.sbin/bhyveload/bhyveload.c @@ -629,7 +629,7 @@ usage(void) { fprintf(stderr, - "usage: %s [-c <console-device>] [-d <disk-path>] [-e <name=value>]\n" + "usage: %s [-S][-c <console-device>] [-d <disk-path>] [-e <name=value>]\n" " %*s [-h <host-path>] [-m mem-size] <vmname>\n", progname, (int)strlen(progname), ""); @@ -642,16 +642,17 @@ main(int argc, char** argv) void *h; void (*func)(struct loader_callbacks *, void *, int, int); uint64_t mem_size; - int opt, error, need_reinit; + int opt, error, need_reinit, memflags; progname = basename(argv[0]); + memflags = 0; mem_size = 256 * MB; consin_fd = STDIN_FILENO; consout_fd = STDOUT_FILENO; - while ((opt = getopt(argc, argv, "c:d:e:h:m:")) != -1) { + while ((opt = getopt(argc, argv, "Sc:d:e:h:m:")) != -1) { switch (opt) { case 'c': error = altcons_open(optarg); @@ -678,6 +679,9 @@ main(int argc, char** argv) if (error != 0) errx(EX_USAGE, "Invalid memsize '%s'", optarg); break; + case 'S': + memflags |= VM_MEM_F_WIRED; + break; case '?': usage(); } @@ -715,6 +719,7 @@ main(int argc, char** argv) } } + vm_set_memflags(ctx, memflags); error = vm_setup_memory(ctx, mem_size, VM_MMAP_ALL); if (error) { perror("vm_setup_memory"); diff --git a/usr.sbin/bsdconfig/usermgmt/share/group.subr b/usr.sbin/bsdconfig/usermgmt/share/group.subr index fb320d1..e9c8b16 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/group.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/group.subr @@ -82,9 +82,9 @@ f_group_add() # # NB: pw(8) has a ``feature'' wherein `-n name' can be taken as GID # instead of name. Work-around is to also pass `-g GID' at the same - # time (any GID will do; but `-1' is appropriate for this context). + # time (the GID is ignored in this case, so any GID will do). # - if [ "$input" ] && f_quietly pw groupshow -n "$input" -g -1; then + if [ "$input" ] && f_quietly pw groupshow -n "$input" -g 1337; then f_show_err "$msg_group_already_used" "$input" return $FAILURE fi @@ -182,7 +182,7 @@ f_group_add() 1) # Group Name (prompt for new group name) f_dialog_input_group_name input "$group_name" || continue - if f_quietly pw groupshow -n "$input" -g -1; then + if f_quietly pw groupshow -n "$input" -g 1337; then f_show_err "$msg_group_already_used" "$input" continue fi @@ -368,9 +368,9 @@ f_group_edit() # # NB: pw(8) has a ``feature'' wherein `-n name' can be taken as GID # instead of name. Work-around is to also pass `-g GID' at the same - # time (any GID will do; but `-1' is appropriate for this context). + # time (the GID is ignored in this case, so any GID will do). # - if [ "$input" ] && ! f_quietly pw groupshow -n "$input" -g -1; then + if [ "$input" ] && ! f_quietly pw groupshow -n "$input" -g 1337; then f_show_err "$msg_group_not_found" "$input" return $FAILURE fi diff --git a/usr.sbin/bsdconfig/usermgmt/share/user.subr b/usr.sbin/bsdconfig/usermgmt/share/user.subr index d0e3887..27d9d66 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/user.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/user.subr @@ -231,9 +231,9 @@ f_user_add() # # NB: pw(8) has a ``feature'' wherein `-n name' can be taken as UID # instead of name. Work-around is to also pass `-u UID' at the same - # time (any UID will do; but `-1' is appropriate for this context). + # time (the UID is ignored in this case, so any UID will do). # - if [ "$input" ] && f_quietly pw usershow -n "$input" -u -1; then + if [ "$input" ] && f_quietly pw usershow -n "$input" -u 1337; then f_show_err "$msg_login_already_used" "$input" return $FAILURE fi @@ -414,7 +414,7 @@ f_user_add() 1) # Login (prompt for new login name) f_dialog_input_name input "$user_name" || continue - if f_quietly pw usershow -n "$input" -u -1; then + if f_quietly pw usershow -n "$input" -u 1337; then f_show_err "$msg_login_already_used" "$input" continue fi @@ -920,9 +920,9 @@ f_user_edit() # # NB: pw(8) has a ``feature'' wherein `-n name' can be taken as UID # instead of name. Work-around is to also pass `-u UID' at the same - # time (any UID will do; but `-1' is appropriate for this context). + # time (the UID is ignored in this case, so any UID will do). # - if [ "$input" ] && ! f_quietly pw usershow -n "$input" -u -1; then + if [ "$input" ] && ! f_quietly pw usershow -n "$input" -u 1337; then f_show_err "$msg_login_not_found" "$input" return $FAILURE fi diff --git a/usr.sbin/bsnmpd/modules/snmp_atm/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_atm/Makefile.depend index a511f26..06b5e37 100644 --- a/usr.sbin/bsnmpd/modules/snmp_atm/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_atm/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile.depend index 24fcca9..7d1ccb6 100644 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile.depend index d6b14d8..64bb2df 100644 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_lm75/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_lm75/Makefile.depend index 98ed0f6..ea1a0a5 100644 --- a/usr.sbin/bsnmpd/modules/snmp_lm75/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_lm75/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile.depend index 25da87b..8e546b0 100644 --- a/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile.depend index 547a1b8..19bbcd5 100644 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile.depend index 868588e..6843d75 100644 --- a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_target/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_target/Makefile.depend index 7b6ccee..c8536c4 100644 --- a/usr.sbin/bsnmpd/modules/snmp_target/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_target/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_usm/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_usm/Makefile.depend index 143eb6b..2e9a3fe 100644 --- a/usr.sbin/bsnmpd/modules/snmp_usm/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_usm/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile.depend index c3e56fe..25501c8 100644 --- a/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_vacm/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile.depend b/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile.depend index 5e42346..80b1aea 100644 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile.depend +++ b/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/crunch/crunchgen/Makefile.depend b/usr.sbin/crunch/crunchgen/Makefile.depend index 11f6434..f384605 100644 --- a/usr.sbin/crunch/crunchgen/Makefile.depend +++ b/usr.sbin/crunch/crunchgen/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ diff --git a/usr.sbin/ctld/token.l b/usr.sbin/ctld/token.l index 54b803b..caf59cc 100644 --- a/usr.sbin/ctld/token.l +++ b/usr.sbin/ctld/token.l @@ -80,7 +80,7 @@ target { return TARGET; } timeout { return TIMEOUT; } \"[^"]+\" { yylval.str = strndup(yytext + 1, strlen(yytext) - 2); return STR; } -[a-zA-Z0-9\.\-_/\:\[\]]+ { yylval.str = strdup(yytext); return STR; } +[a-zA-Z0-9\.\-@_/\:\[\]]+ { yylval.str = strdup(yytext); return STR; } \{ { return OPENING_BRACKET; } \} { return CLOSING_BRACKET; } #.*$ /* ignore comments */; diff --git a/usr.sbin/fstyp/Makefile b/usr.sbin/fstyp/Makefile index d0b14d1..d1de06e 100644 --- a/usr.sbin/fstyp/Makefile +++ b/usr.sbin/fstyp/Makefile @@ -1,9 +1,41 @@ # $FreeBSD$ +.include <src.opts.mk> + PROG= fstyp -SRCS= fstyp.c ext2fs.c cd9660.c msdosfs.c ntfs.c ufs.c +SRCS= cd9660.c ext2fs.c fstyp.c geli.c msdosfs.c ntfs.c ufs.c + +.if ${MK_CDDL} != "no" +SRCS += zfs.c +.endif + MAN= fstyp.8 WARNS= 6 +.if ${MK_CDDL} != "no" +IGNORE_PRAGMA= YES + +CFLAGS+= -DNEED_SOLARIS_BOOLEAN -DHAVE_CDDL +CFLAGS+= -I${.CURDIR}/../../sys/cddl/compat/opensolaris +CFLAGS+= -I${.CURDIR}/../../cddl/compat/opensolaris/include +CFLAGS+= -I${.CURDIR}/../../cddl/compat/opensolaris/lib/libumem +CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libnvpair +CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libzpool/common +CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common/fs/zfs +CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common +CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common/sys +CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/head +.endif + +CFLAGS+=-I${.CURDIR}/../../sys + +DPADD= ${LIBGEOM} ${LIBMD} +LDADD= -lgeom -lmd + +.if ${MK_CDDL} != "no" +DPADD += ${LIBNVPAIR} ${LIBZFS} +LDADD += -lnvpair -lzfs +.endif + .include <bsd.prog.mk> diff --git a/usr.sbin/fstyp/cd9660.c b/usr.sbin/fstyp/cd9660.c index ee6af11..658af33 100644 --- a/usr.sbin/fstyp/cd9660.c +++ b/usr.sbin/fstyp/cd9660.c @@ -45,7 +45,6 @@ int fstyp_cd9660(FILE *fp, char *label, size_t size) { char *sector, *volume; - int i; sector = read_buf(fp, ISO9660_OFFSET, 512); if (sector == NULL) @@ -58,13 +57,6 @@ fstyp_cd9660(FILE *fp, char *label, size_t size) bzero(label, size); strlcpy(label, volume, MIN(size, VOLUME_LEN)); free(sector); - for (i = size - 1; i > 0; i--) { - if (label[i] == '\0') - continue; - else if (label[i] == ' ') - label[i] = '\0'; - else - break; - } + rtrim(label, size); return (0); } diff --git a/usr.sbin/fstyp/fstyp.8 b/usr.sbin/fstyp/fstyp.8 index 5223f81..981a8d3 100644 --- a/usr.sbin/fstyp/fstyp.8 +++ b/usr.sbin/fstyp/fstyp.8 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 14, 2015 +.Dd June 15, 2015 .Dt FSTYP 8 .Os .Sh NAME @@ -37,20 +37,42 @@ .Nm .Op Fl l .Op Fl s +.Op Fl u .Ar special .Sh DESCRIPTION The .Nm utility is used to determine the filesystem type on a given device. It can recognize ISO-9660, Ext2, FAT, NTFS, and UFS filesystems. +When the +.Fl u +flag is specified, +.Nm +also recognizes certain additional metadata formats that cannot be +handled using +.Xr mount 8 , +such as ZFS pools and +.Xr geli 8 +providers. +.Pp The filesystem name is printed to the standard output -as, respectively, -.Li cd9660 , -.Li ext2fs , -.Li msdosfs , -.Li ntfs , -or -.Li ufs . +as, respectively: +.Bl -item -offset indent -compact +.It +cd9660 +.It +ext2fs +.It +geli +.It +msdosfs +.It +ntfs +.It +ufs +.It +zfs +.El .Pp Because .Nm @@ -73,6 +95,9 @@ By default, only works on regular files and disk-like device nodes. Trying to read other file types might have unexpected consequences or hang indefinitely. +.It Fl u +Include filesystems and devices that cannot be mounted directly by +.Xr mount 8 . .El .Sh EXIT STATUS The @@ -82,8 +107,11 @@ type is not recognized. .Sh SEE ALSO .Xr file 1 , .Xr capsicum 4 , +.Xr autofs 8 , +.Xr geli 8 , .Xr glabel 8 , -.Xr mount 8 +.Xr mount 8 , +.Xr zpool 8 .Sh HISTORY The .Nm @@ -95,3 +123,5 @@ The utility was developed by .An Edward Tomasz Napierala Aq Mt trasz@FreeBSD.org under sponsorship from the FreeBSD Foundation. +ZFS and GELI support was added by +.An Allan Jude Aq Mt allanjude@FreeBSD.org diff --git a/usr.sbin/fstyp/fstyp.c b/usr.sbin/fstyp/fstyp.c index d6a48f6..95218ca 100644 --- a/usr.sbin/fstyp/fstyp.c +++ b/usr.sbin/fstyp/fstyp.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <errno.h> #include <stdbool.h> +#include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -54,13 +55,18 @@ typedef int (*fstyp_function)(FILE *, char *, size_t); static struct { const char *name; fstyp_function function; + bool unmountable; } fstypes[] = { - { "cd9660", &fstyp_cd9660 }, - { "ext2fs", &fstyp_ext2fs }, - { "msdosfs", &fstyp_msdosfs }, - { "ntfs", &fstyp_ntfs }, - { "ufs", &fstyp_ufs }, - { NULL, NULL } + { "cd9660", &fstyp_cd9660, false }, + { "ext2fs", &fstyp_ext2fs, false }, + { "geli", &fstyp_geli, true }, + { "msdosfs", &fstyp_msdosfs, false }, + { "ntfs", &fstyp_ntfs, false }, + { "ufs", &fstyp_ufs, false }, +#ifdef HAVE_CDDL + { "zfs", &fstyp_zfs, true }, +#endif + { NULL, NULL, NULL } }; void * @@ -104,11 +110,26 @@ checked_strdup(const char *s) return (c); } +void +rtrim(char *label, size_t size) +{ + ptrdiff_t i; + + for (i = size - 1; i >= 0; i--) { + if (label[i] == '\0') + continue; + else if (label[i] == ' ') + label[i] = '\0'; + else + break; + } +} + static void usage(void) { - fprintf(stderr, "usage: fstyp [-l][-s] special\n"); + fprintf(stderr, "usage: fstyp [-l] [-s] [-u] special\n"); exit(1); } @@ -137,13 +158,13 @@ int main(int argc, char **argv) { int ch, error, i, nbytes; - bool ignore_type = false, show_label = false; + bool ignore_type = false, show_label = false, show_unmountable = false; char label[LABEL_LEN + 1], strvised[LABEL_LEN * 4 + 1]; char *path; FILE *fp; fstyp_function fstyp_f; - while ((ch = getopt(argc, argv, "ls")) != -1) { + while ((ch = getopt(argc, argv, "lsu")) != -1) { switch (ch) { case 'l': show_label = true; @@ -151,6 +172,9 @@ main(int argc, char **argv) case 's': ignore_type = true; break; + case 'u': + show_unmountable = true; + break; default: usage(); } @@ -177,6 +201,8 @@ main(int argc, char **argv) memset(label, '\0', sizeof(label)); for (i = 0;; i++) { + if (show_unmountable == false && fstypes[i].unmountable == true) + continue; fstyp_f = fstypes[i].function; if (fstyp_f == NULL) break; diff --git a/usr.sbin/fstyp/fstyp.h b/usr.sbin/fstyp/fstyp.h index 4474ffe..ca778ba 100644 --- a/usr.sbin/fstyp/fstyp.h +++ b/usr.sbin/fstyp/fstyp.h @@ -36,11 +36,16 @@ void *read_buf(FILE *fp, off_t off, size_t len); char *checked_strdup(const char *s); +void rtrim(char *label, size_t size); int fstyp_cd9660(FILE *fp, char *label, size_t size); int fstyp_ext2fs(FILE *fp, char *label, size_t size); +int fstyp_geli(FILE *fp, char *label, size_t size); int fstyp_msdosfs(FILE *fp, char *label, size_t size); int fstyp_ntfs(FILE *fp, char *label, size_t size); int fstyp_ufs(FILE *fp, char *label, size_t size); +#ifdef HAVE_CDDL +int fstyp_zfs(FILE *fp, char *label, size_t size); +#endif #endif /* !FSTYP_H */ diff --git a/usr.sbin/fstyp/geli.c b/usr.sbin/fstyp/geli.c new file mode 100644 index 0000000..1c15ca6 --- /dev/null +++ b/usr.sbin/fstyp/geli.c @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> + * All rights reserved. + * + * This software was developed by Edward Tomasz Napierala under sponsorship + * from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/disk.h> +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <geom/eli/g_eli.h> + +#include "fstyp.h" + +int +fstyp_geli(FILE *fp, char *label __unused, size_t labelsize __unused) +{ + int error; + off_t mediasize; + u_int sectorsize; + struct g_eli_metadata md; + u_char *buf; + + error = ioctl(fileno(fp), DIOCGMEDIASIZE, &mediasize); + if (error != 0) + return (1); + error = ioctl(fileno(fp), DIOCGSECTORSIZE, §orsize); + if (error != 0) + return (1); + buf = (u_char *)read_buf(fp, mediasize - sectorsize, sectorsize); + if (buf == NULL) + goto gelierr; + error = eli_metadata_decode(buf, &md); + if (error) + goto gelierr; + + if (strncmp(md.md_magic, "GEOM::ELI", 9) == 0) { + free(buf); + return (0); + } + +gelierr: + free(buf); + + return (1); +} diff --git a/usr.sbin/fstyp/msdosfs.c b/usr.sbin/fstyp/msdosfs.c index b299243..3d86802 100644 --- a/usr.sbin/fstyp/msdosfs.c +++ b/usr.sbin/fstyp/msdosfs.c @@ -48,7 +48,6 @@ fstyp_msdosfs(FILE *fp, char *label, size_t size) FAT32_BSBPB *pfat32_bsbpb; FAT_DES *pfat_entry; uint8_t *sector0, *sector; - uint32_t i; sector0 = NULL; sector = NULL; @@ -161,14 +160,7 @@ fstyp_msdosfs(FILE *fp, char *label, size_t size) } endofchecks: - for (i = size - 1; i > 0; i--) { - if (label[i] == '\0') - continue; - else if (label[i] == ' ') - label[i] = '\0'; - else - break; - } + rtrim(label, size); free(sector0); free(sector); diff --git a/usr.sbin/fstyp/zfs.c b/usr.sbin/fstyp/zfs.c new file mode 100644 index 0000000..9d91db6 --- /dev/null +++ b/usr.sbin/fstyp/zfs.c @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> + * All rights reserved. + * + * This software was developed by Edward Tomasz Napierala under sponsorship + * from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <libnvpair.h> +#include <sys/vdev_impl.h> + +#include "fstyp.h" + +int +fstyp_zfs(FILE *fp, char *label, size_t labelsize) +{ + vdev_label_t *zpool_ptr = NULL; + vdev_label_t zpool_label; + char *buf = zpool_label.vl_vdev_phys.vp_nvlist; + char *zpool_name = NULL; + size_t buflen = sizeof (zpool_label.vl_vdev_phys.vp_nvlist); + nvlist_t *config = NULL; + + zpool_ptr = (vdev_label_t *)read_buf(fp, 0, sizeof(zpool_label)); + if (zpool_ptr == NULL) + return (1); + zpool_label = *zpool_ptr; + if (nvlist_unpack(buf, buflen, &config, 0) != 0) + goto zfserr; + if (nvlist_lookup_string(config, "name", &zpool_name) != 0) + goto zfserr; + strlcpy(label, zpool_name, labelsize); + nvlist_free(config); + free(zpool_ptr); + return (0); + +zfserr: + nvlist_free(config); + free(zpool_ptr); + + return (1); +} diff --git a/usr.sbin/nologin/Makefile.depend b/usr.sbin/nologin/Makefile.depend index cae7e64..9cb890b 100644 --- a/usr.sbin/nologin/Makefile.depend +++ b/usr.sbin/nologin/Makefile.depend @@ -3,6 +3,7 @@ DIRDEPS = \ gnu/lib/csu \ + gnu/lib/libgcc \ include \ lib/${CSU_DIR} \ lib/libc \ diff --git a/usr.sbin/ntp/libntp/Makefile.depend b/usr.sbin/ntp/libntp/Makefile.depend index 3214852..aa72b94 100644 --- a/usr.sbin/ntp/libntp/Makefile.depend +++ b/usr.sbin/ntp/libntp/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ include \ include/arpa \ include/xlocale \ diff --git a/usr.sbin/ntp/ntp-keygen/Makefile.depend b/usr.sbin/ntp/ntp-keygen/Makefile.depend index 47e365e..88a55c0 100644 --- a/usr.sbin/ntp/ntp-keygen/Makefile.depend +++ b/usr.sbin/ntp/ntp-keygen/Makefile.depend @@ -10,7 +10,6 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/libmd \ lib/libthr \ lib/msun \ secure/lib/libcrypto \ diff --git a/usr.sbin/ntp/ntpd/Makefile.depend b/usr.sbin/ntp/ntpd/Makefile.depend index c2cd9f7..0fc69e4 100644 --- a/usr.sbin/ntp/ntpd/Makefile.depend +++ b/usr.sbin/ntp/ntpd/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ @@ -11,8 +10,6 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/libmd \ - lib/librt \ lib/libthr \ lib/msun \ secure/lib/libcrypto \ diff --git a/usr.sbin/ntp/ntpdate/Makefile.depend b/usr.sbin/ntp/ntpdate/Makefile.depend index 986d60f..31c07ab 100644 --- a/usr.sbin/ntp/ntpdate/Makefile.depend +++ b/usr.sbin/ntp/ntpdate/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ @@ -11,12 +10,9 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/libmd \ - lib/librt \ lib/libthr \ lib/msun \ secure/lib/libcrypto \ - secure/lib/libssl \ usr.sbin/ntp/libntp \ diff --git a/usr.sbin/ntp/ntpdc/Makefile.depend b/usr.sbin/ntp/ntpdc/Makefile.depend index ffa29bb..7531e73 100644 --- a/usr.sbin/ntp/ntpdc/Makefile.depend +++ b/usr.sbin/ntp/ntpdc/Makefile.depend @@ -2,10 +2,8 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ - gnu/lib/libreadline/readline \ include \ include/arpa \ include/xlocale \ @@ -13,13 +11,10 @@ DIRDEPS = \ lib/libc \ lib/libcompiler_rt \ lib/libedit \ - lib/libmd \ lib/libthr \ lib/msun \ - lib/ncurses/ncurses \ lib/ncurses/ncursesw \ secure/lib/libcrypto \ - secure/lib/libssl \ usr.sbin/ntp/libntp \ usr.sbin/ntp/libopts \ diff --git a/usr.sbin/ntp/ntpq/Makefile.depend b/usr.sbin/ntp/ntpq/Makefile.depend index ac816a3..7531e73 100644 --- a/usr.sbin/ntp/ntpq/Makefile.depend +++ b/usr.sbin/ntp/ntpq/Makefile.depend @@ -2,7 +2,6 @@ # Autogenerated - do NOT edit! DIRDEPS = \ - bin/cat.host \ gnu/lib/csu \ gnu/lib/libgcc \ include \ @@ -12,12 +11,10 @@ DIRDEPS = \ lib/libc \ lib/libcompiler_rt \ lib/libedit \ - lib/libmd \ lib/libthr \ lib/msun \ lib/ncurses/ncursesw \ secure/lib/libcrypto \ - secure/lib/libssl \ usr.sbin/ntp/libntp \ usr.sbin/ntp/libopts \ diff --git a/usr.sbin/ntp/sntp/Makefile.depend b/usr.sbin/ntp/sntp/Makefile.depend index d849eed..9f44d40 100644 --- a/usr.sbin/ntp/sntp/Makefile.depend +++ b/usr.sbin/ntp/sntp/Makefile.depend @@ -10,11 +10,9 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/libmd \ lib/libthr \ lib/msun \ secure/lib/libcrypto \ - secure/lib/libssl \ usr.sbin/ntp/libntp \ usr.sbin/ntp/libntpevent \ usr.sbin/ntp/libopts \ diff --git a/usr.sbin/syslogd/syslogd.8 b/usr.sbin/syslogd/syslogd.8 index b2e8818..3074d08 100644 --- a/usr.sbin/syslogd/syslogd.8 +++ b/usr.sbin/syslogd/syslogd.8 @@ -28,7 +28,7 @@ .\" @(#)syslogd.8 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd March 3, 2015 +.Dd June 16, 2015 .Dt SYSLOGD 8 .Os .Sh NAME @@ -194,6 +194,8 @@ The default .Ar service is .Ql syslog . +This option can be specified multiple times to bind to +multiple addresses and/or ports. .It Fl C Create log files that do not exist (permission is set to .Li 0600 ) . diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index baa79c8..ff3e524 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -124,6 +124,15 @@ const char ctty[] = _PATH_CONSOLE; #define MAXUNAMES 20 /* maximum number of user names */ /* + * List of hosts for binding. + */ +static STAILQ_HEAD(, host) hqueue; +struct host { + char *name; + STAILQ_ENTRY(host) next; +}; + +/* * Unix sockets. * We have two default sockets, one with 666 permissions, * and one for privileged programs. @@ -275,7 +284,7 @@ static int Foreground = 0; /* Run in foreground, instead of daemonizing */ static int resolve = 1; /* resolve hostname */ static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ static const char *LocalDomain; /* our local domain name */ -static int *finet; /* Internet datagram socket */ +static int *finet; /* Internet datagram sockets */ static int fklog = -1; /* /dev/klog */ static int Initialized; /* set when we have initialized ourselves */ static int MarkInterval = 20 * 60; /* interval between marks in seconds */ @@ -348,10 +357,10 @@ main(int argc, char *argv[]) struct sockaddr_storage frominet; fd_set *fdsr = NULL; char line[MAXLINE + 1]; - char *bindhostname; const char *hname; struct timeval tv, *tvp; struct sigaction sact; + struct host *host; struct funix *fx, *fx1; sigset_t mask; pid_t ppid = 1, spid; @@ -360,7 +369,8 @@ main(int argc, char *argv[]) if (madvise(NULL, 0, MADV_PROTECT) != 0) dprintf("madvise() failed: %s\n", strerror(errno)); - bindhostname = NULL; + STAILQ_INIT(&hqueue); + while ((ch = getopt(argc, argv, "468Aa:b:cCdf:Fkl:m:nNop:P:sS:Tuv")) != -1) switch (ch) { @@ -383,8 +393,13 @@ main(int argc, char *argv[]) usage(); break; case 'b': - bindhostname = optarg; + { + if ((host = malloc(sizeof(struct host))) == NULL) + err(1, "malloc failed"); + host->name = optarg; + STAILQ_INSERT_TAIL(&hqueue, host, next); break; + } case 'c': no_compress++; break; @@ -433,7 +448,7 @@ main(int argc, char *argv[]) if (strlen(name) >= sizeof(sunx.sun_path)) errx(1, "%s path too long, exiting", name); if ((fx = malloc(sizeof(struct funix))) == NULL) - errx(1, "malloc failed"); + err(1, "malloc failed"); fx->s = -1; fx->name = name; fx->mode = mode; @@ -555,8 +570,27 @@ main(int argc, char *argv[]) } increase_rcvbuf(fx->s); } - if (SecureMode <= 1) - finet = socksetup(family, bindhostname); + if (SecureMode <= 1) { + if (STAILQ_EMPTY(&hqueue)) + finet = socksetup(family, NULL); + STAILQ_FOREACH(host, &hqueue, next) { + int *finet0, total; + finet0 = socksetup(family, host->name); + if (finet0 && !finet) { + finet = finet0; + } else if (finet0 && finet) { + total = *finet0 + *finet + 1; + finet = realloc(finet, total * sizeof(int)); + if (finet == NULL) + err(1, "realloc failed"); + for (i = 1; i <= *finet0; i++) { + finet[(*finet)+i] = finet0[i]; + } + *finet = total - 1; + free(finet0); + } + } + } if (finet) { if (SecureMode) { @@ -1569,6 +1603,24 @@ init(int signo) } /* + * Load / reload timezone data (in case it changed). + * + * Just calling tzset() again does not work, the timezone code + * caches the result. However, by setting the TZ variable, one + * can defeat the caching and have the timezone code really + * reload the timezone data. Respect any initial setting of + * TZ, in case the system is configured specially. + */ + dprintf("loading timezone data via tzset()\n"); + if (getenv("TZ")) { + tzset(); + } else { + setenv("TZ", ":/etc/localtime", 1); + tzset(); + unsetenv("TZ"); + } + + /* * Close all open log files. */ Initialized = 0; @@ -2730,6 +2782,7 @@ socksetup(int af, char *bindhostname) } (*socks)++; + dprintf("socksetup: new socket fd is %d\n", *s); s++; } |