From nobody Thu Jun 8 18:14:59 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 4QcXS41BFQz4cGLS; Thu, 8 Jun 2023 18:15:00 +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 4QcXS40TjPz413c; Thu, 8 Jun 2023 18:15:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686248100; 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=v7Ni4YagvHA+C3OSnIReBfIUBOWehM8xtKn7JG2j0L8=; b=RT027srWAM1QhWC4wYkX6iXdQBFnnfk2UR9zcWXKD9Z5pXjB58U8QdkuCf6FmU6nGZhw1m 0Qty9aewAf1QmUZXC8O4PAx881vGJ2986cyuVjVQL4WTRMDcgXJZoMiczBE+zzS8FSzrQ9 iV7c9/KQXIlkXg8DjTNsPXhfXKqcGMbLx1JFDmPotTCltTd/LUZufkDn5Ve3UWB5Kyh0gj PDJqQrhMaNyyLG96bi/Lm/sOR8E8BmWaM9HOuP00y2qUdEBrvHYTvmAfFpLibtYWDpMz+k 23X+ebFyDtw4VRkeNv4WiXy7MHRttxOaZdMAQoBaBEvJ74XyffuzsW0dtZvBAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686248100; 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=v7Ni4YagvHA+C3OSnIReBfIUBOWehM8xtKn7JG2j0L8=; b=ykE8APCoCKDKwAUARLlLX974FkXwhOEjHHPWQE0T38GzgxcYliP+CINVlKl0fMur6y4r2d qs7diYkuy+19RigegpyVeprX+sDG/bVdSYM+O0ELeDG67nJlWYPsCoAVib3vj/DjfGPVVo PBDxs6QWjcO0rB1xWu03YpXsHzii/t4zm3QtrJttPhl8Rgbkuk22OHRSiqjioH6DHmWVEL jy1CtsKxeKcg51u+l3+rrl9u1hAZ2D/Pw5z4atxiSrbrkcOGXxlW68HIKMIVZAibpJQ42h ojMWvYKO7ngQJ+9oeRYV7TUly4cGXepJAuZ0M8HPAUCxYZDPQP6sEprJ+3/0Mg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686248100; a=rsa-sha256; cv=none; b=fUYSFOLEa0uoOs/RA9C241jeIQT+M4wPqCuYXc3x8PZiPBmO50CjqllEUTWuo+q+//8rTQ ZmYbBQIcNAbjZV2aifBRR22PYv8gw4HJq7nK4LcUI6vta7l0r3RNWHK6+b9tqOoqh0TdFX YcKRIBFJP+72t+sCElZOxg2+aii4MSLrhbyoWLsCNUIR6SCMrYnffahhiFZuvUHoM7My5a v8vxBhNnQuG0MI3pFbuS/NvXa9HyoGqPplDessTG6PLL7A+1ZuzqqJetMw2iWAyw863zEM LeK6wZdA455puyQEICbrcNAkypApfGwECmT7mKNyvQ01JUSsJkY2GhNf3CUNVQ== 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 4QcXS36f8Hz14D3; Thu, 8 Jun 2023 18:14:59 +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 358IExKB032185; Thu, 8 Jun 2023 18:14:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 358IEx1H032184; Thu, 8 Jun 2023 18:14:59 GMT (envelope-from git) Date: Thu, 8 Jun 2023 18:14:59 GMT Message-Id: <202306081814.358IEx1H032184@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: bbc64cf66cdf - main - stand/boot1.efi: use the bootonce dataset as root dataset 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bbc64cf66cdf03bc0e45aecfbca13f7b6f025a65 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=bbc64cf66cdf03bc0e45aecfbca13f7b6f025a65 commit bbc64cf66cdf03bc0e45aecfbca13f7b6f025a65 Author: Gleb Smirnoff AuthorDate: 2023-06-08 18:14:45 +0000 Commit: Gleb Smirnoff CommitDate: 2023-06-08 18:14:45 +0000 stand/boot1.efi: use the bootonce dataset as root dataset Before this change we would only pass the bootonce dataset name to the environment for the next loader, while actually reading the next stage loader from the 'bootfs' dataset, not the bootonce dataset. Another problem fixed by this change is a boot from a configuration when bootonce attribute is present, but 'bootfs' property is not set. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D40389 --- stand/efi/boot1/zfs_module.c | 54 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/stand/efi/boot1/zfs_module.c b/stand/efi/boot1/zfs_module.c index 234b50084839..c9a1038d0e6a 100644 --- a/stand/efi/boot1/zfs_module.c +++ b/stand/efi/boot1/zfs_module.c @@ -144,6 +144,7 @@ load(const char *filepath, dev_info_t *devinfo, void **bufp, size_t *bufsize) struct zfsmount zmount; dnode_phys_t dn; struct stat st; + uint64_t rootobj; int err; void *buf; @@ -162,20 +163,49 @@ load(const char *filepath, dev_info_t *devinfo, void **bufp, size_t *bufsize) return (EFI_NOT_FOUND); } - if ((err = zfs_mount_impl(spa, 0, &zmount)) != 0) { - DPRINTF("Failed to mount pool '%s' (%d)\n", spa->spa_name, err); - return (EFI_NOT_FOUND); + if (zfs_get_bootonce_spa(spa, OS_BOOTONCE, zfs_bootonce, + sizeof(zfs_bootonce)) == 0) { + /* + * If bootonce attribute is present, use it as root dataset. + * Any attempt to use it should clear the 'once' flag. Prior + * to now, we'd not be able to clear it anyway. We don't care + * if we can't find the files to boot, or if there's a problem + * with it: we've tried to use it once we're able to mount the + * ZFS dataset. + * + * Note: the attribute is prefixed with "zfs:" and suffixed + * with ":". + */ + char *dname, *end; + + if (zfs_bootonce[0] != 'z' || zfs_bootonce[1] != 'f' || + zfs_bootonce[2] != 's' || zfs_bootonce[3] != ':' || + (dname = strchr(&zfs_bootonce[4], '/')) == NULL || + (end = strrchr(&zfs_bootonce[4], ':')) == NULL) { + printf("INVALID zfs bootonce: %s\n", zfs_bootonce); + *zfs_bootonce = '\0'; + rootobj = 0; + } else { + dname += 1; + *end = '\0'; + if (zfs_lookup_dataset(spa, dname, &rootobj) != 0) { + printf("zfs bootonce dataset %s NOT FOUND\n", + dname); + *zfs_bootonce = '\0'; + rootobj = 0; + } else + printf("zfs bootonce: %s\n", zfs_bootonce); + *end = ':'; + } + } else { + *zfs_bootonce = '\0'; + rootobj = 0; } - /* - * OK. We've found a filesystem. Any attempt to use it should clear the - * 'once' flag. Prior to now, we'd not be able to clear it anyway. We - * don't care if we can't find the files to boot, or if there's a - * problem with it: we've tried to use it once we're able to mount the - * ZFS dataset. - */ - *zfs_bootonce = '\0'; - zfs_get_bootonce_spa(spa, OS_BOOTONCE, zfs_bootonce, sizeof(zfs_bootonce)); + if ((err = zfs_mount_impl(spa, rootobj, &zmount)) != 0) { + printf("Failed to mount pool '%s' (%d)\n", spa->spa_name, err); + return (EFI_NOT_FOUND); + } if ((err = zfs_lookup(&zmount, filepath, &dn)) != 0) { if (err == ENOENT) {