From owner-svn-src-projects@freebsd.org Tue Aug 7 01:56:38 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E7C52106D64A for ; Tue, 7 Aug 2018 01:56:37 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9FA3675275; Tue, 7 Aug 2018 01:56:37 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 821BD153CC; Tue, 7 Aug 2018 01:56:37 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w771ubOx070280; Tue, 7 Aug 2018 01:56:37 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w771ubn0070279; Tue, 7 Aug 2018 01:56:37 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808070156.w771ubn0070279@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 7 Aug 2018 01:56:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r337402 - projects/bectl/lib/libbe X-SVN-Group: projects X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: projects/bectl/lib/libbe X-SVN-Commit-Revision: 337402 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Aug 2018 01:56:38 -0000 Author: kevans Date: Tue Aug 7 01:56:37 2018 New Revision: 337402 URL: https://svnweb.freebsd.org/changeset/base/337402 Log: libbe(3): Rewrite activate temp bits to rely less on loader Loader is still relied upon at the beginning of libbe to specify the be root, but we can derive from that the primary zpool and any vdevs that we need to set nextboot bits on. This lets me successfully `bectl activate -t test`, but UEFI loader doesn't quite yet understand so it's effectively defunct. Modified: projects/bectl/lib/libbe/be.c Modified: projects/bectl/lib/libbe/be.c ============================================================================== --- projects/bectl/lib/libbe/be.c Tue Aug 7 00:51:49 2018 (r337401) +++ projects/bectl/lib/libbe/be.c Tue Aug 7 01:56:37 2018 (r337402) @@ -657,7 +657,7 @@ be_import(libbe_handle_t *lbh, char *bootenv, int fd) * XXX TODO: this is a very likely name for someone to already have * used... we should avoid it. */ - if ((err = be_root_concat(lbh, "be_import_temp", buf)) != 0) + if ((err = be_root_concat(lbh, "libbe_import_temp", buf)) != 0) /* XXX TODO error handle */ return (-1); @@ -798,14 +798,43 @@ be_add_child(libbe_handle_t *lbh, char *child_path, bo return (BE_ERR_SUCCESS); } +static int +be_set_nextboot(libbe_handle_t *lbh, nvlist_t *config, uint64_t pool_guid, + const char *zfsdev) +{ + nvlist_t **child; + uint64_t vdev_guid; + int c, children; + if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN, &child, + &children) == 0) { + for (c = 0; c < children; ++c) + if (be_set_nextboot(lbh, child[c], pool_guid, zfsdev) != 0) + return (1); + return (0); + } + + if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID, + &vdev_guid) != 0) { + return (1); + } + + if (zpool_nextboot(lbh->lzh, pool_guid, vdev_guid, zfsdev) != 0) { + perror("ZFS_IOC_NEXTBOOT failed"); + return (1); + } + + return (0); +} + + int be_activate(libbe_handle_t *lbh, char *bootenv, bool temporary) { char be_path[BE_MAXPATHLEN]; char buf[BE_MAXPATHLEN]; uint64_t pool_guid; - uint64_t vdev_guid; + nvlist_t *config, *vdevs; int err; be_root_concat(lbh, bootenv, be_path); @@ -819,33 +848,25 @@ be_activate(libbe_handle_t *lbh, char *bootenv, bool t * XXX TODO: give proper attribution to author(s) of zfsbootcfg * for this snippet. */ - - if (kenv(KENV_GET, "vfs.zfs.boot.primary_pool", buf, - sizeof(buf)) <= 0) + config = zpool_get_config(lbh->active_phandle, NULL); + if (config == NULL) { + printf("no config\n"); return (1); - pool_guid = strtoumax(buf, NULL, 10); - if (pool_guid == 0) - return (1); + } - if (kenv(KENV_GET, "vfs.zfs.boot.primary_vdev", buf, - sizeof(buf)) <= 0) + if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, + &pool_guid) != 0) return (1); - vdev_guid = strtoumax(buf, NULL, 10); - if (vdev_guid == 0) { - return (1); - } /* Expected format according to zfsbootcfg(8) man */ strcpy(buf, "zfs:"); strcat(buf, be_path); strcat(buf, ":"); - if (zpool_nextboot(lbh->lzh, pool_guid, vdev_guid, buf) != 0) { - perror("ZFS_IOC_NEXTBOOT failed"); + if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &vdevs) != 0) return (1); - } - return (BE_ERR_SUCCESS); + return (be_set_nextboot(lbh, vdevs, pool_guid, buf)); } else { /* Obtain bootenv zpool */ err = zpool_set_prop(lbh->active_phandle, "bootfs", be_path);