From nobody Mon May 1 21:04:15 2023 X-Original-To: dev-commits-src-main@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 4Q9G0v7012z491DV; Mon, 1 May 2023 21:04:15 +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 4Q9G0v64b1z3Hts; Mon, 1 May 2023 21:04:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682975055; 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=GZGVgCXaYZ8dHgzloyRJVIhQawhhsB6l/cMwA/nvVCw=; b=kOdhMLGbdw3RkSl0RwOrgBjnqogMJzbFRDWZbns81YIjmkzqyPtL2xTzgbgQGnuS4OAcci ysLKBmFCcSM3kzyQ45wjtY8EO2F9doL6UjIKjDkrTIsVEo3b/jlGEi9vd3IW+J5E9Hv9me r+xxGQMIuHBza6l9fJqYompcF4QtsR2kRUHq0m3xtMGQB47xQqHMSobmjPVM/z5PscBwAp xwJ0yltRqWIJX1lbepcG1CFtkKZc/VCO/DlHawYMD9aueM4PqnwQNzrJB+iw2h1gvfPFk3 iLIfyO3NR250fqcS09o9d+JVb4G58rqcVBQW/+HmhTuaIb+C47aRdkS2y2BT+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682975055; 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=GZGVgCXaYZ8dHgzloyRJVIhQawhhsB6l/cMwA/nvVCw=; b=WIqFIhbuWUPzvrwaDm3nW9rWa3/UFrzgu1LWdnlm+5Tt9vKtMgwm04hhiOssmU3Nra9r6L ZndYMBpDs5qb/I3FM3l+z3oZhsmRnHjFh5AYg+kL7jet47yez2Bwg0UzNwNKVZeFa3OPV9 whamkG/lV0IGhp5utkUU+oXhQT0Yno3hYVpjsjf/IcU+vWwMySf0/G3HXsbjLw+Ang53jh 18G/2r8WTnkj0m8DVKAeBDVLWanuwh/Gz3/oFztI6ghdq8OjI8TVk8twfLsJ/20rJNpRqM B8pfBqj/o5f3Ohp/w+UQoTSiRBUtopNLMTXSnm/d9/vGWrkZG3Ip+2PUdyXF9g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682975055; a=rsa-sha256; cv=none; b=ZWV1wTlygWDI059Gk+2/1ykAtunzNhGVsxBXfW+OT4yNRFeOREQDWvgHgQuv7uZGxAP5Bt VUG04njasoVjbEdpPqMQ3f90O6/NdpntCmeCdzPWuRYho9dtgX/bt97et5OCON3S2Bh/l3 Md9+32OKFvhQfOOtIIQwMWqpVBpLQFIKBMJQUl2fY2icZXU+h/vh1gj0g4XOkYUXzNl19I x2LCF7ElX8qnupPdzRWHwzOrhZSsru4lSPgvA4ifyOqeemMpUaADRCSDXceIcrisnLt/Uf CPdMMUXiLnGIcoF5qrfozZYOR+bGDf2ulYF4KO87mBUQoiuidzVWCXeUJlNJMg== 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 4Q9G0v550GzLWv; Mon, 1 May 2023 21:04:15 +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 341L4FFA051806; Mon, 1 May 2023 21:04:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 341L4FMP051805; Mon, 1 May 2023 21:04:15 GMT (envelope-from git) Date: Mon, 1 May 2023 21:04:15 GMT Message-Id: <202305012104.341L4FMP051805@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: b765cfa380a4 - main - stand/zfs: Refactor zfs_get_bootonce List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: b765cfa380a47de2b77cbf8a6249e226b0de2275 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b765cfa380a47de2b77cbf8a6249e226b0de2275 commit b765cfa380a47de2b77cbf8a6249e226b0de2275 Author: Warner Losh AuthorDate: 2023-05-01 15:27:06 +0000 Commit: Warner Losh CommitDate: 2023-05-01 21:02:53 +0000 stand/zfs: Refactor zfs_get_bootonce Lookup the spa and pass it into zfs_get_bootonce_spa to process the boot once protocol. Sponsored by: Netflix Reviewed by: tsoome, kevans Differential Revision: https://reviews.freebsd.org/D39411 --- stand/libsa/zfs/zfs.c | 23 ++++------------------- stand/libsa/zfs/zfsimpl.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c index 7cdfa1a06df9..8ddd6de8623d 100644 --- a/stand/libsa/zfs/zfs.c +++ b/stand/libsa/zfs/zfs.c @@ -827,27 +827,12 @@ zfs_set_bootenv(void *vdev, nvlist_t *benv) int zfs_get_bootonce(void *vdev, const char *key, char *buf, size_t size) { - nvlist_t *benv; - char *result = NULL; - int result_size, rv; - - if ((rv = zfs_get_bootenv(vdev, &benv)) != 0) - return (rv); + spa_t *spa; - if ((rv = nvlist_find(benv, key, DATA_TYPE_STRING, NULL, - &result, &result_size)) == 0) { - if (result_size == 0) { - /* ignore empty string */ - rv = ENOENT; - } else { - size = MIN((size_t)result_size + 1, size); - strlcpy(buf, result, size); - } - (void) nvlist_remove(benv, key, DATA_TYPE_STRING); - (void) zfs_set_bootenv(vdev, benv); - } + if ((spa = spa_find_by_dev((struct zfs_devdesc *)vdev)) == NULL) + return (ENXIO); - return (rv); + return (zfs_get_bootonce_spa(spa, key, buf, size)); } /* diff --git a/stand/libsa/zfs/zfsimpl.c b/stand/libsa/zfs/zfsimpl.c index 3b093dea3c41..996245b92c45 100644 --- a/stand/libsa/zfs/zfsimpl.c +++ b/stand/libsa/zfs/zfsimpl.c @@ -3899,3 +3899,36 @@ zfs_set_bootenv_spa(spa_t *spa, nvlist_t *benv) spa->spa_bootenv = benv; return (0); } + +/* + * Get bootonce value by key. The bootonce pair is removed from the + * bootenv nvlist and the remaining nvlist is committed back to disk. This process + * the bootonce flag since we've reached the point in the boot that we've 'used' + * the BE. For chained boot scenarios, we may reach this point multiple times (but + * only remove it and return 0 the first time). + */ +static int +zfs_get_bootonce_spa(spa_t *spa, const char *key, char *buf, size_t size) +{ + nvlist_t *benv; + char *result = NULL; + int result_size, rv; + + if ((rv = zfs_get_bootenv_spa(spa, &benv)) != 0) + return (rv); + + if ((rv = nvlist_find(benv, key, DATA_TYPE_STRING, NULL, + &result, &result_size)) == 0) { + if (result_size == 0) { + /* ignore empty string */ + rv = ENOENT; + } else if (buf != NULL) { + size = MIN((size_t)result_size + 1, size); + strlcpy(buf, result, size); + } + (void)nvlist_remove(benv, key, DATA_TYPE_STRING); + (void)zfs_set_bootenv_spa(spa, benv); + } + + return (rv); +}