From owner-svn-src-all@freebsd.org Mon Jun 10 15:46:20 2019 Return-Path: Delivered-To: svn-src-all@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 8C78B15C2779; Mon, 10 Jun 2019 15:46:20 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id ED00180AAE; Mon, 10 Jun 2019 15:46:19 +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 B897F1C500; Mon, 10 Jun 2019 15:46:19 +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 x5AFkJds097625; Mon, 10 Jun 2019 15:46:19 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5AFkJDH097624; Mon, 10 Jun 2019 15:46:19 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201906101546.x5AFkJDH097624@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 10 Jun 2019 15:46:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r348865 - in stable/12/stand: common i386/zfsboot X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/12/stand: common i386/zfsboot X-SVN-Commit-Revision: 348865 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: ED00180AAE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jun 2019 15:46:20 -0000 Author: kevans Date: Mon Jun 10 15:46:19 2019 New Revision: 348865 URL: https://svnweb.freebsd.org/changeset/base/348865 Log: MFC r348569: [zfsboot] Fix boot env back compat (#190) * Fix boot env back compat zfsboot must try zfsloader before loader in order to remain compatible with boot environments created prior to zfs functionality being rolled into loader proper. * Improve comments in zfsboot Explain the significance of the load path order, and put the comment about looping through the paths in the appropriate scope. Modified: stable/12/stand/common/paths.h stable/12/stand/i386/zfsboot/zfsboot.c Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/common/paths.h ============================================================================== --- stable/12/stand/common/paths.h Mon Jun 10 15:44:09 2019 (r348864) +++ stable/12/stand/common/paths.h Mon Jun 10 15:46:19 2019 (r348865) @@ -33,6 +33,7 @@ #define PATH_CONFIG "/boot/config" #define PATH_LOADER "/boot/loader" #define PATH_LOADER_EFI "/boot/loader.efi" +#define PATH_LOADER_ZFS "/boot/zfsloader" #define PATH_KERNEL "/boot/kernel/kernel" #endif /* _PATHS_H_ */ Modified: stable/12/stand/i386/zfsboot/zfsboot.c ============================================================================== --- stable/12/stand/i386/zfsboot/zfsboot.c Mon Jun 10 15:44:09 2019 (r348864) +++ stable/12/stand/i386/zfsboot/zfsboot.c Mon Jun 10 15:46:19 2019 (r348865) @@ -87,6 +87,24 @@ static const unsigned char flags[NOPT] = { }; uint32_t opts; +/* + * Paths to try loading before falling back to the boot2 prompt. + * + * /boot/zfsloader must be tried before /boot/loader in order to remain + * backward compatible with ZFS boot environments where /boot/loader exists + * but does not have ZFS support, which was the case before FreeBSD 12. + * + * If no loader is found, try to load a kernel directly instead. + */ +static const struct string { + const char *p; + size_t len; +} loadpath[] = { + { PATH_LOADER_ZFS, sizeof(PATH_LOADER_ZFS) }, + { PATH_LOADER, sizeof(PATH_LOADER) }, + { PATH_KERNEL, sizeof(PATH_KERNEL) }, +}; + static const unsigned char dev_maj[NDEV] = {30, 4, 2}; static char cmd[512]; @@ -838,16 +856,17 @@ main(void) if (nextboot && !autoboot) reboot(); - /* - * Try to exec /boot/loader. If interrupted by a keypress, - * or in case of failure, try to load a kernel directly instead. - */ - if (autoboot && !*kname) { - memcpy(kname, PATH_LOADER, sizeof(PATH_LOADER)); - if (!keyhit(3)) { + /* + * Iterate through the list of loader and kernel paths, trying to load. + * If interrupted by a keypress, or in case of failure, drop the user + * to the boot2 prompt. + */ + for (i = 0; i < nitems(loadpath); i++) { + memcpy(kname, loadpath[i].p, loadpath[i].len); + if (keyhit(3)) + break; load(); - memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL)); } }