Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Feb 2018 15:57:36 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329725 - in head/stand: . common efi/libefi efi/loader i386/loader sparc64/loader userboot/userboot
Message-ID:  <201802211557.w1LFvajr043355@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Wed Feb 21 15:57:36 2018
New Revision: 329725
URL: https://svnweb.freebsd.org/changeset/base/329725

Log:
  Consolidate three copies of ZFS commands into a central location.
  
  There's no reason to have multiple copies of lszfs and
  reloadbe. Consolidate them into one location. Also ldi_get_size is the
  same everywhere (except sparc64). Make it the same everywhere as the
  common definition is more general and will work on spar64.

Added:
  head/stand/common/zfs_cmd.c   (contents, props changed)
Modified:
  head/stand/efi/libefi/efizfs.c
  head/stand/efi/loader/Makefile
  head/stand/efi/loader/main.c
  head/stand/i386/loader/main.c
  head/stand/loader.mk
  head/stand/sparc64/loader/Makefile
  head/stand/sparc64/loader/main.c
  head/stand/userboot/userboot/main.c

Added: head/stand/common/zfs_cmd.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/stand/common/zfs_cmd.c	Wed Feb 21 15:57:36 2018	(r329725)
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2018 Warner Losh <imp@freebd.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 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 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/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * MD bootstrap main() and assorted miscellaneous
+ * commands.
+ */
+
+#include <stand.h>
+#include <stddef.h>
+#include <sys/disk.h>
+#include <sys/reboot.h>
+
+#include "bootstrap.h"
+
+#ifdef LOADER_ZFS_SUPPORT
+#include "../zfs/libzfs.h"
+#endif
+
+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 = "a single dataset must be supplied";
+		return (CMD_ERROR);
+	}
+
+	err = zfs_list(argv[1]);
+	if (err != 0) {
+		command_errmsg = strerror(err);
+		return (CMD_ERROR);
+	}
+	return (CMD_OK);
+}
+
+COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
+	    command_reloadbe);
+
+static int
+command_reloadbe(int argc, char *argv[])
+{
+	int err;
+	char *root;
+
+	if (argc > 2) {
+		command_errmsg = "wrong number of arguments";
+		return (CMD_ERROR);
+	}
+
+	if (argc == 2) {
+		err = zfs_bootenv(argv[1]);
+	} else {
+		root = getenv("zfs_be_root");
+		if (root == NULL) {
+			/* There does not appear to be a ZFS pool here, exit without error */
+			return (CMD_OK);
+		}
+		err = zfs_bootenv(root);
+	}
+
+	if (err != 0) {
+		command_errmsg = strerror(err);
+		return (CMD_ERROR);
+	}
+
+	return (CMD_OK);
+}
+
+uint64_t
+ldi_get_size(void *priv)
+{
+	int fd = (uintptr_t) priv;
+	uint64_t size;
+
+	ioctl(fd, DIOCGMEDIASIZE, &size);
+	return (size);
+}

Modified: head/stand/efi/libefi/efizfs.c
==============================================================================
--- head/stand/efi/libefi/efizfs.c	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/efi/libefi/efizfs.c	Wed Feb 21 15:57:36 2018	(r329725)
@@ -109,14 +109,4 @@ efi_zfs_probe(void)
 		}
 	}
 }
-
-uint64_t
-ldi_get_size(void *priv)
-{
-	int fd = (uintptr_t) priv;
-	uint64_t size;
-
-	ioctl(fd, DIOCGMEDIASIZE, &size);
-	return (size);
-}
 #endif

Modified: head/stand/efi/loader/Makefile
==============================================================================
--- head/stand/efi/loader/Makefile	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/efi/loader/Makefile	Wed Feb 21 15:57:36 2018	(r329725)
@@ -28,6 +28,7 @@ SRCS=	autoload.c \
 LIBZFSBOOT=	${BOOTOBJ}/zfs/libzfsboot.a
 CFLAGS+=	-I${ZFSSRC}
 CFLAGS+=	-DEFI_ZFS_BOOT
+HAVE_ZFS=	yes
 .endif
 
 .if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201

Modified: head/stand/efi/loader/main.c
==============================================================================
--- head/stand/efi/loader/main.c	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/efi/loader/main.c	Wed Feb 21 15:57:36 2018	(r329725)
@@ -747,61 +747,6 @@ command_mode(int argc, char *argv[])
 	return (CMD_OK);
 }
 
-#ifdef EFI_ZFS_BOOT
-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);
-}
-
-COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
-	    command_reloadbe);
-
-static int
-command_reloadbe(int argc, char *argv[])
-{
-	int err;
-	char *root;
-
-	if (argc > 2) {
-		command_errmsg = "wrong number of arguments";
-		return (CMD_ERROR);
-	}
-
-	if (argc == 2) {
-		err = zfs_bootenv(argv[1]);
-	} else {
-		root = getenv("zfs_be_root");
-		if (root == NULL) {
-			return (CMD_OK);
-		}
-		err = zfs_bootenv(root);
-	}
-
-	if (err != 0) {
-		command_errmsg = strerror(err);
-		return (CMD_ERROR);
-	}
-
-	return (CMD_OK);
-}
-#endif
-
 #ifdef LOADER_FDT_SUPPORT
 extern int command_fdt_internal(int argc, char *argv[]);
 

Modified: head/stand/i386/loader/main.c
==============================================================================
--- head/stand/i386/loader/main.c	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/i386/loader/main.c	Wed Feb 21 15:57:36 2018	(r329725)
@@ -374,63 +374,6 @@ command_heap(int argc, char *argv[])
     return(CMD_OK);
 }
 
-#ifdef LOADER_ZFS_SUPPORT
-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);
-}
-
-COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
-    command_reloadbe);
-
-static int
-command_reloadbe(int argc, char *argv[])
-{
-    int err;
-    char *root;
-
-    if (argc > 2) {
-	command_errmsg = "wrong number of arguments";
-	return (CMD_ERROR);
-    }
-
-    if (argc == 2) {
-	err = zfs_bootenv(argv[1]);
-    } else {
-	root = getenv("zfs_be_root");
-	if (root == NULL) {
-	    /* There does not appear to be a ZFS pool here, exit without error */
-	    return (CMD_OK);
-	}
-	err = zfs_bootenv(root);
-    }
-
-    if (err != 0) {
-	command_errmsg = strerror(err);
-	return (CMD_ERROR);
-    }
-
-    return (CMD_OK);
-}
-#endif
-
 /* ISA bus access functions for PnP. */
 static int
 isa_inb(int port)
@@ -463,15 +406,5 @@ i386_zfs_probe(void)
 	sprintf(devname, "disk%d:", unit);
 	zfs_probe_dev(devname, NULL);
     }
-}
-
-uint64_t
-ldi_get_size(void *priv)
-{
-	int fd = (uintptr_t) priv;
-	uint64_t size;
-
-	ioctl(fd, DIOCGMEDIASIZE, &size);
-	return (size);
 }
 #endif

Modified: head/stand/loader.mk
==============================================================================
--- head/stand/loader.mk	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/loader.mk	Wed Feb 21 15:57:36 2018	(r329725)
@@ -130,7 +130,8 @@ CFLAGS+= -DLOADER_MBR_SUPPORT
 CFLAGS+=	-DLOADER_ZFS_SUPPORT
 CFLAGS+=	-I${ZFSSRC}
 CFLAGS+=	-I${SYSDIR}/cddl/boot/zfs
-.if ${MACHINE} == "amd64"
+SRCS+=		zfs_cmd.c
+.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1
 # Have to override to use 32-bit version of zfs library...
 # kinda lame to select that there XXX
 LIBZFSBOOT=	${BOOTOBJ}/zfs32/libzfsboot.a

Modified: head/stand/sparc64/loader/Makefile
==============================================================================
--- head/stand/sparc64/loader/Makefile	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/sparc64/loader/Makefile	Wed Feb 21 15:57:36 2018	(r329725)
@@ -19,6 +19,10 @@ NEWVERSWHAT?=	"bootstrap loader" sparc64
 VERSION_FILE=	${.CURDIR}/../loader/version
 INSTALLFLAGS=	-b
 
+.if ${MK_ZFS} != "no"
+HAVE_ZFS=	yes
+.endif
+
 # Architecture-specific loader code
 .PATH:		${BOOTSRC}/sparc64/loader
 SRCS=		locore.S main.c vers.c

Modified: head/stand/sparc64/loader/main.c
==============================================================================
--- head/stand/sparc64/loader/main.c	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/sparc64/loader/main.c	Wed Feb 21 15:57:36 2018	(r329725)
@@ -735,15 +735,6 @@ tlb_init_sun4u(void)
 
 #ifdef LOADER_ZFS_SUPPORT
 
-/* Set by sparc64_zfs_probe to provide partition size. */
-static size_t part_size;
-
-uint64_t
-ldi_get_size(void *priv __unused)
-{
-	return ((uint64_t)part_size);
-}
-
 static void
 sparc64_zfs_probe(void)
 {
@@ -799,7 +790,6 @@ sparc64_zfs_probe(void)
 			if (part == 2 || vtoc.part[part].tag !=
 			    VTOC_TAG_FREEBSD_ZFS)
 				continue;
-			part_size = vtoc.map[part].nblks;
 			(void)sprintf(devname, "%s:%c", alias, part + 'a');
 			/* Get the GUID of the ZFS pool on the boot device. */
 			if (strcmp(devname, bootpath) == 0)
@@ -948,7 +938,7 @@ static const char *const page_sizes[] = {
 
 static void
 pmap_print_tte_sun4u(tte_t tag, tte_t tte)
-{
+
 
 	printf("%s %s ",
 	    page_sizes[(tte >> TD_SIZE_SHIFT) & TD_SIZE_MASK],

Modified: head/stand/userboot/userboot/main.c
==============================================================================
--- head/stand/userboot/userboot/main.c	Wed Feb 21 15:57:24 2018	(r329724)
+++ head/stand/userboot/userboot/main.c	Wed Feb 21 15:57:36 2018	(r329725)
@@ -218,70 +218,7 @@ userboot_zfs_probe(void)
 			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 = "a single dataset must be supplied";
-		return (CMD_ERROR);
-	}
-
-	err = zfs_list(argv[1]);
-	if (err != 0) {
-		command_errmsg = strerror(err);
-		return (CMD_ERROR);
-	}
-	return (CMD_OK);
-}
-
-COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
-	    command_reloadbe);
-
-static int
-command_reloadbe(int argc, char *argv[])
-{
-	int err;
-	char *root;
-
-	if (argc > 2) {
-		command_errmsg = "wrong number of arguments";
-		return (CMD_ERROR);
-	}
-
-	if (argc == 2) {
-		err = zfs_bootenv(argv[1]);
-	} else {
-		root = getenv("zfs_be_root");
-		if (root == NULL) {
-			return (CMD_OK);
-		}
-		err = zfs_bootenv(root);
-	}
-
-	if (err != 0) {
-		command_errmsg = strerror(err);
-		return (CMD_ERROR);
-	}
-
-	return (CMD_OK);
-}
-
-uint64_t
-ldi_get_size(void *priv)
-{
-	int fd = (uintptr_t) priv;
-	uint64_t size;
-
-	ioctl(fd, DIOCGMEDIASIZE, &size);
-	return (size);
-}
-#endif /* USERBOOT_ZFS_SUPPORT */
+#endif
 
 COMMAND_SET(quit, "quit", "exit the loader", command_quit);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802211557.w1LFvajr043355>