Index: sys/boot/userboot/Makefile =================================================================== --- sys/boot/userboot/Makefile (revision 261494) +++ sys/boot/userboot/Makefile (working copy) @@ -2,7 +2,7 @@ .include -SUBDIR= ficl libstand test userboot +SUBDIR= ficl libstand test zfs userboot .include Index: sys/boot/userboot/libstand/Makefile =================================================================== --- sys/boot/userboot/libstand/Makefile (revision 261494) +++ sys/boot/userboot/libstand/Makefile (working copy) @@ -21,6 +21,8 @@ WARNS?= 0 +DEBUG_FLAGS= -g -O0 + CFLAGS+= -ffreestanding -Wformat -fPIC CFLAGS+= -I${.CURDIR}/../../../../lib/libstand Index: sys/boot/userboot/userboot/Makefile =================================================================== --- sys/boot/userboot/userboot/Makefile (revision 261494) +++ sys/boot/userboot/userboot/Makefile (working copy) @@ -26,6 +26,8 @@ SRCS+= userboot_disk.c SRCS+= vers.c +DEBUG_FLAGS= -g -O0 + CFLAGS+= -Wall CFLAGS+= -I${.CURDIR}/.. CFLAGS+= -I${.CURDIR}/../../common @@ -50,12 +52,17 @@ LIBSTAND= ${.OBJDIR}/../libstand/libstand.a .endif +.if ${MK_ZFS} != "no" +CFLAGS+= -DUSERBOOT_ZFS_SUPPORT +LIBZFS= ${.OBJDIR}/../zfs/libzfsboot.a +.endif + # Always add MI sources .PATH: ${.CURDIR}/../../common .include "${.CURDIR}/../../common/Makefile.inc" CFLAGS+= -I${.CURDIR}/../../common CFLAGS+= -I. -DPADD= ${LIBFICL} ${LIBSTAND} -LDADD= ${LIBFICL} ${LIBSTAND} +DPADD= ${LIBFICL} ${LIBZFS} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBZFS} ${LIBSTAND} .include Index: sys/boot/userboot/userboot/conf.c =================================================================== --- sys/boot/userboot/userboot/conf.c (revision 261494) +++ sys/boot/userboot/userboot/conf.c (working copy) @@ -38,6 +38,10 @@ #include "libuserboot.h" +#if defined(USERBOOT_ZFS_SUPPORT) +#include "../zfs/libzfs.h" +#endif + /* * We could use linker sets for some or all of these, but * then we would have to control what ended up linked into @@ -51,6 +55,9 @@ struct devsw *devsw[] = { &host_dev, &userboot_disk, +#if defined(USERBOOT_ZFS_SUPPORT) + &zfs_dev, +#endif NULL }; @@ -59,6 +66,9 @@ &ufs_fsops, &cd9660_fsops, &gzipfs_fsops, +#if defined(USERBOOT_ZFS_SUPPORT) + &zfs_fsops, +#endif NULL }; Index: sys/boot/userboot/userboot/devicename.c =================================================================== --- sys/boot/userboot/userboot/devicename.c (revision 261494) +++ sys/boot/userboot/userboot/devicename.c (working copy) @@ -34,6 +34,10 @@ #include "disk.h" #include "libuserboot.h" +#if defined(USERBOOT_ZFS_SUPPORT) +#include "../zfs/libzfs.h" +#endif + static int userboot_parsedev(struct disk_devdesc **dev, const char *devspec, const char **path); /* @@ -119,7 +123,6 @@ case DEVT_CD: case DEVT_NET: - case DEVT_ZFS: unit = 0; if (*np && (*np != ':')) { @@ -141,6 +144,16 @@ *path = (*cp == 0) ? cp : cp + 1; break; + case DEVT_ZFS: +#if defined(USERBOOT_ZFS_SUPPORT) + err = zfs_parsedev((struct zfs_devdesc *)idev, np, path); + if (err != 0) + goto fail; + break; +#else + /* FALLTHROUGH */ +#endif + default: err = EINVAL; goto fail; @@ -179,8 +192,15 @@ return (disk_fmtdev(vdev)); case DEVT_NET: + sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit); + break; + case DEVT_ZFS: +#if defined(USERBOOT_ZFS_SUPPORT) + return (zfs_fmtdev(vdev)); +#else sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit); +#endif break; } return(buf); Index: sys/boot/userboot/userboot/main.c =================================================================== --- sys/boot/userboot/userboot/main.c (revision 261494) +++ sys/boot/userboot/userboot/main.c (working copy) @@ -36,8 +36,17 @@ #include "disk.h" #include "libuserboot.h" +#if defined(USERBOOT_ZFS_SUPPORT) +#include "../zfs/libzfs.h" + +static void userboot_zfs_probe(void); +static int userboot_zfs_found; +#endif + #define USERBOOT_VERSION USERBOOT_VERSION_3 +#define MALLOCSZ (10*1024*1024) + struct loader_callbacks *callbacks; void *callbacks_arg; @@ -69,7 +78,7 @@ void loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks) { - static char malloc[1024*1024]; + static char mallocbuf[MALLOCSZ]; const char *var; int i; @@ -82,10 +91,9 @@ /* * initialise the heap as early as possible. Once this is done, - * alloc() is usable. The stack is buried inside us, so this is - * safe. + * alloc() is usable. */ - setheap((void *)malloc, (void *)(malloc + 1024*1024)); + setheap((void *)mallocbuf, (void *)(mallocbuf + sizeof(mallocbuf))); /* * Hook up the console @@ -92,13 +100,6 @@ */ cons_probe(); - /* - * March through the device switch probing for things. - */ - for (i = 0; devsw[i] != NULL; i++) - if (devsw[i]->dv_init != NULL) - (devsw[i]->dv_init)(); - printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); @@ -124,7 +125,17 @@ archsw.arch_copyin = userboot_copyin; archsw.arch_copyout = userboot_copyout; archsw.arch_readin = userboot_readin; +#if defined(USERBOOT_ZFS_SUPPORT) + archsw.arch_zfs_probe = userboot_zfs_probe; +#endif + /* + * March through the device switch probing for things. + */ + for (i = 0; devsw[i] != NULL; i++) + if (devsw[i]->dv_init != NULL) + (devsw[i]->dv_init)(); + extract_currdev(); if (setjmp(jb)) @@ -146,6 +157,19 @@ //bzero(&dev, sizeof(dev)); +#if defined(USERBOOT_ZFS_SUPPORT) + if (userboot_zfs_found) { + struct zfs_devdesc zdev; + + /* Leave the pool/root guid's unassigned */ + bzero(&zdev, sizeof(zdev)); + zdev.d_dev = &zfs_dev; + zdev.d_type = zdev.d_dev->dv_type; + + dev = *(struct disk_devdesc *)&zdev; + } else +#endif + if (userboot_disk_maxunit > 0) { dev.d_dev = &userboot_disk; dev.d_type = dev.d_dev->dv_type; @@ -172,6 +196,49 @@ env_noset, env_nounset); } +#if defined(USERBOOT_ZFS_SUPPORT) +static void +userboot_zfs_probe(void) +{ + char devname[32]; + uint64_t pool_guid; + int unit; + + /* + * Open all the disks we can find and see if we can reconstruct + * ZFS pools from them. Record if any were found. + */ + for (unit = 0; unit < userboot_disk_maxunit; unit++) { + sprintf(devname, "disk%d:", unit); + pool_guid = 0; + zfs_probe_dev(devname, &pool_guid); + if (pool_guid != 0) + userboot_zfs_found = 1; + } +} + +COMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset", + command_lszfs); + +static int +command_lszfs(int argc, char *argv[]) +{ + int err; + + if (argc != 2) { + command_errmsg = "wrong number of arguments"; + return (CMD_ERROR); + } + + err = zfs_list(argv[1]); + if (err != 0) { + command_errmsg = strerror(err); + return (CMD_ERROR); + } + return (CMD_OK); +} +#endif /* USERBOOT_ZFS_SUPPORT */ + COMMAND_SET(quit, "quit", "exit the loader", command_quit); static int Index: sys/boot/userboot/zfs/Makefile =================================================================== --- sys/boot/userboot/zfs/Makefile (revision 0) +++ sys/boot/userboot/zfs/Makefile (working copy) @@ -0,0 +1,20 @@ +# $FreeBSD$ + +S= ${.CURDIR}/../../zfs + +.PATH: ${S} +LIB= zfsboot +INTERNALLIB= + +SRCS+= zfs.c + +DEBUG_FLAGS= -g -O0 + +CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I. +CFLAGS+= -I${.CURDIR}/../../../../lib/libstand +CFLAGS+= -I${.CURDIR}/../../../cddl/boot/zfs + +CFLAGS+= -ffreestanding -fPIC +CFLAGS+= -Wformat -Wall + +.include Property changes on: sys/boot/userboot/zfs/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: usr.sbin/bhyveload/Makefile =================================================================== --- usr.sbin/bhyveload/Makefile (revision 261494) +++ usr.sbin/bhyveload/Makefile (working copy) @@ -4,6 +4,8 @@ SRCS= bhyveload.c MAN= bhyveload.8 +DEBUG_FLAGS= -g -O0 + DPADD+= ${LIBVMMAPI} ${LIBUTIL} LDADD+= -lvmmapi -lutil Index: usr.sbin/bhyveload/bhyveload.c =================================================================== --- usr.sbin/bhyveload/bhyveload.c (revision 261494) +++ usr.sbin/bhyveload/bhyveload.c (working copy) @@ -88,9 +88,12 @@ #define GB (1024 * 1024 * 1024UL) #define BSP 0 +#define NDISKS 32 + static char *host_base; static struct termios term, oldterm; -static int disk_fd = -1; +static int disk_fd[NDISKS]; +static int ndisks; static int consin_fd, consout_fd; static char *vmname, *progname; @@ -287,9 +290,9 @@ { ssize_t n; - if (unit != 0 || disk_fd == -1) + if (unit < 0 || unit >= ndisks ) return (EIO); - n = pread(disk_fd, to, size, from); + n = pread(disk_fd[unit], to, size, from); if (n < 0) return (errno); *resid = size - n; @@ -301,7 +304,7 @@ { struct stat sb; - if (unit != 0 || disk_fd == -1) + if (unit < 0 || unit >= ndisks) return (EBADF); switch (cmd) { @@ -309,7 +312,7 @@ *(u_int *)data = 512; break; case DIOCGMEDIASIZE: - if (fstat(disk_fd, &sb) == 0) + if (fstat(disk_fd[unit], &sb) == 0) *(off_t *)data = sb.st_size; else return (ENOTTY); @@ -596,6 +599,26 @@ return (err); } +static int +disk_open(char *path) +{ + int err, fd; + + if (ndisks > NDISKS) + return (ERANGE); + + err = 0; + fd = open(path, O_RDONLY); + + if (fd > 0) { + disk_fd[ndisks] = fd; + ndisks++; + } else + err = errno; + + return (err); +} + static void usage(void) { @@ -615,12 +638,10 @@ void (*func)(struct loader_callbacks *, void *, int, int); uint64_t mem_size; int opt, error; - char *disk_image; progname = basename(argv[0]); mem_size = 256 * MB; - disk_image = NULL; consin_fd = STDIN_FILENO; consout_fd = STDOUT_FILENO; @@ -632,8 +653,11 @@ if (error != 0) errx(EX_USAGE, "Could not open '%s'", optarg); break; + case 'd': - disk_image = optarg; + error = disk_open(optarg); + if (error != 0) + errx(EX_USAGE, "Could not open '%s'", optarg); break; case 'e': @@ -699,12 +723,8 @@ return (1); } - if (disk_image) { - disk_fd = open(disk_image, O_RDONLY); - } - addenv("smbios.bios.vendor=BHYVE"); addenv("boot_serial=1"); - func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0); + func(&cb, NULL, USERBOOT_VERSION_3, ndisks); }