From owner-svn-src-stable@FreeBSD.ORG Sun Oct 28 16:10:03 2012 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E3002B97; Sun, 28 Oct 2012 16:10:03 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CA5388FC08; Sun, 28 Oct 2012 16:10:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9SGA3w4046770; Sun, 28 Oct 2012 16:10:03 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9SGA3Om046764; Sun, 28 Oct 2012 16:10:03 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <201210281610.q9SGA3Om046764@svn.freebsd.org> From: Andriy Gapon Date: Sun, 28 Oct 2012 16:10:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r242241 - in stable/9/sys/boot: i386/loader i386/zfsboot zfs X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Oct 2012 16:10:04 -0000 Author: avg Date: Sun Oct 28 16:10:03 2012 New Revision: 242241 URL: http://svn.freebsd.org/changeset/base/242241 Log: MFC r241293: zfs boot: export boot/primary pool and vdev guid all the way to kenv Modified: stable/9/sys/boot/i386/loader/main.c stable/9/sys/boot/i386/zfsboot/zfsboot.c stable/9/sys/boot/zfs/libzfs.h stable/9/sys/boot/zfs/zfsimpl.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/boot/ (props changed) Modified: stable/9/sys/boot/i386/loader/main.c ============================================================================== --- stable/9/sys/boot/i386/loader/main.c Sun Oct 28 16:06:55 2012 (r242240) +++ stable/9/sys/boot/i386/loader/main.c Sun Oct 28 16:10:03 2012 (r242241) @@ -209,6 +209,7 @@ extract_currdev(void) { struct i386_devdesc new_currdev; #ifdef LOADER_ZFS_SUPPORT + char buf[20]; struct zfs_boot_args *zargs; #endif int biosdev = -1; @@ -239,10 +240,17 @@ extract_currdev(void) if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) zargs = (struct zfs_boot_args *)(kargs + 1); - if (zargs != NULL && zargs->size >= sizeof(*zargs)) { + if (zargs != NULL && + zargs->size >= offsetof(struct zfs_boot_args, primary_pool)) { /* sufficient data is provided */ new_currdev.d_kind.zfs.pool_guid = zargs->pool; new_currdev.d_kind.zfs.root_guid = zargs->root; + if (zargs->size >= sizeof(*zargs) && zargs->primary_vdev != 0) { + sprintf(buf, "%llu", zargs->primary_pool); + setenv("vfs.zfs.boot.primary_pool", buf, 1); + sprintf(buf, "%llu", zargs->primary_vdev); + setenv("vfs.zfs.boot.primary_vdev", buf, 1); + } } else { /* old style zfsboot block */ new_currdev.d_kind.zfs.pool_guid = kargs->zfspool; Modified: stable/9/sys/boot/i386/zfsboot/zfsboot.c ============================================================================== --- stable/9/sys/boot/i386/zfsboot/zfsboot.c Sun Oct 28 16:06:55 2012 (r242240) +++ stable/9/sys/boot/i386/zfsboot/zfsboot.c Sun Oct 28 16:10:03 2012 (r242241) @@ -176,6 +176,8 @@ zfs_read(spa_t *spa, const dnode_phys_t * Current ZFS pool */ static spa_t *spa; +static spa_t *primary_spa; +static vdev_t *primary_vdev; /* * A wrapper for dskread that doesn't have to worry about whether the @@ -526,7 +528,7 @@ main(void) * first pool we found, if any. */ if (!spa) { - spa = STAILQ_FIRST(&zfs_pools); + spa = spa_get_primary(); if (!spa) { printf("%s: No ZFS pools located, can't boot\n", BOOTPROG); for (;;) @@ -534,6 +536,9 @@ main(void) } } + primary_spa = spa; + primary_vdev = spa_get_primary_vdev(spa); + if (zfs_spa_init(spa) != 0 || zfs_mount(spa, 0, &zfsmount) != 0) { printf("%s: failed to mount default pool %s\n", BOOTPROG, spa->spa_name); @@ -702,6 +707,11 @@ load(void) zfsargs.size = sizeof(zfsargs); zfsargs.pool = zfsmount.spa->spa_guid; zfsargs.root = zfsmount.rootobj; + zfsargs.primary_pool = primary_spa->spa_guid; + if (primary_vdev != NULL) + zfsargs.primary_vdev = primary_vdev->v_guid; + else + printf("failed to detect primary vdev\n"); __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK), bootdev, KARGS_FLAGS_ZFS | KARGS_FLAGS_EXTARG, Modified: stable/9/sys/boot/zfs/libzfs.h ============================================================================== --- stable/9/sys/boot/zfs/libzfs.h Sun Oct 28 16:06:55 2012 (r242240) +++ stable/9/sys/boot/zfs/libzfs.h Sun Oct 28 16:10:03 2012 (r242241) @@ -53,6 +53,8 @@ struct zfs_boot_args uint32_t reserved; uint64_t pool; uint64_t root; + uint64_t primary_pool; + uint64_t primary_vdev; }; int zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, Modified: stable/9/sys/boot/zfs/zfsimpl.c ============================================================================== --- stable/9/sys/boot/zfs/zfsimpl.c Sun Oct 28 16:06:55 2012 (r242240) +++ stable/9/sys/boot/zfs/zfsimpl.c Sun Oct 28 16:10:03 2012 (r242241) @@ -648,6 +648,34 @@ spa_find_by_name(const char *name) return (0); } +#ifdef BOOT2 +static spa_t * +spa_get_primary(void) +{ + + return (STAILQ_FIRST(&zfs_pools)); +} + +static vdev_t * +spa_get_primary_vdev(const spa_t *spa) +{ + vdev_t *vdev; + vdev_t *kid; + + if (spa == NULL) + spa = spa_get_primary(); + if (spa == NULL) + return (NULL); + vdev = STAILQ_FIRST(&spa->spa_vdevs); + if (vdev == NULL) + return (NULL); + for (kid = STAILQ_FIRST(&vdev->v_children); kid != NULL; + kid = STAILQ_FIRST(&vdev->v_children)) + vdev = kid; + return (vdev); +} +#endif + static spa_t * spa_create(uint64_t guid) {