From nobody Mon May 01 21:04:13 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q9G0s598zz491Xr; Mon, 1 May 2023 21:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q9G0s4W24z3Hsr; Mon, 1 May 2023 21:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682975053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HI34fVl5UNMSx7e2ObdFctGSBKOG6yX/p/yjS3B7ox0=; b=HcgYsqMKq2FCWBXE7RndIB0vA+yhJS2140EDxa+6SN7hGU+BOmpkUA/lj0CAX3/RQ8g/vk NOrz5urQucYCsRKJJmVPGY4sP4aIl5MrrLtNHgAGb+6eiZwVrJ7ZdujEgdEI/kSCx/ycUS yWKSeiJMhkoG4zGX6+cIj7nK+S41HHspHA+4w6tdGkyv00vWpGTLLp/GIcObNuswg2A3dh WXAwnEDbcyKwV7t39g6sJb5kyrE94TiBfJWPgqBe/NnUMWcjjp+ePUJ3lXIeapU5c00Vn3 VCiYlDAXV93Xc8VgIEF8D+xneGEfS7w/IvGCvWceFZzx1tXY3/zF1VZDz+U6zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682975053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HI34fVl5UNMSx7e2ObdFctGSBKOG6yX/p/yjS3B7ox0=; b=lMX26aNpfkOZx2ampH9O/90fn1CdIJQfvHF4Vcwh6TIjnHm/z6zKC9OqePyz2qzBJSeqPq FV79GlzpAaqIkUW4dGfCFQakmAFqYmWzS+nELP1M/ExXk5fj5CY8O+y+Q6UkeUkqk2X2mp N7WQ9BnZMQgLPSva9KwhKFUdSx6L/4TUHYSfzQ5cRWFkgY1E7Mv+PsMqsrVIGfDDzaK++l qPSHV/+9jmgAgcq56iGQMWAu8St80lxaYQkXs2kNbUnmNGA3KHNFHX2U+Z9elsGA52NBQb wjepoN2R1qplIgn/+xEBzKGZRa0+m7/8/ARoPqZzji9FlPFm6HLnBU8kFXTNSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682975053; a=rsa-sha256; cv=none; b=g4aiKTVcUu0EDqB5FBauadAd/FUksHHhgucVoIecQEURGbK1pBEyBJFlF51N1wZpWSb9tD rw1kFmHX2j+tVa0xf8tbrNuVROoFtWEe/1y7Ecka4GFixSdyrj49yw3R1TN6BdfGAmcRoz j3ZCFT0n+x3JL9eMM6pQuJClxMMmDcmS0G5XDC4bt8ejHUkmAr1zsHFZbb0y0Eg9i7sw0I yVcvT2KFU6i4ePOCA9BHHwvt57tl3r3IvCBKNtp47TZ8Gnm3J6E5BFZLWc8x571xABAX61 v5NXLalwhbLvsdvrGsQw0Figr6isnH1ROToHJWfKkCcj5sJE+Nf/w7vx5IRUcg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q9G0s3Jf9zKkx; Mon, 1 May 2023 21:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 341L4DvC051760; Mon, 1 May 2023 21:04:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 341L4Dlu051759; Mon, 1 May 2023 21:04:13 GMT (envelope-from git) Date: Mon, 1 May 2023 21:04:13 GMT Message-Id: <202305012104.341L4Dlu051759@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 6479bd1b7d34 - main - stand/zfs: Refactor zfs_get_bootenv List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6479bd1b7d347e42012fab64b595b0cf091e13f4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=6479bd1b7d347e42012fab64b595b0cf091e13f4 commit 6479bd1b7d347e42012fab64b595b0cf091e13f4 Author: Warner Losh AuthorDate: 2023-05-01 15:26:51 +0000 Commit: Warner Losh CommitDate: 2023-05-01 21:02:53 +0000 stand/zfs: Refactor zfs_get_bootenv Create a new interface to zfs_get_bootenv called zfs_get_bootenv_spa which takes a spa instead of a void * (effectively a devdesc *). Use that in zfs_get_bootenv. Sponsored by: Netflix Reviewed by: tsoome, kevans Differential Revision: https://reviews.freebsd.org/D39409 --- stand/libsa/zfs/zfs.c | 27 ++------------------------- stand/libsa/zfs/zfsimpl.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c index 4a4d3cf26843..17f213fe833c 100644 --- a/stand/libsa/zfs/zfs.c +++ b/stand/libsa/zfs/zfs.c @@ -798,35 +798,12 @@ zfs_probe_partition(void *arg, const char *partname, int zfs_get_bootenv(void *vdev, nvlist_t **benvp) { - struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev; - nvlist_t *benv = NULL; - vdev_t *vd; spa_t *spa; - if (dev->dd.d_dev->dv_type != DEVT_ZFS) - return (ENOTSUP); - - if ((spa = spa_find_by_dev(dev)) == NULL) + if ((spa = spa_find_by_dev((struct zfs_devdesc *)vdev)) == NULL) return (ENXIO); - if (spa->spa_bootenv == NULL) { - STAILQ_FOREACH(vd, &spa->spa_root_vdev->v_children, - v_childlink) { - benv = vdev_read_bootenv(vd); - - if (benv != NULL) - break; - } - spa->spa_bootenv = benv; - } else { - benv = spa->spa_bootenv; - } - - if (benv == NULL) - return (ENOENT); - - *benvp = benv; - return (0); + return (zfs_get_bootenv_spa(spa, benvp)); } /* diff --git a/stand/libsa/zfs/zfsimpl.c b/stand/libsa/zfs/zfsimpl.c index 29e8bb82b6e2..40a1448a0c9f 100644 --- a/stand/libsa/zfs/zfsimpl.c +++ b/stand/libsa/zfs/zfsimpl.c @@ -3853,3 +3853,33 @@ done: free(entry); return (rc); } + +/* + * Return either a cached copy of the bootenv, or read each of the vdev children + * looking for the bootenv. Cache what's found and return the results. Returns 0 + * when benvp is filled in, and some errno when not. + */ +static int +zfs_get_bootenv_spa(spa_t *spa, nvlist_t **benvp) +{ + vdev_t *vd; + nvlist_t *benv = NULL; + + if (spa->spa_bootenv == NULL) { + STAILQ_FOREACH(vd, &spa->spa_root_vdev->v_children, + v_childlink) { + benv = vdev_read_bootenv(vd); + + if (benv != NULL) + break; + } + spa->spa_bootenv = benv; + } + benv = spa->spa_bootenv; + + if (benv == NULL) + return (ENOENT); + + *benvp = benv; + return (0); +}