From owner-svn-src-head@freebsd.org Fri Jun 15 19:07:27 2018 Return-Path: Delivered-To: svn-src-head@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 79A1F1018D34; Fri, 15 Jun 2018 19:07:27 +0000 (UTC) (envelope-from imp@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 2FA817EB37; Fri, 15 Jun 2018 19:07:27 +0000 (UTC) (envelope-from imp@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 10CF71B865; Fri, 15 Jun 2018 19:07:27 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5FJ7QAU096144; Fri, 15 Jun 2018 19:07:26 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5FJ7Qnj096140; Fri, 15 Jun 2018 19:07:26 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201806151907.w5FJ7Qnj096140@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 15 Jun 2018 19:07:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335229 - in head/stand/efi: include libefi loader X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/stand/efi: include libefi loader X-SVN-Commit-Revision: 335229 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2018 19:07:27 -0000 Author: imp Date: Fri Jun 15 19:07:26 2018 New Revision: 335229 URL: https://svnweb.freebsd.org/changeset/base/335229 Log: Provide a more direct interface to tell ZFS what the preferred handle is. We tell the ZFS code now, and it checks rather than having a callback to do the checks. This will allow us to have a more graceful fallback code. In the future, it's anticipated that we may fallback to a more global search (or implement a command to do so) when reqeusted by the user, or we detect a violation of the UEFI Boot Manager protocol severe enough to warrant this backstop. For now, it just allows us to get rid of img as a global. Sponsored by: Netflix Modified: head/stand/efi/include/efizfs.h head/stand/efi/libefi/efizfs.c head/stand/efi/loader/main.c Modified: head/stand/efi/include/efizfs.h ============================================================================== --- head/stand/efi/include/efizfs.h Fri Jun 15 19:07:06 2018 (r335228) +++ head/stand/efi/include/efizfs.h Fri Jun 15 19:07:26 2018 (r335229) @@ -44,11 +44,11 @@ typedef struct zfsinfo extern uint64_t pool_guid; -extern void efi_zfs_probe(void); -extern zfsinfo_list_t *efizfs_get_zfsinfo_list(void); -extern bool efi_zfs_is_preferred(EFI_HANDLE *h); -extern EFI_HANDLE efizfs_get_handle_by_guid(uint64_t); -extern bool efizfs_get_guid_by_handle(EFI_HANDLE, uint64_t *); +void efi_zfs_probe(void); +EFI_HANDLE efizfs_get_handle_by_guid(uint64_t); +bool efizfs_get_guid_by_handle(EFI_HANDLE, uint64_t *); +zfsinfo_list_t *efizfs_get_zfsinfo_list(void); +void efizfs_set_preferred(EFI_HANDLE); #endif Modified: head/stand/efi/libefi/efizfs.c ============================================================================== --- head/stand/efi/libefi/efizfs.c Fri Jun 15 19:07:06 2018 (r335228) +++ head/stand/efi/libefi/efizfs.c Fri Jun 15 19:07:26 2018 (r335229) @@ -45,6 +45,14 @@ static zfsinfo_list_t zfsinfo; uint64_t pool_guid; +static EFI_HANDLE preferred; + +void +efizfs_set_preferred(EFI_HANDLE h) +{ + preferred = h; +} + zfsinfo_list_t * efizfs_get_zfsinfo_list(void) { @@ -110,16 +118,13 @@ efi_zfs_probe(void) */ STAILQ_FOREACH(hd, hdi, pd_link) { STAILQ_FOREACH(pd, &hd->pd_part, pd_link) { - snprintf(devname, sizeof(devname), "%s%dp%d:", efipart_hddev.dv_name, hd->pd_unit, pd->pd_unit); - - if (zfs_probe_dev(devname, &guid) == 0) { - insert_zfs(pd->pd_handle, guid); - - if (efi_zfs_is_preferred(pd->pd_handle)) - pool_guid = guid; - } + if (zfs_probe_dev(devname, &guid) == 0) { + insert_zfs(pd->pd_handle, guid); + if (pd->pd_handle == preferred) + pool_guid = guid; + } } } Modified: head/stand/efi/loader/main.c ============================================================================== --- head/stand/efi/loader/main.c Fri Jun 15 19:07:06 2018 (r335228) +++ head/stand/efi/loader/main.c Fri Jun 15 19:07:26 2018 (r335229) @@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$"); #ifdef EFI_ZFS_BOOT #include - #include "efizfs.h" #endif @@ -73,8 +72,6 @@ EFI_GUID debugimg = DEBUG_IMAGE_INFO_TABLE_GUID; EFI_GUID fdtdtb = FDT_TABLE_GUID; EFI_GUID inputid = SIMPLE_TEXT_INPUT_PROTOCOL; -static EFI_LOADED_IMAGE *img; - /* * Number of seconds to wait for a keystroke before exiting with failure * in the event no currdev is found. -2 means always break, -1 means @@ -84,14 +81,6 @@ static EFI_LOADED_IMAGE *img; */ static int fail_timeout = 5; -#ifdef EFI_ZFS_BOOT -bool -efi_zfs_is_preferred(EFI_HANDLE *h) -{ - return (h == img->DeviceHandle); -} -#endif - static bool has_keyboard(void) { @@ -424,6 +413,7 @@ main(int argc, CHAR16 *argv[]) UINT16 boot_current; size_t sz; UINT16 boot_order[100]; + EFI_LOADED_IMAGE *img; #if !defined(__arm__) char buf[40]; #endif @@ -441,6 +431,10 @@ main(int argc, CHAR16 *argv[]) /* Get our loaded image protocol interface structure. */ BS->HandleProtocol(IH, &imgid, (VOID**)&img); +#ifdef EFI_ZFS_BOOT + /* Tell ZFS probe code where we booted from */ + efizfs_set_preferred(img->DeviceHandle); +#endif /* Init the time source */ efi_time_init();