svn commit: r235364 - in head/sys/boot: . ofw/libofw sparc64/loader zfs

Andriy Gapon avg at FreeBSD.org
Sat May 12 20:27:34 UTC 2012


Author: avg
Date: Sat May 12 20:27:33 2012
New Revision: 235364
URL: http://svn.freebsd.org/changeset/base/235364

Log:
  sparc64/zfs boot: take advantage of new libzfsboot capabilities
  
  Also drop the now unneeded compatibility shims.
  
  Tested by:	marius
  MFC after:	1 month

Modified:
  head/sys/boot/Makefile.sparc64
  head/sys/boot/ofw/libofw/Makefile
  head/sys/boot/ofw/libofw/devicename.c
  head/sys/boot/ofw/libofw/libofw.h
  head/sys/boot/sparc64/loader/Makefile
  head/sys/boot/sparc64/loader/main.c
  head/sys/boot/zfs/zfs.c
  head/sys/boot/zfs/zfsimpl.c

Modified: head/sys/boot/Makefile.sparc64
==============================================================================
--- head/sys/boot/Makefile.sparc64	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/Makefile.sparc64	Sat May 12 20:27:33 2012	(r235364)
@@ -1,3 +1,4 @@
 # $FreeBSD$
 
 SUBDIR+=		ofw
+SUBDIR+=		zfs

Modified: head/sys/boot/ofw/libofw/Makefile
==============================================================================
--- head/sys/boot/ofw/libofw/Makefile	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/ofw/libofw/Makefile	Sat May 12 20:27:33 2012	(r235364)
@@ -6,6 +6,8 @@ INTERNALLIB=
 SRCS=	devicename.c elf_freebsd.c ofw_console.c ofw_copy.c ofw_disk.c \
 	ofw_memory.c ofw_module.c ofw_net.c ofw_reboot.c \
 	ofw_time.c openfirm.c
+.PATH:	${.CURDIR}/../../zfs
+SRCS+=  devicename_stubs.c
 
 CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand/
 

Modified: head/sys/boot/ofw/libofw/devicename.c
==============================================================================
--- head/sys/boot/ofw/libofw/devicename.c	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/ofw/libofw/devicename.c	Sat May 12 20:27:33 2012	(r235364)
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 
 #include "bootstrap.h"
 #include "libofw.h"
+#include "../zfs/libzfs.h"
 
 static int ofw_parsedev(struct ofw_devdesc **, const char *, const char **);
 
@@ -81,6 +82,7 @@ ofw_parsedev(struct ofw_devdesc **dev, c
     char		*ep;
     char		name[256];
     char		type[64];
+    int			err;
     int			len;
     int			i;
 
@@ -114,14 +116,11 @@ found:
     idev->d_dev = dv;
     idev->d_type = dv->dv_type;
     if (idev->d_type == DEVT_ZFS) {
-	idev->d_unit = 0;
-	p = name + strlen(dv->dv_name);
-	if (*p && (*p != ':')) {
-	    idev->d_unit = strtol(p, &ep, 0);
-	    if (ep == p) {
-		free(idev);
-		return (EUNIT);
-	    }
+	p = devspec + strlen(dv->dv_name);
+	err = zfs_parsedev((struct zfs_devdesc *)idev, p, path);
+	if (err != 0) {
+	    free(idev);
+	    return (err);
 	}
     }
 

Modified: head/sys/boot/ofw/libofw/libofw.h
==============================================================================
--- head/sys/boot/ofw/libofw/libofw.h	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/ofw/libofw/libofw.h	Sat May 12 20:27:33 2012	(r235364)
@@ -33,7 +33,13 @@ struct ofw_devdesc {
 	int		d_type;
 	int		d_unit;
 	ihandle_t	d_handle;
-	char		d_path[256];
+	union {
+		char			d_path[256];
+		struct {
+			uint64_t	pool_guid;
+			uint64_t	root_guid;
+		};
+	};
 };
 
 extern int	ofw_getdev(void **vdev, const char *devspec, const char **path);

Modified: head/sys/boot/sparc64/loader/Makefile
==============================================================================
--- head/sys/boot/sparc64/loader/Makefile	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/sparc64/loader/Makefile	Sat May 12 20:27:33 2012	(r235364)
@@ -37,6 +37,7 @@ CFLAGS+=	-DLOADER_CD9660_SUPPORT
 CFLAGS+=	-DLOADER_ZFS_SUPPORT
 CFLAGS+=	-I${.CURDIR}/../../zfs
 CFLAGS+=	-I${.CURDIR}/../../../cddl/boot/zfs
+LIBZFSBOOT=	${.OBJDIR}/../../zfs/libzfsboot.a
 .endif
 .if ${LOADER_GZIP_SUPPORT} == "yes"
 CFLAGS+=	-DLOADER_GZIP_SUPPORT
@@ -83,8 +84,8 @@ CFLAGS+=	-I${.CURDIR}/../../ofw/libofw/
 # where to get libstand from
 CFLAGS+=	-I${.CURDIR}/../../../../lib/libstand/
 
-DPADD=		${LIBFICL} ${LIBOFW} ${LIBSTAND}
-LDADD=		${LIBFICL} ${LIBOFW} -lstand
+DPADD=		${LIBFICL} ${LIBZFSBOOT} ${LIBOFW} ${LIBSTAND}
+LDADD=		${LIBFICL} ${LIBZFSBOOT} ${LIBOFW} -lstand
 
 vers.c:	${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version
 	sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version \

Modified: head/sys/boot/sparc64/loader/main.c
==============================================================================
--- head/sys/boot/sparc64/loader/main.c	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/sparc64/loader/main.c	Sat May 12 20:27:33 2012	(r235364)
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #ifdef LOADER_ZFS_SUPPORT
 #include <sys/vtoc.h>
+#include "../zfs/libzfs.h"
 #endif
 
 #include <vm/vm.h>
@@ -74,7 +75,7 @@ __FBSDID("$FreeBSD$");
 #include "libofw.h"
 #include "dev_net.h"
 
-#define	MAXBDDEV	31
+#define	MAXDEV	31
 
 extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
 
@@ -142,11 +143,6 @@ static vm_offset_t heapva;
 
 static phandle_t root;
 
-#ifdef LOADER_ZFS_SUPPORT
-static int sparc64_zfs_dev_init(void);
-#include "zfs.c"
-#endif
-
 /*
  * Machine dependent structures that the machine independent
  * loader part uses.
@@ -159,7 +155,7 @@ struct devsw *devsw[] = {
 	&netdev,
 #endif
 #ifdef LOADER_ZFS_SUPPORT
-	&zfs_dev_compat,
+	&zfs_dev,
 #endif
 	0
 };
@@ -733,39 +729,20 @@ tlb_init_sun4u(void)
 }
 
 #ifdef LOADER_ZFS_SUPPORT
-
-static int
-sparc64_zfs_dev_init(void)
+static void
+sparc64_zfs_probe(void)
 {
 	struct vtoc8 vtoc;
-	char devname[512];
-	spa_t *spa;
-	vdev_t *vdev;
+	struct zfs_devdesc zfs_currdev;
+	char devname[32];
 	uint64_t guid;
 	int fd, part, unit;
 
-	zfs_init();
-
-	guid = 0;
 	/* Get the GUID of the ZFS pool on the boot device. */
-	fd = open(getenv("currdev"), O_RDONLY);
-	if (fd != -1) {
-		if (vdev_probe(vdev_read, (void *)(uintptr_t) fd, &spa) == 0)
-			guid = spa->spa_guid;
-		close(fd);
-	}
-
-	/* Clean up the environment to let ZFS work. */
-	while ((vdev = STAILQ_FIRST(&zfs_vdevs)) != NULL) {
-		STAILQ_REMOVE_HEAD(&zfs_vdevs, v_alllink);
-		free(vdev);
-	}
-	while ((spa = STAILQ_FIRST(&zfs_pools)) != NULL) {
-		STAILQ_REMOVE_HEAD(&zfs_pools, spa_link);
-		free(spa);
-	}
+	guid = 0;
+	zfs_probe_dev(getenv("currdev"), &guid);
 
-	for (unit = 0; unit < MAXBDDEV; unit++) {
+	for (unit = 0; unit < MAXDEV; unit++) {
 		/* Find freebsd-zfs slices in the VTOC. */
 		sprintf(devname, "disk%d:", unit);
 		fd = open(devname, O_RDONLY);
@@ -783,29 +760,23 @@ sparc64_zfs_dev_init(void)
 			     VTOC_TAG_FREEBSD_ZFS)
 				continue;
 			sprintf(devname, "disk%d:%c", unit, part + 'a');
-			fd = open(devname, O_RDONLY);
-			if (fd == -1)
+			if (zfs_probe_dev(devname, NULL) == ENXIO)
 				break;
-
-			if (vdev_probe(vdev_read, (void*)(uintptr_t) fd, 0))
-				close(fd);
 		}
 	}
 
 	if (guid != 0) {
-		unit = zfs_guid_to_unit(guid);
-		if (unit >= 0) {
-			/* Update the environment for ZFS. */
-			sprintf(devname, "zfs%d", unit);
-			env_setenv("currdev", EV_VOLATILE, devname,
-			   ofw_setcurrdev, env_nounset);
-			env_setenv("loaddev", EV_VOLATILE, devname,
-			   env_noset, env_nounset);
-		}
+		zfs_currdev.pool_guid = guid;
+		zfs_currdev.root_guid = 0;
+		zfs_currdev.d_dev = &zfs_dev;
+		zfs_currdev.d_type = zfs_currdev.d_dev->dv_type;
+		/* Update the environment for ZFS. */
+		env_setenv("currdev", EV_VOLATILE, zfs_fmtdev(&zfs_currdev),
+		    ofw_setcurrdev, env_nounset);
+		env_setenv("loaddev", EV_VOLATILE, zfs_fmtdev(&zfs_currdev),
+		    env_noset, env_nounset);
 	}
-	return (0);
 }
-
 #endif /* LOADER_ZFS_SUPPORT */
 
 int
@@ -825,6 +796,9 @@ main(int (*openfirm)(void *))
 	archsw.arch_copyout = ofw_copyout;
 	archsw.arch_readin = sparc64_readin;
 	archsw.arch_autoload = sparc64_autoload;
+#ifdef LOADER_ZFS_SUPPORT
+	archsw.arch_zfs_probe = sparc64_zfs_probe;
+#endif
 
 	if (init_heap() == (vm_offset_t)-1)
 		OF_exit();
@@ -870,13 +844,6 @@ main(int (*openfirm)(void *))
 	env_setenv("loaddev", EV_VOLATILE, bootpath,
 	    env_noset, env_nounset);
 
-#ifdef LOADER_ZFS_SUPPORT
-	/*
-	 * Patch up ZFS.
-	 */
-	zfs_dev_compat.dv_init = sparc64_zfs_dev_init;
-#endif
-
 	/*
 	 * Initialize devices.
 	 */

Modified: head/sys/boot/zfs/zfs.c
==============================================================================
--- head/sys/boot/zfs/zfs.c	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/zfs/zfs.c	Sat May 12 20:27:33 2012	(r235364)
@@ -418,16 +418,26 @@ zfs_dev_print(int verbose)
  * Attempt to open the pool described by (dev) for use by (f).
  */
 static int
-zfs_dev_open_spa(struct open_file *f, spa_t *spa, uint64_t root_guid)
+zfs_dev_open(struct open_file *f, ...)
 {
+	va_list		args;
+	struct zfs_devdesc	*dev;
 	struct zfsmount	*mount;
+	spa_t		*spa;
 	int		rv;
 
+	va_start(args, f);
+	dev = va_arg(args, struct zfs_devdesc *);
+	va_end(args);
+
+	spa = spa_find_by_guid(dev->pool_guid);
+	if (!spa)
+		return (ENXIO);
 	rv = zfs_spa_init(spa);
 	if (rv != 0)
 		return (rv);
 	mount = malloc(sizeof(*mount));
-	rv = zfs_mount(spa, root_guid, mount);
+	rv = zfs_mount(spa, dev->root_guid, mount);
 	if (rv != 0) {
 		free(mount);
 		return (rv);
@@ -439,49 +449,6 @@ zfs_dev_open_spa(struct open_file *f, sp
 		return (EIO);
 	}
 	f->f_devdata = mount;
-	return (0);
-}
-
-static int
-zfs_dev_open(struct open_file *f, ...)
-{
-	va_list			args;
-	struct zfs_devdesc	*dev;
-	spa_t			*spa;
-	int			rv;
-
-	va_start(args, f);
-	dev = va_arg(args, struct zfs_devdesc *);
-	va_end(args);
-
-	spa = spa_find_by_guid(dev->pool_guid);
-	if (!spa)
-		return (ENXIO);
-	rv = zfs_dev_open_spa(f, spa, dev->root_guid);
-	if (rv != 0)
-		return (rv);
-	free(dev);
-	return (0);
-}
-
-static int
-zfs_dev_open_compat(struct open_file *f, ...)
-{
-	va_list		args;
-	struct devdesc	*dev;
-	spa_t		*spa;
-	int		rv;
-
-	va_start(args, f);
-	dev = va_arg(args, struct devdesc *);
-	va_end(args);
-
-	spa = spa_find_by_unit(dev->d_unit);
-	if (!spa)
-		return (ENXIO);
-	rv = zfs_dev_open_spa(f, spa, 0);
-	if (rv != 0)
-		return (rv);
 	free(dev);
 	return (0);
 }
@@ -514,18 +481,6 @@ struct devsw zfs_dev = {
 	.dv_cleanup = NULL
 };
 
-struct devsw zfs_dev_compat = {
-	.dv_name = "zfs",
-	.dv_type = DEVT_ZFS,
-	.dv_init = zfs_dev_init,
-	.dv_strategy = zfs_dev_strategy,
-	.dv_open = zfs_dev_open_compat,
-	.dv_close = zfs_dev_close,
-	.dv_ioctl = noioctl,
-	.dv_print = zfs_dev_print,
-	.dv_cleanup = NULL
-};
-
 int
 zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path)
 {

Modified: head/sys/boot/zfs/zfsimpl.c
==============================================================================
--- head/sys/boot/zfs/zfsimpl.c	Sat May 12 20:27:13 2012	(r235363)
+++ head/sys/boot/zfs/zfsimpl.c	Sat May 12 20:27:33 2012	(r235364)
@@ -646,38 +646,6 @@ spa_find_by_name(const char *name)
 	return (0);
 }
 
-#ifndef BOOT2
-static spa_t *
-spa_find_by_unit(int unit)
-{
-	spa_t *spa;
-
-	STAILQ_FOREACH(spa, &zfs_pools, spa_link) {
-		if (unit == 0)
-			return (spa);
-		unit--;
-	}
-
-	return (0);
-}
-
-static int
-zfs_guid_to_unit(uint64_t guid)
-{
-	spa_t *spa;
-	int unit;
-
-	unit = 0;
-	STAILQ_FOREACH(spa, &zfs_pools, spa_link) {
-		if (spa->spa_guid == guid)
-			return (unit);
-		unit++;
-	}
-
-	return (-1);
-}
-#endif
-
 static spa_t *
 spa_create(uint64_t guid)
 {


More information about the svn-src-all mailing list